drc: inv: fix ram ofset and mirror handling
[pcsx_rearmed.git] / maemo / main.c
index 267fb55..4531704 100644 (file)
@@ -7,38 +7,33 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <stdarg.h>
-#include <dlfcn.h>
-#include <sys/stat.h>
-#include <sys/types.h>
+#include <stdint.h>
 #include <unistd.h>
-#include <signal.h>
 
 #include "main.h"
+#include "menu.h"
 #include "plugin.h"
+#include "plugin_lib.h"
 #include "../libpcsxcore/misc.h"
-#include "../plugins/cdrcimg/cdrcimg.h"
-
-// from softgpu plugin
-extern int iUseDither;
-extern int UseFrameSkip;
-extern int UseFrameLimit;
-extern uint32_t dwActFixes;
-extern float fFrameRateHz;
-extern int dwFrameRateTicks;
+#include "../libpcsxcore/new_dynarec/new_dynarec.h"
+#include "../plugins/dfinput/main.h"
+#include "maemo_common.h"
 
 // sound plugin
-extern int iUseReverb;
-extern int iUseInterpolation;
-extern int iXAPitch;
-extern int iSPUIRQWait;
 extern int iUseTimer;
 
+int g_opts = OPT_SHOWFPS;
+int g_maemo_opts;
+char file_name[MAXPATHLEN];
+
+enum sched_action emu_action;
+void do_emu_action(void);
+
 static void ChangeWorkingDirectory(char *exe)
 {
-       s8 exepath[1024];
-       s8* s;
-       sprintf(exepath, "%s", exe);
+       char exepath[1024];
+       char *s;
+       snprintf(exepath, sizeof(exepath), "%s", exe);
        s = strrchr(exepath, '/');
        if (s != NULL) {
                *s = '\0';
@@ -53,7 +48,6 @@ int maemo_main(int argc, char **argv)
        char path[MAXPATHLEN];
        const char *cdfile = NULL;
        int loadst = 0;
-       void *tmp;
        int i;
 
        strcpy(Config.BiosDir, "/home/user/MyDocs");
@@ -67,7 +61,6 @@ int maemo_main(int argc, char **argv)
                else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
                else if (!strcmp(argv[i], "-cdfile")) {
                        char isofilename[MAXPATHLEN];
-
                        if (i+1 >= argc) break;
                        strncpy(isofilename, argv[++i], MAXPATHLEN);
                        if (isofilename[0] != '/') {
@@ -79,73 +72,40 @@ int maemo_main(int argc, char **argv)
                                } else
                                        isofilename[0] = 0;
                        }
-
                        cdfile = isofilename;
                }
-               else if (!strcmp(argv[i],"-frameskip")){
-               
-               int tv_reg=atol(argv[++i]);
-               if (tv_reg>0){
-               UseFrameSkip=1;
-               fFrameRateHz = (tv_reg==1)?50.0f:  59.94f;
-               dwFrameRateTicks = (100000*100 / (unsigned long)(fFrameRateHz*100));
-               }
-               }
-               else if (!strcmp(argv[i],"-sputhreaded")){
-                       iUseTimer=1;
-               }
-               else if (!strcmp(argv[i],"-nosound")){
-                               strcpy(Config.Spu, "spunull.so");
-               }
-               else if(!strcmp(argv[i], "-bdir"))      sprintf(Config.BiosDir, "%s", argv[++i]);
-               else if(!strcmp(argv[i], "-bios"))      sprintf(Config.Bios, "%s", argv[++i]);
-               else if (!strcmp(argv[i],"-gles")){
-               strcpy(Config.Gpu, "gpuGLES.so");
+               else if (!strcmp(argv[i],"-frameskip")) {
+                       int tv_reg = atol(argv[++i]);
+                       if (tv_reg > 0)
+                               pl_rearmed_cbs.frameskip = -1;
                }
+               else if (!strcmp(argv[i],"-fullscreen"))                g_maemo_opts |= 2;
+               else if (!strcmp(argv[i],"-accel"))                             g_maemo_opts |= 4;
+               else if (!strcmp(argv[i],"-sputhreaded"))               iUseTimer=1;
+               else if (!strcmp(argv[i],"-nosound"))           strcpy(Config.Spu, "spunull.so");
+               else if (!strcmp(argv[i], "-bdir"))                     sprintf(Config.BiosDir, "%s", argv[++i]);
+               else if (!strcmp(argv[i], "-bios"))                     sprintf(Config.Bios, "%s", argv[++i]);
+               else if (!strcmp(argv[i], "-gles"))                     strcpy(Config.Gpu, "gpuGLES.so");
                else if (!strcmp(argv[i], "-cdda"))             Config.Cdda = 1;
                else if (!strcmp(argv[i], "-xa"))               Config.Xa = 1;
                else if (!strcmp(argv[i], "-rcnt"))             Config.RCntFix = 1 ;
                else if (!strcmp(argv[i], "-sio"))              Config.Sio = 1;
                else if (!strcmp(argv[i], "-spuirq"))   Config.SpuIrq = 1;
                else if (!strcmp(argv[i], "-vsync"))    Config.VSyncWA = 1;
-               else if (!strcmp(argv[i], "-h") ||
-                        !strcmp(argv[i], "-help") ||
-                        !strcmp(argv[i], "--help")) {
-                        printf(PACKAGE_NAME " " PACKAGE_VERSION "\n");
-                        printf("%s\n", _(
-                                                       " pcsx [options] [file]\n"
-                                                       "\toptions:\n"
-                                                       "\t-cdfile FILE\tRuns a CD image file\n"
-                                                       "\t-psxout\t\tEnable PSX output\n"
-                                                       "\t-nosound\t\tDisable sound using spunull plugin\n"
-                                                       "\t-sputhreaded\t\tMove sound to separate thread\n"
-                                                       "\t-frameskip\t\tEnable frameskip\n"
-                                                       "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
-                                                       "\t-h -help\tDisplay this message\n"
-                                                       "\tfile\t\tLoads file\n"));
-                        return 0;
-               } else {
-                       strncpy(file, argv[i], MAXPATHLEN);
-                       if (file[0] != '/') {
-                               getcwd(path, MAXPATHLEN);
-                               if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
-                                       strcat(path, "/");
-                                       strcat(path, file);
-                                       strcpy(file, path);
-                               } else
-                                       file[0] = 0;
-                       }
-               }
        }
 
        hildon_init(&argc, &argv);
        
-       if (cdfile)
+       if (cdfile) {
                set_cd_image(cdfile);
+               strcpy(file_name, strrchr(cdfile,'/'));
+       }
 
        if (SysInit() == -1)
                return 1;
 
+       pl_init();
+
        if (LoadPlugins() == -1) {
                SysMessage("Failed loading plugins!");
                return 1;
@@ -173,24 +133,37 @@ int maemo_main(int argc, char **argv)
                }
        }
 
+       if (!ready_to_go) {
+               printf ("something goes wrong, maybe you forgot -cdfile ? \n");
+               return 1;
+       }
+
        // If a state has been specified, then load that
        if (loadst) {
-               char state_filename[MAXPATHLEN];
-               int ret = get_state_filename(state_filename, sizeof(state_filename), loadst - 1);
-               if (ret == 0)
-                       ret = LoadState(state_filename);
-               printf("%s state %s\n", ret ? "failed to load" : "loaded", state_filename);
+               int ret = emu_load_state(loadst - 1);
+               printf("%s state %d\n", ret ? "failed to load" : "loaded", loadst);
        }
 
-       if (ready_to_go)
-               maemo_init();
-       else
-       {
-               printf ("somethings goes wrong, maybe you forgot -cdfile ? \n");
-               return 0;
+       maemo_init(&argc, &argv);
+
+       if (GPU_open != NULL) {
+               int ret = GPU_open(&gpuDisp, "PCSX", NULL);
+               if (ret)
+                       fprintf(stderr, "Warning: GPU_open returned %d\n", ret);
        }
 
-       psxCpu->Execute();
+       dfinput_activate();
+       pl_timing_prepare(Config.PsxType);
+
+       while (1)
+       {
+               stop = 0;
+               emu_action = SACTION_NONE;
+
+               psxCpu->Execute();
+               if (emu_action != SACTION_NONE)
+                       do_emu_action();
+       }
 
        return 0;
 }