diff options
| author | Roman971 <32455037+Roman971@users.noreply.github.com> | 2020-05-01 04:00:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-30 22:00:39 -0400 |
| commit | 4932e93ba29a4297c4a19c363b9c6e8692a5a7d7 (patch) | |
| tree | fc78ae554937db93ecc5452ea8a3222799242044 /src/code | |
| parent | d0ba37b14817751eeda8ffee1ea895348e2b76c3 (diff) | |
Decompile 2 small files (code_8006BA00.c and code_8006C3A0.c) (#101)
* Decompile code_8006C3A0.c (handling "env" flags)
* Decompile code_8006BA00.c (handling sound sources)
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/code_8006BA00.c | 65 | ||||
| -rw-r--r-- | src/code/code_8006C3A0.c | 32 | ||||
| -rw-r--r-- | src/code/z_actor.c | 2 | ||||
| -rw-r--r-- | src/code/z_demo.c | 12 | ||||
| -rw-r--r-- | src/code/z_effect_soft_sprite.c | 2 | ||||
| -rw-r--r-- | src/code/z_lib.c | 13 | ||||
| -rw-r--r-- | src/code/z_play.c | 2 |
7 files changed, 106 insertions, 22 deletions
diff --git a/src/code/code_8006BA00.c b/src/code/code_8006BA00.c new file mode 100644 index 000000000..af2c68814 --- /dev/null +++ b/src/code/code_8006BA00.c @@ -0,0 +1,65 @@ +#include <ultra64.h> +#include <global.h> + +void func_8006BA00(GlobalContext* globalCtx) { + SoundSource* sources = &globalCtx->soundSources[0]; + s32 i; + + // clang-format off + for (i = 0; i < ARRAY_COUNT(globalCtx->soundSources); i++) { sources[i].countdown = 0; } + // clang-format on +} + +void func_8006BA30(GlobalContext* globalCtx) { + SoundSource* source; + s32 i; + + source = &globalCtx->soundSources[0]; + for (i = 0; i < ARRAY_COUNT(globalCtx->soundSources); i++) { + if (source->countdown != 0) { + if (DECR(source->countdown) == 0) { + func_800F89E8(&source->relativePos); + } else { + func_800A6EF4(&globalCtx->mf_11D60, &source->originPos, &source->relativePos); + } + } + + source++; + } +} + +void Audio_PlaySoundAtPosition(GlobalContext* globalCtx, Vec3f* pos, s32 duration, u16 sfxId) { + s32 countdown; + SoundSource* source; + s32 smallestCountdown; + SoundSource* backupSource; + s32 i; + + smallestCountdown = 0xFFFF; + + source = &globalCtx->soundSources[0]; + for (i = 0; i < ARRAY_COUNT(globalCtx->soundSources); i++) { + if (source->countdown == 0) { + break; + } + + countdown = source->countdown; + if (countdown < smallestCountdown) { + smallestCountdown = countdown; + backupSource = source; + } + + source++; + } + + if (i >= ARRAY_COUNT(globalCtx->soundSources)) { + source = backupSource; + func_800F89E8(&source->relativePos); + } + + source->originPos = *pos; + source->countdown = duration; + + func_800A6EF4(&globalCtx->mf_11D60, &source->originPos, &source->relativePos); + Audio_PlaySoundGeneral(sfxId, &source->relativePos, 4, &D_801333E0, &D_801333E0, &D_801333E8); +} diff --git a/src/code/code_8006C3A0.c b/src/code/code_8006C3A0.c index 1b7c77c4c..789869598 100644 --- a/src/code/code_8006C3A0.c +++ b/src/code/code_8006C3A0.c @@ -1,10 +1,34 @@ #include <ultra64.h> #include <global.h> -#pragma GLOBAL_ASM("asm/non_matchings/code/code_8006C3A0/func_8006C3A0.s") +void Flags_UnsetAllEnv(GlobalContext* globalCtx) { + u8 i; -#pragma GLOBAL_ASM("asm/non_matchings/code/code_8006C3A0/func_8006C3D0.s") + for (i = 0; i < 20; i++) { + globalCtx->envFlags[i] = 0; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/code/code_8006C3A0/func_8006C438.s") +void Flags_SetEnv(GlobalContext* globalCtx, s16 flag) { + s16 index = flag / 16; + s16 bit = flag % 16; + s16 mask = 1 << bit; -#pragma GLOBAL_ASM("asm/non_matchings/code/code_8006C3A0/func_8006C4A4.s") + globalCtx->envFlags[index] |= mask; +} + +void Flags_UnsetEnv(GlobalContext* globalCtx, s16 flag) { + s16 index = flag / 16; + s16 bit = flag % 16; + s16 mask = (1 << bit) ^ 0xFFFF; + + globalCtx->envFlags[index] &= mask; +} + +s32 Flags_GetEnv(GlobalContext* globalCtx, s16 flag) { + s16 index = flag / 16; + s16 bit = flag % 16; + s16 mask = 1 << bit; + + return globalCtx->envFlags[index] & mask; +} diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 4da4a7128..aa3b4999c 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -3054,7 +3054,7 @@ Actor* Actor_Find(ActorContext* actorCtx, s32 actorId, s32 actorType) { void func_80032C7C(GlobalContext* globalCtx, Actor* actor) { globalCtx->actorCtx.unk_00 = 5; - Audio_PlaySoundAtPosition(globalCtx, &actor->posRot.pos, 0x14, NA_SE_EN_LAST_DAMAGE); + Audio_PlaySoundAtPosition(globalCtx, &actor->posRot.pos, 20, NA_SE_EN_LAST_DAMAGE); } s16 func_80032CB4(s16* arg0, s16 arg1, s16 arg2, s16 arg3) { diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 2a39229ac..4a5c48306 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -193,9 +193,9 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* break; case 3: if (sp3F != 0) { - func_8006C3D0(globalCtx, 0); + Flags_SetEnv(globalCtx, 0); if (gSaveContext.entranceIndex == 0x0053) { - func_8006C3D0(globalCtx, 2); + Flags_SetEnv(globalCtx, 2); } } break; @@ -225,7 +225,7 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* globalCtx->envCtx.unk_EE[3] = 0x10; break; case 10: - func_8006C3D0(globalCtx, 1); + Flags_SetEnv(globalCtx, 1); break; case 11: if (globalCtx->unk_11D30[0] < 0x672) { @@ -350,10 +350,10 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* globalCtx->unk_11DE9 = 0; break; case 30: - func_8006C3D0(globalCtx, 3); + Flags_SetEnv(globalCtx, 3); break; case 31: - func_8006C3D0(globalCtx, 4); + Flags_SetEnv(globalCtx, 4); break; case 32: if (sp3F != 0) { @@ -1935,7 +1935,7 @@ void func_80068ECC(GlobalContext* globalCtx, CutsceneContext* csCtx) { } if ((gSaveContext.cutsceneIndex >= 0xFFF0) && (csCtx->state == CS_STATE_IDLE)) { - func_8006C438(globalCtx, 0); + Flags_UnsetEnv(globalCtx, 0); D_8011E1C0 = 0; D_8011E1C4 = 0; diff --git a/src/code/z_effect_soft_sprite.c b/src/code/z_effect_soft_sprite.c index 34b264bf4..c5c9a7864 100644 --- a/src/code/z_effect_soft_sprite.c +++ b/src/code/z_effect_soft_sprite.c @@ -36,7 +36,7 @@ void Effect_SS_Clear(GlobalContext* globalCtx) { void Effect_SS_Delete(LoadedParticleEntry* particle) { if (particle->flags & 2) { - func_800F89E8(particle); + func_800F89E8(&particle->position); } if (particle->flags & 4) { diff --git a/src/code/z_lib.c b/src/code/z_lib.c index c76e400c8..d59cf7374 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -2,16 +2,11 @@ #include <global.h> void Lib_MemSet(u8* dest, size_t size, u8 val) { - u32 i = 0; + u32 i; - // TODO: Convert this to while/for if possible - if (i == size) { - return; - } - do { - *dest++ = val; - i++; - } while (i != size); + // clang-format off + for (i = 0; i < size; i++) { *dest++ = val; } + // clang-format on } f32 Math_Coss(s16 angle) { diff --git a/src/code/z_play.c b/src/code/z_play.c index 2723d2fa3..1e20e00cb 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -367,7 +367,7 @@ void Gameplay_Init(GlobalContext* globalCtx) { TransitionFade_Start(&globalCtx->transitionFade); func_800AD000(&D_80161498); D_801614B0.a = 0x00; - func_8006C3A0(globalCtx); + Flags_UnsetAllEnv(globalCtx); osSyncPrintf("ZELDA ALLOC SIZE=%x\n", THA_GetSize(&globalCtx->state.tha)); zAllocSize = THA_GetSize(&globalCtx->state.tha); |
