gp2x: various fixes, prepare for release
[picodrive.git] / platform / libretro.c
index 4903847..f59cf67 100644 (file)
@@ -39,7 +39,7 @@ static FILE *emu_log;
 #define VOUT_MAX_WIDTH 320
 #define VOUT_MAX_HEIGHT 240
 static void *vout_buf;
-static int vout_width, vout_height;
+static int vout_width, vout_height, vout_offset;
 
 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
 
@@ -251,6 +251,9 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols)
        memset(vout_buf, 0, 320 * 240 * 2);
        vout_width = is_32cols ? 256 : 320;
        PicoDrawSetOutBuf(vout_buf, vout_width * 2);
+
+       vout_height = line_count;
+       vout_offset = vout_width * start_line;
 }
 
 void emu_32x_startup(void)
@@ -292,6 +295,8 @@ void retro_set_environment(retro_environment_t cb)
                //{ "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
@@ -333,10 +338,10 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
        info->timing.fps            = Pico.m.pal ? 50 : 60;
        info->timing.sample_rate    = 44100;
        info->geometry.base_width   = 320;
-       info->geometry.base_height  = 240;
+       info->geometry.base_height  = vout_height;
        info->geometry.max_width    = VOUT_MAX_WIDTH;
        info->geometry.max_height   = VOUT_MAX_HEIGHT;
-       info->geometry.aspect_ratio = 4.0 / 3.0;
+       info->geometry.aspect_ratio = 0.0f;
 }
 
 /* savestates */
@@ -704,7 +709,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;
 }
@@ -799,6 +804,24 @@ static void update_variables(void)
        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";
@@ -829,7 +852,8 @@ void retro_run(void)
 
        PicoFrame();
 
-       video_cb(vout_buf, vout_width, vout_height, vout_width * 2);
+       video_cb((short *)vout_buf + vout_offset,
+               vout_width, vout_height, vout_width * 2);
 }
 
 void retro_init(void)