From 4305d585d87c6bbc197b0fe2d9f144d6d0b772e2 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sat, 22 Apr 2023 18:30:45 +0200 Subject: Add frame time and FPS calculation to profiling macros --- src/common.h | 1 + src/main.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/common.h b/src/common.h index 1fbfa4c..bbe6b52 100644 --- a/src/common.h +++ b/src/common.h @@ -735,6 +735,7 @@ wait_vsync(void) { #define LEN(ARR) (sizeof(ARR) / sizeof((ARR)[0])) // Fixed-point arithmetic for (i.P) numbers. +#define FP_NUM(A,P) ((A) << (P)) #define FP_MUL(A,B,P) (((A) * (B)) >> (P)) #define FP_DIV(A,B,P) (((A) << (P)) / (B)) #define FP_LERP(Y0,Y1,X,P) ((Y0) + FP_MUL((X), ((Y1) - (Y0)), P)) diff --git a/src/main.c b/src/main.c index c6242c2..a2a43d4 100644 --- a/src/main.c +++ b/src/main.c @@ -88,8 +88,19 @@ txt_printf(">FLIP %.8lu\n", avg_flip_cycles);\ txt_printf("AUDIO %.8lu\n", avg_mix_cycles);\ txt_printf("TOTAL %.8lu\n", avg_frame_cycles);\ - screen_fill(BG_BACK, 0, 0, 8 * 16, 8 * 10, 0);\ - flipbuf();\ + u32 frame_time =\ + FP_DIV(\ + FP_NUM(avg_frame_cycles + 1, 2),\ + FP_NUM(2809, 2),\ + 2) * 166;\ + u32 fps =\ + FP_DIV(\ + FP_NUM(280896 * 60, 2),\ + FP_NUM(avg_frame_cycles + 1, 2),\ + 2);\ + txt_printf("TIME %.8lu\n", frame_time >> 2);\ + txt_printf("FPS %.8lu\n", (fps >> 2) + 1);\ + screen_fill(BG_BACK, 0, 0, 8 * 16, 8 * 12, 2);\ } while (0) static u32 prof_frame_counter = 0; @@ -727,7 +738,6 @@ main(void) { // NOTE: A VBLANK is 83776 cycles, anything other than that will make it so // we fail to render at 60FPS. while(true) { - PROF_SHOW(); bios_vblank_wait(); FRAME_START(); PROF(handle_input(&u), input_cycles); @@ -735,6 +745,7 @@ main(void) { PROF(sound_mix(), mix_cycles); // TODO: allow configuration to do VSYNC at 15 or 30 fps to avoid too // much memory copying on demanding uxn roms. + PROF_SHOW(); PROF(flipbuf(), flip_cycles); frame_counter++; if (frame_counter == 60) { -- cgit v1.2.1