tourze / nes-cartridge
0.0.1
2025-05-24 17:14 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-05-24 18:15:52 UTC
README
This package provides NES cartridge-related functionality, handling game ROM data loading and memory mapping for a NES emulator.
Features
- Support for standard iNES and NES2.0 format ROM file parsing
- Memory structure management for cartridge data
- ROM data loading and processing
- Integration with the mapper module (nes-mappers)
- Support for battery-backed SRAM management
Installation
Install via Composer:
composer require nes/cartridge
Basic Usage
// Load ROM from file $cartridge = CartridgeFactory::createFromFile('/path/to/game.nes'); // Get mapper type $mapperType = $cartridge->getMapperType(); // Get PRG-ROM data $prgRomData = $cartridge->getPrgRomData(); // Get CHR-ROM data $chrRomData = $cartridge->getChrRomData(); // Reset cartridge state $cartridge->reset();
Integration with Mapper Module
This package is designed to work with the nes-mappers
package:
// Cartridge and mapper integration example $cartridge = CartridgeFactory::createFromFile('/path/to/game.nes'); $mapper = MapperFactory::create($cartridge->getMapperType(), $cartridge); // CPU read (through mapper) $data = $mapper->cpuRead(0x8000); // PPU read (through mapper) $patternData = $mapper->ppuRead(0x0000);
Architecture
The module uses a layered design:
- Interface Layer - Defines standard interfaces for interaction with other modules
- Core Layer - Provides core cartridge implementation
- Functional Layer - Implements ROM header parsing, memory management, etc.
- Factory Layer - Provides factory classes for creating cartridge instances
- Loader Layer - Handles file IO and ROM data loading
Contributing
Contributions are welcome. Please ensure you add appropriate tests before submitting PRs.
License
MIT License