summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c72
1 files changed, 21 insertions, 51 deletions
diff --git a/src/main.c b/src/main.c
index 30452e1..8b36226 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,23 +13,6 @@
13// TODO: Cleanup OBJ/OAM memory copying and access. 13// TODO: Cleanup OBJ/OAM memory copying and access.
14// 14//
15 15
16//
17// BIOS calls
18//
19
20int hblank_counter = 0;
21
22void
23irs_hblank_func() {
24 hblank_counter++;
25 if (DISP_VCOUNT >= 160) {
26 PAL_BUFFER_BG[0] = rgb15(0, 0, 0);
27 } else {
28 u16 clr = (DISP_VCOUNT / 8);
29 PAL_BUFFER_BG[0] = rgb15(clr, 0, 31 - clr);
30 }
31}
32
33int main(void) { 16int main(void) {
34 // Configure the display in mode 0 to show OBJs, where tile memory is 17 // Configure the display in mode 0 to show OBJs, where tile memory is
35 // sequential. 18 // sequential.
@@ -46,24 +29,18 @@ int main(void) {
46 // Register interrupts. 29 // Register interrupts.
47 irq_init(); 30 irq_init();
48 irs_set(IRQ_VBLANK, irs_stub); 31 irs_set(IRQ_VBLANK, irs_stub);
49 irs_set(IRQ_HBLANK, irs_hblank_func);
50 32
51 // turn sound on 33 // turn sound on
52 SOUND_STATUS = SOUND_ENABLE; 34 SOUND_STATUS = SOUND_ENABLE;
53 SOUND_DMG_MASTER = sound_volume(SOUND_SQUARE1 | SOUND_SQUARE2, 7); 35 SOUND_DMG_MASTER = sound_volume(SOUND_SQUARE1 | SOUND_SQUARE2, 7);
54 SOUND_DSOUND_MASTER = SOUND_DMG100; 36 SOUND_DSOUND_MASTER = SOUND_DMG100;
55 37
56 char *note_names[] = {
57 "C" , "C#" , "D" , "D#" ,
58 "E" , "F" , "F#" , "G" ,
59 "G#" , "A" , "A#" , "B"
60 };
61 int frame_counter = 0; 38 int frame_counter = 0;
62 Note active_note = NOTE_C; 39 Note active_note = NOTE_C_4;
63 u8 octave = 0; 40 int octave_diff = 0;
64 bool playing = false; 41 bool playing = false;
65 bool new_note = false; 42 bool new_note = false;
66 u8 interval = 1; 43 u8 interval = 4;
67 while(true) { 44 while(true) {
68 bios_vblank_wait(); 45 bios_vblank_wait();
69 poll_keys(); 46 poll_keys();
@@ -72,49 +49,39 @@ int main(void) {
72 txt_clear_line(); 49 txt_clear_line();
73 50
74 if (key_pressed(KEY_B)) { 51 if (key_pressed(KEY_B)) {
75 active_note = NOTE_C; 52 active_note = NOTE_C_4 + 12 * octave_diff;
76 new_note = true; 53 new_note = true;
77 octave = 0;
78 } else if (key_pressed(KEY_A)) { 54 } else if (key_pressed(KEY_A)) {
79 active_note = NOTE_D; 55 active_note = NOTE_D_4 + 12 * octave_diff;
80 new_note = true; 56 new_note = true;
81 octave = 0;
82 } else if (key_pressed(KEY_LEFT)) { 57 } else if (key_pressed(KEY_LEFT)) {
83 active_note = NOTE_E; 58 active_note = NOTE_E_4 + 12 * octave_diff;
84 new_note = true; 59 new_note = true;
85 octave = 0;
86 } else if (key_pressed(KEY_DOWN)) { 60 } else if (key_pressed(KEY_DOWN)) {
87 active_note = NOTE_F; 61 active_note = NOTE_F_4 + 12 * octave_diff;
88 new_note = true; 62 new_note = true;
89 octave = 0;
90 } else if (key_pressed(KEY_RIGHT)) { 63 } else if (key_pressed(KEY_RIGHT)) {
91 active_note = NOTE_G; 64 active_note = NOTE_G_4 + 12 * octave_diff;
92 new_note = true; 65 new_note = true;
93 octave = 0;
94 } else if (key_pressed(KEY_UP)) { 66 } else if (key_pressed(KEY_UP)) {
95 active_note = NOTE_A; 67 active_note = NOTE_A_4 + 12 * octave_diff;
96 new_note = true; 68 new_note = true;
97 octave = 0;
98 } else if (key_pressed(KEY_L)) { 69 } else if (key_pressed(KEY_L)) {
99 active_note = NOTE_B; 70 active_note = NOTE_B_4 + 12 * octave_diff;
100 new_note = true; 71 new_note = true;
101 octave = 0;
102 } else if (key_pressed(KEY_R)) { 72 } else if (key_pressed(KEY_R)) {
103 active_note = NOTE_C; 73 active_note = NOTE_C_5 + 12 * octave_diff;
104 new_note = true; 74 new_note = true;
105 octave = 1;
106 } 75 }
107 if (key_pressed(KEY_START)) { 76 if (key_pressed(KEY_START)) {
108 interval++; 77 octave_diff = CLAMP(octave_diff + 1, -2, 3);
109 } 78 }
110 if (key_pressed(KEY_SELECT)) { 79 if (key_pressed(KEY_SELECT)) {
111 interval--; 80 octave_diff = CLAMP(octave_diff - 1, -2, 3);
112 } 81 }
113 82
114 if (key_curr > 0) { 83 if (key_curr > 0) {
115 txt_printf(" Playing: %s + %s\n", 84 txt_printf(" Playing: %s\n", note_names[active_note]);
116 note_names[active_note],
117 (note_names[(active_note + interval) % 12]));
118 playing = true; 85 playing = true;
119 } else { 86 } else {
120 playing = false; 87 playing = false;
@@ -122,10 +89,13 @@ int main(void) {
122 89
123 if (playing) { 90 if (playing) {
124 if (new_note) { 91 if (new_note) {
125 SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(4) | SOUND_SQUARE_ENV_TIME(0); 92 // SOUND_SQUARE1_SWEEP = 3 | (1 << 3) | (2 << 4);
126 SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(4) | SOUND_SQUARE_ENV_TIME(0); 93 // SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(15) | SOUND_SQUARE_ENV_TIME(0x7);
127 SOUND_SQUARE1_FREQ = SOUND_SQUARE_RESET | sound_rate(active_note, octave); 94 // SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(15) | SOUND_SQUARE_ENV_TIME(0);
128 SOUND_SQUARE2_FREQ = SOUND_SQUARE_RESET | sound_rate((active_note + interval) % 12, octave); 95 SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(15) | SOUND_SQUARE_ENV_TIME(4) | SOUND_SQUARE_ENV_INC | SOUND_SQUARE_DUTY(3);
96 // SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(15) | SOUND_SQUARE_ENV_TIME(4) | SOUND_SQUARE_ENV_INC;
97 SOUND_SQUARE1_FREQ = SOUND_SQUARE_RESET | sound_rates[active_note];
98 // SOUND_SQUARE2_FREQ = SOUND_SQUARE_RESET | sound_rate((active_note + interval) % 12, octave);
129 } 99 }
130 new_note = false; 100 new_note = false;
131 } else { 101 } else {