aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: 3a15655507f77afcec35d36f5c3daad9c9e00f09 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
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

void
test_rects() {
    for (size_t i = 0; i < 100; i++) {
        // draw_line(0, 10, 10, 10, 1);
        // draw_line(10, 10, 10, 20, 1);
        // draw_line(0, 0, 10, 10, 2);
        // draw_line(0, 20, 20, 14, 1);
        // draw_line(0, 0, 239, 159, 2);
        // draw_line(0, 159, 239, 0, 3);
        // draw_filled_rect(10, 10, SCREEN_WIDTH - 11, SCREEN_HEIGHT - 11, 3);
        // draw_filled_rect(10, 10, 13, 21, 3);
        draw_filled_rect(10, 10, 20, 20, 3);
    }
}

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);

    // Main loop.
    PROF_INIT();
    while (true) {
        bios_vblank_wait();
        PROF(flip_buffer(), flip_cycles);
        PROF(test_rects(), eval_cycles);
        PROF_SHOW();
    }

    return 0;
}