/* Copyright (c) 2021 Bad Diode Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ #include "gba/gba.h" #include "filesystem.c" #include "renderer.c" // // Config parameters. // #ifdef PROF_ENABLE #if PROF_ENABLE == 0 #define PROF(F,VAR) (profile_start(),(F),(VAR) = profile_stop()) #elif PROF_ENABLE == 1 #define PROF(F,VAR) (profile_start(),(F),(VAR) = MAX(profile_stop(), (VAR))) #endif #ifndef PROF_SHOW_X #define PROF_SHOW_X 0 #endif #ifndef PROF_SHOW_Y #define PROF_SHOW_Y 0 #endif #define PROF_SHOW() \ do {\ txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\ txt_printf("EVAL: %lu ", eval_cycles);\ txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+1);\ txt_printf("FLIP: %lu ", flip_cycles);\ txt_position((PROF_SHOW_X), (PROF_SHOW_Y)+2);\ txt_printf("FRAME: %lu ", frame_counter);\ frame_counter++;\ } while (0) #define PROF_INIT() \ u32 frame_counter = 0;\ u32 eval_cycles = 0;\ u32 flip_cycles = 0; #else #define PROF(F,VAR) (F) #define PROF_SHOW() #define PROF_INIT() #endif #define TRIG_W 15 #define TRIG_H 24 #define TRIG_START_X 66 #define TRIG_START_Y 90 #define TRIG_OFFSET_X (TRIG_W + 4) #define TRIG_OFFSET_Y (TRIG_H + 7) void draw_triggers(void) { for (size_t i = 0; i < 8; i++) { size_t x0 = TRIG_START_X + TRIG_OFFSET_X * i; size_t x1 = TRIG_START_X + TRIG_W + TRIG_OFFSET_X * i; size_t y0 = TRIG_START_Y; size_t y1 = TRIG_START_Y + TRIG_H; draw_rect(x0, y0, x1, y1, 1); } for (size_t i = 0; i < 8; i++) { size_t x0 = TRIG_START_X + TRIG_OFFSET_X * i; size_t x1 = TRIG_START_X + TRIG_W + TRIG_OFFSET_X * i; size_t y0 = TRIG_START_Y + TRIG_OFFSET_Y; size_t y1 = TRIG_START_Y + TRIG_H + TRIG_OFFSET_Y; draw_rect(x0, y0, x1, y1, 1); } } #define CHAN_START_X 35 #define CHAN_START_Y 90 #define CHAN_OFFSET_Y 12 void draw_channels(void) { // Contains 5 channel buttons: Ch. 1-4 + FM. We are only drawing the DMG // channels for now, since FM may take some time to develop. u32 channel_buttons[] = { 0xff017111, 0x117101ff, 0xff008585, 0x879500ff, 0x0f080808, 0x0808080f, 0xff01b989, 0x89b901ff, 0xff004242, 0x434a00ff, 0x0f080909, 0x0909080f, 0xff015d45, 0xc55d01ff, 0xff00a1a1, 0xa1a500ff, 0x0f080a0a, 0x0a0a080f, 0xff015d45, 0xc55d01ff, 0xff00a1a1, 0xa12500ff, 0x0f080a0a, 0x0a0b080f, 0xff01c141, 0xc14101ff, 0xff00151c, 0x141400ff, 0x0f080808, 0x0808080f, }; Tile channel_tiles[3 * 4] = {0}; unpack_tiles(channel_buttons, channel_tiles, 3 * 4); size_t k = 0; for (size_t i = 0; i < 4; i++) { size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y; draw_tile(CHAN_START_X, y, channel_tiles + k++, false); draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, false); draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, false); } } void sequencer_init(void) { draw_triggers(); draw_channels(); } int main(void) { // Adjust system wait times. SYSTEM_WAIT = SYSTEM_WAIT_CARTRIDGE; // Initialize filesystem. fs_init(); // Initialize renderer. renderer_init(); // Register interrupts. irq_init(); irs_set(IRQ_VBLANK, irs_stub); // Initialize sequencer. sequencer_init(); // Main loop. PROF_INIT(); while (true) { bios_vblank_wait(); PROF(flip_buffer(), flip_cycles); PROF_SHOW(); } return 0; }