Lesson plan

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.

3 chapters, 7 lessons, about 6 hours, on the ESP32-C3-DevKitM-1. Every lesson runs in the browser, with nothing to install.

The unit

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.

Chapter 1. About 1 h 50 min

The processor

The machine's state, and the loop that runs it.

LessonTimeWhat 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
  1. A computer that never existed
  2. Memory is a row of bytes
  3. The registers
  4. The font in memory
  5. Find a letter yourself
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
  1. Fetch
  2. Decode
  3. An instruction it does not know
  4. Teach it 7XNN
  5. Edit the ROM

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".

Chapter 2. About 2 h 25 min

Screen, keys and sound

XOR sprites, a keypad on six buttons, and two timers at 60 Hz.

LessonTimeWhat 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
  1. One instruction draws everything
  2. XOR, and the flag
  3. Labels from the font
  4. Count the pixels
  5. Give it a bigger flame
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
  1. Waiting for a key
  2. Press A
  3. Press left
  4. Map B to F
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
  1. Sixty ticks a second
  2. The sound timer
  3. Make it beep
  4. A longer beep

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".

Chapter 3. About 1 h 50 min

Debug and play

A debugger to find a wrong byte, then a whole game.

LessonTimeWhat 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
  1. It writes BAD
  2. Step and disassemble
  3. Set a breakpoint
  4. Read the registers
  5. Fix the byte
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
  1. Space Dodge
  2. Dodge one
  3. Crash into it
  4. Make the rocks faster
  5. Play, then share

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".

Your class

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.