fix a few maemo issues
[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 "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#include "maemo_common.h"
20
21// sound plugin
22extern int iUseReverb;
23extern int iUseInterpolation;
24extern int iSPUIRQWait;
25extern int iUseTimer;
26
27int g_opts = OPT_SHOWFPS;
28int g_maemo_opts;
29char file_name[MAXPATHLEN];
30
31enum sched_action emu_action;
32void do_emu_action(void);
33
34static void ChangeWorkingDirectory(char *exe)
35{
36 char exepath[1024];
37 char *s;
38 snprintf(exepath, sizeof(exepath), "%s", exe);
39 s = strrchr(exepath, '/');
40 if (s != NULL) {
41 *s = '\0';
42 chdir(exepath);
43 }
44}
45
46int maemo_main(int argc, char **argv)
47{
48 ChangeWorkingDirectory("c");
49 char file[MAXPATHLEN] = "";
50 char path[MAXPATHLEN];
51 const char *cdfile = NULL;
52 int loadst = 0;
53 int i;
54
55 strcpy(Config.BiosDir, "/home/user/MyDocs");
56 strcpy(Config.PluginsDir, "/opt/maemo/usr/games/plugins");
57 snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "/opt/maemo/usr/games" PATCHES_DIR);
58 Config.PsxAuto = 1;
59
60 // read command line options
61 for (i = 1; i < argc; i++) {
62 if (!strcmp(argv[i], "-psxout")) Config.PsxOut = 1;
63 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
64 else if (!strcmp(argv[i], "-cdfile")) {
65 char isofilename[MAXPATHLEN];
66 if (i+1 >= argc) break;
67 strncpy(isofilename, argv[++i], MAXPATHLEN);
68 if (isofilename[0] != '/') {
69 getcwd(path, MAXPATHLEN);
70 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
71 strcat(path, "/");
72 strcat(path, isofilename);
73 strcpy(isofilename, path);
74 } else
75 isofilename[0] = 0;
76 }
77 cdfile = isofilename;
78 }
79 else if (!strcmp(argv[i],"-frameskip")) {
80 int tv_reg = atol(argv[++i]);
81 if (tv_reg > 0)
82 pl_rearmed_cbs.frameskip = -1;
83 }
84 else if (!strcmp(argv[i],"-fullscreen")) g_maemo_opts |= 2;
85 else if (!strcmp(argv[i],"-accel")) g_maemo_opts |= 4;
86 else if (!strcmp(argv[i],"-sputhreaded")) iUseTimer=1;
87 else if (!strcmp(argv[i],"-nosound")) strcpy(Config.Spu, "spunull.so");
88 /* unworking with r10
89 else if(!strcmp(argv[i], "-bdir")) sprintf(Config.BiosDir, "%s", argv[++i]);
90 else if(!strcmp(argv[i], "-bios")) sprintf(Config.Bios, "%s", argv[++i]);
91 else if (!strcmp(argv[i],"-gles")) strcpy(Config.Gpu, "gpuGLES.so");
92 */
93 else if (!strcmp(argv[i], "-cdda")) Config.Cdda = 1;
94 else if (!strcmp(argv[i], "-xa")) Config.Xa = 1;
95 else if (!strcmp(argv[i], "-rcnt")) Config.RCntFix = 1 ;
96 else if (!strcmp(argv[i], "-sio")) Config.Sio = 1;
97 else if (!strcmp(argv[i], "-spuirq")) Config.SpuIrq = 1;
98 else if (!strcmp(argv[i], "-vsync")) Config.VSyncWA = 1;
99 }
100
101 pl_rearmed_cbs.gpu_peops.dwActFixes = 1<<7;
102 iUseReverb = 2;
103 iUseInterpolation = 1;
104 iSPUIRQWait = 1;
105 iUseTimer = 2;
106
107 in_type1 = PSE_PAD_TYPE_STANDARD;
108 in_type2 = PSE_PAD_TYPE_STANDARD;
109
110 hildon_init(&argc, &argv);
111
112 if (cdfile) {
113 set_cd_image(cdfile);
114 strcpy(file_name, strrchr(cdfile,'/'));
115 }
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(&argc, &argv);
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