initial pandora port, with hardware scaling and stuff
[gpsp.git] / gui.c
diff --git a/gui.c b/gui.c
index 6eb9ddb..22a39e0 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -16,6 +16,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "common.h"
+#include "font.h"
+
 #ifndef _WIN32_WCE
 
 #include <sys/stat.h>
 #ifndef _WIN32_WCE
 
 #include <sys/stat.h>
 
 #endif
 
 
 #endif
 
-#include "common.h"
-#include "font.h"
-
 #define MAX_PATH 1024
 
 // Blatantly stolen and trimmed from MZX (megazeux.sourceforge.net)
 
 #ifdef GP2X_BUILD
 
 #define MAX_PATH 1024
 
 // Blatantly stolen and trimmed from MZX (megazeux.sourceforge.net)
 
 #ifdef GP2X_BUILD
 
-#define FILE_LIST_ROWS ((int)((SDL_SCREEN_HEIGHT - 40) / FONT_HEIGHT))
+#define FILE_LIST_ROWS 20
 #define FILE_LIST_POSITION 5
 #define DIR_LIST_POSITION 260
 
 #define FILE_LIST_POSITION 5
 #define DIR_LIST_POSITION 260
 
 
 #ifdef PSP_BUILD
 
 
 #ifdef PSP_BUILD
 
+#define COLOR_BG            color16(2, 8, 10)
+
 #define color16(red, green, blue)                                             \
   (blue << 11) | (green << 5) | red                                           \
 
 #else
 
 #define color16(red, green, blue)                                             \
   (blue << 11) | (green << 5) | red                                           \
 
 #else
 
-#define color16(red, green, blue)                                             \
-  (red << 11) | (green << 5) | blue                                           \
-
-#endif
-
-#ifdef GP2X_BUILD
-
 #define COLOR_BG            color16(0, 0, 0)
 
 #define COLOR_BG            color16(0, 0, 0)
 
-#else
-
-#define COLOR_BG            color16(2, 8, 10)
+#define color16(red, green, blue)                                             \
+  (red << 11) | (green << 5) | blue                                           \
 
 #endif
 
 
 #endif
 
 #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
+  u8 *clock_speed_options[] =
+  {
+    "33MHz", "66MHz", "100MHz", "133MHz", "166MHz", "200MHz", "233MHz",
+    "266MHz", "300MHz", "333MHz"
+  };
+  #define menu_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)
+  u8 *clock_speed_options[] =
+  {
+    "300MHz", "333MHz", "366MHz", "400MHz", "433MHz",
+    "466MHz", "500MHz", "533MHz", "566MHz", "600MHz",
+    "633MHz", "666MHz", "700MHz", "733MHz", "766MHz",
+    "800MHz", "833MHz", "866MHz", "900MHz"
+  };
+  #define menu_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)
+  u8 *clock_speed_options[] =
+  {
+    "150MHz", "160MHz", "170MHz", "180MHz", "190MHz",
+    "200MHz", "210MHz", "220MHz", "230MHz", "240MHz",
+    "250MHz", "260MHz", "270MHz", "280MHz", "290MHz"
+  };
+  #define menu_get_clock_speed() \
+    clock_speed = 150 + clock_speed_number * 10
+  #define get_clock_speed_number() \
+    clock_speed_number = (clock_speed - 150) / 10
+#else
+  u8 *clock_speed_options[] =
+  {
+    "0"
+  };
+  #define menu_get_clock_speed() 0
+  #define get_clock_speed_number() 0
+#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);
@@ -108,11 +145,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;
@@ -332,6 +369,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
           {
@@ -352,6 +396,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)
           {
@@ -368,6 +431,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
           {
@@ -387,7 +461,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)
@@ -476,11 +569,11 @@ struct _menu_option_type
   void (* action_function)();
   void (* passive_function)();
   struct _menu_type *sub_menu;
   void (* action_function)();
   void (* passive_function)();
   struct _menu_type *sub_menu;
-  char *display_string;
+  const char *display_string;
   void *options;
   u32 *current_option;
   u32 num_options;
   void *options;
   u32 *current_option;
   u32 num_options;
-  char *help_string;
+  const char *help_string;
   u32 line_number;
   menu_option_type_enum option_type;
 };
   u32 line_number;
   menu_option_type_enum option_type;
 };
@@ -643,10 +736,32 @@ u32 gamepad_config_line_to_button[] =
 #ifdef GP2X_BUILD
 
 u32 gamepad_config_line_to_button[] =
 #ifdef GP2X_BUILD
 
 u32 gamepad_config_line_to_button[] =
- { 0, 2, 1, 3, 8, 9, 10, 11, 6, 7, 4, 5 };
+ { 0, 2, 1, 3, 8, 9, 10, 11, 6, 7, 4, 5, 14 };
 
 #endif
 
 
 #endif
 
+#ifdef PND_BUILD
+
+u32 gamepad_config_line_to_button[] =
+ { 0, 2, 1, 3, 8, 9, 10, 11, 6, 7, 4, 5, 12, 13, 14, 15 };
+
+#endif
+
+u8 *scale_options[] =
+{
+#ifdef PSP_BUILD
+  "unscaled 3:2", "scaled 3:2", "fullscreen 16:9"
+#elif defined(WIZ_BUILD)
+  "unscaled 3:2", "scaled 3:2 (slower)",
+  "unscaled 3:2 (anti-tear)", "scaled 3:2 (anti-tear)"
+#elif defined(PND_BUILD)
+  "unscaled", "2x", "3x", "fullscreen"
+#elif defined(GP2X_BUILD)
+  "unscaled 3:2", "scaled 3:2", "fullscreen", "scaled 3:2 (software)"
+#else
+  "unscaled 3:2"
+#endif
+};
 
 s32 load_game_config_file()
 {
 
 s32 load_game_config_file()
 {
@@ -672,8 +787,16 @@ 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 WIZ_BUILD
+      if(clock_speed > 900)
+        clock_speed = 533;
+#elif defined(GP2X_BUILD)
+      if(clock_speed >= 300)
+        clock_speed = 200;
+#else
       if(clock_speed > 333)
         clock_speed = 333;
       if(clock_speed > 333)
         clock_speed = 333;
+#endif
 
       if(clock_speed < 33)
         clock_speed = 33;
 
       if(clock_speed < 33)
         clock_speed = 33;
@@ -700,8 +823,11 @@ s32 load_game_config_file()
 
   current_frameskip_type = auto_frameskip;
   frameskip_value = 4;
 
   current_frameskip_type = auto_frameskip;
   frameskip_value = 4;
+#ifdef WIZ_BUILD
+  frameskip_value = 1;
+#endif
   random_skip = 0;
   random_skip = 0;
-  clock_speed = 333;
+  clock_speed = default_clock_speed;
 
   for(i = 0; i < 10; i++)
   {
 
   for(i = 0; i < 10; i++)
   {
@@ -716,10 +842,10 @@ s32 load_config_file()
 {
   u8 config_path[512];
 
 {
   u8 config_path[512];
 
-  #if (defined(PSP_BUILD) || defined(ARM_ARCH)) && !defined(_WIN32_WCE)
-    sprintf(config_path, "%s/%s", main_path, GPSP_CONFIG_FILENAME);
-  #else
+  #if defined(_WIN32) || defined(_WIN32_WCE)
     sprintf(config_path, "%s\\%s", main_path, GPSP_CONFIG_FILENAME);
     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);
   #endif
 
   file_open(config_file, config_path, read);
@@ -736,7 +862,8 @@ s32 load_config_file()
       s32 menu_button = -1;
       file_read_array(config_file, file_options);
 
       s32 menu_button = -1;
       file_read_array(config_file, file_options);
 
-      screen_scale = file_options[0] % 3;
+      screen_scale = file_options[0] %
+        (sizeof(scale_options) / sizeof(scale_options[0]));
       screen_filter = file_options[1] % 2;
       global_enable_audio = file_options[2] % 2;
 
       screen_filter = file_options[1] % 2;
       global_enable_audio = file_options[2] % 2;
 
@@ -907,8 +1034,8 @@ void get_savestate_snapshot(u8 *savestate_filename)
   else
   {
     memset(snapshot_buffer, 0, 240 * 160 * 2);
   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_ext("No savestate in this slot.",
+     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);
   }
@@ -945,8 +1072,8 @@ void get_savestate_filename_noshot(u32 slot, u8 *name_buffer)
 
 u32 menu(u16 *original_screen)
 {
 
 u32 menu(u16 *original_screen)
 {
-  u32 clock_speed_number = (clock_speed / 33) - 1;
   u8 print_buffer[81];
   u8 print_buffer[81];
+  u32 clock_speed_number;
   u32 _current_option = 0;
   gui_action_type gui_action;
   menu_enum _current_menu = MAIN_MENU;
   u32 _current_option = 0;
   gui_action_type gui_action;
   menu_enum _current_menu = MAIN_MENU;
@@ -967,7 +1094,7 @@ u32 menu(u16 *original_screen)
   auto void choose_menu();
   auto void clear_help();
 
   auto void choose_menu();
   auto void clear_help();
 
-  u8 *gamepad_help[] =
+  static const u8 * const gamepad_help[] =
   {
     "Up button on GBA d-pad.",
     "Down button on GBA d-pad.",
   {
     "Up button on GBA d-pad.",
     "Down button on GBA d-pad.",
@@ -993,6 +1120,17 @@ u32 menu(u16 *original_screen)
     "Does nothing."
   };
 
     "Does nothing."
   };
 
+  void menu_update_clock()
+  {
+    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();
+    }
+  }
+
   void menu_exit()
   {
     if(!first_load)
   void menu_exit()
   {
     if(!first_load)
@@ -1001,7 +1139,7 @@ u32 menu(u16 *original_screen)
 
   void menu_quit()
   {
 
   void menu_quit()
   {
-    clock_speed = (clock_speed_number + 1) * 33;
+    menu_get_clock_speed();
     save_config_file();
     quit();
   }
     save_config_file();
     quit();
   }
@@ -1021,6 +1159,7 @@ u32 menu(u16 *original_screen)
        return_value = 1;
        repeat = 0;
        reg[CHANGED_PC_STATUS] = 1;
        return_value = 1;
        repeat = 0;
        reg[CHANGED_PC_STATUS] = 1;
+       menu_update_clock();
     }
     else
     {
     }
     else
     {
@@ -1132,11 +1271,6 @@ u32 menu(u16 *original_screen)
   u8 *yes_no_options[] = { "no", "yes" };
   u8 *enable_disable_options[] = { "disabled", "enabled" };
 
   u8 *yes_no_options[] = { "no", "yes" };
   u8 *enable_disable_options[] = { "disabled", "enabled" };
 
-  u8 *scale_options[] =
-  {
-    "unscaled 3:2", "scaled 3:2", "fullscreen 16:9"
-  };
-
   u8 *frameskip_options[] = { "automatic", "manual", "off" };
   u8 *frameskip_variation_options[] = { "uniform", "random" };
 
   u8 *frameskip_options[] = { "automatic", "manual", "off" };
   u8 *frameskip_variation_options[] = { "uniform", "random" };
 
@@ -1158,12 +1292,6 @@ u32 menu(u16 *original_screen)
 
   u8 *update_backup_options[] = { "Exit only", "Automatic" };
 
 
   u8 *update_backup_options[] = { "Exit only", "Automatic" };
 
-  u8 *clock_speed_options[] =
-  {
-    "33MHz", "66MHz", "100MHz", "133MHz", "166MHz", "200MHz", "233MHz",
-    "266MHz", "300MHz", "333MHz"
-  };
-
   u8 *gamepad_config_buttons[] =
   {
     "UP",
   u8 *gamepad_config_buttons[] =
   {
     "UP",
@@ -1194,39 +1322,57 @@ u32 menu(u16 *original_screen)
   menu_option_type graphics_sound_options[] =
   {
     string_selection_option(NULL, "Display scaling", scale_options,
   menu_option_type graphics_sound_options[] =
   {
     string_selection_option(NULL, "Display scaling", scale_options,
-     (u32 *)(&screen_scale), 3,
-     "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"
+     (u32 *)(&screen_scale),
+     sizeof(scale_options) / sizeof(scale_options[0]),
+#ifndef GP2X_BUILD
+     "Determines how the GBA screen is resized in relation to the\n"
+     "entire screen."
+#ifdef PSP_BUILD
+     " Select unscaled 3:2 for GBA resolution, scaled 3:2 for GBA\n"
      "aspect ratio scaled to fill the height of the PSP screen, and\n"
      "aspect ratio scaled to fill the height of the PSP screen, and\n"
-     "fullscreen to fill the entire PSP screen.", 2),
+     "fullscreen to fill the entire PSP screen."
+#endif
+#endif
+     "", 2),
+#ifndef GP2X_BUILD
     string_selection_option(NULL, "Screen filtering", yes_no_options,
      (u32 *)(&screen_filter), 2,
     string_selection_option(NULL, "Screen filtering", yes_no_options,
      (u32 *)(&screen_filter), 2,
-     "Determines whether or not bilinear filtering should be used when\n"
+     "Determines whether or not filtering should be used when\n"
      "scaling the screen. Selecting this will produce a more even and\n"
      "smooth image, at the cost of being blurry and having less vibrant\n"
      "colors.", 3),
      "scaling the screen. Selecting this will produce a more even and\n"
      "smooth image, at the cost of being blurry and having less vibrant\n"
      "colors.", 3),
+#endif
     string_selection_option(NULL, "Frameskip type", frameskip_options,
      (u32 *)(&current_frameskip_type), 3,
     string_selection_option(NULL, "Frameskip type", frameskip_options,
      (u32 *)(&current_frameskip_type), 3,
-     "Determines what kind of frameskipping should be employed.\n"
+#ifndef GP2X_BUILD
+     "Determines what kind of frameskipping to use.\n"
      "Frameskipping may improve emulation speed of many games.\n"
      "Frameskipping may improve emulation speed of many games.\n"
+#endif
      "Off: Do not skip any frames.\n"
      "Off: Do not skip any frames.\n"
-     "Auto: Skip up to N frames (see next option) as needed.\n"
-     "Manual: Always render only 1 out of N + 1 frames.", 5),
+     "Auto: Skip up to N frames (see next opt) as needed.\n"
+     "Manual: Always render only 1 out of N + 1 frames."
+     , 5),
     numeric_selection_option(NULL, "Frameskip value", &frameskip_value, 100,
     numeric_selection_option(NULL, "Frameskip value", &frameskip_value, 100,
+#ifndef GP2X_BUILD
      "For auto frameskip, determines the maximum number of frames that\n"
      "are allowed to be skipped consecutively.\n"
      "For manual frameskip, determines the number of frames that will\n"
      "For auto frameskip, determines the maximum number of frames that\n"
      "are allowed to be skipped consecutively.\n"
      "For manual frameskip, determines the number of frames that will\n"
-     "always be skipped.", 6),
+     "always be skipped."
+#endif
+     "", 6),
     string_selection_option(NULL, "Framskip variation",
      frameskip_variation_options, &random_skip, 2,
     string_selection_option(NULL, "Framskip variation",
      frameskip_variation_options, &random_skip, 2,
+#ifndef GP2X_BUILD
      "If objects in the game flicker at a regular rate certain manual\n"
      "frameskip values may cause them to normally disappear. Change this\n"
      "If objects in the game flicker at a regular rate certain manual\n"
      "frameskip values may cause them to normally disappear. Change this\n"
-     "value to 'random' to avoid this. Do not use otherwise, as it tends to\n"
-     "make the image quality worse, especially in high motion games.", 7),
+     "value to 'random' to avoid this. Do not use otherwise, as it tends\n"
+     "to make the image quality worse, especially in high motion games."
+#endif
+     "", 7),
     string_selection_option(NULL, "Audio output", yes_no_options,
      &global_enable_audio, 2,
     string_selection_option(NULL, "Audio output", yes_no_options,
      &global_enable_audio, 2,
-     "Select 'no' to turn off all audio output. This will not result in a\n"
-     "significant change in performance.", 9),
+     "Select 'no' to turn off all audio output. This will\n"
+     "not result in a significant change in performance.", 9),
 #ifndef PSP_BUILD
     string_selection_option(NULL, "Audio buffer", audio_buffer_options,
              &audio_buffer_size_number, 11,
 #ifndef PSP_BUILD
     string_selection_option(NULL, "Audio buffer", audio_buffer_options,
              &audio_buffer_size_number, 11,
@@ -1235,10 +1381,15 @@ u32 menu(u16 *original_screen)
              &audio_buffer_size_number, 10,
 #endif
 
              &audio_buffer_size_number, 10,
 #endif
 
+#ifdef PSP_BUILD
      "Set the size (in bytes) of the audio buffer. Larger values may result\n"
      "in slightly better performance at the cost of latency; the lowest\n"
      "value will give the most responsive audio.\n"
      "This option requires gpSP to be restarted before it will take effect.",
      "Set the size (in bytes) of the audio buffer. Larger values may result\n"
      "in slightly better performance at the cost of latency; the lowest\n"
      "value will give the most responsive audio.\n"
      "This option requires gpSP to be restarted before it will take effect.",
+#else
+     "Set the size (in bytes) of the audio buffer.\n"
+     "This option requires gpSP restart to take effect.",
+#endif
      10),
     submenu_option(NULL, "Back", "Return to the main menu.", 12)
   };
      10),
     submenu_option(NULL, "Back", "Return to the main menu.", 12)
   };
@@ -1257,17 +1408,29 @@ u32 menu(u16 *original_screen)
     cheat_option(7),
     cheat_option(8),
     cheat_option(9),
     cheat_option(7),
     cheat_option(8),
     cheat_option(9),
+#if defined(PSP_BUILD) || defined(GP2X_BUILD)
     string_selection_option(NULL, "Clock speed",
     string_selection_option(NULL, "Clock speed",
-     clock_speed_options, &clock_speed_number, 10,
-     "Change the clock speed of the device. Higher clock speed will yield\n"
-     "better performance, but will use drain battery life further.", 11),
+     clock_speed_options, &clock_speed_number,
+     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),
+#endif
     string_selection_option(NULL, "Update backup",
      update_backup_options, &update_backup_flag, 2,
     string_selection_option(NULL, "Update backup",
      update_backup_options, &update_backup_flag, 2,
+#ifdef GP2X_BUILD
+     "Determines when in-game save files should be\n"
+     "written back to SD card."
+#else
      "Determines when in-game save files should be written back to\n"
      "Determines when in-game save files should be written back to\n"
-     "memstick. If set to 'automatic' writebacks will occur shortly after\n"
-     "the game's backup is altered. On 'exit only' it will only be written\n"
-     "back when you exit from this menu (NOT from using the home button).\n"
-     "Use the latter with extreme care.", 12),
+     "card. If set to 'automatic' writebacks will occur shortly after\n"
+     "the game's backup is altered. On 'exit only' it will only be\n"
+     "written back when you exit from this menu.\n"
+#ifdef PSP
+     "(NOT from using the home button), use the latter with extreme care."
+#endif
+#endif
+     "", 12),
     submenu_option(NULL, "Back", "Return to the main menu.", 14)
   };
 
     submenu_option(NULL, "Back", "Return to the main menu.", 14)
   };
 
@@ -1277,17 +1440,20 @@ u32 menu(u16 *original_screen)
   {
     numeric_selection_action_hide_option(menu_load_state, menu_change_state,
      "Load savestate from current slot", &savestate_slot, 10,
   {
     numeric_selection_action_hide_option(menu_load_state, menu_change_state,
      "Load savestate from current slot", &savestate_slot, 10,
-     "Select to load the game state from the current slot for this game.\n"
+     "Select to load the game state from the current slot\n"
+     "for this game.\n"
      "Press left + right to change the current slot.", 6),
     numeric_selection_action_hide_option(menu_save_state, menu_change_state,
      "Save savestate to current slot", &savestate_slot, 10,
      "Press left + right to change the current slot.", 6),
     numeric_selection_action_hide_option(menu_save_state, menu_change_state,
      "Save savestate to current slot", &savestate_slot, 10,
-     "Select to save the game state to the current slot for this game.\n"
+     "Select to save the game state to the current slot\n"
+     "for this game.\n"
      "Press left + right to change the current slot.", 7),
     numeric_selection_action_hide_option(menu_load_state_file,
       menu_change_state,
      "Load savestate from file", &savestate_slot, 10,
      "Restore gameplay from a savestate file.\n"
      "Press left + right to change the current slot.", 7),
     numeric_selection_action_hide_option(menu_load_state_file,
       menu_change_state,
      "Load savestate from file", &savestate_slot, 10,
      "Restore gameplay from a savestate file.\n"
-     "Note: The same file used to save the state must be present.\n", 9),
+     "Note: The same file used to save the state must be\n"
+     "present.\n", 9),
     numeric_selection_option(menu_change_state,
      "Current savestate slot", &savestate_slot, 10,
      "Change the current savestate slot.\n", 11),
     numeric_selection_option(menu_change_state,
      "Current savestate slot", &savestate_slot, 10,
      "Change the current savestate slot.\n", 11),
@@ -1334,7 +1500,7 @@ u32 menu(u16 *original_screen)
 
 #endif
 
 
 #endif
 
-#ifdef GP2X_BUILD
+#if defined(GP2X_BUILD) || defined(PND_BUILD)
 
   menu_option_type gamepad_config_options[] =
   {
 
   menu_option_type gamepad_config_options[] =
   {
@@ -1348,9 +1514,24 @@ u32 menu(u16 *original_screen)
     gamepad_config_option("Y            ", 7),
     gamepad_config_option("Left Trigger ", 8),
     gamepad_config_option("Right Trigger", 9),
     gamepad_config_option("Y            ", 7),
     gamepad_config_option("Left Trigger ", 8),
     gamepad_config_option("Right Trigger", 9),
+#ifdef WIZ_BUILD
+    gamepad_config_option("Menu         ", 10),
+#else
     gamepad_config_option("Start        ", 10),
     gamepad_config_option("Start        ", 10),
+#endif
     gamepad_config_option("Select       ", 11),
     gamepad_config_option("Select       ", 11),
-    submenu_option(NULL, "Back", "Return to the main menu.", 13)
+#if !defined(WIZ_BUILD) && !defined(PND_BUILD)
+    gamepad_config_option("Stick Push   ", 12),
+#endif
+#ifdef PND_BUILD
+    gamepad_config_option("1            ", 12),
+    gamepad_config_option("2            ", 13),
+    gamepad_config_option("3            ", 14),
+    gamepad_config_option("4            ", 15),
+    submenu_option(NULL, "Back", "Return to the main menu.", 16)
+#else
+    submenu_option(NULL, "Back", "Return to the main menu.", 14)
+#endif
   };
 
 
   };
 
 
@@ -1381,39 +1562,42 @@ u32 menu(u16 *original_screen)
   menu_option_type main_options[] =
   {
     submenu_option(&graphics_sound_menu, "Graphics and Sound options",
   menu_option_type main_options[] =
   {
     submenu_option(&graphics_sound_menu, "Graphics and Sound options",
-     "Select to set display parameters and frameskip behavior,\n"
-     "audio on/off, audio buffer size, and audio filtering.", 0),
+     "Select to set display parameters and frameskip\n"
+     "behavior, audio on/off, buffer size, and filtering.", 0),
     numeric_selection_action_option(menu_load_state, NULL,
      "Load state from slot", &savestate_slot, 10,
     numeric_selection_action_option(menu_load_state, NULL,
      "Load state from slot", &savestate_slot, 10,
-     "Select to load the game state from the current slot for this game,\n"
-     "if it exists (see the extended menu for more information)\n"
+     "Select to load the game state from the current slot\n"
+     "for this game, if it exists.\n"
      "Press left + right to change the current slot.", 2),
     numeric_selection_action_option(menu_save_state, NULL,
      "Save state to slot", &savestate_slot, 10,
      "Press left + right to change the current slot.", 2),
     numeric_selection_action_option(menu_save_state, NULL,
      "Save state to slot", &savestate_slot, 10,
-     "Select to save the game state to the current slot for this game.\n"
-     "See the extended menu for more information.\n"
+     "Select to save the game state to the current slot\n"
+     "for this game. See the extended menu for more info.\n"
      "Press left + right to change the current slot.", 3),
     submenu_option(&savestate_menu, "Savestate options",
      "Press left + right to change the current slot.", 3),
     submenu_option(&savestate_menu, "Savestate options",
-     "Select to enter a menu for loading, saving, and viewing the\n"
-     "currently active savestate for this game (or to load a savestate\n"
-     "file from another game)", 4),
+     "Select to enter a menu for loading, saving, and\n"
+     "viewing the currently active savestate for this game\n"
+     "(or to load a savestate file from another game)", 4),
     submenu_option(&gamepad_config_menu, "Configure gamepad input",
     submenu_option(&gamepad_config_menu, "Configure gamepad input",
-     "Select to change the in-game behavior of the PSP buttons and d-pad.",
-     6),
+     "Select to change the in-game behavior of buttons\n"
+     "and d-pad.", 6),
+#ifndef GP2X_BUILD
     submenu_option(&analog_config_menu, "Configure analog input",
      "Select to change the in-game behavior of the PSP analog nub.", 7),
     submenu_option(&analog_config_menu, "Configure analog input",
      "Select to change the in-game behavior of the PSP analog nub.", 7),
+#endif
     submenu_option(&cheats_misc_menu, "Cheats and Miscellaneous options",
     submenu_option(&cheats_misc_menu, "Cheats and Miscellaneous options",
-     "Select to manage cheats, set backup behavior, and set device clock\n"
-     "speed.", 9),
+     "Select to manage cheats, set backup behavior,\n"
+     "and set device clock speed.", 9),
     action_option(menu_load, NULL, "Load new game",
     action_option(menu_load, NULL, "Load new game",
-     "Select to load a new game (will exit a game if currently playing).",
-     11),
+     "Select to load a new game\n"
+     "(will exit a game if currently playing).", 11),
     action_option(menu_restart, NULL, "Restart game",
     action_option(menu_restart, NULL, "Restart game",
-     "Select to reset the GBA with the current game loaded.", 12),
+     "Select to reset the GBA with the current game\n"
+     "loaded.", 12),
     action_option(menu_exit, NULL, "Return to game",
      "Select to exit this menu and resume gameplay.", 13),
     action_option(menu_quit, NULL, "Exit gpSP",
     action_option(menu_exit, NULL, "Return to game",
      "Select to exit this menu and resume gameplay.", 13),
     action_option(menu_quit, NULL, "Exit gpSP",
-     "Select to exit gpSP and return to the PSP XMB/loader.", 15)
+     "Select to exit gpSP and return to the menu.", 15)
   };
 
   make_menu(main, submenu_main, NULL);
   };
 
   make_menu(main, submenu_main, NULL);
@@ -1440,10 +1624,11 @@ u32 menu(u16 *original_screen)
   {
     for(i = 0; i < 6; i++)
     {
   {
     for(i = 0; i < 6; i++)
     {
-      print_string_pad(" ", COLOR_BG, COLOR_BG, 30, 210 + (i * 10), 70);
+      print_string_pad(" ", COLOR_BG, COLOR_BG, 8, 210 + (i * 10), 70);
     }
   }
 
     }
   }
 
+  menu_update_clock();
   video_resolution_large();
 
 #ifndef GP2X_BUILD
   video_resolution_large();
 
 #ifndef GP2X_BUILD
@@ -1460,7 +1645,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);
@@ -1505,18 +1690,18 @@ u32 menu(u16 *original_screen)
 
       if(display_option == current_option)
       {
 
       if(display_option == current_option)
       {
-        print_string_pad(line_buffer, COLOR_ACTIVE_ITEM, COLOR_BG, 10,
+        print_string_pad(line_buffer, COLOR_ACTIVE_ITEM, COLOR_BG, 6,
          (display_option->line_number * 10) + 40, 36);
       }
       else
       {
          (display_option->line_number * 10) + 40, 36);
       }
       else
       {
-        print_string_pad(line_buffer, COLOR_INACTIVE_ITEM, COLOR_BG, 10,
+        print_string_pad(line_buffer, COLOR_INACTIVE_ITEM, COLOR_BG, 6,
          (display_option->line_number * 10) + 40, 36);
       }
     }
 
     print_string(current_option->help_string, COLOR_HELP_TEXT,
          (display_option->line_number * 10) + 40, 36);
       }
     }
 
     print_string(current_option->help_string, COLOR_HELP_TEXT,
-     COLOR_BG, 30, 210);
+     COLOR_BG, 8, 210);
 
     flip_screen();
 
 
     flip_screen();
 
@@ -1592,14 +1777,11 @@ u32 menu(u16 *original_screen)
 
   set_gba_resolution(screen_scale);
   video_resolution_small();
 
   set_gba_resolution(screen_scale);
   video_resolution_small();
-
-  clock_speed = (clock_speed_number + 1) * 33;
-
-  #ifdef PSP_BUILD
-    scePowerSetClockFrequency(clock_speed, clock_speed, clock_speed / 2);
-  #endif
+  menu_get_clock_speed();
+  set_clock_speed();
 
   SDL_PauseAudio(0);
 
   SDL_PauseAudio(0);
+  num_skipped_frames = 100;
 
   return return_value;
 }
 
   return return_value;
 }