diff options
| author | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2009-06-09 11:34:52 +0000 |
|---|---|---|
| committer | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2009-06-09 11:34:52 +0000 |
| commit | 10eac4b4928e7dd9f79de454641889f2a0b77250 (patch) | |
| tree | 0f9c98f659552ed2406a6159bc123889ca46b919 /macosx/main.m | |
| parent | 568526e291e9743751d8632327b94e01e7181efc (diff) | |
| download | pcsxr-10eac4b4928e7dd9f79de454641889f2a0b77250.tar.gz | |
added prelimiary Mac OS X port (still not working)
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@23667 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/main.m')
| -rw-r--r-- | macosx/main.m | 250 |
1 files changed, 250 insertions, 0 deletions
diff --git a/macosx/main.m b/macosx/main.m new file mode 100644 index 00000000..472ba4a0 --- /dev/null +++ b/macosx/main.m @@ -0,0 +1,250 @@ +// +// 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" + +int sysInited = 0; +long LoadCdBios; + +//#define EMU_LOG + +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 */ + } + + // TODO: make this redundant + strcpy(Config.BiosDir, "Bios/"); + + // 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) + return 0; + +#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 + + if (psxInit() != 0) + return -1; + + while (LoadPlugins() == -1) { + return -1; + //CancelQuit = 1; + //ConfigurePlugins(); + //CancelQuit = 0; + } + + LoadMcds(Config.Mcd1, Config.Mcd2); + + sysInited = 1; + + return 0; +} + +void SysReset() { + [EmuThread resetNow]; + //psxReset(); +} + +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", msg); +#ifdef EMU_LOG +#ifndef LOG_STDOUT + fprintf(emuLog, "%s", msg); +#endif +#endif +} + +void SysMessage(char *fmt, ...) +{ + va_list list; + char msg[512]; + + NSString *locFmtString = NSLocalizedString([NSString stringWithCString:fmt], nil); + + va_start(list, fmt); + vsprintf(msg, [locFmtString lossyCString], list); + va_end(list); + + NSRunAlertPanel(NSLocalizedString(@"Error!", nil), + [NSString stringWithCString:msg], + nil, nil, nil); +} + +#if 1 +void *SysLoadLibrary(char *lib) { + NSBundle *bundle = [NSBundle bundleWithPath:[NSString stringWithCString:lib]]; + if (bundle != nil) { + return dlopen([[bundle executablePath] fileSystemRepresentation], RTLD_LAZY /*RTLD_NOW*/); + } + return dlopen(lib, RTLD_LAZY); +} + +void *SysLoadSym(void *lib, char *sym) { + return dlsym(lib, sym); +} + +const char *SysLibError() { + return dlerror(); +} + +void SysCloseLibrary(void *lib) { + //dlclose(lib); +} +#else +static int LoadResult = 0; +void *SysLoadLibrary(char *lib) +{ + CFBundleRef myBundle; + CFURLRef bundleURL; + CFStringRef path; + + path = CFStringCreateWithCString(kCFAllocatorDefault, lib, CFStringGetSystemEncoding()); + if (!path) + goto error; + + bundleURL = CFURLCreateWithFileSystemPath( + kCFAllocatorDefault, + path, + kCFURLPOSIXPathStyle, + true ); + if (!bundleURL) + goto error; + + myBundle = CFBundleCreate( kCFAllocatorDefault, bundleURL ); + + if (!CFBundleLoadExecutable(myBundle)) + goto error; + +good: + if (path) CFRelease(path); + if (bundleURL) CFRelease(bundleURL); + + return myBundle; + +error: + if (LoadResult == 0) LoadResult = -1; + myBundle = NULL; + goto good; +} + +void *SysLoadSym(void *lib, char *sym) +{ + CFStringRef funcName; + void *func; + + funcName = CFStringCreateWithCString(kCFAllocatorDefault, sym, CFStringGetSystemEncoding()); + func = CFBundleGetFunctionPointerForName((CFBundleRef)lib, funcName); + if (func == nil) { + LoadResult = -2; + } + + CFRelease(funcName); + return func; +} + +const char *SysLibError() +{ + char *result = NULL; + + if (LoadResult != 0) + result = "Error loading code"; + + LoadResult = 0; + return result; +} +void SysCloseLibrary(void *lib) +{ + if (lib) { + CFBundleUnloadExecutable((CFBundleRef)lib); + CFRelease((CFBundleRef)lib); + } +} +#endif + +void PADhandleKey(int key); + +// Called periodically from the emu thread +void SysUpdate() +{ + UpdateSystemActivity(UsrActivity); + + PADhandleKey(PAD1_keypressed()); + //PADhandleKey(PAD2_keypressed()); + + [emuThread handleEvents]; +} + +void SysRunGui() // Returns to the Gui +{ + +} +void SysClose() // Close mem and plugins +{ + psxShutdown(); + ReleasePlugins(); + + if (emuLog != NULL) fclose(emuLog); + + sysInited = false; +} + +void OnFile_Exit() +{ + SysClose(); + exit(0); +}
\ No newline at end of file |
