more unification; replace some magic bits to defines
[libpicofe.git] / pandora / emu.c
index 85c634f..cce5219 100644 (file)
@@ -53,8 +53,14 @@ static void emu_msg_cb(const char *msg);
 static void emu_msg_tray_open(void);\r
 \r
 \r
-void emu_noticeMsgUpdated(void)\r
+void plat_status_msg(const char *format, ...)\r
 {\r
+       va_list vl;\r
+\r
+       va_start(vl, format);\r
+       vsnprintf(noticeMsg, sizeof(noticeMsg), fmt, vl);\r
+       va_end(vl);\r
+\r
        gettimeofday(&noticeMsgTime, 0);\r
 }\r
 \r
@@ -460,59 +466,6 @@ 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
-       static int pdown_frames = 0;\r
-\r
-       emu_RunEventsPico(events);\r
-\r
-       if (pico_inp_mode == 0) return;\r
-\r
-       // for F200\r
-       ret = gp2x_touchpad_read(&px, &py);\r
-       if (ret >= 0)\r
-       {\r
-               if (ret > 35000)\r
-               {\r
-                       if (pdown_frames++ > 5)\r
-                               PicoPad[0] |= 0x20;\r
-\r
-                       pico_pen_x = px;\r
-                       pico_pen_y = py;\r
-                       if (!(Pico.video.reg[12]&1)) {\r
-                               pico_pen_x -= 32;\r
-                               if (pico_pen_x <   0) pico_pen_x = 0;\r
-                               if (pico_pen_x > 248) pico_pen_x = 248;\r
-                       }\r
-                       if (pico_pen_y > 224) pico_pen_y = 224;\r
-               }\r
-               else\r
-                       pdown_frames = 0;\r
-\r
-               //if (ret == 0)\r
-               //      PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
-       }\r
-\r
-       PicoPad[0] &= ~0x0f; // release UDLR\r
-       if (gp2x_keys & GP2X_UP)    pico_pen_y--;\r
-       if (gp2x_keys & GP2X_DOWN)  pico_pen_y++;\r
-       if (gp2x_keys & GP2X_LEFT)  pico_pen_x--;\r
-       if (gp2x_keys & GP2X_RIGHT) pico_pen_x++;\r
-\r
-       lim_x = (Pico.video.reg[12]&1) ? 319 : 255;\r
-       if (pico_pen_y < 8) pico_pen_y = 8;\r
-       if (pico_pen_y > 224-PICO_PEN_ADJUST_Y) pico_pen_y = 224-PICO_PEN_ADJUST_Y;\r
-       if (pico_pen_x < 0) pico_pen_x = 0;\r
-       if (pico_pen_x > lim_x-PICO_PEN_ADJUST_X) pico_pen_x = lim_x-PICO_PEN_ADJUST_X;\r
-\r
-       PicoPicohw.pen_pos[0] = pico_pen_x;\r
-       if (!(Pico.video.reg[12]&1)) PicoPicohw.pen_pos[0] += pico_pen_x/4;\r
-       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
@@ -548,108 +501,6 @@ static void update_volume(int has_changed, int is_up)
        }\r
 }\r
 \r
-static void RunEvents(unsigned int which)\r
-{\r
-       if (which & 0x1800) // save or load (but not both)\r
-       {\r
-               int do_it = 1;\r
-               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
-                               usleep(50*1024);\r
-                       if (keys & GP2X_X) do_it = 0;\r
-                       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, g_screen_height-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");\r
-                       PicoStateProgressCB = emu_state_cb;\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
-\r
-               reset_timing = 1;\r
-       }\r
-       if (which & 0x0400) // switch renderer\r
-       {\r
-               if      (  PicoOpt&0x10)             { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }\r
-               else if (!(currentConfig.EmuOpt&0x80)) PicoOpt|= 0x10;\r
-               else   currentConfig.EmuOpt &= ~0x80;\r
-\r
-               vidResetMode();\r
-\r
-               if (PicoOpt&0x10) {\r
-                       strcpy(noticeMsg, " 8bit fast renderer");\r
-               } else if (currentConfig.EmuOpt&0x80) {\r
-                       strcpy(noticeMsg, "16bit accurate renderer");\r
-               } else {\r
-                       strcpy(noticeMsg, " 8bit accurate renderer");\r
-               }\r
-\r
-               gettimeofday(&noticeMsgTime, 0);\r
-       }\r
-       if (which & 0x0300)\r
-       {\r
-               if(which&0x0200) {\r
-                       state_slot -= 1;\r
-                       if(state_slot < 0) state_slot = 9;\r
-               } else {\r
-                       state_slot += 1;\r
-                       if(state_slot > 9) state_slot = 0;\r
-               }\r
-               sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");\r
-               gettimeofday(&noticeMsgTime, 0);\r
-       }\r
-       if (which & 0x0080) {\r
-               engineState = PGS_Menu;\r
-       }\r
-}\r
-\r
-static void updateKeys(void)\r
-{\r
-       unsigned int allActions[2] = { 0, 0 }, events;\r
-       static unsigned int prevEvents = 0;\r
-\r
-       /* FIXME: combos, player2 */\r
-       allActions[0] = in_update();\r
-\r
-       PicoPad[0] = allActions[0] & 0xfff;\r
-       PicoPad[1] = allActions[1] & 0xfff;\r
-\r
-       if (allActions[0] & 0x7000) emu_DoTurbo(&PicoPad[0], allActions[0]);\r
-       if (allActions[1] & 0x7000) emu_DoTurbo(&PicoPad[1], allActions[1]);\r
-\r
-       events = (allActions[0] | allActions[1]) >> 16;\r
-\r
-       // volume is treated in special way and triggered every frame\r
-       if (events & 0x6000)\r
-               update_volume(1, events & 0x2000);\r
-\r
-       if ((events ^ prevEvents) & 0x40) {\r
-               emu_changeFastForward(events & 0x40);\r
-               update_volume(0, 0);\r
-               reset_timing = 1;\r
-       }\r
-\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
-       prevEvents = (allActions[0] | allActions[1]) >> 16;\r
-}\r
-\r
 \r
 static void updateSound(int len)\r
 {\r
@@ -892,7 +743,7 @@ void emu_Loop(void)
                                // 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 && pframes_done < target_fps && pframes_done > target_fps-5) {\r
-                                       updateKeys();\r
+                                       emu_update_input();\r
                                        SkipFrame(1); pframes_done++;\r
                                }\r
 \r
@@ -907,7 +758,7 @@ void emu_Loop(void)
                if (currentConfig.Frameskip >= 0) // frameskip enabled\r
                {\r
                        for(i = 0; i < currentConfig.Frameskip; i++) {\r
-                               updateKeys();\r
+                               emu_update_input();\r
                                SkipFrame(1); pframes_done++; frames_done++;\r
                                if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled\r
                                        gettimeofday(&tval, 0);\r
@@ -928,12 +779,12 @@ void emu_Loop(void)
                                reset_timing = 1;\r
                                continue;\r
                        }\r
-                       updateKeys();\r
+                       emu_update_input();\r
                        SkipFrame(tval.tv_usec < lim_time+target_frametime*2); pframes_done++; frames_done++;\r
                        continue;\r
                }\r
 \r
-               updateKeys();\r
+               emu_update_input();\r
                PicoFrame();\r
 \r
                // check time\r