From 1d2757f476f5c10229e10fa16107d73b0c801fa5 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Wed, 4 Nov 2020 21:16:24 +0800 Subject: CHD: Support for precache mode CD access method https://github.com/libretro/pcsx_rearmed/issues/261 --- frontend/libretro.c | 13 ++++++++++++- frontend/libretro_core_options.h | 7 ++++--- libpcsxcore/cdriso.c | 5 ++++- libpcsxcore/psxcommon.h | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index e18b190..5c966a4 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -1744,9 +1744,20 @@ static void update_variables(bool in_flight) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (strcmp(var.value, "async") == 0) + { Config.AsyncCD = 1; - else + Config.CHD_Precache = 0; + } + else if (strcmp(var.value, "sync") == 0) + { Config.AsyncCD = 0; + Config.CHD_Precache = 0; + } + else if (strcmp(var.value, "precache") == 0) + { + Config.AsyncCD = 0; + Config.CHD_Precache = 1; + } } #endif diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index 3f589cc..21f6783 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -935,10 +935,11 @@ struct retro_core_option_definition option_defs_us[] = { { "pcsx_rearmed_async_cd", "CD Access Method (Restart)", - "Select method used to read data from content disk images. 'Synchronous' mimics original hardware. 'Asynchronous' can reduce stuttering on devices with slow storage.", + "Select method used to read data from content disk images. 'Synchronous' mimics original hardware. 'Asynchronous' can reduce stuttering on devices with slow storage. 'Precache' loads disk image into memory for faster access (CHD only).", { - { "sync", "Synchronous" }, - { "async", "Asynchronous" }, + { "sync", "Synchronous" }, + { "async", "Asynchronous" }, + { "precache", "Precache" }, { NULL, NULL}, }, "sync", diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index d8799db..9e70ddf 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -1057,7 +1057,10 @@ static int handlechd(const char *isofile) { goto fail_io; if(chd_open(isofile, CHD_OPEN_READ, NULL, &chd_img->chd) != CHDERR_NONE) - goto fail_io; + goto fail_io; + + if (Config.CHD_Precache && (chd_precache(chd_img->chd) != CHDERR_NONE)) + goto fail_io; chd_img->header = chd_get_header(chd_img->chd); diff --git a/libpcsxcore/psxcommon.h b/libpcsxcore/psxcommon.h index cb417d4..708d984 100644 --- a/libpcsxcore/psxcommon.h +++ b/libpcsxcore/psxcommon.h @@ -121,6 +121,7 @@ typedef struct { boolean PsxAuto; boolean Cdda; boolean AsyncCD; + boolean CHD_Precache; /* loads disk image into memory, works with CHD only. */ boolean HLE; boolean SlowBoot; boolean Debug; -- cgit v1.2.3