From 3b05332d28a82136afc32d1dad30b34482305244 Mon Sep 17 00:00:00 2001 From: Roman Boykov Date: Wed, 15 Apr 2026 15:57:33 +0300 Subject: [PATCH] fix relative jump disasm --- dis/z80disasm.go | 4 ++-- dis/z80disasm_test.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/dis/z80disasm.go b/dis/z80disasm.go index 8de81de..3a2bdc1 100644 --- a/dis/z80disasm.go +++ b/dis/z80disasm.go @@ -39,12 +39,12 @@ func (d *Disassembler) jp(op, cond string) string { } func (d *Disassembler) jr(op, cond string) string { - addr := d.pc + addr := d.pc + 1 offset := d.getByte() if offset&0x80 != 0 { addr += 0xFF00 | uint16(offset) } else { - addr += d.pc + uint16(offset) + addr += uint16(offset) } if cond != "" { cond += sep diff --git a/dis/z80disasm_test.go b/dis/z80disasm_test.go index c3dd5cb..b7be457 100644 --- a/dis/z80disasm_test.go +++ b/dis/z80disasm_test.go @@ -90,3 +90,25 @@ func Test_JP_nn(t *testing.T) { 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) + } +}