How Wozniak’s code for the Apple 1 works

Ben Eater37 minutes read

The text examines the original Apple ROM monitor code by Steve Wozniak running on a 6502 breadboard computer, discussing the code's optimization, user input processing, and parsing of hex digits. Wozniak's unique optimization methods are highlighted, focusing on efficient code assembly and memory usage, with details on how the code manipulates characters and stores values in memory locations.

Insights

  • The Apple ROM monitor code by Steve Wozniak on a 6502 breadboard computer is meticulously optimized for efficiency and size due to limited memory space, utilizing unique methods like converting characters to hex digits and manipulating them using XOR operations.
  • The code intricately handles user input processing, storing key presses in a text buffer, parsing hex digits, and executing functions like block examine mode and value storage with precise control over memory addresses and efficient subroutine usage for printing and interfacing.

Get key ideas from YouTube videos. It’s free

Recent questions

  • How does the Apple ROM monitor code optimize memory space?

    By utilizing page 0 variables and efficient assembly.

  • What is the purpose of the X register in the Apple ROM monitor code?

    Initialized to zero for processing efficiency.

  • How does the Apple ROM monitor code handle user input commands?

    Detects keyboard key presses and processes input.

  • What is the significance of the code manipulation with b0 hex in the Apple ROM monitor code?

    Manipulates characters during parsing.

  • How does the Apple ROM monitor code handle the printing of data?

    Utilizes subroutines for efficient byte printing.

Related videos

Summary

00:00

"Steve Wozniak's Apple ROM Monitor Code"

  • Original Apple ROM monitor code by Steve Wozniak running on a 6502 breadboard computer.
  • Interest in understanding the details of how the code works.
  • Code includes identifier names referring to memory addresses for variables or hardware I/O.
  • Variables stored in memory at the beginning, with page 0 variables defined for efficient code assembly.
  • Code optimization for size and speed due to limited memory space.
  • Code meant to be in raw MID address ff00, with the 6502 starting execution at fffc upon reset.
  • Initial code section sets up display and keyboard hardware.
  • User input command code section explained, starting with keyboard key press detection.
  • Key press stored in a text buffer for user input processing.
  • Code complexity and efficiency discussed, highlighting the unique optimization methods used by Wozniak.

13:52

"Hex Digit Parsing and Accumulation Process"

  • The X register is initialized to zero at the start.
  • The L and H variables are set to zero initially.
  • The current value of the Y register is saved in the Y save variable.
  • The code converts characters being parsed into hex digits.
  • The code XORs with b0 hex to manipulate the characters.
  • It checks if the character is a digit or not.
  • If the character is not a digit, it adds with carry 88 to map characters a-f into hex values.
  • The code shifts and rotates bits to accumulate the 16-bit hex number.
  • The process loops four times to shift bits into the H and L bytes.
  • The code continues parsing hex digits until a non-hex character is encountered.

28:13

Parsing and Storing Hex Values in Memory

  • In Block examine mode, the system parses hex digits until encountering a non-hex character, switching to not hex mode, then compares exam L and exam H to l and H before continuing parsing.
  • Upon reaching a dot, the mode switches to block examine, parsing a hex address and incrementing exam L, checking if it's a multiple of eight to print a carriage return and address.
  • Storing a value involves parsing a hex value, switching to store mode at a colon, loading the value into the a register, and storing it at the address pointed to by store L and store H.
  • Multiple values can be stored in subsequent memory locations by incrementing the store address after each value is stored.
  • The printing code includes a subroutine for printing a byte by printing the hex characters of the byte's high and low nibbles, cleverly using one return statement for multiple functions.
  • The system also includes subroutines for printing a hex character and echoing the byte in the a register, adapting the code for a serial interface is necessary for display.
Channel avatarChannel avatarChannel avatarChannel avatarChannel avatar

Try it yourself — It’s free.