platform, cleanup main emu loop
authorkub <derkub@gmail.com>
Wed, 14 Feb 2024 22:37:40 +0000 (23:37 +0100)
committerkub <derkub@gmail.com>
Wed, 14 Feb 2024 22:48:06 +0000 (23:48 +0100)
platform/common/emu.c

index 309178c..92375ea 100644 (file)
@@ -1395,17 +1395,17 @@ static void emu_loop_prep(void)
 }\r
 \r
 /* our tick here is 1 us right now */\r
-#define ms_to_ticks(x) (int)(x * 1000)\r
-#define get_ticks() plat_get_ticks_us()\r
-#define vsync_delay_x3 3*ms_to_ticks(1)\r
+#define ms_to_ticks(x) (int)(x * 1000)\r
+#define get_ticks()    plat_get_ticks_us()\r
+#define vsync_delay    ms_to_ticks(1)\r
 \r
 void emu_loop(void)\r
 {\r
        int frames_done, frames_shown;  /* actual frames for fps counter */\r
-       int target_frametime_x3;\r
-       unsigned int timestamp_x3 = 0;\r
-       unsigned int timestamp_aim_x3 = 0;\r
-       unsigned int timestamp_fps_x3 = 0;\r
+       int target_frametime;\r
+       unsigned int timestamp = 0;\r
+       unsigned int timestamp_aim = 0;\r
+       unsigned int timestamp_fps = 0;\r
        char *notice_msg = NULL;\r
        char fpsbuff[24];\r
        int fskip_cnt = 0;\r
@@ -1420,9 +1420,9 @@ void emu_loop(void)
 \r
        /* number of ticks per frame */\r
        if (Pico.m.pal)\r
-               target_frametime_x3 = 3 * ms_to_ticks(1000) / 50;\r
+               target_frametime = ms_to_ticks(1000) / 50;\r
        else\r
-               target_frametime_x3 = 3 * ms_to_ticks(1000) / 60;\r
+               target_frametime = ms_to_ticks(1000) / 60;\r
 \r
        reset_timing = 1;\r
        frames_done = frames_shown = 0;\r
@@ -1438,22 +1438,22 @@ void emu_loop(void)
                if (reset_timing) {\r
                        reset_timing = 0;\r
                        plat_video_wait_vsync();\r
-                       timestamp_aim_x3 = get_ticks() * 3;\r
-                       timestamp_fps_x3 = timestamp_aim_x3;\r
+                       timestamp_aim = get_ticks();\r
+                       timestamp_fps = timestamp_aim;\r
                        fskip_cnt = 0;\r
                }\r
                else if (currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) {\r
-                       timestamp_aim_x3 = get_ticks() * 3;\r
+                       timestamp_aim = get_ticks();\r
                }\r
 \r
-               timestamp_x3 = get_ticks() * 3;\r
+               timestamp = get_ticks();\r
 \r
                // show notice_msg message?\r
                if (notice_msg_time != 0)\r
                {\r
                        static int noticeMsgSum;\r
-                       if (timestamp_x3 - ms_to_ticks(notice_msg_time) * 3\r
-                            > ms_to_ticks(STATUS_MSG_TIMEOUT) * 3)\r
+                       if (timestamp - ms_to_ticks(notice_msg_time)\r
+                            > ms_to_ticks(STATUS_MSG_TIMEOUT))\r
                        {\r
                                notice_msg_time = 0;\r
                                notice_msg = NULL;\r
@@ -1470,7 +1470,7 @@ void emu_loop(void)
                }\r
 \r
                // second changed?\r
-               if (timestamp_x3 - timestamp_fps_x3 >= ms_to_ticks(1000) * 3)\r
+               if (timestamp - timestamp_fps >= ms_to_ticks(1000))\r
                {\r
 #ifdef BENCHMARK\r
                        static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];\r
@@ -1488,13 +1488,13 @@ void emu_loop(void)
                                snprintf(fpsbuff, 8, "%02i/%02i  ", frames_shown, frames_done);\r
 #endif\r
                        frames_shown = frames_done = 0;\r
-                       timestamp_fps_x3 += ms_to_ticks(1000) * 3;\r
+                       timestamp_fps += ms_to_ticks(1000);\r
                }\r
 #ifdef PFRAMES\r
                sprintf(fpsbuff, "%i", Pico.m.frame_count);\r
 #endif\r
 \r
-               diff = timestamp_aim_x3 - timestamp_x3;\r
+               diff = timestamp_aim - timestamp;\r
 \r
                if (currentConfig.Frameskip >= 0) // frameskip enabled (or 0)\r
                {\r
@@ -1506,7 +1506,7 @@ void emu_loop(void)
                                fskip_cnt = 0;\r
                        }\r
                }\r
-               else if (diff < -target_frametime_x3)\r
+               else if (diff < -target_frametime)\r
                {\r
                        /* no time left for this frame - skip */\r
                        /* limit auto frameskip to max_skip */\r
@@ -1521,14 +1521,14 @@ void emu_loop(void)
                        fskip_cnt = 0;\r
 \r
                // don't go in debt too much\r
-               while (diff < -target_frametime_x3 * 3) {\r
-                       timestamp_aim_x3 += target_frametime_x3;\r
-                       diff = timestamp_aim_x3 - timestamp_x3;\r
+               while (diff < -target_frametime * 3) {\r
+                       timestamp_aim += target_frametime;\r
+                       diff = timestamp_aim - timestamp;\r
                }\r
 \r
                emu_update_input();\r
                if (skip) {\r
-                       int do_audio = diff > -target_frametime_x3 * 2;\r
+                       int do_audio = diff > -target_frametime * 2;\r
                        PicoIn.skipFrame = do_audio ? 1 : 2;\r
                        PicoFrame();\r
                        PicoIn.skipFrame = 0;\r
@@ -1539,7 +1539,7 @@ void emu_loop(void)
                        frames_shown++;\r
                }\r
                frames_done++;\r
-               timestamp_aim_x3 += target_frametime_x3;\r
+               timestamp_aim += target_frametime;\r
 \r
                if (!skip && !flip_after_sync)\r
                        plat_video_flip();\r
@@ -1549,18 +1549,18 @@ void emu_loop(void)
                    && !(currentConfig.EmuOpt & (EOPT_NO_FRMLIMIT|EOPT_EXT_FRMLIMIT)))\r
                {\r
                        unsigned int timestamp = get_ticks();\r
-                       diff = timestamp_aim_x3 - timestamp * 3;\r
+                       diff = timestamp_aim - timestamp;\r
 \r
                        // sleep or vsync if we are still too fast\r
-                       if (diff > target_frametime_x3 + vsync_delay_x3 && (currentConfig.EmuOpt & EOPT_VSYNC)) {\r
+                       if (diff > target_frametime + vsync_delay && (currentConfig.EmuOpt & EOPT_VSYNC)) {\r
                                // we are too fast\r
                                plat_video_wait_vsync();\r
                                timestamp = get_ticks();\r
-                               diff = timestamp_aim_x3 - timestamp * 3;\r
+                               diff = timestamp_aim - timestamp;\r
                        }\r
-                       if (diff > target_frametime_x3 + vsync_delay_x3) {\r
+                       if (diff > target_frametime + vsync_delay) {\r
                                // still too fast\r
-                               plat_wait_till_us(timestamp + (diff - target_frametime_x3) / 3);\r
+                               plat_wait_till_us(timestamp + (diff - target_frametime));\r
                        }\r
                }\r
 \r