chip8

package module
v0.0.0-...-9ca465c Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 4 Imported by: 0

README

GO CHIP-8

A toolkit to make a interpreter to CHIP-8 builded with GO.


List of interpreters of CHIP-8 builded with this package

CHIP-8 tcell

Builded with this package and tcell

Documentation

Index

Constants

View Source
const Black = "■"
View Source
const White = "□"

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigCpu

type ConfigCpu struct {
	// Externals devices
	Display  Display
	Keyboard Keyboard
	Sound    Sound
	Memory   Memory
	Stack    Stack
	Log      io.Writer

	// Registers
	Register Register
	I        uint16

	// Pseudo Registers
	PC uint16
	SP byte
	DT byte
	ST byte
}

type ConfigDisplay

type ConfigDisplay struct {
	Output io.Writer
}

type ConfigKeyboard

type ConfigKeyboard struct {
	Input io.Reader
}

type ConfigMemory

type ConfigMemory struct {
	Rom io.Reader
	Log io.Writer
}

type Cpu

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

func NewCpu

func NewCpu(config *ConfigCpu) *Cpu

NewCpu receives params and return a pointer to Cpu

func (*Cpu) Log

func (c *Cpu) Log()

Log writes values of registers to "log" of Cpu

func (*Cpu) NextInstruction

func (c *Cpu) NextInstruction() uint16

func (*Cpu) Process

func (c *Cpu) Process(instr Instruction) error

Process is a function that process a instruction

func (*Cpu) Start

func (c *Cpu) Start()

Start the interpreter

type Display

type Display interface {
	/*
		Clear should clear the display
	*/
	Clear()

	/*
		Draw should draw the byte on position xDisplay and yDisplay
		If occourres collision returns true
	*/
	Draw(xDisplay, yDisplay, sprite byte) bool

	/*
		Flush should write on output of display
	*/
	Flush()
}

type Instruction

type Instruction []byte

func (*Instruction) GetN

func (instr *Instruction) GetN() (byte, error)

GetN returns the parameter N of instruction

func (*Instruction) GetNN

func (instr *Instruction) GetNN() (byte, error)

GetNN returns the parameter NN of instruction

func (*Instruction) GetNNN

func (instr *Instruction) GetNNN() (uint16, error)

GetNNN returns the parameter NNN of instruction

func (*Instruction) GetTypeAndSubType

func (instr *Instruction) GetTypeAndSubType() (t InstructionType, s InstructionSubType, err error)

func (*Instruction) GetX

func (instr *Instruction) GetX() (byte, error)

GetX returns the parameter X of instruction

func (*Instruction) GetY

func (instr *Instruction) GetY() (byte, error)

GetY returns the parameter Y of instruction

type InstructionSubType

type InstructionSubType byte

type InstructionType

type InstructionType byte

type Key

type Key byte

type Keyboard

type Keyboard interface {
	/*
		KeyDown should return a Key mapping the input to any key of CHIP-8 (0x00 - 0x0F).
		When none key is down return Key(0xFF)
	*/
	KeyDown() Key
}

type Memory

type Memory interface {
	/*
		Save should saves the register on the memory starting from I on memory
	*/
	Save(register []byte, i uint16)

	/*
		SaveBCD should convert vx to decimal and saves each decimal on addresses I, I+1, I+2
	*/
	SaveBCD(vx byte, i uint16)

	/*
		Load should loads the register on the memory starting from I on memory
	*/
	Load(register []byte, i uint16)

	/*
		LoadInstruction should loads the instruction (2 bytes) of program
	*/
	LoadInstruction(pc uint16) Instruction

	/*
		LoadChar should return the address of char referring to vx
	*/
	LoadChar(vx byte) uint16

	/*
		LoadSprite should return the Sprite on I
	*/
	LoadSprite(i uint16) byte
}

type Register

type Register [0x10]byte

type Sound

type Sound interface {
	/*
		Beep should go off a beep when called
	*/
	Beep()
}

type Stack

type Stack [0x10]uint16

type StandardDisplay

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

StandardDisplay implements interface Display

func NewStandardDisplay

func NewStandardDisplay(config *ConfigDisplay) *StandardDisplay

NewStandardDisplay is a function that receive a config as param and return a pointer to StandardDisplay

func (*StandardDisplay) Clear

func (sd *StandardDisplay) Clear()

Clear sets all pixels to 0

func (*StandardDisplay) Draw

func (sd *StandardDisplay) Draw(xDisplay, yDisplay, sprite byte) bool

Draw draws a sprint on position xDisplay and yDisplay

func (*StandardDisplay) Flush

func (sd *StandardDisplay) Flush()

Flush is a function that paint the screen with information of attribute "screen"

type StandardKeyboard

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

StandardKeyboard implements KeyBoard It's just useful for example "terminal.go"

func NewStandardKeyboard

func NewStandardKeyboard(config *ConfigKeyboard) *StandardKeyboard

NewStandardKeyboard is a function that receive a config as param and return a pointer to StandardKeyboard

func (*StandardKeyboard) KeyDown

func (sk *StandardKeyboard) KeyDown() Key

KeyDown check the input and translate to CHIP-8

type StandardMemory

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

StandardMemory implements interface Memory

func NewStandardMemory

func NewStandardMemory(config *ConfigMemory) *StandardMemory

NewStandardMemory is a function that receive a config as param and return a pointer to StandardMemory

func (*StandardMemory) Load

func (sm *StandardMemory) Load(register []byte, i uint16)

Load loads to the register from of memory starting on register I

func (*StandardMemory) LoadChar

func (sm *StandardMemory) LoadChar(vx byte) uint16

LoadChar returns the address to char VX

func (*StandardMemory) LoadInstruction

func (sm *StandardMemory) LoadInstruction(pc uint16) Instruction

LoadInstruction returns the instruction addressed by register PC

func (*StandardMemory) LoadSprite

func (sm *StandardMemory) LoadSprite(i uint16) byte

LoadSprit returns the sprite on position I

func (*StandardMemory) Log

func (sm *StandardMemory) Log()

Log writes values of memory to "log" of Memory

func (*StandardMemory) Save

func (sm *StandardMemory) Save(register []byte, i uint16)

Save saves the registers on memory starting on register I

func (*StandardMemory) SaveBCD

func (sm *StandardMemory) SaveBCD(vx byte, i uint16)

SaveBCD convert vx byte to decimal and save each digit on I, I+1 and I+2

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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