Write a CHIP-8 emulator lesson plan
Build the classic first emulator in C++ on an ESP32-C3 handheld: memory, fetch-decode-execute, XOR sprites, keys, timers and a debugger, ending with an original game in 151 bytes.
Objectives and materials
By the end, students can
- The machine's state, and the loop that runs it.
- XOR sprites, a keypad on six buttons, and two timers at 60 Hz.
- A debugger to find a wrong byte, then a whole game.
Materials for the whole unit
- ESP32-C3-DevKitM-1
- Full-size breadboard
- Game console buttons
- Piezo speaker
- TFT display, 240x320
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
The processor
The machine's state, and the loop that runs it.
| Lesson | Time | What students do |
|---|---|---|
| The machineCHIP-8 is a computer that was only ever software. Build its 4 KB of memory, sixteen registers, program counter and font, load a ROM at 0x200, and read it back byte by byte. | 55 min |
|
| Fetch, decode, executeThe loop inside every processor: read two bytes at PC, cut them into nibbles, do what they say. Watch a countdown ROM run line by line, hit an instruction the emulator does not know, and teach it. | 55 min |
|
Materials
- ESP32-C3-DevKitM-1
- Full-size breadboard
- Game console buttons
- Piezo speaker
- TFT display, 240x320
Check for understanding
Each student finishes "Fetch, decode, execute" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Edit the ROM".
Screen, keys and sound
XOR sprites, a keypad on six buttons, and two timers at 60 Hz.
| Lesson | Time | What students do |
|---|---|---|
| DisplayDXYN, the one drawing instruction: 8-pixel sprites from memory, drawn by XOR, with collisions in VF. Draw a rocket, erase it by drawing it again, label it with the font, and count the pixels. | 55 min |
|
| KeypadSixteen CHIP-8 keys on a six-button pad: read the buttons each frame, spot new presses, and run the three key instructions, including FX0A, which stops the program until you press something. | 45 min |
|
| Timers and soundTwo timers that tick at 60 Hz: measure the delay timer to the millisecond, make the buzzer follow the sound timer, and edit the ROM for a longer beep. | 45 min |
|
Materials
- ESP32-C3-DevKitM-1
- Full-size breadboard
- Game console buttons
- Piezo speaker
- TFT display, 240x320
Check for understanding
Each student finishes "Timers and sound" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A longer beep".
Debug and play
A debugger to find a wrong byte, then a whole game.
| Lesson | Time | What students do |
|---|---|---|
| Debugging ROMsA ROM should write 600D and writes BAD. Drive the built-in debugger from the serial monitor: step, disassemble, set a breakpoint, read the registers, find the wrong byte and fix it. | 55 min |
|
| Boss: play a gameThe finished emulator runs Space Dodge, an original CHIP-8 game in 151 bytes: steer with the pad, dodge rocks, hear the beeps, and tune the game by editing its machine code. | 55 min |
|
Materials
- ESP32-C3-DevKitM-1
- Full-size breadboard
- Game console buttons
- Piezo speaker
- TFT display, 240x320
Check for understanding
Each student finishes "Boss: play a game" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Play, then share".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.