diff --git a/BizHawk.Emulation/CPUs/MOS 6502/Disassembler.cs b/BizHawk.Emulation/CPUs/MOS 6502/Disassembler.cs index 62dd9c3bf2..b2071b0963 100644 --- a/BizHawk.Emulation/CPUs/MOS 6502/Disassembler.cs +++ b/BizHawk.Emulation/CPUs/MOS 6502/Disassembler.cs @@ -24,15 +24,15 @@ namespace BizHawk.Emulation.CPUs.M6502 case 0x0D: bytesToAdvance = 3; return string.Format("ORA ${0:X4}", ReadWord(++pc)); case 0x0E: bytesToAdvance = 3; return string.Format("ASL ${0:X4}", ReadWord(++pc)); case 0x10: bytesToAdvance = 2; return string.Format("BPL {0}", (sbyte)ReadMemory(++pc)); - case 0x11: bytesToAdvance = 2; return string.Format("ORA (${0:X2}),Y", ReadMemory(++pc)); + case 0x11: bytesToAdvance = 2; return "?"; case 0x14: bytesToAdvance = 2; return string.Format("NOP ${0:X2},X", ReadMemory(++pc)); case 0x15: bytesToAdvance = 2; return string.Format("ORA ${0:X2},X", ReadMemory(++pc)); case 0x16: bytesToAdvance = 2; return string.Format("ASL ${0:X2},X", ReadMemory(++pc)); case 0x18: bytesToAdvance = 1; return "CLC"; - case 0x19: bytesToAdvance = 3; return string.Format("ORA ${0:X4},Y", ReadWord(++pc)); + case 0x19: bytesToAdvance = 3; return "?"; case 0x1A: bytesToAdvance = 1; return "NOP"; case 0x1C: bytesToAdvance = 2; return string.Format("NOP (${0:X2},X)", ReadMemory(++pc)); - case 0x1D: bytesToAdvance = 3; return string.Format("ORA ${0:X4},X", ReadWord(++pc)); + case 0x1D: bytesToAdvance = 3; return "?"; case 0x1E: bytesToAdvance = 3; return string.Format("ASL ${0:X4},X", ReadWord(++pc)); case 0x20: bytesToAdvance = 3; return string.Format("JSR ${0:X4}", ReadWord(++pc)); case 0x21: bytesToAdvance = 2; return string.Format("AND (${0:X2},X)", ReadMemory(++pc)); @@ -46,15 +46,15 @@ namespace BizHawk.Emulation.CPUs.M6502 case 0x2D: bytesToAdvance = 3; return string.Format("AND ${0:X4}", ReadWord(++pc)); case 0x2E: bytesToAdvance = 3; return string.Format("ROL ${0:X4}", ReadWord(++pc)); case 0x30: bytesToAdvance = 2; return string.Format("BMI {0}", (sbyte)ReadMemory(++pc)); - case 0x31: bytesToAdvance = 2; return string.Format("AND (${0:X2}),Y", ReadMemory(++pc)); + case 0x31: bytesToAdvance = 2; return "?"; case 0x34: bytesToAdvance = 2; return string.Format("NOP ${0:X2},X", ReadMemory(++pc)); case 0x35: bytesToAdvance = 2; return string.Format("AND ${0:X2},X", ReadMemory(++pc)); case 0x36: bytesToAdvance = 2; return string.Format("ROL ${0:X2},X", ReadMemory(++pc)); case 0x38: bytesToAdvance = 1; return "SEC"; - case 0x39: bytesToAdvance = 3; return string.Format("AND ${0:X4},Y", ReadWord(++pc)); + case 0x39: bytesToAdvance = 3; return "?"; case 0x3A: bytesToAdvance = 1; return "NOP"; case 0x3C: bytesToAdvance = 2; return string.Format("NOP (${0:X2},X)", ReadMemory(++pc)); - case 0x3D: bytesToAdvance = 3; return string.Format("AND ${0:X4},X", ReadWord(++pc)); + case 0x3D: bytesToAdvance = 3; return "?"; case 0x3E: bytesToAdvance = 3; return string.Format("ROL ${0:X4},X", ReadWord(++pc)); case 0x40: bytesToAdvance = 1; return "RTI"; case 0x41: bytesToAdvance = 2; return string.Format("EOR (${0:X2},X)", ReadMemory(++pc)); @@ -68,15 +68,15 @@ namespace BizHawk.Emulation.CPUs.M6502 case 0x4D: bytesToAdvance = 3; return string.Format("EOR ${0:X4}", ReadWord(++pc)); case 0x4E: bytesToAdvance = 3; return string.Format("LSR ${0:X4}", ReadWord(++pc)); case 0x50: bytesToAdvance = 2; return string.Format("BVC {0}", (sbyte)ReadMemory(++pc)); - case 0x51: bytesToAdvance = 2; return string.Format("EOR (${0:X2}),Y", ReadMemory(++pc)); + case 0x51: bytesToAdvance = 2; return "?"; case 0x54: bytesToAdvance = 2; return string.Format("NOP ${0:X2},X", ReadMemory(++pc)); case 0x55: bytesToAdvance = 2; return string.Format("EOR ${0:X2},X", ReadMemory(++pc)); case 0x56: bytesToAdvance = 2; return string.Format("LSR ${0:X2},X", ReadMemory(++pc)); case 0x58: bytesToAdvance = 1; return "CLI"; - case 0x59: bytesToAdvance = 3; return string.Format("EOR ${0:X4},Y", ReadWord(++pc)); + case 0x59: bytesToAdvance = 3; return "?"; case 0x5A: bytesToAdvance = 1; return "NOP"; case 0x5C: bytesToAdvance = 2; return string.Format("NOP (${0:X2},X)", ReadMemory(++pc)); - case 0x5D: bytesToAdvance = 3; return string.Format("EOR ${0:X4},X", ReadWord(++pc)); + case 0x5D: bytesToAdvance = 3; return "?"; case 0x5E: bytesToAdvance = 3; return string.Format("LSR ${0:X4},X", ReadWord(++pc)); case 0x60: bytesToAdvance = 1; return "RTS"; case 0x61: bytesToAdvance = 2; return string.Format("ADC (${0:X2},X)", ReadMemory(++pc)); @@ -90,15 +90,15 @@ namespace BizHawk.Emulation.CPUs.M6502 case 0x6D: bytesToAdvance = 3; return string.Format("ADC ${0:X4}", ReadWord(++pc)); case 0x6E: bytesToAdvance = 3; return string.Format("ROR ${0:X4}", ReadWord(++pc)); case 0x70: bytesToAdvance = 2; return string.Format("BVS {0}", (sbyte)ReadMemory(++pc)); - case 0x71: bytesToAdvance = 2; return string.Format("ADC (${0:X2}),Y", ReadMemory(++pc)); + case 0x71: bytesToAdvance = 2; return "?"; case 0x74: bytesToAdvance = 2; return string.Format("NOP ${0:X2},X", ReadMemory(++pc)); case 0x75: bytesToAdvance = 2; return string.Format("ADC ${0:X2},X", ReadMemory(++pc)); case 0x76: bytesToAdvance = 2; return string.Format("ROR ${0:X2},X", ReadMemory(++pc)); case 0x78: bytesToAdvance = 1; return "SEI"; - case 0x79: bytesToAdvance = 3; return string.Format("ADC ${0:X4},Y", ReadWord(++pc)); + case 0x79: bytesToAdvance = 3; return "?"; case 0x7A: bytesToAdvance = 1; return "NOP"; case 0x7C: bytesToAdvance = 2; return string.Format("NOP (${0:X2},X)", ReadMemory(++pc)); - case 0x7D: bytesToAdvance = 3; return string.Format("ADC ${0:X4},X", ReadWord(++pc)); + case 0x7D: bytesToAdvance = 3; return "?"; case 0x7E: bytesToAdvance = 3; return string.Format("ROR ${0:X4},X", ReadWord(++pc)); case 0x80: bytesToAdvance = 2; return string.Format("NOP #${0:X2}", ReadMemory(++pc)); case 0x81: bytesToAdvance = 2; return string.Format("STA (${0:X2},X)", ReadMemory(++pc)); @@ -134,16 +134,16 @@ namespace BizHawk.Emulation.CPUs.M6502 case 0xAD: bytesToAdvance = 3; return string.Format("LDA ${0:X4}", ReadWord(++pc)); case 0xAE: bytesToAdvance = 3; return string.Format("LDX ${0:X4}", ReadWord(++pc)); case 0xB0: bytesToAdvance = 2; return string.Format("BCS {0}", (sbyte)ReadMemory(++pc)); - case 0xB1: bytesToAdvance = 2; return string.Format("LDA (${0:X2}),Y", ReadMemory(++pc)); + case 0xB1: bytesToAdvance = 2; return "?"; case 0xB4: bytesToAdvance = 2; return string.Format("LDY ${0:X2},X", ReadMemory(++pc)); case 0xB5: bytesToAdvance = 2; return string.Format("LDA ${0:X2},X", ReadMemory(++pc)); case 0xB6: bytesToAdvance = 2; return string.Format("LDX ${0:X2},Y", ReadMemory(++pc)); case 0xB8: bytesToAdvance = 1; return "CLV"; - case 0xB9: bytesToAdvance = 3; return string.Format("LDA ${0:X4},Y", ReadWord(++pc)); + case 0xB9: bytesToAdvance = 3; return "?"; case 0xBA: bytesToAdvance = 1; return "TSX"; - case 0xBC: bytesToAdvance = 3; return string.Format("LDY ${0:X4},X", ReadWord(++pc)); - case 0xBD: bytesToAdvance = 3; return string.Format("LDA ${0:X4},X", ReadWord(++pc)); - case 0xBE: bytesToAdvance = 3; return string.Format("LDX ${0:X4},Y", ReadWord(++pc)); + case 0xBC: bytesToAdvance = 3; return "?"; + case 0xBD: bytesToAdvance = 3; return "?"; + case 0xBE: bytesToAdvance = 3; return "?"; case 0xC0: bytesToAdvance = 2; return string.Format("CPY #${0:X2}", ReadMemory(++pc)); case 0xC1: bytesToAdvance = 2; return string.Format("CMP (${0:X2},X)", ReadMemory(++pc)); case 0xC2: bytesToAdvance = 2; return string.Format("NOP #${0:X2}", ReadMemory(++pc)); @@ -157,15 +157,15 @@ namespace BizHawk.Emulation.CPUs.M6502 case 0xCD: bytesToAdvance = 3; return string.Format("CMP ${0:X4}", ReadWord(++pc)); case 0xCE: bytesToAdvance = 3; return string.Format("DEC ${0:X4}", ReadWord(++pc)); case 0xD0: bytesToAdvance = 2; return string.Format("BNE {0}", (sbyte)ReadMemory(++pc)); - case 0xD1: bytesToAdvance = 2; return string.Format("CMP (${0:X2}),Y", ReadMemory(++pc)); + case 0xD1: bytesToAdvance = 2; return "?"; case 0xD4: bytesToAdvance = 2; return string.Format("NOP ${0:X2},X", ReadMemory(++pc)); case 0xD5: bytesToAdvance = 2; return string.Format("CMP ${0:X2},X", ReadMemory(++pc)); case 0xD6: bytesToAdvance = 2; return string.Format("DEC ${0:X2},X", ReadMemory(++pc)); case 0xD8: bytesToAdvance = 1; return "CLD"; - case 0xD9: bytesToAdvance = 3; return string.Format("CMP ${0:X4},Y", ReadWord(++pc)); + case 0xD9: bytesToAdvance = 3; return "?"; case 0xDA: bytesToAdvance = 1; return "NOP"; case 0xDC: bytesToAdvance = 2; return string.Format("NOP (${0:X2},X)", ReadMemory(++pc)); - case 0xDD: bytesToAdvance = 3; return string.Format("CMP ${0:X4},X", ReadWord(++pc)); + case 0xDD: bytesToAdvance = 3; return "?"; case 0xDE: bytesToAdvance = 3; return string.Format("DEC ${0:X4},X", ReadWord(++pc)); case 0xE0: bytesToAdvance = 2; return string.Format("CPX #${0:X2}", ReadMemory(++pc)); case 0xE1: bytesToAdvance = 2; return string.Format("SBC (${0:X2},X)", ReadMemory(++pc)); @@ -180,15 +180,15 @@ namespace BizHawk.Emulation.CPUs.M6502 case 0xED: bytesToAdvance = 3; return string.Format("SBC ${0:X4}", ReadWord(++pc)); case 0xEE: bytesToAdvance = 3; return string.Format("INC ${0:X4}", ReadWord(++pc)); case 0xF0: bytesToAdvance = 2; return string.Format("BEQ {0}", (sbyte)ReadMemory(++pc)); - case 0xF1: bytesToAdvance = 2; return string.Format("SBC (${0:X2}),Y", ReadMemory(++pc)); + case 0xF1: bytesToAdvance = 2; return "?"; case 0xF4: bytesToAdvance = 2; return string.Format("NOP ${0:X2},X", ReadMemory(++pc)); case 0xF5: bytesToAdvance = 2; return string.Format("SBC ${0:X2},X", ReadMemory(++pc)); case 0xF6: bytesToAdvance = 2; return string.Format("INC ${0:X2},X", ReadMemory(++pc)); case 0xF8: bytesToAdvance = 1; return "SED"; - case 0xF9: bytesToAdvance = 3; return string.Format("SBC ${0:X4},Y", ReadWord(++pc)); + case 0xF9: bytesToAdvance = 3; return "?"; case 0xFA: bytesToAdvance = 1; return "NOP"; case 0xFC: bytesToAdvance = 2; return string.Format("NOP (${0:X2},X)", ReadMemory(++pc)); - case 0xFD: bytesToAdvance = 3; return string.Format("SBC ${0:X4},X", ReadWord(++pc)); + case 0xFD: bytesToAdvance = 3; return "?"; case 0xFE: bytesToAdvance = 3; return string.Format("INC ${0:X4},X", ReadWord(++pc)); } bytesToAdvance = 1; diff --git a/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs b/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs index 674bb028fc..6146ff3508 100644 --- a/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs +++ b/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs @@ -60,7 +60,7 @@ TriggerException(ExceptionType.BRK); value8 = ReadMemory(ReadMemory(PC++)); A |= value8; P = (byte)((P & 0x7D) | TableNZ[A]); - PendingCycles -= 2; TotalExecutedCycles += 2; + PendingCycles -= 3; TotalExecutedCycles += 3; break; case 0x06: // ASL zp value16 = ReadMemory(PC++); @@ -117,7 +117,7 @@ TriggerException(ExceptionType.BRK); } PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0x11: // ORA (addr),Y + case 0x11: // ORA (addr),Y* temp16 = ReadWordPageWrap(ReadMemory(PC++)); value8 = ReadMemory((ushort)(temp16+Y)); if ((temp16 & 0xFF00) != ((temp16+Y) & 0xFF00)) @@ -133,7 +133,7 @@ TriggerException(ExceptionType.BRK); value8 = ReadMemory((byte)(ReadMemory(PC++)+X)); A |= value8; P = (byte)((P & 0x7D) | TableNZ[A]); - PendingCycles -= 3; TotalExecutedCycles += 3; + PendingCycles -= 4; TotalExecutedCycles += 4; break; case 0x16: // ASL zp,X value16 = (byte)(ReadMemory(PC++)+X); @@ -148,9 +148,10 @@ TriggerException(ExceptionType.BRK); FlagC = false; PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0x19: // ORA addr,Y - value8 = ReadMemory((ushort)(ReadWord(PC)+Y)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0x19: // ORA addr,Y* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+Y)); + if ((temp16 & 0xFF00) != ((temp16 + Y) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; A |= value8; @@ -163,9 +164,10 @@ TriggerException(ExceptionType.BRK); case 0x1C: // NOP (addr,X) PendingCycles -= 4; TotalExecutedCycles += 4; break; - case 0x1D: // ORA addr,X - value8 = ReadMemory((ushort)(ReadWord(PC)+X)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0x1D: // ORA addr,X* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+X)); + if ((temp16 & 0xFF00) != ((temp16 + X) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; A |= value8; @@ -174,8 +176,6 @@ TriggerException(ExceptionType.BRK); break; case 0x1E: // ASL addr,X value16 = (ushort)(ReadWord(PC)+X); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) - { PendingCycles--; TotalExecutedCycles++; } PC += 2; value8 = ReadMemory(value16); FlagC = (value8 & 0x80) != 0; @@ -208,7 +208,7 @@ TriggerException(ExceptionType.BRK); value8 = ReadMemory(ReadMemory(PC++)); A &= value8; P = (byte)((P & 0x7D) | TableNZ[A]); - PendingCycles -= 2; TotalExecutedCycles += 2; + PendingCycles -= 3; TotalExecutedCycles += 3; break; case 0x26: // ROL zp value16 = ReadMemory(PC++); @@ -278,7 +278,7 @@ FlagT = true;//this seems wrong } PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0x31: // AND (addr),Y + case 0x31: // AND (addr),Y* temp16 = ReadWordPageWrap(ReadMemory(PC++)); value8 = ReadMemory((ushort)(temp16+Y)); if ((temp16 & 0xFF00) != ((temp16+Y) & 0xFF00)) @@ -294,7 +294,7 @@ FlagT = true;//this seems wrong value8 = ReadMemory((byte)(ReadMemory(PC++)+X)); A &= value8; P = (byte)((P & 0x7D) | TableNZ[A]); - PendingCycles -= 3; TotalExecutedCycles += 3; + PendingCycles -= 4; TotalExecutedCycles += 4; break; case 0x36: // ROL zp,X value16 = (byte)(ReadMemory(PC++)+X); @@ -309,9 +309,10 @@ FlagT = true;//this seems wrong FlagC = true; PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0x39: // AND addr,Y - value8 = ReadMemory((ushort)(ReadWord(PC)+Y)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0x39: // AND addr,Y* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+Y)); + if ((temp16 & 0xFF00) != ((temp16 + Y) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; A &= value8; @@ -324,9 +325,10 @@ FlagT = true;//this seems wrong case 0x3C: // NOP (addr,X) PendingCycles -= 4; TotalExecutedCycles += 4; break; - case 0x3D: // AND addr,X - value8 = ReadMemory((ushort)(ReadWord(PC)+X)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0x3D: // AND addr,X* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+X)); + if ((temp16 & 0xFF00) != ((temp16 + X) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; A &= value8; @@ -335,8 +337,6 @@ FlagT = true;//this seems wrong break; case 0x3E: // ROL addr,X value16 = (ushort)(ReadWord(PC)+X); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) - { PendingCycles--; TotalExecutedCycles++; } PC += 2; value8 = temp8 = ReadMemory(value16); value8 = (byte)((value8 << 1) | (P & 1)); @@ -422,7 +422,7 @@ FlagT = true;// this seems wrong } PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0x51: // EOR (addr),Y + case 0x51: // EOR (addr),Y* temp16 = ReadWordPageWrap(ReadMemory(PC++)); value8 = ReadMemory((ushort)(temp16+Y)); if ((temp16 & 0xFF00) != ((temp16+Y) & 0xFF00)) @@ -454,9 +454,10 @@ FlagT = true;// this seems wrong CLI_Pending = true; PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0x59: // EOR addr,Y - value8 = ReadMemory((ushort)(ReadWord(PC)+Y)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0x59: // EOR addr,Y* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+Y)); + if ((temp16 & 0xFF00) != ((temp16 + Y) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; A ^= value8; @@ -469,9 +470,10 @@ FlagT = true;// this seems wrong case 0x5C: // NOP (addr,X) PendingCycles -= 4; TotalExecutedCycles += 4; break; - case 0x5D: // EOR addr,X - value8 = ReadMemory((ushort)(ReadWord(PC)+X)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0x5D: // EOR addr,X* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+X)); + if ((temp16 & 0xFF00) != ((temp16 + X) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; A ^= value8; @@ -480,8 +482,6 @@ FlagT = true;// this seems wrong break; case 0x5E: // LSR addr,X value16 = (ushort)(ReadWord(PC)+X); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) - { PendingCycles--; TotalExecutedCycles++; } PC += 2; value8 = ReadMemory(value16); FlagC = (value8 & 1) != 0; @@ -580,7 +580,7 @@ FlagT = true;// this seems wrong } PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0x71: // ADC (addr),Y + case 0x71: // ADC (addr),Y* temp16 = ReadWordPageWrap(ReadMemory(PC++)); value8 = ReadMemory((ushort)(temp16+Y)); if ((temp16 & 0xFF00) != ((temp16+Y) & 0xFF00)) @@ -618,9 +618,10 @@ FlagT = true;// this seems wrong SEI_Pending = true; PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0x79: // ADC addr,Y - value8 = ReadMemory((ushort)(ReadWord(PC)+Y)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0x79: // ADC addr,Y* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+Y)); + if ((temp16 & 0xFF00) != ((temp16 + Y) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; temp = value8 + A + (FlagC ? 1 : 0); @@ -636,9 +637,10 @@ FlagT = true;// this seems wrong case 0x7C: // NOP (addr,X) PendingCycles -= 4; TotalExecutedCycles += 4; break; - case 0x7D: // ADC addr,X - value8 = ReadMemory((ushort)(ReadWord(PC)+X)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0x7D: // ADC addr,X* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+X)); + if ((temp16 & 0xFF00) != ((temp16 + X) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; temp = value8 + A + (FlagC ? 1 : 0); @@ -650,8 +652,6 @@ FlagT = true;// this seems wrong break; case 0x7E: // ROR addr,X value16 = (ushort)(ReadWord(PC)+X); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) - { PendingCycles--; TotalExecutedCycles++; } PC += 2; value8 = temp8 = ReadMemory(value16); value8 = (byte)((value8 >> 1) | ((P & 1)<<7)); @@ -664,7 +664,8 @@ FlagT = true;// this seems wrong PendingCycles -= 2; TotalExecutedCycles += 2; break; case 0x81: // STA (addr,X) - value16 = ReadWordPageWrap((byte)(ReadMemory(PC++)+X)); + temp16 = ReadWordPageWrap(ReadMemory(PC++)); + value16 = (ushort)(temp16+X); WriteMemory(value16, A); PendingCycles -= 6; TotalExecutedCycles += 6; break; @@ -727,8 +728,6 @@ FlagT = true;// this seems wrong case 0x91: // STA (addr),Y temp16 = ReadWordPageWrap(ReadMemory(PC++)); value16 = (ushort)(temp16+Y); - if ((temp16 & 0xFF00) != ((temp16+Y) & 0xFF00)) - { PendingCycles--; TotalExecutedCycles++; } WriteMemory(value16, A); PendingCycles -= 6; TotalExecutedCycles += 6; break; @@ -754,8 +753,6 @@ FlagT = true;// this seems wrong break; case 0x99: // STA addr,Y value16 = (ushort)(ReadWord(PC)+Y); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) - { PendingCycles--; TotalExecutedCycles++; } PC += 2; WriteMemory(value16, A); PendingCycles -= 5; TotalExecutedCycles += 5; @@ -766,8 +763,6 @@ FlagT = true;// this seems wrong break; case 0x9D: // STA addr,X value16 = (ushort)(ReadWord(PC)+X); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) - { PendingCycles--; TotalExecutedCycles++; } PC += 2; WriteMemory(value16, A); PendingCycles -= 5; TotalExecutedCycles += 5; @@ -843,7 +838,7 @@ FlagT = true;// this seems wrong } PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0xB1: // LDA (addr),Y + case 0xB1: // LDA (addr),Y* temp16 = ReadWordPageWrap(ReadMemory(PC++)); A = ReadMemory((ushort)(temp16+Y)); if ((temp16 & 0xFF00) != ((temp16+Y) & 0xFF00)) @@ -870,9 +865,10 @@ FlagT = true;// this seems wrong FlagV = false; PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0xB9: // LDA addr,Y - A = ReadMemory((ushort)(ReadWord(PC)+Y)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0xB9: // LDA addr,Y* + temp16 = ReadWord(PC); + A = ReadMemory((ushort)(temp16+Y)); + if ((temp16 & 0xFF00) != ((temp16 + Y) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; P = (byte)((P & 0x7D) | TableNZ[A]); @@ -883,25 +879,28 @@ FlagT = true;// this seems wrong P = (byte)((P & 0x7D) | TableNZ[X]); PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0xBC: // LDY addr,X - Y = ReadMemory((ushort)(ReadWord(PC)+X)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0xBC: // LDY addr,X* + temp16 = ReadWord(PC); + Y = ReadMemory((ushort)(temp16+X)); + if ((temp16 & 0xFF00) != ((temp16 + X) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; P = (byte)((P & 0x7D) | TableNZ[Y]); PendingCycles -= 4; TotalExecutedCycles += 4; break; - case 0xBD: // LDA addr,X - A = ReadMemory((ushort)(ReadWord(PC)+X)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0xBD: // LDA addr,X* + temp16 = ReadWord(PC); + A = ReadMemory((ushort)(temp16+X)); + if ((temp16 & 0xFF00) != ((temp16 + X) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; P = (byte)((P & 0x7D) | TableNZ[A]); PendingCycles -= 4; TotalExecutedCycles += 4; break; - case 0xBE: // LDX addr,Y - X = ReadMemory((ushort)(ReadWord(PC)+Y)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0xBE: // LDX addr,Y* + temp16 = ReadWord(PC); + X = ReadMemory((ushort)(temp16+Y)); + if ((temp16 & 0xFF00) != ((temp16 + Y) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; P = (byte)((P & 0x7D) | TableNZ[X]); @@ -929,7 +928,7 @@ FlagT = true;// this seems wrong value16 = (ushort) (Y - value8); FlagC = (Y >= value8); P = (byte)((P & 0x7D) | TableNZ[(byte)value16]); - PendingCycles -= 2; + PendingCycles -= 3; break; case 0xC5: // CMP zp value8 = ReadMemory(ReadMemory(PC++)); @@ -992,7 +991,7 @@ FlagT = true;// this seems wrong } PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0xD1: // CMP (addr),Y + case 0xD1: // CMP (addr),Y* temp16 = ReadWordPageWrap(ReadMemory(PC++)); value8 = ReadMemory((ushort)(temp16+Y)); if ((temp16 & 0xFF00) != ((temp16+Y) & 0xFF00)) @@ -1023,9 +1022,10 @@ FlagT = true;// this seems wrong FlagD = false; PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0xD9: // CMP addr,Y - value8 = ReadMemory((ushort)(ReadWord(PC)+Y)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0xD9: // CMP addr,Y* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+Y)); + if ((temp16 & 0xFF00) != ((temp16 + Y) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; value16 = (ushort) (A - value8); @@ -1039,9 +1039,10 @@ FlagT = true;// this seems wrong case 0xDC: // NOP (addr,X) PendingCycles -= 4; TotalExecutedCycles += 4; break; - case 0xDD: // CMP addr,X - value8 = ReadMemory((ushort)(ReadWord(PC)+X)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0xDD: // CMP addr,X* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+X)); + if ((temp16 & 0xFF00) != ((temp16 + X) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; value16 = (ushort) (A - value8); @@ -1051,8 +1052,6 @@ FlagT = true;// this seems wrong break; case 0xDE: // DEC addr,X value16 = (ushort)(ReadWord(PC)+X); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) - { PendingCycles--; TotalExecutedCycles++; } PC += 2; value8 = (byte)(ReadMemory(value16) - 1); WriteMemory(value16, value8); @@ -1083,7 +1082,7 @@ FlagT = true;// this seems wrong value16 = (ushort) (X - value8); FlagC = (X >= value8); P = (byte)((P & 0x7D) | TableNZ[(byte)value16]); - PendingCycles -= 2; + PendingCycles -= 3; break; case 0xE5: // SBC zp value8 = ReadMemory(ReadMemory(PC++)); @@ -1151,7 +1150,7 @@ FlagT = true;// this seems wrong } PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0xF1: // SBC (addr),Y + case 0xF1: // SBC (addr),Y* temp16 = ReadWordPageWrap(ReadMemory(PC++)); value8 = ReadMemory((ushort)(temp16+Y)); if ((temp16 & 0xFF00) != ((temp16+Y) & 0xFF00)) @@ -1186,9 +1185,10 @@ FlagT = true;// this seems wrong FlagD = true; PendingCycles -= 2; TotalExecutedCycles += 2; break; - case 0xF9: // SBC addr,Y - value8 = ReadMemory((ushort)(ReadWord(PC)+Y)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0xF9: // SBC addr,Y* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+Y)); + if ((temp16 & 0xFF00) != ((temp16 + Y) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; temp = A - value8 - (FlagC?0:1); @@ -1204,9 +1204,10 @@ FlagT = true;// this seems wrong case 0xFC: // NOP (addr,X) PendingCycles -= 4; TotalExecutedCycles += 4; break; - case 0xFD: // SBC addr,X - value8 = ReadMemory((ushort)(ReadWord(PC)+X)); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) + case 0xFD: // SBC addr,X* + temp16 = ReadWord(PC); + value8 = ReadMemory((ushort)(temp16+X)); + if ((temp16 & 0xFF00) != ((temp16 + X) & 0xFF00)) { PendingCycles--; TotalExecutedCycles++; } PC += 2; temp = A - value8 - (FlagC?0:1); @@ -1218,8 +1219,6 @@ FlagT = true;// this seems wrong break; case 0xFE: // INC addr,X value16 = (ushort)(ReadWord(PC)+X); - if ((PC & 0xFF00) != ((PC+Y) & 0xFF00)) - { PendingCycles--; TotalExecutedCycles++; } PC += 2; value8 = (byte)(ReadMemory(value16) + 1); WriteMemory(value16, value8); diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs index b1d3170705..cf43999127 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs @@ -41,6 +41,15 @@ namespace BizHawk.Emulation.Consoles.Nintendo videoProvider = new MyVideoProvider(this); } + public void WriteLogTimestamp() + { + Console.Write("[{0:d5}:{1:d3}:{2:d3}]", Frame, ppu.ppur.status.sl, ppu.ppur.status.cycle); + } + public void LogLine(string format, params object[] args) + { + Console.WriteLine("[{0:d5}:{1:d3}:{2:d3}] {3}", Frame, ppu.ppur.status.sl, ppu.ppur.status.cycle, string.Format(format, args)); + } + NESWatch GetWatch(NESWatch.EDomain domain, int address) { if (domain == NESWatch.EDomain.Sysbus) diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.regs.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.regs.cs index 896621457e..d92e61aafb 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.regs.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.regs.cs @@ -439,6 +439,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo addr &= 0x1F; byte color = (byte)(value & 0x3F); //are these bits really unwired? can they be read back somehow? + //this little hack will help you debug things while the screen is black + //color = (byte)(addr & 0x3F); + PALRAM[addr] = color; if ((addr & 3) == 0) {