TechBuzzPro

Atari 2600 Emulation & Debugging with Stella

· 5 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to use Stella, the most mature Atari 2600 emulator, to run classic games and, more importantly, debug your own homebrew or hacked ROMs. Stella includes a built-in debugger that lets you step through 6502 assembly code, inspect memory and registers, and watch the TIA (Television Interface Adaptor) chip's graphics state in real time. You'll need a ROM file (.bin or .a26) to get started—either a commercial game dump or your own compiled source code.

What You'll Need

  • A computer running Windows, macOS, or Linux.
  • The latest Stella release (download from the official Stella GitHub page).
  • A ROM file to load. For debugging, a ROM with symbols (a .sym file) or debug info is helpful.
  • Basic familiarity with 6502 assembly language (for debugging).

Step-by-Step

  1. Install Stella.
    • Windows: Run the installer .exe and follow the prompts.
    • macOS: Open the .dmg and drag Stella to Applications.
    • Linux: Use your package manager (e.g., sudo apt install stella on Debian/Ubuntu) or build from source.
  2. Launch Stella and load a ROM.
    • Open Stella. You'll see a file browser dialog.
    • Navigate to your ROM file and double-click it, or select it and press Enter.
    • The game should start running immediately.
  3. Access the debugger.
    • While the game is running, press the backtick key (`) or the Tab key (depending on your keyboard layout) to enter the debugger.
    • You'll see a prompt at the bottom of the screen. This is the debugger console.
    • Type help and press Enter to see a list of available commands.
  4. Set breakpoints.
    • Breakpoints pause the emulator when a specific address is executed or accessed.
    • To break on execution of address $F000, type break $F000.
    • To break on read or write to a memory location, use breakread $80 or breakwrite $80.
    • You can list active breakpoints with breaklist and clear them with clearbreaks.
  5. Step through code.
    • When the emulator pauses (at a breakpoint or via pause), you can step one instruction at a time.
    • Use step (or just press s) to execute one instruction.
    • Use trace (or t) to step into subroutines.
    • Use run (or r) to continue running until the next breakpoint.
  6. Inspect CPU and memory.
    • Type cpu to see the current register values (A, X, Y, PC, SP, flags).
    • To view memory, type memory followed by an address range, e.g., memory $80 $9F.
    • To set a memory value, use poke $80 #$1A (writes hex value 1A to address 80).
    • To read a specific address, type peek $80.
  7. Watch TIA state.
    • The debugger shows a graphical view of the TIA registers on the right side.
    • You can also type tia to get a text dump of all TIA registers.
    • Use scanline to see the current scanline and cycle count.
  8. Use the built-in cheat system (optional).
    • Type cheat to open the cheat code manager.
    • You can add RAM or ROM cheats to test game behavior.

Common Mistakes

  • Using the wrong breakpoint type: A common error is using break when you want to break on a memory access. break only stops on instruction execution at that address.
  • Forgetting to load symbols: If you have a .sym file, load it with loadsym file.sym before debugging. Otherwise, you'll see raw addresses instead of labels, making code much harder to follow.
  • Not pausing before stepping: You can't step while the game is running. Always pause first (with the backtick or pause command).
  • Misreading hex values: Stella uses hex by default. If you type a decimal number without a prefix, it's interpreted as hex. Use # for decimal (e.g., poke $80 #100).

Tips

  • Use the built-in disassembler: Type disasm $F000 $F010 to see disassembled instructions in that address range.
  • Save and restore debugger states: Use savestate and loadstate to save a snapshot of your debugging session.
  • Use the watch window: Type watch $80 to add an address to the watch list. It will be displayed and updated in the debugger's right panel.
  • Learn the keyboard shortcuts: In the debugger, F5 runs, F6 steps, F7 steps over, and F8 steps out. These save time compared to typing commands.
  • Use the scanline indicator: The bottom bar shows the current scanline (e.g., 50). This is crucial for debugging timing-sensitive code like kernel routines.

Troubleshooting

  • Game won't load: Ensure the ROM file is not corrupted and is a valid Atari 2600 ROM. Try loading it in another emulator to verify. If it's a homebrew, check that it's compiled for the correct bank-switching method.
  • Debugger doesn't open: The backtick key might be remapped. Check the input settings in the Options menu. You can also type debugger at the main Stella prompt (if you have the command-line version).
  • Breakpoints not hitting: Make sure the address is correct. If you're using symbols, verify the symbol file loaded correctly with listsym. Also, check if the code is running in a different bank—you may need to set a breakpoint on the bank-switch address.
  • Registers show unexpected values: This often happens when the game uses undocumented opcodes or illegal memory accesses. Use the undef command to check for undefined opcodes in your code.
  • Stella crashes on startup: Try deleting the Stella configuration file (usually in ~/.stella on Linux/macOS or %APPDATA%\Stella on Windows) and restarting.

Frequently Asked Questions

  • Can I use Stella to debug commercial games? Yes, but you'll only see raw assembly without symbols. You can still set breakpoints and inspect memory, but it's more challenging.
  • How do I load a symbol file? In the debugger, type loadsym /path/to/file.sym. Stella also auto-loads .sym files if they have the same name as the ROM and are in the same directory.
  • What is the difference between 'step' and 'trace'? step executes one instruction and stops. If that instruction is a JSR (jump to subroutine), trace will step into the subroutine, while step will step over it (treating it as a single instruction).
  • How can I see the current frame's graphics? The debugger's TIA tab shows a visual representation of the playfield, sprites, and missiles. You can also use the screenshot command to save an image.
  • Can I set a breakpoint on a specific scanline? Yes, type breakscanline 100 to break when the scanline counter reaches 100. This is very useful for debugging kernel timing.
  • Is there a way to step backwards? No, the debugger is forward-only. However, you can use savestate before a critical section and loadstate to go back to that point.