Woz Monitor Deep Analysis

Under the Bonnet: A Closer Look at the Woz Monitor

Steve Wozniak's ingenious design of the Woz Monitor is a testament to the art of efficient programming in the face of severe memory constraints. Let's delve into the intricacies and compromises that made this 256-byte wonder possible.

1. Uninitialized Stack Pointer

The stack pointer is not initialized, allowing the stack to float anywhere in page $01. This saves bytes but requires caution when using page $01 for code.

; No explicit stack pointer initialization

2. Clever PIA Initialization

Wozniak exploits the PIA's post-reset state to initialize it without explicitly selecting DDR registers, saving precious bytes.

LDY #%0111.1111 ; Mask for DSP data direction reg STY DSP ; (DDR mode is assumed after reset) LDA #%1010.0111 ; KBD and DSP control register mask STA KBDCR ; Enable interrupts, set CA1, CB1 for STA DSPCR ; positive edge sense/output mode.

3. Limited Character Set

Only uppercase ASCII is supported, with bit 7 always set, diverging from standard ASCII but saving on comparison logic.

4. Minimal Error Handling

Errors simply reset the input buffer and print a backslash, eschewing detailed error messages to save space.

ESCAPE LDA #PROMPT ; Print prompt character JSR ECHO ; Output it.

5. Top-Down Programming

The code is structured top-down, optimizing for execution but potentially sacrificing readability.

6. Register Value Recycling

Results from one operation are cleverly reused in unrelated parts of the code, saving initialization bytes but increasing code interdependency.

7. Simplified Input Parsing

Characters below ASCII '.' are treated as blanks, allowing for flexible but potentially error-prone input.

NEXTITEM LDA IN,Y ; Get character CMP #"." BCC BLSKIP ; Ignore everything below "."!

8. Interrupt Handling

NMI and IRQ vectors are set but not used, saving space while allowing for future expansion.

NMI_VEC .DA $0F00 ; NMI vector IRQ_VEC .DA $0000 ; IRQ vector

The Byte-Saving Challenge

Despite these compromises, Wozniak's code is a masterpiece of efficiency, using only 254 of the available 256 bytes. This leaves 2 bytes free, a remarkable achievement given the monitor's functionality.

Bytes Used: 254/256