Level 23: Gamepad
Task
Write a program that reads the gamepad (port 254) and stores the value in RAM[0].
The Gamepad is connected to the data bus and accessible via port 254 (0xFE).
Solution
Key distinction: - LDA N loads the IMMEDIATE value N (a number). - ADD N reads data FROM ADDRESS N on the bus and adds it to the accumulator.
To read the gamepad: 1. LDA 0 — clear the accumulator (Acc = 0) 2. ADD 254 — Acc = 0 + gamepad = button state 3. STA 0 — store in RAM[0] 4. HLT
Gamepad buttons (bits): - Bit 0 (1): Up - Bit 1 (2): Down - Bit 2 (4): Left - Bit 3 (8): Right
The checkpoint sets buttons = 5 (Up + Left) and checks RAM[0] = 5.
Click "Run", then "Checkpoint".