Remove pointer from sound struct, use index instead
This makes serialization possible, previously it was broken.
This commit is contained in:
		
							parent
							
								
									ba51aa6a1c
								
							
						
					
					
						commit
						5fe5121c81
					
				
					 3 changed files with 6 additions and 7 deletions
				
			
		| 
						 | 
					@ -25,8 +25,7 @@
 | 
				
			||||||
  u32 initial_volume = (value >> 12) & 0x0F;                                  \
 | 
					  u32 initial_volume = (value >> 12) & 0x0F;                                  \
 | 
				
			||||||
  u32 envelope_ticks = ((value >> 8) & 0x07) * 4;                             \
 | 
					  u32 envelope_ticks = ((value >> 8) & 0x07) * 4;                             \
 | 
				
			||||||
  gbc_sound_channel[channel].length_ticks = 64 - (value & 0x3F);              \
 | 
					  gbc_sound_channel[channel].length_ticks = 64 - (value & 0x3F);              \
 | 
				
			||||||
  gbc_sound_channel[channel].sample_data =                                    \
 | 
					  gbc_sound_channel[channel].sample_table_idx = ((value >> 6) & 0x03);        \
 | 
				
			||||||
   square_pattern_duty[(value >> 6) & 0x03];                                  \
 | 
					 | 
				
			||||||
  gbc_sound_channel[channel].envelope_direction = (value >> 11) & 0x01;       \
 | 
					  gbc_sound_channel[channel].envelope_direction = (value >> 11) & 0x01;       \
 | 
				
			||||||
  gbc_sound_channel[channel].envelope_initial_volume = initial_volume;        \
 | 
					  gbc_sound_channel[channel].envelope_initial_volume = initial_volume;        \
 | 
				
			||||||
  gbc_sound_channel[channel].envelope_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
 | 
					   // Oops, these contain raw pointers
 | 
				
			||||||
   for(i = 0; i < 4; i++)
 | 
					   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;
 | 
					   instruction_count = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										6
									
								
								sound.c
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								sound.c
									
										
									
									
									
								
							| 
						 | 
					@ -456,7 +456,7 @@ void update_gbc_sound(u32 cpu_ticks)
 | 
				
			||||||
    if(gs->active_flag)
 | 
					    if(gs->active_flag)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      sound_status |= 0x01;
 | 
					      sound_status |= 0x01;
 | 
				
			||||||
      sample_data = gs->sample_data;
 | 
					      sample_data = &square_pattern_duty[gs->sample_table_idx][0];
 | 
				
			||||||
      envelope_volume = gs->envelope_volume;
 | 
					      envelope_volume = gs->envelope_volume;
 | 
				
			||||||
      gbc_sound_render_channel(samples, 8, envelope, sweep);
 | 
					      gbc_sound_render_channel(samples, 8, envelope, sweep);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -465,7 +465,7 @@ void update_gbc_sound(u32 cpu_ticks)
 | 
				
			||||||
    if(gs->active_flag)
 | 
					    if(gs->active_flag)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      sound_status |= 0x02;
 | 
					      sound_status |= 0x02;
 | 
				
			||||||
      sample_data = gs->sample_data;
 | 
					      sample_data = &square_pattern_duty[gs->sample_table_idx][0];
 | 
				
			||||||
      envelope_volume = gs->envelope_volume;
 | 
					      envelope_volume = gs->envelope_volume;
 | 
				
			||||||
      gbc_sound_render_channel(samples, 8, envelope, nosweep);
 | 
					      gbc_sound_render_channel(samples, 8, envelope, nosweep);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -594,7 +594,7 @@ void reset_sound(void)
 | 
				
			||||||
  for(i = 0; i < 4; i++, gs++)
 | 
					  for(i = 0; i < 4; i++, gs++)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    gs->status = GBC_SOUND_INACTIVE;
 | 
					    gs->status = GBC_SOUND_INACTIVE;
 | 
				
			||||||
    gs->sample_data = square_pattern_duty[2];
 | 
					    gs->sample_table_idx = 2;
 | 
				
			||||||
    gs->active_flag = 0;
 | 
					    gs->active_flag = 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								sound.h
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								sound.h
									
										
									
									
									
								
							| 
						 | 
					@ -92,7 +92,7 @@ typedef struct
 | 
				
			||||||
   gbc_sound_status_type status;
 | 
					   gbc_sound_status_type status;
 | 
				
			||||||
   u32 active_flag;
 | 
					   u32 active_flag;
 | 
				
			||||||
   u32 master_enable;
 | 
					   u32 master_enable;
 | 
				
			||||||
   const s8* sample_data;
 | 
					   u32 sample_table_idx;
 | 
				
			||||||
} gbc_sound_struct;
 | 
					} gbc_sound_struct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const extern s8 square_pattern_duty[4][8];
 | 
					const extern s8 square_pattern_duty[4][8];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue