diff options
| author | M4xw <m4x@m4xw.net> | 2022-03-22 02:51:23 +0100 |
|---|---|---|
| committer | M4xw <m4x@m4xw.net> | 2022-03-22 02:51:23 +0100 |
| commit | 39cc86c2608e2f75ace33fc7f43bc4f2ad743f1a (patch) | |
| tree | 0d3fd9e995d7484eaaeb158ac808bd6a39121189 /soh/src/code/padutils.c | |
| parent | 0bb0e7b53bd80bdc7f78e08c441691737e039b2b (diff) | |
git subrepo clone https://github.com/HarbourMasters/soh.git
subrepo:
subdir: "soh"
merged: "ba904bbd0"
upstream:
origin: "https://github.com/HarbourMasters/soh.git"
branch: "master"
commit: "ba904bbd0"
git-subrepo:
version: "0.4.1"
origin: "???"
commit: "???"
Diffstat (limited to 'soh/src/code/padutils.c')
| -rw-r--r-- | soh/src/code/padutils.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/soh/src/code/padutils.c b/soh/src/code/padutils.c new file mode 100644 index 000000000..6a58b14f6 --- /dev/null +++ b/soh/src/code/padutils.c @@ -0,0 +1,94 @@ +#include "global.h" + +#include <string.h> + +void PadUtils_Init(Input* input) { + memset(input,0, sizeof(Input)); +} + +void func_800FCB70(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 = PadUtils_GetCurX(input); + s32 curY = PadUtils_GetCurY(input); + s32 relX; + s32 relY; + + 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); +} |
