From e07349c5825a74adb9cdcd16f720bd1e6ee137b2 Mon Sep 17 00:00:00 2001 From: beirich Date: Sun, 6 Mar 2011 06:06:49 +0000 Subject: [PATCH] [PCE] improve cpu instruction timing --- BizHawk.Emulation/CPUs/HuC6280/Execute.cs | 54 ++++++++++----------- BizHawk.Emulation/Consoles/PC Engine/VCE.cs | 5 +- CpuCoreGenerator/HuC6280/CoreGenerator.cs | 8 +-- CpuCoreGenerator/HuC6280/Instructions.cs | 4 +- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/BizHawk.Emulation/CPUs/HuC6280/Execute.cs b/BizHawk.Emulation/CPUs/HuC6280/Execute.cs index 8ef651b5b4..14357e2c49 100644 --- a/BizHawk.Emulation/CPUs/HuC6280/Execute.cs +++ b/BizHawk.Emulation/CPUs/HuC6280/Execute.cs @@ -148,7 +148,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x01) == 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -157,7 +157,7 @@ throw new Exception("break"); rel8 = (sbyte)ReadMemory(PC++); value16 = (ushort)(PC+rel8); if (FlagN == false) { - PendingCycles--; + PendingCycles -= 2; PC = value16; } PendingCycles -= 2; @@ -264,7 +264,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x02) == 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -274,7 +274,7 @@ throw new Exception("break"); WriteMemory((ushort)(S-- + 0x2100), (byte)(temp16 >> 8)); WriteMemory((ushort)(S-- + 0x2100), (byte)temp16); PC = ReadWord(PC); - PendingCycles -= 6; + PendingCycles -= 7; break; case 0x21: // AND (addr,X) value8 = ReadMemory(ReadWordPageWrap((ushort)((byte)(ReadMemory(PC++)+X)+0x2000))); @@ -397,7 +397,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x04) == 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -406,7 +406,7 @@ throw new Exception("break"); rel8 = (sbyte)ReadMemory(PC++); value16 = (ushort)(PC+rel8); if (FlagN == true) { - PendingCycles--; + PendingCycles -= 2; PC = value16; } PendingCycles -= 2; @@ -547,7 +547,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x08) == 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -684,7 +684,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x10) == 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -693,7 +693,7 @@ throw new Exception("break"); rel8 = (sbyte)ReadMemory(PC++); value16 = (ushort)(PC+rel8); if (FlagV == false) { - PendingCycles--; + PendingCycles -= 2; PC = value16; } PendingCycles -= 2; @@ -739,7 +739,7 @@ throw new Exception("break"); PendingCycles -= 5; break; case 0x54: // CSL - PendingCycles -= 2; + PendingCycles -= 3; break; case 0x55: // EOR zp,X value8 = ReadMemory((ushort)(((ReadMemory(PC++)+X)&0xFF)+0x2000)); @@ -829,7 +829,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x20) == 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1018,7 +1018,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x40) == 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1027,7 +1027,7 @@ throw new Exception("break"); rel8 = (sbyte)ReadMemory(PC++); value16 = (ushort)(PC+rel8); if (FlagV == true) { - PendingCycles--; + PendingCycles -= 2; PC = value16; } PendingCycles -= 2; @@ -1255,7 +1255,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x80) == 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1339,7 +1339,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x01) != 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1348,7 +1348,7 @@ throw new Exception("break"); rel8 = (sbyte)ReadMemory(PC++); value16 = (ushort)(PC+rel8); if (FlagC == false) { - PendingCycles--; + PendingCycles -= 2; PC = value16; } PendingCycles -= 2; @@ -1438,7 +1438,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x02) != 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1522,7 +1522,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x04) != 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1531,7 +1531,7 @@ throw new Exception("break"); rel8 = (sbyte)ReadMemory(PC++); value16 = (ushort)(PC+rel8); if (FlagC == true) { - PendingCycles--; + PendingCycles -= 2; PC = value16; } PendingCycles -= 2; @@ -1627,7 +1627,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x08) != 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1727,7 +1727,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x10) != 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1736,7 +1736,7 @@ throw new Exception("break"); rel8 = (sbyte)ReadMemory(PC++); value16 = (ushort)(PC+rel8); if (FlagZ == false) { - PendingCycles--; + PendingCycles -= 2; PC = value16; } PendingCycles -= 2; @@ -1768,7 +1768,7 @@ throw new Exception("break"); PendingCycles -= temp; break; case 0xD4: // CSH - PendingCycles -= 2; + PendingCycles -= 3; break; case 0xD5: // CMP zp,X value8 = ReadMemory((ushort)(((ReadMemory(PC++)+X)&0xFF)+0x2000)); @@ -1833,7 +1833,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x20) != 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1988,7 +1988,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x40) != 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; @@ -1997,7 +1997,7 @@ throw new Exception("break"); rel8 = (sbyte)ReadMemory(PC++); value16 = (ushort)(PC+rel8); if (FlagZ == true) { - PendingCycles--; + PendingCycles -= 2; PC = value16; } PendingCycles -= 2; @@ -2174,7 +2174,7 @@ throw new Exception("break"); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); rel8 = (sbyte) ReadMemory(PC++); if ((value8 & 0x80) != 0) { - PendingCycles--; + PendingCycles -= 2; PC = (ushort)(PC+rel8); } PendingCycles -= 6; diff --git a/BizHawk.Emulation/Consoles/PC Engine/VCE.cs b/BizHawk.Emulation/Consoles/PC Engine/VCE.cs index 1b45d3fd87..e8e2f8cf0b 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/VCE.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/VCE.cs @@ -12,9 +12,11 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx public int[] Palette = new int[512]; public byte DotClock; + // Note: To keep the VCE class from needing a reference to the CPU, the 1-cycle access + // penalty for the VCE is handled by the memory mappers. + public void WriteVCE(int port, byte value) { - //cpu.PendingCycles--; // VCE access puts CPU into a 1-cycle wait state. switch (port) { case 0: // Control Port. Doesn't control anything we care about... @@ -48,7 +50,6 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx public byte ReadVCE(int port) { - //cpu.PendingCycles--; switch (port) { case 4: // Data LSB diff --git a/CpuCoreGenerator/HuC6280/CoreGenerator.cs b/CpuCoreGenerator/HuC6280/CoreGenerator.cs index 0824df12d5..85b8c43ba8 100644 --- a/CpuCoreGenerator/HuC6280/CoreGenerator.cs +++ b/CpuCoreGenerator/HuC6280/CoreGenerator.cs @@ -165,7 +165,7 @@ namespace HuC6280 Set(0x44, "BSR", AddrMode.Relative, 8); // Branch to Subroutine // CPU Break - Set(0x00, "BRK", AddrMode.Implicit, 7); + Set(0x00, "BRK", AddrMode.Implicit, 8); // Compare accumulator Set(0xC9, "CMP", AddrMode.Immediate, 2); @@ -234,7 +234,7 @@ namespace HuC6280 Set(0x7C, "JMP", AddrMode.AbsoluteIndirectX, 7); // Jump to Subroutine - Set(0x20, "JSR", AddrMode.Absolute, 6); + Set(0x20, "JSR", AddrMode.Absolute, 7); // Load Accumulator Set(0xA9, "LDA", AddrMode.Immediate, 2); @@ -408,8 +408,8 @@ namespace HuC6280 Set(0xB3, "TST", AddrMode.ImmAbsoluteX, 8); // Cpu Speed instructions - Set(0xD4, "CSH", AddrMode.Implicit, 2); - Set(0x54, "CSL", AddrMode.Implicit, 2); + Set(0xD4, "CSH", AddrMode.Implicit, 3); + Set(0x54, "CSL", AddrMode.Implicit, 3); // Block Memory Transfer instructions Set(0xF3, "TAI", AddrMode.BlockMove, 17); // Transfer Alternate Increment diff --git a/CpuCoreGenerator/HuC6280/Instructions.cs b/CpuCoreGenerator/HuC6280/Instructions.cs index 6a9135fe07..f0f1d87101 100644 --- a/CpuCoreGenerator/HuC6280/Instructions.cs +++ b/CpuCoreGenerator/HuC6280/Instructions.cs @@ -98,7 +98,7 @@ namespace HuC6280 w.WriteLine(Spaces + "value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));"); w.WriteLine(Spaces + "rel8 = (sbyte) ReadMemory(PC++);"); w.WriteLine(Spaces + "if ((value8 & "+filter+") "+cond+" 0) {"); - w.WriteLine(Spaces + " PendingCycles--;"); + w.WriteLine(Spaces + " PendingCycles -= 2;"); w.WriteLine(Spaces + " PC = (ushort)(PC+rel8);"); w.WriteLine(Spaces + "}"); w.WriteLine(Spaces + "PendingCycles -= {0};", op.Cycles); @@ -108,7 +108,7 @@ namespace HuC6280 { GetAddress(op, w, "value16"); w.WriteLine(Spaces + "if (Flag" + flag + " == " + cond.ToString().ToLower() + ") {"); - w.WriteLine(Spaces + " PendingCycles--;"); + w.WriteLine(Spaces + " PendingCycles -= 2;"); w.WriteLine(Spaces + " PC = value16;"); w.WriteLine(Spaces + "}"); w.WriteLine(Spaces + "PendingCycles -= {0};", op.Cycles);