From 6bd0fbccef8777a427e20b9b16a840eee84e4489 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Tue, 7 Jan 2020 18:28:12 -0500 Subject: [PATCH] NESHawk: scanline timing and audio fix --- .../Consoles/Nintendo/NES/APU.cs | 16 ++++++++-------- .../Consoles/Nintendo/NES/PPU.run.cs | 10 ++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs index d76a55e839..759e7822a8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/APU.cs @@ -43,8 +43,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES noise = new NoiseUnit(this, pal); triangle = new TriangleUnit(this); - pulse[0] = new PulseUnit(this, 0); - pulse[1] = new PulseUnit(this, 1); + pulse[0] = new PulseUnit(this, 1); + pulse[1] = new PulseUnit(this, 0); if (old != null) { m_vol = old.m_vol; @@ -156,10 +156,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case 3: if (apu.len_clock_active) { - if (len_cnt==0) + if (len_cnt == 0) { - len_cnt = LENGTH_TABLE[(val >> 3) & 0x1F]+1; - } + len_cnt = LENGTH_TABLE[(val >> 3) & 0x1F] + 1; + } } else { len_cnt = LENGTH_TABLE[(val >> 3) & 0x1F]; @@ -167,7 +167,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES timer_reload_value = (timer_reload_value & 0xFF) | ((val & 0x07) << 8); timer_raw_reload_value = timer_reload_value * 2 + 2; - duty_step = 0; + duty_step = 0; env_start_flag = 1; // allow the lenctr_en to kill the len_cnt @@ -202,7 +202,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES // this should be optimized to update only when `timer_reload_value` changes int sweep_shifter = timer_reload_value >> sweep_shiftcount; if (sweep_negate == 1) - sweep_shifter = -sweep_shifter + unit; + sweep_shifter = -sweep_shifter - unit; sweep_shifter += timer_reload_value; // this sweep logic is always enabled: @@ -234,7 +234,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } } - // env_loopdoubles as "halt length counter" + // env_loop doubles as "halt length counter" if ((env_loop == 0 || len_halt) && len_cnt > 0) len_cnt--; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs index 27712dde96..14a3bc717b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.run.cs @@ -308,9 +308,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES if (yp >= read_value && yp < read_value + spriteHeight && spr_true_count == 0) { //a flag gets set if sprite zero is in range - if (oam_index == reg_2003) - sprite_zero_in_range = true; - + if (oam_index == reg_2003) { sprite_zero_in_range = true; } + spr_true_count++; soam_m_index++; } @@ -442,7 +441,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES //2. is the bg pixel nonzero? //then, it is spritehit. Reg2002_objhit |= (sprite_zero_go && s == 0 && pixel != 0 && rasterpos < 255 && show_bg_new && show_obj_new); - //priority handling, if in front of BG: bool drawsprite = !(((temp_attr & 0x20) != 0) && ((pixel & 3) != 0)); if (drawsprite && nes.Settings.DispSprites) @@ -466,7 +464,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { ppur.increment_hsc(); - if (ppur.status.cycle == 256) + if ((ppur.status.cycle == 256) && ppu_was_on) { ppur.increment_vs(); } @@ -540,7 +538,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { ppur.increment_hsc(); - if (ppur.status.cycle == 256) + if ((ppur.status.cycle == 256) && ppu_was_on) { ppur.increment_vs(); }