12#include "mcman-internal.h"
14#ifdef BUILDING_XFROMMAN
18#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
20static u8 mcman_wdmabufs[0x0b * 0x90];
21static u8 mcman_rdmabufs[0x0b * 0x90];
24static u8 mcman_sio2inbufs_PS1PDA[0x90];
25u8 mcman_sio2outbufs_PS1PDA[0x90];
27static u32 mcman_timercount;
28static int mcman_timerthick;
33static const u8 mcman_cmdtable[36] = {
55static void (*sio2packet_add_func)(
int port,
int slot,
int cmd, u8 *buf,
int pos);
56static void sio2packet_add_wdma_u32(
int port,
int slot,
int cmd, u8 *buf,
int pos);
57static void sio2packet_add_pagedata_out(
int port,
int slot,
int cmd, u8 *buf,
int pos);
58static void sio2packet_add_pagedata_in(
int port,
int slot,
int cmd, u8 *buf,
int pos);
59static void sio2packet_add_ecc_in(
int port,
int slot,
int cmd, u8 *buf,
int pos);
60static void sio2packet_add_ecc_out(
int port,
int slot,
int cmd, u8 *buf,
int pos);
61static void sio2packet_add_wdma_5a(
int port,
int slot,
int cmd, u8 *buf,
int pos);
62static void sio2packet_add_wdma_00(
int port,
int slot,
int cmd, u8 *buf,
int pos);
63static void sio2packet_add_wdma_u8(
int port,
int slot,
int cmd, u8 *buf,
int pos);
64static void sio2packet_add_do_nothing(
int port,
int slot,
int cmd, u8 *buf,
int pos);
67static void *sio2packet_add_funcs_array[16] = {
68 (
void *)sio2packet_add_wdma_00,
69 (
void *)sio2packet_add_wdma_u32,
70 (
void *)sio2packet_add_wdma_u32,
71 (
void *)sio2packet_add_wdma_u32,
72 (
void *)sio2packet_add_wdma_u8,
73 (
void *)sio2packet_add_do_nothing,
74 (
void *)sio2packet_add_do_nothing,
75 (
void *)sio2packet_add_wdma_5a,
76 (
void *)sio2packet_add_do_nothing,
77 (
void *)sio2packet_add_pagedata_in,
78 (
void *)sio2packet_add_pagedata_out,
79 (
void *)sio2packet_add_do_nothing,
80 (
void *)sio2packet_add_do_nothing,
81 (
void *)sio2packet_add_ecc_in,
82 (
void *)sio2packet_add_ecc_out,
83 (
void *)sio2packet_add_wdma_u8
87void sio2packet_add(
int port,
int slot,
int cmd, u8 *buf)
91 if ((
unsigned int)cmd == 0xffffffff) {
92 mcman_sio2packet.in_dma.count = 0;
96 if (mcman_sio2packet.in_dma.count < 0xb) {
100 if ((
unsigned int)cmd == 0xfffffffe) {
101 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count] = 0;
102 mcman_sio2packet.out_dma.count = mcman_sio2packet.in_dma.count;
106 regdata = (((port & 1) + 2) & 3) | 0x70;
107 regdata |= mcman_cmdtable[(cmd << 1) + 1] << 18;
108 regdata |= mcman_cmdtable[(cmd << 1) + 1] << 8;
110 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count] = regdata;
112 pos = ((mcman_sio2packet.in_dma.count + (mcman_sio2packet.in_dma.count << 3)) << 4);
114 mcman_sio2packet.in_dma.count++;
116 p = mcman_sio2packet.in_dma.addr + pos;
118 p[1] = mcman_cmdtable[cmd << 1];
120 if (((cmd - 1) >= 16) || ((cmd - 1) < 0))
123 sio2packet_add_func = (
void*)sio2packet_add_funcs_array[(cmd - 1)];
124 (sio2packet_add_func)(port, slot, cmd, buf, pos);
131static void sio2packet_add_wdma_u32(
int port,
int slot,
int cmd, u8 *buf,
int pos)
137 u8 *p = mcman_sio2packet.in_dma.addr + pos;
142 p[6] = mcman_calcEDC(&p[2], 4);
147static void sio2packet_add_pagedata_out(
int port,
int slot,
int cmd, u8 *buf,
int pos)
155 u8 *p = mcman_sio2packet.in_dma.addr + pos;
161static void sio2packet_add_pagedata_in(
int port,
int slot,
int cmd, u8 *buf,
int pos)
169 u8 *p = mcman_sio2packet.in_dma.addr + pos;
172 for (i=0; i<128; i++)
175 p[3 + 128] = mcman_calcEDC(&buf[0], 128);
180static void sio2packet_add_ecc_in(
int port,
int slot,
int cmd, u8 *buf,
int pos)
183 register u32 regdata;
185 u8 *p = mcman_sio2packet.in_dma.addr + pos;
187 p[2] = mcman_sparesize(port, slot);
189 for (i=0; i<(p[2] & 0xff); i++)
192 p[3 + p[2]] = mcman_calcEDC(&buf[0], p[2]);
194 regdata = (p[2] + mcman_cmdtable[(cmd << 1) + 1]) << 18;
195 regdata |= mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] & ~0x07fc0000;
196 regdata &= ~0x0001ff00;
197 regdata |= (p[2] + mcman_cmdtable[(cmd << 1) + 1]) << 8;
199 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] = regdata;
204static void sio2packet_add_ecc_out(
int port,
int slot,
int cmd, u8 *buf,
int pos)
209 register u32 regdata;
210 u8 *p = mcman_sio2packet.in_dma.addr + pos;
212 p[2] = mcman_sparesize(port, slot);
214 regdata = (p[2] + mcman_cmdtable[(cmd << 1) + 1]) << 18;
215 regdata |= mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] & ~0x07fc0000;
216 regdata &= ~0x0001ff00;
217 regdata |= (p[2] + mcman_cmdtable[(cmd << 1) + 1]) << 8;
219 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] = regdata;
224static void sio2packet_add_wdma_5a(
int port,
int slot,
int cmd, u8 *buf,
int pos)
232 u8 *p = mcman_sio2packet.in_dma.addr + pos;
238static void sio2packet_add_wdma_00(
int port,
int slot,
int cmd, u8 *buf,
int pos)
245 u8 *p = mcman_sio2packet.in_dma.addr + pos;
252static void sio2packet_add_wdma_u8(
int port,
int slot,
int cmd, u8 *buf,
int pos)
258 u8 *p = mcman_sio2packet.in_dma.addr + pos;
264static void sio2packet_add_do_nothing(
int port,
int slot,
int cmd, u8 *buf,
int pos)
278#ifdef BUILDING_XMCMAN
283 DPRINTF(
"mcsio2_transfer port%d slot%d\n", port, slot);
290 port_ctrl[(port & 1) + 2] = slot;
292 sio2_mc_transfer_init();
293 sio2_mtap_change_slot(port_ctrl);
294 r = sio2_transfer(sio2data);
295 sio2_transfer_reset();
297 DPRINTF(
"mcsio2_transfer returns %d\n", r);
307 u8 *p = (u8 *)(sio2data->in_dma.addr);
309 DPRINTF(
"mcsio2_transfer port%d slot%d cmd = %02x %02x %02x ", port, slot, p[0], p[1], p[2]);
311 p = (u8 *)(sio2data->in);
312 DPRINTF(
"mcsio2_transfer for secrman port%d slot%d cmd = %02x %02x %02x ", port, slot, p[0], p[1], p[2]);
317 sio2_mc_transfer_init();
318 r = sio2_transfer(sio2data);
320 DPRINTF(
"returns %d\n", r);
328void mcman_initPS2com(
void)
330#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
331 mcman_wmemset((
void *)&mcman_sio2packet,
sizeof (mcman_sio2packet), 0);
333 mcman_sio2packet.port_ctrl1[2] = 0xff020405;
334 mcman_sio2packet.port_ctrl1[3] = 0xff020405;
335 mcman_sio2packet.port_ctrl2[2] = 0x0005ffff & ~0x03000000;
336 mcman_sio2packet.port_ctrl2[3] = 0x0005ffff & ~0x03000000;
338 mcman_sio2packet.in_dma.addr = &mcman_wdmabufs;
339 mcman_sio2packet.in_dma.size = 0x24;
341 mcman_sio2packet.out_dma.addr = &mcman_rdmabufs;
342 mcman_sio2packet.out_dma.size = 0x24;
344 DPRINTF(
"mcman_initPS2com registering secrman_mc_command callback\n");
345 SecrSetMcCommandHandler((
void *)secrman_mc_command);
347 DPRINTF(
"mcman_initPS2com registering mcman_getcnum callback\n");
349 SecrSetMcDevIDHandler((
void *)mcman_getcnum);
351#ifdef BUILDING_DONGLEMAN
353 sema_hakama.attr = 1;
354 sema_hakama.initial = 1;
356 sema_hakama.option = 0;
357 sema_hakama_id = CreateSema(&sema_hakama);
360#elif defined(BUILDING_XFROMMAN)
362 flash_get_info(&dev9_flash_info);
367void mcman_deinitPS2com(
void)
369#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
370 SecrSetMcCommandHandler(0);
371 SecrSetMcDevIDHandler(0);
376void mcman_initPS1PDAcom(
void)
378#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
379 memset((
void *)&mcman_sio2packet_PS1PDA, 0,
sizeof (mcman_sio2packet_PS1PDA));
381 mcman_sio2packet_PS1PDA.port_ctrl1[0] = 0xffc00505;
382 mcman_sio2packet_PS1PDA.port_ctrl1[1] = 0xffc00505;
383 mcman_sio2packet_PS1PDA.port_ctrl1[2] = 0xffc00505;
384 mcman_sio2packet_PS1PDA.port_ctrl1[3] = 0xffc00505;
386 mcman_sio2packet_PS1PDA.port_ctrl2[0] = 0x000201f4 & ~0x03000000;
387 mcman_sio2packet_PS1PDA.port_ctrl2[1] = 0x000201f4 & ~0x03000000;
388 mcman_sio2packet_PS1PDA.port_ctrl2[2] = 0x000201f4 & ~0x03000000;
389 mcman_sio2packet_PS1PDA.port_ctrl2[3] = 0x000201f4 & ~0x03000000;
391 mcman_sio2packet_PS1PDA.in = (u8 *)&mcman_sio2inbufs_PS1PDA;
392 mcman_sio2packet_PS1PDA.out = (u8 *)&mcman_sio2outbufs_PS1PDA;
397void mcman_deinitPS1PDAcom(
void)
402#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
408 DPRINTF(
"secrman_mc_command port%d slot%d\n", port, slot);
410 r = mcsio2_transfer(port, slot, sio2data);
417int mcman_cardchanged(
int port,
int slot)
419#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
420 register int retries;
421 u8 *p = mcman_sio2packet.out_dma.addr;
423 DPRINTF(
"mcman_cardchanged sio2cmd port%d slot%d\n", port, slot);
425 sio2packet_add(port, slot, 0xffffffff, NULL);
426 sio2packet_add(port, slot, 0x00, NULL);
427 sio2packet_add(port, slot, 0xfffffffe, NULL);
431 mcsio2_transfer(port, slot, &mcman_sio2packet);
433 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[3] != 0x66))
436 }
while (++retries < 5);
439 DPRINTF(
"mcman_cardchanged sio2cmd card changed!\n");
440 return sceMcResChangedCard;
443 DPRINTF(
"mcman_cardchanged sio2cmd succeeded\n");
449#if defined(BUILDING_VMCMAN)
450 return sceMcResChangedCard;
452 return sceMcResSucceed;
457int mcman_eraseblock(
int port,
int slot,
int block,
void **pagebuf,
void *eccbuf)
459 register int retries, size, ecc_offset;
462#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
463 u8 *p = mcman_sio2packet.out_dma.addr;
466 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
468 page = block * mcdi->blocksize;
470#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
471 sio2packet_add(port, slot, 0xffffffff, NULL);
472 sio2packet_add(port, slot, 0x02, (u8 *)&page);
473 sio2packet_add(port, slot, 0x0d, NULL);
474 sio2packet_add(port, slot, 0xfffffffe, NULL);
479#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
480 mcsio2_transfer(port, slot, &mcman_sio2packet);
482 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[8] != 0x5a))
487#elif defined(BUILDING_VMCMAN)
488 if (!mcman_iomanx_backing_erase(port, slot, page))
490#elif defined(BUILDING_XFROMMAN)
491 if (!flash_page_erase(&dev9_flash_info, page))
494 }
while (++retries < 5);
497 return sceMcResChangedCard;
499 if (pagebuf && eccbuf) {
500 mcman_wmemset(eccbuf, 32, 0);
503 while (page < mcdi->blocksize) {
504 ecc_offset = page * mcdi->pagesize;
507 ecc_offset = ecc_offset >> 5;
508 p_ecc = (
void *)((u8 *)eccbuf + ecc_offset);
510 while (size < mcdi->pagesize) {
512 McDataChecksum((
void *)((u8 *)(*pagebuf) + size), p_ecc);
514 p_ecc = (
void *)((u8 *)p_ecc + 3);
521#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
522 sio2packet_add(port, slot, 0xffffffff, NULL);
523 sio2packet_add(port, slot, 0x01, NULL);
524 sio2packet_add(port, slot, 0xfffffffe, NULL);
528 mcsio2_transfer(port, slot, &mcman_sio2packet);
530 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000))
535 return sceMcResSucceed;
537 }
while (++retries < 100);
542 return sceMcResFailReplace;
546 return sceMcResNoFormat;
550int McWritePage(
int port,
int slot,
int page,
void *pagebuf,
void *eccbuf)
552 register int retries;
553#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
554 register int index,
count;
555 u8 *p_pagebuf = (u8 *)pagebuf;
556 u8 *p = mcman_sio2packet.out_dma.addr;
561#ifdef BUILDING_XFROMMAN
565 memcpy(page_buf, pagebuf, 512);
566 memcpy(page_buf + 512, eccbuf, 16);
569#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
570 count = (mcman_devinfos[port][slot].pagesize + 127) >> 7;
576#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
578 mcman_cardchanged(port, slot);
580 sio2packet_add(port, slot, 0xffffffff, NULL);
581 sio2packet_add(port, slot, 0x03, (u8 *)&page);
584 while (index <
count) {
585 sio2packet_add(port, slot, 0x0a, (u8 *)&p_pagebuf[index << 7]);
589 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
591 sio2packet_add(port, slot, 0x0e, eccbuf);
593 sio2packet_add(port, slot, 0xfffffffe, NULL);
595 mcsio2_transfer(port, slot, &mcman_sio2packet);
597 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[8] != 0x5a))
601 while (index <
count) {
602 if (p[0x94 + 128 + 1 + ((index + (index << 3)) << 4)] != 0x5a)
610 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
613 if (p[5 + ((index + (index << 3)) << 4) + mcman_sparesize(port, slot)] != 0x5a)
617 sio2packet_add(port, slot, 0xffffffff, NULL);
618 sio2packet_add(port, slot, 0x0c, NULL);
619 sio2packet_add(port, slot, 0xfffffffe, NULL);
621 mcsio2_transfer(port, slot, &mcman_sio2packet);
623 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[3] != 0x5a))
625#elif defined(BUILDING_VMCMAN)
626 if (mcman_iomanx_backing_write(port, slot, page, pagebuf, eccbuf))
628#elif defined(BUILDING_XFROMMAN)
629 if (flash_page_write(&dev9_flash_info, page, page_buf))
633 return sceMcResSucceed;
635 }
while (++retries < 5);
637#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
641 return sceMcResFailReplace;
645 return sceMcResNoFormat;
647 return sceMcResFailReplace;
652int mcman_readpage(
int port,
int slot,
int page,
void *buf,
void *eccbuf)
654#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
655 register int index,
count, retries, r, i;
656 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
657 u8 *
pbuf = (u8 *)buf;
658 u8 *pecc = (u8 *)eccbuf;
659 u8 *p = mcman_sio2packet.out_dma.addr;
661 count = (mcdi->pagesize + 127) >> 7;
667 mcman_cardchanged(port, slot);
669 sio2packet_add(port, slot, 0xffffffff, NULL);
670 sio2packet_add(port, slot, 0x04, (u8 *)&page);
674 while (index <
count) {
675 sio2packet_add(port, slot, 0x0b, NULL);
680 if (mcdi->cardflags & CF_USE_ECC)
681 sio2packet_add(port, slot, 0x0f, NULL);
683 sio2packet_add(port, slot, 0x0c, NULL);
684 sio2packet_add(port, slot, 0xfffffffe, NULL);
686 mcsio2_transfer(port, slot, &mcman_sio2packet);
688 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
690 || (p[0x94 + 0x2cf] != 0x5a))
695 while (index <
count) {
697 r = mcman_calcEDC(&p[0x94 + ((index + (index << 3)) << 4)], 128) & 0xFF;
698 if (r != p[0x94 + 128 + ((index + (index << 3)) << 4)])
707 while (index <
count) {
708 for (i=0; i<128; i++)
709 pbuf[(index << 7) + i] = p[0x94 + ((index + (index << 3)) << 4) + i];
714 memcpy(pecc, &p[0x94 + ((
count + (
count << 3)) << 4)] , mcman_sparesize(port, slot));
717 }
while (++retries < 5);
720 return sceMcResSucceed;
721#elif defined(BUILDING_VMCMAN)
722 if (!mcman_iomanx_backing_read(port, slot, page, buf, eccbuf)) {
723 return sceMcResSucceed;
725#elif defined(BUILDING_XFROMMAN)
730 if (!flash_page_read(&dev9_flash_info, page, 1, page_buf))
734 memcpy(buf, page_buf, 512);
738 memcpy(eccbuf, page_buf + 512, 16);
740 return sceMcResSucceed;
743 return sceMcResChangedCard;
747int McGetCardSpec(
int port,
int slot, s16 *pagesize, u16 *blocksize,
int *cardsize, u8 *flags)
749#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
750 register int retries, r;
751 u8 *p = mcman_sio2packet.out_dma.addr;
753 DPRINTF(
"McGetCardSpec sio2cmd port%d slot%d\n", port, slot);
757 sio2packet_add(port, slot, 0xffffffff, NULL);
758 sio2packet_add(port, slot, 0x07, NULL);
759 sio2packet_add(port, slot, 0xfffffffe, NULL);
764 mcsio2_transfer(port, slot, &mcman_sio2packet);
766 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[12] == 0x5a)) {
768 r = mcman_calcEDC(&p[3], 8) & 0xFF;
772 }
while (++retries < 5);
776 return sceMcResChangedCard;
779 *pagesize = (p[4] << 8) + p[3];
780 *blocksize = (p[6] << 8) + p[5];
781 *cardsize = (p[8] << 8) + p[7] + (p[9] << 16) + (p[10] << 24);
783#elif defined(BUILDING_VMCMAN)
784 if (mcman_iomanx_backing_getcardspec(port, slot, pagesize, blocksize, cardsize, flags))
785 return sceMcResFailDetect2;
786#elif defined(BUILDING_XFROMMAN)
789 flash_get_info(&dev9_flash_info);
791 *blocksize = dev9_flash_info.block_pages;
792 *cardsize = dev9_flash_info.blocks * dev9_flash_info.block_pages;
793 *flags = 0x22 | CF_BAD_BLOCK;
794 if (dev9_flash_info.page_bytes != 512)
795 *flags |= CF_USE_ECC;
797 DPRINTF(
"McGetCardSpec sio2cmd pagesize=%d blocksize=%u cardsize=%d flags%x\n", *pagesize, *blocksize, *cardsize, *flags);
800 return sceMcResSucceed;
804int mcman_resetauth(
int port,
int slot)
806#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
807 register int retries;
809 DPRINTF(
"mcman_resetauth sio2cmd port%d slot%d\n", port, slot);
811 sio2packet_add(port, slot, 0xffffffff, NULL);
812 sio2packet_add(port, slot, 0x11, NULL);
813 sio2packet_add(port, slot, 0xfffffffe, NULL);
818 mcsio2_transfer(port, slot, &mcman_sio2packet);
820 if ((mcman_sio2packet.stat6c & 0xF000) == 0x1000)
823 }
while (++retries < 5);
826 DPRINTF(
"mcman_resetauth sio2cmd card changed!\n");
828 return sceMcResChangedCard;
831 DPRINTF(
"mcman_resetauth sio2cmd succeeded\n");
837 return sceMcResSucceed;
841int mcman_probePS2Card2(
int port,
int slot)
843#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
844 register int retries, r;
845 u8 *p = mcman_sio2packet.out_dma.addr;
847 DPRINTF(
"mcman_probePS2Card2 sio2cmd port%d slot%d\n", port, slot);
851 sio2packet_add(port, slot, 0xffffffff, NULL);
852 sio2packet_add(port, slot, 0x09, NULL);
853 sio2packet_add(port, slot, 0xfffffffe, NULL);
855 mcsio2_transfer(port, slot, &mcman_sio2packet);
857 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
859 }
while (++retries < 5);
863 return sceMcResFailDetect;
867 r = McGetFormat(port, slot);
870 DPRINTF(
"mcman_probePS2Card2 succeeded\n");
872 return sceMcResSucceed;
876 DPRINTF(
"mcman_probePS2Card2 sio2cmd failed (no format)\n");
878 return sceMcResNoFormat;
882 DPRINTF(
"mcman_probePS2Card2 sio2cmd failed (mc detection failed)\n");
884 if (!McGetFormat(port, slot))
886 mcman_probePS2Card(port, slot);
888 if (McGetFormat(port, slot) > 0)
889 return sceMcResSucceed;
890 if (McGetFormat(port, slot) < 0)
891 return sceMcResNoFormat;
895 return sceMcResFailDetect2;
899int mcman_probePS2Card(
int port,
int slot)
902#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
903 register int retries;
904 u8 *p = mcman_sio2packet.out_dma.addr;
909 DPRINTF(
"mcman_probePS2Card sio2cmd port%d slot%d\n", port, slot);
911 r = mcman_cardchanged(port, slot);
912 if (r == sceMcResSucceed) {
913 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));
922 DPRINTF(
"mcman_probePS2Card sio2cmd succeeded\n");
923 return sceMcResSucceed;
927#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
928 if (mcman_resetauth(port, slot) != sceMcResSucceed) {
929 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth reset failed)\n");
931 return sceMcResFailResetAuth;
934#ifdef BUILDING_DONGLEMAN
936 DPRINTF(
"mcman_probePS2Card: SecrAuthDongle(2, %d, %d)\n", slot, mcman_getcnum(port, slot));
937 if (SecrAuthDongle(2, slot, mcman_getcnum(port, slot)) == 0) {
938 DPRINTF(
"mcman_probePS2Card SecrAuthDongle Failed\n");
940 return sceMcResFailAuth;
943 else if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) {
944 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth failed)\n");
946 return sceMcResFailAuth;
949 if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) {
950 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth failed)\n");
952 return sceMcResFailAuth;
958 sio2packet_add(port, slot, 0xffffffff, NULL);
959 sio2packet_add(port, slot, 0x09, NULL);
960 sio2packet_add(port, slot, 0xfffffffe, NULL);
962 mcsio2_transfer(port, slot, &mcman_sio2packet);
964 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
966 }
while (++retries < 5);
969 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
970 return sceMcResFailDetect;
974 mcman_clearcache(port, slot);
976#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
977 sio2packet_add(port, slot, 0xffffffff, NULL);
978 sio2packet_add(port, slot, 0x08, NULL);
979 sio2packet_add(port, slot, 0xfffffffe, NULL);
983 mcsio2_transfer(port, slot, &mcman_sio2packet);
985 if ((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
990 }
while (++retries < 5);
993 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
995 return sceMcResFailDetect2;
999 r = mcman_setdevinfos(port, slot);
1001 DPRINTF(
"mcman_probePS2Card sio2cmd card changed!\n");
1002 return sceMcResChangedCard;
1004 if (r != sceMcResNoFormat) {
1005 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
1006 return sceMcResFailDetect2;
1009 DPRINTF(
"mcman_probePS2Card sio2cmd succeeded\n");
1015int mcman_probePS1Card2(
int port,
int slot)
1017#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1018 register int retries;
1019 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1021 DPRINTF(
"mcman_probePS1Card2 port%d slot%d\n", port, slot);
1023 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1024 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
1025 mcman_sio2packet_PS1PDA.in_size = 3;
1026 mcman_sio2packet_PS1PDA.out_size = 3;
1028 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1029 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1030 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1034 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1037 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1039 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1040 DelayThread(mcman_timerthick - (hi >> 3));
1042 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1044 mcman_timercount = GetTimerCounter(timer_ID);
1045 mcman_timerthick = 0;
1047 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1048 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1051 }
while (++retries < 5);
1056 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1057 if (mcdi->cardform > 0)
1058 return sceMcResSucceed;
1059 else if (mcdi->cardform < 0)
1060 return sceMcResNoFormat;
1062 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1074int mcman_probePS1Card(
int port,
int slot)
1076#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1077 register int i, r, retries;
1078 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1081 DPRINTF(
"mcman_probePS1Card port%d slot%d\n", port, slot);
1083 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1084 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
1085 mcman_sio2packet_PS1PDA.in_size = 3;
1086 mcman_sio2packet_PS1PDA.out_size = 3;
1088 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1089 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1090 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1094 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1097 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1099 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1100 DelayThread(mcman_timerthick - (hi >> 3));
1102 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1104 mcman_timercount = GetTimerCounter(timer_ID);
1105 mcman_timerthick = 0;
1107 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1108 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1111 }
while (++retries < 5);
1116 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1117 if (mcdi->cardform != 0)
1118 return sceMcResSucceed;
1120 return sceMcResNoFormat;
1122 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1126 mcman_clearcache(port, slot);
1128 p = (u32 *)&mcman_sio2outbufs_PS1PDA[124];
1129 for (i = 31; i >= 0; i--)
1132 r = McWritePS1PDACard(port, slot, 63, mcman_sio2outbufs_PS1PDA);
1136 r = mcman_setPS1devinfos(port, slot);
1138 return sceMcResChangedCard;
1144 return sceMcResSucceed;
1149int mcman_probePDACard(
int port,
int slot)
1151#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1152 register int retries;
1154 DPRINTF(
"mcman_probePDACard port%d slot%d\n", port, slot);
1156 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1157 mcman_sio2packet_PS1PDA.regdata[0] = (port & 3) | 0x00140540;
1158 mcman_sio2packet_PS1PDA.in_size = 5;
1159 mcman_sio2packet_PS1PDA.out_size = 5;
1161 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1162 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1163 mcman_sio2inbufs_PS1PDA[1] = 0x58;
1167 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1169 if ((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000)
1172 }
while (++retries < 5);
1181 return sceMcResSucceed;
1185int McWritePS1PDACard(
int port,
int slot,
int page,
void *buf)
1187#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1188 register int i, retries;
1189 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1194 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1195 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02288a40;
1196 mcman_sio2packet_PS1PDA.in_size = 138;
1197 mcman_sio2packet_PS1PDA.out_size = 138;
1198 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1200 for (i = 0; i < 20; i++) {
1201 if (mcdi->bad_block_list[i] == page)
1205 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1206 mcman_sio2inbufs_PS1PDA[1] = 0x57;
1207 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1208 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1211 for (i = 0; i < 128; i++)
1212 mcman_sio2inbufs_PS1PDA[6 + i] = p[i];
1214 mcman_sio2inbufs_PS1PDA[4 + 130] = mcman_calcEDC(&mcman_sio2inbufs_PS1PDA[4], 130);
1218 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1221 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1223 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1224 DelayThread(mcman_timerthick - (hi >> 3));
1226 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1228 mcman_timercount = GetTimerCounter(timer_ID);
1229 mcman_timerthick = 20000;
1231 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1232 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1233 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1234 && (mcman_sio2outbufs_PS1PDA[137] == 0x47)) {
1237 }
while (++retries < 5);
1240 return sceMcResNoEntry;
1242 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1243 return sceMcResFullDevice;
1251 return sceMcResSucceed;
1255int McReadPS1PDACard(
int port,
int slot,
int page,
void *buf)
1257#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1258 register int i, retries;
1259 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1264 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1265 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02308c40;
1266 mcman_sio2packet_PS1PDA.in_size = 140;
1267 mcman_sio2packet_PS1PDA.out_size = 140;
1268 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1270 for (i = 0; i < 20; i++) {
1271 if (mcdi->bad_block_list[i] == page)
1275 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1276 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1277 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1278 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1282 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1285 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1287 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1288 DelayThread(mcman_timerthick - (hi >> 3));
1290 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1292 mcman_timercount = GetTimerCounter(timer_ID);
1293 mcman_timerthick = 10000;
1295 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1296 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1297 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1298 && (mcman_sio2outbufs_PS1PDA[4] == 0x00) \
1299 && (mcman_sio2outbufs_PS1PDA[6] == 0x5c) \
1300 && (mcman_sio2outbufs_PS1PDA[7] == 0x5d) \
1301 && (mcman_sio2outbufs_PS1PDA[139] == 0x47)) {
1303 if (mcman_sio2outbufs_PS1PDA[138] == (mcman_calcEDC(&mcman_sio2outbufs_PS1PDA[8], 130) & 0xff))
1306 }
while (++retries < 5);
1309 return sceMcResNoEntry;
1312 for (i = 0; i < 128; i++)
1313 p[i] = mcman_sio2outbufs_PS1PDA[10 + i];
1315 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1316 return sceMcResDeniedPermit;
1324 return sceMcResSucceed;
u32 count
start sector of fragmented bd/file