From 82ad2194616e51f383fef2aacda3d29c38af1a3f Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 20 Mar 2011 20:42:12 +0000 Subject: [PATCH] [NES] some little speedups, just to prove that it can be done --- .../Consoles/Nintendo/NES/APU.cs | 13 +++++----- .../Consoles/Nintendo/NES/BoardSystem.cs | 1 - .../Consoles/Nintendo/NES/Core.cs | 24 +++++++++---------- .../Consoles/Nintendo/NES/NES.cs | 10 +++++--- .../Consoles/Nintendo/NES/PPU.run.cs | 4 ++-- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs index 64e37dd18c..08296f77cb 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs @@ -233,6 +233,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo int timer_counter; public int sample; int env_output, env_start_flag, env_divider, env_counter; + bool noise_bit = true; public bool IsLenCntNonZero() { return len_cnt > 0; } @@ -304,7 +305,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo public void Run() { if (timer_counter > 0) timer_counter--; - if (timer_counter == 0) + if (timer_counter == 0 && period_cnt != 0) { //reload timer timer_counter = period_cnt; @@ -315,12 +316,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo shift_register >>= 1; shift_register &= ~(1 << 14); shift_register |= (feedback << 14); + noise_bit = (shift_register & 1)!=0; } - sample = env_output; - if ((shift_register & 1) == 0) sample = 0; - if (len_cnt == 0) - sample = 0; + if (noise_bit || len_cnt==0) sample = 0; + else + sample = env_output; } } @@ -546,7 +547,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo metaspu.buffer.clear(); } - void RunOne() + public void RunOne() { pulse[0].Run(); pulse[1].Run(); diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs index 8b446f949c..84a01efa16 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs @@ -250,7 +250,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo if (choices.Count == 0) return null; //pick the first board for this hash arbitrarily. it probably doesn't make a difference - Console.WriteLine("Chose board from nescartdb:"); return choices[0]; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index 34b1996d9c..5a99243c60 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -65,6 +65,13 @@ namespace BizHawk.Emulation.Consoles.Nintendo bool resetSignal; public void FrameAdvance(bool render) { + if (resetSignal) + { + cpu.PC = cpu.ReadWord(MOS6502.ResetVector); + apu.WriteReg(0x4015, 0); + cpu.FlagI = true; + } + Controller.UpdateControls(Frame++); if (resetSignal) Controller.UnpressButton("Reset"); @@ -74,24 +81,17 @@ namespace BizHawk.Emulation.Consoles.Nintendo protected void RunCpu(int ppu_cycles) { - if (resetSignal) - { - cpu.PC = cpu.ReadWord(MOS6502.ResetVector); - apu.WriteReg(0x4015, 0); - cpu.FlagI = true; - } - int cycles = ppu_cycles; if (ppu.PAL) - cycles *= 15; + cycles *= 15; else - cycles *= 16; + cycles <<= 4; cpu_accumulate += cycles; - int todo = cpu_accumulate / 48; - cpu_accumulate -= todo * 48; - if (todo > 0) + if (cpu_accumulate >= 48) { + int todo = cpu_accumulate / 48; + cpu_accumulate -= todo * 48; cpu.Execute(todo); apu.Run(todo); } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs index 2675e07201..ab4fc9b887 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs @@ -412,7 +412,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo CartInfo choice = null; if(USE_DATABASE) choice = IdentifyFromBootGodDB(hash_sha1); - if(choice == null) + if (choice == null) { if (USE_DATABASE) { @@ -435,10 +435,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo else { origin = EDetectionOrigin.GameDB; - Console.WriteLine("Chose board from gamedb: "); + Console.WriteLine("Chose board from gamedb: " + board); } } - else origin = EDetectionOrigin.BootGodDB; + else + { + Console.WriteLine("Chose board from nescartdb: " + choice.board_type); + origin = EDetectionOrigin.BootGodDB; + } Console.WriteLine(choice.game); Console.WriteLine(choice); diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.run.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.run.cs index 05d88226c0..e2b196083b 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.run.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/PPU.run.cs @@ -403,7 +403,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo //screen (or basically, the first nametable address that will be accessed when //the PPU is fetching background data on the next scanline). //(not implemented yet) - runppu(kFetchTime); + runppu(kFetchTime*2); if (sl == 0) { if (idleSynch && reg_2001.PPUON && !PAL) @@ -414,7 +414,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo } else ppur.status.end_cycle = 341; - runppu(kFetchTime); + //runppu(kFetchTime); //After memory access 170, the PPU simply rests for 4 cycles (or the //equivelant of half a memory access cycle) before repeating the whole