Skip to content

Mesen (NES emulator but from a developer's perspective)

Created: 2020-03-05 16:09:16 -0800 Modified: 2020-03-06 16:02:43 -0800

Just to clarify: this note is about an NES emulator, but it’s from the point-of-view of a developer, meaning I’m not going to talk about how to remap controls or play a particular game or something.

These notes go hand-in-hand with the NES ROMs note.

  • It’s highly suggested to turn on Options → Emulation → Advanced → Default power on state for RAM → Random values. This will make it easier to tell when you have uninitialized memory:
  • You can use the debugger to step by instruction or by scanline.
  • Byte order in the debugger is little-endian, meaning if you see “00 80” in the debugger, that’s actually $8000.
  • The debugger is typically very slow with more windows open (e.g. the event viewer).
  • View original source rather than the disassembly:
    • First, make sure you have a debug file like “main.dbg”. This is produced via ld65.exe with the “—dbgfile main.dbg” option.
    • Right-click the disassembly and go to “Switch to Source View (Ctrl+Q)“

  • Random notes about the debugging screen
  • In Mesen’s debugger, you can visualize what’s being drawn to the screen via ctrl+P (assuming drawing is turned on), and the PPU scroll overlay is where we are in nametables (which is shown via a viewport)

The NES doesn’t have something like exception handling, so when you encounter a break, you can use Mesen’s “Step Back” function repeatedly to figure out where your code went wrong.