Skip to content

Commit

Permalink
Merge pull request #663 from uyjulian/cdvd_definitions_20240913
Browse files Browse the repository at this point in the history
CDVD definitions 20240913
  • Loading branch information
rickgaiser authored Sep 16, 2024
2 parents ec28ed8 + 20dd409 commit 1d61154
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 16 deletions.
107 changes: 91 additions & 16 deletions common/include/libcdvd-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,40 @@ enum SCECdvdFanSpeed {
/** Disable the power on functionality. (RM_PS2_POWERON) */
#define CdlRCDisablePowerOn 0x10

// Flag definitions for sceCdCLOCK.stat
/** The RTC clock is stopped */
#define CdlRTCStatClockStopDetected 1
/** There was an issue checking the RTC battery voltage */
#define CdlRTCStatClockBatteryMonitoringVoltageProblem 2
/** The Rohm RTC hardware returned an error */
#define CdlRTCStatCTLRegProblem 4
/** There was an error while preparing to send the command from Mechacon to RTC */
#define CdlRTCStatCommandError 128

// Value definitions for the wakeupreason argument of sceCdReadWakeUpTime
/** The system was powered on using the front panel buttons or the remote */
#define CdlWakeUpReasonMainPowerOn 0
/** The system was reset using the front panel button, the remote, or the SCMD */
#define CdlWakeUpReasonMainReset 1
/** The system was powered on because the timer set by sceCdWriteWakeUpTime expired */
#define CdlWakeUpReasonMainTimer 2
/** The system was powered on using the PON_REQ signal connected to the expansion bay port */
#define CdlWakeUpReasonMainDevice 3

// Value definitions for the return value of sceCdGetWakeUpReason
#define CdlWakeUpReasonExtraSupportHard 0
/** The system was reset using the front panel button, the remote, or the SCMD */
#define CdlWakeUpReasonExtraReset 1
/** The system was reset using the "Quit Game" button */
#define CdlWakeUpReasonExtraGameReset 2
/** The system was powered on because the timer set by sceCdWriteWakeUpTime expired */
#define CdlWakeUpReasonExtraTimer 3
/** The system was powered on using the front panel buttons or the remote */
#define CdlWakeUpReasonExtraPowerOn 4
/** The system was powered on when an object was inserted into the disc slot */
#define CdlWakeUpReasonExtraSlotIn 7
#define CdlWakeUpReasonExtraBackGround 8

// For streaming operations (Use with sceCdStRead())
enum SCECdvdStreamMode {
/** Stream without blocking. */
Expand Down Expand Up @@ -678,12 +712,12 @@ int sceCdAutoAdjustCtrl(int mode, u32 *result);
/** Controls on-the-fly (hardware) data decryption. Setting all options to 0 will disable decryption.
* This is used for decrypting encrypted sectors like the PlayStation 2 logo.
*
* @param arg1 Unknown
* @param arg2 Unknown
* @param shift Shift amount
* @param enable_xor Set to a non-zero value to enable xor by index 4 of the key argument in sceCdReadKey
* @param enable_shift Set to a non-zero value to enable rotate shift right by the amount specified by the "shiftval" argument
* @param shiftval Shift amount enable_shift is enabled
* @return 1 on success, 0 on failure.
*/
int sceCdDecSet(unsigned char arg1, unsigned char arg2, unsigned char shift);
int sceCdDecSet(unsigned char enable_xor, unsigned char enable_shift, unsigned char shiftval);

/** Reads the requested key from the CD/DVD.
*
Expand All @@ -695,9 +729,18 @@ int sceCdDecSet(unsigned char arg1, unsigned char arg2, unsigned char shift);
*/
int sceCdReadKey(unsigned char arg1, unsigned char arg2, unsigned int command, unsigned char *key);

/** Sets the "HD mode", whatever that means.
/** Determines if unique disc key exists
* Unofficial name.
* SUPPORTED IN NEWER CDVDMAN MODULES INCLUDED WITHIN DNAS IOPRP ONLY
*
* @param mode mode
* @param status Command status
* @return 1 on success, 0 on failure.
*/
int sceCdDoesUniqueKeyExist(u32 *status);

/** Blocks disc tray eject functionality and turns off the blue eject LED when enabled.
*
* @param mode Set to a non-zero value to enable the tray eject functionality
* @return 1 on success, 0 on failure.
*/
int sceCdSetHDMode(u32 mode);
Expand All @@ -712,7 +755,7 @@ int sceCdSetHDMode(u32 mode);
*/
int sceCdOpenConfig(int block, int mode, int NumBlocks, u32 *status);

/** Closes the configuration block.
/** Closes the configuration block that is currently opened.
*
* @param result Result code.
* @return 1 on success, 0 on failure.
Expand Down Expand Up @@ -745,8 +788,7 @@ int sceCdWriteConfig(const void *buffer, u32 *result);
int sceCdReadNVM(u32 address, u16 *data, u8 *result);

/** Writes a single word to the NVRAM storage.
* Does not fully work on consoles starting from the SCPH-50000 ("Dragon" MECHACON):
* Some parts, like those containing the console IDs, cannot be overwritten.
* Starting from Mechacon firmware version 50000, attempting to write to address values over 150 will error.
*
* @param address Address in 2-byte words, of the word that will be written to.
* @param data Pointer to the buffer that contains the new data.
Expand All @@ -765,7 +807,7 @@ int sceCdWriteNVM(u32 address, u16 data, u8 *result);
int sceCdRI(u8 *buffer, u32 *result);

/** Writes a new i.Link ID for the console.
* Does not work on consoles starting from the SCPH-50000 ("Dragon" MECHACON):
* Starting from Mechacon firmware version 50000, a unlock combination (0x03 0x46 and 0x03 0x47) needs to be executed first.
*
* @param buffer Pointer to the buffer that contains the new i.Link ID.
* @param result Result code.
Expand All @@ -782,7 +824,7 @@ int sceCdWI(const u8 *buffer, u32 *result);
int sceCdReadConsoleID(u8 *buffer, u32 *result);

/** Writes a new ID for the console. This is not the same as the i.Link ID.
* Does not work on consoles starting from the SCPH-50000 ("Dragon" MECHACON):
* Starting from Mechacon firmware version 50000, a unlock combination (0x03 0x46 and 0x03 0x47) needs to be executed first.
*
* @param buffer Pointer to the buffer that contains the new i.Link ID.
* @param status Result code.
Expand All @@ -792,11 +834,11 @@ int sceCdWriteConsoleID(const u8 *buffer, u32 *status);

/** Controls Audio Digital output.
*
* @param arg1 Unknown
* @param mode Set to a non-zero value to enable digital output.
* @param status Result code.
* @return 1 on success, 0 on failure.
*/
int sceCdCtrlADout(int arg1, u32 *status);
int sceCdCtrlADout(int mode, u32 *status);

/** Reads MECHACON version data (RR MM mm TT): RR = Magicgate region, MM = major, mm = minor, TT = system type (00 = PS2, 01 = PSX)
* Magicgate region codes are: 00 = Japan, 01 = USA, 02 = Europe, 03 = Oceania, 04 = Asia, 05 = Russia, 06 = China, and 07 = Mexico.
Expand Down Expand Up @@ -831,7 +873,7 @@ int sceCdBootCertify(const u8 *romname);
int sceCdRM(char *buffer, u32 *status);

/** Sets the console's model name.
* Does not work on consoles starting from the SCPH-50000 ("Dragon" MECHACON).
* Starting from Mechacon firmware version 50000, a unlock combination (0x03 0x46 and 0x03 0x47) needs to be executed first.
* SUPPORTED IN XCDVDMAN/XCDVDFSV ONLY
*
* @param buffer Pointer to a buffer containing the new model name.
Expand Down Expand Up @@ -956,17 +998,26 @@ int sceCdRcBypassCtl(int mode, u32 *status);
* Minimum Mechacon firmware version: 50000
* SUPPORTED IN XCDVDMAN INCLUDED WITHIN NEWER BOOT ROMS ONLY
*
* @param clock The time to wake up the system.
* @param userdata Any arbitrary value (not used in timer processing)
* @param wakeupreason The reason why the system woke up.
* @param flags bit 0 -> disable timer after expiration, bit 1 -> disable timer
* @return 1 on success, 0 on failure
*/
int sceCdReadWakeUpTime(sceCdCLOCK *clock, u16 *arg2, u32 *arg3, int *arg4);
int sceCdReadWakeUpTime(sceCdCLOCK *clock, u16 *userdata, u32 *wakeupreason, int *flags);

/** Writes wake up time.
* Minimum Mechacon firmware version: 50000
* Note: in newer Mechacon firmware versions (TODO: determine the range), the wake up timer function is removed. However, the storage for the parameters remain.
* Note: if there was a non-zero value in sceCdCLOCK.stat the last time sceCdReadClock was called, no data will be written/enabled.
* SUPPORTED IN XCDVDMAN INCLUDED WITHIN NEWER BOOT ROMS ONLY
*
* @param clock The time to wake up the system.
* @param userdata Any arbitrary value (not used in timer processing)
* @param flags When 1, disables the timer after it has expired. When 255, disables the timer and sets the seconds value to 0xFF.
* @return 1 on success, 0 on failure
*/
int sceCdWriteWakeUpTime(const sceCdCLOCK *clock, u16 arg2, int arg3);
int sceCdWriteWakeUpTime(const sceCdCLOCK *clock, u16 userdata, int flags);

/** Disables Mechacon actions performed using the remote control.
* The actions that can be specified are poweron, poweroff, reset and eject.
Expand All @@ -978,6 +1029,17 @@ int sceCdWriteWakeUpTime(const sceCdCLOCK *clock, u16 arg2, int arg3);
*/
int sceRemote2_7(u16 param, u32 *status);

/** Retrieves the value set by sceRemote2_7.
* Minimum Mechacon firmware version: 50000
* Unofficial name.
* SUPPORTED IN XCDVDMAN INCLUDED WITHIN NEWER BOOT ROMS ONLY
*
* @param param The value set by sceRemote2_7
* @param status Command status
* @return 1 on success, 0 on failure.
*/
int sceRemote2_7Get(u32 *param, u32 *status);

/** Set the LED state of the face buttons of the console.
* The state of the buttons will be reset when the power or eject button is pressed.
* Minimum Mechacon firmware version: 50000
Expand Down Expand Up @@ -1005,6 +1067,19 @@ int sceCdReadPS1BootParam(u8 *out, u32 *result);
*/
int sceCdSetFanProfile(u8 param, u32 *result);

/** Sends SCMD 0x1D. Appears to be stubbed in Mechacon firmware 50000.
* Minimum Mechacon firmware version: 50000
* Unofficial name.
* SUPPORTED IN XCDVDMAN INCLUDED WITHIN NEWER BOOT ROMS ONLY
*
* @param arg1 Unknown
* @param arg2 Unknown
* @param arg3 Unknown
* @param status Command status
* @return 1 on success, 0 on failure.
*/
int sceCdSendSCmd1D(int *arg1, unsigned int *arg2, unsigned int *arg3, u32 *status);

/** Change sys.
* SUPPORTED BY ONLY DESR/PSX DVR CDVDMAN MODULES
*
Expand Down
40 changes: 40 additions & 0 deletions iop/kernel/include/cdvdman.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ int sceCdRV(u32 lsn, u32 sectors, void *buf, sceCdRMode *mode, int arg5, void *c
*/
int sceCdApplySCmd2(u8 cmdNum, const void* inBuff, unsigned long int inBuffSize, void *outBuff);

/** send an s-command by function number
* Unofficial name.
* SUPPORTED IN NEWER CDVDMAN MODULES INCLUDED WITHIN NEWER IOPRP ONLY
*
* @param cmdNum command number
* @param inBuff input buffer (can be null)
* @param inBuffSize size of input buffer (>= 16 bytes)
* @param outBuff output buffer (can be null)
* @return 1 on success, 0 on failure.
*/
int sceCdApplySCmd3(u8 cmdNum, const void* inBuff, unsigned long int inBuffSize, void *outBuff);

/** Controls spindle speed? Not sure what it really does.
* SUPPORTED IN XCDVDMAN ONLY
*
Expand All @@ -63,6 +75,16 @@ int sceCdApplySCmd2(u8 cmdNum, const void* inBuff, unsigned long int inBuffSize,
*/
int sceCdSpinCtrlIOP(u32 speed);

/** Set the eject callback when in ATAPI mode.
* Unofficial name.
* SUPPORTED IN NEWER CDVDMAN MODULES INCLUDED WITHIN DNAS IOPRP ONLY
*
* @param cb The pointer to the callback
* @param userdata The pointer to the userdata that will be passed to the callback
* @return The old callback value
*/
void *sceCdSetAtapiEjectCallback(int (*cb)(int reason, void *userdata), void *userdata);

//DNAS functions

/** Reads the Disk ID.
Expand All @@ -73,6 +95,18 @@ int sceCdSpinCtrlIOP(u32 speed);
*/
int sceCdReadDiskID(unsigned int *id);

/** Deobfuscate using unique key.
* Unofficial name.
* SUPPORTED IN NEWER CDVDMAN MODULES INCLUDED WITHIN DNAS IOPRP ONLY
*
* @param buffer Output buffer
* @param shiftval The amount to rotate left shift
* @param xorval The value to XOR the buffer against
* @param status Command status
* @return 1 on success, 0 on failure.
*/
int sceCdDeobfuscateUsingUniqueKey(u8 *buffer, unsigned int shiftval, int xorval, u32 *status);

#define cdvdman_IMPORTS_start DECLARE_IMPORT_TABLE(cdvdman, 1, 1)
#define cdvdman_IMPORTS_end END_IMPORT_TABLE

Expand Down Expand Up @@ -163,17 +197,23 @@ int sceCdReadDiskID(unsigned int *id);
#define I_sceCdApplySCmd2 DECLARE_IMPORT(112, sceCdApplySCmd2)
#define I_sceCdRE DECLARE_IMPORT(114, sceCdRE)
#define I_sceCdRcBypassCtl DECLARE_IMPORT(115, sceCdRcBypassCtl)
#define I_sceCdSendSCmd1D DECLARE_IMPORT(116, sceCdSendSCmd1D)
#define I_sceRemote2_7 DECLARE_IMPORT(117, sceRemote2_7)
#define I_sceCdSetLEDsMode DECLARE_IMPORT(120, sceCdSetLEDsMode)
#define I_sceCdApplySCmd3 DECLARE_IMPORT(125, sceCdApplySCmd3)
#define I_sceRemote2_7Get DECLARE_IMPORT(128, sceRemote2_7Get)
#define I_sceCdReadPS1BootParam DECLARE_IMPORT(148, sceCdReadPS1BootParam)
#define I_sceCdSetFanProfile DECLARE_IMPORT(150, sceCdSetFanProfile)
#define I_sceCdChgSys DECLARE_IMPORT(154, sceCdChgSys)
#define I_sceCdNoticeGameStart DECLARE_IMPORT(156, sceCdNoticeGameStart)
#define I_sceCdDeobfuscateUsingUniqueKey DECLARE_IMPORT(161, sceCdDeobfuscateUsingUniqueKey)
#define I_sceCdXLEDCtl DECLARE_IMPORT(163, sceCdXLEDCtl)
#define I_sceCdBuzzerCtl DECLARE_IMPORT(165, sceCdBuzzerCtl)
#define I_sceCdXBSPowerCtl DECLARE_IMPORT(171, sceCdXBSPowerCtl)
#define I_sceCdSetAtapiEjectCallback DECLARE_IMPORT(173, sceCdSetAtapiEjectCallback)
#define I_sceCdSetMediumRemoval DECLARE_IMPORT(175, sceCdSetMediumRemoval)
#define I_sceCdGetMediumRemoval DECLARE_IMPORT(177, sceCdGetMediumRemoval)
#define I_sceCdDoesUniqueKeyExist DECLARE_IMPORT(179, sceCdDoesUniqueKeyExist)
#define I_sceCdXDVRPReset DECLARE_IMPORT(181, sceCdXDVRPReset)
#define I_sceCdGetWakeUpReason DECLARE_IMPORT(183, sceCdGetWakeUpReason)
#define I_sceCdReadRegionParams DECLARE_IMPORT(189, sceCdReadRegionParams)
Expand Down

0 comments on commit 1d61154

Please sign in to comment.