Skip to content

ArturSkowronski/kNES

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

268 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kNES - Kotlin NES Emulator

image

kNES is a Nintendo Entertainment System (NES) emulator written in Kotlin, forked from the vNES Java emulator. This project was created primarily for fun and educational purposes, allowing developers to learn about emulation techniques and NES hardware while enjoying classic games.

Tests

About This Project

kNES is a reimplementation and extension of the vNES emulator (originally developed by Brian F. R.) in Kotlin. The project aims to:

  • Provide a modern, Kotlin-based NES emulator
  • Serve as an educational resource for those interested in emulation
  • Demonstrate different UI implementation approaches in the JVM ecosystem
  • Have fun with retro gaming and programming!

This project is distributed under the GNU General Public License v3.0 (GPL-3.0), ensuring it remains free and open source.

Supported Mappers

Mapper Name Games
0 NROM Super Mario Bros, Donkey Kong, Pac-Man, ~250 games
1 MMC1/SxROM Final Fantasy, The Legend of Zelda, Metroid, Mega Man 2, ~680 games

Controls

Key NES Button
Z A
X B
Enter Start
Space Select
Arrow keys D-pad

Gamepad (Switch Joy-Con, Xbox-style controllers) also supported.

Project Structure

The project is organized into the following modules:

  • knes-emulator: Core emulator — CPU (6502), PPU, PAPU, memory, and mappers (NROM, MMC1).
  • knes-controllers: Input handling — keyboard, gamepad (Switch Joy-Con, Xbox-style).
  • knes-compose-ui: Jetpack Compose Desktop UI (primary, recommended).
  • knes-skiko-ui: Skiko-based hardware-accelerated rendering UI.
  • knes-terminal-ui: Terminal-based UI (text-based interface) — slow AF, but freaking fun.
  • knes-api: REST API server for AI agents, TAS tools, and automation (docs).
  • knes-applet-ui: Java Applet-based UI (legacy).
NES.mp4

KotlinConf 2025 Presentation: Build your own NES Emulator with Kotlin (click to play)

Build your own NES Emulator with Kotlin | Artur Skowroński

Building and Running

Prerequisites

  • Java 17 or higher (for running Gradle; build targets Java 11)
  • Gradle 9.4+ (included via wrapper)

Building

./gradlew build

Running

./gradlew run

This will launch the main application, which allows choosing between the different UI implementations.

Running Specific UIs

# Compose UI (recommended)
./gradlew :knes-compose-ui:run

# Terminal UI
./gradlew :knes-terminal-ui:run

# Skiko UI
./gradlew :knes-skiko-ui:run

REST API Server

Run the emulator as a headless REST API for AI agents, TAS tools, and automation:

./gradlew :knes-api:run   # starts on port 6502
# Load a ROM
curl -X POST localhost:6502/rom -H 'Content-Type: application/json' \
  -d '{"path": "/path/to/game.nes"}'

# Step 60 frames holding RIGHT
curl -X POST localhost:6502/step -H 'Content-Type: application/json' \
  -d '{"buttons": ["RIGHT"], "frames": 60}'

# Get screenshot
curl localhost:6502/screen -o frame.png

# Get game state
curl localhost:6502/state

12 endpoints: /step, /screen, /state, /watch, /press, /release, /fm2, and more. Full docs in knes-api/README.md.

Architecture

The emulator uses a modular architecture with a clear separation between the core emulator functionality and the UI. This allows for different UI implementations to be used with the same core emulator.

Core Emulator

The core emulator is contained in the knes-emulator module and provides the following components:

  • CPU: 6502 processor — all 56 official opcodes, cycle-accurate
  • PPU: Picture Processing Unit — background tiles, sprites, scrolling, palette
  • PAPU: Audio — square, triangle, noise, and DMC channels
  • Memory: 64KB CPU address space with mirroring
  • Mappers: NROM (Mapper 0) and MMC1 (Mapper 1) with PRG/CHR bank switching

Testing

400+ automated tests covering every layer:

  • CPU instruction tests (all opcodes, all addressing modes)
  • PPU register and rendering logic tests
  • PAPU audio channel tests
  • MMC1 mapper unit tests
  • nestest.nes ROM integration test (community-standard CPU validation)
  • Super Mario Bros E2E game tests (headless, input injection, RAM assertions)
  • REST API E2E tests (game session, screenshot, FM2 playback, batch stepping)
  • Compose Desktop UI smoke tests
./gradlew test

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

vNES was originally developed by Brian F. R. (bfirsh) and released under the GPL-3.0 license. This project is a reimplementation and extension of that work.

About

Educational implementation of NES emulator in Kotlin, based on Java vNES emulator

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Kotlin 90.7%
  • Java 9.2%
  • Shell 0.1%