Correct timing issues both conditional and unconditional relative jumpson Z80

This commit is contained in:
Adrian Conlon
2025-05-02 14:03:15 +01:00
parent 9670c3fd21
commit 935466ad6f
3 changed files with 22 additions and 9 deletions

View File

@@ -64,7 +64,7 @@
this.Raise("SP", final.SP, cpu.SP);
this.Raise("A", final.A, cpu.A);
this.Raise("F", final.F, cpu.F);
this.RaiseFlags("F", final.F, cpu.F);
this.Raise("B", final.B, cpu.B);
this.Raise("C", final.C, cpu.C);
this.Raise("D", final.D, cpu.D);
@@ -308,6 +308,8 @@
private void Raise(string what, byte expected, byte actual) => this.Messages.Add($"{what}: expected: {expected:X2}, actual: {actual:X2}");
private void RaiseFlags(string what, byte expected, byte actual) => this.Messages.Add($"{what}: expected: {Disassembler.AsFlags(expected)}, actual: {Disassembler.AsFlags(actual)}");
private void Raise(string what, ushort expected, Register16 actual) => this.Raise(what, expected, actual.Word);
private void Raise(string what, ushort expected, ushort actual) => this.Messages.Add($"{what}: expected: {expected:X4}, actual: {actual:X4}");

View File

@@ -6,7 +6,7 @@
public IEnumerable<OpcodeTestSuite> OpcodeTests()
{
foreach (var filename in Directory.EnumerateFiles(this.Location, "*.json"))
foreach (var filename in Directory.EnumerateFiles(this.Location, "0?.json"))
{
var fileInformation = new FileInfo(filename);
if (fileInformation.Length > 0)

View File

@@ -550,6 +550,23 @@ namespace Z80
base.Call(destination);
}
protected override void JumpRelative(sbyte offset)
{
base.JumpRelative(offset);
this.Tick(5);
}
protected override bool JumpRelativeConditional(bool condition)
{
this.Tick();
var offset = this.FetchByte();
if (condition)
{
this.JumpRelative(offset);
}
return condition;
}
private int Zero()
{
return ZeroTest(this.F);
@@ -1139,13 +1156,7 @@ namespace Z80
this.ExxAF();
break;
case 2: // DJNZ d
this.Tick();
if (this.JumpRelativeConditional(--this.B != 0))
{
this.Tick(2);
}
this.Tick(3);
_ = this.JumpRelativeConditional(--this.B != 0);
break;
case 3: // JR d
this.JumpRelative(this.FetchByte());