Overview
The Pokémon Red/Blue disassembly provides several debugging features and outputs symbol files that enable powerful debugging workflows with Game Boy emulators. This guide covers building debug versions, understanding debug outputs, and using debugging tools effectively.Debug Build
The project includes a special debug build of Pokémon Blue with additional features:pokeblue_debug.gbc with:
- Debug menu - Accessible at startup
- Debug party - Pre-configured Pokémon with special moves
- Test battle mode - Rapid battle testing
- All symbols exported - For use with emulator debuggers
- 0xFF padding - Makes unused ROM regions visible
The debug build uses 0xFF as the ROM padding byte (instead of 0x00), which helps identify unused space and makes buffer overruns more visible.
Debug Menu
When you runpokeblue_debug.gbc, you’ll see a debug menu instead of the normal title screen:
Debug Menu Options
The menu presents two options:
- FIGHT - Starts a test battle
- DEBUG - Starts a new game with debug features enabled
Test Battle Mode
Selecting FIGHT:
- Sets player name to “Tom”
- Sets rival name to “Juerry”
- Gives you Earth Badge for obedience
- Starts with a level 20 Rhydon
- Battles against a level 20 Rhydon
- Loops indefinitely for testing
engine/debug/debug_menu.asm:75-121Debug Party
When starting a debug new game, you receive a pre-configured party:Exeggutor - Level 90
Moves: Fly, Cut, Surf, StrengthAll four HM moves for easy navigation. Exeggutor was Tsunekazu Ishihara’s favorite debugging Pokémon.
Mew - Level 5
Purpose: Testing and experimentationThe rarest Pokémon available from the start.
Jolteon - Level 56
Moves: Thunderbolt (added)Powerful Electric-type for testing.
Dugtrio - Level 56
Purpose: Ground-type coverage
Articuno - Level 57
Moves: Fly (added)Legendary bird with HM for flying.
Pikachu - Level 5
Moves: Surf (added)For testing Surfing Pikachu.
engine/debug/debug_party.asm:15-32
Debug Items and Features
The debug new game also provides:Starting Items
- Bicycle × 1 - Fast travel
- Full Restore × 99 - Healing
- Full Heal × 99 - Status cure
- Escape Rope × 99 - Dungeon escape
- Rare Candy × 99 - Level up testing
- Master Ball × 99 - Easy captures
- Town Map × 1 - Navigation
- Secret Key × 1 - Cinnabar Gym access
- Card Key × 1 - Silph Co. access
- S.S. Ticket × 1 - S.S. Anne access
- Lift Key × 1 - Team Rocket HQ access
engine/debug/debug_party.asm:138-150
Starting Flags
- All badges except Earth Badge - Enables HMs and stat boosts
- Complete Pokédex - All 151 Pokémon seen and owned
- All towns visited - Can Fly anywhere
- Obtained Pokédex - Can use Pokédex from start
- Rival chose Squirtle, Player chose Charmander
engine/debug/debug_party.asm:39-124
Building with Debug Symbols
To generate.sym and .map files for any build:
-E flag to rgbasm, which exports all symbols to the output files.
The official CI builds always use
DEBUG=1 to generate symbols for the symbols branch.Symbol Files (.sym)
Symbol files map addresses to labels, making debugging much easier.Format
Each line contains a bank:address pair and a label name:Using with Emulators
Most Game Boy emulators can load symbol files:BGB (Windows)
BGB (Windows)
Loading symbols:
- Open the debugger (Right-click → Debugger)
- Right-click in the disassembly → Load SYM file
- Select
pokered.symorpokeblue.sym
- Disassembly shows label names
- Set breakpoints by symbol name
- Watch expressions using symbols
- Call stack with function names
Emulicious (Cross-platform)
Emulicious (Cross-platform)
Loading symbols:
- Tools → Debugger
- File → Load Symbol File
- Select the
.symfile
- Source-level debugging
- Conditional breakpoints
- Memory viewer with labels
- Profiling support
mGBA (Cross-platform)
mGBA (Cross-platform)
Loading symbols:
- Tools → Game Pak sensors
- Tools → Scripting (for advanced use)
- Load
.symfile via debug console
SameBoy (Cross-platform)
SameBoy (Cross-platform)
Loading symbols:
Automatically loads
.sym files with the same name as the ROM.Features:- Integrated debugger console
- Breakpoints by symbol
- Memory watching
- Step debugging
Map Files (.map)
Map files show how sections are laid out in the ROM.Format
Information Provided
- Section names and addresses
- Section sizes (in bytes)
- Which object files contributed code
- Bank assignments
- Memory alignment
Common Debugging Techniques
Breakpoints
Set breakpoints at key functions:Memory Watching
Monitor important RAM addresses:Party Data
wPartyCount - Number of Pokémon (D163)wPartyMon1Species - First Pokémon species (D164)Battle Data
wBattleType - Current battle type (D05A)wCurOpponent - Enemy trainer/Pokémon (D059)Map Data
wCurMap - Current map ID (D35E)wXCoord / wYCoord - Player position (D361/D362)Flags
wObtainedBadges - Badge flags (D356)wEventFlags - Event completion flags (D747)Tracing Execution
Log function calls to understand control flow:- Enable execution logging in your emulator
- Set breakpoints at function entry points
- Single-step through complex routines
- Watch stack pointer to track call depth
Frame-by-Frame Analysis
For graphics or timing issues:- Advance frame-by-frame (usually F1 key)
- Watch VRAM during VBlank
- Monitor PPU state
- Check sprite OAM updates
Advanced Debugging
Conditional Breakpoints
Break only when specific conditions are met:Logging to Console
Some emulators support logging:Save State Debugging
- Save state at interesting points
- Load and modify RAM values
- Test different scenarios
- Compare states to find bugs
Regression Testing
After making changes:Debugging Symbols Reference
Key symbols for debugging:Engine Functions
Joypad- Input handlingVBlank- VBlank interrupt handlerSerial- Link cable communicationDelayFrames- Timing delaysFarCopyData2- Data copyingCallFunctionInTable- Jump table dispatcher
Battle System
BattleCore- Main battle loopInitBattle- Battle initializationDoBattleMenu- Battle menu handlerExecutePlayerMove- Player attack executionEnemySelection- AI move selection
Menu System
HandleMenuInput- Generic menu handlerPlaceMenuCursor- Cursor positioningDisplayTextID- Text displayPrintText- Text rendering
Map Engine
OverworldLoop- Main overworld loopCheckWarpsNoCollision- Warp detectionHandleMidJump- Jump and ledge handlingUpdateSprites- NPC sprite updates
For a complete symbol reference, see the symbols branch which contains
.sym files for all builds.Troubleshooting
Symbols not loading in emulator
Symbols not loading in emulator
Problem: Emulator doesn’t recognize the
.sym file.Solution:- Ensure the ROM and
.symfile have the same base name - Check emulator documentation for symbol file format
- Try rebuilding with
make DEBUG=1
Debug build crashes or behaves oddly
Debug build crashes or behaves oddly
Problem: Debug features cause unexpected behavior.Solution:
- The debug build has intentional differences (debug party, menu, etc.)
- Use a regular build if you want vanilla behavior
- The test battle mode loops infinitely by design
Breakpoint not triggering
Breakpoint not triggering
Problem: Set a breakpoint but it never hits.Solution:
- Verify the symbol exists in the
.symfile - Check you’re using the correct bank (ROM bank switching)
- Ensure the code path actually executes
Wrong values in memory
Wrong values in memory
Problem: RAM addresses show unexpected values.Solution:
- RAM addresses in symbols are relative to WRAM start
- Add 0xC000 to symbol addresses for actual RAM location
- Some values are computed dynamically