gp2x->common menu migration finished, gp2x now only uses input fwk
[libpicofe.git] / pandora / emu.c
index 0c6935b..16fc7cd 100644 (file)
 \r
 #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/menu.h"\r
 #include "../common/config.h"\r
-#include "../common/common.h"\r
+#include "../common/input.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
 #endif\r
 \r
 \r
-int engineState;\r
 int select_exits = 0;\r
 \r
-char romFileName[PATH_MAX];\r
-\r
 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
@@ -53,7 +49,7 @@ int reset_timing = 0;
 \r
 #define PICO_PEN_ADJUST_X 4\r
 #define PICO_PEN_ADJUST_Y 2\r
-static int pico_pen_x = SCREEN_WIDTH/2, pico_pen_y = 240/2;\r
+static int pico_pen_x = 0, pico_pen_y = 240/2;\r
 \r
 static void emu_msg_cb(const char *msg);\r
 static void emu_msg_tray_open(void);\r
@@ -101,18 +97,6 @@ void emu_Init(void)
 }\r
 \r
 \r
-static void scaling_update(void)\r
-{\r
-       PicoOpt &= ~0x4100;\r
-       switch (currentConfig.scaling) {\r
-               default: break; // off\r
-               case 1:  // hw hor\r
-               case 2:  PicoOpt |=  0x0100; break; // hw hor+vert\r
-               case 3:  PicoOpt |=  0x4000; break; // sw hor\r
-       }\r
-}\r
-\r
-\r
 void emu_Deinit(void)\r
 {\r
        // save SRAM\r
@@ -139,7 +123,6 @@ 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.EmuOpt    &= ~8; // no save gzip\r
        defaultConfig.s_PsndRate = 44100;\r
        defaultConfig.s_PicoRegion = 0;\r
@@ -155,14 +138,14 @@ void emu_prepareDefaultConfig(void)
 static void textOut16(int x, int y, const char *text)\r
 {\r
        int i,l,len=strlen(text);\r
-       unsigned int *screen = (unsigned int *)((unsigned short *)SCREEN_BUFFER + (x&~1) + y*SCREEN_WIDTH);\r
+       unsigned int *screen = (unsigned int *)((unsigned short *)g_screen_ptr + (x&~1) + y*g_screen_width);\r
 \r
        for (i = 0; i < len; i++)\r
        {\r
                for (l=0;l<16;)\r
                {\r
                        unsigned char fd = fontdata8x8[((text[i])*8)+l/2];\r
-                       unsigned int *d = &screen[l*SCREEN_WIDTH/2];\r
+                       unsigned int *d = &screen[l*g_screen_width/2];\r
                        if (fd&0x80) d[0]=0xffffffff;\r
                        if (fd&0x40) d[1]=0xffffffff;\r
                        if (fd&0x20) d[2]=0xffffffff;\r
@@ -171,7 +154,7 @@ static void textOut16(int x, int y, const char *text)
                        if (fd&0x04) d[5]=0xffffffff;\r
                        if (fd&0x02) d[6]=0xffffffff;\r
                        if (fd&0x01) d[7]=0xffffffff;\r
-                       l++; d = &screen[l*SCREEN_WIDTH/2];\r
+                       l++; d = &screen[l*g_screen_width/2];\r
                        if (fd&0x80) d[0]=0xffffffff;\r
                        if (fd&0x40) d[1]=0xffffffff;\r
                        if (fd&0x20) d[2]=0xffffffff;\r
@@ -196,7 +179,7 @@ void osd_text(int x, int y, const char *text)
                x &= ~3; // align x\r
                len = (len+3) >> 2;\r
                for (h = 0; h < 8; h++) {\r
-                       p = (int *) ((unsigned char *) gp2x_screen+x+SCREEN_WIDTH*(y+h));\r
+                       p = (int *) ((unsigned char *) g_screen_ptr+x+g_screen_width*(y+h));\r
                        for (i = len; i; i--, p++) *p = 0xe0e0e0e0;\r
                }\r
                emu_textOut8(x, y, text);\r
@@ -205,7 +188,7 @@ void osd_text(int x, int y, const char *text)
                x &= ~1; // align x\r
                len++;\r
                for (h = 0; h < 16; h++) {\r
-                       p = (int *) ((unsigned short *) gp2x_screen+x+SCREEN_WIDTH*(y+h));\r
+                       p = (int *) ((unsigned short *) g_screen_ptr+x+g_screen_width*(y+h));\r
                        for (i = len; i; i--, p++) *p = 0;//(*p>>2)&0x39e7;\r
                }\r
                textOut16(x, y, text);\r
@@ -223,26 +206,26 @@ static void draw_cd_leds(void)
                // 8-bit modes\r
                unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r
                unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r
-               *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*2+ 4) =\r
-               *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*3+ 4) =\r
-               *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*4+ 4) = col_g;\r
-               *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*2+12) =\r
-               *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*3+12) =\r
-               *(unsigned int *)((char *)gp2x_screen + SCREEN_WIDTH*4+12) = col_r;\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+ 4) =\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+ 4) =\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+ 4) = col_g;\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+12) =\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+12) =\r
+               *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+12) = col_r;\r
        } else {\r
                // 16-bit modes\r
-               unsigned int *p = (unsigned int *)((short *)gp2x_screen + SCREEN_WIDTH*2+4);\r
+               unsigned int *p = (unsigned int *)((short *)g_screen_ptr + g_screen_width*2+4);\r
                unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;\r
                unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;\r
-               *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += SCREEN_WIDTH/2 - 12/2;\r
-               *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += SCREEN_WIDTH/2 - 12/2;\r
+               *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;\r
+               *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;\r
                *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;\r
        }\r
 }\r
 \r
 static void draw_pico_ptr(void)\r
 {\r
-       unsigned short *p = (unsigned short *)gp2x_screen;\r
+       unsigned short *p = (unsigned short *)g_screen_ptr;\r
 \r
        // only if pen enabled and for 16bit modes\r
        if (pico_inp_mode == 0 || (PicoOpt&0x10) || !(currentConfig.EmuOpt&0x80)) return;\r
@@ -250,7 +233,7 @@ static void draw_pico_ptr(void)
        if (!(Pico.video.reg[12]&1) && !(PicoOpt&POPT_DIS_32C_BORDER))\r
                p += 32;\r
 \r
-       p += SCREEN_WIDTH * (pico_pen_y + PICO_PEN_ADJUST_Y);\r
+       p += g_screen_width * (pico_pen_y + PICO_PEN_ADJUST_Y);\r
        p += pico_pen_x + PICO_PEN_ADJUST_X;\r
        p[0]   ^= 0xffff;\r
        p[319] ^= 0xffff;\r
@@ -264,9 +247,9 @@ static void draw_pico_ptr(void)
 static int EmuScanBegin16(unsigned int num)\r
 {\r
        if (!(Pico.video.reg[1]&8)) num += 8;\r
-       DrawLineDest = (unsigned short *)gp2x_screen + num*800 + 800/2 - 320/2;\r
+       DrawLineDest = (unsigned short *)g_screen_ptr + num*800 + 800/2 - 320/2;\r
        //int w = (Pico.video.reg[12]&1) ? 320 : 256;\r
-       //DrawLineDest = (unsigned short *)gp2x_screen + num*w;\r
+       //DrawLineDest = (unsigned short *)g_screen_ptr + num*w;\r
 \r
        return 0;\r
 }\r
@@ -282,7 +265,7 @@ static int EmuScanEnd16(unsigned int num)
        int len, mask = 0xff;\r
 \r
        if (!(Pico.video.reg[1]&8)) num += 8;\r
-       pd=(unsigned short *)gp2x_screen + num*800*2 + 800/2 - 320*2/2;\r
+       pd=(unsigned short *)g_screen_ptr + num*800*2 + 800/2 - 320*2/2;\r
 \r
        if (Pico.m.dirtyPal)\r
                PicoDoHighPal555(sh);\r
@@ -294,8 +277,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
@@ -315,14 +298,6 @@ static int EmuScanEnd16(unsigned int num)
 \r
 #endif // USE_320_SCREEN\r
 \r
-static int EmuScanBegin8(unsigned int num)\r
-{\r
-       if (!(Pico.video.reg[1]&8)) num += 8;\r
-       DrawLineDest = (unsigned char *)  gp2x_screen + SCREEN_WIDTH * num;\r
-\r
-       return 0;\r
-}\r
-\r
 int localPal[0x100];\r
 static void (*vidCpyM2)(void *dest, void *src) = NULL;\r
 \r
@@ -337,13 +312,13 @@ static void blit(const char *fps, const char *notice)
                        Pico.m.dirtyPal = 0;\r
                        vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
                        // feed new palette to our device\r
-                       gp2x_video_setpalette(localPal, 0x40);\r
+                       // gp2x_video_setpalette(localPal, 0x40);\r
                }\r
                // a hack for VR\r
                if (PicoRead16Hook == PicoSVPRead16)\r
                        memset32((int *)(PicoDraw2FB+328*8+328*223), 0xe0e0e0e0, 328);\r
                // do actual copy\r
-               vidCpyM2((unsigned char *)gp2x_screen+SCREEN_WIDTH*8, PicoDraw2FB+328*8);\r
+               vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8);\r
        }\r
        else if (!(emu_opt&0x80))\r
        {\r
@@ -376,12 +351,12 @@ static void blit(const char *fps, const char *notice)
                                localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
                                localPal[0xf0] = 0x00ffffff;\r
                        }\r
-                       gp2x_video_setpalette(localPal, pallen);\r
+                       // gp2x_video_setpalette(localPal, pallen);\r
                }\r
        }\r
 \r
        if (notice || (emu_opt & 2)) {\r
-               int h = SCREEN_HEIGHT-16;\r
+               int h = g_screen_height-16;\r
                if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8)) h -= 16;\r
                if (notice) osd_text(4, h, notice);\r
                if (emu_opt & 2)\r
@@ -391,33 +366,24 @@ static void blit(const char *fps, const char *notice)
                draw_cd_leds();\r
        if (PicoAHW & PAHW_PICO)\r
                draw_pico_ptr();\r
-{\r
-//static int u=0;\r
-//memset((char *)gp2x_screen+800*471*2, (u++)>>1, 800*9*2);\r
-}\r
 \r
        //gp2x_video_wait_vsync();\r
-       gp2x_video_flip();\r
+       // gp2x_video_flip();\r
 }\r
 \r
 \r
 // clears whole screen or just the notice area (in all buffers)\r
 static void clearArea(int full)\r
 {\r
-       if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
-               // 8-bit renderers\r
-               if (full) gp2x_memset_all_buffers(0, 0xe0, SCREEN_WIDTH*240);\r
-               else      gp2x_memset_all_buffers(SCREEN_WIDTH*232, 0xe0, SCREEN_WIDTH*8);\r
-       } else {\r
-               // 16bit accurate renderer\r
-               if (full) gp2x_memset_all_buffers(0, 0, SCREEN_WIDTH*SCREEN_HEIGHT*2);\r
-               else      gp2x_memset_all_buffers(SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, 0, SCREEN_WIDTH*16*2);\r
-       }\r
+       if (full) memset(g_screen_ptr, 0, g_screen_width*g_screen_height*2);\r
+       else      memset((short *)g_screen_ptr + g_screen_width * (g_screen_height - 16), 0,\r
+                       g_screen_width * 16 * 2);\r
 }\r
 \r
 \r
 static void vidResetMode(void)\r
 {\r
+#if 0\r
        if (PicoOpt&0x10) {\r
                gp2x_video_changemode(8);\r
        } else if (currentConfig.EmuOpt&0x80) {\r
@@ -449,27 +415,37 @@ static void vidResetMode(void)
        if (currentConfig.scaling == 2 && !(Pico.video.reg[1]&8))\r
             gp2x_video_RGB_setscaling(8, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 224);\r
        else gp2x_video_RGB_setscaling(0, (PicoOpt&0x100)&&!(Pico.video.reg[12]&1) ? 256 : 320, 240);\r
+#else\r
+#ifdef USE_320_SCREEN\r
+       PicoDrawSetColorFormat(1);\r
+       PicoScanBegin = EmuScanBegin16;\r
+#else\r
+       PicoDrawSetColorFormat(-1);\r
+       PicoScanEnd = EmuScanEnd16;\r
+#endif\r
+#endif\r
 }\r
 \r
 \r
 static void emu_msg_cb(const char *msg)\r
 {\r
+/*\r
        if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
                // 8-bit renderers\r
-               gp2x_memset_all_buffers(SCREEN_WIDTH*(SCREEN_HEIGHT-16), 0xe0, SCREEN_WIDTH*16);\r
-               osd_text(4, SCREEN_HEIGHT-16, msg);\r
-               gp2x_memcpy_all_buffers((char *)gp2x_screen+SCREEN_WIDTH*(SCREEN_HEIGHT-16),\r
-                       SCREEN_WIDTH*(SCREEN_HEIGHT-16), SCREEN_WIDTH*16);\r
+               gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16), 0xe0, g_screen_width*16);\r
+               osd_text(4, g_screen_height-16, msg);\r
+               gp2x_memcpy_all_buffers((char *)g_screen_ptr+g_screen_width*(g_screen_height-16),\r
+                       g_screen_width*(g_screen_height-16), g_screen_width*16);\r
        } else {\r
                // 16bit accurate renderer\r
-               gp2x_memset_all_buffers(SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, 0, SCREEN_WIDTH*16*2);\r
-               osd_text(4, SCREEN_HEIGHT-16, msg);\r
-               gp2x_memcpy_all_buffers((char *)gp2x_screen+SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2,\r
-                       SCREEN_WIDTH*(SCREEN_HEIGHT-16)*2, SCREEN_WIDTH*16*2);\r
+               gp2x_memset_all_buffers(g_screen_width*(g_screen_height-16)*2, 0, g_screen_width*16*2);\r
+               osd_text(4, g_screen_height-16, msg);\r
+               gp2x_memcpy_all_buffers((char *)g_screen_ptr+g_screen_width*(g_screen_height-16)*2,\r
+                       g_screen_width*(g_screen_height-16)*2, g_screen_width*16*2);\r
        }\r
        gettimeofday(&noticeMsgTime, 0);\r
        noticeMsgTime.tv_sec -= 2;\r
-\r
+*/\r
        /* assumption: emu_msg_cb gets called only when something slow is about to happen */\r
        reset_timing = 1;\r
 }\r
@@ -486,6 +462,7 @@ static void emu_msg_tray_open(void)
        gettimeofday(&noticeMsgTime, 0);\r
 }\r
 \r
+#if 0\r
 static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)\r
 {\r
        int ret, px, py, lim_x;\r
@@ -537,6 +514,7 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)
        PicoPicohw.pen_pos[0] += 0x3c;\r
        PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
 }\r
+#endif\r
 \r
 static void update_volume(int has_changed, int is_up)\r
 {\r
@@ -554,7 +532,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
@@ -580,6 +558,7 @@ static void RunEvents(unsigned int which)
                if ( emu_checkSaveFile(state_slot) &&\r
                                (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) ||   // load\r
                                 (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save\r
+#if 0\r
                        unsigned long keys;\r
                        blit("", (which & 0x1000) ? "LOAD STATE? (Y=yes, X=no)" : "OVERWRITE SAVE? (Y=yes, X=no)");\r
                        while ( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) )\r
@@ -588,11 +567,12 @@ static void RunEvents(unsigned int which)
                        while ( gp2x_joystick_read(1) & (GP2X_X|GP2X_Y) ) // wait for release\r
                                usleep(50*1024);\r
                        clearArea(0);\r
+#endif\r
                }\r
                if (do_it) {\r
-                       osd_text(4, SCREEN_HEIGHT-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");\r
+                       osd_text(4, g_screen_height-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");\r
                        PicoStateProgressCB = emu_state_cb;\r
-                       gp2x_memcpy_all_buffers(gp2x_screen, 0, SCREEN_WIDTH*SCREEN_HEIGHT*2);\r
+                       //gp2x_memcpy_all_buffers(g_screen_ptr, 0, g_screen_width*g_screen_height*2);\r
                        emu_SaveLoadGame((which & 0x1000) >> 12, 0);\r
                        PicoStateProgressCB = NULL;\r
                }\r
@@ -636,63 +616,11 @@ static void RunEvents(unsigned int which)
 \r
 static void updateKeys(void)\r
 {\r
-       unsigned int keys, keys2, allActions[2] = { 0, 0 }, events;\r
+       unsigned int allActions[2] = { 0, 0 }, events;\r
        static unsigned int prevEvents = 0;\r
-       int joy, i;\r
-\r
-       keys = gp2x_joystick_read(0);\r
-       if (keys & GP2X_SELECT) {\r
-               engineState = select_exits ? PGS_Quit : PGS_Menu;\r
-               // wait until select is released, so menu would not resume game\r
-               while (gp2x_joystick_read(1) & GP2X_SELECT) usleep(50*1000);\r
-       }\r
-\r
-       keys &= CONFIGURABLE_KEYS;\r
-       keys2 = keys;\r
-\r
-       for (i = 0; i < 32; i++)\r
-       {\r
-               if (keys2 & (1 << i))\r
-               {\r
-                       int pl, acts = currentConfig.KeyBinds[i];\r
-                       if (!acts) continue;\r
-                       pl = (acts >> 16) & 1;\r
-                       if (kb_combo_keys & (1 << i))\r
-                       {\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 < 32; u++)\r
-                                               if ( (keys2 & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {\r
-                                                       allActions[pl] |= acts_c & currentConfig.KeyBinds[u];\r
-                                                       keys2 &= ~((1 << i) | (1 << u));\r
-                                                       break;\r
-                                               }\r
-                               }\r
-                               // add non-combo actions if combo ones were not found\r
-                               if (!acts_c || u == 32)\r
-                                       allActions[pl] |= acts & ~kb_combo_acts;\r
-                       } else {\r
-                               allActions[pl] |= acts;\r
-                       }\r
-               }\r
-       }\r
 \r
-       // add joy inputs\r
-       if (num_of_joys > 0)\r
-       {\r
-               gp2x_usbjoy_update();\r
-               for (joy = 0; joy < num_of_joys; joy++) {\r
-                       int btns = gp2x_usbjoy_check2(joy);\r
-                       for (i = 0; i < 32; i++) {\r
-                               if (btns & (1 << i)) {\r
-                                       int acts = currentConfig.JoyBinds[joy][i];\r
-                                       int pl = (acts >> 16) & 1;\r
-                                       allActions[pl] |= acts;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
+       /* FIXME: combos, player2 */\r
+       allActions[0] = in_update();\r
 \r
        PicoPad[0] = allActions[0] & 0xfff;\r
        PicoPad[1] = allActions[1] & 0xfff;\r
@@ -714,8 +642,10 @@ static void updateKeys(void)
 \r
        events &= ~prevEvents;\r
 \r
+/*\r
        if (PicoAHW == PAHW_PICO)\r
                RunEventsPico(events, keys);\r
+*/\r
        if (events) RunEvents(events);\r
        if (movie_data) emu_updateMovie();\r
 \r
@@ -729,7 +659,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
@@ -767,7 +697,7 @@ void emu_forcedFrame(int opts)
                clearArea(1);\r
        } else  vidCpyM2 = vidCpyM2_40col;\r
 \r
-       vidCpyM2((unsigned char *)gp2x_screen+SCREEN_WIDTH*8, PicoDraw2FB+328*8);\r
+       vidCpyM2((unsigned char *)g_screen_ptr+g_screen_width*8, PicoDraw2FB+328*8);\r
        vidConvCpyRGB32(localPal, Pico.cram, 0x40);\r
        gp2x_video_setpalette(localPal, 0x40);\r
 */\r
@@ -775,6 +705,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
@@ -791,10 +726,46 @@ static void simpleWait(int thissec, int lim_time)
        }\r
 }\r
 \r
+void emu_startSound(void)\r
+{\r
+       static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;\r
+       int target_fps = Pico.m.pal ? 50 : 60;\r
+\r
+       PsndOut = NULL;\r
+\r
+       if (currentConfig.EmuOpt & 4)\r
+       {\r
+               int snd_excess_add;\r
+               if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old)\r
+                       PsndRerate(Pico.m.frame_count ? 1 : 0);\r
+\r
+               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
+               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
+               PsndOut = sndBuffer;\r
+               PsndRate_old = PsndRate;\r
+               PicoOpt_old  = PicoOpt;\r
+               pal_old = Pico.m.pal;\r
+       }\r
+}\r
+\r
+void emu_endSound(void)\r
+{\r
+}\r
+\r
+/* wait until we can write more sound */\r
+void emu_waitSound(void)\r
+{\r
+       // don't need to do anything, writes will block by themselves\r
+}\r
 \r
 void emu_Loop(void)\r
 {\r
-       static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;\r
        char fpsbuff[24]; // fps count c string\r
        struct timeval tval; // timing\r
        int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync\r
@@ -808,38 +779,15 @@ void emu_Loop(void)
 \r
        // make sure we are in correct mode\r
        vidResetMode();\r
-       scaling_update();\r
        Pico.m.dirtyPal = 1;\r
        oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;\r
-       emu_findKeyBindCombos();\r
 \r
        // pal/ntsc might have changed, reset related stuff\r
        target_fps = Pico.m.pal ? 50 : 60;\r
        target_frametime = 1000000/target_fps;\r
        reset_timing = 1;\r
 \r
-       // prepare sound stuff\r
-       if (currentConfig.EmuOpt & 4)\r
-       {\r
-               int snd_excess_add;\r
-               if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old)\r
-                       PsndRerate(Pico.m.frame_count ? 1 : 0);\r
-\r
-               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
-               PicoWriteSound = updateSound;\r
-               update_volume(0, 0);\r
-               memset(sndBuffer, 0, sizeof(sndBuffer));\r
-               PsndOut = sndBuffer;\r
-               PsndRate_old = PsndRate;\r
-               PicoOpt_old  = PicoOpt;\r
-               pal_old = Pico.m.pal;\r
-       } else {\r
-               PsndOut = NULL;\r
-       }\r
+       emu_startSound();\r
 \r
        // prepare CD buffer\r
        if (PicoAHW & PAHW_MCD) PicoCDBufferInit();\r
@@ -847,7 +795,7 @@ void emu_Loop(void)
        // calc vsync offset to sync timing code with vsync\r
        if (currentConfig.EmuOpt&0x2000) {\r
                gettimeofday(&tval, 0);\r
-               gp2x_video_wait_vsync();\r
+               //gp2x_video_wait_vsync();\r
                gettimeofday(&tval, 0);\r
                vsync_offset = tval.tv_usec;\r
                while (vsync_offset >= target_frametime)\r
@@ -891,7 +839,7 @@ void emu_Loop(void)
                modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);\r
                if (modes != oldmodes)\r
                {\r
-                       int scalex = SCREEN_WIDTH;\r
+                       int scalex = g_screen_width;\r
                        osd_fps_x = OSD_FPS_X;\r
                        if (modes & 4) {\r
                                vidCpyM2 = vidCpyM2_40col;\r
@@ -904,9 +852,9 @@ void emu_Loop(void)
                                        vidCpyM2 = vidCpyM2_32col;\r
                                }\r
                        }\r
-                       if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode\r
-                            gp2x_video_RGB_setscaling(8, scalex, 224);\r
-                       else gp2x_video_RGB_setscaling(0, scalex, 240);\r
+                       //if (currentConfig.scaling == 2 && !(modes&8)) // want vertical scaling and game is not in 240 line mode\r
+                       //      gp2x_video_RGB_setscaling(8, scalex, 224);\r
+                       // else gp2x_video_RGB_setscaling(0, scalex, 240);\r
                        oldmodes = modes;\r
                        clearArea(1);\r
                }\r
@@ -996,7 +944,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
@@ -1006,13 +955,13 @@ void emu_Loop(void)
                                if (vsync_offset) {\r
                                        if (lim_time - tval.tv_usec > target_frametime/2)\r
                                                simpleWait(pthissec, lim_time - target_frametime/4);\r
-                                       gp2x_video_wait_vsync();\r
+                                       // gp2x_video_wait_vsync();\r
                                } else {\r
                                        simpleWait(pthissec, lim_time);\r
                                }\r
                        }\r
                }\r
-*/\r
+#endif\r
                blit(fpsbuff, notice);\r
 \r
                pframes_done++; pframes_shown++;\r