A comprehensive Python toolkit for Game Boy Advance ROM hacking and development, with specialized support for Pokemon games. This project consists of two main packages: pyagb (core AGB data handling) and pymap (map editing and project management).
PyAGB provides tools for:
- ROM Data Manipulation: Reading, writing, and processing Game Boy Advance ROM data
- Map Editing: Visual map editor with tileset, block, and event management
- Project Management: Organized workspace for ROM hacking projects
- Asset Management: Graphics, tilesets, palettes, and animations
- Code Generation: Assembly and C code generation from data structures
The foundational library for Game Boy Advance data processing.
Features:
- Low-level ROM data structures and types
- Image and palette processing (4-bit indexed color)
- LZ77 compression/decompression support
- String encoding/decoding with custom character maps
- Binary data model definitions
- Memory layout management
Key Modules:
agb.types- Data type definitions for GBA structuresagb.image- Image processing and conversionagb.palette- Color palette managementagb.model- Data model frameworkagb.string- Text encoding/decoding
Data Model Framework:
The agb.model module provides a type system that mirrors C data structures for working with binary Game Boy Advance data. The framework is built around a base Type class that defines the interface for all data types:
Core Type Hierarchy:
ScalarType- Basic data types likeu8,u16,u32,s8,s16,s32,pointer- Can be associated with constant tables for named values
- Handles endianness and binary packing automatically
Structure- C-style structs with named fields- Supports complex layouts with priorities and dependencies
ArrayType- Fixed and variable-size arraysFixedSizeArrayType- Arrays with compile-time known sizeVariableSizeArrayType- Arrays whose size depends on other fields
UnboundedArrayType- Null-terminated arraysPointerType- Typed pointers to other data structuresBitfieldType- Packed bit fields within scalarsUnionType- C-style unionsStringType- Game text with encoding support
Key Operations: All types support these core operations:
from_data()- Parse binary data from ROM into Python objectsto_assembly()- Generate assembly code from Python objectssize()- Calculate memory footprintget_constants()- Extract required constant definitions
Example usage:
from agb.model.scalar_type import ScalarType
from agb.model.structure import Structure
# Define a scalar associated with constants
map_type = ScalarType('u8', constant='map_types')
# Define a C-style struct
class MapHeader(Structure):
def __init__(self):
super().__init__([
('width', 'u32', 0),
('height', 'u32', 0),
('tileset_primary', 'pointer', 0),
('tileset_secondary', 'pointer', 0),
])
# Parse from ROM data
header = map_header_type.from_data(rom, 0x8000000, project, [], [])
print(f"Map size: {header['width']}x{header['height']}")A full-featured map editor and project management system built on pyagb.
Features:
- Visual Map Editor: Graphical interface for editing game maps
- Tileset Management: Import, edit, and organize tilesets
- Event Editing: Place and configure NPCs, warps, triggers, and signposts
- Connection System: Link maps together with seamless transitions
- Smart Shapes: Advanced block placement tools
- Project Organization: Manage multiple maps, tilesets, and assets
- Undo/Redo Support: Full history tracking for all edits
Key Components:
- GUI Application: Qt-based visual editor
- Project System: JSON-based project files with asset management
- Data Models: Structured definitions for headers, footers, events
- Rendering Engine: Real-time map visualization
- Export Tools: Generate assembly code from project data
# Clone the repository
git clone <repository-url>
cd pyagb
# Install in development mode
pip install -e .# Launch the map editor
python -m pymap.guiimport agb.image
import agb.palette
# Load a GBA image
image, palette = agb.image.from_file('tileset.png')from pymap.project import Project
# Load an existing project
project = Project('my_hack.pmp')
# Load a map header
header, label, namespace = project.load_header('0', '0')
# Load associated footer (map data)
footer, footer_idx, smart_shapes = project.load_footer(label)python -m pymap pymap2s project.pmp -o output.s --projectpython -m pymap bin2s input.bin -o output.spython -m pymap pypreproc input.s project.pmp -o output.sโโโ src/
โ โโโ agb/ # Core AGB library
โ โ โโโ types.py # GBA data type definitions
โ โ โโโ image.py # Image processing
โ โ โโโ palette.py # Palette management
โ โ โโโ model/ # Data model framework
โ โโโ pymap/ # Map editor and project tools
โ โโโ gui/ # Qt-based GUI components
โ โโโ project.py # Project management
โ โโโ model/ # Map data structures
โ โโโ compile.py # Code generation
โโโ pyproject.toml # Project configuration
โโโ README.md
Projects use JSON configuration files that define:
- Data type mappings for different game versions
- File paths and organization
- Graphics formats and constraints
- Event type definitions
- Assembly generation settings
Example project structure:
my_hack/
โโโ my_hack.pmp # Main project file
โโโ my_hack.pmp.config # Configuration
โโโ my_hack.pmp.constants # Constants definitions
- โ Visual block-based map editing
- โ Multiple layer support
- โ Border and connection management
- โ Real-time preview
- โ Smart shape tools for efficient editing
- โ PNG import/export for graphics
- โ Automatic palette optimization
- โ Tileset organization and reuse
- โ Animation support
- โ Assembly code generation
- โ C header generation
- โ Binary data export
- โ Project compilation
Primarily tested with Pokemon games (Ruby/Sapphire/Emerald/FireRed/LeafGreen) but designed to be extensible for other GBA titles.
This project welcomes contributions! Areas of interest:
- GUI improvements
- Performance optimizations
- Documentation
- Bug fixes
See LICENSE file for details.