cpu

package
v0.0.0-...-5039d0b Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IF = 0xFF0F
	IE = 0xFFFF

	VBLANK_INTERRUPT              = 0
	LCDC_INTERRUPT                = 1
	TIMER_OVERFLOW_INTERRUPT      = 2
	SERIAL_IO_INTERRUPT           = 3
	JOYPAD_INTERRUPT              = 4
	VBLANK_INTERRUPT_ADDR         = 0x40
	LCDC_INTERRUPT_ADDR           = 0x48
	TIMER_OVERFLOW_INTERRUPT_ADDR = 0x50
	SERIAL_IO_INTERRUPT_ADDR      = 0x58
	JOYPAD_INTERRUPT_ADDR         = 0x60
)

Interrupts

View Source
const (
	CC_NZ = 00
	CC_Z  = 01
	CC_NC = 10
	CC_C  = 11
)

Condition Codes

View Source
const (
	Z  = 7 // Zero Flag
	N  = 6 // Subtraction Flag
	H  = 5 // Half-Carry Flag
	CY = 4 // Carry Flag
)

flags

View Source
const (
	DIV  = 0xFF04
	TIMA = 0xFF05
	TMA  = 0xFF06
	TAC  = 0xFF07

	TIMER_STOP = 2
)

Timer and Divider Registers

Variables

View Source
var CBInstructions map[byte]*Instruction = map[byte]*Instruction{}/* 256 elements not displayed */
View Source
var Instructions map[byte]*Instruction = map[byte]*Instruction{}/* 244 elements not displayed */

Functions

func UnimplementedInstruction

func UnimplementedInstruction(cpu *CPU)

Types

type CPU

type CPU struct {
	Registers          Registers
	SP                 uint16
	PC                 uint16
	CurrentInstruction *Instruction

	IF  byte // Interrupt Flag
	IE  byte // Interrupt Enabled
	IME bool // Interrupt Master Enable

	Halt bool
	// contains filtered or unexported fields
}

func NewCPU

func NewCPU(mmu *mmu.MMU) *CPU

func (*CPU) ADC_A_s

func (cpu *CPU) ADC_A_s(s byte, cycles byte) byte

ADC A,s | 1,2 | **0* | A=A+s+CY

func (*CPU) ADD_HL_SP

func (cpu *CPU) ADD_HL_SP() (cycles byte)

ADD HL,SP | 2 | **0- | HL=HL+SP

func (*CPU) ADD_HL_rr

func (cpu *CPU) ADD_HL_rr(r1 *byte, r2 *byte) (cycles byte)

ADD HL,rr | 2 | **0- | HL=HL+rr

func (*CPU) ADD_SP_e

func (cpu *CPU) ADD_SP_e() (cycles byte)

ADD SP,e | 4 | **00 | SP=SP+e

func (*CPU) ADD_s

func (cpu *CPU) ADD_s(s byte, cycles byte) byte

ADD s | 1,2 | **0* | A=A+s

func (*CPU) AND_s

func (cpu *CPU) AND_s(s byte, cycles byte) byte

AND s | 1,2 | 010* | A=A&s

func (*CPU) BIT_b_HL

func (cpu *CPU) BIT_b_HL(bit byte) (cycles byte)

BIT b,(HL) | 3 | -10* | Z=^(HL)b

func (*CPU) BIT_b_r

func (cpu *CPU) BIT_b_r(bit byte, r *byte) (cycles byte)

BIT b,r | 2 | -10* | Z=~rb

func (*CPU) CALL

func (cpu *CPU) CALL() (cycles byte)

CALL nn | 6 | ---- | (SP-1)=PCH (SP-2)=PCL PC=nn SP=SP-2

func (*CPU) CALL_cc

func (cpu *CPU) CALL_cc(conditionCode int) (cycles byte)

CALL cc,nn | 6/3 | ---- | (SP-1)=PCH (SP-2)=PCL PC=nn SP=SP-2

func (*CPU) CCF

func (cpu *CPU) CCF() (cycles byte)

CCF | 1 | ---- | CY=~CY

func (*CPU) CPL

func (cpu *CPU) CPL() (cycles byte)

CPL | 1 | -11- | A=^A

func (*CPU) CP_s

func (cpu *CPU) CP_s(s byte, cycles byte) byte

CP s | 1,2 | **1* | A-s

func (*CPU) DAA

func (cpu *CPU) DAA() (cycles byte)

DAA | 1 | z-0x | Decimal Adjust acc

func (*CPU) DEC_HL

func (cpu *CPU) DEC_HL() (cycles byte)

DEC (HL) | 3 | -*1* | (HL)=(HL)-1

func (*CPU) DEC_SP

func (cpu *CPU) DEC_SP() (cycles byte)

DEC SP | 2 | ---- | SP=SP-1

func (*CPU) DEC_r

func (cpu *CPU) DEC_r(r *byte) (cycles byte)

DEC r | 1 | -*1* | r=r-1

func (*CPU) DEC_rr

func (cpu *CPU) DEC_rr(r1 *byte, r2 *byte) (cycles byte)

DEC rr | 2 | ---- | rr=rr-1

func (*CPU) DI

func (cpu *CPU) DI() (cycles byte)

DI | 1 | ---- | Disable interrupts, IME=0

func (*CPU) EI

func (cpu *CPU) EI() (cycles byte)

EI | 1 | ---- | Enable interrupts, IME=1

func (*CPU) GetByteOffset

func (cpu *CPU) GetByteOffset(offset uint16) byte

func (*CPU) GetOpcode

func (cpu *CPU) GetOpcode() byte

func (*CPU) HALT

func (cpu *CPU) HALT() (cycles byte)

Halt | 1 | ---- | Halt until interrupt occurs

func (*CPU) INC_HL

func (cpu *CPU) INC_HL() (cycles byte)

INC (HL) | 3 | -*0* | (HL)=(HL)+1

func (*CPU) INC_SP

func (cpu *CPU) INC_SP() (cycles byte)

INC SP | 2 | ---- | SP=SP+1

func (*CPU) INC_r

func (cpu *CPU) INC_r(r *byte) (cycles byte)

INC r | 1 | -*0* | r=r+1

func (*CPU) INC_rr

func (cpu *CPU) INC_rr(r1 *byte, r2 *byte) (cycles byte)

INC rr | 2 | ---- | rr=rr+1

func (*CPU) IsFlagSet

func (cpu *CPU) IsFlagSet(flag byte) bool

func (*CPU) JP_HL

func (cpu *CPU) JP_HL() (cycles byte)

JP HL | 1 | ---- | PC=HL

func (*CPU) JP_cc_nn

func (cpu *CPU) JP_cc_nn(conditionCode int) (cycles byte)

JP cc,nn | 4,3 | ---- | if cc true, PC=nn

func (*CPU) JP_nn

func (cpu *CPU) JP_nn() (cycles byte)

JP nn | 4 | ---- | PC=nn

func (*CPU) JR_cc_e

func (cpu *CPU) JR_cc_e(conditionCode int) (cycles byte)

JR cc,e | 3/2 | ---- | if cc true, PC=PC+e

func (*CPU) JR_e

func (cpu *CPU) JR_e() (cycles byte)

JR e | 3 | ---- | PC=PC+e

func (*CPU) LDH_A_n

func (cpu *CPU) LDH_A_n() (cycles byte)

LDH A,(n) | 3 | ---- | A=(n)

func (*CPU) LDH_n_A

func (cpu *CPU) LDH_n_A() (cycles byte)

LDH (n),A | 3 | ---- | (n)=A

func (*CPU) LD_A_BC

func (cpu *CPU) LD_A_BC() (cycles byte)

LD A,(BC) | 2 | ---- | A=(BC)

func (*CPU) LD_A_C

func (cpu *CPU) LD_A_C() (cycles byte)

LD A,(C) | 2 | ---- | A=(0xFF00+C)

func (*CPU) LD_A_DE

func (cpu *CPU) LD_A_DE() (cycles byte)

LD A,(DE) | 2 | ---- | A=(DE)

func (*CPU) LD_A_HLD

func (cpu *CPU) LD_A_HLD() (cycles byte)

LD A,(HLD) | 2 | ---- | A=(HL) HL=HL-1

func (*CPU) LD_A_HLI

func (cpu *CPU) LD_A_HLI() (cycles byte)

LD A,(HLI) | 2 | ---- | A=(HL) HL=HL+1

func (*CPU) LD_A_nn

func (cpu *CPU) LD_A_nn() (cycles byte)

LD A,(nn) | 4 | ---- | A=(nn)

func (*CPU) LD_BC_A

func (cpu *CPU) LD_BC_A() (cycles byte)

LD (BC),A | 2 | ---- | (BC)=A

func (*CPU) LD_C_A

func (cpu *CPU) LD_C_A() (cycles byte)

LD (C),A | 2 | ---- | (0xFF00+C)=A

func (*CPU) LD_DE_A

func (cpu *CPU) LD_DE_A() (cycles byte)

LD (DE),A | 2 | ---- | (DE)=A

func (*CPU) LD_HLD_A

func (cpu *CPU) LD_HLD_A() (cycles byte)

LD (HLD),A | 2 | ---- | (HL)=A HL=HL-1

func (*CPU) LD_HLI_A

func (cpu *CPU) LD_HLI_A() (cycles byte)

LD (HLI),A | 2 | ---- | (HL)=A HL=HL+1

func (*CPU) LD_HL_SP_e

func (cpu *CPU) LD_HL_SP_e() (cycles byte)

LDHL SP,e | 3 | **00 | HL=SP+e

func (*CPU) LD_HL_n

func (cpu *CPU) LD_HL_n() (cycles byte)

LD (HL),n | 3 | ---- | (HL)=n

func (*CPU) LD_HL_r

func (cpu *CPU) LD_HL_r(register *byte) (cycles byte)

LD (HL),r | 2 | ---- | (HL)=r

func (*CPU) LD_SP_HL

func (cpu *CPU) LD_SP_HL() (cycles byte)

LD SP,HL | 2 | ---- | SP=HL

func (*CPU) LD_SP_nn

func (cpu *CPU) LD_SP_nn() (cycles byte)

LD SP,nn | 3 | ---- | SP=nn

func (*CPU) LD_nn_A

func (cpu *CPU) LD_nn_A() (cycles byte)

LD (nn),A | 4 | ---- | (nn)=A

func (*CPU) LD_nn_SP

func (cpu *CPU) LD_nn_SP() (cycles byte)

LD (nn),SP | 5 | ---- | (nn)=SPL (nn+1)==SPH

func (*CPU) LD_r_HL

func (cpu *CPU) LD_r_HL(register *byte) (cycles byte)

LD r,(HL) | 2 | ---- | r=(HL)

func (*CPU) LD_r_n

func (cpu *CPU) LD_r_n(register *byte) (cycles byte)

LD r,n | 2 | ---- | r=n

func (*CPU) LD_r_r

func (cpu *CPU) LD_r_r(register_1 *byte, register_2 *byte) (cycles byte)

LD r,r | 1 | ---- | r=r

func (*CPU) LD_rr_nn

func (cpu *CPU) LD_rr_nn(r1 *byte, r2 *byte) (cycles byte)

LD rr,nn | 3 | ---- | rr=nn

func (*CPU) NOP

func (cpu *CPU) NOP() (cycles byte)

NOP | 1 | ---- | No operation

func (*CPU) OR_s

func (cpu *CPU) OR_s(s byte, cycles byte) byte

OR s | 1,2 | 000* | A=A|s

func (*CPU) POP_AF

func (cpu *CPU) POP_AF() (cycles byte)

POP AF | 3 | **** | qqL=(SP) qqH=(SP+1) SP=SP+2

func (*CPU) POP_qq

func (cpu *CPU) POP_qq(r1 *byte, r2 *byte) (cycles byte)

POP qq | 3 | ---- | qqL=(SP) qqH=(SP+1) SP=SP+2

func (*CPU) PUSH_qq

func (cpu *CPU) PUSH_qq(r1 *byte, r2 *byte) (cycles byte)

PUSH qq | 4 | ---- | (SP-1)=qqH (SP-2)=qqL SP=SP-2

func (*CPU) RES_b_HL

func (cpu *CPU) RES_b_HL(bit byte) (cycles byte)

RES b,(HL) | 4 | ---- | (HL)b=0

func (*CPU) RES_b_r

func (cpu *CPU) RES_b_r(bit byte, r *byte) (cycles byte)

RES b,r | 2 | ---- | rb=0

func (*CPU) RET

func (cpu *CPU) RET() (cycles byte)

RET | 4 | ---- | PCL=(SP) PCH=(SP+1) SP=SP+2

func (*CPU) RETI

func (cpu *CPU) RETI() (cycles byte)

RETI | 4 | ---- | PCL=(SP) PCH=(SP+1) SP=SP+2 IME=true

func (*CPU) RET_cc

func (cpu *CPU) RET_cc(conditionCode int) (cycles byte)

RET cc | 5/2 | ---- | if cc true, PCL=(SP) PCH=(SP+1) SP=SP+2

func (*CPU) RLA

func (cpu *CPU) RLA() (cycles byte)

RLA | 1 | *000 | A<<1 A0=CY CY=A7

func (*CPU) RLCA

func (cpu *CPU) RLCA() (cycles byte)

RLCA | 1 | *000 | A<<1 A0=A7 CY=A7

func (*CPU) RLC_HL

func (cpu *CPU) RLC_HL() (cycles byte)

RLC (HL) | 4 | *00* | (HL)<<1 (HL)0=(HL)7 CY=(HL)7

func (*CPU) RLC_r

func (cpu *CPU) RLC_r(r *byte) (cycles byte)

RLC r | 2 | *00* | r<<1 r0=r7 CY=r7

func (*CPU) RL_HL

func (cpu *CPU) RL_HL() (cycles byte)

RL (HL) | 4 | *00* | (HL)<<1 (HL)0=CY CY=(HL)7

func (*CPU) RL_r

func (cpu *CPU) RL_r(r *byte) (cycles byte)

RL r | 2 | *00* | r<<1 r0=CY CY=r7

func (*CPU) RRA

func (cpu *CPU) RRA() (cycles byte)

RRA | 1 | *000 | A>>1 A7=CY CY=A0

func (*CPU) RRCA

func (cpu *CPU) RRCA() (cycles byte)

RRCA | 1 | *000 | A>>1 A7=A0 CY=A0

func (*CPU) RRC_HL

func (cpu *CPU) RRC_HL() (cycles byte)

RRC (HL) | 4 | *00* | (HL)>>1 (HL)7=(HL)0 CY=(HL)0

func (*CPU) RRC_r

func (cpu *CPU) RRC_r(r *byte) (cycles byte)

RRC r | 2 | *00* | r>>1 r7=r0 CY=r0

func (*CPU) RR_HL

func (cpu *CPU) RR_HL() (cycles byte)

RR (HL) | 4 | *00* | (HL)>>1 (HL)7=CY CY=(HL)0

func (*CPU) RR_r

func (cpu *CPU) RR_r(r *byte) (cycles byte)

RR r | 2 | *00* | r>>1 r7=CY CY=r0

func (*CPU) RST

func (cpu *CPU) RST(t byte) (cycles byte)

RST t | 4 | ---- | (SP-1)=PCH (SP-2)=PCL SP=SP-2 PCH=0 PCL=t

func (*CPU) ReadByte

func (cpu *CPU) ReadByte(addr uint16) byte

func (*CPU) Reset

func (cpu *CPU) Reset()

func (*CPU) ResetFlag

func (cpu *CPU) ResetFlag(flag byte)

func (*CPU) SBC_s

func (cpu *CPU) SBC_s(s byte, cycles byte) byte

SBC A,s | 1,2 | **1* | A=A-s-CY

func (*CPU) SCF

func (cpu *CPU) SCF() (cycles byte)

SCF | 1 | ---- | CY=1

func (*CPU) SET_b_HL

func (cpu *CPU) SET_b_HL(bit byte) (cycles byte)

SET b,(HL) | 4 | ---- | (HL)b=1

func (*CPU) SET_b_r

func (cpu *CPU) SET_b_r(bit byte, r *byte) (cycles byte)

SET b,r | 2 | ---- | rb=1

func (*CPU) SLA_HL

func (cpu *CPU) SLA_HL() (cycles byte)

SLA (HL) | 4 | *00* | (HL)<<1 CY=(HL)7

func (*CPU) SLA_r

func (cpu *CPU) SLA_r(r *byte) (cycles byte)

SLA r | 2 | *00* | r<<1 CY=r7

func (*CPU) SRA_HL

func (cpu *CPU) SRA_HL() (cycles byte)

SRA (HL) | 4 | *00* | (HL)>>1 (HL)7=(HL)7 CY=(HL)0

func (*CPU) SRA_r

func (cpu *CPU) SRA_r(r *byte) (cycles byte)

SRA r | 2 | *00* | r>>1 r7=r7 CY=r0

func (*CPU) SRL_HL

func (cpu *CPU) SRL_HL() (cycles byte)

SRL (HL) | 4 | *00* | (HL)>>1 CY=(HL)0

func (*CPU) SRL_r

func (cpu *CPU) SRL_r(r *byte) (cycles byte)

SRL r | 2 | *00* | r>>1 CY=r0

func (*CPU) SUB_s

func (cpu *CPU) SUB_s(s byte, cycles byte) byte

SUB s | 1,2 | **1* | A=A-s

func (*CPU) SWAP_HL

func (cpu *CPU) SWAP_HL() (cycles byte)

SWAP (HL) | 4 | 000* | (HL)=(HL)[4:7]&(HL)[0:3]

func (*CPU) SWAP_r

func (cpu *CPU) SWAP_r(r *byte) (cycles byte)

SWAP r | 2 | 000* | r=r[4:7]&r[0:3]

func (*CPU) SetFlag

func (cpu *CPU) SetFlag(flag byte)

FLAGS

func (*CPU) Step

func (cpu *CPU) Step() (cycles int)

func (*CPU) WriteByte

func (cpu *CPU) WriteByte(addr uint16, value byte)

func (*CPU) XOR_s

func (cpu *CPU) XOR_s(s byte, cycles byte) byte

XOR s | 1,2 | 000* | A=A^s

type Instruction

type Instruction struct {
	Opcode      byte
	Description string
	Length      uint16
	Execute     func(cpu *CPU) byte
}

type Registers

type Registers struct {
	A byte
	B byte
	C byte
	D byte
	E byte
	H byte
	L byte
	F byte
}

type Timer

type Timer struct {
	DIV  byte // Divider
	TIMA byte // Timer Counter
	TMA  byte // Timer Modulo
	TAC  byte // Timer Controller
	// contains filtered or unexported fields
}

func NewTimer

func NewTimer(mmu *mmu.MMU) *Timer

func (*Timer) ReadByte

func (timer *Timer) ReadByte(addr uint16) byte

func (*Timer) Reset

func (timer *Timer) Reset()

func (*Timer) Tick

func (timer *Timer) Tick(cycles int)

func (*Timer) WriteByte

func (timer *Timer) WriteByte(addr uint16, value byte)

Jump to

Keyboard shortcuts

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