From d9808a376ee20a2e6dd57d1f272886f2ad192302 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sun, 23 May 2021 18:48:50 -0400 Subject: Start decompiling Chatot sound data func --- arm9/src/sav_chatot.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 arm9/src/sav_chatot.c (limited to 'arm9/src/sav_chatot.c') diff --git a/arm9/src/sav_chatot.c b/arm9/src/sav_chatot.c new file mode 100644 index 00000000..f2707821 --- /dev/null +++ b/arm9/src/sav_chatot.c @@ -0,0 +1,49 @@ +#include "global.h" +#include "MI_memory.h" +#include "heap.h" +#include "save_block_2.h" + +struct SaveChatotSoundClip +{ + // TODO: Fill this in + BOOL exists; + s8 data[1000]; +}; + +THUMB_FUNC u32 FUN_02029EC4(void) +{ + return sizeof(struct SaveChatotSoundClip); +} + +THUMB_FUNC void FUN_02029ECC(struct SaveChatotSoundClip * chatot) +{ + MIi_CpuClear32(0, chatot, sizeof(struct SaveChatotSoundClip)); + chatot->exists = FALSE; +} + +THUMB_FUNC struct SaveChatotSoundClip * FUN_02029EE4(u32 heap_id) +{ + struct SaveChatotSoundClip * ret = (struct SaveChatotSoundClip *)AllocFromHeap(heap_id, sizeof(struct SaveChatotSoundClip)); + FUN_02029ECC(ret); + return ret; +} + +THUMB_FUNC struct SaveChatotSoundClip * FUN_02029EF8(struct SaveBlock2 * sav2) +{ + return (struct SaveChatotSoundClip *) SavArray_get(sav2, 22); +} + +THUMB_FUNC u32 FUN_02029F04(struct SaveChatotSoundClip * chatot) +{ + return chatot->exists; +} + +THUMB_FUNC void FUN_02029F08(struct SaveChatotSoundClip * chatot) +{ + chatot->exists = FALSE; +} + +THUMB_FUNC s8 * FUN_02029F10(struct SaveChatotSoundClip * chatot) +{ + return chatot->data; +} -- cgit v1.2.3 From eb511d34eab6bdbb157a998b9aa5617b7679c242 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 24 May 2021 09:31:37 -0400 Subject: Finish decomping sav_chatot --- arm9/src/sav_chatot.c | 81 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 16 deletions(-) (limited to 'arm9/src/sav_chatot.c') diff --git a/arm9/src/sav_chatot.c b/arm9/src/sav_chatot.c index f2707821..7b240a99 100644 --- a/arm9/src/sav_chatot.c +++ b/arm9/src/sav_chatot.c @@ -1,49 +1,98 @@ #include "global.h" #include "MI_memory.h" #include "heap.h" -#include "save_block_2.h" +#include "sav_chatot.h" -struct SaveChatotSoundClip -{ - // TODO: Fill this in - BOOL exists; - s8 data[1000]; -}; - -THUMB_FUNC u32 FUN_02029EC4(void) +THUMB_FUNC u32 Sav2_Chatot_sizeof(void) { return sizeof(struct SaveChatotSoundClip); } -THUMB_FUNC void FUN_02029ECC(struct SaveChatotSoundClip * chatot) +THUMB_FUNC void Sav2_Chatot_init(struct SaveChatotSoundClip * chatot) { MIi_CpuClear32(0, chatot, sizeof(struct SaveChatotSoundClip)); chatot->exists = FALSE; } -THUMB_FUNC struct SaveChatotSoundClip * FUN_02029EE4(u32 heap_id) +THUMB_FUNC struct SaveChatotSoundClip * Chatot_new(u32 heap_id) { struct SaveChatotSoundClip * ret = (struct SaveChatotSoundClip *)AllocFromHeap(heap_id, sizeof(struct SaveChatotSoundClip)); - FUN_02029ECC(ret); + Sav2_Chatot_init(ret); return ret; } -THUMB_FUNC struct SaveChatotSoundClip * FUN_02029EF8(struct SaveBlock2 * sav2) +THUMB_FUNC struct SaveChatotSoundClip * Sav2_Chatot_get(struct SaveBlock2 * sav2) { return (struct SaveChatotSoundClip *) SavArray_get(sav2, 22); } -THUMB_FUNC u32 FUN_02029F04(struct SaveChatotSoundClip * chatot) +THUMB_FUNC BOOL Chatot_exists(struct SaveChatotSoundClip * chatot) { return chatot->exists; } -THUMB_FUNC void FUN_02029F08(struct SaveChatotSoundClip * chatot) +THUMB_FUNC void Chatot_invalidate(struct SaveChatotSoundClip * chatot) { chatot->exists = FALSE; } -THUMB_FUNC s8 * FUN_02029F10(struct SaveChatotSoundClip * chatot) +THUMB_FUNC s8 * Chatot_GetData(struct SaveChatotSoundClip * chatot) { return chatot->data; } + +static inline s8 transform(u8 value) +{ + return (s8)(value - 8); +} + +THUMB_FUNC void Chatot_Decode(s8 * dest, const s8 * data) +{ + s32 i; + s32 dest_i; + u8 val; + s8 val2; + + for (dest_i = 0, i = 0; i < 1000; i++, dest_i += 2) + { + val = (u8)(data[i] & 0xF); + val2 = transform(val); + dest[dest_i + 0] = (s8)(val2 << 4); + val = (u8)(data[i] >> 4); + val2 = transform(val); + dest[dest_i + 1] = (s8)(val2 << 4); + } +} + +static inline u8 untransform(s8 val) +{ + val /= 16; + return (u8)(val + 8); +} + +THUMB_FUNC void Chatot_Encode(struct SaveChatotSoundClip * chatot, const s8 * data) +{ + s32 src_i; + s32 i = 0; + u8 val2; + s8 val; + chatot->exists = TRUE; + + for (src_i = 0; src_i < 2000; src_i += 2) + { + val = data[src_i + 0]; + val2 = untransform(val); + chatot->data[i] = (s8)val2; + + val = data[src_i + 1]; + val2 = untransform(val); + chatot->data[i] |= val2 << 4; + + i++; + } +} + +THUMB_FUNC void Chatot_copy(struct SaveChatotSoundClip * dest, const struct SaveChatotSoundClip * src) +{ + MIi_CpuCopyFast(src, dest, sizeof(struct SaveChatotSoundClip)); +} -- cgit v1.2.3