void grlib_Controllers (bool enable) { if (enable) { PAD_Init(); WPAD_Init(); WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(0, 640, 480); WPAD_SetPowerButtonCallback( wmpower_cb ); } else { u8 i; for (i = 0; i < WPAD_MAX_WIIMOTES; i++) { if(WPAD_Probe(i,0) < 0) continue; WPAD_Flush(i); WPAD_Disconnect(i); } WPAD_Shutdown(); PAD_Reset(0xf0000000); } }
void REV_exit() { delete REVConsole; WPAD_Flush(WPAD_CHAN_ALL); WPAD_Disconnect(WPAD_CHAN_ALL); WPAD_Shutdown(); exit(0); }
int Menu_PrintWait() { printf_h(gt("Press any button to continue...")); printf("\n"); // clear button states WPAD_Flush(WPAD_CHAN_ALL); return Wpad_WaitButtonsCommon(); }
void Close_Inputs(void) { while(WPAD_GetStatus() == WPAD_STATE_ENABLING); //Possible freeze if i keep this here? if(WPAD_GetStatus() == WPAD_STATE_ENABLED) { WPAD_Flush(WPAD_CHAN_ALL); WPAD_Shutdown(); } }
static void gx_joypad_destroy(void) { #ifdef HW_RVL #if 0 int i; for (i = 0; i < MAX_PADS; i++) { /* Commenting this out fixes the Wii * remote not reconnecting after * core load, exit, etc. */ WPAD_Flush(i); WPADDisconnect(i); } #endif #endif }
bool Menu_Confirm(const char *msg) { if (msg) { printf_h(gt("Press %s button to %s."), (button_names[CFG.button_confirm.num]), msg); } else { printf_h(gt("Press %s button to continue."), (button_names[CFG.button_confirm.num])); } printf("\n"); printf_h(gt("Press %s button to go back."), (button_names[CFG.button_cancel.num])); printf("\n"); DefaultColor(); WPAD_Flush(WPAD_CHAN_ALL); for (;;) { u32 buttons = Wpad_WaitButtonsCommon(); if (buttons & CFG.button_confirm.mask) return true; if (buttons & CFG.button_cancel.mask) return false; } }
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; }
int BootHomebrewFromMem() { loadStub(); if (Set_Stub_Split(0x00010001,"UNEO")<0) Set_Stub_Split(0x00010001,"ULNR"); entrypoint entry; u32 cpu_isr; if (!innetbuffer) { SDCard_deInit(); USBDevice_deInit(); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } struct __argv args; int ret = valid_elf_image(innetbuffer); if (ret == 1) entry = (entrypoint) load_elf_image(innetbuffer); else entry = (entrypoint) load_dol(innetbuffer, &args); free(innetbuffer); if (!entry) { SDCard_deInit(); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } SDCard_deInit(); WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); _CPU_ISR_Disable (cpu_isr); __exception_closeall(); entry(); _CPU_ISR_Restore (cpu_isr); return 0; }
int Sys_ChangeIos(int ios) { s32 prevIos = IOS_GetVersion(); SDCard_deInit(); USBDevice_deInit(); WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); WDVD_Close(); USBStorage2_Deinit(); s32 ret = IOS_ReloadIOSsafe(ios); if (ret < 0) { ios = prevIos; } SDCard_Init(); if (ios == 222 || ios == 223) { load_ehc_module(); } USBDevice_Init(); PAD_Init(); Wpad_Init(); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); WBFS_Init(WBFS_DEVICE_USB); Disc_Init(); if (Sys_IsHermes()) { WBFS_OpenNamed((char *) &game_partition); } else { WBFS_Open(); } return ret; }
s32 Disc_GCBoot() { /* gprintf("Changing value at address 0xCC03024\n"); *(volatile unsigned int *)0xCC003024 |= 7; gprintf("Retrieving Ticket for BC..."); int retval = ES_GetTicketViews(BC, &view, 1); if (retval != 0) { gprintf("failed %d\n",retval); return -1; } gprintf("done\n"); ghexdump(&view, sizeof(tikview)); */ gprintf("Disconnecting Wiimotes\n"); /* Disconnect Wiimote */ WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); gprintf("Setting video to black..."); VIDEO_SetBlack(TRUE); gprintf("flushing..."); VIDEO_Flush(); gprintf("wait for sync..."); VIDEO_WaitVSync(); gprintf("wait for sync..."); VIDEO_WaitVSync(); gprintf("\n"); gprintf("Launching title\n"); WII_LaunchTitle(BC); /* retval = ES_LaunchTitle(BC, &view); gprintf("Launching title failed: %d\n",retval); while(1); */ return 0; }
static void _Sys_Shutdown(int SHUTDOWN_MODE) { _ExitApp(); WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); /* Poweroff console */ if ((CONF_GetShutdownMode() == CONF_SHUTDOWN_IDLE && SHUTDOWN_MODE != ShutdownToStandby) || SHUTDOWN_MODE == ShutdownToIdle) { s32 ret; /* Set LED mode */ ret = CONF_GetIdleLedMode(); if (ret >= 0 && ret <= 2) STM_SetLedMode(ret); /* Shutdown to idle */ STM_ShutdownToIdle(); } else { /* Shutdown to standby */ STM_ShutdownToStandby(); } }
int BootHomebrew(char * path) { loadStub(); if (Set_Stub_Split(0x00010001,"UNEO")<0) Set_Stub_Split(0x00010001,"ULNR"); void *buffer = NULL; u32 filesize = 0; entrypoint entry; u32 cpu_isr; FILE * file = fopen(path, "rb"); if (!file) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); fseek (file, 0, SEEK_END); filesize = ftell(file); rewind(file); buffer = malloc(filesize); if (fread (buffer, 1, filesize, file) != filesize) { fclose (file); free(buffer); SDCard_deInit(); USBDevice_deInit(); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } fclose (file); struct __argv args; bzero(&args, sizeof(args)); args.argvMagic = ARGV_MAGIC; args.length = strlen(path) + 2; args.commandLine = (char*)malloc(args.length); if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); strcpy(args.commandLine, path); args.commandLine[args.length - 1] = '\0'; args.argc = 1; args.argv = &args.commandLine; args.endARGV = args.argv + 1; int ret = valid_elf_image(buffer); if (ret == 1) entry = (entrypoint) load_elf_image(buffer); else entry = (entrypoint) load_dol(buffer, &args); free(buffer); SDCard_deInit(); USBDevice_deInit(); if (!entry) { SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); _CPU_ISR_Disable (cpu_isr); __exception_closeall(); entry(); _CPU_ISR_Restore (cpu_isr); return 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; }
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; }