Documentation ¶
Index ¶
- Constants
- Variables
- func InvalidJumpError(fromAddr, toAddr uint16) error
- func InvalidProgramError(msg string) error
- func InvalidStateError(msg string) error
- type Emulator
- type EmulatorEvent
- type EmulatorOptions
- type VirtualMachine
- func (vm *VirtualMachine) Clear()
- func (vm *VirtualMachine) ClearDisplay()
- func (vm *VirtualMachine) ClearKeys()
- func (vm *VirtualMachine) ClearProgram()
- func (vm *VirtualMachine) ClearRegisters()
- func (vm *VirtualMachine) Reset()
- func (vm *VirtualMachine) RunCycle() error
- func (vm *VirtualMachine) UpdateTimers()
Constants ¶
const ( // DefaultHertzIO is the default speed (in hertz) in which to update // the IO timers and audio. DefaultHertzIO = 16 * time.Millisecond // DefaultHertzVM is the default speed (in hertz) in which to run a // CPU cycle of the CHIP-8 virtual machine. DefaultHertzVM = 2 * time.Millisecond // DefaultMaxTPS is the default max ticks-per-second (TPS) of the // renderer. DefaultMaxTPS = 60 // DefaultScale is the default scale factor of the CHIP-8 screen. DefaultScale = 10 // FontSize is the number of bytes in a CHIP-8 built-in font. FontSize = 0x5 // MaxStackDepth is the maximum depth of the CHIP-8 virtual // machine's call stack. MaxStackDepth = 0x10 // MemorySize is the total amount of memory available in the CHIP-8 // virtual machine. MemorySize = 0x1000 // DisplayWidth is the width (in pixels) of the CHIP-8 display. DisplayWidth = 0x40 // DisplayHeight is the height (in pixels) of the CHIP-8 display. DisplayHeight = 0x20 // NumberOfKeys is the number of keys in the CHIP-8 keyboard. NumberOfKeys = 0x10 // NumberOfFonts is the total number of built-in fonts in the // CHIP-8 virtual machine. NumberOfFonts = 0x10 // NumberOfPixels is the total number of pixels in the CHIP-8 // display. NumberOfPixels = DisplayWidth * DisplayHeight // NumberOfRegisters is the number of general-purpose registers in // the CHIP-8 virtual machine. NumberOfRegisters = 0x10 // ProgramStartAddress is the start memory location where programs // are loaded in the virtual machine's memory. ProgramStartAddress = 0x200 // ProgramMemorySize is the total amount of memory available for // CHIP-8 programs. ProgramMemorySize = MemorySize - ProgramStartAddress )
Variables ¶
var ErrTerminated = errors.New("Emulator terminated")
Functions ¶
func InvalidJumpError ¶
InvalidJumpError is an error caused by a program trying to jump to an invalid memory location.
func InvalidProgramError ¶
InvalidProgramError is an error that occurs from loading a program.
func InvalidStateError ¶
InvalidStateError is an error that occurs due to bad state in the virtual machine.
Types ¶
type Emulator ¶
type Emulator struct {
// contains filtered or unexported fields
}
Emulator is the CHIP-8 emulator.
func NewEmulator ¶
func NewEmulator(opts EmulatorOptions) (*Emulator, error)
NewEmulator creates a new CHIP-8 emulator instance.
func (*Emulator) Draw ¶
func (emu *Emulator) Draw(screen *ebiten.Image)
Draw renders the screen of the emulator.
func (*Emulator) LoadBytes ¶
LoadBytes reads bytes into the virtual machine's memory.
Note that the bytes will loaded into memory starting at address 0x200, the start address of the virtual machine's program memory.
type EmulatorEvent ¶
type EmulatorEvent string
EmulatorEvent is an event that occurs that controls the state of the emulator.
type EmulatorOptions ¶
type EmulatorOptions struct { // Scale is the scale factor of the CHIP-8 screen. Scale int }
EmulatorOptions is a set of arguments that allows you to set different options in the emulator.
type VirtualMachine ¶
type VirtualMachine struct { I uint16 SP uint8 PC uint16 DT uint8 ST uint8 Opcode uint16 V [NumberOfRegisters]uint8 Stack [MaxStackDepth]uint16 Memory [MemorySize]uint8 Keys [NumberOfKeys]bool Display [DisplayHeight][DisplayWidth]bool }
VirtualMachine is the CHIP-8 virtual machine.
func NewVirtualMachine ¶
func NewVirtualMachine() *VirtualMachine
NewVirtualMachine creates new CHIP-8 virtual machine instance.
func (*VirtualMachine) Clear ¶
func (vm *VirtualMachine) Clear()
Clear clears the entire state of the virtual machine.
func (*VirtualMachine) ClearDisplay ¶
func (vm *VirtualMachine) ClearDisplay()
ClearDisplay clears the state of the display.
func (*VirtualMachine) ClearKeys ¶
func (vm *VirtualMachine) ClearKeys()
ClearKeys clears the state of the keys.
func (*VirtualMachine) ClearProgram ¶
func (vm *VirtualMachine) ClearProgram()
ClearProgram clears the program loaded in the virtual machine.
func (*VirtualMachine) ClearRegisters ¶
func (vm *VirtualMachine) ClearRegisters()
ClearRegisters clears all the registers, including the program counter, timers, stack pointer.
func (*VirtualMachine) Reset ¶
func (vm *VirtualMachine) Reset()
Reset resets the virtual machine.
This preserves the program/opcodes already loaded in memory.
func (*VirtualMachine) RunCycle ¶
func (vm *VirtualMachine) RunCycle() error
RunCycle runs a single CPU cycle of the virtual machine.
func (*VirtualMachine) UpdateTimers ¶
func (vm *VirtualMachine) UpdateTimers()
UpdateTimers updates the delay and sound timers.