psxinterpreter: use cycle_multiplier also
[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 "../frontend/main.h"
14 #include "../frontend/menu.h"
15 #include "../frontend/plugin.h"
16 #include "../frontend/plugin_lib.h"
17 #include "../libpcsxcore/misc.h"
18 #include "../libpcsxcore/cdriso.h"
19 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
20 #include "../plugins/dfinput/main.h"
21 #include "../plugins/dfsound/spu_config.h"
22 #include "maemo_common.h"
23
24 extern int in_enable_vibration;
25 extern int in_type1, in_type2;
26
27 accel_option accelOptions;
28 int ready_to_go, g_emu_want_quit, g_emu_resetting;
29 int g_menuscreen_w, g_menuscreen_h;
30 int g_scaler, soft_filter;
31 int g_opts = 0;
32 int g_maemo_opts;
33 int cornerActions[4] = {0,0,0,0};
34 int bKeepDisplayOn = FALSE;
35 int bAutosaveOnExit = FALSE;
36 char file_name[MAXPATHLEN];
37 char keys_config_file[MAXPATHLEN] = "/opt/psx4m/keys";
38
39 enum sched_action emu_action;
40 void do_emu_action(void);
41
42 static void ChangeWorkingDirectory(char *exe)
43 {
44         char exepath[1024];
45         char *s;
46         snprintf(exepath, sizeof(exepath), "%s", exe);
47         s = strrchr(exepath, '/');
48         if (s != NULL) {
49                 *s = '\0';
50                 chdir(exepath);
51         }
52 }
53
54 void PrintHelp()
55 {
56         printf("PCSX-ReARMed version %s for Maemo\n\n", PACKAGE_VERSION);
57
58         printf("Usage:\n");
59         printf("  pcsx [options] -cdfile FILE\n\n");
60
61         printf("Options:\n");
62         printf("  -help          : This help\n");
63         printf("  -disc VALUE    : Disc number for multi discs images\n");
64         printf("  -fullscreen    : Run fullscreen\n");
65         printf("  -frameskip     : Frameskip\n");
66         printf("                   -1=Auto (Default)\n");
67         printf("                    0=Disabled\n");
68         printf("                    1=Set to 1\n");
69         printf("                    ...\n");
70         printf("  -autosave      : Enable auto save on exit\n");
71         printf("  -accel         : Enable accelerometer\n");
72         printf("  -analog        : Use analog pad for accel\n");
73         printf("  -vibration     : Activate vibration\n");
74         printf("  -sens VALUE    : Set accelerometer sens [0-1000]\n");
75     printf("                   (Default 150)\n");
76         printf("  -ydef VALUE    : Set accelerometer y zero [0-1000]\n");
77     printf("                   (Default 500)\n");
78         printf("  -max VALUE     : Set accelerometer max value[0-1000]\n");
79     printf("                   (Default 500)\n");
80         printf("  -nosound       : No sound output\n");
81         printf("  -bdir PATH     : Set the bios path\n");
82         printf("  -pdir PATH     : Set the plugins path\n");
83         printf("  -bios          : Set the bios\n");
84         printf("  -cdda          : Disable CD Audio for a performance boost\n");
85         printf("  -xa            : Disables XA sound, which can sometimes\n");
86         printf("                   improve performance\n");
87         printf("  -sio           : SIO IRQ Always Enabled\n");
88         printf("  -spuirq        : SPU IRQ Always Enabled\n");
89         printf("  -fps           : Show fps\n");
90         printf("  -cpu           : Show CPU load\n");
91         printf("  -spu           : Show SPU channels\n");
92         printf("  -nofl          : Disable Frame Limiter\n");
93         printf("  -mcd1 FILE     : Set memory card 1 file\n");
94         printf("  -mcd2 FILE     : Set memory card 2 file\n");
95         printf("  -region VALUE  : Set PSX region\n");
96         printf("                   -1=Auto (Default)\n");
97         printf("                    0=NTSC\n");
98         printf("                    1=PAL\n");
99         printf("  -cpuclock VALUE: PSX CPU clock %% [1-500]\n");
100     printf("                   (Default 50)\n");
101         printf("  -displayon     : Prevent display from blanking\n");
102     printf("                   (Default disabled)\n");
103         printf("  -keys FILE     : File with keys configuration\n");
104     printf("                   (Default /opt/psx4m/keys)\n");
105         printf("  -corners VALUE : Define actions for click on the\n");
106     printf("                   display corners\n");
107     printf("                   VALUE is a four digit number, each number\n");
108     printf("                   represent a corner (topleft, topright,\n");
109     printf("                   bottomright and bottomleft\n");
110     printf("                   Actions:\n");
111     printf("                   0=No action\n");
112     printf("                   1=Save\n");
113     printf("                   2=Load\n");
114     printf("                   3=Change slot (+1)\n");
115     printf("                   4=Change slot (-1)\n");
116     printf("                   5=Quit\n");
117         printf("  -guncon        : Set the controller to guncon\n");
118         printf("  -gunnotrigger  : Don't trigger (shoot) when touching screen\n");
119     printf("                   0=Auto (Default)\n");
120     printf("                   1=On\n");
121     printf("                   2=Off\n");
122
123
124         printf("\nGPU Options:\n");
125         printf("  -gles          : Use the GLES plugin (gpu_gles.so)\n");
126         printf("  -oldgpu        : Use the peops plugin (gpu_peops.so)\n");
127         printf("  -unai          : Use the unai plugin (gpu_unai.so)\n");
128
129         printf("\nSound Options:\n");
130         printf("  -spu_reverb VALUE        : Enable/disable reverb [0/1]\n");
131     printf("                             (Default disabled)\n");
132         printf("  -spu_interpolation VALUE : Set interpolation mode\n");
133         printf("                             0=None (Default)\n");
134     printf("                             1=Simple\n");
135         printf("                             2=Gaussian\n");
136         printf("                             3=Cubic\n");
137
138         printf("\nNeon Options (default GPU):\n");
139         printf("  -enhance       : Enable graphic enhancement\n");
140
141         printf("\nGles Options:\n");
142         printf("  -gles_dithering VALUE : Enable/disable dithering [0/1]\n");
143     printf("                          (Default disabled)\n");
144         printf("  -gles_mask VALUE      : Enable/disable mask detect [0/1]\n");
145     printf("                          (Default disabled)\n");
146         printf("  -gles_filtering VALUE : Texture Filtering\n");
147         printf("                          0=None (Default)\n");
148         printf("                          1=Standard\n");
149         printf("                          2=Extended\n");
150         printf("                          3=Standard-sprites\n");
151         printf("                          4=Extended-sprites\n");
152         printf("                          5=Standard+sprites\n");
153         printf("                          6=Extended+sprites\n");
154         printf("  -gles_fbtex VALUE     : Framebuffer Textures\n");
155         printf("                          0=Emulated VRam (Default)\n");
156         printf("                          1=Black\n");
157         printf("                          2=Card\n");
158         printf("                          3=Card+soft\n");
159         printf("  -gles_vram VALUE      : Texture RAM size in MB [4-128]\n");
160     printf("                          (Default 64)\n");
161     printf("  -gles_fastmdec VALUE  : Enable/disable Fast Mdec [0/1]\n");
162     printf("                          (Default disabled)\n");
163     printf("  -gles_advblend VALUE  : Enable/disable Adv. Blend [0/1]\n");
164     printf("                          (Default disabled)\n");
165     printf("  -gles_opaque VALUE    : Enable/disable Opaque Pass [0/1]\n");
166     printf("                          (Default disabled)\n");
167 }
168
169 int main(int argc, char **argv)
170 {
171         if (argc == 1 || (argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-help") || !strcmp(argv[1], "-h")))) {
172                 PrintHelp();
173                 return 0;
174         }
175
176         emu_core_preinit();
177         ChangeWorkingDirectory("c");
178         char file[MAXPATHLEN] = "";
179         char path[MAXPATHLEN];
180         const char *cdfile = NULL;
181         int loadst = 0;
182         int i;
183         int getst = -1;
184         int discNumber = 0;
185
186         g_menuscreen_w = 800;
187         g_menuscreen_h = 480;
188
189         strcpy(Config.Gpu, "builtin_gpu");
190         strcpy(Config.Spu, "builtin_spu");
191         strcpy(Config.BiosDir, "/home/user/MyDocs");
192         strcpy(Config.PluginsDir, "/opt/maemo/usr/games/plugins");
193         snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "/opt/maemo/usr/games" PATCHES_DIR);
194         Config.PsxAuto = 1;
195         pl_rearmed_cbs.frameskip = -1;
196         strcpy(Config.Bios, "HLE");
197         spu_config.iUseReverb = 1;
198         spu_config.iUseInterpolation = 1;
199         in_type1 = PSE_PAD_TYPE_STANDARD;
200         in_type2 = PSE_PAD_TYPE_STANDARD;
201
202         accelOptions.sens     = 150;
203         accelOptions.y_def        = 500;
204         accelOptions.maxValue = 500.0;
205
206         // read command line options
207         for (i = 1; i < argc; i++) {
208                      if (!strcmp(argv[i], "-psxout")) Config.PsxOut = 1;
209                 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
210                 else if (!strcmp(argv[i], "-cdfile")) {
211                         char isofilename[MAXPATHLEN];
212                         if (i+1 >= argc) break;
213                         strncpy(isofilename, argv[++i], MAXPATHLEN);
214                         if (isofilename[0] != '/') {
215                                 getcwd(path, MAXPATHLEN);
216                                 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
217                                         strcat(path, "/");
218                                         strcat(path, isofilename);
219                                         strcpy(isofilename, path);
220                                 } else
221                                         isofilename[0] = 0;
222                         }
223                         cdfile = isofilename;
224                 }
225                 else if (!strcmp(argv[i],"-frameskip")) {
226                         int tv_reg = atol(argv[++i]);
227                         if (tv_reg < -1)
228                                 pl_rearmed_cbs.frameskip = -1;
229                         else
230                                 pl_rearmed_cbs.frameskip = tv_reg;
231                 }
232                 else if (!strcmp(argv[i],"-region")) {
233                         int psx_reg = atol(argv[++i]);
234                         if (psx_reg == 0 || psx_reg == 1){
235                                 Config.PsxAuto = 0;
236                                 Config.PsxType = psx_reg;
237                         }
238                 }
239
240                 else if (!strcmp(argv[i],"-get_sstatename")) getst = atol(argv[++i]);
241
242                 else if (!strcmp(argv[i], "-fullscreen"))               g_maemo_opts |= 2;
243                 else if (!strcmp(argv[i], "-accel"))                            g_maemo_opts |= 4;
244                 else if (!strcmp(argv[i], "-nosound"))                  strcpy(Config.Spu, "spunull.so");
245                 else if (!strcmp(argv[i], "-bdir"))                     sprintf(Config.BiosDir, "%s", argv[++i]);
246                 else if (!strcmp(argv[i], "-pdir"))                             sprintf(Config.PluginsDir, "%s", argv[++i]);
247                 else if (!strcmp(argv[i], "-bios"))                     sprintf(Config.Bios, "%s", argv[++i]);
248                 else if (!strcmp(argv[i], "-gles"))                             { strcpy(Config.Gpu, "gpu_gles.so"); g_maemo_opts |= 8 ;}
249                 else if (!strcmp(argv[i], "-oldgpu"))                   strcpy(Config.Gpu, "gpu_peops.so");
250                 else if (!strcmp(argv[i], "-unai"))                         strcpy(Config.Gpu, "gpu_unai.so");
251                 else if (!strcmp(argv[i], "-cdda"))             Config.Cdda = 1;
252                 else if (!strcmp(argv[i], "-xa"))               Config.Xa = 1;
253                 else if (!strcmp(argv[i], "-fps"))                          g_opts |=OPT_SHOWFPS;
254                 else if (!strcmp(argv[i], "-cpu"))                          g_opts |=OPT_SHOWCPU;
255                 else if (!strcmp(argv[i], "-spu"))                          g_opts |=OPT_SHOWSPU;
256                 else if (!strcmp(argv[i], "-nofl"))                     g_opts |=OPT_NO_FRAMELIM;
257                 else if (!strcmp(argv[i], "-mcd1"))                 sprintf(Config.Mcd1, "%s", argv[++i]);
258                 else if (!strcmp(argv[i], "-mcd2"))                 sprintf(Config.Mcd2, "%s", argv[++i]);
259
260                 else if (!strcmp(argv[i], "-cpuclock"))                 Config.cycle_multiplier = 10000 / atol(argv[++i]);
261                 else if (!strcmp(argv[i], "-guncon"))               in_type1 = PSE_PAD_TYPE_GUNCON;
262                 else if (!strcmp(argv[i], "-gunnotrigger"))             g_opts |= OPT_TSGUN_NOTRIGGER;
263                 else if (!strcmp(argv[i], "-analog"))               in_type1 = PSE_PAD_TYPE_ANALOGPAD;
264                 else if (!strcmp(argv[i], "-vibration"))                { in_type1 = PSE_PAD_TYPE_ANALOGPAD; in_enable_vibration = 1; }
265                 else if (!strcmp(argv[i], "-sens"))                             accelOptions.sens = atol(argv[++i]);
266                 else if (!strcmp(argv[i], "-ydef"))                             accelOptions.y_def = atol(argv[++i]);
267                 else if (!strcmp(argv[i], "-max"))                                  accelOptions.maxValue = atol(argv[++i]);
268                 else if (!strcmp(argv[i], "-displayon"))                    bKeepDisplayOn = TRUE;
269                 else if (!strcmp(argv[i], "-keys"))                             sprintf(keys_config_file, "%s", argv[++i]);
270                 else if (!strcmp(argv[i], "-autosave"))                     bAutosaveOnExit = TRUE;
271                 else if (!strcmp(argv[i], "-disc"))                     discNumber = atol(argv[++i]);
272                 else if (!strcmp(argv[i], "-corners")){
273                         int j = 0;
274                         i++;
275                         char num[2];
276                         for (j=0; j<strlen(argv[i]); j++){
277                                 strncpy(num, argv[i] + j, 1);
278                                 cornerActions[j] = atoi(num);
279                         }
280         }
281
282                 else if (!strcmp(argv[i], "-spu_reverb"))               spu_config.iUseReverb = atol(argv[++i]);
283                 else if (!strcmp(argv[i], "-spu_interpolation"))        spu_config.iUseInterpolation = atol(argv[++i]);
284
285                 else if (!strcmp(argv[i], "-enhance"))                  pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
286                 else if (!strcmp(argv[i], "-enhancehack"))              pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
287
288                 else if (!strcmp(argv[i], "-gles_dithering"))   pl_rearmed_cbs.gpu_peopsgl.bDrawDither = atol(argv[++i]);
289                 else if (!strcmp(argv[i], "-gles_mask"))            pl_rearmed_cbs.gpu_peopsgl.iUseMask = atol(argv[++i]);
290                 else if (!strcmp(argv[i], "-gles_filtering"))   pl_rearmed_cbs.gpu_peopsgl.iFilterType = atol(argv[++i]);
291                 else if (!strcmp(argv[i], "-gles_fbtex"))           pl_rearmed_cbs.gpu_peopsgl.iFrameTexType = atol(argv[++i]);
292                 else if (!strcmp(argv[i], "-gles_vram"))            pl_rearmed_cbs.gpu_peopsgl.iVRamSize = atol(argv[++i]);
293                 else if (!strcmp(argv[i], "-gles_fastmdec"))    pl_rearmed_cbs.gpu_peopsgl.bUseFastMdec = atol(argv[++i]);
294         else if (!strcmp(argv[i], "-gles_advblend"))    pl_rearmed_cbs.gpu_peopsgl.bAdvancedBlend = atol(argv[++i]);
295         else if (!strcmp(argv[i], "-gles_opaque"))          pl_rearmed_cbs.gpu_peopsgl.bOpaquePass = atol(argv[++i]);
296
297                 else {
298                         fprintf(stderr, "Unknown option: %s\n", argv[i]);
299                         return 1;
300                 }
301         }
302         
303         pl_init();
304         if (emu_core_init() == -1)
305                 return 1;
306         
307         if (cdfile) {
308                 set_cd_image(cdfile);
309                 strcpy(file_name, strrchr(cdfile,'/'));
310         }
311
312         if (LoadPlugins() == -1) {
313                 SysMessage("Failed loading plugins!");
314                 return 1;
315         }
316
317         if (discNumber > 0)
318                 cdrIsoMultidiskSelect = discNumber - 1;
319
320         if (OpenPlugins() == -1) {
321                 return 1;
322         }
323         plugin_call_rearmed_cbs();
324
325         CheckCdrom();
326
327         if (getst >= 0){
328                 char fname[MAXPATHLEN];
329
330                 get_state_filename(fname, sizeof(fname), getst);
331                 printf("SAVESTATE: %s\n", fname);
332                 if (cdrIsoMultidiskCount > 1){
333                         int i = 0;
334                         for (i=1; i<cdrIsoMultidiskCount; i++){
335                                 cdrIsoMultidiskSelect = i;
336                                 CdromId[0] = '\0';
337                                 CdromLabel[0] = '\0';
338
339                                 CDR_close();
340                                 if (CDR_open() == 0){
341                                         CheckCdrom();
342                                         get_state_filename(fname, sizeof(fname), getst);
343                                         printf("SAVESTATE: %s\n", fname);
344                                 }
345                         }
346                 }
347                 return 0;
348         }
349
350         SysReset();
351
352         if (file[0] != '\0') {
353                 if (Load(file) != -1)
354                         ready_to_go = 1;
355         } else {
356                 if (cdfile) {
357                         if (LoadCdrom() == -1) {
358                                 ClosePlugins();
359                                 printf(_("Could not load CD-ROM!\n"));
360                                 return -1;
361                         }
362                         emu_on_new_cd(0);
363                         ready_to_go = 1;
364                 }
365         }
366
367         if (!ready_to_go) {
368                 printf ("something goes wrong, maybe you forgot -cdfile ? \n");
369                 return 1;
370         }
371
372         if (cdrIsoMultidiskCount > 1)
373                 printf ("Loaded a multidisc image: %i discs.\n", cdrIsoMultidiskCount);
374
375         // If a state has been specified, then load that
376         if (loadst) {
377                 int ret = emu_load_state(loadst - 1);
378                 printf("%s state %d\n", ret ? "Failed to load" : "Loaded", loadst);
379                 state_slot = loadst - 1;
380         }
381
382         if (maemo_init(&argc, &argv))
383                 return 1;
384
385         if (GPU_open != NULL) {
386                 int ret = GPU_open(&gpuDisp, "PCSX", NULL);
387                 if (ret){
388                         fprintf(stderr, "Warning: GPU_open returned %d\n", ret);
389                         gpuDisp=ret;
390                 }
391         }
392
393         if (Config.HLE)
394                 printf("Note: running without BIOS, expect compatibility problems\n");
395
396         dfinput_activate();
397         pl_timing_prepare(Config.PsxType);
398
399         while (1)
400         {
401                 stop = 0;
402                 emu_action = SACTION_NONE;
403
404                 psxCpu->Execute();
405                 if (emu_action != SACTION_NONE)
406                         do_emu_action();
407         }
408
409         maemo_finish();
410         return 0;
411 }
412