emulator

package
v0.0.0-...-1e2f6ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_CLOCK_SPEED = 16 * time.Millisecond // 60hz
View Source
const DEFAULT_IPF = 1200 // Instructions per frame
View Source
const DISPLAY_HEIGHT = 32
View Source
const DISPLAY_SIZE = DISPLAY_WIDTH * DISPLAY_HEIGHT
View Source
const DISPLAY_WIDTH = 64
View Source
const FONT_START = 0x50
View Source
const FRAME_BUFFER_LENGTH = 3
View Source
const MEM_SIZE = 4 * 1024 // 4kb
View Source
const ROM_START = uint16(0x200)

Variables

View Source
var ErrInvalidOpcode = fmt.Errorf("invalid opcode")
View Source
var FONT = [5 * 16]byte{
	0xF0, 0x90, 0x90, 0x90, 0xF0,
	0x20, 0x60, 0x20, 0x20, 0x70,
	0xF0, 0x10, 0xF0, 0x80, 0xF0,
	0xF0, 0x10, 0xF0, 0x10, 0xF0,
	0x90, 0x90, 0xF0, 0x10, 0x10,
	0xF0, 0x80, 0xF0, 0x10, 0xF0,
	0xF0, 0x80, 0xF0, 0x90, 0xF0,
	0xF0, 0x10, 0x20, 0x40, 0x40,
	0xF0, 0x90, 0xF0, 0x90, 0xF0,
	0xF0, 0x90, 0xF0, 0x10, 0xF0,
	0xF0, 0x90, 0xF0, 0x90, 0x90,
	0xE0, 0x90, 0xE0, 0x90, 0xE0,
	0xF0, 0x80, 0x80, 0x80, 0xF0,
	0xE0, 0x90, 0x90, 0x90, 0xE0,
	0xF0, 0x80, 0xF0, 0x80, 0xF0,
	0xF0, 0x80, 0xF0, 0x80, 0x80,
}

TODO: make this configurable

Functions

This section is empty.

Types

type Emulator

type Emulator interface {
	Keypad

	// LoadFile loads a ROM file from disk into emulator memory.
	LoadFile(path string) error

	// LoadBuffer loads a ROM file from a buffer into emulator memory.
	LoadBuffer(buf io.Reader) error

	// Cycle runs one CPU cycle.
	Cycle() error

	// Run runs the emulator in the background. Call Stop() to end it.
	Run()

	// Stop stops the background emulation process.
	Stop()

	// Frame returns the most recent frame from the display buffer
	Frame() *image.RGBA
}

func NewEmulator

func NewEmulator(rom_path string, clockSpeed time.Duration) (Emulator, error)

NewEmulator takes a path to a ROM file and returns an Emulator with that ROM loaded.

func NewEmulatorFromBuf

func NewEmulatorFromBuf(buf io.Reader, clockSpeed time.Duration) (Emulator, error)

NewEmulatorFromBuf takes a ROM buffer and returns an Emulator with that ROM loaded.

type Keypad

type Keypad interface {
	Pressed(uint8) bool
	Press(uint8) Keypad
	Release(uint8) Keypad
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL