Implement CB instructions
This commit is contained in:
parent
c18615c629
commit
772ff893af
14
gb/cpu.go
14
gb/cpu.go
@ -109,6 +109,20 @@ func (cpu *CPU) Step() {
|
||||
cpu.Regs.PC++
|
||||
|
||||
switch cbOpcode {
|
||||
case 0x7E:
|
||||
// BIT 7, [HL]
|
||||
// Read byte pointed to by address HL
|
||||
address := uint16(cpu.Regs.H)<<8 | uint16(cpu.Regs.L)
|
||||
val := cpu.Bus.Read(address)
|
||||
|
||||
// Check if bit 7 is set
|
||||
if (val & 0x80) == 0 {
|
||||
// Set zero flag if bit is not set
|
||||
cpu.SetFlag(Z)
|
||||
}
|
||||
cpu.ClearFlag(N)
|
||||
cpu.SetFlag(H)
|
||||
|
||||
default:
|
||||
fmt.Printf("\nINVALID INSTRUCTION! Unknown CB opcode: %02X\n", cbOpcode)
|
||||
os.Exit(1)
|
||||
|
||||
@ -167,3 +167,22 @@ func TestInstruction21(t *testing.T) {
|
||||
// Should increase the stack pointer
|
||||
assert.Equal(t, uint16(0x3), cpu.Regs.PC)
|
||||
}
|
||||
|
||||
func TestInstructionCB7E(t *testing.T) {
|
||||
cpu := createCPU([]byte{0xCB, 0x7E, 0x00, 0x00})
|
||||
|
||||
cpu.Regs.H = 0xFF
|
||||
cpu.Regs.L = 0x40
|
||||
err := cpu.Bus.Write(0xFF40, 0xFF)
|
||||
assert.Equal(t, err, nil)
|
||||
|
||||
// FIXME(m): This needs bus access to IO, in particular the LCD
|
||||
// at 0xFF40.
|
||||
|
||||
// assert.Equal(t, 0xFF, cpu.Bus.Read(0xFF40))
|
||||
|
||||
// cpu.Step()
|
||||
|
||||
// // Should set the zero flag
|
||||
// assert.True(t, cpu.IsFlagSet(Z))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user