From a68ee146322457aebf461636df1270ce90e8c741 Mon Sep 17 00:00:00 2001 From: Lectem Date: Wed, 9 Sep 2015 09:48:40 -0400 Subject: [PATCH] Formatting and fixes for DSP --- libctru/include/3ds/services/dsp.h | 19 +++++++++-------- libctru/source/services/dsp.c | 33 +++++++++++------------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/libctru/include/3ds/services/dsp.h b/libctru/include/3ds/services/dsp.h index 045c88d..9cfb78b 100644 --- a/libctru/include/3ds/services/dsp.h +++ b/libctru/include/3ds/services/dsp.h @@ -13,8 +13,8 @@ typedef enum { typedef enum { - DSP_PIPE_INPUT = 0, ///< DSP to ARM - DSP_PIPE_OUTPUT = 1 ///< ARM to DSP + DSP_PIPE_INPUT = 0, ///< DSP to ARM + DSP_PIPE_OUTPUT = 1 ///< ARM to DSP } DSP_PipeDirection; /** @@ -90,17 +90,18 @@ Result DSP_RegisterInterruptEvents(Handle handle,u32 interrupt,u32 channel); /** - * @param channel ?????? TODO usually 2 - * @param buffer The buffer that will store the values read from the pipe - * @param length Length of the buffer + * @param channel unknown. Usually 2 + * @param peer unknown. Usually 0 + * @param buffer The buffer that will store the values read from the pipe + * @param length Length of the buffer * @param length_read Number of bytes read by the command */ -Result DSP_ReadPipeIfPossible(u32 channel, u8 const *buffer, u16 length, u16* length_read); +Result DSP_ReadPipeIfPossible(u32 channel,u32 peer, u8 const *buffer, u16 length, u16* length_read); /** - * @param channel ?????? TODO usually 2 - * @param buffer The message to send to the DSP process - * @param length Length of the message + * @param channel unknown. Usually 2 + * @param buffer The message to send to the DSP process + * @param length Length of the message */ Result DSP_WriteProcessPipe(u32 channel,u8 const* buffer,u32 length); diff --git a/libctru/source/services/dsp.c b/libctru/source/services/dsp.c index 05e006b..603af9c 100644 --- a/libctru/source/services/dsp.c +++ b/libctru/source/services/dsp.c @@ -4,19 +4,17 @@ #include <3ds/ipc.h> #include <3ds/services/dsp.h> -Handle dspHandle = 0; +static Handle dspHandle = 0; Result dspInit(void) { Result ret = 0; - if (dspHandle == 0) { ret = srvGetServiceHandle(&dspHandle, "dsp::DSP"); if (ret < 0) return ret; } - if (ret < 0) return ret; DSP_UnloadComponent(); return 0; } @@ -40,7 +38,7 @@ Result DSP_GetHeadphoneStatus(bool* is_inserted) { Result ret = 0; u32* cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = IPC_MakeHeader(0x001F,0,0); + cmdbuf[0] = IPC_MakeHeader(0x1F,0,0); if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret; *is_inserted = cmdbuf[2] & 0xFF; return cmdbuf[1]; @@ -148,44 +146,37 @@ Result DSP_RegisterInterruptEvents(Handle handle, u32 interrupt, u32 channel) } -Result DSP_ReadPipeIfPossibleEx(u32 channel,u32 unk1, u8 const *buffer, u16 length, u16* length_read) +Result DSP_ReadPipeIfPossible(u32 channel,u32 peer, u8 const *buffer, u16 length, u16* length_read) { Result ret = 0; u32* cmdbuf = getThreadCommandBuffer(); cmdbuf[0] = IPC_MakeHeader(0x10,3,0); cmdbuf[1] = channel; - cmdbuf[2] = unk1; + cmdbuf[2] = peer; cmdbuf[3] = length; - u32 * staticbufs = cmdbuf + 0x100; + u32 * staticbufs = getThreadStaticBuffers(); - u32 saved1 = staticbufs[0x0]; - u32 saved2 = staticbufs[0x4]; + u32 saved1 = staticbufs[0]; + u32 saved2 = staticbufs[1]; - staticbufs[0] = (length<<14) | 2; - staticbufs[4] = (u32)buffer; + staticbufs[0] = IPC_Desc_StaticBuffer(length,0); + staticbufs[1] = (u32)buffer; if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret; staticbufs[0] = saved1; - staticbufs[4] = saved2; + staticbufs[1] = saved2; *length_read = cmdbuf[2] & 0xFFFF; return cmdbuf[1]; } -//TODO change DSP_ReadPipeIfPossibleEx into DSP_ReadPipeIfPossible once unk1 is figured out -//However it seems that it is always used with value 0 -Result DSP_ReadPipeIfPossible(u32 channel, u8 const *buffer, u16 length, u16* length_read) -{ - return DSP_ReadPipeIfPossibleEx(channel,0,buffer,length, length_read); -} - Result DSP_WriteProcessPipe(u32 channel, u8 const *buffer, u32 length) { Result ret = 0; u32* cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = IPC_MakeHeader(0xd,2,2); + cmdbuf[0] = IPC_MakeHeader(0xD,2,2); cmdbuf[1] = channel; cmdbuf[2] = length; cmdbuf[3] = IPC_Desc_StaticBuffer(length,1); @@ -198,7 +189,7 @@ Result DSP_ConvertProcessAddressFromDspDram(u32 dsp_address, u32 *arm_address) { Result ret = 0; u32* cmdbuf = getThreadCommandBuffer(); - cmdbuf[0] = IPC_MakeHeader(0xc,1,0); + cmdbuf[0] = IPC_MakeHeader(0xC,1,0); cmdbuf[1] = dsp_address; if ((ret = svcSendSyncRequest(dspHandle)) != 0) return ret; *arm_address = cmdbuf[2];