#include #include "common.h" #include "gba-buttons.c" #include "background-tiles.c" #include "sprites.h" #include "text.h" // // Main functions. // // TODO: Cleanup OBJ/OAM memory copying and access. // int main(void) { // Configure the display in mode 0 to show OBJs, where tile memory is // sequential. DISP_CTRL = DISP_ENABLE_SPRITES | DISP_MODE_0 | DISP_BG_0; // Initialize sprite button overlay. init_sprite_pal(0, COLOR_WHITE); init_sprites(0); init_button_sprites(); // Initialize text engine. txt_init(0, COLOR_RED, 0); // Register interrupts. irq_init(); irs_set(IRQ_VBLANK, irs_stub); // turn sound on SOUND_STATUS = SOUND_ENABLE; SOUND_DMG_MASTER = sound_volume(SOUND_SQUARE1 | SOUND_SQUARE2, 7); SOUND_DSOUND_MASTER = SOUND_DMG100; int frame_counter = 0; Note active_note = NOTE_C_4; int octave_diff = 0; bool playing = false; bool new_note = false; u8 interval = 4; while(true) { bios_vblank_wait(); poll_keys(); txt_position(0, 1); txt_clear_line(); if (key_pressed(KEY_B)) { active_note = NOTE_C_4 + 12 * octave_diff; new_note = true; } else if (key_pressed(KEY_A)) { active_note = NOTE_D_4 + 12 * octave_diff; new_note = true; } else if (key_pressed(KEY_LEFT)) { active_note = NOTE_E_4 + 12 * octave_diff; new_note = true; } else if (key_pressed(KEY_DOWN)) { active_note = NOTE_F_4 + 12 * octave_diff; new_note = true; } else if (key_pressed(KEY_RIGHT)) { active_note = NOTE_G_4 + 12 * octave_diff; new_note = true; } else if (key_pressed(KEY_UP)) { active_note = NOTE_A_4 + 12 * octave_diff; new_note = true; } else if (key_pressed(KEY_L)) { active_note = NOTE_B_4 + 12 * octave_diff; new_note = true; } else if (key_pressed(KEY_R)) { active_note = NOTE_C_5 + 12 * octave_diff; new_note = true; } if (key_pressed(KEY_START)) { octave_diff = CLAMP(octave_diff + 1, -2, 3); } if (key_pressed(KEY_SELECT)) { octave_diff = CLAMP(octave_diff - 1, -2, 3); } if (key_curr > 0) { txt_printf(" Playing: %s\n", note_names[active_note]); playing = true; } else { playing = false; } if (playing) { if (new_note) { // SOUND_SQUARE1_SWEEP = 3 | (1 << 3) | (2 << 4); // SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(15) | SOUND_SQUARE_ENV_TIME(0x7); // SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(15) | SOUND_SQUARE_ENV_TIME(0); SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(15) | SOUND_SQUARE_ENV_TIME(4) | SOUND_SQUARE_ENV_INC | SOUND_SQUARE_DUTY(3); // SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(15) | SOUND_SQUARE_ENV_TIME(4) | SOUND_SQUARE_ENV_INC; SOUND_SQUARE1_FREQ = SOUND_SQUARE_RESET | sound_rates[active_note]; // SOUND_SQUARE2_FREQ = SOUND_SQUARE_RESET | sound_rate((active_note + interval) % 12, octave); } new_note = false; } else { SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(0) | SOUND_SQUARE_ENV_TIME(0); SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(0) | SOUND_SQUARE_ENV_TIME(0); SOUND_SQUARE1_FREQ = 0; SOUND_SQUARE2_FREQ = 0; } frame_counter++; update_button_sprites(); }; return 0; }