/* Initialise Video, PAD, DVD, Font */ void* Initialise (void) { VIDEO_Init (); PAD_Init (); DVD_Init(); *(volatile unsigned long*)0xcc00643c = 0x00000000; //allow 32mhz exi bus // Disable IPL modchips to allow access to IPL ROM fonts ipl_set_config(6); usleep(1000); //wait for modchip to disable (overkill) __SYS_ReadROM(IPLInfo,256,0); // Read IPL tag // Wii has no IPL tags for "PAL" so let libOGC figure out the video mode if(!is_gamecube()) { vmode = VIDEO_GetPreferredMode(NULL); //Last mode used } else { // Gamecube, determine based on IPL int retPAD = 0, retCnt = 10000; while(retPAD <= 0 && retCnt >= 0) { retPAD = PAD_ScanPads(); usleep(100); retCnt--; } // L Trigger held down ignores the fact that there's a component cable plugged in. if(VIDEO_HaveComponentCable() && !(PAD_ButtonsDown(0) & PAD_TRIGGER_L)) { if(strstr(IPLInfo,"MPAL")!=NULL) { swissSettings.sramVideo = 2; vmode = &TVMpal480Prog; //Progressive 480p } else if((strstr(IPLInfo,"PAL")!=NULL)) { swissSettings.sramVideo = 1; vmode = &TVPal576ProgScale; //Progressive 576p } else { swissSettings.sramVideo = 0; vmode = &TVNtsc480Prog; //Progressive 480p } } else { //try to use the IPL region if(strstr(IPLInfo,"MPAL")!=NULL) { swissSettings.sramVideo = 2; vmode = &TVMpal480IntDf; //PAL-M } else if(strstr(IPLInfo,"PAL")!=NULL) { swissSettings.sramVideo = 1; vmode = &TVPal576IntDfScale; //PAL } else { swissSettings.sramVideo = 0; vmode = &TVNtsc480IntDf; //NTSC } } } initialise_video(vmode); populateVideoStr(vmode); init_font(); init_textures(); whichfb = 0; drive_version(&driveVersion[0]); swissSettings.hasDVDDrive = *(u32*)&driveVersion[0] ? 1 : 0; if(!driveVersion[0]) { // Reset DVD if there was a modchip DrawFrameStart(); WriteFontStyled(640/2, 250, "Initialise DVD .. (HOLD B if NO DVD Drive)", 0.8f, true, defaultColor); DrawFrameFinish(); dvd_reset(); // low-level, basic dvd_read_id(); if(!(PAD_ButtonsHeld(0) & PAD_BUTTON_B)) { dvd_set_streaming(*(char*)0x80000008); } drive_version(&driveVersion[0]); swissSettings.hasDVDDrive = *(u32*)&driveVersion[0] ? 1 : 0; if(!swissSettings.hasDVDDrive) { DrawFrameStart(); DrawMessageBox(D_INFO, "No DVD Drive Detected !!"); DrawFrameFinish(); sleep(2); } } return xfb[0]; }
/**************************************************************************** * Main ****************************************************************************/ int main () { // Setup defaults (if no config is found) memset(&swissSettings, 0 , sizeof(SwissSettings)); void *fb; fb = Initialise(); if(!fb) { return -1; } // Sane defaults refreshSRAM(); swissSettings.debugUSB = 1; swissSettings.gameVMode = 0; // Auto video mode swissSettings.exiSpeed = 1; // 32MHz swissSettings.uiVMode = 0; // Auto UI mode swissSettings.enableFileManagement = 0; config_copy_swiss_settings(&swissSettings); needsDeviceChange = 1; needsRefresh = 1; //debugging stuff if(swissSettings.debugUSB) { if(usb_isgeckoalive(1)) { usb_flush(1); } print_gecko("Arena Size: %iKb\r\n",(SYS_GetArena1Hi()-SYS_GetArena1Lo())/1024); print_gecko("DVD Drive Present? %s\r\n",swissSettings.hasDVDDrive?"Yes":"No"); print_gecko("GIT Commit: %s\r\n", GITREVISION); print_gecko("GIT Revision: %s\r\n", GITVERSION); } // Detect devices populateDeviceAvailability(); curDevice = -1; // Are we working with a Wiikey Fusion? if(__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF) { print_gecko("Detected Wiikey Fusion with SPI Flash ID: %08X\r\n",__wkfSpiReadId()); // Set real device back curDevice = WKF; // SlotB hack trySlotB(); } else { deviceHandler_setStatEnabled(0); // Try to init SD cards here and load config deviceHandler_initial = &initial_SD0; deviceHandler_init = deviceHandler_FAT_init; deviceHandler_deinit = deviceHandler_FAT_deinit; if(deviceHandler_init(deviceHandler_initial)) { print_gecko("Detected SDGecko in Slot A\r\n"); load_auto_dol(); curDevice = SD_CARD; } else { deviceHandler_deinit(deviceHandler_initial); deviceHandler_initial = &initial_SD1; if(deviceHandler_init(deviceHandler_initial)) { print_gecko("Detected SDGecko in Slot B\r\n"); load_auto_dol(); curDevice = SD_CARD; } } deviceHandler_setStatEnabled(1); } // If no device has been selected yet to browse .. if(curDevice < 0) { print_gecko("No default boot device detected, trying DVD!\r\n"); // Do we have a DVD drive with a ready medium we can perhaps browse then? u8 driveReallyExists[8]; drive_version(&driveReallyExists[0]); if(*(u32*)&driveReallyExists[0]) { dvd_read_id(); if(!dvd_get_error()) { print_gecko("DVD Medium is up, using it as default device\r\n"); curDevice = DVD_DISC; // If we have a GameCube (single image) bootable disc, show the banner screen here dvdDiscTypeInt = gettype_disc(); if(dvdDiscTypeInt == GAMECUBE_DISC) { select_device(1); // Setup curFile and load it memset(&curFile, 0, sizeof(file_handle)); strcpy(&curFile.name[0], "game.gcm"); curFile.size = DISC_SIZE; curFile.fileAttrib = IS_FILE; populate_meta(&curFile); load_file(); curDevice = -1; deviceHandler_initial = NULL; } } } } if(curDevice) { needsDeviceChange = 0; select_device(1); // to setup deviceHandler_ ptrs load_config(forceSlot); } // Start up the BBA if it exists init_network_thread(); init_httpd_thread(); // DVD Motor off if(swissSettings.stopMotor && swissSettings.hasDVDDrive) { dvd_motor_off(); } // Swiss video mode force GXRModeObj *forcedMode = getModeFromSwissSetting(swissSettings.uiVMode); if((forcedMode != NULL) && (forcedMode != vmode)) { initialise_video(forcedMode); vmode = forcedMode; } while(1) { main_loop(); } return 0; }
int show_settings(file_handle *file, ConfigEntry *config) { int page = 0, option = 0; // Refresh SRAM in case user changed it from IPL refreshSRAM(); // Copy current settings to a temp copy in case the user cancels out memcpy((void*)&tempSettings,(void*)&swissSettings, sizeof(SwissSettings)); // Setup the settings for the current game if(config != NULL) { page = 2; } while (PAD_ButtonsHeld(0) & PAD_BUTTON_A) { VIDEO_WaitVSync (); } while(1) { settings_draw_page(page, option, file); while (!((PAD_ButtonsHeld(0) & PAD_BUTTON_RIGHT) || (PAD_ButtonsHeld(0) & PAD_BUTTON_LEFT) || (PAD_ButtonsHeld(0) & PAD_BUTTON_UP) || (PAD_ButtonsHeld(0) & PAD_BUTTON_DOWN) || (PAD_ButtonsHeld(0) & PAD_BUTTON_B) || (PAD_ButtonsHeld(0) & PAD_BUTTON_A) || (PAD_ButtonsHeld(0) & PAD_TRIGGER_R) || (PAD_ButtonsHeld(0) & PAD_TRIGGER_L))) { VIDEO_WaitVSync (); } u16 btns = PAD_ButtonsHeld(0); if(btns & PAD_BUTTON_RIGHT) { // If we're on a button (Back, Next, Save, Exit), allow left/right movement if((page != 1) && (option >= settings_count_pp[page]-2) && option < settings_count_pp[page]) { option++; } else if((page == 1) && (option >= settings_count_pp[page]-3) && option < settings_count_pp[page]) { option++; } else { settings_toggle(page, option, 1, file); } } if(btns & PAD_BUTTON_LEFT) { // If we're on a button (Back, Next, Save, Exit), allow left/right movement if((page != 1) && (option > settings_count_pp[page]-2)) { option--; } else if((page == 1) && (option > settings_count_pp[page]-3)) { option--; } else { settings_toggle(page, option, -1, file); } } if((btns & PAD_BUTTON_DOWN) && option < settings_count_pp[page]) option++; if((btns & PAD_BUTTON_UP) && option > 0) option--; if((btns & PAD_TRIGGER_R) && page < 2) { page++; option = 0; } if((btns & PAD_TRIGGER_L) && page > 0) { page--; option = 0; } if((btns & PAD_BUTTON_B)) option = settings_count_pp[page]; // Handle all options/buttons here if((btns & PAD_BUTTON_A)) { // Generic Save/Cancel/Back/Next button actions if(option == settings_count_pp[page]-1) { DrawFrameStart(); DrawMessageBox(D_INFO,"Saving changes!"); DrawFrameFinish(); // Change Swiss video mode if it was modified. if(tempSettings.uiVMode != swissSettings.uiVMode) { GXRModeObj *newmode = getModeFromSwissSetting(swissSettings.uiVMode); initialise_video(newmode); vmode = newmode; } // Save settings to SRAM sram = __SYS_LockSram(); sram->lang = swissSettings.sramLanguage; sram->flags = swissSettings.sramStereo ? (sram->flags|0x04):(sram->flags&~0x04); sram->flags = (swissSettings.sramVideo&0x03)|(sram->flags&~0x03); __SYS_UnlockSram(1); while(!__SYS_SyncSram()); // Update our .ini if(config != NULL) { config->gameVMode = swissSettings.gameVMode; config->softProgressive = swissSettings.softProgressive; config->muteAudioStreaming = swissSettings.muteAudioStreaming; config->forceWidescreen = swissSettings.forceWidescreen; config->forceAnisotropy = swissSettings.forceAnisotropy; config->forceEncoding = swissSettings.forceEncoding; } else { // Save the Swiss system settings since we're called from the main menu if((curDevice == SD_CARD)||(curDevice == IDEEXI)) { DrawFrameStart(); DrawMessageBox(D_INFO,"Saving Config ..."); DrawFrameFinish(); config_copy_swiss_settings(&swissSettings); if(config_update_file()) { DrawFrameStart(); DrawMessageBox(D_INFO,"Config Saved Successfully!"); DrawFrameFinish(); } else { DrawFrameStart(); DrawMessageBox(D_INFO,"Config Failed to Save!"); DrawFrameFinish(); } } } return 1; } if(option == settings_count_pp[page]) { // Exit without saving (revert) memcpy((void*)&swissSettings, (void*)&tempSettings, sizeof(SwissSettings)); return 0; } if((page != 2) && (option == settings_count_pp[page]-2)) { page++; option = 0; } if((page != 0) && (option == settings_count_pp[page]-(page != 2 ? 3:2))) { page--; option = 0; } } while ((PAD_ButtonsHeld(0) & PAD_BUTTON_RIGHT) || (PAD_ButtonsHeld(0) & PAD_BUTTON_LEFT) || (PAD_ButtonsHeld(0) & PAD_BUTTON_UP) || (PAD_ButtonsHeld(0) & PAD_BUTTON_DOWN) || (PAD_ButtonsHeld(0) & PAD_BUTTON_B) || (PAD_ButtonsHeld(0) & PAD_BUTTON_A) || (PAD_ButtonsHeld(0) & PAD_TRIGGER_R) || (PAD_ButtonsHeld(0) & PAD_TRIGGER_L)) { VIDEO_WaitVSync (); } } }