summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-11 17:12:13 +0200
committerBad Diode <bd@badd10de.dev>2021-06-11 17:12:13 +0200
commit562f435116748b259ef5cd97d36e6049c1d9fbc7 (patch)
tree66277341c5ebbe68fc6f15291788485a62561efe
parent5cd6fa9ce339189d5e4e57d78206254f687507fa (diff)
downloadgba-sequencer-562f435116748b259ef5cd97d36e6049c1d9fbc7.tar.gz
gba-sequencer-562f435116748b259ef5cd97d36e6049c1d9fbc7.zip
Add memcpy32 inline function
-rw-r--r--src/gba/gba.h8
-rw-r--r--src/rng.c2
-rw-r--r--src/sequencer.c100
3 files changed, 66 insertions, 44 deletions
diff --git a/src/gba/gba.h b/src/gba/gba.h
index 797c71e..3a84b89 100644
--- a/src/gba/gba.h
+++ b/src/gba/gba.h
@@ -660,4 +660,12 @@ wait_vsync(void) {
660#define EWRAM_CODE __attribute__((section(".ewram"), long_call)) 660#define EWRAM_CODE __attribute__((section(".ewram"), long_call))
661#define EWRAM_BSS __attribute__((section(".sbss"))) 661#define EWRAM_BSS __attribute__((section(".sbss")))
662 662
663static inline
664void
665memcpy32(u32 *dst, const u32 *src, u32 size) {
666 for (size_t i = 0; i < size / 4; i++) {
667 dst[i] = src[i];
668 }
669}
670
663#endif // GBA_H 671#endif // GBA_H
diff --git a/src/rng.c b/src/rng.c
index 96760b8..58a517b 100644
--- a/src/rng.c
+++ b/src/rng.c
@@ -1,4 +1,4 @@
1u16 rng_state; 1static u16 rng_state = 0;
2 2
3u32 hash16(u32 input, u32 key) { 3u32 hash16(u32 input, u32 key) {
4 u32 hash = input * key; 4 u32 hash = input * key;
diff --git a/src/sequencer.c b/src/sequencer.c
index 002b4d0..fae4ce3 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -798,9 +798,9 @@ irq_timer(void) {
798 // TODO: Should we compare if previous and current wave are the 798 // TODO: Should we compare if previous and current wave are the
799 // same before updating? 799 // same before updating?
800 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1); 800 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(1);
801 dma_copy(SOUND_WAVE_RAM, params->wave_a, 16, 3); 801 memcpy32(SOUND_WAVE_RAM, params->wave_a, 16);
802 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0); 802 SOUND_WAVE_MODE = SOUND_WAVE_BANK_SELECT(0);
803 dma_copy(SOUND_WAVE_RAM, params->wave_b, 16, 3); 803 memcpy32(SOUND_WAVE_RAM, params->wave_b, 16);
804 804
805 switch (params->wave_mode) { 805 switch (params->wave_mode) {
806 case 0: { 806 case 0: {
@@ -1164,47 +1164,61 @@ handle_param_selection_ch3(void) {
1164 // ^^ 1164 // ^^
1165 // |`- odd 1165 // |`- odd
1166 // `-- even 1166 // `-- even
1167 // if (param_selection_loc < 32) { 1167 if (param_selection_loc < 32) {
1168 // u8 byte_number = param_selection_loc >> 1; 1168 // u8 byte_number = param_selection_loc >> 1;
1169 // u8 byte = sequences[2][trig_selection_loc].wave_a[byte_number]; 1169 // u8 byte = sequences[2][trig_selection_loc].wave_a[byte_number];
1170 // if (odd) { 1170 // if (odd) {
1171 // byte = (~0xF & byte) | ((byte + inc) & 0xF); 1171 // byte = (~0xF & byte) | ((byte + inc) & 0xF);
1172 // } else { 1172 // } else {
1173 // byte = (0xF & byte) | (((byte >> 4) + inc) & 0xF) << 4; 1173 // byte = (0xF & byte) | (((byte >> 4) + inc) & 0xF) << 4;
1174 // } 1174 // }
1175 // sequences[2][trig_selection_loc].wave_a[byte_number] = byte; 1175 // sequences[2][trig_selection_loc].wave_a[byte_number] = byte;
1176 // } else if (param_selection_loc < 64){ 1176 } else if (param_selection_loc < 64){
1177 // u8 byte_number = (param_selection_loc - 32) >> 1; 1177 // u8 byte_number = (param_selection_loc - 32) >> 1;
1178 // u8 byte = sequences[2][trig_selection_loc].wave_b[byte_number]; 1178 // u8 byte = sequences[2][trig_selection_loc].wave_b[byte_number];
1179 // if (odd) { 1179 // if (odd) {
1180 // byte = (~0xF & byte) | (byte + inc); 1180 // byte = (~0xF & byte) | (byte + inc);
1181 // } else { 1181 // } else {
1182 // byte = (0xF & byte) | ((byte >> 4) + inc) << 4; 1182 // byte = (0xF & byte) | ((byte >> 4) + inc) << 4;
1183 // } 1183 // }
1184 // sequences[2][trig_selection_loc].wave_b[byte_number] = byte; 1184 // sequences[2][trig_selection_loc].wave_b[byte_number] = byte;
1185 // } else if (param_selection_loc == 64){ 1185 } else {
1186 // dma_copy(&trig->wave_a, &sine_wave, 16, 3); 1186 u32 *wave_a = &ch3.params[trig_selection_loc].wave_a;
1187 // } else if (param_selection_loc == 65){ 1187 u32 *wave_b = &ch3.params[trig_selection_loc].wave_b;
1188 // dma_copy(&trig->wave_a, &saw_wave, 16, 3); 1188 switch (param_selection_loc) {
1189 // } else if (param_selection_loc == 66){ 1189 case 64: {
1190 // dma_copy(&trig->wave_a, &square_wave, 16, 3); 1190 memcpy32(wave_a, sine_wave, 16);
1191 // } else if (param_selection_loc == 67){ 1191 } break;
1192 // u32 rand_wave[4] = { 1192 case 65: {
1193 // rng32(), rng32(), rng32(), rng32(), 1193 memcpy32(wave_a, saw_wave, 16);
1194 // }; 1194 } break;
1195 // dma_copy(&trig->wave_a, &rand_wave, 16, 3); 1195 case 66: {
1196 // } else if (param_selection_loc == 68){ 1196 memcpy32(wave_a, square_wave, 16);
1197 // dma_copy(&trig->wave_b, &sine_wave, 16, 3); 1197 } break;
1198 // } else if (param_selection_loc == 69){ 1198 case 67: {
1199 // dma_copy(&trig->wave_b, &saw_wave, 16, 3); 1199 u32 rand_wave[4] = {
1200 // } else if (param_selection_loc == 70){ 1200 rng32(), rng32(), rng32(), rng32(),
1201 // dma_copy(&trig->wave_b, &square_wave, 16, 3); 1201 };
1202 // } else if (param_selection_loc == 71){ 1202 memcpy32(wave_a, rand_wave, 16);
1203 // u32 rand_wave[4] = { 1203 } break;
1204 // rng32(), rng32(), rng32(), rng32(), 1204 case 68: {
1205 // }; 1205 memcpy32(wave_b, sine_wave, 16);
1206 // dma_copy(&trig->wave_b, &rand_wave, 16, 3); 1206 } break;
1207 // } 1207 case 69: {
1208 memcpy32(wave_b, saw_wave, 16);
1209 } break;
1210 case 70: {
1211 memcpy32(wave_b, square_wave, 16);
1212 } break;
1213 case 71: {
1214 u32 rand_wave[4] = {
1215 rng32(), rng32(), rng32(), rng32(),
1216 };
1217 memcpy32(wave_b, rand_wave, 16);
1218 } break;
1219 }
1220 draw_parameters();
1221 }
1208 } 1222 }
1209} 1223}
1210 1224