Retro Z80: The Z88dk

After spending time in the hardware I recently focused on the software. If I have to write all the software in assembler, I will be busy for a long time and debugging till the cows come home.

There is this development kit for the Z80 that allows you to write C and will produce Z80 machine code; its called the Z88dk.

This development kit has default support for all kinds of old retro machines – my personal favorite the ZX Spectrum. The Z88dk calls these targets. When you compile your C code you specify the target machine you wish to run the code on.

But because I am making my own hardware I also need to create my own target. And that is where it gets hairy. The structure of the Z88dk is pretty complex because of its flexibility to service so many targets. That means that each target has to implement interaction with the hardware for standard C-RunTime (CRT) IO functions (stdio.h), like stdin, stdout and stderr streams. Each target can also specify what C libraries are available to the programmer. A target could replace a default implementation for something specific, restrict access to certain functions and add additional libraries to be used. Then I am not even talking about the fact that there are two sets of these libraries and two different C compilers as well. It is a good thing that these are pretty transparent to the target author.

The Z88dk uses .m4 files to generate code for targets. The m4.exe is a (pre)processing program that interprets the text of an .m4 file, executes its macro’s and spits out the result in another file. The Z88dk uses this to setup the CRT startup code and to statically define the stdio streams.

I won’t go into the details here, but needless to say, it takes a while before I was able to wrap my head around how it all worked (and why). If you want to know more details, this page is the place to go. It describes in some detail the steps involved. Also check out the Z88dk forum for it contains several discussions on the subject of creating your own target (including mine).

It took me several days to get comfortable with Z88dk target setup and I have gotten to a point where a C-program compiles into a Z80 machine code binary file. However, when I let the program run, it (still) does not work when I use printf – that uses stdout – that is defined in my target. Simpler programs seem to run fine (not using my target custom code). So I still have some work in front of me.



Published in: on April 9, 2016 at 11:33 am  Leave a Comment  
Tags: ,

The URI to TrackBack this entry is:

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: