Chip8EmulatorPackage
A Chip-8 emulator Swift package. For use in macOS, iOS, watchOS and tvOS projects.
Install / Use
/learn @ryanggrey/Chip8EmulatorPackageREADME
Chip 8 Emulator Swift Package
A Chip-8 emulator Swift package. For use in macOS, iOS, watchOS and tvOS projects.
This package implements the core functionality of a Chip-8 emulator in Swift. It contains no platform UI elements and this is left to a consumer projects to implement.
Design
The emulator package contains a Chip8Engine which drives the Chip-8 run loop.
Start the engine
chip8Engine.start()
Stop the engine
chip8Engine.stop()
Feed inputs into the engine
chip-8 keys (Chip8InputCode)
chip8Engine.handleKeyDown(key: key)chip8Engine.handleKeyUp(key: key)
Receive callbacks from the engine
The callbacks are handled through the delegate pattern. Set the delegate of the engine:
override func viewDidLoad() {
super.viewDidLoad()
chip8Engine.delegate = self
}
Rendering
The engine will call the delegate render method when the engine determines that a render of the pixels is necessary.
This will only be called when the pixels have changed. The engine assumes that pixels have been rendered on a call to the delegate and will not re-call with the same pixels.
Implement the rendering method:
extension YourViewController: Chip8EngineDelegate {
func render(screen: Chip8Screen) {
// ...
}
}
Beeping
The engine will call the delegate beep method when the engine determines that a sound effect needs to be played.
Implement the beep method using the provided BeepPlayer (or through a custom implementation):
extension YourViewController: Chip8EngineDelegate {
func beep() {
beepPlayer.play()
// haptics etc.
}
}
Consumer Projects
- chip-8-macOS
- chip-8-watchOS
- chip-8-tvOS
- CHIP8AR (iOS, AR)
- chip-8-web (Web, SwiftWasm)
Assets
ROMs
The ROMs bundled into this project are from https://github.com/dmatlack/chip8
Sounds
beep.wav file in Assets is from Mixkit, originally titled mixkit-player-jumping-in-a-video-game-2043.wav. See here for Mixkit license.
References
I made heavy use of the following resources when working on this project:
- Checking runtime correctness:
- https://colineberhardt.github.io/wasm-rust-chip8/web/
- http://johnearnest.github.io/Octo/
- Specs:
- https://en.wikipedia.org/wiki/CHIP-8
- http://devernay.free.fr/hacks/chip8/C8TECH10.HTM
- Checking code/logic correctness:
- http://emulator101.com
- https://github.com/davecom/ChipLate
Related Skills
node-connect
348.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
348.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
348.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
