PS2SDK
PS2 Homebrew Libraries
cdvdfsv.c
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
11 #include "irx_imports.h"
12 
13 #include <cdvd-ioctl.h>
14 #include <kerr.h>
15 #include <libcdvd-rpc.h>
16 
17 IRX_ID("cdvd_ee_driver", 2, 38);
18 // Based on the module from SCE SDK 3.1.0.
19 
20 extern struct irx_export_table _exp_cdvdfsv;
21 
22 static int cdvdfsv_init(void);
23 static void cdvdfsv_main_th(void *arg);
24 extern int *cdvdfsv_dummyentry(int arg1);
25 static void cdvdfsv_parseargs(int ac, char **av);
26 static void cdvdfsv_poffloop(void);
27 static void cdvdfsv_rpc1_th(void *arg);
28 static void cdvdfsv_rpc3_th(void *arg);
29 static void cdvdfsv_rpc2_th(void *arg);
30 #ifdef CDVD_VARIANT_OSD
31 static void cdvdfsv_rpc4_th(void *arg);
32 static void cdvdfsv_rpc5_th(void *arg);
33 #endif
34 extern unsigned int optimized_memcpy(char *dst, const char *src, unsigned int n);
35 
36 static int g_cdvdfsv_def_pri = 81;
37 static int g_verbose_level = 0;
38 static int g_cdvdfsv_spinctl = -1;
39 // Was non-const in XOSD
40 static const int g_cdvdfsv_sectors = 0x10;
41 // g_cdvdfsv_sectors_cdda is same as g_cdvdfsv_sectors; separated here for reference
42 #ifdef CDVD_VARIANT_OSD
43 static const int g_cdvdfsv_sectors_cdda = 0x10;
44 #else
45 static const int g_cdvdfsv_sectors_cdda = 8;
46 #endif
47 // Was non-const in XOSD
48 static const int g_cdvdfsv_r2retry_initval = 3;
49 static int g_cdvdfsv_plbreak = 0;
50 static int g_cdvdfsv_nopocm = 0;
51 static int g_cdvdfsv_rpc5flg = 0;
52 static int g_cdvdfsv_rpc3flg = 0;
53 #if 0
54 static iop_library_t g_modload_libinfo = { NULL, NULL, 256, 0, "modload", { NULL } };
55 #endif
56 static int g_cdvdfsv_r2retry = 0;
57 static int g_cdvdfsv_r2count = 0;
58 static int g_cdvdfsv_sid_err_recover_cnt = 0;
59 static int g_cdvdfsv_err_count = 0;
60 static char *g_cdvdfsv_fsvrbuf[2];
61 static char *g_cdvdfsv_rtocbuf;
62 static SifDmaTransfer_t g_cdvdfsv_fssdd;
63 static SifDmaTransfer_t g_cdvdfsv_iomrsdd;
64 static SifDmaTransfer_t g_cdvdfsv_rdp2sdd;
65 static SifDmaTransfer_t g_cdvdfsv_multi_dmat[16];
66 static sceCdRMode g_cdvdfsv_rmodeee;
67 static SifDmaTransfer_t g_cdvdfsv_datasdd;
68 static SifDmaTransfer_t g_cdvdfsv_eerpsdd;
69 static SifDmaTransfer_t g_cdvdfsv_chrdsdd;
70 #ifdef CDVD_VARIANT_OSD
71 static SifDmaTransfer_t g_cdvdfsv_readdvdv_dmat;
72 #endif
73 static SifDmaTransfer_t g_cdvdfsv_eereadfull_dma1;
74 static SifDmaTransfer_t g_cdvdfsv_eereadfull_dma2;
75 static SifDmaTransfer_t g_cdvdfsv_rtocsdd;
76 static iop_sys_clock_t g_cdvdfsv_read_timeout;
77 static int g_cdvdman_intr_evfid;
78 static int g_scmd_evfid;
79 #ifdef CDVD_VARIANT_OSD
80 static int g_cdvdfsv_thids[6];
81 #else
82 static int g_cdvdfsv_thids[4];
83 #endif
84 static cdvdman_internal_struct_t *g_cdvdman_istruct_ptr;
85 static cdvdfsv_rpc1_outpacket_t g_cdvdfsv_initres;
86 static cdvdfsv_unaligned_data_outpacket_t g_cdvdfsv_eereadx;
87 static SifRpcDataQueue_t g_rpc_qdata2;
88 static SifRpcDataQueue_t g_rpc_qdata1;
89 static SifRpcDataQueue_t g_rpc_qdata3;
90 static SifRpcServerData_t g_rpc_sdata1;
91 static SifRpcServerData_t g_rpc_sdata4;
92 static SifRpcServerData_t g_rpc_sdata5;
93 static SifRpcServerData_t g_rpc_sdata2;
94 static SifRpcServerData_t g_rpc_sdata6;
95 static SifRpcServerData_t g_rpc_sdata3;
96 static cdvdfsv_rpc4_outpacket_t g_cdvdfsv_srchres;
97 static int g_cdvdfsv_readpos;
98 static int g_cdvdfsv_rderror;
99 static cdvdfsv_rpc2_outpacket_t g_diskready_res;
100 static cdvdfsv_rpc5_outpacket_t g_crr;
101 static cdvdfsv_rpc3_outpacket_t g_outbuf;
102 static int g_rpc_buffer3[260];
103 static int g_rpc_buffer5[256];
104 static int g_rpc_buffer1[4];
105 static int g_rpc_buffer4[76];
106 static int g_rpc_buffer2[4];
107 static int g_rpc_buffer2[4];
108 #ifdef CDVD_VARIANT_OSD
109 static char g_extra_fsvrbuf[40256];
110 #endif
111 
112 static int cdvdfsv_checkdmastat(int trid)
113 {
114  int retval;
115  int state;
116 
117  if ( QueryIntrContext() )
118  return sceSifDmaStat(trid);
119  CpuSuspendIntr(&state);
120  retval = sceSifDmaStat(trid);
121  CpuResumeIntr(state);
122  return retval;
123 }
124 
125 static int cdvdfsv_cleanuprpc(void)
126 {
127  unsigned int i;
128 
129  sceSifRemoveRpc(&g_rpc_sdata1, &g_rpc_qdata1);
130  sceSifRemoveRpc(&g_rpc_sdata2, &g_rpc_qdata1);
131  sceSifRemoveRpc(&g_rpc_sdata3, &g_rpc_qdata1);
132  sceSifRemoveRpc(&g_rpc_sdata6, &g_rpc_qdata3);
133  sceSifRemoveRpc(&g_rpc_sdata4, &g_rpc_qdata2);
134  sceSifRemoveRpc(&g_rpc_sdata5, &g_rpc_qdata2);
135  sceSifRemoveRpcQueue(&g_rpc_qdata1);
136  sceSifRemoveRpcQueue(&g_rpc_qdata2);
137  sceSifRemoveRpcQueue(&g_rpc_qdata3);
138  g_cdvdfsv_nopocm = 1;
139  g_cdvdfsv_plbreak = 1;
140  for ( i = 0; i < (sizeof(g_cdvdfsv_thids) / sizeof(g_cdvdfsv_thids[0])); i += 1 )
141  {
142  TerminateThread(g_cdvdfsv_thids[i]);
143  DeleteThread(g_cdvdfsv_thids[i]);
144  }
145  return 1;
146 }
147 
148 int _start(int ac, char *av[], void *startaddr, ModuleInfo_t *mi)
149 {
150 #if 0
151  const u16 *LibraryEntryTable;
152 #endif
153  int state;
154 
155  (void)startaddr;
156 
157  if ( ac < 0 )
158  {
159  int error_code;
160 
161  // cppcheck-suppress knownConditionTrueFalse
162  if ( g_cdvdfsv_rpc5flg || g_cdvdfsv_rpc3flg || !cdvdfsv_cleanuprpc() )
163  {
164  return MODULE_REMOVABLE_END;
165  }
166  CpuSuspendIntr(&state);
167  error_code = ReleaseLibraryEntries(&_exp_cdvdfsv);
168  CpuResumeIntr(state);
169  if ( error_code && error_code != KE_LIBRARY_NOTFOUND )
170  {
171  KPRINTF("ReleaseLibraryEntries Error code %d\n", error_code);
172  return MODULE_REMOVABLE_END;
173  }
174  return MODULE_NO_RESIDENT_END;
175  }
176  if ( RegisterLibraryEntries(&_exp_cdvdfsv) )
177  {
178  return MODULE_NO_RESIDENT_END;
179  }
180  g_cdvdfsv_fsvrbuf[0] = (char *)sceGetFsvRbuf();
181 #ifdef CDVD_VARIANT_OSD
182  g_cdvdfsv_fsvrbuf[1] = &g_extra_fsvrbuf[0];
183 #endif
184  g_cdvdfsv_rtocbuf = g_cdvdfsv_fsvrbuf[0];
185  // g_cdvdfsv_sectors was set in XOSD variant
186  // g_cdvdfsv_r2retry_initval was set in XOSD variant
187  cdvdfsv_parseargs(ac, av);
188  cdvdfsv_init();
189 #if 0
190  CpuSuspendIntr(&state);
191  LibraryEntryTable = (u16 *)QueryLibraryEntryTable(&g_modload_libinfo);
192  CpuResumeIntr(state);
193  if ( !LibraryEntryTable || (*(LibraryEntryTable - 6) < 0x104) )
194  {
195  KPRINTF("Warning cdvdfsv.irx: Unload function can't be used.\n");
196  return MODULE_RESIDENT_END;
197  }
198  return MODULE_REMOVABLE_END;
199 #else
200  if ( mi && ((mi->newflags & 2) != 0) )
201  mi->newflags |= 0x10;
202  return MODULE_RESIDENT_END;
203 #endif
204 }
205 
206 static int cdvdfsv_init(void)
207 {
208  const int *BootMode;
209  iop_thread_t thparam;
210  int scres;
211 
212  BootMode = QueryBootMode(3);
213  if ( BootMode && (BootMode[1] & 2) )
214  {
215  PRINTF(" No cdvd driver \n");
216  return 1;
217  }
218  sceCdSC(0xFFFFFFF2, (int *)&g_cdvdman_istruct_ptr);
219  g_scmd_evfid = sceCdSC(0xFFFFFFE7, &scres);
220  thparam.attr = TH_C;
221  thparam.thread = cdvdfsv_main_th;
222  thparam.stacksize = 0x800;
223  thparam.option = 0;
224  thparam.priority = g_cdvdfsv_def_pri - 1;
225  g_cdvdfsv_thids[0] = CreateThread(&thparam);
226  if ( g_cdvdfsv_thids[0] <= 0 )
227  {
228  return 1;
229  }
230  StartThread(g_cdvdfsv_thids[0], 0);
231  return 0;
232 }
233 
234 static void cdvdfsv_main_th(void *arg)
235 {
236  iop_thread_t thparam1;
237  iop_thread_t thparam2;
238 
239  (void)arg;
240 
241  if ( !sceSifCheckInit() )
242  sceSifInit();
243  sceSifInitRpc(0);
244  PRINTF("cdvd driver module version 0.1.1 (C)SCEI\n");
245  thparam2.thread = cdvdfsv_rpc1_th;
246  thparam2.attr = TH_C;
247  thparam2.stacksize = 0x1900;
248  thparam2.option = 0;
249  thparam2.priority = g_cdvdfsv_def_pri;
250  g_cdvdfsv_thids[1] = CreateThread(&thparam2);
251  StartThread(g_cdvdfsv_thids[1], 0);
252  thparam1.attr = TH_C;
253  thparam1.thread = cdvdfsv_rpc2_th;
254  thparam1.stacksize = 0x1900;
255  thparam1.option = 0;
256  thparam1.priority = g_cdvdfsv_def_pri;
257  g_cdvdfsv_thids[2] = CreateThread(&thparam1);
258  StartThread(g_cdvdfsv_thids[2], 0);
259  thparam1.thread = cdvdfsv_rpc3_th;
260  thparam1.attr = TH_C;
261  thparam1.stacksize = 0x800;
262  thparam1.option = 0;
263  thparam1.priority = g_cdvdfsv_def_pri;
264  g_cdvdfsv_thids[3] = CreateThread(&thparam1);
265  StartThread(g_cdvdfsv_thids[3], 0);
266 #ifdef CDVD_VARIANT_OSD
267  thparam1.attr = TH_C;
268  thparam1.thread = cdvdfsv_rpc4_th;
269  thparam1.stacksize = 0x800;
270  thparam1.option = 0;
271  thparam1.priority = g_cdvdfsv_def_pri;
272  g_cdvdfsv_thids[4] = CreateThread(&thparam1);
273  StartThread(g_cdvdfsv_thids[4], 0);
274  thparam1.attr = TH_C;
275  thparam1.thread = cdvdfsv_rpc5_th;
276  thparam1.stacksize = 0x800;
277  thparam1.option = 0;
278  thparam1.priority = g_cdvdfsv_def_pri;
279  g_cdvdfsv_thids[5] = CreateThread(&thparam1);
280  StartThread(g_cdvdfsv_thids[5], 0);
281 #endif
282  cdvdfsv_poffloop();
283  ExitDeleteThread();
284 }
285 
286 int *cdvdfsv_dummyentry(int arg1)
287 {
288  VERBOSE_PRINTF(1, "Dummy Entry Called\n");
289  if ( arg1 != 128 )
290  return 0;
291  return &g_verbose_level;
292 }
293 
294 static void cdvdfsv_parseargs(int ac, char **av)
295 {
296  int i;
297 
298  g_cdvdfsv_def_pri = 81;
299  for ( i = 1; i < ac; i += 1 )
300  {
301  if ( !strncmp(av[i], "thpri=", 6) )
302  {
303  g_cdvdfsv_def_pri = strtol(av[i] + 6, 0, 10);
304  if ( (unsigned int)(g_cdvdfsv_def_pri - 9) >= 0x73 )
305  {
306  PRINTF("Cdvdfsv:thpri=%d Illegal priority\n", g_cdvdfsv_def_pri);
307  g_cdvdfsv_def_pri = 81;
308  }
309  if ( g_cdvdfsv_def_pri == 9 )
310  g_cdvdfsv_def_pri = 10;
311  }
312  }
313 }
314 
315 int sceCdChangeThreadPriority(int priority)
316 {
317  if ( (unsigned int)(priority - 9) >= 0x73 )
318  return -403;
319  if ( priority == 9 )
320  priority = 10;
321  // Unofficial: remove unused ReferThreadStatus
322  ChangeThreadPriority(TH_SELF, 8);
323  ChangeThreadPriority(g_cdvdfsv_thids[0], priority - 1);
324  ChangeThreadPriority(g_cdvdfsv_thids[2], priority);
325  ChangeThreadPriority(g_cdvdfsv_thids[1], priority);
326  ChangeThreadPriority(g_cdvdfsv_thids[3], priority);
327 #ifdef CDVD_VARIANT_OSD
328  ChangeThreadPriority(g_cdvdfsv_thids[4], priority);
329  ChangeThreadPriority(g_cdvdfsv_thids[5], priority);
330 #endif
331  return 0;
332 }
333 
334 static void *cbrpc_rpc1_cdinit(int fno, void *buffer, int length)
335 {
336  int scres_unused;
337 
338  (void)fno;
339  (void)length;
340 
341  VERBOSE_PRINTF(1, "sceCdInit call\n");
342  sceCdInit(((const cdvdfsv_rpc1_inpacket_t *)buffer)->m_mode);
343  g_cdvdfsv_spinctl = -1;
344  g_cdvdfsv_initres.m_debug_mode = g_verbose_level ? 254 : 0;
345  g_cdvdfsv_initres.m_cdvdfsv_ver = (u16)_irx_id.v;
346  g_cdvdfsv_initres.m_cdvdman_ver = sceCdSC(0xFFFFFFF7, &scres_unused);
347  VERBOSE_PRINTF(1, "sceCdInit end\n");
348  g_cdvdfsv_initres.m_retres = 1;
349  return (void *)&g_cdvdfsv_initres;
350 }
351 
352 static void cdvdfsv_rpc3_16_break(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
353 {
354  (void)inbuf;
355  (void)buflen;
356 
357  VERBOSE_PRINTF(1, "sceCdAbort call\n");
358  sceCdBreak();
359  outbuf->m_retres = 1;
360 }
361 
362 static void *cbrpc_rpc4_fscall(int fno, void *buffer, int length)
363 {
364  int scres;
365  int state;
367 
368  (void)fno;
369 
370  inbuf = buffer;
371  scres = 255;
372  sceCdSC(0xFFFFFFF6, &scres);
373  VERBOSE_PRINTF(1, "search file name %s call struct_siz %d\n", inbuf->m_pkt_sz12c.m_path, length);
374  switch ( length )
375  {
376  case sizeof(inbuf->m_pkt_sz12c):
377  g_cdvdfsv_srchres.m_retres =
378  sceCdLayerSearchFile(&(inbuf->m_pkt_sz12c.m_fp), inbuf->m_pkt_sz12c.m_path, inbuf->m_pkt_sz12c.m_layer);
379  g_cdvdfsv_fssdd.src = buffer;
380  g_cdvdfsv_fssdd.dest = (void *)inbuf->m_pkt_sz12c.m_eedest;
381  g_cdvdfsv_fssdd.size = sizeof(sceCdlFILE) + 4;
382  break;
383  case sizeof(inbuf->m_pkt_sz128):
384  PRINTF("sceCdSearchFile: Called from Not_Dual_layer Version.\n");
385  g_cdvdfsv_srchres.m_retres = sceCdSearchFile(&(inbuf->m_pkt_sz128.m_fp), inbuf->m_pkt_sz128.m_path);
386  g_cdvdfsv_fssdd.src = buffer;
387  g_cdvdfsv_fssdd.dest = (void *)inbuf->m_pkt_sz128.m_eedest;
388  g_cdvdfsv_fssdd.size = sizeof(sceCdlFILE) + 4;
389  break;
390  default:
391  PRINTF("Warning sceCdSearchFile: Called from Old liblary.\n");
392  g_cdvdfsv_srchres.m_retres = sceCdSearchFile(&(inbuf->m_pkt_sz124.m_fp), inbuf->m_pkt_sz124.m_path);
393  g_cdvdfsv_fssdd.src = buffer;
394  g_cdvdfsv_fssdd.dest = (void *)inbuf->m_pkt_sz124.m_eedest;
395  g_cdvdfsv_fssdd.size = sizeof(sceCdlFILE);
396  break;
397  }
398  g_cdvdfsv_fssdd.attr = 0;
399  while ( 1 )
400  {
401  int trid;
402 
403  CpuSuspendIntr(&state);
404  trid = sceSifSetDma(&g_cdvdfsv_fssdd, 1);
405  CpuResumeIntr(state);
406  if ( trid )
407  break;
408  DelayThread(500);
409  }
410  scres = 0;
411  sceCdSC(0xFFFFFFF6, &scres);
412  return (void *)&g_cdvdfsv_srchres;
413 }
414 
415 static unsigned int read_timeout_alarm_cb(void *userdata)
416 {
417  int read_timeout;
418  const iop_sys_clock_t *sys_clock;
419 
420  sys_clock = (const iop_sys_clock_t *)userdata;
421  read_timeout = sys_clock->lo / 0x9000;
422  KPRINTF("Read Time Out %d(msec)\n", read_timeout);
423  sceCdSC(0xFFFFFFEE, &read_timeout);
424  return !sceCdBreak();
425 }
426 
427 static void cdvdfsv_rpc5_0D_iopmread(const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf)
428 {
429  int cmd_error;
430  int trid;
431  int scres_unused;
432  int error_code;
433  int state;
434 
435  (void)buflen;
436  (void)outbuf;
437 
438  g_cdvdfsv_rderror = SCECdErREADCFR;
439  g_cdvdfsv_read_timeout.hi = 0;
440  g_cdvdfsv_read_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
441  g_cdvdfsv_iomrsdd.src = &g_cdvdfsv_readpos;
442  g_cdvdfsv_iomrsdd.size = sizeof(g_cdvdfsv_readpos);
443  g_cdvdfsv_iomrsdd.attr = 0;
444  g_cdvdfsv_iomrsdd.dest = (void *)inbuf->m_pkt_0D.m_eedest;
445  VERBOSE_PRINTF(
446  1,
447  "sceCdReadIOPm addr= 0x%08x sector= %d\n",
448  (unsigned int)(uiptr)(inbuf->m_pkt_0D.m_buf),
449  (int)(inbuf->m_pkt_0D.m_sectors));
450  cmd_error = sceCdRE(
451  inbuf->m_pkt_0D.m_lbn, inbuf->m_pkt_0D.m_sectors, inbuf->m_pkt_0D.m_buf, (sceCdRMode *)&inbuf->m_pkt_0D.m_mode);
452  while ( sceCdSync(1) )
453  {
454  g_cdvdfsv_readpos = sceCdGetReadPos();
455  while ( 1 )
456  {
457  CpuSuspendIntr(&state);
458  trid = sceSifSetDma(&g_cdvdfsv_iomrsdd, 1);
459  CpuResumeIntr(state);
460  if ( trid )
461  break;
462  DelayThread(500);
463  }
464  DelayThread(8000);
465  while ( cdvdfsv_checkdmastat(trid) >= 0 )
466  ;
467  }
468  error_code = sceCdGetError();
469  if ( error_code != SCECdErNO || !cmd_error )
470  {
471  if ( !cmd_error )
472  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
473  VERBOSE_PRINTF(1, "Read error code %x cmd error %d\n", error_code, cmd_error);
474  }
475 }
476 
477 static u8 cdvdfsv_syncdec(int flag, int xorkey, int arg2, u8 data)
478 {
479  return flag ? (((data << (arg2 % 8)) | (data >> (8 - arg2 % 8))) ^ xorkey) : data;
480 }
481 
482 static int cdvdfsv_cb_read(void)
483 {
484  iSetEventFlag(g_cdvdman_intr_evfid, 0x20);
485  return 0;
486 }
487 
488 static int cdvdfsv_checksid(u32 lsn, u32 sectors, u32 ps2dvd, void *buf, int decflag, int decshift, u32 *syncdec_mask)
489 {
490  int scret;
491  u32 i;
492  u32 readlsn;
493  int syncdec;
494  u8 syncdec_4;
495  sceCdlLOCCD rpos;
496  int scres;
497  int ipi_emu;
498 
499  ipi_emu = 0;
500  *syncdec_mask = 0;
501  scret = decflag ? sceCdSC(0xFFFFFFE8, &scres) : 0;
502  syncdec_4 = 0;
503  for ( i = 0; i < sectors; i += 1 )
504  {
505  if ( ps2dvd )
506  {
507  syncdec = cdvdfsv_syncdec(decflag, scret, decshift, ((u8 *)buf + (i * 0x810))[3]);
508  syncdec += cdvdfsv_syncdec(decflag, scret, decshift, ((u8 *)buf + (i * 0x810))[2]) << 8;
509  syncdec += cdvdfsv_syncdec(decflag, scret, decshift, ((u8 *)buf + (i * 0x810))[1]) << 16;
510  syncdec_4 = cdvdfsv_syncdec(decflag, scret, decshift, ((u8 *)buf + (i * 0x810))[0]);
511  if ( i && !*syncdec_mask )
512  {
513  ipi_emu = syncdec_4 & 0xC;
514  }
515  else if ( !i )
516  {
517  *syncdec_mask = syncdec_4 & 0xC;
518  }
519  readlsn = syncdec - 0x30000;
520  if (
521  g_cdvdman_istruct_ptr->m_opo_or_para && (lsn + i) >= g_cdvdman_istruct_ptr->m_layer_1_lsn
522  && g_cdvdman_istruct_ptr->m_opo_or_para == 1 )
523  {
524  readlsn += g_cdvdman_istruct_ptr->m_layer_1_lsn;
525  }
526  }
527  else
528  {
529  rpos.minute = cdvdfsv_syncdec(decflag, scret, decshift, ((u8 *)buf + (i * 0x924))[0]);
530  rpos.second = cdvdfsv_syncdec(decflag, scret, decshift, ((u8 *)buf + (i * 0x924))[1]);
531  rpos.sector = cdvdfsv_syncdec(decflag, scret, decshift, ((u8 *)buf + (i * 0x924))[2]);
532  readlsn = sceCdPosToInt(&rpos);
533  }
534  if ( readlsn != (lsn + i) || ipi_emu )
535  {
536  // The following printf was modified for ioprp300x
537  VERBOSE_PRINTF(
538  1,
539  "Read_EE Sector_ID error lsn= %d readlsn= %d layer= %d layer1_start %d ipi_emu %d\n",
540  (int)(lsn + i),
541  (int)readlsn,
542  (syncdec_4 & 1),
543  (int)(g_cdvdman_istruct_ptr->m_layer_1_lsn),
544  ipi_emu);
545  return 0;
546  }
547  }
548  if ( *syncdec_mask )
549  {
550  VERBOSE_PRINTF(
551  1, "Read_EE NO_Data_zone error lsn= %d layer= %d SecID %02x\n", (int)lsn, (syncdec_4 & 1), (int)(*syncdec_mask));
552  }
553  return 1;
554 }
555 
556 static int readproc2(
557  u32 lsn,
558  u32 nsec,
559  sceCdRMode *mode,
560  u32 sector_size_selection,
561  int do_multi_retries,
562  int enable_dec_shift,
563  int dec_shift,
564  char *ee_addr,
565  int fssift,
566  int secsize,
567  int dmasize,
568  SifDmaTransfer_t *post_dmat)
569 {
570  unsigned int i;
571  int csec;
572  int read_res_tmp;
573  int trid;
574  int j;
575  int size_2;
576  int sector_sizes[2];
577  int error_code;
578  int scres_unused;
579  int state;
580  u32 syncdec_mask;
581  u32 chcr;
582  int error_code_tmp;
583  char *ee_addr_tmp;
584  int dmasize_tmp;
585  int csec_comm;
586  int nsec_div_cdvdfsv_sectors;
587  int retry_flag1;
588  int retry_flag2;
589  int sector_size;
590 
591  error_code_tmp = SCECdErNO;
592  sector_sizes[0] = 0x924;
593  sector_sizes[1] = 0x810;
594  g_cdvdfsv_read_timeout.hi = 0;
595  g_cdvdfsv_read_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
596  g_cdvdfsv_rderror = SCECdErREADCF;
597  g_cdvdfsv_r2retry = 0;
598  g_cdvdfsv_r2count = 0;
599  if ( secsize != 0x924 && !fssift )
600  {
601  for ( i = 0; i < (unsigned int)g_cdvdfsv_sectors; i += 1 )
602  {
603  g_cdvdfsv_multi_dmat[i].attr = 0;
604  g_cdvdfsv_multi_dmat[i].size = secsize;
605  }
606  }
607  // The following Kprintf was added for ioprp300x
608  VERBOSE_KPRINTF(1, "lsn= %d nsec= %d ee_addr= %08x fssift= %d secsize= %d\n", lsn, nsec, ee_addr, fssift, secsize);
609  sector_size = sector_sizes[sector_size_selection];
610  while ( 1 )
611  {
612  while ( 1 )
613  {
614  csec = (nsec <= (u32)g_cdvdfsv_sectors) ? nsec : (u32)g_cdvdfsv_sectors;
615 #ifdef CDVD_VARIANT_OSD
616  if ( !g_cdvdfsv_sectors )
617  __builtin_trap();
618 #endif
619  nsec_div_cdvdfsv_sectors = (nsec / g_cdvdfsv_sectors) + (!!((nsec & 0xF)));
620  retry_flag2 = 0;
621  ee_addr_tmp = ee_addr;
622  dmasize_tmp = dmasize;
623  g_cdvdman_istruct_ptr->m_dec_mode_set = 1;
624  g_cdvdman_istruct_ptr->m_dec_mode_last_set = 0;
625  CpuSuspendIntr(&state);
626  if ( enable_dec_shift )
627  {
628  g_cdvdman_istruct_ptr->m_dec_shift = dec_shift;
629  g_cdvdman_istruct_ptr->m_dec_state = 2;
630  }
631  if ( g_cdvdfsv_r2retry )
632  {
633  VERBOSE_KPRINTF(1, "Rty_Read\n");
634  read_res_tmp = (sector_size_selection ? sceCdRV : sceCdRead0)(
635  (lsn >= (u32)(6 * g_cdvdfsv_sectors)) ? (lsn - g_cdvdfsv_sectors * g_cdvdfsv_r2retry) :
636  (lsn + g_cdvdfsv_sectors * g_cdvdfsv_r2retry + 6 * g_cdvdfsv_sectors),
637  g_cdvdfsv_sectors,
638  &g_cdvdfsv_rtocbuf[0x1248],
639  mode,
640  0,
641  0);
642  CpuResumeIntr(state);
643  }
644  else
645  {
646  read_res_tmp = (sector_size_selection ? sceCdRV : sceCdRead0)(
647  lsn, nsec, &g_cdvdfsv_rtocbuf[0x1248], mode, csec, cdvdfsv_cb_read);
648  CpuResumeIntr(state);
649  if ( read_res_tmp )
650  {
651  SetAlarm(&g_cdvdfsv_read_timeout, read_timeout_alarm_cb, &g_cdvdfsv_read_timeout);
652  csec_comm = 0;
653  retry_flag1 = 0;
654  break;
655  }
656  }
657  if ( !read_res_tmp )
658  {
659  g_cdvdman_istruct_ptr->m_dec_state = 0;
660  g_cdvdman_istruct_ptr->m_dec_mode_set = 0;
661  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
662  return 0;
663  }
664  sceCdSync(3);
665  g_cdvdfsv_r2retry -= 1;
666  }
667  for ( i = 0; (int)i < nsec_div_cdvdfsv_sectors; i += 1 )
668  {
669  sceCdSync(32);
670  if ( g_cdvdman_istruct_ptr->m_dec_mode_last_set )
671  break;
672  if ( sceCdGetError() == SCECdErNO )
673  {
674  if ( cdvdfsv_checksid(
675  lsn + csec_comm,
676  csec,
677  sector_size_selection,
678  &g_cdvdfsv_rtocbuf[0x1248],
679  enable_dec_shift,
680  dec_shift,
681  &syncdec_mask) )
682  {
683  if ( do_multi_retries && syncdec_mask && !i )
684  {
685  retry_flag1 = 1;
686  error_code_tmp = SCECdErIPI;
687  }
688  }
689  else if ( do_multi_retries )
690  {
691  retry_flag2 = 1;
692  retry_flag1 = 1;
693  }
694  if ( retry_flag1 || g_cdvdfsv_r2retry )
695  {
696  }
697  else if ( secsize == 0x924 && !sector_size_selection )
698  {
699  if ( fssift )
700  {
701  if ( i )
702  {
703  optimized_memcpy(&g_cdvdfsv_rtocbuf[secsize], &g_cdvdfsv_rtocbuf[fssift], secsize - fssift);
704  optimized_memcpy(g_cdvdfsv_rtocbuf, &g_cdvdfsv_rtocbuf[secsize + secsize * csec], secsize);
705  g_cdvdfsv_rdp2sdd.size =
706  ((int)i == nsec_div_cdvdfsv_sectors - 1) ? dmasize_tmp : (secsize * (csec - 1) + fssift);
707  optimized_memcpy(
708  &g_cdvdfsv_rtocbuf[secsize + secsize - fssift],
709  &g_cdvdfsv_rtocbuf[secsize * 2],
710  g_cdvdfsv_rdp2sdd.size);
711  }
712  else
713  {
714  optimized_memcpy(g_cdvdfsv_rtocbuf, &g_cdvdfsv_rtocbuf[secsize * 2 + secsize * (csec - 1)], secsize);
715  g_cdvdfsv_rdp2sdd.size = ((int)i == nsec_div_cdvdfsv_sectors - 1) ? dmasize_tmp : (secsize * (csec - 1));
716  optimized_memcpy(
717  &g_cdvdfsv_rtocbuf[secsize], &g_cdvdfsv_rtocbuf[secsize * 2 + fssift], g_cdvdfsv_rdp2sdd.size);
718  }
719  g_cdvdfsv_rdp2sdd.src = &g_cdvdfsv_rtocbuf[secsize];
720  }
721  else
722  {
723  g_cdvdfsv_rdp2sdd.src = &g_cdvdfsv_rtocbuf[secsize * 2];
724  g_cdvdfsv_rdp2sdd.size = secsize * csec;
725  }
726  g_cdvdfsv_rdp2sdd.attr = 0;
727  g_cdvdfsv_rdp2sdd.dest = ee_addr_tmp;
728  ee_addr_tmp += g_cdvdfsv_rdp2sdd.size;
729  dmasize_tmp -= g_cdvdfsv_rdp2sdd.size;
730  while ( 1 )
731  {
732  CpuSuspendIntr(&state);
733  trid = sceSifSetDma(&g_cdvdfsv_rdp2sdd, 1);
734  CpuResumeIntr(state);
735  if ( trid )
736  break;
737  DelayThread(500);
738  }
739  while ( cdvdfsv_checkdmastat(trid) >= 0 )
740  ;
741  }
742  else if ( !fssift )
743  {
744  for ( j = 0; j < csec; j += 1 )
745  {
746  g_cdvdfsv_multi_dmat[j].dest = &ee_addr[(csec_comm + j) * secsize];
747  g_cdvdfsv_multi_dmat[j].src = &g_cdvdfsv_rtocbuf[0x1248 + (j * sector_size) + 12];
748  }
749  while ( 1 )
750  {
751  CpuSuspendIntr(&state);
752  trid = sceSifSetDma(g_cdvdfsv_multi_dmat, csec);
753  CpuResumeIntr(state);
754  if ( trid )
755  break;
756  DelayThread(500);
757  }
758  while ( cdvdfsv_checkdmastat(trid) >= 0 )
759  ;
760  }
761  else
762  {
763  size_2 = ((int)i != nsec_div_cdvdfsv_sectors - 1) ? fssift : secsize;
764  g_cdvdfsv_rdp2sdd.size = dmasize_tmp;
765  if ( i )
766  {
767  optimized_memcpy(&g_cdvdfsv_rtocbuf[0x924], &g_cdvdfsv_rtocbuf[fssift + 12], secsize - fssift);
768  optimized_memcpy(g_cdvdfsv_rtocbuf, &g_cdvdfsv_rtocbuf[0x1248 + (csec - 1) * sector_size], sector_size);
769  for ( j = 0; j < csec - 1; j += 1 )
770  {
771  optimized_memcpy(
772  &g_cdvdfsv_rtocbuf[0x924 + secsize - fssift + (j * secsize)],
773  &g_cdvdfsv_rtocbuf[0x1248 + 12 + (j * sector_size)],
774  secsize);
775  }
776  optimized_memcpy(
777  &g_cdvdfsv_rtocbuf[0x924 + secsize - fssift + ((csec - 1) * secsize)],
778  &g_cdvdfsv_rtocbuf[0x1248 + 12 + ((csec - 1) * sector_size)],
779  size_2);
780  if ( (int)i != nsec_div_cdvdfsv_sectors - 1 )
781  {
782  g_cdvdfsv_rdp2sdd.size = secsize * csec;
783  }
784  }
785  else
786  {
787  optimized_memcpy(g_cdvdfsv_rtocbuf, &g_cdvdfsv_rtocbuf[0x1248 + (csec - 1) * sector_size], sector_size);
788  optimized_memcpy(&g_cdvdfsv_rtocbuf[0x924], &g_cdvdfsv_rtocbuf[0x1248 + fssift + 12], secsize - fssift);
789  for ( j = 0; j < csec - 2; j += 1 )
790  {
791  optimized_memcpy(
792  &g_cdvdfsv_rtocbuf[0x924 + secsize - fssift + (j * secsize)],
793  &g_cdvdfsv_rtocbuf[0x1248 + sector_size + 12 + (j * sector_size)],
794  secsize);
795  }
796  optimized_memcpy(
797  &g_cdvdfsv_rtocbuf[0x924 + secsize - fssift + ((csec - 2) * secsize)],
798  &g_cdvdfsv_rtocbuf[0x1248 + sector_size + 12 + ((csec - 2) * sector_size)],
799  size_2);
800  if ( (int)i != nsec_div_cdvdfsv_sectors - 1 )
801  {
802  g_cdvdfsv_rdp2sdd.size = secsize * (csec - 1);
803  }
804  }
805  g_cdvdfsv_rdp2sdd.src = &g_cdvdfsv_rtocbuf[0x924];
806  g_cdvdfsv_rdp2sdd.attr = 0;
807  g_cdvdfsv_rdp2sdd.dest = ee_addr_tmp;
808  ee_addr_tmp += g_cdvdfsv_rdp2sdd.size;
809  dmasize_tmp -= g_cdvdfsv_rdp2sdd.size;
810  while ( 1 )
811  {
812  CpuSuspendIntr(&state);
813  trid = sceSifSetDma(&g_cdvdfsv_rdp2sdd, 1);
814  CpuResumeIntr(state);
815  if ( trid )
816  break;
817  DelayThread(500);
818  }
819  while ( cdvdfsv_checkdmastat(trid) >= 0 )
820  ;
821  }
822  }
823  else
824  {
825  retry_flag1 = 1;
826  }
827  CpuSuspendIntr(&state);
828  if ( (int)i == nsec_div_cdvdfsv_sectors - 1 )
829  {
830  DisableIntr(IOP_IRQ_DMA_CDVD, (int *)&chcr);
831  }
832  else
833  {
834  csec_comm += csec;
835  csec = ((unsigned int)csec > nsec - (unsigned int)csec_comm) ? (nsec - (unsigned int)csec_comm) :
836  (unsigned int)g_cdvdfsv_sectors;
837  ClearEventFlag(g_cdvdman_intr_evfid, ~0x20);
838  dmac_ch_set_chcr(3, 0);
839  dmac_ch_get_chcr(3);
840  g_cdvdman_istruct_ptr->m_dma3_param.m_dma3_maddress = &g_cdvdfsv_rtocbuf[0x1248];
841  dmac_ch_set_madr(3, (uiptr)(&g_cdvdfsv_rtocbuf[0x1248]));
842  dmac_ch_set_bcr(
843  3,
844  g_cdvdman_istruct_ptr->m_dma3_param.m_dma3_blkwords
845  | ((g_cdvdman_istruct_ptr->m_dma3_param.m_dma3_blkcount * csec) << 16));
846  dmac_ch_set_chcr(3, 0x41000200);
847  chcr = dmac_ch_get_chcr(3);
848  if ( post_dmat )
849  {
850  g_cdvdfsv_readpos += secsize * csec;
851  sceSifSetDma(post_dmat, 1);
852  }
853  }
854  CpuResumeIntr(state);
855  }
856  sceCdSync(5);
857  CancelAlarm(read_timeout_alarm_cb, &g_cdvdfsv_read_timeout);
858  g_cdvdman_istruct_ptr->m_dec_mode_set = 0;
859  g_cdvdman_istruct_ptr->m_dec_state = 0;
860  error_code = sceCdGetError();
861  if ( (u16)g_cdvdman_istruct_ptr->m_dec_mode_last_set )
862  {
863  retry_flag2 = 1;
864  error_code = SCECdErNO;
865  mode->spindlctrl = 16;
866  }
867  if ( error_code != SCECdErNO || g_cdvdfsv_r2count >= 5 )
868  break;
869  if ( !retry_flag2 )
870  {
871  if ( error_code_tmp == SCECdErNO )
872  return 1;
873  sceCdSC(0xFFFFFFFE, &error_code_tmp);
874  VERBOSE_KPRINTF(1, "secid_chk_ee_trns lsn %d nsec %d IPI Err\n", lsn, nsec);
875  return 0;
876  }
877  if ( !g_cdvdfsv_r2retry )
878  {
879  g_cdvdfsv_r2count += 1;
880  VERBOSE_PRINTF(1, "Read_CD/DVD-ROM Error Recover Start\n");
881  g_cdvdfsv_r2retry = g_cdvdfsv_r2retry_initval;
882  }
883  }
884  if ( g_cdvdfsv_r2count >= 5 && error_code == SCECdErNO )
885  {
886  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
887  }
888  return 0;
889 }
890 
891 static int readproc1(
892  unsigned int lsn,
893  u32 nsec,
894  void *retptr,
895  sceCdRMode *rmode,
896  int ps2dvd,
897  int enable_retries,
898  int dec_shift_enable,
899  int dec_shift_value)
900 {
901  int scres_unused;
902  int state;
903  u32 syncdec_mask;
904  int error_code_tmp;
905 
906  error_code_tmp = SCECdErNO;
907  g_cdvdfsv_read_timeout.hi = 0;
908  g_cdvdfsv_read_timeout.lo = 0x9000 * sceCdSC(0xFFFFFFF1, &scres_unused);
909  g_cdvdfsv_rderror = SCECdErREADCF;
910  g_cdvdfsv_sid_err_recover_cnt = 0;
911  g_cdvdfsv_err_count = 0;
912  while ( 1 )
913  {
914  int cmd_error;
915  int error_code;
916 
917  CpuSuspendIntr(&state);
918  if ( dec_shift_enable )
919  {
920  g_cdvdman_istruct_ptr->m_dec_shift = dec_shift_value;
921  g_cdvdman_istruct_ptr->m_dec_state = 2;
922  }
923  cmd_error = (ps2dvd ? sceCdRV : sceCdRead0)(
924  (lsn >= 0x30) ? (lsn - 0x10 * g_cdvdfsv_sid_err_recover_cnt) : (lsn + 0x10 * g_cdvdfsv_sid_err_recover_cnt),
925  nsec,
926  retptr,
927  rmode,
928  0,
929  0);
930  CpuResumeIntr(state);
931  if ( cmd_error )
932  SetAlarm(&g_cdvdfsv_read_timeout, read_timeout_alarm_cb, &g_cdvdfsv_read_timeout);
933  sceCdSync(5);
934  CancelAlarm(read_timeout_alarm_cb, &g_cdvdfsv_read_timeout);
935  g_cdvdman_istruct_ptr->m_dec_state = 0;
936  error_code = sceCdGetError();
937  if ( error_code != SCECdErNO || !cmd_error || g_cdvdfsv_err_count >= 5 )
938  {
939  VERBOSE_KPRINTF(1, "Read error error code %x cmd error %d\n", error_code, cmd_error);
940  if ( (!cmd_error || g_cdvdfsv_err_count >= 5) && error_code == SCECdErNO )
941  {
942  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
943  }
944  return 0;
945  }
946  if ( cdvdfsv_checksid(lsn, nsec, ps2dvd, retptr, dec_shift_enable, dec_shift_value, &syncdec_mask) )
947  {
948  if ( enable_retries && syncdec_mask )
949  error_code_tmp = SCECdErIPI;
950  break;
951  }
952  if ( !enable_retries )
953  break;
954  if ( !g_cdvdfsv_sid_err_recover_cnt )
955  {
956  g_cdvdfsv_err_count += 1;
957  VERBOSE_PRINTF(1, "Read_CD/DVD-ROM Sector_ID Error Recover Start\n");
958  g_cdvdfsv_sid_err_recover_cnt = 3;
959  }
960  g_cdvdfsv_sid_err_recover_cnt -= 1;
961  }
962  if ( error_code_tmp == SCECdErNO )
963  return 1;
964  sceCdSC(0xFFFFFFFE, &error_code_tmp);
965  VERBOSE_KPRINTF(1, "secid_chk lsn %d nsec %d IPI Err\n", lsn, nsec);
966  return 0;
967 }
968 
969 static void cdvdfsv_rpc5_01_readee(
970  const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf, u32 ps2dvd, int sync, int decflag)
971 {
972  unsigned int secsize;
973  unsigned int bsize;
974  unsigned int bsize_tmp;
975  unsigned int psize;
976  unsigned int ssize;
977  unsigned int i;
978  int sizestuff;
979  u32 needed_offset;
980  int sector_sizes[2];
981  int scres_unused;
982  int lsndualchg_res;
983  int state;
984  unsigned int buf_offs_sum;
985  unsigned int paddr;
986  int saddr;
987  int datapattern;
988  unsigned int len2_plus_sec2;
989  int trid;
990  int decval;
991  int early_break;
992 
993  (void)buflen;
994 
995  early_break = 0;
996  trid = 0;
997  buf_offs_sum = 0;
998  sector_sizes[0] = 0x924;
999  sector_sizes[1] = 0x810;
1000  g_cdvdfsv_rmodeee = inbuf->m_pkt_01.m_rmodeee;
1001  lsndualchg_res = inbuf->m_pkt_01.m_lbn;
1002  decval = decflag ? inbuf->m_pkt_01.m_decval : 0;
1003  g_cdvdfsv_eerpsdd.src = &g_cdvdfsv_readpos;
1004  g_cdvdfsv_eerpsdd.size = sizeof(g_cdvdfsv_readpos);
1005  g_cdvdfsv_eerpsdd.attr = 0;
1006  g_cdvdfsv_eerpsdd.dest = (void *)inbuf->m_pkt_01.m_eedest;
1007  if ( ps2dvd )
1008  {
1009  if ( !sceCdSC(0xFFFFFFEA, &scres_unused) )
1010  {
1011  g_cdvdfsv_rderror = SCECdErREADCFR;
1012  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
1013  bsize = 0;
1014  psize = 0;
1015  ssize = 0;
1016  saddr = 0;
1017  paddr = 0;
1018  early_break = 1;
1019  }
1020  else
1021  {
1022  lsndualchg_res = sceCdSC(0xFFFFFFE9, &lsndualchg_res);
1023  secsize = 0x800;
1024  datapattern = SCECdSecS2048;
1025  g_cdvdfsv_rmodeee.datapattern = SCECdSecS2048;
1026  }
1027  }
1028  else
1029  {
1030  datapattern = g_cdvdfsv_rmodeee.datapattern;
1031  switch ( datapattern )
1032  {
1033  case SCECdSecS2328:
1034  secsize = 0x918;
1035  break;
1036  case SCECdSecS2340:
1037  secsize = 0x924;
1038  break;
1039  case SCECdSecS2048:
1040  default:
1041  secsize = 0x800;
1042  break;
1043  }
1044  g_cdvdfsv_rmodeee.datapattern = SCECdSecS2340;
1045  }
1046  len2_plus_sec2 = lsndualchg_res + inbuf->m_pkt_01.m_sectors;
1047  if ( !early_break )
1048  {
1049  int all_sec_bytes;
1050 
1051  all_sec_bytes = secsize * inbuf->m_pkt_01.m_sectors;
1052  if ( g_cdvdfsv_spinctl != -1 )
1053  g_cdvdfsv_rmodeee.spindlctrl = g_cdvdfsv_spinctl;
1054  paddr = inbuf->m_pkt_01.m_paddr;
1055  saddr = (paddr + all_sec_bytes) & ~0x3F;
1056  psize = ((paddr & 0x3F)) ? ((paddr & ~0x3F) - (paddr - 0x40)) : 0;
1057  bsize = saddr - (paddr + psize);
1058  ssize = paddr + all_sec_bytes - saddr;
1059  VERBOSE_KPRINTF(1, "CD/DVD-ROM lsn= %d sec= %d\n", lsndualchg_res, inbuf->m_pkt_01.m_sectors);
1060  VERBOSE_KPRINTF(1, "f psize= %d bsize= %d ssize= %d\n", psize, bsize, ssize);
1061  }
1062  if ( psize )
1063  {
1064  u32 sectors;
1065 
1066  sectors = (len2_plus_sec2 < lsndualchg_res + buf_offs_sum / secsize + 2) ? 1 : 2;
1067  VERBOSE_PRINTF(
1068  1,
1069  "0 CD_READ LBN= %d sectors= %d all= %d\n",
1070  (int)(lsndualchg_res + buf_offs_sum / secsize),
1071  (int)sectors,
1072  (int)inbuf->m_pkt_01.m_sectors);
1073  if ( !readproc1(
1074  lsndualchg_res + buf_offs_sum / secsize,
1075  sectors,
1076  g_cdvdfsv_rtocbuf,
1077  &g_cdvdfsv_rmodeee,
1078  ps2dvd,
1079  sync,
1080  decflag,
1081  decval) )
1082  {
1083  ssize = 0;
1084  psize = 0;
1085  bsize = 0;
1086  }
1087  else
1088  {
1089  if ( datapattern != SCECdSecS2340 || ps2dvd )
1090  {
1091  int rtoc_ind;
1092 
1093  rtoc_ind = 12;
1094  for ( i = 0; i < psize; i += 1 )
1095  {
1096  rtoc_ind += (i && !(i % secsize)) ? (sector_sizes[ps2dvd] - secsize) : 0;
1097  g_cdvdfsv_eereadx.m_pbuf1[i] = g_cdvdfsv_rtocbuf[rtoc_ind + i];
1098  }
1099  }
1100  else
1101  {
1102  for ( i = 0; i < psize; i += 1 )
1103  g_cdvdfsv_eereadx.m_pbuf1[i] = g_cdvdfsv_rtocbuf[i];
1104  }
1105  buf_offs_sum += psize;
1106  }
1107  }
1108  bsize_tmp = bsize;
1109  for ( i = 0; i < bsize; i += sizestuff )
1110  {
1111  u32 offs_sector_only;
1112 
1113  bsize_tmp = bsize - i;
1114  if ( g_cdvdfsv_spinctl != -1 )
1115  g_cdvdfsv_rmodeee.spindlctrl = g_cdvdfsv_spinctl;
1116  offs_sector_only = lsndualchg_res + buf_offs_sum / secsize;
1117  if ( (unsigned int)(secsize << 6) >= bsize_tmp )
1118  {
1119  needed_offset = (bsize_tmp / secsize) + (!!(bsize_tmp % secsize));
1120  sizestuff = bsize_tmp;
1121  }
1122  else
1123  {
1124  needed_offset = (((offs_sector_only & 0xF)) && (!(secsize & 0xF))) ? (0x10 - (offs_sector_only & 0xF)) : 0x40;
1125  sizestuff = secsize * needed_offset;
1126  }
1127  needed_offset += !!((buf_offs_sum + i) % secsize);
1128  if ( len2_plus_sec2 < offs_sector_only + needed_offset )
1129  needed_offset = len2_plus_sec2 - (lsndualchg_res + (buf_offs_sum + i) / secsize);
1130  g_cdvdfsv_readpos = buf_offs_sum + i;
1131  if ( !readproc2(
1132  offs_sector_only,
1133  needed_offset,
1134  &g_cdvdfsv_rmodeee,
1135  ps2dvd,
1136  sync,
1137  decflag,
1138  decval,
1139  (char *)(inbuf->m_pkt_01.m_paddr + psize) + i,
1140  (buf_offs_sum + i) % secsize,
1141  secsize,
1142  sizestuff,
1143  &g_cdvdfsv_eerpsdd) )
1144  {
1145  bsize_tmp = 0;
1146  early_break = 1;
1147  break;
1148  }
1149  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1150  ;
1151  CpuSuspendIntr(&state);
1152  trid = sceSifSetDma(&g_cdvdfsv_eerpsdd, 1);
1153  CpuResumeIntr(state);
1154  }
1155  buf_offs_sum += i;
1156  bsize = bsize_tmp;
1157  if ( !early_break && ssize )
1158  {
1159  u32 sectors_1;
1160  unsigned int buf_offs_sum_bytes_in_sector;
1161 
1162  buf_offs_sum_bytes_in_sector = buf_offs_sum % secsize;
1163  sectors_1 = (len2_plus_sec2 < lsndualchg_res + buf_offs_sum / secsize + 2) ? 1 : 2;
1164  VERBOSE_PRINTF(
1165  1, "2 CD_READ LBN= %d sectors= %d\n", (int)(lsndualchg_res + buf_offs_sum / secsize), (int)sectors_1);
1166  if ( !readproc1(
1167  lsndualchg_res + buf_offs_sum / secsize,
1168  sectors_1,
1169  g_cdvdfsv_rtocbuf,
1170  &g_cdvdfsv_rmodeee,
1171  ps2dvd,
1172  sync,
1173  decflag,
1174  decval) )
1175  {
1176  bsize = 0;
1177  }
1178  else
1179  {
1180  if ( datapattern != SCECdSecS2340 || ps2dvd )
1181  {
1182  int i2_offs;
1183 
1184  i2_offs = 12;
1185  for ( i = 0; i < ssize; i += 1 )
1186  {
1187  i2_offs +=
1188  ((i + buf_offs_sum_bytes_in_sector)
1189  && (i % secsize) == (secsize - (buf_offs_sum_bytes_in_sector ? buf_offs_sum_bytes_in_sector : secsize))) ?
1190  (sector_sizes[ps2dvd] - secsize) :
1191  0;
1192  g_cdvdfsv_eereadx.m_pbuf2[i] = g_cdvdfsv_rtocbuf[buf_offs_sum_bytes_in_sector + i2_offs + i];
1193  }
1194  }
1195  else
1196  {
1197  for ( i = 0; i < ssize; i += 1 )
1198  g_cdvdfsv_eereadx.m_pbuf2[i] = g_cdvdfsv_rtocbuf[buf_offs_sum_bytes_in_sector + i];
1199  }
1200  buf_offs_sum += ssize;
1201  }
1202  }
1203  g_cdvdfsv_eereadx.m_b1len = psize;
1204  g_cdvdfsv_eereadx.m_b2len = ssize;
1205  g_cdvdfsv_eereadx.m_b1dst = paddr;
1206  g_cdvdfsv_eereadx.m_b2dst = saddr;
1207  VERBOSE_PRINTF(
1208  1, "b psize= %d paddr= %08x bsize= %d ssize= %d saddr %08x\n", (int)psize, paddr, (int)bsize, (int)ssize, saddr);
1209  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1210  ;
1211  g_cdvdfsv_datasdd.src = &g_cdvdfsv_eereadx;
1212  g_cdvdfsv_datasdd.size = sizeof(g_cdvdfsv_eereadx);
1213  g_cdvdfsv_datasdd.attr = 0;
1214  g_cdvdfsv_readpos = buf_offs_sum;
1215  g_cdvdfsv_datasdd.dest = (void *)inbuf->m_pkt_01.m_eeremaindest;
1216  while ( 1 )
1217  {
1218  CpuSuspendIntr(&state);
1219  trid = sceSifSetDma(&g_cdvdfsv_datasdd, 1);
1220  sceSifSetDma(&g_cdvdfsv_eerpsdd, 1);
1221  CpuResumeIntr(state);
1222  if ( trid )
1223  break;
1224  DelayThread(500);
1225  }
1226  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1227  ;
1228  g_cdvdfsv_spinctl = -1;
1229  VERBOSE_PRINTF(1, "read end\n");
1230  outbuf->m_retres = buf_offs_sum;
1231 }
1232 
1233 static int
1234 cdvdfsv_chreadee(int secoffs, int seccount, char *ee_addr, const sceCdRMode *in_rmode, u32 disktype_14, int sync)
1235 {
1236  unsigned int secsize;
1237  unsigned int i;
1238  int readsize_bytes;
1239  sceCdRMode rmode;
1240  int scres_unused;
1241  int lsndualchg_res;
1242 
1243  lsndualchg_res = secoffs;
1244  rmode = *in_rmode;
1245  if ( disktype_14 )
1246  {
1247  if ( !sceCdSC(0xFFFFFFEA, &scres_unused) )
1248  {
1249  g_cdvdfsv_rderror = SCECdErREADCFR;
1250  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
1251  return 1;
1252  }
1253  secsize = 0x800;
1254  lsndualchg_res = sceCdSC(0xFFFFFFE9, &lsndualchg_res);
1255  rmode.datapattern = SCECdSecS2048;
1256  }
1257  else
1258  {
1259  switch ( rmode.datapattern )
1260  {
1261  case SCECdSecS2328:
1262  secsize = 0x918;
1263  break;
1264  case SCECdSecS2340:
1265  secsize = 0x924;
1266  break;
1267  case SCECdSecS2048:
1268  default:
1269  secsize = 0x800;
1270  break;
1271  }
1272  rmode.datapattern = SCECdSecS2340;
1273  }
1274  for ( i = 0; i < (unsigned int)(secsize * seccount); i += readsize_bytes )
1275  {
1276  unsigned int bytescount;
1277  int sectors_partial;
1278  int bytescount_in_sectors;
1279 
1280  bytescount = (unsigned int)(secsize * seccount) - i;
1281  sectors_partial = (lsndualchg_res + i / secsize) & 0xF;
1282  bytescount_in_sectors = 0x10;
1283  readsize_bytes = secsize * bytescount_in_sectors;
1284  if ( (unsigned int)readsize_bytes >= bytescount )
1285  {
1286  bytescount_in_sectors = (bytescount / secsize) + (!!(bytescount % secsize));
1287  readsize_bytes = bytescount;
1288  }
1289  else if ( sectors_partial && !(secsize & 0xF) )
1290  {
1291  bytescount_in_sectors -= sectors_partial;
1292  }
1293  if ( !readproc2(
1294  lsndualchg_res + i / secsize,
1295  bytescount_in_sectors,
1296  &rmode,
1297  disktype_14,
1298  sync,
1299  0,
1300  0,
1301  ee_addr + i,
1302  0,
1303  secsize,
1304  readsize_bytes,
1305  0) )
1306  {
1307  break;
1308  }
1309  }
1310  return 1;
1311 }
1312 
1313 static void
1314 cdvdfsv_rpc5_0F_readchain(const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf)
1315 {
1316  int sector_size;
1317  unsigned int i;
1318  const sceCdRChain *chain;
1319  void *buf;
1320  int re_result;
1321  int trid;
1322  int scres_unused;
1323  int state;
1324 
1325  (void)buflen;
1326  (void)outbuf;
1327 
1328  g_cdvdfsv_rderror = SCECdErREADCFR;
1329  g_cdvdfsv_readpos = 0;
1330  g_cdvdman_istruct_ptr->m_break_cdvdfsv_readchain = 0;
1331  g_cdvdfsv_chrdsdd.src = &g_cdvdfsv_readpos;
1332  g_cdvdfsv_chrdsdd.size = sizeof(g_cdvdfsv_readpos);
1333  g_cdvdfsv_chrdsdd.attr = 0;
1334  g_cdvdfsv_chrdsdd.dest = (void *)inbuf->m_pkt_0F.m_eedest;
1335  switch ( inbuf->m_pkt_0F.m_mode.datapattern )
1336  {
1337  case SCECdSecS2328:
1338  sector_size = 0x918;
1339  break;
1340  case SCECdSecS2340:
1341  sector_size = 0x924;
1342  break;
1343  case SCECdSecS2048:
1344  default:
1345  sector_size = 0x800;
1346  break;
1347  }
1348  chain = inbuf->m_pkt_0F.m_readChain;
1349  for ( i = 0; i < 0x40; i += 1 )
1350  {
1351  if ( g_cdvdman_istruct_ptr->m_break_cdvdfsv_readchain )
1352  {
1353  VERBOSE_PRINTF(1, "ReadChain cnt %d on sceCdBreak()\n", (int)i);
1354  return;
1355  }
1356  if ( chain[i].lbn == 0xFFFFFFFF || chain[i].sectors == 0xFFFFFFFF || chain[i].buffer == 0xFFFFFFFF )
1357  return;
1358  if ( (chain[i].buffer & 1) )
1359  {
1360  buf = (void *)(chain[i].buffer & ~1);
1361  VERBOSE_PRINTF(
1362  1,
1363  "ReadChain lsn= %d nsec= %d buf= %08x secsize= %d\n",
1364  (int)(chain[i].lbn),
1365  (int)(chain[i].sectors),
1366  (unsigned int)(uiptr)buf,
1367  inbuf->m_pkt_0F.m_mode.datapattern);
1368  re_result = sceCdRE(chain[i].lbn, chain[i].sectors, buf, (sceCdRMode *)&(inbuf->m_pkt_0F.m_mode));
1369  if ( re_result == 1 )
1370  {
1371  sceCdSync(0);
1372  re_result = sceCdGetError() == SCECdErNO;
1373  }
1374  else
1375  {
1376  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
1377  }
1378  }
1379  else
1380  {
1381  // The following printf was modified for ioprp300x
1382  VERBOSE_PRINTF(
1383  1, "ReadChain EE\t Memory addr= 0x%08x sector= %d\n", (unsigned int)(chain[i].lbn), (int)(chain[i].sectors));
1384  // The following call to sceCdGetDiskType was inlined
1385  re_result = cdvdfsv_chreadee(
1386  chain[i].lbn,
1387  chain[i].sectors,
1388  (char *)chain[i].buffer,
1389  &(inbuf->m_pkt_0F.m_mode),
1391  !sceCdSC(0xFFFFFFFC, &scres_unused));
1392  }
1393  if ( !re_result )
1394  {
1395  VERBOSE_PRINTF(1, "ReadChain error code= 0x%02x\n", sceCdGetError());
1396  break;
1397  }
1398  g_cdvdfsv_readpos += chain[i].sectors * sector_size;
1399  while ( 1 )
1400  {
1401  CpuSuspendIntr(&state);
1402  trid = sceSifSetDma(&g_cdvdfsv_chrdsdd, 1);
1403  CpuResumeIntr(state);
1404  if ( trid )
1405  break;
1406  DelayThread(500);
1407  }
1408  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1409  ;
1410  }
1411 }
1412 
1413 #ifdef CDVD_VARIANT_OSD
1414 static void cdvdfsv_rpc5_03_readdvdv(const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf)
1415 {
1416  int all_sec_bytes;
1417  unsigned int buf_1_toalign;
1418  unsigned int buf_offs_mod_sector_size;
1419  unsigned int buf_aligned;
1420  u32 sectors;
1421  int lbn;
1422  int cmd_error;
1423  int error_code;
1424  unsigned int i;
1425  int readbuf;
1426  int cpysize;
1427  int trid;
1428  int state;
1429  unsigned int buf_offs;
1430  unsigned int buf_toalign;
1431  unsigned int buf_sec_tmp;
1432 
1433  (void)buflen;
1434  error_code = SCECdErNO;
1435  cmd_error = 1;
1436  buf_offs = 0;
1437  g_cdvdfsv_rderror = SCECdErREADCFR;
1438  all_sec_bytes = 0x810 * inbuf->m_pkt_03.m_nsectors;
1439  buf_toalign = ((inbuf->m_pkt_03.m_buf & 0x3F)) ? (inbuf->m_pkt_03.m_buf & ~0x3F) - (inbuf->m_pkt_03.m_buf - 0x40) : 0;
1440  buf_1_toalign = (inbuf->m_pkt_03.m_buf + all_sec_bytes) & ~0x3F;
1441  buf_sec_tmp = all_sec_bytes - (buf_1_toalign - inbuf->m_pkt_03.m_buf);
1442  if ( buf_toalign )
1443  {
1444  lbn = inbuf->m_pkt_03.m_lbn + buf_offs / 0x810;
1445  sectors = 1 + (!!((inbuf->m_pkt_03.m_lbn + inbuf->m_pkt_03.m_nsectors) >= (unsigned int)(lbn + 2)));
1446  VERBOSE_PRINTF(1, "0 CD_READ LBN= %d sectors= %d all= %d\n", lbn, (int)sectors, (int)inbuf->m_pkt_03.m_nsectors);
1447  cmd_error = sceCdReadDVDV(lbn, sectors, g_cdvdfsv_fsvrbuf[0], (sceCdRMode *)&inbuf->m_pkt_03.m_mode);
1448  sceCdSync(0);
1449  error_code = sceCdGetError();
1450  if ( error_code != SCECdErNO || !cmd_error )
1451  {
1452  if ( !cmd_error )
1453  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
1454  VERBOSE_PRINTF(1, "Read error code %x cmd error %d\n", error_code, cmd_error);
1455  buf_toalign = 0;
1456  }
1457  for ( i = 0; i < buf_toalign; i += 1 )
1458  g_cdvdfsv_eereadx.m_pbuf1[i] = g_cdvdfsv_fsvrbuf[0][i];
1459  buf_offs += buf_toalign;
1460  }
1461  if ( error_code == SCECdErNO && cmd_error )
1462  {
1463  int firstflag;
1464  unsigned int sector_count_in_bytes;
1465 
1466  buf_offs_mod_sector_size = 0;
1467  readbuf = 0;
1468  firstflag = 0;
1469  cpysize = 0;
1470  for ( buf_aligned = inbuf->m_pkt_03.m_buf + buf_toalign; buf_aligned < buf_1_toalign;
1471  buf_aligned += sector_count_in_bytes )
1472  {
1473  unsigned int buf_align_remain;
1474 
1475  buf_align_remain = buf_1_toalign - buf_aligned;
1476  buf_offs_mod_sector_size = (buf_aligned - inbuf->m_pkt_03.m_buf) % 0x810;
1477  sector_count_in_bytes = (0x8100 >= buf_align_remain) ? buf_align_remain : 0x8100;
1478  sectors = (0x8100 >= buf_align_remain) ? (buf_align_remain / 0x810 + (!!(buf_align_remain % 0x810))) : 16;
1479  sectors += !!buf_offs_mod_sector_size;
1480  lbn = inbuf->m_pkt_03.m_lbn + (buf_aligned - inbuf->m_pkt_03.m_buf) / 0x810;
1481  if ( sectors > (inbuf->m_pkt_03.m_lbn + inbuf->m_pkt_03.m_nsectors) - lbn )
1482  sectors = (inbuf->m_pkt_03.m_lbn + inbuf->m_pkt_03.m_nsectors) - lbn;
1483  cmd_error = sceCdReadDVDV(lbn, sectors, g_cdvdfsv_fsvrbuf[readbuf], (sceCdRMode *)&inbuf->m_pkt_03.m_mode);
1484  if ( firstflag )
1485  {
1486  if ( buf_offs_mod_sector_size )
1487  optimized_memcpy(
1488  g_cdvdfsv_fsvrbuf[readbuf ^ 1], &g_cdvdfsv_fsvrbuf[readbuf ^ 1][buf_offs_mod_sector_size], cpysize);
1489  g_cdvdfsv_readdvdv_dmat.dest = (void *)(buf_aligned - cpysize);
1490  g_cdvdfsv_readdvdv_dmat.size = cpysize;
1491  g_cdvdfsv_readdvdv_dmat.attr = 0;
1492  g_cdvdfsv_readdvdv_dmat.src = g_cdvdfsv_fsvrbuf[readbuf ^ 1];
1493  while ( 1 )
1494  {
1495  CpuSuspendIntr(&state);
1496  trid = sceSifSetDma(&g_cdvdfsv_readdvdv_dmat, 1);
1497  CpuResumeIntr(state);
1498  if ( trid )
1499  break;
1500  DelayThread(500);
1501  }
1502  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1503  ;
1504  }
1505  sceCdSync(0);
1506  error_code = sceCdGetError();
1507  if ( error_code != SCECdErNO || !cmd_error )
1508  {
1509  if ( !cmd_error )
1510  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
1511  VERBOSE_PRINTF(1, "Read error code %x cmd error %d\n", error_code, cmd_error);
1512  break;
1513  }
1514  firstflag = 1;
1515  readbuf ^= 1;
1516  cpysize = sector_count_in_bytes;
1517  buf_offs += sector_count_in_bytes;
1518  }
1519  }
1520  if ( error_code == SCECdErNO && cmd_error )
1521  {
1522  if ( buf_offs_mod_sector_size )
1523  optimized_memcpy(
1524  g_cdvdfsv_fsvrbuf[readbuf ^ 1], &g_cdvdfsv_fsvrbuf[readbuf ^ 1][buf_offs_mod_sector_size], cpysize);
1525  g_cdvdfsv_readdvdv_dmat.dest = (void *)buf_aligned;
1526  g_cdvdfsv_readdvdv_dmat.size = cpysize;
1527  g_cdvdfsv_readdvdv_dmat.attr = 0;
1528  g_cdvdfsv_readdvdv_dmat.src = g_cdvdfsv_fsvrbuf[readbuf ^ 1];
1529  while ( 1 )
1530  {
1531  CpuSuspendIntr(&state);
1532  trid = sceSifSetDma(&g_cdvdfsv_readdvdv_dmat, 1);
1533  CpuResumeIntr(state);
1534  if ( trid )
1535  break;
1536  DelayThread(500);
1537  }
1538  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1539  ;
1540  if ( buf_sec_tmp )
1541  {
1542  lbn = inbuf->m_pkt_03.m_lbn + buf_offs / 0x810;
1543  sectors = 1 + (!!((inbuf->m_pkt_03.m_lbn + inbuf->m_pkt_03.m_nsectors) >= (unsigned int)(lbn + 2)));
1544  VERBOSE_PRINTF(1, "2 CD_READ LBN= %d sectors= %d\n", lbn, (int)sectors);
1545  cmd_error = sceCdReadDVDV(lbn, sectors, g_cdvdfsv_fsvrbuf[0], (sceCdRMode *)&inbuf->m_pkt_03.m_mode);
1546  sceCdSync(0);
1547  error_code = sceCdGetError();
1548  if ( error_code != SCECdErNO || !cmd_error )
1549  {
1550  if ( !cmd_error )
1551  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
1552  VERBOSE_PRINTF(1, "Read error code %x cmd error %d\n", error_code, cmd_error);
1553  buf_sec_tmp = 0;
1554  }
1555  for ( i = 0; i < buf_sec_tmp; i += 1 )
1556  g_cdvdfsv_eereadx.m_pbuf2[i] = g_cdvdfsv_fsvrbuf[0][(buf_offs % 0x810) + i];
1557  buf_offs += buf_sec_tmp;
1558  }
1559  }
1560  g_cdvdfsv_eereadx.m_b1len = buf_toalign;
1561  g_cdvdfsv_eereadx.m_b2len = buf_sec_tmp;
1562  g_cdvdfsv_eereadx.m_b1dst = inbuf->m_pkt_03.m_buf;
1563  g_cdvdfsv_eereadx.m_b2dst = buf_1_toalign;
1564  g_cdvdfsv_readdvdv_dmat.src = &g_cdvdfsv_eereadx;
1565  g_cdvdfsv_readdvdv_dmat.size = sizeof(g_cdvdfsv_eereadx);
1566  g_cdvdfsv_readdvdv_dmat.attr = 0;
1567  g_cdvdfsv_readdvdv_dmat.dest = (void *)inbuf->m_pkt_03.m_eedest;
1568  while ( 1 )
1569  {
1570  CpuSuspendIntr(&state);
1571  trid = sceSifSetDma(&g_cdvdfsv_readdvdv_dmat, 1);
1572  CpuResumeIntr(state);
1573  if ( trid )
1574  break;
1575  DelayThread(500);
1576  }
1577  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1578  ;
1579  VERBOSE_PRINTF(1, "read end\n");
1580  outbuf->m_retres = buf_offs;
1581 }
1582 #endif
1583 
1584 // Note: in OSD variant, the do_read_full argument was added
1585 static void cdvdfsv_rpc5_02_readcdda(
1586  const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf, int do_read_full)
1587 {
1588  int trid;
1589  unsigned int sector_size;
1590  int all_sec_bytes;
1591  unsigned int buf_1_toalign;
1592  u32 sectors;
1593  int lbn;
1594  int cmd_error;
1595  int error_code;
1596  unsigned int i;
1597  int state;
1598  int error_code_tmp;
1599  unsigned int buf_offs;
1600  unsigned int buf_toalign;
1601  unsigned int buf_sec_tmp;
1602 
1603 #ifndef CDVD_VARIANT_OSD
1604  (void)do_read_full;
1605 #endif
1606  trid = 0;
1607  g_cdvdfsv_rderror = SCECdErREADCFR;
1608  error_code_tmp = SCECdErNO;
1609  g_cdvdfsv_eereadfull_dma2.src = &g_cdvdfsv_readpos;
1610  g_cdvdfsv_eereadfull_dma2.size = sizeof(g_cdvdfsv_readpos);
1611  g_cdvdfsv_eereadfull_dma2.attr = 0;
1612  g_cdvdfsv_eereadfull_dma2.dest = (void *)inbuf->m_pkt_02.m_eedest;
1613  switch ( inbuf->m_pkt_02.m_mode.datapattern )
1614  {
1615  case SCECdSecS2368:
1616  sector_size = 0x940;
1617  break;
1618  case SCECdSecS2352:
1619  case SCECdSecS2448:
1620  default:
1621  sector_size = 0x930;
1622  break;
1623  }
1624  buf_offs = 0;
1625  all_sec_bytes = sector_size * inbuf->m_pkt_02.m_sectors;
1626  buf_toalign =
1627  ((inbuf->m_pkt_02.m_buf & 0x3F)) ? ((inbuf->m_pkt_02.m_buf & ~0x3F) - (inbuf->m_pkt_02.m_buf - 0x40)) : 0;
1628  buf_1_toalign = (inbuf->m_pkt_02.m_buf + all_sec_bytes) & ~0x3F;
1629  buf_sec_tmp = all_sec_bytes - (buf_1_toalign - inbuf->m_pkt_02.m_buf);
1630  if ( buf_toalign )
1631  {
1632  unsigned int buf_offs_sectors;
1633 
1634  buf_offs_sectors = buf_offs / sector_size;
1635  lbn = inbuf->m_pkt_02.m_lbn + buf_offs_sectors;
1636  sectors = 1 + !!((inbuf->m_pkt_02.m_lbn + inbuf->m_pkt_02.m_sectors) >= (unsigned int)(lbn + 2));
1637  VERBOSE_PRINTF(
1638  1, "0 CD_READ LBN= %d sectors= %d all= %d\n", (int)lbn, (int)sectors, (int)inbuf->m_pkt_02.m_sectors);
1639 #ifdef CDVD_VARIANT_OSD
1640  cmd_error = do_read_full ? sceCdReadFull(lbn, sectors, g_cdvdfsv_rtocbuf, (sceCdRMode *)&inbuf->m_pkt_02.m_mode) :
1641  sceCdReadCDDA(lbn, sectors, g_cdvdfsv_rtocbuf, (sceCdRMode *)&inbuf->m_pkt_02.m_mode);
1642 #else
1643  cmd_error = sceCdReadCDDA(lbn, sectors, g_cdvdfsv_rtocbuf, (sceCdRMode *)&inbuf->m_pkt_02.m_mode);
1644 #endif
1645  sceCdSync(3);
1646  error_code = sceCdGetError();
1647  if ( error_code != SCECdErNO || !cmd_error )
1648  {
1649  if ( !cmd_error )
1650  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
1651  VERBOSE_PRINTF(1, "Read error code %x cmd error %d\n", error_code, cmd_error);
1652  if ( error_code == SCECdErEOM || error_code == SCECdErSFRMTNG )
1653  error_code_tmp = error_code;
1654  else
1655  {
1656  buf_toalign = 0;
1657  }
1658  }
1659  if ( error_code_tmp != SCECdErNO && error_code_tmp != SCECdErEOM && error_code_tmp != SCECdErSFRMTNG )
1660  {
1661  for ( i = 0; i < buf_toalign; i += 1 )
1662  {
1663  g_cdvdfsv_eereadx.m_pbuf1[i] = g_cdvdfsv_rtocbuf[i];
1664  }
1665  buf_offs += buf_toalign;
1666  }
1667  }
1668  if ( error_code_tmp != SCECdErNO && error_code_tmp != SCECdErEOM && error_code_tmp != SCECdErSFRMTNG )
1669  {
1670  unsigned int sector_count_in_bytes;
1671  unsigned int buf_aligned;
1672 
1673  for ( buf_aligned = inbuf->m_pkt_02.m_buf + buf_toalign; buf_aligned < buf_1_toalign;
1674  buf_aligned += sector_count_in_bytes )
1675  {
1676  unsigned int buf_align_remain;
1677  unsigned int buf_offs_mod_sector_size;
1678 
1679  buf_align_remain = buf_1_toalign - buf_aligned;
1680  buf_offs_mod_sector_size = buf_offs % sector_size;
1681  lbn = inbuf->m_pkt_02.m_lbn + buf_offs / sector_size;
1682  sectors = (g_cdvdfsv_sectors_cdda * sector_size >= buf_align_remain) ?
1683  (buf_align_remain / sector_size) + (!!(buf_align_remain % sector_size)) :
1684  g_cdvdfsv_sectors_cdda;
1685  sectors += !!buf_offs_mod_sector_size;
1686  sector_count_in_bytes = (g_cdvdfsv_sectors_cdda * sector_size >= buf_align_remain) ?
1687  g_cdvdfsv_sectors_cdda * sector_size :
1688  buf_align_remain;
1689  if ( sectors > (inbuf->m_pkt_02.m_lbn + inbuf->m_pkt_02.m_sectors) - lbn )
1690  sectors = (inbuf->m_pkt_02.m_lbn + inbuf->m_pkt_02.m_sectors) - lbn;
1691  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1692  ;
1693 #ifdef CDVD_VARIANT_OSD
1694  cmd_error = do_read_full ? sceCdReadFull(lbn, sectors, g_cdvdfsv_rtocbuf, (sceCdRMode *)&inbuf->m_pkt_02.m_mode) :
1695  sceCdReadCDDA(lbn, sectors, g_cdvdfsv_rtocbuf, (sceCdRMode *)&inbuf->m_pkt_02.m_mode);
1696 #else
1697  cmd_error = sceCdReadCDDA(lbn, sectors, g_cdvdfsv_rtocbuf, (sceCdRMode *)&inbuf->m_pkt_02.m_mode);
1698 #endif
1699  sceCdSync(3);
1700  error_code = sceCdGetError();
1701  if ( error_code != SCECdErNO || !cmd_error )
1702  {
1703  if ( !cmd_error )
1704  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
1705  VERBOSE_PRINTF(1, "Read error code %x cmd error %d\n", error_code, cmd_error);
1706  if ( error_code == SCECdErEOM || error_code == SCECdErSFRMTNG )
1707  {
1708  error_code_tmp = error_code;
1709  break;
1710  }
1711  }
1712  if ( buf_offs_mod_sector_size )
1713  optimized_memcpy(g_cdvdfsv_rtocbuf, &g_cdvdfsv_rtocbuf[buf_offs_mod_sector_size], sector_count_in_bytes);
1714  g_cdvdfsv_eereadfull_dma1.src = g_cdvdfsv_rtocbuf;
1715  g_cdvdfsv_eereadfull_dma1.size = sector_count_in_bytes;
1716  g_cdvdfsv_eereadfull_dma1.attr = 0;
1717  g_cdvdfsv_eereadfull_dma1.dest = (char *)buf_aligned;
1718  g_cdvdfsv_readpos = buf_offs;
1719  while ( 1 )
1720  {
1721  CpuSuspendIntr(&state);
1722  trid = sceSifSetDma(&g_cdvdfsv_eereadfull_dma1, 1);
1723  CpuResumeIntr(state);
1724  if ( trid )
1725  break;
1726  DelayThread(500);
1727  }
1728  if ( (unsigned int)buflen >= 0x19 )
1729  {
1730  CpuSuspendIntr(&state);
1731  sceSifSetDma(&g_cdvdfsv_eereadfull_dma2, 1);
1732  CpuResumeIntr(state);
1733  }
1734  buf_offs += sector_count_in_bytes;
1735  }
1736  }
1737  if (
1738  (error_code_tmp != SCECdErNO && error_code_tmp != SCECdErEOM && error_code_tmp != SCECdErSFRMTNG) && buf_sec_tmp )
1739  {
1740  lbn = inbuf->m_pkt_02.m_lbn + buf_offs / sector_size;
1741  sectors = 1 + !!((inbuf->m_pkt_02.m_lbn + inbuf->m_pkt_02.m_sectors) >= (unsigned int)(lbn + 2));
1742  VERBOSE_PRINTF(
1743  1,
1744  "0 CD_READ LBN= %d sectors= %d all= %d\n",
1745  (int)(inbuf->m_pkt_02.m_lbn + buf_offs / sector_size),
1746  (int)sectors,
1747  (int)inbuf->m_pkt_02.m_sectors);
1748  VERBOSE_PRINTF(1, "2 CD_READ LBN= %d sectors= %d\n", (int)lbn, (int)sectors);
1749 #ifdef CDVD_VARIANT_OSD
1750  cmd_error = do_read_full ? sceCdReadFull(lbn, sectors, g_cdvdfsv_rtocbuf, (sceCdRMode *)&inbuf->m_pkt_02.m_mode) :
1751  sceCdReadCDDA(lbn, sectors, g_cdvdfsv_rtocbuf, (sceCdRMode *)&inbuf->m_pkt_02.m_mode);
1752 #else
1753  cmd_error = sceCdReadCDDA(lbn, sectors, g_cdvdfsv_rtocbuf, (sceCdRMode *)&inbuf->m_pkt_02.m_mode);
1754 #endif
1755  sceCdSync(3);
1756  error_code = sceCdGetError();
1757  if ( error_code != SCECdErNO || !cmd_error )
1758  {
1759  if ( !cmd_error )
1760  sceCdSC(0xFFFFFFFE, &g_cdvdfsv_rderror);
1761  VERBOSE_PRINTF(1, "Read error code %x cmd error %d\n", error_code, cmd_error);
1762  if ( error_code == SCECdErEOM || error_code == SCECdErSFRMTNG )
1763  error_code_tmp = error_code;
1764  else
1765  buf_sec_tmp = 0;
1766  }
1767  for ( i = 0; i < buf_sec_tmp; i += 1 )
1768  {
1769  g_cdvdfsv_eereadx.m_pbuf2[i] = g_cdvdfsv_rtocbuf[(buf_offs % sector_size) + i];
1770  }
1771  buf_offs += buf_sec_tmp;
1772  }
1773  g_cdvdfsv_eereadx.m_b1len = buf_toalign;
1774  g_cdvdfsv_eereadx.m_b2len = buf_sec_tmp;
1775  g_cdvdfsv_eereadx.m_b1dst = inbuf->m_pkt_02.m_buf;
1776  g_cdvdfsv_eereadx.m_b2dst = buf_1_toalign;
1777  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1778  ;
1779  g_cdvdfsv_eereadfull_dma1.src = &g_cdvdfsv_eereadx;
1780  g_cdvdfsv_eereadfull_dma1.size = sizeof(g_cdvdfsv_eereadx);
1781  g_cdvdfsv_eereadfull_dma1.attr = 0;
1782  g_cdvdfsv_readpos = buf_offs;
1783  g_cdvdfsv_eereadfull_dma1.dest = (void *)inbuf->m_pkt_02.m_eeremaindest;
1784  while ( 1 )
1785  {
1786  CpuSuspendIntr(&state);
1787  trid = sceSifSetDma(&g_cdvdfsv_eereadfull_dma1, 1);
1788  if ( (unsigned int)buflen >= 0x19 )
1789  sceSifSetDma(&g_cdvdfsv_eereadfull_dma2, 1);
1790  CpuResumeIntr(state);
1791  if ( trid )
1792  break;
1793  DelayThread(500);
1794  }
1795  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1796  ;
1797  if ( error_code_tmp != SCECdErNO )
1798  sceCdSC(0xFFFFFFFE, &error_code_tmp);
1799  VERBOSE_PRINTF(1, "read end\n");
1800  outbuf->m_retres = buf_offs;
1801 }
1802 
1803 static void *cbrpc_rpc2_diskready(int fno, void *buffer, int length)
1804 {
1805  (void)fno;
1806  (void)length;
1807 
1808  // The following call to sceCdStatus was inlined
1809  VERBOSE_KPRINTF(1, "DISK READY call 0x%02x\n", sceCdStatus());
1810  // The following call to sceCdDiskReady was inlined
1811  g_diskready_res.m_retres = sceCdDiskReady(((const cdvdfsv_rpc2_inpacket_t *)buffer)->m_mode);
1812  return (void *)&g_diskready_res;
1813 }
1814 
1815 static void cdvdfsv_rpc5_04_gettoc(const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf)
1816 {
1817  int trid;
1818  int state;
1819 
1820  (void)buflen;
1821 
1822  VERBOSE_PRINTF(1, "GET TOC call 0x%08x\n", (int)inbuf);
1823  outbuf->m_retres = sceCdGetToc((u8 *)g_cdvdfsv_rtocbuf);
1824  VERBOSE_PRINTF(1, "GET TOC called\n");
1825  g_cdvdfsv_rtocsdd.src = g_cdvdfsv_rtocbuf;
1826  g_cdvdfsv_rtocsdd.size = 0x810;
1827  g_cdvdfsv_rtocsdd.attr = 0;
1828  g_cdvdfsv_rtocsdd.dest = (void *)inbuf->m_pkt_04.m_eedest;
1829  while ( 1 )
1830  {
1831  CpuSuspendIntr(&state);
1832  trid = sceSifSetDma(&g_cdvdfsv_rtocsdd, 1);
1833  CpuResumeIntr(state);
1834  if ( trid )
1835  break;
1836  DelayThread(500);
1837  }
1838  while ( cdvdfsv_checkdmastat(trid) >= 0 )
1839  ;
1840  // The following call to sceCdGetDiskType was inlined
1841  switch ( sceCdGetDiskType() )
1842  {
1843  case SCECdPS2DVD:
1844  case SCECdDVDVR:
1845  case SCECdDVDV:
1846  outbuf->m_pkt_04.m_isdvd = 1;
1847  break;
1848  default:
1849  outbuf->m_pkt_04.m_isdvd = 0;
1850  break;
1851  }
1852 }
1853 
1854 static void cdvdfsv_rpc3_03_disktype(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1855 {
1856  (void)inbuf;
1857  (void)buflen;
1858 
1859  outbuf->m_retres = sceCdGetDiskType();
1860 }
1861 
1862 static void cdvdfsv_rpc3_0C_cdstatus(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1863 {
1864  (void)inbuf;
1865  (void)buflen;
1866 
1867  outbuf->m_retres = sceCdStatus();
1868 }
1869 
1870 static void cdvdfsv_rpc3_06_ri(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1871 {
1872  int i;
1873  u32 efbits;
1874 
1875  (void)inbuf;
1876  (void)buflen;
1877 
1878  outbuf->m_retres = 0;
1879  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
1880  {
1881  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1882  outbuf->m_retres = sceCdRI(outbuf->m_pkt_06.m_buffer, &outbuf->m_pkt_06.m_result);
1883  }
1884 }
1885 
1886 static void cdvdfsv_rpc3_1A_rm(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1887 {
1888  int i;
1889  u32 efbits;
1890 
1891  (void)inbuf;
1892  (void)buflen;
1893 
1894  outbuf->m_retres = 0;
1895  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
1896  {
1897  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1898  outbuf->m_retres = sceCdRM(outbuf->m_pkt_1A.m_buffer, &outbuf->m_pkt_1A.m_status);
1899  }
1900 }
1901 
1902 #ifdef CDVD_VARIANT_DNAS
1903 static void cdvdfsv_rpc3_24_readguid(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1904 {
1905  int i;
1906  u32 efbits;
1907 
1908  (void)inbuf;
1909  (void)buflen;
1910 
1911  outbuf->m_retres = 0;
1912  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
1913  {
1914  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1915  outbuf->m_retres = sceCdReadGUID(&outbuf->m_pkt_24.m_guid);
1916  }
1917 }
1918 
1919 static void
1920 cdvdfsv_rpc3_26_readmodelid(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1921 {
1922  int i;
1923  u32 efbits;
1924 
1925  (void)inbuf;
1926  (void)buflen;
1927 
1928  outbuf->m_retres = 0;
1929  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
1930  {
1931  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1932  outbuf->m_retres = sceCdReadModelID(&outbuf->m_pkt_26.m_id);
1933  }
1934 }
1935 #endif
1936 
1937 static void cdvdfsv_rpc3_22_mmode(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1938 {
1939  if ( buflen == 4 || !inbuf->m_pkt_22.m_char4 )
1940  {
1941  outbuf->m_retres = sceCdMmode(inbuf->m_pkt_22.m_media);
1942  }
1943 }
1944 
1945 #ifdef CDVD_VARIANT_XOSD
1946 static void cdvdfsv_rpc3_2D_chgsys(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1947 {
1948  (void)buflen;
1949  VERBOSE_KPRINTF(1, "EE call recv sceCdChgSys %d %08x\n", inbuf->m_pkt_2D.m_arg1, inbuf);
1950  outbuf->m_retres = sceCdChgSys(inbuf->m_pkt_2D.m_arg1);
1951 }
1952 #endif
1953 
1954 static void
1955 cdvdfsv_rpc3_23_changethreadpriority(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1956 {
1957  (void)buflen;
1958 
1959  outbuf->m_retres = sceCdChangeThreadPriority(inbuf->m_pkt_23.m_priority);
1960 }
1961 
1962 #ifdef CDVD_VARIANT_OSD
1963 static void cdvdfsv_rpc3_07_wi(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1964 {
1965  int i;
1966  u32 efbits;
1967 
1968  (void)inbuf;
1969  (void)buflen;
1970  outbuf->m_retres = 0;
1971  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
1972  {
1973  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1974  outbuf->m_retres = sceCdWI(inbuf->m_pkt_07.m_buffer, &outbuf->m_pkt_07.m_status);
1975  }
1976 }
1977 #endif
1978 
1979 #ifdef CDVD_VARIANT_OSD
1980 static void cdvdfsv_rpc3_1B_wm(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1981 {
1982  int i;
1983  u32 efbits;
1984 
1985  (void)inbuf;
1986  (void)buflen;
1987  outbuf->m_retres = 0;
1988  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
1989  {
1990  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
1991  outbuf->m_retres = sceCdWM(inbuf->m_pkt_1B.m_buffer, &outbuf->m_pkt_1B.m_status);
1992  }
1993 }
1994 #endif
1995 
1996 #ifdef CDVD_VARIANT_OSD
1997 static void
1998 cdvdfsv_rpc3_12_readconsoleid(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
1999 {
2000  int i;
2001  u32 efbits;
2002 
2003  (void)inbuf;
2004  (void)buflen;
2005  outbuf->m_retres = 0;
2006  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2007  {
2008  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2009  outbuf->m_retres = sceCdReadConsoleID(outbuf->m_pkt_12.m_buffer, &outbuf->m_pkt_12.m_status);
2010  }
2011 }
2012 #endif
2013 
2014 #ifdef CDVD_VARIANT_OSD
2015 static void
2016 cdvdfsv_rpc3_13_writeconsoleid(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2017 {
2018  int i;
2019  u32 efbits;
2020 
2021  (void)inbuf;
2022  (void)buflen;
2023  outbuf->m_retres = 0;
2024  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2025  {
2026  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2027  outbuf->m_retres = sceCdWriteConsoleID(inbuf->m_pkt_13.m_buffer, &outbuf->m_pkt_13.m_status);
2028  }
2029 }
2030 #endif
2031 
2032 #ifdef CDVD_VARIANT_OSD
2033 static void
2034 cdvdfsv_rpc3_14_getmversion(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2035 {
2036  int i;
2037  u32 efbits;
2038 
2039  (void)inbuf;
2040  (void)buflen;
2041  outbuf->m_retres = 0;
2042  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2043  {
2044  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2045  outbuf->m_retres = sceCdMV(outbuf->m_pkt_14.m_buffer, &outbuf->m_pkt_14.m_status);
2046  }
2047 }
2048 #endif
2049 
2050 #ifdef CDVD_VARIANT_OSD
2051 static void cdvdfsv_rpc3_17_readsubq(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2052 {
2053  int i;
2054  u32 efbits;
2055 
2056  (void)inbuf;
2057  (void)buflen;
2058  outbuf->m_retres = 0;
2059  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2060  {
2061  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2062  outbuf->m_retres = sceCdReadSUBQ(outbuf->m_pkt_17.m_buffer, &outbuf->m_pkt_17.m_status);
2063  }
2064 }
2065 #endif
2066 
2067 #ifdef CDVD_VARIANT_OSD
2068 static void
2069 cdvdfsv_rpc3_18_forbiddvdp(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2070 {
2071  int i;
2072  u32 efbits;
2073 
2074  (void)inbuf;
2075  (void)buflen;
2076  outbuf->m_retres = 0;
2077  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2078  {
2079  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2080  outbuf->m_retres = sceCdForbidDVDP(&outbuf->m_pkt_18.m_status);
2081  }
2082 }
2083 #endif
2084 
2085 #ifdef CDVD_VARIANT_OSD
2086 static void
2087 cdvdfsv_rpc3_1C_forbidread(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2088 {
2089  int i;
2090  u32 efbits;
2091 
2092  (void)inbuf;
2093  (void)buflen;
2094  outbuf->m_retres = 0;
2095  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2096  {
2097  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2098  outbuf->m_retres = sceCdForbidRead(&outbuf->m_pkt_1C.m_status);
2099  }
2100 }
2101 #endif
2102 
2103 #ifdef CDVD_VARIANT_OSD
2104 static void
2105 cdvdfsv_rpc3_1E_bootcertify(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2106 {
2107  int i;
2108  u32 efbits;
2109 
2110  (void)buflen;
2111  outbuf->m_retres = 0;
2112  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2113  {
2114  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2115  outbuf->m_retres = sceCdBootCertify(inbuf->m_pkt_1E.m_romname);
2116  }
2117 }
2118 #endif
2119 
2120 #ifdef CDVD_VARIANT_OSD
2121 static void
2122 cdvdfsv_rpc3_1F_cancelpoffrdy(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2123 {
2124  int i;
2125  u32 efbits;
2126 
2127  (void)inbuf;
2128  (void)buflen;
2129  outbuf->m_retres = 0;
2130  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2131  {
2132  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2133  outbuf->m_retres = sceCdCancelPOffRdy(&outbuf->m_pkt_1F.m_status);
2134  }
2135 }
2136 #endif
2137 
2138 static void cdvdfsv_rpc3_21_poweroff(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2139 {
2140  int i;
2141  u32 efbits;
2142 
2143  (void)inbuf;
2144  (void)buflen;
2145 
2146  outbuf->m_retres = 0;
2147  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2148  {
2149  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2150  outbuf->m_retres = sceCdPowerOff(&outbuf->m_pkt_21.m_result);
2151  }
2152 }
2153 
2154 #ifdef CDVD_VARIANT_OSD
2155 static void
2156 cdvdfsv_rpc3_20_blueledctl(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2157 {
2158  int i;
2159  u32 efbits;
2160 
2161  (void)buflen;
2162  outbuf->m_retres = 0;
2163  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2164  {
2165  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2166  outbuf->m_retres = sceCdBlueLEDCtl(inbuf->m_pkt_20.m_control, &outbuf->m_pkt_20.m_status);
2167  }
2168 }
2169 #endif
2170 
2171 #ifdef CDVD_VARIANT_OSD
2172 static void
2173 cdvdfsv_rpc3_1D_sc_FFFFFFF8(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2174 {
2175  (void)buflen;
2176  g_cdvdfsv_spinctl = inbuf->m_pkt_1D.m_spinctl;
2177  outbuf->m_retres = sceCdSC(0xFFFFFFF8, &g_cdvdfsv_spinctl);
2178 }
2179 #endif
2180 
2181 static void
2182 cdvdfsv_rpc3_15_ctrladout(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2183 {
2184  int i;
2185  u32 efbits;
2186 
2187  (void)buflen;
2188 
2189  outbuf->m_retres = 0;
2190  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2191  {
2192  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2193  outbuf->m_retres = sceCdCtrlADout(inbuf->m_pkt_15.m_mode, &outbuf->m_pkt_15.m_status);
2194  }
2195 }
2196 
2197 #ifdef CDVD_VARIANT_OSD
2198 static void
2199 cdvdfsv_rpc3_19_autoadjustctrl(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2200 {
2201  int i;
2202  u32 efbits;
2203 
2204  (void)buflen;
2205  outbuf->m_retres = 0;
2206  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2207  {
2208  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2209  outbuf->m_retres = sceCdAutoAdjustCtrl(inbuf->m_pkt_19.m_mode, &outbuf->m_pkt_19.m_status);
2210  }
2211 }
2212 #endif
2213 
2214 #ifdef CDVD_VARIANT_OSD
2215 static void
2216 cdvdfsv_rpc3_29_readwakeuptime(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2217 {
2218  int i;
2219  u32 efbits;
2220 
2221  (void)inbuf;
2222  (void)buflen;
2223  outbuf->m_retres = 0;
2224  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2225  {
2226  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2227  outbuf->m_retres = sceCdReadWakeUpTime(
2228  &outbuf->m_pkt_29.m_clock,
2229  &outbuf->m_pkt_29.m_userdata,
2230  &outbuf->m_pkt_29.m_wakeupreason,
2231  &outbuf->m_pkt_29.m_flags);
2232  }
2233 }
2234 #endif
2235 
2236 #ifdef CDVD_VARIANT_OSD
2237 static void
2238 cdvdfsv_rpc3_28_writewakeuptime(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2239 {
2240  int i;
2241  u32 efbits;
2242 
2243  (void)buflen;
2244  outbuf->m_retres = 0;
2245  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2246  {
2247  // Unofficial: copy to output buffer then use it
2248  memcpy(&outbuf->m_pkt_28.m_clock, &inbuf->m_pkt_28.m_clock, sizeof(sceCdCLOCK));
2249  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2250  outbuf->m_retres =
2251  sceCdWriteWakeUpTime(&outbuf->m_pkt_28.m_clock, inbuf->m_pkt_28.m_userdata, inbuf->m_pkt_28.m_flags);
2252  }
2253 }
2254 #endif
2255 
2256 #ifdef CDVD_VARIANT_OSD
2257 static void
2258 cdvdfsv_rpc3_30_rcbypassctl(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2259 {
2260  int i;
2261  u32 efbits;
2262 
2263  (void)buflen;
2264  outbuf->m_retres = 0;
2265  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2266  {
2267  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2268  outbuf->m_retres = sceCdRcBypassCtl(inbuf->m_pkt_30.m_mode, &outbuf->m_pkt_30.m_status);
2269  }
2270 }
2271 #endif
2272 
2273 #ifdef CDVD_VARIANT_OSD
2274 static void
2275 cdvdfsv_rpc3_32_sendscmd1d(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2276 {
2277  int i;
2278  u32 efbits;
2279 
2280  (void)inbuf;
2281  (void)buflen;
2282  outbuf->m_retres = 0;
2283  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2284  {
2285  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2286  outbuf->m_retres = sceCdSendSCmd1D(
2287  (int *)&outbuf->m_pkt_32.m_arg1, &outbuf->m_pkt_32.m_arg2, &outbuf->m_pkt_32.m_arg3, &outbuf->m_pkt_32.m_arg4);
2288  }
2289 }
2290 #endif
2291 
2292 #ifdef CDVD_VARIANT_OSD
2293 static void
2294 cdvdfsv_rpc3_31_remote2_7(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2295 {
2296  int i;
2297  u32 efbits;
2298 
2299  (void)buflen;
2300  outbuf->m_retres = 0;
2301  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2302  {
2303  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2304  outbuf->m_retres = sceRemote2_7(inbuf->m_pkt_31.m_param, &outbuf->m_pkt_31.m_status);
2305  }
2306 }
2307 #endif
2308 
2309 #ifdef CDVD_VARIANT_OSD
2310 static void
2311 cdvdfsv_rpc3_38_remote2_7_get(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2312 {
2313  int i;
2314  u32 efbits;
2315 
2316  (void)inbuf;
2317  (void)buflen;
2318  outbuf->m_retres = 0;
2319  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2320  {
2321  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2322  outbuf->m_retres = sceRemote2_7Get(&outbuf->m_pkt_38.m_param, &outbuf->m_pkt_38.m_status);
2323  }
2324 }
2325 #endif
2326 
2327 #ifdef CDVD_VARIANT_OSD
2328 static void
2329 cdvdfsv_rpc3_2A_readps1bootparam(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2330 {
2331  int i;
2332  u32 efbits;
2333 
2334  (void)inbuf;
2335  (void)buflen;
2336  outbuf->m_retres = 0;
2337  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2338  {
2339  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2340  outbuf->m_retres = sceCdReadPS1BootParam(outbuf->m_pkt_2A.m_out, &outbuf->m_pkt_2A.m_status);
2341  }
2342 }
2343 #endif
2344 
2345 #ifdef CDVD_VARIANT_OSD
2346 static void
2347 cdvdfsv_rpc3_2B_setfanprofile(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2348 {
2349  int i;
2350  u32 efbits;
2351 
2352  (void)buflen;
2353  outbuf->m_retres = 0;
2354  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2355  {
2356  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2357  outbuf->m_retres = sceCdSetFanProfile(inbuf->m_pkt_2B.m_param, &outbuf->m_pkt_2B.m_status);
2358  }
2359 }
2360 #endif
2361 
2362 #ifdef CDVD_VARIANT_OSD
2363 static void cdvdfsv_rpc3_2C_i_152_gettemperature(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2364 {
2365  int i;
2366  u32 efbits;
2367 
2368  (void)inbuf;
2369  (void)buflen;
2370  outbuf->m_retres = 0;
2371  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2372  {
2373  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2374  outbuf->m_retres = cdvdman_152_get_temperature(&outbuf->m_pkt_2C.m_arg1, &outbuf->m_pkt_2C.m_arg2);
2375  }
2376 }
2377 #endif
2378 
2379 #ifdef CDVD_VARIANT_OSD
2380 static void
2381 cdvdfsv_rpc3_43_readregionparams(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2382 {
2383  int i;
2384  u32 efbits;
2385 
2386  (void)inbuf;
2387  (void)buflen;
2388  outbuf->m_retres = 0;
2389  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2390  {
2391  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2392  outbuf->m_retres = sceCdReadRegionParams(outbuf->m_pkt_43.m_arg1, &outbuf->m_pkt_43.m_status);
2393  }
2394 }
2395 #endif
2396 
2397 #ifdef CDVD_VARIANT_OSD
2398 static void
2399 cdvdfsv_rpc3_44_writeregionparams(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2400 {
2401  int i;
2402  u32 efbits;
2403 
2404  (void)buflen;
2405  outbuf->m_retres = 0;
2406  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2407  {
2408  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2409  outbuf->m_retres = sceCdWriteRegionParams(
2410  inbuf->m_pkt_44.m_arg1, (u32 *)inbuf->m_pkt_44.m_arg2, (u8 *)inbuf->m_pkt_44.m_arg3, &outbuf->m_pkt_44.m_status);
2411  }
2412 }
2413 #endif
2414 
2415 #ifdef CDVD_VARIANT_XOSD
2416 static void
2417 cdvdfsv_rpc3_2F_noticegamestart(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2418 {
2419  int i;
2420  u32 efbits;
2421 
2422  (void)buflen;
2423  outbuf->m_retres = 0;
2424  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2425  {
2426  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2427  outbuf->m_retres = sceCdNoticeGameStart(inbuf->m_pkt_2F.m_arg1, &outbuf->m_pkt_2F.m_status);
2428  }
2429 }
2430 #endif
2431 
2432 #ifdef CDVD_VARIANT_OSD
2433 static void
2434 cdvdfsv_rpc3_35_setledsmode(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2435 {
2436  int i;
2437  u32 efbits;
2438 
2439  (void)buflen;
2440  outbuf->m_retres = 0;
2441  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2442  {
2443  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2444  outbuf->m_retres = sceCdSetLEDsMode(inbuf->m_pkt_35.m_param, &outbuf->m_pkt_35.m_status);
2445  }
2446 }
2447 #endif
2448 
2449 static void
2450 cdvdfsv_rpc3_01_readclock(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2451 {
2452  int i;
2453  u32 efbits;
2454 
2455  (void)inbuf;
2456  (void)buflen;
2457 
2458  outbuf->m_retres = 0;
2459  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2460  {
2461  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2462  outbuf->m_retres = sceCdReadClock(&outbuf->m_pkt_01.m_clock);
2463  }
2464 }
2465 
2466 #ifdef CDVD_VARIANT_OSD
2467 static void
2468 cdvdfsv_rpc3_02_writeclock(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2469 {
2470  int i;
2471  u32 efbits;
2472 
2473  (void)buflen;
2474 
2475  outbuf->m_retres = 0;
2476  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2477  {
2478  // Unofficial: copy to output buffer then use it
2479  memcpy(&outbuf->m_pkt_02.m_clock, &inbuf->m_pkt_02.m_clock, sizeof(sceCdCLOCK));
2480  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2481  outbuf->m_retres = sceCdWriteClock(&outbuf->m_pkt_02.m_clock);
2482  }
2483 }
2484 #endif
2485 
2486 #ifdef CDVD_VARIANT_OSD
2487 static void cdvdfsv_rpc3_08_readnvm(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2488 {
2489  int i;
2490  u32 efbits;
2491 
2492  (void)buflen;
2493  outbuf->m_retres = 0;
2494  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2495  {
2496  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2497  // Unofficial: direct to outbuf
2498  outbuf->m_retres = sceCdReadNVM(inbuf->m_pkt_08.m_address, &outbuf->m_pkt_08.m_data, &outbuf->m_pkt_08.m_status);
2499  }
2500  outbuf->m_pkt_08.m_address = inbuf->m_pkt_08.m_address;
2501 }
2502 #endif
2503 
2504 #ifdef CDVD_VARIANT_OSD
2505 static void cdvdfsv_rpc3_09_writenvm(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2506 {
2507  int i;
2508  u32 efbits;
2509 
2510  (void)buflen;
2511  outbuf->m_retres = 0;
2512  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2513  {
2514  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2515  outbuf->m_retres = sceCdWriteNVM(inbuf->m_pkt_09.m_address, inbuf->m_pkt_09.m_data, &outbuf->m_pkt_09.m_status);
2516  }
2517  outbuf->m_pkt_09.m_address = inbuf->m_pkt_09.m_address;
2518  outbuf->m_pkt_09.m_data = inbuf->m_pkt_09.m_data;
2519 }
2520 #endif
2521 
2522 #ifdef CDVD_VARIANT_OSD
2523 static void
2524 cdvdfsv_rpc3_0D_sethdmode(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2525 {
2526  (void)buflen;
2527  outbuf->m_retres = sceCdSetHDMode(inbuf->m_pkt_0D.m_mode);
2528 }
2529 #endif
2530 
2531 #ifdef CDVD_VARIANT_XOSD
2532 static void cdvdfsv_rpc3_2E_xledctl(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2533 {
2534  int i;
2535  u32 efbits;
2536 
2537  (void)buflen;
2538  outbuf->m_retres = 0;
2539  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2540  {
2541  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2542  outbuf->m_retres = sceCdXLEDCtl(
2543  inbuf->m_pkt_2E.m_arg1, inbuf->m_pkt_2E.m_arg2, &outbuf->m_pkt_2E.m_result1, &outbuf->m_pkt_2E.m_result2);
2544  }
2545 }
2546 #endif
2547 
2548 #ifdef CDVD_VARIANT_XOSD
2549 static void
2550 cdvdfsv_rpc3_39_buzzerctl(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2551 {
2552  int i;
2553  u32 efbits;
2554 
2555  (void)inbuf;
2556  (void)buflen;
2557  outbuf->m_retres = 0;
2558  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2559  {
2560  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2561  outbuf->m_retres = sceCdBuzzerCtl(&outbuf->m_pkt_39.m_status);
2562  }
2563 }
2564 #endif
2565 
2566 #ifdef CDVD_VARIANT_XOSD
2567 static void
2568 cdvdfsv_rpc3_3A_i_167_atapi2dragon(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2569 {
2570  int i;
2571  u32 efbits;
2572 
2573  (void)buflen;
2574  outbuf->m_retres = 0;
2575  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2576  {
2577  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2578  outbuf->m_retres = cdvdman_167_atapi2dragon((char *)inbuf, &outbuf->m_pkt_3A.m_arg2);
2579  }
2580 }
2581 #endif
2582 
2583 #ifdef CDVD_VARIANT_XOSD
2584 static void cdvdfsv_rpc3_3B_i_169_dragon2atapi(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2585 {
2586  int i;
2587  u32 efbits;
2588 
2589  (void)inbuf;
2590  (void)buflen;
2591  outbuf->m_retres = 0;
2592  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2593  {
2594  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2595  outbuf->m_retres = cdvdman_169_dragon2atapi(outbuf->m_pkt_3B.m_arg1, &outbuf->m_pkt_3B.m_arg2);
2596  }
2597 }
2598 #endif
2599 
2600 #ifdef CDVD_VARIANT_XOSD
2601 static void
2602 cdvdfsv_rpc3_3C_xbspowerctl(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2603 {
2604  int i;
2605  u32 efbits;
2606 
2607  (void)buflen;
2608  outbuf->m_retres = 0;
2609  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2610  {
2611  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2612  outbuf->m_retres = sceCdXBSPowerCtl(
2613  inbuf->m_pkt_3C.m_arg1, inbuf->m_pkt_3C.m_arg2, &outbuf->m_pkt_3C.m_result1, &outbuf->m_pkt_3C.m_result2);
2614  }
2615 }
2616 #endif
2617 
2618 #ifdef CDVD_VARIANT_XOSD
2619 static void
2620 cdvdfsv_rpc3_3D_setmediumremoval(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2621 {
2622  int i;
2623  u32 efbits;
2624 
2625  (void)buflen;
2626  outbuf->m_retres = 0;
2627  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2628  {
2629  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2630  outbuf->m_retres = sceCdSetMediumRemoval(inbuf->m_pkt_3D.m_arg1, &outbuf->m_pkt_3D.m_status);
2631  }
2632 }
2633 #endif
2634 
2635 #ifdef CDVD_VARIANT_XOSD
2636 static void
2637 cdvdfsv_rpc3_3E_getmediumremoval(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2638 {
2639  int i;
2640  u32 efbits;
2641 
2642  (void)inbuf;
2643  (void)buflen;
2644  outbuf->m_retres = 0;
2645  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2646  {
2647  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2648  outbuf->m_retres = sceCdGetMediumRemoval(&outbuf->m_pkt_3E.m_result1, &outbuf->m_pkt_3E.m_result2);
2649  }
2650 }
2651 #endif
2652 
2653 #ifdef CDVD_VARIANT_XOSD
2654 static void
2655 cdvdfsv_rpc3_3F_xdvrpreset(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2656 {
2657  int i;
2658  u32 efbits;
2659 
2660  (void)buflen;
2661  outbuf->m_retres = 0;
2662  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2663  {
2664  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2665  outbuf->m_retres = sceCdXDVRPReset(inbuf->m_pkt_3F.m_arg1, &outbuf->m_pkt_3F.m_status);
2666  }
2667 }
2668 #endif
2669 
2670 #ifdef CDVD_VARIANT_XOSD
2671 static void
2672 cdvdfsv_rpc3_40_getwakeupreason(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2673 {
2674  (void)inbuf;
2675  (void)buflen;
2676  outbuf->m_retres = sceCdGetWakeUpReason();
2677 }
2678 #endif
2679 
2680 #ifdef CDVD_VARIANT_OSD
2681 static void
2682 cdvdfsv_rpc3_0E_openconfig(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2683 {
2684  int i;
2685  u32 efbits;
2686 
2687  (void)buflen;
2688  outbuf->m_retres = 0;
2689  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2690  {
2691  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2692  outbuf->m_retres = sceCdOpenConfig(
2693  inbuf->m_pkt_0E.m_block, inbuf->m_pkt_0E.m_mode, inbuf->m_pkt_0E.m_NumBlocks, &outbuf->m_pkt_0E.m_status);
2694  }
2695 }
2696 #endif
2697 
2698 #ifdef CDVD_VARIANT_OSD
2699 static void
2700 cdvdfsv_rpc3_0F_closeconfig(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2701 {
2702  int i;
2703  u32 efbits;
2704 
2705  (void)inbuf;
2706  (void)buflen;
2707  outbuf->m_retres = 0;
2708  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2709  {
2710  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2711  outbuf->m_retres = sceCdCloseConfig(&outbuf->m_pkt_0F.m_status);
2712  }
2713 }
2714 #endif
2715 
2716 #ifdef CDVD_VARIANT_OSD
2717 static void
2718 cdvdfsv_rpc3_10_readconfig(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2719 {
2720  int i;
2721  u32 efbits;
2722 
2723  (void)inbuf;
2724  (void)buflen;
2725  outbuf->m_retres = 0;
2726  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2727  {
2728  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2729  outbuf->m_retres = sceCdReadConfig(outbuf->m_pkt_10.m_buffer, &outbuf->m_pkt_10.m_status);
2730  }
2731 }
2732 #endif
2733 
2734 #ifdef CDVD_VARIANT_OSD
2735 static void
2736 cdvdfsv_rpc3_11_writeconfig(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2737 {
2738  int i;
2739  u32 efbits;
2740 
2741  (void)buflen;
2742  outbuf->m_retres = 0;
2743  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2744  {
2745  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2746  outbuf->m_retres = sceCdWriteConfig(inbuf->m_pkt_11.m_buffer, &outbuf->m_pkt_11.m_status);
2747  }
2748 }
2749 #endif
2750 
2751 #ifdef CDVD_VARIANT_DNAS
2752 static void
2753 cdvdfsv_rpc5_11_readdiskid(const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf)
2754 {
2755  (void)inbuf;
2756  (void)buflen;
2757 
2758  outbuf->m_retres = sceCdReadDiskID((unsigned int *)&(outbuf->m_pkt_11.m_diskid));
2759 }
2760 
2761 static void
2762 cdvdfsv_rpc5_17_doesuniquekeyexist(const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf)
2763 {
2764  (void)inbuf;
2765  (void)buflen;
2766 
2767  outbuf->m_retres = sceCdDoesUniqueKeyExist(&outbuf->m_pkt_17.m_status);
2768 }
2769 #endif
2770 
2771 #ifdef CDVD_VARIANT_OSD
2772 static void cdvdfsv_rpc5_0B_dg(const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf)
2773 {
2774  (void)buflen;
2775  // Unofficial: write directly to output buffer
2776  outbuf->m_retres = sceCdReadKey(
2777  inbuf->m_pkt_0B.m_arg1, inbuf->m_pkt_0B.m_arg2, inbuf->m_pkt_0B.m_command, (u8 *)outbuf->m_pkt_0B.m_dg_buf);
2778 }
2779 #endif
2780 
2781 #ifdef CDVD_VARIANT_OSD
2782 static void cdvdfsv_rpc3_0A_decset(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2783 {
2784  (void)buflen;
2785  outbuf->m_retres =
2786  sceCdDecSet(inbuf->m_pkt_0A.m_enable_xor, inbuf->m_pkt_0A.m_enable_shift, inbuf->m_pkt_0A.m_shiftval);
2787 }
2788 #endif
2789 
2790 static void
2791 cdvdfsv_rpc3_0B_applyscmd(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2792 {
2793  (void)buflen;
2794 
2796  inbuf->m_pkt_0B.m_cmdNum, &inbuf->m_pkt_0B.m_inBuff, inbuf->m_pkt_0B.m_inBuffSize, &(outbuf->m_pkt_0B.m_outbuf));
2797 }
2798 
2799 static void
2800 cdvdfsv_rpc5_0C_applyncmd(const cdvdfsv_rpc5_inpacket_t *inbuf, int buflen, cdvdfsv_rpc5_outpacket_t *outbuf)
2801 {
2802  (void)buflen;
2803 
2804  outbuf->m_retres = sceCdApplyNCmd(inbuf->m_pkt_0C.m_cmdNum, &inbuf->m_pkt_0C.m_inBuff, inbuf->m_pkt_0C.m_inBuffSize);
2805  sceCdSync(2);
2806 }
2807 
2808 static void cdvdfsv_rpc3_04_geterror(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2809 {
2810  (void)inbuf;
2811  (void)buflen;
2812 
2813  outbuf->m_retres = sceCdGetError();
2814 }
2815 
2816 static void cdvdfsv_rpc3_05_trayreq(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2817 {
2818  int i;
2819  u32 efbits;
2820 
2821  (void)buflen;
2822 
2823  outbuf->m_retres = 0;
2824  for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
2825  {
2826  WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2827  outbuf->m_retres = sceCdTrayReq(inbuf->m_pkt_05.m_param, &outbuf->m_pkt_05.m_traychk);
2828  }
2829 }
2830 
2831 static void
2832 cdvdfsv_rpc3_25_settimeout(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2833 {
2834  (void)buflen;
2835 
2836  outbuf->m_retres = sceCdSetTimeout(inbuf->m_pkt_25.m_param, inbuf->m_pkt_25.m_timeout);
2837 }
2838 
2839 static void
2840 cdvdfsv_rpc3_27_readdvddualinfo(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2841 {
2842  (void)inbuf;
2843  (void)buflen;
2844 
2845  outbuf->m_retres = sceCdReadDvdDualInfo(&outbuf->m_pkt_27.m_on_dual, &outbuf->m_pkt_27.m_layer1_start);
2846 }
2847 
2848 static int cdvdfsv_rpc5_0E_diskready(void)
2849 {
2850  int is_detecting;
2851  int scres_unused;
2852 
2853  is_detecting = 0;
2854  // The following printf was added for ioprp300x
2855  VERBOSE_PRINTF(1, "sceCdNcmddiskready call\n");
2856  // The following call to sceCdGetDiskType was inlined
2857  switch ( sceCdGetDiskType() )
2858  {
2859  case SCECdDETCT:
2860  case SCECdDETCTCD:
2861  case SCECdDETCTDVDS:
2862  case SCECdDETCTDVDD:
2863  is_detecting = 1;
2864  break;
2865  default:
2866  break;
2867  }
2868  // The following call to sceCdDiskReady was inlined
2869  if (
2870  (sceCdDiskReady(8) & 0xC0) != 0x40 || sceCdSC(0xFFFFFFFD, &scres_unused) || !sceCdSC(0xFFFFFFF4, &scres_unused)
2871  || is_detecting )
2872  {
2873  VERBOSE_PRINTF(1, "Drive Not Ready\n");
2874  return 6;
2875  }
2876  // The following printf was added for ioprp300x
2877  VERBOSE_PRINTF(1, "sceCdNcmddiskready call OKend\n");
2878  return 2;
2879 }
2880 
2881 static void *cbrpc_rpc5_cdvdncmds(int fno, void *buffer, int length)
2882 {
2883  int scres_unused;
2884  int fno_1;
2885 
2886  fno_1 = fno;
2887  // Note: in ioprp300x, the following was changed from printf to Kprintf
2888  VERBOSE_KPRINTF(1, "sce_cdvd N cmd start %d\n", fno);
2889  g_cdvdfsv_rpc5flg = 1;
2890  sceCdSC(0xFFFFFFF6, &fno_1);
2891  switch ( fno )
2892  {
2893  case 1:
2894  // The following call to sceCdGetDiskType was inlined
2895  cdvdfsv_rpc5_01_readee(
2896  buffer, length, &g_crr, !(sceCdGetDiskType() ^ SCECdPS2DVD), !sceCdSC(0xFFFFFFFC, &scres_unused), 0);
2897  break;
2898  case 2:
2899  cdvdfsv_rpc5_02_readcdda(buffer, length, &g_crr, 0);
2900  break;
2901 #ifdef CDVD_VARIANT_OSD
2902  case 3:
2903  cdvdfsv_rpc5_03_readdvdv(buffer, length, &g_crr);
2904  break;
2905 #endif
2906  case 4:
2907  cdvdfsv_rpc5_04_gettoc(buffer, length, &g_crr);
2908  break;
2909  case 5:
2910  VERBOSE_PRINTF(1, "Call Seek lsn= %d\n", (int)(((const cdvdfsv_rpc5_inpacket_t *)buffer)->m_pkt_05.m_lbn));
2911  g_crr.m_retres = sceCdSeek(((const cdvdfsv_rpc5_inpacket_t *)buffer)->m_pkt_05.m_lbn);
2912  VERBOSE_PRINTF(1, "Call Seek end\n");
2913  sceCdSync(6);
2914  break;
2915  case 6:
2916  VERBOSE_PRINTF(1, "Call Standby\n");
2917  g_crr.m_retres = sceCdStandby();
2918  sceCdSync(4);
2919  VERBOSE_PRINTF(1, "Call Standby called\n");
2920  break;
2921  case 7:
2922  VERBOSE_PRINTF(1, "Call Stop\n");
2923  g_crr.m_retres = sceCdStop();
2924  sceCdSync(4);
2925  break;
2926  case 8:
2927  VERBOSE_PRINTF(1, "Call Pause\n");
2928  g_crr.m_retres = sceCdPause();
2929  sceCdSync(6);
2930  break;
2931  case 9:
2932  if ( devctl("cdrom_stm0:", 0x4396, buffer, length, &g_crr.m_retres, sizeof(g_crr.m_retres)) < 0 )
2933  g_crr.m_retres = 0;
2934  break;
2935  case 10:
2936  if ( devctl("cdrom_stm0:", 0x4398, buffer, length, &g_crr.m_retres, sizeof(g_crr.m_retres)) < 0 )
2937  g_crr.m_retres = 0;
2938  break;
2939 #ifdef CDVD_VARIANT_OSD
2940  case 11:
2941  cdvdfsv_rpc5_0B_dg(buffer, length, &g_crr);
2942  break;
2943 #endif
2944  case 12:
2945  cdvdfsv_rpc5_0C_applyncmd(buffer, length, &g_crr);
2946  break;
2947  case 13:
2948  cdvdfsv_rpc5_0D_iopmread(buffer, length, &g_crr);
2949  break;
2950  case 14:
2951  g_crr.m_retres = cdvdfsv_rpc5_0E_diskready();
2952  break;
2953  case 15:
2954  cdvdfsv_rpc5_0F_readchain(buffer, length, &g_crr);
2955  break;
2956 #ifdef CDVD_VARIANT_OSD
2957  case 16:
2958  cdvdfsv_rpc5_02_readcdda(buffer, length, &g_crr, 1);
2959  break;
2960 #endif
2961 #ifdef CDVD_VARIANT_DNAS
2962  case 17:
2963  cdvdfsv_rpc5_11_readdiskid(buffer, length, &g_crr);
2964  break;
2965 #endif
2966  case 19:
2967  // The following call to sceCdGetDiskType was inlined
2968  cdvdfsv_rpc5_01_readee(
2969  buffer, length, &g_crr, !(sceCdGetDiskType() ^ SCECdPS2DVD), 1, !g_cdvdman_istruct_ptr->m_no_dec_flag);
2970  break;
2971 #ifdef CDVD_VARIANT_DNAS
2972  case 23:
2973  cdvdfsv_rpc5_17_doesuniquekeyexist(buffer, length, &g_crr);
2974  break;
2975 #endif
2976  default:
2977  VERBOSE_PRINTF(1, "sce_cdvd no block IO :unrecognized code %x\n", fno);
2978  g_crr.m_retres = 0;
2979  break;
2980  }
2981  fno_1 = 0;
2982  sceCdSC(0xFFFFFFF6, &fno_1);
2983  g_cdvdfsv_rpc5flg = 0;
2984  // Note: in ioprp300x, the following was changed from printf to Kprintf
2985  VERBOSE_KPRINTF(1, "sce_cdvd N cmd end\n");
2986  return (void *)&g_crr;
2987 }
2988 
2989 // cppcheck-suppress constParameterCallback
2990 static void *cbrpc_rpc3_cdvdscmds(int fno, void *buffer, int length)
2991 {
2992  VERBOSE_PRINTF(1, "sce_cdvd S cmd start %d\n", fno);
2993  g_cdvdfsv_rpc3flg = 1;
2994  switch ( fno )
2995  {
2996  case 1:
2997  cdvdfsv_rpc3_01_readclock(buffer, length, &g_outbuf);
2998  break;
2999 #ifdef CDVD_VARIANT_OSD
3000  case 2:
3001  cdvdfsv_rpc3_02_writeclock(buffer, length, &g_outbuf);
3002  break;
3003 #endif
3004  case 3:
3005  cdvdfsv_rpc3_03_disktype(buffer, length, &g_outbuf);
3006  break;
3007  case 4:
3008  cdvdfsv_rpc3_04_geterror(buffer, length, &g_outbuf);
3009  break;
3010  case 5:
3011  cdvdfsv_rpc3_05_trayreq(buffer, length, &g_outbuf);
3012  break;
3013  case 6:
3014  cdvdfsv_rpc3_06_ri(buffer, length, &g_outbuf);
3015  break;
3016 #ifdef CDVD_VARIANT_OSD
3017  // Not in XOSD or DVD Player 3.11
3018  case 7:
3019  cdvdfsv_rpc3_07_wi(buffer, length, &g_outbuf);
3020  break;
3021  case 8:
3022  cdvdfsv_rpc3_08_readnvm(buffer, length, &g_outbuf);
3023  break;
3024  case 9:
3025  cdvdfsv_rpc3_09_writenvm(buffer, length, &g_outbuf);
3026  break;
3027  case 10:
3028  cdvdfsv_rpc3_0A_decset(buffer, length, &g_outbuf);
3029  break;
3030 #endif
3031  case 11:
3032  cdvdfsv_rpc3_0B_applyscmd(buffer, length, &g_outbuf);
3033  break;
3034  case 12:
3035  cdvdfsv_rpc3_0C_cdstatus(buffer, length, &g_outbuf);
3036  break;
3037 #ifdef CDVD_VARIANT_OSD
3038  case 13:
3039  cdvdfsv_rpc3_0D_sethdmode(buffer, length, &g_outbuf);
3040  break;
3041  case 14:
3042  cdvdfsv_rpc3_0E_openconfig(buffer, length, &g_outbuf);
3043  break;
3044  case 15:
3045  cdvdfsv_rpc3_0F_closeconfig(buffer, length, &g_outbuf);
3046  break;
3047  case 16:
3048  cdvdfsv_rpc3_10_readconfig(buffer, length, &g_outbuf);
3049  break;
3050  case 17:
3051  cdvdfsv_rpc3_11_writeconfig(buffer, length, &g_outbuf);
3052  break;
3053  case 18:
3054  cdvdfsv_rpc3_12_readconsoleid(buffer, length, &g_outbuf);
3055  break;
3056  // Not in XOSD or DVD Player 3.11
3057  case 19:
3058  cdvdfsv_rpc3_13_writeconsoleid(buffer, length, &g_outbuf);
3059  break;
3060  case 20:
3061  cdvdfsv_rpc3_14_getmversion(buffer, length, &g_outbuf);
3062  break;
3063 #endif
3064  case 21:
3065  cdvdfsv_rpc3_15_ctrladout(buffer, length, &g_outbuf);
3066  break;
3067  case 22:
3068  cdvdfsv_rpc3_16_break(buffer, length, &g_outbuf);
3069  break;
3070 #ifdef CDVD_VARIANT_OSD
3071  case 23:
3072  cdvdfsv_rpc3_17_readsubq(buffer, length, &g_outbuf);
3073  break;
3074  case 24:
3075  cdvdfsv_rpc3_18_forbiddvdp(buffer, length, &g_outbuf);
3076  break;
3077  case 25:
3078  cdvdfsv_rpc3_19_autoadjustctrl(buffer, length, &g_outbuf);
3079  break;
3080 #endif
3081  case 26:
3082  cdvdfsv_rpc3_1A_rm(buffer, length, &g_outbuf);
3083  break;
3084 #ifdef CDVD_VARIANT_OSD
3085  // Not in XOSD or DVD Player 3.11
3086  case 27:
3087  cdvdfsv_rpc3_1B_wm(buffer, length, &g_outbuf);
3088  break;
3089  case 28:
3090  cdvdfsv_rpc3_1C_forbidread(buffer, length, &g_outbuf);
3091  break;
3092  case 29:
3093  cdvdfsv_rpc3_1D_sc_FFFFFFF8(buffer, length, &g_outbuf);
3094  break;
3095  case 30:
3096  cdvdfsv_rpc3_1E_bootcertify(buffer, length, &g_outbuf);
3097  break;
3098  case 31:
3099  cdvdfsv_rpc3_1F_cancelpoffrdy(buffer, length, &g_outbuf);
3100  break;
3101  case 32:
3102  cdvdfsv_rpc3_20_blueledctl(buffer, length, &g_outbuf);
3103  break;
3104 #endif
3105  case 33:
3106  cdvdfsv_rpc3_21_poweroff(buffer, length, &g_outbuf);
3107  break;
3108  case 34:
3109  cdvdfsv_rpc3_22_mmode(buffer, length, &g_outbuf);
3110  break;
3111  case 35:
3112  cdvdfsv_rpc3_23_changethreadpriority(buffer, length, &g_outbuf);
3113  break;
3114 #ifdef CDVD_VARIANT_DNAS
3115  case 36:
3116  cdvdfsv_rpc3_24_readguid(buffer, length, &g_outbuf);
3117  break;
3118 #endif
3119  case 37:
3120  cdvdfsv_rpc3_25_settimeout(buffer, length, &g_outbuf);
3121  break;
3122 #ifdef CDVD_VARIANT_DNAS
3123  case 38:
3124  cdvdfsv_rpc3_26_readmodelid(buffer, length, &g_outbuf);
3125  break;
3126 #endif
3127  case 39:
3128  cdvdfsv_rpc3_27_readdvddualinfo(buffer, length, &g_outbuf);
3129  break;
3130 #ifdef CDVD_VARIANT_OSD
3131  case 40:
3132  cdvdfsv_rpc3_28_writewakeuptime(buffer, length, &g_outbuf);
3133  break;
3134  case 41:
3135  cdvdfsv_rpc3_29_readwakeuptime(buffer, length, &g_outbuf);
3136  break;
3137  case 42:
3138  cdvdfsv_rpc3_2A_readps1bootparam(buffer, length, &g_outbuf);
3139  break;
3140  case 43:
3141  cdvdfsv_rpc3_2B_setfanprofile(buffer, length, &g_outbuf);
3142  break;
3143  case 44:
3144  cdvdfsv_rpc3_2C_i_152_gettemperature(buffer, length, &g_outbuf);
3145  break;
3146 #endif
3147 #ifdef CDVD_VARIANT_XOSD
3148  case 45:
3149  cdvdfsv_rpc3_2D_chgsys(buffer, length, &g_outbuf);
3150  break;
3151  case 46:
3152  cdvdfsv_rpc3_2E_xledctl(buffer, length, &g_outbuf);
3153  break;
3154  case 47:
3155  cdvdfsv_rpc3_2F_noticegamestart(buffer, length, &g_outbuf);
3156  break;
3157 #endif
3158 #ifdef CDVD_VARIANT_OSD
3159  case 48:
3160  cdvdfsv_rpc3_30_rcbypassctl(buffer, length, &g_outbuf);
3161  break;
3162  case 49:
3163  cdvdfsv_rpc3_31_remote2_7(buffer, length, &g_outbuf);
3164  break;
3165  case 50:
3166  cdvdfsv_rpc3_32_sendscmd1d(buffer, length, &g_outbuf);
3167  break;
3168  case 53:
3169  cdvdfsv_rpc3_35_setledsmode(buffer, length, &g_outbuf);
3170  break;
3171  case 56:
3172  cdvdfsv_rpc3_38_remote2_7_get(buffer, length, &g_outbuf);
3173  break;
3174 #endif
3175 #ifdef CDVD_VARIANT_XOSD
3176  case 57:
3177  cdvdfsv_rpc3_39_buzzerctl(buffer, length, &g_outbuf);
3178  break;
3179  case 58:
3180  cdvdfsv_rpc3_3A_i_167_atapi2dragon(buffer, length, &g_outbuf);
3181  break;
3182  case 59:
3183  cdvdfsv_rpc3_3B_i_169_dragon2atapi(buffer, length, &g_outbuf);
3184  break;
3185  case 60:
3186  cdvdfsv_rpc3_3C_xbspowerctl(buffer, length, &g_outbuf);
3187  break;
3188  case 61:
3189  cdvdfsv_rpc3_3D_setmediumremoval(buffer, length, &g_outbuf);
3190  break;
3191  case 62:
3192  cdvdfsv_rpc3_3E_getmediumremoval(buffer, length, &g_outbuf);
3193  break;
3194  case 63:
3195  cdvdfsv_rpc3_3F_xdvrpreset(buffer, length, &g_outbuf);
3196  break;
3197  case 64:
3198  cdvdfsv_rpc3_40_getwakeupreason(buffer, length, &g_outbuf);
3199  break;
3200 #endif
3201 #ifdef CDVD_VARIANT_OSD
3202  case 67:
3203  cdvdfsv_rpc3_43_readregionparams(buffer, length, &g_outbuf);
3204  break;
3205  // Not in XOSD or DVD Player 3.11
3206  case 68:
3207  cdvdfsv_rpc3_44_writeregionparams(buffer, length, &g_outbuf);
3208  break;
3209 #endif
3210  default:
3211  VERBOSE_PRINTF(1, "sce_cdvd block IO :unrecognized code 0x%02x\n", fno);
3212  g_outbuf.m_retres = 0;
3213  break;
3214  }
3215  VERBOSE_PRINTF(1, "sce_cdvd S cmd end\n");
3216  g_cdvdfsv_rpc3flg = 0;
3217  return (void *)&g_outbuf;
3218 }
3219 
3220 static void cdvdfsv_poffloop(void)
3221 {
3222  int trid;
3223  char cmdpkt[16];
3224  int scres;
3225  u32 efbits;
3226 
3227  g_cdvdman_intr_evfid = sceCdSC(0xFFFFFFF5, &scres);
3228  while ( 1 )
3229  {
3230  ClearEventFlag(g_cdvdman_intr_evfid, ~4);
3231  WaitEventFlag(g_cdvdman_intr_evfid, 4, WEF_AND, &efbits);
3232  if ( g_cdvdfsv_nopocm )
3233  break;
3234  if ( !g_cdvdfsv_plbreak )
3235  {
3236  while ( 1 )
3237  {
3238  trid = sceSifSendCmd(0x80000012, cmdpkt, sizeof(cmdpkt), 0, 0, 0);
3239  if ( trid )
3240  break;
3241  DelayThread(500);
3242  }
3243  while ( cdvdfsv_checkdmastat(trid) >= 0 )
3244  ;
3245  }
3246  }
3247 }
3248 
3249 #ifdef CDVD_VARIANT_OSD
3250 static void cdvdfsv_rpc4_th(void *arg)
3251 {
3252  int trid;
3253  char cmdpkt[16];
3254  int scres;
3255  u32 efbits;
3256 
3257  (void)arg;
3258  g_cdvdman_intr_evfid = sceCdSC(0xFFFFFFF5, &scres);
3259  while ( 1 )
3260  {
3261  ClearEventFlag(g_cdvdman_intr_evfid, ~0x40);
3262  WaitEventFlag(g_cdvdman_intr_evfid, 0x40, WEF_AND, &efbits);
3263  if ( g_cdvdfsv_nopocm )
3264  break;
3265  if ( !g_cdvdfsv_plbreak )
3266  {
3267  while ( 1 )
3268  {
3269  trid = sceSifSendCmd(0x80000015, cmdpkt, sizeof(cmdpkt), 0, 0, 0);
3270  if ( trid )
3271  break;
3272  DelayThread(500);
3273  }
3274  while ( cdvdfsv_checkdmastat(trid) >= 0 )
3275  ;
3276  }
3277  }
3278  ExitDeleteThread();
3279 }
3280 #endif
3281 
3282 #ifdef CDVD_VARIANT_OSD
3283 static void cdvdfsv_rpc5_th(void *arg)
3284 {
3285  int trid;
3286  char cmdpkt[16];
3287  int scres;
3288  u32 efbits;
3289 
3290  (void)arg;
3291  g_cdvdman_intr_evfid = sceCdSC(0xFFFFFFF5, &scres);
3292  while ( 1 )
3293  {
3294  ClearEventFlag(g_cdvdman_intr_evfid, ~0x80);
3295  WaitEventFlag(g_cdvdman_intr_evfid, 0x80, WEF_AND, &efbits);
3296  if ( g_cdvdfsv_nopocm )
3297  break;
3298  if ( !g_cdvdfsv_plbreak )
3299  {
3300  while ( 1 )
3301  {
3302  trid = sceSifSendCmd(0x80000016, cmdpkt, sizeof(cmdpkt), 0, 0, 0);
3303  if ( trid )
3304  break;
3305  DelayThread(500);
3306  }
3307  while ( cdvdfsv_checkdmastat(trid) >= 0 )
3308  ;
3309  }
3310  }
3311  ExitDeleteThread();
3312 }
3313 #endif
3314 
3315 static void cdvdfsv_rpc1_th(void *arg)
3316 {
3317  (void)arg;
3318 
3319  sceSifSetRpcQueue(&g_rpc_qdata1, GetThreadId());
3320  sceSifRegisterRpc(&g_rpc_sdata1, 0x80000592, cbrpc_rpc1_cdinit, g_rpc_buffer1, 0, 0, &g_rpc_qdata1);
3321  sceSifRegisterRpc(&g_rpc_sdata2, 0x8000059A, cbrpc_rpc2_diskready, g_rpc_buffer2, 0, 0, &g_rpc_qdata1);
3322  sceSifRegisterRpc(&g_rpc_sdata3, 0x80000593, cbrpc_rpc3_cdvdscmds, g_rpc_buffer3, 0, 0, &g_rpc_qdata1);
3323  sceSifRpcLoop(&g_rpc_qdata1);
3324  ExitDeleteThread();
3325 }
3326 
3327 static void cdvdfsv_rpc3_th(void *arg)
3328 {
3329  (void)arg;
3330 
3331  sceSifSetRpcQueue(&g_rpc_qdata3, GetThreadId());
3332  sceSifRegisterRpc(&g_rpc_sdata6, 0x8000059C, cbrpc_rpc2_diskready, g_rpc_buffer2, 0, 0, &g_rpc_qdata3);
3333  sceSifRpcLoop(&g_rpc_qdata3);
3334  ExitDeleteThread();
3335 }
3336 
3337 static void cdvdfsv_rpc2_th(void *arg)
3338 {
3339  (void)arg;
3340 
3341  sceSifSetRpcQueue(&g_rpc_qdata2, GetThreadId());
3342  sceSifRegisterRpc(&g_rpc_sdata4, 0x80000597, cbrpc_rpc4_fscall, g_rpc_buffer4, 0, 0, &g_rpc_qdata2);
3343  sceSifRegisterRpc(&g_rpc_sdata5, 0x80000595, cbrpc_rpc5_cdvdncmds, g_rpc_buffer5, 0, 0, &g_rpc_qdata2);
3344  sceSifRpcLoop(&g_rpc_qdata2);
3345  ExitDeleteThread();
3346 }
3347 
3348 // Unofficial: unused obfuscation code was removed
3349 
3350 // clang-format off
3351 __asm__ (
3352  "\t" ".set push" "\n"
3353  "\t" ".set noat" "\n"
3354  "\t" ".set noreorder" "\n"
3355  "\t" ".global optimized_memcpy" "\n"
3356  "\t" "optimized_memcpy:" "\n"
3357  "\t" " srl $a3, $a2, 2" "\n"
3358  "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3359  "\t" " or $a3, $a0, $a1" "\n"
3360  "\t" " andi $a3, $a3, 0x3" "\n"
3361  "\t" " bnez $a3, .Loptimized_memcpy_3" "\n"
3362  "\t" " nop" "\n"
3363  "\t" " srl $a3, $a2, 2" "\n"
3364  "\t" " addiu $at, $zero, 0xC" "\n"
3365  "\t" " div $zero, $a3, $at" "\n"
3366  "\t" " mflo $a3" "\n"
3367  "\t" " mfhi $v1" "\n"
3368  "\t" " beqz $v1, .Loptimized_memcpy_2" "\n"
3369  "\t" " nop" "\n"
3370  "\t" ".Loptimized_memcpy_1:" "\n"
3371  "\t" " lw $v0, 0x0($a1)" "\n"
3372  "\t" " addiu $v1, $v1, -0x1" "\n"
3373  "\t" " sw $v0, 0x0($a0)" "\n"
3374  "\t" " addiu $a1, $a1, 0x4" "\n"
3375  "\t" " bnez $v1, .Loptimized_memcpy_1" "\n"
3376  "\t" " addiu $a0, $a0, 0x4" "\n"
3377  "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3378  "\t" " nop" "\n"
3379  "\t" ".Loptimized_memcpy_2:" "\n"
3380  "\t" " lw $v0, 0x0($a1)" "\n"
3381  "\t" " lw $v1, 0x4($a1)" "\n"
3382  "\t" " lw $t0, 0x8($a1)" "\n"
3383  "\t" " lw $t1, 0xC($a1)" "\n"
3384  "\t" " lw $t2, 0x10($a1)" "\n"
3385  "\t" " lw $t3, 0x14($a1)" "\n"
3386  "\t" " lw $t4, 0x18($a1)" "\n"
3387  "\t" " lw $t5, 0x1C($a1)" "\n"
3388  "\t" " lw $t6, 0x20($a1)" "\n"
3389  "\t" " lw $t7, 0x24($a1)" "\n"
3390  "\t" " lw $t8, 0x28($a1)" "\n"
3391  "\t" " lw $t9, 0x2C($a1)" "\n"
3392  "\t" " addiu $a3, $a3, -0x1" "\n"
3393  "\t" " sw $v0, 0x0($a0)" "\n"
3394  "\t" " sw $v1, 0x4($a0)" "\n"
3395  "\t" " sw $t0, 0x8($a0)" "\n"
3396  "\t" " sw $t1, 0xC($a0)" "\n"
3397  "\t" " sw $t2, 0x10($a0)" "\n"
3398  "\t" " sw $t3, 0x14($a0)" "\n"
3399  "\t" " sw $t4, 0x18($a0)" "\n"
3400  "\t" " sw $t5, 0x1C($a0)" "\n"
3401  "\t" " sw $t6, 0x20($a0)" "\n"
3402  "\t" " sw $t7, 0x24($a0)" "\n"
3403  "\t" " sw $t8, 0x28($a0)" "\n"
3404  "\t" " sw $t9, 0x2C($a0)" "\n"
3405  "\t" " addiu $a1, $a1, 0x30" "\n"
3406  "\t" " bnez $a3, .Loptimized_memcpy_2" "\n"
3407  "\t" " addiu $a0, $a0, 0x30" "\n"
3408  "\t" " j .Loptimized_memcpy_12" "\n"
3409  "\t" " nop" "\n"
3410  "\t" ".Loptimized_memcpy_3:" "\n"
3411  "\t" " andi $a3, $a0, 0x3" "\n"
3412  "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3413  "\t" " andi $a3, $a1, 0x3" "\n"
3414  "\t" " beqz $a3, .Loptimized_memcpy_6" "\n"
3415  "\t" " nop" "\n"
3416  "\t" " srl $a3, $a2, 2" "\n"
3417  "\t" " addiu $at, $zero, 0xC" "\n"
3418  "\t" " div $zero, $a3, $at" "\n"
3419  "\t" " mflo $a3" "\n"
3420  "\t" " mfhi $v1" "\n"
3421  "\t" " beqz $v1, .Loptimized_memcpy_5" "\n"
3422  "\t" " nop" "\n"
3423  "\t" ".Loptimized_memcpy_4:" "\n"
3424  "\t" " lwl $v0, 0x3($a1)" "\n"
3425  "\t" " lwr $v0, 0x0($a1)" "\n"
3426  "\t" " addiu $v1, $v1, -0x1" "\n"
3427  "\t" " swl $v0, 0x3($a0)" "\n"
3428  "\t" " swr $v0, 0x0($a0)" "\n"
3429  "\t" " addiu $a1, $a1, 0x4" "\n"
3430  "\t" " bnez $v1, .Loptimized_memcpy_4" "\n"
3431  "\t" " addiu $a0, $a0, 0x4" "\n"
3432  "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3433  "\t" " nop" "\n"
3434  "\t" ".Loptimized_memcpy_5:" "\n"
3435  "\t" " lwl $v0, 0x3($a1)" "\n"
3436  "\t" " lwr $v0, 0x0($a1)" "\n"
3437  "\t" " lwl $v1, 0x7($a1)" "\n"
3438  "\t" " lwr $v1, 0x4($a1)" "\n"
3439  "\t" " lwl $t0, 0xB($a1)" "\n"
3440  "\t" " lwr $t0, 0x8($a1)" "\n"
3441  "\t" " lwl $t1, 0xF($a1)" "\n"
3442  "\t" " lwr $t1, 0xC($a1)" "\n"
3443  "\t" " lwl $t2, 0x13($a1)" "\n"
3444  "\t" " lwr $t2, 0x10($a1)" "\n"
3445  "\t" " lwl $t3, 0x17($a1)" "\n"
3446  "\t" " lwr $t3, 0x14($a1)" "\n"
3447  "\t" " lwl $t4, 0x1B($a1)" "\n"
3448  "\t" " lwr $t4, 0x18($a1)" "\n"
3449  "\t" " lwl $t5, 0x1F($a1)" "\n"
3450  "\t" " lwr $t5, 0x1C($a1)" "\n"
3451  "\t" " lwl $t6, 0x23($a1)" "\n"
3452  "\t" " lwr $t6, 0x20($a1)" "\n"
3453  "\t" " lwl $t7, 0x27($a1)" "\n"
3454  "\t" " lwr $t7, 0x24($a1)" "\n"
3455  "\t" " lwl $t8, 0x2B($a1)" "\n"
3456  "\t" " lwr $t8, 0x28($a1)" "\n"
3457  "\t" " lwl $t9, 0x2F($a1)" "\n"
3458  "\t" " lwr $t9, 0x2C($a1)" "\n"
3459  "\t" " addiu $a3, $a3, -0x1" "\n"
3460  "\t" " swl $v0, 0x3($a0)" "\n"
3461  "\t" " swr $v0, 0x0($a0)" "\n"
3462  "\t" " swl $v1, 0x7($a0)" "\n"
3463  "\t" " swr $v1, 0x4($a0)" "\n"
3464  "\t" " swl $t0, 0xB($a0)" "\n"
3465  "\t" " swr $t0, 0x8($a0)" "\n"
3466  "\t" " swl $t1, 0xF($a0)" "\n"
3467  "\t" " swr $t1, 0xC($a0)" "\n"
3468  "\t" " swl $t2, 0x13($a0)" "\n"
3469  "\t" " swr $t2, 0x10($a0)" "\n"
3470  "\t" " swl $t3, 0x17($a0)" "\n"
3471  "\t" " swr $t3, 0x14($a0)" "\n"
3472  "\t" " swl $t4, 0x1B($a0)" "\n"
3473  "\t" " swr $t4, 0x18($a0)" "\n"
3474  "\t" " swl $t5, 0x1F($a0)" "\n"
3475  "\t" " swr $t5, 0x1C($a0)" "\n"
3476  "\t" " swl $t6, 0x23($a0)" "\n"
3477  "\t" " swr $t6, 0x20($a0)" "\n"
3478  "\t" " swl $t7, 0x27($a0)" "\n"
3479  "\t" " swr $t7, 0x24($a0)" "\n"
3480  "\t" " swl $t8, 0x2B($a0)" "\n"
3481  "\t" " swr $t8, 0x28($a0)" "\n"
3482  "\t" " swl $t9, 0x2F($a0)" "\n"
3483  "\t" " swr $t9, 0x2C($a0)" "\n"
3484  "\t" " addiu $a1, $a1, 0x30" "\n"
3485  "\t" " bnez $a3, .Loptimized_memcpy_5" "\n"
3486  "\t" " addiu $a0, $a0, 0x30" "\n"
3487  "\t" " j .Loptimized_memcpy_12" "\n"
3488  "\t" " nop" "\n"
3489  "\t" ".Loptimized_memcpy_6:" "\n"
3490  "\t" " andi $a3, $a0, 0x3" "\n"
3491  "\t" " beqz $a3, .Loptimized_memcpy_9" "\n"
3492  "\t" " nop" "\n"
3493  "\t" " srl $a3, $a2, 2" "\n"
3494  "\t" " addiu $at, $zero, 0xC" "\n"
3495  "\t" " div $zero, $a3, $at" "\n"
3496  "\t" " mflo $a3" "\n"
3497  "\t" " mfhi $v1" "\n"
3498  "\t" " beqz $v1, .Loptimized_memcpy_8" "\n"
3499  "\t" " nop" "\n"
3500  "\t" ".Loptimized_memcpy_7:" "\n"
3501  "\t" " lw $v0, 0x0($a1)" "\n"
3502  "\t" " addiu $v1, $v1, -0x1" "\n"
3503  "\t" " swl $v0, 0x3($a0)" "\n"
3504  "\t" " swr $v0, 0x0($a0)" "\n"
3505  "\t" " addiu $a1, $a1, 0x4" "\n"
3506  "\t" " bnez $v1, .Loptimized_memcpy_7" "\n"
3507  "\t" " addiu $a0, $a0, 0x4" "\n"
3508  "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3509  "\t" " nop" "\n"
3510  "\t" ".Loptimized_memcpy_8:" "\n"
3511  "\t" " lw $v0, 0x0($a1)" "\n"
3512  "\t" " lw $v1, 0x4($a1)" "\n"
3513  "\t" " lw $t0, 0x8($a1)" "\n"
3514  "\t" " lw $t1, 0xC($a1)" "\n"
3515  "\t" " lw $t2, 0x10($a1)" "\n"
3516  "\t" " lw $t3, 0x14($a1)" "\n"
3517  "\t" " lw $t4, 0x18($a1)" "\n"
3518  "\t" " lw $t5, 0x1C($a1)" "\n"
3519  "\t" " lw $t6, 0x20($a1)" "\n"
3520  "\t" " lw $t7, 0x24($a1)" "\n"
3521  "\t" " lw $t8, 0x28($a1)" "\n"
3522  "\t" " lw $t9, 0x2C($a1)" "\n"
3523  "\t" " addiu $a3, $a3, -0x1" "\n"
3524  "\t" " swl $v0, 0x3($a0)" "\n"
3525  "\t" " swr $v0, 0x0($a0)" "\n"
3526  "\t" " swl $v1, 0x7($a0)" "\n"
3527  "\t" " swr $v1, 0x4($a0)" "\n"
3528  "\t" " swl $t0, 0xB($a0)" "\n"
3529  "\t" " swr $t0, 0x8($a0)" "\n"
3530  "\t" " swl $t1, 0xF($a0)" "\n"
3531  "\t" " swr $t1, 0xC($a0)" "\n"
3532  "\t" " swl $t2, 0x13($a0)" "\n"
3533  "\t" " swr $t2, 0x10($a0)" "\n"
3534  "\t" " swl $t3, 0x17($a0)" "\n"
3535  "\t" " swr $t3, 0x14($a0)" "\n"
3536  "\t" " swl $t4, 0x1B($a0)" "\n"
3537  "\t" " swr $t4, 0x18($a0)" "\n"
3538  "\t" " swl $t5, 0x1F($a0)" "\n"
3539  "\t" " swr $t5, 0x1C($a0)" "\n"
3540  "\t" " swl $t6, 0x23($a0)" "\n"
3541  "\t" " swr $t6, 0x20($a0)" "\n"
3542  "\t" " swl $t7, 0x27($a0)" "\n"
3543  "\t" " swr $t7, 0x24($a0)" "\n"
3544  "\t" " swl $t8, 0x2B($a0)" "\n"
3545  "\t" " swr $t8, 0x28($a0)" "\n"
3546  "\t" " swl $t9, 0x2F($a0)" "\n"
3547  "\t" " swr $t9, 0x2C($a0)" "\n"
3548  "\t" " addiu $a1, $a1, 0x30" "\n"
3549  "\t" " bnez $a3, .Loptimized_memcpy_8" "\n"
3550  "\t" " addiu $a0, $a0, 0x30" "\n"
3551  "\t" " j .Loptimized_memcpy_12" "\n"
3552  "\t" " nop" "\n"
3553  "\t" ".Loptimized_memcpy_9:" "\n"
3554  "\t" " srl $a3, $a2, 2" "\n"
3555  "\t" " addiu $at, $zero, 0xC" "\n"
3556  "\t" " div $zero, $a3, $at" "\n"
3557  "\t" " mflo $a3" "\n"
3558  "\t" " mfhi $v1" "\n"
3559  "\t" " beqz $v1, .Loptimized_memcpy_11" "\n"
3560  "\t" " nop" "\n"
3561  "\t" ".Loptimized_memcpy_10:" "\n"
3562  "\t" " lwl $v0, 0x3($a1)" "\n"
3563  "\t" " lwr $v0, 0x0($a1)" "\n"
3564  "\t" " addiu $v1, $v1, -0x1" "\n"
3565  "\t" " sw $v0, 0x0($a0)" "\n"
3566  "\t" " addiu $a1, $a1, 0x4" "\n"
3567  "\t" " bnez $v1, .Loptimized_memcpy_10" "\n"
3568  "\t" " addiu $a0, $a0, 0x4" "\n"
3569  "\t" " beqz $a3, .Loptimized_memcpy_12" "\n"
3570  "\t" " nop" "\n"
3571  "\t" ".Loptimized_memcpy_11:" "\n"
3572  "\t" " lwl $v0, 0x3($a1)" "\n"
3573  "\t" " lwr $v0, 0x0($a1)" "\n"
3574  "\t" " lwl $v1, 0x7($a1)" "\n"
3575  "\t" " lwr $v1, 0x4($a1)" "\n"
3576  "\t" " lwl $t0, 0xB($a1)" "\n"
3577  "\t" " lwr $t0, 0x8($a1)" "\n"
3578  "\t" " lwl $t1, 0xF($a1)" "\n"
3579  "\t" " lwr $t1, 0xC($a1)" "\n"
3580  "\t" " lwl $t2, 0x13($a1)" "\n"
3581  "\t" " lwr $t2, 0x10($a1)" "\n"
3582  "\t" " lwl $t3, 0x17($a1)" "\n"
3583  "\t" " lwr $t3, 0x14($a1)" "\n"
3584  "\t" " lwl $t4, 0x1B($a1)" "\n"
3585  "\t" " lwr $t4, 0x18($a1)" "\n"
3586  "\t" " lwl $t5, 0x1F($a1)" "\n"
3587  "\t" " lwr $t5, 0x1C($a1)" "\n"
3588  "\t" " lwl $t6, 0x23($a1)" "\n"
3589  "\t" " lwr $t6, 0x20($a1)" "\n"
3590  "\t" " lwl $t7, 0x27($a1)" "\n"
3591  "\t" " lwr $t7, 0x24($a1)" "\n"
3592  "\t" " lwl $t8, 0x2B($a1)" "\n"
3593  "\t" " lwr $t8, 0x28($a1)" "\n"
3594  "\t" " lwl $t9, 0x2F($a1)" "\n"
3595  "\t" " lwr $t9, 0x2C($a1)" "\n"
3596  "\t" " addiu $a3, $a3, -0x1" "\n"
3597  "\t" " sw $v0, 0x0($a0)" "\n"
3598  "\t" " sw $v1, 0x4($a0)" "\n"
3599  "\t" " sw $t0, 0x8($a0)" "\n"
3600  "\t" " sw $t1, 0xC($a0)" "\n"
3601  "\t" " sw $t2, 0x10($a0)" "\n"
3602  "\t" " sw $t3, 0x14($a0)" "\n"
3603  "\t" " sw $t4, 0x18($a0)" "\n"
3604  "\t" " sw $t5, 0x1C($a0)" "\n"
3605  "\t" " sw $t6, 0x20($a0)" "\n"
3606  "\t" " sw $t7, 0x24($a0)" "\n"
3607  "\t" " sw $t8, 0x28($a0)" "\n"
3608  "\t" " sw $t9, 0x2C($a0)" "\n"
3609  "\t" " addiu $a1, $a1, 0x30" "\n"
3610  "\t" " bnez $a3, .Loptimized_memcpy_11" "\n"
3611  "\t" " addiu $a0, $a0, 0x30" "\n"
3612  "\t" ".Loptimized_memcpy_12:" "\n"
3613  "\t" " andi $v1, $a2, 0x3" "\n"
3614  "\t" " beqz $v1, .Loptimized_memcpy_14" "\n"
3615  "\t" " nop" "\n"
3616  "\t" ".Loptimized_memcpy_13:" "\n"
3617  "\t" " lb $v0, 0x0($a1)" "\n"
3618  "\t" " addiu $v1, $v1, -0x1" "\n"
3619  "\t" " sb $v0, 0x0($a0)" "\n"
3620  "\t" " addiu $a1, $a1, 0x1" "\n"
3621  "\t" " bnez $v1, .Loptimized_memcpy_13" "\n"
3622  "\t" " addiu $a0, $a0, 0x1" "\n"
3623  "\t" ".Loptimized_memcpy_14:" "\n"
3624  "\t" " addu $v0, $a2, $zero" "\n"
3625  "\t" " jr $ra" "\n"
3626  "\t" " nop" "\n"
3627  "\t" ".set pop" "\n"
3628 );
3629 // clang-format on
sceCdReadSUBQ
int sceCdReadSUBQ(void *buffer, u32 *status)
sceCdlLOCCD::sector
u8 sector
Definition: libcdvd-common.h:228
sceRemote2_7Get
int sceRemote2_7Get(u32 *param, u32 *status)
sceCdNoticeGameStart
int sceCdNoticeGameStart(u8 arg1, u32 *result)
cdvdfsv_rpc5_inpacket_
Definition: libcdvd-rpc.h:822
sceCdPowerOff
int sceCdPowerOff(u32 *result)
Definition: cdvdman.c:7560
sceCdDoesUniqueKeyExist
int sceCdDoesUniqueKeyExist(u32 *status)
sceCdOpenConfig
int sceCdOpenConfig(int block, int mode, int NumBlocks, u32 *status)
sceCdSetHDMode
int sceCdSetHDMode(u32 mode)
_ModuleInfo::newflags
u16 newflags
Definition: loadcore.h:36
libcdvd-rpc.h
sceCdBootCertify
int sceCdBootCertify(const u8 *romname)
sceCdCtrlADout
int sceCdCtrlADout(int mode, u32 *status)
Definition: cdvdman.c:7592
sceCdReadWakeUpTime
int sceCdReadWakeUpTime(sceCdCLOCK *clock, u16 *userdata, u32 *wakeupreason, int *flags)
sceCdSetTimeout
int sceCdSetTimeout(int param, int timeout)
Definition: cdvdman.c:2066
sceCdGetMediumRemoval
int sceCdGetMediumRemoval(u32 *result1, u32 *result2)
sceCdWriteConfig
int sceCdWriteConfig(const void *buffer, u32 *result)
sceCdXDVRPReset
int sceCdXDVRPReset(u8 arg1, u32 *result)
sceCdSync
int sceCdSync(int mode)
Definition: cdi.c:109
sceCdTrayReq
int sceCdTrayReq(int param, u32 *traychk)
Definition: cdi.c:162
sceCdRChain
Definition: libcdvd-common.h:245
sceCdReadModelID
int sceCdReadModelID(unsigned int *id)
cdvdman_169_dragon2atapi
int cdvdman_169_dragon2atapi(u8 *outbuf, u32 *status)
sceCdReadKey
int sceCdReadKey(unsigned char arg1, unsigned char arg2, unsigned int command, unsigned char *key)
sceCdBlueLEDCtl
int sceCdBlueLEDCtl(u8 control, u32 *result)
TH_SELF
#define TH_SELF
Definition: kernel.h:68
sceCdCLOCK
Definition: libcdvd-common.h:188
sceCdBreak
int sceCdBreak(void)
Definition: cdi.c:25
DisableIntr
int DisableIntr(int irq, int *res)
Definition: intrman.c:385
sceCdRChain::sectors
u32 sectors
Definition: libcdvd-common.h:250
sceCdStandby
int sceCdStandby(void)
Definition: cdi.c:147
QueryIntrContext
int QueryIntrContext(void)
sceCdGetDiskType
int sceCdGetDiskType(void)
Definition: cdi.c:35
cdvd-ioctl.h
sceCdRM
int sceCdRM(char *buffer, u32 *status)
Definition: cdvdman.c:7279
sceCdlLOCCD::second
u8 second
Definition: libcdvd-common.h:226
CpuSuspendIntr
int CpuSuspendIntr(int *state)
Definition: intrman.c:195
sceCdReadDvdDualInfo
int sceCdReadDvdDualInfo(int *on_dual, unsigned int *layer1_start)
Definition: cdvdman.c:4517
_iop_library
Definition: loadcore.h:68
SCECdDVDVR
@ SCECdDVDVR
Definition: libcdvd-common.h:133
sceCdForbidRead
int sceCdForbidRead(u32 *result)
cdvdman_152_get_temperature
int cdvdman_152_get_temperature(u32 *param, u32 *status)
sceRemote2_7
int sceRemote2_7(u16 param, u32 *status)
sceCdWriteRegionParams
int sceCdWriteRegionParams(u8 arg1, u32 *arg2, u8 *arg3, u32 *result)
sceCdWriteNVM
int sceCdWriteNVM(u32 address, u16 data, u8 *result)
sceCdRE
int sceCdRE(unsigned int lsn, unsigned int sectors, void *buf, sceCdRMode *mode)
Definition: cdvdman.c:6853
sceCdlFILE
Definition: libcdvd-common.h:208
cdvdfsv_rpc4_inpacket_
Definition: libcdvd-rpc.h:121
SCECdPS2DVD
@ SCECdPS2DVD
Definition: libcdvd-common.h:130
cdvdfsv_rpc2_inpacket_
Definition: libcdvd-rpc.h:77
sceCdGetError
int sceCdGetError(void)
Definition: cdi.c:40
sceCdApplyNCmd
int sceCdApplyNCmd(u8 cmdNum, const void *inBuff, u16 inBuffSize)
Definition: cdvdman.c:6079
sceCdXBSPowerCtl
int sceCdXBSPowerCtl(u8 arg1, u8 arg2, u32 *result1, u32 *result2)
SCECdDETCT
@ SCECdDETCT
Definition: libcdvd-common.h:114
sceCdReadNVM
int sceCdReadNVM(u32 address, u16 *data, u8 *result)
sceCdReadPS1BootParam
int sceCdReadPS1BootParam(u8 *out, u32 *result)
sceCdMV
int sceCdMV(u8 *buffer, u32 *status)
Definition: cdvdman.c:7386
sceCdForbidDVDP
int sceCdForbidDVDP(u32 *result)
cdvdman_167_atapi2dragon
int cdvdman_167_atapi2dragon(u8 *inbuf, u32 *status)
irx_export_table
Definition: irx.h:90
sceCdChgSys
int sceCdChgSys(u32 arg1)
sceCdWriteConsoleID
int sceCdWriteConsoleID(const u8 *buffer, u32 *status)
sceCdPause
int sceCdPause(void)
Definition: cdi.c:93
sceCdSendSCmd1D
int sceCdSendSCmd1D(int *arg1, unsigned int *arg2, unsigned int *arg3, u32 *status)
_iop_thread
Definition: thbase.h:39
sceCdReadGUID
int sceCdReadGUID(u64 *guid)
sceCdInit
int sceCdInit(int mode)
Definition: cdi.c:64
t_SifDmaTransfer
Definition: sifdma.h:52
sceCdCloseConfig
int sceCdCloseConfig(u32 *result)
CpuResumeIntr
int CpuResumeIntr(int state)
Definition: intrman.c:217
sceCdCancelPOffRdy
int sceCdCancelPOffRdy(u32 *result)
Definition: cdvdman.c:7531
cdvdfsv_rpc4_outpacket_
Definition: libcdvd-rpc.h:128
SCECdErIPI
@ SCECdErIPI
Definition: libcdvd-common.h:89
cdvdfsv_rpc2_outpacket_
Definition: libcdvd-rpc.h:82
cdvdfsv_rpc1_outpacket_
Definition: libcdvd-rpc.h:69
sceCdMmode
int sceCdMmode(int media)
Definition: cdi.c:86
t_SifRpcServerData
Definition: sifrpc-common.h:98
sceCdXLEDCtl
int sceCdXLEDCtl(u8 arg1, u8 arg2, u32 *result1, u32 *result2)
sceCdStop
int sceCdStop(void)
Definition: cdi.c:157
sceCdPosToInt
u32 sceCdPosToInt(sceCdlLOCCD *p)
Definition: cdvdman.c:2411
sceCdGetReadPos
u32 sceCdGetReadPos(void)
Definition: cdi.c:45
cdvdfsv_unaligned_data_outpacket_
Definition: libcdvd-rpc.h:87
sceCdSearchFile
int sceCdSearchFile(sceCdlFILE *file, const char *name)
Definition: cdi.c:114
t_SifRpcDataQueue
Definition: sifrpc-common.h:153
sceCdRV
int sceCdRV(u32 lsn, u32 sectors, void *buf, sceCdRMode *mode, int arg5, void *cb)
Definition: cdvdman.c:7127
sceCdChangeThreadPriority
int sceCdChangeThreadPriority(int priority)
Definition: cdvdfsv.c:315
sceCdRMode::datapattern
u8 datapattern
Definition: libcdvd-common.h:240
sceCdReadFull
int sceCdReadFull(unsigned int lsn, unsigned int sectors, void *buf, sceCdRMode *mode)
sceCdWriteClock
int sceCdWriteClock(sceCdCLOCK *clock)
sceCdGetWakeUpReason
int sceCdGetWakeUpReason(void)
sceCdSetFanProfile
int sceCdSetFanProfile(u8 param, u32 *result)
sceCdSeek
int sceCdSeek(u32 lbn)
Definition: cdi.c:142
sceCdWriteWakeUpTime
int sceCdWriteWakeUpTime(const sceCdCLOCK *clock, u16 userdata, int flags)
sceCdAutoAdjustCtrl
int sceCdAutoAdjustCtrl(int mode, u32 *result)
SCECdErNO
@ SCECdErNO
Definition: libcdvd-common.h:73
sceCdReadRegionParams
int sceCdReadRegionParams(u32 *arg1, u32 *result)
sceCdReadClock
int sceCdReadClock(sceCdCLOCK *clock)
Definition: cdvdman.c:7934
cdvdman_internal_struct_
Definition: cdvdman.h:64
SCECdErEOM
@ SCECdErEOM
Definition: libcdvd-common.h:100
sceCdReadDiskID
int sceCdReadDiskID(unsigned int *id)
sceCdlLOCCD::minute
u8 minute
Definition: libcdvd-common.h:224
sceCdRMode
Definition: libcdvd-common.h:233
sceCdSetMediumRemoval
int sceCdSetMediumRemoval(u8 arg1, u32 *result)
sceCdRcBypassCtl
int sceCdRcBypassCtl(int mode, u32 *status)
sceCdReadConfig
int sceCdReadConfig(void *buffer, u32 *result)
SCECdDVDV
@ SCECdDVDV
Definition: libcdvd-common.h:137
sceCdDiskReady
int sceCdDiskReady(int mode)
Definition: cdi.c:30
cdvdfsv_rpc1_inpacket_
Definition: libcdvd-rpc.h:64
sceCdlLOCCD
Definition: libcdvd-common.h:221
cdvdfsv_rpc3_outpacket_
Definition: libcdvd-rpc.h:684
cdvdfsv_rpc5_outpacket_
Definition: libcdvd-rpc.h:863
sceCdWM
int sceCdWM(const char *buffer, u32 *status)
sceCdLayerSearchFile
int sceCdLayerSearchFile(sceCdlFILE *fp, const char *path, int layer)
Definition: cdvdman.c:2190
sceCdGetToc
int sceCdGetToc(u8 *toc)
Definition: cdi.c:57
_ModuleInfo
Definition: loadcore.h:31
sceCdBuzzerCtl
int sceCdBuzzerCtl(u32 *result)
sceCdReadConsoleID
int sceCdReadConsoleID(u8 *buffer, u32 *result)
SCECdErREADCFR
@ SCECdErREADCFR
Definition: libcdvd-common.h:106
sceCdRMode::spindlctrl
u8 spindlctrl
Definition: libcdvd-common.h:238
cdvdfsv_rpc3_inpacket_
Definition: libcdvd-rpc.h:318
SCECdErREADCF
@ SCECdErREADCF
Definition: libcdvd-common.h:104
sceCdStatus
int sceCdStatus(void)
Definition: cdi.c:152
sceCdWI
int sceCdWI(const u8 *buffer, u32 *result)
_iop_sys_clock
Definition: thbase.h:87
sceCdDecSet
int sceCdDecSet(unsigned char enable_xor, unsigned char enable_shift, unsigned char shiftval)
Definition: cdvdman.c:8468
sceCdApplySCmd
int sceCdApplySCmd(u8 cmdNum, const void *inBuff, u16 inBuffSize, void *outBuff)
Definition: cdvdman.c:5405
sceCdSetLEDsMode
int sceCdSetLEDsMode(u32 param, u32 *result)
kerr.h
sceCdRI
int sceCdRI(u8 *buffer, u32 *result)
Definition: cdvdman.c:7268