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