Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions iop/memorycard/mcman/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions iop/memorycard/mcman/src/mcman-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
41 changes: 27 additions & 14 deletions iop/memorycard/mcman/src/mcsio2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -740,6 +750,7 @@ int mcman_readpage(int port, int slot, int page, void *buf, void *eccbuf)
return sceMcResSucceed;
}
#endif
HAKAMA_SIGNALSEMA();
return sceMcResChangedCard;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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");
Expand All @@ -1007,7 +1020,7 @@ int mcman_probePS2Card(int port, int slot) //2
}

DPRINTF("mcman_probePS2Card sio2cmd succeeded\n");

HAKAMA_SIGNALSEMA();
return r;
}

Expand Down