summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-11 14:41:55 +0200
committerBad Diode <bd@badd10de.dev>2021-06-11 14:41:55 +0200
commit3caf8f1e040c9d186fddc3039e5e4e8dcf5c9d0f (patch)
treef60582f5d95ac905596a9f2850e1238aac1828a4
parent662058f10989f4a0cee6bfdbcf61786f2bb6a687 (diff)
downloadgba-sequencer-3caf8f1e040c9d186fddc3039e5e4e8dcf5c9d0f.tar.gz
gba-sequencer-3caf8f1e040c9d186fddc3039e5e4e8dcf5c9d0f.zip
Add prototype for CH3 parameter drawing
-rw-r--r--src/sequencer.c138
-rw-r--r--src/text/text.h20
2 files changed, 139 insertions, 19 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index d31475e..0c2f2a5 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -105,30 +105,27 @@ static const u32 channel_buttons[] = {
105 0x0f080808, 0x0808080f, 105 0x0f080808, 0x0808080f,
106}; 106};
107 107
108static const u32 default_wave_buttons[] = {
109 0xff013149, 0x850101ff, 0x3f202028, 0x2423203f,
110 0xff016151, 0x49c501ff, 0x3f202c2a, 0x2928203f,
111 0xff017d45, 0x45c501ff, 0x3f202828, 0x282f203f,
112 0xff014911, 0x812501ff, 0x3f202128, 0x2420203f,
113};
114
108// 115//
109// Wave data. 116// Wave data.
110// 117//
111 118
112// TODO: Make them u32. 119static const u32 sine_wave[16] = {
113static const u8 sine_wave[16] = { 120 0xefdebc89, 0x98cbedfe, 0x10214376, 0x67341201,
114 0x89, 0xBC, 0xDE, 0xEF,
115 0xFE, 0xED, 0xCB, 0x98,
116 0x76, 0x43, 0x21, 0x10,
117 0x01, 0x12, 0x34, 0x67,
118}; 121};
119 122
120static const u8 saw_wave[16] = { 123static const u32 saw_wave[16] = {
121 0x01, 0x23, 0x45, 0x67, 124 0x67452301, 0xefcdab89, 0x67452301, 0xefcdab89,
122 0x89, 0xab, 0xcd, 0xef,
123 0x01, 0x23, 0x45, 0x67,
124 0x89, 0xab, 0xcd, 0xef,
125}; 125};
126 126
127static const u8 square_wave[16] = { 127static const u32 square_wave[16] = {
128 0xff, 0xff, 0xff, 0xff, 128 0xffffffff, 0xffffffff, 0x00000000, 0x00000000,
129 0xff, 0xff, 0xff, 0xff,
130 0x00, 0x00, 0x00, 0x00,
131 0x00, 0x00, 0x00, 0x00,
132}; 129};
133 130
134// 131//
@@ -276,10 +273,10 @@ static ChannelWave ch3 = {
276 }, 273 },
277 .params = { 274 .params = {
278 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, 275 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
276 {3, 0, {0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
279 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, 277 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
280 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, 278 {3, 0, {0x00000000, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
281 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, 279 {3, 0, {0x00000000, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
282 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
283 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, 280 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
284 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, 281 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
285 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}}, 282 {3, 0, {0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000},{0xFFFFFFFF, 0x00000000, 0xFFFFFFFF, 0x00000000}},
@@ -558,6 +555,103 @@ draw_piano(void) {
558 } 555 }
559} 556}
560 557
558#define PARAMS_W 170
559#define PARAMS_H 48
560#define PARAMS_START_X 35
561#define PARAMS_START_Y 12
562
563IWRAM_CODE
564void
565draw_wave_pattern(u8 *pattern, int x, int y, u8 clr) {
566 for (size_t i = 0; i < 16; ++i) {
567 u8 byte = pattern[i];
568 u8 first = (byte >> 4) & 0xF;
569 u8 second = byte & 0xF;
570 u8 a = x + i * 4;
571 u8 b = y + 16;
572 draw_pixel(a, b - first, clr);
573 draw_pixel(a + 1, b - first, clr);
574 draw_pixel(a + 2, b - second, clr);
575 draw_pixel(a + 3, b - second, clr);
576 }
577}
578
579IWRAM_CODE
580void
581clear_parameters(void) {
582 size_t x0 = PARAMS_START_X;
583 size_t y0 = PARAMS_START_Y;
584 size_t x1 = PARAMS_START_X + PARAMS_W;
585 size_t y1 = PARAMS_START_Y + PARAMS_H;
586 draw_filled_rect(x0, y0, x1, y1, COL_BG);
587}
588
589IWRAM_CODE
590void
591draw_parameters(void) {
592 // Clear until the default parameters, since those don't change.
593 {
594 size_t x0 = PARAMS_START_X;
595 size_t y0 = PARAMS_START_Y;
596 size_t x1 = PARAMS_START_X + PARAMS_W;
597 size_t y1 = PARAMS_START_Y + PARAMS_H - 8;
598 draw_filled_rect(x0, y0, x1, y1, COL_BG);
599 }
600
601 // TODO: Move to VRAM and decompress at the beginning.
602 Tile wave_tiles[4 * 2] = {0};
603 unpack_tiles(default_wave_buttons, wave_tiles, 4 * 2);
604
605 // Draw current wave data.
606 {
607 u8 *wave_a = ch3.params[trig_selection_loc].wave_a;
608 u8 *wave_b = ch3.params[trig_selection_loc].wave_b;
609
610 size_t x = PARAMS_START_X;
611 size_t y = PARAMS_START_Y + 2;
612
613 // Wave Patterns.
614 draw_wave_pattern(wave_a, x, y, COL_RED);
615 draw_wave_pattern(wave_b, x + 70, y, COL_CYAN);
616
617 // Wave text.
618 x -= 2;
619 txt_drawf_small("%02x%02x%02x%02x", x, y + 20, 4, COL_FG,
620 wave_a[0], wave_a[1], wave_a[2], wave_a[3]);
621 txt_drawf_small("%02x%02x%02x%02x", x + 34, y + 20, 4, COL_FG,
622 wave_a[4], wave_a[5], wave_a[6], wave_a[7]);
623 txt_drawf_small("%02x%02x%02x%02x", x, y + 28, 4, COL_FG,
624 wave_a[8], wave_a[9], wave_a[10], wave_a[11]);
625 txt_drawf_small("%02x%02x%02x%02x", x + 34, y + 28, 4, COL_FG,
626 wave_a[12], wave_a[13], wave_a[14], wave_a[15]);
627
628 x += 70;
629 txt_drawf_small("%02x%02x%02x%02x", x, y + 20, 4, COL_FG,
630 wave_b[0], wave_b[1], wave_b[2], wave_b[3]);
631 txt_drawf_small("%02x%02x%02x%02x", x + 34, y + 20, 4, COL_FG,
632 wave_b[4], wave_b[5], wave_b[6], wave_b[7]);
633 txt_drawf_small("%02x%02x%02x%02x", x, y + 28, 4, COL_FG,
634 wave_b[8], wave_b[9], wave_b[10], wave_b[11]);
635 txt_drawf_small("%02x%02x%02x%02x", x + 34, y + 28, 4, COL_FG,
636 wave_b[12], wave_b[13], wave_b[14], wave_b[15]);
637 }
638
639 // Draw default wave buttons.
640 {
641 size_t x = PARAMS_START_X;
642 size_t y = PARAMS_START_Y + PARAMS_H - 7;
643 for (size_t i = 0, k = 0; i < 4 * 2; i += 2, k++) {
644 draw_tile(x + 17 * k, y, wave_tiles + i, COL_FG, true);
645 draw_tile(x + 17 * k + 8, y, wave_tiles + i + 1, COL_FG, true);
646 }
647 for (size_t i = 0, k = 0; i < 4 * 2; i += 2, k++) {
648 draw_tile(x + 17 * k + 70, y, wave_tiles + i, COL_FG, true);
649 draw_tile(x + 17 * k + 8 + 70, y, wave_tiles + i + 1, COL_FG, true);
650 }
651 }
652
653}
654
561void 655void
562irq_timer(void) { 656irq_timer(void) {
563 if (ch1.active) { 657 if (ch1.active) {
@@ -721,6 +815,7 @@ handle_channel_selection(void) {
721 draw_trig_cursor(trig_selection_loc, COL_BLUE); 815 draw_trig_cursor(trig_selection_loc, COL_BLUE);
722 TriggerNote *trig = get_current_trig(); 816 TriggerNote *trig = get_current_trig();
723 draw_note(trig->note, COL_BLUE); 817 draw_note(trig->note, COL_BLUE);
818 draw_parameters();
724 } else if (key_tap(KEY_UP)) { 819 } else if (key_tap(KEY_UP)) {
725 draw_channel_cursor(channel_selection_loc, COL_BG); 820 draw_channel_cursor(channel_selection_loc, COL_BG);
726 if (channel_selection_loc == 0) { 821 if (channel_selection_loc == 0) {
@@ -1043,6 +1138,7 @@ handle_trigger_selection(void) {
1043 draw_note(trig->note, COL_FG); 1138 draw_note(trig->note, COL_FG);
1044 input_handler = handle_channel_selection; 1139 input_handler = handle_channel_selection;
1045 draw_channel_cursor(channel_selection_loc, COL_BLUE); 1140 draw_channel_cursor(channel_selection_loc, COL_BLUE);
1141 clear_parameters();
1046 } else { 1142 } else {
1047 draw_trig_cursor(trig_selection_loc, COL_BG); 1143 draw_trig_cursor(trig_selection_loc, COL_BG);
1048 draw_note(trig->note, COL_FG); 1144 draw_note(trig->note, COL_FG);
@@ -1050,6 +1146,7 @@ handle_trigger_selection(void) {
1050 trig = get_current_trig(); 1146 trig = get_current_trig();
1051 draw_trig_cursor(trig_selection_loc, COL_BLUE); 1147 draw_trig_cursor(trig_selection_loc, COL_BLUE);
1052 draw_note(trig->note, COL_BLUE); 1148 draw_note(trig->note, COL_BLUE);
1149 draw_parameters();
1053 } 1150 }
1054 } else if (key_tap(KEY_RIGHT)) { 1151 } else if (key_tap(KEY_RIGHT)) {
1055 if (trig_selection_loc != 7) { 1152 if (trig_selection_loc != 7) {
@@ -1059,6 +1156,7 @@ handle_trigger_selection(void) {
1059 trig = get_current_trig(); 1156 trig = get_current_trig();
1060 draw_trig_cursor(trig_selection_loc, COL_BLUE); 1157 draw_trig_cursor(trig_selection_loc, COL_BLUE);
1061 draw_note(trig->note, COL_BLUE); 1158 draw_note(trig->note, COL_BLUE);
1159 draw_parameters();
1062 } 1160 }
1063 } else if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { 1161 } else if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) {
1064 draw_trig_cursor(trig_selection_loc, COL_BG); 1162 draw_trig_cursor(trig_selection_loc, COL_BG);
@@ -1067,6 +1165,7 @@ handle_trigger_selection(void) {
1067 trig = get_current_trig(); 1165 trig = get_current_trig();
1068 draw_trig_cursor(trig_selection_loc, COL_BLUE); 1166 draw_trig_cursor(trig_selection_loc, COL_BLUE);
1069 draw_note(trig->note, COL_BLUE); 1167 draw_note(trig->note, COL_BLUE);
1168 draw_parameters();
1070 } else if (key_tap(KEY_A)) { 1169 } else if (key_tap(KEY_A)) {
1071 // Switch to parameter selection. 1170 // Switch to parameter selection.
1072 switch (channel_selection_loc) { 1171 switch (channel_selection_loc) {
@@ -1126,6 +1225,7 @@ sequencer_init(void) {
1126 draw_piano(); 1225 draw_piano();
1127 TriggerNote *trig = get_current_trig(); 1226 TriggerNote *trig = get_current_trig();
1128 draw_note(trig->note, COL_BLUE); 1227 draw_note(trig->note, COL_BLUE);
1228 draw_parameters();
1129 1229
1130 // Initialize input handler. 1230 // Initialize input handler.
1131 channel_selection_loc = 2; // DEBUG: Starting on CH3 1231 channel_selection_loc = 2; // DEBUG: Starting on CH3
diff --git a/src/text/text.h b/src/text/text.h
index 931227c..647a021 100644
--- a/src/text/text.h
+++ b/src/text/text.h
@@ -136,4 +136,24 @@ txt_draws(char *msg, size_t x, size_t y, size_t spacing, u8 clr) {
136 txt_draws(buf, x, y, s, c); \ 136 txt_draws(buf, x, y, s, c); \
137 } 137 }
138 138
139// Small font is located after the initial ASCII characters, and only supports
140// lowercase characters.
141// NOTE: Slow, we should do this with a LUT.
142#define txt_drawf_small(msg, x, y, s, c, ...) \
143 { \
144 char buf[256] = {0}; \
145 posprintf(buf, msg, ##__VA_ARGS__); \
146 for (size_t i = 0; i < 256; i++) { \
147 if (buf[i] == 0) { \
148 break; \
149 } \
150 if (buf[i] < 'a') { \
151 buf[i] += 16 * 6; \
152 } else { \
153 buf[i] += 16 * 4; \
154 }\
155 } \
156 txt_draws(buf, x, y, s, c); \
157 }
158
139#endif // TEXT_H 159#endif // TEXT_H