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