aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..e228034
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,81 @@
1/*
2Copyright (c) 2021 Bad Diode
3
4Permission to use, copy, modify, and distribute this software for any
5purpose with or without fee is hereby granted, provided that the above
6copyright notice and this permission notice appear in all copies.
7
8THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9WITH REGARD TO THIS SOFTWARE.
10*/
11
12#include "common.h"
13// #include "text.h"
14
15#include "interrupts.c"
16#include "filesystem.c"
17#include "renderer.c"
18
19//
20// Config parameters.
21//
22
23#ifdef PROF_ENABLE
24#if PROF_ENABLE == 0
25#define PROF(F,VAR) (profile_start(),(F),(VAR) = profile_stop())
26#elif PROF_ENABLE == 1
27#define PROF(F,VAR) (profile_start(),(F),(VAR) = MAX(profile_stop(), (VAR)))
28#endif
29#ifndef PROF_SHOW_X
30#define PROF_SHOW_X 0
31#endif
32#ifndef PROF_SHOW_Y
33#define PROF_SHOW_Y 0
34#endif
35#define PROF_SHOW() \
36 do { \
37 txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\
38 txt_printf("EVAL: %lu ", eval_cycles);\
39 txt_position((PROF_SHOW_X), (PROF_SHOW_Y));\
40 txt_printf("FLIP: %lu ", flip_cycles);\
41 } while (0)
42#define PROF_INIT() \
43 u32 eval_cycles = 0;\
44 u32 flip_cycles = 0;
45#else
46#define PROF(F,VAR) (F)
47#define PROF_SHOW()
48#define PROF_INIT()
49#endif
50
51int main(void) {
52 // Adjust system wait times.
53 SYSTEM_WAIT = SYSTEM_WAIT_CARTRIDGE;
54
55 // Initialize filesystem.
56 fs_init();
57
58 // Initialize renderer.
59 renderer_init();
60
61 // Register interrupts.
62 irq_init();
63 irs_set(IRQ_VBLANK, irs_stub);
64
65 draw_pixel(0, 0, 1);
66 draw_pixel(0, 1, 2);
67 draw_pixel(0, 2, 3);
68 draw_pixel(0, 3, 4);
69
70 // Main loop.
71 PROF_INIT();
72 size_t frame_counter = 0;
73 while(true) {
74 bios_vblank_wait();
75 PROF_SHOW();
76 PROF(flip_buffer(), flip_cycles);
77 frame_counter++;
78 }
79
80 return 0;
81}