The ZX Spectrum platform is very well supported in the Z88 Development Kit. All the generic functions are covered (excepting the FAR memory model) and many platform specific libraries are available for both the standard 48K (or 16K) model and the various clones and peripherals.
The binary raw code can be relocated, made auto-relocating or left at its default position at $8000. Tools are provided to package it in various ways, but the default one is the “.TAP” format.
zcc +zx -lndos -lm -create-app program.c
-or-
zcc +zxansi -lndos -lm -create-app program.c
This command will build a .TAP tape image, linking a foo file library and the default math support. To save some memory it is possible to use the ZX Spectrum specific math library, by changing the “-lm” parameter with “-lmzx” or “-lmzx_tiny”, but it will run slower and with less precision.
The +zxansi parameter enables the full VT/ANSI emulation (see the ZX Spectrum libraries section).
If file support is required it is possible to change the “-lndos” parameter and pass a library name (see the ZX Spectrum libraries section).
The ‘appmake’ tool is activated by passing the “-create-app” parameter to the compiler, as already shown. Here are some other examples:
zcc +zx -lndos -lm -zorg=25000 -create-app program.c
The “-zorg=<location>” option locates the code at the desired position; it has effect both on the compiler and on the “appmake” tool, which will adapt the loader for the new location.
zcc +zx -lndos -lm -Cz-o -Cz-myname -create-app program.c
This is an advanced way to pass parameters to the appmake tool; in this case we’ve specified a different file name. The available options are:
-h --help (bool) Display this help
-b --binfile (string) Linked binary file
-c --crt0file (string) crt0 file used in linking
-o --output (string) Name of output file
--org (integer) Origin of the binary
--blockname (string) Name of the code block in tap file
This is a quick and dirty hack originally written for mymzx - this takes any file and creates a .TAP file for it - the file contained is of type CODE and loads to address 0.
This tool appends to the end of the specified .TAP file so watch out!
Warning: this tool overwrites the specified .TAP file
(this one is also included in the standard compiler command line options):
Creates .TAP file with a very simple BASIC loader at the beginning. After converting, a LOAD “” is sufficient to run the code.
Warning: this tool overwrites the specified .TAP file
For skilled developers only.
Creates a new TAP file (overwriting if necessary) with a BASIC program line in which we store the self-relocating binary file as if it was a REMark.
The relocation routine is patched by this tool to fit with the ZX Spectrum behaviour.
To compile a relocatable program:
zcc +zx -Ca-R -lm -lndos program.c bin2bas-rem a.bin a.tap <line number>
To run the machine code:
PRINT USR (PEEK 23635+256*PEEK 23636+5)
Alternatively it is possible to make use of the system variable 23637 (location of the next line to be run) and stuff different programs in a single BASIC source:
1 DEF FN l()=USR(PEEK 23637+256*PEEK 23638+5)
100 LET x=FN l()
101 REM (program)
200 LET x=FN l()
201 REM (another merged program)
Hints: DO NOT edit the REM line. You need to place it at its right position with this tool.
If you are in trouble try to re-MERGE the REM lines onto you main BASIC block.
The new screen driver is still fairly minimal but it does feature 64 column text and 32 column text (switchable) and can be easily extended.
Here are the byte sequences for it:
1,64 - Switch to 64 column mode
1,32 - Switch to 32 column mode
2,ll,hh - Set the address of the 32 column font. ll is low byte, hh = high
byte. By default this points to the ROM font at 15616
3,ll,hh - Set the address for the UDGs by default this points to
65368
8,9,10,11 - Move in x and y as you would expect
12 - Form feed - clears the screen and moves print posn to 0,0
13 - Carriage return - advances y and sets x to 0
16,x - Set the ink colour (x = 48-55 ('0'-'7'))
17,x - Set the paper colour (x = 48-55 ('0'-'7'))
18,x - Turn flash on/off (x=49/48 ('1'/'0')
19,x - Turn on/off bright
20,x - Turn on/off inverse (x=49/48 ('1'/'0')
22,y,x - Move to position y,x on the screen (0<=y<=23, 0<=x<=63)
NB. y and x are displaced by 32 eg to move the print position
to (0,0) use 22,32,32. 32 column mode also uses 64 column
coordinates.
All the commands, except for the udg address/font address can be embedded in strings using either octal or hexadecimal representation. Address changes can be sent either using fputc() or using printf with the address as parameters.
Characters greater than 127 are interpreted as udgs. These are always printed using the 32 column mode. This gives a potential of 128 udgs though obviously, it’s possible to swap between banks in the middle of printing a string.
The screen scrolls when line 24 is “hit”, the routine used is in the 48k ROM.
WARNING: THIS SECTION IS FOR EXPERT USERS ONLY
Before making the library, set the ZXCOLS environment variable. Valid presets are:
24, 28, 32, 36, 40, 42, 51, 64, 80, 85, 128, ROM24, ROM28, ROM32 and ROM36.
When possible the library will be built with a “packed” font to save memory. If you need to save further space, you can choose the ROMxx options: they are all based on the standard ROM font.