Pet project to write a Chip-8 emulator with go.
The idea of the repository is to provide a chip8 emulator to be used with any display, keyboard and speaker interface. This is done by satisfying the interfaces as shown below.
// Display defines the interface required
// to mimic the screen for a chip 8.
type Display interface {
// DrawFrame is called when once frame of display is done setting/clearing
DrawFrame()
// ClearPixel clears the pixel at location x,y or (row,col)
ClearPixel(x, y int)
// SetPixel sets the pixel at location x,y or (row,col)
SetPixel(x, y int)
// ClearAll should clear all the pixels
ClearAll()
}
// Keyboard exposes mapping to emulator defined keys
// Refer http://devernay.free.fr/hacks/chip8/C8TECH10.HTM#keyboard
type Keyboard interface {
PressedKeys() map[int]bool
}
// Speaker acts as a sound device for the emulator
type Speaker interface {
// Beep should play some sound
Beep()
// Pause should pause any sound that's playing
Pause()
}
With the interfaces, you can create a Chip-8 instance and run it as follows
import chip8 "github.com/kunalpowar/gochip8"
c := chip8.New(myDisplay, myKeyboard, mySpeaker)
c.RunOnce()
Refer to goc8sdl
which uses sdl2 based Display and Keyboard.
You can install the cmd and use it as follows. Please install sdl2 requirements for this to work.
go install github.com/kunalpowar/gochip8/cmd/goc8sdl
goc8sdl -rom <rom file>
Refer to goc8gif
which takes advantage of the Display
interface to output a gif of running 1000 cycles.
go install github.com/kunalpowar/gochip8/cmd/goc8gif
# Runs the emulator for 1000 cycles and outputs a out.gif of the display
goc8gif -rom <rom file>
- Update sdl cmd with sound device
- WASM support?