PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
mcsio2.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright (c) 2009 jimmikaelkael
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include <mcman.h>
12#include "mcman-internal.h"
13
14#ifdef BUILDING_XFROMMAN
15static flash_info_t dev9_flash_info;
16#endif
17
18#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
19static sio2_transfer_data_t mcman_sio2packet; // buffer for mcman sio2 packet
20static u8 mcman_wdmabufs[0x0b * 0x90]; // buffer array for SIO2 DMA I/O (write)
21static u8 mcman_rdmabufs[0x0b * 0x90]; // not sure here for size, buffer array for SIO2 DMA I/O (read)
22
23static sio2_transfer_data_t mcman_sio2packet_PS1PDA;
24static u8 mcman_sio2inbufs_PS1PDA[0x90];
25u8 mcman_sio2outbufs_PS1PDA[0x90];
26
27static u32 mcman_timercount;
28static int mcman_timerthick;
29
30// mcman cmd table used by sio2packet_add fnc
31// This is not an exaustive list of all commands being used. Some commands are generated by SECRMAN
32// See usages of functions beginning with card_auth in SECRMAN.
33static const u8 mcman_cmdtable[36] = {
34 0x11, 0x04, // 00, Probe, mcman/mcman_cardchanged
35 0x12, 0x04, // 01, ???, mcman/mcman_eraseblock
36 0x21, 0x09, // 02, Start Erase, mcman/mcman_eraseblock
37 0x22, 0x09, // 03, Start Write, mcman/McWritePage
38 0x23, 0x09, // 04, Start Read, mcman/mcman_readpage
39 0x24, 0x86, // 05, ???, ???
40 0x25, 0x04, // 06, ???, ???
41 0x26, 0x0d, // 07, Get Specs, mcman/McGetCardSpec
42 0x27, 0x05, // 08, Set Terminator, mcman/mcman_probePS2Card
43 0x28, 0x05, // 09, Get Terminator, mcman/mcman_probePS2Card2;mcman/mcman_probePS2Card
44 0x42, 0x86, // 0A, Write Data, mcman/McWritePage
45 0x43, 0x86, // 0B, Read Data, mcman/mcman_readpage
46 0x81, 0x04, // 0C, Read/Write End, mcman/McWritePage;mcman/mcman_readpage
47 0x82, 0x04, // 0D, Erase Block, mcman/mcman_eraseblock
48 0x42, 0x06, // 0E, Write Data, mcman/McWritePage
49 0x43, 0x06, // 0F, Read Data, mcman/mcman_readpage
50 0xbf, 0x05, // 10, ???, ???
51 0xf3, 0x05, // 11, ???, mcman/mcman_resetauth
52};
53
54// sio2packet_add child functions
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);
65
66// functions pointer array to handle sio2packet_add inner functions calls
67static void *sio2packet_add_funcs_array[16] = {
68 (void *)sio2packet_add_wdma_00, // commands that needs to clear in_dma.addr[2]
69 (void *)sio2packet_add_wdma_u32, // commands that needs to copy an int to in_dma.addr[2..5] (an int* can be passed as arg into buf)
70 (void *)sio2packet_add_wdma_u32, // ...
71 (void *)sio2packet_add_wdma_u32, // ...
72 (void *)sio2packet_add_wdma_u8, // commands that needs to copy an u8 value to in_dma.addr[2]
73 (void *)sio2packet_add_do_nothing, // do nothing
74 (void *)sio2packet_add_do_nothing, // ...
75 (void *)sio2packet_add_wdma_5a, // commands that needs to set in_dma.addr[2] to value 0x5a, used to set termination code
76 (void *)sio2packet_add_do_nothing, // do nothing
77 (void *)sio2packet_add_pagedata_in, // commands that needs to copy pagedata buf into in_dma.addr
78 (void *)sio2packet_add_pagedata_out,// commands that needs to set in_dma.addr[2] to value 128 for pagedata out
79 (void *)sio2packet_add_do_nothing, // do nothing
80 (void *)sio2packet_add_do_nothing, // ...
81 (void *)sio2packet_add_ecc_in, // commands that needs to copy sparedata buf into in_dma.addr
82 (void *)sio2packet_add_ecc_out, // commands that needs to prepare regdata and in_dma.addr to receive sparedata
83 (void *)sio2packet_add_wdma_u8 // commands that needs to copy an u8 value to in_dma.addr[2]
84};
85
86//--------------------------------------------------------------
87void sio2packet_add(int port, int slot, int cmd, u8 *buf)
88{ // Used to build the sio2packets for all mc commands
89 register u32 regdata;
90
91 if ((unsigned int)cmd == 0xffffffff) {
92 mcman_sio2packet.in_dma.count = 0;
93 return;
94 }
95
96 if (mcman_sio2packet.in_dma.count < 0xb) {
97 register int pos;
98 u8 *p;
99
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;
103 return;
104 }
105
106 regdata = (((port & 1) + 2) & 3) | 0x70;
107 regdata |= mcman_cmdtable[(cmd << 1) + 1] << 18;
108 regdata |= mcman_cmdtable[(cmd << 1) + 1] << 8;
109
110 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count] = regdata;
111
112 pos = ((mcman_sio2packet.in_dma.count + (mcman_sio2packet.in_dma.count << 3)) << 4);
113
114 mcman_sio2packet.in_dma.count++;
115
116 p = mcman_sio2packet.in_dma.addr + pos;
117 p[0] = 0x81;
118 p[1] = mcman_cmdtable[cmd << 1];
119
120 if (((cmd - 1) >= 16) || ((cmd - 1) < 0))
121 return;
122
123 sio2packet_add_func = (void*)sio2packet_add_funcs_array[(cmd - 1)];
124 (sio2packet_add_func)(port, slot, cmd, buf, pos); // call to the needed child func
125 }
126}
127
128//----
129// sio2packet child funcs
130
131static void sio2packet_add_wdma_u32(int port, int slot, int cmd, u8 *buf, int pos)
132{
133 (void)port;
134 (void)slot;
135 (void)cmd;
136
137 u8 *p = mcman_sio2packet.in_dma.addr + pos;
138 p[2] = buf[0];
139 p[3] = buf[1];
140 p[4] = buf[2];
141 p[5] = buf[3];
142 p[6] = mcman_calcEDC(&p[2], 4);
143}
144
145//--
146
147static void sio2packet_add_pagedata_out(int port, int slot, int cmd, u8 *buf, int pos)
148{
149 (void)port;
150 (void)slot;
151 (void)cmd;
152 (void)buf;
153
154 // used for sio2 command 0x81 0x43 to read page data
155 u8 *p = mcman_sio2packet.in_dma.addr + pos;
156 p[2] = 128;
157}
158
159//--
160
161static void sio2packet_add_pagedata_in(int port, int slot, int cmd, u8 *buf, int pos)
162{
163 (void)port;
164 (void)slot;
165 (void)cmd;
166
167 // used for sio2 command 0x81 0x42 to write page data
168 register int i;
169 u8 *p = mcman_sio2packet.in_dma.addr + pos;
170 p[2] = 128;
171
172 for (i=0; i<128; i++)
173 p[3 + i] = buf[i];
174
175 p[3 + 128] = mcman_calcEDC(&buf[0], 128);
176}
177
178//--
179
180static void sio2packet_add_ecc_in(int port, int slot, int cmd, u8 *buf, int pos)
181{
182 // used for sio2 command 0x81 0x42 to write page ecc
183 register u32 regdata;
184 int i;
185 u8 *p = mcman_sio2packet.in_dma.addr + pos;
186
187 p[2] = mcman_sparesize(port, slot);
188
189 for (i=0; i<(p[2] & 0xff); i++)
190 p[3 + i] = buf[i];
191
192 p[3 + p[2]] = mcman_calcEDC(&buf[0], p[2]);
193
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;
198
199 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] = regdata;
200}
201
202//--
203
204static void sio2packet_add_ecc_out(int port, int slot, int cmd, u8 *buf, int pos)
205{
206 (void)buf;
207
208 // used for sio2 command 0x81 0x43 to read page ecc
209 register u32 regdata;
210 u8 *p = mcman_sio2packet.in_dma.addr + pos;
211
212 p[2] = mcman_sparesize(port, slot);
213
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;
218
219 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] = regdata;
220}
221
222//--
223
224static void sio2packet_add_wdma_5a(int port, int slot, int cmd, u8 *buf, int pos)
225{
226 (void)port;
227 (void)slot;
228 (void)cmd;
229 (void)buf;
230
231 // used for sio2 command 0x81 0x27 to set a termination code
232 u8 *p = mcman_sio2packet.in_dma.addr + pos;
233 p[2] = 0x5a;
234}
235
236//--
237
238static void sio2packet_add_wdma_00(int port, int slot, int cmd, u8 *buf, int pos)
239{
240 (void)port;
241 (void)slot;
242 (void)cmd;
243 (void)buf;
244
245 u8 *p = mcman_sio2packet.in_dma.addr + pos;
246 p[2] = 0x00;
247
248}
249
250//--
251
252static void sio2packet_add_wdma_u8(int port, int slot, int cmd, u8 *buf, int pos)
253{
254 (void)port;
255 (void)slot;
256 (void)cmd;
257
258 u8 *p = mcman_sio2packet.in_dma.addr + pos;
259 p[2] = buf[0];
260}
261
262//--
263
264static void sio2packet_add_do_nothing(int port, int slot, int cmd, u8 *buf, int pos)
265{
266 (void)port;
267 (void)slot;
268 (void)cmd;
269 (void)buf;
270 (void)pos;
271
272 // do nothing
273}
274
275//--------------------------------------------------------------
276int mcsio2_transfer(int port, int slot, sio2_transfer_data_t *sio2data)
277{
278#ifdef BUILDING_XMCMAN
279 // SIO2 transfer for XMCMAN
280 register int r;
281 s32 port_ctrl[8];
282
283 DPRINTF("mcsio2_transfer port%d slot%d\n", port, slot);
284
285 port_ctrl[0] = -1;
286 port_ctrl[1] = -1;
287 port_ctrl[2] = -1;
288 port_ctrl[3] = -1;
289
290 port_ctrl[(port & 1) + 2] = slot;
291
292 sio2_mc_transfer_init();
293 sio2_mtap_change_slot(port_ctrl);
294 r = sio2_transfer(sio2data);
295 sio2_transfer_reset();
296
297 DPRINTF("mcsio2_transfer returns %d\n", r);
298
299 return r;
300#else
301 register int r;
302
303 (void)port;
304 (void)slot;
305
306#ifdef DEBUG
307 u8 *p = (u8 *)(sio2data->in_dma.addr);
308 if (p)
309 DPRINTF("mcsio2_transfer port%d slot%d cmd = %02x %02x %02x ", port, slot, p[0], p[1], p[2]);
310 else {
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]);
313 }
314#endif
315
316 // SIO2 transfer for MCMAN
317 sio2_mc_transfer_init();
318 r = sio2_transfer(sio2data);
319
320 DPRINTF("returns %d\n", r);
321
322 return r;
323#endif
324}
325#endif
326
327//--------------------------------------------------------------
328void mcman_initPS2com(void)
329{
330#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
331 mcman_wmemset((void *)&mcman_sio2packet, sizeof (mcman_sio2packet), 0);
332
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;
337
338 mcman_sio2packet.in_dma.addr = &mcman_wdmabufs;
339 mcman_sio2packet.in_dma.size = 0x24;
340
341 mcman_sio2packet.out_dma.addr = &mcman_rdmabufs;
342 mcman_sio2packet.out_dma.size = 0x24;
343
344 DPRINTF("mcman_initPS2com registering secrman_mc_command callback\n");
345 SecrSetMcCommandHandler((void *)secrman_mc_command);
346
347 DPRINTF("mcman_initPS2com registering mcman_getcnum callback\n");
348
349 SecrSetMcDevIDHandler((void *)mcman_getcnum);
350#elif defined(BUILDING_XFROMMAN)
351 flash_detect();
352 flash_get_info(&dev9_flash_info);
353#endif
354}
355
356//--------------------------------------------------------------
357void mcman_deinitPS2com(void)
358{
359#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
360 SecrSetMcCommandHandler(0);
361 SecrSetMcDevIDHandler(0);
362#endif
363}
364
365//--------------------------------------------------------------
366void mcman_initPS1PDAcom(void)
367{
368#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
369 memset((void *)&mcman_sio2packet_PS1PDA, 0, sizeof (mcman_sio2packet_PS1PDA));
370
371 mcman_sio2packet_PS1PDA.port_ctrl1[0] = 0xffc00505;
372 mcman_sio2packet_PS1PDA.port_ctrl1[1] = 0xffc00505;
373 mcman_sio2packet_PS1PDA.port_ctrl1[2] = 0xffc00505;
374 mcman_sio2packet_PS1PDA.port_ctrl1[3] = 0xffc00505;
375
376 mcman_sio2packet_PS1PDA.port_ctrl2[0] = 0x000201f4 & ~0x03000000;
377 mcman_sio2packet_PS1PDA.port_ctrl2[1] = 0x000201f4 & ~0x03000000;
378 mcman_sio2packet_PS1PDA.port_ctrl2[2] = 0x000201f4 & ~0x03000000;
379 mcman_sio2packet_PS1PDA.port_ctrl2[3] = 0x000201f4 & ~0x03000000;
380
381 mcman_sio2packet_PS1PDA.in = (u8 *)&mcman_sio2inbufs_PS1PDA;
382 mcman_sio2packet_PS1PDA.out = (u8 *)&mcman_sio2outbufs_PS1PDA;
383#endif
384}
385
386//--------------------------------------------------------------
387void mcman_deinitPS1PDAcom(void)
388{
389 // For now, stubbed. Semaphore was created somewhere between 1.6.0 (exclusive) and 3.1.0 (inclusive)
390}
391
392#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
393//--------------------------------------------------------------
394int secrman_mc_command(int port, int slot, sio2_transfer_data_t *sio2data)
395{
396 register int r;
397
398 DPRINTF("secrman_mc_command port%d slot%d\n", port, slot);
399
400 r = mcsio2_transfer(port, slot, sio2data);
401
402 return r;
403}
404#endif
405
406//--------------------------------------------------------------
407int mcman_cardchanged(int port, int slot)
408{
409#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
410 register int retries;
411 u8 *p = mcman_sio2packet.out_dma.addr;
412
413 DPRINTF("mcman_cardchanged sio2cmd port%d slot%d\n", port, slot);
414
415 sio2packet_add(port, slot, 0xffffffff, NULL);
416 sio2packet_add(port, slot, 0x00, NULL);
417 sio2packet_add(port, slot, 0xfffffffe, NULL);
418
419 retries = 0;
420 do {
421 mcsio2_transfer(port, slot, &mcman_sio2packet);
422
423 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[3] != 0x66))
424 break;
425
426 } while (++retries < 5);
427
428 if (retries >= 5) {
429 DPRINTF("mcman_cardchanged sio2cmd card changed!\n");
430 return sceMcResChangedCard;
431 }
432
433 DPRINTF("mcman_cardchanged sio2cmd succeeded\n");
434#else
435 (void)port;
436 (void)slot;
437#endif
438
439#if defined(BUILDING_VMCMAN)
440 return sceMcResChangedCard;
441#else
442 return sceMcResSucceed;
443#endif
444}
445
446//--------------------------------------------------------------
447int mcman_eraseblock(int port, int slot, int block, void **pagebuf, void *eccbuf)
448{
449 register int retries, size, ecc_offset;
450 int page;
451#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
452 u8 *p = mcman_sio2packet.out_dma.addr;
453#endif
454 void *p_ecc;
455 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
456
457 page = block * mcdi->blocksize;
458
459#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
460 sio2packet_add(port, slot, 0xffffffff, NULL);
461 sio2packet_add(port, slot, 0x02, (u8 *)&page);
462 sio2packet_add(port, slot, 0x0d, NULL);
463 sio2packet_add(port, slot, 0xfffffffe, NULL);
464#endif
465
466 retries = 0;
467 do {
468#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
469 mcsio2_transfer(port, slot, &mcman_sio2packet);
470
471 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[8] != 0x5a))
472 continue;
473
474 if (p[0x93] == p[8])
475 break;
476#elif defined(BUILDING_VMCMAN)
477 if (!mcman_iomanx_backing_erase(port, slot, page))
478 break;
479#elif defined(BUILDING_XFROMMAN)
480 if (!flash_page_erase(&dev9_flash_info, page))
481 break;
482#endif
483 } while (++retries < 5);
484
485 if (retries >= 5)
486 return sceMcResChangedCard;
487
488 if (pagebuf && eccbuf) { // This part leave the first ecc byte of each block page in eccbuf
489 mcman_wmemset(eccbuf, 32, 0);
490
491 page = 0;
492 while (page < mcdi->blocksize) {
493 ecc_offset = page * mcdi->pagesize;
494 if (ecc_offset < 0)
495 ecc_offset += 0x1f;
496 ecc_offset = ecc_offset >> 5;
497 p_ecc = (void *)((u8 *)eccbuf + ecc_offset);
498 size = 0;
499 while (size < mcdi->pagesize) {
500 if (*pagebuf)
501 McDataChecksum((void *)((u8 *)(*pagebuf) + size), p_ecc);
502 size += 128;
503 p_ecc = (void *)((u8 *)p_ecc + 3);
504 }
505 pagebuf++;
506 page++;
507 }
508 }
509
510#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
511 sio2packet_add(port, slot, 0xffffffff, NULL);
512 sio2packet_add(port, slot, 0x01, NULL);
513 sio2packet_add(port, slot, 0xfffffffe, NULL);
514
515 retries = 0;
516 do {
517 mcsio2_transfer(port, slot, &mcman_sio2packet);
518
519 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000))
520 continue;
521
522 if (p[3] == 0x5a)
523 return sceMcResSucceed;
524 } while (++retries < 100);
525
526 if (p[3] == 0x66)
527 return sceMcResFailReplace;
528#endif
529
530 return sceMcResNoFormat;
531}
532
533//--------------------------------------------------------------
534int McWritePage(int port, int slot, int page, void *pagebuf, void *eccbuf) // Export #19
535{
536 register int retries;
537#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
538 register int index, count;
539 u8 *p_pagebuf = (u8 *)pagebuf;
540 u8 *p = mcman_sio2packet.out_dma.addr;
541#endif
542
543#ifdef BUILDING_XFROMMAN
544 (void)port;
545 (void)slot;
546 char page_buf[528];
547 memcpy(page_buf, pagebuf, 512);
548 memcpy(page_buf + 512, eccbuf, 16);
549#endif
550
551#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
552 count = (mcman_devinfos[port][slot].pagesize + 127) >> 7;
553#endif
554
555 retries = 0;
556
557 do {
558#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
559 if (retries > 0)
560 mcman_cardchanged(port, slot);
561
562 sio2packet_add(port, slot, 0xffffffff, NULL);
563 sio2packet_add(port, slot, 0x03, (u8 *)&page);
564
565 index = 0;
566 while (index < count) {
567 sio2packet_add(port, slot, 0x0a, (u8 *)&p_pagebuf[index << 7]);
568 index++;
569 }
570
571 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
572 // if memcard have ECC support
573 sio2packet_add(port, slot, 0x0e, eccbuf);
574 }
575 sio2packet_add(port, slot, 0xfffffffe, NULL);
576
577 mcsio2_transfer(port, slot, &mcman_sio2packet);
578
579 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[8] != 0x5a))
580 continue;
581
582 index = 0;
583 while (index < count) {
584 if (p[0x94 + 128 + 1 + ((index + (index << 3)) << 4)] != 0x5a)
585 break;
586 index++;
587 }
588
589 if (index < count)
590 continue;
591
592 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
593 // if memcard have ECC support
594 index++;
595 if (p[5 + ((index + (index << 3)) << 4) + mcman_sparesize(port, slot)] != 0x5a)
596 continue;
597 }
598
599 sio2packet_add(port, slot, 0xffffffff, NULL);
600 sio2packet_add(port, slot, 0x0c, NULL);
601 sio2packet_add(port, slot, 0xfffffffe, NULL);
602
603 mcsio2_transfer(port, slot, &mcman_sio2packet);
604
605 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[3] != 0x5a))
606 continue;
607#elif defined(BUILDING_VMCMAN)
608 if (mcman_iomanx_backing_write(port, slot, page, pagebuf, eccbuf))
609 continue;
610#elif defined(BUILDING_XFROMMAN)
611 if (flash_page_write(&dev9_flash_info, page, page_buf))
612 continue;
613#endif
614 return sceMcResSucceed;
615
616 } while (++retries < 5);
617
618#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
619 if (p[3] == 0x66)
620 return sceMcResFailReplace;
621
622 return sceMcResNoFormat;
623#else
624 return sceMcResFailReplace;
625#endif
626}
627
628//--------------------------------------------------------------
629int mcman_readpage(int port, int slot, int page, void *buf, void *eccbuf)
630{
631#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
632 register int index, count, retries, r, i;
633 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
634 u8 *pbuf = (u8 *)buf;
635 u8 *pecc = (u8 *)eccbuf;
636 u8 *p = mcman_sio2packet.out_dma.addr;
637
638 count = (mcdi->pagesize + 127) >> 7;
639
640 retries = 0;
641
642 do {
643 if (retries > 0)
644 mcman_cardchanged(port, slot);
645
646 sio2packet_add(port, slot, 0xffffffff, NULL);
647 sio2packet_add(port, slot, 0x04, (u8 *)&page);
648
649 if (count > 0) {
650 index = 0;
651 while (index < count) {
652 sio2packet_add(port, slot, 0x0b, NULL);
653 index++;
654 }
655 }
656
657 if (mcdi->cardflags & CF_USE_ECC) // if memcard have ECC support
658 sio2packet_add(port, slot, 0x0f, NULL);
659
660 sio2packet_add(port, slot, 0x0c, NULL);
661 sio2packet_add(port, slot, 0xfffffffe, NULL);
662
663 mcsio2_transfer(port, slot, &mcman_sio2packet);
664
665 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
666 || (p[8] != 0x5a)
667 || (p[0x94 + 0x2cf] != 0x5a))
668 continue;
669
670 if (count > 0) {
671 index = 0;
672 while (index < count) {
673 // checking EDC
674 r = mcman_calcEDC(&p[0x94 + ((index + (index << 3)) << 4)], 128) & 0xFF;
675 if (r != p[0x94 + 128 + ((index + (index << 3)) << 4)])
676 break;
677 index++;
678 }
679
680 if (index < count)
681 continue;
682
683 index = 0;
684 while (index < count) {
685 for (i=0; i<128; i++)
686 pbuf[(index << 7) + i] = p[0x94 + ((index + (index << 3)) << 4) + i];
687 index++;
688 }
689 }
690
691 memcpy(pecc, &p[0x94 + ((count + (count << 3)) << 4)] , mcman_sparesize(port, slot));
692 break;
693
694 } while (++retries < 5);
695
696 if (retries < 5)
697 return sceMcResSucceed;
698#elif defined(BUILDING_VMCMAN)
699 if (!mcman_iomanx_backing_read(port, slot, page, buf, eccbuf)) {
700 return sceMcResSucceed;
701 }
702#elif defined(BUILDING_XFROMMAN)
703 (void)port;
704 (void)slot;
705 // No retry logic here.
706 char page_buf[528];
707 if (!flash_page_read(&dev9_flash_info, page, 1, page_buf))
708 {
709 if (buf)
710 {
711 memcpy(buf, page_buf, 512);
712 }
713 if (eccbuf)
714 {
715 memcpy(eccbuf, page_buf + 512, 16);
716 }
717 return sceMcResSucceed;
718 }
719#endif
720 return sceMcResChangedCard;
721}
722
723//--------------------------------------------------------------
724int McGetCardSpec(int port, int slot, s16 *pagesize, u16 *blocksize, int *cardsize, u8 *flags)
725{
726#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
727 register int retries, r;
728 u8 *p = mcman_sio2packet.out_dma.addr;
729
730 DPRINTF("McGetCardSpec sio2cmd port%d slot%d\n", port, slot);
731
732 sio2packet_add(port, slot, 0xffffffff, NULL);
733 sio2packet_add(port, slot, 0x07, NULL);
734 sio2packet_add(port, slot, 0xfffffffe, NULL);
735
736 retries = 0;
737
738 do {
739 mcsio2_transfer(port, slot, &mcman_sio2packet);
740
741 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[12] == 0x5a)) {
742 // checking EDC
743 r = mcman_calcEDC(&p[3], 8) & 0xFF;
744 if (r == p[11])
745 break;
746 }
747 } while (++retries < 5);
748
749 if (retries >= 5)
750 return sceMcResChangedCard;
751
752 *pagesize = (p[4] << 8) + p[3];
753 *blocksize = (p[6] << 8) + p[5];
754 *cardsize = (p[8] << 8) + p[7] + (p[9] << 16) + (p[10] << 24);
755 *flags = p[2];
756#elif defined(BUILDING_VMCMAN)
757 if (mcman_iomanx_backing_getcardspec(port, slot, pagesize, blocksize, cardsize, flags))
758 return sceMcResFailDetect2;
759#elif defined(BUILDING_XFROMMAN)
760 (void)port;
761 (void)slot;
762 flash_get_info(&dev9_flash_info);
763 *pagesize = 512; /* Yes, this is hardcoded to 512 bytes */
764 *blocksize = dev9_flash_info.block_pages;
765 *cardsize = dev9_flash_info.blocks * dev9_flash_info.block_pages;
766 *flags = 0x22 | CF_BAD_BLOCK;
767 if (dev9_flash_info.page_bytes != 512)
768 *flags |= CF_USE_ECC;
769#endif
770
771 DPRINTF("McGetCardSpec sio2cmd pagesize=%d blocksize=%u cardsize=%d flags%x\n", *pagesize, *blocksize, *cardsize, *flags);
772
773 return sceMcResSucceed;
774}
775
776//--------------------------------------------------------------
777int mcman_resetauth(int port, int slot)
778{
779#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
780 register int retries;
781
782 DPRINTF("mcman_resetauth sio2cmd port%d slot%d\n", port, slot);
783
784 sio2packet_add(port, slot, 0xffffffff, NULL);
785 sio2packet_add(port, slot, 0x11, NULL);
786 sio2packet_add(port, slot, 0xfffffffe, NULL);
787
788 retries = 0;
789
790 do {
791 mcsio2_transfer(port, slot, &mcman_sio2packet);
792
793 if ((mcman_sio2packet.stat6c & 0xF000) == 0x1000)
794 break;
795
796 } while (++retries < 5);
797
798 if (retries >= 5) {
799 DPRINTF("mcman_resetauth sio2cmd card changed!\n");
800
801 return sceMcResChangedCard;
802 }
803
804 DPRINTF("mcman_resetauth sio2cmd succeeded\n");
805#else
806 (void)port;
807 (void)slot;
808#endif
809
810 return sceMcResSucceed;
811}
812
813//--------------------------------------------------------------
814int mcman_probePS2Card2(int port, int slot)
815{
816#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
817 register int retries, r;
818 u8 *p = mcman_sio2packet.out_dma.addr;
819
820 DPRINTF("mcman_probePS2Card2 sio2cmd port%d slot%d\n", port, slot);
821
822 retries = 0;
823 do {
824 sio2packet_add(port, slot, 0xffffffff, NULL);
825 sio2packet_add(port, slot, 0x09, NULL);
826 sio2packet_add(port, slot, 0xfffffffe, NULL);
827
828 mcsio2_transfer(port, slot, &mcman_sio2packet);
829
830 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
831 break;
832 } while (++retries < 5);
833
834 if (retries >= 5)
835 return sceMcResFailDetect;
836
837 if (p[3] == 0x5a) {
838 r = McGetFormat(port, slot);
839 if (r > 0)
840 {
841 DPRINTF("mcman_probePS2Card2 succeeded\n");
842
843 return sceMcResSucceed;
844 }
845 else if (r < 0)
846 {
847 DPRINTF("mcman_probePS2Card2 sio2cmd failed (no format)\n");
848
849 return sceMcResNoFormat;
850 }
851 }
852
853 DPRINTF("mcman_probePS2Card2 sio2cmd failed (mc detection failed)\n");
854#else
855 if (!McGetFormat(port, slot))
856 {
857 mcman_probePS2Card(port, slot);
858 }
859 if (McGetFormat(port, slot) > 0)
860 return sceMcResSucceed;
861 if (McGetFormat(port, slot) < 0)
862 return sceMcResNoFormat;
863#endif
864
865 return sceMcResFailDetect2;
866}
867
868//--------------------------------------------------------------
869int mcman_probePS2Card(int port, int slot) //2
870{
871 register int r;
872#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
873 register int retries;
874 u8 *p = mcman_sio2packet.out_dma.addr;
875#endif
876
877 DPRINTF("mcman_probePS2Card sio2cmd port%d slot%d\n", port, slot);
878
879 r = mcman_cardchanged(port, slot);
880 if (r == sceMcResSucceed) {
881 r = McGetFormat(port, slot);
882 if (r > 0)
883 {
884 DPRINTF("mcman_probePS2Card sio2cmd succeeded\n");
885
886 return sceMcResSucceed;
887 }
888 else if (r < 0)
889 {
890 DPRINTF("mcman_probePS2Card sio2cmd failed (no format)\n");
891
892 return sceMcResNoFormat;
893 }
894 }
895
896#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
897 if (mcman_resetauth(port, slot) != sceMcResSucceed) {
898 DPRINTF("mcman_probePS2Card sio2cmd failed (auth reset failed)\n");
899
900 return sceMcResFailResetAuth;
901 }
902
903 if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) {
904 DPRINTF("mcman_probePS2Card sio2cmd failed (auth failed)\n");
905
906 return sceMcResFailAuth;
907 }
908
909 retries = 0;
910 do {
911 sio2packet_add(port, slot, 0xffffffff, NULL);
912 sio2packet_add(port, slot, 0x09, NULL);
913 sio2packet_add(port, slot, 0xfffffffe, NULL);
914
915 mcsio2_transfer(port, slot, &mcman_sio2packet);
916
917 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
918 break;
919 } while (++retries < 5);
920
921 if (retries >= 5) {
922 DPRINTF("mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
923 return sceMcResFailDetect;
924 }
925#endif
926
927 mcman_clearcache(port, slot);
928
929#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
930 sio2packet_add(port, slot, 0xffffffff, NULL);
931 sio2packet_add(port, slot, 0x08, NULL);
932 sio2packet_add(port, slot, 0xfffffffe, NULL);
933
934 retries = 0;
935 do {
936 mcsio2_transfer(port, slot, &mcman_sio2packet);
937
938 if ((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
939 continue;
940
941 if (p[4] == 0x5a)
942 break;
943 } while (++retries < 5);
944
945 if (retries >= 5) {
946 DPRINTF("mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
947
948 return sceMcResFailDetect2;
949 }
950#endif
951
952 r = mcman_setdevinfos(port, slot);
953 if (r == 0) {
954 DPRINTF("mcman_probePS2Card sio2cmd card changed!\n");
955 return sceMcResChangedCard;
956 }
957 if (r != sceMcResNoFormat) {
958 DPRINTF("mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
959 return sceMcResFailDetect2;
960 }
961
962 DPRINTF("mcman_probePS2Card sio2cmd succeeded\n");
963
964 return r;
965}
966
967//--------------------------------------------------------------
968int mcman_probePS1Card2(int port, int slot)
969{
970#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
971 register int retries;
972 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
973
974 DPRINTF("mcman_probePS1Card2 port%d slot%d\n", port, slot);
975
976 mcman_sio2packet_PS1PDA.regdata[0] = 0;
977 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
978 mcman_sio2packet_PS1PDA.in_size = 3;
979 mcman_sio2packet_PS1PDA.out_size = 3;
980
981 mcman_sio2packet_PS1PDA.regdata[1] = 0;
982 mcman_sio2inbufs_PS1PDA[0] = 0x81;
983 mcman_sio2inbufs_PS1PDA[1] = 0x52;
984
985 retries = 0;
986 do {
987 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
988
989 u32 hi, lo;
990 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
991
992 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
993 DelayThread(mcman_timerthick - (hi >> 3));
994
995 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
996
997 mcman_timercount = GetTimerCounter(timer_ID);
998 mcman_timerthick = 0;
999
1000 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1001 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1002 break;
1003 }
1004 } while (++retries < 5);
1005
1006 if (retries >= 5)
1007 return -12;
1008
1009 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1010 if (mcdi->cardform > 0)
1011 return sceMcResSucceed;
1012 else if (mcdi->cardform < 0)
1013 return sceMcResNoFormat;
1014 }
1015 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1016 return -14;
1017 }
1018#else
1019 (void)port;
1020 (void)slot;
1021#endif
1022
1023 return -13;
1024}
1025
1026//--------------------------------------------------------------
1027int mcman_probePS1Card(int port, int slot)
1028{
1029#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1030 register int i, r, retries;
1031 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1032 u32 *p;
1033
1034 DPRINTF("mcman_probePS1Card port%d slot%d\n", port, slot);
1035
1036 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1037 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
1038 mcman_sio2packet_PS1PDA.in_size = 3;
1039 mcman_sio2packet_PS1PDA.out_size = 3;
1040
1041 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1042 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1043 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1044
1045 retries = 0;
1046 do {
1047 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1048
1049 u32 hi, lo;
1050 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1051
1052 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1053 DelayThread(mcman_timerthick - (hi >> 3));
1054
1055 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1056
1057 mcman_timercount = GetTimerCounter(timer_ID);
1058 mcman_timerthick = 0;
1059
1060 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1061 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1062 break;
1063 }
1064 } while (++retries < 5);
1065
1066 if (retries >= 5)
1067 return -11;
1068
1069 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1070 if (mcdi->cardform != 0)
1071 return sceMcResSucceed;
1072 else
1073 return sceMcResNoFormat;
1074 }
1075 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1076 return -12;
1077 }
1078
1079 mcman_clearcache(port, slot);
1080
1081 p = (u32 *)&mcman_sio2outbufs_PS1PDA[124];
1082 for (i = 31; i >= 0; i--)
1083 *p-- = 0;
1084
1085 r = McWritePS1PDACard(port, slot, 63, mcman_sio2outbufs_PS1PDA);
1086 if (r < 0)
1087 return -13;
1088
1089 r = mcman_setPS1devinfos(port, slot);
1090 if (r == 0)
1091 return sceMcResChangedCard;
1092
1093 return r;
1094#else
1095 (void)port;
1096 (void)slot;
1097 return sceMcResSucceed;
1098#endif
1099}
1100
1101//--------------------------------------------------------------
1102int mcman_probePDACard(int port, int slot)
1103{
1104#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1105 register int retries;
1106
1107 DPRINTF("mcman_probePDACard port%d slot%d\n", port, slot);
1108
1109 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1110 mcman_sio2packet_PS1PDA.regdata[0] = (port & 3) | 0x00140540;
1111 mcman_sio2packet_PS1PDA.in_size = 5;
1112 mcman_sio2packet_PS1PDA.out_size = 5;
1113
1114 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1115 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1116 mcman_sio2inbufs_PS1PDA[1] = 0x58;
1117
1118 retries = 0;
1119 do {
1120 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1121
1122 if ((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000)
1123 break;
1124
1125 } while (++retries < 5);
1126
1127 if (retries >= 5)
1128 return -11;
1129#else
1130 (void)port;
1131 (void)slot;
1132#endif
1133
1134 return sceMcResSucceed;
1135}
1136
1137//--------------------------------------------------------------
1138int McWritePS1PDACard(int port, int slot, int page, void *buf) // Export #30
1139{
1140#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1141 register int i, retries;
1142 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1143 u8 *p;
1144
1145 //DPRINTF("McWritePS1PDACard port%d slot%d page %x\n", port, slot, page);
1146
1147 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1148 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02288a40;
1149 mcman_sio2packet_PS1PDA.in_size = 138;
1150 mcman_sio2packet_PS1PDA.out_size = 138;
1151 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1152
1153 for (i = 0; i < 20; i++) {
1154 if (mcdi->bad_block_list[i] == page)
1155 page += 36;
1156 }
1157
1158 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1159 mcman_sio2inbufs_PS1PDA[1] = 0x57;
1160 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1161 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1162
1163 p = (u8 *)buf;
1164 for (i = 0; i < 128; i++)
1165 mcman_sio2inbufs_PS1PDA[6 + i] = p[i];
1166
1167 mcman_sio2inbufs_PS1PDA[4 + 130] = mcman_calcEDC(&mcman_sio2inbufs_PS1PDA[4], 130);
1168
1169 retries = 0;
1170 do {
1171 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1172
1173 u32 hi, lo;
1174 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1175
1176 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1177 DelayThread(mcman_timerthick - (hi >> 3));
1178
1179 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1180
1181 mcman_timercount = GetTimerCounter(timer_ID);
1182 mcman_timerthick = 20000;
1183
1184 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1185 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1186 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1187 && (mcman_sio2outbufs_PS1PDA[137] == 0x47)) {
1188 break;
1189 }
1190 } while (++retries < 5);
1191
1192 if (retries >= 5)
1193 return sceMcResNoEntry;
1194
1195 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1196 return sceMcResFullDevice;
1197#else
1198 (void)port;
1199 (void)slot;
1200 (void)page;
1201 (void)buf;
1202#endif
1203
1204 return sceMcResSucceed;
1205}
1206
1207//--------------------------------------------------------------
1208int McReadPS1PDACard(int port, int slot, int page, void *buf) // Export #29
1209{
1210#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1211 register int i, retries;
1212 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1213 u8 *p;
1214
1215 //DPRINTF("McReadPS1PDACard port%d slot%d page %x\n", port, slot, page);
1216
1217 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1218 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02308c40;
1219 mcman_sio2packet_PS1PDA.in_size = 140;
1220 mcman_sio2packet_PS1PDA.out_size = 140;
1221 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1222
1223 for (i = 0; i < 20; i++) {
1224 if (mcdi->bad_block_list[i] == page)
1225 page += 36;
1226 }
1227
1228 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1229 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1230 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1231 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1232
1233 retries = 0;
1234 do {
1235 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1236
1237 u32 hi, lo;
1238 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1239
1240 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1241 DelayThread(mcman_timerthick - (hi >> 3));
1242
1243 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1244
1245 mcman_timercount = GetTimerCounter(timer_ID);
1246 mcman_timerthick = 10000;
1247
1248 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1249 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1250 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1251 && (mcman_sio2outbufs_PS1PDA[4] == 0x00) \
1252 && (mcman_sio2outbufs_PS1PDA[6] == 0x5c) \
1253 && (mcman_sio2outbufs_PS1PDA[7] == 0x5d) \
1254 && (mcman_sio2outbufs_PS1PDA[139] == 0x47)) {
1255
1256 if (mcman_sio2outbufs_PS1PDA[138] == (mcman_calcEDC(&mcman_sio2outbufs_PS1PDA[8], 130) & 0xff))
1257 break;
1258 }
1259 } while (++retries < 5);
1260
1261 if (retries >= 5)
1262 return sceMcResNoEntry;
1263
1264 p = (u8 *)buf;
1265 for (i = 0; i < 128; i++)
1266 p[i] = mcman_sio2outbufs_PS1PDA[10 + i];
1267
1268 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1269 return sceMcResDeniedPermit;
1270#else
1271 (void)port;
1272 (void)slot;
1273 (void)page;
1274 (void)buf;
1275#endif
1276
1277 return sceMcResSucceed;
1278}
1279
1280
Definition tcpip.h:200
u32 count
start sector of fragmented bd/file