summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-11 14:30:12 +0200
committerBad Diode <bd@badd10de.dev>2021-05-11 14:30:12 +0200
commit7bccc14ea476b380ab77f05463fad1cb57149e58 (patch)
treec8ae013b3983eaa758c0779fb4071441acd33ca5
parentc3045883260e0e1ba06f9d965487e21cdb47392b (diff)
downloadgba-experiments-7bccc14ea476b380ab77f05463fad1cb57149e58.tar.gz
gba-experiments-7bccc14ea476b380ab77f05463fad1cb57149e58.zip
Add default wave patterns in channel 3
-rw-r--r--src/main.c1
-rw-r--r--src/rng.c15
-rw-r--r--src/sequencer.c239
3 files changed, 212 insertions, 43 deletions
diff --git a/src/main.c b/src/main.c
index d4d49cc..636d5c4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -18,6 +18,7 @@ int main(void) {
18 DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_4 | DISP_BG_2; 18 DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_4 | DISP_BG_2;
19 // DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_3 | DISP_BG_2; 19 // DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_3 | DISP_BG_2;
20 20
21 // PAL_BUFFER_BG[0] = COLOR_BLUE;
21 PAL_BUFFER_BG[1] = COLOR_WHITE; 22 PAL_BUFFER_BG[1] = COLOR_WHITE;
22 PAL_BUFFER_BG[2] = COLOR_RED; 23 PAL_BUFFER_BG[2] = COLOR_RED;
23 PAL_BUFFER_BG[3] = COLOR_CYAN; 24 PAL_BUFFER_BG[3] = COLOR_CYAN;
diff --git a/src/rng.c b/src/rng.c
new file mode 100644
index 0000000..96760b8
--- /dev/null
+++ b/src/rng.c
@@ -0,0 +1,15 @@
1u16 rng_state;
2
3u32 hash16(u32 input, u32 key) {
4 u32 hash = input * key;
5 return ((hash >> 16) ^ hash) & 0xFFFF;
6}
7
8u16 rng16() {
9 rng_state += 0xbadd;
10 return hash16(rng_state, 0x10de);
11}
12
13u32 rng32() {
14 return (rng16() << 16) | rng16();
15}
diff --git a/src/sequencer.c b/src/sequencer.c
index fa44eae..867d3e4 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -1,26 +1,31 @@
1#include "bitmap.h" 1#include "bitmap.h"
2#include "rng.c"
2 3
3// Positioning parameters. 4// Positioning parameters.
4#define SEQ_TRIG_POS_X 45 5#define SEQ_TRIG_POS_X 45
5#define SEQ_TRIG_POS_Y 50 6#define SEQ_TRIG_POS_Y 58
6#define SEQ_TRIG_DIST_X 18 7#define SEQ_TRIG_DIST_X 18
7#define SEQ_TRIG_DIST_Y 28 8#define SEQ_TRIG_DIST_Y 28
8#define SEQ_CHANNEL_POS_X SEQ_TRIG_POS_X - 32 9#define SEQ_CHANNEL_POS_X SEQ_TRIG_POS_X - 32
9#define SEQ_CHANNEL_POS_Y SEQ_TRIG_POS_Y 10#define SEQ_CHANNEL_POS_Y SEQ_TRIG_POS_Y
10#define SEQ_CHANNEL_DIST_Y 11 11#define SEQ_CHANNEL_DIST_Y 11
11#define SEQ_ENV_POS_X 10 12#define SEQ_ENV_POS_X 10
12#define SEQ_ENV_POS_Y 10 13#define SEQ_ENV_POS_Y 18
13#define SEQ_ENV_DIST 32 14#define SEQ_ENV_DIST 32
14#define SEQ_DUTYCYCLE_POS_X SEQ_ENV_POS_X + SEQ_ENV_DIST * 3 15#define SEQ_DUTYCYCLE_POS_X SEQ_ENV_POS_X + SEQ_ENV_DIST * 3
15#define SEQ_DUTYCYCLE_POS_Y 10 - 8 16#define SEQ_DUTYCYCLE_POS_Y SEQ_ENV_POS_Y - 8
16#define SEQ_SWEEP_POS_X SEQ_DUTYCYCLE_POS_X + SEQ_ENV_DIST 17#define SEQ_SWEEP_POS_X SEQ_DUTYCYCLE_POS_X + SEQ_ENV_DIST
17#define SEQ_SWEEP_POS_Y SEQ_ENV_POS_Y 18#define SEQ_SWEEP_POS_Y SEQ_ENV_POS_Y
18#define SEQ_CH3_PARAM_X SEQ_TRIG_POS_X 19#define SEQ_CH3_PARAM_X SEQ_TRIG_POS_X
19#define SEQ_CH3_PARAM_Y SEQ_ENV_POS_Y 20#define SEQ_CH3_PARAM_Y SEQ_ENV_POS_Y - 12
20#define SEQ_CH3_PARAM_SEL_X SEQ_CH3_PARAM_X - 5 21#define SEQ_CH3_PARAM_SEL_X SEQ_CH3_PARAM_X - 5
21#define SEQ_CH3_PARAM_SEL_Y SEQ_CH3_PARAM_Y + 22 22#define SEQ_CH3_PARAM_SEL_Y SEQ_CH3_PARAM_Y + 22
22#define SEQ_N_CHANNELS 3 23#define SEQ_N_CHANNELS 3
23 24
25//
26// Sprite data.
27//
28
24u32 sprite_note_names[] = { 29u32 sprite_note_names[] = {
25 0x000000e0, 0x202020e0, 0x0000000e, 0x080e020e, 30 0x000000e0, 0x202020e0, 0x0000000e, 0x080e020e,
26 0x00000098, 0xa8a8a898, 0x00000038, 0x203b0a39, 31 0x00000098, 0xa8a8a898, 0x00000038, 0x203b0a39,
@@ -108,6 +113,12 @@ u32 sprite_trigger_active_indicator[] = {
108 0x00000000, 0x00f80000, 113 0x00000000, 0x00f80000,
109}; 114};
110 115
116u32 sprite_ch_3_parameter_selection[] = {
117 0x00000000, 0x00f80000,
118 0xfe000000, 0x00000000,
119 0x7f000000, 0x00000000,
120};
121
111u32 sprite_trigger_selection[] = { 122u32 sprite_trigger_selection[] = {
112 0x0f010101, 0x00000000, 0x80000000, 0x00000000, 123 0x0f010101, 0x00000000, 0x80000000, 0x00000000,
113 0x07040404, 0x00000000, 0x00000000, 0x00000000, 124 0x07040404, 0x00000000, 0x00000000, 0x00000000,
@@ -266,6 +277,17 @@ u32 sprite_channels_selector[] = {
266 0x00000000, 0x00000000, 0x0008080e, 0x00000000, 277 0x00000000, 0x00000000, 0x0008080e, 0x00000000,
267}; 278};
268 279
280u32 sprite_default_wave[] = {
281 0xff013149, 0x850101ff, 0x3f202028, 0x2423203f,
282 0xff016151, 0x49c501ff, 0x3f202c2a, 0x2928203f,
283 0xff017d45, 0x45c501ff, 0x3f202828, 0x282f203f,
284 0xff014911, 0x812501ff, 0x3f202128, 0x2420203f,
285};
286
287//
288// Wave data.
289//
290
269u8 sine_wave[] = { 291u8 sine_wave[] = {
270 0x89, 0xBC, 0xDE, 0xEF, 292 0x89, 0xBC, 0xDE, 0xEF,
271 0xFE, 0xED, 0xCB, 0x98, 293 0xFE, 0xED, 0xCB, 0x98,
@@ -280,6 +302,13 @@ u8 saw_wave[16] = {
280 0x89, 0xab, 0xcd, 0xef, 302 0x89, 0xab, 0xcd, 0xef,
281}; 303};
282 304
305u8 square_wave[16] = {
306 0xff, 0xff, 0xff, 0xff,
307 0xff, 0xff, 0xff, 0xff,
308 0x00, 0x00, 0x00, 0x00,
309 0x00, 0x00, 0x00, 0x00,
310};
311
283// TODO: Should we split this up in individual trigger structs depending on the 312// TODO: Should we split this up in individual trigger structs depending on the
284// channel? 313// channel?
285typedef struct SeqTrigger { 314typedef struct SeqTrigger {
@@ -367,13 +396,9 @@ static SeqTrigger sequences[3][16] = {
367// well or the note/duration. 396// well or the note/duration.
368// TODO: Allow muting and unmuting channels. Show in grey when muted. 397// TODO: Allow muting and unmuting channels. Show in grey when muted.
369// TODO: Show channel beat indicator if a note is being played. 398// TODO: Show channel beat indicator if a note is being played.
370// TODO: Parameters should change depending on the selected channel. For 399// TODO: Enable control on channel 4.
371// example, we may want to hide the sweep parameters for synth 2.
372// TODO: Research a way of having pattern chains. 400// TODO: Research a way of having pattern chains.
373// TODO: Enable control on channels 3-4.
374// TODO: Study how to save patterns and chains. 401// TODO: Study how to save patterns and chains.
375// TODO: Wave channel should have a default (sine, saw, square) and/or maybe
376// some buttons for set those values.
377 402
378static int bpm = 115; 403static int bpm = 115;
379static int step_counter = 0; 404static int step_counter = 0;
@@ -418,9 +443,9 @@ irq_timer_0(void) {
418 // TODO: Should we compare if previous and current wave are the 443 // TODO: Should we compare if previous and current wave are the
419 // same before updating? 444 // same before updating?
420 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1); 445 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1);
421 memcpy(SOUND_WAVE_RAM, trig->wave_a, 32); 446 memcpy(SOUND_WAVE_RAM, trig->wave_a, 16);
422 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0); 447 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0);
423 memcpy(SOUND_WAVE_RAM, trig->wave_b, 32); 448 memcpy(SOUND_WAVE_RAM, trig->wave_b, 16);
424 449
425 switch (trig->wave_mode) { 450 switch (trig->wave_mode) {
426 case 0: { 451 case 0: {
@@ -528,6 +553,7 @@ set_time(int bpm) {
528// - 055-055 RESERVED: FM synth?. 553// - 055-055 RESERVED: FM synth?.
529// - 056-056 channel selector. 554// - 056-056 channel selector.
530// - 057-057 ch3 selector. 555// - 057-057 ch3 selector.
556// - 058-066 ch3 default wave buttons.
531// 557//
532 558
533 559
@@ -550,11 +576,11 @@ typedef enum {
550} SeqSelect; 576} SeqSelect;
551 577
552int trig_selection_loc = 0; 578int trig_selection_loc = 0;
553int param_selection_loc = 0; 579int param_selection_loc = 64;
554int channel_selection_loc = 2; 580int channel_selection_loc = 2;
555SeqSelect current_selection = SEQ_SELECT_TRIGGER; 581SeqSelect current_selection = SEQ_SELECT_TRIGGER;
556 582
557SeqSprite seq_sprites[58] = {0}; 583SeqSprite seq_sprites[66] = {0};
558 584
559void 585void
560draw_wave_pattern(u8 *pattern, int x, int y, u16 clr_idx) { 586draw_wave_pattern(u8 *pattern, int x, int y, u16 clr_idx) {
@@ -628,16 +654,6 @@ init_sequencer_sprites(void) {
628 seq_sprites[32].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x); 654 seq_sprites[32].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
629 seq_sprites[32].obj_attr_2 = base_tile | OBJ_PAL_BANK(1); 655 seq_sprites[32].obj_attr_2 = base_tile | OBJ_PAL_BANK(1);
630 } 656 }
631 {
632 int x = SEQ_CH3_PARAM_SEL_X;
633 int y = SEQ_CH3_PARAM_SEL_Y;
634 int base_tile = sprites[sprite_id].tile_start;
635 seq_sprites[57].id = obj_counter++;
636 seq_sprites[57].base_tile = base_tile;
637 seq_sprites[57].obj_attr_0 = OBJ_SHAPE_SQUARE | OBJ_Y_COORD(y);
638 seq_sprites[57].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
639 seq_sprites[57].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
640 }
641 657
642 sprite_id = load_packed_sprite_data(&sprite_trigger_selection, 16, 1); 658 sprite_id = load_packed_sprite_data(&sprite_trigger_selection, 16, 1);
643 { 659 {
@@ -910,12 +926,46 @@ init_sequencer_sprites(void) {
910 int base_tile = sprites[sprite_id].tile_start; 926 int base_tile = sprites[sprite_id].tile_start;
911 seq_sprites[56].id = obj_counter++; 927 seq_sprites[56].id = obj_counter++;
912 seq_sprites[56].base_tile = base_tile; 928 seq_sprites[56].base_tile = base_tile;
913 // TODO: Start hidden. 929 seq_sprites[56].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y) | OBJ_HIDDEN;
914 // seq_sprites[55].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y) | OBJ_HIDDEN;
915 seq_sprites[56].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
916 seq_sprites[56].obj_attr_1 = OBJ_SIZE_BIG | OBJ_X_COORD(x); 930 seq_sprites[56].obj_attr_1 = OBJ_SIZE_BIG | OBJ_X_COORD(x);
917 seq_sprites[56].obj_attr_2 = base_tile | OBJ_PAL_BANK(2); 931 seq_sprites[56].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
918 } 932 }
933
934 sprite_id = load_packed_sprite_data(&sprite_ch_3_parameter_selection, 3, 1);
935 {
936 int x = SEQ_CH3_PARAM_SEL_X;
937 int y = SEQ_CH3_PARAM_SEL_Y;
938 int base_tile = sprites[sprite_id].tile_start;
939 seq_sprites[57].id = obj_counter++;
940 seq_sprites[57].base_tile = base_tile;
941 seq_sprites[57].obj_attr_0 = OBJ_SHAPE_SQUARE | OBJ_Y_COORD(y);
942 seq_sprites[57].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
943 seq_sprites[57].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
944 }
945
946 sprite_id = load_packed_sprite_data(&sprite_default_wave, 2, 4);
947 // Wave A
948 for (size_t i = 0; i < 4; ++i) {
949 int x = SEQ_CH3_PARAM_X + 17 * i;
950 int y = SEQ_CH3_PARAM_Y + 37;
951 int base_tile = sprites[sprite_id].tile_start + i * 2 % 8;
952 seq_sprites[58 + i].id = obj_counter++;
953 seq_sprites[58 + i].base_tile = base_tile;
954 seq_sprites[58 + i].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
955 seq_sprites[58 + i].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
956 seq_sprites[58 + i].obj_attr_2 = base_tile | OBJ_PAL_BANK(0);
957 }
958 // Wave B
959 for (size_t i = 0; i < 4; ++i) {
960 int x = SEQ_CH3_PARAM_X + 17 * i + 76;
961 int y = SEQ_CH3_PARAM_Y + 37;
962 int base_tile = sprites[sprite_id].tile_start + i * 2 % 8;
963 seq_sprites[58 + 4 + i].id = obj_counter++;
964 seq_sprites[58 + 4 + i].base_tile = base_tile;
965 seq_sprites[58 + 4 + i].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
966 seq_sprites[58 + 4 + i].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
967 seq_sprites[58 + 4 + i].obj_attr_2 = base_tile | OBJ_PAL_BANK(0);
968 }
919} 969}
920 970
921bool update_params_screen = true; 971bool update_params_screen = true;
@@ -1040,7 +1090,7 @@ update_sequencer_sprites(void) {
1040 int x = SEQ_CHANNEL_POS_X; 1090 int x = SEQ_CHANNEL_POS_X;
1041 int y = SEQ_CHANNEL_POS_Y - 2; 1091 int y = SEQ_CHANNEL_POS_Y - 2;
1042 y += (channel_selection_loc % SEQ_N_CHANNELS * SEQ_CHANNEL_DIST_Y); 1092 y += (channel_selection_loc % SEQ_N_CHANNELS * SEQ_CHANNEL_DIST_Y);
1043 seq_sprites[56].obj_attr_0 = OBJ_SHAPE_SQUARE | OBJ_Y_COORD(y); 1093 seq_sprites[56].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y);
1044 seq_sprites[56].obj_attr_1 = OBJ_SIZE_BIG | OBJ_X_COORD(x); 1094 seq_sprites[56].obj_attr_1 = OBJ_SIZE_BIG | OBJ_X_COORD(x);
1045 int base_tile = seq_sprites[56].base_tile; 1095 int base_tile = seq_sprites[56].base_tile;
1046 if (current_selection == SEQ_SELECT_CHANNEL) { 1096 if (current_selection == SEQ_SELECT_CHANNEL) {
@@ -1090,35 +1140,81 @@ update_sequencer_sprites(void) {
1090 // Update parameter selection. 1140 // Update parameter selection.
1091 { 1141 {
1092 u8 x_positions[] = { 1142 u8 x_positions[] = {
1143 // 32 half bytes (Wave A).
1093 0, 4, 8, 12, 16, 20, 24, 28, 1144 0, 4, 8, 12, 16, 20, 24, 28,
1094 36, 40, 44, 48, 52, 56, 60, 64, 1145 36, 40, 44, 48, 52, 56, 60, 64,
1095 0, 4, 8, 12, 16, 20, 24, 28, 1146 0, 4, 8, 12, 16, 20, 24, 28,
1096 36, 40, 44, 48, 52, 56, 60, 64, 1147 36, 40, 44, 48, 52, 56, 60, 64,
1148 // 32 half bytes (Wave B).
1097 76, 80, 84, 88, 92, 96, 100, 104, 1149 76, 80, 84, 88, 92, 96, 100, 104,
1098 112, 116, 120, 124, 128, 132, 136, 140, 1150 112, 116, 120, 124, 128, 132, 136, 140,
1099 76, 80, 84, 88, 92, 96, 100, 104, 1151 76, 80, 84, 88, 92, 96, 100, 104,
1100 112, 116, 120, 124, 128, 132, 136, 140, 1152 112, 116, 120, 124, 128, 132, 136, 140,
1153 // Default wave A.
1154 4, 21, 38, 55,
1155 // Default wave B.
1156 80, 97, 114, 131,
1101 }; 1157 };
1102 u8 y_positions[] = { 1158 u8 y_positions[] = {
1159 // 32 half bytes (Wave A)
1103 0, 0, 0, 0, 0, 0, 0, 0, 1160 0, 0, 0, 0, 0, 0, 0, 0,
1104 0, 0, 0, 0, 0, 0, 0, 0, 1161 0, 0, 0, 0, 0, 0, 0, 0,
1105 8, 8, 8, 8, 8, 8, 8, 8, 1162 8, 8, 8, 8, 8, 8, 8, 8,
1106 8, 8, 8, 8, 8, 8, 8, 8, 1163 8, 8, 8, 8, 8, 8, 8, 8,
1164 // 32 half bytes (Wave B)
1107 0, 0, 0, 0, 0, 0, 0, 0, 1165 0, 0, 0, 0, 0, 0, 0, 0,
1108 0, 0, 0, 0, 0, 0, 0, 0, 1166 0, 0, 0, 0, 0, 0, 0, 0,
1109 8, 8, 8, 8, 8, 8, 8, 8, 1167 8, 8, 8, 8, 8, 8, 8, 8,
1110 8, 8, 8, 8, 8, 8, 8, 8, 1168 8, 8, 8, 8, 8, 8, 8, 8,
1169 // Default wave A.
1170 23, 23, 23, 23,
1171 // Default wave B.
1172 23, 23, 23, 23,
1111 }; 1173 };
1112 int x = SEQ_CH3_PARAM_SEL_X + x_positions[param_selection_loc]; 1174 {
1113 int y = SEQ_CH3_PARAM_SEL_Y + y_positions[param_selection_loc]; 1175 int x = SEQ_CH3_PARAM_SEL_X + x_positions[param_selection_loc];
1114 int base_tile = seq_sprites[57].base_tile; 1176 int y = SEQ_CH3_PARAM_SEL_Y + y_positions[param_selection_loc];
1115 int hidden = 0; 1177 int base_tile = seq_sprites[57].base_tile;
1116 if (current_selection != SEQ_SELECT_PARAMETER) { 1178 int shape = OBJ_SHAPE_SQUARE;
1117 hidden = OBJ_HIDDEN; 1179 int hidden = 0;
1180 if (current_selection != SEQ_SELECT_PARAMETER) {
1181 hidden = OBJ_HIDDEN;
1182 }
1183 if (param_selection_loc >= 64) {
1184 shape = OBJ_SHAPE_WIDE;
1185 base_tile += 1;
1186 }
1187 seq_sprites[57].obj_attr_0 = shape | OBJ_Y_COORD(y) | hidden;
1188 seq_sprites[57].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
1189 seq_sprites[57].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
1190 }
1191
1192 // Wave A
1193 for (size_t i = 0; i < 4; ++i) {
1194 int x = SEQ_CH3_PARAM_X + 17 * i;
1195 int y = SEQ_CH3_PARAM_Y + 37;
1196 int base_tile = seq_sprites[58 + i].base_tile;
1197 int hidden = 0;
1198 if (current_selection == SEQ_SELECT_CHANNEL) {
1199 hidden = OBJ_HIDDEN;
1200 }
1201 seq_sprites[58 + i].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y) | hidden;
1202 seq_sprites[58 + i].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
1203 seq_sprites[58 + i].obj_attr_2 = base_tile | OBJ_PAL_BANK(0);
1204 }
1205 // Wave B
1206 for (size_t i = 0; i < 4; ++i) {
1207 int x = SEQ_CH3_PARAM_X + 17 * i + 76;
1208 int y = SEQ_CH3_PARAM_Y + 37;
1209 int base_tile = seq_sprites[58 + 4 + i].base_tile;
1210 int hidden = 0;
1211 if (current_selection == SEQ_SELECT_CHANNEL) {
1212 hidden = OBJ_HIDDEN;
1213 }
1214 seq_sprites[58 + 4 + i].obj_attr_0 = OBJ_SHAPE_WIDE | OBJ_Y_COORD(y) | hidden;
1215 seq_sprites[58 + 4 + i].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
1216 seq_sprites[58 + 4 + i].obj_attr_2 = base_tile | OBJ_PAL_BANK(0);
1118 } 1217 }
1119 seq_sprites[57].obj_attr_0 = OBJ_SHAPE_SQUARE | OBJ_Y_COORD(y) | hidden;
1120 seq_sprites[57].obj_attr_1 = OBJ_SIZE_SMALL | OBJ_X_COORD(x);
1121 seq_sprites[57].obj_attr_2 = base_tile | OBJ_PAL_BANK(2);
1122 } 1218 }
1123 } 1219 }
1124 1220
@@ -1159,6 +1255,9 @@ update_sequencer_sprites(void) {
1159 for (size_t i = 34; i <= 50; ++i) { 1255 for (size_t i = 34; i <= 50; ++i) {
1160 seq_sprites[i].obj_attr_0 |= OBJ_HIDDEN; 1256 seq_sprites[i].obj_attr_0 |= OBJ_HIDDEN;
1161 } 1257 }
1258 for (size_t i = 58; i <= 66; ++i) {
1259 seq_sprites[i].obj_attr_0 |= OBJ_HIDDEN;
1260 }
1162 flip_page(); 1261 flip_page();
1163 clear_screen_m4(); 1262 clear_screen_m4();
1164 } 1263 }
@@ -1262,33 +1361,65 @@ handle_sequencer_input(void) {
1262 int inc = 0; 1361 int inc = 0;
1263 int loc = param_selection_loc; 1362 int loc = param_selection_loc;
1264 if (key_pressed(KEY_RIGHT)) { 1363 if (key_pressed(KEY_RIGHT)) {
1265 if (loc == 15 || loc == 32) { 1364 if (loc == 15 || loc == 31) {
1266 inc = 17; 1365 inc = 17;
1267 } else if (loc != 47){ 1366 } else if (loc != 47 && loc != 63){
1268 inc = 1; 1367 inc = 1;
1269 } 1368 }
1270 } else { 1369 } else {
1271 if (loc == 32 || loc == 48) { 1370 if (loc == 32 || loc == 48) {
1272 inc = -17; 1371 inc = -17;
1273 } else if (loc != 16){ 1372 } else if (loc != 16 && loc != 64){
1274 inc = -1; 1373 inc = -1;
1275 } 1374 }
1276 } 1375 }
1277 param_selection_loc = CLAMP(loc + inc, 0, 63); 1376 param_selection_loc = CLAMP(loc + inc, 0, 71);
1278 } 1377 }
1279 if (key_pressed(KEY_UP) || key_pressed(KEY_DOWN)) { 1378 if (key_pressed(KEY_UP) || key_pressed(KEY_DOWN)) {
1280 int inc = 0; 1379 int inc = 0;
1281 int loc = param_selection_loc; 1380 int loc = param_selection_loc;
1282 if (key_pressed(KEY_UP)) { 1381 if (key_pressed(KEY_UP)) {
1283 if ((loc >= 16 && loc < 32) || (loc >= 48)) { 1382 if ((loc >= 16 && loc < 32) || (loc >= 48 && loc < 64)) {
1284 inc = -16; 1383 inc = -16;
1384 } else if (loc == 64) {
1385 inc = -48;
1386 } else if (loc == 65) {
1387 inc = -45;
1388 } else if (loc == 66) {
1389 inc = -42;
1390 } else if (loc == 67) {
1391 inc = -39;
1392 } else if (loc == 68) {
1393 inc = -20;
1394 } else if (loc == 69) {
1395 inc = -17;
1396 } else if (loc == 70) {
1397 inc = -14;
1398 } else if (loc == 71) {
1399 inc = -11;
1285 } 1400 }
1286 } else { 1401 } else {
1287 if (loc < 16 || (loc >= 32 && loc < 48)) { 1402 if (loc < 16 || (loc >= 32 && loc < 48)) {
1288 inc = 16; 1403 inc = 16;
1404 } else if (loc >= 16 && loc <= 19){
1405 inc = 48 - (loc - 16);
1406 } else if (loc >= 20 && loc <= 23){
1407 inc = 45 - (loc - 20);
1408 } else if (loc >= 24 && loc <= 27){
1409 inc = 42 - (loc - 24);
1410 } else if (loc >= 28 && loc <= 31){
1411 inc = 39 - (loc - 28);
1412 } else if (loc >= 48 && loc <= 51){
1413 inc = 20 - (loc - 48);
1414 } else if (loc >= 52 && loc <= 55){
1415 inc = 17 - (loc - 52);
1416 } else if (loc >= 56 && loc <= 59){
1417 inc = 14 - (loc - 56);
1418 } else if (loc >= 60 && loc <= 63){
1419 inc = 11 - (loc - 60);
1289 } 1420 }
1290 } 1421 }
1291 param_selection_loc = CLAMP(loc + inc, 0, 63); 1422 param_selection_loc = CLAMP(loc + inc, 0, 71);
1292 } 1423 }
1293 if (key_pressed(KEY_R) || key_pressed(KEY_L)) { 1424 if (key_pressed(KEY_R) || key_pressed(KEY_L)) {
1294 int odd = param_selection_loc & 0x1; 1425 int odd = param_selection_loc & 0x1;
@@ -1311,7 +1442,7 @@ handle_sequencer_input(void) {
1311 byte = (0xF & byte) | (((byte >> 4) + inc) & 0xF) << 4; 1442 byte = (0xF & byte) | (((byte >> 4) + inc) & 0xF) << 4;
1312 } 1443 }
1313 sequences[2][trig_selection_loc].wave_a[byte_number] = byte; 1444 sequences[2][trig_selection_loc].wave_a[byte_number] = byte;
1314 } else { 1445 } else if (param_selection_loc < 64){
1315 u8 byte_number = (param_selection_loc - 32) >> 1; 1446 u8 byte_number = (param_selection_loc - 32) >> 1;
1316 u8 byte = sequences[2][trig_selection_loc].wave_b[byte_number]; 1447 u8 byte = sequences[2][trig_selection_loc].wave_b[byte_number];
1317 if (odd) { 1448 if (odd) {
@@ -1320,6 +1451,28 @@ handle_sequencer_input(void) {
1320 byte = (0xF & byte) | ((byte >> 4) + inc) << 4; 1451 byte = (0xF & byte) | ((byte >> 4) + inc) << 4;
1321 } 1452 }
1322 sequences[2][trig_selection_loc].wave_b[byte_number] = byte; 1453 sequences[2][trig_selection_loc].wave_b[byte_number] = byte;
1454 } else if (param_selection_loc == 64){
1455 memcpy(&trig->wave_a, &sine_wave, 16);
1456 } else if (param_selection_loc == 65){
1457 memcpy(&trig->wave_a, &saw_wave, 16);
1458 } else if (param_selection_loc == 66){
1459 memcpy(&trig->wave_a, &square_wave, 16);
1460 } else if (param_selection_loc == 67){
1461 u32 rand_wave[4] = {
1462 rng32(), rng32(), rng32(), rng32(),
1463 };
1464 memcpy(&trig->wave_a, &rand_wave, 16);
1465 } else if (param_selection_loc == 68){
1466 memcpy(&trig->wave_b, &sine_wave, 16);
1467 } else if (param_selection_loc == 69){
1468 memcpy(&trig->wave_b, &saw_wave, 16);
1469 } else if (param_selection_loc == 70){
1470 memcpy(&trig->wave_b, &square_wave, 16);
1471 } else if (param_selection_loc == 71){
1472 u32 rand_wave[4] = {
1473 rng32(), rng32(), rng32(), rng32(),
1474 };
1475 memcpy(&trig->wave_b, &rand_wave, 16);
1323 } 1476 }
1324 } 1477 }
1325 } 1478 }