Skip to content

Commit dd840cc

Browse files
authored
Merge pull request #804 from uyjulian/xatapi
Add implementation of xatapi module
2 parents a73bba7 + d8ac8b4 commit dd840cc

File tree

13 files changed

+3886
-32
lines changed

13 files changed

+3886
-32
lines changed

common/include/libcdvd-common.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,30 @@ extern int sceCdReadRegionParams(u32 *arg1, u32 *result);
11661166
*/
11671167
extern int sceCdWriteRegionParams(u8 arg1, u32 *arg2, u8 *arg3, u32 *result);
11681168

1169+
/** Gets temperature of the temperature sensor connected to Mechacon in Celsius
1170+
* Minimum Mechacon firmware version: 50400
1171+
* SUPPORTED IN XCDVDMAN INCLUDED WITHIN NEWER BOOT ROMS ONLY
1172+
*
1173+
* @return 1 on success, 0 on failure
1174+
*/
1175+
extern int cdvdman_152_get_temperature(u32 *param, u32 *status);
1176+
1177+
/** Stores some sort of buffer from ATAPI drive to PS2 drive.
1178+
* Minimum Mechacon firmware version: 50400
1179+
* SUPPORTED BY ONLY DESR/PSX DVR CDVDMAN MODULES
1180+
*
1181+
* @return 1 on success, 0 on failure
1182+
*/
1183+
extern int cdvdman_167_atapi2dragon(u8 *inbuf, u32 *status);
1184+
1185+
/** Stores some sort of buffer from PS2 drive to ATAPI drive.
1186+
* Minimum Mechacon firmware version: 50400
1187+
* SUPPORTED BY ONLY DESR/PSX DVR CDVDMAN MODULES
1188+
*
1189+
* @return 1 on success, 0 on failure
1190+
*/
1191+
extern int cdvdman_169_dragon2atapi(u8 *outbuf, u32 *status);
1192+
11691193
// Compatibility names for older ps2sdk versions.
11701194

11711195
// sceCdlFILE renames

common/include/libcdvd-rpc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ typedef struct cdvdfsv_rpc3_3B_outpacket_
639639
{
640640
int m_retres;
641641
u32 m_arg2;
642-
u32 m_arg1;
642+
u8 m_arg1[16];
643643
} cdvdfsv_rpc3_3B_outpacket_t;
644644

645645
typedef struct cdvdfsv_rpc3_3C_outpacket_

iop/cdvd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SUBDIRS = \
1212
cdvdman \
1313
cdvdstm \
1414
poffsim \
15+
xatapi \
1516
xesdrv
1617

1718
include $(PS2SDKSRC)/Defs.make

iop/cdvd/cdvdfsv/src/cdvdfsv.c

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,7 @@ cdvdfsv_rpc3_2B_setfanprofile(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen,
23622362
#endif
23632363

23642364
#ifdef CDVD_VARIANT_OSD
2365-
static void cdvdfsv_rpc3_2C_i_152(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2365+
static void cdvdfsv_rpc3_2C_i_152_gettemperature(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
23662366
{
23672367
int i;
23682368
u32 efbits;
@@ -2373,12 +2373,7 @@ static void cdvdfsv_rpc3_2C_i_152(const cdvdfsv_rpc3_inpacket_t *inbuf, int bufl
23732373
for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
23742374
{
23752375
WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2376-
#if 0
2377-
// TODO FIXME IMPORT
2378-
outbuf->m_retres = cdvdman_152(&outbuf->m_pkt_2C.m_arg1, &outbuf->m_pkt_2C.m_arg2);
2379-
#else
2380-
outbuf->m_retres = 1;
2381-
#endif
2376+
outbuf->m_retres = cdvdman_152_get_temperature(&outbuf->m_pkt_2C.m_arg1, &outbuf->m_pkt_2C.m_arg2);
23822377
}
23832378
}
23842379
#endif
@@ -2572,7 +2567,7 @@ cdvdfsv_rpc3_39_buzzerctl(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvd
25722567

25732568
#ifdef CDVD_VARIANT_XOSD
25742569
static void
2575-
cdvdfsv_rpc3_3A_resetwakeupreason(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2570+
cdvdfsv_rpc3_3A_i_167_atapi2dragon(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
25762571
{
25772572
int i;
25782573
u32 efbits;
@@ -2582,19 +2577,13 @@ cdvdfsv_rpc3_3A_resetwakeupreason(const cdvdfsv_rpc3_inpacket_t *inbuf, int bufl
25822577
for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
25832578
{
25842579
WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2585-
#if 0
2586-
// TODO FIXME IMPORT
2587-
outbuf->m_retres = sceCdResetWakeupReason((u32 *)inbuf, &outbuf->m_pkt_3A.m_arg2);
2588-
#else
2589-
(void)inbuf;
2590-
outbuf->m_retres = 1;
2591-
#endif
2580+
outbuf->m_retres = cdvdman_167_atapi2dragon((char *)inbuf, &outbuf->m_pkt_3A.m_arg2);
25922581
}
25932582
}
25942583
#endif
25952584

25962585
#ifdef CDVD_VARIANT_XOSD
2597-
static void cdvdfsv_rpc3_3B_i_169(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
2586+
static void cdvdfsv_rpc3_3B_i_169_dragon2atapi(const cdvdfsv_rpc3_inpacket_t *inbuf, int buflen, cdvdfsv_rpc3_outpacket_t *outbuf)
25982587
{
25992588
int i;
26002589
u32 efbits;
@@ -2605,12 +2594,7 @@ static void cdvdfsv_rpc3_3B_i_169(const cdvdfsv_rpc3_inpacket_t *inbuf, int bufl
26052594
for ( i = 0; i < 3 && !outbuf->m_retres; i += 1 )
26062595
{
26072596
WaitEventFlag(g_scmd_evfid, 1, WEF_AND, &efbits);
2608-
#if 0
2609-
// TODO FIXME IMPORT
2610-
outbuf->m_retres = cdvdman_169(&outbuf->m_pkt_3B.m_arg1, &outbuf->m_pkt_3B.m_arg2);
2611-
#else
2612-
outbuf->m_retres = 1;
2613-
#endif
2597+
outbuf->m_retres = cdvdman_169_dragon2atapi(outbuf->m_pkt_3B.m_arg1, &outbuf->m_pkt_3B.m_arg2);
26142598
}
26152599
}
26162600
#endif
@@ -3159,7 +3143,7 @@ static void *cbrpc_rpc3_cdvdscmds(int fno, void *buffer, int length)
31593143
cdvdfsv_rpc3_2B_setfanprofile(buffer, length, &g_outbuf);
31603144
break;
31613145
case 44:
3162-
cdvdfsv_rpc3_2C_i_152(buffer, length, &g_outbuf);
3146+
cdvdfsv_rpc3_2C_i_152_gettemperature(buffer, length, &g_outbuf);
31633147
break;
31643148
#endif
31653149
#ifdef CDVD_VARIANT_XOSD
@@ -3195,10 +3179,10 @@ static void *cbrpc_rpc3_cdvdscmds(int fno, void *buffer, int length)
31953179
cdvdfsv_rpc3_39_buzzerctl(buffer, length, &g_outbuf);
31963180
break;
31973181
case 58:
3198-
cdvdfsv_rpc3_3A_resetwakeupreason(buffer, length, &g_outbuf);
3182+
cdvdfsv_rpc3_3A_i_167_atapi2dragon(buffer, length, &g_outbuf);
31993183
break;
32003184
case 59:
3201-
cdvdfsv_rpc3_3B_i_169(buffer, length, &g_outbuf);
3185+
cdvdfsv_rpc3_3B_i_169_dragon2atapi(buffer, length, &g_outbuf);
32023186
break;
32033187
case 60:
32043188
cdvdfsv_rpc3_3C_xbspowerctl(buffer, length, &g_outbuf);

iop/cdvd/cdvdman/include/cdvdman.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,14 @@ extern int sceCdDeobfuscateUsingUniqueKey(u8 *buffer, unsigned int shiftval, int
317317
#define I_sceRemote2_7Get DECLARE_IMPORT(128, sceRemote2_7Get)
318318
#define I_sceCdReadPS1BootParam DECLARE_IMPORT(148, sceCdReadPS1BootParam)
319319
#define I_sceCdSetFanProfile DECLARE_IMPORT(150, sceCdSetFanProfile)
320+
#define I_cdvdman_152_get_temperature DECLARE_IMPORT(152, cdvdman_152_get_temperature)
320321
#define I_sceCdChgSys DECLARE_IMPORT(154, sceCdChgSys)
321322
#define I_sceCdNoticeGameStart DECLARE_IMPORT(156, sceCdNoticeGameStart)
322323
#define I_sceCdDeobfuscateUsingUniqueKey DECLARE_IMPORT(161, sceCdDeobfuscateUsingUniqueKey)
323324
#define I_sceCdXLEDCtl DECLARE_IMPORT(163, sceCdXLEDCtl)
324325
#define I_sceCdBuzzerCtl DECLARE_IMPORT(165, sceCdBuzzerCtl)
326+
#define I_cdvdman_167_atapi2dragon DECLARE_IMPORT(167, cdvdman_167_atapi2dragon)
327+
#define I_cdvdman_169_dragon2atapi DECLARE_IMPORT(169, cdvdman_169_dragon2atapi)
325328
#define I_sceCdXBSPowerCtl DECLARE_IMPORT(171, sceCdXBSPowerCtl)
326329
#define I_sceCdSetAtapiEjectCallback DECLARE_IMPORT(173, sceCdSetAtapiEjectCallback)
327330
#define I_sceCdSetMediumRemoval DECLARE_IMPORT(175, sceCdSetMediumRemoval)

iop/cdvd/cdvdman/src/cdvdman.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7811,7 +7811,7 @@ int sceCdSetFanProfile(u8 param, u32 *status)
78117811
return retval;
78127812
}
78137813

7814-
int cdvdman_152(u32 *param, u32 *status)
7814+
int cdvdman_152_get_temperature(u32 *param, u32 *status)
78157815
{
78167816
int retval;
78177817
char rdata[3];
@@ -8670,20 +8670,20 @@ int sceCdBuzzerCtl(u32 *status)
86708670
#endif
86718671

86728672
#ifdef CDVD_VARIANT_XOSD
8673-
int sceCdResetWakeupReason(u32 *inbuf, u32 *status)
8673+
int cdvdman_167_atapi2dragon(u8 *inbuf, u32 *status)
86748674
{
86758675
if ( !g_cdvdman_minver_50600 )
86768676
{
86778677
*status = 256;
86788678
return 1;
86798679
}
86808680
*status = SCECdErNO;
8681-
return cdvdman_write_scmd_swap_dev5(0x2F, (char *)inbuf, 16, (char *)status, 1, 1);
8681+
return cdvdman_write_scmd_swap_dev5(0x2F, inbuf, 16, (char *)status, 1, 1);
86828682
}
86838683
#endif
86848684

86858685
#ifdef CDVD_VARIANT_XOSD
8686-
int cdvdman_169(u32 *arg1, u32 *status)
8686+
int cdvdman_169_dragon2atapi(u8 *outbuf, u32 *status)
86878687
{
86888688
int i;
86898689
int retval;
@@ -8701,7 +8701,7 @@ int cdvdman_169(u32 *arg1, u32 *status)
87018701
{
87028702
return 0;
87038703
}
8704-
memset(arg1, 0, 16);
8704+
memset(outbuf, 0, 16);
87058705
if ( *status )
87068706
{
87078707
vSetEventFlag(g_scmd_evfid, 1);
@@ -8716,7 +8716,7 @@ int cdvdman_169(u32 *arg1, u32 *status)
87168716
{
87178717
DelayThread(2000);
87188718
retval = cdvdman_write_scmd_swap_dev5(0x30, wdata, sizeof(wdata), rdata, sizeof(rdata), 0);
8719-
memcpy(&arg1[i * 2], &rdata[1], sizeof(rdata) - 1);
8719+
memcpy(&outbuf[i * 8], &rdata[1], sizeof(rdata) - 1);
87208720
*status = rdata[0];
87218721
}
87228722
}

iop/cdvd/xatapi/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# _____ ___ ____ ___ ____
2+
# ____| | ____| | | |____|
3+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
4+
#-----------------------------------------------------------------------
5+
# Copyright ps2dev - http://www.ps2dev.org
6+
# Licenced under Academic Free License version 2.0
7+
# Review ps2sdk README & LICENSE files for further details.
8+
9+
IOP_BIN ?= xatapi.irx
10+
11+
IOP_CFLAGS += -DBUILDING_CDVD_MODULE
12+
13+
IOP_IMPORT_INCS += \
14+
cdvd/cdvdman \
15+
system/dmacman \
16+
system/intrman \
17+
system/iomanx \
18+
system/loadcore \
19+
system/stdio \
20+
system/sysclib \
21+
system/sysmem \
22+
system/threadman
23+
24+
IOP_OBJS = xatapi.o imports.o exports.o
25+
26+
include $(PS2SDKSRC)/Defs.make
27+
include $(PS2SDKSRC)/iop/Rules.bin.make
28+
include $(PS2SDKSRC)/iop/Rules.make
29+
include $(PS2SDKSRC)/iop/Rules.release

iop/cdvd/xatapi/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# DEV5 SPEED module for ATAPI
2+
3+
This module allows access to the ATAPI CD/DVD drive connected to SPEED on DEV5.
4+
This module also contains support code for switching between the IDE/ATAPI and
5+
MechaCon/Dragon-connected CD/DVD drives.
6+
7+
## Configurations
8+
9+
There are multiple configurations of this library, allowing the choice of
10+
balancing between size, speed, and features.
11+
12+
* `xatapi` -> The recommended version.
13+
14+
## How to use this module in your program
15+
16+
In order to use this module in your program, use `LoadModule` or \
17+
`LoadModuleBuffer` with no arguments.

iop/cdvd/xatapi/include/xatapi.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
# _____ ___ ____ ___ ____
3+
# ____| | ____| | | |____|
4+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5+
#-----------------------------------------------------------------------
6+
# Copyright ps2dev - http://www.ps2dev.org
7+
# Licenced under Academic Free License version 2.0
8+
# Review ps2sdk README & LICENSE files for further details.
9+
*/
10+
11+
/**
12+
* @file
13+
* SPEED ATAPI device driver definitions and imports.
14+
*/
15+
16+
#ifndef _XATAPI_H
17+
#define _XATAPI_H
18+
19+
#include <tamtypes.h>
20+
21+
extern int xatapi_2_terminate(int with_quit);
22+
extern int xatapi_4_sceAtaSoftReset(void);
23+
extern int xatapi_5_sceAtaExecCmd(
24+
void *buf,
25+
u32 blkcount,
26+
u16 feature,
27+
u16 nsector,
28+
u16 sector,
29+
u16 lcyl,
30+
u16 hcyl,
31+
u16 select,
32+
u16 command,
33+
u32 unk10);
34+
extern int xatapi_6_sceAtaWaitResult(void);
35+
extern int xatapi_7_sceCdAtapiExecCmd(s16 n, void *buf, int nsec, int secsize, void *pkt, int pkt_len, int proto);
36+
extern int xatapi_8_sceCdAtapiWaitResult(void);
37+
extern void xatapi_9_sceCdSpdAtaDmaStart(int dir);
38+
extern void xatapi_10_sceCdSpdAtaDmaEnd(void);
39+
extern int xatapi_11_sceAtaGetError(void);
40+
extern int xatapi_12_get_ata_control(void);
41+
extern int xatapi_13_get_speed_reg(int regaddr);
42+
extern int xatapi_14_set_speed_reg(int regaddr, u16 regval);
43+
extern int xatapi_15_exec_f6_f9_scsi(void);
44+
45+
#define xatapi_IMPORTS_start DECLARE_IMPORT_TABLE(xatapi, 1, 1)
46+
#define xatapi_IMPORTS_end END_IMPORT_TABLE
47+
48+
#define I_xatapi_2_terminate DECLARE_IMPORT(2, xatapi_2_terminate)
49+
#define I_xatapi_4_sceAtaSoftReset DECLARE_IMPORT(4, xatapi_4_sceAtaSoftReset)
50+
#define I_xatapi_5_sceAtaExecCmd DECLARE_IMPORT(5, xatapi_5_sceAtaExecCmd)
51+
#define I_xatapi_6_sceAtaWaitResult DECLARE_IMPORT(6, xatapi_6_sceAtaWaitResult)
52+
#define I_xatapi_7_sceCdAtapiExecCmd DECLARE_IMPORT(7, xatapi_7_sceCdAtapiExecCmd)
53+
#define I_xatapi_8_sceCdAtapiWaitResult DECLARE_IMPORT(8, xatapi_8_sceCdAtapiWaitResult)
54+
#define I_xatapi_9_sceCdSpdAtaDmaStart DECLARE_IMPORT(9, xatapi_9_sceCdSpdAtaDmaStart)
55+
#define I_xatapi_10_sceCdSpdAtaDmaEnd DECLARE_IMPORT(10, xatapi_10_sceCdSpdAtaDmaEnd)
56+
#define I_xatapi_11_sceAtaGetError DECLARE_IMPORT(11, xatapi_11_sceAtaGetError)
57+
#define I_xatapi_12_get_ata_control DECLARE_IMPORT(12, xatapi_12_get_ata_control)
58+
#define I_xatapi_13_get_speed_reg DECLARE_IMPORT(13, xatapi_13_get_speed_reg)
59+
#define I_xatapi_14_set_speed_reg DECLARE_IMPORT(14, xatapi_14_set_speed_reg)
60+
#define I_xatapi_15_exec_f6_f9_scsi DECLARE_IMPORT(15, xatapi_15_exec_f6_f9_scsi)
61+
62+
#endif

iop/cdvd/xatapi/src/exports.tab

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
DECLARE_EXPORT_TABLE(xatapi, 1, 1)
3+
DECLARE_EXPORT(_start)
4+
DECLARE_EXPORT(_retonly)
5+
DECLARE_EXPORT(xatapi_2_terminate)
6+
DECLARE_EXPORT(_retonly)
7+
DECLARE_EXPORT(xatapi_4_sceAtaSoftReset)
8+
DECLARE_EXPORT(xatapi_5_sceAtaExecCmd)
9+
DECLARE_EXPORT(xatapi_6_sceAtaWaitResult)
10+
DECLARE_EXPORT(xatapi_7_sceCdAtapiExecCmd)
11+
DECLARE_EXPORT(xatapi_8_sceCdAtapiWaitResult)
12+
DECLARE_EXPORT(xatapi_9_sceCdSpdAtaDmaStart)
13+
DECLARE_EXPORT(xatapi_10_sceCdSpdAtaDmaEnd)
14+
DECLARE_EXPORT(xatapi_11_sceAtaGetError)
15+
DECLARE_EXPORT(xatapi_12_get_ata_control)
16+
DECLARE_EXPORT(xatapi_13_get_speed_reg)
17+
DECLARE_EXPORT(xatapi_14_set_speed_reg)
18+
DECLARE_EXPORT(xatapi_15_exec_f6_f9_scsi)
19+
END_EXPORT_TABLE
20+
21+
void _retonly() {}

0 commit comments

Comments
 (0)