Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tomassirio/Chip8-Kt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CHIP8-KT

❯ Bringing CHIP-8 classics back to life — now in Kotlin

license last-commit repo-top-language repo-language-count


📚 Table of Contents


🔍 Overview

This implementation of the Chip-8 was a first step on my learning of emulation.

The main goal of this investigation process is to achieve a complete Game Boy Color emulator as it was one that gave me lots of happy times throughout my childhood. This is my way to push myself to further extents as a Recognition to all of those who came up with those emulators at the time

The main ideas behind the project were:

  • Learn how a System can be modeled into an emulator
  • Ignore the memory aspects with a high level language first to learn step-by-step about emulation itself
  • Create an emulator that can work as a reference for others by creating an object-oriented solution
  • Practice modularization of the project by using maven submodules
  • Create the same emulator in a low level language (either c or rust) to make emphasis on memory management
  • Create a Game Boy Color emulator in the low level language selected
  • Make a project till the end :)

✨ Features

Complete CHIP-8 Interpreter: Faithfully executes classic CHIP-8 ROMs.

Written in Kotlin: Modern, concise, and expressive codebase.

Object-Oriented Design: Modular and extensible architecture, easy to understand and maintain.

Keyboard Input Handling: Maps CHIP-8 keys to your physical keyboard for interactive gameplay.

Sound Support: Beep emulation for authentic CHIP-8 audio feedback.

Test ROM Suite: Includes a comprehensive set of test ROMs to verify emulator correctness and compatibility.

Maven Multi-Module Project: Clean separation of concerns between core, UI, controller, and system logic.

Easy to Run & Extend: Simple entry point and clear structure for adding new features or learning about emulation.

Open Source: MIT-licensed and open for contributions!


🏗️ Project Structure

Project structure

This Chip-8 project is divided into 4 Maven submodules.

└── Chip8-Kt/
    ├── chip8-app   - This submodule only contains the Main file
    ├── controller  - A mother board of sorts. Controls tickers and timers
    ├── ui          - JavaFx UI implementation; Handles keyboard 
    ├── roms        - Rom selection
    ├── system      - CPU implementation. Logic layer
    └── pom.xml

To begin fiddling with the emulator I would suggest the system module.

The CPU class holds the state of the memory, registers, display, keyboard, etc. The only method exposed by the cpu is the runCycle() where the cpu will fetch(), decode() and execute(command)

The Commands are implemented from an interface which only method is the execute()

Also, the system supports both the Chip-8 and Super-Chip-8 systems

🗂️ Project Index

CHIP8-KT/
chip8-app
src
main
kotlin
Main.kt ❯ Main File. The program runs from here
system
src
main
kotlin
com
tomassirio
emulation
chip8
system
memory
Memory.kt ❯ Chip8's Cpu Memory. 2048 bytes
preload
FontSet.kt ❯ Fontset. Preloaded in the first 512 bytes
factory
MemoryFactory.kt ❯ Factory to create Memory instances
validator
MemoryValidator.kt ❯ Validates memory locking and overflows
accessor
MemoryAccessor.kt ❯ Utility class to access Memory; Delegates responsibilities
util
MemoryUtils.kt ❯ Memory utility; Could be moved to Accessor
constants
Constants.kt ❯ System Constants
io
display
DisplayScroller.kt ❯ Takes responsibility for Scrolling; Super-Chip-8 feature
PixelBuffer.kt ❯ Manages Pixels
DisplayState.kt ❯ Facade for Display
DisplayType.kt ❯ NORMAL/EXTENDED modes
DisplayModeManager.kt ❯ Manages Display Modes
SpriteDrawer.kt ❯ Draws Sprites
keyboard
KeyboardState.kt ❯ Holds state for keyboard
cpu
CPUType.kt ❯ [CHIP-8/SUPER-CHIP-8]
CPU.kt ❯ Main Class of the System. Fetches/Decodes/Executes code
opcode
Command.kt ❯ Command Interface. Executes commands
OpCodeTable.kt ❯ Holds mapping for all OpCodes
commands
ExitCommand.kt
SUBNVxVyCommand.kt
LDHFVxCommand.kt
LDDTVxCommand.kt
SNEVxByteCommand.kt
RETCommand.kt
LDIVxCommand.kt
SEVxVyCommand.kt
XORVxVyCommand.kt
SCRCommand.kt
SEVxByteCommand.kt
SHRVxCommand.kt
JPAddrCommand.kt
ANDVxVyCommand.kt
HighCommand.kt
CALLAddrCommand.kt
SCDCommand.kt
ORVxVyCommand.kt
LowCommand.kt
CLSCommand.kt
SHLVxCommand.kt
ADDVxVyCommand.kt
ADDIVxCommand.kt
LDVxDTCommand.kt
SNEVxVyCommand.kt
RNDVxByteCommand.kt
LDBVXCommand.kt
LDRVxCommand.kt
LDSTVxCommand.kt
SYSAddrCommand.kt
SUBVxVyCommand.kt
DRWVxVyNCommand.kt
LDVxICommand.kt
LDVxVyCommand.kt
SKPVxCommand.kt
LDVxRCommand.kt
LDIToAddrCommand.kt
LDVxByteCommand.kt
LDVxKCommand.kt
SCLCommand.kt
ADDVxByteCommand.kt
LDFVxCommand.kt
JPAddrV0Command.kt
SKNPVxCommand.kt
factory
CPUFactory.kt ❯ Creates CPU Instances
utils
SizedStack.kt ❯ Implementation of Stack with limited entries
exception
CPUNotFoundException.kt
RegisterNotFoundException.kt
CommandNotFoundException.kt
register
Register.kt ❯ [ByteRegister/ShortRegister/TimerRegister]
Timer.kt ❯ Timer interface with Tick method
utils
RegisterSet.kt ❯ Util class
controller
src
main
kotlin
com
tomassirio
emulation
chip8
controller
SystemController.kt ❯ Facades the CPU; Works as a Main Board
sfx
SoundPlayer.kt ❯ Plays Sounds. Uses beep.wav
loader
RomLoader.kt ❯ Loads Roms
debug
DebugLevel.kt ❯ [NONE/MINIMAL/FULL]
CPUDebugger.kt ❯ Debugger class for CPU
handler
KeyHandler.kt ❯ Works on key events
resources
beep.wav ❯ Sound resource
ui
src
main
kotlin
com
tomassirio
emulation
chip8
ui
EmulatorUI.kt ❯ Main Emulator class
mapping
KeyMapper.kt ❯ Maps Keys to Chip8 keyboard
params
EmulatorParamsFactory.kt ❯ Gets parameters from Arguments
EmulatorParams.kt ❯ Holds Emulator Params
pane
DebuggingPane.kt ❯ Dividing pane for CPU and Memory State
CPUStatePane.kt ❯ CPU State Pane
MemoryPane.kt ❯ Memory Pane
constants
Constants.kt ❯ UI Constants
debug
Debug.kt ❯ Debbugger interface
scene
MainScene.kt ❯ Main Scene where action happens

🚀 Getting Started

🧰 Prerequisites

Before getting started with Chip8-Kt, ensure your runtime environment meets the following requirements:

  • Programming Language: Kotlin
  • Packaging: Maven

💾 Installation

Install Chip8-Kt using one of the following methods:

Build from source:

  1. Clone the Chip8-Kt repository:
❯ git clone https://github.com/tomassirio/Chip8-Kt
  1. Navigate to the project directory:
cd Chip8-Kt
  1. Install the project dependencies:
❯ mvn clean install

🕹 Usage

In order to run the project you will need a rom. This repository provides a selection of them in the /roms folder.

So after running mvn clean install you can just begin playing roms with

❯ java -jar chip8-app/target/chip8-app-1.0.0.jar --rom=roms/games/PONG     

🔡 Parameters

This implementation of the Chip-8 console includes a few options you can play around with

--rom     [Mandatory] declares path to rom
--cpu     [CHIP8/SCHIP8](default=CHIP8) defines which system to emulate between the Chip-8 and Super-Chip
--debug   [NONE/MINIMAL/FULL](default=NONE) debugging windows
--scale   [Int](default=10) scale for the pixels in the screen
--fps     [Int](default=15) Frames per second at which the rom will run

✅ Testing

This project allows for two different types of testing. Both Unit tests and 'Rom-tests'

For the Unit tests you can test your project with

❯ mvn test

or you can compile and test it with

❯ mvn clean verify 

The project can also be tested with the 'Rom-Tests' in the roms folder. Each of them can be ran as any other rom

❯ java -jar chip8-app/target/chip8-app-1.0.0.jar --rom=roms/test-suite/1-chip8-logo.ch8     
roms
test-suite
1-chip8-logo.ch8 ❯ Should print a Chip-8 logo
2-ibm-logo.ch8 ❯ Should print an IBM logo
3-corax+.ch8 ❯ Corax+ test ROM
4-flags.ch8 ❯ Tests flag instructions
5-quirks.ch8 ❯ Tests common CHIP-8 quirks
6-keypad.ch8 ❯ Tests keypad input
7-beep.ch8 ❯ Tests sound/beep functionality
8-scrolling.ch8 ❯ Tests scrolling instructions

🛣️ Project Roadmap

  • Task 1: Implement Chip-8 in Kotlin
  • Task 2: Implement Chip-8 in Rust
  • Bonus Task: Implement Nes in mmBASIC
  • Task 3: Implement Gameboy Color in Rust

🤝 Contributing

Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/tomassirio/Chip8-Kt
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b feature/[ticket#]new_feature_x
    • Please use feature/ bugfix/ hotfix/ depending on the case
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
  6. Push to GitHub: Push the changes to your forked repository.
    git push origin feature/[ticket#]new_feature_x
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
  8. Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
Contributor Graph


📚 Reference


About

A Chip-8 implementation in Kotlin following Object oriented programming and Maven Submoduling

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Languages