Skip to content

Commit

Permalink
Fix PSG channel 3 one-shot mode
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioND committed Mar 30, 2021
1 parent d8a53ce commit 07c2b3a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
38 changes: 21 additions & 17 deletions source/gb_core/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
45 changes: 22 additions & 23 deletions source/gba_core/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 07c2b3a

Please sign in to comment.