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