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