Implement timer, some IO operations and more CPU instructions
This commit is contained in:
39
gb/cpu.go
39
gb/cpu.go
@@ -35,6 +35,7 @@ type CPU struct {
|
||||
Halted bool
|
||||
Stepping bool
|
||||
InterruptMasterEnable bool
|
||||
InterruptFlags byte
|
||||
}
|
||||
|
||||
func NewCPU(bus *Bus) *CPU {
|
||||
@@ -127,6 +128,14 @@ func (cpu *CPU) Step() {
|
||||
cpu.ClearFlag(H)
|
||||
}
|
||||
|
||||
case 0x18:
|
||||
// JR e8
|
||||
// Jump relative to 8-bit signed offset
|
||||
// emu_cycles(3);
|
||||
offset := int8(cpu.Bus.Read(cpu.Regs.PC))
|
||||
cpu.Regs.PC++
|
||||
cpu.Regs.PC = uint16(int(cpu.Regs.PC) + int(offset))
|
||||
|
||||
case 0x1C:
|
||||
// INC E
|
||||
cpu.Regs.E++
|
||||
@@ -225,6 +234,14 @@ func (cpu *CPU) Step() {
|
||||
// LD A, B
|
||||
cpu.Regs.A = cpu.Regs.B
|
||||
|
||||
case 0x7C:
|
||||
// LD A, H
|
||||
cpu.Regs.A = cpu.Regs.H
|
||||
|
||||
case 0x7D:
|
||||
// LD A, L
|
||||
cpu.Regs.A = cpu.Regs.L
|
||||
|
||||
case 0xCB:
|
||||
// Prefix byte instructions
|
||||
cbOpcode := cpu.Bus.Read(cpu.Regs.PC)
|
||||
@@ -262,10 +279,10 @@ func (cpu *CPU) Step() {
|
||||
// emu_cycles(1);
|
||||
cpu.Regs.PC = uint16(lo) | uint16(hi)<<8
|
||||
|
||||
// case 0xC9:
|
||||
// // RET
|
||||
// // emu_cycles(4);
|
||||
// cpu.Regs.PC = cpu.StackPop16()
|
||||
case 0xC9:
|
||||
// RET
|
||||
// emu_cycles(4);
|
||||
cpu.Regs.PC = cpu.StackPop16()
|
||||
|
||||
case 0xCD:
|
||||
// CALL a16
|
||||
@@ -284,6 +301,12 @@ func (cpu *CPU) Step() {
|
||||
cpu.Bus.Write(address, cpu.Regs.A)
|
||||
cpu.Regs.PC++
|
||||
|
||||
case 0xE5:
|
||||
// PUSH HL
|
||||
// emu_cycles(4);
|
||||
cpu.StackPush(cpu.Regs.H)
|
||||
cpu.StackPush(cpu.Regs.L)
|
||||
|
||||
case 0xE9:
|
||||
// JP HL
|
||||
val := uint16(cpu.Regs.H)<<8 | uint16(cpu.Regs.L)
|
||||
@@ -349,3 +372,11 @@ func (cpu *CPU) StackPop16() uint16 {
|
||||
|
||||
return uint16(hi)<<8 | uint16(lo)
|
||||
}
|
||||
|
||||
func (cpu *CPU) GetInterruptFlags() byte {
|
||||
return cpu.InterruptFlags
|
||||
}
|
||||
|
||||
func (cpu *CPU) SetInterruptFlags(value byte) {
|
||||
cpu.InterruptFlags = value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user