frontend: support ingame actions (state load and such)
[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
B
12
13#include "main.h"
14#include "plugin.h"
b7b2fb41 15#include "../libpcsxcore/misc.h"
54b4a001 16#include "../libpcsxcore/new_dynarec/new_dynarec.h"
b7b2fb41
B
17
18// from softgpu plugin
19extern int iUseDither;
20extern int UseFrameSkip;
21extern int UseFrameLimit;
22extern uint32_t dwActFixes;
23extern float fFrameRateHz;
24extern int dwFrameRateTicks;
25
26// sound plugin
27extern int iUseReverb;
28extern int iUseInterpolation;
29extern int iXAPitch;
30extern int iSPUIRQWait;
31extern int iUseTimer;
32
54b4a001 33enum sched_action emu_action;
34void do_emu_action(void);
35
b7b2fb41
B
36static void ChangeWorkingDirectory(char *exe)
37{
54b4a001 38 char exepath[1024];
39 char *s;
40 snprintf(exepath, sizeof(exepath), "%s", exe);
b7b2fb41
B
41 s = strrchr(exepath, '/');
42 if (s != NULL) {
43 *s = '\0';
44 chdir(exepath);
45 }
46}
47
e0c692d9 48int maemo_main(int argc, char **argv)
b7b2fb41
B
49{
50 ChangeWorkingDirectory("c");
51 char file[MAXPATHLEN] = "";
52 char path[MAXPATHLEN];
53 const char *cdfile = NULL;
54 int loadst = 0;
b7b2fb41
B
55 int i;
56
b7b2fb41 57 strcpy(Config.BiosDir, "/home/user/MyDocs");
b7b2fb41 58 strcpy(Config.PluginsDir, "/opt/maemo/usr/games/plugins");
e0c692d9 59 snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "/opt/maemo/usr/games" PATCHES_DIR);
60 Config.PsxAuto = 1;
b7b2fb41
B
61
62 // read command line options
63 for (i = 1; i < argc; i++) {
64 if (!strcmp(argv[i], "-psxout")) Config.PsxOut = 1;
65 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
66 else if (!strcmp(argv[i], "-cdfile")) {
67 char isofilename[MAXPATHLEN];
68
69 if (i+1 >= argc) break;
70 strncpy(isofilename, argv[++i], MAXPATHLEN);
71 if (isofilename[0] != '/') {
72 getcwd(path, MAXPATHLEN);
73 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
74 strcat(path, "/");
75 strcat(path, isofilename);
76 strcpy(isofilename, path);
77 } else
78 isofilename[0] = 0;
79 }
80
81 cdfile = isofilename;
82 }
83 else if (!strcmp(argv[i],"-frameskip")){
84
85 int tv_reg=atol(argv[++i]);
86 if (tv_reg>0){
87 UseFrameSkip=1;
88 fFrameRateHz = (tv_reg==1)?50.0f: 59.94f;
89 dwFrameRateTicks = (100000*100 / (unsigned long)(fFrameRateHz*100));
90 }
91 }
92 else if (!strcmp(argv[i],"-sputhreaded")){
93 iUseTimer=1;
94 }
95 else if (!strcmp(argv[i],"-nosound")){
96 strcpy(Config.Spu, "spunull.so");
97 }
98 else if(!strcmp(argv[i], "-bdir")) sprintf(Config.BiosDir, "%s", argv[++i]);
99 else if(!strcmp(argv[i], "-bios")) sprintf(Config.Bios, "%s", argv[++i]);
100 else if (!strcmp(argv[i],"-gles")){
101 strcpy(Config.Gpu, "gpuGLES.so");
102 }
103 else if (!strcmp(argv[i], "-cdda")) Config.Cdda = 1;
104 else if (!strcmp(argv[i], "-xa")) Config.Xa = 1;
105 else if (!strcmp(argv[i], "-rcnt")) Config.RCntFix = 1 ;
106 else if (!strcmp(argv[i], "-sio")) Config.Sio = 1;
107 else if (!strcmp(argv[i], "-spuirq")) Config.SpuIrq = 1;
108 else if (!strcmp(argv[i], "-vsync")) Config.VSyncWA = 1;
109 else if (!strcmp(argv[i], "-h") ||
110 !strcmp(argv[i], "-help") ||
111 !strcmp(argv[i], "--help")) {
112 printf(PACKAGE_NAME " " PACKAGE_VERSION "\n");
113 printf("%s\n", _(
114 " pcsx [options] [file]\n"
115 "\toptions:\n"
116 "\t-cdfile FILE\tRuns a CD image file\n"
117 "\t-psxout\t\tEnable PSX output\n"
118 "\t-nosound\t\tDisable sound using spunull plugin\n"
119 "\t-sputhreaded\t\tMove sound to separate thread\n"
120 "\t-frameskip\t\tEnable frameskip\n"
121 "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
122 "\t-h -help\tDisplay this message\n"
123 "\tfile\t\tLoads file\n"));
124 return 0;
125 } else {
126 strncpy(file, argv[i], MAXPATHLEN);
127 if (file[0] != '/') {
128 getcwd(path, MAXPATHLEN);
129 if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
130 strcat(path, "/");
131 strcat(path, file);
132 strcpy(file, path);
133 } else
134 file[0] = 0;
135 }
136 }
137 }
138
b7b2fb41
B
139 hildon_init(&argc, &argv);
140
141 if (cdfile)
142 set_cd_image(cdfile);
143
144 if (SysInit() == -1)
145 return 1;
146
b7b2fb41
B
147 if (LoadPlugins() == -1) {
148 SysMessage("Failed loading plugins!");
149 return 1;
150 }
b7b2fb41
B
151
152 if (OpenPlugins() == -1) {
153 return 1;
154 }
155 plugin_call_rearmed_cbs();
156
157 CheckCdrom();
158 SysReset();
159
160 if (file[0] != '\0') {
161 if (Load(file) != -1)
162 ready_to_go = 1;
163 } else {
164 if (cdfile) {
165 if (LoadCdrom() == -1) {
166 ClosePlugins();
167 printf(_("Could not load CD-ROM!\n"));
168 return -1;
169 }
170 ready_to_go = 1;
171 }
172 }
173
174 // If a state has been specified, then load that
175 if (loadst) {
8f892648 176 int ret = emu_load_state(loadst - 1);
177 printf("%s state %d\n", ret ? "failed to load" : "loaded", loadst);
b7b2fb41
B
178 }
179
b7b2fb41
B
180 if (ready_to_go)
181 maemo_init();
182 else
183 {
e0c692d9 184 printf ("somethings goes wrong, maybe you forgot -cdfile ? \n");
185 return 0;
b7b2fb41
B
186 }
187
54b4a001 188 while (1)
189 {
190 stop = 0;
191 emu_action = SACTION_NONE;
192
193 psxCpu->Execute();
194 if (emu_action != SACTION_NONE)
195 do_emu_action();
196 }
b7b2fb41
B
197
198 return 0;
199}
200