4 // Created by Gil Pedersen on Fri Jun 06 2003.
5 // Copyright (c) 2003 SoftWorkz. All rights reserved.
8 #import <Cocoa/Cocoa.h>
9 #import <Carbon/Carbon.h>
12 //#import <sys/param.h>
14 #include "psxcommon.h"
17 static BOOL sysInited = NO;
20 int main(int argc, const char *argv[]) {
21 if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
22 char parentdir[MAXPATHLEN];
25 strncpy ( parentdir, argv[0], sizeof(parentdir) );
26 c = (char*) parentdir;
28 while (*c != '\0') /* go to end */
31 while (*c != '/') /* back up to parent */
34 *c++ = '\0'; /* cut off last part (binary name) */
36 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
37 assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
40 strcpy(Config.BiosDir, "Bios/");
41 strcpy(Config.PatchesDir, "Patches/");
43 // Setup the X11 window
44 if (getenv("DISPLAY") == NULL)
45 setenv("DISPLAY", ":0.0", 0); // Default to first local display
47 return NSApplicationMain(argc, argv);
54 emuLog = fopen("emuLog.txt","wb");
58 setvbuf(emuLog, NULL, _IONBF, 0);
67 if (LoadPlugins() == -1) {
71 LoadMcds(Config.Mcd1, Config.Mcd2);
81 void SysPrintf(const char *fmt, ...) {
86 vsprintf(msg, fmt, list);
89 if (Config.PsxOut) printf ("%s", msg);
92 fprintf(emuLog, "%s", msg);
97 void SysMessage(const char *fmt, ...) {
101 NSString *locFmtString = NSLocalizedString([NSString stringWithCString:fmt], nil);
104 vsprintf(msg, [locFmtString lossyCString], list);
107 NSRunAlertPanel(NSLocalizedString(@"Error!", nil),
108 [NSString stringWithCString:msg],
112 void *SysLoadLibrary(const char *lib) {
113 NSBundle *bundle = [NSBundle bundleWithPath:[NSString stringWithCString:lib]];
115 return dlopen([[bundle executablePath] fileSystemRepresentation], RTLD_LAZY /*RTLD_NOW*/);
117 return dlopen(lib, RTLD_LAZY);
120 void *SysLoadSym(void *lib, const char *sym) {
121 return dlsym(lib, sym);
124 const char *SysLibError() {
128 void SysCloseLibrary(void *lib) {
132 // Called periodically from the emu thread
134 UpdateSystemActivity(UsrActivity);
136 [emuThread handleEvents];
139 // Returns to the Gui
143 // Close mem and plugins
148 if (emuLog != NULL) fclose(emuLog);