Classroom Public page

Week 1: What is an Emulator?

1,403 words

The setup week. Install Mesen, run a homebrew NES game, understand the difference between emulator and hardware. You start the week curious; you end the week with software you built familiarity with running real ROMs on your laptop.


Theme

An emulator is a program that pretends to be another computer. When you run an NES game on your laptop using Mesen, Mesen is reading the bytes of the game cartridge file (the ROM) and faithfully simulating what an actual Nintendo Entertainment System would do with those bytes: drawing the pixels, playing the sounds, watching for button presses, advancing the game's clock 60 times a second.

This week you install three free emulators (Mesen for NES, SameBoy for Game Boy, bsnes-plus for SNES, you will use the latter two in week 5). You download a homebrew ROM (a game written by a hobbyist and shared freely online) and run it. By the end of the week you can boot a ROM, take a screenshot, and explain in plain English what just happened when you double-clicked the file.

This is the foundation. Every subsequent week assumes you know how to load a ROM into an emulator and observe what happens.

Reading list (~45 minutes)

  1. NESdev wiki: "Cartridge connector" at wiki.nesdev.org/w/index.php/Cartridge_connector, a brief tour of what an NES cartridge actually contains and how it talks to the console.
  2. NESdev wiki: "INES file format" at wiki.nesdev.org/w/index.php/INES, the file format that ROM dumps use. You will hex-view this in week 2; reading the overview first prepares you.
  3. Mesen documentation: "Getting Started" at mesen.ca/docs, the practitioner overview of the emulator you are installing this week.

Lecture outline (~1.5 hours)

Section 1: What is a video game cartridge, actually?

  • A cartridge is a plastic case around a circuit board
  • The circuit board carries a ROM chip (read-only memory) and sometimes a few other parts
  • The ROM chip stores the bytes of the game: the code that runs, the graphics, the sounds, the level data
  • The console reads bytes out of the ROM as the game plays
  • A "ROM dump" is a file containing the bytes from a real cartridge's ROM chip, captured by a hardware tool called a cartridge reader

Section 2: What is an emulator, actually?

  • An emulator is a program that simulates the console
  • Mesen simulates the 6502 CPU that the NES used
  • It simulates the Picture Processing Unit (PPU) that drew the graphics
  • It simulates the Audio Processing Unit (APU) that played the sounds
  • It simulates the cartridge slot, the controllers, even the TV display
  • When you load a ROM file into Mesen, the emulator pretends to be a real NES that has that cartridge plugged in
  • The emulator runs at the same speed the real hardware did (60 frames per second on NTSC)

Section 3: Why does this work?

  • Emulation works because computers can simulate other computers
  • The simulator does not need to be the same kind of computer as the simulated one
  • Your laptop has a CPU that is thousands of times faster than the 6502; this means it can simulate a 6502 (and a PPU, and an APU, and a cartridge slot) with cycles to spare
  • The simulation is faithful enough that real NES games run correctly inside Mesen
  • This is the same idea that makes virtual machines work for modern computing: one computer pretending to be another

Section 4: What is a ROM hack?

  • A ROM hack is a modified version of a ROM file
  • A hacker changes some of the bytes of the ROM, then loads the modified ROM into the emulator
  • The emulator does not know or care that the ROM is modified; it just runs whatever bytes it is given
  • This is how people have modified classic games for decades: change the byte that says "your character's hat is red," to a byte that says "your character's hat is blue"
  • In week 4 you make your own ROM hack. This week you learn the foundation: how to run an unmodified ROM faithfully

Section 5: Legal vs illegal ROMs

  • It is legal to dump a ROM from a cartridge you own. The legal status of distributing dumps you did not make yourself varies by country and by what game; if you do not own the cartridge, do not download the ROM.
  • It is legal to download and modify open-source homebrew ROMs released by their creators under a permissive license. We will use homebrew ROMs throughout this course.
  • Examples of legal homebrew ROMs you can download right now: most of the NESdev competition entries on the NESdev wiki; many entries on itch.io under "NES homebrew"; the Roth Brothers homebrew compilation.
  • We do NOT download commercial-game ROMs in this course. The academy's commitment is that everything you do in SPK-101 is unambiguously legal, regardless of where you live.

Labs (~4 hours)

Two labs this week.

Lab 1.1: Install Mesen and run your first ROM (labs/lab-1-1-install-mesen.md)

  • Goal: Mesen is installed, a homebrew ROM is downloaded, and you have it running with sound and graphics
  • Time: ~90 minutes including download and any troubleshooting
  • Artifact: a screenshot of the homebrew ROM running, plus the file path of the ROM on your laptop

Lab 1.2: Tour the Mesen interface (labs/lab-1-2-mesen-tour.md)

  • Goal: You can pause, reset, save state, load state, take a screenshot, change controller mappings, and find the debugger menu (you will use the debugger in week 3)
  • Time: ~90 minutes
  • Artifact: a short reflection note (~150 words) in your lab journal explaining what each menu does

Independent practice (~2.5 hours)

Free exploration with the emulator. Recommended exploration paths (pick any one or two):

  1. Play with controller mappings. Try the keyboard-default mapping, then try plugging in a USB game controller (an Xbox or PlayStation controller works on Windows / macOS / Linux). See if the game feels different with a real controller.
  2. Try save states. Pick a hard moment in your homebrew ROM. Make a save state right before the hard moment. Try the moment over and over loading the save state each time. Notice how this lets you experiment with strategies you would not try without save states.
  3. Find another homebrew ROM and try it. The NESdev wiki has a "Game development competition" section; many entries are free downloads. Try one or two.
  4. Read the Mesen menus you have not opened yet. What does "Video options" do? What does "Audio mixer" do? Open them. Change a setting. Change it back.

Reflection prompts (~30 minutes)

Journal these at week's end. There are no wrong answers; the journal is for your own learning, not for grading.

  1. Before this week, what did you think an emulator was? After this week, has your understanding changed?
  2. The lecture mentioned that an emulator simulates the CPU, the PPU, the APU, and the cartridge slot. Which of these did you find easiest to understand? Which was hardest?
  3. You ran a ROM file this week. The ROM is a sequence of bytes. The emulator turns those bytes into pictures and sounds. Roughly, what do you think the emulator is doing during the gap between the bytes-on-disk and the pixels-on-screen?
  4. The course asks you to use legal ROMs only. Why do you think the academy cares about this?
  5. What is one question you have after this week that you hope week 2 will answer?

Visual Helpers

This week introduces the idea that a ROM is a sequence of bytes. Bytes, addresses, and the difference between the two become more important starting in Week 2.

If you are working through this course independently and find yourself confused when numbers like "byte offset 0x0010" come up, turn to the cognitive tools supplement: curriculum-supplements/spk-101-younger-learner-tools.md. The Mailbox metaphor section there gives you a concrete picture of what an address is and why it is different from a value. You do not need it yet, but it is worth reading before Week 2's labs.


What comes next

Week 2 takes you inside the ROM. You open the same file you ran this week, but in a hex editor instead of an emulator. You look at the bytes directly. You will see the INES header (the first 16 bytes of every NES ROM file), the program code section, and the graphics data. By the end of week 2 you can point to a specific byte and say "that byte is part of the sprite for the main character."