1 // Copyright (c) 2012- PPSSPP Project.
2
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
6
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
11
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18 #include "Core/HLE/HLE.h"
19 #include "Core/HLE/FunctionWrappers.h"
20 #include "Core/HLE/sceP3da.h"
21 #include "Core/MemMap.h"
22 #include "Core/Reporting.h"
23
24
sceP3daBridgeInit(u32 channelsNum,u32 samplesNum)25 static u32 sceP3daBridgeInit(u32 channelsNum, u32 samplesNum)
26 {
27 ERROR_LOG_REPORT(SCEAUDIO, "UNIMPL sceP3daBridgeInit(%08x, %08x)", channelsNum, samplesNum);
28 return 0;
29 }
30
sceP3daBridgeExit()31 static u32 sceP3daBridgeExit()
32 {
33 ERROR_LOG_REPORT(SCEAUDIO, "UNIMPL sceP3daBridgeExit()");
34 return 0;
35 }
36
getScaleValue(u32 channelsNum)37 static inline int getScaleValue(u32 channelsNum) {
38 int val = 0;
39 while (channelsNum > 1) {
40 channelsNum >>= 1;
41 val++;
42 }
43 return val;
44 }
45
sceP3daBridgeCore(u32 p3daCoreAddr,u32 channelsNum,u32 samplesNum,u32 inputAddr,u32 outputAddr)46 static u32 sceP3daBridgeCore(u32 p3daCoreAddr, u32 channelsNum, u32 samplesNum, u32 inputAddr, u32 outputAddr)
47 {
48 DEBUG_LOG(SCEAUDIO, "sceP3daBridgeCore(%08x, %08x, %08x, %08x, %08x)", p3daCoreAddr, channelsNum, samplesNum, inputAddr, outputAddr);
49 if (Memory::IsValidAddress(inputAddr) && Memory::IsValidAddress(outputAddr)) {
50 int scaleval = getScaleValue(channelsNum);
51 s16_le *outbuf = (s16_le *)Memory::GetPointer(outputAddr);
52 memset(outbuf, 0, samplesNum * sizeof(s16) * 2);
53 for (u32 k = 0; k < channelsNum; k++) {
54 u32 inaddr = Memory::Read_U32(inputAddr + k * 4);
55 const s16 *inbuf = (const s16 *)Memory::GetPointer(inaddr);
56 if (!inbuf)
57 continue;
58 for (u32 i = 0; i < samplesNum; i++) {
59 s16 sample = inbuf[i] >> scaleval;
60 outbuf[i*2] += sample;
61 outbuf[i*2 + 1] += sample;
62 }
63 }
64 }
65 // same as sas core
66 return hleDelayResult(0, "p3da core", 240);
67 }
68
69 const HLEFunction sceP3da[] =
70 {
71 {0X374500A5, &WrapU_UU<sceP3daBridgeInit>, "sceP3daBridgeInit", 'x', "xx" },
72 {0X43F756A2, &WrapU_V<sceP3daBridgeExit>, "sceP3daBridgeExit", 'x', "" },
73 {0X013016F3, &WrapU_UUUUU<sceP3daBridgeCore>, "sceP3daBridgeCore", 'x', "xxxxx"},
74 };
75
Register_sceP3da()76 void Register_sceP3da()
77 {
78 RegisterModule("sceP3da", ARRAY_SIZE(sceP3da), sceP3da);
79 }
80