/
LnxMain.c
378 lines (325 loc) · 7.75 KB
/
LnxMain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/* Pcsx - Pc Psx Emulator
* Copyright (C) 1999-2002 Pcsx Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <dlfcn.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <dirent.h>
#include "PsxCommon.h"
#include "Sio.h"
#include "gpuAPI/newGPU/newGPU.h"
#ifdef IPHONE
extern const char* get_resource_path(char* file);
extern const char* get_documents_path(char* file);
#endif
int __saved = 0;
PcsxConfig Config;
R3000Acpu *psxCpu;
psxRegisters* psxRegs;
u32 *psxMemWLUT;
u32 *psxMemRLUT;
s8 *psxH;
s8 *psxR;
s8 *psxP;
s8 *psxM;
psxCounter psxCounters[5];
unsigned long psxNextCounter, psxNextsCounter;
cdrStruct cdr;
char CdromId[9];
char CdromLabel[11];
FILE *emuLog;
long LoadCdBios;
int StatesC;
int cdOpenCase;
int NetOpened;
s8* packfile = NULL;
s8 gamepath[1024]={ '.', '/', 0, 0 };
s8 save_filename[1024];
static void ChangeWorkingDirectory(char *exe)
{
s8 exepath[1024];
s8* s;
sprintf(exepath, "%s", exe);
s = strrchr(exepath, '/');
if (s != NULL) {
*s = '\0';
chdir(exepath);
}
}
#ifdef IPHONE
#define main iphone_main
extern
#endif
int main(int argc, char *argv[])
{
char *file = NULL;
char *lang;
int runcd = 2;
char* loadst = NULL;
int i;
int skipCountTable[9] = { 0,1,3,2,4,7,10,15,17 };
int skipRateTable[9] = { 1,2,5,3,5,8,11,16,18 };
__saved = 0;
memset(&Config, 0, sizeof(PcsxConfig));
Config.HLE = 0;
sprintf(Config.Bios, "/scph1001.bin");
strcpy(Config.Net, _("Disabled"));
#ifdef IPHONE
ChangeWorkingDirectory(get_documents_path("psx4iphone"));
#else
#ifndef MAEMO_CHANGES
ChangeWorkingDirectory(argv[0]);
#endif
#endif
#ifdef ROM_PREFIX
strncpy(gamepath,ROM_PREFIX,1024);
#else
getcwd(gamepath, 1024);
#endif
sprintf(Config.BiosDir, "%s", gamepath);
#ifdef DATA_PREFIX
sprintf(Config.Mcd1, "%s/mcd001.mcr", DATA_PREFIX);
sprintf(Config.Mcd2, "%s/mcd002.mcr", DATA_PREFIX);
#else
sprintf(Config.Mcd1, "%s/mcd001.mcr", gamepath);
sprintf(Config.Mcd2, "%s/mcd002.mcr", gamepath);
#endif
Config.PsxAuto = 1;
Config.Cdda = 0;
Config.Xa = 0;
#ifdef DYNAREC
Config.Cpu = 0;
#else
Config.Cpu = 1;
#endif
Config.Mdec = 0;
Config.PsxOut = 0;
Config.PsxType = 0;
Config.QKeys = 0;
Config.RCntFix = 0 ;
Config.Sio = 0;
Config.SpuIrq = 0;
Config.VSyncWA = 0;
displayFrameInfo = 0;
for (i=1; i<argc; i++) {
if (!strcmp(argv[i], "-runcd")) runcd = 1;
else if (!strcmp(argv[i], "-psxout")) Config.PsxOut = 1;
else if (!strcmp(argv[i], "-load")) loadst = argv[++i];
else if (!strcmp(argv[i], "-nosound")) iSoundMuted = 1;
else if (!strcmp(argv[i], "-showfps")) displayFrameInfo = 1;
#if defined(ENABLE_GPU_PRIM_STATS) || defined(ENABLE_GPU_PROFILLER)
else if (!strcmp(argv[i], "-gpustats")) displayGpuStats = 1;
#endif
else if (!strcmp(argv[i], "-frameskip"))
{
int skipValue = atoi(argv[++i]);
if (skipValue >= 0 && skipValue <= 8)
{
skipCount = skipCountTable[skipValue];
skipRate = skipRateTable[skipValue];
}
}
else if (!strcmp(argv[i], "-cyclemult"))
{
int cycleValue = atoi(argv[++i]);
if (cycleValue >= 0 && cycleValue <= 10)
{
PsxCycleMult = cycleValue;
}
}
else if (!strcmp(argv[i], "-ilace"))
{
int iLace = atoi(argv[++i]);
if (iLace == 0 || iLace == 1 || iLace == 3 || iLace == 7)
{
linesInterlace_user = iLace;
}
}
else if (!strcmp(argv[i], "-h") ||
!strcmp(argv[i], "-help") ||
!strcmp(argv[i], "--help")) {
printf("%s %s\n", argv[0], _(
"[options] [CD IMAGE FILE]\n"
"\toptions:\n"
"\t-h -help --help\tThis help\n"
"\t-runcd\t\tRuns CdRom\n"
"\t-psxout\t\tEnable stdout output\n"
"\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
"\t-nosound\tDisable sound\n"
"\t-showfps\tShow FPS\n"
#if defined(ENABLE_GPU_PRIM_STATS) || defined(ENABLE_GPU_PROFILLER)
"\t-gpustats\tShow GPU statistics (needs -showfps)\n"
#endif
"\t-frameskip 0-8\tFrame skipping ratio\n"
"\t-cyclemult 0-10\tCPU cycle multiplier\n"
"\t-ilace 0,1,3,7\tInterlace lines\n"
"\tFILE\t\tCdRom file\n"));
return 0;
} else file = argv[i];
}
packfile = file;
gp2x_init(1000, 16, 11025, 16, 1, 60, 1);
#ifdef MAEMO_CHANGES
hildon_init (&argc, &argv);
#endif
if (SysInit() == -1) return 1;
if (OpenPlugins() == -1) return 1;
SysReset();
CheckCdrom();
/*if (file != NULL) Load(file);
else*/
{
if (runcd == 1) {
LoadCdBios = 0;
if (LoadCdrom() == -1) {
ClosePlugins();
printf(_("Could not load Cdrom\n"));
return -1;
}
}
else if (runcd == 2)
{
LoadCdBios = 1;
}
}
if (loadst)
{
__saved = 1;
sprintf (save_filename, "%s", loadst);
LoadState(save_filename);
}
#ifdef MAEMO_CHANGES
printf(
"CdromFile: %s\n"
"Show FPS %s\n"
#if defined(ENABLE_GPU_PRIM_STATS) || defined(ENABLE_GPU_PROFILLER)
"Show GPU Stats %s\n"
#endif
"Display Video Memory %s\n"
"Set NULL GPU %s\n"
"Interlace Count %d\n"
"Frame Limit %s\n"
"Frame Skip %d/%d\n"
"Cycle Multiplier %d\n"
"Abe's Oddysee Fix %s\n"
"Sound %s\n",
file,
(displayFrameInfo == false ? "OFF" : "ON"),
#if defined(ENABLE_GPU_PRIM_STATS) || defined(ENABLE_GPU_PROFILLER)
(displayGpuStats == false ? "OFF" : "ON"),
#endif
(displayVideoMemory == false ? "OFF" : "ON"),
(activeNullGPU == false ? "OFF" : "ON"),
linesInterlace_user,
(enableFrameLimit == false ? "OFF" : "ON"),
skipCount, skipRate,
PsxCycleMult,
(enableAbbeyHack == false ? "OFF" : "ON"),
(iSoundMuted == 0 ? "ON" : "OFF")
);
#endif
psxCpu->Execute();
return 0;
}
DIR *dir;
void InitLanguages() {
}
char *GetLanguageNext() {
return NULL;
}
void CloseLanguages() {
}
void ChangeLanguage(char *lang) {
}
int SysInit() {
#ifdef GTE_DUMP
gteLog = fopen("gteLog.txt","wb");
setvbuf(gteLog, NULL, _IONBF, 0);
#endif
#ifdef EMU_LOG
#ifndef LOG_STDOUT
emuLog = fopen("emuLog.txt","wb");
#else
emuLog = stdout;
#endif
setvbuf(emuLog, NULL, _IONBF, 0);
#endif
psxInit();
//LoadPlugins();
LoadMcds(Config.Mcd1, Config.Mcd2);
return 0;
}
void SysReset() {
psxReset();
}
void SysClose() {
psxShutdown();
ClosePlugins();
if (emuLog != NULL) fclose(emuLog);
gp2x_deinit();
#ifdef IPHONE
pthread_exit(NULL);
#endif
}
void SysPrintf(char *fmt, ...) {
va_list list;
char msg[512];
va_start(list, fmt);
vsprintf(msg, fmt, list);
va_end(list);
if (Config.PsxOut) printf ("%s\n", msg);
#ifdef EMU_LOG
#ifndef LOG_STDOUT
fprintf(emuLog, "%s\n", msg);
#endif
#endif
}
void *SysLoadLibrary(char *lib) {
return NULL;
}
void *SysLoadSym(void *lib, char *sym) {
return NULL;
}
const char *SysLibError() {
return NULL;
}
void SysCloseLibrary(void *lib) {
}
void SysUpdate() {
}
void SysRunGui() {
}
void SysMessage(char* fmt, ...) {
#ifdef EMU_LOG
va_list list;
va_start(list, fmt);
vsprintf(__sysmsg, fmt, list);
va_end(list);
__sysmsg[127]=0;
if (Config.PsxOut) printf ("%s\n", __sysmsg);
//SysPrintf("%s", __sysmsg);
fprintf(emuLog, "%s\r\n", __sysmsg);
fflush(emuLog);
#endif
}