GithubHelp home page GithubHelp logo

cocoaplayground / chip8 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from indragiek/chip8

0.0 2.0 0.0 121 KB

CHIP-8 emulator and disassembler written in Swift

License: MIT License

Swift 98.82% Objective-C 1.18%

chip8's Introduction

Chip8

CHIP-8 Emulator and Disassembler

This project contains an emulator and disassembler for the CHIP-8 virtual machine written in Swift. Emulation is an area of interest that I hadn't explored much, so I worked on this relatively simple emulator to learn more about it.

Chip8 Emulator

Chip8Kit

Chip8Kit is a library that contains a platform independent, pure Swift implementation of a CHIP-8 emulator and disassembler. It can be compiled as an OS X framework from Xcode using Chip8.xcodeproj, or it can be compiled as a Swift module using Swift Package Manager by running swift build inside the project root directory.

Emulation

import Chip8Kit

do {
	let rom = try ROM(path: "BRIX")
	let emulator = Emulator(rom: rom)
	
	// Emulate a single clock cycle
	// Typically called at a rate of 500Hz
	let state = try emulator.emulateCycle()
	
	// Emulate a single timer tick for the sound and delay timers
	// Should always be called at 60Hz regardless of the master clock rate
	emulator.emulateTimerTick()
	
	// Pass key events to the emulator.
	emulator.setState(true, forKey: .Num1)
} catch let error {	
	print(error)
}

Disassembly

import Chip8Kit

do {
	let rom = try ROM(path: "BRIX")
	
	// Disassemble the ROM and get a list of opcodes
	let opcodes = Disassembler.disassemble(rom)
	
	// ...or pretty print the disassembly
	Disassembler.printDisassembly(rom)
} catch let error {	
	print(error)
}

Chip8

Chip8.app is an OS X application (pictured above) that uses Chip8Kit to emulate and SpriteKit to render the screen. It provides a few simple UI controls for loading ROMs, resetting the emulator, pausing/resuming, and varying the clock rate from 1Hz - 1000Hz.

Keypad

The following default key mapping is used (from here):

Keypad                   Keyboard
+-+-+-+-+                +-+-+-+-+
|1|2|3|C|                |1|2|3|4|
+-+-+-+-+                +-+-+-+-+
|4|5|6|D|                |Q|W|E|R|
+-+-+-+-+       =>       +-+-+-+-+
|7|8|9|E|                |A|S|D|F|
+-+-+-+-+                +-+-+-+-+
|A|0|B|F|                |Z|X|C|V|
+-+-+-+-+                +-+-+-+-+

The key mapping can be customized by setting Chip8View.keyMapping.

Sound

The CHIP-8 can only play a single sound, which is a beep. I couldn't find an appropriately licensed copy of the original sound, so Chip8.app defaults to using the system beep noise in its place. The beep sound can be customized by setting the Chip8View.beepSound property.

ROMs

A collection of public domain ROMs that can be used with this emulator can be found here.

Resources

Contact

License

Chip8 is licensed under the MIT License. See LICENSE.md for more information.

chip8's People

Contributors

indragiek avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.