My previous post on the subject of building a Z80-based computer briefly explained my motivation, and the approach I was going to take.
This post describes my progress so far:
- On the hardware side, zero progress.
- On the software-side, lots of fun.
To recap I expect to wire a Z80 microprocessor to an Arduino (mega). The arduino will generate a clock-signal which will make the processor "tick". It will also react to read/write attempts that the processor makes to access RAM, and I/O devices.
The Z80 has a neat system for requesting I/O, via the use of the IN and OUT instructions which allow the processor to read/write a single byte to one of 255 connected devices.
With the appropriate tools available I could write some simple code. I implemented two I/O routines in the emulator, one to read a character from STDIN, and one to write to STDOUT:
IN A, (1) ; Read a character from STDIN, store in A-register. OUT (1), A ; Write the character in A-register to STDOUT
With those primitives implemented I wrote a simple script:
; Simple program to upper-case a string
; show a prompt.
ld a, '>'
out (1), a
; read a character
jp z, quit
; is it lower-case? If not just output it
jp nc, output
; convert from lower-case to upper-case. yeah. math.
sub a, 32
; output the character
out (1), a
; repeat forever.
With that written it could be compiled:
$ z80asm ./sample.z80 -o ./sample.bin
Then I could execute it:
$ echo "Hello, world" | ./z80emulator ./sample.bin Testing "./sample.bin"... >HELLO, WORLD 1150 cycle(s) emulated.
And that's where I'll leave it for now. When I have the real hardware I'll hookup some fake-RAM containing this program, and code a similar I/O handler to allow reading/writing to the arduino's serial-console. That will allow the same code to run, unchanged. That'd be nice.
I've got a simple Z80-manager written, but since I don't have the chips yet I can only compile-test it. We'll see how well I did soon enough.