From ae963b54437380bc94c7716857ea6af8a5ec3ea7 Mon Sep 17 00:00:00 2001 From: goyuken Date: Mon, 3 Dec 2012 15:01:04 +0000 Subject: [PATCH] nes: fix PAL DMC frequencies --- BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs | 13 ++++++++----- BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs | 5 ++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs index 8c35f9de55..a6cf49d482 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs @@ -34,10 +34,10 @@ namespace BizHawk.Emulation.Consoles.Nintendo public bool EnableDMC = true; NES nes; - public APU(NES nes, APU old = null) + public APU(NES nes, APU old, bool pal) { this.nes = nes; - dmc = new DMCUnit(this); + dmc = new DMCUnit(this, pal); if (old != null) { EnableSquare1 = old.EnableSquare1; @@ -49,6 +49,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo } static int[] DMC_RATE_NTSC = { 428, 380, 340, 320, 286, 254, 226, 214, 190, 160, 142, 128, 106, 84, 72, 54 }; + static int[] DMC_RATE_PAL = { 398, 354, 316, 298, 276, 236, 210, 198, 176, 148, 132, 118, 98, 78, 66, 50 }; static int[] LENGTH_TABLE = { 10, 254, 20, 2, 40, 4, 80, 6, 160, 8, 60, 10, 14, 12, 26, 14, 12, 16, 24, 18, 48, 20, 96, 22, 192, 24, 72, 26, 16, 28, 32, 30 }; static byte[,] PULSE_DUTY = { {0,1,0,0,0,0,0,0}, //(12.5%) @@ -548,11 +549,13 @@ namespace BizHawk.Emulation.Consoles.Nintendo class DMCUnit { APU apu; - public DMCUnit(APU apu) + int[] DMC_RATE; + public DMCUnit(APU apu, bool pal) { this.apu = apu; out_silence = true; - timer_reload = DMC_RATE_NTSC[0]; + DMC_RATE = pal ? DMC_RATE_PAL : DMC_RATE_NTSC; + timer_reload = DMC_RATE[0]; sample_buffer_filled = false; out_deltacounter = 64; out_bits_remaining = 0; @@ -700,7 +703,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo case 0: irq_enabled = val.Bit(7); loop_flag = val.Bit(6); - timer_reload = DMC_RATE_NTSC[val & 0xF]; + timer_reload = DMC_RATE[val & 0xF]; if (!irq_enabled) apu.dmc_irq = false; apu.SyncIRQ(); break; diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index 773255a299..18b52d891d 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -139,7 +139,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo BoardSystemHardReset(); - apu = new APU(this, apu); // don't replace the magicSoundProvider on reset, as it's not needed // if (magicSoundProvider != null) magicSoundProvider.Dispose(); @@ -150,6 +149,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo case "NES-PAL": case "NES-PAL-A": case "NES-PAL-B": + apu = new APU(this, apu, true); ppu.region = PPU.Region.PAL; CoreOutputComm.VsyncNum = 50; CoreOutputComm.VsyncDen = 1; @@ -159,6 +159,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo break; case "NES-NTSC": case "Famicom": + apu = new APU(this, apu, false); ppu.region = PPU.Region.NTSC; cpu_sequence = cpu_sequence_NTSC; if (magicSoundProvider == null) @@ -167,6 +168,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo // there's no official name for these in bootgod, not sure what we should use //case "PC10"://TODO case "VS": + apu = new APU(this, apu, false); ppu.region = PPU.Region.RGB; cpu_sequence = cpu_sequence_NTSC; if (magicSoundProvider == null) @@ -175,6 +177,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo break; // this is in bootgod, but not used at all case "Dendy": + apu = new APU(this, apu, false); ppu.region = PPU.Region.Dendy; CoreOutputComm.VsyncNum = 50; CoreOutputComm.VsyncDen = 1;