This wiki is being migrated to http://www.github.com/z88dk/z88dk/wiki

 

ZX 81 LIBRARY (zx81.h)

Header {z88dk}/include/zx81.h
Source {z88dk}/libsrc/zx81
Include #include <zx81.h>
Linking n/a
Compile n/a
Supported zx 81
Comments n/a

The ZX 81 library contains functions specific to the Sinclair ZX81 / Timex 1000 family machines.

Constants

BASIC language keyword tokens

RNDTK_RND64
INKEY$TK_INKEYS65
PITK_PI66
” “TK_DBLQUOTE192
ATTK_AT193
TABTK_TAB194
CODETK_CODE196
VALTK_VAL197
LENTK_LEN198
SINTK_SIN199
COSTK_COS200
TANTK_TAN201
ASNTK_ASN202
ACSTK_ACS203
ATNTK_ATN204
LNTK_LN205
EXPTK_EXP206
INTTK_INT207
SQRTK_SQR208
SGNTK_SGN209
ABSTK_ABS210
PEEKTK_PEEK211
USRTK_USR212
STR$TK_STRS213
CHR$TK_CHRS214
NOTTK_NOT215
* *TK_STARSTAR216
ORTK_OR217
ANDTK_AND218
< = TK_LEQ219
> = TK_GEQ220
< > TK_NEQ221
THENTK_THEN222
TOTK_TO223
STEPTK_STEP224
LPRINTTK_LPRINT225
LLISTTK_LLIST226
STOPTK_STOP227
SLOWTK_SLOW228
FASTTK_FAST229
NEWTK_NEW230
SCROLLTK_SCROLL231
CONTINUETK_CONTINUE232
CONTTK_CONT232
DIMTK_DIM233
REMTK_REM234
FORTK_FOR235
GO TOTK_GO_TO236
GO SUBTK_GO_SUB237
INPUTTK_INPUT238
LOADTK_LOAD239
LISTTK_LIST240
LETTK_LET241
PAUSETK_PAUSE242
NEXTTK_NEXT243
POKETK_POKE244
PRINTTK_PRINT245
PLOTTK_PLOT246
RUNTK_RUN247
SAVETK_SAVE248
RANDOMIZETK_RANDOMIZE249
RANDOMIZETK_RAND249
IFTK_IF250
CLSTK_CLS251
UNPLOTTK_UNPLOT252
CLEARTK_CLEAR253
RETURNTK_RETURN254
COPYTK_COPY255

Configuration diagnostics

int zx_basic_length()

Computes the size of the BASIC program in memory (if any).

int zx_var_length()

Computes the current size of the BASIC variables area.

Interfacing to the ZX 81 BASIC

The following functions open a powerful way to exchange data between the BASIC environment and to develop programs mixing BASIC, C and machine code modules. The variable names are automatically translated from ASCII to the ZX81 char encoding, while the string content translator can, if necessary, be disabled to manage the ZX81 special characters.

int zx_line(int line)

Runs a single BASIC line. The returned value is zero or the BASIC error code, if any.

int zx_getstr(char variable, char *value)

Load the specified BASIC string variable into *value.

The character codes are converted from ZX81 to ASCII. (This behaviour can be changed with the zx_asciimode function).

void zx_setstr(char variable, char *value)

Copies *value into a given BASIC string variable, creating it if necessary.

The character codes are converted from ASCII to ZX81. (This behaviour can be changed with the zx_asciimode function).

int zx_getint(char *variable)

Return the integer value for the specified BASIC numeric variable.

void zx_setint(char *variable, int value)

Copies “value” (int format) to the specified BASIC variable, creating it if necessary. *variable must be set with the BASIC variable name.

double zx_getfloat(char *variable)

Return the floating point value for the specified BASIC numeric variable.

void zx_setfloat(char *variable, float value)

Copies “value” (floating point format) to the specified BASIC variable, creating it if necessary. *variable must be set with the BASIC variable name.

Example

Interfacing the ZX 81 BASIC

This demonstration program computes the coordinates for a second level equation, then calls BASIC to plot the pixel.

First compile the program:

zcc +zx81 -o zxbasic -create-app zxbasic.c

Then load “zxbasic.p” in your (real or emulated) zx81, and add the following BASIC lines:

      100 PLOT X,Y
      900 STOP

Now you can RUN the demo. Try also changing the BASIC sub as follows:

      100 PRINT AT Y/2,X/2;"O"

#include <stdio.h>

main()
{
int x;

	for (x=-30; x<30; x++)
	{

		zx_setint ("Y",x*x/30);
		zx_setint ("X",32+x);
		zx_line (100); // 100 PLOT X,Y

	}
	// BASIC termination stub
	zx_line (900); // 900 STOP
}

Miscellaneous functions

invtxt()

Invert the text mode screen

mirrortxt()

Mirror screen horizontally in text mode: rightmost character is put at leftmost position and vice versa.

zx_asciimode()

Activates / Deactivates the ZX81 ↔ ASCII converter used in some output routine and interfacing to the BASIC strings. The ZX81 libraries are set by default to “1” (on).

Note that the normal console output library is based on this converter: when it is disabled and wrong characters are put on the screen, the display handler might be confused, making your program crash.

zx_ascii(unsigned char character)

ZX81 → ASCII char conversion

ascii_zx(unsigned char character)

ASCII → ZX81 char conversion

zx_fast()

Switch to FAST mode, not available if subtype=fast. To gain speed with no screen flickering in HRG you can use blank()/noblank().

zx_slow()

Switch BACK to SLOW mode, not available if subtype=fast.

hrg_tune_left()

Hardware shifting of TV picture in HRG mode

hrg_tune_right()

Hardware shifting of TV picture in HRG mode

blank()

Hides the display picture with no flicker and lets the zx81 run faster.

noblank()

Makes the video visible again, back from the 'blank' status.

High resolution library related functions

There are three available versions of the High resolution libraries, gfx81hr192 (WRX hardware mod) and gfx81arx192 (ARX816 hardware mod) providing a full 256×192 graphics map, and the smaller but faster gfx81hr64/gfx81arx64 which is capable of 256×64 pixels. gfx81mt64 (248×192) and gfx81mt192 (248*64) do the same with The Memotech HRG while g007 supports the G007 board (it needs to be initialized from BASIC with the “SLOW 4” command). Look for more informations on how to activate the WRX style HRG engine at the ZX81 platform description page.

The pictures above show the “microman” demo running on a Memotech HRG board and “wall” on a recent colour expansion (Chroma-81, 2014), comatible with the WRX mode.

base_graphics global variable

This global variable holds the current graphics map. It can be forced to a specific value in the C source with the #pragma directive, in example:

  #pragma output hrgpage = 36096

By default (when no hrgpage is specified) the program is compiled with a builtin relocator for the stack, targetted to a 16K model. For 8K models it is possible to modify the relocator with the following definition:

  #pragma output MEM8K

It is also possible to specify the graphics page location at binary level, by POKEing locations 16518/16519. If the ” #pragma output hrgpage = ” directive is used, an alternate map can still be POKEd, but the automatic relocation engine is excluded.

_clg_hr()

Clear graphics page. It is equal to clg().

hrg_off()

Disable the High Resolution Graphics mode and go back to text mode.

hrg_on()

Enable the High Resolution Graphics mode and go back to text mode.

invhrg()

Invert the video output if in High Resolution mode. This is done without affecting the data in the video memory.

copytxt(int ovmode)

Copies the text page to the HRG screen, permitting to mix text and graphics behaviours. The following modes can be used:

txt_and“white ink”
txt_and_cpl“white ink” and invert
txt_ornormal black on white output
txt_xorxor (sort of sprite effect)
txt_or_rshift 1 pixel left before printing, useful for BOLD or similar effects
txt_or_lshift 1 pixel right before printing, as above
txt_and_ras above, but using “white ink”
txt_and_las above
 
library/zx81.txt · Last modified: 2017/03/25 08:50 by stefano
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki