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