Skip to content

Commit 654b026

Browse files
authored
Merge pull request #750 from uyjulian/sdrdrv
Implementation of sdrdrv module
2 parents b09db35 + 523f532 commit 654b026

File tree

11 files changed

+999
-1
lines changed

11 files changed

+999
-1
lines changed

iop/sound/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ SUBDIRS = \
1414
libsnd2 \
1515
libspu2 \
1616
ps2snd \
17-
rspu2drv
17+
rspu2drv \
18+
sdrdrv
1819

1920
include $(PS2SDKSRC)/Defs.make
2021
include $(PS2SDKSRC)/Rules.make

iop/sound/sdrdrv/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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_IMPORT_INCS += \
10+
sound/libsd \
11+
system/intrman \
12+
system/loadcore \
13+
system/sifcmd \
14+
system/sysclib \
15+
system/sysmem \
16+
system/threadman
17+
18+
IOP_OBJS = sdd_main.o sdd_com.o sdd_cb.o imports.o exports.o
19+
20+
include $(PS2SDKSRC)/Defs.make
21+
include $(PS2SDKSRC)/iop/Rules.bin.make
22+
include $(PS2SDKSRC)/iop/Rules.make
23+
include $(PS2SDKSRC)/iop/Rules.release

iop/sound/sdrdrv/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Sound Device Remote Library
2+
3+
This module is a IOP-side SIF RPC server for accessing libsd functions.
4+
5+
## Configurations
6+
7+
There are multiple configurations of this library, allowing the choice of
8+
balancing between size, speed, and features.
9+
10+
* `sdrdrv` -> The recommended version.
11+
12+
## How to use this module in your program
13+
14+
In order to use this module in your program, use `LoadModule` or \
15+
`LoadModuleBuffer` with no arguments.

iop/sound/sdrdrv/include/sdrdrv.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
#ifndef _SDRDRV_H
12+
#define _SDRDRV_H
13+
14+
typedef int (*sceSdrUserCommandFunction)(unsigned int command, void *data, int size);
15+
16+
extern int sceSdrChangeThreadPriority(int priority_main, int priority_cb);
17+
extern sceSdrUserCommandFunction sceSdrSetUserCommandFunction(int command, sceSdrUserCommandFunction func);
18+
19+
#define sdrdrv_IMPORTS_start DECLARE_IMPORT_TABLE(sdrdrv, 1, 1)
20+
#define sdrdrv_IMPORTS_end END_IMPORT_TABLE
21+
22+
#define I_sceSdrChangeThreadPriority DECLARE_IMPORT(4, sceSdrChangeThreadPriority)
23+
#define I_sceSdrSetUserCommandFunction DECLARE_IMPORT(5, sceSdrSetUserCommandFunction)
24+
25+
#endif

iop/sound/sdrdrv/src/exports.tab

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
DECLARE_EXPORT_TABLE(sdrdrv, 1, 1)
3+
DECLARE_EXPORT(_start)
4+
DECLARE_EXPORT(_retonly)
5+
DECLARE_EXPORT(_retonly)
6+
DECLARE_EXPORT(_retonly)
7+
DECLARE_EXPORT(sceSdrChangeThreadPriority)
8+
DECLARE_EXPORT(sceSdrSetUserCommandFunction)
9+
END_EXPORT_TABLE
10+
11+
void _retonly() {}

iop/sound/sdrdrv/src/imports.lst

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
libsd_IMPORTS_start
3+
I_sceSdInit
4+
I_sceSdSetParam
5+
I_sceSdGetParam
6+
I_sceSdSetSwitch
7+
I_sceSdGetSwitch
8+
I_sceSdSetAddr
9+
I_sceSdGetAddr
10+
I_sceSdSetCoreAttr
11+
I_sceSdGetCoreAttr
12+
I_sceSdNote2Pitch
13+
I_sceSdPitch2Note
14+
I_sceSdProcBatch
15+
I_sceSdProcBatchEx
16+
I_sceSdVoiceTrans
17+
I_sceSdBlockTrans
18+
I_sceSdVoiceTransStatus
19+
I_sceSdBlockTransStatus
20+
I_sceSdSetEffectAttr
21+
I_sceSdGetEffectAttr
22+
I_sceSdClearEffectWorkArea
23+
I_sceSdSetTransIntrHandler
24+
I_sceSdSetSpu2IntrHandler
25+
I_sceSdStopTrans
26+
I_sceSdCleanEffectWorkArea
27+
I_sceSdSetEffectMode
28+
I_sceSdSetEffectModeParams
29+
I_sceSdSetIRQCallback
30+
I_sceSdSetTransCallback
31+
libsd_IMPORTS_end
32+
33+
sysmem_IMPORTS_start
34+
I_Kprintf
35+
sysmem_IMPORTS_end
36+
37+
intrman_IMPORTS_start
38+
I_CpuSuspendIntr
39+
I_CpuResumeIntr
40+
intrman_IMPORTS_end
41+
42+
loadcore_IMPORTS_start
43+
I_RegisterLibraryEntries
44+
I_ReleaseLibraryEntries
45+
loadcore_IMPORTS_end
46+
47+
sifcmd_IMPORTS_start
48+
I_sceSifInitRpc
49+
I_sceSifBindRpc
50+
I_sceSifCallRpc
51+
I_sceSifRegisterRpc
52+
I_sceSifSetRpcQueue
53+
I_sceSifRpcLoop
54+
I_sceSifRemoveRpc
55+
I_sceSifRemoveRpcQueue
56+
sifcmd_IMPORTS_end
57+
58+
sysclib_IMPORTS_start
59+
I_look_ctype_table
60+
I_strncmp
61+
I_strtol
62+
I_memset
63+
I_memcpy
64+
sysclib_IMPORTS_end
65+
66+
thbase_IMPORTS_start
67+
I_CreateThread
68+
I_DeleteThread
69+
I_StartThread
70+
I_TerminateThread
71+
I_ChangeThreadPriority
72+
I_GetThreadId
73+
I_ReferThreadStatus
74+
I_SleepThread
75+
I_iWakeupThread
76+
I_iCancelWakeupThread
77+
thbase_IMPORTS_end

iop/sound/sdrdrv/src/irx_imports.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
# Defines all IRX imports.
11+
*/
12+
13+
#ifndef IOP_IRX_IMPORTS_H
14+
#define IOP_IRX_IMPORTS_H
15+
16+
#include <irx.h>
17+
18+
/* Please keep these in alphabetical order! */
19+
#include <intrman.h>
20+
#include <libsd.h>
21+
#include <loadcore.h>
22+
#include <sifcmd.h>
23+
#include <sysclib.h>
24+
#include <sysmem.h>
25+
#include <thbase.h>
26+
27+
#endif /* IOP_IRX_IMPORTS_H */

iop/sound/sdrdrv/src/sdd_cb.c

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
#include <sdr_i.h>
12+
13+
// Unofficial: argument
14+
static void sceSifCmdLoop2(SifRpcClientData_t *cd, SdrEECBInfo *cbi)
15+
{
16+
while ( 1 )
17+
{
18+
int state;
19+
// Unofficial: make local variable
20+
SdrEECBData eeCBDataSend;
21+
22+
while ( !cbi->m_eeCBData.mode )
23+
SleepThread();
24+
CpuSuspendIntr(&state);
25+
// Unofficial: was inlined
26+
memcpy(&eeCBDataSend, &cbi->m_eeCBData, sizeof(eeCBDataSend));
27+
CpuResumeIntr(state);
28+
#if SDRDRV_EECB_COMPAT
29+
if ( eeCBDataSend.mode )
30+
{
31+
int mode_tmp;
32+
int mode_cur;
33+
34+
mode_tmp = eeCBDataSend.mode;
35+
mode_cur = mode_tmp;
36+
while ( 1 )
37+
{
38+
// Only the obsolete DMA0/DMA1/IRQ funcs (not implemented in libsdr 4.0.1) clashes
39+
if ( mode_cur & (1 << 0) )
40+
{
41+
mode_cur &= ~(1 << 0);
42+
eeCBDataSend.mode = 1;
43+
}
44+
else if ( mode_cur & (1 << 1) )
45+
{
46+
mode_cur &= ~(1 << 1);
47+
eeCBDataSend.mode = 2;
48+
}
49+
else if ( mode_cur & (1 << 2) )
50+
{
51+
mode_cur &= ~(1 << 2);
52+
eeCBDataSend.mode = 3;
53+
}
54+
else if ( mode_cur & (1 << 8) )
55+
{
56+
mode_cur &= ~(1 << 8);
57+
eeCBDataSend.mode = 11;
58+
}
59+
else if ( mode_cur & (1 << 9) )
60+
{
61+
mode_cur &= ~(1 << 9);
62+
eeCBDataSend.mode = 12;
63+
}
64+
else if ( mode_cur & (1 << 10) )
65+
{
66+
mode_cur &= ~(1 << 10);
67+
eeCBDataSend.mode = 13;
68+
}
69+
else
70+
{
71+
break;
72+
}
73+
sceSifCallRpc(cd, 0, 0, &eeCBDataSend, sizeof(eeCBDataSend), 0, 0, 0, 0);
74+
}
75+
eeCBDataSend.mode = mode_tmp;
76+
}
77+
// Set the high bit to make libsdr 2.0.0 and lower not process it
78+
eeCBDataSend.mode |= ((u32)1 << 31);
79+
#endif
80+
sceSifCallRpc(cd, 0, 0, &eeCBDataSend, sizeof(eeCBDataSend), 0, 0, 0, 0);
81+
#if SDRDRV_EECB_COMPAT
82+
eeCBDataSend.mode &= ~((u32)1 << 31);
83+
#endif
84+
CpuSuspendIntr(&state);
85+
if ( cbi->m_eeCBData.mode == eeCBDataSend.mode )
86+
{
87+
cbi->m_eeCBData.mode = 0;
88+
iCancelWakeupThread(0);
89+
CpuResumeIntr(state);
90+
break;
91+
}
92+
cbi->m_eeCBData.mode &= ~eeCBDataSend.mode;
93+
CpuResumeIntr(state);
94+
}
95+
}
96+
97+
#if SDRDRV_OBSOLETE_FUNCS
98+
int _sce_sdrDMA0CallBackProc(void *data)
99+
{
100+
(void)data;
101+
102+
g_eeCBInfo.m_eeCBData.mode |= (1 << 0);
103+
iWakeupThread(g_eeCBInfo.m_thid_cb);
104+
return 1;
105+
}
106+
107+
int _sce_sdrDMA1CallBackProc(void *data)
108+
{
109+
(void)data;
110+
111+
g_eeCBInfo.m_eeCBData.mode |= (1 << 1);
112+
iWakeupThread(g_eeCBInfo.m_thid_cb);
113+
return 1;
114+
}
115+
116+
int _sce_sdrIRQCallBackProc(void *data)
117+
{
118+
(void)data;
119+
120+
g_eeCBInfo.m_eeCBData.mode |= (1 << 2);
121+
iWakeupThread(g_eeCBInfo.m_thid_cb);
122+
return 1;
123+
}
124+
#endif
125+
126+
int _sce_sdrDMA0IntrHandler(int core, void *common)
127+
{
128+
SdrEECBInfo *cbi;
129+
130+
(void)core;
131+
132+
cbi = (SdrEECBInfo *)common;
133+
cbi->m_eeCBData.mode |= (1 << 8);
134+
iWakeupThread(cbi->m_thid_cb);
135+
return 0;
136+
}
137+
138+
int _sce_sdrDMA1IntrHandler(int core, void *common)
139+
{
140+
SdrEECBInfo *cbi;
141+
142+
(void)core;
143+
144+
cbi = (SdrEECBInfo *)common;
145+
cbi->m_eeCBData.mode |= (1 << 9);
146+
iWakeupThread(cbi->m_thid_cb);
147+
return 0;
148+
}
149+
150+
int _sce_sdrSpu2IntrHandler(int core_bit, void *common)
151+
{
152+
SdrEECBInfo *cbi;
153+
154+
(void)core_bit;
155+
156+
cbi = (SdrEECBInfo *)common;
157+
cbi->m_eeCBData.mode |= (1 << 10);
158+
cbi->m_eeCBData.voice_bit = core_bit;
159+
iWakeupThread(cbi->m_thid_cb);
160+
return 0;
161+
}
162+
163+
void sce_sdrcb_loop(void *arg)
164+
{
165+
SdrEECBInfo *cbi;
166+
// Unofficial: make local
167+
SifRpcClientData_t cd;
168+
169+
cbi = (SdrEECBInfo *)arg;
170+
cbi->m_eeCBData.mode = 0;
171+
while ( sceSifBindRpc(&cd, 0x80000704, 0) >= 0 )
172+
{
173+
int i;
174+
175+
for ( i = 0; i < 10000; i += 1 )
176+
;
177+
if ( cd.server )
178+
sceSifCmdLoop2(&cd, cbi);
179+
}
180+
Kprintf("error \n");
181+
while ( 1 )
182+
;
183+
}

0 commit comments

Comments
 (0)