From 01fc137256fcc54f3b7baf58831726913a2267bd Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 6 Sep 2016 22:36:16 +0300 Subject: [PATCH] Fixed an APU issue that might occur when having more than one GB_gameboy_t object --- Core/apu.c | 9 ++++----- Core/apu.h | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/apu.c b/Core/apu.c index c4085eed..1234a151 100755 --- a/Core/apu.c +++ b/Core/apu.c @@ -271,7 +271,6 @@ uint8_t GB_apu_read(GB_gameboy_t *gb, uint8_t reg) void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) { static const double duties[] = {0.125, 0.25, 0.5, 0.75}; - static uint16_t NRX3_X4_temp[3] = {0}; uint8_t channel = 0; if (!gb->apu.global_enable && reg != GB_IO_NR52) { @@ -336,8 +335,8 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) case GB_IO_NR13: case GB_IO_NR23: case GB_IO_NR33: - NRX3_X4_temp[channel] = (NRX3_X4_temp[channel] & 0xFF00) | value; - gb->apu.wave_channels[channel].frequency = 131072.0 / (2048 - NRX3_X4_temp[channel]); + gb->apu.NRX3_X4_temp[channel] = (gb->apu.NRX3_X4_temp[channel] & 0xFF00) | value; + gb->apu.wave_channels[channel].frequency = 131072.0 / (2048 - gb->apu.NRX3_X4_temp[channel]); if (channel == 2) { gb->apu.wave_channels[channel].frequency /= 2; } @@ -353,8 +352,8 @@ void GB_apu_write(GB_gameboy_t *gb, uint8_t reg, uint8_t value) gb->apu.wave_channels[channel].cur_envelope_steps = gb->apu.wave_channels[channel].envelope_steps; } - NRX3_X4_temp[channel] = (NRX3_X4_temp[channel] & 0xFF) | ((value & 0x7) << 8); - gb->apu.wave_channels[channel].frequency = 131072.0 / (2048 - NRX3_X4_temp[channel]); + gb->apu.NRX3_X4_temp[channel] = (gb->apu.NRX3_X4_temp[channel] & 0xFF) | ((value & 0x7) << 8); + gb->apu.wave_channels[channel].frequency = 131072.0 / (2048 - gb->apu.NRX3_X4_temp[channel]); if (channel == 2) { gb->apu.wave_channels[channel].frequency /= 2; } diff --git a/Core/apu.h b/Core/apu.h index 835c569f..4e2f1308 100644 --- a/Core/apu.h +++ b/Core/apu.h @@ -53,6 +53,7 @@ typedef struct bool left_on[4]; bool right_on[4]; bool global_enable; + uint16_t NRX3_X4_temp[3]; } GB_apu_t; void GB_apu_render(GB_gameboy_t *gb, unsigned int sample_rate, unsigned int n_samples, GB_sample_t *samples);