/* Test 5 : boucle de lecture/écriture séquentielle avec localité * -------------------------------------------------------------- * Ce test tente de combiner une certaine localité avec la sequentialité. On effectue en fait * N_Working_Sets phases, chaque phase comportant le même nombre d'accès (noté * nlocal). Pour chaque phase, l'enregistrement de base (ind) progresse séquentiellement, * puis on tire au sort (nlocal fois) un incrément (incr) afin d'accéder à * l'enregistrement ind - incr (c'est-à-dire quelque chose qui a été accédé précedemment). * * Comme dans le test précédent on effectue une écriture tous les * Ratio_Read_Write accès, une lecture sinon. */ void Test_5() { /* nombre d'accès locaux pour un working set */ int nlocal = N_Loops / N_Working_Sets; int i; int k; /* Invalidation du cache */ if (!Cache_Invalidate(The_Cache)) Error("Test_5 : Cache_Invalidate"); /* Boucle mixte de lecture:écriture aléatoire */ for (i = 0, k = 0; i < N_Loops; i += nlocal, ++k) { if (i % N_Working_Sets == 0) { /* indice-fichier de l'enregistrement de base */ int ind = k * N_Records_in_File / N_Working_Sets; int j; /* On effectue nlocal accès à partir de ind */ for (j = 0; j < nlocal; ++j) { int incr = RANDOM(0, N_Local_Window);/* on tire au sort * l'enregistrement dans la * fenêtre locale */ int ind1 = ind - incr; /* indice de l'enregistrement à accéder */ /* On fait une écriture tous les Ratio_Read_Write accès */ int rd = (ind1 % Ratio_Read_Write != 0); struct Any temp; if (ind1 < 0) ind1 = 0; if (ind1 >= N_Records_in_File) ind1 = N_Records_in_File -1; temp.i = ind1; temp.x = (double)ind1; if (rd) { if (!Cache_Read(The_Cache, ind1, &temp)) Error("Test_5 : Cache_Read(ind)"); } else { if (!Cache_Write(The_Cache, ind1, &temp)) Error("Test_5 : Cache_Write(ind)"); } } } } Print_Instrument(The_Cache, "Test_5 : boucle lecture/écriture séquentielle avec localité"); }
/* Test 1 : boucle de lecture séquentielle * --------------------------------------- * On écrit un enregistreùent et on lit le précédent. La localité est bien sûr * excellente, toutes les stratégies doivent être efficaces. */ static void Test_1() { int ind; /* indice-fichier de l'enregistrement à écrire */ struct Any temp = {0, 0.0}; if (!Cache_Invalidate(The_Cache)) Error("Test_1 : Cache_Invalidate"); if (!Cache_Write(The_Cache, 0, &temp)) Error("Test_1 : Cache_Write(0)"); for (ind = 1; ind < N_Records_in_File; ind++) { temp.i = ind; temp.x = (double)ind; if (!Cache_Write(The_Cache, ind, &temp)) Error("Test_1 : Cache_Write"); if (!Cache_Read(The_Cache, ind - 1, &temp)) Error("Test_1 : Cache_Read"); } Print_Instrument(The_Cache, "Test_1 : boucle de lecture séquentielle"); }
/* Test 3 : boucle de lecture/écriture aléatoire * --------------------------------------------- * On tire au sort l'indice de l'enregistrement ainsi que le nombre nr * d'enregistrements consécutifs à partir de ind (nr est compris entre 1 et * N_Seq_Access - 1). Tous les Ratio_Read_Write accès on fait une écriture, * sinon une lecture. */ void Test_3() { int i; /* Invalidation du cache */ if (!Cache_Invalidate(The_Cache)) Error("Test_3 : Cache_Invalidate"); /* Boucle de lecture/écriture aléatoire */ for (i = 0; i < N_Loops; ) { int ind = RANDOM(0, N_Records_in_File); /* indice-fichier de l'enregistrement */ int nr = RANDOM(1, N_Seq_Access); /* nombre d'enregistrements consécutifs */ int j; if (nr <= 0) nr = 1; /* On lit ou écrit nr blocs consécutifs à partir de ind */ for (j = 0; j < nr; ++j) { struct Any temp; /* On fait une écriture tous les Ratio_Read_Write accès */ int rd = ((i + j) % Ratio_Read_Write != 0); temp.i = ind; temp.x = (double)ind; if (rd) { if (!Cache_Read(The_Cache, ind + j, &temp)) Error("Test_3 : Cache_Read"); } else { if (!Cache_Write(The_Cache, ind + j, &temp)) Error("Test_3 : Cache_Write"); } } /* On a fait nr accès de plus */ i += nr; } Print_Instrument(The_Cache, "Test_3 : boucle lecture/écriture aléatoire"); }
/* Test 2 : boucle d'écriture aléatoire * ------------------------------------ * On tire au sort ind entre 0 et N_Records_in_File et on écrit * l'enregistrement correspondant. */ void Test_2() { int ind; /* indice-fichier de l'enregistrement à écrire */ /* Invalidation du cache */ if (!Cache_Invalidate(The_Cache)) Error("Test_2 : Cache_Invalidate"); /* Accès (purement) aléatoire aux éléments en écriture */ for (ind = 0; ind < N_Loops; ind++) { int ind = RANDOM(0, N_Records_in_File); struct Any temp; temp.i = ind; temp.x = (double)ind; if (!Cache_Write(The_Cache, ind, &temp)) Error("Test_2 : Cache_Write"); } Print_Instrument(The_Cache, "Test_2 : boucle écriture aléatoire"); }
int Menu_Boot_Options(struct discHdr *header) { int ret_val = 0; if (CFG.disable_options) return 0; struct Game_CFG_2 *game_cfg2 = NULL; struct Game_CFG *game_cfg = NULL; int opt_saved, opt_ios_reload; int redraw_cover = 0; int rows, cols, win_size; CON_GetMetrics(&cols, &rows); if ((win_size = rows-9) < 3) win_size = 3; Con_Clear(); FgColor(CFG.color_header); printf_x(gt("Selected Game")); printf(":"); __console_flush(0); printf(" (%.6s)\n", header->id); DefaultColor(); printf(" %s %s\n\n", CFG.cursor_space, __Menu_PrintTitle(get_title(header))); __console_flush(0); // load_dolmenu((char*)header->id); game_cfg2 = CFG_get_game(header->id); if (!game_cfg2) { printf(gt("ERROR game opt")); printf("\n"); sleep(5); return 0; } game_cfg = &game_cfg2->curr; struct Menu menu; const int NUM_OPT = 16; char active[NUM_OPT]; menu_init(&menu, NUM_OPT); for (;;) { /* // fat on 249? if (wbfs_part_fs && !disc) { if (!is_ios_idx_mload(game_cfg->ios_idx)) { game_cfg->ios_idx = CFG_IOS_222_MLOAD; } } */ menu_init_active(&menu, active, sizeof(active)); opt_saved = game_cfg2->is_saved; // if not mload disable block ios reload opt opt_ios_reload = game_cfg->block_ios_reload; // if not ocarina and not wiird, deactivate hooks if (!game_cfg->ocarina && !CFG.wiird) { active[11] = 0; } //if admin lock is off or they're not in admin // mode then they can't hide/unhide games if (!CFG.admin_lock || CFG.admin_mode_locked) { active[14] = 0; } //These things shouldn't be changed if using a disc...maybe active[0] = 0; active[8] = 0; active[9] = 0; active[14] = 0; Con_Clear(); FgColor(CFG.color_header); printf_x(gt("Selected Game")); printf(":"); printf(" (%.6s)\n", header->id); DefaultColor(); printf(" %s %s\n\n", CFG.cursor_space, __Menu_PrintTitle(get_title(header))); FgColor(CFG.color_header); printf_x(gt("Game Options: %s"), CFG_is_changed(header->id) ? gt("[ CHANGED ]") : opt_saved ? gt("[ SAVED ]") : ""); printf("\n"); DefaultColor(); char c1 = '<', c2 = '>'; //if (opt_saved) { c1 = '['; c2 = ']'; } const char *str_vpatch[3]; str_vpatch[0] = gt("Off"); str_vpatch[1] = gt("On"); str_vpatch[2] = gt("All"); // start menu draw menu_begin(&menu); menu_jump_active(&menu); #define PRINT_OPT_S(N,V) \ printf("%s%c %s %c\n", con_align(N,18), c1, V, c2) #define PRINT_OPT_A(N,V) \ printf("%s%c%s%c\n", con_align(N,18), c1, V, c2) #define PRINT_OPT_B(N,V) \ PRINT_OPT_S(N,(V?gt("On"):gt("Off"))) menu_window_begin(&menu, win_size, NUM_OPT); if (menu_window_mark(&menu)) PRINT_OPT_S(gt("Favorite:"), is_favorite(header->id) ? gt("Yes") : gt("No")); if (menu_window_mark(&menu)) PRINT_OPT_S(gt("Language:"), languages[game_cfg->language]); if (menu_window_mark(&menu)) PRINT_OPT_S(gt("Video:"), videos[game_cfg->video]); if (menu_window_mark(&menu)) PRINT_OPT_S(gt("Video Patch:"), str_vpatch[game_cfg->video_patch]); if (menu_window_mark(&menu)) PRINT_OPT_B("VIDTV:", game_cfg->vidtv); if (menu_window_mark(&menu)) PRINT_OPT_B(gt("Country Fix:"), game_cfg->country_patch); if (menu_window_mark(&menu)) PRINT_OPT_B(gt("Anti 002 Fix:"), game_cfg->fix_002); if (menu_window_mark(&menu)) PRINT_OPT_B(gt("Block IOS Reload:"), opt_ios_reload); if (menu_window_mark(&menu)) PRINT_OPT_B(gt("Ocarina (cheats):"), game_cfg->ocarina); if (menu_window_mark(&menu)) PRINT_OPT_S(gt("Hook Type:"), hook_name[game_cfg->hooktype]); if (menu_window_mark(&menu)) PRINT_OPT_A(gt("Cheat Codes:"), gt("Manage")); if (menu_window_mark(&menu)) printf("%s%s\n", con_align(gt("Cover Image:"), 18), imageNotFound ? gt("< DOWNLOAD >") : gt("[ FOUND ]")); if (menu_window_mark(&menu)) PRINT_OPT_S(gt("Hide Game:"), is_hide_game(header->id) ? gt("Yes") : gt("No")); if (menu_window_mark(&menu)) PRINT_OPT_B(gt("Write Playlog:"), game_cfg->write_playlog); DefaultColor(); menu_window_end(&menu, cols); printf_h(gt("Press %s to start game"), (button_names[CFG.button_confirm.num])); printf("\n"); bool need_save = !opt_saved || CFG_is_changed(header->id); if (need_save) printf_h(gt("Press %s to save options"), (button_names[CFG.button_save.num])); else printf_h(gt("Press %s to discard options"), (button_names[CFG.button_save.num])); printf("\n"); printf_h(gt("Press %s for global options"), (button_names[CFG.button_other.num])); DefaultColor(); __console_flush(0); if (redraw_cover) { Gui_DrawCover(header->id); redraw_cover = 0; } u32 buttons = Wpad_WaitButtonsRpt(); int change = 0; menu_move_active(&menu, buttons); if (buttons & WPAD_BUTTON_LEFT) change = -1; if (buttons & WPAD_BUTTON_RIGHT) change = +1; if (change) { switch (menu.current) { case 0: printf("\n\n"); printf_x(gt("Saving Settings... ")); __console_flush(0); if (set_favorite(header->id, change > 0)) { printf(gt("OK")); } else { printf(gt("ERROR")); sleep(1); } __console_flush(0); Gui_DrawCover(header->id); break; case 1: CHANGE(game_cfg->language, CFG_LANG_MAX); break; case 2: CHANGE(game_cfg->video, CFG_VIDEO_MAX); break; case 3: CHANGE(game_cfg->video_patch, 2); break; case 4: CHANGE(game_cfg->vidtv, 1); break; case 5: CHANGE(game_cfg->country_patch, 1); break; case 6: CHANGE(game_cfg->fix_002, 1); break; case 7: CHANGE(game_cfg->block_ios_reload, 1); break; case 8: CHANGE(game_cfg->ocarina, 1); break; case 9: CHANGE(game_cfg->hooktype, NUM_HOOK-1); break; case 10: Menu_Cheats(header); break; case 11: printf("\n\n"); Download_Cover((char*)header->id, change > 0, true); Cache_Invalidate(); Gui_DrawCover(header->id); Menu_PrintWait(); break; case 12: // hide game printf("\n\n"); printf_x(gt("Saving Settings... ")); __console_flush(0); if (set_hide_game(header->id, change > 0)) { printf(gt("OK")); } else { printf(gt("ERROR")); sleep(1); } __console_flush(0); Gui_DrawCover(header->id); break; case 13: CHANGE(game_cfg->write_playlog, 1); break; } } if (buttons & CFG.button_confirm.mask) { CFG.confirm_start = 0; Menu_Boot(); break; } if (buttons & CFG.button_save.mask) { bool ret; printf("\n\n"); if (need_save) { ret = CFG_save_game_opt(header->id); if (ret) { printf_x(gt("Options saved for this game.")); } else printf(gt("Error saving options!")); } else { ret = CFG_discard_game_opt(header->id); if (ret) printf_x(gt("Options discarded for this game.")); else printf(gt("Error discarding options!")); } sleep(1); } // HOME button if (buttons & CFG.button_exit.mask) { Handle_Home(0); } if (buttons & CFG.button_other.mask) { ret_val = 1; break; } if (buttons & CFG.button_cancel.mask) break; } CFG_release_game(game_cfg2); return ret_val; }
s32 __Menu_GetEntries(void) { struct discHdr *buffer = NULL; u32 cnt, len; s32 ret; Cache_Invalidate(); Switch_Favorites(false); SAFE_FREE(fav_gameList); fav_gameCnt = 0; SAFE_FREE(filter_gameList); filter_gameCnt = 0; /* Get list length */ ret = WBFS_GetCount(&cnt); if (ret < 0) return ret; /* Buffer length */ len = sizeof(struct discHdr) * cnt; /* Allocate memory */ buffer = (struct discHdr *)memalign(32, len); if (!buffer) return -1; /* Clear buffer */ memset(buffer, 0, len); /* Get header list */ ret = WBFS_GetHeaders(buffer, cnt, sizeof(struct discHdr)); if (ret < 0) goto err; /* Sort entries */ __set_default_sort(); qsort(buffer, cnt, sizeof(struct discHdr), default_sort_function); // hide and re-sort preffered if (!CFG.admin_lock || CFG.admin_mode_locked) cnt = CFG_hide_games(buffer, cnt); CFG_sort_pref(buffer, cnt); /* Free memory */ if (gameList) free(gameList); /* Set values */ gameList = buffer; gameCnt = cnt; /* Reset variables */ gameSelected = gameStart = 0; // init favorites all_gameList = gameList; all_gameCnt = gameCnt; len = sizeof(struct discHdr) * all_gameCnt; fav_gameList = (struct discHdr *)memalign(32, len); if (fav_gameList) { memcpy(fav_gameList, all_gameList, len); fav_gameCnt = all_gameCnt; } filter_gameList = (struct discHdr *)memalign(32, len); if (filter_gameList) { memcpy(filter_gameList, all_gameList, len); filter_gameCnt = all_gameCnt; } return 0; err: /* Free memory */ if (buffer) free(buffer); return ret; }
void DoAction(int action) { if (action & CFG_BTN_REMAP) return; switch(action) { case CFG_BTN_NOTHING: break; case CFG_BTN_OPTIONS: if (!CFG.disable_options) Menu_Options(); break; case CFG_BTN_GUI: if (go_gui) { action_string[0] = 0; action_alpha=0; } if (CFG.gui) go_gui = !go_gui; break; case CFG_BTN_REBOOT: Con_Clear(); Restart(); break; case CFG_BTN_EXIT: Con_Clear(); printf("\n"); printf_("Exiting..."); __console_flush(0); Sys_Exit(); break; case CFG_BTN_SCREENSHOT: __console_flush(0); Make_ScreenShot(); CFG.home = CFG_HOME_EXIT; break; case CFG_BTN_MAIN_MENU: Menu_Views(); break; case CFG_BTN_GLOBAL_OPS: if (!CFG.disable_options) Menu_Global_Options(); break; case CFG_BTN_PROFILE: if (CFG.current_profile == CFG.num_profiles-1) CFG.current_profile = 0; else CFG.current_profile++; Switch_Favorites(enable_favorite); sprintf(action_string, gt("Profile: %s"), CFG.profile_names[CFG.current_profile]); break; case CFG_BTN_FAVORITES: { extern void reset_sort_default(); reset_sort_default(); Switch_Favorites(!enable_favorite); } break; case CFG_BTN_BOOT_GAME: Menu_Boot(0); break; case CFG_BTN_BOOT_DISC: Menu_Boot(1); break; case CFG_BTN_THEME: CFG_switch_theme(cur_theme + 1); if (gameCnt) Gui_DrawCover(gameList[gameSelected].id);//redraw_cover = 1; Cache_Invalidate(); sprintf(action_string, gt("Theme: %s"), theme_list[cur_theme]); if (go_gui) action_alpha = 0xFF; break; case CFG_BTN_UNLOCK: if (CFG.admin_lock) Menu_Unlock(); break; case CFG_BTN_HBC: Con_Clear(); printf("\n"); printf_("HBC..."); __console_flush(0); Sys_HBC(); break; case CFG_BTN_SORT: if (sort_desc) { sort_desc = 0; if (sort_index == sortCnt - 1) sort_index = 0; else sort_index = sort_index + 1; sortList(sortTypes[sort_index].sortAsc); } else { sort_desc = 1; sortList(sortTypes[sort_index].sortDsc); } if (gameCnt) Gui_DrawCover(gameList[gameSelected].id);//redraw_cover = 1; sprintf(action_string, gt("Sort: %s-%s"), sortTypes[sort_index].name, (sort_desc) ? "DESC":"ASC"); break; case CFG_BTN_FILTER: Menu_Filter(); break; default: // Priiloader magic words, and channels if ((action & 0xFF) < 'a') { // upper case final letter implies channel Con_Clear(); Sys_Channel(action); } else { // lower case final letter implies magic word Con_Clear(); *(vu32*)0x8132FFFB = action; Restart(); } break; } }
int Menu_Global_Options() { int rows, cols, win_size = 11; CON_GetMetrics(&cols, &rows); if (strcmp(LAST_CFG_PATH, USBLOADER_PATH)) win_size += 2; if ((win_size = rows-win_size) < 3) win_size = 3; if (CFG.disable_options) return 0; struct discHdr *header = NULL; int redraw_cover = 0; struct Menu menu; menu_init(&menu, 9); for (;;) { menu.line_count = 0; if (gameCnt) { header = &gameList[gameSelected]; } else { header = NULL; } Con_Clear(); FgColor(CFG.color_header); printf_x(gt("Global Options")); printf(":\n\n"); DefaultColor(); menu_window_begin(&menu, win_size, 9); if (menu_window_mark(&menu)) printf("<%s>\n", gt("Main Menu")); if (menu_window_mark(&menu)) printf("%s%2d/%-2d< %s > (%d)\n", con_align(gt("Profile:"),8), CFG.current_profile + 1, CFG.num_profiles, CFG.profile_names[CFG.current_profile], CFG.num_favorite_game); if (menu_window_mark(&menu)) printf("%s%2d/%2d < %s >\n", con_align(gt("Theme:"),7), cur_theme + 1, num_theme, *CFG.theme ? CFG.theme : gt("none")); if (menu_window_mark(&menu)) printf("%s< %s >\n", con_align(gt("Partition:"),13), CFG.partition); if (menu_window_mark(&menu)) printf("<%s>\n", gt("Download All Missing Covers")); if (menu_window_mark(&menu)) printf("<%s>\n", gt("Update WiiTDB Game Database")); // download database - lustar if (menu_window_mark(&menu)) printf("<%s>\n", gt("Update titles.txt")); if (menu_window_mark(&menu)) printf("<%s>\n", gt("Check For Updates")); DefaultColor(); menu_window_end(&menu, cols); printf_h(gt("Press %s for game options"), (button_names[CFG.button_other.num])); printf("\n"); printf_h(gt("Press %s to save global settings"), (button_names[CFG.button_save.num])); printf("\n\n"); Print_SYS_Info(); DefaultColor(); __console_flush(0); if (redraw_cover) { if (header) Gui_DrawCover(header->id); redraw_cover = 0; } u32 buttons = Wpad_WaitButtonsRpt(); menu_move(&menu, buttons); int change = 0; if (buttons & WPAD_BUTTON_LEFT) change = -1; if (buttons & WPAD_BUTTON_RIGHT) change = +1; if (buttons & CFG.button_confirm.mask) change = +1; if (change) { switch (menu.current) { case 0: Menu_Views(); return 0; case 1: CHANGE(CFG.current_profile, CFG.num_profiles-1); // refresh favorites list Switch_Favorites(enable_favorite); redraw_cover = 1; break; case 2: CFG_switch_theme(cur_theme + change); redraw_cover = 1; Cache_Invalidate(); break; case 3: Menu_Partition(true); return 0; case 4: Download_All_Covers(change > 0); Cache_Invalidate(); if (header) Gui_DrawCover(header->id); Menu_PrintWait(); break; case 5: Download_XML(); break; case 6: Download_Titles(); break; case 7: Online_Update(); break; } } // HOME button if (buttons & CFG.button_exit.mask) { Handle_Home(0); } if (buttons & CFG.button_save.mask) { int ret; printf("\n"); printf_x(gt("Saving Settings... ")); printf("\n"); __console_flush(0); FgColor(CFG.color_inactive); ret = CFG_Save_Global_Settings(); DefaultColor(); if (ret) { printf_(gt("OK")); printf("\n"); Save_Game_List(); } else { printf_(gt("ERROR")); } printf("\n"); //sleep(2); Menu_PrintWait(); } if (buttons & WPAD_BUTTON_PLUS) { printf("\n"); mem_stat(); Menu_PrintWait(); } if (buttons & CFG.button_other.mask) return 1; if (buttons & CFG.button_cancel.mask) break; } return 0; }