added banks loading from a .tic cart

This commit is contained in:
BADIM-PC\Vadim 2017-12-15 11:42:25 +03:00
parent e210027e71
commit 07616adaca
7 changed files with 66 additions and 49 deletions

View File

@ -602,14 +602,14 @@ static char* saveBinarySection(char* ptr, const char* comment, const char* tag,
typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection; typedef struct {char* tag; s32 count; s32 offset; s32 size; bool flip;} BinarySection;
static const BinarySection BinarySections[] = static const BinarySection BinarySections[] =
{ {
{"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false}, {"PALETTE", 1, offsetof(tic_cartridge, palette.data), sizeof(tic_palette), false},
{"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank0.tiles), sizeof(tic_tile), true}, {"TILES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank0.tiles), sizeof(tic_tile), true},
{"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank0.sprites), sizeof(tic_tile), true}, {"SPRITES", TIC_BANK_SPRITES, offsetof(tic_cartridge, bank0.sprites), sizeof(tic_tile), true},
{"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank0.map), TIC_MAP_WIDTH, true}, {"MAP", TIC_MAP_HEIGHT, offsetof(tic_cartridge, bank0.map), TIC_MAP_WIDTH, true},
{"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank0.sfx.waveform.envelopes), sizeof(tic_waveform), true}, {"WAVES", ENVELOPES_COUNT, offsetof(tic_cartridge, bank0.sfx.waveform), sizeof(tic_waveform), true},
{"SFX", SFX_COUNT, offsetof(tic_cartridge, bank0.sfx.data), sizeof(tic_sound_effect), true}, {"SFX", SFX_COUNT, offsetof(tic_cartridge, bank0.sfx.samples), sizeof(tic_sample), true},
{"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank0.music.patterns), sizeof(tic_track_pattern), true}, {"PATTERNS", MUSIC_PATTERNS, offsetof(tic_cartridge, bank0.music.patterns), sizeof(tic_track_pattern), true},
{"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank0.music.tracks), sizeof(tic_track), true}, {"TRACKS", MUSIC_TRACKS, offsetof(tic_cartridge, bank0.music.tracks), sizeof(tic_track), true},
}; };
static s32 saveProject(Console* console, void* buffer, const char* comment) static s32 saveProject(Console* console, void* buffer, const char* comment)
@ -2143,7 +2143,7 @@ static void onConsoleRamCommand(Console* console, const char* param)
{offsetof(tic_ram, persistent), "PERSISTENT MEMORY"}, {offsetof(tic_ram, persistent), "PERSISTENT MEMORY"},
{offsetof(tic_ram, registers), "SOUND REGISTERS"}, {offsetof(tic_ram, registers), "SOUND REGISTERS"},
{offsetof(tic_ram, sfx.waveform), "WAVEFORMS"}, {offsetof(tic_ram, sfx.waveform), "WAVEFORMS"},
{offsetof(tic_ram, sfx.data), "SFX"}, {offsetof(tic_ram, sfx.samples), "SFX"},
{offsetof(tic_ram, music.patterns.data), "MUSIC PATTERNS"}, {offsetof(tic_ram, music.patterns.data), "MUSIC PATTERNS"},
{offsetof(tic_ram, music.tracks.data), "MUSIC TRACKS"}, {offsetof(tic_ram, music.tracks.data), "MUSIC TRACKS"},
{offsetof(tic_ram, music_pos), "MUSIC POS"}, {offsetof(tic_ram, music_pos), "MUSIC POS"},

View File

@ -257,7 +257,7 @@ static duk_ret_t duk_sfx(duk_context* duk)
{ {
if(index >= 0) if(index >= 0)
{ {
tic_sound_effect* effect = memory->ram.sfx.data + index; tic_sample* effect = memory->ram.sfx.samples.data + index;
note = effect->note; note = effect->note;
octave = effect->octave; octave = effect->octave;

View File

@ -682,7 +682,7 @@ static s32 lua_sfx(lua_State* lua)
{ {
if (index >= 0) if (index >= 0)
{ {
tic_sound_effect* effect = memory->ram.sfx.data + index; tic_sample* effect = memory->ram.sfx.samples.data + index;
note = effect->note; note = effect->note;
octave = effect->octave; octave = effect->octave;

View File

@ -104,9 +104,9 @@ static void drawSwitch(Sfx* sfx, s32 x, s32 y, const char* label, s32 value, voi
} }
} }
static tic_sound_effect* getEffect(Sfx* sfx) static tic_sample* getEffect(Sfx* sfx)
{ {
return sfx->src->data + sfx->index; return sfx->src->samples.data + sfx->index;
} }
static void setIndex(Sfx* sfx, s32 delta) static void setIndex(Sfx* sfx, s32 delta)
@ -116,7 +116,7 @@ static void setIndex(Sfx* sfx, s32 delta)
static void setSpeed(Sfx* sfx, s32 delta) static void setSpeed(Sfx* sfx, s32 delta)
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
effect->speed += delta; effect->speed += delta;
@ -129,14 +129,14 @@ static void drawTopPanel(Sfx* sfx, s32 x, s32 y)
drawSwitch(sfx, x, y, "IDX", sfx->index, setIndex); drawSwitch(sfx, x, y, "IDX", sfx->index, setIndex);
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
drawSwitch(sfx, x += Gap, y, "SPD", effect->speed, setSpeed); drawSwitch(sfx, x += Gap, y, "SPD", effect->speed, setSpeed);
} }
static void setLoopStart(Sfx* sfx, s32 delta) static void setLoopStart(Sfx* sfx, s32 delta)
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
tic_sound_loop* loop = effect->loops + sfx->canvasTab; tic_sound_loop* loop = effect->loops + sfx->canvasTab;
loop->start += delta; loop->start += delta;
@ -146,7 +146,7 @@ static void setLoopStart(Sfx* sfx, s32 delta)
static void setLoopSize(Sfx* sfx, s32 delta) static void setLoopSize(Sfx* sfx, s32 delta)
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
tic_sound_loop* loop = effect->loops + sfx->canvasTab; tic_sound_loop* loop = effect->loops + sfx->canvasTab;
loop->size += delta; loop->size += delta;
@ -160,7 +160,7 @@ static void drawLoopPanel(Sfx* sfx, s32 x, s32 y)
enum {Gap = 2}; enum {Gap = 2};
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
tic_sound_loop* loop = effect->loops + sfx->canvasTab; tic_sound_loop* loop = effect->loops + sfx->canvasTab;
drawSwitch(sfx, x, y += Gap + TIC_FONT_HEIGHT, "", loop->size, setLoopSize); drawSwitch(sfx, x, y += Gap + TIC_FONT_HEIGHT, "", loop->size, setLoopSize);
@ -248,7 +248,7 @@ static void drawWaveButtons(Sfx* sfx, s32 x, s32 y)
if(checkMouseClick(&iconRect, SDL_BUTTON_LEFT)) if(checkMouseClick(&iconRect, SDL_BUTTON_LEFT))
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
for(s32 c = 0; c < SFX_TICKS; c++) for(s32 c = 0; c < SFX_TICKS; c++)
effect->data[c].wave = i; effect->data[c].wave = i;
} }
@ -270,7 +270,7 @@ static void drawWaveButtons(Sfx* sfx, s32 x, s32 y)
// draw full icon // draw full icon
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
u8 start = effect->data[0].wave; u8 start = effect->data[0].wave;
bool full = true; bool full = true;
for(s32 c = 1; c < SFX_TICKS; c++) for(s32 c = 1; c < SFX_TICKS; c++)
@ -310,7 +310,7 @@ static void drawCanvasTabs(Sfx* sfx, s32 x, s32 y)
sfx->tic->api.text(sfx->tic, Labels[i], rect.x, rect.y, i == sfx->canvasTab ? (tic_color_white) : (tic_color_dark_gray)); sfx->tic->api.text(sfx->tic, Labels[i], rect.x, rect.y, i == sfx->canvasTab ? (tic_color_white) : (tic_color_dark_gray));
} }
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
switch(sfx->canvasTab) switch(sfx->canvasTab)
{ {
@ -372,7 +372,7 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y)
SDL_Rect rect = {x, y, CANVAS_WIDTH, CANVAS_HEIGHT}; SDL_Rect rect = {x, y, CANVAS_WIDTH, CANVAS_HEIGHT};
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
if(checkMousePos(&rect)) if(checkMousePos(&rect))
{ {
@ -447,7 +447,7 @@ static void drawCanvas(Sfx* sfx, s32 x, s32 y)
static void drawPiano(Sfx* sfx, s32 x, s32 y) static void drawPiano(Sfx* sfx, s32 x, s32 y)
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
static const s32 ButtonIndixes[] = {0, 2, 4, 5, 7, 9, 11, 1, 3, -1, 6, 8, 10}; static const s32 ButtonIndixes[] = {0, 2, 4, 5, 7, 9, 11, 1, 3, -1, 6, 8, 10};
@ -514,7 +514,7 @@ static void drawPiano(Sfx* sfx, s32 x, s32 y)
static void drawOctavePanel(Sfx* sfx, s32 x, s32 y) static void drawOctavePanel(Sfx* sfx, s32 x, s32 y)
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
static const char Label[] = "OCT"; static const char Label[] = "OCT";
sfx->tic->api.text(sfx->tic, Label, x, y, (tic_color_white)); sfx->tic->api.text(sfx->tic, Label, x, y, (tic_color_white));
@ -545,7 +545,7 @@ static void playSound(Sfx* sfx)
{ {
if(sfx->play.active) if(sfx->play.active)
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
if(sfx->play.note != effect->note) if(sfx->play.note != effect->note)
{ {
@ -573,8 +573,8 @@ static void redo(Sfx* sfx)
static void copyToClipboard(Sfx* sfx) static void copyToClipboard(Sfx* sfx)
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
toClipboard(effect, sizeof(tic_sound_effect), true); toClipboard(effect, sizeof(tic_sample), true);
} }
static void copyWaveToClipboard(Sfx* sfx) static void copyWaveToClipboard(Sfx* sfx)
@ -585,8 +585,8 @@ static void copyWaveToClipboard(Sfx* sfx)
static void resetSfx(Sfx* sfx) static void resetSfx(Sfx* sfx)
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
memset(effect, 0, sizeof(tic_sound_effect)); memset(effect, 0, sizeof(tic_sample));
history_add(sfx->history); history_add(sfx->history);
} }
@ -613,9 +613,9 @@ static void cutWaveToClipboard(Sfx* sfx)
static void copyFromClipboard(Sfx* sfx) static void copyFromClipboard(Sfx* sfx)
{ {
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
if(fromClipboard(effect, sizeof(tic_sound_effect), true, false)) if(fromClipboard(effect, sizeof(tic_sample), true, false))
history_add(sfx->history); history_add(sfx->history);
} }
@ -660,7 +660,7 @@ static void processKeyboard(Sfx* sfx)
keyboardButton = i; keyboardButton = i;
} }
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
if(keyboardButton >= 0) if(keyboardButton >= 0)
{ {
@ -808,7 +808,7 @@ static void drawSfxToolbar(Sfx* sfx)
} }
} }
tic_sound_effect* effect = getEffect(sfx); tic_sample* effect = getEffect(sfx);
{ {
static const char* Notes[] = SFX_NOTES; static const char* Notes[] = SFX_NOTES;

View File

@ -332,7 +332,7 @@ tic_map* getBankMap()
void playSystemSfx(s32 id) void playSystemSfx(s32 id)
{ {
const tic_sound_effect* effect = &studio.tic->config.bank0.sfx.data[id]; const tic_sample* effect = &studio.tic->config.bank0.sfx.samples.data[id];
studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0); studio.tic->api.sfx_ex(studio.tic, id, effect->note, effect->octave, -1, 0, MAX_VOLUME, 0);
} }

View File

@ -70,7 +70,7 @@ typedef struct
STATIC_ASSERT(rom_chunk_size, sizeof(Chunk) == 4); STATIC_ASSERT(rom_chunk_size, sizeof(Chunk) == 4);
STATIC_ASSERT(tic_map, sizeof(tic_map) < 1024*32); STATIC_ASSERT(tic_map, sizeof(tic_map) < 1024*32);
STATIC_ASSERT(tic_sound_effect, sizeof(tic_sound_effect) == 66); STATIC_ASSERT(tic_sample, sizeof(tic_sample) == 66);
STATIC_ASSERT(tic_track_pattern, sizeof(tic_track_pattern) == 3*MUSIC_PATTERN_ROWS); STATIC_ASSERT(tic_track_pattern, sizeof(tic_track_pattern) == 3*MUSIC_PATTERN_ROWS);
STATIC_ASSERT(tic_track, sizeof(tic_track) == 3*MUSIC_FRAMES+3); STATIC_ASSERT(tic_track, sizeof(tic_track) == 3*MUSIC_FRAMES+3);
STATIC_ASSERT(tic_vram, sizeof(tic_vram) == TIC_VRAM_SIZE); STATIC_ASSERT(tic_vram, sizeof(tic_vram) == TIC_VRAM_SIZE);
@ -357,7 +357,7 @@ static void channelSfx(tic_mem* memory, s32 index, s32 note, s32 octave, s32 dur
if(index >= 0) if(index >= 0)
{ {
struct {s8 speed:SFX_SPEED_BITS;} temp = {speed}; struct {s8 speed:SFX_SPEED_BITS;} temp = {speed};
c->speed = speed == temp.speed ? speed : machine->sound.sfx->data[index].speed; c->speed = speed == temp.speed ? speed : machine->sound.sfx->samples.data[index].speed;
} }
// start index of idealized piano // start index of idealized piano
@ -1061,7 +1061,7 @@ static void sfx(tic_mem* memory, s32 index, s32 freq, Channel* channel, tic_soun
return; return;
} }
const tic_sound_effect* effect = &machine->sound.sfx->data[index]; const tic_sample* effect = &machine->sound.sfx->samples.data[index];
s32 pos = ++channel->tick; s32 pos = ++channel->tick;
s8 speed = channel->speed; s8 speed = channel->speed;
@ -1599,6 +1599,18 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet
#define LOAD_CHUNK(to) memcpy(&to, buffer, min(sizeof(to), chunk.size)) #define LOAD_CHUNK(to) memcpy(&to, buffer, min(sizeof(to), chunk.size))
struct
{
s32 tiles;
s32 sprites;
s32 map;
s32 sfx;
s32 waves;
s32 tracks;
s32 patterns;
s32 code;
} bank = {0, 0, 0, 0, 0, 0, 0, 0};
while(buffer < end) while(buffer < end)
{ {
Chunk chunk; Chunk chunk;
@ -1607,17 +1619,17 @@ static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palet
switch(chunk.type) switch(chunk.type)
{ {
case CHUNK_TILES: LOAD_CHUNK(cart->bank0.tiles); break; case CHUNK_TILES: memcpy(&cart->banks[bank.tiles++].tiles, buffer, min(sizeof(tic_tiles), chunk.size)); break;
case CHUNK_SPRITES: LOAD_CHUNK(cart->bank0.sprites); break; case CHUNK_SPRITES: memcpy(&cart->banks[bank.sprites++].sprites, buffer, min(sizeof(tic_tiles), chunk.size)); break;
case CHUNK_MAP: LOAD_CHUNK(cart->bank0.map); break; case CHUNK_MAP: memcpy(&cart->banks[bank.map++].map, buffer, min(sizeof(tic_map), chunk.size)); break;
case CHUNK_CODE: LOAD_CHUNK(cart->bank0.code); break; case CHUNK_CODE: memcpy(&cart->banks[bank.code++].code, buffer, min(sizeof(tic_code), chunk.size)); break;
case CHUNK_SOUND: LOAD_CHUNK(cart->bank0.sfx.data); break; case CHUNK_SOUND: memcpy(&cart->banks[bank.sfx++].sfx.samples, buffer, min(sizeof(tic_samples), chunk.size)); break;
case CHUNK_WAVEFORM: LOAD_CHUNK(cart->bank0.sfx.waveform); break; case CHUNK_WAVEFORM: memcpy(&cart->banks[bank.waves++].sfx.waveform, buffer, min(sizeof(tic_waveforms), chunk.size)); break;
case CHUNK_MUSIC: LOAD_CHUNK(cart->bank0.music.tracks.data); break; case CHUNK_MUSIC: memcpy(&cart->banks[bank.tracks++].music.tracks, buffer, min(sizeof(tic_tracks), chunk.size)); break;
case CHUNK_PATTERNS: LOAD_CHUNK(cart->bank0.music.patterns.data); break; case CHUNK_PATTERNS: memcpy(&cart->banks[bank.patterns++].music.patterns, buffer, min(sizeof(tic_patterns), chunk.size)); break;
case CHUNK_PALETTE: case CHUNK_PALETTE:
if(palette) if(palette)
LOAD_CHUNK(cart->palette); LOAD_CHUNK(cart->palette);
break; break;
case CHUNK_COVER: case CHUNK_COVER:
LOAD_CHUNK(cart->cover.data); LOAD_CHUNK(cart->cover.data);
@ -1680,7 +1692,7 @@ static s32 api_save(const tic_cartridge* cart, u8* buffer)
buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank0.sprites); buffer = SAVE_CHUNK(CHUNK_SPRITES, cart->bank0.sprites);
buffer = SAVE_CHUNK(CHUNK_MAP, cart->bank0.map); buffer = SAVE_CHUNK(CHUNK_MAP, cart->bank0.map);
buffer = SAVE_CHUNK(CHUNK_CODE, cart->bank0.code); buffer = SAVE_CHUNK(CHUNK_CODE, cart->bank0.code);
buffer = SAVE_CHUNK(CHUNK_SOUND, cart->bank0.sfx.data); buffer = SAVE_CHUNK(CHUNK_SOUND, cart->bank0.sfx.samples);
buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->bank0.sfx.waveform); buffer = SAVE_CHUNK(CHUNK_WAVEFORM, cart->bank0.sfx.waveform);
buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank0.music.patterns.data); buffer = SAVE_CHUNK(CHUNK_PATTERNS, cart->bank0.music.patterns.data);
buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank0.music.tracks.data); buffer = SAVE_CHUNK(CHUNK_MUSIC, cart->bank0.music.tracks.data);

View File

@ -203,7 +203,7 @@ typedef struct
tic_sound_loop loops[4]; tic_sound_loop loops[4];
}; };
} tic_sound_effect; } tic_sample;
typedef struct typedef struct
{ {
@ -250,10 +250,15 @@ typedef struct
tic_track data[MUSIC_TRACKS]; tic_track data[MUSIC_TRACKS];
} tic_tracks; } tic_tracks;
typedef struct
{
tic_sample data[SFX_COUNT];
} tic_samples;
typedef struct typedef struct
{ {
tic_waveforms waveform; tic_waveforms waveform;
tic_sound_effect data[SFX_COUNT]; tic_samples samples;
}tic_sfx; }tic_sfx;
typedef struct typedef struct