forgotten credit..
[picodrive.git] / platform / libretro.c
index b2697ce..f3252ab 100644 (file)
@@ -290,6 +290,13 @@ void retro_set_environment(retro_environment_t cb)
 {
        static const struct retro_variable vars[] = {
                //{ "region", "Region; Auto|NTSC|PAL" },
+               { "picodrive_input1", "Input device 1; 3 button pad|6 button pad|None" },
+               { "picodrive_input2", "Input device 2; 3 button pad|6 button pad|None" },
+               { "picodrive_sprlim", "No sprite limit; disabled|enabled" },
+               { "picodrive_ramcart", "MegaCD RAM cart; disabled|enabled" },
+#ifdef DRC_SH2
+               { "picodrive_drc", "Dynamic recompilers; enabled|disabled" },
+#endif
                { NULL, NULL },
        };
 
@@ -580,13 +587,13 @@ static void disk_tray_close(void)
 
 
 static const char * const biosfiles_us[] = {
-       "us_scd1_9210", "us_scd2_9306", "SegaCDBIOS9303", "bios_CD_U"
+       "us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210", "bios_CD_U"
 };
 static const char * const biosfiles_eu[] = {
-       "eu_mcd1_9210", "eu_mcd2_9306", "eu_mcd2_9303", "bios_CD_E"
+       "eu_mcd2_9306", "eu_mcd2_9303", "eu_mcd1_9210", "bios_CD_E"
 };
 static const char * const biosfiles_jp[] = {
-       "jp_mcd1_9112", "jp_mcd1_9111", "bios_CD_J"
+       "jp_mcd2_921222", "jp_mcd1_9112", "jp_mcd1_9111", "bios_CD_J"
 };
 
 static void make_system_path(char *buf, size_t buf_size,
@@ -652,7 +659,7 @@ bool retro_load_game(const struct retro_game_info *info)
 
        enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
        if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
-               lprintf("RGB565 suppot required, sorry\n");
+               lprintf("RGB565 support required, sorry\n");
                return false;
        }
 
@@ -699,7 +706,7 @@ bool retro_load_game(const struct retro_game_info *info)
        PicoWriteSound = snd_write;
        memset(sndBuffer, 0, sizeof(sndBuffer));
        PsndOut = sndBuffer;
-       PsndRerate(1);
+       PsndRerate(0);
 
        return true;
 }
@@ -767,13 +774,70 @@ static void snd_write(int len)
        audio_batch_cb(PsndOut, len / 4);
 }
 
+static enum input_device input_name_to_val(const char *name)
+{
+       if (strcmp(name, "3 button pad") == 0)
+               return PICO_INPUT_PAD_3BTN;
+       if (strcmp(name, "6 button pad") == 0)
+               return PICO_INPUT_PAD_6BTN;
+       if (strcmp(name, "None") == 0)
+               return PICO_INPUT_NOTHING;
+
+       lprintf("invalid picodrive_input: '%s'\n", name);
+       return PICO_INPUT_PAD_3BTN;
+}
+
+static void update_variables(void)
+{
+       struct retro_variable var;
+
+       var.value = NULL;
+       var.key = "picodrive_input1";
+       if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
+               PicoSetInputDevice(0, input_name_to_val(var.value));
+
+       var.value = NULL;
+       var.key = "picodrive_input2";
+       if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
+               PicoSetInputDevice(1, input_name_to_val(var.value));
+
+       var.value = NULL;
+       var.key = "picodrive_sprlim";
+       if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
+               if (strcmp(var.value, "enabled") == 0)
+                       PicoOpt |= POPT_DIS_SPRITE_LIM;
+               else
+                       PicoOpt &= ~POPT_DIS_SPRITE_LIM;
+       }
+
+       var.value = NULL;
+       var.key = "picodrive_ramcart";
+       if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
+               if (strcmp(var.value, "enabled") == 0)
+                       PicoOpt |= POPT_EN_MCD_RAMCART;
+               else
+                       PicoOpt &= ~POPT_EN_MCD_RAMCART;
+       }
+
+#ifdef DRC_SH2
+       var.value = NULL;
+       var.key = "picodrive_drc";
+       if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
+               if (strcmp(var.value, "enabled") == 0)
+                       PicoOpt |= POPT_EN_DRC;
+               else
+                       PicoOpt &= ~POPT_EN_DRC;
+       }
+#endif
+}
+
 void retro_run(void) 
 {
        bool updated = false;
        int pad, i;
 
        if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
-               ; //update_variables(true);
+               update_variables();
 
        input_poll_cb();
 
@@ -810,7 +874,7 @@ void retro_init(void)
                | POPT_EN_32X|POPT_EN_PWM
                | POPT_ACC_SPRITES|POPT_DIS_32C_BORDER;
 #ifdef __arm__
-       PicoOpt |= POPT_EN_SVP_DRC;
+       PicoOpt |= POPT_EN_DRC;
 #endif
        PsndRate = 44100;
        PicoAutoRgnOrder = 0x184; // US, EU, JP
@@ -827,6 +891,8 @@ void retro_init(void)
        //PicoMessage = plat_status_msg_busy_next;
        PicoMCDopenTray = disk_tray_open;
        PicoMCDcloseTray = disk_tray_close;
+
+       update_variables();
 }
 
 void retro_deinit(void)