Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/pret/pokeemerald/llms.txt

Use this file to discover all available pages before exploring further.

pokeemerald is a GBA decompilation of Pokémon Emerald. The repository separates C source, assembly stubs, binary assets, and build tooling into distinct directory trees.

Top-level layout

pokeemerald/
├── src/                  # C source files (300+ files)
├── asm/                  # ARM assembly stubs and macros
├── data/                 # Scripts, map data, tilesets, sound
├── include/              # C headers
│   ├── constants/        # Numeric constants
│   └── gba/              # GBA hardware abstraction
├── graphics/             # Sprite sheets and tilemaps (PNG + binary)
├── sound/                # MIDI songs
├── tools/                # Build tools
├── Makefile              # Build system entry point
├── ld_script.ld          # Linker script (retail-matching build)
├── ld_script_modern.ld   # Linker script (modern/non-matching build)
└── build/                # Generated output — created at build time

Directory reference

All game logic written in C, organized by subsystem. Over 300 .c files cover the battle engine, Pokémon data, overworld, UI screens, save system, and scripting.Key files:
FilePurpose
src/main.cEntry point — hardware init, main game loop, callback dispatch
src/battle_main.cBattle engine core — turn processing, battler actions
src/pokemon.cGetMonData / SetMonData, CreateMon, CalculateMonStats
src/overworld.cField (overworld) game loop
src/save.cSave file read/write and sector management
src/script.cScript VM entry points and context management
Hand-written or not-yet-decompiled ARM Thumb assembly files (.s). Also contains asm/macros/ with .inc files that define the domain-specific assembly languages used in data/.
Macro fileUsed for
asm/macros/battle_script.incBattle script bytecode commands
asm/macros/battle_anim_script.incBattle animation sequencing
asm/macros/battle_ai_script.incBattle AI script commands
asm/macros/event.incMap event scripts
asm/macros/movement.incNPC and player movement sequences
asm/macros/function.incARM function entry/exit macros
asm/macros/m4a.incM4A audio driver macros
asm/macros/map.incMap header macros
Binary and text data consumed by the C source.
data/
├── battle_scripts_1.s      # Core battle script bytecode
├── battle_scripts_2.s      # Additional battle scripts
├── battle_anim_scripts.s   # Animation sequences for all moves
├── battle_ai_scripts.s     # AI decision scripts
├── maps/                   # Per-map headers, events, and scripts
├── layouts/                # Per-map tile layout binaries
├── tilesets/               # Primary and secondary tileset binaries
├── scripts/                # Global and town-level event scripts
├── text/                   # All in-game strings
└── sound_data.s            # Sound table and music track data
All .h files. Two important sub-trees:
  • include/constants/ — numeric constant definitions: species.h, moves.h, items.h, flags.h, vars.h, abilities.h, maps.h, songs.h, battle.h
  • include/gba/ — GBA hardware register definitions and I/O macros (display, DMA, timers, interrupts)
include/global.h is the universal prelude. It pulls in the GBA headers, game type definitions, fixed-point math macros, and all constant headers.
PNG source images and precompiled binary tilesets. gbagfx converts these to .4bpp, .8bpp, and .bin files that are INCBIN-embedded into the ROM at build time.
MIDI song files (.mid) and raw audio samples. mid2agb and wav2agb convert these to the GBA m4a sound driver format during the build.
Custom tools compiled from C and invoked by the Makefile:
ToolPurpose
gbagfxConverts PNG graphics to GBA tile formats
preprocCustom C preprocessor for Pokémon string encoding
scanincDependency scanner for .s include files
mid2agbMIDI to AGB sound driver format converter
jsonprocProcesses JSON data files into C arrays
rsfontFont bitmap generator
wav2agbWAV to AGB PCM sample converter

Build system

The Makefile at the repository root drives the entire build and targets the arm-none-eabi toolchain.
Produces a byte-for-byte identical ROM to the original Pokémon Emerald release.
make
Output: pokeemerald.gba (in the repository root)
Key Makefile variables:
TITLE      := POKEMON EMER
GAME_CODE  := BPEE
MAKER_CODE := 01
REVISION   := 0
FILE_NAME  := pokeemerald
BUILD_DIR  := build
The standard matching build requires the arm-none-eabi toolchain at a specific version. See the repository README for version requirements and setup instructions.

Linker scripts

FilePurpose
ld_script.ldRetail build — places every section at addresses matching the original ROM
ld_script_modern.ldModern build — relaxed placement, compatible with current GCC

Build output

The build/ directory is created automatically:
build/
├── emerald/            # Object files for the default (agbcc) build
├── modern/             # Object files for the modern build
pokeemerald.gba         # Final ROM image (in the repository root)
Add build/ to your editor’s file exclude list to prevent indexing thousands of generated object files.

Build docs developers (and LLMs) love