chip8

package module
v0.0.0-...-e978dc3 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 6 Imported by: 0

README

go-chip8

CHIP-8 emulator in Go.

termbox is used for default implementation for graphics and input.

Architecture

Struct that contains the internals of CHIP-8 emulator. Emulator

  • CPU - contains
  • Memory
  • Graphics (interarface)
  • Input (interface)

CLIs:

  • chip8 : CHIP-8 emulator that can run binaries
  • TODO: disassembler

References

Documentation

Index

Constants

View Source
const (
	DisplayWidth  uint8 = 64
	DisplayHeigth uint8 = 32
)

Variables

This section is empty.

Functions

func OpKK

func OpKK(op uint16) uint16

kk or byte - An 8-bit value, the lowest 8 bits of the instruction

func OpN

func OpN(op uint16) uint16

n or nibble - A 4-bit value, the lowest 4 bits of the instruction

func OpNNN

func OpNNN(op uint16) uint16

nnn or addr - A 12-bit value, the lowest 12 bits of the instruction

func OpNr

func OpNr(op uint16) uint16

Get opcode number (highest 4bits)

func OpNr0

func OpNr0(op uint16, r *CPU, m *Memory, d Graphics) error

func OpNr1

func OpNr1(op uint16, r *CPU, m *Memory) error

1nnn - JP addr Jump to location nnn.

func OpNr2

func OpNr2(op uint16, r *CPU, m *Memory) error

2nnn - CALL addr Call subroutine at nnn.

func OpNr3

func OpNr3(op uint16, r *CPU, m *Memory) error

3xkk - SE Vx, byte Skip next instruction if Vx = kk.

func OpNr4

func OpNr4(op uint16, r *CPU, m *Memory) error

4xkk - SNE Vx, byte Skip next instruction if Vx != kk.

func OpNr5

func OpNr5(op uint16, r *CPU, m *Memory) error

5xy0 - SE Vx, Vy Skip next instruction if Vx = Vy.

func OpNr6

func OpNr6(op uint16, r *CPU, m *Memory) error

6xkk - LD Vx, byte Set Vx = kk.

func OpNr7

func OpNr7(op uint16, r *CPU, m *Memory) error

7xkk - ADD Vx, byte Set Vx = Vx + kk.

func OpNr8

func OpNr8(op uint16, r *CPU, m *Memory) error

func OpNr9

func OpNr9(op uint16, r *CPU, m *Memory) error

9xy0 - SNE Vx, Vy Skip next instruction if Vx != Vy.

func OpNrA

func OpNrA(op uint16, r *CPU, m *Memory) error

Annn - LD I, addr Set I = nnn.

func OpNrB

func OpNrB(op uint16, r *CPU, m *Memory) error

Bnnn - JP V0, addr Jump to location nnn + V0.

func OpNrC

func OpNrC(op uint16, r *CPU, m *Memory) error

Cxkk - RND Vx, byte Set Vx = random byte AND kk.

func OpNrD

func OpNrD(op uint16, r *CPU, m *Memory, d Graphics) error

Dxyn - DRW Vx, Vy, nibble Display n-byte sprite starting at memory location I at (Vx, Vy), set VF = collision.

func OpNrE

func OpNrE(op uint16, r *CPU, m *Memory) error

func OpNrF

func OpNrF(op uint16, r *CPU, m *Memory) error

func OpX

func OpX(op uint16) uint16

x - A 4-bit value, the lower 4 bits of the high byte of the instruction

func OpY

func OpY(op uint16) uint16

y - A 4-bit value, the upper 4 bits of the low byte of the instruction

Types

type CPU

type CPU struct {
	V     [16]byte
	I     uint16
	DT    byte       // delay timer
	ST    byte       // sound timer
	PC    uint16     // program counter
	SP    byte       // stack pointer
	Stack [16]uint16 // stack
}

func (*CPU) Init

func (cpu *CPU) Init() error

func (*CPU) String

func (r *CPU) String() string

type Emulator

type Emulator struct {
	CPU      CPU
	Memory   Memory
	Graphics Graphics
	Input    Input
	// contains filtered or unexported fields
}

func CreateDefaultEmulator

func CreateDefaultEmulator() (*Emulator, error)

func CreateEmulator

func CreateEmulator(graphics Graphics, input Input) (*Emulator, error)

func (*Emulator) Close

func (e *Emulator) Close()

func (*Emulator) LoadProgram

func (e *Emulator) LoadProgram(b []byte) error

func (*Emulator) Run

func (e *Emulator) Run() error

func (*Emulator) Step

func (e *Emulator) Step(delayTick bool) error

type ErrOpcodeNotImplemented

type ErrOpcodeNotImplemented uint16

func (ErrOpcodeNotImplemented) Error

func (e ErrOpcodeNotImplemented) Error() string

type ErrOutOfBounds

type ErrOutOfBounds struct {
	// contains filtered or unexported fields
}

func (ErrOutOfBounds) Error

func (e ErrOutOfBounds) Error() string

type ErrUnknownOpcode

type ErrUnknownOpcode uint16

func (ErrUnknownOpcode) Error

func (e ErrUnknownOpcode) Error() string

type Graphics

type Graphics interface {
	Init() error
	Close()
	Clear()
	Draw(x, y byte, sprite []byte) (collision byte)
}

type GraphicsTermbox

type GraphicsTermbox struct {
	// contains filtered or unexported fields
}

func (*GraphicsTermbox) Clear

func (d *GraphicsTermbox) Clear()

func (*GraphicsTermbox) Close

func (d *GraphicsTermbox) Close()

func (*GraphicsTermbox) Draw

func (d *GraphicsTermbox) Draw(x, y byte, sprite []byte) (collision byte)

func (*GraphicsTermbox) Init

func (d *GraphicsTermbox) Init() error

type Input

type Input interface {
	Init() error
	Close()
	WaitForEvent()
}

type InputTermbox

type InputTermbox struct{}

func (*InputTermbox) Close

func (k *InputTermbox) Close()

func (*InputTermbox) Init

func (k *InputTermbox) Init() error

func (*InputTermbox) WaitForEvent

func (k *InputTermbox) WaitForEvent()

type Memory

type Memory [4096]byte

func (*Memory) Init

func (m *Memory) Init() error

func (*Memory) Load

func (m *Memory) Load(address int, data []byte) error

type OpError

type OpError struct {
	// contains filtered or unexported fields
}

func (*OpError) Error

func (err *OpError) Error() string

Directories

Path Synopsis
cli
chip8 command

Jump to

Keyboard shortcuts

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