add a hack for Decap Attack
[picodrive.git] / platform / libretro / libretro.c
index 33ede0d..9111048 100644 (file)
@@ -10,6 +10,7 @@
 
 #define _GNU_SOURCE 1 // mremap
 #include <stdio.h>
+#include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
 #ifndef _WIN32
@@ -78,11 +79,7 @@ static void *vout_buf;
 static int vout_width, vout_height, vout_offset;
 static float user_vout_width = 0.0;
 
-#ifdef _MSC_VER
-static short sndBuffer[2*44100/50];
-#else
-static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
-#endif
+static short ALIGNED(4) sndBuffer[2*44100/50];
 
 static void snd_write(int len);
 
@@ -374,7 +371,7 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
    int flags = MAP_PRIVATE | MAP_ANONYMOUS;
    void *req, *ret;
 
-   req = (void *)addr;
+   req = (void *)(uintptr_t)addr;
    ret = mmap(req, size, PROT_READ | PROT_WRITE, flags, -1, 0);
    if (ret == MAP_FAILED) {
       if (log_cb)
@@ -382,7 +379,7 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
       return NULL;
    }
 
-   if (addr != 0 && ret != (void *)addr) {
+   if (addr != 0 && ret != (void *)(uintptr_t)addr) {
       if (log_cb)
          log_cb(RETRO_LOG_WARN, "warning: wanted to map @%08lx, got %p\n",
                addr, ret);
@@ -450,7 +447,8 @@ int plat_mem_set_exec(void *ptr, size_t size)
 {
    int ret = -1;
 #ifdef _WIN32
-   ret = VirtualProtect(ptr, size, PAGE_EXECUTE_READWRITE, 0);
+   DWORD oldProtect = 0;
+   ret = VirtualProtect(ptr, size, PAGE_EXECUTE_READWRITE, &oldProtect);
    if (ret == 0 && log_cb)
       log_cb(RETRO_LOG_ERROR, "VirtualProtect(%p, %d) failed: %d\n", ptr, (int)size,
              GetLastError());
@@ -527,6 +525,7 @@ void retro_set_environment(retro_environment_t cb)
       { "picodrive_region",      "Region; Auto|Japan NTSC|Japan PAL|US|Europe" },
       { "picodrive_aspect",      "Core-provided aspect ratio; PAR|4/3|CRT" },
       { "picodrive_overscan",    "Show Overscan; disabled|enabled" },
+      { "picodrive_overclk68k",  "68k overclock; disabled|+25%|+50%|+75%|+100%|+200%|+400%" },
 #ifdef DRC_SH2
       { "picodrive_drc", "Dynamic recompilers; enabled|disabled" },
 #endif
@@ -1086,9 +1085,9 @@ bool retro_load_game(const struct retro_game_info *info)
 
    PicoLoopPrepare();
 
-   PicoWriteSound = snd_write;
+   PicoIn.writeSound = snd_write;
    memset(sndBuffer, 0, sizeof(sndBuffer));
-   PsndOut = sndBuffer;
+   PicoIn.sndOut = sndBuffer;
    PsndRerate(0);
 
    return true;
@@ -1191,7 +1190,7 @@ static const unsigned short retro_pico_map[] = {
 
 static void snd_write(int len)
 {
-   audio_batch_cb(PsndOut, len / 4);
+   audio_batch_cb(PicoIn.sndOut, len / 4);
 }
 
 static enum input_device input_name_to_val(const char *name)
@@ -1295,6 +1294,14 @@ static void update_variables(void)
       environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &av_info);
    }
 
+   var.value = NULL;
+   var.key = "picodrive_overclk68k";
+   if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
+      PicoIn.overclockM68k = 0;
+      if (var.value[0] == '+')
+         PicoIn.overclockM68k = atoi(var.value + 1);
+   }
+
 #ifdef DRC_SH2
    var.value = NULL;
    var.key = "picodrive_drc";
@@ -1365,7 +1372,7 @@ void retro_init(void)
 #endif
       PicoIn.opt |= POPT_EN_DRC;
 #endif
-   PsndRate = 44100;
+   PicoIn.sndRate = 44100;
    PicoIn.autoRgnOrder = 0x184; // US, EU, JP
 
    vout_width = 320;
@@ -1380,9 +1387,9 @@ void retro_init(void)
    PicoDrawSetOutFormat(PDF_RGB555, 0);
    PicoDrawSetOutBuf(vout_buf, vout_width * 2);
 
-   //PicoMessage = plat_status_msg_busy_next;
-   PicoMCDopenTray = disk_tray_open;
-   PicoMCDcloseTray = disk_tray_close;
+   //PicoIn.osdMessage = plat_status_msg_busy_next;
+   PicoIn.mcdTrayOpen = disk_tray_open;
+   PicoIn.mcdTrayClose = disk_tray_close;
 
    update_variables();
 }