#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; Note active_note = NOTE_C_4; int octave_diff = 0; bool playing = false; bool new_note = false; u8 interval = 7; u32 sound_sequence[16] = { NOTE_C_4, NOTE_A_4, NOTE_D_5, NOTE_D_4, NOTE_F_4, NOTE_G_4, NOTE_C_4, NOTE_A_4, NOTE_D_5, NOTE_D_4, NOTE_F_4, NOTE_G_4, NOTE_A_4, NOTE_G_4, NOTE_A_4, NOTE_F_4, }; int step_counter = 0; int step_counter_2 = 0; int frame_counter = 0; bool trigger_1 = true; bool trigger_2 = true; while(true) { bios_vblank_wait(); poll_keys(); txt_position(0, 1); if (frame_counter >= 7 * 4) { if ((step_counter + 1) % 4 == 0) { step_counter_2 = (step_counter_2 + 1) % 16; trigger_2 = true; } trigger_1 = true; frame_counter = 0; step_counter = (step_counter + 1) % 16; } if (trigger_1 && playing) { active_note = sound_sequence[step_counter]; txt_clear_line(); txt_printf("SYNTH 1\n\n"); txt_clear_line(); txt_printf("Step: %d\n", step_counter); txt_clear_line(); txt_printf("Playing: %s\n\n\n\n", note_names[active_note]); SOUND_SQUARE1_CTRL = SOUND_SQUARE_ENV_VOL(13) | SOUND_SQUARE_ENV_TIME(4) | SOUND_SQUARE_DUTY(1); SOUND_SQUARE1_FREQ = SOUND_SQUARE_RESET | sound_rates[active_note]; trigger_1 = false; } if (trigger_2 && playing) { active_note = sound_sequence[step_counter_2]; txt_clear_line(); txt_printf("SYNTH 2\n\n"); txt_clear_line(); txt_printf("Step: %d\n", step_counter_2); txt_clear_line(); txt_printf("Playing: %s\n", note_names[active_note]); SOUND_SQUARE2_CTRL = SOUND_SQUARE_ENV_VOL(12) | SOUND_SQUARE_ENV_TIME(3) | SOUND_SQUARE_DUTY(3); SOUND_SQUARE2_FREQ = SOUND_SQUARE_RESET | sound_rates[active_note]; trigger_2 = false; } if (key_pressed(KEY_B)) { playing = true; step_counter = 0; step_counter_2 = 8; frame_counter = 0; trigger_1 = true; trigger_2 = true; } if (key_pressed(KEY_A)) { playing = false; } frame_counter++; // update_button_sprites(); }; return 0; }