some readme and general cleanups
[picodrive.git] / platform / libretro.c
index a059157..21f5a96 100644 (file)
 #include "common/version.h"
 #include "libretro.h"
 
-#ifndef MAP_ANONYMOUS
-#define MAP_ANONYMOUS MAP_ANON
-#endif
-
 static retro_video_refresh_t video_cb;
 static retro_input_poll_t input_poll_cb;
 static retro_input_state_t input_state_cb;
@@ -167,21 +163,13 @@ static void munmap(void *addr, size_t length)
        /* ruh-ro, we leaked handle from CreateFileMapping() ... */
 }
 #endif
+
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
 void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
 {
-#ifndef _WIN32
-   int flags = 0;
-   void *ret = mmap((void*)addr,size,PROT_READ | PROT_WRITE, flags, -1, 0);
-   if (addr != 0 && ret != (void *)addr) {
-      lprintf("warning: wanted to map @%08lx, got %p\n",
-            addr, ret);
-
-      if (is_fixed) {
-         munmap(ret, size);
-         return NULL;
-      }
-   }
-#else
    int flags = MAP_PRIVATE | MAP_ANONYMOUS;
    void *req, *ret;
 
@@ -201,7 +189,6 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
          return NULL;
       }
    }
-#endif
 
        return ret;
 }
@@ -303,6 +290,11 @@ 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" },
+#ifdef DRC_SH2
+               { "picodrive_drc", "Dynamic recompilers; enabled|disabled" },
+#endif
                { NULL, NULL },
        };
 
@@ -665,7 +657,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;
        }
 
@@ -780,13 +772,52 @@ 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));
+
+#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();
 
@@ -823,7 +854,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
@@ -840,6 +871,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)