aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: 8ee494549dc82b32e9d09612773697c67a3ffc32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
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_m0.c"
#include "sequencer.c"

#define PROF_ENABLE 1
#include "profiling.c"


void
render(void) {
    // TODO: Make sure we are drawing the proper cursor color.
    // TODO: Decouple update from rendering.
    PROF(screen_fill(0), clear_cycles);
    PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles);
    PROF(draw_triggers(), draw_trigs_cycles);
    PROF(draw_channels(), draw_btn_cycles);
    PROF(draw_pattern_buttons(), draw_btn_cycles);
    PROF(draw_bank_buttons(), draw_btn_cycles);
    PROF(draw_bpm(), draw_btn_cycles);
    PROF(draw_play(), draw_btn_cycles);
    PROF(draw_stop(), draw_btn_cycles);
    PROF(draw_piano(), draw_piano_cycles);
    // TODO: Draw the notes currently playing with a fade off animation for the
    // first 3 channels.
    TriggerNote *trig = get_current_trig();
    PROF(draw_note(trig->note, COL_NOTE_PRESSED), draw_piano_cycles);
    PROF(draw_parameters(), draw_param_cycles);
    PROF(draw_trig_cursor(trig_selection_loc, COL_CURSOR), draw_cursor_cycles);
    PROF(draw_channel_cursor(channel_selection_loc, COL_GREY), draw_cursor_cycles);
    PROF(draw_pattern_cursor(pattern_selection_loc, COL_GREY), draw_cursor_cycles);
    PROF(draw_current_step(COL_RED), draw_cursor_cycles);
}

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();
    txt_spacing(6);

    // Main loop.
    while (true) {
        poll_keys();
        bios_vblank_wait();
        PROF_SHOW();
        FRAME_START();
        PROF(flip_buffer(), flip_cycles);
        PROF(handle_sequencer_input(), input_cycles);
        PROF(render(), render_cycles);
        FRAME_END();
    }

    return 0;
}