From: retro-wertz Date: Sun, 10 Mar 2019 14:19:59 +0000 (+0800) Subject: Fix memcard2 still detected by games when its supposed to be disabled X-Git-Tag: r24l~750^2~1 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bf562688e3738d347a51a72967e29836f8be65a;p=pcsx_rearmed.git Fix memcard2 still detected by games when its supposed to be disabled --- diff --git a/frontend/libretro.c b/frontend/libretro.c index 7eb8480d..838e4491 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -819,7 +819,7 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code) // cheat funcs are destructive, need a copy.. strncpy(buf, code, sizeof(buf)); buf[sizeof(buf) - 1] = 0; - + //Prepare buffered cheat for PCSX's AddCheat fucntion. int cursor=0; int nonhexdec=0; @@ -833,7 +833,7 @@ void retro_cheat_set(unsigned index, bool enabled, const char *code) } cursor++; } - + if (index < NumCheats) ret = EditCheat(index, "", buf); @@ -1581,7 +1581,7 @@ static void update_variables(bool in_flight) } else{ //not yet running - + //bootlogo display hack if (found_bios) { var.value = "NULL"; @@ -1881,9 +1881,12 @@ static int init_memcards(void) struct retro_variable var = { .key="pcsx_rearmed_memcard2", .value=NULL }; static const char CARD2_FILE[] = "pcsx-card2.mcd"; - McdDisable[0] = 0; - // Disable memcard 2 by default - McdDisable[1] = 1; + // Memcard2 will be handled and is re-enabled if needed using core + // operations. + // Memcard1 is handled by libretro, doing this will set core to + // skip file io operations for memcard1 like SaveMcd + snprintf(Config.Mcd1, sizeof(Config.Mcd1), "none"); + snprintf(Config.Mcd2, sizeof(Config.Mcd2), "none"); init_memcard(Mcd1Data); // Memcard 2 is managed by the emulator on the filesystem, // There is no need to initialize Mcd2Data like Mcd1Data. @@ -1987,7 +1990,7 @@ void retro_init(void) psxUnmapHook = pl_vita_munmap; #endif ret = emu_core_preinit(); -#ifdef _3DS +#ifdef _3DS /* emu_core_preinit sets the cpu to dynarec */ if(!__ctr_svchax) Config.Cpu = CPU_INTERPRETER; @@ -2007,7 +2010,7 @@ void retro_init(void) #else vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); #endif - + vout_buf_ptr = vout_buf; loadPSXBios(); diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index d5ed7253..a6846017 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -26,6 +26,7 @@ #include "psxbios.h" #include "psxhw.h" #include "gpu.h" +#include "sio.h" #include #undef SysPrintf @@ -261,7 +262,7 @@ static int CardState = -1; static TCB Thread[8]; static int CurThread = 0; static FileDesc FDesc[32]; -static u32 card_active_chan; +static u32 card_active_chan = 0; boolean hleSoftCall = FALSE; @@ -1271,14 +1272,35 @@ void psxBios_SetMem() { // 9f } void psxBios__card_info() { // ab + u8 ret, port; #ifdef PSXBIOS_LOG PSXBIOS_LOG("psxBios_%s: %x\n", biosA0n[0xab], a0); #endif card_active_chan = a0; + port = card_active_chan >> 4; + + switch (port) { + case 0x0: + case 0x1: + ret = 0x2; + if (McdDisable[port & 1]) + ret = 0x8; + break; + default: +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("psxBios_%s: UNKNOWN PORT 0x%x\n", biosA0n[0xab], card_active_chan); +#endif + ret = 0x11; + break; + } + + if (McdDisable[0] && McdDisable[1]) + ret = 0x8; // DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 - DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 +// DeliverEvent(0x81, 0x2); // 0xf4000001, 0x0004 + DeliverEvent(0x81, ret); // 0xf4000001, 0x0004 v0 = 1; pc0 = ra; } @@ -2643,6 +2665,7 @@ void psxBiosInit() { CardState = -1; CurThread = 0; memset(FDesc, 0, sizeof(FDesc)); + card_active_chan = 0; psxMu32ref(0x0150) = SWAPu32(0x160); psxMu32ref(0x0154) = SWAPu32(0x320); diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c index d251fa74..c2390bf0 100644 --- a/libpcsxcore/sio.c +++ b/libpcsxcore/sio.c @@ -423,6 +423,12 @@ void LoadMcd(int mcd, char *str) { } McdDisable[mcd - 1] = 0; +#ifdef HAVE_LIBRETRO + // memcard1 is handled by libretro + if (mcd == 1) + return; +#endif + if (str == NULL || strcmp(str, "none") == 0) { McdDisable[mcd - 1] = 1; return; diff --git a/libpcsxcore/sio.h b/libpcsxcore/sio.h index eff1746a..a554c2bb 100644 --- a/libpcsxcore/sio.h +++ b/libpcsxcore/sio.h @@ -34,6 +34,7 @@ extern "C" { #define MCD_SIZE (1024 * 8 * 16) extern char Mcd1Data[MCD_SIZE], Mcd2Data[MCD_SIZE]; +extern char McdDisable[2]; void sioWrite8(unsigned char value); void sioWriteStat16(unsigned short value);