void initSDL() { SDL_DisplayMode video_info; int init_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK; if(SDL_Init(init_flags) < 0) { printf("SDL Failed to Init!!!! (%s)\n", SDL_GetError()); borExit(0); } SDL_ShowCursor(SDL_DISABLE); atexit(SDL_Quit); #ifdef LOADGL if(SDL_GL_LoadLibrary(NULL) < 0) { printf("Warning: couldn't load OpenGL library (%s)\n", SDL_GetError()); } #endif SDL_GetCurrentDisplayMode(0, &video_info); nativeWidth = video_info.w; nativeHeight = video_info.h; printf("debug:nativeWidth, nativeHeight, bpp, Hz %d, %d, %d, %d\n", nativeWidth, nativeHeight, SDL_BITSPERPIXEL(video_info.format), video_info.refresh_rate); SDL_initFramerate(&framerate_manager); SDL_setFramerate(&framerate_manager, 200); }
void Menu() { int done = 0; int ctrl = 0; // Set video mode based on aspect ratio if(CONF_GetAspectRatio() == CONF_ASPECT_16_9) isWide = 1; setVideoMode(); drawLogo(); dListTotal = findPaks(); dListCurrentPosition = 0; if(dListTotal != 1) { sortList(); getAllLogs(); initMenu(1); drawMenu(); pControl = ControlMenu; while(!done) { ctrl = Control(); switch(ctrl) { case 1: case 2: done = 1; break; case 3: drawLogs(); break; case -1: drawMenu(); break; case -2: // BGM player isn't supported break; } } freeAllLogs(); termMenu(); if(ctrl == 2) { if (filelist) { free(filelist); filelist = NULL; } borExit(0); } } getBasePath(packfile, filelist[dListCurrentPosition+dListScrollPosition].filename, 1); free(filelist); }
// replacement for assert that writes the error to the log file void exitIfFalse(int value, const char *assertion, const char *func, const char *file, int line) { if(!value) { writeToLogFile("\n\n********** An Error Occurred **********" "\n* Shutting Down *\n\n"); writeToLogFile("Assertion `%s' failed in function '%s' at %s:%i.\n", assertion, func, file, line); writeToLogFile("This is an OpenBOR bug. Please report this at www.chronocrash.com.\n\n"); borExit(1); } }
void *checkAlloc(void *ptr, size_t size, const char *func, const char *file, int line) { if (size > 0 && ptr == NULL) { writeToLogFile("\n\n********** An Error Occurred **********" "\n* Shutting Down *\n\n"); writeToLogFile("Out of memory!\n"); writeToLogFile("Allocation of size %i failed in function '%s' at %s:%i.\n", size, func, file, line); #ifndef WIN writeToLogFile("Memory usage at exit: %u\n", mallinfo().arena); #endif borExit(2); } return ptr; }
void initSDL() { SDL_DisplayMode mode; int init_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK; const char *var = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY"); int vm; #ifdef CUSTOM_SIGNAL_HANDLER init_flags |= SDL_INIT_NOPARACHUTE; #endif if(SDL_Init(init_flags) < 0) { printf("SDL Failed to Init!!!! (%s)\n", SDL_GetError()); borExit(0); } SDL_ShowCursor(SDL_DISABLE); atexit(SDL_Quit); if ( !var ) { var = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD"); } if ( var ) { vm = SDL_atoi(var); } else { vm = 0; } // Store the monitor's current resolution before setting the video mode for the first time if(SDL_GetDesktopDisplayMode(vm, &mode) == 0) { nativeWidth = mode.w; nativeHeight = mode.h; } else { nativeWidth = 640; nativeHeight = 480; } savedata.fullscreen = 1; }
int gp2x_init() { #ifndef WIZ int gp2x_type; #endif gp2x_mem = open("/dev/mem", O_RDWR); gp2x_mixer = open("/dev/mixer", O_RDWR); #ifndef WIZ gp2x_memregl = (uint32_t*)mmap(0, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, gp2x_mem, 0xc0000000); gp2x_memregs = (uint16_t*)gp2x_memregl; gp2x_type = InitMemPool(); if(!gp2x_type || !gp2x_mem || !gp2x_mixer || !gp2x_memregl || !gp2x_memregs) { printf("GP2X Failed to Init!!!!\n"); borExit(0); } return gp2x_type; #else return 0; #endif }
int main(int argc, char *argv[]) { #ifndef SKIP_CODE char pakname[256]; #endif #ifdef CUSTOM_SIGNAL_HANDLER struct sigaction sigact; #endif #ifdef DARWIN char resourcePath[PATH_MAX]; CFBundleRef mainBundle; CFURLRef resourcesDirectoryURL; mainBundle = CFBundleGetMainBundle(); resourcesDirectoryURL = CFBundleCopyResourcesDirectoryURL(mainBundle); if(!CFURLGetFileSystemRepresentation(resourcesDirectoryURL, true, (UInt8 *) resourcePath, PATH_MAX)) { borExit(0); } CFRelease(resourcesDirectoryURL); chdir(resourcePath); #elif WII fatInitDefault(); #endif #ifdef CUSTOM_SIGNAL_HANDLER sigact.sa_sigaction = handleFatalSignal; sigact.sa_flags = SA_RESTART | SA_SIGINFO; if(sigaction(SIGSEGV, &sigact, NULL) != 0) { printf("Error setting signal handler for %d (%s)\n", SIGSEGV, strsignal(SIGSEGV)); exit(EXIT_FAILURE); } #endif setSystemRam(); initSDL(); packfile_mode(0); #ifdef ANDROID dirExists(rootDir, 1); chdir(rootDir); #endif dirExists(paksDir, 1); dirExists(savesDir, 1); dirExists(logsDir, 1); dirExists(screenShotsDir, 1); #ifdef ANDROID if(dirExists("/mnt/usbdrive/OpenBOR/Paks", 0)) strcpy(paksDir, "/mnt/usbdrive/OpenBOR/Paks"); else if(dirExists("/usbdrive/OpenBOR/Paks", 0)) strcpy(paksDir, "/usbdrive/OpenBOR/Paks"); else if(dirExists("/mnt/extsdcard/OpenBOR/Paks", 0)) strcpy(paksDir, "/mnt/extsdcard/OpenBOR/Paks"); #endif Menu(); #ifndef SKIP_CODE getPakName(pakname, -1); video_set_window_title(pakname); #endif openborMain(argc, argv); borExit(0); return 0; }