Skip to content

Commit 7311880

Browse files
committed
add DONGLEMAN variant of MCMAN
1 parent 0f60997 commit 7311880

File tree

6 files changed

+112
-14
lines changed

6 files changed

+112
-14
lines changed

iop/memorycard/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Review ps2sdk README & LICENSE files for further details.
88

99
SUBDIRS = \
10+
dongleman \
1011
mcman \
1112
mcman-old \
1213
mcserv \

iop/memorycard/dongleman/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# _____ ___ ____ ___ ____
2+
# ____| | ____| | | |____|
3+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
4+
#-----------------------------------------------------------------------
5+
# Copyright 2001-2025, ps2dev - http://www.ps2dev.org
6+
# Licenced under Academic Free License version 2.0
7+
# Review ps2sdk README & LICENSE files for further details.
8+
9+
PARENT_DIR=$(PS2SDKSRC)/iop/memorycard/mcman
10+
11+
IOP_SRC_DIR = $(PARENT_DIR)/src/
12+
IOP_INC_DIR = $(PARENT_DIR)/include/
13+
14+
IOP_BIN ?= dongleman.irx
15+
16+
MCMAN_BUILDING_DONGLEMAN ?= 0
17+
18+
include $(PARENT_DIR)/Makefile

iop/memorycard/mcman/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ IOP_CFLAGS += -DIOMANX_OLD_NAME_COMPATIBILITY=0
5757
IOP_CFLAGS += -DIOMANX_OLD_NAME_ADDDELDRV=0
5858
endif
5959

60+
ifneq (x$(MCMAN_BUILDING_DONGLEMAN),x0)
61+
IOP_CFLAGS += -DBUILDING_DONGLEMAN
62+
endif
63+
6064
include $(PS2SDKSRC)/Defs.make
6165
include $(PS2SDKSRC)/iop/Rules.bin.make
6266
include $(PS2SDKSRC)/iop/Rules.make

iop/memorycard/mcman/src/main.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ static const u8 mcman_xortable[256] = {
103103
};
104104
// clang-format on
105105

106+
#ifdef BUILDING_DONGLEMAN
107+
int sema_hakama_id = 0;
108+
#endif
109+
106110
//--------------------------------------------------------------
107111
void long_multiply(u32 v1, u32 v2, u32 *HI, u32 *LO)
108112
{
@@ -1162,6 +1166,8 @@ int McReadPage(int port, int slot, int page, void *buf) // Export #18
11621166
u8 eccbuf[32];
11631167
u8 *pdata, *peccb;
11641168

1169+
HAKAMA_WAITSEMA();
1170+
11651171
count = (mcdi->pagesize + 127) >> 7;
11661172
erase_byte = (mcdi->cardflags & CF_ERASE_ZEROES) ? 0x0 : 0xFF;
11671173

@@ -1203,6 +1209,8 @@ int McReadPage(int port, int slot, int page, void *buf) // Export #18
12031209
}
12041210
} while (++retries < 5);
12051211

1212+
HAKAMA_SIGNALSEMA();
1213+
12061214
if (retries < 5)
12071215
return sceMcResSucceed;
12081216

@@ -1241,7 +1249,17 @@ void McDataChecksum(void *buf, void *ecc) // Export #20
12411249
//--------------------------------------------------------------
12421250
int mcman_getcnum(int port, int slot)
12431251
{
1244-
return ((port & 1) << 3) + slot;
1252+
return
1253+
#if !defined(BULDING_DONGLEMAN)
1254+
((port & 1) << 3) + slot;
1255+
#else
1256+
/**
1257+
* this cnum is impossible to get with any combination in 4 slots, 2 ports
1258+
* most likely this is intened to be used by MCMAN modules that read dongles. as Arcade rom0:MCMANO does not have this.
1259+
* secrAuthDongle will xor this number with 0x40 for `mechacon_auth_81()`
1260+
*/
1261+
0xF;
1262+
#endif
12451263
}
12461264

12471265
//--------------------------------------------------------------

iop/memorycard/mcman/src/mcman-internal.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
#define MODNAME "vmcman"
6464
#elif defined(BUILDING_XFROMMAN)
6565
#define MODNAME "xfromman"
66+
#elif defined(BUILDING_DONGLEMAN)
67+
#define MODNAME "dongleman"
6668
#endif
6769
#define MODVER 0x20b
6870

@@ -363,4 +365,13 @@ extern u8 mcman_eccdata[512]; // size for 32 ecc
363365
// Defined in mcsio2.c
364366
extern u8 mcman_sio2outbufs_PS1PDA[0x90];
365367

368+
#ifdef BUILDING_DONGLEMAN
369+
extern int sema_hakama_id;
370+
#define HAKAMA_SIGNALSEMA() SignalSema(sema_hakama_id)
371+
#define HAKAMA_WAITSEMA() WaitSema(sema_hakama_id)
372+
#else
373+
#define HAKAMA_SIGNALSEMA() while(0)/* SignalSema wrapper for an additional semaphore used by arcade MCMAN */
374+
#define HAKAMA_WAITSEMA() while(0)/* WaitSema wrapper for an additional semaphore used by arcade MCMAN */
375+
#endif
376+
366377
#endif // __MCMAN_INTERNAL_H__

iop/memorycard/mcman/src/mcsio2.c

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ void mcman_initPS2com(void)
347347
DPRINTF("mcman_initPS2com registering mcman_getcnum callback\n");
348348

349349
SecrSetMcDevIDHandler((void *)mcman_getcnum);
350+
351+
#ifdef BUILDING_DONGLEMAN
352+
iop_sema_t sema_hakama;
353+
sema_hakama.attr = 1;
354+
sema_hakama.initial = 1;
355+
sema_hakama.max = 1;
356+
sema_hakama.option = 0;
357+
sema_hakama_id = CreateSema(&sema_hakama);
358+
#endif
359+
350360
#elif defined(BUILDING_XFROMMAN)
351361
flash_detect();
352362
flash_get_info(&dev9_flash_info);
@@ -448,6 +458,7 @@ int mcman_eraseblock(int port, int slot, int block, void **pagebuf, void *eccbuf
448458
{
449459
register int retries, size, ecc_offset;
450460
int page;
461+
HAKAMA_WAITSEMA();
451462
#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
452463
u8 *p = mcman_sio2packet.out_dma.addr;
453464
#endif
@@ -519,14 +530,19 @@ int mcman_eraseblock(int port, int slot, int block, void **pagebuf, void *eccbuf
519530
if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000))
520531
continue;
521532

522-
if (p[3] == 0x5a)
533+
if (p[3] == 0x5a) {
534+
HAKAMA_SIGNALSEMA();
523535
return sceMcResSucceed;
536+
}
524537
} while (++retries < 100);
525538

526-
if (p[3] == 0x66)
539+
HAKAMA_SIGNALSEMA(); //El_isra: Original impl has two semas (still commented there) replaced with one for simplicity
540+
if (p[3] == 0x66) {
541+
//HAKAMA_SIGNALSEMA();
527542
return sceMcResFailReplace;
543+
}
528544
#endif
529-
545+
//HAKAMA_SIGNALSEMA();
530546
return sceMcResNoFormat;
531547
}
532548

@@ -540,6 +556,8 @@ int McWritePage(int port, int slot, int page, void *pagebuf, void *eccbuf) // Ex
540556
u8 *p = mcman_sio2packet.out_dma.addr;
541557
#endif
542558

559+
HAKAMA_WAITSEMA();
560+
543561
#ifdef BUILDING_XFROMMAN
544562
(void)port;
545563
(void)slot;
@@ -611,14 +629,19 @@ int McWritePage(int port, int slot, int page, void *pagebuf, void *eccbuf) // Ex
611629
if (flash_page_write(&dev9_flash_info, page, page_buf))
612630
continue;
613631
#endif
632+
HAKAMA_SIGNALSEMA();
614633
return sceMcResSucceed;
615634

616635
} while (++retries < 5);
617636

618637
#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
619-
if (p[3] == 0x66)
638+
HAKAMA_SIGNALSEMA(); // El_isra: simplify original impl
639+
if (p[3] == 0x66) {
640+
//HAKAMA_SIGNALSEMA();
620641
return sceMcResFailReplace;
642+
}
621643

644+
//HAKAMA_SIGNALSEMA();
622645
return sceMcResNoFormat;
623646
#else
624647
return sceMcResFailReplace;
@@ -729,6 +752,8 @@ int McGetCardSpec(int port, int slot, s16 *pagesize, u16 *blocksize, int *cardsi
729752

730753
DPRINTF("McGetCardSpec sio2cmd port%d slot%d\n", port, slot);
731754

755+
HAKAMA_WAITSEMA();
756+
732757
sio2packet_add(port, slot, 0xffffffff, NULL);
733758
sio2packet_add(port, slot, 0x07, NULL);
734759
sio2packet_add(port, slot, 0xfffffffe, NULL);
@@ -746,8 +771,10 @@ int McGetCardSpec(int port, int slot, s16 *pagesize, u16 *blocksize, int *cardsi
746771
}
747772
} while (++retries < 5);
748773

749-
if (retries >= 5)
774+
if (retries >= 5) {
775+
HAKAMA_SIGNALSEMA();
750776
return sceMcResChangedCard;
777+
}
751778

752779
*pagesize = (p[4] << 8) + p[3];
753780
*blocksize = (p[6] << 8) + p[5];
@@ -767,8 +794,8 @@ int McGetCardSpec(int port, int slot, s16 *pagesize, u16 *blocksize, int *cardsi
767794
if (dev9_flash_info.page_bytes != 512)
768795
*flags |= CF_USE_ECC;
769796
#endif
770-
771797
DPRINTF("McGetCardSpec sio2cmd pagesize=%d blocksize=%u cardsize=%d flags%x\n", *pagesize, *blocksize, *cardsize, *flags);
798+
HAKAMA_SIGNALSEMA();
772799

773800
return sceMcResSucceed;
774801
}
@@ -818,7 +845,7 @@ int mcman_probePS2Card2(int port, int slot)
818845
u8 *p = mcman_sio2packet.out_dma.addr;
819846

820847
DPRINTF("mcman_probePS2Card2 sio2cmd port%d slot%d\n", port, slot);
821-
848+
HAKAMA_WAITSEMA();
822849
retries = 0;
823850
do {
824851
sio2packet_add(port, slot, 0xffffffff, NULL);
@@ -831,21 +858,23 @@ int mcman_probePS2Card2(int port, int slot)
831858
break;
832859
} while (++retries < 5);
833860

834-
if (retries >= 5)
861+
if (retries >= 5) {
862+
HAKAMA_SIGNALSEMA();
835863
return sceMcResFailDetect;
864+
}
836865

837866
if (p[3] == 0x5a) {
838867
r = McGetFormat(port, slot);
839868
if (r > 0)
840869
{
841870
DPRINTF("mcman_probePS2Card2 succeeded\n");
842-
871+
HAKAMA_SIGNALSEMA();
843872
return sceMcResSucceed;
844873
}
845874
else if (r < 0)
846875
{
847876
DPRINTF("mcman_probePS2Card2 sio2cmd failed (no format)\n");
848-
877+
HAKAMA_SIGNALSEMA();
849878
return sceMcResNoFormat;
850879
}
851880
}
@@ -862,6 +891,7 @@ int mcman_probePS2Card2(int port, int slot)
862891
return sceMcResNoFormat;
863892
#endif
864893

894+
HAKAMA_SIGNALSEMA();
865895
return sceMcResFailDetect2;
866896
}
867897

@@ -874,32 +904,48 @@ int mcman_probePS2Card(int port, int slot) //2
874904
u8 *p = mcman_sio2packet.out_dma.addr;
875905
#endif
876906

907+
HAKAMA_WAITSEMA();
908+
877909
DPRINTF("mcman_probePS2Card sio2cmd port%d slot%d\n", port, slot);
878910

879911
r = mcman_cardchanged(port, slot);
880912
if (r == sceMcResSucceed) {
881913
r = McGetFormat(port, slot);
914+
if (r != 0 && port == 0) {
915+
DPRINTF("mcman_probePS2Card:[McGetFormat() != 0]: calling authdongle()\n")
916+
SecrAuthDongle(2, slot, mcman_getcnum(port, slot));
917+
}
882918
if (r > 0)
883919
{
884920
DPRINTF("mcman_probePS2Card sio2cmd succeeded\n");
885-
921+
HAKAMA_SIGNALSEMA();
886922
return sceMcResSucceed;
887923
}
888924
else if (r < 0)
889925
{
890926
DPRINTF("mcman_probePS2Card sio2cmd failed (no format)\n");
891-
927+
HAKAMA_SIGNALSEMA();
892928
return sceMcResNoFormat;
893929
}
894930
}
895931

896932
#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
897933
if (mcman_resetauth(port, slot) != sceMcResSucceed) {
898934
DPRINTF("mcman_probePS2Card sio2cmd failed (auth reset failed)\n");
899-
935+
HAKAMA_SIGNALSEMA();
900936
return sceMcResFailResetAuth;
901937
}
902938

939+
#ifdef BUILDING_DONGLEMAN
940+
if (port == 0) {
941+
DPRINTF("mcman_probePS2Card: SecrAuthDongle()\n")
942+
if (SecrAuthDongle(2, slot, mcman_getcnum(port, slot)) == 0) {
943+
DPRINTF("mcman_probePS2Card SecrAuthDongle Failed\n");
944+
945+
return sceMcResFailAuth;
946+
}
947+
} else
948+
#endif
903949
if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) {
904950
DPRINTF("mcman_probePS2Card sio2cmd failed (auth failed)\n");
905951

0 commit comments

Comments
 (0)