Compare commits

..

No commits in common. "main" and "v1.0.1" have entirely different histories.
main ... v1.0.1

4 changed files with 3 additions and 51 deletions

View File

@ -39,12 +39,12 @@ func (d *Disassembler) jp(op, cond string) string {
} }
func (d *Disassembler) jr(op, cond string) string { func (d *Disassembler) jr(op, cond string) string {
addr := d.pc + 1 addr := d.pc
offset := d.getByte() offset := d.getByte()
if offset&0x80 != 0 { if offset&0x80 != 0 {
addr += 0xFF00 | uint16(offset) addr += 0xFF00 | uint16(offset)
} else { } else {
addr += uint16(offset) addr += d.pc + uint16(offset)
} }
if cond != "" { if cond != "" {
cond += sep cond += sep

View File

@ -90,25 +90,3 @@ func Test_JP_nn(t *testing.T) {
t.Errorf("Error disassm JP nn, result '%s', expected '%s'", res, expected) t.Errorf("Error disassm JP nn, result '%s', expected '%s'", res, expected)
} }
} }
var testJRf = []byte{0x28, 0x09} // JR Z,+9
func Test_JR_Z_nn(t *testing.T) {
expected := " 31EF JR Z, 0x31FA" // PC+2+9
setMemory(0x31EF, testJRf)
res := disasm.Disassm(0x31EF)
if res != expected {
t.Errorf("Error disassm JR Z,nn, result '%s', expected '%s'", res, expected)
}
}
var testJRb = []byte{0x18, 0xf1} // JR Z,+9
func Test_JR_mnn(t *testing.T) {
expected := " 31F8 JR 0x31EB" // JR back
setMemory(0x31F8, testJRb)
res := disasm.Disassm(0x31F8)
if res != expected {
t.Errorf("Error disassm JR -nn, result '%s', expected '%s'", res, expected)
}
}

View File

@ -1093,13 +1093,7 @@ 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:
// jr * z.PC += uint16(z.nextB()) // 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, *

View File

@ -593,23 +593,3 @@ 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)
}
}