A Nintendo Entertainment System (NES) emulator written in C using SDL2.
- 6502 CPU: Full instruction set implementation with all addressing modes
- PPU (2C02): Basic PPU structure with register handling
- Cartridge Loading: iNES format support with Mapper 0 (NROM)
- Controller Input: NES controller emulation with keyboard mapping
- SDL2 Graphics: Window and rendering system
- GCC compiler
- SDL2 development libraries
- Make
On macOS:
brew install sdl2makeOn Apple Silicon Macs, the build uses x86_64 architecture:
arch -x86_64 make./bin/nes_emu <path_to_rom.nes>Example:
./bin/nes_emu roms/game.nesAnalyze NES ROM files and display detailed information:
./bin/nes_info <rom.nes>Features:
- iNES header parsing
- Mapper identification
- ROM size information
- Interrupt vectors
- CHR-ROM analysis
- Visual pattern display
Example output:
╔════════════════════════════════════════╗
║ NES ROM Analysis Tool ║
╚════════════════════════════════════════╝
File: Tetris.nes
=== iNES Header Information ===
Magic: NES ✓ Valid
--- ROM Sizes ---
PRG-ROM: 8 x 16KB = 128KB
CHR-ROM: 16 x 8KB = 128KB
--- Mapper ---
Mapper Number: 65
Mapper Name: Irem H3001
Run unit tests:
make testTests verify:
- CPU operations
- Mapper 65 bank switching
- PPU palette/nametable
- Pattern extraction
.
├── Makefile
├── include/
│ ├── common.h # Common type definitions
│ ├── bus.h # Memory bus interface
│ ├── cpu.h # 6502 CPU interface
│ ├── ppu.h # PPU interface
│ └── cartridge.h # ROM cartridge interface
└── src/
├── main.c # Entry point and SDL loop
├── bus.c # Memory mapping
├── cpu.c # 6502 CPU implementation
├── ppu.c # PPU implementation
└── cartridge.c # ROM loading
- All official opcodes implemented
- 12 addressing modes
- Interrupt handling (NMI, IRQ, RESET)
- Cycle-accurate timing
- Basic register implementation ($2000-$2007)
- Scanline and cycle tracking
- VBlank NMI generation
- Frame buffer output
- iNES format parsing
- Mapper 0 (NROM) support
- 16KB/32KB PRG-ROM
- 8KB CHR-ROM/RAM
The emulator maps keyboard keys to NES controller buttons:
| NES Button | Keyboard Key |
|---|---|
| A | X |
| B | Z |
| Start | Enter |
| Select | Space |
| Up | ↑ |
| Down | ↓ |
| Left | ← |
| Right | → |
- Only Mapper 0 (NROM) is supported
- No APU (Audio Processing Unit)
- PPU rendering is not fully implemented
- No sprite or background rendering
To make this a fully functional emulator:
- PPU Rendering: Implement background and sprite rendering
- More Mappers: Implement additional mappers (MMC1, MMC3, etc.)
- APU: Add audio support
- Save States: Implement save/load functionality
This is an educational project for learning NES emulation.