From 07c2b3aa055936a3ec4fc93dd25309609e1bca4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Tue, 30 Mar 2021 22:06:28 +0100 Subject: [PATCH] Fix PSG channel 3 one-shot mode --- source/gb_core/sound.c | 38 ++++++++++++++++++---------------- source/gba_core/sound.c | 45 ++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/source/gb_core/sound.c b/source/gb_core/sound.c index fb21f42..f5a2f97 100644 --- a/source/gb_core/sound.c +++ b/source/gb_core/sound.c @@ -543,7 +543,7 @@ void GB_SoundRegWrite(u32 address, u32 value) Sound.Chn1.frequency = freq; Sound.Chn1.frequency_steps = freq; - Sound.Chn1.limittime = (Sound.Chn1.reg[4] & (1 << 6)); + Sound.Chn1.limittime = (value & (1 << 6)); if (value & (1 << 7)) { @@ -712,16 +712,17 @@ void GB_SoundRegWrite(u32 address, u32 value) Sound.Chn3.limittime = (value & (1 << 6)); - if (Sound.Chn3.playing) // ? + if (Sound.Chn3.playing && (value & (1 << 7))) { - if (value & (1 << 7)) - { - //Sound.Chn3.playing = 1; // ? - Sound.Chn3.samplecount = 0; - mem->IO_Ports[NR52_REG - 0xFF00] |= (1 << 2); - GB_SoundLoadWave(); - Sound.Chn3.running = 1; - } + Sound.Chn3.samplecount = 0; + mem->IO_Ports[NR52_REG - 0xFF00] |= (1 << 2); + GB_SoundLoadWave(); + Sound.Chn3.running = 1; + } + else + { + Sound.Chn3.running = 0; + mem->IO_Ports[NR52_REG - 0xFF00] &= ~(1 << 2); } return; } @@ -1107,14 +1108,17 @@ void GB_SoundUpdateClocksCounterReference(int reference_clocks) // Channel 3 if (Sound.Chn3.running) { - if (Sound.Chn3.stepsleft > 0) - { - Sound.Chn3.stepsleft--; - } - else if (Sound.Chn3.limittime) + if (Sound.Chn3.limittime) { - Sound.Chn3.running = 0; - mem->IO_Ports[NR52_REG - 0xFF00] &= ~(1 << 2); + if (Sound.Chn3.stepsleft > 0) + { + Sound.Chn3.stepsleft--; + } + else + { + Sound.Chn3.running = 0; + mem->IO_Ports[NR52_REG - 0xFF00] &= ~(1 << 2); + } } } diff --git a/source/gba_core/sound.c b/source/gba_core/sound.c index 11502fc..75d3848 100644 --- a/source/gba_core/sound.c +++ b/source/gba_core/sound.c @@ -752,14 +752,17 @@ u32 GBA_SoundUpdate(u32 clocks) // Channel 3 if (Sound.Chn3.running) { - if (Sound.Chn3.stepsleft > 0) + if (Sound.Chn3.limittime) { - Sound.Chn3.stepsleft--; - } - else if (Sound.Chn3.limittime) - { - Sound.Chn3.running = 0; - REG_SOUNDCNT_X &= ~(1 << 2); + if (Sound.Chn3.stepsleft > 0) + { + Sound.Chn3.stepsleft--; + } + else + { + Sound.Chn3.running = 0; + REG_SOUNDCNT_X &= ~(1 << 2); + } } } @@ -1208,26 +1211,22 @@ void GBA_SoundRegWrite16(u32 address, u16 value) case SOUND3CNT_X: Sound.Chn3.reg[2] = value; - if (Sound.Chn3.playing) - { - Sound.Chn3.frequency = value & 0x07FF; - Sound.Chn3.frequency_steps = Sound.Chn3.frequency; - } + Sound.Chn3.frequency = value & 0x07FF; + Sound.Chn3.frequency_steps = Sound.Chn3.frequency; - Sound.Chn3.limittime = (value & (1 << 6)); + Sound.Chn3.limittime = (value & (1 << 14)); - if (Sound.Chn3.playing) // ? + if (Sound.Chn3.playing && (value & (1 << 15))) { Sound.Chn3.samplecount = 0; - - if (value & (1 << 15)) - { - //Sound.Chn3.playing = 1; // ? - Sound.Chn3.samplecount = 0; - REG_SOUNDCNT_X |= (1 << 2); - GBA_SoundLoadWave(); - Sound.Chn3.running = 1; - } + REG_SOUNDCNT_X |= (1 << 2); + GBA_SoundLoadWave(); + Sound.Chn3.running = 1; + } + else + { + Sound.Chn3.running = 0; + REG_SOUNDCNT_X &= ~(1 << 2); } return;