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