use picofe menu, move generic code out of gp2x/
authornotaz <notasas@gmail.com>
Sun, 9 Sep 2012 21:55:40 +0000 (00:55 +0300)
committernotaz <notasas@gmail.com>
Sat, 15 Sep 2012 17:22:36 +0000 (20:22 +0300)
21 files changed:
.gitignore
Makefile.sdl
drivers/common/dface.h [moved from drivers/gp2x/dface.h with 95% similarity]
drivers/common/input.c [moved from drivers/gp2x/input.c with 71% similarity]
drivers/common/input.h [new file with mode: 0644]
drivers/common/main.c [moved from drivers/gp2x/main.c with 86% similarity]
drivers/common/main.h
drivers/common/menu.c [new file with mode: 0644]
drivers/common/menu.h [new file with mode: 0644]
drivers/common/platform.h [new file with mode: 0644]
drivers/common/settings.h [moved from drivers/gp2x/gp2x.h with 83% similarity]
drivers/common/throttle.h [moved from drivers/gp2x/throttle.h with 100% similarity]
drivers/common/usage.h [moved from drivers/gp2x/usage.h with 91% similarity]
drivers/gp2x/gp2x-sound.c
drivers/gp2x/gp2x-video.c
drivers/gp2x/gp2x.c
drivers/gp2x/throttle.c
drivers/sdl/minimal.c [moved from drivers/gp2x_test/minimal.c with 100% similarity]
drivers/sdl/sdl.c [new file with mode: 0644]
drivers/sdl/throttle.c [moved from drivers/gp2x_test/throttle.c with 95% similarity]
input.h

index 0558aee..f683457 100644 (file)
@@ -2,3 +2,4 @@
 cscope.out
 tags
 *.swp
+drivers/common/revision.h
index e9a2ecf..85da117 100644 (file)
@@ -24,19 +24,16 @@ endif
 
 all:           fceu
 
-gpfce.gpe: fceu
-       cp fceu $@
-
 include zlib/Makefile
 
-OBJDRIVER = drivers/gp2x_test/minimal.o drivers/gp2x_test/throttle.o \
-       ${G}gp2x.o ${G}main.o ${G}gp2x-sound.o ${G}gp2x-video.o \
-       ${G}usbjoy.o ${G}menu.o \
-       ${L}fonts.o ${L}readpng.o ${L}linux/plat.o \
+OBJDRIVER = drivers/sdl/sdl.o drivers/sdl/minimal.o drivers/sdl/throttle.o \
+       ${G}gp2x-sound.o ${G}gp2x-video.o ${G}usbjoy.o \
+       ${L}fonts.o ${L}readpng.o ${L}input.o ${L}in_sdl.o ${L}linux/plat.o \
+       ${C}main.o ${C}menu.o \
        ${C}cheat.o ${C}config.o ${C}args.o ${C}vidblit.o ${C}unix-netplay.o \
        ${UNZIPOBJS} \
        ppu.o movie.o fceu098.o ppu098.o
-LDRIVER                += -lm -lz -lpng `sdl-config --libs`
+LDRIVER += -lm -lz -lpng `sdl-config --libs`
 
 OBJDRIVER += x6502.o
 
@@ -44,21 +41,16 @@ x6502.o: x6502.c x6502.h ops.h fce.h sound.h dprintf.h
 
 include Makefile.base
 
+${C}menu.o:            ${C}revision.h
 ${B}main.o:            ${B}main.c ${B}main.h ${B}usage.h ${B}input.c
 ${B}gp2x.o:            ${B}gp2x.c ${B}gp2x.h ${B}rev.h
 ${B}throttle.o:         ${B}throttle.c ${B}main.h ${B}throttle.h
 ppu.o:                 ppu.c ppu.h
 
-${B}rev.h: FORCE
-       @if [ -f $@ ]; then prevrev=`cat $@`; else prevrev="00"; fi; \
-       if [ "`which svn`" != "" ]; then \
-               rev=`svn update|tail -n 1|sed 's/.*\ \(.*\)\./\1/g'|sed "s/'//g"`; \
-       fi; \
-       if [ "$$rev"  = "" ]; then rev="0"; fi; \
-       if [ "$$rev" != "$$prevrev" ]; then \
-               echo "$$rev" > $@; \
-       fi
-
+${C}revision.h: FORCE
+       @(git describe || echo) | sed -e 's/.*/#define REV "\0"/' > $@_
+       @diff -q $@_ $@ > /dev/null 2>&1 || cp $@_ $@
+       @rm $@_
 .PHONY: FORCE
 
 include Makefile.common
similarity index 95%
rename from drivers/gp2x/dface.h
rename to drivers/common/dface.h
index cb66b5c..b22d07d 100644 (file)
@@ -8,6 +8,7 @@ void GetBaseDirectory(char *BaseDirectory);
 int InitSound(void);
 void WriteSound(int16 *Buffer, int Count);
 
+void StartSound(void);
 void KillSound(void);
 void SilenceSound(int s);
 
similarity index 71%
rename from drivers/gp2x/input.c
rename to drivers/common/input.c
index f554f35..e4d0466 100644 (file)
@@ -20,7 +20,8 @@
 #include "../../input.h"
 #include "../../svga.h"
 #include "../../video.h"
-#include "usbjoy.h"
+#include "../libpicofe/input.h"
+#include "input.h"
 
 /* UsrInputType[] is user-specified.  InputType[] is current
        (game loading can override user settings)
@@ -55,8 +56,9 @@ static void setsoundvol(int soundvolume)
                prev_snd_on = !!soundvolume;
        }
 
+       platform_set_volume(soundvolume);
+
        // draw on screen :D
-       gp2x_sound_volume(soundvolume, soundvolume);
        int meterval=soundvolume/5;
        for (soundvolIndex = 0; soundvolIndex < 20; soundvolIndex++)
        {
@@ -80,51 +82,78 @@ static void do_emu_acts(uint32 acts)
        acts &= acts ^ prev_emu_acts;
        prev_emu_acts = actsc;
 
-       if (acts & (3 << 30))
+       if (acts & (EACT_SAVE_STATE | EACT_LOAD_STATE))
        {
-               unsigned long keys;
                int do_it = 1;
-               if (acts & (1 << 30))
+               int need_confirm = 0;
+               const char *nm;
+               char tmp[64];
+               int keys, len;
+
+               if (acts & EACT_LOAD_STATE)
                {
                        if (Settings.sstate_confirm & 2)
                        {
-                               FCEU_DispMessage("LOAD STATE? (Y=yes, X=no)");
-                               FCEU_PutImage();
-                               FCEUD_Update(XBuf+8,NULL,0);
-                               while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
-                               if (keys & GP2X_X) do_it = 0;
-                               FCEU_CancelDispMessage();
+                               need_confirm = 1;
                        }
-                       if (do_it) FCEUI_LoadState();
                }
                else
                {
                        if (Settings.sstate_confirm & 1)
                        {
                                char *fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
-                               FILE *st=fopen(fname,"rb");
+                               FILE *st = fopen(fname, "rb");
                                free(fname);
                                if (st)
                                {
                                        fclose(st);
-                                       FCEU_DispMessage("OVERWRITE SAVE? (Y=yes, X=no)");
-                                       FCEU_PutImage();
-                                       FCEUD_Update(XBuf+8,NULL,0);
-                                       while( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) ) usleep(50*1024);
-                                       if (keys & GP2X_X) do_it = 0;
-                                       FCEU_CancelDispMessage();
+                                       need_confirm = 1;
                                }
                        }
-                       if (do_it) FCEUI_SaveState();
                }
+
+               if (need_confirm) {
+                       strcpy(tmp, (acts & EACT_LOAD_STATE) ?
+                               "LOAD STATE?" : "OVERWRITE SAVE?");
+                       len = strlen(tmp);
+                       nm = in_get_key_name(-1, -PBTN_MA3);
+                       snprintf(tmp + len, sizeof(tmp) - len, "(%s=yes, ", nm);
+                       len = strlen(tmp);
+                       nm = in_get_key_name(-1, -PBTN_MBACK);
+                       snprintf(tmp + len, sizeof(tmp) - len, "%s=no)", nm);
+
+                       FCEU_DispMessage(tmp);
+                       FCEU_PutImage();
+                       FCEUD_Update(XBuf+8, NULL, 0);
+
+                       in_set_config_int(0, IN_CFG_BLOCKING, 1);
+                       while (in_menu_wait_any(NULL, 50) & (PBTN_MA3|PBTN_MBACK))
+                               ;
+                       while ( !((keys = in_menu_wait_any(NULL, 50)) & (PBTN_MA3|PBTN_MBACK)) )
+                               ;
+                       if (keys & PBTN_MBACK)
+                               do_it = 0;
+                       while (in_menu_wait_any(NULL, 50) & (PBTN_MA3|PBTN_MBACK))
+                               ;
+                       in_set_config_int(0, IN_CFG_BLOCKING, 0);
+
+                       FCEU_CancelDispMessage();
+               }
+               if (do_it) {
+                       if (acts & EACT_LOAD_STATE)
+                               FCEUI_LoadState();
+                       else
+                               FCEUI_SaveState();
+               }
+
                RefreshThrottleFPS();
        }
-       else if (acts & (3 << 28)) // state slot next/prev
+       else if (acts & (EACT_NEXT_SLOT|EACT_PREV_SLOT))
        {
                FILE *st;
                char *fname;
 
-               CurrentState += (acts & (1 << 29)) ? 1 :  -1;
+               CurrentState += (acts & EACT_NEXT_SLOT) ? 1 : -1;
                if (CurrentState > 9) CurrentState = 0;
                if (CurrentState < 0) CurrentState = 9;
 
@@ -134,17 +163,17 @@ static void do_emu_acts(uint32 acts)
                FCEU_DispMessage("[%s] State Slot %i", st ? "USED" : "FREE", CurrentState);
                if (st) fclose(st);
        }
-       else if (acts & (1 << 27)) // FDS insert/eject
+       else if (acts & EACT_FDS_INSERT)
        {
                if(FCEUGameInfo.type == GIT_FDS)
                        FCEU_DoSimpleCommand(FCEUNPCMD_FDSINSERT);
        }
-       else if (acts & (1 << 26)) // FDS select
+       else if (acts & EACT_FDS_SELECT)
        {
                if(FCEUGameInfo.type == GIT_FDS)
                        FCEU_DoSimpleCommand(FCEUNPCMD_FDSSELECT);
        }
-       else if (acts & (1 << 25)) // VS Unisystem insert coin
+       else if (acts & EACT_INSERT_COIN)
        {
                if(FCEUGameInfo.type == GIT_VSUNI)
                        FCEU_DoSimpleCommand(FCEUNPCMD_VSUNICOIN);
@@ -152,32 +181,31 @@ static void do_emu_acts(uint32 acts)
 }
 
 
-#define down(b) (keys & GP2X_##b)
-static void do_fake_mouse(unsigned long keys)
+static void do_fake_mouse(uint32 acts)
 {
        static int x=256/2, y=240/2;
        int speed = 3;
 
-       if (down(A)) speed = 1;
-       if (down(Y)) speed = 5;
+       if (acts & NKEY_B_TURBO) speed = 1;
+       if (acts & NKEY_A_TURBO) speed = 5;
 
-       if (down(LEFT))
+       if (acts & NKEY_LEFT)
        {
                x -= speed;
                if (x < 0) x = 0;
        }
-       else if (down(RIGHT))
+       else if (acts & NKEY_RIGHT)
        {
                x += speed;
                if (x > 255) x = 255;
        }
 
-       if (down(UP))
+       if (acts & NKEY_UP)
        {
                y -= speed;
                if (y < 0) y = 0;
        }
-       else if (down(DOWN))
+       else if (acts & NKEY_DOWN)
        {
                y += speed;
                if (y > 239) y = 239;
@@ -186,8 +214,8 @@ static void do_fake_mouse(unsigned long keys)
        MouseData[0] = x;
        MouseData[1] = y;
        MouseData[2] = 0;
-       if (down(B)) MouseData[2] |= 1;
-       if (down(X)) MouseData[2] |= 2;
+       if (acts & NKEY_A) MouseData[2] |= 1;
+       if (acts & NKEY_B) MouseData[2] |= 2;
 }
 
 
@@ -195,16 +223,20 @@ static void FCEUD_UpdateInput(void)
 {
        static int volpushed_frames = 0;
        static int turbo_rate_cnt_a[2] = {0,0}, turbo_rate_cnt_b[2] = {0,0};
-       unsigned long keys = gp2x_joystick_read(0);
-       uint32 all_acts[2] = {0,0};
-       int i;
+       uint32 all_acts[2], emu_acts;
+       int actions[IN_BINDTYPE_COUNT] = { 0, };
 
-       if ((down(VOL_DOWN) && down(VOL_UP)) || (keys & (GP2X_L|GP2X_START)) == (GP2X_L|GP2X_START))
+       in_update(actions);
+       all_acts[0] = actions[IN_BINDTYPE_PLAYER12];
+       all_acts[1] = actions[IN_BINDTYPE_PLAYER12] >> 16;
+       emu_acts = actions[IN_BINDTYPE_EMU];
+
+       if (emu_acts & EACT_ENTER_MENU)
        {
                Exit = 1;
                return;
        }
-       else if (down(VOL_UP))
+       else if (emu_acts & EACT_VOLUME_UP)
        {
                /* wait for at least 10 updates, because user may be just trying to enter menu */
                if (volpushed_frames++ > 10 && (volpushed_frames&1)) {
@@ -214,7 +246,7 @@ static void FCEUD_UpdateInput(void)
                        setsoundvol(soundvol);
                }
        }
-       else if (down(VOL_DOWN))
+       else if (emu_acts & EACT_VOLUME_DOWN)
        {
                if (volpushed_frames++ > 10 && (volpushed_frames&1)) {
                        soundvol-=1;
@@ -233,74 +265,32 @@ static void FCEUD_UpdateInput(void)
        if (InputType[1] != SI_GAMEPAD)
        {
                /* try to feed fake mouse there */
-               do_fake_mouse(keys);
-       }
-
-       for (i = 0; i < 32; i++)
-       {
-               if (keys & (1 << i))
-               {
-                       uint32 acts, u = 32;
-                       acts = Settings.KeyBinds[i];
-                       if (!acts) continue;
-                       if ((1 << i) & combo_keys)
-                       {
-                               // combo key detected, try to find if other is pressed
-                               for (u = i+1; u < 32; u++)
-                               {
-                                       if ((keys & (1 << u)) && (Settings.KeyBinds[u] & acts))
-                                       {
-                                               keys &= ~(1 << u);
-                                               acts &= Settings.KeyBinds[u];
-                                               break;
-                                       }
-                               }
-                       }
-                       if (u != 32) acts &=  combo_acts; // other combo key pressed
-                       else         acts &= ~combo_acts;
-                       all_acts[(acts>>16)&1] |= acts;
-               }
-       }
-
-       // add joy inputs
-       if (num_of_joys > 0)
-       {
-               int joy;
-               gp2x_usbjoy_update();
-               for (joy = 0; joy < num_of_joys; joy++) {
-                       int keys = gp2x_usbjoy_check2(joy);
-                       for (i = 0; i < 32; i++) {
-                               if (keys & (1 << i)) {
-                                       int acts = Settings.JoyBinds[joy][i];
-                                       all_acts[(acts>>16)&1] |= acts;
-                               }
-                       }
-               }
+               do_fake_mouse(all_acts[0]);
        }
 
        // player 1
        JSreturn |= all_acts[0] & 0xff;
-       if (all_acts[0] & 0x100) {              // A turbo
+       if (all_acts[0] & NKEY_A_TURBO) {
                turbo_rate_cnt_a[0] += Settings.turbo_rate_add;
                JSreturn |= (turbo_rate_cnt_a[0] >> 24) & 1;
        }
-       if (all_acts[0] & 0x200) {              // B turbo
+       if (all_acts[0] & NKEY_B_TURBO) {
                turbo_rate_cnt_b[0] += Settings.turbo_rate_add;
                JSreturn |= (turbo_rate_cnt_b[0] >> 23) & 2;
        }
 
        // player 2
        JSreturn |= (all_acts[1] & 0xff) << 16;
-       if (all_acts[1] & 0x100) {              // A turbo
+       if (all_acts[1] & NKEY_A_TURBO) {
                turbo_rate_cnt_a[1] += Settings.turbo_rate_add;
                JSreturn |= (turbo_rate_cnt_a[1] >> 8) & 0x10000;
        }
-       if (all_acts[1] & 0x200) {              // B turbo
+       if (all_acts[1] & NKEY_B_TURBO) {
                turbo_rate_cnt_b[1] += Settings.turbo_rate_add;
                JSreturn |= (turbo_rate_cnt_b[1] >> 7) & 0x20000;
        }
 
-       do_emu_acts(all_acts[0]|all_acts[1]);
+       do_emu_acts(emu_acts);
 }
 
 
diff --git a/drivers/common/input.h b/drivers/common/input.h
new file mode 100644 (file)
index 0000000..6bec074
--- /dev/null
@@ -0,0 +1,52 @@
+enum nkeys_bits {
+       NKEYB_A = 0,
+       NKEYB_B,
+       NKEYB_SELECT,
+       NKEYB_START,
+       NKEYB_UP,
+       NKEYB_DOWN,
+       NKEYB_LEFT,
+       NKEYB_RIGHT,
+       NKEYB_A_TURBO,
+       NKEYB_B_TURBO,
+};
+
+enum nkeys {
+       NKEY_A       = 1 << NKEYB_A,
+       NKEY_B       = 1 << NKEYB_B,
+       NKEY_SELECT  = 1 << NKEYB_SELECT,
+       NKEY_START   = 1 << NKEYB_START,
+       NKEY_UP      = 1 << NKEYB_UP,
+       NKEY_DOWN    = 1 << NKEYB_DOWN,
+       NKEY_LEFT    = 1 << NKEYB_LEFT,
+       NKEY_RIGHT   = 1 << NKEYB_RIGHT,
+       NKEY_A_TURBO = 1 << NKEYB_A_TURBO,
+       NKEY_B_TURBO = 1 << NKEYB_B_TURBO,
+};
+
+enum emu_actions_bits {
+       EACTB_SAVE_STATE  = 31,
+       EACTB_LOAD_STATE  = 30,
+       EACTB_NEXT_SLOT   = 29,
+       EACTB_PREV_SLOT   = 28,
+       EACTB_FDS_INSERT  = 27,
+       EACTB_FDS_SELECT  = 26,
+       EACTB_INSERT_COIN = 25,
+       EACTB_ENTER_MENU  = 24,
+       EACTB_VOLUME_UP   = 23,
+       EACTB_VOLUME_DOWN = 22,
+};
+
+enum emu_actions {
+       EACT_SAVE_STATE  = 1 << EACTB_SAVE_STATE,
+       EACT_LOAD_STATE  = 1 << EACTB_LOAD_STATE,
+       EACT_NEXT_SLOT   = 1 << EACTB_NEXT_SLOT,
+       EACT_PREV_SLOT   = 1 << EACTB_PREV_SLOT,
+       EACT_FDS_INSERT  = 1 << EACTB_FDS_INSERT,
+       EACT_FDS_SELECT  = 1 << EACTB_FDS_SELECT,
+       EACT_INSERT_COIN = 1 << EACTB_INSERT_COIN,
+       EACT_ENTER_MENU  = 1 << EACTB_ENTER_MENU,
+       EACT_VOLUME_UP   = 1 << EACTB_VOLUME_UP,
+       EACT_VOLUME_DOWN = 1 << EACTB_VOLUME_DOWN,
+};
+
similarity index 86%
rename from drivers/gp2x/main.c
rename to drivers/common/main.c
index 091fc83..616b7c6 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "../common/main.h"
-#include "minimal.h"
+#include "main.h"
 #include "throttle.h"
+#include "config.h"
+#include "args.h"
+#include "unixdsp.h"
+#include "cheat.h"
+#include "dface.h"
+#include "platform.h"
 #include "menu.h"
-#include "gp2x.h"
-
-#include "../common/config.h"
-#include "../common/args.h"
-#include "../common/unixdsp.h"
-#include "../common/cheat.h"
+#include "settings.h"
 
 #include "../../fce.h"
 #include "../../cart.h"
 
-#include "dface.h"
 
+// these are now here to try to make compatible configs
+// between different versions of the emu
+DSETTINGS Settings;
+CFGSTRUCT DriverConfig[]={
+       AC(Settings.turbo_rate_add),
+       AC(Settings.sound_rate),
+       AC(Settings.showfps),
+       AC(Settings.scaling),
+       AC(Settings.frameskip),
+       AC(Settings.sstate_confirm),
+       AC(Settings.region_force),
+       AC(Settings.cpuclock),
+       AC(Settings.mmuhack),
+       AC(Settings.ramtimings),
+       AC(Settings.gamma),
+       AC(Settings.perfect_vsync),
+       AC(Settings.accurate_mode),
+       ENDCFGSTRUCT
+};
 
 void CleanSurface(void);
 
 // internals
-extern char lastLoadedGameName[2048];
 extern uint8 Exit; // exit emu loop flag
 extern int FSkip;
 void CloseGame(void);
@@ -260,6 +277,9 @@ static int DoArgs(int argc, char *argv[])
        static char *inputa[2]={0,0};
        static char *fcexp=0;
        static int docheckie[4];
+#ifdef NETWORK
+        static int docheckie2[2]={0,0};
+#endif
 
         static ARGPSTRUCT FCEUArgs[]={
          {"-soundvol",0,&soundvol,0},
@@ -279,8 +299,15 @@ static int DoArgs(int argc, char *argv[])
         {"-noautowrite",0,&eoptions,0x8000|EO_NOAUTOWRITE},
          {"-slstart",0,&srendlinev[0],0},{"-slend",0,&erendlinev[0],0},
          {"-slstartp",0,&srendlinev[1],0},{"-slendp",0,&erendlinev[1],0},
-        {0,(void *)DriverArgs,0,0},
-        {0,0,0,0}
+         {"-sound",0,&Settings.sound_rate,0},
+         {"-showfps",0,&Settings.showfps,0},
+         #ifdef NETWORK
+         {"-connect",&docheckie2[0],&netplayhost,0x4001},
+         {"-server",&docheckie2[1],0,0},
+         {"-netport",0,&Port,0},
+         #endif
+         {0,(void *)DriverArgs,0,0},
+         {0,0,0,0}
         };
 
         memset(docheckie,0,sizeof(docheckie));
@@ -308,6 +335,15 @@ static int DoArgs(int argc, char *argv[])
 
         FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
         FCEUI_SetSoundVolume(80);
+       #ifdef NETWORK
+        if(docheckie2[0])
+         netplay=2;
+        else if(docheckie2[1])
+         netplay=1;
+
+        if(netplay)
+         FCEUI_SetNetworkPlay(netplay);
+       #endif
        DoDriverArgs();
 
        if(fcexp)
@@ -350,7 +386,7 @@ static int DoArgs(int argc, char *argv[])
 
 #include "usage.h"
 
-int CLImain(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
        int last_arg_parsed, ret;
         /* TODO if(argc<=1)
@@ -359,6 +395,7 @@ int CLImain(int argc, char *argv[])
          return 1;
         }*/
 
+        platform_init();
         if(!DriverInitialize())
         {
         return 1;
@@ -369,11 +406,15 @@ int CLImain(int argc, char *argv[])
         GetBaseDirectory(BaseDirectory);
        FCEUI_SetBaseDirectory(BaseDirectory);
        lastLoadedGameName[0] = 0;
+       menu_init();
+       in_init();
 
        CreateDirs();
         LoadConfig(NULL);
         last_arg_parsed=DoArgs(argc-1,&argv[1]);
-       gp2x_opt_setup();
+       platform_late_init();
+       in_probe();
+
        LoadLLGN();
        FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
        if(cpalette)
@@ -424,17 +465,17 @@ int CLImain(int argc, char *argv[])
          else
          {
           switch(LoadGameLastError) {
-           default: strcpy(menuErrorMsg, "failed to load ROM"); break;
-           case  2: strcpy(menuErrorMsg, "Can't find a ROM for ips/movie"); break;
-           case 10: strcpy(menuErrorMsg, "FDS BIOS ROM is missing, read docs"); break;
-           case 11: strcpy(menuErrorMsg, "Error reading auxillary FDS file"); break;
+           default: menu_update_msg("failed to load ROM"); break;
+           case  2: menu_update_msg("Can't find a ROM for ips/movie"); break;
+           case 10: menu_update_msg("FDS BIOS ROM is missing, read docs"); break;
+           case 11: menu_update_msg("Error reading auxillary FDS file"); break;
           }
          }
         }
          if(Exit || !fceugi)
          {
           int ret;
-         ret = gp2x_menu_do();
+         ret = menu_loop();
          if (ret == 1) break;          // exit emu
          if (ret == 2) {               // reload ROM
           Exit = 0;
@@ -442,18 +483,11 @@ int CLImain(int argc, char *argv[])
          }
          }
 
-        gp2x_opt_update();
         PrepareOtherInput();
         FCEUI_GetCurrentVidSystem(&srendline,&erendline);
-        gp2x_video_changemode(Settings.scaling == 3 ? 15 : 8);
-        switch (Settings.scaling & 3) {
-                case 0: gp2x_video_set_offs(0);  gp2x_video_RGB_setscaling(320, 240); break;
-                case 1: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(256, 240); break;
-                case 2: gp2x_video_set_offs(32+srendline*320); gp2x_video_RGB_setscaling(256, erendline-srendline); break;
-                case 3: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(320, 240); break;
-        }
+        platform_apply_config();
         CleanSurface();
-        gp2x_start_sound(Settings.sound_rate, 16, 0);
+        StartSound();
         RefreshThrottleFPS();
         FCEUI_Emulate();
        }
@@ -464,7 +498,8 @@ int CLImain(int argc, char *argv[])
        SaveLLGN();
        FCEUI_Kill();
        DriverKill();
-        return 0;
+       platform_finish();
+       return 0;
 }
 
 static int DriverInitialize(void)
@@ -506,3 +541,4 @@ void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count)
  if (Exit) FSkip=0;
 }
 
+
index 4739595..0b9bf7d 100644 (file)
@@ -30,6 +30,7 @@ extern int eoptions;
 #define EO_NOAUTOWRITE 256
 extern int srendline,erendline,srendlinev[2],erendlinev[2];
 extern int NoWaiting;
+extern int soundvol;
 
 extern FCEUGI *fceugi;
 
diff --git a/drivers/common/menu.c b/drivers/common/menu.c
new file mode 100644 (file)
index 0000000..5fe0cfc
--- /dev/null
@@ -0,0 +1,649 @@
+/*
+ * (C) GraÅžvydas "notaz" Ignotas, 2010-2011
+ *
+ * This work is licensed under the terms of any of these licenses
+ * (at your option):
+ *  - GNU GPL, version 2 or later.
+ *  - GNU LGPL, version 2.1 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include "main.h"
+#include "menu.h"
+#include "input.h"
+#include "settings.h"
+#include "config.h"
+#include "args.h"
+#include "dface.h"
+#include "../libpicofe/plat.h"
+#include "../libpicofe/input.h"
+#include "../../state.h"
+#include "../../general.h"
+#include "../../input.h"
+#include "../../palette.h"
+#include "revision.h"
+
+#define array_size(x) (sizeof(x) / sizeof(x[0]))
+
+#define state_slot CurrentState
+extern uint8 Exit;
+
+typedef enum
+{
+       MA_NONE = 1,
+       MA_CTRL_PLAYER1,
+       MA_CTRL_PLAYER2,
+       MA_CTRL_EMU,
+       MA_CTRL_DEADZONE,
+       MA_OPT_SAVECFG,
+       MA_OPT_SAVECFG_GAME,
+       MA_CTRL_DEV_FIRST,
+       MA_CTRL_DEV_NEXT,
+       MA_OPT_NTSC_COLOR,
+       MA_OPT_NTSC_TINT,
+       MA_OPT_NTSC_HUE,
+       MA_OPT_SREND_N,
+       MA_OPT_EREND_N,
+       MA_OPT_SREND_P,
+       MA_OPT_EREND_P,
+       MA_OPT_CLIP,
+       MA_OPT_NO8LIM,
+       MA_OPT_GG,
+       MA_OPT_SHOWFPS,
+       MA_OPT_FSKIP,
+       MA_OPT_RENDERER,
+       MA_OPT_SOUNDON,
+       MA_OPT_SOUNDRATE,
+       MA_OPT_REGION,
+       MA_OPT_TURBO,
+       MA_OPT_SSTATE,
+       MA_OPT_SSLOT,
+       MA_OPT_GAMMA,
+       MA_MAIN_RESUME_GAME,
+       MA_MAIN_SAVE_STATE,
+       MA_MAIN_LOAD_STATE,
+       MA_MAIN_RESET_GAME,
+       MA_MAIN_LOAD_ROM,
+       MA_MAIN_CHEATS,
+       MA_MAIN_CREDITS,
+       MA_MAIN_EXIT,
+} menu_id;
+
+void emu_make_path(char *buff, const char *end, int size)
+{
+       int pos, end_len;
+
+       end_len = strlen(end);
+       pos = plat_get_root_dir(buff, size);
+       strncpy(buff + pos, end, size - pos);
+       buff[size - 1] = 0;
+       if (pos + end_len > size - 1)
+               printf("Warning: path truncated: %s\n", buff);
+}
+
+static int emu_check_save_file(int slot, int *time)
+{
+       struct stat status;
+       char *fname;
+       FILE *st;
+       int retval = 0;
+       int ret;
+       
+       fname = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0);
+       st = fopen(fname,"rb");
+       if (st == NULL)
+               goto out;
+       fclose(st);
+
+       retval = 1;
+       if (time == NULL)
+               goto out;
+
+       ret = stat(fname, &status);
+       if (ret != 0)
+               goto out;
+
+       if (status.st_mtime < 1347000000)
+               goto out; // probably bad rtc like on some Caanoos
+
+       *time = status.st_mtime;
+
+out:
+       free(fname);
+       return retval;
+}
+
+static int emu_save_load_game(int load, int unused)
+{
+       if (load)
+               FCEUI_LoadState();
+       else
+               FCEUI_SaveState();
+
+       return 0;
+}
+
+// rrrr rggg gggb bbbb
+static unsigned short fname2color(const char *fname)
+{
+       static const char *rom_exts[]   = { ".zip", ".nes", ".fds", ".unf",
+                                           ".nez", ".unif" };
+       static const char *other_exts[] = { ".nsf", ".ips", ".fcm" };
+       const char *ext = strrchr(fname, '.');
+       int i;
+
+       if (ext == NULL)
+               return 0xffff;
+       for (i = 0; i < array_size(rom_exts); i++)
+               if (strcasecmp(ext, rom_exts[i]) == 0)
+                       return 0xbdff;
+       for (i = 0; i < array_size(other_exts); i++)
+               if (strcasecmp(ext, other_exts[i]) == 0)
+                       return 0xaff5;
+       return 0xffff;
+}
+
+static const char *filter_exts[] = {
+       ".txt", ".srm", ".pnd"
+};
+
+#define MENU_ALIGN_LEFT
+#ifdef __ARM_ARCH_7A__ // assume hires device
+#define MENU_X2 1
+#else
+#define MENU_X2 0
+#endif
+
+#include "../libpicofe/menu.c"
+
+static void draw_savestate_bg(int slot)
+{
+}
+
+static void debug_menu_loop(void)
+{
+}
+
+// ------------ patch/gg menu ------------
+
+extern void *cheats;
+static int cheat_count, cheat_start, cheat_pos;
+
+static int countcallb(char *name, uint32 a, uint8 v, int compare, int s, int type, void *data)
+{
+       cheat_count++;
+       return 1;
+}
+
+static int clistcallb(char *name, uint32 a, uint8 v, int compare, int s, int type, void *data)
+{
+       int pos;
+
+       pos = cheat_start + cheat_pos;
+       cheat_pos++;
+       if (pos < 0) return 1;
+       if (pos >= g_menuscreen_h / me_sfont_h) return 0;
+
+       smalltext_out16(14, pos * me_sfont_h, s ? "ON " : "OFF", 0xffff);
+       smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, type ? "S" : "R", 0xffff);
+       smalltext_out16(14 + me_sfont_w*6, pos * me_sfont_h, name, 0xffff);
+
+       return 1;
+}
+
+static void draw_patchlist(int sel)
+{
+       int pos, max_cnt;
+
+       menu_draw_begin(1, 1);
+
+       max_cnt = g_menuscreen_h / me_sfont_h;
+       cheat_start = max_cnt / 2 - sel;
+       cheat_pos = 0;
+       FCEUI_ListCheats(clistcallb, 0);
+
+       pos = cheat_start + cheat_pos;
+       if (pos < max_cnt)
+               smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
+
+       text_out16(5, max_cnt / 2 * me_sfont_h, ">");
+       menu_draw_end();
+}
+
+void patches_menu_loop(void)
+{
+       static int menu_sel = 0;
+       int inp;
+
+       cheat_count = 0;
+       FCEUI_ListCheats(countcallb, 0);
+
+       for (;;)
+       {
+               draw_patchlist(menu_sel);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
+                               |PBTN_MOK|PBTN_MBACK, NULL, 33);
+               if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = cheat_count; }
+               if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > cheat_count) menu_sel = 0; }
+               if (inp &(PBTN_LEFT|PBTN_L))  { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
+               if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > cheat_count) menu_sel = cheat_count; }
+               if (inp & PBTN_MOK) { // action
+                       if (menu_sel < cheat_count)
+                               FCEUI_ToggleCheat(menu_sel);
+                       else    break;
+               }
+               if (inp & PBTN_MBACK)
+                       break;
+       }
+}
+
+// -------------- key config --------------
+
+// b_turbo,a_turbo  RLDU SEBA
+me_bind_action me_ctrl_actions[] =
+{
+       { "UP     ", NKEY_UP      },
+       { "DOWN   ", NKEY_DOWN    },
+       { "LEFT   ", NKEY_LEFT    },
+       { "RIGHT  ", NKEY_RIGHT   },
+       { "A      ", NKEY_A       },
+       { "B      ", NKEY_B       },
+       { "A TURBO", NKEY_A_TURBO },
+       { "B TURBO", NKEY_B_TURBO },
+       { "START  ", NKEY_START   },
+       { "SELECT ", NKEY_SELECT  },
+       { NULL, 0 }
+};
+
+me_bind_action emuctrl_actions[] =
+{
+       { "Save State       ", EACT_SAVE_STATE },
+       { "Load State       ", EACT_LOAD_STATE },
+       { "Next State Slot  ", EACT_NEXT_SLOT },
+       { "Prev State Slot  ", EACT_PREV_SLOT },
+       { "FDS Insert/Eject ", EACT_FDS_INSERT },
+       { "FDS Select Disk  ", EACT_FDS_SELECT },
+       { "VSUni Insert Coin", EACT_INSERT_COIN },
+       { "Enter Menu       ", EACT_ENTER_MENU },
+       { NULL,                0 }
+};
+
+static int key_config_loop_wrap(int id, int keys)
+{
+       switch (id) {
+               case MA_CTRL_PLAYER1:
+                       key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
+                       break;
+               case MA_CTRL_PLAYER2:
+                       key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
+                       break;
+               case MA_CTRL_EMU:
+                       key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
+                       break;
+               default:
+                       break;
+       }
+       return 0;
+}
+
+static const char *mgn_dev_name(int id, int *offs)
+{
+       const char *name = NULL;
+       static int it = 0;
+
+       if (id == MA_CTRL_DEV_FIRST)
+               it = 0;
+
+       for (; it < IN_MAX_DEVS; it++) {
+               name = in_get_dev_name(it, 1, 1);
+               if (name != NULL)
+                       break;
+       }
+
+       it++;
+       return name;
+}
+
+static const char *mgn_saveloadcfg(int id, int *offs)
+{
+       return "";
+}
+
+static void config_commit(void);
+
+static int mh_savecfg(int id, int keys)
+{
+       const char *fname = NULL;
+       if (id == MA_OPT_SAVECFG_GAME)
+               fname = lastLoadedGameName;
+
+       config_commit();
+       if (SaveConfig(fname) == 0)
+               menu_update_msg("config saved");
+       else
+               menu_update_msg("failed to write config");
+
+       return 1;
+}
+
+static int mh_input_rescan(int id, int keys)
+{
+       //menu_sync_config();
+       in_probe();
+       menu_update_msg("rescan complete.");
+
+       return 0;
+}
+
+static menu_entry e_menu_keyconfig[] =
+{
+       mee_handler_id("Player 1",              MA_CTRL_PLAYER1,    key_config_loop_wrap),
+       mee_handler_id("Player 2",              MA_CTRL_PLAYER2,    key_config_loop_wrap),
+       mee_handler_id("Emulator controls",     MA_CTRL_EMU,        key_config_loop_wrap),
+       mee_label     (""),
+//     mee_range     ("Analog deadzone",   MA_CTRL_DEADZONE,   analog_deadzone, 1, 99),
+       mee_cust_nosave("Save global config",       MA_OPT_SAVECFG,      mh_savecfg, mgn_saveloadcfg),
+       mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
+       mee_handler   ("Rescan devices:",  mh_input_rescan),
+       mee_label     (""),
+       mee_label_mk  (MA_CTRL_DEV_FIRST, mgn_dev_name),
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),
+       mee_end,
+};
+
+static int menu_loop_keyconfig(int id, int keys)
+{
+       static int sel = 0;
+
+       me_loop(e_menu_keyconfig, &sel);
+       return 0;
+}
+
+// --------- FCEU options ----------
+
+extern int ntsccol,ntschue,ntsctint;
+extern int srendlinev[2];
+extern int erendlinev[2];
+extern int eoptions;
+extern char *cpalette;
+extern void LoadCPalette(void);
+
+static menu_entry e_menu_fceu_options[] =
+{
+       //gp2x_text_out15(tl_x,  y,      "Custom palette: %s", cpal);
+       mee_onoff     ("NTSC Color Emulation",      MA_OPT_NTSC_COLOR, ntsccol, 1),
+       mee_range     ("  Tint (default: 56)",      MA_OPT_NTSC_TINT, ntsctint, 0, 128),
+       mee_range     ("  Hue  (default: 72)",      MA_OPT_NTSC_HUE, ntschue, 0, 128),
+       mee_range     ("First visible line (NTSC)", MA_OPT_SREND_N, srendlinev[0], 0, 239),
+       mee_range     ("Last visible line (NTSC)",  MA_OPT_EREND_N, erendlinev[0], 0, 239),
+       mee_range     ("First visible line (PAL)",  MA_OPT_SREND_P, srendlinev[1], 0, 239),
+       mee_range     ("Last visible line (PAL)",   MA_OPT_EREND_P, erendlinev[1], 0, 239),
+       mee_onoff     ("Clip 8 left/right columns", MA_OPT_CLIP, eoptions, EO_CLIPSIDES),
+       mee_onoff     ("Disable 8 sprite limit",    MA_OPT_NO8LIM, eoptions, EO_NO8LIM),
+       mee_onoff     ("Enable authentic GameGenie",MA_OPT_GG, eoptions, EO_GG),
+       mee_end,
+};
+
+static int menu_loop_fceu_options(int id, int keys)
+{
+       static int sel = 0;
+       int i;
+
+       FCEUI_GetNTSCTH(&ntsctint, &ntschue);
+
+       me_loop(e_menu_fceu_options, &sel);
+
+       for(i = 0; i < 2; i++)
+       {
+               if (srendlinev[i] < 0 || srendlinev[i] > 239)
+                       srendlinev[i] = 0;
+               if (erendlinev[i] < srendlinev[i] || erendlinev[i] > 239)
+                       erendlinev[i] = 239;
+       }
+       FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
+       FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
+       FCEUI_DisableSpriteLimitation(eoptions&EO_NO8LIM);
+       FCEUI_SetGameGenie(eoptions&EO_GG);
+       //if (cpalette) LoadCPalette();
+       //else 
+       FCEUI_SetPaletteArray(0); // set to default
+       FCEU_ResetPalette();
+
+       return 0;
+}
+
+// -------------- options --------------
+
+static const char *men_frameskip[] = { "Auto", "0", "1", "2", "3", "4", NULL };
+static const char *men_rates[]   = { "8000", "11025", "16000", "22050", "44100", NULL };
+static const int   men_rates_i[] = {  8000 ,  11025 ,  16000 ,  22050 ,  44100 };
+static const char *men_region[] = { "Auto", "NTSC", "PAL", NULL };
+static const char *men_sstate[] = { "OFF", "writes", "loads", "both", NULL };
+static const char h_renderer[] = "ROM reload required for this\n"
+                                "setting to take effect";
+
+static int sndrate_i;
+static int sndon;
+static int turbo_i;
+
+static void config_commit(void)
+{
+       Settings.sound_rate = men_rates_i[sndrate_i];
+       soundvol = sndon ? 0 : 50;
+       Settings.turbo_rate_add = (turbo_i * 2 << 24) / 60 + 1;
+
+       if (Settings.region_force)
+               FCEUI_SetVidSystem(Settings.region_force - 1);
+}
+
+static menu_entry e_menu_options[] =
+{
+       mee_onoff      ("Show FPS",                MA_OPT_SHOWFPS, Settings.showfps, 1),
+       mee_enum       ("Frameskip",               MA_OPT_FSKIP, Settings.frameskip, men_frameskip),
+       mee_onoff_h    ("Accurate renderer (slow)",MA_OPT_RENDERER, Settings.accurate_mode, 1, h_renderer),
+       mee_onoff      ("Enable sound",            MA_OPT_SOUNDON, sndon, 1),
+       mee_enum       ("Sound Rate",              MA_OPT_SOUNDRATE, sndrate_i, men_rates),
+       mee_enum       ("Region",                  MA_OPT_REGION, Settings.region_force, men_region),
+       mee_range      ("Turbo rate (Hz)",         MA_OPT_TURBO, turbo_i, 1, 30),
+       mee_enum       ("Confirm savestate",       MA_OPT_SSTATE, Settings.sstate_confirm, men_sstate),
+       mee_range      ("Save slot",               MA_OPT_SSLOT, CurrentState, 0, 9),
+       mee_range      ("Gamma correction",        MA_OPT_GAMMA, Settings.gamma, 0, 300),
+       mee_handler    ("[FCE Ultra options]",     menu_loop_fceu_options),
+       mee_cust_nosave("Save global config",      MA_OPT_SAVECFG,      mh_savecfg, mgn_saveloadcfg),
+       mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
+       mee_end,
+};
+
+static int menu_loop_options(int id, int keys)
+{
+       static int sel = 0;
+       int oldrate;
+       int i;
+
+       oldrate = Settings.sound_rate;
+       for (i = 0; i < array_size(men_rates_i); i++) {
+               if (Settings.sound_rate == men_rates_i[i]) {
+                       sndrate_i = i;
+                       break;
+               }
+       }
+       sndon = soundvol != 0;
+       turbo_i = (Settings.turbo_rate_add * 60 / 2) >> 24;
+
+       me_loop(e_menu_options, &sel);
+
+       config_commit();
+       if (oldrate != Settings.sound_rate)
+               InitSound();
+
+       return 0;
+}
+
+// -------------- root menu --------------
+
+static const char credits_text[] = 
+       "GPFCE " REV "\n"
+       "(c) notaz, 2007,2012\n\n"
+       "Based on FCE Ultra versions\n"
+       "0.81 and 0.98.1x\n\n"
+       "         - Credits -\n"
+       "Bero: FCE\n"
+       "Xodnizel: FCE Ultra\n"
+       "FCA author: 6502 core\n";
+
+static void draw_frame_credits(void)
+{
+       smalltext_out16(4, 1, "build: " __DATE__ " " __TIME__ " " REV, 0xe7fc);
+}
+
+static int romsel_run(void)
+{
+       const char *fname;
+
+       fname = menu_loop_romsel(lastLoadedGameName, sizeof(lastLoadedGameName));
+       if (fname == NULL)
+               return -1;
+
+       printf("selected file: %s\n", fname);
+       //keys_load_all(cfg);
+
+       strcpy(lastLoadedGameName, rom_fname_reload);
+       return 0;
+}
+
+static int menu_loop_ret;
+
+static int main_menu_handler(int id, int keys)
+{
+       switch (id)
+       {
+       case MA_MAIN_RESUME_GAME:
+               if (fceugi)
+                       return 1;
+               break;
+       case MA_MAIN_SAVE_STATE:
+               if (fceugi) {
+                       Exit = 0;
+                       return menu_loop_savestate(0);
+               }
+               break;
+       case MA_MAIN_LOAD_STATE:
+               if (fceugi) {
+                       Exit = 0;
+                       return menu_loop_savestate(1);
+               }
+               break;
+       case MA_MAIN_RESET_GAME:
+               if (fceugi) {
+                       FCEU_DoSimpleCommand(FCEUNPCMD_RESET);
+                       Exit = 0;
+                       return 0;
+               }
+               break;
+       case MA_MAIN_LOAD_ROM:
+               if (romsel_run() == 0) {
+                       menu_loop_ret = 2;
+                       return 1;
+               }
+               break;
+       case MA_MAIN_CREDITS:
+               draw_menu_message(credits_text, draw_frame_credits);
+               in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
+               break;
+       case MA_MAIN_EXIT:
+               menu_loop_ret = 1;
+               return 1;
+       default:
+               lprintf("%s: something unknown selected\n", __FUNCTION__);
+               break;
+       }
+
+       return 0;
+}
+
+static menu_entry e_menu_main[] =
+{
+       mee_handler_id("Resume game",        MA_MAIN_RESUME_GAME, main_menu_handler),
+       mee_handler_id("Save State",         MA_MAIN_SAVE_STATE,  main_menu_handler),
+       mee_handler_id("Load State",         MA_MAIN_LOAD_STATE,  main_menu_handler),
+       mee_handler_id("Reset game",         MA_MAIN_RESET_GAME,  main_menu_handler),
+       mee_handler_id("Load ROM",           MA_MAIN_LOAD_ROM,    main_menu_handler),
+       mee_handler   ("Options",            menu_loop_options),
+       mee_handler   ("Controls",           menu_loop_keyconfig),
+       mee_handler_id("Cheats",             MA_MAIN_CHEATS,      main_menu_handler),
+       mee_handler_id("Credits",            MA_MAIN_CREDITS,     main_menu_handler),
+       mee_handler_id("Exit",               MA_MAIN_EXIT,        main_menu_handler),
+       mee_end,
+};
+
+// ----------------------------
+
+int menu_loop(void)
+{
+       static int sel = 0;
+
+       menu_loop_ret = 0;
+
+       me_enable(e_menu_main, MA_MAIN_RESUME_GAME, fceugi != NULL);
+       me_enable(e_menu_main, MA_MAIN_SAVE_STATE,  fceugi != NULL);
+       me_enable(e_menu_main, MA_MAIN_LOAD_STATE,  fceugi != NULL);
+       me_enable(e_menu_main, MA_MAIN_RESET_GAME,  fceugi != NULL);
+       me_enable(e_menu_main, MA_MAIN_CHEATS,      fceugi && cheats);
+
+       plat_video_menu_enter(fceugi != NULL);
+       in_set_config_int(0, IN_CFG_BLOCKING, 1);
+
+       do {
+               me_loop_d(e_menu_main, &sel, NULL, NULL);
+       } while (!fceugi && menu_loop_ret == 0);
+
+       /* wait until menu, ok, back is released */
+       while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
+               ;
+
+       in_set_config_int(0, IN_CFG_BLOCKING, 0);
+       plat_video_menu_leave();
+
+       return menu_loop_ret;
+}
+
+void menu_init(void)
+{
+       char buff[256];
+
+       g_border_style = 1;
+       menu_init_base();
+
+       //menu_load_config(0);
+
+       g_menubg_src_ptr = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
+       g_menubg_ptr = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
+       if (g_menubg_src_ptr == NULL || g_menubg_ptr == NULL) {
+               fprintf(stderr, "OOM\n");
+               exit(1);
+       }
+
+       emu_make_path(buff, "skin/background.png", sizeof(buff));
+       readpng(g_menubg_src_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h);
+}
+
+void menu_update_msg(const char *msg)
+{
+       strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
+       menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
+
+       menu_error_time = plat_get_ticks_ms();
+       lprintf("msg: %s\n", menu_error_msg);
+}
+
diff --git a/drivers/common/menu.h b/drivers/common/menu.h
new file mode 100644 (file)
index 0000000..881f231
--- /dev/null
@@ -0,0 +1,3 @@
+void menu_init(void);
+int  menu_loop(void);
+void menu_update_msg(const char *msg);
diff --git a/drivers/common/platform.h b/drivers/common/platform.h
new file mode 100644 (file)
index 0000000..7135b23
--- /dev/null
@@ -0,0 +1,5 @@
+void platform_init(void);
+void platform_late_init(void);
+void platform_apply_config(void);
+void platform_set_volume(int val); // 0-100
+void platform_finish(void);
similarity index 83%
rename from drivers/gp2x/gp2x.h
rename to drivers/common/settings.h
index b0861a9..536b5e3 100644 (file)
@@ -1,26 +1,21 @@
-#define GP2X_PORT_VERSION "0.4"
-
 typedef struct {
-       // gp2x specific
-       int KeyBinds[32];
-       int JoyBinds[4][32];
        int turbo_rate_add;     // 8.24 int
        int sound_rate;         // in Hz
        int showfps;
-       int scaling;            // unscaled=0, hw_hor, hw_hor_vert, sw_hor
        int frameskip;          // -1 ~ auto, >=0 ~ count
        int sstate_confirm;
        int region_force;       // 0 ~ off, 1 ~ NTSC, 2 ~ PAL
+       int gamma;
+       int accurate_mode;
+       // gp2x specific
+       int KeyBinds[32];
+       int JoyBinds[4][32];
+       int scaling;            // unscaled=0, hw_hor, hw_hor_vert, sw_hor
        int cpuclock;
        int mmuhack;
        int ramtimings;
-       int gamma;
        int perfect_vsync;
-       int accurate_mode;
 } DSETTINGS;
 
 extern DSETTINGS Settings;
 
-void gp2x_opt_setup(void);
-void gp2x_opt_update(void);
-
similarity index 91%
rename from drivers/gp2x/usage.h
rename to drivers/common/usage.h
index 425a907..320fc31 100644 (file)
@@ -23,7 +23,12 @@ void ShowUsage(char *prog)
 printf("\nUsage is as follows:\n%s <options> filename\n\n",prog);
 puts("Options:");
 puts(DriverUsage);
-puts("-cpalette x     Load a custom global palette from file x.\n\
+puts(
+"-sound x        Sound.\n\
+                 0 = Disabled.\n\
+                 Otherwise, x = playback rate.\n\
+-showfps x      Display fps counter if x is nonzero\n\
+-cpalette x     Load a custom global palette from file x.\n\
 -ntsccol x      Emulate an NTSC's TV's colors.\n\
                  0 = Disabled.\n\
                  1 = Enabled.\n\
index 666aee1..b4a38e0 100644 (file)
@@ -18,9 +18,9 @@
 #include <stdio.h>
 
 #include "../../driver.h"
-#include "gp2x.h"
+#include "../common/settings.h"
+#include "../common/throttle.h"
 #include "minimal.h"
-#include "throttle.h"
 
 
 extern int soundvol;
@@ -54,6 +54,11 @@ uint32 GetWriteSound(void)
        return 1024;
 }
 
+void StartSound(void)
+{
+        gp2x_start_sound(Settings.sound_rate, 16, 0);
+}
+
 int KillSound(void)
 {
        //FCEUI_Sound(0);
index 7f4159b..c8b094c 100644 (file)
@@ -22,7 +22,7 @@
 #include "../../video.h"
 
 #include "../common/main.h"
-#include "gp2x.h"
+#include "../common/settings.h"
 #include "minimal.h"
 #include "../libpicofe/fonts.h"
 #include "asmutils.h"
index ab00045..ac8bb92 100644 (file)
@@ -5,7 +5,9 @@
 #include "../../driver.h"
 #include "../common/config.h"
 #include "../common/args.h"
-#include "gp2x.h"
+#include "../common/platform.h"
+#include "../common/settings.h"
+#include "../common/revision.h"
 #include "gp2x-video.h"
 #ifdef NETWORK
 #include "unix-netplay.h"
 #include "cpuctrl.h"
 #include "squidgehack.h"
 
-int GP2X_PORT_REV =
-#include "rev.h"
-;
-
 extern uint8 PAL;
 
-int CLImain(int argc, char *argv[]);
-
-DSETTINGS Settings;
-CFGSTRUCT DriverConfig[]={
-        ACA(Settings.KeyBinds),
-       ACA(Settings.JoyBinds),
-        AC(Settings.turbo_rate_add),
-        AC(Settings.sound_rate),
-       AC(Settings.showfps),
-       AC(Settings.scaling),
-       AC(Settings.frameskip),
-       AC(Settings.sstate_confirm),
-       AC(Settings.region_force),
-       AC(Settings.cpuclock),
-       AC(Settings.mmuhack),
-       AC(Settings.ramtimings),
-       AC(Settings.gamma),
-       AC(Settings.perfect_vsync),
-       AC(Settings.accurate_mode),
-        ENDCFGSTRUCT
-};
-
-
 char *DriverUsage=
-"-joyx   y       Use joystick y as virtual joystick x.\n\
--sound x        Sound.\n\
-                 0 = Disabled.\n\
-                 Otherwise, x = playback rate.\n\
--showfps x      Display fps counter if x is nonzero\n\
--mmuhack x      Enable squidge's MMU hack if x is nonzero (GP2X).\n\
+"-mmuhack x      Enable squidge's MMU hack if x is nonzero (GP2X).\n\
 -ramtimings x   Enable RAM overclocking if x is nonzero (GP2X).\n\
-"
-#ifdef NETWORK
-"-connect s      Connect to server 's' for TCP/IP network play.\n\
--server         Be a host/server for TCP/IP network play.\n\
--netport x      Use TCP/IP port x for network play."
-#endif
-;
+";
 
-#ifdef NETWORK
-static int docheckie[2]={0,0};
-#endif
 ARGPSTRUCT DriverArgs[]={
-         {"-sound",0,&Settings.sound_rate,0},
-         {"-showfps",0,&Settings.showfps,0},
          {"-mmuhack",0,&Settings.mmuhack,0},
          {"-ramtimings",0,&Settings.ramtimings,0},
          {"-menu",0,&ext_menu,0x4001},
          {"-menustate",0,&ext_state,0x4001},
-        #ifdef NETWORK
-         {"-connect",&docheckie[0],&netplayhost,0x4001},
-         {"-server",&docheckie[1],0,0},
-         {"-netport",0,&Port,0},
-        #endif
          {0,0,0,0}
 };
 
-
-
 void GetBaseDirectory(char *BaseDirectory)
 {
  strcpy(BaseDirectory, "fceultra");
@@ -113,29 +65,15 @@ static void SetDefaults(void)
 
 void DoDriverArgs(void)
 {
-       #ifdef NETWORK
-        if(docheckie[0])
-         netplay=2;
-        else if(docheckie[1])
-         netplay=1;
-
-        if(netplay)
-         FCEUI_SetNetworkPlay(netplay);
-       #endif
 }
 
 
-char **g_argv;
 int mmuhack_status = 0;
 
 
-// TODO: cleanup
-int main(int argc, char *argv[])
+void platform_init(void)
 {
-       int ret;
-       g_argv = argv;
-
-        printf("Starting GPFCE - Port version " GP2X_PORT_VERSION " r%i (" __DATE__ ")\n", GP2X_PORT_REV);
+        printf("Starting GPFCE " REV " (" __DATE__ ")\n");
         puts("Based on FCE Ultra "VERSION_STRING" and 0.98.1x versions");
         puts("Original port by Zheng Zhu");
         puts("Menu/optimization/misc work by notaz\n");
@@ -144,9 +82,10 @@ int main(int argc, char *argv[])
        cpuctrl_init();
 
         SetDefaults();
+}
 
-        ret = CLImain(argc,argv);
-
+void platform_finish(void)
+{
         // unscale the screen, in case it is bad.
         gp2x_video_RGB_setscaling(320, 240);
 
@@ -160,9 +99,13 @@ int main(int argc, char *argv[])
         return(ret?0:-1);
 }
 
+void platform_set_volume(int val) // 0-100
+{
+       platform_set_volume(val, val);
+}
 
 /* optional GP2X stuff to be done after config is loaded */
-void gp2x_opt_setup(void)
+void platform_late_init(void)
 {
        if (Settings.mmuhack) {
                int ret = mmuhack();
@@ -178,7 +121,7 @@ void gp2x_opt_setup(void)
        }
 }
 
-void gp2x_opt_update(void)
+void platform_apply_config(void)
 {
        static int prev_cpuclock = 200, prev_gamma = 100, prev_vsync = 0, prev_pal = 0;
        if (Settings.cpuclock != 0 && Settings.cpuclock != prev_cpuclock)
@@ -206,6 +149,14 @@ void gp2x_opt_update(void)
                }
                prev_vsync = Settings.perfect_vsync;
        }
+
+       gp2x_video_changemode(Settings.scaling == 3 ? 15 : 8);
+       switch (Settings.scaling & 3) {
+               case 0: gp2x_video_set_offs(0);  gp2x_video_RGB_setscaling(320, 240); break;
+               case 1: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(256, 240); break;
+               case 2: gp2x_video_set_offs(32+srendline*320); gp2x_video_RGB_setscaling(256, erendline-srendline); break;
+               case 3: gp2x_video_set_offs(32); gp2x_video_RGB_setscaling(320, 240); break;
+       }
 }
 
 
index c572598..5a5f55e 100644 (file)
@@ -1,6 +1,6 @@
 #include <sys/time.h>
+#include "../common/settings.h"
 #include "main.h"
-#include "gp2x.h"
 #include "minimal.h"
 #include "throttle.h"
 
diff --git a/drivers/sdl/sdl.c b/drivers/sdl/sdl.c
new file mode 100644 (file)
index 0000000..db4d5c1
--- /dev/null
@@ -0,0 +1,93 @@
+#include <SDL.h>
+#include "../common/platform.h"
+#include "../common/args.h"
+#include "../common/settings.h"
+#include "../common/input.h"
+#include "../libpicofe/menu.h"
+#include "../libpicofe/input.h"
+#include "../libpicofe/in_sdl.h"
+
+static const struct in_default_bind in_sdl_defbinds[] = {
+  { SDLK_UP,     IN_BINDTYPE_PLAYER12, NKEYB_UP },
+  { SDLK_DOWN,   IN_BINDTYPE_PLAYER12, NKEYB_DOWN },
+  { SDLK_LEFT,   IN_BINDTYPE_PLAYER12, NKEYB_LEFT },
+  { SDLK_RIGHT,  IN_BINDTYPE_PLAYER12, NKEYB_RIGHT },
+  { SDLK_z,      IN_BINDTYPE_PLAYER12, NKEYB_B },
+  { SDLK_x,      IN_BINDTYPE_PLAYER12, NKEYB_A },
+  { SDLK_a,      IN_BINDTYPE_PLAYER12, NKEYB_B_TURBO },
+  { SDLK_s,      IN_BINDTYPE_PLAYER12, NKEYB_A_TURBO },
+  { SDLK_ESCAPE, IN_BINDTYPE_EMU, EACTB_ENTER_MENU },
+  { 0, 0, 0 }
+};
+
+SDL_Surface *screen;
+
+void platform_init(void)
+{
+       memset(&Settings, 0, sizeof(Settings));
+       Settings.frameskip = -1; // auto
+       Settings.sound_rate = 44100;
+       Settings.turbo_rate_add = (8*2 << 24) / 60 + 1; // 8Hz turbofire
+       Settings.gamma = 100;
+       Settings.sstate_confirm = 1;
+
+       g_menuscreen_w = 320;
+       g_menuscreen_h = 240;
+
+       // tmp
+       {
+               extern void gp2x_init();
+               gp2x_init();
+       }
+}
+
+void platform_late_init(void)
+{
+       in_sdl_init(in_sdl_defbinds);
+}
+
+void platform_apply_config(void)
+{
+}
+
+void platform_set_volume(int val)
+{
+}
+
+void platform_finish(void)
+{
+}
+
+void plat_video_menu_enter(int is_rom_loaded)
+{
+       screen = SDL_SetVideoMode(320, 240, 16, 0);
+}
+
+void plat_video_menu_begin(void)
+{
+       g_menuscreen_ptr = screen->pixels;
+}
+
+void plat_video_menu_end(void)
+{
+       SDL_Flip(screen);
+}
+
+void plat_video_menu_leave(void)
+{
+}
+
+char *DriverUsage="";
+
+ARGPSTRUCT DriverArgs[]={
+         {0,0,0,0}
+};
+
+void DoDriverArgs(void)
+{
+}
+
+void GetBaseDirectory(char *BaseDirectory)
+{
+ strcpy(BaseDirectory, "fceultra");
+}
similarity index 95%
rename from drivers/gp2x_test/throttle.c
rename to drivers/sdl/throttle.c
index 4a6d699..5272226 100644 (file)
@@ -2,8 +2,8 @@
 #include <unistd.h>
 
 #include "../common/main.h"
-#include "../gp2x/gp2x.h"
-#include "../gp2x/throttle.h"
+#include "../common/throttle.h"
+#include "../common/settings.h"
 
 
 extern uint8 PAL;
diff --git a/input.h b/input.h
index 7c0da59..14586d0 100644 (file)
--- a/input.h
+++ b/input.h
@@ -38,3 +38,4 @@ void FCEUI_VSUniCoin(void);
 void FCEUI_ResetNES(void);
 void FCEUI_PowerNES(void);
 
+extern char lastLoadedGameName [2048];