Skip to content
/ go-nes Public

The Golang implementation of the NES core library that includes a full 6502 CPU instruction set emulation, PPU, APU, memory mapping, and ROM integration. It provides a complete, reusable NES library for building your own emulator or for educational use.

License

Notifications You must be signed in to change notification settings

ghosind/go-nes

Repository files navigation

go-nes

Test Go Report Card codecov License Badge

go-nes is a focused, well-tested Go library that implements the core internals of an NES emulator. It intentionally excludes GUI and real hardware I/O (display/windowing, real controllers, audio output). The goal is to provide a clean, reusable emulator core you can embed into your own frontend, educational tooling, or testing harness.

Important

This project is a work in progress and may not yet be feature-complete or fully accurate.

Features

  • Accurate 6502 CPU emulation with support for all official/unofficial opcodes and addressing modes.
  • Passed the NESTest CPU test ROM for accuracy verification of 6502 instructions and unofficial opcodes.
  • Basic PPU implementation for rendering graphics (background and sprites).
  • APU stubs for audio processing (full audio implementation is a work in progress).
  • Memory mapping that supports various NES mappers (NROM, MMC1, etc.).

Components

  • nes: High-level NES struct that ties together CPU, PPU, APU, and memory.
  • cpu: Implements the 6502 CPU with all instructions, addressing modes, and status flags.
  • ppu: Handles the NES Picture Processing Unit (PPU) for graphics rendering.
  • apu: Manages the NES Audio Processing Unit (APU) for sound generation.
  • memory: Emulates the NES memory map, including RAM, ROM, and I/O registers.
  • rom: Loads and parses NES ROM files in iNES format.
  • rom/ines: Loads and parses iNES header.
  • rom/mapper: Supports various NES cartridge mappers for memory banking.
  • controller: Emulates NES controller input handling.

Supported Mappers

  • NROM (Mapper 0)

Getting Started

There are a minimal example of how to use the library to load a ROM and run the emulation loop:

// Import the library
import "github.com/ghosind/go-nes"

// Read a ROM file
romData, err := os.ReadFile("path/to/your/game.nes")

// Create a new NES instance
myNes, err := nes.New(romData)

// Run the emulation loop
for {
    myNes.Step() // Step the CPU, PPU, and APU
    // Handle input, rendering, etc.
}

Testing

The project includes extensive unit tests covering CPU instructions, memory mapping, and ROM loading. To run all tests, use:

go test ./...

To run tests for a specific package, e.g., CPU:

go test ./cpu -v

Todo List

  • 6502 CPU implementation with unofficial opcodes
  • Complete NESTest compliance
  • Memory mapping and RAM emulation
  • iNES ROM loading and parsing
  • IRQ and NMI handling
  • Complete NROM mapper support (mapper 0)
  • PPU implementation for full graphics rendering
  • APU implementation for audio output
  • Support for additional mappers (MMC1, MMC3, etc.)
  • Controller input handling
  • Debugging and logging utilities

Reference

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

The Golang implementation of the NES core library that includes a full 6502 CPU instruction set emulation, PPU, APU, memory mapping, and ROM integration. It provides a complete, reusable NES library for building your own emulator or for educational use.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages