@@ -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,37 +904,61 @@ 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+ #ifdef BUILDING_DONGLEMAN
915+ if (r != 0 && port == 0 ) {
916+ DPRINTF ("mcman_probePS2Card:[McGetFormat() != 0]: calling authdongle(2, %d, %d)\n" , slot , mcman_getcnum (port , slot ));
917+ SecrAuthDongle (2 , slot , mcman_getcnum (port , slot ));
918+ }
919+ #endif
882920 if (r > 0 )
883921 {
884922 DPRINTF ("mcman_probePS2Card sio2cmd succeeded\n" );
885-
923+ HAKAMA_SIGNALSEMA ();
886924 return sceMcResSucceed ;
887925 }
888926 else if (r < 0 )
889927 {
890928 DPRINTF ("mcman_probePS2Card sio2cmd failed (no format)\n" );
891-
929+ HAKAMA_SIGNALSEMA ();
892930 return sceMcResNoFormat ;
893931 }
894932 }
895933
896934#if !defined(BUILDING_XFROMMAN ) && !defined(BUILDING_VMCMAN )
897935 if (mcman_resetauth (port , slot ) != sceMcResSucceed ) {
898936 DPRINTF ("mcman_probePS2Card sio2cmd failed (auth reset failed)\n" );
899-
937+ HAKAMA_SIGNALSEMA ();
900938 return sceMcResFailResetAuth ;
901939 }
902940
903- if (SecrAuthCard (port + 2 , slot , mcman_getcnum (port , slot )) == 0 ) {
904- DPRINTF ("mcman_probePS2Card sio2cmd failed (auth failed)\n" );
941+ #ifdef BUILDING_DONGLEMAN
942+ if (port == 0 ) {
943+ DPRINTF ("mcman_probePS2Card: SecrAuthDongle(2, %d, %d)\n" , slot , mcman_getcnum (port , slot ));
944+ if (SecrAuthDongle (2 , slot , mcman_getcnum (port , slot )) == 0 ) {
945+ DPRINTF ("mcman_probePS2Card SecrAuthDongle Failed\n" );
905946
906- return sceMcResFailAuth ;
907- }
947+ return sceMcResFailAuth ;
948+ }
949+ }
950+ else if (SecrAuthCard (port + 2 , slot , mcman_getcnum (port , slot )) == 0 ) {
951+ DPRINTF ("mcman_probePS2Card sio2cmd failed (auth failed)\n" );
952+
953+ return sceMcResFailAuth ;
954+ }
955+ #else
956+ if (SecrAuthCard (port + 2 , slot , mcman_getcnum (port , slot )) == 0 ) {
957+ DPRINTF ("mcman_probePS2Card sio2cmd failed (auth failed)\n" );
958+
959+ return sceMcResFailAuth ;
960+ }
961+ #endif
908962
909963 retries = 0 ;
910964 do {
0 commit comments