mirror of
https://github.com/romychs/z80go.git
synced 2026-04-16 08:44:20 +03:00
fix JR -nn execution
This commit is contained in:
parent
3b05332d28
commit
3c891c0a04
@ -1093,7 +1093,13 @@ func (z *CPU) execOpcode(opcode byte) {
|
|||||||
z.B--
|
z.B--
|
||||||
z.condJr(z.B != 0) // djnz *
|
z.condJr(z.B != 0) // djnz *
|
||||||
case 0x18:
|
case 0x18:
|
||||||
z.PC += uint16(z.nextB()) // jr *
|
// jr *
|
||||||
|
offset := z.nextB()
|
||||||
|
if offset&0x80 == 0 {
|
||||||
|
z.PC += uint16(offset)
|
||||||
|
} else {
|
||||||
|
z.PC += 0xFF00 | uint16(offset)
|
||||||
|
}
|
||||||
z.MemPtr = z.PC
|
z.MemPtr = z.PC
|
||||||
case 0x20:
|
case 0x20:
|
||||||
z.condJr(!z.Flags.Z) // jr nz, *
|
z.condJr(!z.Flags.Z) // jr nz, *
|
||||||
|
|||||||
@ -593,3 +593,23 @@ func checkComputerState(t *testing.T, name string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setMemory(addr uint16, value []byte) {
|
||||||
|
for i := 0; i < len(value); i++ {
|
||||||
|
computer.memory[addr+uint16(i)] = value[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var testJRm = []byte{0x70, 0x7d, 0xb3, 0x3c, 0x28, 0x09, 0xb3, 0xab, 0x4f, 0x7d, 0xa3, 0xb1, 0x6f, 0x18, 0xf1, 0x7d}
|
||||||
|
|
||||||
|
func TestZ80_JR_mnn(t *testing.T) {
|
||||||
|
setMemory(0x31eb, testJRm)
|
||||||
|
state := computer.cpu.GetState()
|
||||||
|
state.PC = 0x31F8
|
||||||
|
computer.cpu.SetState(state)
|
||||||
|
computer.cpu.RunInstruction()
|
||||||
|
expected := uint16(0x31EB)
|
||||||
|
if computer.cpu.PC != expected {
|
||||||
|
t.Errorf("Error JR -nn, result PC=0x%04X, expected: 0x%04X", computer.cpu.PC, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user