From e943b25bc5adc0d0b834dd2ced993a506db5d871 Mon Sep 17 00:00:00 2001 From: fincs Date: Thu, 1 Jan 2015 16:23:09 +0100 Subject: [PATCH] CSND: move waiting code to csndExecChnCmds() --- libctru/include/3ds/services/csnd.h | 4 ++-- libctru/source/services/csnd.c | 23 ++++++++--------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/libctru/include/3ds/services/csnd.h b/libctru/include/3ds/services/csnd.h index a9d65c3..ef6656d 100644 --- a/libctru/include/3ds/services/csnd.h +++ b/libctru/include/3ds/services/csnd.h @@ -24,7 +24,7 @@ Result csndInit(void); Result csndExit(void); void csndWriteChnCmd(int cmdid, u8 *cmdparams); -Result csndExecChnCmds(void); +Result csndExecChnCmds(bool waitDone); void CSND_ChnSetPlayStateR(u32 channel, u32 value); void CSND_ChnSetPlayState(u32 channel, u32 value); @@ -33,7 +33,7 @@ void CSND_ChnSetVol(u32 channel, u16 left, u16 right); void CSND_ChnSetTimer(u32 channel, u32 timer); void CSND_ChnConfig(u32 channel, u32 looping, u32 encoding, u32 timer, u32 unk0, u32 unk1, u32 physaddr0, u32 physaddr1, u32 totalbytesize); -Result CSND_UpdateChnInfo(bool waitdone); +Result CSND_UpdateChnInfo(bool waitDone); Result csndChnPlaySound(u32 channel, u32 looping, u32 encoding, u32 samplerate, u32 *vaddr0, u32 *vaddr1, u32 totalbytesize, u32 unk0, u32 unk1); diff --git a/libctru/source/services/csnd.c b/libctru/source/services/csnd.c index 85d9bde..ede9a5a 100644 --- a/libctru/source/services/csnd.c +++ b/libctru/source/services/csnd.c @@ -149,7 +149,7 @@ void csndWriteChnCmd(int cmdid, u8 *cmdparams) svcReleaseMutex(csndMutex); } -Result csndExecChnCmds(void) +Result csndExecChnCmds(bool waitDone) { Result ret=0; @@ -157,9 +157,14 @@ Result csndExecChnCmds(void) if (csndCmdStartOff == csndCmdCurOff) return 0; + vu8* flag = (vu8*)&csndSharedMem[csndCmdStartOff>>2]; + ret = CSND_ExecChnCmds(csndCmdStartOff); csndCmdStartOff = csndCmdCurOff; + // FIXME: This is a really ugly busy waiting loop! + while (waitDone && *flag == 0); + return ret; } @@ -248,26 +253,14 @@ void CSND_ChnConfig(u32 channel, u32 looping, u32 encoding, u32 timer, u32 unk0, csndWriteChnCmd(0xe, (u8*)&cmdparams); } -Result CSND_UpdateChnInfo(bool waitdone) +Result CSND_UpdateChnInfo(bool waitDone) { - u8 *ptr; - int ret=0; - u32 cmdparams[0x18>>2]; memset(cmdparams, 0, 0x18); - ptr = (u8*)&csndSharedMem[csndCmdStartOff>>2]; - csndWriteChnCmd(0x300, (u8*)&cmdparams); - - ret = csndExecChnCmds(); - if (ret != 0) return ret; - - // This is bad! Busy loops are bad! - while (waitdone && *ptr == 0); - - return 0; + return csndExecChnCmds(waitDone); } Result csndChnPlaySound(u32 channel, u32 looping, u32 encoding, u32 samplerate, u32 *vaddr0, u32 *vaddr1, u32 totalbytesize, u32 unk0, u32 unk1)