aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-28 22:42:41 +0200
committerBad Diode <bd@badd10de.dev>2021-05-28 22:42:41 +0200
commit59e1991f7ba8bcd6bc4aab611b904c7419b719a9 (patch)
tree241e6a736fbdf2ffccd58c86394368d4b8f06006
parent5068ec8d19fb7248abfcd065e1890c85fd96566b (diff)
downloaduxngba-59e1991f7ba8bcd6bc4aab611b904c7419b719a9.tar.gz
uxngba-59e1991f7ba8bcd6bc4aab611b904c7419b719a9.zip
Add macros for easy cycle profiling
-rw-r--r--src/main.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 2aa744c..255c790 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,6 +33,34 @@ WITH REGARD TO THIS SOFTWARE.
33#define CONTROL_METHODS CONTROL_CONTROLLER,CONTROL_MOUSE,CONTROL_KEYBOARD 33#define CONTROL_METHODS CONTROL_CONTROLLER,CONTROL_MOUSE,CONTROL_KEYBOARD
34#endif 34#endif
35 35
36#ifdef PROF_ENABLE
37#if PROF_ENABLE == 0
38#define PROF(F,VAR) (profile_start(),(F),(VAR) = profile_stop())
39#else
40#define PROF(F,VAR) (profile_start(),(F),(VAR) = MAX(profile_stop(), (VAR)))
41#endif
42#define PROF_SHOW(X,Y) \
43 do { \
44 txt_position((X), (Y));\
45 txt_printf("INPUT: %lu ", input_cycles);\
46 txt_position((X), (Y)+1);\
47 txt_printf("EVAL: %lu ", eval_cycles);\
48 txt_position((X), (Y)+2);\
49 txt_printf("FLIP: %lu ", flip_cycles);\
50 txt_position((X), (Y)+3);\
51 txt_printf("MIX: %lu ", mix_cycles);\
52 } while (0)
53#define PROF_INIT() \
54 u32 flip_cycles = 0;\
55 u32 eval_cycles = 0;\
56 u32 input_cycles = 0;\
57 u32 mix_cycles = 0;
58#else
59#define PROF(F,VAR) (F)
60#define PROF_SHOW(X,Y)
61#define PROF_INIT()
62#endif
63
36typedef enum { 64typedef enum {
37 CONTROL_CONTROLLER, 65 CONTROL_CONTROLLER,
38 CONTROL_MOUSE, 66 CONTROL_MOUSE,
@@ -392,12 +420,14 @@ int main(void) {
392 420
393 // Main loop. 421 // Main loop.
394 evaluxn(&u, 0x0100); 422 evaluxn(&u, 0x0100);
423 PROF_INIT();
395 while(true) { 424 while(true) {
396 bios_vblank_wait(); 425 bios_vblank_wait();
397 handle_input(&u); 426 PROF(handle_input(&u), input_cycles);
398 evaluxn(&u, mempeek16(devscreen->dat, 0)); 427 PROF(evaluxn(&u, mempeek16(devscreen->dat, 0)), eval_cycles);
399 sound_mix(); 428 PROF(sound_mix(), mix_cycles);
400 flipbuf(&ppu); 429 PROF_SHOW(9, 8);
430 PROF(flipbuf(&ppu), flip_cycles);
401 } 431 }
402 432
403 return 0; 433 return 0;