e5faacfe9a97e6f75a5fea775c4f0f64a4a5a8f8
[pcsx_rearmed.git] / maemo / main.c
1 /*
2  * (C) notaz, 2010-2011
3  *
4  * This work is licensed under the terms of the GNU GPLv2 or later.
5  * See the COPYING file in the top-level directory.
6  */
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdint.h>
11 #include <unistd.h>
12
13 #include "main.h"
14 #include "menu.h"
15 #include "plugin.h"
16 #include "plugin_lib.h"
17 #include "../libpcsxcore/misc.h"
18 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
19
20 // sound plugin
21 extern int iUseReverb;
22 extern int iUseInterpolation;
23 extern int iSPUIRQWait;
24 extern int iUseTimer;
25
26 int g_opts = OPT_SHOWFPS;
27
28 enum sched_action emu_action;
29 void do_emu_action(void);
30 char* file_name;
31
32 static void ChangeWorkingDirectory(char *exe)
33 {
34         char exepath[1024];
35         char *s;
36         snprintf(exepath, sizeof(exepath), "%s", exe);
37         s = strrchr(exepath, '/');
38         if (s != NULL) {
39                 *s = '\0';
40                 chdir(exepath);
41         }
42 }
43
44 int maemo_main(int argc, char **argv)
45 {
46         ChangeWorkingDirectory("c");
47         char file[MAXPATHLEN] = "";
48         char path[MAXPATHLEN];
49         const char *cdfile = NULL;
50         int loadst = 0;
51         int i;
52
53         strcpy(Config.BiosDir, "/home/user/MyDocs");
54         strcpy(Config.PluginsDir, "/opt/maemo/usr/games/plugins");
55         snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "/opt/maemo/usr/games" PATCHES_DIR);
56         Config.PsxAuto = 1;
57         
58         // read command line options
59         for (i = 1; i < argc; i++) {
60                      if (!strcmp(argv[i], "-psxout")) Config.PsxOut = 1;
61                 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
62                 else if (!strcmp(argv[i], "-cdfile")) {
63                         char isofilename[MAXPATHLEN];
64                         if (i+1 >= argc) break;
65                         strncpy(isofilename, argv[++i], MAXPATHLEN);
66                         if (isofilename[0] != '/') {
67                                 getcwd(path, MAXPATHLEN);
68                                 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
69                                         strcat(path, "/");
70                                         strcat(path, isofilename);
71                                         strcpy(isofilename, path);
72                                 } else
73                                         isofilename[0] = 0;
74                         }
75                         cdfile = isofilename;
76                 }
77                 else if (!strcmp(argv[i],"-frameskip")) {
78                         int tv_reg = atol(argv[++i]);
79                         if (tv_reg > 0)
80                                 pl_rearmed_cbs.frameskip = -1;
81                 }
82                 else if (!strcmp(argv[i],"-fullscreen"))                g_opts |= 2;
83                 else if (!strcmp(argv[i],"-accel"))                             g_opts |= 4;
84                 else if (!strcmp(argv[i],"-sputhreaded"))               iUseTimer=1;
85                 else if (!strcmp(argv[i],"-nosound"))           strcpy(Config.Spu, "spunull.so");
86                 /* unworking with r10
87                 else if(!strcmp(argv[i], "-bdir"))                      sprintf(Config.BiosDir, "%s", argv[++i]);
88                 else if(!strcmp(argv[i], "-bios"))                      sprintf(Config.Bios, "%s", argv[++i]);
89                 else if (!strcmp(argv[i],"-gles"))                      strcpy(Config.Gpu, "gpuGLES.so");
90                 */
91                 else if (!strcmp(argv[i], "-cdda"))             Config.Cdda = 1;
92                 else if (!strcmp(argv[i], "-xa"))               Config.Xa = 1;
93                 else if (!strcmp(argv[i], "-rcnt"))             Config.RCntFix = 1 ;
94                 else if (!strcmp(argv[i], "-sio"))              Config.Sio = 1;
95                 else if (!strcmp(argv[i], "-spuirq"))   Config.SpuIrq = 1;
96                 else if (!strcmp(argv[i], "-vsync"))    Config.VSyncWA = 1;
97         }
98
99         pl_rearmed_cbs.gpu_peops.dwActFixes = 1<<7;
100         iUseReverb = 2;
101         iUseInterpolation = 1;
102         iSPUIRQWait = 1;
103         iUseTimer = 2;
104
105         in_type1 = PSE_PAD_TYPE_STANDARD;
106         in_type2 = PSE_PAD_TYPE_STANDARD;
107
108         hildon_init(&argc, &argv);
109         
110         char f_name[MAXPATHLEN];
111         strcpy(f_name, strrchr(cdfile,'/'));
112         file_name=f_name;
113
114         if (cdfile)
115                 set_cd_image(cdfile);
116
117         if (SysInit() == -1)
118                 return 1;
119
120         pl_init();
121
122         if (LoadPlugins() == -1) {
123                 SysMessage("Failed loading plugins!");
124                 return 1;
125         }
126
127         if (OpenPlugins() == -1) {
128                 return 1;
129         }
130         plugin_call_rearmed_cbs();
131
132         CheckCdrom();
133         SysReset();
134
135         if (file[0] != '\0') {
136                 if (Load(file) != -1)
137                         ready_to_go = 1;
138         } else {
139                 if (cdfile) {
140                         if (LoadCdrom() == -1) {
141                                 ClosePlugins();
142                                 printf(_("Could not load CD-ROM!\n"));
143                                 return -1;
144                         }
145                         ready_to_go = 1;
146                 }
147         }
148
149         // If a state has been specified, then load that
150         if (loadst) {
151                 int ret = emu_load_state(loadst - 1);
152                 printf("%s state %d\n", ret ? "failed to load" : "loaded", loadst);
153         }
154
155         if (ready_to_go)
156                 maemo_init();
157         else
158         {
159                 printf ("somethings goes wrong, maybe you forgot -cdfile ? \n");
160                 return 0;
161         }
162
163         pl_timing_prepare(Config.PsxType);
164
165         while (1)
166         {
167                 stop = 0;
168                 emu_action = SACTION_NONE;
169
170                 psxCpu->Execute();
171                 if (emu_action != SACTION_NONE)
172                         do_emu_action();
173         }
174
175         return 0;
176 }
177