Commit | Line | Data |
---|---|---|
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 | |
76f7048e | 22 | int g_opts = OPT_SHOWFPS; |
d64280d6 | 23 | int g_maemo_opts; |
24 | char file_name[MAXPATHLEN]; | |
76f7048e | 25 | |
54b4a001 | 26 | enum sched_action emu_action; |
27 | void do_emu_action(void); | |
28 | ||
b7b2fb41 B |
29 | static void ChangeWorkingDirectory(char *exe) |
30 | { | |
54b4a001 | 31 | char exepath[1024]; |
32 | char *s; | |
33 | snprintf(exepath, sizeof(exepath), "%s", exe); | |
b7b2fb41 B |
34 | s = strrchr(exepath, '/'); |
35 | if (s != NULL) { | |
36 | *s = '\0'; | |
37 | chdir(exepath); | |
38 | } | |
39 | } | |
40 | ||
e0c692d9 | 41 | int maemo_main(int argc, char **argv) |
b7b2fb41 B |
42 | { |
43 | ChangeWorkingDirectory("c"); | |
44 | char file[MAXPATHLEN] = ""; | |
45 | char path[MAXPATHLEN]; | |
46 | const char *cdfile = NULL; | |
47 | int loadst = 0; | |
b7b2fb41 B |
48 | int i; |
49 | ||
b7b2fb41 | 50 | strcpy(Config.BiosDir, "/home/user/MyDocs"); |
b7b2fb41 | 51 | strcpy(Config.PluginsDir, "/opt/maemo/usr/games/plugins"); |
e0c692d9 | 52 | snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "/opt/maemo/usr/games" PATCHES_DIR); |
53 | Config.PsxAuto = 1; | |
b7b2fb41 B |
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]; | |
b7b2fb41 B |
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 | } | |
b7b2fb41 B |
72 | cdfile = isofilename; |
73 | } | |
76f7048e | 74 | else if (!strcmp(argv[i],"-frameskip")) { |
76f7048e | 75 | int tv_reg = atol(argv[++i]); |
76 | if (tv_reg > 0) | |
bbd471af | 77 | pl_rearmed_cbs.frameskip = -1; |
b7b2fb41 | 78 | } |
d64280d6 | 79 | else if (!strcmp(argv[i],"-fullscreen")) g_maemo_opts |= 2; |
80 | else if (!strcmp(argv[i],"-accel")) g_maemo_opts |= 4; | |
bbd471af | 81 | else if (!strcmp(argv[i],"-nosound")) strcpy(Config.Spu, "spunull.so"); |
2aa6a3a0 | 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"); | |
b7b2fb41 B |
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; | |
b7b2fb41 B |
91 | } |
92 | ||
b7b2fb41 B |
93 | hildon_init(&argc, &argv); |
94 | ||
d64280d6 | 95 | if (cdfile) { |
b7b2fb41 | 96 | set_cd_image(cdfile); |
d64280d6 | 97 | strcpy(file_name, strrchr(cdfile,'/')); |
98 | } | |
b7b2fb41 B |
99 | |
100 | if (SysInit() == -1) | |
101 | return 1; | |
102 | ||
76f7048e | 103 | pl_init(); |
104 | ||
b7b2fb41 B |
105 | if (LoadPlugins() == -1) { |
106 | SysMessage("Failed loading plugins!"); | |
107 | return 1; | |
108 | } | |
b7b2fb41 B |
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 | } | |
9c27c205 | 128 | emu_on_new_cd(); |
b7b2fb41 B |
129 | ready_to_go = 1; |
130 | } | |
131 | } | |
132 | ||
2aa6a3a0 | 133 | if (!ready_to_go) { |
134 | printf ("something goes wrong, maybe you forgot -cdfile ? \n"); | |
135 | return 1; | |
136 | } | |
137 | ||
b7b2fb41 B |
138 | // If a state has been specified, then load that |
139 | if (loadst) { | |
8f892648 | 140 | int ret = emu_load_state(loadst - 1); |
141 | printf("%s state %d\n", ret ? "failed to load" : "loaded", loadst); | |
b7b2fb41 B |
142 | } |
143 | ||
2aa6a3a0 | 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); | |
b7b2fb41 B |
150 | } |
151 | ||
2aa6a3a0 | 152 | dfinput_activate(); |
76f7048e | 153 | pl_timing_prepare(Config.PsxType); |
154 | ||
54b4a001 | 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 | } | |
b7b2fb41 B |
164 | |
165 | return 0; | |
166 | } | |
167 |