static void init_machine(void) { /* Allocate cart_rom here ( 10 MBytes ) */ cart.rom = memalign(32, MAXROMSIZE); if (!cart.rom) { FONT_writeCenter("Failed to allocate ROM buffer... Rebooting",18,0,640,200,(GXColor)WHITE); gxSetScreen(); sleep(2); gx_audio_Shutdown(); gx_video_Shutdown(); #ifdef HW_RVL DI_Close(); SYS_ResetSystem(SYS_RESTART,0,0); #else SYS_ResetSystem(SYS_HOTRESET,0,0); #endif } /* BIOS support */ load_bios(); /* allocate global work bitmap */ memset (&bitmap, 0, sizeof (bitmap)); bitmap.width = 720; bitmap.height = 576; bitmap.depth = 16; bitmap.granularity = 2; bitmap.pitch = bitmap.width * bitmap.granularity; bitmap.viewport.w = 256; bitmap.viewport.h = 224; bitmap.viewport.x = 0; bitmap.viewport.y = 0; bitmap.data = texturemem; }
void ExitCleanup() { LWP_SuspendThread (devicethread); UnmountAllFAT(); CloseShare(); #ifdef HW_RVL DI_Close(); #endif }
/************************************************** Shutdown everything properly ***************************************************/ void shutdown(void) { /* system shutdown */ memfile_autosave(-1,config.state_auto); system_shutdown(); audio_shutdown(); free(cart.rom); gx_audio_Shutdown(); gx_video_Shutdown(); #ifdef HW_RVL DI_Close(); #endif }
/************************************************** Shutdown everything properly ***************************************************/ void shutdown(void) { /* save current config */ config_save(); /* auto-save State file */ slot_autosave(config.s_default,config.s_device); /* shutdown emulation */ audio_shutdown(); gx_audio_Shutdown(); gx_video_Shutdown(); #ifdef HW_RVL DI_Close(); #endif }
void mainmenu (int selectedMenu) { int quit = 0; int ret; // disable game-specific menu items if a ROM isn't loaded if ( ARAM_ROMSIZE == 0 ) menuitems[3][0] = '\0'; else sprintf (menuitems[3], "Game Menu"); VIDEO_WaitVSync (); while (quit == 0) { if(selectedMenu >= 0) { ret = selectedMenu; selectedMenu = -1; // default back to main menu } else { ret = RunMenu (menuitems, menucount, (char*)"Main Menu"); } switch (ret) { case 0: // Load ROM Menu quit = LoadManager (); break; case 1: // Configure Controllers ConfigureControllers (); break; case 2: // Preferences PreferencesMenu (); break; case 3: // Game Options quit = GameMenu (); break; case 4: // Credits Credits (); WaitButtonA (); break; case 5: // Reset the Gamecube/Wii Reboot(); break; case 6: // Exit to Loader #ifdef HW_RVL #ifdef WII_DVD DI_Close(); #endif exit(0); #else // gamecube if (psoid[0] == PSOSDLOADID) PSOReload (); #endif break; case -1: // Button B // Return to Game quit = 1; break; } } /*** Remove any still held buttons ***/ #ifdef HW_RVL while( PAD_ButtonsHeld(0) || WPAD_ButtonsHeld(0) ) VIDEO_WaitVSync(); #else while( PAD_ButtonsHeld(0) ) VIDEO_WaitVSync(); #endif }
void MainMenu () { s8 ret; u8 quit = 0; menu = 0; #ifdef HW_RVL u8 count = 6; char items[6][20] = #else u8 count = 5; char items[5][20] = #endif { {"Play Game"}, {"Hard Reset"}, {"Load New Game"}, {"Emulator Options"}, #ifdef HW_RVL {"Return to Loader"}, #endif {"System Reboot"} }; /* 50 hz TV mode */ if (gc_pal) { VIDEO_Configure (vmode); VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK); VIDEO_Flush(); VIDEO_WaitVSync(); VIDEO_WaitVSync(); } /* autosave (SRAM only) */ int temp = config.freeze_auto; config.freeze_auto = -1; memfile_autosave(); config.freeze_auto = temp; while (quit == 0) { strcpy (menutitle, "Version 1.04.2"); ret = DoMenu (&items[0], count); switch (ret) { case -1: /*** Button B ***/ case 0: /*** Play Game ***/ quit = 1; break; case 1: emu_reset(); quit = 1; break; case 2: /*** Load ROM Menu ***/ quit = loadmenu(); break; case 3: /*** Emulator Options */ Emu_options(); break; case 4: /*** SD/PSO/TP Reload ***/ memfile_autosave(); VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK); VIDEO_Flush(); VIDEO_WaitVSync(); #ifdef HW_RVL DI_Close(); exit(0); break; case 5: /*** Return to Wii System Menu ***/ memfile_autosave(); VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK); VIDEO_Flush(); VIDEO_WaitVSync(); DI_Close(); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); #else SYS_ResetSystem(SYS_HOTRESET,0,0); #endif break; } } /*** Remove any still held buttons ***/ while (PAD_ButtonsHeld(0)) PAD_ScanPads(); #ifdef HW_RVL while (WPAD_ButtonsHeld(0)) WPAD_ScanPads(); #endif /*** Restore fullscreen 50hz ***/ if (gc_pal) { extern GXRModeObj TV50hz_576i; GXRModeObj *rmode = &TV50hz_576i; Mtx p; rmode->xfbHeight = 574; rmode->viYOrigin = 0; rmode->viHeight = 574; VIDEO_Configure (rmode); VIDEO_ClearFrameBuffer(rmode, xfb[whichfb], COLOR_BLACK); VIDEO_Flush(); VIDEO_WaitVSync(); VIDEO_WaitVSync(); /* reset rendering mode */ GX_SetViewport (0.0F, 0.0F, rmode->fbWidth, rmode->efbHeight, 0.0F, 1.0F); GX_SetScissor (0, 0, rmode->fbWidth, rmode->efbHeight); f32 yScale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight); u16 xfbHeight = GX_SetDispCopyYScale (yScale); GX_SetDispCopySrc (0, 0, rmode->fbWidth, rmode->efbHeight); GX_SetDispCopyDst (rmode->fbWidth, xfbHeight); GX_SetCopyFilter (rmode->aa, rmode->sample_pattern, GX_TRUE, rmode->vfilter); GX_SetFieldMode (rmode->field_rendering, ((rmode->viHeight == 2 * rmode->xfbHeight) ? GX_ENABLE : GX_DISABLE)); GX_SetPixelFmt (GX_PF_RGB8_Z24, GX_ZC_LINEAR); guOrtho(p, rmode->efbHeight/2, -(rmode->efbHeight/2), -(rmode->fbWidth/2), rmode->fbWidth/2, 100, 1000); GX_LoadProjectionMtx (p, GX_ORTHOGRAPHIC); } #ifndef HW_RVL /*** Stop the DVD from causing clicks while playing ***/ uselessinquiry (); #endif }
void ProcessArgs(int argc, char **argv, int boothbdirect) { int i; s32 retval; u32 bootcode = launchcode & ~(0xff<<24);//Mask out the high 8-bits of launchcode, since that's used for options etc. char *path = (char*)0x900FFF00; void (*entry)() = (void*)0x80001800; u64 nandboot_titleid; YellHttp_Ctx *ctx; int use_wc24http = 0; u32 index; FILE *fdol; struct stat dolstats; if(!fatInitDefault())printf("FAT init failed.\n"); printf("Processing args...\n"); #ifndef WIILOADAPPDEBUG if(argc && !boothbdirect) { sscanf(argv[0], "%016llx", &nandboot_titleid); if(curtitleid!=nandboot_titleid) { printf("Current titleID and titleID from NANDBOOTINFO don't match: %016llx %s\n", curtitleid, argv[0]); argc = 0; } } #endif if(argc) { if(boothbdirect)launchcode = 1; if(launchcode & BIT(24))use_wc24http = 1; switch(bootcode) { case 1://Boot homebrew if(argc<2)break; if(!boothbdirect)printf("Booting homebrew from: %s\n", argv[1]); memcpy((void*)0x80001800, loader_bin, loader_bin_size); memset(path, 0, 256); if(!boothbdirect) { if(strncmp(argv[1], "http", 4)==0) { if(!use_wc24http) { printf("Using libyellhttp to download: %s\n", argv[1]); memset(localip, 0, 16); memset(netmask, 0, 16); memset(gateway, 0, 16); printf("Initializing network...\n"); retval = if_config (localip, netmask, gateway, true); if(retval<0) { printf("Network init failed: %d\n", retval); break; } ctx = YellHttp_InitCtx(); if(ctx==NULL) { printf("Failed to init/alloc http ctx.\n"); break; } printf("Downloading %s...\n", argv[1]); if(launchcode & BIT(26)) { WC24_MountWC24DlVFF(); chdir("wc24dl.vff:/"); } retval = YellHttp_ExecRequest(ctx, argv[1]); YellHttp_FreeCtx(ctx); if(retval<0) { memset(errstr, 0, 256); YellHttp_GetErrorStr(retval, errstr, 256); printf("retval = %d str: %s", retval, errstr); break; } for(i=strlen(argv[1])-1; i>0; i--) { if(argv[1][i]=='/')break; } i++; if(launchcode & BIT(26))strncpy(path, "wc24dl.vff:", 255); strncat(path, &argv[1][i], 255); } else { printf("Using WC24 to download: %s\n", argv[1]); printf("Creating record+entry...\n"); retval = WC24_CreateRecord(&myrec, &myent, 0, 0, 0x4842, WC24_TYPE_TITLEDATA, WC24_RECORD_FLAGS_DEFAULT, WC24_FLAGS_HB, 0x3c, 0x5a0, 0, argv[1], VFFPATH "boot.dol"); if(retval<0) { printf("WC24_CreateRecord returned %d\n", retval); WC24_Shutdown(); break; } index = retval; printf("Downloading...\n"); retval = KD_Download(KD_DOWNLOADFLAGS_MANUAL, (u16)index, 0x0); if(retval<0) { printf("KD_Download returned %d\n", retval); WC24_DeleteRecord(index); WC24_Shutdown(); break; } printf("Deleting record+entry...\n"); WC24_DeleteRecord(index); printf("Mounting VFF...\n"); retval = WC24_MountWC24DlVFF(); if(retval<0) { printf("WC24_MountWC24DlVFF returned %d\n", retval); WC24_Shutdown(); break; } printf("Reading wc24dl.vff:/" VFFPATH "boot.dol...\n"); fdol = fopen("wc24dl.vff:/" VFFPATH "boot.dol", "r"); if(fdol==NULL) { printf("Failed to open wc24dl.vff:/" VFFPATH "boot.dol\n"); } else { stat("wc24dl.vff:/" VFFPATH "boot.dol", &dolstats); dol_size = dolstats.st_size; fread((void*)0x90100000, 1, dolstats.st_size, fdol); fclose(fdol); unlink("wc24dl.vff:/" VFFPATH "boot.dol"); DCFlushRange((void*)0x90100000, dolstats.st_size); } printf("Unmounting VFF...\n"); VFF_Unmount("wc24dl.vff"); memset(path, 0, 256); boothbdirect = 1; WII_SetNANDBootInfoLaunchcode(0); } } else { strncpy(path, argv[1], 255); } if(!use_wc24http) { if(strncmp(path, "dvd", 3)==0) { DI_Init(); if(!ISO9660_Mount()) { printf("Failed to mount DVD ISO9660.\n"); DI_Close(); break; } } stat(path, &dolstats); dol_size = dolstats.st_size; fdol = fopen(path, "r"); if(fdol==NULL) { printf("Dol doesn't exist: %s\n", argv[1]); break; } else { fread((void*)0x90100000, 1, dol_size, fdol); DCFlushRange((void*)0x90100000, dol_size); fclose(fdol); } memset(path, 0, 256); if(strncmp(path, "dvd", 3)==0) { ISO9660_Unmount(); DI_Close(); } if(launchcode & BIT(26)) { unlink(path); VFF_Unmount("wc24dl.vff"); } } } SetDolArgv((void*)0x90100000, dol_size, argc, argv); DCFlushRange((void*)0x80001800, loader_bin_size); DCFlushRange(path, 256); if(!boothbdirect)WII_SetNANDBootInfoLaunchcode(0); if(!boothbdirect) { printf("Booting: %s\n", path); } else { printf("Booting homebrew directly from RAM buffer.\n"); } WC24_Shutdown(); WPAD_Shutdown(); FlushLog(); //IOS_ReloadIOS(36); SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); entry(); break; case 2://Boot game disc memcpy((void*)0x80001800, loader_bin, loader_bin_size); memset(path, 0, 256); memcpy((void*)0x90100000, tinyload_dol, tinyload_dol_size); DCFlushRange((void*)0x80001800, loader_bin_size); DCFlushRange(path, 256); DCFlushRange((void*)0x90100000, tinyload_dol_size); WII_SetNANDBootInfoLaunchcode(0); WC24_Shutdown(); WPAD_Shutdown(); printf("Booting game disc.\n"); FlushLog(); entry(); break; default: break; } } printf("Invalid launchcode or argc: %x %x\n", launchcode, argc); #ifdef DEBUG printf("Press A to contine.\n"); while(1) { WPAD_ScanPads(); if(WPAD_ButtonsDown(0) & WPAD_BUTTON_A)break; VIDEO_WaitVSync(); } #endif printf("Shutting down...\n"); printf("Shutting down WC24...\n"); if(launchcode & BIT(26))VFF_Unmount("wc24dl.vff"); WC24_Shutdown(); FlushLog(); WPAD_Shutdown(); WII_Shutdown(); }
int main(int argc, char *argv[]) { s32 res; #ifdef USE_WII_DI DI_Init(); #endif VIDEO_Init(); PAD_Init(); AUDIO_Init(NULL); #ifdef DEBUG_WII_USBGECKO CON_EnableGecko(1, false); #endif #ifdef DEBUG_WII_GDB DEBUG_Init(GDBSTUB_DEVICE_USB, 1); #endif printf("startup as "); if (argc > 0) printf("'%s'\n", argv[0]); else printf("<unknown>\n"); SYS_SetResetCallback(reset_cb); #ifndef GAMECUBE SYS_SetPowerCallback(power_cb); #endif #ifdef USE_WII_DI // initial async mount for the browser, see wii-fs.cpp DI_Mount(); #endif if (!fatInitDefault()) { printf("fatInitDefault failed\n"); } else { // set the default path if libfat couldnt set it // this allows loading over tcp/usbgecko char cwd[MAXPATHLEN]; if (getcwd(cwd, MAXPATHLEN)) { size_t len = strlen(cwd); if (len > 2 && (cwd[len - 1] == ':' || cwd[len - 2] == ':')) { printf("chdir to default\n"); chdir("/apps/scummvm"); } } } g_system = new OSystem_Wii(); assert(g_system); res = scummvm_main(argc, argv); g_system->quit(); printf("shutdown\n"); fatUnmountDefault(); #ifdef USE_WII_DI DI_Close(); #endif if (power_btn_pressed) { printf("shutting down\n"); SYS_ResetSystem(SYS_POWEROFF, 0, 0); } printf("reloading\n"); return res; }
void Gui::draw() { // printf("Gui draw\n"); Input::getInstance().refreshInput(); Cursor::getInstance().updateCursor(); Focus::getInstance().updateFocus(); if(padAutoAssign) auto_assign_controllers(); //Update time?? //Get graphics framework and pass to Frame draw fns? gfx->drawInit(); drawBackground(); FrameList::const_iterator iteration; for (iteration = frameList.begin(); iteration != frameList.end(); iteration++) { (*iteration)->updateTime(0.0f); //TODO: Pass deltaTime (*iteration)->drawChildren(*gfx); } // menuLogo->drawComponent(*gfx); menuLogo->draw(*gfx); if (MessageBox::getInstance().getActive()) MessageBox::getInstance().drawMessageBox(*gfx); if (LoadingBar::getInstance().getActive()) LoadingBar::getInstance().drawLoadingBar(*gfx); Cursor::getInstance().drawCursor(*gfx); if(shutdown) { Cursor::getInstance().setFreezeAction(true); Focus::getInstance().setFreezeAction(true); gfx->enableBlending(true); gfx->setTEV(GX_PASSCLR); gfx->setDepth(-10.0f); gfx->newModelView(); gfx->loadModelView(); gfx->loadOrthographic(); gfx->setColor((GXColor){0, 0, 0, fade}); if(screenMode) gfx->fillRect(-104, 0, 848, 480); else gfx->fillRect(0, 0, 640, 480); if(fade == 255) { VIDEO_SetBlack(true); VIDEO_Flush(); VIDEO_WaitVSync(); if(shutdown==1) //Power off System SYS_ResetSystem(SYS_POWEROFF, 0, 0); else //Return to Loader { #ifdef WII if(dvd_hard_init) { DI_Close(); } #endif void (*rld)() = (void (*)()) 0x80001800; rld(); } } char increment = 3; fade = fade +increment > 255 ? 255 : fade + increment; } gfx->swapBuffers(); }
u16 ogc_input__getMenuButtons(void) { #ifdef HW_RVL if (Shutdown) { /* autosave SRAM/State */ memfile_autosave(); /* shutdown Wii */ DI_Close(); SYS_ResetSystem(SYS_POWEROFF, 0, 0); } #endif /* slowdown input updates */ VIDEO_WaitVSync(); /* get gamepad inputs */ PAD_ScanPads(); u16 p = PAD_ButtonsDown(0); s8 x = PAD_StickX(0); s8 y = PAD_StickY(0); if (x > 70) p |= PAD_BUTTON_RIGHT; else if (x < -70) p |= PAD_BUTTON_LEFT; if (y > 60) p |= PAD_BUTTON_UP; else if (y < -60) p |= PAD_BUTTON_DOWN; #ifdef HW_RVL /* get wiimote + expansions inputs */ WPAD_ScanPads(); u32 q = WPAD_ButtonsDown(0); u32 h = WPAD_ButtonsHeld(0); x = WPAD_StickX(0, 0); y = WPAD_StickY(0, 0); /* is Wiimote directed toward screen (horizontal/vertical orientation) ? */ struct ir_t ir; WPAD_IR(0, &ir); /* wiimote directions */ if (q & WPAD_BUTTON_UP) p |= ir.valid ? PAD_BUTTON_UP : PAD_BUTTON_LEFT; else if (q & WPAD_BUTTON_DOWN) p |= ir.valid ? PAD_BUTTON_DOWN : PAD_BUTTON_RIGHT; else if (q & WPAD_BUTTON_LEFT) p |= ir.valid ? PAD_BUTTON_LEFT : PAD_BUTTON_DOWN; else if (q & WPAD_BUTTON_RIGHT) p |= ir.valid ? PAD_BUTTON_RIGHT : PAD_BUTTON_UP; if (h & WPAD_BUTTON_UP) { held_cnt ++; if (held_cnt == MAX_HELD_CNT) { held_cnt = MAX_HELD_CNT - 2; p |= ir.valid ? PAD_BUTTON_UP : PAD_BUTTON_LEFT; } } else if (h & WPAD_BUTTON_DOWN) { held_cnt ++; if (held_cnt == MAX_HELD_CNT) { held_cnt = MAX_HELD_CNT - 2; p |= ir.valid ? PAD_BUTTON_DOWN : PAD_BUTTON_RIGHT; } } else if (h & WPAD_BUTTON_LEFT) { held_cnt ++; if (held_cnt == MAX_HELD_CNT) { held_cnt = MAX_HELD_CNT - 2; p |= ir.valid ? PAD_BUTTON_LEFT : PAD_BUTTON_DOWN; } } else if (h & WPAD_BUTTON_RIGHT) { held_cnt ++; if (held_cnt == MAX_HELD_CNT) { held_cnt = MAX_HELD_CNT - 2; p |= ir.valid ? PAD_BUTTON_RIGHT : PAD_BUTTON_UP; } } else { held_cnt = 0; } /* analog sticks */ if (y > 70) p |= PAD_BUTTON_UP; else if (y < -70) p |= PAD_BUTTON_DOWN; if (x < -60) p |= PAD_BUTTON_LEFT; else if (x > 60) p |= PAD_BUTTON_RIGHT; /* classic controller directions */ if (q & WPAD_CLASSIC_BUTTON_UP) p |= PAD_BUTTON_UP; else if (q & WPAD_CLASSIC_BUTTON_DOWN) p |= PAD_BUTTON_DOWN; if (q & WPAD_CLASSIC_BUTTON_LEFT) p |= PAD_BUTTON_LEFT; else if (q & WPAD_CLASSIC_BUTTON_RIGHT) p |= PAD_BUTTON_RIGHT; /* wiimote keys */ if (q & WPAD_BUTTON_MINUS) p |= PAD_TRIGGER_L; if (q & WPAD_BUTTON_PLUS) p |= PAD_TRIGGER_R; if (q & WPAD_BUTTON_A) p |= PAD_BUTTON_A; if (q & WPAD_BUTTON_B) p |= PAD_BUTTON_B; if (q & WPAD_BUTTON_2) p |= PAD_BUTTON_A; if (q & WPAD_BUTTON_1) p |= PAD_BUTTON_B; if (q & WPAD_BUTTON_HOME) p |= PAD_TRIGGER_Z; /* classic controller keys */ if (q & WPAD_CLASSIC_BUTTON_FULL_L) p |= PAD_TRIGGER_L; if (q & WPAD_CLASSIC_BUTTON_FULL_R) p |= PAD_TRIGGER_R; if (q & WPAD_CLASSIC_BUTTON_A) p |= PAD_BUTTON_A; if (q & WPAD_CLASSIC_BUTTON_B) p |= PAD_BUTTON_B; if (q & WPAD_CLASSIC_BUTTON_HOME) p |= PAD_TRIGGER_Z; #endif return p; }