chip8

package
v0.0.0-...-583f887 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2017 License: MIT Imports: 7 Imported by: 0

README

###Opcode dispatcher

  • Error handling

###Utils vx vy extractor

###Testing ####Instructions

  • 8???
  • DXYN (collide, no print, height, simple print)
  • E???
  • F???

####Dispatch

####Utils

  • LoadRom
  • Fetch
  • Decode

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CheckInputs = func(m *Memory) (bool, byte) {
	for i := range m.Key {
		m.Key[i] = false
	}
	ev := termbox.PollEvent()
	if ev.Type == termbox.EventKey {
		str := string(ev.Ch)
		if str >= "A" {
			str = strings.ToLower(str)
		}
		switch str {
		case "3":
			m.Key[0] = true
			return true, 0
		case "4":
			m.Key[1] = true
			return true, 1
		case "5":
			m.Key[2] = true
			return true, 2
		case "6":
			m.Key[3] = true
			return true, 3
		case "e":
			m.Key[4] = true
			return true, 4
		case "r":
			m.Key[5] = true
			return true, 5
		case "t":
			m.Key[6] = true
			return true, 6
		case "y":
			m.Key[7] = true
			return true, 7
		case "d":
			m.Key[8] = true
			return true, 8
		case "f":
			m.Key[9] = true
			return true, 9
		case "g":
			m.Key[10] = true
			return true, 10
		case "h":
			m.Key[11] = true
			return true, 11
		case "c":
			m.Key[12] = true
			return true, 12
		case "v":
			m.Key[13] = true
			return true, 13
		case "b":
			m.Key[14] = true
			return true, 14
		case "n":
			m.Key[15] = true
			return true, 15
		}
	}
	return false, 0
}

CheckInputs verify if there is a key pressed and then set the Key array accordingly

Functions

func ASetAddressRegister

func ASetAddressRegister(m *Memory, opcode uint16)

ASetAddressRegister is the ANNN opcode which set the Address register I to NNN

func BJumpToV0

func BJumpToV0(m *Memory, opcode uint16)

BJumpToV0 is the BNNN opcode which jump to the address V0 + NNN

func CSetToRandomNumber

func CSetToRandomNumber(m *Memory, opcode uint16)

CSetToRandomNumber is the CXNN opcode which set VX to a random number and NN

func DWrapsOnScreen

func DWrapsOnScreen(m *Memory, opcode uint16)

DWrapsOnScreen is the DXYN opcode which draw sprites

func EDispatcher

func EDispatcher(m *Memory, opcode uint16)

EDispatcher is the E??? opcodes dispatcher

func ESkipIfKeyNotPress

func ESkipIfKeyNotPress(m *Memory, opcode uint16)

ESkipIfKeyNotPress is the EXA1 opcode which skip the next instruction if the key stored in VX is not pressed

func ESkipIfKeyPress

func ESkipIfKeyPress(m *Memory, opcode uint16)

ESkipIfKeyPress is the EX9E opcode which skip the next instruction if the key stored in VX is pressed

func EightDispatcher

func EightDispatcher(m *Memory, opcode uint16)

EightDispatcher is the dispatcher for 8XY? opcodes

func EightFiveSub

func EightFiveSub(m *Memory, opcode uint16)

EightFiveSub is the 8XY5 opcode which set VX to VX-VY

func EightFourAdd

func EightFourAdd(m *Memory, opcode uint16)

EightFourAdd is the 8XY4 opcode which Adds VY to VX. VF is set to 1 when there's a carry, and to 0 when there isn't

func EightFourteenLeftShift

func EightFourteenLeftShift(m *Memory, opcode uint16)

EightFourteenLeftShift is the 8XYE opcode which shifts VX left by one

func EightOneORSet

func EightOneORSet(m *Memory, opcode uint16)

EightOneORSet is the 8XY1 opcode which sets VX to VX OR VY

func EightSevenMinus

func EightSevenMinus(m *Memory, opcode uint16)

EightSevenMinus is the 8XY7 opcode which set VX to VY-VX

func EightSixRightShift

func EightSixRightShift(m *Memory, opcode uint16)

EightSixRightShift is the 8XY6 opcode which shifts VX right by one

func EightThreeXORSet

func EightThreeXORSet(m *Memory, opcode uint16)

EightThreeXORSet is the 8XY3 opcode which sets VX to VX XOR VY

func EightTwoANDSet

func EightTwoANDSet(m *Memory, opcode uint16)

EightTwoANDSet is the 8XY2 opcode which sets VX to VX AND VY

func EightZeroSet

func EightZeroSet(m *Memory, opcode uint16)

EightZeroSet is the 8XY0 opcode which sets VX to the value of VY

func FAddVXToI

func FAddVXToI(m *Memory, opcode uint16)

FAddVXToI is the FX1E opcode which adds VX to I

func FBCD

func FBCD(m *Memory, opcode uint16)

FBCD is the FX33 opcode which stores the Binary-coded decimal representation of VX, with the most significant of three digits at the address in I, the middle digit at I plus 1, and the least significant digit at I plus 2.

func FDispatcher

func FDispatcher(m *Memory, opcode uint16)

FDispatcher is the dispatcher for FNNN opcodes

func FGoToSprite

func FGoToSprite(m *Memory, opcode uint16)

FGoToSprite is the FX29 opcode which sets I to the location of the sprite for the character in VX

func FReadMemory

func FReadMemory(m *Memory, opcode uint16)

FReadMemory is the FX65 opcode which fills V0 to VX with values from memory starting at address I

func FSetDelayTimerToVX

func FSetDelayTimerToVX(m *Memory, opcode uint16)

FSetDelayTimerToVX is the FX15 opcode which sets the delay timer to VX

func FSetSoundTimerToVX

func FSetSoundTimerToVX(m *Memory, opcode uint16)

FSetSoundTimerToVX is the FX18 opcode which sets the sound timer to VX

func FSetVXtoDelayTimer

func FSetVXtoDelayTimer(m *Memory, opcode uint16)

FSetVXtoDelayTimer is the FX07 opcode which sets VX to the value of the delay timer

func FWaitKeyPress

func FWaitKeyPress(m *Memory, opcode uint16)

FWaitKeyPress is the FX0A opcode which wait a key press and then stores it in VX

func FWriteMemory

func FWriteMemory(m *Memory, opcode uint16)

FWriteMemory is the FX55 opcode which stores V0 to VX in memory starting at address I

func FiveEqSkip

func FiveEqSkip(m *Memory, opcode uint16)

FiveEqSkip is the 5XY0 opcode which skips the next instruction if VX equals VY.

func FourNeqSkip

func FourNeqSkip(m *Memory, opcode uint16)

FourNeqSkip is the 4XNN opcode which skips the next instruction if VX not equals NN

func NineNeqSkip

func NineNeqSkip(m *Memory, opcode uint16)

NineNeqSkip is the 9XY0 opcode which skips the next instruction if VX doesn't equal VY

func OneJumpTo

func OneJumpTo(m *Memory, opcode uint16)

OneJumpTo is the 1NNN opcode which jump to the NNN address

func SevenAddToRegister

func SevenAddToRegister(m *Memory, opcode uint16)

SevenAddToRegister is the 7XNN opcode which add NN to VX

func SixSetRegister

func SixSetRegister(m *Memory, opcode uint16)

SixSetRegister is the 6XNN opcode which set VX to NN

func ThreeEqSkip

func ThreeEqSkip(m *Memory, opcode uint16)

ThreeEqSkip is the 3XNN opcode which skip the next instruction if VX equals NN

func TwoCallSubRoutine

func TwoCallSubRoutine(m *Memory, opcode uint16)

TwoCallSubRoutine is the 2NNN opcode which call the subroutine at the NNN address

func WaitForInput

func WaitForInput(m *Memory) byte

WaitForInput wait for an input and then returns it

func ZeroClearScreen

func ZeroClearScreen(m *Memory, opcode uint16)

ZeroClearScreen is 00E0 opcode which clear the screen

func ZeroDispatcher

func ZeroDispatcher(m *Memory, opcode uint16)

ZeroDispatcher is the 0??? opcodes dispatcher

func ZeroReturnFromSubRoutine

func ZeroReturnFromSubRoutine(m *Memory, opcode uint16)

ZeroReturnFromSubRoutine is the 00EE opcode which return from a subroutine

Types

type Memory

type Memory struct {
	I          uint16
	PC         uint16
	SP         uint16
	DelayTimer byte
	SoundTimer byte
	Key        [16]bool
	Screen     [][]bool
	V          [16]byte
	CallStack  [256]uint16
	Memory     [4096]byte
}

Memory represents the internal memory of the CHIP-8 emulator

func (*Memory) Decode

func (m *Memory) Decode(opcode uint16)

Decode does stuff

func (*Memory) Fetch

func (m *Memory) Fetch() uint16

Fetch get an opcode from memory and then return it

func (*Memory) Init

func (m *Memory) Init()

Init must be called when right after you create a Memory variable it initialize the screen array and set some values

func (*Memory) Iterate

func (m *Memory) Iterate()

Iterate does one cycle of a chip8

func (*Memory) LoadRom

func (m *Memory) LoadRom(filePath string) error

LoadRom load a rom in the memory

func (*Memory) PrintMemoryValues

func (m *Memory) PrintMemoryValues()

PrintMemoryValues print chip8 state value

Jump to

Keyboard shortcuts

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