[PCE] improve cpu instruction timing

This commit is contained in:
beirich 2011-03-06 06:06:49 +00:00
parent 4e8d161ed8
commit e07349c582
4 changed files with 36 additions and 35 deletions

View File

@ -148,7 +148,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x01) == 0) { if ((value8 & 0x01) == 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -157,7 +157,7 @@ throw new Exception("break");
rel8 = (sbyte)ReadMemory(PC++); rel8 = (sbyte)ReadMemory(PC++);
value16 = (ushort)(PC+rel8); value16 = (ushort)(PC+rel8);
if (FlagN == false) { if (FlagN == false) {
PendingCycles--; PendingCycles -= 2;
PC = value16; PC = value16;
} }
PendingCycles -= 2; PendingCycles -= 2;
@ -264,7 +264,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x02) == 0) { if ((value8 & 0x02) == 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -274,7 +274,7 @@ throw new Exception("break");
WriteMemory((ushort)(S-- + 0x2100), (byte)(temp16 >> 8)); WriteMemory((ushort)(S-- + 0x2100), (byte)(temp16 >> 8));
WriteMemory((ushort)(S-- + 0x2100), (byte)temp16); WriteMemory((ushort)(S-- + 0x2100), (byte)temp16);
PC = ReadWord(PC); PC = ReadWord(PC);
PendingCycles -= 6; PendingCycles -= 7;
break; break;
case 0x21: // AND (addr,X) case 0x21: // AND (addr,X)
value8 = ReadMemory(ReadWordPageWrap((ushort)((byte)(ReadMemory(PC++)+X)+0x2000))); value8 = ReadMemory(ReadWordPageWrap((ushort)((byte)(ReadMemory(PC++)+X)+0x2000)));
@ -397,7 +397,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x04) == 0) { if ((value8 & 0x04) == 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -406,7 +406,7 @@ throw new Exception("break");
rel8 = (sbyte)ReadMemory(PC++); rel8 = (sbyte)ReadMemory(PC++);
value16 = (ushort)(PC+rel8); value16 = (ushort)(PC+rel8);
if (FlagN == true) { if (FlagN == true) {
PendingCycles--; PendingCycles -= 2;
PC = value16; PC = value16;
} }
PendingCycles -= 2; PendingCycles -= 2;
@ -547,7 +547,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x08) == 0) { if ((value8 & 0x08) == 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -684,7 +684,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x10) == 0) { if ((value8 & 0x10) == 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -693,7 +693,7 @@ throw new Exception("break");
rel8 = (sbyte)ReadMemory(PC++); rel8 = (sbyte)ReadMemory(PC++);
value16 = (ushort)(PC+rel8); value16 = (ushort)(PC+rel8);
if (FlagV == false) { if (FlagV == false) {
PendingCycles--; PendingCycles -= 2;
PC = value16; PC = value16;
} }
PendingCycles -= 2; PendingCycles -= 2;
@ -739,7 +739,7 @@ throw new Exception("break");
PendingCycles -= 5; PendingCycles -= 5;
break; break;
case 0x54: // CSL case 0x54: // CSL
PendingCycles -= 2; PendingCycles -= 3;
break; break;
case 0x55: // EOR zp,X case 0x55: // EOR zp,X
value8 = ReadMemory((ushort)(((ReadMemory(PC++)+X)&0xFF)+0x2000)); value8 = ReadMemory((ushort)(((ReadMemory(PC++)+X)&0xFF)+0x2000));
@ -829,7 +829,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x20) == 0) { if ((value8 & 0x20) == 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1018,7 +1018,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x40) == 0) { if ((value8 & 0x40) == 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1027,7 +1027,7 @@ throw new Exception("break");
rel8 = (sbyte)ReadMemory(PC++); rel8 = (sbyte)ReadMemory(PC++);
value16 = (ushort)(PC+rel8); value16 = (ushort)(PC+rel8);
if (FlagV == true) { if (FlagV == true) {
PendingCycles--; PendingCycles -= 2;
PC = value16; PC = value16;
} }
PendingCycles -= 2; PendingCycles -= 2;
@ -1255,7 +1255,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x80) == 0) { if ((value8 & 0x80) == 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1339,7 +1339,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x01) != 0) { if ((value8 & 0x01) != 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1348,7 +1348,7 @@ throw new Exception("break");
rel8 = (sbyte)ReadMemory(PC++); rel8 = (sbyte)ReadMemory(PC++);
value16 = (ushort)(PC+rel8); value16 = (ushort)(PC+rel8);
if (FlagC == false) { if (FlagC == false) {
PendingCycles--; PendingCycles -= 2;
PC = value16; PC = value16;
} }
PendingCycles -= 2; PendingCycles -= 2;
@ -1438,7 +1438,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x02) != 0) { if ((value8 & 0x02) != 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1522,7 +1522,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x04) != 0) { if ((value8 & 0x04) != 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1531,7 +1531,7 @@ throw new Exception("break");
rel8 = (sbyte)ReadMemory(PC++); rel8 = (sbyte)ReadMemory(PC++);
value16 = (ushort)(PC+rel8); value16 = (ushort)(PC+rel8);
if (FlagC == true) { if (FlagC == true) {
PendingCycles--; PendingCycles -= 2;
PC = value16; PC = value16;
} }
PendingCycles -= 2; PendingCycles -= 2;
@ -1627,7 +1627,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x08) != 0) { if ((value8 & 0x08) != 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1727,7 +1727,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x10) != 0) { if ((value8 & 0x10) != 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1736,7 +1736,7 @@ throw new Exception("break");
rel8 = (sbyte)ReadMemory(PC++); rel8 = (sbyte)ReadMemory(PC++);
value16 = (ushort)(PC+rel8); value16 = (ushort)(PC+rel8);
if (FlagZ == false) { if (FlagZ == false) {
PendingCycles--; PendingCycles -= 2;
PC = value16; PC = value16;
} }
PendingCycles -= 2; PendingCycles -= 2;
@ -1768,7 +1768,7 @@ throw new Exception("break");
PendingCycles -= temp; PendingCycles -= temp;
break; break;
case 0xD4: // CSH case 0xD4: // CSH
PendingCycles -= 2; PendingCycles -= 3;
break; break;
case 0xD5: // CMP zp,X case 0xD5: // CMP zp,X
value8 = ReadMemory((ushort)(((ReadMemory(PC++)+X)&0xFF)+0x2000)); value8 = ReadMemory((ushort)(((ReadMemory(PC++)+X)&0xFF)+0x2000));
@ -1833,7 +1833,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x20) != 0) { if ((value8 & 0x20) != 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1988,7 +1988,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x40) != 0) { if ((value8 & 0x40) != 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;
@ -1997,7 +1997,7 @@ throw new Exception("break");
rel8 = (sbyte)ReadMemory(PC++); rel8 = (sbyte)ReadMemory(PC++);
value16 = (ushort)(PC+rel8); value16 = (ushort)(PC+rel8);
if (FlagZ == true) { if (FlagZ == true) {
PendingCycles--; PendingCycles -= 2;
PC = value16; PC = value16;
} }
PendingCycles -= 2; PendingCycles -= 2;
@ -2174,7 +2174,7 @@ throw new Exception("break");
value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000)); value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));
rel8 = (sbyte) ReadMemory(PC++); rel8 = (sbyte) ReadMemory(PC++);
if ((value8 & 0x80) != 0) { if ((value8 & 0x80) != 0) {
PendingCycles--; PendingCycles -= 2;
PC = (ushort)(PC+rel8); PC = (ushort)(PC+rel8);
} }
PendingCycles -= 6; PendingCycles -= 6;

View File

@ -12,9 +12,11 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx
public int[] Palette = new int[512]; public int[] Palette = new int[512];
public byte DotClock; 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) public void WriteVCE(int port, byte value)
{ {
//cpu.PendingCycles--; // VCE access puts CPU into a 1-cycle wait state.
switch (port) switch (port)
{ {
case 0: // Control Port. Doesn't control anything we care about... 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) public byte ReadVCE(int port)
{ {
//cpu.PendingCycles--;
switch (port) switch (port)
{ {
case 4: // Data LSB case 4: // Data LSB

View File

@ -165,7 +165,7 @@ namespace HuC6280
Set(0x44, "BSR", AddrMode.Relative, 8); // Branch to Subroutine Set(0x44, "BSR", AddrMode.Relative, 8); // Branch to Subroutine
// CPU Break // CPU Break
Set(0x00, "BRK", AddrMode.Implicit, 7); Set(0x00, "BRK", AddrMode.Implicit, 8);
// Compare accumulator // Compare accumulator
Set(0xC9, "CMP", AddrMode.Immediate, 2); Set(0xC9, "CMP", AddrMode.Immediate, 2);
@ -234,7 +234,7 @@ namespace HuC6280
Set(0x7C, "JMP", AddrMode.AbsoluteIndirectX, 7); Set(0x7C, "JMP", AddrMode.AbsoluteIndirectX, 7);
// Jump to Subroutine // Jump to Subroutine
Set(0x20, "JSR", AddrMode.Absolute, 6); Set(0x20, "JSR", AddrMode.Absolute, 7);
// Load Accumulator // Load Accumulator
Set(0xA9, "LDA", AddrMode.Immediate, 2); Set(0xA9, "LDA", AddrMode.Immediate, 2);
@ -408,8 +408,8 @@ namespace HuC6280
Set(0xB3, "TST", AddrMode.ImmAbsoluteX, 8); Set(0xB3, "TST", AddrMode.ImmAbsoluteX, 8);
// Cpu Speed instructions // Cpu Speed instructions
Set(0xD4, "CSH", AddrMode.Implicit, 2); Set(0xD4, "CSH", AddrMode.Implicit, 3);
Set(0x54, "CSL", AddrMode.Implicit, 2); Set(0x54, "CSL", AddrMode.Implicit, 3);
// Block Memory Transfer instructions // Block Memory Transfer instructions
Set(0xF3, "TAI", AddrMode.BlockMove, 17); // Transfer Alternate Increment Set(0xF3, "TAI", AddrMode.BlockMove, 17); // Transfer Alternate Increment

View File

@ -98,7 +98,7 @@ namespace HuC6280
w.WriteLine(Spaces + "value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));"); w.WriteLine(Spaces + "value8 = ReadMemory((ushort)(ReadMemory(PC++)+0x2000));");
w.WriteLine(Spaces + "rel8 = (sbyte) ReadMemory(PC++);"); w.WriteLine(Spaces + "rel8 = (sbyte) ReadMemory(PC++);");
w.WriteLine(Spaces + "if ((value8 & "+filter+") "+cond+" 0) {"); 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 + " PC = (ushort)(PC+rel8);");
w.WriteLine(Spaces + "}"); w.WriteLine(Spaces + "}");
w.WriteLine(Spaces + "PendingCycles -= {0};", op.Cycles); w.WriteLine(Spaces + "PendingCycles -= {0};", op.Cycles);
@ -108,7 +108,7 @@ namespace HuC6280
{ {
GetAddress(op, w, "value16"); GetAddress(op, w, "value16");
w.WriteLine(Spaces + "if (Flag" + flag + " == " + cond.ToString().ToLower() + ") {"); 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 + " PC = value16;");
w.WriteLine(Spaces + "}"); w.WriteLine(Spaces + "}");
w.WriteLine(Spaces + "PendingCycles -= {0};", op.Cycles); w.WriteLine(Spaces + "PendingCycles -= {0};", op.Cycles);