Overview
The Pokémon Red/Blue engine is organized into specialized modules located in theengine/ directory. Each module handles a specific aspect of the game, from battles to overworld movement to menu systems.
This modular architecture makes the codebase easier to understand and modify, with clear separation of concerns between different game systems.
Engine Architecture
Battle System
Overworld
Menu Systems
Pokémon Management
Item System
Event System
Battle System
Location:engine/battle/
The battle engine handles all combat mechanics including damage calculation, status effects, AI behavior, and battle animations.
Core Files
core.asm - Battle Core Loop
core.asm - Battle Core Loop
- Initialize battle variables
- Display battle intro
- Main turn loop:
- Player chooses action
- AI chooses action
- Determine move order
- Execute moves
- Apply residual effects
- Check for battle end
- Handle battle outcome
effects.asm - Move Effects
effects.asm - Move Effects
- Damage calculation
- Status effect application
- Stat modification
- Special move effects (Substitute, Transform, etc.)
experience.asm - EXP & Leveling
experience.asm - EXP & Leveling
Move Effects System
Location:engine/battle/move_effects/
Each complex move effect has its own file:
- substitute_effect.asm - Creates substitute doll
- confusion_side_effect.asm - Confusion mechanics
- haze_effect.asm - Removes all stat changes
- recoil_effect.asm - Recoil damage calculation
- mist_effect.asm - Prevents stat reduction
Battle State Variables
Overworld System
Location:engine/overworld/
Manages map navigation, sprite movement, collision detection, and field interactions.
Core Components
map_sprites.asm - Sprite Management
map_sprites.asm - Sprite Management
- Up to 16 sprites per map
- Each sprite has two data structures:
SpriteStateData1- Animation and positionSpriteStateData2- Map coordinates and movement
movement.asm - Movement Engine
movement.asm - Movement Engine
- STAY - Stand still
- WANDER - Random movement
- WALK - Predefined path
- LOOK - Turn to face player
- SPINRANDOM - Spin randomly
- SPINCLOCKWISE - Rotate clockwise
player_state.asm - Player Control
player_state.asm - Player Control
hidden_events.asm - Item Balls & Signs
hidden_events.asm - Item Balls & Signs
Field Moves
Location:engine/overworld/ (various files)
- cut.asm - Cut down trees
- surf.asm - Water navigation
- strength.asm - Push boulders (
push_boulder.asm) - flash.asm - Illuminate dark caves
Menu Systems
Location:engine/menus/
Handles all menu interfaces including the start menu, party menu, bag, and PC systems.
Key Menus
start_sub_menus.asm - Start Menu
start_sub_menus.asm - Start Menu
party_menu.asm - Pokémon Menu
party_menu.asm - Pokémon Menu
pokedex.asm - Pokédex Interface
pokedex.asm - Pokédex Interface
pc.asm - PC System
pc.asm - PC System
- Someone’s PC - Pokémon storage
- Bill’s PC - Box management
- Player’s PC - Item storage
- Prof. Oak’s PC - Pokédex rating
- League PC - Hall of Fame
players_pc.asm- Item storageoaks_pc.asm- Pokédex ratingleague_pc.asm- Hall of Fame records
Pokémon Management
Location:engine/pokemon/
Handles Pokémon data loading, storage, evolution, and status management.
Core Systems
load_mon_data.asm - Data Loading
load_mon_data.asm - Data Loading
add_mon.asm - Adding Pokémon
add_mon.asm - Adding Pokémon
evos_moves.asm - Evolution & Moves
evos_moves.asm - Evolution & Moves
bills_pc.asm - Box Storage
bills_pc.asm - Box Storage
Item System
Location:engine/items/
Manages inventory, item effects, and TM/HM mechanics.
Key Components
inventory.asm - Bag Management
inventory.asm - Bag Management
item_effects.asm - Item Usage
item_effects.asm - Item Usage
- Medicine (Potions, Full Heal, etc.)
- Status healing (Antidote, Awakening, etc.)
- Battle items (X Attack, Dire Hit, etc.)
- Evolution stones
- Poké Balls
- Key items
tmhm.asm - TM/HM System
tmhm.asm - TM/HM System
Event System
Location:engine/events/
Handles scripting, hidden items, gifts, trades, and special events.
Event Types
Hidden Events
Hidden Events
in_game_trades.asm - NPC Trades
in_game_trades.asm - NPC Trades
give_pokemon.asm - Gift Pokémon
give_pokemon.asm - Gift Pokémon
Graphics System
Location:engine/gfx/
Handles graphics loading, animation, and visual effects.
Key Systems
- screen_effects.asm - Screen transitions
- sprite_oam.asm - Sprite rendering
- load_pokedex_tiles.asm - Pokédex graphics
- mon_icons.asm - Menu icons
Module Interactions
Best Practices
Understand Module Boundaries
Use Existing Functions
Follow Data Flow
Test Module Changes
Key RAM Variables
Global Variables
Module-Specific Variables
Each module typically has a dedicated WRAM section for its variables. For example:- Battle:
wBattle*variables - Menu:
wMenu*variables - Sprite:
wSprite*variables
Related Pages
- Constants Reference - Constants used by modules
- Macros Reference - Helper macros
- Data Structures - Memory layouts