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