aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-05-28 18:54:03 +0200
committerBad Diode <bd@badd10de.dev>2023-05-28 18:54:03 +0200
commit765dc3ab3d79bdca696a0d651385af3020c895c6 (patch)
tree628a6ad09f1f0d9f2d8918a5a8924ded0ce001c4
parent5024c6631ab583c0b375f0002e2ad6d6373d84ee (diff)
downloadstepper-765dc3ab3d79bdca696a0d651385af3020c895c6.tar.gz
stepper-765dc3ab3d79bdca696a0d651385af3020c895c6.zip
Add initial link cable clock sync
-rw-r--r--Makefile5
-rw-r--r--src/gba/gba.h18
-rw-r--r--src/sequencer.c29
3 files changed, 52 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 90b0a0d..5ccc725 100644
--- a/Makefile
+++ b/Makefile
@@ -81,6 +81,11 @@ $(BUILD_DIR):
81run: main 81run: main
82 mgba-qt $(BIN) 82 mgba-qt $(BIN)
83 83
84deploy:
85 mount /dev/sdf1 /mnt
86 cp $(BIN) /mnt
87 umount /mnt
88
84# Remove build directory. 89# Remove build directory.
85clean: 90clean:
86 rm -rf $(BUILD_DIR) 91 rm -rf $(BUILD_DIR)
diff --git a/src/gba/gba.h b/src/gba/gba.h
index be7a305..f726b72 100644
--- a/src/gba/gba.h
+++ b/src/gba/gba.h
@@ -452,6 +452,24 @@ int bios_vblank_wait();
452int bios_div(int num, int denom); 452int bios_div(int num, int denom);
453 453
454// 454//
455// SIO Link Cable
456//
457
458#define SIO_MODE *((vu16*)(MEM_IO + 0x0134))
459#define SIO_CNT *((vu16*)(MEM_IO + 0x0128))
460
461#define SIO_MODE_GP (2 << 14)
462#define SIO_SC(X) ((X) << 0)
463#define SIO_SD(X) ((X) << 1)
464#define SIO_SI(X) ((X) << 2)
465#define SIO_SO(X) ((X) << 3)
466#define SIO_SC_OUT(X) ((X) << 4)
467#define SIO_SD_OUT(X) ((X) << 5)
468#define SIO_SI_OUT(X) ((X) << 6)
469#define SIO_SO_OUT(X) ((X) << 7)
470#define SIO_IRQ_ENABLE (1 << 8)
471
472//
455// Sound. 473// Sound.
456// 474//
457 475
diff --git a/src/sequencer.c b/src/sequencer.c
index 867e686..7c989f2 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -20,6 +20,19 @@ bool redraw_piano_note = true;
20bool update_bpm = false; 20bool update_bpm = false;
21 21
22void 22void
23gate_off(void) {
24 SIO_MODE = SIO_MODE_GP
25 | SIO_SC_OUT(1)
26 | SIO_SD_OUT(1)
27 | SIO_SI_OUT(0)
28 | SIO_SO_OUT(1)
29 | SIO_SC(0)
30 | SIO_SD(1)
31 | SIO_SO(0);
32 TIMER_CTRL_1 = 0;
33}
34
35void
23play_step(void) { 36play_step(void) {
24 Pattern *pat = &patterns[current_pattern]; 37 Pattern *pat = &patterns[current_pattern];
25 if (current_pattern != next_pattern && step_counter == 15) { 38 if (current_pattern != next_pattern && step_counter == 15) {
@@ -135,6 +148,22 @@ play_step(void) {
135 SOUND_NOISE_CTRL = 0; 148 SOUND_NOISE_CTRL = 0;
136 SOUND_NOISE_FREQ = 0; 149 SOUND_NOISE_FREQ = 0;
137 } 150 }
151 // TODO: This should be configurable e.g. po needs a 1 each 2 to sync
152 // exactly, but we can also just want a pseudo clock divider.
153 if (step_counter % 2 == 0) {
154 SIO_MODE = SIO_MODE_GP
155 | SIO_SC_OUT(1)
156 | SIO_SD_OUT(1)
157 | SIO_SI_OUT(0)
158 | SIO_SO_OUT(1)
159 | SIO_SC(1)
160 | SIO_SD(1)
161 | SIO_SO(0);
162 int n_ticks = -244181 / 600;
163 irs_set(IRQ_TIMER_1, gate_off);
164 TIMER_DATA_1 = n_ticks;
165 TIMER_CTRL_1 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3;
166 }
138 step_counter = (step_counter + 1) % 16; 167 step_counter = (step_counter + 1) % 16;
139 redraw_piano_note = true; 168 redraw_piano_note = true;
140} 169}