From 1f0c9f2be883ab1c9d5dc23589217cbd4248c29e Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 15 Dec 2017 14:29:11 -0500 Subject: [PATCH] GBHawk: Fix audio and states --- BizHawk.Client.Common/PathManager.cs | 6 +++++ .../Consoles/Nintendo/GBHawk/Audio.cs | 26 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/BizHawk.Client.Common/PathManager.cs b/BizHawk.Client.Common/PathManager.cs index c77af2cca0..51826e93f5 100644 --- a/BizHawk.Client.Common/PathManager.cs +++ b/BizHawk.Client.Common/PathManager.cs @@ -336,6 +336,12 @@ namespace BizHawk.Client.Common name += "." + Global.Emulator.Attributes().CoreName; } + // Gambatte and GBHawk have incompatible savestates, store the name to keep them separate + if (Global.Emulator.SystemId == "GB") + { + name += "." + Global.Emulator.Attributes().CoreName; + } + if (Global.Emulator is Snes9x) // Keep snes9x savestate away from libsnes, we want to not be too tedious so bsnes names will just have the profile name not the core name { name += "." + Global.Emulator.Attributes().CoreName; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Audio.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Audio.cs index 6af2ade6ce..2574978258 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Audio.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawk/Audio.cs @@ -405,11 +405,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk NOISE_len_cntr = NOISE_length; break; case 0xFF21: // NR42 (envelope) - Audio_Regs[NR42] = value; NOISE_st_vol = (byte)((value & 0xF0) >> 4); NOISE_env_add = (value & 8) > 0; NOISE_per = (byte)(value & 7); + + // several glitchy effects happen when writing to NRx2 during audio playing + if (((Audio_Regs[NR42] & 7) == 0) && !NOISE_vol_done) { NOISE_vol_state++; } + else if ((Audio_Regs[NR42] & 8) == 0) { NOISE_vol_state += 2; } + + if (((Audio_Regs[NR42] ^ value) & 8) > 0) { NOISE_vol_state = (byte)(0x10 - NOISE_vol_state); } + + NOISE_vol_state &= 0xF; if ((value & 0xF8) == 0) { NOISE_enable = false; NOISE_output = 0; } + Audio_Regs[NR42] = value; break; case 0xFF22: // NR43 (shift) Audio_Regs[NR43] = value; @@ -978,7 +986,21 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk ser.Sync("sequencer_tick", ref sequencer_tick); ser.Sync("master_audio_clock", ref master_audio_clock); - } + + ser.Sync("AUD_CTRL_vin_L_en", ref AUD_CTRL_vin_L_en); + ser.Sync("AUD_CTRL_vin_R_en", ref AUD_CTRL_vin_R_en); + ser.Sync("AUD_CTRL_sq1_L_en", ref AUD_CTRL_sq1_L_en); + ser.Sync("AUD_CTRL_sq2_L_en", ref AUD_CTRL_sq2_L_en); + ser.Sync("AUD_CTRL_wave_L_en", ref AUD_CTRL_wave_L_en); + ser.Sync("AUD_CTRL_noise_L_en", ref AUD_CTRL_noise_L_en); + ser.Sync("AUD_CTRL_sq1_R_en", ref AUD_CTRL_sq1_R_en); + ser.Sync("AUD_CTRL_sq2_R_en", ref AUD_CTRL_sq2_R_en); + ser.Sync("AUD_CTRL_wave_R_en", ref AUD_CTRL_wave_R_en); + ser.Sync("AUD_CTRL_noise_R_en", ref AUD_CTRL_noise_R_en); + ser.Sync("AUD_CTRL_power", ref AUD_CTRL_power); + ser.Sync("AUD_CTRL_vol_L", ref AUD_CTRL_vol_L); + ser.Sync("AUD_CTRL_vol_R", ref AUD_CTRL_vol_R); + } public byte Read_NR52() {