void init_sbv_patches() { sbv_patch_enable_lmb(); // Needed for loading ELFS from memory card sbv_patch_disable_prefix_check(); }
static int load_modules () { const char *STEP_OK = "*"; const char *FAILED = "failed to load with"; int ret, ipcfg_ret = 0; size_t i; const char *IPCONFIG_DAT_PATHS[] = { "mc0:/BIDATA-SYSTEM/IPCONFIG.DAT", /* japan */ "mc0:/BADATA-SYSTEM/IPCONFIG.DAT", /* us */ "mc0:/BEDATA-SYSTEM/IPCONFIG.DAT", /* europe */ "mc0:/SYS-CONF/IPCONFIG.DAT", /* old location */ NULL }; #if defined (LOAD_MRBROWN_PATCHES) sbv_patch_enable_lmb (); sbv_patch_disable_prefix_check (); scr_printf (STEP_OK); #endif #if defined (LOAD_SIOMAN_AND_MC) ret = SifLoadModule ("rom0:SIO2MAN", 0, NULL); if (ret > 0) scr_printf (STEP_OK); else { scr_printf ("\nrom0:SIO2MAN %s %d\n", FAILED, ret); return (-1); } ret = SifLoadModule ("rom0:MCMAN", 0, NULL); if (ret > 0) scr_printf (STEP_OK); else { scr_printf ("\nrom0:MCMAN %s %d\n", FAILED, ret); return (-1); } ret = SifLoadModule ("rom0:MCSERV", 0, NULL); if (ret > 0) scr_printf (STEP_OK); else { scr_printf ("\nrom0:MCSERV %s %d\n", FAILED, ret); return (-1); } #endif SifExecModuleBuffer (&iomanx_irx, size_iomanx_irx, 0, NULL, &ret); if (ret == 0) scr_printf (STEP_OK); else { scr_printf ("IOMANX.IRX %s %d\n", FAILED, ret); return (-1); } SifExecModuleBuffer (&ps2dev9_irx, size_ps2dev9_irx, 0, NULL, &ret); if (ret == 0) scr_printf (STEP_OK); else { scr_printf ("PS2DEV9.IRX %s %d\n", FAILED, ret); return (-1); } SifExecModuleBuffer (&ps2atad_irx, size_ps2atad_irx, 0, NULL, &ret); if (ret == 0) scr_printf (STEP_OK); else { scr_printf ("PS2ATAD.IRX %s %d\n", FAILED, ret); return (-1); } SifExecModuleBuffer (&ps2ip_irx, size_ps2ip_irx, 0, NULL, &ret); if (ret == 0) scr_printf (STEP_OK); else { scr_printf ("PS2IP.IRX %s %d\n", FAILED, ret); return (-1); } ipcfg_ret = -1; for (i = 0; ipcfg_ret != 0 && IPCONFIG_DAT_PATHS[i] != NULL; ++i) { ipcfg_ret = setup_ip (IPCONFIG_DAT_PATHS[i], if_conf, &if_conf_len); } SifExecModuleBuffer (&ps2smap_irx, size_ps2smap_irx, if_conf_len, if_conf, &ret); if (ret == 0) scr_printf (STEP_OK); else { scr_printf ("PS2SMAP.IRX %s %d\n", FAILED, ret); return (-1); } scr_printf ("\n"); switch (ipcfg_ret) { case 0: scr_printf ("\nusing %s\n", IPCONFIG_DAT_PATHS[i - 1]); break; case -1: scr_printf ("\nuse one of the following locations to set IP address:\n"); for (i = 0; IPCONFIG_DAT_PATHS[i] != NULL; ++i) scr_printf (" %s\n", IPCONFIG_DAT_PATHS[i]); break; case -2: scr_printf ("\nusing %s\n", IPCONFIG_DAT_PATHS[i - 1]); scr_printf ("\ninvalid configuration file format; use:\n" "ip_address network_mask gateway_ip\n" "separated by a single space; for example:" "192.168.0.10 255.255.255.0 192.168.0.1\n\n"); break; } scr_printf ("Playstation 2 IP address: %s\n", if_conf); return (0); }
static void frontend_ps2_init(void *data) { char cwd[FILENAME_MAX]; int bootDeviceID; SifInitRpc(0); #if !defined(DEBUG) /* Comment this line if you don't wanna debug the output */ while(!SifIopReset(NULL, 0)){}; #endif while(!SifIopSync()){}; SifInitRpc(0); sbv_patch_enable_lmb(); /* I/O Files */ SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, NULL, NULL); SifExecModuleBuffer(&fileXio_irx, size_fileXio_irx, 0, NULL, NULL); SifExecModuleBuffer(&freesio2_irx, size_freesio2_irx, 0, NULL, NULL); /* Memory Card */ SifExecModuleBuffer(&mcman_irx, size_mcman_irx, 0, NULL, NULL); SifExecModuleBuffer(&mcserv_irx, size_mcserv_irx, 0, NULL, NULL); /* Controllers */ SifExecModuleBuffer(&freemtap_irx, size_freemtap_irx, 0, NULL, NULL); SifExecModuleBuffer(&freepad_irx, size_freepad_irx, 0, NULL, NULL); /* USB */ SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, NULL); SifExecModuleBuffer(&usbhdfsd_irx, size_usbhdfsd_irx, 0, NULL, NULL); /* Audio */ SifExecModuleBuffer(&freesd_irx, size_freesd_irx, 0, NULL, NULL); SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, NULL, NULL); /* CDVD */ SifExecModuleBuffer(&cdvd_irx, size_cdvd_irx, 0, NULL, NULL); if (mcInit(MC_TYPE_XMC)) { RARCH_ERR("mcInit library not initalizated\n"); } /* Initializes audsrv library */ if (audsrv_init()) { RARCH_ERR("audsrv library not initalizated\n"); } /* Initializes pad libraries Must be init with 0 as parameter*/ if (mtapInit() != 1) { RARCH_ERR("mtapInit library not initalizated\n"); } if (padInit(0) != 1) { RARCH_ERR("padInit library not initalizated\n"); } if (mtapPortOpen(0) != 1) { RARCH_ERR("mtapPortOpen library not initalizated\n"); } /* Initializes CDVD library */ /* SCECdINoD init without check for a disc. Reduces risk of a lockup if the drive is in a erroneous state. */ sceCdInit(SCECdINoD); if (CDVD_Init() != 1) { RARCH_ERR("CDVD_Init library not initalizated\n"); } _init_ps2_io(); /* Prepare device */ getcwd(cwd, sizeof(cwd)); bootDeviceID=getBootDeviceID(cwd); waitUntilDeviceIsReady(bootDeviceID); #if defined(HAVE_FILE_LOGGER) retro_main_log_file_init("retroarch.log"); verbosity_enable(); #endif }
void InitPS2() { int i, sometime; static char hddarg[] = "-o" "\0" "4" "\0" "-n" "\0" "20"; static char pfsarg[] = "-m" "\0" "4" "\0" "-o" "\0" "10" "\0" "-n" "\0" "40"; SifInitRpc(0); // Reset IOP borrowed from uLaunchelf while (!SifIopReset(NULL, 0)){}; while (!SifIopSync()){}; SifInitRpc(0); sbv_patch_enable_lmb(); SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, NULL, NULL); SifExecModuleBuffer(&fileXio_irx, size_fileXio_irx, 0, NULL, NULL); SifExecModuleBuffer(&freesio2_irx, size_freesio2_irx, 0, NULL, NULL); /* SifLoadModule("rom0:XSIO2MAN", 0, NULL); SifLoadModule("rom0:XMCMAN", 0, NULL); SifLoadModule("rom0:XMCSERV", 0, NULL); SifLoadModule("rom0:XMTAPMAN", 0, NULL); SifLoadModule("rom0:XPADMAN", 0, NULL); */ SifExecModuleBuffer(&mcman_irx, size_mcman_irx, 0, NULL, NULL); SifExecModuleBuffer(&mcserv_irx, size_mcserv_irx, 0, NULL, NULL); SifExecModuleBuffer(&freemtap_irx, size_freemtap_irx, 0, NULL, NULL); SifExecModuleBuffer(&freepad_irx, size_freepad_irx, 0, NULL, NULL); #ifdef SOUND_ON SifExecModuleBuffer(&freesd_irx, size_freesd_irx, 0, NULL, NULL); SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, NULL, NULL); #endif SifExecModuleBuffer(&SMSUTILS_irx, size_SMSUTILS_irx, 0, NULL, NULL); SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, NULL); SifExecModuleBuffer(&usbhdfsd_irx, size_usbhdfsd_irx, 0, NULL, NULL); for (i = 0; i < 3; i++) { // Taken from ulaunchelf sometime = 0x01000000; while (sometime--) asm("nop\nnop\nnop\nnop"); } SifExecModuleBuffer(&poweroff_irx, size_poweroff_irx, 0, NULL, NULL); SifExecModuleBuffer(&ps2dev9_irx, size_ps2dev9_irx, 0, NULL, NULL); SifExecModuleBuffer(&ps2atad_irx, size_ps2atad_irx, 0, NULL, NULL); SifExecModuleBuffer(&ps2hdd_irx, size_ps2hdd_irx, sizeof(hddarg), hddarg, NULL); SifExecModuleBuffer(&ps2fs_irx, size_ps2fs_irx, sizeof(pfsarg), pfsarg, NULL); mcInit(MC_TYPE_XMC); #ifdef CDSUPPORT SifExecModuleBuffer(&cdvd_irx, size_cdvd_irx, 0, NULL, NULL); cdInit(CDVD_INIT_INIT); CDVD_Init(); #endif #ifdef SOUND_ON audsrv_init(); #endif mtapInit(); padInit(0); mtapPortOpen(0); }
int main(int argc, char *argv[]) #endif { #ifdef PSP SetupCallbacks(); scePowerSetClockFrequency(333, 333, 166); #endif for (int i=0; i<FLAG_COUNT; i++) { GAME_FLAGS[i] = false; } UNUSED(argc); string argvString = ""; #ifndef WII argvString = string(argv[0]); #else if (!fatInitDefault()) { printf("fatInitDefault ERROR #1"); std::fflush(stdout); timer.delay(500); exit(-1); } #endif get_filepath(); // fallback in case getcwd returns null if (FILEPATH.size() == 0) { std::cout << "Could not read path, fallback to using argv" << std::endl; FILEPATH = argvString.substr(0, argvString.size()-EXEC_NAME.size()); } std::cout << "main - argvString: '" << argvString << "', FILEPATH: '" << FILEPATH << "'" << std::endl; std::fflush(stdout); #ifdef PLAYSTATION2 std::cout << "PS2.DEBUG #1" << std::endl; std::fflush(stdout); #ifndef PS2LINK SifIopReset(NULL, 0); // clean previous loading of irx by apps like ulaunchElf. Comment this line to get cout on ps2link #endif printf("DEBUG.PS2 #1.1\n"); /* SP193: Being creative (Do something while waiting for the slow IOP to be reset). =D */ int main_id = GetThreadId(); ChangeThreadPriority(main_id, 72); std::cout << "PS2.DEBUG #1.1" << std::endl; std::fflush(stdout); printf("DEBUG.PS2 #1.2\n"); #ifndef PS2LINK while(SifIopSync()) { std::cout << "PS2.SifIopSync()" << std::endl; } #endif /* Initialize and connect to all SIF services on the IOP. */ SifInitRpc(0); SifInitIopHeap(); SifLoadFileInit(); fioInit(); printf("DEBUG.PS2 #1.3\n"); /* Apply the SBV LMB patch to allow modules to be loaded from a buffer in EE RAM. */ sbv_patch_enable_lmb(); // --- DEBUG --- // //FILEPATH = "cdfs:/"; // --- DEBUG --- // std::cout << "PS2.DEBUG #2" << std::endl; std::fflush(stdout); if (FILEPATH.find("mass:") != std::string::npos) { printf("DEBUG.PS2 #1.4\n"); std::cout << "PS2.DEBUG Load USB" << std::endl; std::fflush(stdout); PS2_load_USB(); } if (FILEPATH.find("cdfs") != std::string::npos || FILEPATH.find("cdrom") != std::string::npos) { printf("DEBUG.PS2 #1.5\n"); std::cout << "PS2.DEBUG Load CDROM" << std::endl; std::fflush(stdout); FILEPATH = "cdfs:"; PS2_load_CDROM(); } printf("DEBUG.PS2 #2\n"); std::cout << "PS2.DEBUG #3" << std::endl; std::fflush(stdout); #endif // check command-line paramethers if (argc > 1) { for (int i=1; i<argc; i++) { std::string temp_argv(argv[i]); if (temp_argv == "--fullscreen") { } else if (temp_argv == "--quickload") { GAME_FLAGS[FLAG_QUICKLOAD] = true; } else if (temp_argv == "--invencible") { // player have infinite HP GAME_FLAGS[FLAG_INVENCIBLE] = true; } else if (temp_argv == "--allweapons") { // player have all weapons available even if GAME_FLAGS[FLAG_ALLWEAPONS] = true; } else if (temp_argv == "--infinitejump") { // player can jump again and again GAME_FLAGS[FLAG_INFINITE_JUMP] = true; } } } std::cout << "PS2.DEBUG #7" << std::endl; std::fflush(stdout); //fio.check_conversion(); fio.read_game(game_data); //GAME_FLAGS[FLAG_INFINITE_HP] = true; // DEBUG gameControl.get_drop_item_ids(); soundManager.init_audio_system(); // PS2 version have to load config AFTER SDL_Init due to SDK issues #ifdef LINUX SAVEPATH = std::string(getenv("HOME")) + "/.rockbot/"; mkdir(SAVEPATH.c_str(), 0777); //std::cout << "SAVEPATH: " << SAVEPATH << ", mkdir-res: " << res << ", errno: " << errno << std::endl; #elif WIN32 SAVEPATH = std::string(getenv("APPDATA")) + "/rockbot"; std::cout << "SAVEPATH: " << SAVEPATH << std::endl; _mkdir(SAVEPATH.c_str()); #else SAVEPATH = FILEPATH; #endif #ifndef PLAYSTATION2 fio.load_config(game_config); #endif // INIT GRAPHICS if (graphLib.initGraphics() != true) { printf("ERROR intializing graphic\n"); return -1; } // define SAVEPATH #ifdef PLAYSTATION2 PS2_load_MC(); SAVEPATH = "mc0:Rockbot/"; if (fioMkdir(SAVEPATH.c_str()) < 0) { std::cout << "main - warning: could not create '" << SAVEPATH << "' folder" << std::endl; std::fflush(stdout); /// @TODO - check if directory exists } else { std::cout << "Folder '" << SAVEPATH << "' created" << std::endl; std::fflush(stdout); } #endif have_save = fio.save_exists(); #ifndef DEBUG_OUTPUT // redirect output to null std::string cout_file = "/dev/null"; std::ofstream out(cout_file.c_str()); std::cout.rdbuf(out.rdbuf()); #else // --- REDIRECT STDOUT TO A FILE --- // #if defined(PSP) || defined(WII) || defined(ANDROID) || defined(DINGUX) || defined(PLAYSTATION2) //std::string cout_file = SAVEPATH + "/stdout.txt"; std::string cout_file = FILEPATH + "/stdout.txt"; std::streambuf *coutbuf = std::cout.rdbuf(); std::ofstream out(cout_file.c_str()); std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt! #endif #endif graphLib.preload(); #ifdef PLAYSTATION2 fio.load_config(game_config); PS2_create_save_icons(); #endif draw_lib.preload(); gameControl.currentStage = APEBOT; // INIT GAME if (GAME_FLAGS[FLAG_QUICKLOAD] == false) { if (gameControl.showIntro() == false) { std::cout << "ERROR SHOWING INTRO" << std::endl; return 0; } } else { gameControl.quick_load_game(); //ending end_obj; //end_obj.start(); //return 1; } input.clean(); input.p1_input[BTN_START] = 0; input.waitTime(200); input.clean(); bool run_game = true; while (run_game) { #if !defined(PSP) && !defined(DINGUX) timer.start_ticker(); #endif #ifdef PLAYSTATION2 RotateThreadReadyQueue(_MIXER_THREAD_PRIORITY); #endif gameControl.showGame(); #ifdef DEBUG_SHOW_FPS gameControl.fps_count(); #endif draw_lib.update_screen(); if (input.p1_input[BTN_QUIT] == 1) { //std::cout << "LEAVE #3" << std::endl; std::fflush(stdout); gameControl.leave_game(); } unsigned int now_ticks = timer.get_ticks(); if (now_ticks < (1000 / FRAMES_PER_SECOND)) { timer.delay((1000 / FRAMES_PER_SECOND) - now_ticks); } } /// @TODO: sdl quit sub-systems #ifdef PSP sceKernelExitGame(); return 0; #else SDL_Quit(); #endif return 1; }
int loadLoaderModules(int debug_mode, int disable_cdrom) { static int load_dvd_config = -1; static int load_netsurf_config = -1; static int load_usb_config = -1; int i; int rv; int lrv = -1; if (debug_mode == 1) { /* Network is used by ps2link and can't be used by Linux. */ network_support = 0; } #ifdef RESET_IOP if (debug_mode == -1) { graphic_setStatusMessage("Flushing cache"); FlushCache(0); graphic_setStatusMessage("Exit IOP Heap"); SifExitIopHeap(); graphic_setStatusMessage("Exit LoadFile"); SifLoadFileExit(); graphic_setStatusMessage("Exit FIO"); fioExit(); graphic_setStatusMessage("Exit RPC"); SifExitRpc(); graphic_setStatusMessage("Stop DMA"); SifStopDma(); graphic_setStatusMessage("PreReset Init RPC"); SifInitRpc(0); graphic_setStatusMessage("Reseting IOP"); while(!SifIopReset(s_pUDNL, 0)); graphic_setStatusMessage("IOP Sync"); while (!SifIopSync()); graphic_setStatusMessage("Initialize RPC"); SifInitRpc(0); } #endif graphic_setStatusMessage("Patching enable LMB"); sbv_patch_enable_lmb(); graphic_setStatusMessage("Patching disable prefix check"); sbv_patch_disable_prefix_check(); /* CDVDMAN is loaded by IopReset and NVRAM can be read. */ graphic_setStatusMessage("Read NVRAM from CDVD"); if (!disable_cdrom) { nvram_init(); } eromdrvSupport = 0; /* FIXME: eedebug handler seems to crash the ee graphic_setStatusMessage("Add eedebug handler"); addEEDebugHandler(); */ graphic_setStatusMessage("Loading modules"); for (i = 0; i < moduleLoaderNumberOfModules; i++) { const rom_entry_t *romfile; if (moduleList[i].debug_mode != 0) { if (moduleList[i].debug_mode != debug_mode) { continue; } } /* Load configuration when necessary modules are loaded. */ if (moduleList[i].loadCfg) { checkForMusicSupport(); setDefaultConfiguration(NULL); lrv = loadConfiguration(CONFIG_FILE); changeMode(); /* Load configuration on startup and not on IOP reset. */ moduleList[i].loadCfg = 0; } graphic_setStatusMessage(moduleList[i].path); kprintf("Loading module (%s)\n", moduleList[i].path); if (!network_support) { if (moduleList[i].network) { continue; } } if (moduleList[i].ps2smap) { moduleList[i].args = getPS2MAPParameter(&moduleList[i].argLen); } if (moduleList[i].dns) { moduleList[i].args = getPS2DNS(&moduleList[i].argLen); } if (moduleList[i].checkMc) { static char file[256]; /* Try to load module from MC if available. */ snprintf(file, sizeof(file), CONFIG_DIR "/%s", moduleList[i].path); rv = SifLoadModule(file, moduleList[i].argLen, moduleList[i].args); } else { rv = -1; } if (rv < 0) { if ((moduleList[i].sms_mod == 0) || (isDVDVSupported())) { if (moduleList[i].eromdrv < 0) { /* Try to detect EROM driver only the first time. */ moduleList[i].eromdrv = 1; if (disable_cdrom) { continue; } rv = open("rom1:EROMDRV", O_RDONLY); if (rv >=0 ) { eromdrvpath[12] = 0; /* This is an old fat PS2 (working with SCPH-50004 and SCPH-39004). */ close(rv); } else { const u8 *nvm; nvm = get_nvram(); if (nvm_errors == 0) { /* NVM layout seems to be correct. */ eromdrvpath[12] = nvm[NVM_REAL_REGION]; rv = open(eromdrvpath, O_RDONLY); if (rv >=0 ) { /* Region code seems to be correct. */ close(rv); } else { error_printf("The region code stored in the NVRAM S%02x T%02x F%02x R%02x " "can't be detected by version string %s (%s).", nvm[0x180], nvm[0x181], nvm[NVM_FAKE_REGION], nvm[NVM_REAL_REGION], ps2_rom_version); continue; } } else { error_printf("%d errors when reading NVRAM. Please set path " "to EROMDRV and reload modules.", nvm_errors); continue; } } } if (moduleList[i].eromdrv != 0) { moduleList[i].args = get_eromdrvpath(); moduleList[i].argLen = strlen(moduleList[i].args) + 1; } romfile = rom_getFile(moduleList[i].path); if (romfile != NULL) { int ret; ret = SifExecModuleBuffer((void *) romfile->start, romfile->size, moduleList[i].argLen, moduleList[i].args, &rv); if (ret < 0) { rv = ret; } } else { rv = SifLoadModule(moduleList[i].path, moduleList[i].argLen, moduleList[i].args); } if (rv < 0) { if (moduleList[i].eromdrv != 0) { kprintf("Failed to load module \"%s\".\n", get_eromdrvpath()); } else { kprintf("Failed to load module \"%s\".\n", moduleList[i].path); } if (moduleList[i].ps2smap && !isSlimPSTwo()) { network_support = 0; } else { if (moduleList[i].eromdrv != 0) { error_printf("Failed to load module \"%s\".", get_eromdrvpath()); } else { error_printf("Failed to load module \"%s\".", moduleList[i].path); } } } else { if (moduleList[i].eromdrv != 0) { eromdrvSupport = -1; } } } } } graphic_setStatusMessage(NULL); printAllModules(); fileXioInit(); if (load_netsurf_config) { load_netsurf_config = 0; if (lrv != 0) { graphic_setStatusMessage("Check for NetSurf config"); lrv = loadConfiguration(PS2NS_CONFIG_FILE); graphic_setStatusMessage(NULL); } } if (load_usb_config) { load_usb_config = 0; if (lrv != 0) { graphic_setStatusMessage("Check for USB config"); lrv = loadConfiguration(USB_CONFIG_FILE); graphic_setStatusMessage(NULL); } } if (load_dvd_config && isDVDVSupported()) { load_dvd_config = 0; graphic_setStatusMessage("Init DVD driver"); CDDA_Init(); CDVD_Init(); if (lrv != 0) { DiskType type; graphic_setStatusMessage("Load config from DVD"); type = CDDA_DiskType(); if (type == DiskType_DVDV) { CDVD_SetDVDV(1); } else { CDVD_SetDVDV(0); } kprintf("kloader disc type %u\n", type); switch (type) { case DiskType_CD: case DiskType_DVD: case DiskType_DVDV: /* Load configuration from disc. */ lrv = loadConfiguration(DVD_CONFIG_FILE); changeMode(); #if 0 if (lrv != 0) { error_printf("Failed to load config from \"%s\", using default configuration.", DVD_CONFIG_FILE); } #endif break; default: kprintf("kloader unsupported disc type %u\n", type); break; } /* Stop CD when finished. */ CDVD_Stop(); CDVD_FlushCache(); } graphic_setStatusMessage(NULL); } snprintf(hardware_information, sizeof(hardware_information), "%s with DVD-R %s, %s sound support and %s network adapter", isSlimPSTwo() ? "slim PSTwo" : "fat PS2", disable_cdrom ? "disabled" : (isDVDVSupported() ? "support" : "problem"), (libsd_version <= 0x104) ? "direct" : "indirect", network_support ? "with" : "without"); return 0; }