summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-11 22:13:47 +0200
committerBad Diode <bd@badd10de.dev>2021-06-11 22:13:47 +0200
commit0391e4b7ac374bf210be79db66d188494ed2dd45 (patch)
tree54554b832518f9c80b624c77fc0e98c3d2b86c99
parent52d77490dbcc70294b5d7cafb3ee0cbf607a5312 (diff)
downloadgba-sequencer-0391e4b7ac374bf210be79db66d188494ed2dd45.tar.gz
gba-sequencer-0391e4b7ac374bf210be79db66d188494ed2dd45.zip
Load all assets on VRAM at init
-rw-r--r--src/sequencer.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index efec779..6859ba5 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -14,9 +14,9 @@
14 14
15// Theme colors. 15// Theme colors.
16#define COL_CURSOR COL_BLUE 16#define COL_CURSOR COL_BLUE
17#define COL_NOTE_PRESSED COL_BLUE 17#define COL_NOTE_PRESSED COL_GREY
18#define COL_CURRENT_CHANNEL COL_FG 18#define COL_CURRENT_CHANNEL COL_GREY
19#define COL_CURRENT_TRIG COL_FG 19#define COL_CURRENT_TRIG COL_GREY
20#define COL_WAVE_A COL_RED 20#define COL_WAVE_A COL_RED
21#define COL_WAVE_B COL_CYAN 21#define COL_WAVE_B COL_CYAN
22 22
@@ -24,7 +24,13 @@
24// Assets. 24// Assets.
25// 25//
26 26
27#define ASSETS_DATA ((u32*)(MEM_VRAM + KB(32))) 27#define N_TILES_NOTE_NAMES 73 * 2
28#define N_TILES_CHAN_BTSN 4 * 3
29#define N_TILES_WAVE_BTNS 4 * 2
30
31#define ASSETS_NOTE_NAMES ((u32*)(MEM_VRAM + KB(32)))
32#define ASSETS_CHANNEL_BUTTONS (ASSETS_NOTE_NAMES + (N_TILES_NOTE_NAMES * 8))
33#define ASSETS_DEFAULT_WAVES (ASSETS_CHANNEL_BUTTONS + (N_TILES_CHAN_BTSN * 8))
28 34
29static const u32 note_names[] = { 35static const u32 note_names[] = {
30 0x000000e0, 0x202020e0, 0x0000000e, 0x080e020e, 36 0x000000e0, 0x202020e0, 0x0000000e, 0x080e020e,
@@ -341,7 +347,7 @@ draw_trigger(size_t chan, size_t i) {
341 size_t offset_y = i < 8 ? 0 : TRIG_OFFSET_Y; 347 size_t offset_y = i < 8 ? 0 : TRIG_OFFSET_Y;
342 size_t x = TRIG_START_X + offset_x; 348 size_t x = TRIG_START_X + offset_x;
343 size_t y = TRIG_START_Y + offset_y; 349 size_t y = TRIG_START_Y + offset_y;
344 Tile *tiles = ASSETS_DATA; 350 Tile *tiles = ASSETS_NOTE_NAMES;
345 tiles += 2 * trig.note; 351 tiles += 2 * trig.note;
346 draw_tile(x, y, tiles, COL_FG, true); 352 draw_tile(x, y, tiles, COL_FG, true);
347 draw_tile(x + 8, y, tiles + 1, COL_FG, true); 353 draw_tile(x + 8, y, tiles + 1, COL_FG, true);
@@ -389,8 +395,7 @@ void
389draw_channels(void) { 395draw_channels(void) {
390 // Contains 5 channel buttons: Ch. 1-4 + FM. We are only drawing the DMG 396 // Contains 5 channel buttons: Ch. 1-4 + FM. We are only drawing the DMG
391 // channels for now, since FM may take some time to develop. 397 // channels for now, since FM may take some time to develop.
392 Tile channel_tiles[3 * 4] = {0}; 398 Tile *channel_tiles = ASSETS_CHANNEL_BUTTONS;
393 unpack_tiles(channel_buttons, channel_tiles, 3 * 4);
394 size_t k = 0; 399 size_t k = 0;
395 for (size_t i = 0; i < 4; i++) { 400 for (size_t i = 0; i < 4; i++) {
396 bool active = false; 401 bool active = false;
@@ -669,10 +674,6 @@ void
669draw_parameters_ch3(void) { 674draw_parameters_ch3(void) {
670 clear_parameters(); 675 clear_parameters();
671 676
672 // TODO: Move to VRAM and decompress at the beginning.
673 Tile wave_tiles[4 * 2] = {0};
674 unpack_tiles(default_wave_buttons, wave_tiles, 4 * 2);
675
676 // Draw current wave data. 677 // Draw current wave data.
677 { 678 {
678 u8 *wave_a = ch3.params[trig_selection_loc].wave_a; 679 u8 *wave_a = ch3.params[trig_selection_loc].wave_a;
@@ -709,6 +710,7 @@ draw_parameters_ch3(void) {
709 710
710 // Draw default wave buttons. 711 // Draw default wave buttons.
711 { 712 {
713 Tile *wave_tiles = ASSETS_DEFAULT_WAVES;
712 size_t x = PARAMS_START_X; 714 size_t x = PARAMS_START_X;
713 size_t y = PARAMS_START_Y + PARAMS_H - 7; 715 size_t y = PARAMS_START_Y + PARAMS_H - 7;
714 for (size_t i = 0, k = 0; i < 4 * 2; i += 2, k++) { 716 for (size_t i = 0, k = 0; i < 4 * 2; i += 2, k++) {
@@ -1387,14 +1389,16 @@ handle_sequencer_input(void) {
1387} 1389}
1388 1390
1389void 1391void
1390load_note_names(void) { 1392load_assets(void) {
1391 unpack_tiles(note_names, ASSETS_DATA, 2 * 73); 1393 unpack_tiles(note_names, ASSETS_NOTE_NAMES, N_TILES_NOTE_NAMES);
1394 unpack_tiles(channel_buttons, ASSETS_CHANNEL_BUTTONS, N_TILES_CHAN_BTSN);
1395 unpack_tiles(default_wave_buttons, ASSETS_DEFAULT_WAVES, N_TILES_WAVE_BTNS);
1392} 1396}
1393 1397
1394void 1398void
1395sequencer_init(void) { 1399sequencer_init(void) {
1396 // Unpack non-sprite tiles directly on the VRAM. 1400 // Unpack non-sprite tiles directly on the VRAM.
1397 load_note_names(); 1401 load_assets();
1398 1402
1399 // Initialize background objects and sprites. 1403 // Initialize background objects and sprites.
1400 draw_triggers(); 1404 draw_triggers();