Remove pointer from sound struct, use index instead

This makes serialization possible, previously it was broken.
This commit is contained in:
David Guillen Fandos 2021-07-27 21:45:15 +02:00
parent ba51aa6a1c
commit 5fe5121c81
3 changed files with 6 additions and 7 deletions

View File

@ -25,8 +25,7 @@
u32 initial_volume = (value >> 12) & 0x0F; \
u32 envelope_ticks = ((value >> 8) & 0x07) * 4; \
gbc_sound_channel[channel].length_ticks = 64 - (value & 0x3F); \
gbc_sound_channel[channel].sample_data = \
square_pattern_duty[(value >> 6) & 0x03]; \
gbc_sound_channel[channel].sample_table_idx = ((value >> 6) & 0x03); \
gbc_sound_channel[channel].envelope_direction = (value >> 11) & 0x01; \
gbc_sound_channel[channel].envelope_initial_volume = initial_volume; \
gbc_sound_channel[channel].envelope_volume = initial_volume; \
@ -3183,7 +3182,7 @@ void gba_load_state(const void* src)
// Oops, these contain raw pointers
for(i = 0; i < 4; i++)
gbc_sound_channel[i].sample_data = square_pattern_duty[2];
gbc_sound_channel[i].sample_table_idx = 2;
instruction_count = 0;

View File

@ -456,7 +456,7 @@ void update_gbc_sound(u32 cpu_ticks)
if(gs->active_flag)
{
sound_status |= 0x01;
sample_data = gs->sample_data;
sample_data = &square_pattern_duty[gs->sample_table_idx][0];
envelope_volume = gs->envelope_volume;
gbc_sound_render_channel(samples, 8, envelope, sweep);
}
@ -465,7 +465,7 @@ void update_gbc_sound(u32 cpu_ticks)
if(gs->active_flag)
{
sound_status |= 0x02;
sample_data = gs->sample_data;
sample_data = &square_pattern_duty[gs->sample_table_idx][0];
envelope_volume = gs->envelope_volume;
gbc_sound_render_channel(samples, 8, envelope, nosweep);
}
@ -594,7 +594,7 @@ void reset_sound(void)
for(i = 0; i < 4; i++, gs++)
{
gs->status = GBC_SOUND_INACTIVE;
gs->sample_data = square_pattern_duty[2];
gs->sample_table_idx = 2;
gs->active_flag = 0;
}
}

View File

@ -92,7 +92,7 @@ typedef struct
gbc_sound_status_type status;
u32 active_flag;
u32 master_enable;
const s8* sample_data;
u32 sample_table_idx;
} gbc_sound_struct;
const extern s8 square_pattern_duty[4][8];