Retro Z80: CPU Board

Hardware

I have been busy with designing a PCB for the Z80 CPU. This CPU Board has 4x 64k (x8 bits)  static RAM on board next to the Z80. It also has an additional 32k of RAM that serves as a Memory Management Unit (MMU) for deciding which 4k blocks of the 4 banks of 64k are in the active 64k range and where.

Here is the board as it arrived today. I had it made in China with Elecrow (found through pcb-shopper) and they did an excellent job for a small price tag.

WP_20160417_12_40_11_Pro

There are two 40 pin headers on each side of the board that runs bus signals to the other boards that are yet to be designed. The idea is that a stack of these 10cm x 10cm boards all connected to the common bus, makes a complete computer system.

Next up is the decoder board that decodes all the control signals from the common bus feeds them back to the CPU-board – thats the connector on the top-right side. The decoder board contains an Altera Max II (240) with a load of passives (clamp diodes, pull-up and series resistors) to adapt the 3.3V CPLD to the 5V bus. I am designing that now. I have waited until I got my CPU board back. If there is any (stupid) mistakes in the CPU-board, I can correct them (or learn from them) in the decoder board. All these boards will have the 4 mounting holes in each corner and the two bus connectors (as well as the power supply connector in the top right).

The only downside…. I have 12 of them (I ordered 10)…

Software

I have also been busy with the software. I have created a custom target for the z88dk. It was quite a tedious process because my test setup had a couple of hardware bugs (wiring faults). These errors caused the system to run ok on small programs but hang on larger programs. So always check your wiring twice!

Once I had the hardware sorted, the software started to work pretty quickly. A z88dk target consists of startup code to connect the C program with its execution environment (the computer). This can optionally contain a bios at address $0000 which I used to test with. I only coded the entry points for the RST instructions and NMI interrupt so I could catch those if they happened. The z88dk uses drivers to connect the C-porgram to things like the stdin and stdout streams (although in C this structure is called FILE – talk about a bad name). If you recall I had the basic input and output working on the System Contoller so I implementing these drivers for basic IO was dead-easy.

The complexity (at first) in creating a z88dk target lies in the structure, organization and mechanisms used in the z88dk. Thankfully they have a forum and you receive very elaborate answers on your questions – excellent support.

I added two commands for the System Controller. A Memory Fill (mf) that allows you to initialize a part of the RAM memory. This has been useful to ensure you start with a clean slate for each test run. I also added a Terminal Off command (to) that makes the System Controller ignore the incoming serial data. It just keeps it in its buffer and now the Z80 can use the input instruction to retrieve the characters.

Next Steps

Next I will finish designing the decoder board and get started with advancing the bios for the system as well as the C integration. There are a couple of more drivers I need to look at in detail.

I will also start to think on how I wish to manage those 4 banks of 64k of RAM memory. The z88dk C compiler supports a 24 bit far memory model but I cannot see (yet) how to map that to my MMU mechanism of 4k blocks that can be swapped and positioned anywhere…

Advertisements
Published in: on April 17, 2016 at 1:13 pm  Leave a Comment  

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: ,