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