From 4e85d82f1477bbdd8a543871e1096edd9283b288 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 27 Feb 2011 09:49:53 +0000 Subject: [PATCH] update 6502 core generator legit-like --- BizHawk.Emulation/CPUs/MOS 6502/Execute.cs | 34 ++++++++++------------ CpuCoreGenerator/MOS 6502/CoreGenerator.cs | 19 ++++++++++-- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs b/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs index 8fd4129744..d2ca288a82 100644 --- a/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs +++ b/BizHawk.Emulation/CPUs/MOS 6502/Execute.cs @@ -17,23 +17,23 @@ namespace BizHawk.Emulation.CPUs.M6502 PendingCycles += cycles; while (PendingCycles > 0) { - if (NMI) - { - WriteMemory((ushort)(S-- + 0x100), (byte)(PC >> 8)); - WriteMemory((ushort)(S-- + 0x100), (byte)PC); - byte oldP = P; - FlagB = false; - FlagT = true; - WriteMemory((ushort)(S-- + 0x100), P); - P = oldP; - FlagI = true; - PC = ReadWord(NMIVector); - PendingCycles -= 7; - NMI = false; - } + if (NMI) + { + WriteMemory((ushort)(S-- + 0x100), (byte)(PC >> 8)); + WriteMemory((ushort)(S-- + 0x100), (byte)PC); + byte oldP = P; + FlagB = false; + FlagT = true; + WriteMemory((ushort)(S-- + 0x100), P); + P = oldP; + FlagI = true; + PC = ReadWord(NMIVector); + PendingCycles -= 7; + NMI = false; + } if(debug) Console.WriteLine(State()); - ushort this_pc = PC; + ushort this_pc = PC; byte opcode = ReadMemory(PC++); switch (opcode) { @@ -748,10 +748,6 @@ FlagT = true;// this seems wrong PendingCycles -= 4; TotalExecutedCycles += 4; break; case 0xAD: // LDA addr - if (this_pc == 0x800A) - { - int zzz = 9; - } A = ReadMemory(ReadWord(PC)); PC += 2; P = (byte)((P & 0x7D) | TableNZ[A]); PendingCycles -= 4; TotalExecutedCycles += 4; diff --git a/CpuCoreGenerator/MOS 6502/CoreGenerator.cs b/CpuCoreGenerator/MOS 6502/CoreGenerator.cs index bdbeb087e3..0e7f280728 100644 --- a/CpuCoreGenerator/MOS 6502/CoreGenerator.cs +++ b/CpuCoreGenerator/MOS 6502/CoreGenerator.cs @@ -329,10 +329,25 @@ namespace M6502 w.WriteLine(" while (PendingCycles > 0)"); w.WriteLine(" {"); + w.WriteLine(" if (NMI)"); + w.WriteLine(" {"); + w.WriteLine(" WriteMemory((ushort)(S-- + 0x100), (byte)(PC >> 8));"); + w.WriteLine(" WriteMemory((ushort)(S-- + 0x100), (byte)PC);"); + w.WriteLine(" byte oldP = P;"); + w.WriteLine(" FlagB = false;"); + w.WriteLine(" FlagT = true;"); + w.WriteLine(" WriteMemory((ushort)(S-- + 0x100), P);"); + w.WriteLine(" P = oldP;"); + w.WriteLine(" FlagI = true;"); + w.WriteLine(" PC = ReadWord(NMIVector);"); + w.WriteLine(" PendingCycles -= 7;"); + w.WriteLine(" NMI = false;"); + w.WriteLine(" }"); + w.WriteLine(""); + w.WriteLine("if(debug) Console.WriteLine(State());"); - // TODO interrupts, halt state, shit like that - + w.WriteLine(" ushort this_pc = PC;"); w.WriteLine(" byte opcode = ReadMemory(PC++);"); w.WriteLine(" switch (opcode)"); w.WriteLine(" {");