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
|
//
// main.m
//
// Created by Gil Pedersen on Fri Jun 06 2003.
// Copyright (c) 2003 SoftWorkz. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
#import "EmuThread.h"
#include <dlfcn.h>
//#import <sys/param.h>
#import <unistd.h>
#include "psxcommon.h"
#include "sio.h"
#import <IOKit/pwr_mgt/IOPMLib.h>
#import "hotkeys.h"
static BOOL sysInited = NO;
//#define EMU_LOG
static IOPMAssertionID powerAssertion = kIOPMNullAssertionID;
int main(int argc, const char *argv[]) {
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
char parentdir[MAXPATHLEN];
char *c;
strncpy ( parentdir, argv[0], sizeof(parentdir) );
c = (char*) parentdir;
while (*c != '\0') /* go to end */
c++;
while (*c != '/') /* back up to parent */
c--;
*c++ = '\0'; /* cut off last part (binary name) */
assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
}
strcpy(Config.BiosDir, "Bios/");
strcpy(Config.PatchesDir, "Patches/");
// Setup the X11 window
if (getenv("DISPLAY") == NULL)
setenv("DISPLAY", ":0.0", 0); // Default to first local display
return NSApplicationMain(argc, argv);
}
int SysInit() {
if (!sysInited) {
#ifdef EMU_LOG
#ifndef LOG_STDOUT
emuLog = fopen("emuLog.txt","wb");
#else
emuLog = stdout;
#endif
setvbuf(emuLog, NULL, _IONBF, 0);
#endif
if (EmuInit() != 0)
return -1;
sysInited = YES;
}
if (LoadPlugins() == -1) {
return -1;
}
LoadMcds(Config.Mcd1, Config.Mcd2);
IOReturn success= IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, CFSTR("PSX Emu Running"), &powerAssertion);
if (success != kIOReturnSuccess) {
NSLog(@"Unable to stop sleep, error code %d", success);
}
attachHotkeys();
return 0;
}
void SysReset() {
[EmuThread resetNow];
//EmuReset();
}
void SysPrintf(const char *fmt, ...) {
va_list list;
char msg[512];
va_start(list, fmt);
vsprintf(msg, fmt, list);
va_end(list);
if (Config.PsxOut) printf ("%s", msg);
#ifdef EMU_LOG
#ifndef LOG_STDOUT
fprintf(emuLog, "%s", msg);
#endif
#endif
}
void SysMessage(const char *fmt, ...) {
va_list list;
NSString *locFmtString = NSLocalizedString([NSString stringWithCString:fmt encoding:NSUTF8StringEncoding], nil);
va_start(list, fmt);
NSString *msg = [[NSString alloc] initWithFormat:locFmtString arguments:list];
va_end(list);
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:msg forKey:NSLocalizedFailureReasonErrorKey];
[NSApp presentError:[NSError errorWithDomain:@"Unknown Domain" code:-1 userInfo:userInfo]];
[msg release];
}
void *SysLoadLibrary(const char *lib) {
NSBundle *bundle = [NSBundle bundleWithPath:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:lib length:strlen(lib)]];
if (bundle != nil) {
return dlopen([[bundle executablePath] fileSystemRepresentation], RTLD_LAZY /*RTLD_NOW*/);
}
return dlopen(lib, RTLD_LAZY);
}
void *SysLoadSym(void *lib, const char *sym) {
return dlsym(lib, sym);
}
const char *SysLibError() {
return dlerror();
}
void SysCloseLibrary(void *lib) {
dlclose(lib);
}
// Called periodically from the emu thread
void SysUpdate() {
PAD1_keypressed();
PAD2_keypressed();
[emuThread handleEvents];
}
// Returns to the Gui
void SysRunGui() {
if (powerAssertion != kIOPMNullAssertionID) {
IOPMAssertionRelease(powerAssertion);
powerAssertion = kIOPMNullAssertionID;
}
}
// Close mem and plugins
void SysClose() {
EmuShutdown();
ReleasePlugins();
if (powerAssertion != kIOPMNullAssertionID) {
IOPMAssertionRelease(powerAssertion);
powerAssertion = kIOPMNullAssertionID;
}
if (emuLog != NULL) fclose(emuLog);
sysInited = NO;
detachHotkeys();
}
void OnFile_Exit() {
SysClose();
exit(0);
}
const char* Pcsxr_locale_text(char* toloc){
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *origString = nil, *transString = nil;
origString = [NSString stringWithCString:toloc encoding:NSUTF8StringEncoding];
transString = [mainBundle localizedStringForKey:origString value:nil table:nil];
return [transString cStringUsingEncoding:NSUTF8StringEncoding];
}
|