From 32d0e622fd958fb02086131ae58b1283518e7df3 Mon Sep 17 00:00:00 2001 From: Rozelette Date: Mon, 22 Mar 2021 11:03:33 -0500 Subject: [PATCH] padutils OK (#72) * padutils OK * Update to latest OOT --- include/functions.h | 34 +++---- include/io/controller.h | 44 +++------ include/macros.h | 9 +- include/z64.h | 16 +--- linker_scripts/code_script.txt | 2 +- src/boot_O2/padutils.c | 95 +++++++++++++++++++ src/boot_O2_g3_trapuv/fault.c | 48 +++++----- .../actors/ovl_Arms_Hook/z_arms_hook.c | 4 +- tables/functions.txt | 34 +++---- tables/objects.txt | 2 +- 10 files changed, 182 insertions(+), 106 deletions(-) create mode 100644 src/boot_O2/padutils.c diff --git a/include/functions.h b/include/functions.h index 3d9a0912ea..a4af2f236c 100644 --- a/include/functions.h +++ b/include/functions.h @@ -124,23 +124,23 @@ void* Load_AllocateAndLoad(u32 vRomStart, u32 vRomEnd, u32 vRamStart); void Load2_Relocate(u32 allocatedVRamAddr, OverlayRelocationSection* overlayInfo, u32 vRamStart); s32 Load2_LoadOverlay(u32 vRomStart, u32 vRomEnd, u32 vRamStart, u32 vRamEnd, u32 allocatedVRamAddr); void* Load2_AllocateAndLoad(u32 vRomStart, u32 vRomEnd, u32 vRamStart, u32 vRamEnd); -// void func_80085130(void); -// void func_80085150(void); -void func_80085158(s32 param_1); -u32 func_80085164(s16* param_1, s16 param_2); -u32 func_8008517C(u16* param_1, u16 param_2); -u32 func_80085198(s32 param_1, u16 param_2); -u32 func_800851B4(s32 param_1, u16 param_2); -u32 func_800851D0(u16* param_1); -u32 func_800851D8(s32 param_1); -// void func_800851E0(void); -// void func_800851E8(void); -// void func_800851F0(void); -// void func_800851FC(void); -// void func_80085204(void); -// void func_8008520C(void); -// void func_8008522C(void); -// void func_8008524C(void); +void PadUtils_Init(Input* input); +void func_80085150(void); +void PadUtils_ResetPressRel(Input* input); +u32 PadUtils_CheckCurExact(Input* input, u16 value); +u32 PadUtils_CheckCur(Input* input, u16 key); +u32 PadUtils_CheckPressed(Input* input, u16 key); +u32 PadUtils_CheckReleased(Input* input, u16 key); +u16 PadUtils_GetCurButton(Input* input); +u16 PadUtils_GetPressButton(Input* input); +s8 PadUtils_GetCurX(Input* input); +s8 PadUtils_GetCurY(Input* input); +void PadUtils_SetRelXY(Input* input, s32 x, s32 y); +s8 PadUtils_GetRelXImpl(Input* input); +s8 PadUtils_GetRelYImpl(Input* input); +s8 PadUtils_GetRelX(Input* input); +s8 PadUtils_GetRelY(Input* input); +void PadUtils_UpdateRelXY(Input* input); void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 initValue, s32 minSpace, const char* name); void StackCheck_Cleanup(StackEntry* entry); s32 StackCheck_GetState(StackEntry* entry); diff --git a/include/io/controller.h b/include/io/controller.h index 530ccb3978..6c99582cf9 100644 --- a/include/io/controller.h +++ b/include/io/controller.h @@ -3,35 +3,21 @@ #include -#define CONT_A 0x8000 -#define CONT_B 0x4000 -#define CONT_G 0x2000 -#define CONT_START 0x1000 -#define CONT_UP 0x0800 -#define CONT_DOWN 0x0400 -#define CONT_LEFT 0x0200 -#define CONT_RIGHT 0x0100 -#define CONT_L 0x0020 -#define CONT_R 0x0010 -#define CONT_E 0x0008 -#define CONT_D 0x0004 -#define CONT_C 0x0002 -#define CONT_F 0x0001 - -#define A_BUTTON CONT_A -#define B_BUTTON CONT_B -#define L_TRIG CONT_L -#define R_TRIG CONT_R -#define Z_TRIG CONT_G -#define START_BUTTON CONT_START -#define U_JPAD CONT_UP -#define L_JPAD CONT_LEFT -#define R_JPAD CONT_RIGHT -#define D_JPAD CONT_DOWN -#define U_CBUTTONS CONT_E -#define L_CBUTTONS CONT_C -#define R_CBUTTONS CONT_F -#define D_CBUTTONS CONT_D +/* Buttons */ +#define BTN_CRIGHT 0x0001 +#define BTN_CLEFT 0x0002 +#define BTN_CDOWN 0x0004 +#define BTN_CUP 0x0008 +#define BTN_R 0x0010 +#define BTN_L 0x0020 +#define BTN_DRIGHT 0x0100 +#define BTN_DLEFT 0x0200 +#define BTN_DDOWN 0x0400 +#define BTN_DUP 0x0800 +#define BTN_START 0x1000 +#define BTN_Z 0x2000 +#define BTN_B 0x4000 +#define BTN_A 0x8000 typedef struct { /* 0x00 */ u32 ramarray[15]; diff --git a/include/macros.h b/include/macros.h index 01f3c283f3..40125ecfd1 100644 --- a/include/macros.h +++ b/include/macros.h @@ -19,13 +19,16 @@ #define SET_NEXT_GAMESTATE(curState, newInit, newStruct) \ (curState)->nextGameStateInit = (GameStateFunc)newInit; \ - (curState)->nextGameStateSize = sizeof(newStruct); - + (curState)->nextGameStateSize = sizeof(newStruct); + #define PLAYER ((ActorPlayer*)globalCtx->actorCtx.actorList[ACTORCAT_PLAYER].first) #define SQ(x) ((x)*(x)) #define DECR(x) ((x) == 0 ? 0 : ((x) -= 1)) +#define CHECK_BTN_ALL(state, combo) (~((state) | ~(combo)) == 0) +#define CHECK_BTN_ANY(state, combo) (((state) & (combo)) != 0) + extern GraphicsContext* __gfxCtx; #define WORK_DISP __gfxCtx->work.p @@ -46,7 +49,7 @@ extern GraphicsContext* __gfxCtx; #define GRAPH_ALLOC(gfxCtx, size) \ ((gfxCtx)->polyOpa.d = (Gfx*)((u8*)(gfxCtx)->polyOpa.d - (size))) - + #define ALIGN8(val) (((val) + 7) & ~7) #define ALIGN16(val) (((val) + 0xF) & ~0xF) diff --git a/include/z64.h b/include/z64.h index 27001572bf..962e9544ce 100644 --- a/include/z64.h +++ b/include/z64.h @@ -283,14 +283,6 @@ typedef enum IRQ_TYPE { IRQ_PRENMI_4 = 0x2A1 } IRQ_TYPE; -typedef struct { - /* 0x0 */ u16 buttons; - /* 0x2 */ s8 xAxis; - /* 0x3 */ s8 yAxis; - /* 0x4 */ s8 status; - /* 0x5 */ UNK_TYPE1 pad5[0x1]; -} InputInfo; // size = 0x6 - typedef struct { /* 0x0 */ u32 vromStart; /* 0x4 */ u32 vromEnd; @@ -629,10 +621,10 @@ typedef struct { } GlobalContext1F78; // size = 0x1C typedef struct { - /* 0x00 */ InputInfo current; - /* 0x06 */ InputInfo last; - /* 0x0C */ InputInfo pressEdge; - /* 0x12 */ InputInfo releaseEdge; + /* 0x00 */ OSContPad cur; + /* 0x06 */ OSContPad prev; + /* 0x0C */ OSContPad press; // X/Y store delta from last frame + /* 0x12 */ OSContPad rel; // X/Y store adjusted } Input; // size = 0x18 typedef struct { diff --git a/linker_scripts/code_script.txt b/linker_scripts/code_script.txt index 58c6202175..df24a2b9a0 100644 --- a/linker_scripts/code_script.txt +++ b/linker_scripts/code_script.txt @@ -24,7 +24,7 @@ SECTIONS build/src/boot_O1/boot_0x80084940.o(.text) build/asm/boot/loadfragment.o(.text) build/src/boot_O2/loadfragment2.o(.text) - build/asm/boot/boot_0x80085130.o(.text) + build/src/boot_O2/padutils.o(.text) build/src/boot_O2/stackcheck.o(.text) build/asm/boot/boot_0x80085570.o(.text) build/asm/boot/mtxuty-cvt.o(.text) diff --git a/src/boot_O2/padutils.c b/src/boot_O2/padutils.c new file mode 100644 index 0000000000..ea51b3dc15 --- /dev/null +++ b/src/boot_O2/padutils.c @@ -0,0 +1,95 @@ +#include +#include + +void PadUtils_Init(Input* input) { + bzero(input, sizeof(Input)); +} + +void func_80085150(void) { +} + +void PadUtils_ResetPressRel(Input* input) { + input->press.button = 0; + input->rel.button = 0; +} + +u32 PadUtils_CheckCurExact(Input* input, u16 value) { + return value == input->cur.button; +} + +u32 PadUtils_CheckCur(Input* input, u16 key) { + return key == (input->cur.button & key); +} + +u32 PadUtils_CheckPressed(Input* input, u16 key) { + return key == (input->press.button & key); +} + +u32 PadUtils_CheckReleased(Input* input, u16 key) { + return key == (input->rel.button & key); +} + +u16 PadUtils_GetCurButton(Input* input) { + return input->cur.button; +} + +u16 PadUtils_GetPressButton(Input* input) { + return input->press.button; +} + +s8 PadUtils_GetCurX(Input* input) { + return input->cur.stick_x; +} + +s8 PadUtils_GetCurY(Input* input) { + return input->cur.stick_y; +} + +void PadUtils_SetRelXY(Input* input, s32 x, s32 y) { + input->rel.stick_x = x; + input->rel.stick_y = y; +} + +s8 PadUtils_GetRelXImpl(Input* input) { + return input->rel.stick_x; +} + +s8 PadUtils_GetRelYImpl(Input* input) { + return input->rel.stick_y; +} + +s8 PadUtils_GetRelX(Input* input) { + return PadUtils_GetRelXImpl(input); +} + +s8 PadUtils_GetRelY(Input* input) { + return PadUtils_GetRelYImpl(input); +} + +void PadUtils_UpdateRelXY(Input* input) { + s32 curX, curY; + s32 relX, relY; + + curX = PadUtils_GetCurX(input); + curY = PadUtils_GetCurY(input); + + if (curX > 7) { + relX = (curX < 0x43) ? curX - 7 : 0x43 - 7; + } else if (curX < -7) { + relX = (curX > -0x43) ? curX + 7 : -0x43 + 7; + } else { + relX = 0; + } + + if (curY > 7) { + relY = (curY < 0x43) ? curY - 7 : 0x43 - 7; + + } else if (curY < -7) { + relY = (curY > -0x43) ? curY + 7 : -0x43 + 7; + } else { + relY = 0; + } + + PadUtils_SetRelXY(input, relX, relY); +} + diff --git a/src/boot_O2_g3_trapuv/fault.c b/src/boot_O2_g3_trapuv/fault.c index 80bb0c5cd4..0c009a9dc1 100644 --- a/src/boot_O2_g3_trapuv/fault.c +++ b/src/boot_O2_g3_trapuv/fault.c @@ -203,8 +203,8 @@ s32 Fault_WaitForInputImpl() { while (1) { Fault_Sleep(0x10); Fault_UpdatePadImpl(); - kDown = curInput->pressEdge.buttons; - if (kDown == 0x20) { + kDown = curInput->press.button; + if (kDown == BTN_L) { faultCtxt->faultActive = !faultCtxt->faultActive; } @@ -217,16 +217,16 @@ s32 Fault_WaitForInputImpl() { } } - if (kDown == 0x8000 || kDown == 0x100) { + if (kDown == BTN_A || kDown == BTN_DRIGHT) { return 0; } - if (kDown == 0x200) { + if (kDown == BTN_DLEFT) { return 1; } - if (kDown == 0x800) { + if (kDown == BTN_DUP) { FaultDrawer_SetOsSyncPrintfEnabled(1); } - if (kDown == 0x400) { + if (kDown == BTN_DDOWN) { FaultDrawer_SetOsSyncPrintfEnabled(0); } } @@ -463,8 +463,8 @@ void Fault_WaitForButtonCombo(void) { do { Fault_Sleep(0x10); Fault_UpdatePadImpl(); - } while (~(input->pressEdge.buttons | ~0x80) != 0); - } while (~(input->current.buttons | ~0x231) != 0); + } while (!CHECK_BTN_ALL(input->press.button, 0x80)); + } while (!CHECK_BTN_ALL(input->cur.button, BTN_DLEFT | BTN_L | BTN_R | BTN_CRIGHT)); } void Fault_DrawMemDumpPage(char* title, u32* addr, u32 param_3) { @@ -530,46 +530,46 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { Fault_Sleep(0x10); Fault_UpdatePadImpl(); - if (~(input->pressEdge.buttons | ~0x20) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_L)) { faultCtxt->faultActive = 0; } } do { Fault_Sleep(0x10); Fault_UpdatePadImpl(); - } while (input->pressEdge.buttons == 0); + } while (input->press.button == 0); - if (~(input->pressEdge.buttons | ~0x1000) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_START)) == 0) { return; } off = 0x10; - if (~(input->current.buttons | ~0x8000) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_A)) { off = 0x100; } - if (~(input->current.buttons | ~0x4000) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_B)) { off <<= 8; } - if (~(input->pressEdge.buttons | ~0x800) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_DUP)) { addr -= off; } - if (~(input->pressEdge.buttons | ~0x400) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_DDOWN)) { addr += off; } - if (~(input->pressEdge.buttons | ~0x8) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_CUP)) { addr = pc; } - if (~(input->pressEdge.buttons | ~0x4) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_CDOWN)) { addr = sp; } - if (~(input->pressEdge.buttons | ~0x2) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_CLEFT)) { addr = unk0; } - if (~(input->pressEdge.buttons | ~0x1) == 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_CRIGHT)) { addr = unk1; } - } while (~(input->pressEdge.buttons | ~0x20) != 0); + } while (!CHECK_BTN_ALL(input->press.button, BTN_L)); faultCtxt->faultActive = 1; } @@ -764,7 +764,7 @@ void Fault_SetOptionsFromController3(void) { input3 = &faultCtxt->padInput[3]; - if (~(input3->pressEdge.buttons | ~0x80) == 0) { + if (CHECK_BTN_ALL(input3->press.button, 0x80)) { faultCustomOptions = faultCustomOptions == 0; } @@ -772,14 +772,14 @@ void Fault_SetOptionsFromController3(void) { graphPC = graphOSThread.context.pc; graphRA = graphOSThread.context.ra; graphSP = graphOSThread.context.sp; - if (~(input3->current.buttons | ~0x10) == 0) { + if (CHECK_BTN_ALL(input3->press.button, BTN_R)) { faultCopyToLog = !faultCopyToLog; FaultDrawer_SetOsSyncPrintfEnabled(faultCopyToLog); } - if (~(input3->current.buttons | ~0x8000) == 0) { + if (CHECK_BTN_ALL(input3->press.button, BTN_A)) { Fault_Log(D_80098A44, graphPC, graphRA, graphSP); } - if (~(input3->current.buttons | ~0x4000) == 0) { + if (CHECK_BTN_ALL(input3->press.button, BTN_B)) { FaultDrawer_SetDrawerFB(osViGetNextFramebuffer(), 0x140, 0xF0); Fault_DrawRec(0, 0xD7, 0x140, 9, 1); FaultDrawer_SetCharPad(-2, 0); diff --git a/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c b/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c index 27a3c902c9..8c382240ce 100644 --- a/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c +++ b/src/overlays/actors/ovl_Arms_Hook/z_arms_hook.c @@ -256,8 +256,8 @@ void ArmsHook_Shoot(ArmsHook* this, GlobalContext* globalCtx) { func_8019F1C0(&this->actor.projectedPos, 0x1813); } } else { - if ((globalCtx->state.input[0].pressEdge.buttons & - (A_BUTTON | B_BUTTON | R_TRIG | U_CBUTTONS | L_CBUTTONS | R_CBUTTONS | D_CBUTTONS))) { + if (CHECK_BTN_ANY(globalCtx->state.input[0].press.button, + BTN_A | BTN_B | BTN_R | BTN_CUP | BTN_CLEFT | BTN_CRIGHT | BTN_CDOWN)) { s32 pad; this->timer = 1; } diff --git a/tables/functions.txt b/tables/functions.txt index 98a7695d34..88f0332b74 100644 --- a/tables/functions.txt +++ b/tables/functions.txt @@ -114,23 +114,23 @@ 0x80084DB0:("Load2_Relocate",), 0x8008501C:("Load2_LoadOverlay",), 0x800850C8:("Load2_AllocateAndLoad",), - 0x80085130:("func_80085130",), - 0x80085150:("func_80085150",), - 0x80085158:("func_80085158",), - 0x80085164:("func_80085164",), - 0x8008517C:("func_8008517C",), - 0x80085198:("func_80085198",), - 0x800851B4:("func_800851B4",), - 0x800851D0:("func_800851D0",), - 0x800851D8:("func_800851D8",), - 0x800851E0:("func_800851E0",), - 0x800851E8:("func_800851E8",), - 0x800851F0:("func_800851F0",), - 0x800851FC:("func_800851FC",), - 0x80085204:("func_80085204",), - 0x8008520C:("func_8008520C",), - 0x8008522C:("func_8008522C",), - 0x8008524C:("func_8008524C",), + 0x80085130:("PadUtils_Init",), + 0x80085150:("func_800FCB70",), + 0x80085158:("PadUtils_ResetPressRel",), + 0x80085164:("PadUtils_CheckCurExact",), + 0x8008517C:("PadUtils_CheckCur",), + 0x80085198:("PadUtils_CheckPressed",), + 0x800851B4:("PadUtils_CheckReleased",), + 0x800851D0:("PadUtils_GetCurButton",), + 0x800851D8:("PadUtils_GetPressButton",), + 0x800851E0:("PadUtils_GetCurX",), + 0x800851E8:("PadUtils_GetCurY",), + 0x800851F0:("PadUtils_SetRelXY",), + 0x800851FC:("PadUtils_GetRelXImpl",), + 0x80085204:("PadUtils_GetRelYImpl",), + 0x8008520C:("PadUtils_GetRelX",), + 0x8008522C:("PadUtils_GetRelY",), + 0x8008524C:("PadUtils_UpdateRelXY",), 0x80085320:("StackCheck_Init",), 0x800853F8:("StackCheck_Cleanup",), 0x80085468:("StackCheck_GetState",), diff --git a/tables/objects.txt b/tables/objects.txt index d62038303f..a80b2ed57a 100644 --- a/tables/objects.txt +++ b/tables/objects.txt @@ -12,7 +12,7 @@ 0x80084940:"", 0x800849A0:"loadfragment", 0x80084DB0:"loadfragment2", - 0x80085130:"", + 0x80085130:"padutils", 0x80085320:"stackcheck", 0x80085570:"", 0x80086110:"mtxuty-cvt",