mirror of
https://github.com/macocianradu/goboy.git
synced 2026-03-18 21:10:07 +00:00
setup getters and setters for combined registers
This commit is contained in:
73
cpu/cpu.go
73
cpu/cpu.go
@@ -4,26 +4,67 @@ import (
|
||||
"radu.macocian.me/goboy/memory"
|
||||
)
|
||||
|
||||
type cpu_struct struct {
|
||||
A int8
|
||||
F int8
|
||||
B int8
|
||||
C int8
|
||||
D int8
|
||||
E int8
|
||||
H int8
|
||||
L int8
|
||||
IR int8
|
||||
IE int8
|
||||
type CPU_struct struct {
|
||||
A byte
|
||||
F byte
|
||||
B byte
|
||||
C byte
|
||||
D byte
|
||||
E byte
|
||||
H byte
|
||||
L byte
|
||||
IR byte
|
||||
IE byte
|
||||
|
||||
PC int16
|
||||
SP int16
|
||||
PC uint16
|
||||
SP uint16
|
||||
}
|
||||
|
||||
var cpu = new(cpu_struct)
|
||||
var cpu = new(CPU_struct)
|
||||
|
||||
func Execute(addr int) {
|
||||
instr := memory.Read(addr + int(cpu.PC))
|
||||
func Execute(addr uint) {
|
||||
instr := memory.Read(addr + uint(cpu.PC))
|
||||
cpu.PC++
|
||||
print(string(instr))
|
||||
}
|
||||
|
||||
func readDoubleRegis(r1 byte, r2 byte) uint16 {
|
||||
return uint16(r1)<<8 | uint16(r2)
|
||||
}
|
||||
|
||||
func setDoubleRegis(r1 *byte, r2 *byte, value uint16) {
|
||||
*r1 = byte((value & 0xFF00) >> 8)
|
||||
*r2 = byte(value & 0x00FF)
|
||||
}
|
||||
|
||||
func (cpu *CPU_struct) AF() uint16 {
|
||||
return readDoubleRegis(cpu.A, cpu.F)
|
||||
}
|
||||
|
||||
func (cpu *CPU_struct) SetAF(value uint16) {
|
||||
setDoubleRegis(&cpu.A, &cpu.F, value)
|
||||
}
|
||||
|
||||
func (cpu *CPU_struct) BC() uint16 {
|
||||
return readDoubleRegis(cpu.B, cpu.C)
|
||||
}
|
||||
|
||||
func (cpu *CPU_struct) SetBC(value uint16) {
|
||||
setDoubleRegis(&cpu.B, &cpu.C, value)
|
||||
}
|
||||
|
||||
func (cpu *CPU_struct) DE() uint16 {
|
||||
return readDoubleRegis(cpu.D, cpu.E)
|
||||
}
|
||||
|
||||
func (cpu *CPU_struct) SetDE(value uint16) {
|
||||
setDoubleRegis(&cpu.D, &cpu.E, value)
|
||||
}
|
||||
|
||||
func (cpu *CPU_struct) HL() uint16 {
|
||||
return readDoubleRegis(cpu.H, cpu.L)
|
||||
}
|
||||
|
||||
func (cpu *CPU_struct) SetHL(value uint16) {
|
||||
setDoubleRegis(&cpu.H, &cpu.L, value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user