spu: also return on decoder irqs
[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"
76f7048e 14#include "menu.h"
b7b2fb41 15#include "plugin.h"
76f7048e 16#include "plugin_lib.h"
b7b2fb41 17#include "../libpcsxcore/misc.h"
54b4a001 18#include "../libpcsxcore/new_dynarec/new_dynarec.h"
e4c83ca6 19#include "../plugins/dfinput/externals.h"
d64280d6 20#include "maemo_common.h"
b7b2fb41 21
76f7048e 22int g_opts = OPT_SHOWFPS;
d64280d6 23int g_maemo_opts;
cc56203b 24int g_scaler, soft_filter;
25int g_menuscreen_w, g_menuscreen_h;
26
d64280d6 27char file_name[MAXPATHLEN];
76f7048e 28
54b4a001 29enum sched_action emu_action;
30void do_emu_action(void);
31
b7b2fb41
B
32static void ChangeWorkingDirectory(char *exe)
33{
54b4a001 34 char exepath[1024];
35 char *s;
36 snprintf(exepath, sizeof(exepath), "%s", exe);
b7b2fb41
B
37 s = strrchr(exepath, '/');
38 if (s != NULL) {
39 *s = '\0';
40 chdir(exepath);
41 }
42}
43
38c2028e 44int main(int argc, char **argv)
b7b2fb41 45{
b7b2fb41
B
46 char file[MAXPATHLEN] = "";
47 char path[MAXPATHLEN];
48 const char *cdfile = NULL;
49 int loadst = 0;
b7b2fb41
B
50 int i;
51
38c2028e 52 emu_core_preinit();
53 ChangeWorkingDirectory("c");
54
b7b2fb41 55 strcpy(Config.BiosDir, "/home/user/MyDocs");
b7b2fb41 56 strcpy(Config.PluginsDir, "/opt/maemo/usr/games/plugins");
e0c692d9 57 snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "/opt/maemo/usr/games" PATCHES_DIR);
58 Config.PsxAuto = 1;
cc56203b 59
60 g_menuscreen_w = 800;
61 g_menuscreen_h = 480;
62
38c2028e 63 pl_init();
64
65 emu_core_init();
66
b7b2fb41
B
67 // read command line options
68 for (i = 1; i < argc; i++) {
69 if (!strcmp(argv[i], "-psxout")) Config.PsxOut = 1;
70 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
71 else if (!strcmp(argv[i], "-cdfile")) {
72 char isofilename[MAXPATHLEN];
b7b2fb41
B
73 if (i+1 >= argc) break;
74 strncpy(isofilename, argv[++i], MAXPATHLEN);
75 if (isofilename[0] != '/') {
76 getcwd(path, MAXPATHLEN);
77 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
78 strcat(path, "/");
79 strcat(path, isofilename);
80 strcpy(isofilename, path);
81 } else
82 isofilename[0] = 0;
83 }
b7b2fb41
B
84 cdfile = isofilename;
85 }
76f7048e 86 else if (!strcmp(argv[i],"-frameskip")) {
76f7048e 87 int tv_reg = atol(argv[++i]);
88 if (tv_reg > 0)
bbd471af 89 pl_rearmed_cbs.frameskip = -1;
b7b2fb41 90 }
d64280d6 91 else if (!strcmp(argv[i],"-fullscreen")) g_maemo_opts |= 2;
92 else if (!strcmp(argv[i],"-accel")) g_maemo_opts |= 4;
bbd471af 93 else if (!strcmp(argv[i],"-nosound")) strcpy(Config.Spu, "spunull.so");
2aa6a3a0 94 else if (!strcmp(argv[i], "-bdir")) sprintf(Config.BiosDir, "%s", argv[++i]);
95 else if (!strcmp(argv[i], "-bios")) sprintf(Config.Bios, "%s", argv[++i]);
96 else if (!strcmp(argv[i], "-gles")) strcpy(Config.Gpu, "gpuGLES.so");
b7b2fb41
B
97 else if (!strcmp(argv[i], "-cdda")) Config.Cdda = 1;
98 else if (!strcmp(argv[i], "-xa")) Config.Xa = 1;
99 else if (!strcmp(argv[i], "-rcnt")) Config.RCntFix = 1 ;
100 else if (!strcmp(argv[i], "-sio")) Config.Sio = 1;
101 else if (!strcmp(argv[i], "-spuirq")) Config.SpuIrq = 1;
102 else if (!strcmp(argv[i], "-vsync")) Config.VSyncWA = 1;
b7b2fb41
B
103 }
104
b7b2fb41
B
105 hildon_init(&argc, &argv);
106
d64280d6 107 if (cdfile) {
b7b2fb41 108 set_cd_image(cdfile);
d64280d6 109 strcpy(file_name, strrchr(cdfile,'/'));
110 }
b7b2fb41 111
b7b2fb41
B
112 if (LoadPlugins() == -1) {
113 SysMessage("Failed loading plugins!");
114 return 1;
115 }
b7b2fb41
B
116
117 if (OpenPlugins() == -1) {
118 return 1;
119 }
120 plugin_call_rearmed_cbs();
121
122 CheckCdrom();
123 SysReset();
124
125 if (file[0] != '\0') {
126 if (Load(file) != -1)
127 ready_to_go = 1;
128 } else {
129 if (cdfile) {
130 if (LoadCdrom() == -1) {
131 ClosePlugins();
132 printf(_("Could not load CD-ROM!\n"));
133 return -1;
134 }
79f216e3 135 emu_on_new_cd(0);
b7b2fb41
B
136 ready_to_go = 1;
137 }
138 }
139
2aa6a3a0 140 if (!ready_to_go) {
141 printf ("something goes wrong, maybe you forgot -cdfile ? \n");
142 return 1;
143 }
144
b7b2fb41
B
145 // If a state has been specified, then load that
146 if (loadst) {
8f892648 147 int ret = emu_load_state(loadst - 1);
148 printf("%s state %d\n", ret ? "failed to load" : "loaded", loadst);
b7b2fb41
B
149 }
150
2aa6a3a0 151 maemo_init(&argc, &argv);
152
153 if (GPU_open != NULL) {
154 int ret = GPU_open(&gpuDisp, "PCSX", NULL);
155 if (ret)
156 fprintf(stderr, "Warning: GPU_open returned %d\n", ret);
b7b2fb41
B
157 }
158
2aa6a3a0 159 dfinput_activate();
76f7048e 160 pl_timing_prepare(Config.PsxType);
161
54b4a001 162 while (1)
163 {
164 stop = 0;
165 emu_action = SACTION_NONE;
166
167 psxCpu->Execute();
168 if (emu_action != SACTION_NONE)
169 do_emu_action();
170 }
b7b2fb41
B
171
172 return 0;
173}
174