Z80 Project

Nathan's Z80 Project Mark 2: An actual Z80!!

Last updated: Dec. 6, 2009, 6:20 p.m.

At long last I've fitted a Z80 into the Z80 computer. I know shocking isn't it. After months of tinkering with it and fiddling with things using the on-board PIC I finally got the boot code sorted out and the clock generation (in the new file called boot.asm). After some serious head scratching about why id didn't work, I got it all running smoothly and counting on the debug port LEDs.

New Code I've added the boot.asm file which contains the code to copy the top 8K of flash from the PIC into the system memory starting at address 0. This, along with the rest of the boot setup happens faster than you can see so it looks like the system is booting straight from ROM. The clock generation is also in the new code, I've used one of the PWM peripherals in the PIC to generate a 50% duty ratio square wave at a software selectable rate. At the moment it's hard coded into the PIC assembly code, and it's only running at 250kHz because my scope is pretty slow and I was having trouble debugging it at higher speeds. The target clock speeds are 2.5MHz, 3.33MHz or 5MHz if it's still stable at that speed, although my Z80 is only rated at 4MHz. These speeds are fractions of the 10MHz input crystal on the PIC. I could get it running at 4MHz if I replaced the PIC's crystal with an 8 MHz one.

I found one significant bug in my code when trying to get the Z80 working. The PIC was driving the system bus while it was supposedly in slave mode. After a heap of poking around the system I realised it was because I'd never set Port A and E to digital pins. There's two extra lines in main.asm now that set ADCON1 so that all pins are treated as digital.

Makefile-fu There is some fairly crazy makefile work going on now to automate the build. I've written a python script that generates an assembly code file for the PIC that contains data statements with the appropriate static data definitions for the Z80 boot ROM. The python script reads a binary image that is output by z80asm from a z80 assembly code file called bios.asm. The make file now calls z80asm to build the latest bios version, the python script bin2asm to generate a PIC asm wrapper around the compiled BIOS, then compiles the rom.asm file along with the rest of the PIC assembly code to generate a hex file for programming the PIC.

Stuff to test I've not thoroughly tested the DMA mode stealing the bus while the Z80 is running, and I haven't yet added the PIC code to update the BIOS image through the serial port without having to re-program the PIC.

Next things to do Next I plan to get the Z80 writing data out of the serial port to make sure this is working, then the RTC module. Once these are working a basic POST diagnostic then booting from the SD card which I have yet to wire in.

Z80 Project
Z80 Mark 2,
Z80 homebrew


Posting comments is not currently possible. If you want to discuss this article you can reach me on twitter or via email.


Email: nathan@nathandumont.com

Twitter: @hairymnstr