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