Skip to content

kunalpowar/gochip8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chip-8 Emulator with Go

Go Report Card Go Reference

Chip 8 Picture ROM generated by goc8gif

Pet project to write a Chip-8 emulator with go.

References

Description

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()

Examples

SDL2 Player

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>

GIF

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>

TODOs and Experiments

  • Update sdl cmd with sound device
  • WASM support?

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages