diff options
author | Bad Diode <bd@badd10de.dev> | 2023-05-28 18:54:03 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-05-28 18:54:03 +0200 |
commit | 765dc3ab3d79bdca696a0d651385af3020c895c6 (patch) | |
tree | 628a6ad09f1f0d9f2d8918a5a8924ded0ce001c4 | |
parent | 5024c6631ab583c0b375f0002e2ad6d6373d84ee (diff) | |
download | stepper-765dc3ab3d79bdca696a0d651385af3020c895c6.tar.gz stepper-765dc3ab3d79bdca696a0d651385af3020c895c6.zip |
Add initial link cable clock sync
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | src/gba/gba.h | 18 | ||||
-rw-r--r-- | src/sequencer.c | 29 |
3 files changed, 52 insertions, 0 deletions
@@ -81,6 +81,11 @@ $(BUILD_DIR): | |||
81 | run: main | 81 | run: main |
82 | mgba-qt $(BIN) | 82 | mgba-qt $(BIN) |
83 | 83 | ||
84 | deploy: | ||
85 | mount /dev/sdf1 /mnt | ||
86 | cp $(BIN) /mnt | ||
87 | umount /mnt | ||
88 | |||
84 | # Remove build directory. | 89 | # Remove build directory. |
85 | clean: | 90 | clean: |
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(); | |||
452 | int bios_div(int num, int denom); | 452 | int 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; | |||
20 | bool update_bpm = false; | 20 | bool update_bpm = false; |
21 | 21 | ||
22 | void | 22 | void |
23 | gate_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 | |||
35 | void | ||
23 | play_step(void) { | 36 | play_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 | } |