diff --git a/BizHawk.Emulation/CPUs/MOS 6502X/Execute.cs b/BizHawk.Emulation/CPUs/MOS 6502X/Execute.cs index f298f1f961..70ac5e2aa8 100644 --- a/BizHawk.Emulation/CPUs/MOS 6502X/Execute.cs +++ b/BizHawk.Emulation/CPUs/MOS 6502X/Execute.cs @@ -283,12 +283,13 @@ namespace BizHawk.Emulation.CPUs.M6502 //0x100 /*VOP_Fetch1*/ new Uop[] { Uop.Fetch1 }, /*VOP_RelativeStuff*/ new Uop[] { Uop.RelBranch_Stage3, Uop.End }, + /*VOP_RelativeStuff2*/ new Uop[] { Uop.RelBranch_Stage4, Uop.End }, //i assume these are dummy fetches.... maybe theyre just nops? supposedly these take 7 cycles so thats the only way i can make sense of it //one of them might be the next instruction's fetch, and whatever fetch follows it. //the interrupt would then take place if necessary, using a cached PC. but im not so sure about that. /*VOP_NMI*/ new Uop[] { Uop.FetchDummy, Uop.FetchDummy, Uop.PushPCH, Uop.PushPCL, Uop.PushP_NMI, Uop.FetchPCLVector, Uop.FetchPCHVector, Uop.End }, /*VOP_IRQ*/ new Uop[] { Uop.FetchDummy, Uop.FetchDummy, Uop.PushPCH, Uop.PushPCL, Uop.PushP_IRQ, Uop.FetchPCLVector, Uop.FetchPCHVector, Uop.End }, - /*VOP_RelativeStuff2*/ new Uop[] { Uop.RelBranch_Stage4, Uop.End }, + /*VOP_RESET*/ new Uop[] { Uop.FetchDummy, Uop.FetchDummy, Uop.PushDummy, Uop.PushDummy, Uop.PushP_Reset, Uop.FetchPCLVector, Uop.FetchPCHVector, Uop.End }, }; enum Uop @@ -354,7 +355,7 @@ namespace BizHawk.Emulation.CPUs.M6502 IncS, DecS, PushPCL, PushPCH, PushPCH_B, PushP, PullP, PullPCL, PullPCH_NoInc, PushA, PullA_NoInc, PullP_NoInc, - PushP_BRK, PushP_NMI, PushP_IRQ, + PushP_BRK, PushP_NMI, PushP_IRQ, PushP_Reset, PushDummy, FetchPCLVector, FetchPCHVector, //todo - may not need these ?? can reuse fetch2 and fetch3? //[implied] and [accumulator] @@ -388,9 +389,10 @@ namespace BizHawk.Emulation.CPUs.M6502 const int VOP_Fetch1 = 256; const int VOP_RelativeStuff = 257; - const int VOP_NMI = 258; - const int VOP_IRQ = 259; - const int VOP_RelativeStuff2 = 260; + const int VOP_RelativeStuff2 = 258; + const int VOP_NMI = 259; + const int VOP_IRQ = 260; + const int VOP_RESET = 261; int opcode; byte opcode2, opcode3; //opcode bytes.. theoretically redundant with the temp variables? who knows. @@ -515,6 +517,14 @@ namespace BizHawk.Emulation.CPUs.M6502 FlagI = true; //is this right? ea = NMIVector; break; + case Uop.PushP_Reset: + ea = ResetVector; + S--; + FlagI = true; + break; + case Uop.PushDummy: + S--; + break; case Uop.FetchPCLVector: alu_temp = ReadMemory((ushort)ea); break; @@ -1225,12 +1235,12 @@ namespace BizHawk.Emulation.CPUs.M6502 break; case Uop.End_ISpecial: - opcode = 256; + opcode = VOP_Fetch1; mi = 0; goto RETRY; case Uop.End: - opcode = 256; + opcode = VOP_Fetch1; mi = 0; iflag_pending = FlagI; goto RETRY; diff --git a/BizHawk.Emulation/CPUs/MOS 6502X/MOS6502X.cs b/BizHawk.Emulation/CPUs/MOS 6502X/MOS6502X.cs index 87e888ffde..d1777d9d3f 100644 --- a/BizHawk.Emulation/CPUs/MOS 6502X/MOS6502X.cs +++ b/BizHawk.Emulation/CPUs/MOS 6502X/MOS6502X.cs @@ -29,6 +29,14 @@ namespace BizHawk.Emulation.CPUs.M6502 iflag_pending = true; } + public void NESSoftReset() + { + opcode = VOP_RESET; + mi = 0; + iflag_pending = true; + FlagI = true; + } + public string State() { int notused; diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index 6622e306f4..a7a1f709bb 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -68,9 +68,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo lagged = true; if (resetSignal) { - cpu.PC = cpu.ReadWord(MOS6502.ResetVector); - apu.WriteReg(0x4015, 0); - cpu.FlagI = true; + cpu.NESSoftReset(); + //need to study what happens to ppu and apu and stuff.. } Controller.UpdateControls(Frame++); diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.cs index 1402642b47..d17b321756 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.cs @@ -59,6 +59,19 @@ namespace BizHawk.Emulation.Consoles.Nintendo public PPU(NES nes) { this.nes = nes; + + OAM = new byte[0x100]; + PALRAM = new byte[0x20]; + + //power-up palette verified by blargg's power_up_palette test. + //he speculates that these may differ depending on the system tested.. + //and I don't see why the ppu would waste any effort setting these.. + //but for the sake of uniformity, we'll do it. + Array.Copy(new byte[] { + 0x09,0x01,0x00,0x01,0x00,0x02,0x02,0x0D,0x08,0x10,0x08,0x24,0x00,0x00,0x04,0x2C, + 0x09,0x01,0x34,0x03,0x00,0x04,0x00,0x14,0x08,0x3A,0x00,0x02,0x00,0x20,0x2C,0x08 + }, PALRAM, 0x20); + Reset(); } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.regs.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.regs.cs index f3cf2c6ecd..96391b585f 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.regs.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.regs.cs @@ -330,8 +330,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo Reg2002_vblank_active = false; PPUGenLatch = 0; reg_2003 = 0; - OAM = new byte[0x100]; - PALRAM = new byte[0x20]; vtoggle = false; VRAMBuffer = 0; }