major menu unification, minor reorganization
[libpicofe.git] / gp2x / emu.c
index dc78521..f5052db 100644 (file)
 \r
 #include "emu.h"\r
 #include "gp2x.h"\r
-#include "usbjoy.h"\r
 #include "menu.h"\r
+#include "../linux/usbjoy.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/input.h"\r
+#include "../linux/sndout_oss.h"\r
 #include "cpuctrl.h"\r
+#include "version.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
 extern int crashed_940;\r
 \r
 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
@@ -122,12 +122,8 @@ void emu_Deinit(void)
                SRam.changed = 0;\r
        }\r
 \r
-       if (!(currentConfig.EmuOpt & 0x20)) {\r
-               config_writelrom(PicoConfigFile);\r
-#ifndef NO_SYNC\r
-               sync();\r
-#endif\r
-       }\r
+       if (!(currentConfig.EmuOpt & EOPT_NO_AUTOSVCFG))\r
+               emu_writelrom();\r
 \r
        free(PicoDraw2FB);\r
 \r
@@ -487,7 +483,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
@@ -583,6 +579,10 @@ static void updateKeys(void)
        keys &= CONFIGURABLE_KEYS;\r
        keys2 = keys;\r
 \r
+#if 1\r
+       /* FIXME: combos, player2 */\r
+       allActions[0] = in_update();\r
+#else\r
        for (i = 0; i < 32; i++)\r
        {\r
                if (keys2 & (1 << i))\r
@@ -610,13 +610,14 @@ static void updateKeys(void)
                        }\r
                }\r
        }\r
+#endif\r
 \r
        // 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
@@ -662,7 +663,47 @@ 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
+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
+       // 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
+                               ((PicoOpt&0x200) && crashed_940)) {\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
 \r
@@ -776,8 +817,7 @@ static void tga_dump(void)
 \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
+       static int gp2x_old_clock = 200, EmuOpt_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
@@ -821,29 +861,7 @@ void emu_Loop(void)
        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
-                               ((PicoOpt&0x200) && crashed_940)) {\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
@@ -1045,3 +1063,24 @@ void emu_ResetGame(void)
        reset_timing = 1;\r
 }\r
 \r
+const char *plat_get_credits(void)\r
+{\r
+       return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n"\r
+               "Credits:\n"\r
+               "fDave: Cyclone 68000 core,\n"\r
+               "      base code of PicoDrive\n"\r
+               "Reesy & FluBBa: DrZ80 core\n"\r
+               "MAME devs: YM2612 and SN76496 cores\n"\r
+               "rlyeh and others: minimal SDK\n"\r
+               "Squidge: squidgehack\n"\r
+               "Dzz: ARM940 sample\n"\r
+               "GnoStiC / Puck2099: USB joy code\n"\r
+               "craigix: GP2X hardware\n"\r
+               "ketchupgun: skin design\n"\r
+               "\n"\r
+               "special thanks (for docs, ideas):\n"\r
+               " Charles MacDonald, Haze,\n"\r
+               " Stephane Dallongeville,\n"\r
+               " Lordus, Exophase, Rokas,\n"\r
+               " Nemesis, Tasco Deluxe";\r
+}\r