From a1741254cf733aa4335d0e10d07550a07c137552 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 5 Aug 2014 22:22:43 -0400 Subject: [PATCH 1/2] Updated CSND header/.c, including enums for the looping/encoding fields. --- libctru/include/ctr/CSND.h | 24 ++++++++++++++++++------ libctru/source/CSND.c | 10 +++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/libctru/include/ctr/CSND.h b/libctru/include/ctr/CSND.h index 3909cdc..408d1da 100644 --- a/libctru/include/ctr/CSND.h +++ b/libctru/include/ctr/CSND.h @@ -1,18 +1,30 @@ #ifndef CSND_H #define CSND_H +//See here regarding CSND shared-mem commands, etc: http://3dbrew.org/wiki/CSND_Shared_Memory + #define CSND_SHAREDMEM_DEFAULT 0x10004000 -//See here regarding CSND shared-mem commands, etc: http://3dbrew.org/wiki/CSND_Shared_Memory +typedef enum{ + CSND_LOOP_DISABLE, + CSND_LOOP_ENABLE +} CSND_LOOPING; + +typedef enum{ + CSND_ENCODING_PCM8, + CSND_ENCODING_PCM16, + CSND_ENCODING_IMA_ADPCM, + CSND_ENCODING_PSG//"3 = PSG, similar to DS?" +} CSND_ENCODING; Result CSND_initialize(u32* sharedMem); Result CSND_shutdown(); -Result CSND_playsound(u32 channel, u32 looping, u32 encoding, u32 samplerate, u32 *vaddr0, u32 *vaddr1, u32 totalbytesize, u32 unk0, u32 unk1); -void CSND_setchannel_playbackstate(u32 channel, u32 value); -void CSND_sharedmemtype0_cmd0(u32 channel, u32 value); -void CSND_writesharedmem_cmdtype0(u16 cmdid, u8 *cmdparams); -Result CSND_sharedmemtype0_cmdupdatestate(int waitdone); +Result CSND_playsound(u32 channel, CSND_LOOPING looping, CSND_ENCODING encoding, u32 samplerate, u32 *vaddr0, u32 *vaddr1, u32 totalbytesize, u32 unk0, u32 unk1);//vaddr0 is the initial virtual-address of the audio-data. vaddr1 is the audio-data virtual-address used for looping, when playback is restarted for looping. +void CSND_setchannel_playbackstate(u32 channel, u32 value);//value0 = pause playback, value1 = resume playback. +void CSND_sharedmemtype0_cmd0(u32 channel, u32 value);//value1 = start playback. value0 = stop playback, and reset the CSND registers for this channel. +void CSND_writesharedmem_cmdtype0(u16 cmdid, u8 *cmdparams);//This can be used to use arbitary CSND shared-memory commands. +Result CSND_sharedmemtype0_cmdupdatestate(int waitdone);//This must be used after using CSND shared-memory commands in order for those commands to be processed. CSND_playsound() and CSND_getchannelstate() use this automatically. Result CSND_getchannelstate(u32 entryindex, u32 *out); Result CSND_getchannelstate_isplaying(u32 entryindex, u8 *status); diff --git a/libctru/source/CSND.c b/libctru/source/CSND.c index f911b36..cb40db4 100644 --- a/libctru/source/CSND.c +++ b/libctru/source/CSND.c @@ -232,7 +232,7 @@ void CSND_sharedmemtype0_cmd8(u32 channel, u32 samplerate) CSND_writesharedmem_cmdtype0(0x8, (u8*)&cmdparams); } -void CSND_sharedmemtype0_cmde(u32 channel, u32 looping, u32 encoding, u32 samplerate, u32 unk0, u32 unk1, u32 physaddr0, u32 physaddr1, u32 totalbytesize) +void CSND_sharedmemtype0_cmde(u32 channel, CSND_LOOPING looping, CSND_ENCODING encoding, u32 samplerate, u32 unk0, u32 unk1, u32 physaddr0, u32 physaddr1, u32 totalbytesize) { u32 val; u32 cmdparams[0x18>>2]; @@ -241,8 +241,8 @@ void CSND_sharedmemtype0_cmde(u32 channel, u32 looping, u32 encoding, u32 sample cmdparams[0] = channel & 0x1f; cmdparams[0] |= (unk0 & 0xf) << 6; - if(!looping)cmdparams[0] |= 2 << 10; - if(looping)cmdparams[0] |= 1 << 10; + if(looping==CSND_LOOP_DISABLE)cmdparams[0] |= 2 << 10; + if(looping==CSND_LOOP_ENABLE)cmdparams[0] |= 1 << 10; cmdparams[0] |= (encoding & 3) << 12; cmdparams[0] |= (unk1 & 3) << 14; @@ -282,7 +282,7 @@ Result CSND_sharedmemtype0_cmdupdatestate(int waitdone) return 0; } -Result CSND_playsound(u32 channel, u32 looping, u32 encoding, u32 samplerate, u32 *vaddr0, u32 *vaddr1, u32 totalbytesize, u32 unk0, u32 unk1) +Result CSND_playsound(u32 channel, CSND_LOOPING looping, CSND_ENCODING encoding, u32 samplerate, u32 *vaddr0, u32 *vaddr1, u32 totalbytesize, u32 unk0, u32 unk1) { u32 physaddr0 = 0; u32 physaddr1 = 0; @@ -292,7 +292,7 @@ Result CSND_playsound(u32 channel, u32 looping, u32 encoding, u32 samplerate, u3 CSND_sharedmemtype0_cmde(channel, looping, encoding, samplerate, unk0, unk1, physaddr0, physaddr1, totalbytesize); CSND_sharedmemtype0_cmd8(channel, samplerate); - if(looping)CSND_sharedmemtype0_cmd3(channel, physaddr0, totalbytesize); + if(looping==CSND_LOOP_ENABLE)CSND_sharedmemtype0_cmd3(channel, physaddr0, totalbytesize); CSND_sharedmemtype0_cmd8(channel, samplerate); CSND_sharedmemtype0_cmd9(channel, 0xffff); CSND_setchannel_playbackstate(channel, 1); From 470be6d4ba78d126105ce561f7b3990c14b8ffdd Mon Sep 17 00:00:00 2001 From: plutoo Date: Mon, 11 Aug 2014 19:38:48 +0200 Subject: [PATCH 2/2] Added svc's. --- libctru/include/ctr/svc.h | 4 ++-- libctru/source/svc.s | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/libctru/include/ctr/svc.h b/libctru/include/ctr/svc.h index ddd5950..dfa073e 100644 --- a/libctru/include/ctr/svc.h +++ b/libctru/include/ctr/svc.h @@ -15,7 +15,6 @@ typedef enum{ }MEMORY_OPERATION; u32* getThreadCommandBuffer(void); - Result svc_controlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions); //(outaddr is usually the same as the input addr0) void svc_exitProcess(void); Result svc_createThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stacktop, s32 threadpriority, s32 processorid); @@ -23,6 +22,7 @@ typedef enum{ void svc_sleepThread(s64 ns); Result svc_createMutex(Handle* mutex, bool initialLocked); Result svc_releaseMutex(Handle handle); + Result svc_releaseSemaphore(s32* count, Handle semaphore, s32 releaseCount); Result svc_createEvent(Handle* event, u8 resettype); Result svc_signalEvent(Handle handle); Result svc_clearEvent(Handle handle); @@ -31,10 +31,10 @@ typedef enum{ Result svc_unmapMemoryBlock(Handle memblock, u32 addr); Result svc_waitSynchronization1(Handle handle, s64 nanoseconds); Result svc_waitSynchronizationN(s32* out, Handle* handles, s32 handlecount, bool waitAll, s64 nanoseconds); + Result svc_arbitrateAddress(Handle arbiter, u32 addr, u8 type, s32 value, s64 nanoseconds); Result svc_closeHandle(Handle handle); u64 svc_getSystemTick(); Result svc_getSystemInfo(s64* out, u32 type, s32 param); - Result svc_getProcessInfo(s64* out, Handle process, u32 type); Result svc_connectToPort(volatile Handle* out, const char* portName); Result svc_sendSyncRequest(Handle session); Result svc_getProcessId(u32 *out, Handle handle); diff --git a/libctru/source/svc.s b/libctru/source/svc.s index 09b4d9c..8fdce4a 100644 --- a/libctru/source/svc.s +++ b/libctru/source/svc.s @@ -67,6 +67,15 @@ svc_releaseMutex: svc 0x14 bx lr +.global svc_releaseSemaphore +.type svc_releaseSemaphore, %function +svc_releaseSemaphore: + str r0, [sp,#-4]! + svc 0x16 + ldr r2, [sp], #4 + str r1, [r2] + bx lr + .global svc_createEvent .type svc_createEvent, %function svc_createEvent: @@ -110,6 +119,12 @@ svc_unmapMemoryBlock: svc 0x20 bx lr +.global svc_arbitrateAddress +.type svc_arbitrateAddress, %function +svc_arbitrateAddress: + svc 0x22 + bx lr + .global svc_closeHandle .type svc_closeHandle, %function svc_closeHandle: