X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Flibretro.c;h=23f0694effbdc90ebf45d7a9a267f13e529a96f9;hb=126eb5f46978a7e97aae210971f1364ee548a646;hp=c02b2061d508265380e549ffdb82e58f8e277fc2;hpb=e4455c234287e0324b8a79b9e9578c9aa09a25f9;p=picodrive.git diff --git a/platform/libretro.c b/platform/libretro.c index c02b206..23f0694 100644 --- a/platform/libretro.c +++ b/platform/libretro.c @@ -28,10 +28,6 @@ #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; @@ -43,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]; @@ -167,6 +163,11 @@ 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) { int flags = MAP_PRIVATE | MAP_ANONYMOUS; @@ -250,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) @@ -289,6 +293,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 }, }; @@ -327,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 */ @@ -489,7 +500,7 @@ static unsigned int disk_get_image_index(void) static bool disk_set_image_index(unsigned int index) { - cd_img_type cd_type; + enum cd_img_type cd_type; int ret; if (index >= sizeof(disks) / sizeof(disks[0])) @@ -510,7 +521,7 @@ static bool disk_set_image_index(unsigned int index) ret = -1; cd_type = PicoCdCheck(disks[index].fname, NULL); if (cd_type != CIT_NOT_CD) - ret = Insert_CD(disks[index].fname, cd_type); + ret = cdd_load(disks[index].fname, cd_type); if (ret != 0) { lprintf("Load failed, invalid CD image?\n"); return 0; @@ -579,13 +590,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, @@ -651,7 +662,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; } @@ -698,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; } @@ -730,14 +741,25 @@ void *retro_get_memory_data(unsigned id) size_t retro_get_memory_size(unsigned id) { + unsigned int i; + int sum; + if (id != RETRO_MEMORY_SAVE_RAM) return 0; if (PicoAHW & PAHW_MCD) // bram return 0x2000; - else + + 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; } void retro_reset(void) @@ -766,13 +788,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(); @@ -784,7 +863,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) @@ -809,11 +889,10 @@ 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 - PicoCDBuffers = 0; vout_width = 320; vout_height = 240; @@ -826,6 +905,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)