From f6686f1e86927f038086023362251ebe78ce5ad6 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 2 Jun 2021 17:26:08 +0200 Subject: Init repo with basic BG framebuffer renderer --- src/main.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') 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 @@ +/* +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 "common.h" +// #include "text.h" + +#include "interrupts.c" +#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));\ + txt_printf("FLIP: %lu ", flip_cycles);\ + } while (0) +#define PROF_INIT() \ + u32 eval_cycles = 0;\ + u32 flip_cycles = 0; +#else +#define PROF(F,VAR) (F) +#define PROF_SHOW() +#define PROF_INIT() +#endif + +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); + + draw_pixel(0, 0, 1); + draw_pixel(0, 1, 2); + draw_pixel(0, 2, 3); + draw_pixel(0, 3, 4); + + // Main loop. + PROF_INIT(); + size_t frame_counter = 0; + while(true) { + bios_vblank_wait(); + PROF_SHOW(); + PROF(flip_buffer(), flip_cycles); + frame_counter++; + } + + return 0; +} -- cgit v1.2.1