u5 release
[gpsp.git] / gui.c
diff --git a/gui.c b/gui.c
index 18170f7..f03aa49 100644 (file)
--- a/gui.c
+++ b/gui.c
 #define COLOR_FRAMESKIP_BAR color16(15, 31, 31)
 #define COLOR_HELP_TEXT     color16(16, 40, 24)
 
 #define COLOR_FRAMESKIP_BAR color16(15, 31, 31)
 #define COLOR_HELP_TEXT     color16(16, 40, 24)
 
+#ifdef PSP_BUILD
+  #define get_clock_speed() \
+    clock_speed = (clock_speed_number + 1) * 33
+  #define get_clock_speed_number() \
+    clock_speed_number = (clock_speed / 33) - 1
+#elif defined(WIZ_BUILD)
+  #define get_clock_speed() \
+    clock_speed = 300 + (clock_speed_number * 3333) / 100
+  #define get_clock_speed_number() \
+    clock_speed_number = (clock_speed - 300) / 33
+#elif defined(GP2X_BUILD)
+  #define get_clock_speed() \
+    clock_speed = 150 + clock_speed_number * 10
+  #define get_clock_speed_number() \
+    clock_speed_number = (clock_speed - 150) / 10
+#else
+  #define get_clock_speed() 0
+  #define get_clock_speed_number() 0
+#endif
+
+const int
+#ifdef WIZ_BUILD
+  default_clock_speed = 533;
+#elif defined(GP2X_BUILD)
+  default_clock_speed = 200;
+#else
+  default_clock_speed = 333;
+#endif
 int sort_function(const void *dest_str_ptr, const void *src_str_ptr)
 {
   char *dest_str = *((char **)dest_str_ptr);
 int sort_function(const void *dest_str_ptr, const void *src_str_ptr)
 {
   char *dest_str = *((char **)dest_str_ptr);
@@ -112,11 +140,11 @@ s32 load_file(u8 **wildcards, u8 *result)
   u32 chosen_file, chosen_dir;
   u32 dialog_result = 1;
   s32 return_value = 1;
   u32 chosen_file, chosen_dir;
   u32 dialog_result = 1;
   s32 return_value = 1;
-  u32 current_file_selection;
-  u32 current_file_scroll_value;
+  s32 current_file_selection;
+  s32 current_file_scroll_value;
   u32 current_dir_selection;
   u32 current_dir_scroll_value;
   u32 current_dir_selection;
   u32 current_dir_scroll_value;
-  u32 current_file_in_scroll;
+  s32 current_file_in_scroll;
   u32 current_dir_in_scroll;
   u32 current_file_number, current_dir_number;
   u32 current_column = 0;
   u32 current_dir_in_scroll;
   u32 current_file_number, current_dir_number;
   u32 current_column = 0;
@@ -336,6 +364,13 @@ s32 load_file(u8 **wildcards, u8 *result)
                 current_file_in_scroll++;
               }
             }
                 current_file_in_scroll++;
               }
             }
+            else
+            {
+              clear_screen(COLOR_BG);
+              current_file_selection = 0;
+              current_file_scroll_value = 0;
+              current_file_in_scroll = 0;
+            }
           }
           else
           {
           }
           else
           {
@@ -356,6 +391,25 @@ s32 load_file(u8 **wildcards, u8 *result)
 
           break;
 
 
           break;
 
+        case CURSOR_R:
+          if (current_column != 0)
+            break;
+          clear_screen(COLOR_BG);
+         current_file_selection += FILE_LIST_ROWS;
+          if (current_file_selection > num_files - 1)
+            current_file_selection = num_files - 1;
+          current_file_scroll_value = current_file_selection - FILE_LIST_ROWS / 2;
+          if (current_file_scroll_value < 0)
+          {
+            current_file_scroll_value = 0;
+            current_file_in_scroll = current_file_selection;
+          }
+          else
+          {
+            current_file_in_scroll = FILE_LIST_ROWS / 2;
+          }
+          break;
+
         case CURSOR_UP:
           if(current_column == 0)
           {
         case CURSOR_UP:
           if(current_column == 0)
           {
@@ -372,6 +426,17 @@ s32 load_file(u8 **wildcards, u8 *result)
                 current_file_in_scroll--;
               }
             }
                 current_file_in_scroll--;
               }
             }
+            else
+            {
+              clear_screen(COLOR_BG);
+              current_file_selection = num_files - 1;
+              current_file_in_scroll = FILE_LIST_ROWS - 1;
+              if (current_file_in_scroll > num_files - 1)
+                current_file_in_scroll = num_files - 1;
+              current_file_scroll_value = num_files - FILE_LIST_ROWS;
+              if (current_file_scroll_value < 0)
+                current_file_scroll_value = 0;
+            }
           }
           else
           {
           }
           else
           {
@@ -391,7 +456,26 @@ s32 load_file(u8 **wildcards, u8 *result)
           }
           break;
 
           }
           break;
 
-        case CURSOR_RIGHT:
+        case CURSOR_L:
+          if (current_column != 0)
+            break;
+          clear_screen(COLOR_BG);
+         current_file_selection -= FILE_LIST_ROWS;
+          if (current_file_selection < 0)
+            current_file_selection = 0;
+          current_file_scroll_value = current_file_selection - FILE_LIST_ROWS / 2;
+          if (current_file_scroll_value < 0)
+          {
+            current_file_scroll_value = 0;
+            current_file_in_scroll = current_file_selection;
+          }
+          else
+          {
+            current_file_in_scroll = FILE_LIST_ROWS / 2;
+          }
+          break;
+
+         case CURSOR_RIGHT:
           if(current_column == 0)
           {
             if(num_dirs != 0)
           if(current_column == 0)
           {
             if(num_dirs != 0)
@@ -676,7 +760,10 @@ s32 load_game_config_file()
       random_skip = file_options[2] % 2;
       clock_speed = file_options[3];
 
       random_skip = file_options[2] % 2;
       clock_speed = file_options[3];
 
-#ifdef GP2X_BUILD
+#ifdef WIZ_BUILD
+      if(clock_speed > 900)
+        clock_speed = 533;
+#elif defined(GP2X_BUILD)
       if(clock_speed >= 300)
         clock_speed = 200;
 #else
       if(clock_speed >= 300)
         clock_speed = 200;
 #else
@@ -709,12 +796,11 @@ s32 load_game_config_file()
 
   current_frameskip_type = auto_frameskip;
   frameskip_value = 4;
 
   current_frameskip_type = auto_frameskip;
   frameskip_value = 4;
-  random_skip = 0;
-#ifdef GP2X_BUILD
-  clock_speed = 200;
-#else
-  clock_speed = 333;
+#ifdef WIZ_BUILD
+  frameskip_value = 1;
 #endif
 #endif
+  random_skip = 0;
+  clock_speed = default_clock_speed;
 
   for(i = 0; i < 10; i++)
   {
 
   for(i = 0; i < 10; i++)
   {
@@ -921,7 +1007,7 @@ void get_savestate_snapshot(u8 *savestate_filename)
   {
     memset(snapshot_buffer, 0, 240 * 160 * 2);
     print_string_ext("No savestate exists for this slot.",
   {
     memset(snapshot_buffer, 0, 240 * 160 * 2);
     print_string_ext("No savestate exists for this slot.",
-     0xFFFF, 0x0000, 15, 75, snapshot_buffer, 240, 0);
+     0xFFFF, 0x0000, 15, 75, snapshot_buffer, 240, 0, 0, FONT_HEIGHT);
     print_string("---------- --/--/---- --:--:--          ", COLOR_HELP_TEXT,
      COLOR_BG, 10, 40);
   }
     print_string("---------- --/--/---- --:--:--          ", COLOR_HELP_TEXT,
      COLOR_BG, 10, 40);
   }
@@ -959,9 +1045,7 @@ void get_savestate_filename_noshot(u32 slot, u8 *name_buffer)
 u32 menu(u16 *original_screen)
 {
   u32 clock_speed_number;
 u32 menu(u16 *original_screen)
 {
   u32 clock_speed_number;
-#ifdef GP2X_BUILD
-  static u32 clock_speed_old = 200;
-#endif
+  static u32 clock_speed_old = default_clock_speed;
   u8 print_buffer[81];
   u32 _current_option = 0;
   gui_action_type gui_action;
   u8 print_buffer[81];
   u32 _current_option = 0;
   gui_action_type gui_action;
@@ -1017,11 +1101,7 @@ u32 menu(u16 *original_screen)
 
   void menu_quit()
   {
 
   void menu_quit()
   {
-  #ifdef PSP_BUILD
-    clock_speed = (clock_speed_number + 1) * 33;
-  #elif defined(GP2X_BUILD)
-    clock_speed = 150 + clock_speed_number * 10;
-  #endif
+    get_clock_speed();
     save_config_file();
     quit();
   }
     save_config_file();
     quit();
   }
@@ -1154,9 +1234,14 @@ u32 menu(u16 *original_screen)
 
   u8 *scale_options[] =
   {
 
   u8 *scale_options[] =
   {
+#ifdef WIZ_BUILD
+    "unscaled 3:2", "scaled 3:2 (slower)",
+    "unscaled 3:2 (anti-tear)", "scaled 3:2 (anti-tear)"
+#else
     "unscaled 3:2", "scaled 3:2", "fullscreen"
 #ifdef PSP_BUILD
     " 16:9"
     "unscaled 3:2", "scaled 3:2", "fullscreen"
 #ifdef PSP_BUILD
     " 16:9"
+#endif
 #endif
   };
 
 #endif
   };
 
@@ -1181,7 +1266,15 @@ u32 menu(u16 *original_screen)
 
   u8 *update_backup_options[] = { "Exit only", "Automatic" };
 
 
   u8 *update_backup_options[] = { "Exit only", "Automatic" };
 
-#ifdef GP2X_BUILD
+#ifdef WIZ_BUILD
+  u8 *clock_speed_options[] =
+  {
+    "300MHz", "333MHz", "366MHz", "400MHz", "433MHz",
+    "466MHz", "500MHz", "533MHz", "566MHz", "600MHz",
+    "633MHz", "666MHz", "700MHz", "733MHz", "766MHz",
+    "800MHz", "833MHz", "866MHz", "900MHz"
+  };
+#elif defined(GP2X_BUILD)
   u8 *clock_speed_options[] =
   {
     "150MHz", "160MHz", "170MHz", "180MHz", "190MHz",
   u8 *clock_speed_options[] =
   {
     "150MHz", "160MHz", "170MHz", "180MHz", "190MHz",
@@ -1227,11 +1320,7 @@ u32 menu(u16 *original_screen)
   {
     string_selection_option(NULL, "Display scaling", scale_options,
      (u32 *)(&screen_scale),
   {
     string_selection_option(NULL, "Display scaling", scale_options,
      (u32 *)(&screen_scale),
-#ifdef WIZ_BUILD
-     2,
-#else
-     3,
-#endif
+     sizeof(scale_options) / sizeof(scale_options[0]),
 #ifndef GP2X_BUILD
      "Determines how the GBA screen is resized in relation to the entire\n"
      "screen. Select unscaled 3:2 for GBA resolution, scaled 3:2 for GBA\n"
 #ifndef GP2X_BUILD
      "Determines how the GBA screen is resized in relation to the entire\n"
      "screen. Select unscaled 3:2 for GBA resolution, scaled 3:2 for GBA\n"
@@ -1315,11 +1404,7 @@ u32 menu(u16 *original_screen)
     cheat_option(9),
     string_selection_option(NULL, "Clock speed",
      clock_speed_options, &clock_speed_number,
     cheat_option(9),
     string_selection_option(NULL, "Clock speed",
      clock_speed_options, &clock_speed_number,
-#ifdef GP2X_BUILD
-     15,
-#else
-     10,
-#endif
+     sizeof(clock_speed_options) / sizeof(clock_speed_options[0]),
      "Change the clock speed of the device. Higher clock\n"
      "speed will yield better performance, but will drain\n"
      "battery life further.", 11),
      "Change the clock speed of the device. Higher clock\n"
      "speed will yield better performance, but will drain\n"
      "battery life further.", 11),
@@ -1525,11 +1610,13 @@ u32 menu(u16 *original_screen)
     }
   }
 
     }
   }
 
-#ifdef PSP_BUILD
-  clock_speed_number = (clock_speed / 33) - 1;
-#elif defined(GP2X_BUILD)
-  clock_speed_number = (clock_speed - 150) / 10;
-#endif
+  get_clock_speed_number();
+  if (clock_speed_number < 0 || clock_speed_number >=
+   sizeof(clock_speed_options) / sizeof(clock_speed_options[0]))
+  {
+    clock_speed = default_clock_speed;
+    get_clock_speed_number();
+  }
 
   video_resolution_large();
 
 
   video_resolution_large();
 
@@ -1547,7 +1634,7 @@ u32 menu(u16 *original_screen)
     first_load = 1;
     memset(original_screen, 0x00, 240 * 160 * 2);
     print_string_ext("No game loaded yet.", 0xFFFF, 0x0000,
     first_load = 1;
     memset(original_screen, 0x00, 240 * 160 * 2);
     print_string_ext("No game loaded yet.", 0xFFFF, 0x0000,
-     60, 75,original_screen, 240, 0);
+     60, 75,original_screen, 240, 0, 0, FONT_HEIGHT);
   }
 
   choose_menu(&main_menu);
   }
 
   choose_menu(&main_menu);
@@ -1593,12 +1680,12 @@ u32 menu(u16 *original_screen)
       if(display_option == current_option)
       {
         print_string_pad(line_buffer, COLOR_ACTIVE_ITEM, COLOR_BG, 10,
       if(display_option == current_option)
       {
         print_string_pad(line_buffer, COLOR_ACTIVE_ITEM, COLOR_BG, 10,
-         (display_option->line_number * 10) + 40, 36);
+         (display_option->line_number * 10) + 40, 41);
       }
       else
       {
         print_string_pad(line_buffer, COLOR_INACTIVE_ITEM, COLOR_BG, 10,
       }
       else
       {
         print_string_pad(line_buffer, COLOR_INACTIVE_ITEM, COLOR_BG, 10,
-         (display_option->line_number * 10) + 40, 36);
+         (display_option->line_number * 10) + 40, 41);
       }
     }
 
       }
     }
 
@@ -1680,18 +1767,17 @@ u32 menu(u16 *original_screen)
   set_gba_resolution(screen_scale);
   video_resolution_small();
 
   set_gba_resolution(screen_scale);
   video_resolution_small();
 
+  get_clock_speed();
+  if (clock_speed != clock_speed_old)
+  {
+    printf("about to set CPU clock to %iMHz\n", clock_speed);
   #ifdef PSP_BUILD
   #ifdef PSP_BUILD
-    clock_speed = (clock_speed_number + 1) * 33;
     scePowerSetClockFrequency(clock_speed, clock_speed, clock_speed / 2);
   #elif defined(GP2X_BUILD)
     scePowerSetClockFrequency(clock_speed, clock_speed, clock_speed / 2);
   #elif defined(GP2X_BUILD)
-    clock_speed = 150 + clock_speed_number * 10;
-    if (clock_speed != clock_speed_old)
-    {
-      printf("about to set CPU clock to %iMHz\n", clock_speed);
-      set_FCLK(clock_speed);
-      clock_speed_old = clock_speed;
-    }
+    set_FCLK(clock_speed);
   #endif
   #endif
+    clock_speed_old = clock_speed;
+  }
 
   SDL_PauseAudio(0);
 
 
   SDL_PauseAudio(0);