Example #1
0
bool loadIOS(int ios, bool MountDevices)
{
	int CurIOS = IOS_GetVersion();
	bool ret = true;

	if(ios != CurIOS && IOS_GetType(ios) != IOS_TYPE_STUB)
	{
		WDVD_Close();
		gprintf("Reloading into IOS %i from %i...\n", ios, CurIOS);
		ShutdownBeforeExit();
		NandHandle.Patch_AHB(); //No AHBPROT for the next IOS
		ret = IOS_ReloadIOS(ios) == 0;
		gprintf("AHBPROT after IOS Reload: %u\n", AHBRPOT_Patched());
		NandHandle.Init_ISFS();
		WDVD_Init();
	}

	IOS_GetCurrentIOSInfo();
	if(CurrentIOS.Type == IOS_TYPE_HERMES)
		load_ehc_module_ex();
	else if(CurrentIOS.Type == IOS_TYPE_WANIN && CurrentIOS.Revision >= 18)
		load_dip_249();
	DeviceHandle.SetModes();
	if(MountDevices && ios != CurIOS)
		DeviceHandle.MountAll();

	return ret;
}
int main(int argc, char **argv)
{
	/* Load Custom IOS */
	IOS_ReloadIOS(249);

	/* Initialize subsystems */
	Sys_Init();

	/* Set video mode */
	Video_SetMode();

	/* Initialize console */
	Gui_InitConsole();

	/* Draw background */
	Gui_DrawBackground();

	/* Initialize Wiimote subsystem */
	Wpad_Init();

	/* Initialize disc subsystem */
	Disc_Init();

	/* Mount SD card */
	Fat_MountSD();

	/* Menu loop */
	Menu_Loop();

	/* Restart */
	Restart();

	return 0;
}
Example #3
0
int main(int argc, char **argv)
{
    //DEBUG_Init(GDBSTUB_DEVICE_USB, 1);
    s8 ios_patched = 0;
    s32 ret = 0;

    CheckForGecko();
    VIDEO_Init();

    vmode = VIDEO_GetPreferredMode(NULL);
    xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode));

    VIDEO_Configure(vmode);
    VIDEO_SetNextFramebuffer(xfb);
    VIDEO_SetBlack(false);
    VIDEO_Flush();

    VIDEO_WaitVSync();
    if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();

    int x = 20, y = 20, w, h;
    w = vmode->fbWidth - (x * 2);
    h = vmode->xfbHeight - (y + 20);

    // Initialize the console
    //Con_InitEX works better but for some odd reason doesn't show right when clearing screen...
    //CON_InitEx(vmode, x, y, w, h);
    CON_Init(xfb,x,y,w,h, vmode->fbWidth*VI_DISPLAY_PIX_SZ );
    printf("\n\n\n");
    VIDEO_ClearFrameBuffer(vmode, xfb, COLOR_BLACK);

    gprintf("resolution is %dx%d\n",vmode->viWidth,vmode->viHeight);
    //printf("\x1b[2J");
    /*sleep(3);
    gprintf("crashing...\n");
    free((void*)0x1);*/
    /*free((void*)0x1);
    free((void*)0x1);
    free((void*)0x1);
    memcpy((void*)0x0,(void*)0x1,5);*/
    //return 0;
    //reload ios so that IF the user started this with AHBPROT we lose everything from HBC. also, IOS36 is the most patched ios :')
    IOS_ReloadIOS(36);

    WPAD_Init();
    PAD_Init();

    printf("\nIOS %d rev %d\n\n",IOS_GetVersion(),IOS_GetRevision());
    if( (VERSION&0xFF) % 10 == 0 )
    {
#if BETAVERSION > 0
        printf("Priiloader v%d.%db%d(r0x%08x) Installation/Removal Tool\n\n\n\n\t",VERSION>>8, (VERSION&0xFF) / 10,BETAVERSION,GIT_REV);
#else
        printf("\t\tPriiloader v%d.%d(r0x%08x) Installation / Removal Tool\n\n\n\n\t",VERSION>>8, (VERSION&0xFF) / 10,GIT_REV);
#endif
    }
Example #4
0
static void frontend_gx_init(void *data)
{
   (void)data;
#ifdef HW_RVL
   IOS_ReloadIOS(IOS_GetVersion());
   L2Enhance();
#ifndef IS_SALAMANDER
   gx_init_mem2();
#endif
#endif

#if defined(DEBUG) && defined(IS_SALAMANDER)
   VIDEO_Init();
   GXRModeObj *rmode = VIDEO_GetPreferredMode(NULL);
   void *xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
   console_init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ);
   VIDEO_Configure(rmode);
   VIDEO_SetNextFramebuffer(xfb);
   VIDEO_SetBlack(FALSE);
   VIDEO_Flush();
   VIDEO_WaitVSync();
   VIDEO_WaitVSync();
#endif

#ifndef DEBUG
   __exception_setreload(8);
#endif

   fatInitDefault();

#ifdef HAVE_LOGGER
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_net;
#elif defined(HAVE_FILE_LOGGER) && !defined(IS_SALAMANDER)
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_file;
#endif

#if defined(HW_RVL) && !defined(IS_SALAMANDER)
   OSThread gx_device_thread;
   gx_devices[GX_DEVICE_SD].interface = &__io_wiisd;
   gx_devices[GX_DEVICE_SD].name = "sd";
   gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface);
   gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage;
   gx_devices[GX_DEVICE_USB].name = "usb";
   gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface);

   OSInitMutex(&gx_device_cond_mutex);
   OSInitCond(&gx_device_cond);
   OSInitMutex(&gx_device_mutex);
   OSCreateThread(&gx_device_thread, gx_devthread, 0, NULL, NULL, 0, 66, 0);
#endif
}
int main(int argc, char **argv)
{
	s32 ret;

	/* Load Custom IOS */
	ret = IOS_ReloadIOS(249);

	/* Initialize subsystems */
	Sys_Init();

	/* Set video mode */
	Video_SetMode();

	/* Initialize console */
	Gui_InitConsole();

	/* Draw bckground */
	Gui_DrawBackground();

	/* Initialize Wiimote subsystem */
	Wpad_Init();

	/* Check for Custom IOS */
	if (ret < 0) {
		printf("[+] ERROR: Could not load Custom IOS! (ret = %d)\n", ret);
		goto out;
	}

	/* Initialize ISFS */
	ret = ISFS_Initialize();
	if (ret < 0) {
		printf("[+] ERROR: Could not initialize ISFS! (ret = %d)\n", ret);
		goto out;
	}

	/* Mount ISFS */
	ret = ISFS_Mount();
	if (ret < 0) {
		printf("[+] ERROR: Could not mount ISFS! (ret = %d)\n", ret);
		goto out;
	}

	/* Menu loop */
	Menu_Loop();

out:
	/* Restart */
	Restart_Wait();

	return 0;
}
Example #6
0
int main(int argc, char *argv[]) 
{
	/* INITIALIZE */
#ifdef HW_RVL
	DI_UseCache(false);
	if (!__di_check_ahbprot()) {
		s32 preferred = IOS_GetPreferredVersion();
		if (preferred == 58 || preferred == 61)
			IOS_ReloadIOS(preferred);
		else DI_LoadDVDX(true);
	}
	
	DI_Init();    // first
#endif
	
	loadSettings(argc, argv);
	MenuContext *menu = new MenuContext(vmode);
	VIDEO_SetPostRetraceCallback (ScanPADSandReset);

#ifndef WII
	DVD_Init();
#endif

#ifdef DEBUGON
	//DEBUG_Init(GDBSTUB_DEVICE_TCP,GDBSTUB_DEF_TCPPORT); //Default port is 2828
	DEBUG_Init(GDBSTUB_DEVICE_USB, 1);
	_break();
#endif

	control_info_init(); //Perform controller auto assignment at least once at startup.

	// Start up AESND (inited here because its used in SPU and CD)
	AESND_Init();

#ifdef HW_RVL
	// Initialize the network if the user has specified something in their SMB settings
	if(strlen(&smbShareName[0]) && strlen(&smbIpAddr[0])) {
	  init_network_thread();
  }
#endif
	
	while (menu->isRunning()) {}
	
	// Shut down AESND
	AESND_Reset();

	delete menu;

	return 0;
}
Example #7
0
void Sys_Exit(void)
{
    if(return_to_disable) return;

    /* Shutdown Inputs */
    Close_Inputs();

    if (return_to_menu || return_to_priiloader) Sys_LoadMenu();
    else if(return_to_bootmii) IOS_ReloadIOS(254);
    if(WII_LaunchTitle(HBC_108)<0)
        if(WII_LaunchTitle(HBC_HAXX)<0)
            if(WII_LaunchTitle(HBC_JODI)<0)
                SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
}
Example #8
0
static void DoMini(u8* kbuf, size_t kernel_size)  
	{  
	kernel_size +=3;
	kernel_size &= 0xFFFFFFFC;		

	u8* mini = (u8*) memalign( 32, armboot_bin_size + kernel_size + 4 );  

	if( !mini )  
		{  
		Debug( "Cannot allocate mini buffer %d, %d", armboot_bin_size, kernel_size);  
		return;  
		}  
	Debug( "mini buffer: %p", mini );  

	memcpy( mini, kbuf, kernel_size);
	DCFlushRange( mini, kernel_size );  
	free(kbuf);
	
	memcpy( mini+kernel_size+4, armboot_bin, armboot_bin_size );  
	DCFlushRange( mini+kernel_size+4, armboot_bin_size );  

	Debug( "armboot.bin copied" );  
	*(u32*)0xc150f000 = 0x424d454d;  
	asm volatile( "eieio" );  

	// physical address for armboot.bin.  ( virtualToPhysical() )  
	*(u32*)0xc150f004 = MEM_VIRTUAL_TO_PHYSICAL( mini+kernel_size+4 );  

	asm volatile( "eieio" );  

	Debug( "physical memory address: %08x", MEM_VIRTUAL_TO_PHYSICAL( mini ) );  
	Debug( "loading bootmii IOS" );  

	// pass position of kernel.bin to mini		
	*(u32*)0x8132FFF0 = MEM_VIRTUAL_TO_PHYSICAL( mini );
	asm volatile( "eieio" );  
	DCFlushRange((void*)0x8132FFF0,4);

	// pass length of kernel.bin to mini        
	*(u32*)0x8132FFF4 = kernel_size;
	asm volatile( "eieio" );  
	DCFlushRange((void*)0x8132FFF4,4);

	IOS_ReloadIOS( 0xfe );  

	Debug( "well shit.  this shouldnt happen" );  

	free( mini );  
	}
Example #9
0
void loadStartupIOS()
{
	if (!startupiosloaded)
	{
		sdio_Shutdown();
		if (IOS_GetVersion() != 36) IOS_ReloadIOS(36);
		detectIOScapabilities();
		
		if (!identifyworks && !isIOSstub(249) && IOS_ReloadIOS(249) >= 0)
			detectIOScapabilities();
		
		if (!identifyworks && IOS_ReloadIOS(35) >= 0)
			detectIOScapabilities();
		
		if (!identifyworks)
		{
			IOS_ReloadIOS(36);
			disableRebooter = 1;
		}
		
		sd_init();
		startupiosloaded = 1;
	}
}
Example #10
0
void detectIOScapabilities()
{
	if (!(identifyworks = DIVerify_works()) || identify_SU() < 0 || !DIVerify_works())
	{
		if (identifyworks)
		{
			menu_generatechannellist(TRUE);	// DIVerify seems to be slightly broken, try to workaround the problem
			IOS_ReloadIOS(IOS_GetVersion()); // Reset IOS, needed for some buggy cIOS versions
			buggycIOS = 1;
			identifyworks = (channellist_menu_items > 0);
		}
	}
	if (IOS_GetVersion() == 249 && IOS_GetRevision() > 7 && IOS_GetRevision() < 14)
		disableRebooter = 1;
	else
		disableRebooter = 0;
}
Example #11
0
int Sys_IosReload(int IOS) {
    s32 ret = -1;

    //shutdown SD and USB before IOS Reload in DiscWait
    SDCard_deInit();
    USBDevice_deInit();

    WPAD_Flush(0);
    WPAD_Disconnect(0);
    WPAD_Shutdown();

    WDVD_Close();

    USBStorage_Deinit();

    if (IOS == 249 || IOS == 222 || IOS == 223) {
        int i;
		for (i = 0; i < 10; i++) {
            ret = IOS_ReloadIOS(IOS);
            if (ret < 0) return ret;
            if (IOS == 222 || IOS == 223) load_ehc_module();
            ret = WBFS_Init(WBFS_DEVICE_USB);
            if (!(ret < 0)) break;
            sleep(1);
            USBStorage_Deinit();
        }
        if (ret>=0) {
            ret = Disc_Init();
            if (ret>=0) {
                ret = WBFS_Open();
            }
        } else Sys_BackToLoader();
    }

    PAD_Init();
    Wpad_Init();
    WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
//    WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
    //reinitialize SD and USB
    SDCard_Init();
    USBDevice_Init();

    return ret;
}
Example #12
0
static void system_init(void)
{
#ifdef HW_RVL
   IOS_ReloadIOS(IOS_GetVersion());
   L2Enhance();
#ifndef IS_SALAMANDER
   gx_init_mem2();
#endif
#endif

#ifndef DEBUG
   __exception_setreload(8);
#endif

   fatInitDefault();

#ifdef HAVE_LOGGER
   inl_logger_init();
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_net;
#elif defined(HAVE_FILE_LOGGER)
   inl_logger_init();
#ifndef IS_SALAMANDER
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_file;
#endif
#endif

#if defined(HW_RVL) && !defined(IS_SALAMANDER)
   lwp_t gx_device_thread;
   gx_devices[GX_DEVICE_SD].interface = &__io_wiisd;
   gx_devices[GX_DEVICE_SD].name = "sd";
   gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface);
   gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage;
   gx_devices[GX_DEVICE_USB].name = "usb";
   gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface);
   LWP_MutexInit(&gx_device_mutex, false);
   LWP_CreateThread(&gx_device_thread, gx_devthread, NULL, NULL, 0, 66);
#endif
}
Example #13
0
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	// Initialise the video system
	VIDEO_Init();
	Video_SetMode();

	WPAD_Init();
	PAD_Init();

   	if(AHBPROT_DISABLED)
		IosPatch_RUNTIME(true, false, false, true);
	else
		IOS_ReloadIOS(236);

	menu();

	signed_blob *p_tmd = NULL;
	u32 len;
	s32 ret;

	ret = GetTMD(0x0001000154484246LL, &p_tmd, &len);

	if(ret < 0)
	{
		*(vu32*)0x8132FFFB = 0x50756E65;
		DCFlushRange((void*)0x8132FFFB, 4);
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	}
	else
	{
		WII_LaunchTitle(0x0001000154484246);

	}

	return 0;
}
Example #14
0
s32 IOS_ReloadIOSsafe(int ios)
{
	if (ios==222)
	{
		if (ios222rev == -69)
			ios222rev = getIOSrev(0x00000001000000dell);

		if (ios222rev > 0 && (ios222rev != 4 && ios222rev != 5))return -2;
	}
	else if (ios==223)
	{
		if (ios223rev == -69)
			ios223rev = getIOSrev(0x00000001000000dfll);

		if (ios223rev > 0 && (ios223rev != 4 && ios223rev != 5))return -2;
	}
	else if (ios==249)
	{
		if (ios249rev == -69)
			ios249rev = getIOSrev(0x00000001000000f9ll);

		if (ios249rev >= 0 && !(ios249rev>=9 && ios249rev<65280))return -2;
	}
	else if (ios==250)
	{
		if (ios250rev == -69)
			ios250rev = getIOSrev(0x00000001000000fall);

		if (ios250rev >= 0 && !(ios250rev>=9 && ios250rev<65280))return -2;
	}

	s32 r = IOS_ReloadIOS(ios);
	if (r >= 0) {
		WII_Initialize();
	}
	return r;
}
Example #15
0
void KeepAccessRightsAndReload(s32 ios, bool verbose)
{
	s32 ret;
	
	if (AHBPROT_DISABLED)
	{
		/* There should be nothing to worry about if this fails, as long as the new IOS is patched */
		if (verbose) printf("\t- Patching IOS%ld to keep hardware access rights... ", IOS_GetVersion());
		ret = IosPatch_AHBPROT(false);
		if (verbose) printf("%s.\n", (ret < 0 ? "FAILED" : "OK"));
	}
	
	if (verbose) printf("\t- Reloading to IOS%ld... ", ios);
	WUPC_Shutdown();
	WPAD_Shutdown();
	IOS_ReloadIOS(ios);
	//sleep(2);
	PAD_Init();
	WUPC_Init();
	WPAD_Init();
	WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
	if (verbose) printf("done.");
	
	if (AHBPROT_DISABLED)
	{
		if (verbose) printf("\n\t- Applying runtime patches to IOS%ld... ", IOS_GetVersion());
		ret = IosPatch_RUNTIME(true, false, vwii, false);
		if (verbose) printf("%s.\n", (ret < 0 ? "FAILED" : "OK"));
	}
	
	if (IsHermesIOS(ios))
	{
		mload_Init();
		if (verbose) printf("\n\t- Hermes cIOS detected! ehcmodule loaded through mload.");
	}
}
int BootHomebrew()
{

    char* abuf;
    size_t asize;

    if(homebrewsize == 0)
        return -1;

    entrypoint entry;
    u32 cpu_isr;

	arg_init();

	if (wiiload_args)
	{
		abuf = temp_arg;
		asize = strlen(abuf);
		while (asize != 0)
		{
			xprintf("argument = %s\n",abuf);
			arg_add(abuf);
			abuf+=asize;
			abuf+=1;
			asize = strlen(abuf);
		}
	}
	else
	{
		arg_add(filepath.c_str()); // argv[0] = filepath
		while(parser(Settings.forwarder_arg, "<arg>", "</arg>") != "")
		{
			arg_add(parser(Settings.forwarder_arg, "<arg>", "</arg>").c_str());
			Settings.forwarder_arg.erase(0, Settings.forwarder_arg.find("</arg>") +1);
		}
	}

	if ( valid_elf_image(homebrewbuffer) == 1 )
		entry = (entrypoint) load_elf_image(homebrewbuffer);
	else
		entry = (entrypoint) load_dol(homebrewbuffer, &args);

    if (!entry)
        return -1;

	//ExitApp();
//we can't use check_uneek_fs
//as we already shut down the uneek_fs system
//so it will always return false

	if (in_neek == false)
	{
		xprintf("Booting Homebrew");
		if(wiiload)
		{
			xprintf(" via wiiload\n");

			if(Options.wiiload_ahb == 2)
			{
				xprintf("with HW_AHBPROT\n");
				Patch_ahbprot();
			}

			if(Options.wiiload_ahb != 0)
			{
				xprintf("with IOS reload\n");
				IOS_ReloadIOS(Options.wiiload_ios);
			}
			else
				xprintf("without reloading IOS\n");
		}
		else
		{
			xprintf(" from storage device\n");
			if(Settings.force_reload == "HW_AHBPROT")
			{
				xprintf("with HW_AHBPROT\n");
				Patch_ahbprot();
			}

			if(Settings.force_reload != "NORELOAD")
			{
				xprintf("with IOS reload\n");
				IOS_ReloadIOS(SelectedIOS());
			}
			else
				xprintf("without IOS reload\n");
		}
	}

	wiiload_args = 0;

	/*this will also be called when wiiloading an application
	will need to check if it's expected behavour? */

/*
	if(!wiiload_args)
	{

		if(SelectedIOS() != IOS_GetVersion() || Settings.force_reload != "")
		{
			//keep ahbprot rights in new ios
			Patch_ahbprot();
			IOS_ReloadIOS(SelectedIOS());
		}
	}
    wiiload_args = 0;
*/
    SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
    _CPU_ISR_Disable (cpu_isr);
    __exception_closeall();
    entry();
    _CPU_ISR_Restore (cpu_isr);

    return 0;
}
Example #17
0
int main(int argc, char *argv[])
{
#ifdef HW_RVL
   IOS_ReloadIOS(IOS_GetVersion());
   L2Enhance();
   gx_init_mem2();
#endif

   fatInitDefault();

#ifdef HAVE_LOGGER
   g_extern.verbose = true;
   logger_init();
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_net;
#elif defined(HAVE_FILE_LOGGER)
   g_extern.verbose = true;
   log_fp = fopen("/retroarch-log.txt", "w");
   devoptab_list[STD_OUT] = &dotab_stdout;
   devoptab_list[STD_ERR] = &dotab_stdout;
   dotab_stdout.write_r = gx_logger_file;
#endif

#ifdef HW_RVL
   lwp_t gx_device_thread;
   gx_devices[GX_DEVICE_SD].interface = &__io_wiisd;
   gx_devices[GX_DEVICE_SD].name = "sd";
   gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface);
   gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage;
   gx_devices[GX_DEVICE_USB].name = "usb";
   gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface);
   LWP_MutexInit(&gx_device_mutex, false);
   LWP_CreateThread(&gx_device_thread, gx_devthread, NULL, NULL, 0, 66);
#endif

   get_environment_settings();
   make_directories();
   config_set_defaults();
   input_gx.init();

   video_gx.start();
   driver.video = &video_gx;

   gx_video_t *gx = (gx_video_t*)driver.video_data;
   gx->menu_data = (uint32_t *) menu_framebuf;

   char tmp_path[PATH_MAX];
   const char *extension = default_paths.executable_extension;
   snprintf(tmp_path, sizeof(tmp_path), "%s/", default_paths.core_dir);
   const char *path_prefix = tmp_path; 

   char full_path[1024];
   snprintf(full_path, sizeof(full_path), "%sCORE%s", path_prefix, extension);

   bool find_libretro_file = rarch_configure_libretro_core(full_path, path_prefix, path_prefix, 
   default_paths.config_file, extension);

   rarch_settings_set_default(&input_gx);
   rarch_config_load(default_paths.config_file, path_prefix, extension, find_libretro_file);

   char core_name[64];
   rarch_console_name_from_id(core_name, sizeof(core_name));
   char input_path[1024];
   snprintf(input_path, sizeof(input_path), "%s/%s.cfg", default_paths.input_presets_dir, core_name);
   config_read_keybinds(input_path);

   init_libretro_sym();

   input_gx.post_init();

   menu_init();

   if (argc > 2 && argv[1] != NULL && argv[2] != NULL)
   {
      char rom[PATH_MAX];
      g_console.external_launcher_support = EXTERN_LAUNCHER_CHANNEL;
      snprintf(rom, sizeof(rom), "%s%s", argv[1], argv[2]);
      g_console.zip_extract_mode = ZIP_EXTRACT_TO_CURRENT_DIR_AND_LOAD_FIRST_FILE;
      rarch_console_load_game_wrap(rom, g_console.zip_extract_mode, S_DELAY_1);

      rgui_iterate(rgui, RGUI_ACTION_MESSAGE);
      gx->menu_render = true;
      rarch_render_cached_frame();
      gx->menu_render = false;

      rarch_startup(default_paths.config_file);
   }
   else
   {
      g_console.external_launcher_support = EXTERN_LAUNCHER_SALAMANDER;
   }

begin_loop:
   if(g_console.mode_switch == MODE_EMULATION)
   {
      bool repeat = false;

      input_gx.poll(NULL);

      video_set_aspect_ratio_func(g_console.aspect_ratio_index);

      audio_start_func();

      do{
         repeat = rarch_main_iterate();
      }while(repeat && !g_console.frame_advance_enable);

      audio_stop_func();
   }
   else if(g_console.mode_switch == MODE_MENU)
   {
      menu_loop();

      if (g_console.mode_switch != MODE_EXIT)
         rarch_startup(default_paths.config_file);
   }
   else
      goto begin_shutdown;
   goto begin_loop;

begin_shutdown:
   rarch_config_save(default_paths.config_file);
   config_save_keybinds(input_path);

   if(g_console.emulator_initialized)
      rarch_main_deinit();

   input_gx.free(NULL);

   video_gx.stop();
   menu_free();

#ifdef HAVE_LOGGER
   logger_shutdown();
#elif defined(HAVE_FILE_LOGGER)
   fclose(log_fp);
#endif

   if(g_console.return_to_launcher)
      rarch_console_exec(g_console.launch_app_on_exit);

   exit(0);
}
Example #18
0
int main()
{
	void *xfb;
	GXRModeObj *rmode;
	lwp_t handle;
	int r;
	char *stack;

	IOS_ReloadIOS(30);

	VIDEO_Init();

	switch(VIDEO_GetCurrentTvMode())
	{
		case VI_NTSC:
			rmode = &TVNtsc480IntDf;
			break;

		case VI_PAL:
			rmode = &TVPal528IntDf;
			break;

		case VI_MPAL:
			rmode = &TVMpal480IntDf;
			break;

		default:
			rmode = &TVNtsc480IntDf;
			break;
	}

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));

	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();

#if 1
	printf("Calling main()\n");
	main_real();
	printf("main() returned\n");
#else
	printf("Creating main thread\n");

	stack = malloc(1024*1024);
	if (stack == 0)
	{
		printf("Unable to allocate stack\n");
		while(1);
	}

	handle = 0;
	r = LWP_CreateThread(&handle, main_real, 0, stack, 1024*1024, 50);
	if (r != 0)
	{
		printf("Failed to create thread\n");
		while(1);
	}
	printf("Main thread created\n");
	LWP_SetThreadPriority(0, 0);

	printf("Looping\n");
	while(1);
#endif
}
int main(int argc, char* argv[])
{
	__exception_setreload(10);
	
	int i, ret;
	
	Init_Console();
	printf("\x1b[%u;%um", 37, false);
	
	PAD_Init();
	WPAD_Init();
	WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
	
	printheadline();
	
	ret = ahbprot_menu();
	if (ret < 0)
	{
		ret = ios_selectionmenu(236);
		if (ret > 0)
		{
			printf("\t- Reloading to IOS%d... ", ret);
			WPAD_Shutdown();
			IOS_ReloadIOS(ret);
			sleep(2);
			PAD_Init();
			WPAD_Init();
			WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
			printf("done.\n\n");
		} else
		if (ret == 0)
		{
			printf("\t- Proceeding without IOS reload...\n\n");
		} else {
			Reboot();
		}
	}
	
	resetscreen();
	printheadline();
	
	/* Initialize NAND FS */
	ISFS_Initialize();
	
	/* Do our stuff */
	char path[ISFS_MAXPATH];
	char *filenames[10] = { "misc.bin", "nwc24dl.bin", "nwc24fl.bin", "nwc24fls.bin", "nwc24msg.cbk", "nwc24msg.cfg", \
							"mbox/wc24recv.ctl", "mbox/wc24recv.mbx", "mbox/wc24send.ctl", "mbox/wc24send.mbx" };
	
	for (i = 0; i < 10; i++)
	{
		snprintf(path, MAX_CHARACTERS(path), "/shared2/wc24/%s", filenames[i]);
		
		printf("%u. Deleting \"%s\"... ", i + 1, path);
		ret = ISFS_Delete(path);
		if (ret < 0)
		{
			switch (ret)
			{
				case -1:
				case -102:
					printf("\n\t- Error: Permission denied!");
					break;
				case -2:
				case -105:
					printf("\n\t- Error: File exists!");
					break;
				case -4:
				case -101:
					printf("\n\t- Error: Invalid argument!");
					break;
				case -6:
				case -106:
					printf("\n\t- Error: File not found!");
					break;
				case -8:
				case -118:
					printf("\n\t- Error: Resource busy!");
					break;
				case -12:
				case -103:
				case -114:
					printf("\n\t- Error: NAND ECC failure!");
					break;
				case -22:
					printf("\n\t- Error: Memory allocation failed during request!");
					break;
				case -107:
				case -109:
					printf("\n\t- Error: Too many files open!");
					break;
				case -108:
					printf("\n\t- Error: Memory full!");
					break;
				case -110:
					printf("\n\t- Error: Path name is too long!");
					break;
				case -111:
					printf("\n\t- Error: File already open!");
					break;
				case -115:
					printf("\n\t- Error: Directory not empty!");
					break;
				case -116:
					printf("\n\t- Error: Max directory depth exceeded!");
					break;
				default:
					printf("\n\t- FATAL / UNKNOWN ERROR!!!");
			}
			
			printf(" (ret = %d)\n\n", ret);
			
			if (ret <= -119) break;
		} else {
			printf("OK!\n\n");
		}
		
		usleep(2000000); // 2 seconds
	}
	
	/* Unmount NAND FS and exit */
	ISFS_Deinitialize();
	Reboot();
	
	return 0;
}
Example #20
0
s32 Disc_BootPartition(u64 offset, u8 videoselected, u8 cheat, u8 vipatch, u8 patchcountrystring, u32 rtrn) {
    entry_point p_entry;

    s32 ret;

    /* Open specified partition */
    ret = WDVD_OpenPartition(offset, tmd_buffer);
    if (ret < 0)
        return ret;

	char gameid[8];
	memset(gameid, 0, 8);
	memcpy(gameid, (char*)Disc_ID, 6);

	//kill the SD
    SDCard_deInit();

    /* Disconnect Wiimote */
    WPAD_Flush(0);
    WPAD_Disconnect(0);
    WPAD_Shutdown();
	
	// Load Disc IOS
	u32 disc_ios = tmd_buffer[0x18B];
	if (disc_ios != IOS_GetVersion()) {
		WDVD_ClosePartition();
		WDVD_Close();

		ret = IOS_ReloadIOS(disc_ios);
		if (ret < 0) {
			gprintf("Disc IOS %u could not be loaded! (ret = %d)", disc_ios, ret);
			return ret;
		}
		Disc_Init();
		Disc_Open();
		WDVD_OpenPartition(offset, tmd_buffer);
	}	

    /* Setup low memory */
    __Disc_SetLowMem();

    /* Run apploader */
    ret = Apploader_Run(&p_entry, cheat, videoselected, vipatch, patchcountrystring, rtrn);
    if (ret < 0)
        return ret;

    bool cheatloaded = false;

    if (cheat == 1) {
        /* OCARINA STUFF - FISHEARS*/
		cheatloaded = ocarina_do_code() == 1;
		cheatloaded = true;
    }

    /* Set an appropiate video mode */
    __Disc_SetVMode(videoselected);

    /* Set time */
    __Disc_SetTime();

	// Anti-green screen fix
	VIDEO_SetBlack(TRUE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	gprintf("\n\nUSB Loader GX is done.\n\n");

    /* Shutdown IOS subsystems */
	// fix for PeppaPig (from NeoGamma)
	extern void __exception_closeall();
	IRQ_Disable();
	__IOS_ShutdownSubsystems();
	__exception_closeall();

	appentrypoint = (u32) p_entry;

	if (cheat == 1 && cheatloaded)
	{
		__asm__(
			"lis %r3, appentrypoint@h\n"
			"ori %r3, %r3, appentrypoint@l\n"
			"lwz %r3, 0(%r3)\n"
			"mtlr %r3\n"
			"lis %r3, 0x8000\n"
			"ori %r3, %r3, 0x18A8\n"
			"mtctr %r3\n"
			"bctr\n"
		);
	}
	else
	{
		__asm__(
			"lis %r3, appentrypoint@h\n"
			"ori %r3, %r3, appentrypoint@l\n"
			"lwz %r3, 0(%r3)\n"
			"mtlr %r3\n"
			"blr\n"
		);
	}

    return 0;
}
Example #21
0
int main(int argc, char **argv)
{
	u32 cookie;
	FILE *exeFile = NULL;
	void *exeBuffer = (void *)EXECUTABLE_MEM_ADDR;
	u32 exeSize = 0;
	u32 exeEntryPointAddress = 0;
	entrypoint exeEntryPoint;
	__exception_setreload(0);

	IOS_ReloadIOS(58);

	/* int videomod */
	InitVideo();
	/* get imagedata */
	u8 * imgdata = GetImageData();
	fadein(imgdata);
	/* check devices */
	SDCard_Init();
	USBDevice_Init();

	char cfgpath[256];
	bool result = false;

	sprintf(cfgpath, "sd:/config/SaveGame_Manager_GX/SaveGame_Manager_GX.cfg");
	result = cfg_parsefile(cfgpath, &cfg_set);
	if(!result) //no cfg-File on SD: try USB:
	{
		sprintf(cfgpath, "usb:config/SaveGame_Manager_GX/SaveGame_Manager_GX.cfg");
		result = cfg_parsefile(cfgpath, &cfg_set);
	}

    if(result)
    {
        sprintf(cfgpath, "%sboot.dol", update_path);
		/* Open dol File and check exist */
        exeFile = fopen (cfgpath, "rb");
        if (exeFile==NULL)
        {
            sprintf(cfgpath, "%sboot.elf", update_path);
            exeFile = fopen (cfgpath,"rb");
        }
        if (exeFile==NULL)
			result = false;
        else
        result = true;
    }

	if(!result) // non cfg-File loaded or update_path not set
	{
		/* Open dol File and check exist */
		sprintf(cfgpath, "sd:/apps/SaveGame_Manager_GX/boot.dol");
		exeFile = fopen (cfgpath ,"rb");
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "sd:/apps/SaveGame_Manager_GX/boot.elf");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "usb:/apps/SaveGame_Manager_GX/boot.dol");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "usb:/apps/SaveGame_Manager_GX/boot.elf");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "sd:/apps/SaveGameManagerGX/boot.dol");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "sd:/apps/SaveGameManagerGX/boot.elf");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "usb:/apps/SaveGameManagerGX/boot.dol");
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, "usb:/apps/SaveGameManagerGX/boot.elf");
			exeFile = fopen (cfgpath ,"rb");
		}
		// if nothing found exiting
		if (exeFile==NULL)
		{
            fadeout(imgdata);
            fclose (exeFile);
            SDCard_deInit();
            USBDevice_deInit();
            StopGX();
            free(imgdata);
			SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
		}
	}

	fseek (exeFile, 0, SEEK_END);
	exeSize = ftell(exeFile);
	rewind (exeFile);

	if(fread (exeBuffer, 1, exeSize, exeFile) != exeSize)
	{
		fadeout(imgdata);
        fclose (exeFile);
        SDCard_deInit();
        USBDevice_deInit();
        StopGX();
        free(imgdata);
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	}
	fclose (exeFile);

	/* load entry point */
	struct __argv args;
	bzero(&args, sizeof(args));
	args.argvMagic = ARGV_MAGIC;
	args.length = strlen(cfgpath) + 2;
	args.commandLine = (char*)malloc(args.length);
	if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	strcpy(args.commandLine, cfgpath);
	args.commandLine[args.length - 1] = '\0';
	args.argc = 1;
	args.argv = &args.commandLine;
	args.endARGV = args.argv + 1;

	u8 * appboot_buff = (u8 *) malloc(app_booter_dol_size);
	if(!appboot_buff)
	{
		fadeout(imgdata);
        SDCard_deInit();
        USBDevice_deInit();
        StopGX();
        free(imgdata);
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	}

    memcpy(appboot_buff, app_booter_dol, app_booter_dol_size);

	exeEntryPointAddress = load_dol_image(appboot_buff, &args);

    if(appboot_buff)
        free(appboot_buff);

	fadeout(imgdata);
	SDCard_deInit();
	USBDevice_deInit();
	StopGX();
	free(imgdata);

	if (exeEntryPointAddress == 0)
	{
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	}

	exeEntryPoint = (entrypoint) exeEntryPointAddress;
	/* cleaning up and load dol */
	SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
	_CPU_ISR_Disable (cookie);
	__exception_closeall ();
	exeEntryPoint ();
	_CPU_ISR_Restore (cookie);
	return 0;
}
Example #22
0
int main(int argc, char **argv) 
{
int ret;

	VIDEO_Init();                                        //Inicialización del Vídeo.
                                      
	rmode = VIDEO_GetPreferredMode(NULL);                //mediante esta función rmode recibe el valor de tu modo de vídeo.
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));  //inicialización del buffer.
	console_init(xfb,20,20,rmode->fbWidth,rmode->        //inicialización de la consola.
	xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);  
	VIDEO_Configure(rmode);                              //configuración del vídeo.
	VIDEO_SetNextFramebuffer(xfb);                       //Configura donde guardar el siguiente buffer .
	VIDEO_SetBlack(FALSE);                               //Hace visible el display  .                     
	VIDEO_Flush();
	VIDEO_WaitVSync();                                   
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

	SYS_SetResetCallback(reset_call);

	IOS_ReloadIOS(222);
	sleep(1);

	/* secuencias de escape 

	\33[2J -> borra pantalla y posiciona en 1,1
	\33[1;1H -> posiciona en 1,1
	\33[42m -> color de fondo verde (0->negro, 1->rojo, 2->verde, 3-> amarillo, 4->azul, 5->magenta 6->cyan 7->blanco )
	\33[32m -> color de letras verde

	*/

	printf("\33[2J\n\n\n \33[42m dev/mload Test \33[40m \n\n\n\n");

	ret=mload_init();
	if(ret<0)
		{
		printf("fail to get dev/mload\n");
		
		goto out;
		}
	else
		{
		u32 addr;
		int len;

		printf("Hello!: my name is dev/mload and my thread id is %i\n", mload_get_thread_id());
		mload_get_load_base(&addr, &len);
		printf("You have from 0x%x to 0x%x to work\n\n", addr, addr+len-1);
		}
	/*
	mload_elf((void *) ehcmodule_elf, &my_data_elf);
	my_thread_id=mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio);
	*/

	printf("Loading example1.elf (Starlet)\n");

	if(((u32) example1_elf) & 3) {printf("Unaligned elf!\n"); goto out;}

	mload_elf((void *) example1_elf, &my_data_elf);

	printf("Running... at 0x%x\n", (u32) my_data_elf.start);

	my_thread_id=mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio);

    if(my_thread_id<0) {printf("fail to init the starlet thread: %i\n", my_thread_id); goto out;}

	printf("Module thread id: %i Priority in elf: 0x%x\n", my_thread_id, my_data_elf.prio);

	printf("The example Module counts seconds and report the thread id and the priority\n");

	{
	#if 0
		int n,m;

		sleep(1);
		#define UMS_BASE			(('U'<<24)|('M'<<16)|('S'<<8))
		#define USB_IOCTL_UMS_INIT	        (UMS_BASE+0x1)
		
		s32 hid2 = -1;
		hid2 = iosCreateHeap(1024);
		n=IOS_Open(ehc_fs, 0);
		if(n<0) printf("Error: device not found\n");
		else {
			printf("OK\n");
		     /* Initialize USB storage */
		     m=IOS_IoctlvFormat(hid2, n, USB_IOCTL_UMS_INIT, ":");

			 }

    #endif	
	}

	while(1)
		{
		static u32 data[8] ATTRIBUTE_ALIGN(32);

		if(exit_by_reset) break;

		mload_seek(0x13740000, SEEK_SET);
		mload_read(&data,32);
		printf("\33[16;16H Starlet activity: %i Thid: %i Prio: 0x%x    \n",data[0],data[1],data[2]);
		
		VIDEO_WaitVSync();
		}

	// you can stops the Starlet thread using this function:
	 mload_stop_thread(my_thread_id);
out:
	mload_close();
VIDEO_WaitVSync();
sleep(4);

return 0;
}
Example #23
0
void DoMini(u8* kbuf, size_t kernel_size)
{
//temporary test
//copy kernel.bin


		kernel_size +=3;
		kernel_size &= 0xFFFFFFFC;
		//memcpy((void*)0x91000000,kernel_bin,KERNEL_SIZE);
		//DCFlushRange( (void *)0x91000000, KERNEL_SIZE );


//        char* mini = (char*) memalign( 32, armboot_bin_size +KERNEL_SIZE + 4 );
        u8* mini = (u8*) memalign( 32, armboot_size +kernel_size + 4 );

        if( !mini )
        {
                return;
        }
        xprintf( "mini buffer: %p\n", mini );

//		memcpy( mini, kernel_bin,KERNEL_SIZE);
//        DCFlushRange( mini, KERNEL_SIZE );
//        memcpy( mini+KERNEL_SIZE+4, armboot_bin, armboot_bin_size );
//        DCFlushRange( mini+KERNEL_SIZE+4, armboot_bin_size );

		memcpy( mini, kbuf,kernel_size);
        DCFlushRange( mini, kernel_size );
        free(kbuf);
        memcpy( mini+kernel_size+4, armboot, armboot_size );
        DCFlushRange( mini+kernel_size+4, armboot_size );

        xprintf( "armboot.bin copied\n" );
        *(u32*)0xc150f000 = 0x424d454d;
        asm volatile( "eieio" );

        // physical address for armboot.bin.  ( virtualToPhysical() )
//        *(u32*)0xc150f004 = MEM_VIRTUAL_TO_PHYSICAL( mini+KERNEL_SIZE+4 );
        *(u32*)0xc150f004 = MEM_VIRTUAL_TO_PHYSICAL( mini+kernel_size+4 );

        asm volatile( "eieio" );

        xprintf( "physical memory address: %08x\n", MEM_VIRTUAL_TO_PHYSICAL( mini ) );
        xprintf( "loading bootmii IOS\n" );

// pass position of kernel.bin to mini
		*(u32*)0x8132FFF0 = MEM_VIRTUAL_TO_PHYSICAL( mini );
        asm volatile( "eieio" );
		DCFlushRange((void*)0x8132FFF0,4);

// pass length of kernel.bin to mini
		*(u32*)0x8132FFF4 = kernel_size;
        asm volatile( "eieio" );
		DCFlushRange((void*)0x8132FFF4,4);

        IOS_ReloadIOS( 0xfe );

        xprintf( "well shit.  this shouldnt happen\n" );

        free( mini );
}
Example #24
0
void Menu_SelectIOS(void)
{
	u8 *iosVersion = NULL;
	u32 iosCnt;
	u8 tmpVersion;

	u32 cnt;
	s32 ret, selected = 0;
	bool found = false;

	/* Get IOS versions */
	ret = Title_GetIOSVersions(&iosVersion, &iosCnt);
	if (ret < 0)
		return;

	/* Sort list */
	qsort(iosVersion, iosCnt, sizeof(u8), __Menu_IsGreater);

	if (gConfig.cIOSVersion < 0)
		tmpVersion = CIOS_VERSION;
	else
	{
		tmpVersion = (u8)gConfig.cIOSVersion;
		// For debugging only
		//printf ("User pre-selected cIOS: %i\n", tmpVersion);
		//WaitButtons();
	}

	/* Set default version */
	for (cnt = 0; cnt < iosCnt; cnt++) {
		u8 version = iosVersion[cnt];

		/* Custom IOS available */
		//if (version == CIOS_VERSION)
		if (version == tmpVersion)
		{
			selected = cnt;
			found = true;
			break;
		}

		/* Current IOS */
		if (version == IOS_GetVersion())
			selected = cnt;
	}

	/* Ask user for IOS version */
	if ((gConfig.cIOSVersion < 0) || (found == false))
	{
		for (;;)
		{
			/* Clear console */
			Con_Clear();

			printf("\t>> Select IOS version to use: < IOS%d >\n\n", iosVersion[selected]);

			printf("\t   Press LEFT/RIGHT to change IOS version.\n\n");

			printf("\t   Press A button to continue.\n");
			printf("\t   Press HOME button to restart.\n\n");

			u32 buttons = WaitButtons();

			/* LEFT/RIGHT buttons */
			if (buttons & WPAD_BUTTON_LEFT) {
				if ((--selected) <= -1)
					selected = (iosCnt - 1);
			}
			if (buttons & WPAD_BUTTON_RIGHT) {
				if ((++selected) >= iosCnt)
					selected = 0;
			}

			/* HOME button */
			if (buttons & WPAD_BUTTON_HOME)
				Restart();

			/* A button */
			if (buttons & WPAD_BUTTON_A)
				break;
		}
	}


	u8 version = iosVersion[selected];

	if (IOS_GetVersion() != version) {
		/* Shutdown subsystems */
		Wpad_Disconnect();

		/* Load IOS */
		ret = IOS_ReloadIOS(version);

		/* Initialize subsystems */
		Wpad_Init();
	}
}
Example #25
0
int main(int argc, char **argv)
{
	set_new_handler(no_memory);
	geckoinit = InitGecko();
	__exception_setreload(5);

	SYS_SetArena1Hi(APPLOADER_START);

	char *gameid = NULL;
	string dolLoc; //(argv[0] != NULL ? argv[0] : "");

	for (int i = 0; i < argc; i++)
	{
		if (argv[i] != NULL && strcasestr(argv[i], "ios=") != NULL && strlen(argv[i]) > 4)
		{
			while(argv[i][0] && !isdigit(argv[i][0])) argv[i]++;
			if (atoi(argv[i]) < 254 && atoi(argv[i]) > 0)
				mainIOS = atoi(argv[i]);
		}
		else if (strlen(argv[i]) == 6)
		{
			gameid = argv[i];
			for (int i=0; i < 5; i++)
				if (!isalnum(gameid[i]))
					gameid = NULL;
		}
	}
	gprintf("Loading cIOS: %d\n", mainIOS);

	ISFS_Initialize();

	// Load Custom IOS
	bool iosOK = loadIOS(mainIOS, false);
	MEM2_init(52);

	u8 mainIOSBase = 0;
	iosOK = iosOK && cIOSInfo::D2X(mainIOS, &mainIOSBase);
	gprintf("Loaded cIOS: %u has base %u\n", mainIOS, mainIOSBase);

	// Init video
	CVideo vid;
	vid.init();
	WIILIGHT_Init();
	vid.waitMessage(0.2f);

	// Init
	Sys_Init();
	Sys_ExitTo(EXIT_TO_HBC);

	int ret = 0;

	do
	{
		Open_Inputs();

		bool deviceAvailable = false;

		u8 timeout = 0;
		while(!deviceAvailable && timeout++ != 20)
		{
			DeviceHandler::Instance()->MountAll();
			sleep(1);

			for(u8 device = SD; device <= USB8; device++)
				if(DeviceHandler::Instance()->IsInserted(device))
					deviceAvailable = true;
		}

		bool dipOK = Disc_Init() >= 0;

		CMenu menu(vid);
		menu.init(dolLoc);
		mainMenu = &menu;
		if(!deviceAvailable)
		{
			menu.error(L"Could not find a device to save configuration files on!");
			break;
		}
		else if(!iosOK)
		{
			menu.error(sfmt("d2x cIOS %i rev6 or later is required", mainIOS));
			break;
		}
		else if(!dipOK)
		{
			menu.error(L"Could not initialize the DIP module!");
			break;
		}
		else
		{
			if (gameid != NULL && strlen(gameid) == 6)
				menu._directlaunch(gameid);
			else
				ret = menu.main();
		}
		vid.cleanup();
		if (bootHB)
		{
			IOS_ReloadIOS(58);
			BootHomebrew();
		}

	} while (ret == 1);

	WifiGecko_Close();

	Nand::Instance()->Disable_Emu();
	Nand::DestroyInstance();

	Sys_Exit();
	return 0;
};
Example #26
0
void Boot (void)
	{
	printd ("---------------------------------------------------------------------------\n");
	
	if (pln.bootMode == PLN_BOOT_REAL)
		printd ("       You are in REAL NAND mode: Press any key NOW for boot options\n");
	if (pln.bootMode == PLN_BOOT_NEEK)
		printd ("         You are in UNEEK mode: Press any key NOW for boot options\n");
	if (pln.bootMode == PLN_BOOT_SM)
		printd ("      You are in System Menu' mode: Press any key NOW for boot options\n");
	if (pln.bootMode == PLN_BOOT_HBC)
		printd ("     You are in HomeBrewChannel mode: Press any key NOW for boot options\n");

	if (keypressed || WaitForAnyKey ())
		{
		ChooseNewMode ();
		}
		
	printd ("\n");

	SavePLN ();
	
	WPAD_Shutdown();
	PAD_Reset(0xf0000000);

	//if (IsNandFolder ("usb:/") && pln.bootMode == PLN_BOOT_NEEK)
	if (pln.bootMode == PLN_BOOT_NEEK)
		{
		printd ("Booting neek...");
		Fat_Unmount ();
		green_fix ();
		IOS_ReloadIOS (254); 
		}

	if (pln.bootMode == PLN_BOOT_REAL)
		{
		bool found = FALSE;
		
		if (pl_sd)
			{
			if (!found) found = LoadExecFile (POSTLOADER_SD, "priibooter");
			if (!found) found = LoadExecFile (POSTLOADER_SDAPP, "priibooter");
			}
		if (pl_usb)
			{
			if (!found) found = LoadExecFile (POSTLOADER_USB, "priibooter");
			if (!found) found = LoadExecFile (POSTLOADER_USBAPP, "priibooter");
			}

		if (!found) BootToMenu ();
				
		Fat_Unmount ();
		green_fix ();
		BootExecFile ();
		}
		
	if (pln.bootMode == PLN_BOOT_SM)
		{
		green_fix ();
		BootToMenu ();
		}
		
	exit (0); // This isn't really needed...
	}
Example #27
0
//---------------------------------------------------------------------------------
int main(int argc, char **argv)
{
    IOS_ReloadIOS(56);

    InitVideo ();

    printd ("---------------------------------------------------------------------------");
    printd ("                        neekbooter "VER" by stfour");
    printd ("                       (part of postLoader project)");
    printd ("---------------------------------------------------------------------------");

    u32 idx = -1;
    u32 status = 0;
    u32 hi, lo;
    u32 back2real;

    if (neek_PLNandInfo	(0, &idx, &status, &lo, &hi, &back2real) == false)
    {
        printd ("no boot information...");
        Reload ();
    }

    printd ("idx = %d", idx);
    printd ("status = %d", status);

    if (status == PLNANDSTATUS_NONE)
    {
        status = PLNANDSTATUS_BOOTING;
        neek_PLNandInfo	(1, &idx, &status, &lo, &hi, &back2real);

        if (!hi && !lo)
        {
            printd ("booting disk");

            // Copy the di image
            memcpy(EXECUTE_ADDR, di_dol, di_dol_size);
            DCFlushRange((void *) EXECUTE_ADDR, di_dol_size);

            // Load the booter
            memcpy(BOOTER_ADDR, booter_dol, booter_dol_size);
            DCFlushRange(BOOTER_ADDR, booter_dol_size);

            memset(ARGS_ADDR, 0, sizeof(struct __argv));
            DCFlushRange(ARGS_ADDR, sizeof(struct __argv));

            printd ("stating di");

            entrypoint hbboot_ep = (entrypoint) BOOTER_ADDR;

            // bootit !
            u32 level;
            SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
            _CPU_ISR_Disable(level);
            __exception_closeall();
            hbboot_ep();
            _CPU_ISR_Restore(level);
        }
        else
        {
            printd ("booting channel");

            WII_Initialize();
            WII_LaunchTitle((u64)(TITLE_ID (hi, lo)));

            exit(0);  // Use exit() to exit a program, do not use 'return' from main()

            /*

            s_nandbooter nb ATTRIBUTE_ALIGN(32);

            u8 *tfb = ((u8 *) 0x93200000);

            memset (&nb, 0, sizeof (s_nandbooter));

            nb.channel.language = -1;
            nb.channel.titleId = TITLE_ID (hi, lo);
            nb.channel.bootMode = 1;

            // Copy the triiforce image
            memcpy(EXECUTE_ADDR, nandbooter_dol, nandbooter_dol_size);
            DCFlushRange((void *) EXECUTE_ADDR, nandbooter_dol_size);

            // Load the booter
            memcpy(BOOTER_ADDR, booter_dol, booter_dol_size);
            DCFlushRange(BOOTER_ADDR, booter_dol_size);

            memset(ARGS_ADDR, 0, sizeof(struct __argv));
            DCFlushRange(ARGS_ADDR, sizeof(struct __argv));

            memcpy (tfb, &nb, sizeof(s_nandbooter));

            printd ("stating nandbooter");

            entrypoint hbboot_ep = (entrypoint) BOOTER_ADDR;

            u32 level;
            SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
            _CPU_ISR_Disable(level);
            __exception_closeall();
            hbboot_ep();
            _CPU_ISR_Restore(level);
            */
        }
    }
    else if (status == PLNANDSTATUS_BOOTING)
    {
        status = PLNANDSTATUS_BOOTED;
        neek_PLNandInfo	(1, &idx, &status, &lo, &hi, &back2real);

        if (!hi && !lo)
        {
            if (back2real)
            {
                printd ("returning to realnand");

                RestoreSneekFolder ();
                SYS_ResetSystem(SYS_RESTART,0,0);
            }
            else
            {
                printd ("restoring old nanndindex");

                neek_GetNandConfig ();

                // Go back to previous nand
                nandConfig->NandSel = idx;
                neek_WriteNandConfig ();

                neek_PLNandInfoRemove ();
                SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
            }
        }
        else
        {
            // restore sneek files
            RestoreSneekFolder ();
            SYS_ResetSystem(SYS_RESTART,0,0);
        }
    }

    exit (0);
}
Example #28
0
void REV_init()
{
	//Local variables
	f32 yscale;
	u32 xfbHeight;
	//Load the right IOS, so keyboard works fin
	u32 iosVersion = IOS_GetVersion();
	if(iosVersion != 36)
	{
		IOS_ReloadIOS(36);
	}
	////
	VIDEO_Init();//Video Library Init
	PAD_Init();//Gamecube Pad Library Init
	WPAD_Init();//Wiimote Library Init
	rMode = VIDEO_GetPreferredMode(NULL);//Set render mode
	// allocate 2 framebuffers for double buffering
	frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rMode));
	frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rMode));
	//Configure Video System
	VIDEO_Configure(rMode);
	VIDEO_SetNextFramebuffer(frameBuffer[fb]);//Initial Framebuffer
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rMode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
	fb ^= 1;//Set next index
	//Set up the FIFO
	void *gp_fifo = memalign(32,DEFAULT_FIFO_SIZE);//Allocate
	memset(gp_fifo,0,DEFAULT_FIFO_SIZE);//and Clear
	//Init GX hardware
	GX_Init(gp_fifo,DEFAULT_FIFO_SIZE);
	// clears the bg to color and clears the z buffer
	GX_SetCopyClear(DEF_BG_COLOR , 0x00ffffff);
	//More initialization
	w = rMode->viWidth;
    h = rMode->viHeight;
	
	yscale = GX_GetYScaleFactor(rMode->efbHeight,rMode->xfbHeight);
	xfbHeight = GX_SetDispCopyYScale(yscale);
	GX_SetDispCopySrc(0,0,rMode->fbWidth,rMode->efbHeight);
	GX_SetDispCopyDst(rMode->fbWidth,xfbHeight);
	GX_SetFieldMode(rMode->field_rendering,((h==2*rMode->xfbHeight)?GX_ENABLE:GX_DISABLE));
	
	if (rMode->aa)
        GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
    else
        GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
	
	GX_CopyDisp(frameBuffer[fb],GX_TRUE);
	GX_SetDispCopyGamma(GX_GM_1_0);
	
	for(u8 i = 0; i < 4; i++)
	WPAD_SetVRes(i,w,h);
	
	//Hardware Initialized, now engine initialization
	//Init filesystem
	fatInitDefault();
	//First create a Root
	mainRoot = new ROOT;
	mainRoot->init((f32)w,(f32)h);
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
	GX_SetColorUpdate(GX_ENABLE);
	GX_SetAlphaUpdate(GX_ENABLE);
	GX_SetZCompLoc(GX_TRUE);
	GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE);
	init3dConfig();
	init2dConfig();
	init2D(w, h);
	transQueue = NULL;
	solidQueue = NULL;
	zQueue = NULL;
	REV_fontsInit();
	KEYBOARD_Init(NULL);
	keyboardInit();
}
Example #29
0
s32 Disc_BootPartition(u64 offset, u8 vidMode, const u8 *cheat, u32 cheatSize, bool vipatch, bool countryString, u8 patchVidMode)
{
	entry_point p_entry;

	gprintf("Open partition at offset: 0x%08x\n", offset);
	s32 ret = WDVD_OpenPartition(offset, 0, 0, 0, Tmd_Buffer);
	if (ret < 0) {
		gprintf("Open partition failed: %d\n", ret);
		return ret;
	}
		
	/* Disconnect Wiimote */
    WPAD_Flush(0);
    WPAD_Disconnect(0);
    WPAD_Shutdown();

	/* Reload IOS into the correct IOS */
	u8 ios = Tmd_Buffer[0x18B];
	
	gprintf("Game requires ios %d\n", ios);
	if (ios != IOS_GetVersion()) {
		WDVD_ClosePartition();
		WDVD_Close();
	
		gprintf("Reloading IOS...");
		ret = IOS_ReloadIOS(ios);
		if (ret < 0) {
			gprintf("failed: %d\n", ret);
		} else {
			gprintf("done\n");
		}
		
		if (Disc_Init() < 0) {
			return -4;
		}
		if (Disc_Open() < 0) {
			return -6;
		}
		if (WDVD_OpenPartition(offset, 0, 0, 0, Tmd_Buffer) < 0) {
			return -8;
		}
	}
	

	gprintf("Setting low memory\n");
	
	/* Setup low memory */;
	__Disc_SetLowMem();

	gprintf("Select video mode\n");

	/* Select an appropriate video mode */
	__Disc_SelectVMode(vidMode);

	gprintf("Running apploader\n");

	/* Run apploader */
	ret = Apploader_Run(&p_entry, cheat != 0, vidMode, vmode, vipatch, countryString, patchVidMode);
	if (ret < 0) {
		gprintf("Failed to run apploader\n");
		return ret;
	}

	gprintf("Set video mode\n");

	/* Set an appropriate video mode */
	__Disc_SetVMode();

	if (cheat != 0 && hooktype != 0)
	{
		ocarina_do_code();
	}

	gprintf("Set time\n");

	/* Set time */
	__Disc_SetTime();

	gprintf("Reset video...");

	/* This prevent a green screen (or a flash of green before loading the game) */
	VIDEO_SetBlack(TRUE);
	gprintf("flushing...");
	VIDEO_Flush();
	gprintf("wait for sync...");
	VIDEO_WaitVSync();
	gprintf("wait for sync...");
	VIDEO_WaitVSync();
	gprintf("\n");

	u8 temp_data[4];

	gprintf("Shutting down wii systems\n");

	// fix for PeppaPig
	memcpy((char *) &temp_data, (void*)0x800000F4,4);

	/* Shutdown IOS subsystems */
	SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);

	// fix for PeppaPig
	memcpy((void*)0x800000F4,(char *) &temp_data, 4);

	appentrypoint = (u32) p_entry;

	gprintf("Current IOS: %d\n", IOS_GetVersion());

	gprintf("Starting game\n");

	if (cheat != 0)
	{
		__asm__(
			"lis %r3, appentrypoint@h\n"
			"ori %r3, %r3, appentrypoint@l\n"
			"lwz %r3, 0(%r3)\n"
			"mtlr %r3\n"
			"lis %r3, 0x8000\n"
			"ori %r3, %r3, 0x18A8\n"
			"mtctr %r3\n"
			"bctr\n"
		);
	}
	else
	{
		__asm__(
			"lis %r3, appentrypoint@h\n"
			"ori %r3, %r3, appentrypoint@l\n"
			"lwz %r3, 0(%r3)\n"
			"mtlr %r3\n"
			"blr\n"
		);
	}

	return 0;
}