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  ReferThreadStatus(CdThreadId, &CdThreadParam);
463  if (_CdSyncS(1)) {
464  SignalSema(sCmdSemaId);
465  return 0;
466  }
467 
468  sceSifInitRpc(0);
470  memset(&clientSCmd, 0, sizeof(clientSCmd));
471  if (clientSCmd.server)
472  return 1;
473  while (1) {
474  if (sceSifBindRpc(&clientSCmd, CD_SERVER_SCMD, 0) < 0) {
475  if (CdDebug > 0)
476  printf("Libcdvd bind err S cmd\n");
477  }
478  if (clientSCmd.server != 0)
479  break;
480 
481  nopdelay();
482  }
483  return 1;
484 }
485 #endif
486 
487 #ifdef F_sceCdForbidRead
488 int sceCdForbidRead(u32 *status)
489 {
490  int result;
491 
492  if (_CdCheckSCmd(CD_SCMD_FORBID_READ) == 0)
493  return 0;
494  if (sceSifCallRpc(&clientSCmd, CD_SCMD_FORBID_READ, 0, NULL, 0, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
495  *status = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
496  result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[0];
497  } else {
498  result = 0;
499  }
500  SignalSema(sCmdSemaId);
501  return result;
502 }
503 #endif
504 
505 #ifdef F_sceCdSpinCtrlEE
506 int sceCdSpinCtrlEE(u32 speed)
507 {
508  int result;
509 
510  if (_CdCheckSCmd(CD_SCMD_SPIN_CTRL) == 0)
511  return 0;
512  sCmdSendBuff.u32arg = speed;
513  if (sceSifCallRpc(&clientSCmd, CD_SCMD_SPIN_CTRL, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
514  result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[0];
515  } else {
516  result = 0;
517  }
518  SignalSema(sCmdSemaId);
519  return result;
520 }
521 #endif
522 
523 #ifdef F_sceCdBootCertify
524 int sceCdBootCertify(const u8 *romname)
525 {
526  int result;
527 
528  if (_CdCheckSCmd(CD_SCMD_BOOT_CERTIFY) == 0)
529  return 0;
530 
531  memcpy(sCmdSendBuff.bcertify, romname, 4);
532  if (sceSifCallRpc(&clientSCmd, CD_SCMD_BOOT_CERTIFY, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 4, NULL, NULL) >= 0) {
533  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
534  } else {
535  result = 0;
536  }
537 
538  SignalSema(sCmdSemaId);
539  return result;
540 }
541 #endif
542 
543 #ifdef F_sceCdReadSUBQ
544 int sceCdReadSUBQ(void *buffer, u32 *status)
545 {
546  int result;
547 
548  if (_CdCheckSCmd(CD_SCMD_READ_SUBQ) == 0)
549  return 0;
550 
551  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_SUBQ, 0, NULL, 0, sCmdRecvBuff, 0x12, NULL, NULL) >= 0) {
552  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 0x12);
553  *status = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
554  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
555  } else {
556  result = 0;
557  }
558 
559  SignalSema(sCmdSemaId);
560  return result;
561 }
562 #endif
563 
564 #ifdef F_sceCdForbidDVDP
565 int sceCdForbidDVDP(u32 *result)
566 {
567  int status;
568 
569  if (_CdCheckSCmd(CD_SCMD_FORBID_DVDP) == 0)
570  return 0;
571 
572  if (sceSifCallRpc(&clientSCmd, CD_SCMD_FORBID_DVDP, 0, NULL, 0, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
573  *result = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
574  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
575  } else {
576  status = 0;
577  }
578 
579  SignalSema(sCmdSemaId);
580  return status;
581 }
582 #endif
583 
584 #ifdef F_sceCdAutoAdjustCtrl
585 int sceCdAutoAdjustCtrl(int mode, u32 *result)
586 {
587  int status;
588 
589  if (_CdCheckSCmd(CD_SCMD_AUTO_ADJUST_CTRL) == 0)
590  return 0;
591 
592  sCmdSendBuff.s32arg = mode;
593  if (sceSifCallRpc(&clientSCmd, CD_SCMD_AUTO_ADJUST_CTRL, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
594  *result = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
595  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
596  } else {
597  status = 0;
598  }
599 
600  SignalSema(sCmdSemaId);
601  return status;
602 }
603 #endif
604 
605 #ifdef F_sceCdDecSet
606 int sceCdDecSet(unsigned char arg1, unsigned char arg2, unsigned char shift)
607 {
608  int result;
609 
610  if (_CdCheckSCmd(CD_SCMD_DEC_SET) == 0)
611  return 0;
612 
613  sCmdSendBuff.decSet.arg1 = arg1;
614  sCmdSendBuff.decSet.arg2 = arg2;
615  sCmdSendBuff.decSet.shift = shift;
616 
617  if (sceSifCallRpc(&clientSCmd, CD_SCMD_DEC_SET, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 16, NULL, NULL) >= 0) {
618  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
619  } else {
620  result = 0;
621  }
622 
623  SignalSema(sCmdSemaId);
624  return result;
625 }
626 #endif
627 
628 #ifdef F_sceCdSetHDMode
629 int sceCdSetHDMode(u32 mode)
630 {
631  int result;
632 
633  if (_CdCheckSCmd(CD_SCMD_SET_HD_MODE) == 0)
634  return 0;
635  sCmdSendBuff.u32arg = mode;
636  if (sceSifCallRpc(&clientSCmd, CD_SCMD_SET_HD_MODE, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 4, NULL, NULL) >= 0) {
637  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
638  } else {
639  result = 0;
640  }
641  SignalSema(sCmdSemaId);
642  return result;
643 }
644 #endif
645 
646 #ifdef F_sceCdOpenConfig
647 int sceCdOpenConfig(int block, int mode, int NumBlocks, u32 *status)
648 {
649  int result;
650 
651  if (NumBlocks < 0x45) {
652  if (_CdCheckSCmd(CD_SCMD_OPEN_CONFIG) == 0)
653  return 0;
654 
655  sCmdSendBuff.u32arg = ((NumBlocks & 0xFF) << 16) | (mode & 0xFF) | ((block & 0xFF) << 8);
656  CdConfigRdWrNumBlocks = NumBlocks;
657  if (sceSifCallRpc(&clientSCmd, CD_SCMD_OPEN_CONFIG, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
658  *status = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
659  result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[0];
660  } else
661  result = 0;
662 
663  SignalSema(sCmdSemaId);
664  } else
665  result = 0;
666 
667  return result;
668 }
669 #endif
670 
671 #ifdef F_sceCdCloseConfig
672 int sceCdCloseConfig(u32 *result)
673 {
674  int status;
675 
676  if (_CdCheckSCmd(CD_SCMD_CLOSE_CONFIG) == 0)
677  return 0;
678 
679  if (sceSifCallRpc(&clientSCmd, CD_SCMD_CLOSE_CONFIG, 0, NULL, 0, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
680  *result = ((u32 *)UNCACHED_SEG(sCmdRecvBuff))[1];
681  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
682  } else {
683  status = 0;
684  }
685 
686  SignalSema(sCmdSemaId);
687  return status;
688 }
689 #endif
690 
691 #ifdef F_sceCdReadConfig
692 int sceCdReadConfig(void *buffer, u32 *result)
693 {
694  int status;
695 
696  if (_CdCheckSCmd(CD_SCMD_READ_CONFIG) == 0)
697  return 0;
698 
699  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_CONFIG, 0, NULL, 0, sCmdRecvBuff, 0x408, NULL, NULL) >= 0) {
700  *result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[1];
701  memcpy(buffer, &((u32 *)UNCACHED_SEG(sCmdRecvBuff))[2], (CdConfigRdWrNumBlocks << 4) - CdConfigRdWrNumBlocks);
702  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
703  } else {
704  status = 0;
705  }
706 
707  SignalSema(sCmdSemaId);
708  return status;
709 }
710 #endif
711 
712 #ifdef F_sceCdWriteConfig
713 int sceCdWriteConfig(const void *buffer, u32 *result)
714 {
715  int status;
716 
717  if (_CdCheckSCmd(CD_SCMD_WRITE_CONFIG) == 0)
718  return 0;
719 
720  memcpy(sCmdSendBuff.data, buffer, (CdConfigRdWrNumBlocks << 4) - CdConfigRdWrNumBlocks);
721  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_CONFIG, 0, &sCmdSendBuff, 0x400, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
722  *result = ((int *)UNCACHED_SEG(sCmdRecvBuff))[1];
723  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
724  } else {
725  status = 0;
726  }
727 
728  SignalSema(sCmdSemaId);
729 
730  return status;
731 }
732 #endif
733 
734 #ifdef F_sceCdReadNVM
735 int sceCdReadNVM(u32 address, u16 *data, u8 *result)
736 {
737  int status;
738 
739  if (_CdCheckSCmd(CD_SCMD_READ_NVM) == 0)
740  return 0;
741 
742  sCmdSendBuff.nvm.address = address;
743  sCmdSendBuff.nvm.value = 0;
744  sCmdSendBuff.nvm.pad = 0;
745 
746  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_NVM, 0, &sCmdSendBuff, 8, sCmdRecvBuff, 0x10, NULL, NULL) >= 0) {
747  *data = *(unsigned short int *)UNCACHED_SEG(&sCmdRecvBuff[8]);
748  *result = *(u8 *)UNCACHED_SEG(&sCmdRecvBuff[10]);
749  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
750  } else {
751  status = 0;
752  }
753 
754  SignalSema(sCmdSemaId);
755  return status;
756 }
757 #endif
758 
759 #ifdef F_sceCdWriteNVM
760 int sceCdWriteNVM(u32 address, u16 data, u8 *result)
761 {
762  int status;
763 
764  if (_CdCheckSCmd(CD_SCMD_WRITE_NVM) == 0)
765  return 0;
766 
767  sCmdSendBuff.nvm.address = address;
768  sCmdSendBuff.nvm.value = data;
769  sCmdSendBuff.nvm.pad = 0;
770 
771  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_NVM, 0, &sCmdSendBuff, 8, sCmdRecvBuff, 0x10, NULL, NULL) >= 0) {
772  *result = *(u8 *)UNCACHED_SEG(&sCmdRecvBuff[10]);
773  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
774  } else {
775  status = 0;
776  }
777 
778  SignalSema(sCmdSemaId);
779  return status;
780 }
781 #endif
782 
783 #ifdef F_sceCdRI
784 int sceCdRI(unsigned char *buffer, u32 *result)
785 {
786  int status;
787 
788  if (_CdCheckSCmd(CD_SCMD_READ_ILINK_ID) == 0)
789  return 0;
790 
791  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_ILINK_ID, 0, NULL, 0, sCmdRecvBuff, 16, NULL, NULL) >= 0) {
792  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 8);
793  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
794  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
795  } else {
796  status = 0;
797  }
798 
799  SignalSema(sCmdSemaId);
800  return status;
801 }
802 #endif
803 
804 #ifdef F_sceCdWI
805 int sceCdWI(const unsigned char *buffer, u32 *status)
806 {
807  int result;
808 
809  if (_CdCheckSCmd(CD_SCMD_WRITE_ILINK_ID) == 0)
810  return 0;
811 
812  memcpy(sCmdSendBuff.id, buffer, 8);
813  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_ILINK_ID, 0, &sCmdSendBuff, 8, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
814  *status = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
815  result = *(int *)UNCACHED_SEG(sCmdRecvBuff);
816  } else {
817  result = 0;
818  }
819 
820  SignalSema(sCmdSemaId);
821  return result;
822 }
823 #endif
824 
825 #ifdef F_sceCdReadConsoleID
826 int sceCdReadConsoleID(unsigned char *buffer, u32 *result)
827 {
828  int status;
829 
830  if (_CdCheckSCmd(CD_SCMD_READ_CONSOLE_ID) == 0)
831  return 0;
832 
833  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_CONSOLE_ID, 0, NULL, 0, sCmdRecvBuff, 16, NULL, NULL) >= 0) {
834  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 8);
835  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
836  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
837  } else {
838  status = 0;
839  }
840 
841  SignalSema(sCmdSemaId);
842  return status;
843 }
844 #endif
845 
846 #ifdef F_sceCdWriteConsoleID
847 int sceCdWriteConsoleID(const unsigned char *buffer, u32 *result)
848 {
849  int status;
850 
851  if (_CdCheckSCmd(CD_SCMD_WRITE_CONSOLE_ID) == 0)
852  return 0;
853 
854  memcpy(sCmdSendBuff.id, buffer, 8);
855  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_CONSOLE_ID, 0, &sCmdSendBuff, 8, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
856  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
857  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
858  } else {
859  status = 0;
860  }
861 
862  SignalSema(sCmdSemaId);
863  return status;
864 }
865 #endif
866 
867 #ifdef F_sceCdMV
868 int sceCdMV(unsigned char *buffer, u32 *result)
869 {
870  int status;
871 
872  if (_CdCheckSCmd(CD_SCMD_READ_MECHACON_VERSION) == 0)
873  return 0;
874 
875  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_MECHACON_VERSION, 0, NULL, 0, sCmdRecvBuff, 16, NULL, NULL) >= 0) {
876 
877  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), (initVersionCdvdman >= 0x200) ? 4 : 3);
878  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
879  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
880  } else {
881  status = 0;
882  }
883 
884  SignalSema(sCmdSemaId);
885  return status;
886 }
887 #endif
888 
889 #ifdef F_sceCdCtrlADout
890 int sceCdCtrlADout(int arg1, u32 *result)
891 {
892  int status;
893 
894  if (_CdCheckSCmd(CD_SCMD_CTRL_AD_OUT) == 0)
895  return 0;
896 
897  sCmdSendBuff.s32arg = arg1;
898  if (sceSifCallRpc(&clientSCmd, CD_SCMD_CTRL_AD_OUT, 0, &sCmdSendBuff, 4, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
899  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
900  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
901  } else {
902  status = 0;
903  }
904 
905  SignalSema(sCmdSemaId);
906  return status;
907 }
908 #endif
909 
910 #ifdef F_sceCdRM
911 int sceCdRM(char *buffer, u32 *result)
912 {
913  int status;
914 
915  if (_CdCheckSCmd(CD_SCMD_READ_MODEL_NAME) == 0)
916  return 0;
917 
918  if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_MODEL_NAME, 0, NULL, 0, sCmdRecvBuff, 0x18, NULL, NULL) >= 0) {
919  memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 16);
920  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
921  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
922  } else {
923  status = 0;
924  }
925 
926  SignalSema(sCmdSemaId);
927  return status;
928 }
929 #endif
930 
931 #ifdef F_sceCdWM
932 int sceCdWM(const char *buffer, u32 *result)
933 {
934  int status;
935 
936  if (_CdCheckSCmd(CD_SCMD_WRITE_MODEL_NAME) == 0)
937  return 0;
938 
939  memcpy(sCmdSendBuff.mname, buffer, 16);
940  if (sceSifCallRpc(&clientSCmd, CD_SCMD_WRITE_MODEL_NAME, 0, &sCmdSendBuff, 0x10, sCmdRecvBuff, 8, NULL, NULL) >= 0) {
941  *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]);
942  status = *(int *)UNCACHED_SEG(sCmdRecvBuff);
943  } else {
944  status = 0;
945  }
946 
947  SignalSema(sCmdSemaId);
948  return status;
949 }
950 #endif
951 
952 #ifdef F_sceCdNoticeGameStart
953 int sceCdNoticeGameStart(u8 arg1, u32 *result)
954 {
955  int res;
956  u8 out[16];
957  u8 in[16];
958 
959  if (result) {
960  *result = 0;
961  }
962  {
963  in[0] = arg1;
964  res = sceCdApplySCmd(0x29u, in, 1, out);
965  if (result) {
966  *result = (u8)out[0];
967  }
968  }
969  return res;
970 }
971 #endif
972 
973 #ifdef F__CdSyncS
974 int _CdSyncS(int mode)
975 {
976  if (mode == 0) {
977  if (CdDebug > 0)
978  printf("S cmd wait\n");
979  while (sceSifCheckStatRpc(&clientSCmd))
980  ;
981  return 0;
982  }
983 
984  return sceSifCheckStatRpc(&clientSCmd);
985 }
986 #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