diff --git a/src/tic.c b/src/tic.c index 0d7c963..f5f295b 100644 --- a/src/tic.c +++ b/src/tic.c @@ -53,7 +53,7 @@ typedef enum CHUNK_TEMP, // 6 CHUNK_TEMP2, // 7 CHUNK_TEMP3, // 8 - CHUNK_SOUND, // 9 + CHUNK_SAMPLES, // 9 CHUNK_WAVEFORM, // 10 CHUNK_TEMP4, // 11 CHUNK_PALETTE, // 12 @@ -68,7 +68,7 @@ typedef struct u32 size:24; } Chunk; -STATIC_ASSERT(rom_chunk_size, sizeof(Chunk) == 4); +STATIC_ASSERT(tic_chunk_size, sizeof(Chunk) == 4); STATIC_ASSERT(tic_map, sizeof(tic_map) < 1024*32); STATIC_ASSERT(tic_sample, sizeof(tic_sample) == 66); STATIC_ASSERT(tic_track_pattern, sizeof(tic_track_pattern) == 3*MUSIC_PATTERN_ROWS); @@ -1619,14 +1619,14 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet switch(chunk.type) { - case CHUNK_TILES: memcpy(&cart->banks[bank.tiles++].tiles, buffer, min(sizeof(tic_tiles), chunk.size)); break; - case CHUNK_SPRITES: memcpy(&cart->banks[bank.sprites++].sprites, buffer, min(sizeof(tic_tiles), chunk.size)); break; - case CHUNK_MAP: memcpy(&cart->banks[bank.map++].map, buffer, min(sizeof(tic_map), chunk.size)); break; - case CHUNK_CODE: memcpy(&cart->banks[bank.code++].code, buffer, min(sizeof(tic_code), chunk.size)); break; - case CHUNK_SOUND: memcpy(&cart->banks[bank.sfx++].sfx.samples, buffer, min(sizeof(tic_samples), chunk.size)); break; - case CHUNK_WAVEFORM: memcpy(&cart->banks[bank.waves++].sfx.waveform, buffer, min(sizeof(tic_waveforms), chunk.size)); break; - case CHUNK_MUSIC: memcpy(&cart->banks[bank.tracks++].music.tracks, buffer, min(sizeof(tic_tracks), chunk.size)); break; - case CHUNK_PATTERNS: memcpy(&cart->banks[bank.patterns++].music.patterns, buffer, min(sizeof(tic_patterns), chunk.size)); break; + case CHUNK_TILES: LOAD_CHUNK(cart->banks[bank.tiles++].tiles); break; + case CHUNK_SPRITES: LOAD_CHUNK(cart->banks[bank.sprites++].sprites); break; + case CHUNK_MAP: LOAD_CHUNK(cart->banks[bank.map++].map); break; + case CHUNK_CODE: LOAD_CHUNK(cart->banks[bank.code++].code); break; + case CHUNK_SAMPLES: LOAD_CHUNK(cart->banks[bank.sfx++].sfx.samples); break; + case CHUNK_WAVEFORM: LOAD_CHUNK(cart->banks[bank.waves++].sfx.waveform); break; + case CHUNK_MUSIC: LOAD_CHUNK(cart->banks[bank.tracks++].music.tracks); break; + case CHUNK_PATTERNS: LOAD_CHUNK(cart->banks[bank.patterns++].music.patterns); break; case CHUNK_PALETTE: if(palette) LOAD_CHUNK(cart->palette); @@ -1688,16 +1688,19 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer) #define SAVE_CHUNK(id, from) saveChunk(buffer, id, &from, sizeof(from)) - buffer = SAVE_CHUNK(CHUNK_TILES, cart->bank0.tiles); - buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank0.sprites); - buffer = SAVE_CHUNK(CHUNK_MAP, cart->bank0.map); - buffer = SAVE_CHUNK(CHUNK_CODE, cart->bank0.code); - buffer = SAVE_CHUNK(CHUNK_SOUND, cart->bank0.sfx.samples); - buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->bank0.sfx.waveform); - buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank0.music.patterns.data); - buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank0.music.tracks.data); - buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); + for(s32 i = 0; i < TIC_BANKS; i++) + { + buffer = SAVE_CHUNK(CHUNK_TILES, cart->banks[i].tiles); + buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->banks[i].sprites); + buffer = SAVE_CHUNK(CHUNK_MAP, cart->banks[i].map); + buffer = SAVE_CHUNK(CHUNK_CODE, cart->banks[i].code); + buffer = SAVE_CHUNK(CHUNK_SAMPLES, cart->banks[i].sfx.samples); + buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->banks[i].sfx.waveform); + buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->banks[i].music.patterns); + buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->banks[i].music.tracks); + } + buffer = SAVE_CHUNK(CHUNK_PALETTE, cart->palette); buffer = saveFixedChunk(buffer, CHUNK_COVER, cart->cover.data, cart->cover.size); #undef SAVE_CHUNK