⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui.c

📁 psp上的GBA模拟器
💻 C
📖 第 1 页 / 共 3 页
字号:
}                                                                             \#define cheat_option(number)                                                  \{                                                                             \  NULL,                                                                       \  NULL,                                                                       \  NULL,                                                                       \  cheat_format_str[number],                                                   \  enable_disable_options,                                                     \  &(cheats[number].cheat_active),                                             \  2,                                                                          \  "Activate/deactivate this cheat code.",                                     \  number,                                                                     \  STRING_SELECTION_OPTION                                                     \}                                                                             \#define action_option(action_function, passive_function, display_string,      \ help_string, line_number)                                                    \{                                                                             \  action_function,                                                            \  passive_function,                                                           \  NULL,                                                                       \  display_string,                                                             \  NULL,                                                                       \  NULL,                                                                       \  0,                                                                          \  help_string,                                                                \  line_number,                                                                \  ACTION_OPTION                                                               \}                                                                             \#define submenu_option(sub_menu, display_string, help_string, line_number)    \{                                                                             \  NULL,                                                                       \  NULL,                                                                       \  sub_menu,                                                                   \  display_string,                                                             \  NULL,                                                                       \  NULL,                                                                       \  sizeof(sub_menu) / sizeof(menu_option_type),                                \  help_string,                                                                \  line_number,                                                                \  SUBMENU_OPTION                                                              \}                                                                             \#define selection_option(passive_function, display_string, options,           \ option_ptr, num_options, help_string, line_number, type)                     \{                                                                             \  NULL,                                                                       \  passive_function,                                                           \  NULL,                                                                       \  display_string,                                                             \  options,                                                                    \  option_ptr,                                                                 \  num_options,                                                                \  help_string,                                                                \  line_number,                                                                \  type                                                                        \}                                                                             \#define action_selection_option(action_function, passive_function,            \ display_string, options, option_ptr, num_options, help_string, line_number,  \ type)                                                                        \{                                                                             \  action_function,                                                            \  passive_function,                                                           \  NULL,                                                                       \  display_string,                                                             \  options,                                                                    \  option_ptr,                                                                 \  num_options,                                                                \  help_string,                                                                \  line_number,                                                                \  type | ACTION_OPTION                                                        \}                                                                             \#define string_selection_option(passive_function, display_string, options,    \ option_ptr, num_options, help_string, line_number)                           \  selection_option(passive_function, display_string ": %s", options,          \   option_ptr, num_options, help_string, line_number, STRING_SELECTION_OPTION)\#define numeric_selection_option(passive_function, display_string,            \ option_ptr, num_options, help_string, line_number)                           \  selection_option(passive_function, display_string ": %d", NULL, option_ptr, \   num_options, help_string, line_number, NUMBER_SELECTION_OPTION)            \#define string_selection_action_option(action_function, passive_function,     \ display_string, options, option_ptr, num_options, help_string, line_number)  \  action_selection_option(action_function, passive_function,                  \   display_string ": %s",  options, option_ptr, num_options, help_string,     \   line_number, STRING_SELECTION_OPTION)                                      \#define numeric_selection_action_option(action_function, passive_function,    \ display_string, option_ptr, num_options, help_string, line_number)           \  action_selection_option(action_function, passive_function,                  \   display_string ": %d",  NULL, option_ptr, num_options, help_string,        \   line_number, NUMBER_SELECTION_OPTION)                                      \#define numeric_selection_action_hide_option(action_function,                 \ passive_function, display_string, option_ptr, num_options, help_string,      \ line_number)                                                                 \  action_selection_option(action_function, passive_function,                  \   display_string, NULL, option_ptr, num_options, help_string,                \   line_number, NUMBER_SELECTION_OPTION)                                      \#define GAMEPAD_MENU_WIDTH 15u32 gamepad_config_line_to_psp_button[] = { 8, 6, 7, 9, 1, 2, 3, 0, 4, 5, 11, 10 };s32 load_game_config_file(){  u8 game_config_filename[512];  u32 file_loaded = 0;  u32 i;  change_ext(gamepak_filename, game_config_filename, ".cfg");  file_open(game_config_file, game_config_filename, read);  if(file_check_valid(game_config_file))  {    u32 file_size = file_length(game_config_filename, game_config_file);    // Sanity check: File size must be the right size    if(file_size == 56)    {      u32 file_options[file_size / 4];      file_read_array(game_config_file, file_options);      current_frameskip_type = file_options[0] % 3;      frameskip_value = file_options[1];      random_skip = file_options[2] & 1;      clock_speed = file_options[3];      if(clock_speed > 333)        clock_speed = 333;      if(clock_speed < 33)        clock_speed = 33;      if(frameskip_value < 0)        frameskip_value = 0;      if(frameskip_value > 99)        frameskip_value = 99;      file_close(game_config_file);      file_loaded = 1;    }  }  if(file_loaded)    return 0;  current_frameskip_type = auto_frameskip;  frameskip_value = 4;  random_skip = 0;  clock_speed = 333;  for(i = 0; i < 10; i++)  {    cheats[i].cheat_active = 0;  }  return -1;}s32 load_config_file(){  u8 config_path[512];  #ifdef PSP_BUILD    sprintf(config_path, "%s/%s", main_path, GPSP_CONFIG_FILENAME);  #else    sprintf(config_path, "%s\\%s", main_path, GPSP_CONFIG_FILENAME);  #endif  file_open(config_file, config_path, read);  if(file_check_valid(config_file))  {    u32 file_size = file_length(config_path, config_file);    // Sanity check: File size must be the right size    if(file_size == 92)    {      u32 file_options[file_size / 4];      u32 i;      s32 menu_button = -1;      file_read_array(config_file, file_options);      screen_scale = file_options[0] % 3;      screen_filter = file_options[1] % 2;      global_enable_audio = file_options[2] % 2;      audio_buffer_size_number = file_options[3] % 11;      update_backup_flag = file_options[4] % 2;      global_enable_analog = file_options[5] % 2;      analog_sensitivity_level = file_options[6] % 8;#ifdef PSP_BUILD    scePowerSetClockFrequency(clock_speed, clock_speed, clock_speed / 2);#endif      // Sanity check: Make sure there's a MENU or FRAMESKIP      // key, if not assign to triangle      for(i = 0; i < 16; i++)      {        gamepad_config_map[i] = file_options[7 + i] %         (BUTTON_ID_NONE + 1);        if(gamepad_config_map[i] == BUTTON_ID_MENU)        {          menu_button = i;        }      }      if(menu_button == -1)      {        gamepad_config_map[0] = BUTTON_ID_MENU;      }      file_close(config_file);    }    return 0;  }  return -1;}s32 save_game_config_file(){  u8 game_config_filename[512];  u32 i;  change_ext(gamepak_filename, game_config_filename, ".cfg");  file_open(game_config_file, game_config_filename, write);  if(file_check_valid(game_config_file))  {    u32 file_options[14];    file_options[0] = current_frameskip_type;    file_options[1] = frameskip_value;    file_options[2] = random_skip;    file_options[3] = clock_speed;    for(i = 0; i < 10; i++)    {      file_options[4 + i] = cheats[i].cheat_active;    }    file_write_array(game_config_file, file_options);    file_close(game_config_file);    return 0;  }  return -1;}s32 save_config_file(){  u8 config_path[512];  #ifdef PSP_BUILD    sprintf(config_path, "%s/%s", main_path, GPSP_CONFIG_FILENAME);  #else    sprintf(config_path, "%s\\%s", main_path, GPSP_CONFIG_FILENAME);  #endif  file_open(config_file, config_path, write);  save_game_config_file();  if(file_check_valid(config_file))  {    u32 file_options[23];    u32 i;    file_options[0] = screen_scale;    file_options[1] = screen_filter;    file_options[2] = global_enable_audio;    file_options[3] = audio_buffer_size_number;    file_options[4] = update_backup_flag;    file_options[5] = global_enable_analog;    file_options[6] = analog_sensitivity_level;    for(i = 0; i < 16; i++)    {      file_options[7 + i] = gamepad_config_map[i];    }    file_write_array(config_file, file_options);    file_close(config_file);    return 0;  }  return -1;}typedef enum{  MAIN_MENU,  GAMEPAD_MENU,  SAVESTATE_MENU,  FRAMESKIP_MENU,  CHEAT_MENU} menu_enum;u32 savestate_slot = 0;void get_savestate_snapshot(u8 *savestate_filename){  u16 snapshot_buffer[240 * 160];  u8 savestate_timestamp_string[80];  file_open(savestate_file, savestate_filename, read);  if(file_check_valid(savestate_file))  {    u8 weekday_strings[7][11] =    {      "Sunday", "Monday", "Tuesday", "Wednesday",      "Thursday", "Friday", "Saturday"    };    time_t savestate_time_flat;    struct tm *current_time;    file_read_array(savestate_file, snapshot_buffer);    file_read_variable(savestate_file, savestate_time_flat);    file_close(savestate_file);    current_time = localtime(&savestate_time_flat);    sprintf(savestate_timestamp_string,     "%s  %02d/%02d/%04d  %02d:%02d:%02d                ",     weekday_strings[current_time->tm_wday], current_time->tm_mon + 1,     current_time->tm_mday, current_time->tm_year + 1900,     current_time->tm_hour, current_time->tm_min, current_time->tm_sec);    savestate_timestamp_string[40] = 0;    print_string(savestate_timestamp_string, COLOR_HELP_TEXT, COLOR_BG,     10, 40);  }  else  {    memset(snapshot_buffer, 0, 240 * 160 * 2);    print_string_ext("No savestate exists for this slot.",     0xFFFF, 0x0000, 15, 75, snapshot_buffer, 240, 0);    print_string("---------- --/--/---- --:--:--          ", COLOR_HELP_TEXT,     COLOR_BG, 10, 40);  }  blit_to_screen(snapshot_buffer, 240, 160, 230, 40);}void get_savestate_filename(u32 slot, u8 *name_buffer){  u8 savestate_ext[16];  sprintf(savestate_ext, "%d.svs", slot);  change_ext(gamepak_filename, name_buffer, savestate_ext);  get_savestate_snapshot(name_buffer);}void get_savestate_filename_noshot(u32 slot, u8 *name_buffer){  u8 savestate_ext[16];  sprintf(savestate_ext, "%d.svs", slot);  change_ext(gamepak_filename, name_buffer, savestate_ext);}#ifdef PSP_BUILD  void _flush_cache()  {    sceKernelDcacheWritebackAll();  }#endifu32 menu(u16 *original_screen){  u32 clock_speed_number = (clock_speed / 33) - 1;  u8 print_buffer[81];  u32 _current_option = 0;  gui_action_type gui_action;  menu_enum _current_menu = MAIN_MENU;  u32 i;  u32 repeat = 1;  u32 return_value = 0;  u32 first_load = 0;  u8 savestate_ext[16];  u8 current_savestate_filename[512];  u8 line_buffer[80];  u8 cheat_format_str[10][41];  menu_type *current_menu;  menu_option_type *current_option;  menu_option_type *display_option;  u32 current_option_num;  auto void choose_menu();  auto void clear_help();  u8 *gamepad_help[] =  {    "Up button on GBA d-pad.",    "Down button on GBA d-pad.",    "Left button on GBA d-pad.",    "Right button on GBA d-pad.",    "A button on GBA.",    "B button on GBA.",    "Left shoulder button on GBA.",    "Right shoulder button on GBA.",    "Start button on GBA.",    "Select button on GBA.",    "Brings up frameskip adjust bar and menu access.",    "Jumps directly to the menu.",    "Toggles fastforward on/off (don't expect it to do much or anything)",    "Loads the game state from the current slot.",    "Saves the game state to the current slot.",    "Rapidly press/release the A button on GBA.",    "Rapidly press/release the B button on GBA.",    "Rapidly press/release the Left shoulder button on GBA.",    "Rapidly press/release the Right shoulder button on GBA.",    "Does nothing."  };  void menu_exit()  {    if(!first_load)     repeat = 0;  }  void menu_quit()  {    clock_speed = (clock_speed_number + 1) * 33;    save_config_file();    quit();  }  void menu_load()  {    u8 *file_ext[] = { ".gba", ".bin", ".zip", NULL };    u8 load_filename[512];    save_game_config_file();    if(load_file(file_ext, load_filename) != -1)    {       if(load_gamepak(load_filename) == -1)       {         quit();       }       reset_gba();       return_value = 1;       repeat = 0;       reg[CHANGED_PC_STATUS] = 1;    }    else    {      choose_menu(current_menu);    }  }  void menu_restart()  {    if(!first_load)    {      reset_gba();      reg[CHANGED_PC_STATUS] = 1;      return_value = 1;      repeat = 0;    }  }  void menu_change_state()  {    get_savestate_filename(savestate_slot, current_savestate_filename);  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -