WOZMON, Eight CPUs, and a Paper Tape
By Michael Doornbos
- 7 minutes read - 1305 wordsCROSSWOZ is an emulator I’ve been writing for the past couple of months. It runs eight different CPUs from the 1970s and early 1980s on a shared 64K of memory, with an Apple-1 WOZMON-style monitor on the front and a paper-tape station for I/O. It’s live in the browser at /crosswoz/live/, and the rest of this post will make more sense if you have that tab open.
The page boots into a 6502. The register window in the top left has A, X, Y, the program counter, and the flags. Underneath it is the live disassembly, with a small arrow pointing at the instruction about to execute. The stack and a memory pane sit on the right, and the command prompt runs across the bottom. A short example program is pre-loaded at $0300 that adds two numbers and stores the result, so typing R actually does something. The registers flash yellow whenever they change, which was the first thing I built into the TUI, because none of the rest of it is interesting without it.
The examine syntax is straight off the Apple-1. Typing 0300 dumps the bytes starting at $0300. 0300.0320 shows the range from $0300 through $0320. Writing bytes looks like 0300: A9 42 8D 00 02 00, which puts LDA #$42; STA $0200; BRK into RAM at $0300. D 0300 disassembles back so you can confirm the bytes mean what you thought they meant. R runs from the reset vector. S single-steps, which is where I spend most of my time when something is broken.
If you don’t want to hand-assemble opcodes by hex (it is fun, but), you can type A 0300 and drop into the mini-assembler. It’s KIM-1 style and runs one instruction per line. Type LDA #$42, hit enter, and it tells you the bytes it wrote and the next address. A blank line exits. Each CPU has its own assembler that knows its own mnemonics, so switching to a different chip changes the syntax, too. LD A,(HL) is a valid Z80 input and would be a syntax error on the 6502.
WOZMON
The WOZ in CROSSWOZ is for Steve Wozniak’s monitor on the Apple-1, which was the machine’s entire firmware. WOZMON is 256 bytes of 6502 code, hand-rolled to fit on a single 256-byte ROM chip, and somehow contained everything a person could do on an Apple-1 before booting BASIC off the cassette interface. You typed XXXX to look at a byte, XXXX.YYYY for a range, XXXX: aa bb cc to write bytes, and R to run from the last address you examined. That was it. Four primitives.
CROSSWOZ stays close to the original. The examine and write syntax is intact. R runs from the reset vector instead of the last-examined address, because every CPU CROSSWOZ supports has a real reset vector in a way the Apple-1 didn’t quite have. D (disassemble) and S (single-step) are additions, since those are the things you actually want when you’re trying to figure out why your code is doing something it shouldn’t. If you’ve never read the WOZMON source listing, the whole thing is about a page long and very much worth twenty minutes. It’s the kind of code that makes you want to write less code.
Swap the CPU
Typing cpu z80 swaps in a Z80 in place of the 6502. The bytes you wrote at $0200 are still where you left them. The Z80 can read them, write back into the same address space, and when you switch back to the 6502 the changes are sitting in memory waiting for the 6502 to find them. The 64K is the 64K. Only the chip looking at it is different.
The eight CPUs are:
- 6502 (Apple-1, Commodore, most of the 1970s)
- 65C02 (Apple IIc and IIe Enhanced)
- Z80 (CP/M, ZX Spectrum, MSX, Game Boy)
- 8080 and 8085 (Altair 8800, the SDK-85 trainer)
- 6809 (TRS-80 CoCo, Vectrex)
- 1802 (COSMAC ELF, and also Voyager 1 and 2, Galileo, and Magellan, which I think about a lot)
- TMS9900 (TI-99/4A, 1979). The only 16-bit chip in the bunch, with the famous TI architectural quirk where the “registers” are actually consecutive words of RAM pointed at by the workspace pointer. Context switching is just changing one word.
This shared-bus idea is borrowed from the Cerberus 2080 and from Grant Searle’s Multicomp. They both run a Z80 and a 6502 against the same RAM with a control that decides which CPU is driving. I bought a Cerberus a couple of years ago, and writing a Z80 program that reads the bytes the 6502 left behind has been one of those ideas I keep coming back to.
The paper tape
There’s a paper tape station built into the monitor. PUNCH 0300.030F writes those sixteen bytes to tape and animates the hole pattern across the screen as the bytes go by. It runs at 8 bytes per second, which is slow on purpose. Speeding it up would turn the paper tape into a file transfer.
READ plays the tape back into memory at whatever address you give it. You can punch the output of a 6502 program, switch to the 8080, read the tape into some other region of RAM, and now the 8080 has the bytes without you having to think about shared addresses at all. It’s the only I/O CROSSWOZ has so far, and I keep finding excuses to add to it.
Single-board computers worth knowing about
The Apple-1 belongs to a small group of single-board computers that were sold as hobby kits in the mid-1970s, before consumer microcomputers like the Apple II and the C64 made everything weirder. The common features were a 6502 or 8080-class CPU, a few hundred bytes to a few kilobytes of RAM, a monitor program that fit in 1K or 2K of ROM, and almost no I/O beyond a hex keypad or a serial terminal. They are the right place to learn what a CPU actually does, because the abstraction layer between you and the chip is, deliberately, a few hundred bytes thick.
Worth your attention:
- KIM-1 (MOS Technology, 1976). Six 7-segment digits, a 23-key hex keypad, 1K of RAM, and a monitor in 2K of ROM. The reason “type in machine code” is even possible as a phrase. Original units are expensive on eBay, but the modern PAL-II clone is a pleasant way to actually use one. I wrote about running 10 PRINT on the PAL-II last year.
- COSMAC ELF (Popular Electronics, 1976). The 1802 board you built yourself from a magazine article. Toggle switches, two hex digits of display, and the same chip family that’s still flying on Voyager.
- Apple-1 (Apple Computer, 1976). The one Woz designed. Original boards turn up at auction for six figures, but several Apple-1 reproduction kits are still in production and include WOZMON and Apple BASIC in ROM.
- Multicomp (Grant Searle). Not a board in the original 1970s sense (it’s an FPGA design) but the spiritual modern descendant, with a 6502, Z80, 6800, and 6809 selectable from a single board.
- Cerberus 2080 (Bernardo Kastrup). The Z80 and 6502 share 64K of SRAM, with a custom BIOS that decides which CPU is active. The hardware version of what CROSSWOZ is doing in software.
If you’ve never built one of these and want to start, the PAL-II ships in a single box, takes a couple of hours to solder, and drops you straight into a hex monitor with the same paper-tape semantics CROSSWOZ has. That’s the territory this project is trying to live inside.
Go open the live one and try writing something for the 1802. I’d be curious to know how anyone gets along with sixteen 16-bit registers and no real stack.
There’s also a full manual with every monitor command, the mini-assembler syntax for each CPU, the paper tape formats, and a per-CPU walkthrough.