Archives
now browsing by author
Z88DK: Creating libraries
About 20 or so years ago a guy called Juergen Buchmeuller joined the VZ200 Yahoo group and was posting updates for MAME (then, MESS) for VZ200 support. He created a few graphics and sound library functions for the VZ200 and created a game “Defense Command” using Z88DK.
I used his base functions and wrote a bunch of my own and created an Arkanoid clone I called “Arkaball“.
The guys at Z88DK used his functions and some of mine and ported them into the main Z88DK repository.
In the years since I have helped add VZ200 support to the Multi-Platform Arcade Game Designer (MPAGD) and Turbo Rascal: ‘;’ expected but “BEGIN”. (TRSE for short!).
I have talked with Prince from the PHAZE101 group and he has “Game Jams” where you get a short amount of time (usually a few weeks) to create a game for a retro platform of your choice, using the theme he decides. The games have to be written in BASIC, Assembly Language or C. While I can write games in Assembler, I prefer something a bit higher level. BASIC is too high and too slow in most cases, but C with Z80 Assembler functions hits the right spot.
I did a lot of research of different ways to do this and finally decided on Z88DK since some of my coding was already done with that and they are really responsive on their forum. The problem is I already wrote a ton of Z80 Assembler code for TRSE Units to code games in Pascal. Now, I need them converted to Z88DK library format.
So, I cloned their github repository and started to work out what to do next. As I had no experience with Z88DK for years it took me a while to grasp things. I also wanted to set up the SublimeText Text Editor to write, build and test my C code.
To start, you will need to BUILD the Z88DK repository code. I will leave you to read this on their website. This was one crucial step I forgot to do! You can set up a SublimeText build system with the following info:
{
"working_dir": "<YOUR HOME>/Dev/VZ/VZEm-Linux/",
"cmd": "zcc +vz -zorg=31488 -vn --list -pragma-define:CLIB_CONIO_NATIVE_COLOUR=1 -create-app -lndos -m $file -o $file_path/$file_base_name.vz",
"shell": true,
"variants":
[
{
"name": "Run",
"cmd": "<YOUR HOME>/Dev/VZ/VZEm-Linux/VZEm-SDL -f $file_path/$file_base_name.vz",
"shell": true
}
]
}
Remember to change the ‘home’ paths to your own. I am building on Fedora Linux. I recently built Guy’s VZEm Emulator (SDL version) for Linux, which you can download from this site.
You can do something similar if you are on Windows and probably on OSX as well. I called my file BuildVZ200.sublime-build You can add it in the Packages/User folder. Select it in the Tools -> Build System menu.
Now, there are certain conventions when it comes to writing code for Z88DK. If you have a simple function with zero or one parameter, you can get away with just one file. Eg. vz_getrnd.asm
SECTION code_clib
PUBLIC vz_getrnd
PUBLIC _vz_getrnd
vz_getrnd:
_vz_getrnd:
ld bc,$0000
call $09b4 ; Loads ACC with BCDE
call $0a9d ; Set flag to Integer
call $14c9 ; RND routine. Using ACC, not A
call $0a7f ; CINT. Puts ACC into HL
ret
This is a function I called vz_getrnd(x). It’s used to get a random number. The number returned can be any value from 0 to 65535. This is because it is defined as an Integer. The above built-in VZ ROM functions are built that way. Note the code above does not have code for the value of ‘x’ which is the highest number limit for your random number. The reason for this is when you call one of these functions, Z88DK will by default put the value directly into the HL registers. This is very handy because the VZ ROM rnd() function requires that number to be in HL. You will see it also does not return the number it selects. This is because, again, the VZ ROM routines return the random number in the HL registers by default. How handy is that?? It sure saves a lot of mucking around. Since we only have one parameter for vz_getrnd() and return one, this is all we need. If you put a value in the HL registers this is returned to the calling function. To make it work with your C code using Z88DK you need to do a couple of things.
Add this function to the vz.h header. This is in include/arch/vz.h :
extern int __LIB__ vz_getrnd(int x);
This let’s you include it at the top of your code. #include <arch/vz.h>
It also defines the return value as an INTeger and the supplied value as INTeger, which is important.
Your Z80 Assembler code goes in z88dk/libsrc/target/vz/ eg. vz_getrnd.asm
You will also need to add the function to the vz200.lst file which is in z88dk/libsrc/target/vz/ eg:
target/vz/vz_getrnd
You also need to add it to vz_clib.lib which is your code compiled and ready to use in a library. To build the library, enter the z88dk/libsrc/ directory. Delete the existing file, make the new library and copy it to z88dk/lib/clibs/ I use this one-liner shortcut from the libsrc directory:
rm vz_clib.lib; make vz_clib.lib; cp vz_clib.lib ../lib/clibs/
Now I can immediately test the C code from SublimeText by using CTRL-B and ENTER to Build the code and CTRL-B, cursor-down to Run to launch the VZ200 VZEm emulator and load and run my code. You can create a SublimeText Build function to build then straight away RUN your new code in the emulator but I like to keep my functions separate.
There is one caveat and that is if your function requires more than one parameter. In which case you need your function.asm file and also a function_callee.asm file.
An example I have is the vz_poke(addr,n) function which just pokes a value into memory somewhere. Handy to use on the graphics MODE(1) screen when you make a game. Since this has two parameters you need the two files. You also need to handle the program stack yourself to make sure things are good to go when Z88DK returns from your function. The return address will be pushed onto the stack, then the second parameter will be pushed onto the stack, then the first parameter will be pushed onto the stack. Eg: vz_poke.asm
; ----- void __FASTCALL__ vz_poke(void *addr, char byte)
SECTION code_clib
PUBLIC vz_poke
PUBLIC _vz_poke
EXTERN vz_poke_callee
EXTERN asm_vz_poke
vz_poke:
_vz_poke:
pop af
pop bc
pop hl
push af
jp asm_vz_poke
And vz_poke_callee.asm :
; ----- void __CALLEE__ vz_poke_callee(void *addr, char byte)
SECTION code_clib
PUBLIC vz_poke_callee
PUBLIC _vz_poke_callee
EXTERN asm_vz_poke
vz_poke_callee:
_vz_poke_callee:
pop af
pop bc
pop hl
push af
; c = byte
; hl = addr
asm_vz_poke:
ld a,c
ld (hl),a
ret
You will see above the first thing I do is ‘pop af’. When this function is called the return address is pushed onto the stack. You need to pop this off the stack and store it safely. Next, I use ‘pop bc’. This will get the SECOND parameter. Lastly, ‘pop hl’ will take the FIRST parameter (the address to POKE the second parameter into). Lastly, I use ‘push af’ which puts the return address back onto the stack. Now, when the code hits ‘ret’ to return at the end, it goes back to the correct return address. Note that if you want to return any values, load them into HL before you use ret. You will still need to correctly define your function in vz.h but you will need to have 3 lines to define it. ie:
extern void __LIB__ vz_poke(void *addr, int byte) __smallc;
extern void __LIB__ vz_poke_callee(void *addr, int byte) __smallc __z88dk_callee;
#define vz_poke(a,b) vz_poke_callee(a,b)
Now when you build the clib file everything will link up correctly.
The handy thing about parameter values is they will go in the correct sized registers on return. So, an 8-bit (1 byte) or 16-bit (2 byte) value will go into HL and a 32-bit (4 byte) value will go into a combination as DEHL. Your code can ignore the higher byte register if you like, as I have done above where I copy the value in the C register into the Accumulator but ignore the value in the B register. You can read more about this on the Calling Conventions page on the Z88DK website.
Note that when you add your function and your _callee function you will have to add BOTH to vz200.lst :
target/vz/vz_poke
target/vz/vz_poke_callee
Otherwise the clib library will not build with both and you will get errors when you Build (compile).
One handy thing is in the meantime since I first posted on the Z88DK forum 20-odd years ago they’ve added a lot of support for the MC6847 graphics chip which happens to be in the VZ200 so you can use their already existing functions like:
int mode = 0;
console_ioctl(IOCTL_GENCON_SET_MODE, &mode); // Set MODE(1) graphics mode
textcolour(YELLOW); // Set drawing colour to Yellow
draw(5,5,50,50); // Draw a line from 5,5 to 50,50 in Yellow
You can see a bunch of their functions on the Classic Monochrome Graphics wiki page. Since the Z88DK guys already have a lot of this code it saves me the time, which I appreciate.
VZ200 & VZ300 – 8 bits of awesome!
Below is an article I wrote for The Retrogaming Times.
In the early eighties, Video Technology (aka VTech) created a popular little 8-bit computer. They named it the Laser 200 and sold it as a competitor to the ZX Spectrum. It was also known as the Texet TX8000 in Europe and the Salora Fellow in Finland. But to us Australians, it was known as the Dick Smith VZ-200. Dick Smith Electronics (DSE) was a tinkerer’s favourite place to get electronic components and various gadgets.
The computer was derived from the TRS-80 and most of the Assembly Language routines were exactly the same, although many had been moved up in memory. It featured Microsoft BASIC as a built-in language, but most games were developed in Assembly. A quirk occurred when the graphics in games were updated while the raster scan was in progress and this meant a glitching ‘snowy’ effect was often seen. The VZ-200 featured a Zilog Z80 microprocessor and originally 4kb of RAM. This was upgradable with a 16k expansion pack and, later, a 64k expansion pack. It could output two sets of four colours when in graphics MODE(1): green, blue, red and yellow or buff, cyan, magenta and orange. Most games used the former colour set as it was easier on the eyes.
VZ200 and VZ300 computers with datasette, disk drives, memory expansion, joysticks, cassettes and printer peripheral.

Later on, an updated version was released named Laser 310 aka VZ-300 with more memory and a real keyboard with plastic keys (as opposed to the VZ-200’s ZX-like rubber keys) and a full-length spacebar. Other peripherals available for these computers included a printer/plotter, floppy disk drive (capacity of 78kb per disk), joysticks and a light pen.
A few Extended BASIC applications were released, partially to ‘unlock’ the disabled TRS-80 features such as auto-line numbering, line renumbering, fast graphics routines and sound routines. The most popular would have been Russell Harrison’s Extended BASIC. An updated DOS firmware was released, also developed with Russell which allowed auto-starting of an application when the floppy disk was inserted and extra commands.
VZ200 (front) and VZ300 (back), Wordprocessor cartridge, Memory expansions, Joysticks, Printer interface, datasette.

A rudimentary Word Processor (Wordpro) could help you with your essays and letters and you could also purchase an Editor/Assembler program for developing your own applications. Keen developers created patches to update the “EDASM” to allow for disk functions which were not in the original program. A more functional Word Processor called Quickwrite was developed by Leslie Milburn. Several popular journals and fan magazines were created in Australia and New Zealand and many fun hours were spent at computer groups meeting other fans and sharing the excitement of our favourite 8-bit computer. A few magazines included: Hunter Valley VZ Journal, Le VZ OOP (Owners, Operators and Programmers), VeeZed Down Under and one I wrote myself and distributed on floppy disk called VZ Diskmag.
Hoppy (a Frogger clone)

Early games included a clone of Frogger called “Hoppy” and a clone of Space Invaders called “VZ Invaders.” Hoppy was a two-screen game as it was not easy to fit the full game screen on at once. I have many happy memories playing these games over and over. I waited patiently for the game to load from cassette in the DR20 cassette recorder. I also was quite fond of the Pac-Man clone “Ghost Hunter.” There was really only one level, although the ghosts did get faster as the levels progressed. Still, it was wonderful to be able to play my favourite arcade games at home.
VZInvaders (Space invaders) and Ghost Hunter (Pacman clone)

A lot of games were programmed by a developer duo called “Dubois and McNamara.” They also created a lot of games for the TRS-80. It’s possible the games were programmed first on another computer and then ported to the VZ-200. I have an interview with Greg Dubois on this website.
Later on, other fun games were released such as a very cool clone of Choplifter called “Dawn Patrol.” This version was programmed as a side-scroller. There weren’t very many side-scrollers released for the VZ-200 computer. I know of this one and “Defense Penetrator” which was a fantastic clone of Scramble by Tom Thiel. “Planet Patrol” (a clone of Moon Patrol) was sort of a side scroller, but not in the usual sense. “Galaxon” (a clone of Galaxian) was one game which really impressed me. The programming was tight, the sound effects delicious and it was incredibly fun to play. The fact that I was quite terrible at it did not deter me from hours upon hours of my teenage years lost to this game.
Dawn Patrol (Choplifter) and Galaxon (Galaxian clone)

Juergen Buchmueller joined the VZ Emu mailing list created by Eggy Lippman. He developed some drivers for the VZ-200 for MESS and released a set of libraries in Small C to assist in writing games. He left us with a lovely version of Defense Command which played beautifully and was very enjoyable.
Gaining some motivation from this game release and now having access to a very useful library of routines I was encouraged to make a game of my own. I’ve been a long-time fan of Arkanoid and so put myself to the test of creating a playable version on the VZ-200. It was developed in Small C and tested on Guy Thomason’s WinVZ emulator. I downloaded the original Arkanoid arcade game into an emulator and used an infinite lives cheat to see how each level was designed, then went about coming up with ways to do the same levels for my version I named “Arka Ball.” It was very satisfying to create a fun game for others to download and play. I added funky sound effects and even tried to mimic the level intro tune and game over tune. Whether I managed or not is a task for the players to decide.
Defense Command and Arkaball (Arkanoid clone)

There were many other games developed for the VZ-200 computers such as: VZ Panik (Panic clone), Ace of Aces, Ladder Challenge (Donkey Kong), Chess, Dig Out (Dig Dug), Hamburger Sam (BurgerTime), Kamakaze Invaders (Astro Invader), Lunar Lander (Moon Lander), Missile Attack (Missile Command), Penguin (Pengo), Super Snake (Snake), VZ Asteroids (Asteroids) and others.
You must be logged in to post a comment.