X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fsio.c;h=6478338dedbdff643234f38057f1e9299c300bbc;hb=8c84ba5f4478dd4e7cc48e86f1b023bc6b99ea9c;hp=4a0a73c48af1efa77c097f01dff9358dc016f418;hpb=f3a770329bf0ac2d47d442eb70e8fcc25a7f8db2;p=pcsx_rearmed.git diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c index 4a0a73c4..6478338d 100644 --- a/libpcsxcore/sio.c +++ b/libpcsxcore/sio.c @@ -24,6 +24,10 @@ #include "sio.h" #include +#ifdef USE_LIBRETRO_VFS +#include +#endif + // Status Flags #define TX_RDY 0x0001 #define RX_RDY 0x0002 @@ -68,12 +72,10 @@ char Mcd1Data[MCD_SIZE], Mcd2Data[MCD_SIZE]; char McdDisable[2]; #define SIO_INT(eCycle) { \ - if (!Config.Sio) { \ - psxRegs.interrupt |= (1 << PSXINT_SIO); \ - psxRegs.intCycle[PSXINT_SIO].cycle = eCycle; \ - psxRegs.intCycle[PSXINT_SIO].sCycle = psxRegs.cycle; \ - new_dyna_set_event(PSXINT_SIO, eCycle); \ - } \ + psxRegs.interrupt |= (1 << PSXINT_SIO); \ + psxRegs.intCycle[PSXINT_SIO].cycle = eCycle; \ + psxRegs.intCycle[PSXINT_SIO].sCycle = psxRegs.cycle; \ + new_dyna_set_event(PSXINT_SIO, eCycle); \ } // clk cycle byte @@ -386,8 +388,10 @@ void sioInterrupt() { PAD_LOG("Sio Interrupt (CP0.Status = %x)\n", psxRegs.CP0.n.Status); #endif // SysPrintf("Sio Interrupt\n"); - StatReg |= IRQ; - psxHu32ref(0x1070) |= SWAPu32(0x80); + if (!(StatReg & IRQ)) { + StatReg |= IRQ; + psxHu32ref(0x1070) |= SWAPu32(0x80); + } } void LoadMcd(int mcd, char *str) { @@ -407,10 +411,19 @@ void LoadMcd(int mcd, char *str) { } McdDisable[mcd - 1] = 0; - if (str == NULL || *str == 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; } + if (*str == 0) + return; + f = fopen(str, "rb"); if (f == NULL) { SysPrintf(_("The memory card %s doesn't exist - creating it\n"), str); @@ -425,7 +438,12 @@ void LoadMcd(int mcd, char *str) { else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } - fread(data, 1, MCD_SIZE, f); + if (fread(data, 1, MCD_SIZE, f) != MCD_SIZE) { +#ifndef NDEBUG + SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__); +#endif + memset(data, 0x00, MCD_SIZE); + } fclose(f); } else @@ -440,7 +458,12 @@ void LoadMcd(int mcd, char *str) { else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } - fread(data, 1, MCD_SIZE, f); + if (fread(data, 1, MCD_SIZE, f) != MCD_SIZE) { +#ifndef NDEBUG + SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__); +#endif + memset(data, 0x00, MCD_SIZE); + } fclose(f); } } @@ -453,6 +476,9 @@ void LoadMcds(char *mcd1, char *mcd2) { void SaveMcd(char *mcd, char *data, uint32_t adr, int size) { FILE *f; + if (mcd == NULL || *mcd == 0 || strcmp(mcd, "none") == 0) + return; + f = fopen(mcd, "r+b"); if (f != NULL) { struct stat buf; @@ -804,7 +830,7 @@ void GetMcdBlockInfo(int mcd, int block, McdBlock *Info) { strncpy(Info->Name, ptr, 16); } -int sioFreeze(gzFile f, int Mode) { +int sioFreeze(void *f, int Mode) { gzfreeze(buf, sizeof(buf)); gzfreeze(&StatReg, sizeof(StatReg)); gzfreeze(&ModeReg, sizeof(ModeReg));