X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Flibretro%2Flibretro.c;h=581702c9d9d6c14ed1cce996160e665d2859ab5e;hb=e1360c668cd06a0625e180d7cc1baa31390e4f66;hp=7c271388bcb5b198aa4c77a98eea06a9f608d17e;hpb=0fa9e859bfd2be1ab82b84370cf57afc59183df8;p=picodrive.git diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index 7c27138..581702c 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -55,8 +55,14 @@ static retro_audio_sample_batch_t audio_batch_cb; #define VOUT_MAX_WIDTH 320 #define VOUT_MAX_HEIGHT 240 + +static const float VOUT_PAR = 0.0; +static const float VOUT_4_3 = (224.0f * (4.0f / 3.0f)); +static const float VOUT_CRT = (224.0f * 1.29911f); + 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]; @@ -455,6 +461,11 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) vout_height = line_count; vout_offset = vout_width * start_line; + + // Update the geometry + struct retro_system_av_info av_info; + retro_get_system_av_info(&av_info); + environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &av_info); } void emu_32x_startup(void) @@ -483,6 +494,7 @@ void retro_set_environment(retro_environment_t cb) { "picodrive_ramcart", "MegaCD RAM cart; disabled|enabled" }, { "picodrive_region", "Region; Auto|Japan NTSC|Japan PAL|US|Europe" }, { "picodrive_region_fps", "Region FPS; Auto|NTSC|PAL" }, + { "picodrive_aspect", "Core-provided aspect ratio; PAR|4/3|CRT" }, #ifdef DRC_SH2 { "picodrive_drc", "Dynamic recompilers; enabled|disabled" }, #endif @@ -523,11 +535,16 @@ void retro_get_system_av_info(struct retro_system_av_info *info) memset(info, 0, sizeof(*info)); info->timing.fps = Pico.m.pal ? 50 : 60; info->timing.sample_rate = 44100; - info->geometry.base_width = 320; + info->geometry.base_width = vout_width; 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.0f / 3.0f; + info->geometry.max_width = vout_width; + info->geometry.max_height = vout_height; + + float common_width = vout_width; + if (user_vout_width != 0) + common_width = user_vout_width; + + info->geometry.aspect_ratio = common_width / vout_height; } /* savestates */ @@ -983,38 +1000,64 @@ unsigned retro_get_region(void) return Pico.m.pal ? RETRO_REGION_PAL : RETRO_REGION_NTSC; } -void *retro_get_memory_data(unsigned id) +void *retro_get_memory_data(unsigned type) { - if (id != RETRO_MEMORY_SAVE_RAM) - return NULL; + uint8_t* data; - if (PicoAHW & PAHW_MCD) - return Pico_mcd->bram; - else - return SRam.data; + switch(type) + { + case RETRO_MEMORY_SAVE_RAM: + if (PicoAHW & PAHW_MCD) + data = Pico_mcd->bram; + else + data = SRam.data; + break; + case RETRO_MEMORY_SYSTEM_RAM: + if (PicoAHW & PAHW_SMS) + data = Pico.vramb; + else + data = Pico.ram; + break; + default: + data = NULL; + break; + } + + return data; } -size_t retro_get_memory_size(unsigned id) +size_t retro_get_memory_size(unsigned type) { unsigned int i; int sum; - - if (id != RETRO_MEMORY_SAVE_RAM) - return 0; - - if (PicoAHW & PAHW_MCD) - // bram - return 0x2000; - - if (Pico.m.frame_count == 0) - return SRam.size; - - // if game doesn't write to sram, don't report it to - // libretro so that RA doesn't write out zeroed .srm - for (i = 0, sum = 0; i < SRam.size; i++) - sum |= SRam.data[i]; - - return (sum != 0) ? SRam.size : 0; + + switch(type) + { + case RETRO_MEMORY_SAVE_RAM: + if (PicoAHW & PAHW_MCD) + // bram + return 0x2000; + + if (Pico.m.frame_count == 0) + return SRam.size; + + // if game doesn't write to sram, don't report it to + // libretro so that RA doesn't write out zeroed .srm + for (i = 0, sum = 0; i < SRam.size; i++) + sum |= SRam.data[i]; + + return (sum != 0) ? SRam.size : 0; + + case RETRO_MEMORY_SYSTEM_RAM: + if (PicoAHW & PAHW_SMS) + return sizeof(Pico.vramb); + else + return sizeof(Pico.ram); + + default: + return 0; + } + } void retro_reset(void) @@ -1126,6 +1169,26 @@ static void update_variables(void) PsndRerate(1); } + float old_user_vout_width = user_vout_width; + var.value = NULL; + var.key = "picodrive_aspect"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { + if (strcmp(var.value, "4/3") == 0) + user_vout_width = VOUT_4_3; + else if (strcmp(var.value, "CRT") == 0) + user_vout_width = VOUT_CRT; + else + user_vout_width = VOUT_PAR; + } + + if (user_vout_width != old_user_vout_width) + { + // Update the geometry + struct retro_system_av_info av_info; + retro_get_system_av_info(&av_info); + environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &av_info); + } + #ifdef DRC_SH2 var.value = NULL; var.key = "picodrive_drc";