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