I’ve been wanting to write a Z-machine interpreter and wanted to get the community’s advice on the best process to follow.
I’m a programmer by trade but haven’t written any sort of interpreter or emulator before. I have a conceptual understanding of how CPUs work and interact with memory and I/O, but no hands-on experience implementing a virtual one.
So far I’ve been following two documents:
- The official spec which I find quite terse and disjointed (but that’s probably due to my lack of experience in this area). I suppose it’s a good reference when you have specific questions, but as someone trying to understand the big picture it feels overwhelming.
- The Z-machine, And How To Emulate It – a PDF much heavier in prose but dives into the high level concepts of the Z-machine. This document was published in 1996 whereas the spec was updated in 2014, so I’m unsure if I’d be missing anything critical by following this guide.
My current strategy has been to build out specific functions of the interpreter. For instance, I’ve implemented functions to decode a Z-string into printable chars given an arbitrary memory address, and I was going to move onto user input encoding next. While I’m happy with this progress, it feels like I’m not seeing the forest for the trees.
I wonder if it’s more prudent to start by writing a skeleton; say the main loop to fetch and decode opcodes from memory, and then implement the functions necessary to process each opcode as I encounter them?
Thanks in advance!