experimental thread I/O code, fps counter fix
authornotaz <notasas@gmail.com>
Wed, 26 Mar 2008 19:00:40 +0000 (19:00 +0000)
committernotaz <notasas@gmail.com>
Wed, 26 Mar 2008 19:00:40 +0000 (19:00 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@396 be3aeb3a-fb24-0410-a615-afba39da0efa

base_readme.txt
gp2x/emu.c
psp/emu.c

index 947ac98..1a13a4d 100644 (file)
@@ -643,6 +643,8 @@ Changelog
     configs are now held in single file (but old game config files are still\r
     read).\r
   * Fixed a bug where some key combos didn't work.\r
+  * Fixed a regression in renderer (rare graphic glitches).\r
+  * Adjusted fast rernderer to work with more games, including VR.\r
 \r
 1.35b\r
   * PSP: mp3 code should no longer fail on 1.5 firmware.\r
index f251188..a3e7f83 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/limits.h>\r
 #include <ctype.h>\r
 #include <unistd.h>\r
+#include <sched.h>\r
 \r
 #include <stdarg.h>\r
 \r
@@ -541,10 +542,10 @@ static void updateKeys(void)
                        pl = (acts >> 16) & 1;\r
                        if (kb_combo_keys & (1 << i))\r
                        {\r
-                               int u, acts_c = acts & kb_combo_acts;\r
+                               int u = i+1, acts_c = acts & kb_combo_acts;\r
                                // let's try to find the other one\r
                                if (acts_c) {\r
-                                       for (u = i + 1; u < 32; u++)\r
+                                       for (; u < 32; u++)\r
                                                if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {\r
                                                        allActions[pl] |= acts_c & currentConfig.KeyBinds[u];\r
                                                        keys &= ~((1 << i) | (1 << u));\r
@@ -650,25 +651,78 @@ static void simpleWait(int thissec, int lim_time)
 \r
        spend_cycles(1024);\r
        gettimeofday(&tval, 0);\r
-       if(thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
+       if (thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
 \r
-       while(tval.tv_usec < lim_time)\r
+       if (tval.tv_usec < lim_time)\r
+               sched_yield();\r
+\r
+       while (tval.tv_usec < lim_time)\r
        {\r
                spend_cycles(1024);\r
                gettimeofday(&tval, 0);\r
-               if(thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
+               if (thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
        }\r
 }\r
 \r
 \r
+#if 0\r
+static void tga_dump(void)\r
+{\r
+#define BYTE unsigned char\r
+#define WORD unsigned short\r
+       struct\r
+       {\r
+               BYTE IDLength;        /* 00h  Size of Image ID field */\r
+               BYTE ColorMapType;    /* 01h  Color map type */\r
+               BYTE ImageType;       /* 02h  Image type code */\r
+               WORD CMapStart;       /* 03h  Color map origin */\r
+               WORD CMapLength;      /* 05h  Color map length */\r
+               BYTE CMapDepth;       /* 07h  Depth of color map entries */\r
+               WORD XOffset;         /* 08h  X origin of image */\r
+               WORD YOffset;         /* 0Ah  Y origin of image */\r
+               WORD Width;           /* 0Ch  Width of image */\r
+               WORD Height;          /* 0Eh  Height of image */\r
+               BYTE PixelDepth;      /* 10h  Image pixel size */\r
+               BYTE ImageDescriptor; /* 11h  Image descriptor byte */\r
+       } __attribute__((packed)) TGAHEAD;\r
+       static unsigned short oldscr[320*240];\r
+       FILE *f; char name[128]; int i;\r
+\r
+       memset(&TGAHEAD, 0, sizeof(TGAHEAD));\r
+       TGAHEAD.ImageType = 2;\r
+       TGAHEAD.Width = 320;\r
+       TGAHEAD.Height = 240;\r
+       TGAHEAD.PixelDepth = 16;\r
+       TGAHEAD.ImageDescriptor = 2<<4; // image starts at top-left\r
+\r
+#define CONV(X) (((X>>1)&0x7fe0)|(X&0x1f)) // 555?\r
+\r
+       for (i = 0; i < 320*240; i++)\r
+               if(oldscr[i] != CONV(((unsigned short *)gp2x_screen)[i])) break;\r
+       if (i < 320*240)\r
+       {\r
+               for (i = 0; i < 320*240; i++)\r
+                       oldscr[i] = CONV(((unsigned short *)gp2x_screen)[i]);\r
+               sprintf(name, "%05i.tga", Pico.m.frame_count);\r
+               f = fopen(name, "wb");\r
+               if (!f) { printf("!f\n"); exit(1); }\r
+               fwrite(&TGAHEAD, 1, sizeof(TGAHEAD), f);\r
+               fwrite(oldscr, 1, 320*240*2, f);\r
+               fclose(f);\r
+       }\r
+}\r
+#endif\r
+\r
+\r
 void emu_Loop(void)\r
 {\r
        static int gp2x_old_clock = 200;\r
        static int PsndRate_old = 0, PicoOpt_old = 0, EmuOpt_old = 0, pal_old = 0;\r
        char fpsbuff[24]; // fps count c string\r
        struct timeval tval; // timing\r
-       int thissec = 0, frames_done = 0, frames_shown = 0, oldmodes = 0;\r
-       int target_fps, target_frametime, lim_time, vsync_offset, i;\r
+       int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync\r
+       int  frames_done,  frames_shown,  thissec; // actual frames\r
+       int oldmodes = 0, target_fps, target_frametime, lim_time, vsync_offset, i;\r
        char *notice = 0;\r
 \r
        printf("entered emu_Loop()\n");\r
@@ -747,7 +801,10 @@ void emu_Loop(void)
        } else\r
                vsync_offset = 0;\r
 \r
-       // loop?\r
+       frames_done = frames_shown = thissec =\r
+       pframes_done = pframes_shown = pthissec = 0;\r
+\r
+       // loop\r
        while (engineState == PGS_Running)\r
        {\r
                int modes;\r
@@ -755,8 +812,8 @@ void emu_Loop(void)
                gettimeofday(&tval, 0);\r
                if (reset_timing) {\r
                        reset_timing = 0;\r
-                       thissec = tval.tv_sec;\r
-                       frames_shown = frames_done = tval.tv_usec/target_frametime;\r
+                       pthissec = tval.tv_sec;\r
+                       pframes_shown = pframes_done = tval.tv_usec/target_frametime;\r
                }\r
 \r
                // show notice message?\r
@@ -816,42 +873,50 @@ void emu_Loop(void)
                                sprintf(fpsbuff, "%02i/%02i", frames_shown, frames_done);\r
                        if (fpsbuff[5] == 0) { fpsbuff[5] = fpsbuff[6] = ' '; fpsbuff[7] = 0; }\r
 #endif\r
+                       frames_shown = frames_done = 0;\r
                        thissec = tval.tv_sec;\r
+               }\r
+#ifdef PFRAMES\r
+               sprintf(fpsbuff, "%i", Pico.m.frame_count);\r
+#endif\r
 \r
+               if (pthissec != tval.tv_sec)\r
+               {\r
                        if (PsndOut == 0 && currentConfig.Frameskip >= 0) {\r
-                               frames_done = frames_shown = 0;\r
+                               pframes_done = pframes_shown = 0;\r
                        } else {\r
                                // it is quite common for this implementation to leave 1 fame unfinished\r
                                // when second changes, but we don't want buffer to starve.\r
-                               if(PsndOut && frames_done < target_fps && frames_done > target_fps-5) {\r
+                               if(PsndOut && pframes_done < target_fps && pframes_done > target_fps-5) {\r
                                        updateKeys();\r
-                                       SkipFrame(1); frames_done++;\r
+                                       SkipFrame(1); pframes_done++;\r
                                }\r
 \r
-                               frames_done  -= target_fps; if (frames_done  < 0) frames_done  = 0;\r
-                               frames_shown -= target_fps; if (frames_shown < 0) frames_shown = 0;\r
-                               if (frames_shown > frames_done) frames_shown = frames_done;\r
+                               pframes_done  -= target_fps; if (pframes_done  < 0) pframes_done  = 0;\r
+                               pframes_shown -= target_fps; if (pframes_shown < 0) pframes_shown = 0;\r
+                               if (pframes_shown > pframes_done) pframes_shown = pframes_done;\r
                        }\r
+                       pthissec = tval.tv_sec;\r
                }\r
-#ifdef PFRAMES\r
-               sprintf(fpsbuff, "%i", Pico.m.frame_count);\r
-#endif\r
 \r
-               lim_time = (frames_done+1) * target_frametime + vsync_offset;\r
-               if(currentConfig.Frameskip >= 0) { // frameskip enabled\r
+               lim_time = (pframes_done+1) * target_frametime + vsync_offset;\r
+               if (currentConfig.Frameskip >= 0) // frameskip enabled\r
+               {\r
                        for(i = 0; i < currentConfig.Frameskip; i++) {\r
                                updateKeys();\r
-                               SkipFrame(1); frames_done++;\r
+                               SkipFrame(1); pframes_done++; frames_done++;\r
                                if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled\r
                                        gettimeofday(&tval, 0);\r
-                                       if(thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
-                                       if(tval.tv_usec < lim_time) { // we are too fast\r
-                                               simpleWait(thissec, lim_time);\r
+                                       if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;\r
+                                       if (tval.tv_usec < lim_time) { // we are too fast\r
+                                               simpleWait(pthissec, lim_time);\r
                                        }\r
                                }\r
                                lim_time += target_frametime;\r
                        }\r
-               } else if(tval.tv_usec > lim_time) { // auto frameskip\r
+               }\r
+               else if (tval.tv_usec > lim_time) // auto frameskip\r
+               {\r
                        // no time left for this frame - skip\r
                        if (tval.tv_usec - lim_time >= 300000) {\r
                                /* something caused a slowdown for us (disk access? cache flush?)\r
@@ -860,74 +925,16 @@ void emu_Loop(void)
                                continue;\r
                        }\r
                        updateKeys();\r
-                       SkipFrame(tval.tv_usec < lim_time+target_frametime*2); frames_done++;\r
+                       SkipFrame(tval.tv_usec < lim_time+target_frametime*2); pframes_done++; frames_done++;\r
                        continue;\r
                }\r
 \r
                updateKeys();\r
                PicoFrame();\r
 \r
-#if 0\r
-if (Pico.m.frame_count == 31563) {\r
-       FILE *f;\r
-       f = fopen("ram_p.bin", "wb");\r
-       if (!f) { printf("!f\n"); exit(1); }\r
-       fwrite(Pico.ram, 1, 0x10000, f);\r
-       fclose(f);\r
-       exit(0);\r
-}\r
-#endif\r
-#if 0\r
-               // debug\r
-               {\r
-                       #define BYTE unsigned char\r
-                       #define WORD unsigned short\r
-                       struct\r
-                       {\r
-                               BYTE IDLength;        /* 00h  Size of Image ID field */\r
-                               BYTE ColorMapType;    /* 01h  Color map type */\r
-                               BYTE ImageType;       /* 02h  Image type code */\r
-                               WORD CMapStart;       /* 03h  Color map origin */\r
-                               WORD CMapLength;      /* 05h  Color map length */\r
-                               BYTE CMapDepth;       /* 07h  Depth of color map entries */\r
-                               WORD XOffset;         /* 08h  X origin of image */\r
-                               WORD YOffset;         /* 0Ah  Y origin of image */\r
-                               WORD Width;           /* 0Ch  Width of image */\r
-                               WORD Height;          /* 0Eh  Height of image */\r
-                               BYTE PixelDepth;      /* 10h  Image pixel size */\r
-                               BYTE ImageDescriptor; /* 11h  Image descriptor byte */\r
-                       } __attribute__((packed)) TGAHEAD;\r
-                       static unsigned short oldscr[320*240];\r
-                       FILE *f; char name[128]; int i;\r
-\r
-                       memset(&TGAHEAD, 0, sizeof(TGAHEAD));\r
-                       TGAHEAD.ImageType = 2;\r
-                       TGAHEAD.Width = 320;\r
-                       TGAHEAD.Height = 240;\r
-                       TGAHEAD.PixelDepth = 16;\r
-                       TGAHEAD.ImageDescriptor = 2<<4; // image starts at top-left\r
-\r
-                       #define CONV(X) (((X>>1)&0x7fe0)|(X&0x1f)) // 555?\r
-\r
-                       for (i = 0; i < 320*240; i++)\r
-                               if(oldscr[i] != CONV(((unsigned short *)gp2x_screen)[i])) break;\r
-                       if (i < 320*240)\r
-                       {\r
-                               for (i = 0; i < 320*240; i++)\r
-                                       oldscr[i] = CONV(((unsigned short *)gp2x_screen)[i]);\r
-                               sprintf(name, "%05i.tga", Pico.m.frame_count);\r
-                               f = fopen(name, "wb");\r
-                               if (!f) { printf("!f\n"); exit(1); }\r
-                               fwrite(&TGAHEAD, 1, sizeof(TGAHEAD), f);\r
-                               fwrite(oldscr, 1, 320*240*2, f);\r
-                               fclose(f);\r
-                       }\r
-               }\r
-#endif\r
-\r
                // check time\r
                gettimeofday(&tval, 0);\r
-               if (thissec != tval.tv_sec) tval.tv_usec+=1000000;\r
+               if (pthissec != tval.tv_sec) tval.tv_usec+=1000000;\r
 \r
                if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 300000) // slowdown detection\r
                        reset_timing = 1;\r
@@ -940,17 +947,18 @@ if (Pico.m.frame_count == 31563) {
                                // we are too fast\r
                                if (vsync_offset) {\r
                                        if (lim_time - tval.tv_usec > target_frametime/2)\r
-                                               simpleWait(thissec, lim_time - target_frametime/4);\r
+                                               simpleWait(pthissec, lim_time - target_frametime/4);\r
                                        gp2x_video_wait_vsync();\r
                                } else {\r
-                                       simpleWait(thissec, lim_time);\r
+                                       simpleWait(pthissec, lim_time);\r
                                }\r
                        }\r
                }\r
 \r
                blit(fpsbuff, notice);\r
 \r
-               frames_done++; frames_shown++;\r
+               pframes_done++; pframes_shown++;\r
+                frames_done++;  frames_shown++;\r
        }\r
 \r
        change_fast_forward(0);\r
@@ -976,4 +984,3 @@ void emu_ResetGame(void)
        reset_timing = 1;\r
 }\r
 \r
-\r
index 2ea2673..acbe643 100644 (file)
--- a/psp/emu.c
+++ b/psp/emu.c
@@ -765,10 +765,10 @@ static void updateKeys(void)
                        pl = (acts >> 16) & 1;
                        if (kb_combo_keys & (1 << i))
                        {
-                               int u, acts_c = acts & kb_combo_acts;
+                               int u = i+1, acts_c = acts & kb_combo_acts;
                                // let's try to find the other one
                                if (acts_c) {
-                                       for (u = i + 1; u < 32; u++)
+                                       for (; u < 32; u++)
                                                if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {
                                                        allActions[pl] |= acts_c & currentConfig.KeyBinds[u];
                                                        keys &= ~((1 << i) | (1 << u));