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