diff options
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/code_80026B00.c | 26 | ||||
| -rw-r--r-- | src/code/fault.c | 76 | ||||
| -rw-r--r-- | src/code/fault_drawer.c | 76 | ||||
| -rw-r--r-- | src/code/gfxprint.c | 12 | ||||
| -rw-r--r-- | src/code/sys_matrix.c | 10 | ||||
| -rw-r--r-- | src/code/z_actor.c | 183 | ||||
| -rw-r--r-- | src/code/z_camera.c | 18 | ||||
| -rw-r--r-- | src/code/z_construct.c | 47 | ||||
| -rw-r--r-- | src/code/z_debug.c | 24 | ||||
| -rw-r--r-- | src/code/z_demo.c | 65 | ||||
| -rw-r--r-- | src/code/z_effect.c | 26 | ||||
| -rw-r--r-- | src/code/z_en_a_keep.c | 6 | ||||
| -rw-r--r-- | src/code/z_en_item00.c | 29 | ||||
| -rw-r--r-- | src/code/z_face_reaction.c (renamed from src/code/code_8006C360.c) | 8 | ||||
| -rw-r--r-- | src/code/z_horse.c | 27 | ||||
| -rw-r--r-- | src/code/z_kaleido_scope_call.c | 3 | ||||
| -rw-r--r-- | src/code/z_lifemeter.c | 2 | ||||
| -rw-r--r-- | src/code/z_parameter.c | 356 | ||||
| -rw-r--r-- | src/code/z_path.c | 46 | ||||
| -rw-r--r-- | src/code/z_room.c | 39 | ||||
| -rw-r--r-- | src/code/z_sample.c | 4 | ||||
| -rw-r--r-- | src/code/z_scene.c | 8 | ||||
| -rw-r--r-- | src/code/z_scene_table.c | 5 |
23 files changed, 670 insertions, 426 deletions
diff --git a/src/code/code_80026B00.c b/src/code/code_80026B00.c deleted file mode 100644 index beb5006ee..000000000 --- a/src/code/code_80026B00.c +++ /dev/null @@ -1,26 +0,0 @@ -#include <ultra64.h> -#include <global.h> - -GlobalContext* func_80026B00(void) { - return D_80157DA0; -} - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80026B00/func_80026B0C.s") - -void func_80026C1C(u8* arg0) { - arg0[0] = 0; - arg0[1] = 0; - arg0[2] = 0; -} - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80026B00/func_80026C2C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80026B00/Effect_Add.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80026B00/func_80026E74.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80026B00/func_80026F70.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80026B00/func_8002709C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_80026B00/func_800271A8.s") diff --git a/src/code/fault.c b/src/code/fault.c index 7884c5057..05bee87d5 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -137,8 +137,9 @@ void Fault_AddClient(FaultClient* client, void* callback, void* param0, void* pa end: osSetIntMask(mask); - if (alreadyExists) + if (alreadyExists) { osSyncPrintf(VT_COL(RED, WHITE) "fault_AddClient: %08x は既にリスト中にある\n" VT_RST, client); + } } #else #pragma GLOBAL_ASM("asm/non_matchings/code/fault/Fault_AddClient.s") @@ -270,27 +271,34 @@ u32 Fault_WaitForInputImpl() { kDown = curInput->padPressed; - if (kDown == 0x20) + if (kDown == 0x20) { sFaultStructPtr->faultActive = !sFaultStructPtr->faultActive; + } - if (!sFaultStructPtr->faultActive) + if (!sFaultStructPtr->faultActive) { break; + } - if (count-- < 1) + if (count-- < 1) { return false; + } } - if (kDown == 0x8000 || kDown == 0x100) + if (kDown == 0x8000 || kDown == 0x100) { return false; + } - if (kDown == 0x200) + if (kDown == 0x200) { return true; + } - if (kDown == 0x800) + if (kDown == 0x800) { FaultDrawer_SetOsSyncPrintfEnabled(true); + } - if (kDown == 0x400) + if (kDown == 0x400) { FaultDrawer_SetOsSyncPrintfEnabled(false); + } } return false; @@ -555,24 +563,28 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { s32 off; while (true) { - if (addr < 0x80000000) + if (addr < 0x80000000) { addr = 0x80000000; - if (addr > 0x807fff00) + } + if (addr > 0x807fff00) { addr = 0x807fff00; + } addr &= ~0xF; Fault_DrawMemDumpPage("Dump", (u32*)addr, 0); count = 600; while (sFaultStructPtr->faultActive) { - if (count == 0) + if (count == 0) { return; + } count--; Fault_Sleep(0x10); Fault_UpdatePadImpl(); - if (!~(curInput->padPressed | ~0x20)) + if (!~(curInput->padPressed | ~0x20)) { sFaultStructPtr->faultActive = false; + } } do { @@ -580,31 +592,42 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { Fault_UpdatePadImpl(); } while (curInput->padPressed == 0); - if (!~(curInput->padPressed | ~0x1000)) + if (!~(curInput->padPressed | ~0x1000)) { return; + } - if (!~(curInput->raw.pad | ~0x8000)) + if (!~(curInput->raw.pad | ~0x8000)) { return; + } off = 0x10; - if (!~(curInput->raw.pad | ~0x2000)) + if (!~(curInput->raw.pad | ~0x2000)) { off = 0x100; - if (!~(curInput->raw.pad | ~0x4000)) + } + if (!~(curInput->raw.pad | ~0x4000)) { off <<= 8; - if (!~(curInput->raw.pad | ~0x800)) + } + if (!~(curInput->raw.pad | ~0x800)) { addr -= off; - if (!~(curInput->raw.pad | ~0x400)) + } + if (!~(curInput->raw.pad | ~0x400)) { addr += off; - if (!~(curInput->raw.pad | ~0x8)) + } + if (!~(curInput->raw.pad | ~0x8)) { addr = pc; - if (!~(curInput->raw.pad | ~0x4)) + } + if (!~(curInput->raw.pad | ~0x4)) { addr = sp; - if (!~(curInput->raw.pad | ~0x2)) + } + if (!~(curInput->raw.pad | ~0x2)) { addr = unk0; - if (!~(curInput->raw.pad | ~0x1)) + } + if (!~(curInput->raw.pad | ~0x1)) { addr = unk1; - if (!~(curInput->raw.pad | ~0x20)) + } + if (!~(curInput->raw.pad | ~0x20)) { break; + } } sFaultStructPtr->faultActive = true; @@ -715,15 +738,16 @@ void Fault_ThreadEntry(void* arg) { __osSetFpcCsr(__osGetFpcCsr() & -0xf81); sFaultStructPtr->faultedThread = faultedThread; - while (!sFaultStructPtr->faultHandlerEnabled) + while (!sFaultStructPtr->faultHandlerEnabled) { Fault_Sleep(1000); + } Fault_Sleep(500); Fault_CommitFB(); - if (sFaultStructPtr->faultActive) + if (sFaultStructPtr->faultActive) { Fault_Wait5Seconds(); - else { + } else { Fault_DrawCornerRec(0xF801); Fault_WaitForButtonCombo(); } diff --git a/src/code/fault_drawer.c b/src/code/fault_drawer.c index 8d85af18b..ef7a784ae 100644 --- a/src/code/fault_drawer.c +++ b/src/code/fault_drawer.c @@ -65,46 +65,61 @@ void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled) { sFaultDrawerStruct.osSyncPrintfEnabled = enabled; } -#ifdef NON_MATCHING -void FaultDrawer_DrawRecImpl(s32 xstart, s32 ystart, s32 xend, s32 yend, u16 color) { - if (sFaultDrawerStruct.w - xstart > 0 && sFaultDrawerStruct.h - ystart > 0) { - s32 x, y; +void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 color) { + u16* fb; + s32 x, y; + s32 xDiff = sFaultDrawerStruct.w - xStart; + s32 yDiff = sFaultDrawerStruct.h - yStart; + s32 xSize = xEnd - xStart + 1; + s32 ySize = yEnd - yStart + 1; + + if (xDiff > 0 && yDiff > 0) { + if (xDiff < xSize) { + xSize = xDiff; + } - for (y = 0; y <= yend - ystart; y++) - for (x = 0; x <= xend - xstart; x++) - sFaultDrawerStruct.fb[sFaultDrawerStruct.w * y + x] = color; + if (yDiff < ySize) { + ySize = yDiff; + } + + fb = sFaultDrawerStruct.fb + sFaultDrawerStruct.w * yStart + xStart; + for (y = 0; y < ySize; y++) { + for (x = 0; x < xSize; x++) { + *fb++ = color; + } + fb += sFaultDrawerStruct.w - xSize; + } osWritebackDCacheAll(); } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/fault_drawer/FaultDrawer_DrawRecImpl.s") -#endif -#ifdef NON_MATCHING -// regalloc and minor ordering differences void FaultDrawer_DrawChar(char c) { + u16* fb; s32 x, y; u32* dataPtr; - u16* fb; - - dataPtr = &sFaultDrawerStruct.fontData[((c & 4) >> 2) + ((c / 8) * 16)]; - - fb = &sFaultDrawerStruct.fb[sFaultDrawerStruct.cursorY * sFaultDrawerStruct.w]; - fb = &fb[sFaultDrawerStruct.cursorX]; - - if ((sFaultDrawerStruct.xStart <= sFaultDrawerStruct.cursorX) && - ((sFaultDrawerStruct.charW + sFaultDrawerStruct.cursorX - 1) <= sFaultDrawerStruct.xEnd) && - (sFaultDrawerStruct.yStart <= sFaultDrawerStruct.cursorY) && - ((sFaultDrawerStruct.charH + sFaultDrawerStruct.cursorY - 1) <= sFaultDrawerStruct.yEnd)) { + u32 data; + s32 cursorX = sFaultDrawerStruct.cursorX; + s32 cursorY = sFaultDrawerStruct.cursorY; + u32** fontData = &sFaultDrawerStruct.fontData; + s32 shift = c % 4; + + dataPtr = &fontData[0][(((c / 8) * 16) + ((c & 4) >> 2))]; + fb = sFaultDrawerStruct.fb + (sFaultDrawerStruct.w * cursorY) + cursorX; + + if ((sFaultDrawerStruct.xStart <= cursorX) && + ((sFaultDrawerStruct.charW + cursorX - 1) <= sFaultDrawerStruct.xEnd) && + (sFaultDrawerStruct.yStart <= cursorY) && + ((sFaultDrawerStruct.charH + cursorY - 1) <= sFaultDrawerStruct.yEnd)) { for (y = 0; y < sFaultDrawerStruct.charH; y++) { - u32 mask = 0x10000000 << (c % 4); - u32 data = *dataPtr; + u32 mask = 0x10000000 << shift; + data = *dataPtr; for (x = 0; x < sFaultDrawerStruct.charW; x++) { - if (mask & data) + if (mask & data) { fb[x] = sFaultDrawerStruct.foreColor; - else if (sFaultDrawerStruct.backColor & 1) + } else if (sFaultDrawerStruct.backColor & 1) { fb[x] = sFaultDrawerStruct.backColor; + } mask >>= 4; } fb += sFaultDrawerStruct.w; @@ -112,9 +127,6 @@ void FaultDrawer_DrawChar(char c) { } } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/fault_drawer/FaultDrawer_DrawChar.s") -#endif s32 FaultDrawer_ColorToPrintColor(u16 color) { s32 i; @@ -152,7 +164,7 @@ void FaultDrawer_SetBackColor(u16 color) { } void FaultDrawer_SetFontColor(u16 color) { - FaultDrawer_SetForeColor((u16)(color | 1)); // force alpha to be set + FaultDrawer_SetForeColor(color | 1); // force alpha to be set } void FaultDrawer_SetCharPad(s8 padW, s8 padH) { @@ -260,7 +272,7 @@ void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...) { } void FaultDrawer_SetDrawerFB(void* fb, u16 w, u16 h) { - sFaultDrawerStruct.fb = (u16*)fb; + sFaultDrawerStruct.fb = fb; sFaultDrawerStruct.w = w; sFaultDrawerStruct.h = h; } diff --git a/src/code/gfxprint.c b/src/code/gfxprint.c index fbcca3cee..9b7c6fa0f 100644 --- a/src/code/gfxprint.c +++ b/src/code/gfxprint.c @@ -223,7 +223,7 @@ void GfxPrint_SetBasePosPx(GfxPrint* this, s32 x, s32 y) { #ifdef NON_MATCHING // regalloc and ordering differences -void GfxPrint_PrintCharImpl(GfxPrint* this, char c) { +void GfxPrint_PrintCharImpl(GfxPrint* this, u8 c) { if (this->flag & GFXPRINT_UPDATE_MODE) { this->flag &= ~GFXPRINT_UPDATE_MODE; @@ -246,22 +246,24 @@ void GfxPrint_PrintCharImpl(GfxPrint* this, char c) { if (this->flag & GFXPRINT_FLAG4) { gDPSetPrimColorMod(this->dlist++, 0, 0, 0); - if (this->flag & GFXPRINT_FLAG64) + if (this->flag & GFXPRINT_FLAG64) { gSPTextureRectangle(this->dlist++, (this->posX + 4) << 1, (this->posY + 4) << 1, (this->posX + 4 + 32) << 1, (this->posY + 4 + 32) << 1, c * 2, (u16)(c & 4) * 64, (u16)(c >> 3) * 256, 512, 512); - else + } else { gSPTextureRectangle(this->dlist++, this->posX + 4, this->posY + 4, this->posX + 4 + 32, this->posY + 4 + 32, c * 2, (u16)(c & 4) * 64, (u16)(c >> 3) * 256, 1024, 1024); + } gDPSetPrimColorMod(this->dlist++, 0, 0, *(u32*)&this->color); } - if (this->flag & GFXPRINT_FLAG64) + if (this->flag & GFXPRINT_FLAG64) { gSPTextureRectangle(this->dlist++, (this->posX) << 1, (this->posY) << 1, (this->posX + 32) << 1, (this->posY + 32) << 1, c * 2, (u16)(c & 4) * 64, (u16)(c >> 3) * 256, 512, 512); - else + } else { gSPTextureRectangle(this->dlist++, this->posX, this->posY, this->posX + 32, this->posY + 32, c * 2, (u16)(c & 4) * 64, (u16)(c >> 3) * 256, 1024, 1024); + } this->posX += 32; } diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index 688b21500..0d1ed55e7 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -794,12 +794,13 @@ void func_800D20CC(MtxF* mf, Vec3s* vec, s32 flag) { vec->y = Math_atan2f(mf->zx, mf->zz) * (32768 / M_PI); - if (!flag) + if (!flag) { vec->z = Math_atan2f(mf->xy, mf->yy) * (32768 / M_PI); - else + } else { vec->z = Math_atan2f(mf->xy / sqrtf(SQ(mf->xx) + SQ(mf->xz) + SQ(mf->xy)), mf->yy / sqrtf(SQ(mf->yx) + SQ(mf->yz) + SQ(mf->yy))) * (32768 / M_PI); + } } #else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D20CC.s") @@ -818,12 +819,13 @@ void func_800D2264(MtxF* mf, Vec3s* vec, s32 flag) { vec->z = Math_atan2f(mf->xy, mf->xx) * (32768 / M_PI); - if (!flag) + if (!flag) { vec->x = Math_atan2f(mf->yz, mf->zz) * (32768 / M_PI); - else + } else { vec->x = Math_atan2f(mf->yz / sqrtf(SQ(mf->yx) + SQ(mf->yy) + SQ(mf->yz)), mf->zz / sqrtf(SQ(mf->zx) + SQ(mf->zy) + SQ(mf->zz))) * (32768 / M_PI); + } } #else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D2264.s") diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 01ff7ed32..91bf21c5e 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -96,14 +96,14 @@ void func_8002B66C(GlobalContext* globalCtx, Light* light, MtxF* arg2, s32 arg3, } #ifdef NON_MATCHING -// this function still needs a lot of work +// saved register, stack usage and minor ordering differences void ActorShadow_DrawFunc_Teardrop(Actor* actor, LightMapper* lightMapper, GlobalContext* globalCtx) { GraphicsContext* gfxCtx; MtxF spE8; - Vec2f spE0; - s32 index; + f32 spE0[2]; + s32 i; f32* spAC; - Gfx* gfxArr[7]; + Gfx* gfxArr[4]; f32 temp_10; u8 temp_14; f32 temp_f0; @@ -124,8 +124,8 @@ void ActorShadow_DrawFunc_Teardrop(Actor* actor, LightMapper* lightMapper, Globa if (temp_f20 > 20.0f) { temp_10 = actor->shape.unk_10; - actor->shape.unk_10 *= 0.3f; temp_14 = actor->shape.unk_14; + actor->shape.unk_10 *= 0.3f; actor->shape.unk_14 *= ((temp_f20 - 20.0f) * 0.02f) > 1.0f ? 1.0f : ((temp_f20 - 20.0f) * 0.02f); ActorShadow_DrawFunc_Circle(actor, lightMapper, globalCtx); actor->shape.unk_10 = temp_10; @@ -133,18 +133,18 @@ void ActorShadow_DrawFunc_Teardrop(Actor* actor, LightMapper* lightMapper, Globa } if (temp_f20 < 200.0f) { - spAC = &spE0.x; - gfxCtx = globalCtx->state.gfxCtx; - temp_s6 = lightMapper->numLights - 2; + phi_s7 = &actor->unk_CC[0]; + spAC = &spE0[0]; + temp_s6 = lightMapper->numLights; + temp_s6 -= 2; + gfxCtx = globalCtx->state.gfxCtx; func_800C6AC4(gfxArr, globalCtx->state.gfxCtx, "../z_actor.c", 1741); gfxCtx->polyOpa.p = func_80093774(gfxCtx->polyOpa.p, 0x2C); actor->shape.unk_15 = 0; - phi_s7 = &actor->unk_CC; - - for (index = 0; index < 2; index++) { + for (i = 0; i < 2; i++) { phi_s7->y += 50.0f; *spAC = func_800BFCB8(globalCtx, &spE8, phi_s7); phi_s7->y -= 50.0f; @@ -156,18 +156,21 @@ void ActorShadow_DrawFunc_Teardrop(Actor* actor, LightMapper* lightMapper, Globa if ((phi_f2 >= -1.0f) && (phi_f2 < 500.0f)) { phi_s0 = lightMapper->lights; - if (phi_f2 <= 0.0f) + if (phi_f2 <= 0.0f) { actor->shape.unk_15++; + } - if (30.0f < phi_f2) + if (30.0f < phi_f2) { phi_f2 = 30.0f; + } - temp_f24 = actor->shape.unk_14 * (1.0f - (phi_f2 * (1.f / 30))); + temp_f24 = actor->shape.unk_14 * (1.0f - (phi_f2 * (1.0f / 30))); - if (30.0f < phi_f2) + if (30.0f < phi_f2) { phi_f2 = 30.0f; + } - temp_f20_2 = 1.0f - (phi_f2 * (1.f / 70)); + temp_f20_2 = 1.0f - (phi_f2 * (1.0f / 70)); temp_f22_2 = (actor->shape.unk_10 * temp_f20_2) * actor->scale.x; phi_s2 = 0; @@ -187,8 +190,9 @@ void ActorShadow_DrawFunc_Teardrop(Actor* actor, LightMapper* lightMapper, Globa if (phi_s0->l.dir[1] > 0) { temp_a3 = (ABS(phi_s0->l.dir[1]) * ((phi_s0->l.col[0] + phi_s0->l.col[1]) + phi_s0->l.col[2])) - (phi_s2 * 8); - if (temp_a3 > 0) + if (temp_a3 > 0) { func_8002B66C(globalCtx, phi_s0, &spE8, temp_a3, temp_f24, temp_f22_2, temp_f20_2); + } } phi_s0++; } @@ -198,14 +202,11 @@ void ActorShadow_DrawFunc_Teardrop(Actor* actor, LightMapper* lightMapper, Globa phi_s7++; } - if (!(actor->bgCheckFlags & 1)) + if (!(actor->bgCheckFlags & 1)) { actor->shape.unk_15 = 0; - else if (actor->shape.unk_15 == 3) { - temp_f0 = actor->unk_CC.y - actor->unk_D8.y; - if ((spE0.x + temp_f0) < (spE0.y - temp_f0)) - actor->shape.unk_15 = 2; - else - actor->shape.unk_15 = 1; + } else if (actor->shape.unk_15 == 3) { + temp_f0 = actor->unk_CC[0].y - actor->unk_CC[1].y; + actor->shape.unk_15 = ((spE0[0] + temp_f0) < (spE0[1] - temp_f0)) ? 2 : 1; } func_800C6B54(gfxArr, globalCtx->state.gfxCtx, "../z_actor.c", 1831); @@ -217,9 +218,9 @@ void ActorShadow_DrawFunc_Teardrop(Actor* actor, LightMapper* lightMapper, Globa void func_8002BDB0(Actor* actor, s32 arg1, s32 arg2, UNK_PTR arg3, s32 arg4, UNK_PTR arg5) { if (arg1 == arg2) { - Matrix_MultVec3f(arg3, &actor->unk_CC); + Matrix_MultVec3f(arg3, &actor->unk_CC[0]); } else if (arg1 == arg4) { - Matrix_MultVec3f(arg5, &actor->unk_D8); + Matrix_MultVec3f(arg5, &actor->unk_CC[1]); } } @@ -310,25 +311,25 @@ void func_8002C0C0(TargetContext* targetCtx, Actor* actor, GlobalContext* global } #ifdef NON_MATCHING -// this function still needs some work +// regalloc and minor ordering differences void func_8002C124(TargetContext* targetCtx, GlobalContext* globalCtx) { Actor* actor; Player* player; GraphicsContext* gfxCtx; - Gfx* gfxArr[5]; + Gfx* gfxArr[4]; + TargetContextEntry* entry; s16 spCE; + f32 temp1; Vec3f spBC; s32 spB8; f32 spB4; s32 spB0; s32 spAC; - s32 i; - TargetContextEntry* entry; - f32 temp1; f32 var1; f32 var2; - Vec3f* vec; + s32 i; + actor = targetCtx->targetedActor; gfxCtx = globalCtx->state.gfxCtx; func_800C6AC4(gfxArr, globalCtx->state.gfxCtx, "../z_actor.c", 2029); @@ -338,48 +339,52 @@ void func_8002C124(TargetContext* targetCtx, GlobalContext* globalCtx) { spCE = 0xFF; var1 = 1.0f; - if (targetCtx->unk_4B != 0) + if (targetCtx->unk_4B != 0) { spB8 = 1; - else + } else { spB8 = 3; + } - if (targetCtx->targetedActor != NULL) { - Math_Vec3f_Copy(&targetCtx->targetCenterPos, &targetCtx->targetedActor->posRot2.pos); + if (actor != NULL) { + Math_Vec3f_Copy(&targetCtx->targetCenterPos, &actor->posRot2.pos); var1 = (500.0f - targetCtx->unk_44) / 420.0f; } else { - targetCtx->unk_48 -= 0x78; - if (targetCtx->unk_48 < 0) + targetCtx->unk_48 -= 120; + if (targetCtx->unk_48 < 0) { targetCtx->unk_48 = 0; + } spCE = targetCtx->unk_48; } func_8002BE04(globalCtx, &targetCtx->targetCenterPos, &spBC, &spB4); - temp1 = ((spBC.x * spB4) * 160.0f) * var1; - spBC.x = (temp1 < -320.0f) ? -320.0f : ((temp1 > 320.0f) ? 320.0f : temp1); + temp1 = ((spBC.x * spB4) * 160) * var1; + spBC.x = (temp1 < -320) ? -320 : ((temp1 > 320) ? 320 : temp1); - temp1 = ((spBC.y * spB4) * 120.0f) * var1; - spBC.y = (temp1 < -240.0f) ? -240.0f : ((temp1 > 240.0f) ? 240.0f : temp1); + temp1 = ((spBC.y * spB4) * 120) * var1; + spBC.y = (temp1 < -240) ? -240 : ((temp1 > 240) ? 240 : temp1); - spBC.z *= var1; + spBC.z = spBC.z * var1; targetCtx->unk_4C--; - if (targetCtx->unk_4C < 0) + if (targetCtx->unk_4C < 0) { targetCtx->unk_4C = 2; + } func_8002BE64(targetCtx, targetCtx->unk_4C, spBC.x, spBC.y, spBC.z); - if ((!(player->stateFlags1 & 0x40)) || (targetCtx->targetedActor != player->unk_664)) { + if ((!(player->stateFlags1 & 0x40)) || (actor != player->unk_664)) { gfxCtx->overlay.p = func_80093774(gfxCtx->overlay.p, 0x39); for (spB0 = 0, spAC = targetCtx->unk_4C; spB0 < spB8; spB0++) { entry = &targetCtx->arr_50[spAC]; if (entry->unk_0C < 500.0f) { - if (entry->unk_0C <= 120.0f) + if (entry->unk_0C <= 120.0f) { var2 = 0.15f; - else + } else { var2 = ((entry->unk_0C - 120.0f) * 0.001f) + 0.15f; + } Matrix_Translate(entry->pos.x, entry->pos.y, 0.0f, MTXMODE_NEW); Matrix_Scale(var2, 0.15f, 1.0f, MTXMODE_APPLY); @@ -401,8 +406,9 @@ void func_8002C124(TargetContext* targetCtx, GlobalContext* globalCtx) { } spCE = spCE - (0xFF / 3); - if (spCE < 0) + if (spCE < 0) { spCE = 0; + } spAC = (spAC + 1) % 3; } } @@ -720,20 +726,17 @@ void TitleCard_Update(GlobalContext* globalCtx, TitleCardContext* titleCtx) { } } -#ifdef NON_MATCHING -// major ordering and stack usage differences void TitleCard_Draw(GlobalContext* globalCtx, TitleCardContext* titleCtx) { s32 spCC; s32 spC8; s32 unk1; s32 spC0; - s32 unk2; + s32 sp38; s32 spB8; s32 spB4; s32 spB0; GraphicsContext* gfxCtx; Gfx* gfxArr[4]; - s32 sp38; if (titleCtx->unk_C != 0) { spCC = titleCtx->unk_8; @@ -743,14 +746,13 @@ void TitleCard_Draw(GlobalContext* globalCtx, TitleCardContext* titleCtx) { sp38 = spCC * 2; gfxCtx = globalCtx->state.gfxCtx; - func_800C6AC4(gfxArr, globalCtx->state.gfxCtx, "../z_actor.c", 2824); spB0 = spCC * spC8 * gSaveContext.language; - spC8 = (spCC * spC8 > 0x1000) ? 0x1000 / spCC : spC8; + spB4 = spB8 + (spC8 * 4); - spB4 = (spC8 * 4) + spB8; + if (1) {} // Necessary to match gfxCtx->overlay.p = func_80093808(gfxCtx->overlay.p); @@ -761,8 +763,8 @@ void TitleCard_Draw(GlobalContext* globalCtx, TitleCardContext* titleCtx) { G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(gfxCtx->overlay.p++, spC0, spB8, ((sp38 * 2) + spC0) - 4, spB8 - 1, G_TX_RENDERTILE, 0, 0, - 1024, 1024); + gSPTextureRectangle(gfxCtx->overlay.p++, spC0, spB8, ((sp38 * 2) + spC0) - 4, spB8 + (spC8 * 4) - 1, + G_TX_RENDERTILE, 0, 0, 1024, 1024); spC8 = titleCtx->unk_9 - spC8; @@ -771,16 +773,13 @@ void TitleCard_Draw(GlobalContext* globalCtx, TitleCardContext* titleCtx) { spC8, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(gfxCtx->overlay.p++, spC0, spB4, ((sp38 * 2) + spC0) - 4, spB4 - 1, G_TX_RENDERTILE, 0, - 0, 1024, 1024); + gSPTextureRectangle(gfxCtx->overlay.p++, spC0, spB4, ((sp38 * 2) + spC0) - 4, spB4 + (spC8 * 4) - 1, + G_TX_RENDERTILE, 0, 0, 1024, 1024); } func_800C6B54(gfxArr, globalCtx->state.gfxCtx, "../z_actor.c", 2880); } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/z_actor/TitleCard_Draw.s") -#endif s32 func_8002D53C(GlobalContext* globalCtx, TitleCardContext* titleCtx) { if ((globalCtx->actorCtx.titleCtx.delayB != 0) || (globalCtx->actorCtx.titleCtx.unk_C != 0)) { @@ -1447,14 +1446,16 @@ f32 func_8002EFC0(Actor* actor, Player* player, s16 arg2) { abs_var = ABS(var); if (player->unk_664 != NULL) { - if ((abs_var > 0x4000) || (actor->flags & 0x8000000)) + if ((abs_var > 0x4000) || (actor->flags & 0x8000000)) { return FLT_MAX; - else + } else { return actor->waterSurfaceDist - actor->waterSurfaceDist * 0.8f * ((0x4000 - abs_var) * 3.0517578125e-05f); + } } - if (abs_var > 0x2AAA) + if (abs_var > 0x2AAA) { return FLT_MAX; + } return actor->waterSurfaceDist; } @@ -1802,7 +1803,8 @@ Color_RGB8 D_80116060 = { 0xFF, 0xFF, 0xFF }; Color_RGB8 D_80116064 = { 0x64, 0xC8, 0x00 }; #ifdef NON_MATCHING -// this function still needs a lot of work +// saved register, stack usage and minor ordering differences +// this also doesn't generate a few useless struct copies void func_8002FBAC(GlobalContext* globalCtx) { GraphicsContext* gfxCtx; Gfx* gfxArr[6]; @@ -1810,6 +1812,7 @@ void func_8002FBAC(GlobalContext* globalCtx) { f32 spD8; f32 spD4; s32 spD0; + s32 spCC; f32 spC0; Vec3f spB4; Vec3f spA4; @@ -1830,15 +1833,17 @@ void func_8002FBAC(GlobalContext* globalCtx) { func_800C6AC4(gfxArr, globalCtx->state.gfxCtx, "../z_actor.c", 5308); if (gSaveContext.respawn[RESPAWN_MODE_TOP].data != 0) { - if (LINK_IS_ADULT) + if (LINK_IS_ADULT) { spD8 = 80.0f; - else + } else { spD8 = 60.0f; + } spD0 = 0xFF; spD4 = 1.0f; temp_a3 = gSaveContext.respawn[RESPAWN_MODE_TOP].data - 0x28; + spCC = temp_a3; if (temp_a3 < 0) { gSaveContext.respawn[RESPAWN_MODE_TOP].data++; @@ -1871,7 +1876,7 @@ void func_8002FBAC(GlobalContext* globalCtx) { temp_f12 = sp9C * 0.5f; temp_f14 = temp_ret - temp_f12; spD8 += sqrtf((temp_f12 * temp_f12) - (temp_f14 * temp_f14)) * 0.2f; - osSyncPrintf("-------- DISPLAY Y=%f\n", (f64)spD8); + osSyncPrintf("-------- DISPLAY Y=%f\n", spD8); } spA4.x = Math_Rand_CenteredFloat(6.0f) + gSaveContext.respawn[RESPAWN_MODE_TOP].pos.x; @@ -1886,6 +1891,7 @@ void func_8002FBAC(GlobalContext* globalCtx) { gSaveContext.respawn[RESPAWN_MODE_TOP].data = 0x28; } + // somehow this shouldn't be optimized out gSaveContext.respawn[RESPAWN_MODE_TOP].pos = gSaveContext.respawn[RESPAWN_MODE_TOP].pos; } else if (temp_a3 > 0) { temp_f12 = temp_a3 * 0.1f; @@ -1914,7 +1920,7 @@ void func_8002FBAC(GlobalContext* globalCtx) { gSaveContext.respawn[RESPAWN_MODE_TOP].data++; } - spD4 = temp_a3 * 0.200000000000000011102230246252 + 1.0f; + spD4 = spCC * 0.200000000000000011102230246252 + 1.0f; } if ((globalCtx->csCtx.state == 0) && @@ -3723,17 +3729,15 @@ struct_80116130 D_80116130[13] = { }; #ifdef NON_MATCHING -// this function still needs a lot of work +// regalloc differences void func_800344BC(Actor* actor, struct_80034A14_arg1* arg1, s16 arg2, s16 arg3, s16 arg4, s16 arg5, s16 arg6, s16 arg7, u8 arg8) { s16 sp46; s16 sp44; - s16 temp1; - s16 sp40; s16 temp2; + s16 sp40; + s16 temp1; Vec3f sp30; - s16 temp3; - s16 temp4; sp30.x = actor->posRot.pos.x; sp30.y = actor->posRot.pos.y + arg1->unk_14; @@ -3741,27 +3745,34 @@ void func_800344BC(Actor* actor, struct_80034A14_arg1* arg1, s16 arg2, s16 arg3, sp46 = Math_Vec3f_Pitch(&sp30, &arg1->unk_18); sp44 = Math_Vec3f_Yaw(&sp30, &arg1->unk_18); + sp40 = Math_Vec3f_Yaw(&actor->posRot.pos, &arg1->unk_18) - actor->shape.rot.y; - temp1 = Math_Vec3f_Yaw(&actor->posRot.pos, &arg1->unk_18) - actor->shape.rot.y; + temp1 = (sp40 < -arg2) ? -arg2 : ((sp40 > arg2) ? arg2 : sp40); + Math_SmoothScaleMaxMinS(&arg1->unk_0A, temp1, 6, 2000, 1); - Math_SmoothScaleMaxMinS(&arg1->unk_0A, (temp1 < -arg2) ? -arg2 : ((temp1 > arg2) ? arg2 : temp1), 6, 2000, 1); + sp40 = (ABS(sp40) >= 0x8000) ? 0 : ((sp40 >= 0) ? sp40 : -sp40); + arg1->unk_0A = ((arg1->unk_0A < -sp40) ? -sp40 : ((arg1->unk_0A > sp40) ? sp40 : arg1->unk_0A)); - temp3 = (ABS(temp1) >= 0x8000) ? 0 : ((temp1 >= 0) ? temp1 : -temp1); - arg1->unk_0A = ((arg1->unk_0A < -temp3) ? -temp3 : ((arg1->unk_0A > temp3) ? temp3 : arg1->unk_0A)); + sp40 = sp40 - arg1->unk_0A; - sp40 = temp1 - arg1->unk_0A; - Math_SmoothScaleMaxMinS(&arg1->unk_10, (sp40 < -arg5) ? -arg5 : ((sp40 > arg5) ? arg5 : sp40), 6, 2000, 1); + temp1 = (sp40 < -arg5) ? -arg5 : ((sp40 > arg5) ? arg5 : sp40); + Math_SmoothScaleMaxMinS(&arg1->unk_10, temp1, 6, 2000, 1); - temp4 = (ABS(sp40) >= 0x8000) ? 0 : ((sp40 >= 0) ? sp40 : -sp40); - arg1->unk_10 = ((arg1->unk_10 < -temp4) ? -temp4 : ((arg1->unk_10 > temp4) ? temp4 : arg1->unk_10)); + sp40 = (ABS(sp40) >= 0x8000) ? 0 : ((sp40 >= 0) ? sp40 : -sp40); + arg1->unk_10 = ((arg1->unk_10 < -sp40) ? -sp40 : ((arg1->unk_10 > sp40) ? sp40 : arg1->unk_10)); - if (arg8 != 0) + if (arg8 != 0) { + if (arg3) {} // Seems necessary to match Math_SmoothScaleMaxMinS(&actor->shape.rot.y, sp44, 6, 2000, 1); + } - Math_SmoothScaleMaxMinS(&arg1->unk_08, (sp46 < arg4) ? arg4 : ((sp46 > arg3) ? arg3 : sp46), 6, 2000, 1); + temp1 = (sp46 < arg4) ? arg4 : ((sp46 > arg3) ? arg3 : sp46); + Math_SmoothScaleMaxMinS(&arg1->unk_08, temp1, 6, 2000, 1); temp2 = sp46 - arg1->unk_08; - Math_SmoothScaleMaxMinS(&arg1->unk_0E, (temp2 < arg7) ? arg4 : ((temp2 > arg6) ? arg3 : temp2), 6, 2000, 1); + + temp1 = (temp2 < arg7) ? arg7 : ((temp2 > arg6) ? arg6 : temp2); + Math_SmoothScaleMaxMinS(&arg1->unk_0E, temp1, 6, 2000, 1); } #else #pragma GLOBAL_ASM("asm/non_matchings/code/z_actor/func_800344BC.s") diff --git a/src/code/z_camera.c b/src/code/z_camera.c index d7b0108d5..b48b58321 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -224,8 +224,9 @@ s32 func_800443A0(Camera* camera, Vec3f* b, Vec3f* c) { sp34 = NULL; // this is moved to the top when it should be done in the middle of the function args being loaded if (func_8003DD6C(&camera->globalCtx->colCtx, b, c, &sp40, &sp34, 1, 1, 1, 0, &sp38) != 0) { - if (func_80038B7C(sp34, b) < 0.0f) + if (func_80038B7C(sp34, b) < 0.0f) { return 1; + } } return 0; } @@ -461,18 +462,20 @@ s32 func_800458D4(Camera* camera, struct_80045714* b, f32 c, f32* d, s16 e) { sp60.z = 0.0f; temp_s1 = &camera->unk_94; - if (e != 0) + if (e != 0) { sp60.y -= func_80045714(&camera->unk_108, temp_s1->rot.y, b->unk_06, OREG(9)); + } sp48 = temp_s1->pos.y - *d; temp_ret = Math_atan2f(sp48, func_8007C028(&camera->unk_50, &camera->unk_5C)); // f2 and f14 are swapped - if (OREG(32) * (M_PI / 180) < temp_ret) + if (OREG(32) * (M_PI / 180) < temp_ret) { phi_f2 = 1.0f - sinf(temp_ret - OREG(32) * (M_PI / 180)); - else if (OREG(33) * (M_PI / 180) > temp_ret) + } else if (OREG(33) * (M_PI / 180) > temp_ret) { phi_f2 = 1.0f - sinf(OREG(33) * (M_PI / 180) - temp_ret); - else + } else { phi_f2 = 1.0f; + } sp60.y -= sp48 * phi_f2; func_80043A3C(&sp60, &camera->unk_E4, OREG(29) * 0.01f, OREG(30) * 0.01f, 0.1f); @@ -520,7 +523,7 @@ s32 func_80045B08(Camera* camera, struct_80045714* b, f32 c, s16 d) { return 1; } -#ifdef NON_MATCHING +/* // someone who's not me can have fun with this function s32 func_80045C74(Camera* camera, struct_80045714* b, f32 c, f32* d, s16 arg4) { Vec3f sp70; @@ -593,9 +596,8 @@ s32 func_80045C74(Camera* camera, struct_80045714* b, f32 c, f32* d, s16 arg4) { return 1; } -#else +*/ #pragma GLOBAL_ASM("asm/non_matchings/code/z_camera/func_80045C74.s") -#endif // 421 lines #pragma GLOBAL_ASM("asm/non_matchings/code/z_camera/func_800460A8.s") diff --git a/src/code/z_construct.c b/src/code/z_construct.c index 59c6e11a4..d14e6ef8c 100644 --- a/src/code/z_construct.c +++ b/src/code/z_construct.c @@ -44,8 +44,9 @@ void func_801109B0(GlobalContext* globalCtx) { osSyncPrintf("parameter->parameterSegment=%x", interfaceCtx->parameterSegment); - if (interfaceCtx->parameterSegment == NULL) + if (interfaceCtx->parameterSegment == NULL) { __assert("parameter->parameterSegment != NULL", "../z_construct.c", 161); + } DmaMgr_SendRequest1(interfaceCtx->parameterSegment, parameterStart, parameterSize, "../z_construct.c", 162); @@ -55,27 +56,30 @@ void func_801109B0(GlobalContext* globalCtx) { osSyncPrintf("DOアクション テクスチャ初期=%x\n", 0x480); osSyncPrintf("parameter->do_actionSegment=%x", interfaceCtx->do_actionSegment); - if (interfaceCtx->do_actionSegment == NULL) + if (interfaceCtx->do_actionSegment == NULL) { __assert("parameter->do_actionSegment != NULL", "../z_construct.c", 169); + } do_actionStart = _do_action_staticSegmentRomStart; - if (gSaveContext.language == 0) + if (gSaveContext.language == 0) { do_actionOffset = 0; - else if (gSaveContext.language == 1) + } else if (gSaveContext.language == 1) { do_actionOffset = 0x2B80; - else + } else { do_actionOffset = 0x5700; + } DmaMgr_SendRequest1(interfaceCtx->do_actionSegment, do_actionStart + do_actionOffset, 0x300, "../z_construct.c", 174); - if (gSaveContext.language == 0) + if (gSaveContext.language == 0) { do_actionOffset = 0x480; - else if (gSaveContext.language == 1) + } else if (gSaveContext.language == 1) { do_actionOffset = 0x3000; - else + } else { do_actionOffset = 0x5B80; + } DmaMgr_SendRequest1((void*)((u32)interfaceCtx->do_actionSegment + 0x300), do_actionStart + do_actionOffset, 0x180, "../z_construct.c", 178); @@ -86,36 +90,41 @@ void func_801109B0(GlobalContext* globalCtx) { osSyncPrintf("アイコンアイテム テクスチャ初期=%x\n", 0x4000); osSyncPrintf("parameter->icon_itemSegment=%x\n", interfaceCtx->icon_itemSegment); - if (interfaceCtx->icon_itemSegment == NULL) + if (interfaceCtx->icon_itemSegment == NULL) { __assert("parameter->icon_itemSegment != NULL", "../z_construct.c", 193); + } osSyncPrintf("Register_Item[%x, %x, %x, %x]\n", gSaveContext.equips.button_items[0], gSaveContext.equips.button_items[1], gSaveContext.equips.button_items[2], gSaveContext.equips.button_items[3]); - if (gSaveContext.equips.button_items[0] < 0xF0) + if (gSaveContext.equips.button_items[0] < 0xF0) { DmaMgr_SendRequest1(interfaceCtx->icon_itemSegment, _icon_item_staticSegmentRomStart + gSaveContext.equips.button_items[0] * 0x80, 0x1000, "../z_construct.c", 198); - else if (gSaveContext.equips.button_items[0] != 0xFF) + } else if (gSaveContext.equips.button_items[0] != 0xFF) { DmaMgr_SendRequest1(interfaceCtx->icon_itemSegment, _icon_item_staticSegmentRomStart + gSaveContext.equips.button_items[0] * 0x80, 0x1000, "../z_construct.c", 203); + } - if (gSaveContext.equips.button_items[1] < 0xF0) + if (gSaveContext.equips.button_items[1] < 0xF0) { DmaMgr_SendRequest1((void*)((u32)interfaceCtx->icon_itemSegment + 0x1000), _icon_item_staticSegmentRomStart + gSaveContext.equips.button_items[1] * 0x80, 0x1000, "../z_construct.c", 209); + } - if (gSaveContext.equips.button_items[2] < 0xF0) + if (gSaveContext.equips.button_items[2] < 0xF0) { DmaMgr_SendRequest1((void*)((u32)interfaceCtx->icon_itemSegment + 0x2000), _icon_item_staticSegmentRomStart + gSaveContext.equips.button_items[2] * 0x80, 0x1000, "../z_construct.c", 214); + } - if (gSaveContext.equips.button_items[3] < 0xF0) + if (gSaveContext.equips.button_items[3] < 0xF0) { DmaMgr_SendRequest1((void*)((u32)interfaceCtx->icon_itemSegment + 0x3000), _icon_item_staticSegmentRomStart + gSaveContext.equips.button_items[3] * 0x80, 0x1000, "../z_construct.c", 219); + } osSyncPrintf("EVENT=%d\n", gSaveContext.timer_1_state); @@ -131,17 +140,19 @@ void func_801109B0(GlobalContext* globalCtx) { } } - if ((gSaveContext.timer_1_state == 4) || (gSaveContext.timer_1_state == 8)) + if ((gSaveContext.timer_1_state == 4) || (gSaveContext.timer_1_state == 8)) { temp = 0; - else + } else { temp = 1; + } gSaveContext.timer_x[temp] = 26; - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { gSaveContext.timer_y[temp] = 54; - else + } else { gSaveContext.timer_y[temp] = 46; + } } if ((gSaveContext.timer_1_state >= 11) && (gSaveContext.timer_1_state < 16)) { diff --git a/src/code/z_debug.c b/src/code/z_debug.c index e0c1c4f9f..e5bc9199f 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -1,8 +1,5 @@ #include <ultra64.h> #include <global.h> -#include <z64.h> -#include <color.h> -#include <regs.h> #include <PR/os_cont.h> typedef struct { @@ -60,29 +57,24 @@ void func_800636C0() { void func_8006375C(s32 arg0, s32 arg1, float* d_80855320) { } -#ifdef NON_MATCHING // regalloc // Copy Camera Debugger Text void func_8006376C(u8 x, u8 y, u8 colorId, const char* text) { PrintTextBuffer* buf; char* bufText; - s16 i; // v1 + s16 i; buf = &D_8015FA98[D_8011E0B0]; if (D_8011E0B0 < 0x16) { - buf->x = x; buf->y = y; buf->colorId = colorId; i = 0; - bufText = buf->text + 1; - - if (*buf->text = *text++) { - do - if (i++ > 0x14) { - break; - } - while (*bufText++ = *text++); + bufText = buf->text; + while (*bufText++ = *text++) { + if (i++ > 0x14) { + break; + } } *bufText = '\0'; @@ -90,10 +82,6 @@ void func_8006376C(u8 x, u8 y, u8 colorId, const char* text) { } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug/func_8006376C.s") -#endif - // Draw Text void func_80063828(GfxPrint* gfxPrint) { s32 i; diff --git a/src/code/z_demo.c b/src/code/z_demo.c index bbc125e26..dd47227d4 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -114,8 +114,9 @@ void func_800645A0(GlobalContext* globalCtx, CutsceneContext* csCtx) { gSaveContext.cutscene_trigger = 1; } - if ((gSaveContext.cutscene_trigger != 0) && (globalCtx->sceneLoadFlag == 0x14)) + if ((gSaveContext.cutscene_trigger != 0) && (globalCtx->sceneLoadFlag == 0x14)) { gSaveContext.cutscene_trigger = 0; + } if ((gSaveContext.cutscene_trigger != 0) && (csCtx->state == CS_STATE_IDLE)) { // Translates to: "CUTSCENE START REQUEST ANNOUNCEMENT!" @@ -172,13 +173,15 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* sp3F = 0; - if ((csCtx->frames < cmd->startFrame) || (csCtx->frames >= cmd->endFrame) && (cmd->endFrame != cmd->startFrame)) + if ((csCtx->frames < cmd->startFrame) || (csCtx->frames >= cmd->endFrame) && (cmd->endFrame != cmd->startFrame)) { return; + } temp = func_8006F93C(cmd->endFrame - 1, cmd->startFrame, csCtx->frames); - if (csCtx->frames == cmd->startFrame) + if (csCtx->frames == cmd->startFrame) { sp3F = 1; + } switch (cmd->base) { case 1: @@ -198,13 +201,15 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* case 3: if (sp3F != 0) { func_8006C3D0(globalCtx, 0); - if (gSaveContext.entrance_index == 0x0053) + if (gSaveContext.entrance_index == 0x0053) { func_8006C3D0(globalCtx, 2); + } } break; case 6: - if (globalCtx->unk_10AC4 < 0x3200) + if (globalCtx->unk_10AC4 < 0x3200) { globalCtx->unk_10AC4 += 0x23; + } break; case 7: if (sp3F != 0) { @@ -219,8 +224,9 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* } break; case 8: - if (globalCtx->unk_11D30[0] < 0x80) + if (globalCtx->unk_11D30[0] < 0x80) { globalCtx->unk_11D30[0] += 4; + } break; case 9: globalCtx->unk_10B12[3] = 0x10; @@ -229,33 +235,40 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* func_8006C3D0(globalCtx, 1); break; case 11: - if (globalCtx->unk_11D30[0] < 0x672) + if (globalCtx->unk_11D30[0] < 0x672) { globalCtx->unk_11D30[0] += 0x14; - if (csCtx->frames == 0x30F) + } + if (csCtx->frames == 0x30F) { func_80078884(NA_SE_EV_DEKU_DEATH); - else if (csCtx->frames == 0x2CD) + } else if (csCtx->frames == 0x2CD) { globalCtx->unk_11D30[0] = 0; + } break; case 12: if (sp3F != 0) { - if (csCtx->state != CS_STATE_UNSKIPPABLE_EXEC) + if (csCtx->state != CS_STATE_UNSKIPPABLE_EXEC) { csCtx->state = CS_STATE_UNSKIPPABLE_INIT; + } } break; case 13: - if (globalCtx->unk_11D30[1] == 0) + if (globalCtx->unk_11D30[1] == 0) { func_80078884(NA_SE_EV_TRIFORCE_FLASH); - if (globalCtx->unk_11D30[1] < 0xFF) + } + if (globalCtx->unk_11D30[1] < 0xFF) { globalCtx->unk_11D30[1] += 5; + } break; case 14: - if (sp3F != 0) + if (sp3F != 0) { func_800BC490(globalCtx, 1); + } break; case 15: - if (sp3F != 0) + if (sp3F != 0) { TitleCard_InitPlaceName(globalCtx, &globalCtx->actorCtx.titleCtx, player->unk_1B0, 0xA0, 0x78, 0x90, 0x18, 0x14); + } break; case 16: if (sp3F != 0) { @@ -266,14 +279,16 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* } break; case 17: - if (sp3F != 0) + if (sp3F != 0) { func_80092FAC(D_8015FCCA); + } break; case 18: globalCtx->unk_10B12[0] = 0; globalCtx->gloomySkyEvent = 2; - if (gSaveContext.day_time < 0x4AAB) + if (gSaveContext.day_time < 0x4AAB) { gSaveContext.day_time += 30; + } if (globalCtx->unk_10B12[1] == 0) { D_8011FB30 = 0; func_800F6D58(14, 1, 0); @@ -305,17 +320,19 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* break; case 25: gSaveContext.day_time += 30; - if ((gSaveContext.day_time & 0xFFFF) > 0xCAAA) + if ((gSaveContext.day_time & 0xFFFF) > 0xCAAA) { gSaveContext.day_time = 0xCAAA; + } break; case 26: if ((gSaveContext.day_time < 0x3000) || (gSaveContext.day_time >= 0x4555)) { - if ((gSaveContext.day_time >= 0x4555) && (gSaveContext.day_time < 0xAAAB)) + if ((gSaveContext.day_time >= 0x4555) && (gSaveContext.day_time < 0xAAAB)) { globalCtx->unk_10AE3 = 1; - else if ((gSaveContext.day_time >= 0xAAAB) && (gSaveContext.day_time < 0xC556)) + } else if ((gSaveContext.day_time >= 0xAAAB) && (gSaveContext.day_time < 0xC556)) { globalCtx->unk_10AE3 = 2; - else + } else { globalCtx->unk_10AE3 = 3; + } } break; case 27: @@ -346,18 +363,20 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase* func_8006C3D0(globalCtx, 4); break; case 32: - if (sp3F != 0) + if (sp3F != 0) { globalCtx->unk_10B0A = 1; + } func_800788CC(0x20C0); break; case 33: gSaveContext.unk_1422 = 1; break; case 34: - if (!gSaveContext.night_flag) + if (!gSaveContext.night_flag) { gSaveContext.day_time -= D_8011FB40; - else + } else { gSaveContext.day_time -= D_8011FB40 * 2; + } break; case 35: func_800EE824(csCtx); diff --git a/src/code/z_effect.c b/src/code/z_effect.c new file mode 100644 index 000000000..dfe367d13 --- /dev/null +++ b/src/code/z_effect.c @@ -0,0 +1,26 @@ +#include <ultra64.h> +#include <global.h> + +GlobalContext* func_80026B00(void) { + return D_80157DA0; +} + +#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_80026B0C.s") + +void func_80026C1C(u8* arg0) { + arg0[0] = 0; + arg0[1] = 0; + arg0[2] = 0; +} + +#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_80026C2C.s") + +#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/Effect_Add.s") + +#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_80026E74.s") + +#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_80026F70.s") + +#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_8002709C.s") + +#pragma GLOBAL_ASM("asm/non_matchings/code/z_effect/func_800271A8.s") diff --git a/src/code/z_en_a_keep.c b/src/code/z_en_a_keep.c index ea67ceb05..85cc0e9c2 100644 --- a/src/code/z_en_a_keep.c +++ b/src/code/z_en_a_keep.c @@ -94,8 +94,9 @@ void En_A_Obj_Init(ActorEnAObj* this, GlobalContext* globalCtx) { break; } - if (this->actor.params >= 9) + if (this->actor.params >= 9) { sp28 = 12.0f; + } ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawFunc_Circle, sp28); @@ -154,8 +155,9 @@ void En_A_Obj_Init(ActorEnAObj* this, GlobalContext* globalCtx) { break; } - if (this->actor.params < 5) + if (this->actor.params < 5) { this->actor.sub_98.mass = 0xFF; + } if (this->dynaPolyId != -1) { DynaPolyInfo_Alloc(D_8011546C[this->dynaPolyId], &sp34); diff --git a/src/code/z_en_item00.c b/src/code/z_en_item00.c index 1945c75ff..348e983ba 100644 --- a/src/code/z_en_item00.c +++ b/src/code/z_en_item00.c @@ -289,8 +289,9 @@ void En_Item00_Init(ActorEnItem00* this, GlobalContext* globalCtx) { break; } - if ((sp2C != 0) && !func_8002F410(&this->actor, globalCtx)) + if ((sp2C != 0) && !func_8002F410(&this->actor, globalCtx)) { func_8002F554(&this->actor, globalCtx, sp2C); + } En_Item00_SetNewUpdate(this, (ActorFunc)func_8001E5C8); this->updateFunc(this, globalCtx); @@ -480,11 +481,13 @@ void En_Item00_Update(ActorEnItem00* this, GlobalContext* globalCtx) { sp3C = 0; sp3A = 0; - if (this->unk_15A > 0) + if (this->unk_15A > 0) { this->unk_15A--; + } - if ((this->unk_15A > 0) && (this->unk_15A < 41) && (this->unk_154 <= 0)) + if ((this->unk_15A > 0) && (this->unk_15A < 41) && (this->unk_154 <= 0)) { this->unk_156 = this->unk_15A; + } this->updateFunc(this, globalCtx); @@ -533,23 +536,28 @@ void En_Item00_Update(ActorEnItem00* this, GlobalContext* globalCtx) { (this->actor.params == DROP_TUNIC_ZORA) || (this->actor.params == DROP_TUNIC_GORON)) { f32 newUnkBC = Math_Coss(this->actor.shape.rot.x) * 37.0f; this->actor.shape.unk_08 = newUnkBC; - if (newUnkBC >= 0.0f) + if (newUnkBC >= 0.0f) { this->actor.shape.unk_08 = this->actor.shape.unk_08; - else + } else { this->actor.shape.unk_08 = -this->actor.shape.unk_08; + } } - if (this->unk_154 > 0) + if (this->unk_154 > 0) { return; + } // MISMATCH: The first function argument is loaded too early here if (!((this->actor.xzDistanceFromLink <= 30.0f) && (this->actor.yDistanceFromLink >= -50.0f) && - (this->actor.yDistanceFromLink <= 50.0f))) - if (!func_8002F410(&this->actor, globalCtx)) + (this->actor.yDistanceFromLink <= 50.0f))) { + if (!func_8002F410(&this->actor, globalCtx)) { return; + } + } - if (globalCtx->unk_10A20 != 0) + if (globalCtx->unk_10A20 != 0) { return; + } switch (this->actor.params) { case DROP_RUPEE_GREEN: @@ -630,8 +638,9 @@ void En_Item00_Update(ActorEnItem00* this, GlobalContext* globalCtx) { } // MISMATCH: The first function argument is also loaded too early here - if ((sp3C != 0) && !func_8002F410(&this->actor, globalCtx)) + if ((sp3C != 0) && !func_8002F410(&this->actor, globalCtx)) { func_8002F554(&this->actor, globalCtx, sp3C); + } switch (this->actor.params) { case DROP_HEART_PIECE: diff --git a/src/code/code_8006C360.c b/src/code/z_face_reaction.c index 01cf89b4d..1bfe18b7c 100644 --- a/src/code/code_8006C360.c +++ b/src/code/z_face_reaction.c @@ -1,7 +1,7 @@ #include <ultra64.h> #include <global.h> -u16 D_8011F3F0[60][9] = { +u16 sReactionTextIds[60][9] = { { 0x0000, 0x7124, 0x7127, 0x7126, 0x7125, 0x7127, 0x7124, 0x7125, 0x7127 }, { 0x0000, 0x7128, 0x7129, 0x7128, 0x7128, 0x7128, 0x7128, 0x712A, 0x712B }, { 0x0000, 0x7128, 0x712B, 0x7128, 0x7128, 0x7129, 0x7128, 0x712B, 0x7128 }, @@ -64,7 +64,7 @@ u16 D_8011F3F0[60][9] = { { 0x0000, 0x7104, 0x7105, 0x7107, 0x7105, 0x710C, 0x7105, 0x7107, 0x7107 }, }; -u16 func_8006C360(GlobalContext* globalCtx, u32 idx) { - u8 mask = func_8008F080(globalCtx); - return D_8011F3F0[idx][mask]; +u16 Text_GetFaceReaction(GlobalContext* globalCtx, u32 reactionSet) { + u8 currentMask = func_8008F080(globalCtx); + return sReactionTextIds[reactionSet][currentMask]; } diff --git a/src/code/z_horse.c b/src/code/z_horse.c index 13f6382f5..44612269b 100644 --- a/src/code/z_horse.c +++ b/src/code/z_horse.c @@ -159,19 +159,21 @@ void func_8006D684(GlobalContext* globalCtx, Player* player) { { 0xF6F7, 0x0139, 0x1766 }, }; - if (gSaveContext.entrance_index == 0x028A) + if (gSaveContext.entrance_index == 0x028A) { spawnPos = spawnPositions[0]; - else if (gSaveContext.entrance_index == 0x028E) + } else if (gSaveContext.entrance_index == 0x028E) { spawnPos = spawnPositions[1]; - else if (gSaveContext.entrance_index == 0x0292) + } else if (gSaveContext.entrance_index == 0x0292) { spawnPos = spawnPositions[2]; - else + } else { spawnPos = spawnPositions[3]; + } player->rideActor = Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, spawnPos.x, spawnPos.y, spawnPos.z, 0, player->actor.posRot.rot.y, 0, 7); - if (player->rideActor == NULL) + if (player->rideActor == NULL) { __assert("player->ride.actor != NULL", "../z_horse.c", 561); + } func_8002DECC(globalCtx, player, player->rideActor); func_8002DE74(globalCtx, player); @@ -180,15 +182,17 @@ void func_8006D684(GlobalContext* globalCtx, Player* player) { (Flags_GetEventChkInf(0x18) == 0) && (DREG(1) == 0)) { player->rideActor = Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, 894.0f, 0.0f, -2084.0f, 0, -0x7FFF, 0, 5); - if (player->rideActor == NULL) + if (player->rideActor == NULL) { __assert("player->ride.actor != NULL", "../z_horse.c", 582); + } func_8002DECC(globalCtx, player, player->rideActor); func_8002DE74(globalCtx, player); gSaveContext.horse_data.scene = globalCtx->sceneNum; - if (globalCtx->sceneNum == SCENE_SPOT12) + if (globalCtx->sceneNum == SCENE_SPOT12) { player->rideActor->room = -1; + } } else { static struct_8011F9B8 D_8011F9B8[] = { { 93, 0xFFF0, 0x0E10, 0x0585, 0x0168, 0x8001, 8 }, { 99, 0xFFF0, 0xFF06, 0x0001, 0xF9D4, 0x4000, 6 }, @@ -210,8 +214,9 @@ void func_8006D684(GlobalContext* globalCtx, Player* player) { player->rideActor = Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, D_8011F9B8[i].pos.x, D_8011F9B8[i].pos.y, D_8011F9B8[i].pos.z, 0, player->actor.posRot.rot.y, 0, D_8011F9B8[i].type); - if (player->rideActor == NULL) + if (player->rideActor == NULL) { __assert("player->ride.actor != NULL", "../z_horse.c", 628); + } func_8002DECC(globalCtx, player, player->rideActor); func_8002DE74(globalCtx, player); @@ -221,14 +226,16 @@ void func_8006D684(GlobalContext* globalCtx, Player* player) { s32 pad2; temp = 0; - if (((gSaveContext.event_inf[0] & 0x10) >> 4) && D_8011F9B8[i].type == 6) + if (((gSaveContext.event_inf[0] & 0x10) >> 4) && D_8011F9B8[i].type == 6) { temp = 0x8000; + } player->rideActor = Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, D_8011F9B8[i].pos.x, D_8011F9B8[i].pos.y, D_8011F9B8[i].pos.z, 0, D_8011F9B8[i].angle, 0, D_8011F9B8[i].type | temp); - if (player->rideActor == NULL) + if (player->rideActor == NULL) { __assert("player->ride.actor != NULL", "../z_horse.c", 667); + } player->actor.posRot.pos.x = D_8011F9B8[i].pos.x; player->actor.posRot.pos.y = D_8011F9B8[i].pos.y; diff --git a/src/code/z_kaleido_scope_call.c b/src/code/z_kaleido_scope_call.c index a722beff9..3366c932d 100644 --- a/src/code/z_kaleido_scope_call.c +++ b/src/code/z_kaleido_scope_call.c @@ -75,8 +75,9 @@ void KaleidoScopeCall_Update(GlobalContext* globalCtx) { pauseCtx->state++; } else if (pauseCtx->state == 2 || pauseCtx->state == 9) { osSyncPrintf("R_PAUSE_MENU_MODE=%d\n", R_PAUSE_MENU_MODE); - if (R_PAUSE_MENU_MODE >= 3) + if (R_PAUSE_MENU_MODE >= 3) { pauseCtx->state++; + } } else if (pauseCtx->state != 0) { if (&gKaleidoMgrOverlayTable[KALEIDO_OVL_KALEIDO_SCOPE] != gKaleidoMgrCurOvl) { if (gKaleidoMgrCurOvl) { diff --git a/src/code/z_lifemeter.c b/src/code/z_lifemeter.c index b69ac8b34..27050cf24 100644 --- a/src/code/z_lifemeter.c +++ b/src/code/z_lifemeter.c @@ -48,7 +48,7 @@ void Health_InitData(GlobalContext* globalCtx) { } #ifdef NON_MATCHING -// this function still needs some work +// this function still needs some work but it should be functionally equivalent void Health_UpdateData(GlobalContext* globalCtx) { InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; f32 temp_f0 = interfaceCtx->unk_1FE * 0.1f; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 91c70d609..51de6e08c 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -1141,13 +1141,15 @@ void Inventory_SwapAgeEquipment(void) { if (LINK_AGE_IN_YEARS == YEARS_CHILD) { for (i = 0; i < 4; i++) { - if (i != 0) + if (i != 0) { gSaveContext.child_equips.button_items[i] = gSaveContext.equips.button_items[i]; - else + } else { gSaveContext.child_equips.button_items[i] = ITEM_SWORD_KOKIRI; + } - if (i != 0) + if (i != 0) { gSaveContext.child_equips.c_button_slots[i - 1] = gSaveContext.equips.c_button_slots[i - 1]; + } } gSaveContext.child_equips.equipment = gSaveContext.equips.equipment; @@ -1172,8 +1174,9 @@ void Inventory_SwapAgeEquipment(void) { for (i = 0; i < 4; i++) { gSaveContext.equips.button_items[i] = gSaveContext.adult_equips.button_items[i]; - if (i != 0) + if (i != 0) { gSaveContext.equips.c_button_slots[i - 1] = gSaveContext.adult_equips.c_button_slots[i - 1]; + } if (((gSaveContext.equips.button_items[i] >= ITEM_BOTTLE) && (gSaveContext.equips.button_items[i] <= ITEM_POE)) || @@ -1190,8 +1193,9 @@ void Inventory_SwapAgeEquipment(void) { for (i = 0; i < 4; i++) { gSaveContext.adult_equips.button_items[i] = gSaveContext.equips.button_items[i]; - if (i != 0) + if (i != 0) { gSaveContext.adult_equips.c_button_slots[i - 1] = gSaveContext.equips.c_button_slots[i - 1]; + } } gSaveContext.adult_equips.equipment = gSaveContext.equips.equipment; @@ -1200,8 +1204,9 @@ void Inventory_SwapAgeEquipment(void) { for (i = 0; i < 4; i++) { gSaveContext.equips.button_items[i] = gSaveContext.child_equips.button_items[i]; - if (i != 0) + if (i != 0) { gSaveContext.equips.c_button_slots[i - 1] = gSaveContext.child_equips.c_button_slots[i - 1]; + } if (((gSaveContext.equips.button_items[i] >= ITEM_BOTTLE) && (gSaveContext.equips.button_items[i] <= ITEM_POE)) || @@ -1221,8 +1226,9 @@ void Inventory_SwapAgeEquipment(void) { temp = gEquipMasks[EQUIP_SHIELD] & gSaveContext.equips.equipment; if (temp != 0) { temp >>= gEquipShifts[EQUIP_SHIELD]; - if (!(gBitFlags[temp + 3] & gSaveContext.equipment)) + if (!(gBitFlags[temp + 3] & gSaveContext.equipment)) { gSaveContext.equips.equipment &= gEquipNegMasks[EQUIP_SHIELD]; + } } } #else @@ -1315,8 +1321,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { s8 bombCount; slot = SLOT(item); - if (item >= ITEM_STICKS_5) + if (item >= ITEM_STICKS_5) { slot = SLOT(sExtraItemBases[item - ITEM_STICKS_5]); + } osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("item_get_setting=%d pt=%d z=%x\n", item, slot, gSaveContext.items[slot]); @@ -1330,8 +1337,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { osSyncPrintf("封印 = %x\n", gSaveContext.quest_items); osSyncPrintf(VT_RST); - if (item == ITEM_MEDALLION_WATER) + if (item == ITEM_MEDALLION_WATER) { func_8006D0AC(globalCtx); + } return ITEM_NONE; } else if ((item >= ITEM_SONG_MINUET) && (item <= ITEM_SONG_STORMS)) { @@ -1423,8 +1431,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return ITEM_NONE; } else { AMMO(ITEM_BOW)++; - if (AMMO(ITEM_BOW) > CUR_CAPACITY(UPG_QUIVER)) + if (AMMO(ITEM_BOW) > CUR_CAPACITY(UPG_QUIVER)) { AMMO(ITEM_BOW) = CUR_CAPACITY(UPG_QUIVER); + } } } else if (item == ITEM_QUIVER_40) { Inventory_ChangeUpgrade(UPG_QUIVER, 2); @@ -1450,8 +1459,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return ITEM_NONE; } else { AMMO(ITEM_BOMB)++; - if (AMMO(ITEM_BOMB) > CUR_CAPACITY(UPG_BOMB_BAG)) + if (AMMO(ITEM_BOMB) > CUR_CAPACITY(UPG_BOMB_BAG)) { AMMO(ITEM_BOMB) = CUR_CAPACITY(UPG_BOMB_BAG); + } } } else if (item == ITEM_BOMB_BAG_30) { Inventory_ChangeUpgrade(UPG_BOMB_BAG, 2); @@ -1483,26 +1493,30 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { Inventory_ChangeUpgrade(UPG_WALLET, 2); return ITEM_NONE; } else if (item == ITEM_STICK_UPGRADE_20) { - if (gSaveContext.items[slot] == ITEM_NONE) + if (gSaveContext.items[slot] == ITEM_NONE) { INV_CONTENT(ITEM_STICK) = ITEM_STICK; + } Inventory_ChangeUpgrade(UPG_STICKS, 2); AMMO(ITEM_STICK) = CAPACITY(UPG_STICKS, 2); return ITEM_NONE; } else if (item == ITEM_STICK_UPGRADE_30) { - if (gSaveContext.items[slot] == ITEM_NONE) + if (gSaveContext.items[slot] == ITEM_NONE) { INV_CONTENT(ITEM_STICK) = ITEM_STICK; + } Inventory_ChangeUpgrade(UPG_STICKS, 3); AMMO(ITEM_STICK) = CAPACITY(UPG_STICKS, 3); return ITEM_NONE; } else if (item == ITEM_NUT_UPGRADE_30) { - if (gSaveContext.items[slot] == ITEM_NONE) + if (gSaveContext.items[slot] == ITEM_NONE) { INV_CONTENT(ITEM_NUT) = ITEM_NUT; + } Inventory_ChangeUpgrade(UPG_NUTS, 2); AMMO(ITEM_NUT) = CAPACITY(UPG_NUTS, 2); return ITEM_NONE; } else if (item == ITEM_NUT_UPGRADE_40) { - if (gSaveContext.items[slot] == ITEM_NONE) + if (gSaveContext.items[slot] == ITEM_NONE) { INV_CONTENT(ITEM_NUT) = ITEM_NUT; + } Inventory_ChangeUpgrade(UPG_NUTS, 3); AMMO(ITEM_NUT) = CAPACITY(UPG_NUTS, 3); return ITEM_NONE; @@ -1521,8 +1535,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { AMMO(ITEM_STICK) = 1; } else { AMMO(ITEM_STICK)++; - if (AMMO(ITEM_STICK) > CUR_CAPACITY(UPG_STICKS)) + if (AMMO(ITEM_STICK) > CUR_CAPACITY(UPG_STICKS)) { AMMO(ITEM_STICK) = CUR_CAPACITY(UPG_STICKS); + } } } else if ((item == ITEM_STICKS_5) || (item == ITEM_STICKS_10)) { if (gSaveContext.items[slot] == ITEM_NONE) { @@ -1530,8 +1545,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { AMMO(ITEM_STICK) = sAmmoRefillCounts[item - ITEM_STICKS_5]; } else { AMMO(ITEM_STICK) += sAmmoRefillCounts[item - ITEM_STICKS_5]; - if (AMMO(ITEM_STICK) > CUR_CAPACITY(UPG_STICKS)) + if (AMMO(ITEM_STICK) > CUR_CAPACITY(UPG_STICKS)) { AMMO(ITEM_STICK) = CUR_CAPACITY(UPG_STICKS); + } } item = ITEM_STICK; } else if (item == ITEM_NUT) { @@ -1540,8 +1556,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { AMMO(ITEM_NUT) = ITEM_NUT; } else { AMMO(ITEM_NUT)++; - if (AMMO(ITEM_NUT) > CUR_CAPACITY(UPG_NUTS)) + if (AMMO(ITEM_NUT) > CUR_CAPACITY(UPG_NUTS)) { AMMO(ITEM_NUT) = CUR_CAPACITY(UPG_NUTS); + } } } else if ((item == ITEM_NUTS_5) || (item == ITEM_NUTS_10)) { if (gSaveContext.items[slot] == ITEM_NONE) { @@ -1552,8 +1569,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { sAmmoRefillCounts[item - ITEM_NUTS_5]); } else { AMMO(ITEM_NUT) += sAmmoRefillCounts[item - ITEM_NUTS_5]; - if (AMMO(ITEM_NUT) > CUR_CAPACITY(UPG_NUTS)) + if (AMMO(ITEM_NUT) > CUR_CAPACITY(UPG_NUTS)) { AMMO(ITEM_NUT) = CUR_CAPACITY(UPG_NUTS); + } } item = ITEM_NUT; } else if (item == ITEM_BOMB) { @@ -1561,14 +1579,16 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { osSyncPrintf(" 爆弾 爆弾 爆弾 爆弾 爆弾 爆弾 爆弾 \n"); bombCount = AMMO(ITEM_BOMB) + 1; AMMO(ITEM_BOMB) = bombCount; - if (bombCount > CUR_CAPACITY(UPG_BOMB_BAG)) + if (bombCount > CUR_CAPACITY(UPG_BOMB_BAG)) { AMMO(ITEM_BOMB) = CUR_CAPACITY(UPG_BOMB_BAG); + } return ITEM_NONE; } else if ((item >= ITEM_BOMBS_5) && (item <= ITEM_BOMBS_30)) { bombCount = AMMO(ITEM_BOMB) + sAmmoRefillCounts[item - ITEM_BOMBS_5]; AMMO(ITEM_BOMB) = bombCount; - if (bombCount > CUR_CAPACITY(UPG_BOMB_BAG)) + if (bombCount > CUR_CAPACITY(UPG_BOMB_BAG)) { AMMO(ITEM_BOMB) = CUR_CAPACITY(UPG_BOMB_BAG); + } return ITEM_NONE; } else if (item == ITEM_BOMBCHU) { if (gSaveContext.items[slot] == ITEM_NONE) { @@ -1577,8 +1597,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return ITEM_NONE; } else { AMMO(ITEM_BOMBCHU) += 10; - if (AMMO(ITEM_BOMBCHU) > 50) + if (AMMO(ITEM_BOMBCHU) > 50) { AMMO(ITEM_BOMBCHU) = 50; + } return ITEM_NONE; } } else if ((item == ITEM_BOMBCHUS_5) || (item == ITEM_BOMBCHUS_20)) { @@ -1588,15 +1609,17 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return ITEM_NONE; } else { AMMO(ITEM_BOMBCHU) += sAmmoRefillCounts[item - ITEM_BOMBCHUS_5 + 8]; - if (AMMO(ITEM_BOMBCHU) > 50) + if (AMMO(ITEM_BOMBCHU) > 50) { AMMO(ITEM_BOMBCHU) = 50; + } return ITEM_NONE; } } else if ((item >= ITEM_ARROWS_SMALL) && (item <= ITEM_ARROWS_LARGE)) { AMMO(ITEM_BOW) += sAmmoRefillCounts[item - ITEM_ARROWS_SMALL + 4]; - if ((AMMO(ITEM_BOW) >= CUR_CAPACITY(UPG_QUIVER)) || (AMMO(ITEM_BOW) < 0)) + if ((AMMO(ITEM_BOW) >= CUR_CAPACITY(UPG_QUIVER)) || (AMMO(ITEM_BOW) < 0)) { AMMO(ITEM_BOW) = CUR_CAPACITY(UPG_QUIVER); + } osSyncPrintf("%d本 Item_MaxGet=%d\n", AMMO(ITEM_BOW), CUR_CAPACITY(UPG_QUIVER)); @@ -1609,8 +1632,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { } else if (item == ITEM_SEEDS) { AMMO(ITEM_SLINGSHOT) += 5; - if (AMMO(ITEM_SLINGSHOT) >= CUR_CAPACITY(UPG_BULLET_BAG)) + if (AMMO(ITEM_SLINGSHOT) >= CUR_CAPACITY(UPG_BULLET_BAG)) { AMMO(ITEM_SLINGSHOT) = CUR_CAPACITY(UPG_BULLET_BAG); + } if (!(gSaveContext.item_get_inf[1] & 8)) { gSaveContext.item_get_inf[1] |= 8; @@ -1621,8 +1645,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { } else if (item == ITEM_SEEDS_30) { AMMO(ITEM_SLINGSHOT) += 30; - if (AMMO(ITEM_SLINGSHOT) >= CUR_CAPACITY(UPG_BULLET_BAG)) + if (AMMO(ITEM_SLINGSHOT) >= CUR_CAPACITY(UPG_BULLET_BAG)) { AMMO(ITEM_SLINGSHOT) = CUR_CAPACITY(UPG_BULLET_BAG); + } if (!(gSaveContext.item_get_inf[1] & 8)) { gSaveContext.item_get_inf[1] |= 8; @@ -1665,8 +1690,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { Health_ChangeBy(globalCtx, 0x10); return item; } else if (item == ITEM_MAGIC_SMALL) { - if (gSaveContext.unk_13F0 != 10) + if (gSaveContext.unk_13F0 != 10) { func_80087680(globalCtx); + } func_80087708(globalCtx, 12, 5); @@ -1677,8 +1703,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { return item; } else if (item == ITEM_MAGIC_LARGE) { - if (gSaveContext.unk_13F0 != 10) + if (gSaveContext.unk_13F0 != 10) { func_80087680(globalCtx); + } func_80087708(globalCtx, 24, 5); @@ -1741,8 +1768,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) { } } } else if ((item >= ITEM_WEIRD_EGG) && (item <= ITEM_CLAIM_CHECK)) { - if (item == ITEM_SAW) + if (item == ITEM_SAW) { gSaveContext.item_get_inf[1] |= 0x8000; + } prevTradeItem = INV_CONTENT(item); INV_CONTENT(item) = item; @@ -1990,8 +2018,9 @@ void Inventory_UpdateBottleItem(GlobalContext* globalCtx, u8 item, u8 cButton) { // Special case to only empty half of a Lon Lon Milk Bottle if ((gSaveContext.items[gSaveContext.equips.c_button_slots[cButton - 1]] == ITEM_MILK_BOTTLE) && - (item == ITEM_BOTTLE)) + (item == ITEM_BOTTLE)) { item = ITEM_MILK_HALF; + } gSaveContext.items[gSaveContext.equips.c_button_slots[cButton - 1]] = item; gSaveContext.equips.button_items[cButton] = item; @@ -2052,14 +2081,17 @@ u32 sDoActionTextures[] = { 0x07000000, 0x07000180 }; #ifdef NON_MATCHING // 0x80000000 is reused in the 2 *_TO_VIRTUAL macros when it shouldn't void Interface_LoadActionLabel(InterfaceContext* interfaceCtx, u16 action, s16 arg2) { - if (action >= 0x1D) + if (action >= 0x1D) { action = 0x0A; + } - if (gSaveContext.language != 0) + if (gSaveContext.language != 0) { action += 0x1D; + } - if (gSaveContext.language == 2) + if (gSaveContext.language == 2) { action += 0x1D; + } if ((action != 0x0A) && (action != 0x27) && (action != 0x44)) { osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, OS_MESG_BLOCK); @@ -2375,12 +2407,14 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { if (gSaveContext.unk_13F4 != maxMagic) { if (gSaveContext.unk_13F4 < maxMagic) { gSaveContext.unk_13F4 += 8; - if (gSaveContext.unk_13F4 > maxMagic) + if (gSaveContext.unk_13F4 > maxMagic) { gSaveContext.unk_13F4 = maxMagic; + } } else { gSaveContext.unk_13F4 -= 8; - if (gSaveContext.unk_13F4 <= maxMagic) + if (gSaveContext.unk_13F4 <= maxMagic) { gSaveContext.unk_13F4 = maxMagic; + } } } else { gSaveContext.unk_13F0 = 9; @@ -2389,8 +2423,9 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { case 9: gSaveContext.magic += 4; - if (gSaveContext.game_mode == 0 && gSaveContext.scene_setup_index < 4) + if (gSaveContext.game_mode == 0 && gSaveContext.scene_setup_index < 4) { Audio_PlaySoundGeneral(0x401F, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } // Translates to: "Storage MAGIC_NOW=%d (%d)" osSyncPrintf("蓄電 MAGIC_NOW=%d (%d)\n", gSaveContext.magic, gSaveContext.unk_13F6); @@ -2423,20 +2458,23 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { case 6: color = sMagicBorderColors[sMagicBorderIndexes[sMagicBorderStep]]; - if (sMagicBorderR >= color[0]) + if (sMagicBorderR >= color[0]) { sMagicBorderR -= ABS(sMagicBorderR - color[0]) / sMagicBorderRatio; - else + } else { sMagicBorderR += ABS(sMagicBorderR - color[0]) / sMagicBorderRatio; + } - if (sMagicBorderG >= color[1]) + if (sMagicBorderG >= color[1]) { sMagicBorderG -= ABS(sMagicBorderG - color[1]) / sMagicBorderRatio; - else + } else { sMagicBorderG += ABS(sMagicBorderG - color[1]) / sMagicBorderRatio; + } - if (sMagicBorderB >= color[2]) + if (sMagicBorderB >= color[2]) { sMagicBorderB -= ABS(sMagicBorderB - color[2]) / sMagicBorderRatio; - else + } else { sMagicBorderB += ABS(sMagicBorderB - color[2]) / sMagicBorderRatio; + } sMagicBorderRatio--; if (sMagicBorderRatio == 0) { @@ -2445,8 +2483,9 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { sMagicBorderB = color[2]; sMagicBorderRatio = YREG(40 + sMagicBorderStep); sMagicBorderStep++; - if (sMagicBorderStep >= 4) + if (sMagicBorderStep >= 4) { sMagicBorderStep = 0; + } } break; case 5: @@ -2481,20 +2520,23 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { color = sMagicBorderColors[sMagicBorderIndexes[sMagicBorderStep]]; - if (sMagicBorderR >= color[0]) + if (sMagicBorderR >= color[0]) { sMagicBorderR -= ABS(sMagicBorderR - color[0]) / sMagicBorderRatio; - else + } else { sMagicBorderR += ABS(sMagicBorderR - color[0]) / sMagicBorderRatio; + } - if (sMagicBorderG >= color[1]) + if (sMagicBorderG >= color[1]) { sMagicBorderG -= ABS(sMagicBorderG - color[1]) / sMagicBorderRatio; - else + } else { sMagicBorderG += ABS(sMagicBorderG - color[1]) / sMagicBorderRatio; + } - if (sMagicBorderB >= color[2]) + if (sMagicBorderB >= color[2]) { sMagicBorderB -= ABS(sMagicBorderB - color[2]) / sMagicBorderRatio; - else + } else { sMagicBorderB += ABS(sMagicBorderB - color[2]) / sMagicBorderRatio; + } sMagicBorderRatio--; if (sMagicBorderRatio == 0) { @@ -2503,8 +2545,9 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { sMagicBorderB = color[2]; sMagicBorderRatio = YREG(40 + sMagicBorderStep); sMagicBorderStep++; - if (sMagicBorderStep >= 4) + if (sMagicBorderStep >= 4) { sMagicBorderStep = 0; + } } break; case 10: @@ -2772,13 +2815,14 @@ void Interface_DrawItemButtons(GlobalContext* globalCtx) { // C-Up Button Texture, Color & Label (Navi Text) gDPPipeSync(gfxCtx->overlay.p++); - if ((gSaveContext.unk_13EA == 1) || (gSaveContext.unk_13EA == 2) || (gSaveContext.unk_13EA == 5)) + if ((gSaveContext.unk_13EA == 1) || (gSaveContext.unk_13EA == 2) || (gSaveContext.unk_13EA == 5)) { cUpAlpha = 0; - else if ((player->stateFlags2 & 0x00200000) || (func_8008F2F8(globalCtx) == 4) || - (player->stateFlags2 & 0x00040000)) + } else if ((player->stateFlags2 & 0x00200000) || (func_8008F2F8(globalCtx) == 4) || + (player->stateFlags2 & 0x00040000)) { cUpAlpha = 0x46; - else + } else { cUpAlpha = interfaceCtx->healthAlpha; + } gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, R_C_BTN_COLOR(0), R_C_BTN_COLOR(1), R_C_BTN_COLOR(2), cUpAlpha); gDPSetCombineLERP(gfxCtx->overlay.p++, TEXEL0, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0, TEXEL0, 0, @@ -2820,15 +2864,16 @@ void Interface_DrawItemButtons(GlobalContext* globalCtx) { // Empty C Button Arrows for (i = 1; i < 4; i++) { if (gSaveContext.equips.button_items[i] > 0xF0) { - if (i == 1) + if (i == 1) { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, R_C_BTN_COLOR(0), R_C_BTN_COLOR(1), R_C_BTN_COLOR(2), interfaceCtx->cLeftAlpha); - else if (i == 2) + } else if (i == 2) { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, R_C_BTN_COLOR(0), R_C_BTN_COLOR(1), R_C_BTN_COLOR(2), interfaceCtx->cDownAlpha); - else + } else { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, R_C_BTN_COLOR(0), R_C_BTN_COLOR(1), R_C_BTN_COLOR(2), interfaceCtx->cRightAlpha); + } gfxCtx->overlay.p = Draw_TextureIA8(gfxCtx->overlay.p, &D_02000A00[i + 1], 0x20, 0x20, R_ITEM_BTN_X(i), R_ITEM_BTN_Y(i), @@ -3188,12 +3233,13 @@ void Interface_Draw(GlobalContext* globalCtx) { // Rupee Counter gDPPipeSync(gfxCtx->overlay.p++); - if (gSaveContext.rupees == CUR_CAPACITY(UPG_WALLET)) + if (gSaveContext.rupees == CUR_CAPACITY(UPG_WALLET)) { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, 0x78, 0xFF, 0x00, interfaceCtx->magicAlpha); - else if (gSaveContext.rupees != 0) + } else if (gSaveContext.rupees != 0) { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, 0xFF, 0xFF, 0xFF, interfaceCtx->magicAlpha); - else + } else { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, 0x64, 0x64, 0x64, interfaceCtx->magicAlpha); + } gDPSetCombineLERP(gfxCtx->overlay.p++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0); @@ -3201,8 +3247,9 @@ void Interface_Draw(GlobalContext* globalCtx) { interfaceCtx->counterDigits[0] = interfaceCtx->counterDigits[1] = 0; interfaceCtx->counterDigits[2] = gSaveContext.rupees; - if ((interfaceCtx->counterDigits[2] >= 10000) || (interfaceCtx->counterDigits[2] < 0)) + if ((interfaceCtx->counterDigits[2] >= 10000) || (interfaceCtx->counterDigits[2] < 0)) { interfaceCtx->counterDigits[2] &= 0xDDD; + } while (interfaceCtx->counterDigits[2] >= 100) { interfaceCtx->counterDigits[2] -= 100; @@ -3225,8 +3272,9 @@ void Interface_Draw(GlobalContext* globalCtx) { Interface_DrawMagicBar(globalCtx); Interface_DrawMinimap(globalCtx); - if ((R_PAUSE_MENU_MODE != 2) && (R_PAUSE_MENU_MODE != 3)) + if ((R_PAUSE_MENU_MODE != 2) && (R_PAUSE_MENU_MODE != 3)) { func_8002C124(&globalCtx->actorCtx.targetCtx, globalCtx); // Draw Z-Target + } func_80094520(globalCtx->state.gfxCtx); @@ -3343,10 +3391,11 @@ void Interface_Draw(GlobalContext* globalCtx) { G_MTX_MODELVIEW | G_MTX_LOAD); gSPVertex(gfxCtx->overlay.p++, &interfaceCtx->vtx_128[4], 4, 0); - if ((interfaceCtx->unk_1EC < 2) || (interfaceCtx->unk_1EC == 3)) + if ((interfaceCtx->unk_1EC < 2) || (interfaceCtx->unk_1EC == 3)) { Interface_DrawActionLabel(globalCtx->state.gfxCtx, (void*)(u32)interfaceCtx->do_actionSegment); - else + } else { Interface_DrawActionLabel(globalCtx->state.gfxCtx, (void*)((u32)interfaceCtx->do_actionSegment + 0x180)); + } gDPPipeSync(gfxCtx->overlay.p++); @@ -3441,10 +3490,11 @@ void Interface_Draw(GlobalContext* globalCtx) { phi_s1 = ZREG(14); for (phi_s3 = 1; phi_s3 < 7; phi_s3++) { // Carrot Color (based on availability) - if ((interfaceCtx->unk_23A == 0) || (interfaceCtx->unk_23A < phi_s3)) + if ((interfaceCtx->unk_23A == 0) || (interfaceCtx->unk_23A < phi_s3)) { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, 0x00, 0x96, 0xFF, interfaceCtx->aAlpha); - else + } else { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, 0xFF, 0xFF, 0xFF, interfaceCtx->aAlpha); + } gSPTextureRectangle(gfxCtx->overlay.p++, phi_s1 << 2, ZREG(15) << 2, (phi_s1 + 16) << 2, (ZREG(15) + 16) << 2, G_TX_RENDERTILE, 0, 0, 1024, 1024); @@ -3507,10 +3557,11 @@ void Interface_Draw(GlobalContext* globalCtx) { (gSaveContext.equips.button_items[0] != ITEM_SWORD_MASTER) && (gSaveContext.equips.button_items[0] != ITEM_SWORD_BGS) && (gSaveContext.equips.button_items[0] != ITEM_SWORD_KNIFE)) { - if (gSaveContext.button_status[0] != BTN_ENABLED) + if (gSaveContext.button_status[0] != BTN_ENABLED) { gSaveContext.equips.button_items[0] = gSaveContext.button_status[0]; - else + } else { gSaveContext.equips.button_items[0] = ITEM_NONE; + } } // Revert any spoiling trade quest items @@ -3553,20 +3604,22 @@ void Interface_Draw(GlobalContext* globalCtx) { case 5: case 11: D_8015FFE0 = D_8015FFE2 = 20; - if (gSaveContext.timer_1_state == 5) + if (gSaveContext.timer_1_state == 5) { gSaveContext.timer_1_state = 6; - else + } else { gSaveContext.timer_1_state = 12; + } break; case 6: case 12: D_8015FFE2--; if (D_8015FFE2 == 0) { D_8015FFE2 = 20; - if (gSaveContext.timer_1_state == 6) + if (gSaveContext.timer_1_state == 6) { gSaveContext.timer_1_state = 7; - else + } else { gSaveContext.timer_1_state = 13; + } } break; case 3: @@ -3574,10 +3627,11 @@ void Interface_Draw(GlobalContext* globalCtx) { phi_s3 = (gSaveContext.timer_x[0] - 26) / D_8015FFE2; gSaveContext.timer_x[0] -= phi_s3; - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { phi_s3 = (gSaveContext.timer_y[0] - 54) / D_8015FFE2; - else + } else { phi_s3 = (gSaveContext.timer_y[0] - 46) / D_8015FFE2; + } gSaveContext.timer_y[0] -= phi_s3; D_8015FFE2--; @@ -3585,30 +3639,34 @@ void Interface_Draw(GlobalContext* globalCtx) { gSaveContext.timer_x[0] = 26; D_8015FFE2 = 20; - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { gSaveContext.timer_y[0] = 54; - else + } else { gSaveContext.timer_y[0] = 46; + } - if (gSaveContext.timer_1_state == 3) + if (gSaveContext.timer_1_state == 3) { gSaveContext.timer_1_state = 4; - else + } else { gSaveContext.timer_1_state = 8; + } } case 4: case 8: if ((gSaveContext.timer_1_state == 4) || (gSaveContext.timer_1_state == 8)) { - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { gSaveContext.timer_y[0] = 54; - else + } else { gSaveContext.timer_y[0] = 46; + } } if ((gSaveContext.timer_1_state >= 3) && (msgCtx->unk_E300 == 0)) { D_8015FFE0--; if (D_8015FFE0 == 0) { - if (gSaveContext.timer_1_value != 0) + if (gSaveContext.timer_1_value != 0) { gSaveContext.timer_1_value--; + } D_8015FFE0 = 20; @@ -3620,13 +3678,15 @@ void Interface_Draw(GlobalContext* globalCtx) { } D_80125A5C = 0; } else if (gSaveContext.timer_1_value > 60) { - if (sTimerDigits[4] == 1) + if (sTimerDigits[4] == 1) { Audio_PlaySoundGeneral(NA_SE_SY_MESSAGE_WOMAN, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } } else if (gSaveContext.timer_1_value >= 11) { - if (sTimerDigits[4] & 1) + if (sTimerDigits[4] & 1) { Audio_PlaySoundGeneral(NA_SE_SY_WARNING_COUNT_N, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } } else { Audio_PlaySoundGeneral(NA_SE_SY_WARNING_COUNT_E, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); @@ -3638,10 +3698,11 @@ void Interface_Draw(GlobalContext* globalCtx) { phi_s3 = (gSaveContext.timer_x[0] - 26) / D_8015FFE2; gSaveContext.timer_x[0] -= phi_s3; - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { phi_s3 = (gSaveContext.timer_y[0] - 54) / D_8015FFE2; - else + } else { phi_s3 = (gSaveContext.timer_y[0] - 46) / D_8015FFE2; + } gSaveContext.timer_y[0] -= phi_s3; D_8015FFE2--; @@ -3649,19 +3710,21 @@ void Interface_Draw(GlobalContext* globalCtx) { gSaveContext.timer_x[0] = 26; D_8015FFE2 = 20; - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { gSaveContext.timer_y[0] = 54; - else + } else { gSaveContext.timer_y[0] = 46; + } gSaveContext.timer_1_state = 14; } case 14: if (gSaveContext.timer_1_state == 14) { - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { gSaveContext.timer_y[0] = 54; - else + } else { gSaveContext.timer_y[0] = 46; + } } if (gSaveContext.timer_1_state >= 3) { @@ -3686,10 +3749,11 @@ void Interface_Draw(GlobalContext* globalCtx) { gSaveContext.timer_y[1] = 80; D_8015FFE4 = D_8015FFE6 = 20; - if (gSaveContext.timer_2_state < 7) + if (gSaveContext.timer_2_state < 7) { gSaveContext.timer_2_state = 2; - else + } else { gSaveContext.timer_2_state = 8; + } gSaveContext.timer_1_state = 0; } else { @@ -3706,20 +3770,22 @@ void Interface_Draw(GlobalContext* globalCtx) { gSaveContext.timer_x[1] = 140; gSaveContext.timer_y[1] = 80; D_8015FFE4 = D_8015FFE6 = 20; - if (gSaveContext.timer_2_state == 1) + if (gSaveContext.timer_2_state == 1) { gSaveContext.timer_2_state = 2; - else + } else { gSaveContext.timer_2_state = 8; + } break; case 2: case 8: D_8015FFE6--; if (D_8015FFE6 == 0) { D_8015FFE6 = 20; - if (gSaveContext.timer_2_state == 2) + if (gSaveContext.timer_2_state == 2) { gSaveContext.timer_2_state = 3; - else + } else { gSaveContext.timer_2_state = 9; + } } break; case 3: @@ -3730,10 +3796,11 @@ void Interface_Draw(GlobalContext* globalCtx) { phi_s3 = (gSaveContext.timer_x[1] - 26) / D_8015FFE2; gSaveContext.timer_x[1] -= phi_s3; - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { phi_s3 = (gSaveContext.timer_y[1] - 54) / D_8015FFE6; - else + } else { phi_s3 = (gSaveContext.timer_y[1] - 46) / D_8015FFE6; + } gSaveContext.timer_y[1] -= phi_s3; D_8015FFE6--; @@ -3741,23 +3808,26 @@ void Interface_Draw(GlobalContext* globalCtx) { gSaveContext.timer_x[1] = 26; D_8015FFE6 = 20; - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { gSaveContext.timer_y[1] = 54; - else + } else { gSaveContext.timer_y[1] = 46; + } - if (gSaveContext.timer_2_state == 3) + if (gSaveContext.timer_2_state == 3) { gSaveContext.timer_2_state = 4; - else + } else { gSaveContext.timer_2_state = 10; + } } case 4: case 10: if ((gSaveContext.timer_2_state == 4) || (gSaveContext.timer_2_state == 10)) { - if (gSaveContext.health_capacity > 0xA0) + if (gSaveContext.health_capacity > 0xA0) { gSaveContext.timer_y[1] = 54; - else + } else { gSaveContext.timer_y[1] = 46; + } } if (gSaveContext.timer_2_state >= 3) { @@ -3785,13 +3855,15 @@ void Interface_Draw(GlobalContext* globalCtx) { } } else { if (gSaveContext.timer_2_value > 60) { - if (sTimerDigits[4] == 1) + if (sTimerDigits[4] == 1) { Audio_PlaySoundGeneral(NA_SE_SY_MESSAGE_WOMAN, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } } else if (gSaveContext.timer_2_value > 10) { - if (sTimerDigits[4] & 1) + if (sTimerDigits[4] & 1) { Audio_PlaySoundGeneral(NA_SE_SY_WARNING_COUNT_N, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } } else { Audio_PlaySoundGeneral(NA_SE_SY_WARNING_COUNT_E, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); @@ -3817,8 +3889,9 @@ void Interface_Draw(GlobalContext* globalCtx) { break; case 6: D_8015FFE6--; - if (D_8015FFE6 == 0) + if (D_8015FFE6 == 0) { gSaveContext.timer_2_state = 0; + } break; } } @@ -3828,10 +3901,11 @@ void Interface_Draw(GlobalContext* globalCtx) { sTimerDigits[0] = sTimerDigits[1] = sTimerDigits[3] = 0; sTimerDigits[2] = 10; // digit 10 is used as ':' (colon) - if (gSaveContext.timer_1_state != 0) + if (gSaveContext.timer_1_state != 0) { sTimerDigits[4] = gSaveContext.timer_1_value; - else + } else { sTimerDigits[4] = gSaveContext.timer_2_value; + } while (sTimerDigits[4] >= 60) { sTimerDigits[1]++; @@ -3860,15 +3934,17 @@ void Interface_Draw(GlobalContext* globalCtx) { TEXEL0, 0, PRIMITIVE, 0); if (gSaveContext.timer_1_state != 0) { - if ((gSaveContext.timer_1_value < 10) && (gSaveContext.timer_1_state < 11)) + if ((gSaveContext.timer_1_value < 10) && (gSaveContext.timer_1_state < 11)) { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, 0xFF, 0x32, 0x00, 0xFF); - else + } else { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF); + } } else { - if ((gSaveContext.timer_2_value < 10) && (gSaveContext.timer_2_state < 6)) + if ((gSaveContext.timer_2_value < 10) && (gSaveContext.timer_2_state < 6)) { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, 0xFF, 0x32, 0x00, 0xFF); - else + } else { gDPSetPrimColor(gfxCtx->overlay.p++, 0, 0, 0xFF, 0xFF, 0x00, 0xFF); + } } for (phi_s3 = 0; phi_s3 < 5; phi_s3++) { @@ -3881,8 +3957,9 @@ void Interface_Draw(GlobalContext* globalCtx) { } } - if (pauseCtx->flag == 3) + if (pauseCtx->flag == 3) { func_8002AAB0(globalCtx); + } if (interfaceCtx->unk_244 != 0) { gDPPipeSync(gfxCtx->overlay.p++); @@ -3952,32 +4029,38 @@ void Interface_Update(GlobalContext* globalCtx) { case 12: case 13: alpha = 0xFF - (gSaveContext.unk_13EC << 5); - if (alpha < 0) + if (alpha < 0) { alpha = 0; + } func_80082850(globalCtx, alpha); gSaveContext.unk_13EC++; - if (alpha == 0) + if (alpha == 0) { gSaveContext.unk_13E8 = 0; + } break; case 50: alpha = 0xFF - (gSaveContext.unk_13EC << 5); - if (alpha < 0) + if (alpha < 0) { alpha = 0; + } alpha1 = 0xFF - alpha; - if (alpha1 >= 0xFF) + if (alpha1 >= 0xFF) { alpha1 = 0xFF; + } osSyncPrintf("case 50 : alpha=%d alpha1=%d\n", alpha, alpha1); func_80082644(globalCtx, alpha1); - if (interfaceCtx->healthAlpha != 0xFF) + if (interfaceCtx->healthAlpha != 0xFF) { interfaceCtx->healthAlpha = alpha1; + } - if (interfaceCtx->magicAlpha != 0xFF) + if (interfaceCtx->magicAlpha != 0xFF) { interfaceCtx->magicAlpha = alpha1; + } switch (globalCtx->sceneNum) { case SCENE_SPOT00: @@ -4000,20 +4083,23 @@ void Interface_Update(GlobalContext* globalCtx) { case SCENE_SPOT18: case SCENE_SPOT20: case SCENE_GANON_TOU: - if (interfaceCtx->minimapAlpha < 0xAA) + if (interfaceCtx->minimapAlpha < 0xAA) { interfaceCtx->minimapAlpha = alpha1; - else + } else { interfaceCtx->minimapAlpha = 0xAA; + } break; default: - if (interfaceCtx->minimapAlpha != 0xFF) + if (interfaceCtx->minimapAlpha != 0xFF) { interfaceCtx->minimapAlpha = alpha1; + } break; } gSaveContext.unk_13EC++; - if (alpha1 == 0xFF) + if (alpha1 == 0xFF) { gSaveContext.unk_13E8 = 0; + } break; case 52: @@ -4030,8 +4116,9 @@ void Interface_Update(GlobalContext* globalCtx) { gSaveContext.health_accumulator -= 4; gSaveContext.health += 4; - if ((gSaveContext.health & 0xF) < 4) + if ((gSaveContext.health & 0xF) < 4) { Audio_PlaySoundGeneral(NA_SE_SY_HP_RECOVER, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } osSyncPrintf("now_life=%d max_life=%d\n", gSaveContext.health, gSaveContext.health_capacity); @@ -4079,8 +4166,9 @@ void Interface_Update(GlobalContext* globalCtx) { gSaveContext.rupee_accumulator += 10; gSaveContext.rupees -= 10; - if (gSaveContext.rupees < 0) + if (gSaveContext.rupees < 0) { gSaveContext.rupees = 0; + } Audio_PlaySoundGeneral(NA_SE_SY_RUPY_COUNT, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } else { @@ -4108,8 +4196,9 @@ void Interface_Update(GlobalContext* globalCtx) { interfaceCtx->unk_1EC = 0; interfaceCtx->unk_1EE = interfaceCtx->unk_1F0; action = interfaceCtx->unk_1EE; - if ((action == 0x1D) || (action == 0x1E)) + if ((action == 0x1D) || (action == 0x1E)) { action = 0xA; + } Interface_LoadActionLabel(interfaceCtx, action, 0); } break; @@ -4127,8 +4216,9 @@ void Interface_Update(GlobalContext* globalCtx) { interfaceCtx->unk_1EC = 0; interfaceCtx->unk_1EE = interfaceCtx->unk_1F0; action = interfaceCtx->unk_1EE; - if ((action == 0x1D) || (action == 0x1E)) + if ((action == 0x1D) || (action == 0x1E)) { action = 0xA; + } Interface_LoadActionLabel(interfaceCtx, action, 0); } break; @@ -4173,11 +4263,13 @@ void Interface_Update(GlobalContext* globalCtx) { interfaceCtx->unk_23C = 0; if (sHBAScoreTier == 0) { - if (gSaveContext.minigame_score >= 1000) + if (gSaveContext.minigame_score >= 1000) { sHBAScoreTier++; + } } else if (sHBAScoreTier == 1) { - if (gSaveContext.minigame_score >= 1500) + if (gSaveContext.minigame_score >= 1500) { sHBAScoreTier++; + } } sHBAScoreDigits[1] = 0; @@ -4202,14 +4294,16 @@ void Interface_Update(GlobalContext* globalCtx) { } if (gSaveContext.unk_1422 != 0) { - if ((msgCtx->unk_E3F0 != 0x31) && (gSaveContext.unk_1422 == 1)) + if ((msgCtx->unk_E3F0 != 0x31) && (gSaveContext.unk_1422 == 1)) { globalCtx->msgCtx.unk_E3EE = 4; + } if (globalCtx->unk_10A26 != 0) { if (gSaveContext.unk_1422 != 2) { D_80125B60 = 0; - if ((gSaveContext.day_time >= 0x4555) && (gSaveContext.day_time <= 0xC001)) + if ((gSaveContext.day_time >= 0x4555) && (gSaveContext.day_time <= 0xC001)) { D_80125B60 = 1; + } gSaveContext.unk_1422 = 2; D_80125B64 = D_8011FB40; diff --git a/src/code/z_path.c b/src/code/z_path.c new file mode 100644 index 000000000..03dc6d6f6 --- /dev/null +++ b/src/code/z_path.c @@ -0,0 +1,46 @@ +#include <ultra64.h> +#include <global.h> + +Path* Path_GetByIndex(GlobalContext* globalCtx, s16 index, s16 max) { + Path* path; + + if (index != max) { + path = &globalCtx->setupPathList[index]; + } else { + path = NULL; + } + + return path; +} + +f32 Path_OrientAndGetDistSq(Actor* actor, Path* path, s16 waypoint, s16* yaw) { + f32 dx; + f32 dz; + Vec3s* pointPos; + + if (path == NULL) { + return -1.0; + } + + pointPos = SEGMENTED_TO_VIRTUAL(path->points); + pointPos = &pointPos[waypoint]; + + dx = pointPos->x - actor->posRot.pos.x; + dz = pointPos->z - actor->posRot.pos.z; + + *yaw = Math_atan2f(dx, dz) * (32768 / M_PI); + + return SQ(dx) + SQ(dz); +} + +void Path_CopyLastPoint(Path* path, Vec3f* dest) { + Vec3s* pointPos; + + if (path != NULL) { + pointPos = &((Vec3s*)SEGMENTED_TO_VIRTUAL(path->points))[path->count - 1]; + + dest->x = pointPos->x; + dest->y = pointPos->y; + dest->z = pointPos->z; + } +} diff --git a/src/code/z_room.c b/src/code/z_room.c index f9973bfea..f74888438 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -85,7 +85,7 @@ typedef struct struct_80095D04 { // Room Draw Polygon Type 2 #ifdef NON_MATCHING -// this function still needs some work +// this function still needs some work but it should be functionally equivalent void func_80095D04(GlobalContext* globalCtx, Room* room, u32 flags) { PolygonType2* polygon2; PolygonDlist2* polygonDlist; @@ -129,8 +129,9 @@ void func_80095D04(GlobalContext* globalCtx, Room* room, u32 flags) { spA4 = &spB8[0]; polygonDlist = SEGMENTED_TO_VIRTUAL(room->mesh->polygon2.start); polygon2 = &room->mesh->polygon2; - if (polygon2->num > SHAPE_SORT_MAX) + if (polygon2->num > SHAPE_SORT_MAX) { __assert("polygon2->num <= SHAPE_SORT_MAX", "../z_room.c", 317); + } sp78 = polygonDlist; for (sp9C = 0; sp9C < polygon2->num; sp9C++) { @@ -152,8 +153,9 @@ void func_80095D04(GlobalContext* globalCtx, Room* room, u32 flags) { spA4->unk_08 = NULL; } else { do { - if (spA4->unk_04 < phi_v0->unk_04) + if (spA4->unk_04 < phi_v0->unk_04) { break; + } phi_v0 = phi_v0->unk_0C; } while (phi_v0 != NULL); @@ -165,10 +167,11 @@ void func_80095D04(GlobalContext* globalCtx, Room* room, u32 flags) { } else { phi_a0 = phi_v0->unk_08; spA4->unk_08 = phi_a0; - if (phi_a0 == NULL) + if (phi_a0 == NULL) { spB4 = spA4; - else + } else { phi_a0->unk_0C = spA4; + } phi_v0->unk_08 = spA4; spA4->unk_0C = (void*)phi_v0; } @@ -187,25 +190,30 @@ void func_80095D04(GlobalContext* globalCtx, Room* room, u32 flags) { if (iREG(86) != 0) { phi_v1 = 0; while (phi_v1 < polygon2->num) { - if (phi_s0 == sp78) + if (phi_s0 == sp78) { break; + } phi_v1++; sp78++; } if (((iREG(86) == 1) && (iREG(89) > sp9C)) || ((iREG(86) == 2) && (iREG(89) == sp9C))) { - if ((flags & 1) && (phi_s0->opa != NULL)) + if ((flags & 1) && (phi_s0->opa != NULL)) { gSPDisplayList(gfxCtx->polyOpa.p++, phi_s0->opa); + } - if ((flags & 2) && (phi_s0->xlu != NULL)) + if ((flags & 2) && (phi_s0->xlu != NULL)) { gSPDisplayList(gfxCtx->polyXlu.p++, phi_s0->xlu); + } } } else { - if ((flags & 1) && (phi_s0->opa != NULL)) + if ((flags & 1) && (phi_s0->opa != NULL)) { gSPDisplayList(gfxCtx->polyOpa.p++, phi_s0->opa); + } - if ((flags & 2) && (phi_s0->xlu != NULL)) + if ((flags & 2) && (phi_s0->xlu != NULL)) { gSPDisplayList(gfxCtx->polyXlu.p++, phi_s0->xlu); + } } spB4 = spB4->unk_0C; @@ -541,8 +549,9 @@ u32 func_80096FE8(GlobalContext* globalCtx, RoomContext* roomCtx) { for (i = 0; i < globalCtx->nbRooms; i++) { roomSize = roomList[i].vromEnd - roomList[i].vromStart; osSyncPrintf("ROOM%d size=%d\n", i, roomSize); - if (maxRoomSize < roomSize) + if (maxRoomSize < roomSize) { maxRoomSize = roomSize; + } } if (globalCtx->nbTransitionActors != 0) { @@ -559,8 +568,9 @@ u32 func_80096FE8(GlobalContext* globalCtx, RoomContext* roomCtx) { cumulRoomSize = (frontRoom != backRoom) ? frontRoomSize + backRoomSize : frontRoomSize; osSyncPrintf("DOOR%d=<%d> ROOM1=<%d, %d> ROOM2=<%d, %d>\n", j, cumulRoomSize, frontRoom, frontRoomSize, backRoom, backRoomSize); - if (maxRoomSize < cumulRoomSize) + if (maxRoomSize < cumulRoomSize) { maxRoomSize = cumulRoomSize; + } transitionActor++; } } @@ -578,10 +588,11 @@ u32 func_80096FE8(GlobalContext* globalCtx, RoomContext* roomCtx) { roomCtx->unk_30 = 0; roomCtx->status = 0; - if (gSaveContext.respawn_flag > 0) + if (gSaveContext.respawn_flag > 0) { nextRoomNum = gSaveContext.respawn[gSaveContext.respawn_flag - 1].room_index; - else + } else { nextRoomNum = globalCtx->setupEntranceList[globalCtx->curSpawn].room; + } func_8009728C(globalCtx, roomCtx, nextRoomNum); return maxRoomSize; diff --git a/src/code/z_sample.c b/src/code/z_sample.c index cbd934701..2f4f3fc6f 100644 --- a/src/code/z_sample.c +++ b/src/code/z_sample.c @@ -20,8 +20,8 @@ void Sample_Draw(SampleContext* this) { func_800C6AC4(gfxArr, gfxCtx, "../z_sample.c", 62); - gSPSegment(gfxCtx->polyOpa.p++, 0, NULL; - gSPSegment(gfxCtx->polyOpa.p++, 1, this->staticSegment); + gSPSegment(gfxCtx->polyOpa.p++, 0x00, NULL); + gSPSegment(gfxCtx->polyOpa.p++, 0x01, this->staticSegment); func_80095248(gfxCtx, 0, 0, 0); diff --git a/src/code/z_scene.c b/src/code/z_scene.c index c8c97459c..3a7121b04 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -280,7 +280,7 @@ void func_80098958(GlobalContext* globalCtx, SceneCmd* cmd) { // Scene Command 0x0B: Object List #ifdef NON_MATCHING -// this function still needs some work +// this function still needs some work but it should be functionally equivalent void func_8009899C(GlobalContext* globalCtx, SceneCmd* cmd) { s32 i, j, k; s16* objectEntry; @@ -312,13 +312,15 @@ void func_8009899C(GlobalContext* globalCtx, SceneCmd* cmd) { } } - if (cmd->objectList.num > OBJECT_EXCHANGE_BANK_MAX) + if (cmd->objectList.num > OBJECT_EXCHANGE_BANK_MAX) { __assert("scene_info->object_bank.num <= OBJECT_EXCHANGE_BANK_MAX", "../z_scene.c", 705); + } while (k < cmd->objectList.num) { nextPtr = func_800982FC(&globalCtx->objectCtx, i, *objectEntry); - if (i < OBJECT_EXCHANGE_BANK_MAX - 1) + if (i < OBJECT_EXCHANGE_BANK_MAX - 1) { globalCtx->objectCtx.status[i + 1].segment = nextPtr; + } k++; objectEntry++; status++; diff --git a/src/code/z_scene_table.c b/src/code/z_scene_table.c index 86d79168f..1bdfde9e3 100644 --- a/src/code/z_scene_table.c +++ b/src/code/z_scene_table.c @@ -2271,10 +2271,11 @@ void func_8009FE58(GlobalContext* globalCtx) { D_8012A398 += 0.15f + (globalCtx->unk_11D30[1] * 0.001f); } - if (globalCtx->roomCtx.curRoom.num == 2) + if (globalCtx->roomCtx.curRoom.num == 2) { Matrix_Scale(1, sinf(D_8012A398) * 0.8f, 1, MTXMODE_NEW); - else + } else { Matrix_Scale(1.005f, sinf(D_8012A398) * 0.8f, 1.005f, MTXMODE_NEW); + } gSPSegment(gfxCtx->polyOpa.p++, 0x0D, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_scene_table.c", 7809)); |
