extracted OSS code to sndout_oss_*, BTN->PBTN, refactoring
[libpicofe.git] / pandora / emu.c
index 633d027..f12bac6 100644 (file)
 #include <stdarg.h>\r
 \r
 #include "../gp2x/emu.h"\r
-#include "../gp2x/usbjoy.h"\r
 #include "../gp2x/menu.h"\r
 #include "../common/arm_utils.h"\r
 #include "../common/fonts.h"\r
 #include "../common/emu.h"\r
 #include "../common/config.h"\r
 #include "../common/common.h"\r
+#include "../linux/usbjoy.h"\r
+#include "../linux/sndout_oss.h"\r
 #include "asm_utils.h"\r
 \r
-#include <Pico/PicoInt.h>\r
-#include <Pico/Patch.h>\r
-#include <Pico/sound/mix.h>\r
+#include <pico/pico_int.h>\r
+#include <pico/patch.h>\r
+#include <pico/sound/mix.h>\r
 #include <zlib/zlib.h>\r
 \r
 //#define PFRAMES\r
@@ -48,7 +49,6 @@ char romFileName[PATH_MAX];
 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
 static struct timeval noticeMsgTime = { 0, 0 };        // when started showing\r
 static int osd_fps_x;\r
-char noticeMsg[64];                    // notice msg to draw\r
 unsigned char *PicoDraw2FB = NULL;  // temporary buffer for alt renderer\r
 int reset_timing = 0;\r
 \r
@@ -65,7 +65,7 @@ void emu_noticeMsgUpdated(void)
        gettimeofday(&noticeMsgTime, 0);\r
 }\r
 \r
-void emu_getMainDir(char *dst, int len)\r
+int emu_getMainDir(char *dst, int len)\r
 {\r
        extern char **g_argv;\r
        int j;\r
@@ -76,6 +76,8 @@ void emu_getMainDir(char *dst, int len)
        dst[len] = 0;\r
        for (j = strlen(dst); j > 0; j--)\r
                if (dst[j] == '/') { dst[j+1] = 0; break; }\r
+\r
+       return j + 1;\r
 }\r
 \r
 void emu_Init(void)\r
@@ -138,7 +140,7 @@ void emu_prepareDefaultConfig(void)
        defaultConfig.EmuOpt    = 0x8f | 0x00600; // | <- confirm_save, cd_leds\r
        defaultConfig.s_PicoOpt  = 0x0f | POPT_EXT_FM|POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_SVP_DRC;\r
        defaultConfig.s_PicoOpt |= POPT_ACC_SPRITES|POPT_EN_MCD_GFX;\r
-       defaultConfig.s_PicoOpt &= ~POPT_EN_SVP_DRC; // crashes :(\r
+//     defaultConfig.s_PicoOpt &= ~POPT_EN_SVP_DRC; // crashes :(\r
        defaultConfig.EmuOpt    &= ~8; // no save gzip\r
        defaultConfig.s_PsndRate = 44100;\r
        defaultConfig.s_PicoRegion = 0;\r
@@ -151,16 +153,6 @@ void emu_prepareDefaultConfig(void)
        defaultConfig.turbo_rate = 15;\r
 }\r
 \r
-void emu_setDefaultConfig(void)\r
-{\r
-       memcpy(&currentConfig, &defaultConfig, sizeof(currentConfig));\r
-       PicoOpt = currentConfig.s_PicoOpt;\r
-       PsndRate = currentConfig.s_PsndRate;\r
-       PicoRegionOverride = currentConfig.s_PicoRegion;\r
-       PicoAutoRgnOrder = currentConfig.s_PicoAutoRgnOrder;\r
-       PicoCDBuffers = currentConfig.s_PicoCDBuffers;\r
-}\r
-\r
 static void textOut16(int x, int y, const char *text)\r
 {\r
        int i,l,len=strlen(text);\r
@@ -303,8 +295,8 @@ static int EmuScanEnd16(unsigned int num)
                len = 256;\r
        }\r
 \r
-       if (!sh && (rendstatus & PDRAW_ACC_SPRITES))\r
-               mask=0x3f; // accurate sprites, upper bits are priority stuff\r
+       if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI))\r
+               mask=0x3f; // messed sprites, upper bits are priority stuff\r
 \r
 #if 1\r
        clut_line(pd, ps, pal, (mask<<16) | len);\r
@@ -359,7 +351,7 @@ static void blit(const char *fps, const char *notice)
                // 8bit accurate renderer\r
                if (Pico.m.dirtyPal)\r
                {\r
-                       int pallen = 0x40;\r
+                       int pallen = 0xc0;\r
                        Pico.m.dirtyPal = 0;\r
                        if (Pico.video.reg[0xC]&8) // shadow/hilight mode\r
                        {\r
@@ -369,13 +361,6 @@ static void blit(const char *fps, const char *notice)
                                memcpy32(localPal+0xc0, localPal+0x40, 0x40);\r
                                pallen = 0x100;\r
                        }\r
-                       else if (rendstatus & PDRAW_ACC_SPRITES) {\r
-                               vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
-                               memcpy32(localPal+0x40, localPal, 0x40);\r
-                               memcpy32(localPal+0x80, localPal, 0x40);\r
-                               memcpy32(localPal+0xc0, localPal, 0x40);\r
-                               pallen = 0x100;\r
-                       }\r
                        else if (rendstatus & PDRAW_SONIC_MODE) { // mid-frame palette changes\r
                                vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
                                vidConvCpyRGB32(localPal+0x40, HighPal, 0x40);\r
@@ -384,6 +369,7 @@ static void blit(const char *fps, const char *notice)
                        }\r
                        else {\r
                                vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
+                               memcpy32(localPal+0x80, localPal, 0x40);\r
                        }\r
                        if (pallen > 0xc0) {\r
                                localPal[0xc0] = 0x0000c000;\r
@@ -569,7 +555,7 @@ static void update_volume(int has_changed, int is_up)
                                if (vol >  0) vol--;\r
                        }\r
                        wait_frames = 0;\r
-                       gp2x_sound_volume(vol, vol);\r
+                       sndout_oss_setvol(vol, vol);\r
                        currentConfig.volume = vol;\r
                }\r
                sprintf(noticeMsg, "VOL: %02i", vol);\r
@@ -696,9 +682,9 @@ static void updateKeys(void)
        // add joy inputs\r
        if (num_of_joys > 0)\r
        {\r
-               gp2x_usbjoy_update();\r
+               usbjoy_update();\r
                for (joy = 0; joy < num_of_joys; joy++) {\r
-                       int btns = gp2x_usbjoy_check2(joy);\r
+                       int btns = usbjoy_check2(joy);\r
                        for (i = 0; i < 32; i++) {\r
                                if (btns & (1 << i)) {\r
                                        int acts = currentConfig.JoyBinds[joy][i];\r
@@ -744,7 +730,7 @@ static void updateSound(int len)
 \r
        /* avoid writing audio when lagging behind to prevent audio lag */\r
        if (PicoSkipFrame != 2)\r
-               gp2x_sound_write(PsndOut, len<<1);\r
+               sndout_oss_write(PsndOut, len<<1);\r
 }\r
 \r
 \r
@@ -790,6 +776,11 @@ void emu_forcedFrame(int opts)
        currentConfig.EmuOpt = eo_old;\r
 }\r
 \r
+void emu_platformDebugCat(char *str)\r
+{\r
+       // nothing\r
+}\r
+\r
 static void simpleWait(int thissec, int lim_time)\r
 {\r
        struct timeval tval;\r
@@ -843,8 +834,8 @@ void emu_Loop(void)
                snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;\r
                printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
                        PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);\r
-               gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3);\r
-               gp2x_sound_volume(currentConfig.volume, currentConfig.volume);\r
+               sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);\r
+               sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
                PicoWriteSound = updateSound;\r
                update_volume(0, 0);\r
                memset(sndBuffer, 0, sizeof(sndBuffer));\r
@@ -1011,7 +1002,8 @@ void emu_Loop(void)
 \r
                if (currentConfig.Frameskip < 0 && tval.tv_usec - lim_time >= 300000) // slowdown detection\r
                        reset_timing = 1;\r
-/*             else if (PsndOut != NULL || currentConfig.Frameskip < 0)\r
+#if 1\r
+               else if (PsndOut != NULL || currentConfig.Frameskip < 0)\r
                {\r
                        // sleep or vsync if we are still too fast\r
                        // usleep sleeps for ~20ms minimum, so it is not a solution here\r
@@ -1027,7 +1019,7 @@ void emu_Loop(void)
                                }\r
                        }\r
                }\r
-*/\r
+#endif\r
                blit(fpsbuff, notice);\r
 \r
                pframes_done++; pframes_shown++;\r