I was toying around with Udo Munk’s z80pack emulator suite recently. It not only brings a ready-to-run IMSAI and Altair emulation - including working frint panels in X11! - but alaso a really bare-bone z80 ismulator, starting up in a pretty simple Machine code Monitor.

So when starting up z80sim just like that, you’re presented with the following screen:

$ ./z80sim 

#######  #####    ###            #####    ###   #     #
     #  #     #  #   #          #     #    #    ##   ##
    #   #     # #     #         #          #    # # # #
   #     #####  #     #  #####   #####     #    #  #  #
  #     #     # #     #               #    #    #     #
 #      #     #  #   #          #     #    #    #     #
#######  #####    ###            #####    ###   #     #

Release 1.37, Copyright (C) 1987-2021 by Udo Munk

CPU speed is unlimited, CPU executes undocumented instructions
>>> 

So, what can we do here? Inspect registers…

>>> x

PC   A  SZHPNC I  IFF BC   DE   HL   A'F' B'C' D'E' H'L' IX   IY   SP
0000 5b 111100 00 00  baf6 d10a fc24 a8ec cc25 f894 deb1 4342 9b59 23c6

Fill memory with nulls & dump memory…

>>> d0
Adr    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f  ASCII
0000 - d4 45 0c 2e 0a ba 1d e4 7c e5 f4 4d e7 f5 0a 71 	.E......|..M...q
0010 - 80 37 30 34 9a 01 d9 ef 0b d0 35 c3 ff f3 ef d3 	.704......5.....
...
>>> f 0,ffff,0
>>> d0
Adr    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f  ASCII
0000 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 	................
0010 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 	................

Read intel-hex-file formatted binaries & run them…

>>> r /home/alex/Projects/asm/z80/loop.hex
Loader statistics for file /home/alex/Projects/asm/z80/loop.hex:
START : 0000H
END   : 000DH
LOADED: 000EH (14)

>>> g0
0123456789HALT Op-Code reached at 000d

PC   A  SZHPNC I  IFF BC   DE   HL   A'F' B'C' D'E' H'L' IX   IY   SP
000e 3a 010010 00 00  bd8a 8b2d beb4 d12f a455 0af7 45b7 fbbe ef2c 8002

Disassemble my sloppy code:

>>> l0
0000 - LD	A,30
0002 - CP	3A
0004 - JP	Z,000D
0007 - OUT	(01),A
0009 - INC	A
000a - JP	0002
000d - HALT
000e - NOP
000f - NOP
0010 - NOP

Fun! However, while you can tell “save a memory dump and CPU-state when shutting down” or “read a memory dump & CPU-state at start up”, you can’t read a core file at runtime, so I created a simple patch which applies just happily against the version in HEAD at the time of this writing.

No, I didn’t write the code myself, I simply grabbed it from z80sim/srcsim/sim0.c and included it in simctl.c so that you can pull it up from the monitor menu.

When I find the time, I’m gonna add the reverse “read core from file” operation.

In the meantime, have fun - also, a nice link to get into z80 assembly, this Z80 Opcode Table is nice, though I’d prefer a manual page. I’m a sucker for manual pages. Maybe I even make one.