PS2SDK
PS2 Homebrew Libraries
scmd.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 ## (C) 2002 Nicholas Van Veen (nickvv@xtra.co.nz)
7 # 2003 loser (loser@internalreality.com)
8 # (c) 2004 Marcus R. Brown <mrbrown@0xd6.org> Licenced under Academic Free License version 2.0
9 # Review ps2sdk README & LICENSE files for further details.
10 */
11 
22 #include <stdio.h>
23 #include <kernel.h>
24 #include <sifrpc.h>
25 #include <libcdvd.h>
26 #include <libcdvd-rpc.h>
27 #include <string.h>
28 #include <time.h>
29 #include <osd_config.h>
30 #include <sys/_tz_structs.h>
31 #include <iopcontrol.h>
32 
33 #include "internal.h"
34 
36 #define CD_SERVER_SCMD 0x80000593
37 
38 enum CD_SCMD_CMDS {
39  CD_SCMD_READCLOCK = 0x01,
40  CD_SCMD_WRITECLOCK,
41  CD_SCMD_GETDISKTYPE,
42  CD_SCMD_GETERROR,
43  CD_SCMD_TRAYREQ,
44  CD_SCMD_READ_ILINK_ID,
45  CD_SCMD_WRITE_ILINK_ID,
46  CD_SCMD_READ_NVM,
47  CD_SCMD_WRITE_NVM,
48  CD_SCMD_DEC_SET,
49  CD_SCMD_SCMD,
50  CD_SCMD_STATUS,
51  CD_SCMD_SET_HD_MODE,
52  CD_SCMD_OPEN_CONFIG,
53  CD_SCMD_CLOSE_CONFIG,
54  CD_SCMD_READ_CONFIG,
55  CD_SCMD_WRITE_CONFIG,
56  CD_SCMD_READ_CONSOLE_ID,
57  CD_SCMD_WRITE_CONSOLE_ID,
58  CD_SCMD_READ_MECHACON_VERSION,
59  CD_SCMD_CTRL_AD_OUT,
60  CD_SCMD_BREAK,
61  CD_SCMD_READ_SUBQ,
62  CD_SCMD_FORBID_DVDP,
63  CD_SCMD_AUTO_ADJUST_CTRL,
64  CD_SCMD_READ_MODEL_NAME,
65  CD_SCMD_WRITE_MODEL_NAME,
66  CD_SCMD_FORBID_READ,
67  CD_SCMD_SPIN_CTRL,
68  CD_SCMD_BOOT_CERTIFY,
69  CD_SCMD_CANCELPOWEROFF,
70  CD_SCMD_BLUELEDCTRL,
71  CD_SCMD_POWEROFF,
72  CD_SCMD_MMODE,
73  CD_SCMD_SETTHREADPRI,
74 };
75 
76 typedef union
77 {
78  s32 s32arg;
79  u32 u32arg;
80  u8 bcertify[4];
81  sceCdCLOCK clock;
82  struct cdvdScmdParam scmd;
83  struct cdvdDecSetParam decSet;
84  struct cdvdReadWriteNvmParam nvm;
85  u8 id[8];
86  char mname[16];
87  u8 data[0x420];
89 
90 #ifdef F__scmd_internals
91 SifRpcClientData_t clientSCmd __attribute__((aligned(64)));
92 
93 int sCmdSemaId;
94 
95 u8 sCmdRecvBuff[0x440] __attribute__((aligned(64)));
96 sCmdSendParams_t sCmdSendBuff __attribute__((aligned(64)));
97 
98 int sCmdNum = 0;
99 
100 int CdConfigRdWrNumBlocks;
101 #endif
102 
103 extern int initVersionCdvdman;
104 extern SifRpcClientData_t clientSCmd;
105 extern int sCmdSemaId;
106 extern u8 sCmdRecvBuff[];
107 extern sCmdSendParams_t sCmdSendBuff;
108 extern int sCmdNum;
109 
110 extern int CdConfigRdWrNumBlocks;
111 
112 extern void convertfrombcd(sceCdCLOCK *time);
113 
114 int _CdCheckSCmd(int cmd);
115 
116 /* S-Command Functions */
117 
118 #ifdef F_sceCdReadClock
119 int sceCdReadClock(sceCdCLOCK *clock)
120 {
121  if (_CdCheckSCmd(CD_SCMD_READCLOCK) == 0)
122  return 0;
123 
124  if (CdDebug > 0)
125  printf("Libcdvd call Clock read 1\n");
126 
127  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READCLOCK, 0, NULL, 0, sCmdRecvBuff, 16, NULL, NULL) < 0) {
128  SignalSema(sCmdSemaId);
129  return 0;
130  }
131 
132  memcpy(clock, UNCACHED_SEG(sCmdRecvBuff + 4), 8);
133 
134  if (CdDebug > 0)
135  printf("Libcdvd call Clock read 2\n");
136 
137  SignalSema(sCmdSemaId);
138  return *(int *)UNCACHED_SEG(sCmdRecvBuff);
139 }
140 #endif
141 
142 #ifdef F_ps2time
143 /*
144  * newlib function, unfortunately depends on the 'cdvd' library.
145  * In libc there is a 'time' function wihch call the `_gettimeofday` function.
146  * `_gettimeofday` is declared in glue.c (ee/libcglue folder inside of ps2sdk)
147  * `_gettimeofday` finally needs ps2time, to get proper time_t
148  */
149 time_t ps2time(time_t *t)
150 {
151  sceCdCLOCK ps2tim;
152  struct tm tim;
153  time_t tim2;
154  __tzinfo_type *tz;
155  int offset_save;
156 
157  tz = __gettzinfo();
158 
159  sceCdReadClock(&ps2tim);
160  convertfrombcd(&ps2tim);
161 #ifdef DEBUG
162  printf("ps2time: %d-%d-%d %d:%d:%d\n",
163  ps2tim.day,
164  ps2tim.month,
165  ps2tim.year,
166  ps2tim.hour,
167  ps2tim.minute,
168  ps2tim.second);
169 #endif
170  tim.tm_sec = ps2tim.second;
171  tim.tm_min = ps2tim.minute;
172  tim.tm_hour = ps2tim.hour;
173  tim.tm_mday = ps2tim.day;
174  tim.tm_mon = ps2tim.month - 1;
175  tim.tm_year = ps2tim.year + 100;
176 
177  // Temporally set the offset relative to JST
178  if (tz != NULL)
179  {
180  offset_save = tz->__tzrule[0].offset;
181  tz->__tzrule[0].offset = -9 * 60 * 60;
182  }
183  tim2 = mktime(&tim);
184  if (tz != NULL)
185  tz->__tzrule[0].offset = offset_save;
186 
187  if (t != NULL)
188  *t = tim2;
189 
190  return tim2;
191 }
192 #endif
193 
194 #ifdef F_sceCdWriteClock
195 int sceCdWriteClock(sceCdCLOCK *clock)
196 {
197  int result;
198 
199  if (_CdCheckSCmd(CD_SCMD_WRITECLOCK) == 0)
200  return 0;
201 
202  memcpy(&sCmdSendBuff.clock, clock, 8);
203 
204  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITECLOCK, 0, &sCmdSendBuff, 8, sCmdRecvBuff, 16, NULL, NULL) < 0) {
205  SignalSema(sCmdSemaId);
206  return 0;
207  }
208 
209  memcpy(clock, UNCACHED_SEG(sCmdRecvBuff + 4), 8);
210  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
211 
212  SignalSema(sCmdSemaId);
213  return result;
214 }
215 #endif
216 
217 #ifdef F_sceCdGetDiskType
218 int sceCdGetDiskType(void)
219 {
220  int result;
221 
222  if (_CdCheckSCmd(CD_SCMD_GETDISKTYPE) == 0)
223  return 0;
224 
225  if (sceSifCallRpc(&clientSCmd, CD_SCMD_GETDISKTYPE, 0, NULL, 0, sCmdRecvBuff, 4, NULL, NULL) < 0) {
226  SignalSema(sCmdSemaId);
227  return 0;
228  }
229 
230  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
231 
232  SignalSema(sCmdSemaId);
233  return result;
234 }
235 #endif
236 
237 #ifdef F_sceCdGetError
238 int sceCdGetError(void)
239 {
240  int result;
241 
242  if (_CdCheckSCmd(CD_SCMD_GETERROR) == 0)
243  return -1;
244 
245  if (sceSifCallRpc(&clientSCmd, CD_SCMD_GETERROR, 0, NULL, 0, sCmdRecvBuff, 4, NULL, NULL) < 0) {
246  SignalSema(sCmdSemaId);
247  return -1;
248  }
249 
250  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
251 
252  SignalSema(sCmdSemaId);
253  return result;
254 }
255 #endif
256 
257 #ifdef F_sceCdTrayReq
258 int sceCdTrayReq(int param, u32 *traychk)
259 {
260  int result;
261 
262  if (_CdCheckSCmd(CD_SCMD_TRAYREQ) == 0)
263  return 0;
264 
265  sCmdSendBuff.s32arg = param;
266 
267  if (sceSifCallRpc(&clientSCmd, CD_SCMD_TRAYREQ, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) < 0) {
268  SignalSema(sCmdSemaId);
269  return 0;
270  }
271 
272  if (traychk)
273  *traychk = *(u32 *)UNCACHED_SEG(sCmdRecvBuff + 4);
274  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
275 
276  SignalSema(sCmdSemaId);
277  return result;
278 }
279 #endif
280 
281 #ifdef F_sceCdApplySCmd
282 int sceCdApplySCmd(u8 cmdNum, const void *inBuff, u16 inBuffSize, void *outBuff)
283 {
284  if (_CdCheckSCmd(CD_SCMD_SCMD) == 0)
285  return 0;
286 
287  sCmdSendBuff.scmd.cmdNum = cmdNum;
288  sCmdSendBuff.scmd.inBuffSize = inBuffSize;
289  memset(sCmdSendBuff.scmd.inBuff, 0, 16);
290  if (inBuff)
291  memcpy(sCmdSendBuff.scmd.inBuff, inBuff, inBuffSize);
292 
293  if (sceSifCallRpc(&clientSCmd, CD_SCMD_SCMD, 0, &sCmdSendBuff, 20, sCmdRecvBuff, 16, NULL, NULL) < 0) {
294  SignalSema(sCmdSemaId);
295  return 0;
296  }
297 
298  if (outBuff)
299  memcpy(outBuff, UNCACHED_SEG(sCmdRecvBuff), 16);
300  SignalSema(sCmdSemaId);
301  return 1;
302 }
303 #endif
304 
305 #ifdef F_sceCdStatus
306 int sceCdStatus(void)
307 {
308  int result;
309 
310  if (_CdCheckSCmd(CD_SCMD_STATUS) == 0)
311  return -1;
312 
313  if (sceSifCallRpc(&clientSCmd, CD_SCMD_STATUS, 0, NULL, 0, sCmdRecvBuff, 4, NULL, NULL) < 0) {
314  SignalSema(sCmdSemaId);
315  return -1;
316  }
317 
318  if (CdDebug >= 2)
319  printf("status called\n");
320  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
321 
322  SignalSema(sCmdSemaId);
323  return result;
324 }
325 #endif
326 
327 #ifdef F_sceCdBreak
328 int sceCdBreak(void)
329 {
330  int result;
331 
332  if (_CdCheckSCmd(CD_SCMD_BREAK) == 0)
333  return 0;
334 
335  if (sceSifCallRpc(&clientSCmd, CD_SCMD_BREAK, 0, NULL, 0, sCmdRecvBuff, 4, NULL, NULL) < 0) {
336  SignalSema(sCmdSemaId);
337  return 0;
338  }
339  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
340 
341  SignalSema(sCmdSemaId);
342  return result;
343 }
344 #endif
345 
346 #ifdef F_sceCdCancelPOffRdy
347 int sceCdCancelPOffRdy(u32 *result)
348 {
349  int status;
350 
351  if (_CdCheckSCmd(CD_SCMD_CANCELPOWEROFF) == 0)
352  return 0;
353 
354  if (sceSifCallRpc(&clientSCmd, CD_SCMD_CANCELPOWEROFF, 0, NULL, 0, sCmdRecvBuff, 8, NULL, NULL) < 0) {
355  SignalSema(sCmdSemaId);
356  return 0;
357  }
358 
359  *result = *(u32 *)UNCACHED_SEG(sCmdRecvBuff + 4);
360  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
361 
362  SignalSema(sCmdSemaId);
363  return status;
364 }
365 #endif
366 
367 #ifdef F_sceCdBlueLedCtrl
368 int sceCdBlueLedCtrl(u8 control, u32 *result)
369 {
370  int status;
371 
372  if (_CdCheckSCmd(CD_SCMD_BLUELEDCTRL) == 0)
373  return 0;
374 
375  sCmdSendBuff.u32arg = control;
376  if (sceSifCallRpc(&clientSCmd, CD_SCMD_BLUELEDCTRL, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) < 0) {
377  SignalSema(sCmdSemaId);
378  return 0;
379  }
380 
381  *result = *(u32 *)UNCACHED_SEG(sCmdRecvBuff + 4);
382  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
383 
384  SignalSema(sCmdSemaId);
385  return status;
386 }
387 #endif
388 
389 #ifdef F_sceCdPowerOff
390 int sceCdPowerOff(u32 *result)
391 {
392  int status;
393 
394  if (_CdCheckSCmd(CD_SCMD_POWEROFF) == 0)
395  return 0;
396 
397  if (sceSifCallRpc(&clientSCmd, CD_SCMD_POWEROFF, 0, NULL, 0, sCmdRecvBuff, 8, NULL, NULL) < 0) {
398  SignalSema(sCmdSemaId);
399  return 0;
400  }
401 
402  *result = *(u32 *)UNCACHED_SEG(sCmdRecvBuff + 4);
403  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
404 
405  SignalSema(sCmdSemaId);
406  return status;
407 }
408 #endif
409 
410 #ifdef F_sceCdMmode
411 int sceCdMmode(int media)
412 {
413  int result;
414 
415  if (_CdCheckSCmd(CD_SCMD_MMODE) == 0)
416  return 0;
417 
418  sCmdSendBuff.s32arg = media;
419  if (sceSifCallRpc(&clientSCmd, CD_SCMD_MMODE, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 4, NULL, NULL) < 0) {
420  SignalSema(sCmdSemaId);
421  return 0;
422  }
423 
424  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
425 
426  SignalSema(sCmdSemaId);
427  return result;
428 }
429 #endif
430 
431 #ifdef F_sceCdChangeThreadPriority
432 int sceCdChangeThreadPriority(int priority)
433 {
434  int result;
435 
436  if (_CdCheckSCmd(CD_SCMD_SETTHREADPRI) == 0)
437  return 0;
438 
439  sCmdSendBuff.s32arg = priority;
440  if (sceSifCallRpc(&clientSCmd, CD_SCMD_SETTHREADPRI, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 4, NULL, NULL) < 0) {
441  SignalSema(sCmdSemaId);
442  return 0;
443  }
444 
445  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
446 
447  SignalSema(sCmdSemaId);
448  return result;
449 }
450 #endif
451 
452 #ifdef F__CdCheckSCmd
453 int _CdCheckSCmd(int cur_cmd)
454 {
455  _CdSemaInit();
456  if (PollSema(sCmdSemaId) != sCmdSemaId) {
457  if (CdDebug > 0)
458  printf("Scmd fail sema cur_cmd:%d keep_cmd:%d\n", cur_cmd, sCmdNum);
459  return 0;
460  }
461  sCmdNum = cur_cmd;
462  if (_CdSyncS(1)) {
463  SignalSema(sCmdSemaId);
464  return 0;
465  }
466 
467  sceSifInitRpc(0);
469  memset(&clientSCmd, 0, sizeof(clientSCmd));
470  if (clientSCmd.server)
471  return 1;
472  while (1) {
473  if (sceSifBindRpc(&clientSCmd, CD_SERVER_SCMD, 0) < 0) {
474  if (CdDebug > 0)
475  printf("Libcdvd bind err S cmd\n");
476  }
477  if (clientSCmd.server != 0)
478  break;
479 
480  nopdelay();
481  }
482  return 1;
483 }
484 #endif
485 
486 #ifdef F_sceCdForbidRead
487 int sceCdForbidRead(u32 *status)
488 {
489  int result;
490 
491  if (_CdCheckSCmd(CD_SCMD_FORBID_READ) == 0)
492  return 0;
493  if (sceSifCallRpc(&clientSCmd, CD_SCMD_FORBID_READ, 0, NULL, 0, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
494  *status = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
495  result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[0];
496  } else {
497  result = 0;
498  }
499  SignalSema(sCmdSemaId);
500  return result;
501 }
502 #endif
503 
504 #ifdef F_sceCdSpinCtrlEE
505 int sceCdSpinCtrlEE(u32 speed)
506 {
507  int result;
508 
509  if (_CdCheckSCmd(CD_SCMD_SPIN_CTRL) == 0)
510  return 0;
511  sCmdSendBuff.u32arg = speed;
512  if (sceSifCallRpc(&clientSCmd, CD_SCMD_SPIN_CTRL, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
513  result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[0];
514  } else {
515  result = 0;
516  }
517  SignalSema(sCmdSemaId);
518  return result;
519 }
520 #endif
521 
522 #ifdef F_sceCdBootCertify
523 int sceCdBootCertify(const u8 *romname)
524 {
525  int result;
526 
527  if (_CdCheckSCmd(CD_SCMD_BOOT_CERTIFY) == 0)
528  return 0;
529 
530  memcpy(sCmdSendBuff.bcertify, romname, 4);
531  if (sceSifCallRpc(&clientSCmd, CD_SCMD_BOOT_CERTIFY, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 4, NULL, NULL) >= 0) {
532  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
533  } else {
534  result = 0;
535  }
536 
537  SignalSema(sCmdSemaId);
538  return result;
539 }
540 #endif
541 
542 #ifdef F_sceCdReadSUBQ
543 int sceCdReadSUBQ(void *buffer, u32 *status)
544 {
545  int result;
546 
547  if (_CdCheckSCmd(CD_SCMD_READ_SUBQ) == 0)
548  return 0;
549 
550  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_SUBQ, 0, NULL, 0, sCmdRecvBuff, 0x12, NULL, NULL) >= 0) {
551  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 0x12);
552  *status = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
553  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
554  } else {
555  result = 0;
556  }
557 
558  SignalSema(sCmdSemaId);
559  return result;
560 }
561 #endif
562 
563 #ifdef F_sceCdForbidDVDP
564 int sceCdForbidDVDP(u32 *result)
565 {
566  int status;
567 
568  if (_CdCheckSCmd(CD_SCMD_FORBID_DVDP) == 0)
569  return 0;
570 
571  if (sceSifCallRpc(&clientSCmd, CD_SCMD_FORBID_DVDP, 0, NULL, 0, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
572  *result = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
573  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
574  } else {
575  status = 0;
576  }
577 
578  SignalSema(sCmdSemaId);
579  return status;
580 }
581 #endif
582 
583 #ifdef F_sceCdAutoAdjustCtrl
584 int sceCdAutoAdjustCtrl(int mode, u32 *result)
585 {
586  int status;
587 
588  if (_CdCheckSCmd(CD_SCMD_AUTO_ADJUST_CTRL) == 0)
589  return 0;
590 
591  sCmdSendBuff.s32arg = mode;
592  if (sceSifCallRpc(&clientSCmd, CD_SCMD_AUTO_ADJUST_CTRL, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
593  *result = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
594  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
595  } else {
596  status = 0;
597  }
598 
599  SignalSema(sCmdSemaId);
600  return status;
601 }
602 #endif
603 
604 #ifdef F_sceCdDecSet
605 int sceCdDecSet(unsigned char arg1, unsigned char arg2, unsigned char shift)
606 {
607  int result;
608 
609  if (_CdCheckSCmd(CD_SCMD_DEC_SET) == 0)
610  return 0;
611 
612  sCmdSendBuff.decSet.arg1 = arg1;
613  sCmdSendBuff.decSet.arg2 = arg2;
614  sCmdSendBuff.decSet.shift = shift;
615 
616  if (sceSifCallRpc(&clientSCmd, CD_SCMD_DEC_SET, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 16, NULL, NULL) >= 0) {
617  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
618  } else {
619  result = 0;
620  }
621 
622  SignalSema(sCmdSemaId);
623  return result;
624 }
625 #endif
626 
627 #ifdef F_sceCdSetHDMode
628 int sceCdSetHDMode(u32 mode)
629 {
630  int result;
631 
632  if (_CdCheckSCmd(CD_SCMD_SET_HD_MODE) == 0)
633  return 0;
634  sCmdSendBuff.u32arg = mode;
635  if (sceSifCallRpc(&clientSCmd, CD_SCMD_SET_HD_MODE, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 4, NULL, NULL) >= 0) {
636  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
637  } else {
638  result = 0;
639  }
640  SignalSema(sCmdSemaId);
641  return result;
642 }
643 #endif
644 
645 #ifdef F_sceCdOpenConfig
646 int sceCdOpenConfig(int block, int mode, int NumBlocks, u32 *status)
647 {
648  int result;
649 
650  if (NumBlocks < 0x45) {
651  if (_CdCheckSCmd(CD_SCMD_OPEN_CONFIG) == 0)
652  return 0;
653 
654  sCmdSendBuff.u32arg = ((NumBlocks & 0xFF) << 16) | (mode & 0xFF) | ((block & 0xFF) << 8);
655  CdConfigRdWrNumBlocks = NumBlocks;
656  if (sceSifCallRpc(&clientSCmd, CD_SCMD_OPEN_CONFIG, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
657  *status = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
658  result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[0];
659  } else
660  result = 0;
661 
662  SignalSema(sCmdSemaId);
663  } else
664  result = 0;
665 
666  return result;
667 }
668 #endif
669 
670 #ifdef F_sceCdCloseConfig
671 int sceCdCloseConfig(u32 *result)
672 {
673  int status;
674 
675  if (_CdCheckSCmd(CD_SCMD_CLOSE_CONFIG) == 0)
676  return 0;
677 
678  if (sceSifCallRpc(&clientSCmd, CD_SCMD_CLOSE_CONFIG, 0, NULL, 0, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
679  *result = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
680  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
681  } else {
682  status = 0;
683  }
684 
685  SignalSema(sCmdSemaId);
686  return status;
687 }
688 #endif
689 
690 #ifdef F_sceCdReadConfig
691 int sceCdReadConfig(void *buffer, u32 *result)
692 {
693  int status;
694 
695  if (_CdCheckSCmd(CD_SCMD_READ_CONFIG) == 0)
696  return 0;
697 
698  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_CONFIG, 0, NULL, 0, sCmdRecvBuff, 0x408, NULL, NULL) >= 0) {
699  *result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[1];
700  memcpy(buffer, &((u32 *)UNCACHED_SEG(sCmdRecvBuff))[2], (CdConfigRdWrNumBlocks << 4) - CdConfigRdWrNumBlocks);
701  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
702  } else {
703  status = 0;
704  }
705 
706  SignalSema(sCmdSemaId);
707  return status;
708 }
709 #endif
710 
711 #ifdef F_sceCdWriteConfig
712 int sceCdWriteConfig(const void *buffer, u32 *result)
713 {
714  int status;
715 
716  if (_CdCheckSCmd(CD_SCMD_WRITE_CONFIG) == 0)
717  return 0;
718 
719  memcpy(sCmdSendBuff.data, buffer, (CdConfigRdWrNumBlocks << 4) - CdConfigRdWrNumBlocks);
720  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_CONFIG, 0, &sCmdSendBuff, 0x400, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
721  *result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[1];
722  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
723  } else {
724  status = 0;
725  }
726 
727  SignalSema(sCmdSemaId);
728 
729  return status;
730 }
731 #endif
732 
733 #ifdef F_sceCdReadNVM
734 int sceCdReadNVM(u32 address, u16 *data, u8 *result)
735 {
736  int status;
737 
738  if (_CdCheckSCmd(CD_SCMD_READ_NVM) == 0)
739  return 0;
740 
741  sCmdSendBuff.nvm.address = address;
742  sCmdSendBuff.nvm.value = 0;
743  sCmdSendBuff.nvm.pad = 0;
744 
745  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_NVM, 0, &sCmdSendBuff, 8, sCmdRecvBuff, 0x10, NULL, NULL) >= 0) {
746  *data = *(unsigned short int *)UNCACHED_SEG(&sCmdRecvBuff[8]);
747  *result = *(u8 *)UNCACHED_SEG(&sCmdRecvBuff[10]);
748  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
749  } else {
750  status = 0;
751  }
752 
753  SignalSema(sCmdSemaId);
754  return status;
755 }
756 #endif
757 
758 #ifdef F_sceCdWriteNVM
759 int sceCdWriteNVM(u32 address, u16 data, u8 *result)
760 {
761  int status;
762 
763  if (_CdCheckSCmd(CD_SCMD_WRITE_NVM) == 0)
764  return 0;
765 
766  sCmdSendBuff.nvm.address = address;
767  sCmdSendBuff.nvm.value = data;
768  sCmdSendBuff.nvm.pad = 0;
769 
770  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_NVM, 0, &sCmdSendBuff, 8, sCmdRecvBuff, 0x10, NULL, NULL) >= 0) {
771  *result = *(u8 *)UNCACHED_SEG(&sCmdRecvBuff[10]);
772  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
773  } else {
774  status = 0;
775  }
776 
777  SignalSema(sCmdSemaId);
778  return status;
779 }
780 #endif
781 
782 #ifdef F_sceCdRI
783 int sceCdRI(unsigned char *buffer, u32 *result)
784 {
785  int status;
786 
787  if (_CdCheckSCmd(CD_SCMD_READ_ILINK_ID) == 0)
788  return 0;
789 
790  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_ILINK_ID, 0, NULL, 0, sCmdRecvBuff, 16, NULL, NULL) >= 0) {
791  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 8);
792  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
793  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
794  } else {
795  status = 0;
796  }
797 
798  SignalSema(sCmdSemaId);
799  return status;
800 }
801 #endif
802 
803 #ifdef F_sceCdWI
804 int sceCdWI(const unsigned char *buffer, u32 *status)
805 {
806  int result;
807 
808  if (_CdCheckSCmd(CD_SCMD_WRITE_ILINK_ID) == 0)
809  return 0;
810 
811  memcpy(sCmdSendBuff.id, buffer, 8);
812  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_ILINK_ID, 0, &sCmdSendBuff, 8, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
813  *status = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
814  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
815  } else {
816  result = 0;
817  }
818 
819  SignalSema(sCmdSemaId);
820  return result;
821 }
822 #endif
823 
824 #ifdef F_sceCdReadConsoleID
825 int sceCdReadConsoleID(unsigned char *buffer, u32 *result)
826 {
827  int status;
828 
829  if (_CdCheckSCmd(CD_SCMD_READ_CONSOLE_ID) == 0)
830  return 0;
831 
832  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_CONSOLE_ID, 0, NULL, 0, sCmdRecvBuff, 16, NULL, NULL) >= 0) {
833  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 8);
834  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
835  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
836  } else {
837  status = 0;
838  }
839 
840  SignalSema(sCmdSemaId);
841  return status;
842 }
843 #endif
844 
845 #ifdef F_sceCdWriteConsoleID
846 int sceCdWriteConsoleID(const unsigned char *buffer, u32 *result)
847 {
848  int status;
849 
850  if (_CdCheckSCmd(CD_SCMD_WRITE_CONSOLE_ID) == 0)
851  return 0;
852 
853  memcpy(sCmdSendBuff.id, buffer, 8);
854  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_CONSOLE_ID, 0, &sCmdSendBuff, 8, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
855  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
856  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
857  } else {
858  status = 0;
859  }
860 
861  SignalSema(sCmdSemaId);
862  return status;
863 }
864 #endif
865 
866 #ifdef F_sceCdMV
867 int sceCdMV(unsigned char *buffer, u32 *result)
868 {
869  int status;
870 
871  if (_CdCheckSCmd(CD_SCMD_READ_MECHACON_VERSION) == 0)
872  return 0;
873 
874  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_MECHACON_VERSION, 0, NULL, 0, sCmdRecvBuff, 16, NULL, NULL) >= 0) {
875 
876  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), (initVersionCdvdman >= 0x200) ? 4 : 3);
877  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
878  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
879  } else {
880  status = 0;
881  }
882 
883  SignalSema(sCmdSemaId);
884  return status;
885 }
886 #endif
887 
888 #ifdef F_sceCdCtrlADout
889 int sceCdCtrlADout(int arg1, u32 *result)
890 {
891  int status;
892 
893  if (_CdCheckSCmd(CD_SCMD_CTRL_AD_OUT) == 0)
894  return 0;
895 
896  sCmdSendBuff.s32arg = arg1;
897  if (sceSifCallRpc(&clientSCmd, CD_SCMD_CTRL_AD_OUT, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
898  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
899  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
900  } else {
901  status = 0;
902  }
903 
904  SignalSema(sCmdSemaId);
905  return status;
906 }
907 #endif
908 
909 #ifdef F_sceCdRM
910 int sceCdRM(char *buffer, u32 *result)
911 {
912  int status;
913 
914  if (_CdCheckSCmd(CD_SCMD_READ_MODEL_NAME) == 0)
915  return 0;
916 
917  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_MODEL_NAME, 0, NULL, 0, sCmdRecvBuff, 0x18, NULL, NULL) >= 0) {
918  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 16);
919  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
920  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
921  } else {
922  status = 0;
923  }
924 
925  SignalSema(sCmdSemaId);
926  return status;
927 }
928 #endif
929 
930 #ifdef F_sceCdWM
931 int sceCdWM(const char *buffer, u32 *result)
932 {
933  int status;
934 
935  if (_CdCheckSCmd(CD_SCMD_WRITE_MODEL_NAME) == 0)
936  return 0;
937 
938  memcpy(sCmdSendBuff.mname, buffer, 16);
939  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_MODEL_NAME, 0, &sCmdSendBuff, 0x10, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
940  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
941  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
942  } else {
943  status = 0;
944  }
945 
946  SignalSema(sCmdSemaId);
947  return status;
948 }
949 #endif
950 
951 #ifdef F_sceCdNoticeGameStart
952 int sceCdNoticeGameStart(u8 arg1, u32 *result)
953 {
954  int res;
955  u8 out[16];
956  u8 in[16];
957 
958  if (result) {
959  *result = 0;
960  }
961  {
962  in[0] = arg1;
963  res = sceCdApplySCmd(0x29u, in, 1, out);
964  if (result) {
965  *result = (u8)out[0];
966  }
967  }
968  return res;
969 }
970 #endif
971 
972 #ifdef F__CdSyncS
973 int _CdSyncS(int mode)
974 {
975  if (mode == 0) {
976  if (CdDebug > 0)
977  printf("S cmd wait\n");
978  while (sceSifCheckStatRpc(&clientSCmd))
979  ;
980  return 0;
981  }
982 
983  return sceSifCheckStatRpc(&clientSCmd);
984 }
985 #endif
sceCdReadSUBQ
int sceCdReadSUBQ(void *buffer, u32 *status)
kernel.h
sceCdNoticeGameStart
int sceCdNoticeGameStart(u8 arg1, u32 *result)
sceCdPowerOff
int sceCdPowerOff(u32 *result)
Definition: cdvdman.c:7560
sceCdOpenConfig
int sceCdOpenConfig(int block, int mode, int NumBlocks, u32 *status)
sceCdSetHDMode
int sceCdSetHDMode(u32 mode)
libcdvd-rpc.h
sceCdBootCertify
int sceCdBootCertify(const u8 *romname)
sceCdCtrlADout
int sceCdCtrlADout(int mode, u32 *status)
Definition: cdvdman.c:7592
sceCdWriteConfig
int sceCdWriteConfig(const void *buffer, u32 *result)
sceCdTrayReq
int sceCdTrayReq(int param, u32 *traychk)
Definition: cdi.c:162
sceCdCLOCK::year
u8 year
Definition: libcdvd-common.h:205
CD_SERVER_SCMD
#define CD_SERVER_SCMD
Definition: scmd.c:36
sceCdCLOCK
Definition: libcdvd-common.h:188
sceCdBreak
int sceCdBreak(void)
Definition: cdi.c:25
sceCdGetDiskType
int sceCdGetDiskType(void)
Definition: cdi.c:35
sceCdRM
int sceCdRM(char *buffer, u32 *status)
Definition: cdvdman.c:7279
sceCdCLOCK::hour
u8 hour
Definition: libcdvd-common.h:197
cdvdScmdParam
Definition: libcdvd-rpc.h:24
sceCdForbidRead
int sceCdForbidRead(u32 *result)
libcdvd.h
iopcontrol.h
sceCdCLOCK::month
u8 month
Definition: libcdvd-common.h:203
sceCdWriteNVM
int sceCdWriteNVM(u32 address, u16 data, u8 *result)
cdvdReadWriteNvmParam
Definition: libcdvd-rpc.h:39
sceCdSpinCtrlEE
int sceCdSpinCtrlEE(u32 speed)
sceCdGetError
int sceCdGetError(void)
Definition: cdi.c:40
sceCdReadNVM
int sceCdReadNVM(u32 address, u16 *data, u8 *result)
__attribute__
typedef __attribute__
Definition: tlbfunc.c:60
sceCdMV
int sceCdMV(u8 *buffer, u32 *status)
Definition: cdvdman.c:7386
sceCdForbidDVDP
int sceCdForbidDVDP(u32 *result)
time.h
HasIopRebootedSinceLastCall
static int HasIopRebootedSinceLastCall(void)
Definition: iopcontrol.h:47
sceCdWriteConsoleID
int sceCdWriteConsoleID(const u8 *buffer, u32 *status)
stdio.h
cdvdDecSetParam
Definition: libcdvd-rpc.h:31
sceCdCloseConfig
int sceCdCloseConfig(u32 *result)
sceCdCancelPOffRdy
int sceCdCancelPOffRdy(u32 *result)
Definition: cdvdman.c:7531
sceCdMmode
int sceCdMmode(int media)
Definition: cdi.c:86
sceCdCLOCK::day
u8 day
Definition: libcdvd-common.h:201
sceCdChangeThreadPriority
int sceCdChangeThreadPriority(int priority)
Definition: cdvdfsv.c:315
sceCdWriteClock
int sceCdWriteClock(sceCdCLOCK *clock)
t_SifRpcClientData
Definition: sifrpc-common.h:134
__attribute__
Definition: gif_registers.h:38
sceCdAutoAdjustCtrl
int sceCdAutoAdjustCtrl(int mode, u32 *result)
sceCdReadClock
int sceCdReadClock(sceCdCLOCK *clock)
Definition: cdvdman.c:7934
osd_config.h
sceCdReadConfig
int sceCdReadConfig(void *buffer, u32 *result)
sceCdCLOCK::minute
u8 minute
Definition: libcdvd-common.h:195
sceCdWM
int sceCdWM(const char *buffer, u32 *status)
sceCdCLOCK::second
u8 second
Definition: libcdvd-common.h:193
sceCdReadConsoleID
int sceCdReadConsoleID(u8 *buffer, u32 *result)
sceCdStatus
int sceCdStatus(void)
Definition: cdi.c:152
sceCdWI
int sceCdWI(const u8 *buffer, u32 *result)
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
sceCdRI
int sceCdRI(u8 *buffer, u32 *result)
Definition: cdvdman.c:7268
sCmdSendParams_t
Definition: scmd.c:76