diff --git a/iop/memorycard/mcman/src/main.c b/iop/memorycard/mcman/src/main.c index 4c6a463bf1b..ec5e36eac80 100644 --- a/iop/memorycard/mcman/src/main.c +++ b/iop/memorycard/mcman/src/main.c @@ -103,9 +103,6 @@ static const u8 mcman_xortable[256] = { }; // clang-format on -#ifdef BUILDING_DONGLEMAN -int sema_hakama_id = 0; -#endif //-------------------------------------------------------------- void long_multiply(u32 v1, u32 v2, u32 *HI, u32 *LO) @@ -1166,8 +1163,6 @@ int McReadPage(int port, int slot, int page, void *buf) // Export #18 u8 eccbuf[32]; u8 *pdata, *peccb; - HAKAMA_WAITSEMA(); - count = (mcdi->pagesize + 127) >> 7; erase_byte = (mcdi->cardflags & CF_ERASE_ZEROES) ? 0x0 : 0xFF; @@ -1209,8 +1204,6 @@ int McReadPage(int port, int slot, int page, void *buf) // Export #18 } } while (++retries < 5); - HAKAMA_SIGNALSEMA(); - if (retries < 5) return sceMcResSucceed; diff --git a/iop/memorycard/mcman/src/mcman-internal.h b/iop/memorycard/mcman/src/mcman-internal.h index 009619ca05c..4133cbea724 100644 --- a/iop/memorycard/mcman/src/mcman-internal.h +++ b/iop/memorycard/mcman/src/mcman-internal.h @@ -367,9 +367,8 @@ extern u8 mcman_sio2outbufs_PS1PDA[0x90]; #ifdef BUILDING_DONGLEMAN extern int sema_hakama_id; -/// El_isra: Not sure why it hangs... I still need to determine their actual purpose. disabled for now... -#define HAKAMA_SIGNALSEMA() //SignalSema(sema_hakama_id) -#define HAKAMA_WAITSEMA() //WaitSema(sema_hakama_id) +#define HAKAMA_SIGNALSEMA() SignalSema(sema_hakama_id) +#define HAKAMA_WAITSEMA() WaitSema(sema_hakama_id) #else #define HAKAMA_SIGNALSEMA() //while(0) {} /* SignalSema wrapper for an additional semaphore used by arcade MCMAN */ #define HAKAMA_WAITSEMA() //while(0) {} /* WaitSema wrapper for an additional semaphore used by arcade MCMAN */ diff --git a/iop/memorycard/mcman/src/mcsio2.c b/iop/memorycard/mcman/src/mcsio2.c index 613913d0063..37eb6b3fb13 100644 --- a/iop/memorycard/mcman/src/mcsio2.c +++ b/iop/memorycard/mcman/src/mcsio2.c @@ -15,6 +15,10 @@ static flash_info_t dev9_flash_info; #endif +#ifdef BUILDING_DONGLEMAN +int sema_hakama_id = 0; +#endif + #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) static sio2_transfer_data_t mcman_sio2packet; // buffer for mcman sio2 packet static u8 mcman_wdmabufs[0x0b * 0x90]; // buffer array for SIO2 DMA I/O (write) @@ -493,8 +497,10 @@ int mcman_eraseblock(int port, int slot, int block, void **pagebuf, void *eccbuf #endif } while (++retries < 5); - if (retries >= 5) + if (retries >= 5) { + HAKAMA_SIGNALSEMA(); return sceMcResChangedCard; + } if (pagebuf && eccbuf) { // This part leave the first ecc byte of each block page in eccbuf mcman_wmemset(eccbuf, 32, 0); @@ -536,13 +542,12 @@ int mcman_eraseblock(int port, int slot, int block, void **pagebuf, void *eccbuf } } while (++retries < 100); - HAKAMA_SIGNALSEMA(); //El_isra: Original impl has two semas (still commented there) replaced with one for simplicity if (p[3] == 0x66) { - //HAKAMA_SIGNALSEMA(); + HAKAMA_SIGNALSEMA(); return sceMcResFailReplace; } #endif - //HAKAMA_SIGNALSEMA(); + HAKAMA_SIGNALSEMA(); return sceMcResNoFormat; } @@ -635,15 +640,15 @@ int McWritePage(int port, int slot, int page, void *pagebuf, void *eccbuf) // Ex } while (++retries < 5); #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) - HAKAMA_SIGNALSEMA(); // El_isra: simplify original impl if (p[3] == 0x66) { - //HAKAMA_SIGNALSEMA(); + HAKAMA_SIGNALSEMA(); return sceMcResFailReplace; } - //HAKAMA_SIGNALSEMA(); + HAKAMA_SIGNALSEMA(); return sceMcResNoFormat; #else + HAKAMA_SIGNALSEMA(); return sceMcResFailReplace; #endif } @@ -653,6 +658,9 @@ int mcman_readpage(int port, int slot, int page, void *buf, void *eccbuf) { #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) register int index, count, retries, r, i; + + HAKAMA_WAITSEMA(); + register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; u8 *pbuf = (u8 *)buf; u8 *pecc = (u8 *)eccbuf; @@ -716,8 +724,10 @@ int mcman_readpage(int port, int slot, int page, void *buf, void *eccbuf) } while (++retries < 5); - if (retries < 5) + if (retries < 5) { + HAKAMA_SIGNALSEMA(); return sceMcResSucceed; + } #elif defined(BUILDING_VMCMAN) if (!mcman_iomanx_backing_read(port, slot, page, buf, eccbuf)) { return sceMcResSucceed; @@ -740,6 +750,7 @@ int mcman_readpage(int port, int slot, int page, void *buf, void *eccbuf) return sceMcResSucceed; } #endif + HAKAMA_SIGNALSEMA(); return sceMcResChangedCard; } @@ -795,8 +806,8 @@ int McGetCardSpec(int port, int slot, s16 *pagesize, u16 *blocksize, int *cardsi *flags |= CF_USE_ECC; #endif DPRINTF("McGetCardSpec sio2cmd pagesize=%d blocksize=%u cardsize=%d flags%x\n", *pagesize, *blocksize, *cardsize, *flags); - HAKAMA_SIGNALSEMA(); + HAKAMA_SIGNALSEMA(); return sceMcResSucceed; } @@ -936,19 +947,19 @@ int mcman_probePS2Card(int port, int slot) //2 DPRINTF("mcman_probePS2Card: SecrAuthDongle(2, %d, %d)\n", slot, mcman_getcnum(port, slot)); if (SecrAuthDongle(2, slot, mcman_getcnum(port, slot)) == 0) { DPRINTF("mcman_probePS2Card SecrAuthDongle Failed\n"); - + HAKAMA_SIGNALSEMA(); return sceMcResFailAuth; } } else if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) { DPRINTF("mcman_probePS2Card sio2cmd failed (auth failed)\n"); - + HAKAMA_SIGNALSEMA(); return sceMcResFailAuth; } #else if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) { DPRINTF("mcman_probePS2Card sio2cmd failed (auth failed)\n"); - + HAKAMA_SIGNALSEMA(); return sceMcResFailAuth; } #endif @@ -967,6 +978,7 @@ int mcman_probePS2Card(int port, int slot) //2 if (retries >= 5) { DPRINTF("mcman_probePS2Card sio2cmd failed (mc detection failed)\n"); + HAKAMA_SIGNALSEMA(); return sceMcResFailDetect; } #endif @@ -991,11 +1003,12 @@ int mcman_probePS2Card(int port, int slot) //2 if (retries >= 5) { DPRINTF("mcman_probePS2Card sio2cmd failed (mc detection failed)\n"); - + HAKAMA_SIGNALSEMA(); return sceMcResFailDetect2; } #endif + HAKAMA_SIGNALSEMA(); //Here we signal before returning bc devinfo will internally read a page, wich also waits for hakama r = mcman_setdevinfos(port, slot); if (r == 0) { DPRINTF("mcman_probePS2Card sio2cmd card changed!\n"); @@ -1007,7 +1020,7 @@ int mcman_probePS2Card(int port, int slot) //2 } DPRINTF("mcman_probePS2Card sio2cmd succeeded\n"); - + HAKAMA_SIGNALSEMA(); return r; }