diff --git a/asm/code_8008E6A0.s b/asm/code_8008E6A0.s deleted file mode 100644 index 163d9d8306..0000000000 --- a/asm/code_8008E6A0.s +++ /dev/null @@ -1,61 +0,0 @@ -.include "macro.inc" - -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches -.set gp=64 # allow use of 64-bit general purposee registers - -.section .text - -.align 4 - -glabel func_8008E6A0 -/* B05840 8008E6A0 AC800004 */ sw $zero, 4($a0) -/* B05844 8008E6A4 03E00008 */ jr $ra -/* B05848 8008E6A8 AC800000 */ sw $zero, ($a0) - -glabel func_8008E6AC -/* B0584C 8008E6AC 94AE0000 */ lhu $t6, ($a1) -/* B05850 8008E6B0 2403FFEF */ li $v1, -17 -/* B05854 8008E6B4 01C37827 */ nor $t7, $t6, $v1 -/* B05858 8008E6B8 55E0000A */ bnezl $t7, .L8008E6E4 -/* B0585C 8008E6BC 8C880000 */ lw $t0, ($a0) -/* B05860 8008E6C0 94B8000C */ lhu $t8, 0xc($a1) -/* B05864 8008E6C4 2401FBFF */ li $at, -1025 -/* B05868 8008E6C8 0301C827 */ nor $t9, $t8, $at -/* B0586C 8008E6CC 57200005 */ bnezl $t9, .L8008E6E4 -/* B05870 8008E6D0 8C880000 */ lw $t0, ($a0) -/* B05874 8008E6D4 8C820000 */ lw $v0, ($a0) -/* B05878 8008E6D8 2C420001 */ sltiu $v0, $v0, 1 -/* B0587C 8008E6DC AC820000 */ sw $v0, ($a0) -/* B05880 8008E6E0 8C880000 */ lw $t0, ($a0) -.L8008E6E4: -/* B05884 8008E6E4 51000013 */ beql $t0, $zero, .L8008E734 -/* B05888 8008E6E8 AC800004 */ sw $zero, 4($a0) -/* B0588C 8008E6EC 94A20000 */ lhu $v0, ($a1) -/* B05890 8008E6F0 2401DFFF */ li $at, -8193 -/* B05894 8008E6F4 00414827 */ nor $t1, $v0, $at -/* B05898 8008E6F8 55200011 */ bnezl $t1, .L8008E740 -/* B0589C 8008E6FC 00001025 */ move $v0, $zero -/* B058A0 8008E700 94AA000C */ lhu $t2, 0xc($a1) -/* B058A4 8008E704 00436027 */ nor $t4, $v0, $v1 -/* B058A8 8008E708 01435827 */ nor $t3, $t2, $v1 -/* B058AC 8008E70C 51600009 */ beql $t3, $zero, .L8008E734 -/* B058B0 8008E710 AC800004 */ sw $zero, 4($a0) -/* B058B4 8008E714 5580000A */ bnezl $t4, .L8008E740 -/* B058B8 8008E718 00001025 */ move $v0, $zero -/* B058BC 8008E71C 8C8D0004 */ lw $t5, 4($a0) -/* B058C0 8008E720 25AE0001 */ addiu $t6, $t5, 1 -/* B058C4 8008E724 29C10009 */ slti $at, $t6, 9 -/* B058C8 8008E728 14200004 */ bnez $at, .L8008E73C -/* B058CC 8008E72C AC8E0004 */ sw $t6, 4($a0) -/* B058D0 8008E730 AC800004 */ sw $zero, 4($a0) -.L8008E734: -/* B058D4 8008E734 03E00008 */ jr $ra -/* B058D8 8008E738 24020001 */ li $v0, 1 - -.L8008E73C: -/* B058DC 8008E73C 00001025 */ move $v0, $zero -.L8008E740: -/* B058E0 8008E740 03E00008 */ jr $ra -/* B058E4 8008E744 00000000 */ nop diff --git a/include/macros.h b/include/macros.h index 480a7de6a2..4eca922b68 100644 --- a/include/macros.h +++ b/include/macros.h @@ -77,4 +77,6 @@ viewport.topY = ty; \ viewport.leftX = lx; +#define CHECK_PAD(state, combo) (~(state.in.button | ~(combo)) == 0) + #endif diff --git a/include/z64.h b/include/z64.h index 6700ef24ed..4c26e7bdab 100644 --- a/include/z64.h +++ b/include/z64.h @@ -448,8 +448,8 @@ typedef struct { } SoundContext; // size = 0x4 typedef struct { - /* 0x00 */ s32 unk_0; - /* 0x04 */ char unk_4[0x4]; + /* 0x00 */ u32 toggle; + /* 0x04 */ s32 counter; } SubGlobalContext7B8; // size = 0x8 typedef struct { diff --git a/spec b/spec index 9494d334c3..3213132e13 100644 --- a/spec +++ b/spec @@ -343,7 +343,7 @@ beginseg include "build/data/z_map_data.data.o" include "build/src/code/z_parameter.o" include "build/src/code/z_path.o" - include "build/asm/code_8008E6A0.o" + include "build/src/code//code_8008E6A0.o" include "build/src/code/z_player_lib.o" include "build/data/z_player_lib.data.o" include "build/data/z_player_lib.bss.o" diff --git a/src/code/code_8008E6A0.c b/src/code/code_8008E6A0.c new file mode 100644 index 0000000000..6a1fe8c319 --- /dev/null +++ b/src/code/code_8008E6A0.c @@ -0,0 +1,38 @@ +#include + +void func_8008E6A0(SubGlobalContext7B8* this) { + this->counter = 0; + this->toggle = false; +} + +u32 func_8008E6AC(SubGlobalContext7B8* this, Input* input) { + if (CHECK_PAD(input->cur, R_TRIG) && CHECK_PAD(input->press, D_JPAD)) { + this->toggle = !this->toggle; + } + if (!this->toggle) { + goto ret_true; + } + + if (CHECK_PAD(input->cur, Z_TRIG)) { + + if (CHECK_PAD(input->press, R_TRIG)) { + goto ret_true; + } + + if (CHECK_PAD(input->cur, R_TRIG)) { + this->counter++; + if (this->counter >= 9) { + goto ret_true; + } + } + } + + goto ret_false; + +ret_true: + this->counter = 0; + return true; + +ret_false: + return false; +} diff --git a/src/code/fault.c b/src/code/fault.c index 7350ac1ac6..bc6e57dfed 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -583,7 +583,7 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { count--; Fault_Sleep(0x10); Fault_UpdatePadImpl(); - if (!~(curInput->press.in.button | ~L_TRIG)) { + if (CHECK_PAD(curInput->press, L_TRIG)) { sFaultStructPtr->faultActive = false; } } @@ -593,40 +593,40 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { Fault_UpdatePadImpl(); } while (curInput->press.in.button == 0); - if (!~(curInput->press.in.button | ~START_BUTTON)) { + if (CHECK_PAD(curInput->press, START_BUTTON)) { return; } - if (!~(curInput->cur.in.button | ~A_BUTTON)) { + if (CHECK_PAD(curInput->cur, A_BUTTON)) { return; } off = 0x10; - if (!~(curInput->cur.in.button | ~Z_TRIG)) { + if (CHECK_PAD(curInput->cur, Z_TRIG)) { off = 0x100; } - if (!~(curInput->cur.in.button | ~B_BUTTON)) { + if (CHECK_PAD(curInput->cur, B_BUTTON)) { off <<= 8; } - if (!~(curInput->cur.in.button | ~U_JPAD)) { + if (CHECK_PAD(curInput->cur, U_JPAD)) { addr -= off; } - if (!~(curInput->cur.in.button | ~D_JPAD)) { + if (CHECK_PAD(curInput->cur, D_JPAD)) { addr += off; } - if (!~(curInput->cur.in.button | ~U_CBUTTONS)) { + if (CHECK_PAD(curInput->cur, U_CBUTTONS)) { addr = pc; } - if (!~(curInput->cur.in.button | ~D_CBUTTONS)) { + if (CHECK_PAD(curInput->cur, D_CBUTTONS)) { addr = sp; } - if (!~(curInput->cur.in.button | ~L_CBUTTONS)) { + if (CHECK_PAD(curInput->cur, L_CBUTTONS)) { addr = unk0; } - if (!~(curInput->cur.in.button | ~R_CBUTTONS)) { + if (CHECK_PAD(curInput->cur, R_CBUTTONS)) { addr = unk1; } - if (!~(curInput->cur.in.button | ~L_TRIG)) { + if (CHECK_PAD(curInput->cur, L_TRIG)) { break; } } diff --git a/src/code/game.c b/src/code/game.c index 5a7c149855..7bbfb965a4 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -88,8 +88,8 @@ void func_800C4344(GameState* gameState) { HREG(89) = selectedInput->cur.in.x; HREG(90) = selectedInput->cur.in.y; HREG(93) = (selectedInput->cur.in.button == hReg82); - HREG(94) = (~(selectedInput->cur.in.button | ~hReg82) == 0); - HREG(95) = (~(selectedInput->press.in.button | ~hReg82) == 0); + HREG(94) = CHECK_PAD(selectedInput->cur, hReg82); + HREG(95) = CHECK_PAD(selectedInput->press, hReg82); } if (D_8012DBC0 != 0) { diff --git a/src/code/graph.c b/src/code/graph.c index b8c8605d6b..e8c5a6393a 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -386,8 +386,8 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) { } sGraphUpdateTime = time; - if (D_8012DBC0 && (!~(gameState->input[0].press.in.button | ~Z_TRIG)) && - (!~(gameState->input[0].cur.in.button | ~(L_TRIG | R_TRIG)))) { + if (D_8012DBC0 && CHECK_PAD(gameState->input[0].press, Z_TRIG) && + CHECK_PAD(gameState->input[0].cur, L_TRIG | R_TRIG)) { gSaveContext.gameMode = 0; SET_NEXT_GAMESTATE(gameState, func_80801E44, char[0x240]); // TODO : SelectContext gameState->running = false; diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 68366d27e3..fb5a9bd19d 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -1360,19 +1360,19 @@ s32 func_80058D34(Camera* camera) { if (D_8011D394 == 0) { if (camera->globalCtx->activeCamera == 0) { - if (~(D_8015BD7C->state.input[2].press.in.button | ~U_CBUTTONS) == 0) { + if (CHECK_PAD(D_8015BD7C->state.input[2].press, U_CBUTTONS)) { osSyncPrintf("attention sound URGENCY\n"); func_80078884(NA_SE_SY_ATTENTION_URGENCY); } - if (~(D_8015BD7C->state.input[2].press.in.button | ~D_CBUTTONS) == 0) { + if (CHECK_PAD(D_8015BD7C->state.input[2].press, D_CBUTTONS)) { osSyncPrintf("attention sound NORMAL\n"); func_80078884(NA_SE_SY_ATTENTION_ON); } - if (~(D_8015BD7C->state.input[2].press.in.button | ~R_CBUTTONS) == 0) { + if (CHECK_PAD(D_8015BD7C->state.input[2].press, R_CBUTTONS)) { phi_a2 = 1; } - if (~(D_8015BD7C->state.input[2].press.in.button | ~L_CBUTTONS) == 0) { + if (CHECK_PAD(D_8015BD7C->state.input[2].press, L_CBUTTONS)) { phi_a2 = -1; } if (phi_a2 != 0) { diff --git a/src/code/z_debug.c b/src/code/z_debug.c index fc663c3d25..bcb40d16e4 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -115,8 +115,7 @@ void func_8006390C(Input* input) { regGroup = (gGameInfo->regGroup * REG_PAGES + gGameInfo->regPage) * REG_PER_PAGE - REG_PER_PAGE; dpad = input->cur.in.button & (U_JPAD | L_JPAD | R_JPAD | D_JPAD); - if (!~(input->cur.in.button | ~L_TRIG) || !~(input->cur.in.button | ~R_TRIG) || - !~(input->cur.in.button | ~START_BUTTON)) { + if (CHECK_PAD(input->cur, L_TRIG) || CHECK_PAD(input->cur, R_TRIG) || CHECK_PAD(input->cur, START_BUTTON)) { input_combo = inputCombos; for (i = 0; i < REG_GROUPS; i++) { if (~(~input_combo->push | input->cur.in.button) || ~(~input_combo->held | input->press.in.button)) { @@ -157,16 +156,15 @@ void func_8006390C(Input* input) { increment = (dpad & R_JPAD) - ? (!~(input->cur.in.button | ~(A_BUTTON | B_BUTTON)) + ? (CHECK_PAD(input->cur, A_BUTTON | B_BUTTON) ? 1000 - : !~(input->cur.in.button | ~A_BUTTON) ? 100 - : !~(input->cur.in.button | ~B_BUTTON) ? 10 : 1) - : (dpad & L_JPAD) ? (!~(input->cur.in.button | ~(A_BUTTON | B_BUTTON)) - ? -1000 - : !~(input->cur.in.button | ~A_BUTTON) - ? -100 - : !~(input->cur.in.button | ~B_BUTTON) ? -10 : -1) - : 0; + : CHECK_PAD(input->cur, A_BUTTON) ? 100 : CHECK_PAD(input->cur, B_BUTTON) ? 10 : 1) + : (dpad & L_JPAD) + ? (CHECK_PAD(input->cur, A_BUTTON | B_BUTTON) + ? -1000 + : CHECK_PAD(input->cur, A_BUTTON) ? -100 + : CHECK_PAD(input->cur, B_BUTTON) ? -10 : -1) + : 0; gGameInfo->data[gGameInfo->regCur + regGroup] += increment; if (dpad & U_JPAD) { diff --git a/src/code/z_demo.c b/src/code/z_demo.c index e67cd51765..36b47ee591 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -99,13 +99,13 @@ void func_80064558(GlobalContext* globalCtx, CutsceneContext* csCtx) { void func_800645A0(GlobalContext* globalCtx, CutsceneContext* csCtx) { Input* pad1 = &globalCtx->state.input[0]; - if (!~(pad1->press.in.button | ~L_JPAD) && (csCtx->state == CS_STATE_IDLE) && (gSaveContext.sceneSetupIndex >= 4)) { + if (CHECK_PAD(pad1->press, L_JPAD) && (csCtx->state == CS_STATE_IDLE) && (gSaveContext.sceneSetupIndex >= 4)) { D_8015FCC8 = 0; gSaveContext.cutsceneIndex = 0xFFFD; gSaveContext.cutsceneTrigger = 1; } - if (!~(pad1->press.in.button | ~U_JPAD) && (csCtx->state == CS_STATE_IDLE) && (gSaveContext.sceneSetupIndex >= 4) && + if (CHECK_PAD(pad1->press, U_JPAD) && (csCtx->state == CS_STATE_IDLE) && (gSaveContext.sceneSetupIndex >= 4) && (D_8011D394 == 0)) { D_8015FCC8 = 1; gSaveContext.cutsceneIndex = 0xFFFD; @@ -443,16 +443,15 @@ void Cutscene_Command_Terminator(GlobalContext* globalCtx, CutsceneContext* csCt if ((gSaveContext.gameMode != 0) && (gSaveContext.gameMode != 3) && (globalCtx->sceneNum != SCENE_SPOT00) && (csCtx->frames > 20) && - (!~(globalCtx->state.input[0].press.in.button | ~A_BUTTON) || - !~(globalCtx->state.input[0].press.in.button | ~B_BUTTON) || - !~(globalCtx->state.input[0].press.in.button | ~START_BUTTON)) && + (CHECK_PAD(globalCtx->state.input[0].press, A_BUTTON) || CHECK_PAD(globalCtx->state.input[0].press, B_BUTTON) || + CHECK_PAD(globalCtx->state.input[0].press, START_BUTTON)) && (gSaveContext.fileNum != 0xFEDC) && (globalCtx->sceneLoadFlag == 0)) { Audio_PlaySoundGeneral(NA_SE_SY_PIECE_OF_HEART, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); temp = 1; } if ((csCtx->frames == cmd->startFrame) || (temp != 0) || - ((csCtx->frames > 20) && (!~(globalCtx->state.input[0].press.in.button | ~START_BUTTON)) && + ((csCtx->frames > 20) && CHECK_PAD(globalCtx->state.input[0].press, START_BUTTON) && (gSaveContext.fileNum != 0xFEDC))) { csCtx->state = CS_STATE_UNSKIPPABLE_EXEC; func_800F68BC(0); @@ -1524,7 +1523,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, return; } - if (!~(globalCtx->state.input[0].press.in.button | ~R_JPAD)) { + if (CHECK_PAD(globalCtx->state.input[0].press, R_JPAD)) { csCtx->state = CS_STATE_UNSKIPPABLE_INIT; return; } diff --git a/src/code/z_map_exp.c b/src/code/z_map_exp.c index 729542beac..aea0719ba0 100644 --- a/src/code/z_map_exp.c +++ b/src/code/z_map_exp.c @@ -413,7 +413,7 @@ void Minimap_Draw(GlobalContext* globalCtx) { } } - if (!~(globalCtx->state.input[0].press.in.button | ~L_TRIG) && !Gameplay_InCsMode(globalCtx)) { + if (CHECK_PAD(globalCtx->state.input[0].press, L_TRIG) && !Gameplay_InCsMode(globalCtx)) { osSyncPrintf("Game_play_demo_mode_check=%d\n", Gameplay_InCsMode(globalCtx)); // clang-format off if (!R_MINIMAP_TOGGLED) { Audio_PlaySoundGeneral(NA_SE_SY_CAMERA_ZOOM_UP, &D_801333D4, 4, @@ -494,7 +494,7 @@ void Minimap_Draw(GlobalContext* globalCtx) { Minimap_DrawCompassIcons(globalCtx); // Draw icons for the player spawn and current position } - if (!~(globalCtx->state.input[0].press.in.button | ~L_TRIG) && !Gameplay_InCsMode(globalCtx)) { + if (CHECK_PAD(globalCtx->state.input[0].press, L_TRIG) && !Gameplay_InCsMode(globalCtx)) { // clang-format off if (!R_MINIMAP_TOGGLED) { Audio_PlaySoundGeneral(NA_SE_SY_CAMERA_ZOOM_UP, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 5c32f70c29..ab88d7f023 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -3979,13 +3979,13 @@ void Interface_Update(GlobalContext* globalCtx) { u16 action; Input* input = &globalCtx->state.input[2]; - if (!~(input->press.in.button | ~L_JPAD)) { + if (CHECK_PAD(input->press, L_JPAD)) { gSaveContext.language = 0; osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language); - } else if (!~(input->press.in.button | ~U_JPAD)) { + } else if (CHECK_PAD(input->press, U_JPAD)) { gSaveContext.language = 1; osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language); - } else if (!~(input->press.in.button | ~R_JPAD)) { + } else if (CHECK_PAD(input->press, R_JPAD)) { gSaveContext.language = 2; osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language); } diff --git a/src/code/z_play.c b/src/code/z_play.c index 0c8bc8540f..2f1411a92d 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -924,7 +924,7 @@ void Gameplay_Update(GlobalContext* globalCtx) { } if (globalCtx->unk_1242B != 0) { - if (!~(input[0].press.in.button | ~8)) { + if (CHECK_PAD(input[0].press, U_CBUTTONS)) { if ((globalCtx->pauseCtx.state != 0) || (globalCtx->pauseCtx.flag != 0)) { // Translates to: "Changing viewpoint is prohibited due to the kaleidoscope" osSyncPrintf(VT_FGCOL(CYAN) "カレイドスコープ中につき視点変更を禁止しております\n" VT_RST); @@ -1823,7 +1823,7 @@ s32 func_800C0CB8(GlobalContext* globalCtx) { } s32 func_800C0D28(GlobalContext* globalCtx) { - return (globalCtx->sub_7B8.unk_0 != 0); + return (globalCtx->sub_7B8.toggle != 0); } s32 func_800C0D34(GlobalContext* globalCtx, Actor* actor, s16* yaw) { diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 862a10f333..677ae8a686 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -505,7 +505,8 @@ void func_800906D4(GlobalContext* globalCtx, Player* player, ColliderTrisItemDim Matrix_MultVec3f(&D_801260BC, &sp44); if (func_80090480(globalCtx, NULL, &player->swordDimensions, &trisInit->vtx[0], &sp2C) != 0 && (s32)(player->stateFlags1 << 9) >= 0) { - EffectBlure_AddVertex(Effect_GetByIndex(player->swordEffectId), &player->swordDimensions.tip, &player->swordDimensions.base); + EffectBlure_AddVertex(Effect_GetByIndex(player->swordEffectId), &player->swordDimensions.tip, + &player->swordDimensions.base); } if (player->swordState > 0 && ((player->swordAnimation < 0x18) || ((s32)(player->stateFlags2 << 0xE) < 0))) { func_80090480(globalCtx, &player->unk_4E4, &player->unk_8D0, &trisInit->vtx[1], &sp38); diff --git a/src/code/z_sample.c b/src/code/z_sample.c index 1ad2e6e28a..74e7639f2f 100644 --- a/src/code/z_sample.c +++ b/src/code/z_sample.c @@ -3,7 +3,7 @@ #include void Sample_HandleStateChange(SampleContext* this) { - if (!~(this->state.input[0].press.in.button | ~START_BUTTON)) { + if (CHECK_PAD(this->state.input[0].press, START_BUTTON)) { SET_NEXT_GAMESTATE(&this->state, Gameplay_Init, GlobalContext); this->state.running = false; }