diff --git a/docs/game/controller-input.md b/docs/game/controller-input.md new file mode 100644 index 0000000000..151a6f1771 --- /dev/null +++ b/docs/game/controller-input.md @@ -0,0 +1,35 @@ +# Controller input + +`PadState` in `include/rnc/input/pad_state.h` describes the record at +`D_0013C940`. The boot producers are `poll_pad_device_state` (`FUN_002170c8`), +`clear_pad_input` (`FUN_002172c0`) and `process_pad_input` (`FUN_00217328`). + +| Offset | Field | Meaning | +|---|---|---| +| `0x100`, `0x140` | `analog`, `analog_prev` | Stick axes and pressure values, then their copy | +| `0x180`, `0x184` | `button_profile`, `vibration_profile` | SDK device profiles | +| `0x1A0`, `0x1A4`, `0x1A8` | `held`, `pressed`, `released` | Button masks including stick directions | +| `0x1B0`–`0x1BC` | `raw_*`, `prev_raw_held` | Button-only masks and previous poll | +| `0x1C0`–`0x1C8` | `*_unmasked` | Masks before mode filtering, with mirror swap undone | +| `0x1E0`, `0x258`, `0x2D0` | `pressed_history`, `angle_history`, `float_history` | Thirty-sample button, angle and magnitude rings | +| `0x348` | `saved_held` | Held mask before mode filtering, used by the next poll | +| `0x34D`–`0x34F` | `repeat_delay`, `repeat_rate`, `repeat_timer` | Button-repeat timing | + +`pad_held_words` (`D_0013CAE0`) and `pad_pressed_words` (`D_0013CAE4`) name the two +interior words separately because retail code addresses them directly. +The array declarations preserve the original address formation; the scalar +`pad_held_lui` and `pad_pressed_lui` aliases preserve explicit non-small-data access. +These two deliberate array/scalar declaration variants remain in the declaration audit. The controller record +also retains a `_lui` alias; pyrocitor uses the second name to preserve address +reconstruction between button tests. + +Signed and unsigned views are intentional. Some menu/debug/movie paths load +two button words together; their `PadStateWords` member views or explicit `u64`/PS2 `long` accesses +must not become two independent loads. The member views also preserve the +compiler's base-plus-field addressing where a scalar pointer cast does not. Pause-menu entry reads the unmasked pressed +word through a volatile signed view. The save-loading menu reads `raw_pressed`, +not `held`. + +These names and layouts follow the existing matching producer and consumer C. +Byte equality qualifies this cleanup; it does not establish native gameplay +or new PS2 runtime coverage. diff --git a/include/rnc/input.h b/include/rnc/input.h index 10b4147977..4abc6e786b 100644 --- a/include/rnc/input.h +++ b/include/rnc/input.h @@ -3,9 +3,11 @@ #include "types.h" -struct PAD; +struct PadState; -void poll_pad_device_state(struct PAD *) __asm__("FUN_002170c8"); +void poll_pad_device_state(struct PadState *) __asm__("FUN_002170c8"); +void clear_pad_input(struct PadState *) __asm__("func_002172C0"); +void process_pad_input(struct PadState *, u8 *, s32) __asm__("func_00217328"); void reset_pad_history(void) __asm__("func_00217020"); #endif /* LOMBYTE_RNC_INPUT_H */ diff --git a/include/rnc/input/pad_globals.h b/include/rnc/input/pad_globals.h index 020dbecaa0..d0a725824a 100644 --- a/include/rnc/input/pad_globals.h +++ b/include/rnc/input/pad_globals.h @@ -2,7 +2,15 @@ #define LOMBYTE_RNC_INPUT_PAD_GLOBALS_H #include "types.h" +#include "sda.h" -extern s32 pad_held[] __asm__("D_0013CAE0"); +/* Button words within controller_state, at offsets 0x1A0 and 0x1A4. */ +/* Array views preserve address formation in the original array consumers. */ +extern s32 pad_held_words[] __asm__("D_0013CAE0"); +extern s32 pad_held_words_lui[] __asm__("D_0013CAE0") NOT_SDA; +extern s32 pad_pressed_words[] __asm__("D_0013CAE4"); + +extern s32 pad_held_lui __asm__("D_0013CAE0") NOT_SDA; +extern s32 pad_pressed_lui __asm__("D_0013CAE4") NOT_SDA; #endif /* LOMBYTE_RNC_INPUT_PAD_GLOBALS_H */ diff --git a/include/rnc/input/pad_state.h b/include/rnc/input/pad_state.h index 7666b08666..cb267c1cd9 100644 --- a/include/rnc/input/pad_state.h +++ b/include/rnc/input/pad_state.h @@ -2,6 +2,7 @@ #define LOMBYTE_RNC_INPUT_PAD_STATE_H #include "types.h" +#include "sda.h" /* * Controller state D_0013C940, polled each frame by poll_pad_device_state @@ -33,9 +34,11 @@ struct PadState { u8 pad_0[0x100] __attribute__((aligned(16))); - f32 analog[16]; /* 0x100: [0..3] stick axes (-1..1), [4..15] pressure (0..1) */ - f32 analog_prev[16]; /* 0x140: copy of analog */ - u8 pad_180[0x9]; + f32 analog[16]; /* 0x100: [0..3] stick axes (-1..1), [4..15] pressure (0..1) */ + f32 analog_prev[16]; /* 0x140: copy of analog */ + u8 button_profile[4]; /* 0x180: scePad2GetButtonProfile */ + u8 vibration_profile[4]; /* 0x184: sceVibGetProfile */ + u8 unk188; u8 unk189; /* 0x189: copied by metal_detector_update on spawn */ u8 pad_18A[0x4]; s16 hist_idx; /* 0x18E: cleared with unk190 by reset_pad_history */ @@ -60,11 +63,17 @@ struct PadState { s32 stick_moved; /* 0x1D8: analog[2] or analog[3] nonzero */ s32 unk1DC; /* 0x1DC: 0x79 if the button profile is all ones, else 0; l01 picks pressure input on 0x79 */ u32 pressed_history[30]; /* 0x1E0: ring indexed by hist_idx, searched by pad_pressed_within */ - u8 pad_258[0x78]; - f32 float_history[30]; /* 0x2D0: ring indexed by hist_idx, read by read_pad_float_history */ + f32 angle_history[30]; /* 0x258: left-stick direction history */ + f32 float_history[30]; /* 0x2D0: ring indexed by hist_idx, read by read_pad_float_history */ + s32 saved_held; /* 0x348: held before mode masking, copied to prev_held on the next poll */ + u8 pad_34C; + u8 repeat_delay; /* 0x34D */ + u8 repeat_rate; /* 0x34E: zero disables button repeat */ + u8 repeat_timer; /* 0x34F */ }; extern struct PadState controller_state __asm__("D_0013C940"); +extern struct PadState controller_state_lui __asm__("D_0013C940") NOT_SDA; /* * The same pad state as some functions read it: the stick axes, and the held/pressed button words, @@ -82,7 +91,15 @@ struct PadStateWords { s32 pressed; /* 0x1A4 */ } w; } buttons; - char pad1A8[0x1D8 - 0x1A8]; + char pad1A8[0x1C0 - 0x1A8]; + union { + long held_pressed; /* PS2 long-width unmasked pair, used by the trespasser */ + struct { + s32 held; + s32 pressed; + } w; + } unmasked; + char pad1C8[0x1D8 - 0x1C8]; s32 stick_moved; /* 0x1D8: analog[2] or analog[3] nonzero */ }; diff --git a/include/rnc/overlay/shared/world/level_globals.h b/include/rnc/overlay/shared/world/level_globals.h index ad5850a63a..4a57dd301e 100644 --- a/include/rnc/overlay/shared/world/level_globals.h +++ b/include/rnc/overlay/shared/world/level_globals.h @@ -5,7 +5,6 @@ /* Shared overlay globals whose complete owning layouts are not recovered yet. */ -extern u32 D_0013CAE4 __attribute__((section(".data"))); extern s32 D_L10_0015F5C4_vendor __asm__("D_L10_0015F5C4"); extern char D_L12_00167240[]; extern char *D_L12_0015FFD8_p __asm__("D_L12_0015FFD8"); diff --git a/scripts/test_public_tools.py b/scripts/test_public_tools.py index 4fd527c2dd..5862f64e40 100755 --- a/scripts/test_public_tools.py +++ b/scripts/test_public_tools.py @@ -535,7 +535,7 @@ class DataDeclarationTests(unittest.TestCase): """No new data label may get a second type or name (scripts/data-decls.py).""" # Labels that still disagree; lower it when you fix some, never raise it. - KNOWN_CONFLICTS = 420 + KNOWN_CONFLICTS = 384 def test_no_new_conflicting_declarations(self): decls = load_module("rnc_data_decls", ROOT / "scripts" / "data-decls.py") diff --git a/src/check/pad_state_layout_check.c b/src/check/pad_state_layout_check.c index 1b48c6f417..55b5d73478 100644 --- a/src/check/pad_state_layout_check.c +++ b/src/check/pad_state_layout_check.c @@ -1,5 +1,4 @@ -/* Built only by `make layout-check-sys` (never linked). gcc 2.95 has no - _Static_assert: a negative array size fails the compile. */ +/* Compiled by make check with the EE compiler; never linked. */ #define OFFSET_CHECK(name, type, field, off) \ typedef char offset_check_##name[((unsigned long)&((type *)0)->field == (off)) ? 1 : -1] @@ -7,18 +6,44 @@ OFFSET_CHECK(analog, struct PadState, analog, 0x100); OFFSET_CHECK(analog_prev, struct PadState, analog_prev, 0x140); +OFFSET_CHECK(button_profile, struct PadState, button_profile, 0x180); +OFFSET_CHECK(vibration_profile, struct PadState, vibration_profile, 0x184); +OFFSET_CHECK(unk188, struct PadState, unk188, 0x188); +OFFSET_CHECK(unk189, struct PadState, unk189, 0x189); +OFFSET_CHECK(hist_idx, struct PadState, hist_idx, 0x18E); +OFFSET_CHECK(hist_count, struct PadState, hist_count, 0x190); OFFSET_CHECK(socket, struct PadState, socket, 0x194); +OFFSET_CHECK(profile_state, struct PadState, profile_state, 0x198); +OFFSET_CHECK(device_state, struct PadState, device_state, 0x19C); OFFSET_CHECK(held, struct PadState, held, 0x1A0); OFFSET_CHECK(pressed, struct PadState, pressed, 0x1A4); +OFFSET_CHECK(released, struct PadState, released, 0x1A8); +OFFSET_CHECK(prev_held, struct PadState, prev_held, 0x1AC); +OFFSET_CHECK(raw_held, struct PadState, raw_held, 0x1B0); OFFSET_CHECK(raw_pressed, struct PadState, raw_pressed, 0x1B4); -OFFSET_CHECK(profile_state, struct PadState, profile_state, 0x198); -OFFSET_CHECK(device_state, struct PadState, device_state, 0x19C); OFFSET_CHECK(raw_released, struct PadState, raw_released, 0x1B8); OFFSET_CHECK(prev_raw_held, struct PadState, prev_raw_held, 0x1BC); OFFSET_CHECK(held_unmasked, struct PadState, held_unmasked, 0x1C0); OFFSET_CHECK(pressed_unmasked, struct PadState, pressed_unmasked, 0x1C4); +OFFSET_CHECK(released_unmasked, struct PadState, released_unmasked, 0x1C8); OFFSET_CHECK(mode, struct PadState, mode, 0x1CC); +OFFSET_CHECK(no_buttons, struct PadState, no_buttons, 0x1D0); OFFSET_CHECK(no_direction, struct PadState, no_direction, 0x1D4); +OFFSET_CHECK(stick_moved, struct PadState, stick_moved, 0x1D8); OFFSET_CHECK(unk1DC, struct PadState, unk1DC, 0x1DC); OFFSET_CHECK(pressed_history, struct PadState, pressed_history, 0x1E0); +OFFSET_CHECK(angle_history, struct PadState, angle_history, 0x258); OFFSET_CHECK(float_history, struct PadState, float_history, 0x2D0); +OFFSET_CHECK(saved_held, struct PadState, saved_held, 0x348); +OFFSET_CHECK(repeat_delay, struct PadState, repeat_delay, 0x34D); +OFFSET_CHECK(repeat_rate, struct PadState, repeat_rate, 0x34E); +OFFSET_CHECK(repeat_timer, struct PadState, repeat_timer, 0x34F); + +typedef char pad_state_size_check[sizeof(struct PadState) == 0x350 ? 1 : -1]; + +OFFSET_CHECK(words_held_pressed, struct PadStateWords, buttons.held_pressed, 0x1A0); +OFFSET_CHECK(words_unmasked, struct PadStateWords, unmasked.held_pressed, 0x1C0); +OFFSET_CHECK(words_unmasked_pressed, struct PadStateWords, unmasked.w.pressed, 0x1C4); +OFFSET_CHECK(words_stick_moved, struct PadStateWords, stick_moved, 0x1D8); +typedef char pad_unmasked_pair_width_check + [sizeof(((struct PadStateWords *)0)->unmasked.held_pressed) == 8 ? 1 : -1]; diff --git a/src/input/clear_pad_input.c b/src/input/clear_pad_input.c index 0c07242487..68afa8853d 100644 --- a/src/input/clear_pad_input.c +++ b/src/input/clear_pad_input.c @@ -1,48 +1,30 @@ #include "types.h" - -struct PAD { - u8 pad_0[0x1A0]; - s32 unk1A0; - s32 unk1A4; - s32 unk1A8; - u8 pad_1AC[0x4]; - s32 unk1B0; - s32 unk1B4; - s32 unk1B8; - u8 pad_1BC[0x4]; - s32 unk1C0; - s32 unk1C4; - s32 unk1C8; - u8 pad_1CC[0x4]; - s32 unk1D0; - s32 unk1D4; - s32 unk1D8; -}; +#include "rnc/input/pad_state.h" struct WordCell { s32 unk0; }; -void clear_pad_input(struct PAD *pad_state) __asm__("FUN_002172c0"); +void clear_pad_input(struct PadState *pad_state) __asm__("FUN_002172c0"); -void clear_pad_input(struct PAD *pad_state) { +void clear_pad_input(struct PadState *pad_state) { s32 remaining; struct WordCell *slot; slot = ((u8 *)pad_state + (0x140)); remaining = 0xF; - pad_state->unk1A0 = 0; - pad_state->unk1A4 = 0; - pad_state->unk1A8 = 0; - pad_state->unk1D0 = 1; - pad_state->unk1B4 = 0; - pad_state->unk1B8 = 0; - pad_state->unk1C0 = 0; - pad_state->unk1C4 = 0; - pad_state->unk1C8 = 0; - pad_state->unk1D8 = 0; - pad_state->unk1D4 = 1; - pad_state->unk1B0 = 0; + pad_state->held = 0; + pad_state->pressed = 0; + pad_state->released = 0; + pad_state->no_buttons = 1; + pad_state->raw_pressed = 0; + pad_state->raw_released = 0; + pad_state->held_unmasked = 0; + pad_state->pressed_unmasked = 0; + pad_state->released_unmasked = 0; + pad_state->stick_moved = 0; + pad_state->no_direction = 1; + pad_state->raw_held = 0; do { *(s32 *)((u8 *)slot - 0x40) = 0; remaining -= 1; @@ -51,4 +33,4 @@ void clear_pad_input(struct PAD *pad_state) { } while (remaining >= 0); } -extern void func_002172C0(struct PAD *pad_state) __attribute__((alias("FUN_002172c0"))); \ No newline at end of file +extern void func_002172C0(struct PadState *pad_state) __attribute__((alias("FUN_002172c0"))); \ No newline at end of file diff --git a/src/input/poll_pad_device_state.c b/src/input/poll_pad_device_state.c index 6171bcfb0c..46f7070fe6 100644 --- a/src/input/poll_pad_device_state.c +++ b/src/input/poll_pad_device_state.c @@ -1,42 +1,12 @@ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/sdk/input.h" -struct PAD { - u8 pad0[0x180]; - u8 unk180[4]; - u8 unk184[4]; - u8 unk188; - u8 unk189; - u8 pad18A[0xA]; - s32 socket; - s32 unk198; - s32 unk19C; - s32 unk1A0; - s32 unk1A4; - s32 unk1A8; - s32 unk1AC; - s32 unk1B0; - u8 pad1B4[4]; - s32 unk1B8; - s32 unk1BC; - s32 unk1C0; - s32 unk1C4; - s32 unk1C8; - s32 unk1CC; - s32 unk1D0; - s32 unk1D4; - s32 unk1D8; - s32 unk1DC; - u8 pad1E0[0x168]; - s32 unk348; -}; +#include "rnc/input.h" -extern void clear_pad_input(struct PAD *p) __asm__("func_002172C0"); -extern void process_pad_input(struct PAD *p, u8 *buf, s32 len) __asm__("func_00217328"); +void poll_pad_device_state(struct PadState *p) __asm__("FUN_002170c8"); -void poll_pad_device_state(struct PAD *p) __asm__("FUN_002170c8"); - -void poll_pad_device_state(struct PAD *pad_state) { +void poll_pad_device_state(struct PadState *pad_state) { enum { PAD_PROFILE_INITIALIZATION = 0, PAD_INPUT_POLLING = 1, @@ -48,15 +18,15 @@ void poll_pad_device_state(struct PAD *pad_state) { s32 i; u8 pad_response_buffer[0x40]; - pad_state->unk1A0 = 0; - saved_pad_value = pad_state->unk1B0; - pad_state->unk1B0 = 0; - pad_state->unk1AC = pad_state->unk348; - pad_state->unk1BC = saved_pad_value; + pad_state->held = 0; + saved_pad_value = pad_state->raw_held; + pad_state->raw_held = 0; + pad_state->prev_held = pad_state->saved_held; + pad_state->prev_raw_held = saved_pad_value; pad_device_state = scePad2GetState(pad_state->socket); - pad_state->unk19C = pad_device_state; + pad_state->device_state = pad_device_state; if (pad_device_state == 1) { - switch (pad_state->unk198) { + switch (pad_state->profile_state) { case PAD_PROFILE_INITIALIZATION: { byte_count = scePad2GetButtonProfile(pad_state->socket, pad_response_buffer); if (*(u32 *)pad_response_buffer == 0xFFFFFFFF) { @@ -66,26 +36,26 @@ void poll_pad_device_state(struct PAD *pad_state) { } if (byte_count < 5) { for (i = 0; i < byte_count; i++) { - pad_state->unk180[i] = pad_response_buffer[i]; + pad_state->button_profile[i] = pad_response_buffer[i]; } - pad_state->unk198 = 1; + pad_state->profile_state = 1; } else { - pad_state->unk198 = 2; + pad_state->profile_state = 2; byte_count = 0; } for (i = byte_count; i < 4; i++) { - pad_state->unk180[i] = pad_response_buffer[i]; + pad_state->button_profile[i] = pad_response_buffer[i]; } byte_count = sceVibGetProfile(pad_state->socket, pad_response_buffer); if (byte_count < 5) { for (i = 0; i < byte_count; i++) { - pad_state->unk184[i] = pad_response_buffer[i]; + pad_state->vibration_profile[i] = pad_response_buffer[i]; } } else { byte_count = 0; } for (i = byte_count; i < 4; i++) { - pad_state->unk184[i] = pad_response_buffer[i]; + pad_state->vibration_profile[i] = pad_response_buffer[i]; } clear_pad_input(pad_state); break; @@ -100,7 +70,7 @@ void poll_pad_device_state(struct PAD *pad_state) { } } else { clear_pad_input(pad_state); - pad_state->unk198 = 0; + pad_state->profile_state = 0; } pad_state->unk188 = 0; pad_state->unk189 = 0; diff --git a/src/input/process_pad_input.c b/src/input/process_pad_input.c index 93d26b0bf6..c6ee4c6ad8 100644 --- a/src/input/process_pad_input.c +++ b/src/input/process_pad_input.c @@ -1,41 +1,8 @@ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/math/fast_math.h" #include "rnc/math/asm_helpers.h" -typedef struct Pad { - u8 pad0[0x100]; - float axes[16]; /* 0x100 */ - float prev[16]; /* 0x140 */ - u8 pad180[0xE]; - s16 idx; /* 0x18E */ - s32 count; /* 0x190 */ - u8 pad194[0xC]; - s32 held; /* 0x1A0 */ - s32 pressed; /* 0x1A4 */ - s32 released; /* 0x1A8 */ - s32 old; /* 0x1AC */ - s32 raw; /* 0x1B0 */ - s32 x1B4; /* 0x1B4 */ - s32 x1B8; /* 0x1B8 */ - s32 x1BC; /* 0x1BC */ - s32 x1C0; /* 0x1C0 */ - s32 x1C4; /* 0x1C4 */ - s32 x1C8; /* 0x1C8 */ - s32 mode; /* 0x1CC */ - s32 none; /* 0x1D0 */ - s32 nodir; /* 0x1D4 */ - s32 moving; /* 0x1D8 */ - u8 pad1DC[4]; - s32 hist_btn[30]; /* 0x1E0 */ - float hist_ang[30]; /* 0x258 */ - float hist_mag[30]; /* 0x2D0 */ - s32 x348; /* 0x348 */ - u8 pad34C; - u8 rep_delay; /* 0x34D */ - u8 rep_rate; /* 0x34E */ - u8 rep_timer; /* 0x34F */ -} Pad; - extern volatile u8 D_0015EDB4; extern float fast_difference_between_rotations(float, float) __asm__("func_001FA688"); @@ -46,17 +13,17 @@ extern float fast_difference_between_rotations(float, float) __asm__("func (x) = ((x) & ~0x2000) | 0x8000; \ } -void process_pad_input(Pad *p, u8 *buf, s32 len) __asm__("FUN_00217328"); +void process_pad_input(struct PadState *p, u8 *buf, s32 len) __asm__("FUN_00217328"); -void process_pad_input(Pad *pad_state, u8 *pad_read_data, s32 pad_read_byte_count) { +void process_pad_input(struct PadState *pad_state, u8 *pad_read_data, s32 pad_read_byte_count) { float axis_vector[2]; s32 i, j, k; s32 held_buttons, old, ncur, nold; float mag, axis_vector_angle; - pad_state->raw = pad_state->held = ((pad_read_data[0] << 8) | pad_read_data[1]) ^ 0xFFFF; + pad_state->raw_held = pad_state->held = ((pad_read_data[0] << 8) | pad_read_data[1]) ^ 0xFFFF; for (i = 15; i >= 0; i--) { - pad_state->axes[i] = 0; + pad_state->analog[i] = 0; } if (pad_read_byte_count >= 6) { for (i = 0; i < 4; i++) { @@ -67,91 +34,93 @@ void process_pad_input(Pad *pad_state, u8 *pad_read_data, s32 pad_read_byte_coun float scaled_axis_magnitude = convert_integer_to_float(axis_center_distance - 0x30) / convert_integer_to_float(0x4C); - pad_state->axes[i] = scaled_axis_magnitude; + pad_state->analog[i] = scaled_axis_magnitude; if (scaled_axis_magnitude > 1.0f) { - pad_state->axes[i] = 1.0f; + pad_state->analog[i] = 1.0f; } if (pad_read_data[i + 2] < 0x7F) { - pad_state->axes[i] = -pad_state->axes[i]; + pad_state->analog[i] = -pad_state->analog[i]; } } } } if (pad_read_byte_count >= 0x12) { for (i = 4; i < 16; i++) { - pad_state->axes[i] = convert_integer_to_float(pad_read_data[i + 2]) * 0.003921569f; + pad_state->analog[i] = convert_integer_to_float(pad_read_data[i + 2]) * 0.003921569f; } } if (D_0015EDB4) { - pad_state->axes[2] = -pad_state->axes[2]; - pad_state->axes[0] = -pad_state->axes[0]; + pad_state->analog[2] = -pad_state->analog[2]; + pad_state->analog[0] = -pad_state->analog[0]; SWAPLR(pad_state->held); - pad_state->raw = pad_state->held; + pad_state->raw_held = pad_state->held; } { - float *axis_copy_destination = pad_state->prev, *axis_copy_source = pad_state->axes; + float *axis_copy_destination = pad_state->analog_prev, + *axis_copy_source = pad_state->analog; for (i = 15; i >= 0; i--) { *axis_copy_destination++ = *axis_copy_source++; } } - if (((volatile float *)pad_state->axes)[2] != 0.0f || - ((volatile float *)pad_state->axes)[3] != 0.0f) { - pad_state->moving = 1; + if (((volatile float *)pad_state->analog)[2] != 0.0f || + ((volatile float *)pad_state->analog)[3] != 0.0f) { + pad_state->stick_moved = 1; } else { - pad_state->moving = 0; + pad_state->stick_moved = 0; } - if (pad_state->axes[2] < 0.0f) + if (pad_state->analog[2] < 0.0f) pad_state->held |= 0x8000; - if (pad_state->axes[2] > 0.0f) + if (pad_state->analog[2] > 0.0f) pad_state->held |= 0x2000; - if (pad_state->axes[3] < 0.0f) + if (pad_state->analog[3] < 0.0f) pad_state->held |= 0x1000; - if (pad_state->axes[3] > 0.0f) + if (pad_state->analog[3] > 0.0f) pad_state->held |= 0x4000; - pad_state->nodir = (pad_state->held & 0xF000) == 0; - pad_state->none = pad_state->held == 0; - pad_state->pressed = ~pad_state->old & pad_state->held; - pad_state->x1B4 = ~pad_state->old & pad_state->raw; - pad_state->released = ~pad_state->held & pad_state->old; - pad_state->x1B8 = ~pad_state->held & pad_state->x1BC; - pad_state->x1C4 = pad_state->pressed; - pad_state->x1C8 = pad_state->released; - pad_state->x1C0 = pad_state->held; - pad_state->x348 = pad_state->held; + pad_state->no_direction = (pad_state->held & 0xF000) == 0; + pad_state->no_buttons = pad_state->held == 0; + pad_state->pressed = ~pad_state->prev_held & pad_state->held; + pad_state->raw_pressed = ~pad_state->prev_held & pad_state->raw_held; + pad_state->released = ~pad_state->held & pad_state->prev_held; + pad_state->raw_released = ~pad_state->held & pad_state->prev_raw_held; + (*(s32 *)&pad_state->pressed_unmasked) = pad_state->pressed; + (*(s32 *)&pad_state->released_unmasked) = pad_state->released; + (*(s32 *)&pad_state->held_unmasked) = pad_state->held; + pad_state->saved_held = pad_state->held; if (D_0015EDB4) { - pad_state->prev[2] = -pad_state->prev[2]; - pad_state->prev[0] = -pad_state->prev[0]; - SWAPLR(pad_state->x1C0); - SWAPLR(pad_state->x1C4); - SWAPLR(pad_state->x1C8); + pad_state->analog_prev[2] = -pad_state->analog_prev[2]; + pad_state->analog_prev[0] = -pad_state->analog_prev[0]; + SWAPLR((*(s32 *)&pad_state->held_unmasked)); + SWAPLR((*(s32 *)&pad_state->pressed_unmasked)); + SWAPLR((*(s32 *)&pad_state->released_unmasked)); } if (pad_state->mode == 1) { pad_state->held = *(volatile s32 *)&pad_state->held & ~0x5030; pad_state->pressed &= ~0x5030; pad_state->released &= ~0x5030; - pad_state->axes[0] = 0.0f; - pad_state->axes[1] = 0.0f; + pad_state->analog[0] = 0.0f; + pad_state->analog[1] = 0.0f; pad_state->mode = 0; } if (pad_state->mode == 2) { pad_state->held = *(volatile s32 *)&pad_state->held & 0x900; pad_state->pressed &= 0x900; pad_state->released &= 0x900; - pad_state->raw = *(volatile s32 *)&pad_state->raw & 0x900; - pad_state->nodir = 1; - pad_state->axes[2] = 0.0f; - pad_state->axes[3] = 0.0f; + pad_state->raw_held = *(volatile s32 *)&pad_state->raw_held & 0x900; + pad_state->no_direction = 1; + pad_state->analog[2] = 0.0f; + pad_state->analog[3] = 0.0f; pad_state->mode = 0; } - axis_vector[0] = pad_state->axes[2]; - axis_vector[1] = pad_state->axes[3]; + axis_vector[0] = pad_state->analog[2]; + axis_vector[1] = pad_state->analog[3]; mag = vector_length_xy(axis_vector); axis_vector_angle = fast_arc_tan(axis_vector[0], axis_vector[1]); - pad_state->hist_mag[pad_state->idx] = mag; - pad_state->hist_ang[pad_state->idx] = axis_vector_angle; + pad_state->float_history[pad_state->hist_idx] = mag; + pad_state->angle_history[pad_state->hist_idx] = axis_vector_angle; if (mag > 0.9f) { for (j = 1; j < scale_game_frames(4); j++) { - float historical_magnitude = pad_state->hist_mag[(pad_state->idx - j + 30) % 30]; + float historical_magnitude = + pad_state->float_history[(pad_state->hist_idx - j + 30) % 30]; if (historical_magnitude > 0.9f) break; if (historical_magnitude < 0.25f) { @@ -162,29 +131,29 @@ void process_pad_input(Pad *pad_state, u8 *pad_read_data, s32 pad_read_byte_coun if (!(pad_state->pressed & 0x10000)) { for (k = 1; k < scale_game_frames(5); k++) { if (fast_difference_between_rotations( - pad_state->hist_ang[(pad_state->idx - k + 30) % 30], axis_vector_angle) > - 0.9599311f) { + pad_state->angle_history[(pad_state->hist_idx - k + 30) % 30], + axis_vector_angle) > 0.9599311f) { pad_state->pressed |= 0x10000; break; } } } } - pad_state->hist_btn[pad_state->idx] = pad_state->pressed; - pad_state->idx = (pad_state->idx + 1) % 30; - if (++pad_state->count > 30) { - pad_state->count = 30; + pad_state->pressed_history[pad_state->hist_idx] = pad_state->pressed; + pad_state->hist_idx = (pad_state->hist_idx + 1) % 30; + if (++pad_state->hist_count > 30) { + pad_state->hist_count = 30; } - if (pad_state->rep_rate) { + if (pad_state->repeat_rate) { held_buttons = pad_state->held; - if (held_buttons != 0 && held_buttons == pad_state->old) { - u8 repeat_timer_value = --pad_state->rep_timer; + if (held_buttons != 0 && held_buttons == pad_state->prev_held) { + u8 repeat_timer_value = --pad_state->repeat_timer; if (0 == repeat_timer_value || repeat_timer_value == 0xFF) { - pad_state->rep_timer = pad_state->rep_rate; + pad_state->repeat_timer = pad_state->repeat_rate; pad_state->pressed = held_buttons; } } else { - pad_state->rep_timer = pad_state->rep_delay; + pad_state->repeat_timer = pad_state->repeat_delay; } } } diff --git a/src/movies/decoder/read_mpeg.c b/src/movies/decoder/read_mpeg.c index cd0e191cca..dfc8217ff7 100644 --- a/src/movies/decoder/read_mpeg.c +++ b/src/movies/decoder/read_mpeg.c @@ -13,8 +13,7 @@ #include "rnc/sdk/graph.h" #include "rnc/sdk/mpeg/api.h" -extern struct PadStateWords pad_words __asm__("D_0013C940"); -extern s32 D_0015EEA0; +extern s32 D_0015EEA0; /* Movie skip mode (decode_mode): -1 no skipping, 2 any new button. Read through a volatile view because retail loads it once for the -1 and 2 tests and then again inside the skip-allowed test, with no store or call @@ -34,12 +33,12 @@ extern s32 video_dec_flush(struct VideoDec *) __asm__("func_0023CD08"); /* Each pad test takes the pad by pointer, so retail forms the pad address afresh for every test from one shared upper half. */ -static inline s32 pad_pressed(struct PadStateWords *pad, s32 mask) { - return pad->buttons.w.pressed & mask; +static inline s32 pad_pressed(struct PadState *pad, s32 mask) { + return pad->pressed & mask; } -static inline s32 pad_chord(struct PadStateWords *pad, u64 mask) { - if ((pad->buttons.held_pressed & mask) != mask) { +static inline s32 pad_chord(struct PadState *pad, u64 mask) { + if (((*(u64 *)&pad->held) & mask) != mask) { return 0; } return 1; @@ -83,13 +82,13 @@ s32 read_mpeg(struct VideoDec *video_dec, update_primary_pad_state(); mode = DECODE_MODE; if (mode != -1) { - if ((mode == 2 && pad_pressed(&pad_words, -1)) || + if ((mode == 2 && pad_pressed(&controller_state, -1)) || ((D_0015EEA0 != 0 || alternate_animation_sequence != 0 || DECODE_MODE != 0 || current_level_index <= 0) && - pad_pressed(&pad_words, 0x800))) { + pad_pressed(&controller_state, 0x800))) { skip = 1; } else { - skip = pad_chord(&pad_words, 0x8000000000FULL); + skip = pad_chord(&controller_state, 0x8000000000FULL); } if (skip) { skipped = 1; diff --git a/src/overlays/l03/hero/update_hero_motion_for_current_state.c b/src/overlays/l03/hero/update_hero_motion_for_current_state.c index 846276b5e8..165641f969 100644 --- a/src/overlays/l03/hero/update_hero_motion_for_current_state.c +++ b/src/overlays/l03/hero/update_hero_motion_for_current_state.c @@ -11,6 +11,7 @@ #include "rnc/math/vector.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/world/level_labels.h" #include "rnc/math/asm_helpers.h" #include "rnc/math/random.h" @@ -138,24 +139,6 @@ struct MobyView { Vec4 vC0; }; #define MV(p) ((struct MobyView *)(p)) -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - unsigned long d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; struct PlayerJointTable { u8 pad0[0x60]; @@ -220,8 +203,8 @@ extern void correct_hero_airborne_wall_velocity(void) __asm__("FUN_L00_002121c0" extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L03_0017A780; #define AN D_L03_0017A780 struct VoiceSlot { @@ -585,19 +568,20 @@ void update_hero_motion_for_current_state(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; swim_pitch_easing_coefficient = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -609,15 +593,15 @@ void update_hero_motion_for_current_state(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -633,9 +617,9 @@ void update_hero_motion_for_current_state(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 use_seconds; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -655,7 +639,7 @@ void update_hero_motion_for_current_state(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (D_L03_0015F5CC - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -664,7 +648,7 @@ void update_hero_motion_for_current_state(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -686,7 +670,7 @@ void update_hero_motion_for_current_state(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -695,7 +679,7 @@ void update_hero_motion_for_current_state(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -709,7 +693,7 @@ void update_hero_motion_for_current_state(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero.puff_timer) != 0) { @@ -899,7 +883,7 @@ void update_hero_motion_for_current_state(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -907,7 +891,7 @@ void update_hero_motion_for_current_state(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -2055,13 +2039,13 @@ void update_hero_motion_for_current_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L03_00166ED8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/l03/mobys/rail_lift.c b/src/overlays/l03/mobys/rail_lift.c index 42815a2300..a3fe3c6694 100644 --- a/src/overlays/l03/mobys/rail_lift.c +++ b/src/overlays/l03/mobys/rail_lift.c @@ -1,4 +1,5 @@ /* Level 03 moby class rail_lift (0x3f4): carries the hero between the ends of two rail paths, with its help message and hud. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/overlay/shared/world/level_path.h" #include "rnc/mobys/moby.h" @@ -156,7 +157,7 @@ void rail_lift_update(struct Moby *lift_moby) { } else if (lift_vars->ready && is_hero_on_moby(lift_moby)) { update_rail_lift_help_and_hud((char *)lift_moby, lift_vars->help[lift_moby->command ^ 1]); - if ((D_0013CAE4 & 0x10) && D_L03_0015F594 == 8) { + if ((((u32)pad_pressed_lui) & 0x10) && D_L03_0015F594 == 8) { request_hero_target_pose(&lift_moby->pos, lift_moby->rot.z, 0); lift_moby->command ^= 1; lift_vars->unk64 = 1; diff --git a/src/overlays/l03/mobys/taxi.c b/src/overlays/l03/mobys/taxi.c index 74a7e213e2..1ba6184e1e 100644 --- a/src/overlays/l03/mobys/taxi.c +++ b/src/overlays/l03/mobys/taxi.c @@ -1,4 +1,5 @@ /* Level 03 moby class taxi (0x330): the rail taxi that carries Ratchet along its routes, its rail path flight and its bobbing. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/overlay/shared/world/level_path.h" #include "rnc/globals.h" @@ -217,7 +218,7 @@ void rail_taxi_update(struct Moby *taxi_moby) { frame_time * 12.566371f); if (hero.ground_moby == taxi_moby && hero.air_frames.s == 0) { request_taxi_return_help_message(taxi_moby, taxi_vars->help[taxi_moby->command]); - if ((D_0013CAE4 & 0x10) && D_L03_0015F594 == 8) { + if ((((u32)pad_pressed_lui) & 0x10) && D_L03_0015F594 == 8) { request_hero_target_pose(&taxi_moby->pos, taxi_moby->rot.z, 0); taxi_moby->state = 4; taxi_vars->idx = 1; diff --git a/src/overlays/l05/hero/update_hero_motion_by_state.c b/src/overlays/l05/hero/update_hero_motion_by_state.c index 722732fd9a..a0fdd16a37 100644 --- a/src/overlays/l05/hero/update_hero_motion_by_state.c +++ b/src/overlays/l05/hero/update_hero_motion_by_state.c @@ -12,6 +12,7 @@ #include "rnc/overlay/shared/hero/hero_tables.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/math/fast_math.h" #include "rnc/math/asm_helpers.h" #include "rnc/math/random.h" @@ -73,25 +74,6 @@ struct MobyView { Vec4 vC0; }; -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - unsigned long d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - struct PlayerJointTable { u8 pad0[0x60]; f32 f60; @@ -171,8 +153,8 @@ extern void compute_hero_reference_tilt_rotation(void *, void *, f32, f32, f32, extern void rotate_hero_about_local_pivot(void *, f32, f32, f32) __asm__("FUN_L00_002090d0"); extern void update_hero_hoverboard_race_progress(void) __asm__("FUN_L05_00254608"); extern Vec4 l05_hoverboard_trick_rotation_pivots[] __asm__("D_L05_00179BE0"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L05_0017AAE0; #define AN D_L05_0017AAE0 struct VoiceSlot { @@ -546,19 +528,20 @@ void update_hero_motion_by_state(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; swim_pitch_response_coefficient = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -570,15 +553,15 @@ void update_hero_motion_by_state(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -594,9 +577,9 @@ void update_hero_motion_by_state(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 use_seconds; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -616,7 +599,7 @@ void update_hero_motion_by_state(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (frame_number - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -625,7 +608,7 @@ void update_hero_motion_by_state(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -647,7 +630,7 @@ void update_hero_motion_by_state(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -656,7 +639,7 @@ void update_hero_motion_by_state(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -670,7 +653,7 @@ void update_hero_motion_by_state(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero.puff_timer) != 0) { @@ -858,7 +841,7 @@ void update_hero_motion_by_state(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -866,7 +849,7 @@ void update_hero_motion_by_state(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -951,8 +934,8 @@ void update_hero_motion_by_state(void) { hero.voice_slot6 = -1; } } - hero.trick_input = hero.board_jump_frames && (PD.u1A0.i1A0 & 0xF); - if ((((PD.u1A0.i1A0 & 0x80) || hero.boost_min_frames != 0) && hero.boost_frames != 0) || + hero.trick_input = hero.board_jump_frames && (PD.held & 0xF); + if ((((PD.held & 0x80) || hero.boost_min_frames != 0) && hero.boost_frames != 0) || hero.boost_pad_timer != 0) { fast_dec_timer_s16(&hero.boost_min_frames); if (hero.board_boost_active == 0) { @@ -2656,13 +2639,13 @@ void update_hero_motion_by_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L05_001671D8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/l05/mobys/taxi.c b/src/overlays/l05/mobys/taxi.c index 3903b7ba2a..dfbe3f8cab 100644 --- a/src/overlays/l05/mobys/taxi.c +++ b/src/overlays/l05/mobys/taxi.c @@ -1,4 +1,5 @@ /* Level 05 moby class taxi: picks a route and moves between its stops. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero.h" #include "rnc/globals.h" @@ -23,7 +24,6 @@ extern float fast_add_rotations(float, float); extern float fast_subtract_rotations(float, float); /* Same source as the exact taxi_update, with its moby data 8 bytes further on, an x range on the pickup test and a table test for state 6. */ -extern char D_0013CAE4[]; void initialize_taxi_stop_state(void *moby_v) __asm__("FUN_L05_00319208"); extern void select_taxi_route(struct Moby *) __asm__("FUN_L05_003193a8"); extern void sample_camera_path(int *path, @@ -105,7 +105,7 @@ void taxi_update(struct Moby *moby) { hero_offset[0] > -0.75f) { select_taxi_route(moby); request_moby_variant_help_message(moby); - if (*(int *)(D_0013CAE4) & 0x10) { + if (pad_pressed_words[0] & 0x10) { moby->state = 3; destination_stop_moby = find_moby_in_owner_list_by_id(moby, taxi_data->unkB6); if (destination_stop_moby != 0) { diff --git a/src/overlays/l06/hero/update_hero_motion_for_current_state.c b/src/overlays/l06/hero/update_hero_motion_for_current_state.c index 94edf6d7bc..4909a1e3c2 100644 --- a/src/overlays/l06/hero/update_hero_motion_for_current_state.c +++ b/src/overlays/l06/hero/update_hero_motion_for_current_state.c @@ -14,6 +14,7 @@ #include "rnc/overlay/shared/hero/hero_tables.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "sda.h" #include "rnc/math/asm_helpers.h" #include "rnc/math/random.h" @@ -816,25 +817,6 @@ struct MobyView { Vec4 vC0; }; -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - u64 d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - struct PlayerJointTable { u8 pad0[0x60]; f32 f60; @@ -905,8 +887,8 @@ extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 allocate_voice_for_target_entry(s32, s32, struct MobyView *) __asm__("FUN_0022da68"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L06_0017AE00; #define AN D_L06_0017AE00 struct VoiceSlot { @@ -2597,13 +2579,13 @@ void update_hero_motion_for_current_state(void) { m = sp; } FUN_L00_002118c8_c(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, D_0015ED6C_c * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L06_00167558; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, D_0015ED6C_c * 4.712389f); diff --git a/src/overlays/l06/mobys/alien_queen.c b/src/overlays/l06/mobys/alien_queen.c index e16419bfb3..d620094604 100644 --- a/src/overlays/l06/mobys/alien_queen.c +++ b/src/overlays/l06/mobys/alien_queen.c @@ -1,4 +1,5 @@ /* Level 06 moby class 0x41b: alien queen. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/mobys/moby.h" #include "rnc/hero/hero.h" @@ -168,7 +169,6 @@ extern void FUN_L06_002fb148_recovery_high(char *) __asm__("FUN_ extern void FUN_L06_002fb148_recovery_low(char *) __asm__("FUN_L06_002fb8c8"); extern short D_L06_0014162A NOT_SDA; extern int D_L06_00140408 NOT_SDA; -extern int D_0013CAE0 NOT_SDA; extern int D_L06_001413D0 NOT_SDA; #include "rnc/overlay/l06/mobys/alien_queen_data/update_alien_queen_hit_response_and_recovery.h" @@ -884,7 +884,7 @@ void update_alien_queen_hit_response_and_recovery(char *moby) { moby[0x20] = 14; return; } - if ((unsigned char)moby[0x20] >= 2 && D_L06_00140408 != 8 && (D_0013CAE0 & 0x20)) + if ((unsigned char)moby[0x20] >= 2 && D_L06_00140408 != 8 && (pad_held_lui & 0x20)) alien_queen_hit_recovery_vars->unk178 = 1; timer = alien_queen_hit_recovery_vars->timer_12C; if (timer != 0 && alien_queen_hit_recovery_vars->unk170 != 0) { diff --git a/src/overlays/l06/mobys/elevator.c b/src/overlays/l06/mobys/elevator.c index 6544428218..013326ff29 100644 --- a/src/overlays/l06/mobys/elevator.c +++ b/src/overlays/l06/mobys/elevator.c @@ -1,4 +1,5 @@ /* Level 06 moby class 0x425: elevator; carries the hero between two heights and switches the states of its linked mobys. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/mobys/moby.h" #include "asm.h" @@ -142,7 +143,6 @@ void set_moby_and_links_to_states_2_and_3(char *a) __asm__("FUN_ extern unsigned char D_0013D5DD_2FDA70[] __asm__("D_0013D4C6"); extern unsigned char D_0013D4AF_2FDA70[] __asm__("D_0013D3A8"); extern unsigned char D_0013D5CA_2FDA70[] __asm__("D_0013D4C6"); -extern char D_0013A5E0_2FDA70[] __asm__("D_0013CAE4"); void elevator_update(Moby_2FDA70 *moby) __asm__("FUN_L06_002fc640"); void set_moby_and_links_to_states_2_and_3(char *moby) { @@ -253,7 +253,7 @@ void elevator_update(Moby_2FDA70 *moby) { } else { ok = try_set_help_message(9, 0x1789) != 0; } - if ((*(int *)D_0013A5E0_2FDA70 & 0x10) && ((Hero_2FDA70 *)(D_0013F350))->f2084 != 100 && + if ((pad_pressed_words[0] & 0x10) && ((Hero_2FDA70 *)(D_0013F350))->f2084 != 100 && ok) { ((Hero_2FDA70 *)(D_0013F350))->f1F2 = scale_game_frames(0x3C); moby_data->f90 = scale_game_frames(0x78); diff --git a/src/overlays/l08/hero/update_hero_motion_for_current_state.c b/src/overlays/l08/hero/update_hero_motion_for_current_state.c index 839821bc3a..1493d8da10 100644 --- a/src/overlays/l08/hero/update_hero_motion_for_current_state.c +++ b/src/overlays/l08/hero/update_hero_motion_for_current_state.c @@ -10,6 +10,7 @@ #include "rnc/overlay/shared/hero/hero_tables.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/world/level_labels.h" #include "rnc/math/asm_helpers.h" #include "rnc/math/random.h" @@ -197,25 +198,6 @@ struct MobyView { /* Second name for hero: one call needs it to keep the original address CSE. */ extern struct Hero hero_b __asm__("D_0013F350"); -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - u64 d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - struct PlayerJointTable { u8 pad0[0x60]; f32 f60; @@ -282,8 +264,8 @@ extern void correct_hero_airborne_wall_velocity(void) __asm__("FUN_L00_002121c0" extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L08_0017AE80; #define AN D_L08_0017AE80 struct VoiceSlot { @@ -649,19 +631,20 @@ void update_hero_motion_for_current_state(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; swim_pitch_easing_factor = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -673,15 +656,15 @@ void update_hero_motion_for_current_state(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -697,9 +680,9 @@ void update_hero_motion_for_current_state(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 use_seconds; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -719,7 +702,7 @@ void update_hero_motion_for_current_state(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (D_L08_0015F5CC - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -728,7 +711,7 @@ void update_hero_motion_for_current_state(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -750,7 +733,7 @@ void update_hero_motion_for_current_state(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -759,7 +742,7 @@ void update_hero_motion_for_current_state(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -773,7 +756,7 @@ void update_hero_motion_for_current_state(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero.puff_timer) != 0) { @@ -966,7 +949,7 @@ void update_hero_motion_for_current_state(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -974,7 +957,7 @@ void update_hero_motion_for_current_state(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -2486,13 +2469,13 @@ void update_hero_motion_for_current_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L08_001675D8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/l08/mobys/batalia_cannon.c b/src/overlays/l08/mobys/batalia_cannon.c index bbc288cca9..64cf4a06c3 100644 --- a/src/overlays/l08/mobys/batalia_cannon.c +++ b/src/overlays/l08/mobys/batalia_cannon.c @@ -264,7 +264,6 @@ float batalia_cannon_yaw_deceleration_gp __asm__("D_L08_00161AF8") = 3.6e float batalia_cannon_pitch_deceleration_gp __asm__("D_L08_00161AFC") = 7.2e+02f; float batalia_cannon_rocket_speed_gp __asm__("D_L08_00161B00") = 1.8e+02f; extern s32 D_0015ED84; -extern char D_0013A5E0_2E16A0[] __asm__("D_0013CAE4"); extern int D_0015ED84; extern short batalia_cannon_dismount_offset_gp __asm__("D_L08_00161A90") __attribute__((sda)); extern short batalia_cannon_left_gun_offset_gp __asm__("D_L08_00161B10") __attribute__((sda)); @@ -767,7 +766,7 @@ void batalia_cannon_update(Moby *moby) { } if (visited52[moby->mission + D_0015ED84 * 16] != 0xFF && (hero.ship_flags & 1)) hero_respawn(); - if (((*(int *)D_0013A5E0_2E16A0 & 0x10) || + if (((pad_pressed_words[0] & 0x10) || (*(unsigned char *)(l08_cannon_hero_interaction_flags) & 1)) && visited52[moby->mission + D_0015ED84 * 16] == 0xFF) { hero.ship_flags = 0; @@ -894,7 +893,7 @@ void batalia_cannon_update(Moby *moby) { } else if (cannon_control_vars->lock_timer) cannon_control_vars->lock_timer--; fast_dec_timer_s16(&cannon_control_vars->fire_timer); - if ((pad_held[0] & 0x20) && cannon_control_vars->fire_timer == 0) { + if ((pad_held_words[0] & 0x20) && cannon_control_vars->fire_timer == 0) { if (cannon_control_vars->barrel == 1) { int count; build_spherical_offset(direction, diff --git a/src/overlays/l08/mobys/shuttle.c b/src/overlays/l08/mobys/shuttle.c index 1f79a59855..f6d49939cc 100644 --- a/src/overlays/l08/mobys/shuttle.c +++ b/src/overlays/l08/mobys/shuttle.c @@ -1,4 +1,5 @@ /* Level 08 moby class 0x1a8: shuttle. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero.h" #include "rnc/globals.h" @@ -56,7 +57,6 @@ extern s32 D_L08_0015F594 __attribute__((sda)); extern LiftLock l08_shuttle_departure_lock __asm__("D_L08_00179C10"); -extern s32 D_0013CAE4[]; extern void build_quaternion_from_axis_rotations(void *, void *) __asm__("FUN_L00_00259f50"); extern void resolve_point_path_segment_xy_clearance(s32, float, void *, void *) __asm__("FUN_L00_00261d78"); @@ -140,7 +140,8 @@ void shuttle_update(struct Moby *moby) { shuttle_vars->stop, 0.5f, &hero_position_probe, &hero_position_probe); if (fast_vec_dist(&hero.motion.pos, &hero_position_probe) < 0.001f) { try_set_shuttle_departure_help_message((char *)moby); - if ((D_0013CAE4[0] & 0x10) && hero.air_frames.s == 0 && D_L08_0015F594 == 10) + if ((pad_pressed_words[0] & 0x10) && hero.air_frames.s == 0 && + D_L08_0015F594 == 10) moby->state = 3; } } diff --git a/src/overlays/l09/mobys/turret.c b/src/overlays/l09/mobys/turret.c index 8c717dd58d..c3d6cffa64 100644 --- a/src/overlays/l09/mobys/turret.c +++ b/src/overlays/l09/mobys/turret.c @@ -1,4 +1,5 @@ /* Level 09 moby class 0x4b1: turret. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/game/options.h" #include "rnc/hero/hero.h" @@ -124,7 +125,7 @@ void turret_update(struct Moby *moby) { offset.f[2] = 0.0f; fast_vec_add(&hero.motion.pos, &hero.motion.pos, &offset); fast_mem_zero16(&hero.motion.velocity, 0x90); - if (D_0013CAE4 & 0x10) { + if (((u32)pad_pressed_lui) & 0x10) { jet_end_mount(0); hero_set_state(0, 1); moby->command = 2; diff --git a/src/overlays/l10/mobys/nanotech_upgrade_vendor.c b/src/overlays/l10/mobys/nanotech_upgrade_vendor.c index 5cf08a9a8f..e8cce8b313 100644 --- a/src/overlays/l10/mobys/nanotech_upgrade_vendor.c +++ b/src/overlays/l10/mobys/nanotech_upgrade_vendor.c @@ -1,4 +1,5 @@ /* Level 10 moby class nanotech_upgrade_vendor: sells the two health upgrades. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/overlay/shared/world/level_globals.h" @@ -53,7 +54,7 @@ void nanotech_upgrade_vendor_update(struct Moby *moby) { if (alternate_item_available[4] == 0) { if (current_bolt_count >= 4001) { int accepted = try_set_help_message(1, 0x271e) != 0; - if (!(D_0013CAE4 & 0x10)) + if (!(((u32)pad_pressed_lui) & 0x10)) return; if (accepted == 0) return; @@ -73,7 +74,7 @@ void nanotech_upgrade_vendor_update(struct Moby *moby) { return; if (current_bolt_count >= 30001) { int accepted = try_set_help_message(1, 0x271f) != 0; - if (!(D_0013CAE4 & 0x10)) + if (!(((u32)pad_pressed_lui) & 0x10)) return; if (accepted == 0) return; diff --git a/src/overlays/l11/hero/update_hero_motion_by_state.c b/src/overlays/l11/hero/update_hero_motion_by_state.c index 658cea833a..d69a98d8a0 100644 --- a/src/overlays/l11/hero/update_hero_motion_by_state.c +++ b/src/overlays/l11/hero/update_hero_motion_by_state.c @@ -10,6 +10,7 @@ #include "rnc/overlay/shared/hero/hero_tables.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/math/asm_helpers.h" #include "rnc/math/random.h" #include "rnc/mobys/moby_spawn.h" @@ -179,24 +180,6 @@ struct MobyView { Vec4 vC0; }; #define MV(p) ((struct MobyView *)(p)) -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - unsigned long d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; struct PlayerJointTable { u8 pad0[0x60]; @@ -265,8 +248,8 @@ extern void correct_hero_airborne_wall_velocity(void) __asm__("FUN_L00_002121c0" extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L11_0017B080; #define AN D_L11_0017B080 struct VoiceSlot { @@ -634,19 +617,20 @@ void update_hero_motion_by_state(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; swim_pitch_smoothing_factor = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -658,15 +642,15 @@ void update_hero_motion_by_state(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -682,9 +666,9 @@ void update_hero_motion_by_state(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 use_seconds; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -704,7 +688,7 @@ void update_hero_motion_by_state(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (level_frame - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -713,7 +697,7 @@ void update_hero_motion_by_state(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -735,7 +719,7 @@ void update_hero_motion_by_state(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -744,7 +728,7 @@ void update_hero_motion_by_state(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -758,7 +742,7 @@ void update_hero_motion_by_state(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero.puff_timer) != 0) { @@ -951,7 +935,7 @@ void update_hero_motion_by_state(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -959,7 +943,7 @@ void update_hero_motion_by_state(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -1959,13 +1943,13 @@ void update_hero_motion_by_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L11_001677D8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/l11/mobys/child_sets_controller.c b/src/overlays/l11/mobys/child_sets_controller.c index 3ac0d10474..d47330641f 100644 --- a/src/overlays/l11/mobys/child_sets_controller.c +++ b/src/overlays/l11/mobys/child_sets_controller.c @@ -1,4 +1,5 @@ /* Level 11 moby class child_sets_controller: spawns and poses its child moby sets. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero.h" #include "rnc/globals.h" @@ -244,7 +245,7 @@ void child_sets_controller_update(struct Moby *child_sets_controller) { frame_time + frame_time); } update_child_set_poses(child_sets_controller); - if (alternate_item_available[0x56] != 0 && D_0013CAE4 != 0) { + if (alternate_item_available[0x56] != 0 && ((u32)pad_pressed_lui) != 0) { child_sets_controller->command = 1; } if (D_L11_00161ED8 < 1.0f && child_sets_controller->command == 0) { diff --git a/src/overlays/l11/mobys/jet_fighter.c b/src/overlays/l11/mobys/jet_fighter.c index 4b66a80e60..767554bc3d 100644 --- a/src/overlays/l11/mobys/jet_fighter.c +++ b/src/overlays/l11/mobys/jet_fighter.c @@ -1,4 +1,5 @@ /* Level 11 moby class jet_fighter: the player ship on Pokitaru, its flight, shots, lock-on and HUD. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/audio/voice_pool.h" #include "rnc/hero/hero.h" @@ -1367,7 +1368,7 @@ void jet_fighter_update(struct Moby *moby) { help_records[0x3C].latest_time_bucket = scale_game_frames(D_0015EEA4) / 600; } } - if (item_available[7] != 0 && (D_0013CAE4 & 0x10)) { + if (item_available[7] != 0 && (((u32)pad_pressed_lui) & 0x10)) { moby->state = 2; ship_vars->i118 = -1; } diff --git a/src/overlays/l11/mobys/teleporter.c b/src/overlays/l11/mobys/teleporter.c index 7845336ea6..7a71543b50 100644 --- a/src/overlays/l11/mobys/teleporter.c +++ b/src/overlays/l11/mobys/teleporter.c @@ -1,4 +1,5 @@ /* Level 11 moby class teleporter: the three-part switch, its help message and ring. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero.h" @@ -17,7 +18,6 @@ #include "rnc/game/game_globals.h" extern float D_0013F3D8_lui __asm__("D_0013F3D8") NOT_SDA; /* hero z */ -extern int D_0013CAE4_lui __asm__("D_0013CAE4") NOT_SDA; extern int D_L11_0015F594 __asm__("D_L11_0015F594"); extern char *D_L11_0015FFD8_2518 __asm__("D_L11_0015FFD8"); extern unsigned char D_001413F5_lui __asm__("D_001413F5") NOT_SDA; @@ -121,7 +121,7 @@ void teleporter_update(struct Moby *moby) { if (g->air_frames.s != 0) break; FUN_L11_002f2cd0_2518(moby); - if (!(D_0013CAE4_lui & 0x10)) + if (!(pad_pressed_lui & 0x10)) break; if (D_L11_0015F594 != 0xB) break; diff --git a/src/overlays/l12/hero/update_hero_motion_for_current_state.c b/src/overlays/l12/hero/update_hero_motion_for_current_state.c index 084c09790a..a35baf4dc3 100644 --- a/src/overlays/l12/hero/update_hero_motion_for_current_state.c +++ b/src/overlays/l12/hero/update_hero_motion_for_current_state.c @@ -2,6 +2,7 @@ #include "types.h" #include "rnc/overlay/shared/camera/level_camera.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/audio/voice_pool.h" #include "rnc/hero/hero_state.h" #include "rnc/globals.h" @@ -453,25 +454,6 @@ struct MobyView { /* Second name for hero: one call needs it to keep the original address CSE. */ extern struct Hero hero_b __asm__("D_0013F350"); -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - unsigned long d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - struct PlayerJointTable { u8 pad0[0x60]; f32 f60; @@ -544,8 +526,8 @@ extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 allocate_voice_for_target_entry(s32, s32, struct MobyView *) __asm__("FUN_0022da68"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L12_0017AB00; #define AN D_L12_0017AB00 struct VoiceSlot { @@ -924,19 +906,20 @@ void update_hero_motion_for_current_state(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; swim_pitch_smoothing_coefficient = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -948,15 +931,15 @@ void update_hero_motion_for_current_state(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -972,9 +955,9 @@ void update_hero_motion_for_current_state(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 use_seconds; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -994,7 +977,7 @@ void update_hero_motion_for_current_state(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (D_L12_0015F5CC - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -1003,7 +986,7 @@ void update_hero_motion_for_current_state(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -1025,7 +1008,7 @@ void update_hero_motion_for_current_state(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -1034,7 +1017,7 @@ void update_hero_motion_for_current_state(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -1048,7 +1031,7 @@ void update_hero_motion_for_current_state(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero.puff_timer) != 0) { @@ -1241,7 +1224,7 @@ void update_hero_motion_for_current_state(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -1249,7 +1232,7 @@ void update_hero_motion_for_current_state(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -1793,7 +1776,7 @@ void update_hero_motion_for_current_state(void) { if (test_hero_animation_frame_window(84.0f) != 0) { f32 a = fast_add_rotations(hero.motion.rot.f[2], 3.1415927f); f32 s = frame_time * 2.5f; - if (pad_held[0] & 0xA) { + if (pad_held_words[0] & 0xA) { s = frame_time * 3.0f; } hero.motion.velocity.f[0] += fast_cos(a) * s; @@ -2397,13 +2380,13 @@ void update_hero_motion_for_current_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L12_00167258; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/l12/mobys/help_hints.c b/src/overlays/l12/mobys/help_hints.c index ffc95103e1..6f0c84f769 100644 --- a/src/overlays/l12/mobys/help_hints.c +++ b/src/overlays/l12/mobys/help_hints.c @@ -61,7 +61,7 @@ void help_hints_update(struct Moby *moby) { struct Hero *q = &hero; if (q->state.current == 0x81) { moby_vars[1]++; - if ((pad_held[0] & 3) && 0.3f < q->stick_magnitude) { + if ((pad_held_words[0] & 3) && 0.3f < q->stick_magnitude) { moby_vars[2]++; } else { moby_vars[2] = 0; diff --git a/src/overlays/l12/mobys/hoven_turret.c b/src/overlays/l12/mobys/hoven_turret.c index 58bb166677..250a5fa55a 100644 --- a/src/overlays/l12/mobys/hoven_turret.c +++ b/src/overlays/l12/mobys/hoven_turret.c @@ -411,7 +411,7 @@ void hoven_turret_update(struct Moby *moby) { blend_moby_animation(moby, 5, 0, 1); } fast_dec_timer_s16(&hoven_turret_state->f70); - if ((pad_held[0] & 0xA0) && hoven_turret_state->f70 == 0) { + if ((pad_held_words[0] & 0xA0) && hoven_turret_state->f70 == 0) { Vec_304920 firing_offset; Vec_304920 muz; float yaw; diff --git a/src/overlays/l13/mobys/fighter_jet.c b/src/overlays/l13/mobys/fighter_jet.c index 2dc1191cd5..4e0baed8f2 100644 --- a/src/overlays/l13/mobys/fighter_jet.c +++ b/src/overlays/l13/mobys/fighter_jet.c @@ -1,5 +1,6 @@ /* Level 13 fighter jet moby class: moby group switches, flight, targeting, HUD, radar, guns and rockets. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/audio/music/music_stream_state.h" #include "rnc/mobys/moby.h" #include "rnc/hero/hero.h" @@ -757,8 +758,6 @@ int select_fighter_jet_target_and_draw_indicators(int source_moby, extern char fighter_jet_radar_rotation[] __asm__("D_L13_001670D0"); -extern char D_0013C940[]; - int select_fighter_jet_target_and_draw_indicators(int a, char *p, char *radar_origin_position, @@ -783,20 +782,20 @@ void update_fighter_jet_target_tracking(int source_moby, char *moby_vars) __asm__("FUN_L13_002b95b8"); void update_fighter_jet_target_tracking(int source_moby, char *moby_vars) { - char *excluded_target_moby = 0; - char *pad; - char *current_target_moby; - char *selected_target_moby; - float radar_rotation_copy[4]; + char *excluded_target_moby = 0; + struct PadState *pad; + char *current_target_moby; + char *selected_target_moby; + float radar_rotation_copy[4]; if (!(D_L13_0015F5C4 >= 3 && D_L13_0015F5C4 <= 4)) { fast_dec_timer((int *)(moby_vars + 0x8C)); } if (W(moby_vars, 0x8C) != 0 && P(moby_vars, 0x88) != 0 && H(P(moby_vars, 0x88), 0xA6) == W(moby_vars, 0x124) && B(P(moby_vars, 0x88), 0x20) != 0xFE && B(P(moby_vars, 0x88), 0x20) != 0xFD) { - pad = D_0013C940; + pad = &controller_state; if (B(P(moby_vars, 0x88), 0x31) != 0) { - if (W(pad, 0x1B4) & 0x2000) { + if (pad->raw_pressed & 0x2000) { goto take; } if (FLAG != 0) { @@ -804,8 +803,8 @@ void update_fighter_jet_target_tracking(int source_moby, char *moby_vars) { } } } - pad = D_0013C940; - if (W(pad, 0x1B4) & 0x2000) { + pad = &controller_state; + if (pad->raw_pressed & 0x2000) { take: excluded_target_moby = P(moby_vars, 0x88); } diff --git a/src/overlays/l14/hero/update_hero_motion_by_state.c b/src/overlays/l14/hero/update_hero_motion_by_state.c index f659914564..54ca42c54a 100644 --- a/src/overlays/l14/hero/update_hero_motion_by_state.c +++ b/src/overlays/l14/hero/update_hero_motion_by_state.c @@ -13,6 +13,7 @@ #include "rnc/overlay/shared/hero/hero_tables.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/world/level_labels.h" #include "rnc/math/asm_helpers.h" #include "rnc/math/random.h" @@ -334,25 +335,6 @@ struct MobyView { /* Second name for hero: one call needs it to keep the original address CSE. */ extern struct Hero hero_b __asm__("D_0013F350"); -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - u64 d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - struct PlayerJointTable { u8 pad0[0x60]; f32 f60; @@ -421,8 +403,8 @@ extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 allocate_voice_for_target_entry(s32, s32, struct MobyView *) __asm__("FUN_0022da68"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L14_0017AD80; #define AN D_L14_0017AD80 struct VoiceSlot { @@ -1213,7 +1195,7 @@ void update_hero_motion_by_state(void) { if (test_hero_animation_frame_window(84.0f) != 0) { f32 a = fast_add_rotations(hero.motion.rot.f[2], 3.1415927f); f32 s = frame_time * 2.5f; - if (pad_held[0] & 0xA) { + if (pad_held_words[0] & 0xA) { s = frame_time * 3.0f; } hero.motion.velocity.f[0] += fast_cos(a) * s; @@ -2199,13 +2181,13 @@ void update_hero_motion_by_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L14_001674D8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/l14/mobys/taxi.c b/src/overlays/l14/mobys/taxi.c index ed4add765f..6f8cd5ab80 100644 --- a/src/overlays/l14/mobys/taxi.c +++ b/src/overlays/l14/mobys/taxi.c @@ -1,4 +1,5 @@ /* Level 14 taxi moby class: stops, routes and prompts. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/overlay/shared/world/level_path.h" #include "rnc/audio/voice_pool.h" @@ -54,8 +55,6 @@ extern s32 D_L14_0015F5CC; extern s32 D_L14_0015F594; -extern char D_0013CAE4[]; - extern f32 advance_accelerated_scalar(f32 *value, f32 *velocity, f32 target, @@ -124,7 +123,7 @@ void taxi_update(struct Moby *moby) { if (absolute_float(hero_relative_position[1]) < 1.2f) { prepare_taxi_route(moby); request_taxi_stop_prompt(moby); - if ((*(int *)D_0013CAE4 & button) && D_L14_0015F594 == 4) { + if ((pad_pressed_words[0] & button) && D_L14_0015F594 == 4) { struct Moby *m; moby->state = 3; m = find_group_moby_by_tag(moby, taxi_vars->target); @@ -309,7 +308,7 @@ void taxi_update(struct Moby *moby) { hero_relative_position, hero_relative_position, taxi_inverse_rotation_matrix); if (absolute_float(hero_relative_position[1]) < 1.2f) { request_taxi_stop_prompt(moby); - if (*(int *)D_0013CAE4 & button) { + if (pad_pressed_words[0] & button) { qcopy(taxi_vars->save_pos, taxi_vars->pos); qcopy(taxi_vars->save_rot, taxi_vars->rot); initialize_taxi_stop_from_position(moby); diff --git a/src/overlays/l15/hero/update_hero_motion_for_current_state.c b/src/overlays/l15/hero/update_hero_motion_for_current_state.c index 019c0acca8..e4f003c337 100644 --- a/src/overlays/l15/hero/update_hero_motion_for_current_state.c +++ b/src/overlays/l15/hero/update_hero_motion_for_current_state.c @@ -10,6 +10,7 @@ #include "rnc/overlay/shared/hero/hero_tables.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/math/asm_helpers.h" #include "rnc/math/random.h" #include "rnc/mobys/moby_spawn.h" @@ -390,25 +391,6 @@ struct MobyView { Vec4 vC0; }; -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - unsigned long d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - struct PlayerJointTable { u8 pad0[0x60]; f32 f60; @@ -477,8 +459,8 @@ extern void correct_hero_airborne_wall_velocity(void) __asm__("FUN_L00_002121c0" extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L15_0017AC80; #define AN D_L15_0017AC80 struct VoiceSlot { @@ -817,19 +799,20 @@ void update_hero_motion_for_current_state(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; swim_pitch_smoothing_coefficient = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -841,15 +824,15 @@ void update_hero_motion_for_current_state(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -865,9 +848,9 @@ void update_hero_motion_for_current_state(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 use_seconds; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -887,7 +870,7 @@ void update_hero_motion_for_current_state(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (D_L15_0015F5CC - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -896,7 +879,7 @@ void update_hero_motion_for_current_state(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -919,7 +902,7 @@ void update_hero_motion_for_current_state(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -928,7 +911,7 @@ void update_hero_motion_for_current_state(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -942,7 +925,7 @@ void update_hero_motion_for_current_state(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero.puff_timer) != 0) { @@ -1133,7 +1116,7 @@ void update_hero_motion_for_current_state(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -1141,7 +1124,7 @@ void update_hero_motion_for_current_state(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -2209,13 +2192,13 @@ void update_hero_motion_for_current_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L15_001673D8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/l15/moby_follow_camera.c b/src/overlays/l15/moby_follow_camera.c index d50171ebcc..769800afa6 100644 --- a/src/overlays/l15/moby_follow_camera.c +++ b/src/overlays/l15/moby_follow_camera.c @@ -1,5 +1,6 @@ /* Level 15 moby follow camera type: region and angle checks, update and dispatch. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/camera/level_camera.h" #include "rnc/math_consts.h" #include "rnc/math/fast_math.h" @@ -119,14 +120,6 @@ int check_moby_target_angular_limits(char *moby, float projected_angle_limit_deg return 0; } -typedef struct { - char pad[0x100]; - float x; - float y; -} G_88e8; - -extern G_88e8 D_0013C940_lui __asm__("D_0013C940") NOT_SDA; - extern int try_select_follow_camera_volume(char *) __asm__("FUN_L00_002e83c0"); extern void clear_follow_camera_volume_if_current(char *) __asm__("FUN_L00_002e8388"); @@ -163,9 +156,9 @@ void update_moby_follow_camera(char *moby) { cycle_reset_frames = scale_game_frames(560); spin_ramp_frames = scale_game_frames(200); set_nonzero_follow_camera_parameters(1.0f, 12.0f, 0.11f); - if (D_0013C940_lui.x != 0.0f) + if (controller_state_lui.analog[0] != 0.0f) *(short *)(slot_data + 0x20) = hold_start_frames; - else if (D_0013C940_lui.y != 0.0f) + else if (controller_state_lui.analog[1] != 0.0f) *(short *)(slot_data + 0x20) = hold_start_frames; if (*(short *)(slot_data + 0x20) >= hold_start_frames) { if (++*(int *)(slot_data + 0x3C) >= cone_check_delay_frames && diff --git a/src/overlays/l16/hero/update_hero_motion_for_current_state.c b/src/overlays/l16/hero/update_hero_motion_for_current_state.c index 16d9f4dfc3..a62aa52b2d 100644 --- a/src/overlays/l16/hero/update_hero_motion_for_current_state.c +++ b/src/overlays/l16/hero/update_hero_motion_for_current_state.c @@ -14,6 +14,7 @@ #include "rnc/overlay/shared/hero/hero_tables.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/world/level_labels.h" #include "rnc/math/fast_math.h" #include "rnc/math/asm_helpers.h" @@ -76,25 +77,6 @@ struct MobyView { Vec4 vC0; }; -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - u64 d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - struct PlayerJointTable { u8 pad0[0x60]; f32 f60; @@ -178,8 +160,8 @@ extern void compute_hero_reference_tilt_rotation(void *, void *, f32, f32, f32, extern void rotate_hero_about_local_pivot(void *, f32, f32, f32) __asm__("FUN_L00_002090d0"); extern void update_hero_hoverboard_race_progress(void) __asm__("FUN_L05_00254608"); extern Vec4 l16_hoverboard_trick_pivots_by_air_pose[] __asm__("D_L16_00179BE0"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L16_0017AAE0; #define AN D_L16_0017AAE0 struct VoiceSlot { @@ -546,19 +528,20 @@ void update_hero_motion_for_current_state(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; steering_response_coefficient = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -570,15 +553,15 @@ void update_hero_motion_for_current_state(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -594,9 +577,9 @@ void update_hero_motion_for_current_state(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 use_seconds; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -616,7 +599,7 @@ void update_hero_motion_for_current_state(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (D_L16_0015F5CC - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -625,7 +608,7 @@ void update_hero_motion_for_current_state(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -647,7 +630,7 @@ void update_hero_motion_for_current_state(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -656,7 +639,7 @@ void update_hero_motion_for_current_state(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -670,7 +653,7 @@ void update_hero_motion_for_current_state(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero_b.puff_timer) != 0) { @@ -856,7 +839,7 @@ void update_hero_motion_for_current_state(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -864,7 +847,7 @@ void update_hero_motion_for_current_state(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -1106,8 +1089,8 @@ void update_hero_motion_for_current_state(void) { hero.voice_slot6 = -1; } } - hero.trick_input = hero.board_jump_frames && (PD.u1A0.i1A0 & 0xF); - if ((((PD.u1A0.i1A0 & 0x80) || hero.boost_min_frames != 0) && hero.boost_frames != 0) || + hero.trick_input = hero.board_jump_frames && (PD.held & 0xF); + if ((((PD.held & 0x80) || hero.boost_min_frames != 0) && hero.boost_frames != 0) || hero.boost_pad_timer != 0) { fast_dec_timer_s16(&hero.boost_min_frames); if (hero.board_boost_active == 0) { @@ -2792,13 +2775,13 @@ void update_hero_motion_for_current_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L16_001671D8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/l16/mobys/taxi.c b/src/overlays/l16/mobys/taxi.c index b635478c30..d9a89f5a32 100644 --- a/src/overlays/l16/mobys/taxi.c +++ b/src/overlays/l16/mobys/taxi.c @@ -1,4 +1,5 @@ /* Level 16 moby class taxi: its update, stop setup, departure path and the helpers it calls. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/audio/voice_pool.h" #include "rnc/hero/hero.h" @@ -60,7 +61,6 @@ typedef struct { extern L16PickupPose *D_L16_001600EC; extern char *find_group_moby_by_data_id(struct Moby *, int) __asm__("FUN_L16_002e4be0"); -extern char D_0013CAE4[]; extern float D_0015EE6C_u; extern int advance_taxi_path(struct Moby *) __asm__("FUN_L16_002e4c40"); extern s32 D_L16_0015F594; @@ -116,7 +116,7 @@ void taxi_update(struct Moby *moby) { if (absolute_float(hero_local_offset[1]) < 1.2f) { FUN_L16_002e4a58_c(moby); request_taxi_destination_help_message(moby); - if ((*(int *)(D_0013CAE4) & 0x10) && *(int *)&D_L16_0015F594 == 8) { + if ((pad_pressed_words[0] & 0x10) && *(int *)&D_L16_0015F594 == 8) { moby->state = 3; matched_moby = find_group_moby_by_data_id(moby, *(short *)(taxi_data + 0xAE)); if (matched_moby != 0) { diff --git a/src/overlays/l17/hero/update_hero_motion_for_current_state.c b/src/overlays/l17/hero/update_hero_motion_for_current_state.c index 8a418b375b..56d94c3814 100644 --- a/src/overlays/l17/hero/update_hero_motion_for_current_state.c +++ b/src/overlays/l17/hero/update_hero_motion_for_current_state.c @@ -15,6 +15,7 @@ #include "rnc/math/vector.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/world/level_labels.h" #include "rnc/math/fast_math.h" #include "rnc/math/asm_helpers.h" @@ -74,25 +75,6 @@ struct MobyView { Vec4 vC0; }; -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - u64 d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - struct PlayerJointTable { u8 pad0[0x60]; f32 f60; @@ -162,8 +144,8 @@ extern void correct_hero_airborne_wall_velocity(void) __asm__("FUN_L00_002121c0" extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L17_0017AF80; #define AN D_L17_0017AF80 struct VoiceSlot { @@ -543,19 +525,20 @@ void update_hero_motion_for_current_state(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; pitch_smoothing_coefficient = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -567,15 +550,15 @@ void update_hero_motion_for_current_state(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -591,9 +574,9 @@ void update_hero_motion_for_current_state(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 use_seconds; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -613,7 +596,7 @@ void update_hero_motion_for_current_state(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (D_L17_0015F5CC - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -622,7 +605,7 @@ void update_hero_motion_for_current_state(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -645,7 +628,7 @@ void update_hero_motion_for_current_state(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -654,7 +637,7 @@ void update_hero_motion_for_current_state(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -668,7 +651,7 @@ void update_hero_motion_for_current_state(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero_b.puff_timer) != 0) { @@ -844,7 +827,7 @@ void update_hero_motion_for_current_state(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -852,7 +835,7 @@ void update_hero_motion_for_current_state(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -1388,7 +1371,7 @@ void update_hero_motion_for_current_state(void) { if (test_hero_animation_frame_window(84.0f) != 0) { f32 a = fast_add_rotations(hero.motion.rot.f[2], 3.1415927f); f32 s = frame_time * 2.5f; - if (pad_held[0] & 0xA) { + if (pad_held_words[0] & 0xA) { s = frame_time * 3.0f; } hero.motion.velocity.f[0] += fast_cos(a) * s; @@ -2517,13 +2500,13 @@ void update_hero_motion_for_current_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L17_001676D8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/l17/mobys/fighter_jet.c b/src/overlays/l17/mobys/fighter_jet.c index ed08aba39b..f798a14a58 100644 --- a/src/overlays/l17/mobys/fighter_jet.c +++ b/src/overlays/l17/mobys/fighter_jet.c @@ -656,21 +656,21 @@ extern char D_L17_001676D0_lui[] __asm__("D_L17_001676D0") NOT_SDA; void update_fighter_jet_target_lock(int ship_moby, char *ship_vars) __asm__("FUN_L17_002eb768"); void update_fighter_jet_target_lock(int ship_moby, char *ship_vars) { - char *excluded_target = 0; - char *pad; - char *locked_target; - char *candidate_target; - float radar_rotation[4]; - int lock_timer_reload; + char *excluded_target = 0; + struct PadState *pad; + char *locked_target; + char *candidate_target; + float radar_rotation[4]; + int lock_timer_reload; if (!(D_L17_0015F5C4 >= 3 && D_L17_0015F5C4 <= 4)) { fast_dec_timer((int *)(ship_vars + 0x8C)); } if (W(ship_vars, 0x8C) != 0 && P(ship_vars, 0x88) != 0 && H(P(ship_vars, 0x88), 0xA6) == W(ship_vars, 0x128) && B(P(ship_vars, 0x88), 0x20) != 0xFE && B(P(ship_vars, 0x88), 0x20) != 0xFD) { - pad = (char *)&controller_state; + pad = &controller_state; if (B(P(ship_vars, 0x88), 0x31) != 0) { - if (W(pad, 0x1B4) & 0x2000) { + if (pad->raw_pressed & 0x2000) { goto take; } if (FLAG != 0) { @@ -678,8 +678,8 @@ void update_fighter_jet_target_lock(int ship_moby, char *ship_vars) { } } } - pad = (char *)&controller_state; - if (W(pad, 0x1B4) & 0x2000) { + pad = &controller_state; + if (pad->raw_pressed & 0x2000) { take: excluded_target = P(ship_vars, 0x88); } @@ -1168,7 +1168,6 @@ void adjust_fighter_jet_steering_for_flight_bounds( void adjust_fighter_jet_steering_for_flight_bounds(char *moby, float *a, float *b) __asm__("FUN_L17_002edf10"); -extern char D_0013C940[]; extern void func_L00_0025F4A8_alt(void *, void *, void *, @@ -1192,33 +1191,33 @@ void update_fighter_jet_flight(FighterJetMoby *ship_moby, FighterJetVars *ship_vars) __asm__("FUN_L17_002ec360"); void update_fighter_jet_flight(FighterJetMoby *ship_moby, FighterJetVars *ship_vars) { - sceVu0FVECTOR pre_movement_ship_position; - sceVu0FVECTOR death_explosion_velocity; - UQ_c4 movement_delta; - sceVu0FVECTOR side; - UQ_c4 up; - sceVu0FVECTOR camera_rotation; - sceVu0FVECTOR target; - sceVu0FVECTOR target_record_sum_or_camera_local_offset; - float horizontal_steering_input; - float vertical_steering_input; - float ka; - float kb; - float lenA; - float lenB; - float distance_to_default_target; - float target_height_distance, target_height_distance_for_moby_pitch; - float x, y; - float half_fov, tn; - float ratio; - float collision_adjusted_pitch; - float k; - char *pad; - struct Hero *steering_input_hero; - char *e; - char *collision_result; - int voice_slot_index; - int hc; + sceVu0FVECTOR pre_movement_ship_position; + sceVu0FVECTOR death_explosion_velocity; + UQ_c4 movement_delta; + sceVu0FVECTOR side; + UQ_c4 up; + sceVu0FVECTOR camera_rotation; + sceVu0FVECTOR target; + sceVu0FVECTOR target_record_sum_or_camera_local_offset; + float horizontal_steering_input; + float vertical_steering_input; + float ka; + float kb; + float lenA; + float lenB; + float distance_to_default_target; + float target_height_distance, target_height_distance_for_moby_pitch; + float x, y; + float half_fov, tn; + float ratio; + float collision_adjusted_pitch; + float k; + struct PadState *pad; + struct Hero *steering_input_hero; + char *e; + char *collision_result; + int voice_slot_index; + int hc; movement_delta.q = 0; up.q = 0; @@ -1228,8 +1227,8 @@ void update_fighter_jet_flight(FighterJetMoby *ship_moby, FighterJetVars *ship_v *(Q_c4 *)death_explosion_velocity = movement_delta.q; if (ship_moby->bc == 0) { if (D_L17_00162000 < ship_vars->count) { - pad = (char *)((char *)&D_0013C940); - if (*(int *)(pad + 0x1B4) & 0x40) { + pad = &controller_state; + if (pad->raw_pressed & 0x40) { voice_slot_index = ship_vars->i10C; if (voice_slot_index != -1) { e = (char *)&voice_pool + voice_slot_index * 0x70; @@ -1240,7 +1239,7 @@ void update_fighter_jet_flight(FighterJetMoby *ship_moby, FighterJetVars *ship_v } ship_vars->i10C = -1; ship_vars->i10C = allocate_voice_for_target_entry(1, 4, (int)ship_moby); - } else if (*(int *)(pad + 0x1B8) & 0x40) { + } else if (pad->raw_released & 0x40) { voice_slot_index = ship_vars->i10C; if (voice_slot_index != -1) { e = (char *)&voice_pool + voice_slot_index * 0x70; @@ -1251,8 +1250,8 @@ void update_fighter_jet_flight(FighterJetMoby *ship_moby, FighterJetVars *ship_v } ship_vars->i10C = -1; } - pad = (char *)((char *)&D_0013C940); - if (*(int *)(pad + 0x1B0) & 0x40) { + pad = &controller_state; + if (pad->raw_held & 0x40) { float accelerated_speed = ship_vars->speed + fighter_jet_boost_speed_step_gp * D_L17_001620A0_gp; float max = fighter_jet_boost_speed_limit_gp * D_L17_001620A0_gp; @@ -1290,7 +1289,7 @@ void update_fighter_jet_flight(FighterJetMoby *ship_moby, FighterJetVars *ship_v kb = fighter_jet_vertical_steering_settle_threshold_scale_gp; horizontal_steering_input = x; vertical_steering_input = y; - if (*(int *)(((char *)&pad_held)) & 0x200) { + if (pad_held_words[0] & 0x200) { horizontal_steering_input = x / D_L17_00162028 * D_L17_00162030; vertical_steering_input = y / D_L17_00162024 * D_L17_0016202C; ka = fighter_jet_rescaled_horizontal_steering_settle_threshold_scale_gp; @@ -1675,8 +1674,6 @@ typedef struct { int flags; } ShipHit; -extern char D_0013CAE4_ed[] __asm__("D_0013CAE4"); - typedef struct { char pad0[0xA]; unsigned short idx; @@ -1877,7 +1874,7 @@ void fighter_jet_update(ShipMoby *moby) { struct Hero *g = &hero; board = jet_distance(moby, (ShipCamera *)g->moby) < fighter_jet_boarding_distance_limit_gp && - FUN_00215130(7, 0x53E4) != 0 && (*(int *)D_0013CAE4_ed & 0x10); + FUN_00215130(7, 0x53E4) != 0 && (pad_pressed_words[0] & 0x10); if (board) { remove_help_message_for_selector(7); moby->state = 2; diff --git a/src/overlays/l17/mobys/shuttle.c b/src/overlays/l17/mobys/shuttle.c index b649af0d74..728fc93cd7 100644 --- a/src/overlays/l17/mobys/shuttle.c +++ b/src/overlays/l17/mobys/shuttle.c @@ -100,7 +100,6 @@ int update_shuttle_travel_and_camera(char *moby, int idx) __asm__("FUN_L17_002f void update_shuttle_help_message(struct Moby *moby) __asm__("FUN_L17_002f20d8"); extern char D_0014C190[]; -extern char D_0013CAE4[]; void shuttle_update(struct Moby *m) __asm__("FUN_L17_002f1940"); @@ -167,7 +166,7 @@ void shuttle_update(struct Moby *shuttle_moby) { pl = &hero; if (((unsigned char *)pl->ground_moby) == shuttle_moby && pl->air_frames.s == 0) { update_shuttle_help_message(shuttle_moby); - if ((*(int *)(((char *)&D_0013CAE4)) & 0x10) && D_L17_0015F594 == 10) { + if ((pad_pressed_words[0] & 0x10) && D_L17_0015F594 == 10) { int s = shuttle_vars->dir; if (s >= 0) { shuttle_vars->go = 1; diff --git a/src/overlays/l18/hero/update_hero_motion_for_current_state.c b/src/overlays/l18/hero/update_hero_motion_for_current_state.c index 0f93720561..95501585d6 100644 --- a/src/overlays/l18/hero/update_hero_motion_for_current_state.c +++ b/src/overlays/l18/hero/update_hero_motion_for_current_state.c @@ -15,6 +15,7 @@ #include "rnc/overlay/shared/hero/hero_tables.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/world/level_labels.h" #include "rnc/math/fast_math.h" #include "rnc/math/asm_helpers.h" @@ -74,25 +75,6 @@ struct MobyView { Vec4 vC0; }; -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - u64 d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - struct PlayerJointTable { u8 pad0[0x60]; f32 f60; @@ -162,8 +144,8 @@ extern void correct_hero_airborne_wall_velocity(void) __asm__("FUN_L00_002121c0" extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct PlayerJointTable D_L18_0017B080; #define AN D_L18_0017B080 struct VoiceSlot { @@ -495,19 +477,20 @@ void update_hero_motion_for_current_state(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; swim_steering_smoothing_gain = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -519,15 +502,15 @@ void update_hero_motion_for_current_state(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -543,9 +526,9 @@ void update_hero_motion_for_current_state(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 use_seconds; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -565,7 +548,7 @@ void update_hero_motion_for_current_state(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (game_frame - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -574,7 +557,7 @@ void update_hero_motion_for_current_state(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -597,7 +580,7 @@ void update_hero_motion_for_current_state(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -606,7 +589,7 @@ void update_hero_motion_for_current_state(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -620,7 +603,7 @@ void update_hero_motion_for_current_state(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero_b.puff_timer) != 0) { @@ -815,7 +798,7 @@ void update_hero_motion_for_current_state(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -823,7 +806,7 @@ void update_hero_motion_for_current_state(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -2404,13 +2387,13 @@ void update_hero_motion_for_current_state(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L18_001677D8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/shared/camera/aim_volume_camera.c b/src/overlays/shared/camera/aim_volume_camera.c index 8dadc54790..9ae168d050 100644 --- a/src/overlays/shared/camera/aim_volume_camera.c +++ b/src/overlays/shared/camera/aim_volume_camera.c @@ -110,7 +110,7 @@ void volume_camera_aim(struct UpdateCam *aim_camera_record) { params->timer = 0; return; } - if (!(pad_held[0] & (PAD_L2 | PAD_L1))) { + if (!(pad_held_words[0] & (PAD_L2 | PAD_L1))) { goto run; } } diff --git a/src/overlays/shared/camera/follow_camera_setup.c b/src/overlays/shared/camera/follow_camera_setup.c index 9db224b5fc..5fd5944b33 100644 --- a/src/overlays/shared/camera/follow_camera_setup.c +++ b/src/overlays/shared/camera/follow_camera_setup.c @@ -1,5 +1,6 @@ /* Follow camera: setup, per-frame approach and overrides, pose rebuild, and the collision probes that keep it clear of the level. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/camera/camera.h" #include "rnc/overlay/shared/world/level_globals.h" #include "rnc/hero/hero.h" @@ -212,12 +213,6 @@ typedef struct { u8 pad2[0x380 - 0x264]; } A_2e6000; -typedef struct { - u8 pad[0x100]; - f32 f100; - f32 f104; -} C_2e6000; - typedef struct { u8 pad[0x2000]; s32 i2000; @@ -225,7 +220,6 @@ typedef struct { #include "rnc/overlay/shared/camera/level_camera.h" -extern C_2e6000 D_0013C940_2e6000 __asm__("D_0013C940"); extern L_2e6000 D_0013F3D0_2e6000 __asm__("D_0013F3D0"); extern s32 D_L00_00177F00[]; extern f32 D_L00_00166E10[]; @@ -336,8 +330,8 @@ void follow_camera_apply_overrides(O_2e6000 *camera_moby) { if ((s8)player_camera_state->p25C[0x20] < 0) { player_camera_state->p25C = 0; } else { - if (0.3f <= absolute_float(D_0013C940_2e6000.f100) || - 0.3f <= absolute_float(D_0013C940_2e6000.f104)) { + if (0.3f <= absolute_float(controller_state.analog[0]) || + 0.3f <= absolute_float(controller_state.analog[1])) { player_camera_state->i260 = 0; } x = (A_2e6000 *)&l00_camera; @@ -363,7 +357,7 @@ void follow_camera_apply_overrides(O_2e6000 *camera_moby) { } } } - if (hero.state.current == 0x81 && (pad_held[0] & 3)) { + if (hero.state.current == 0x81 && (pad_held_words[0] & 3)) { set_follow_camera_orbit_clamp_mode(0); follow_camera_start_slide(); follow_camera_set_lateral_spring(0.04f, 0.2f); @@ -1394,14 +1388,6 @@ extern u8 *D_L00_001E75C0[] NOT_SDA; extern f32 follow_camera_minimum_retracted_orbit_distance_gp __asm__("D_L00_00161CD0") __attribute__((sda)); -typedef struct { - u8 pad[0x100]; - f32 x; - f32 y; -} C940_2e7d20_t; - -extern C940_2e7d20_t D_0013C940_lui __asm__("D_0013C940") NOT_SDA; - typedef struct { u8 pad[0x18]; s32 p18; @@ -1533,10 +1519,10 @@ void follow_camera_avoid_mobies(u8 *camera_moby) { if (retraction_timer_or_below_hold_threshold && BH_2e7d20(0x34) > 0) { goto dec; } - if (!(D_0013C940_lui.x < 0.3f)) { + if (!(controller_state_lui.analog[0] < 0.3f)) { goto slow; } - if (!(D_0013C940_lui.y < 0.3f)) { + if (!(controller_state_lui.analog[1] < 0.3f)) { goto slow; } dec: diff --git a/src/overlays/shared/camera/hero_aligned_camera.c b/src/overlays/shared/camera/hero_aligned_camera.c index 7b3f9dde32..4b96c7aa7f 100644 --- a/src/overlays/shared/camera/hero_aligned_camera.c +++ b/src/overlays/shared/camera/hero_aligned_camera.c @@ -1,6 +1,7 @@ /* Camera type 4: a camera aligned with the hero, steered by the pad, and its transition step. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/camera/camera.h" #include "rnc/hero/hero.h" #include "sda.h" @@ -26,13 +27,6 @@ typedef struct { float a, va, b, vb, ang, z, vz; } S_9f38; -typedef struct { - u8 pad0[0x100]; - float f100, f104, f108, f10C; - u8 pad1[0x1A0 - 0x110]; - int i1A0; -} C940; - typedef struct { u8 pad0[0x180]; char *current_follow_cam; /* 0x180: struct UpdateCam * */ @@ -128,7 +122,6 @@ extern float FUN_001f9af0_2ea810(void *) __asm__("FUN_001f9af0"); extern unsigned char D_0015EDB3_002e9cc0 __asm__("D_0015EDB3"); extern u128 D_0013F3D0_2e9dd0 __asm__("D_0013F3D0"); extern FollowCamSideRef *D_L00_00166E04 __asm__("D_L00_00166E04") NOT_SDA; -extern C940 D_0013C940; extern float hero_aligned_camera_rotation_gain_at_zero_input_gp __asm__("D_L00_00161DC0") __attribute__((sda)); extern float hero_aligned_camera_rotation_gain_at_unit_input_gp __asm__("D_L00_00161DC4") @@ -321,13 +314,13 @@ void update_hero_aligned_camera_from_input(u8 *camera_object) { FUN_001f9bf8_c(&up, ((u8 *)hero.moby) + 0xE0, 1.0f); if (l00_camera.unk270 == 0 && hero.unk20A5 == 0) hero.unk20A5 = 1; - rotation_input_target = -D_0013C940.f108; + rotation_input_target = -controller_state.analog[2]; if (rotation_input_target == 0.0f) - rotation_input_target = -D_0013C940.f100; + rotation_input_target = -controller_state.analog[0]; if (rotation_input_target == 0.0f) - rotation_input_target = convert_integer_to_float((D_0013C940.i1A0 >> 15) & 1); + rotation_input_target = convert_integer_to_float((controller_state.held >> 15) & 1); if (rotation_input_target == 0.0f) - rotation_input_target = -convert_integer_to_float((D_0013C940.i1A0 >> 13) & 1); + rotation_input_target = -convert_integer_to_float((controller_state.held >> 13) & 1); rotation_input_scratch = absolute_float(camera_rotation_state->a); k = hero_aligned_camera_rotation_gain_at_zero_input_gp + (hero_aligned_camera_rotation_gain_at_unit_input_gp - @@ -344,13 +337,13 @@ void update_hero_aligned_camera_from_input(u8 *camera_object) { build_look_at_matrix(camera_object, camera_object, &up, k * rotation_input_scratch); if (hero.motion.platform_carry.f[3] != 0.0f && hero.unk308 == 0) build_look_at_matrix(camera_object, camera_object, &up, hero.motion.platform_carry.f[3]); - rotation_input_target = -D_0013C940.f10C; + rotation_input_target = -controller_state.analog[3]; if (rotation_input_target == 0.0f) - rotation_input_target = -D_0013C940.f104; + rotation_input_target = -controller_state.analog[1]; if (rotation_input_target == 0.0f) - rotation_input_target = convert_integer_to_float((D_0013C940.i1A0 >> 12) & 1); + rotation_input_target = convert_integer_to_float((controller_state.held >> 12) & 1); if (rotation_input_target == 0.0f) - rotation_input_target = -convert_integer_to_float((D_0013C940.i1A0 >> 14) & 1); + rotation_input_target = -convert_integer_to_float((controller_state.held >> 14) & 1); if (l00_camera.unk270 != 0 && hero.state.prev == 2) rotation_input_target = 0.0f; if (invert52 == 0) diff --git a/src/overlays/shared/camera/swing_volume_camera.c b/src/overlays/shared/camera/swing_volume_camera.c index 421442e431..3a3f06f6ad 100644 --- a/src/overlays/shared/camera/swing_volume_camera.c +++ b/src/overlays/shared/camera/swing_volume_camera.c @@ -166,7 +166,8 @@ void volume_camera_swing(struct UpdateCam *swing_camera_record) { D_L00_00166DD8) >= 1.3962634f) { goto stop; } - if (params->l_buttons_end != 0 && params->type == 5 && (pad_held[0] & (PAD_L2 | PAD_L1))) { + if (params->l_buttons_end != 0 && params->type == 5 && + (pad_held_words[0] & (PAD_L2 | PAD_L1))) { stop: if (params->timer != 0) { params->done = 1; diff --git a/src/overlays/shared/cutscenes/update_cutscene_playback.c b/src/overlays/shared/cutscenes/update_cutscene_playback.c index 94e4b83b75..fd86cb5853 100644 --- a/src/overlays/shared/cutscenes/update_cutscene_playback.c +++ b/src/overlays/shared/cutscenes/update_cutscene_playback.c @@ -1,4 +1,5 @@ /* Cutscene, movie and slideshow playback, the game frame and idle counters and pause input; also defines the vendor menu data (vendor/vendor_menu.c holds its code). */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/overlay/shared/world/level_globals.h" #include "rnc/game/scene_trigger.h" @@ -78,8 +79,6 @@ void reset_frame_counters(void) { #include "rnc/game/usage_stats.h" -extern struct PadStateWords D_0013C940; - int controller_idle_frames_gp __asm__("D_L00_00160FF0") = 0; extern int D_L00_0015F5CC; extern int D_0015EEA4; @@ -88,9 +87,9 @@ extern int D_0015EE28; void update_game_frame_and_idle_counters(void) __asm__("FUN_L00_00297e70"); void update_game_frame_and_idle_counters(void) { - if (D_0013C940.buttons.w.held != 0 || D_0013C940.analog[2] != 0.0f || - D_0013C940.analog[3] != 0.0f || D_0013C940.analog[0] != 0.0f || - D_0013C940.analog[1] != 0.0f) { + if (controller_state.held != 0 || controller_state.analog[2] != 0.0f || + controller_state.analog[3] != 0.0f || controller_state.analog[0] != 0.0f || + controller_state.analog[1] != 0.0f) { controller_idle_frames_gp = 0; } else { controller_idle_frames_gp++; @@ -116,14 +115,6 @@ typedef struct { s32 wEC; } S_297f78; -typedef struct { - u8 pad0[0x19C]; - s32 w19C; - s32 w1A0; - s32 w1A4; - s32 w1A8; -} C_297f78; - typedef struct { u8 pad0[0xA6]; s16 hA6; @@ -152,7 +143,6 @@ typedef struct { } P_297f78; extern S_297f78 D_L00_0016C058; -extern C_297f78 D_0013C940_c __asm__("D_0013C940"); extern s32 D_L00_0015F5C0_macro[] __asm__("D_L00_0015F5C0") MACRO_ADDR; extern s32 level_timer __asm__("D_L00_0015F5C8"); extern s32 game_frame __asm__("D_L00_0015F5CC"); @@ -195,9 +185,10 @@ extern void update_hud_elements(s32) __asm__("FUN_L00_0023ac78"); extern void update_help_state(void) __asm__("FUN_001fde90"); extern void update_game_frame_and_idle_counters(void) __asm__("FUN_L00_00297e70"); -#define DBG(b) \ - ((D_L00_0016C058.w8 & (b)) || ((D_L00_0016C058.w8 & 0x10) && (D_0013C940_c.w1A4 & 0x200))) -#define HELD ((D_0013C940_c.w1A4 & 0x800) || noctl) +#define DBG(b) \ + ((D_L00_0016C058.w8 & (b)) || \ + ((D_L00_0016C058.w8 & 0x10) && (controller_state.pressed & 0x200))) +#define HELD ((controller_state.pressed & 0x800) || noctl) void handle_pause_input(void) __asm__("FUN_L00_00297f78"); @@ -207,17 +198,17 @@ void handle_pause_input(void) { if (--D_L00_0016C058.wEC == 0) D_L00_0016C058.w8 = 0x10; } - if ((D_L00_0016C058.w8 & 0x10) && (D_0013C940_c.w1A4 & 0x200)) { - D_0013C940_c.w1A4 = ~D_L00_0016C058.wA0 & D_0013C940_c.w1A0; - D_0013C940_c.w1A8 = ~D_0013C940_c.w1A0 & D_L00_0016C058.wA0; - D_L00_0016C058.wA0 = D_0013C940_c.w1A0 & ~0x200; + if ((D_L00_0016C058.w8 & 0x10) && (controller_state.pressed & 0x200)) { + controller_state.pressed = ~D_L00_0016C058.wA0 & controller_state.held; + controller_state.released = ~controller_state.held & D_L00_0016C058.wA0; + D_L00_0016C058.wA0 = controller_state.held & ~0x200; } lvl = D_L00_0015F5C0_macro[1]; if (lvl == 0 && (mode_freeze_flags & 1) && level_timer >= 8) { mode_freeze_init(3, 0); return; } - noctl = D_0013C940_c.w19C == 0; + noctl = controller_state.device_state == 0; if (D_L00_001B9DE0 && lvl == 0) { pause_all_sounds(0); return; @@ -255,7 +246,7 @@ void handle_pause_input(void) { pause_all_sounds(0); return; } - if (!(D_L00_0016C058.w8 & 0x10) && level_timer >= 8 && (D_0013C940_c.w1A4 & 0x500) && + if (!(D_L00_0016C058.w8 & 0x10) && level_timer >= 8 && (controller_state.pressed & 0x500) && hero.state.control_mode != 0x16 && hero.state.current != 0x72 && hero.state.current != 0x32 && hero.state.current != 0x1D && !hero.fall_fade_pending && hero.health.hp && lvl == 0 && !special && !D_L00_0016C058.wEC) { @@ -271,7 +262,8 @@ void handle_pause_input(void) { } if (hero.state.current != 0x1D && hero.state.current != 0x32) update_timed_hud_visibility(); - if ((D_0013C940_c.w1A4 & 0x200) && hero.state.current != 0x1D && hero.state.current != 0x32) { + if ((controller_state.pressed & 0x200) && hero.state.current != 0x1D && + hero.state.current != 0x32) { s32 x; x = show_health_hud(); hud_keep_visible(x, scale_game_frames(0xB4)); @@ -725,25 +717,25 @@ void update_cutscene_playback(void) { f32 weighted_next_key_position[4] __attribute__((aligned(16))); if ((g_debug_menu.update_flags & 2) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { reset_frame_counters(); } - if (!(g_debug_menu.update_flags & 0x10) || (D_0013CAE4 & 0x220)) { + if (!(g_debug_menu.update_flags & 0x10) || (((u32)pad_pressed_lui) & 0x220)) { apply_level_specific_cutscene_moby_effects(); } if ((g_debug_menu.update_flags & 2) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { update_visible_mobys(); enqueue_voice_request(); } noop_main_callback(D_L00_00160FF8, 3); if ((g_debug_menu.update_flags & 1) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { coordinate_hero_frame_update(); } noop_main_callback(D_L00_00161008, 7); if ((g_debug_menu.update_flags & 4) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { update_parts(); } noop_main_callback(D_L00_00161018, 5); @@ -762,9 +754,10 @@ void update_cutscene_playback(void) { if (cs->f34 >= scale_game_frames(0x12) && fade_level == 0.0f) { if ((D_0015EEA0 || alternate_animation_sequence || decode_mode || current_level_index <= 0) && - (D_0013C940.buttons.w.pressed & 0x800)) { + (controller_state.pressed & 0x800)) { done = 1; - } else if ((D_0013C940.buttons.held_pressed & 0x8000000000FUL) == 0x8000000000FUL) { + } else if ((((struct PadStateWords *)&controller_state)->buttons.held_pressed & + 0x8000000000FUL) == 0x8000000000FUL) { done = 1; } } @@ -817,7 +810,7 @@ void update_cutscene_playback(void) { update_all_point_lights(); update_resident_packed_direction(); if ((g_debug_menu.update_flags & 2) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { update_game_frame_and_idle_counters(); } } @@ -1221,7 +1214,7 @@ void update_slideshow(void) { } slideshow.timer++; slideshow.frame++; - if (D_0013CAE4 & 0x800) { + if (((u32)pad_pressed_lui) & 0x800) { end_slideshow(); } FUN_0022ca50(); diff --git a/src/overlays/shared/cutscenes/update_npc_dialogue.c b/src/overlays/shared/cutscenes/update_npc_dialogue.c index 47e82d7951..deee7e0327 100644 --- a/src/overlays/shared/cutscenes/update_npc_dialogue.c +++ b/src/overlays/shared/cutscenes/update_npc_dialogue.c @@ -1,4 +1,5 @@ /* NPC dialogue: initializes and updates a dialogue and reads and writes its dialogue records. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/game/level_object_states.h" #include "rnc/ui/vendor/vendor_item_info.h" @@ -58,7 +59,6 @@ struct SceneTrigger { extern s32 D_L00_0015F5C4; /* nonzero blocks all triggers */ extern s32 game_frame __asm__("D_L00_0015F5CC"); -extern s32 D_0013CAE4[]; /* bit 0x10 lifts the facing check */ extern s32 bolt_hud_item __asm__("D_L00_00160130") __attribute__((sda)); extern void FUN_L00_002668a0_c(struct Moby *, struct SceneTrigger *) __asm__("FUN_L00_002668a0"); @@ -112,7 +112,7 @@ s32 update_npc_dialogue(struct Moby *moby, struct SceneTrigger *trigger) { if (game_frame < active_scene_trigger.next_frame) return 0; - if (trigger->any_direction != 0 || (D_0013CAE4[0] & 0x10)) { + if (trigger->any_direction != 0 || (pad_pressed_words[0] & 0x10)) { index = FUN_L00_002667d0_c2(moby); if (level_object_states[index].state == 0) level_object_states[index].state = 1; diff --git a/src/overlays/shared/hero/hero_frame_update.c b/src/overlays/shared/hero/hero_frame_update.c index 4dcdbab0ad..49c4af1228 100644 --- a/src/overlays/shared/hero/hero_frame_update.c +++ b/src/overlays/shared/hero/hero_frame_update.c @@ -1,4 +1,5 @@ /* Hero per-frame update: idle animation, voice requests, ground material effects, ledge probes, vehicle mode entry and exit, hit response and collision dimensions. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero_state.h" #include "rnc/hero/hero.h" @@ -1582,13 +1583,12 @@ void request_hero_idle_state_for_vehicle_mode(void) { } } -extern s32 pad_held __asm__("D_0013CAE0") NOT_SDA; -void set_hero_animation(s32, s32, f32) __asm__("FUN_L00_002323b8"); -void stick_target(s32, f32) __asm__("FUN_L00_002118c8"); -void hero_queue_sequence(s32, s32) __asm__("FUN_L00_002325e0"); -void FUN_L00_0025f730_242198(void *, f32) __asm__("FUN_L00_0025f730"); -s32 get_hero_idle_animation_index(s32) __asm__("FUN_L01_00226f10"); -void select_hero_locomotion_state(void) __asm__("FUN_L01_00242198"); +void set_hero_animation(s32, s32, f32) __asm__("FUN_L00_002323b8"); +void stick_target(s32, f32) __asm__("FUN_L00_002118c8"); +void hero_queue_sequence(s32, s32) __asm__("FUN_L00_002325e0"); +void FUN_L00_0025f730_242198(void *, f32) __asm__("FUN_L00_0025f730"); +s32 get_hero_idle_animation_index(s32) __asm__("FUN_L01_00226f10"); +void select_hero_locomotion_state(void) __asm__("FUN_L01_00242198"); void select_hero_locomotion_state(void) { struct Hero *hero_ptr, *run_hero, *stop_idle_hero; @@ -1596,7 +1596,7 @@ void select_hero_locomotion_state(void) { hero_ptr = &hero; hero_ptr->unk2284 = 0; stick_target(0, 1.0f); - if (pad_held & 0xA) { + if (pad_held_lui & 0xA) { l01_hero_set_state(HERO_STATE_CROUCH, 0); set_hero_animation(0xD, 2, -2.0f); hero_queue_sequence(3, 0x12); diff --git a/src/overlays/shared/hero/hero_handle_jump_press.c b/src/overlays/shared/hero/hero_handle_jump_press.c index d94c222ad6..cea5e1470e 100644 --- a/src/overlays/shared/hero/hero_handle_jump_press.c +++ b/src/overlays/shared/hero/hero_handle_jump_press.c @@ -1,4 +1,5 @@ /* Hero: jump press handling, locomotion state, idle fidgets, item idle animations and the forward collision height check. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero.h" #include "asm.h" @@ -107,7 +108,6 @@ s32 pick_idle_fidget(s32 *index) { } extern u8 D_0013F350_002293a8[] __asm__("D_0013F350"); -extern s32 pad_held __asm__("D_0013CAE0") NOT_SDA; extern s32 D_L00_0015F6DC __asm__("D_L00_0015F6DC"); extern int hero_set_state(int, int) __asm__("FUN_L00_002223f8"); void set_hero_animation(s32, s32, f32) __asm__("FUN_L00_002323b8"); @@ -127,7 +127,7 @@ void update_hero_locomotion_state(void) { return; } stick_target(0, 1.0f); - if (pad_held & 0xA) { + if (pad_held_lui & 0xA) { hero_set_state(HERO_STATE_CROUCH, 0); set_hero_animation(0xD, 2, -2.0f); hero_queue_sequence(3, 0x12); @@ -172,7 +172,6 @@ void update_hero_locomotion_state(void) { } } -extern s32 pad_held_lui __asm__("D_0013CAE0") NOT_SDA; extern u8 D_0013D4C2_lui __asm__("D_0013D4C2") NOT_SDA; extern int get_hero_high_jump_input_window_frames(void) __asm__("FUN_L00_00221d98"); extern int check_pad_press_separation(int, void *, int, int) __asm__("FUN_L00_00266e00"); diff --git a/src/overlays/shared/hero/hero_switch_item.c b/src/overlays/shared/hero/hero_switch_item.c index 44b6ed3814..435792e02e 100644 --- a/src/overlays/shared/hero/hero_switch_item.c +++ b/src/overlays/shared/hero/hero_switch_item.c @@ -1,5 +1,7 @@ /* Hero items and targeting: item slots and switching, ledge and grind rail probes, aim pitch, target scoring and selection. */ +#include "rnc/input/pad_globals.h" #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/mobys/moby_hit.h" #include "rnc/mobys/moby.h" #include "rnc/math/asm_helpers.h" @@ -344,8 +346,7 @@ typedef union { float f[4]; } Vec4_20d330; -extern int D_0013CAE4_0020d330[] __asm__("D_0013CAE4"); -void update_hero_offset_rail_candidate(void) __asm__("FUN_L00_0020d330"); +void update_hero_offset_rail_candidate(void) __asm__("FUN_L00_0020d330"); void update_hero_offset_rail_candidate(void) { struct Hero *P = &hero; @@ -365,7 +366,7 @@ void update_hero_offset_rail_candidate(void) { float bz, az; int fl; az = rail_query_position.f[2]; - fl = D_0013CAE4_0020d330[0]; + fl = pad_pressed_words[0]; bz = rail_point.f[2]; minimum_query_height_above_rail = -0.7f; query_height_above_rail = az - bz; @@ -1908,7 +1909,6 @@ s32 can_select_hero_item_31(void) { /* Applies the wrench/item selection for slot i: resolves pending, queued and requested items and refreshes the slot when it changes. */ /* Ported from rac1-decomp (src/overlays/shared/help_0020CDF0.c: func_L00_00210558), where it is exact; names translated to the US level program. */ -extern char D_0013C940[]; extern char D_00141660[]; extern unsigned char D_0013D4C0[]; extern int D_0015ED8C; @@ -1963,8 +1963,8 @@ void hero_switch_item(int i) { } changed = 0; { - char *pad = D_0013C940; - if ((*(int *)(pad + 0x1A4) & 0x80) || hero.force_slot0_item8 != 0) { + struct PadState *pad = &controller_state; + if ((pad->pressed & 0x80) || hero.force_slot0_item8 != 0) { if (i == 0) { int v; struct Hero *g = &hero; @@ -1980,8 +1980,8 @@ void hero_switch_item(int i) { } } if (i == 0) { - char *pad = D_0013C940; - if (*(int *)(pad + 0x1A4) & 0x20) { + struct PadState *pad = &controller_state; + if (pad->pressed & 0x20) { struct Hero *g = &hero; if (g->item_select_blocked == 0) { if (g->items[0].item_id != *(int *)(D_00141660) && *(int *)(D_00141660) != 0) { @@ -2725,7 +2725,6 @@ extern void FUN_L00_001ff9e8(void *); extern void matrix_from_basis_rows(void *, void *) __asm__("FUN_L00_001ffcf8"); extern void update_hero_motion_and_collision_probes(void) __asm__("FUN_L00_00221310"); extern void update_hero_timers_and_reach_state(void) __asm__("FUN_L00_002215c8"); -extern u8 controller_state[] __asm__("D_0013C940"); /* Per-frame hero input: stick (or d-pad) into unk1D20/24, the yaw and position history rings, then the hero basis matrix and the movement updates. */ @@ -2745,7 +2744,7 @@ void hero_update(void) { hero_state->gravity_mode = mode; hero_state->stick_magnitude = get_capped_hero_stick_magnitude(); hero_state->unk240 = 0; - source = controller_state; + source = (u8 *)&controller_state; hero_state->stick_x = *(f32 *)(source + 0x108); hero_state->stick_y = *(f32 *)(source + 0x10C); if (FUN_L00_001ff408(&hero_state->stick_x) < 0.25f) { @@ -4152,7 +4151,6 @@ extern int nearest_rail_point() __asm__("FUN_L00_0020cd08"); extern char hero_pos[] __asm__("D_0013F3D0"); extern f32 D_0015ED6C; extern u8 D_0013D4C2 NOT_SDA; -extern s32 pad_held_lui __asm__("D_0013CAE0") NOT_SDA; extern s32 hero_slot_item_id(s32) __asm__("FUN_L00_0020d498"); diff --git a/src/overlays/shared/hero/hero_update_movement.c b/src/overlays/shared/hero/hero_update_movement.c index 5f44df66f2..12c1d87be6 100644 --- a/src/overlays/shared/hero/hero_update_movement.c +++ b/src/overlays/shared/hero/hero_update_movement.c @@ -14,6 +14,7 @@ #include "rnc/overlay/shared/hero/hero_tables.h" #include "rnc/data_labels.h" #include "rnc/input/pad_globals.h" +#include "rnc/input/pad_state.h" #include "rnc/math/random.h" #include "rnc/mobys/moby_spawn.h" #include "rnc/audio/voice_alloc.h" @@ -71,25 +72,6 @@ struct MobyView { Vec4 vC0; }; -struct PadState { - u8 pad0[0x128]; - f32 f128; - f32 f12C; - u8 pad130[0x70]; - union { - u64 d1A0; - s32 i1A0; - struct { - u8 pad[0x4]; - s32 v; - } i1A4; - } u1A0; - u8 pad1A8[0x2C]; - s32 i1D4; - u8 pad1D8[0x4]; - s32 i1DC; -}; - /* second name for hero: gcc reloads the base through it (exactness) */ extern struct Hero hero_b __asm__("D_0013F350"); extern f32 D_0015ED6C_a __asm__("D_0015ED6C"); @@ -120,8 +102,8 @@ extern void correct_hero_airborne_wall_velocity(void) __asm__("FUN_L00_002121c0" extern void spawn_hero_radial_particle_burst(void) __asm__("FUN_L00_00217450"); extern s32 FUN_L00_001ff600(f32, void *, void *); extern void update_hero_water_height_and_bobbing(void) __asm__("FUN_L00_00227d40"); -extern struct PadState D_0013C940; -#define PD D_0013C940 + +#define PD controller_state extern struct HeroEase hero_eases[] __asm__("D_L00_0017A680"); struct VoiceSlot { @@ -513,19 +495,20 @@ void hero_update_movement(void) { struct Hero *pl; steer = 0.0f; - m = PD.f128 < PD.f12C ? PD.f12C : PD.f128; + m = PD.analog[10] < PD.analog[11] ? PD.analog[11] : PD.analog[10]; rate = frame_scale_sq * 0.2f; swim_pitch_easing_coefficient = frame_scale_sq * 0.015f; lo = lo + (frame_time * 1.2217305f - lo) * m; - if ((PD.u1A0.d1A0 & 0xC0) == 0x80 || hero.state.step == 1) { - f32 s = PD.f12C * 1.5f; + if ((((struct PadStateWords *)&PD)->buttons.held_pressed & 0xC0) == 0x80 || + hero.state.step == 1) { + f32 s = PD.analog[11] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames++; s = hero.swim_square_hold_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -537,15 +520,15 @@ void hero_update_movement(void) { s = 0.35f; } steer = s * 1.3613569f; - } else if (PD.u1A0.i1A0 & 0x40) { - f32 s = PD.f128 * 1.5f; + } else if (PD.held & 0x40) { + f32 s = PD.analog[10] * 1.5f; if (s > 1.0f) { s = 1.0f; } if (s < 0.2f) { s = 0.2f; } - if (PD.i1DC != 0x79) { + if (PD.unk1DC != 0x79) { hero.swim_square_hold_frames = 0; hero.cw_turn_frames++; s = hero.cw_turn_frames * 0.5f / scale_game_frames(20) + 0.5f; @@ -561,9 +544,9 @@ void hero_update_movement(void) { hero.cw_turn_frames = 0; hero.swim_square_hold_frames = 0; } - if (PD.u1A0.i1A0 & 0x40) { + if (PD.held & 0x40) { hero.jump_button_frames++; - if (PD.f128 > 0.75f) { + if (PD.analog[10] > 0.75f) { s32 t2; if (++hero.swim_hard_press_frames > scale_game_frames(90) && usage_stats.stat[11].count < 0xFFFF) { @@ -583,7 +566,7 @@ void hero_update_movement(void) { hero.jump_button_frames = 0; hero.swim_hard_press_frames = 0; } - if (PD.u1A0.i1A4.v & 0x40) { + if (PD.pressed & 0x40) { if (D_L00_0015F5CC - hero.last_cross_press_frame < scale_game_frames(70)) { hero.swim_cross_tap_count++; } @@ -592,7 +575,7 @@ void hero_update_movement(void) { if (hero.jump_button_frames > scale_game_frames(70)) { hero.swim_cross_tap_count = 0; } - if (PD.u1A0.i1A0 & 0x80) { + if (PD.held & 0x80) { hero.swim_cross_tap_count = 0; } if (hero.state.current == 0x34) { @@ -614,7 +597,7 @@ void hero_update_movement(void) { if (hero.state.step == 1) { hero.target_speed = frame_time * 6.0f; } else if (hero.state.current == 0x35) { - if (PD.u1A0.i1A0 & 0xA) { + if (PD.held & 0xA) { hero.target_speed = frame_time * 7.0f; } else { hero.target_speed = frame_time * 7.0f * 0.4f; @@ -623,7 +606,7 @@ void hero_update_movement(void) { hero.target_speed = frame_time * 3.0f; } k = hero.stick_magnitude; - if ((PD.u1A0.i1A0 & 0xC0) || hero.state.step == 1) { + if ((PD.held & 0xC0) || hero.state.step == 1) { if (k < 1.0f) { k = 1.0f; } @@ -637,7 +620,7 @@ void hero_update_movement(void) { k = mn; } } - if (hero.state.current != 0x35 || !(PD.u1A0.i1A0 & 0xA)) { + if (hero.state.current != 0x35 || !(PD.held & 0xA)) { hero.target_speed *= k; }; if (fast_dec_timer(&hero_b.puff_timer) != 0) { @@ -808,7 +791,7 @@ void hero_update_movement(void) { } hero.anim_speed = 0.6f; stick_target(frame_time * 3.0f, 0); - if (PD.i1D4 == 0) { + if (PD.no_direction == 0) { if (hero.target_speed < frame_time * 3.0f * 0.5f) { hero.target_speed = frame_time * 3.0f * 0.5f; } @@ -816,7 +799,7 @@ void hero_update_movement(void) { turn_to(0, frame_scale_sq * 0.007f, frame_scale_sq * 0.08f, frame_time * 5.2359877f); fast_dec_timer(&hero.unk698); if (hero.state.current == 0x36) { - if (PD.i1D4 != 0 && hero.unk698 != 0) { + if (PD.no_direction != 0 && hero.unk698 != 0) { hero.target_speed = frame_time * 3.0f; } if (absolute_float(hero.motion.yaw_error) > 0.7853982f) { @@ -1346,7 +1329,7 @@ void hero_update_movement(void) { if (test_hero_animation_frame_window(84.0f) != 0) { f32 a = fast_add_rotations(hero.motion.rot.f[2], 3.1415927f); f32 s = frame_time * 2.5f; - if (pad_held[0] & 0xA) { + if (pad_held_words[0] & 0xA) { s = frame_time * 3.0f; } hero.motion.velocity.f[0] += fast_cos(a) * s; @@ -2456,13 +2439,13 @@ void hero_update_movement(void) { m = sp; } stick_target(hero.stick_magnitude * m, 0); - if (hero.stick_magnitude > 0.2f && !(PD.u1A0.i1A0 & 3)) { + if (hero.stick_magnitude > 0.2f && !(PD.held & 3)) { turn_to(0, frame_scale_sq * 0.027f, frame_scale_sq * 0.3f, frame_time * 5.934119f * hero.stick_magnitude); } - if (PD.u1A0.i1A0 & 3) { + if (PD.held & 3) { f32 o = hero.motion.move_yaw; hero.motion.move_yaw = *(f32 *)D_L00_00166DD8; turn_to(0, frame_scale_sq * 0.017f, frame_scale_sq * 0.3f, frame_time * 4.712389f); diff --git a/src/overlays/shared/hero/process_hero_primary_item_input.c b/src/overlays/shared/hero/process_hero_primary_item_input.c index 4c774cbffd..731870bbcd 100644 --- a/src/overlays/shared/hero/process_hero_primary_item_input.c +++ b/src/overlays/shared/hero/process_hero_primary_item_input.c @@ -1,5 +1,6 @@ /* Hero: primary item input, item slot selection, water and ground transitions, and the hoverboard tricks, race progress and respawn. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/mobys/moby.h" #include "rnc/overlay/shared/hero/hero_tables.h" #include "qcopy.h" @@ -114,7 +115,6 @@ typedef struct { char pad2[0x28]; } ItemDef; -extern char D_0013C940[]; extern char D_00141660[]; extern u8 item_available_lui[35] __asm__("D_0013D4C0") NOT_SDA; extern int D_0015ED8C; @@ -180,8 +180,8 @@ void apply_hero_item_slot_selection(int i) { } changed = 0; { - char *pad = D_0013C940; - if ((*(int *)(pad + 0x1A4) & 0x80) || (&hero)->force_slot0_item8 != 0) { + struct PadState *pad = &controller_state; + if ((pad->pressed & 0x80) || (&hero)->force_slot0_item8 != 0) { if (i == 0) { int v; struct Hero *g = &hero; @@ -197,8 +197,8 @@ void apply_hero_item_slot_selection(int i) { } } if (i == 0) { - char *pad = D_0013C940; - if (*(int *)(pad + 0x1A4) & 0x20) { + struct PadState *pad = &controller_state; + if (pad->pressed & 0x20) { struct Hero *g = &hero; if (g->item_select_blocked == 0) { if (g->items[0].item_id != *(int *)(D_00141660) && *(int *)(D_00141660) != 0) { @@ -627,8 +627,6 @@ int try_apply_hero_water_and_ground_transitions(void) { return water_state_requested; } -#include "rnc/input/pad_state.h" - /* Gadget and weapon input for the current hero state: starts the matching move and returns 1 when the state changed. */ /* Ported from rac1-decomp (src/overlays/shared/help_00237B00.c: func_L05_002523C8), where it is exact; names translated to the US level program. */ @@ -659,8 +657,7 @@ extern void launch_hero_wrench(void) __asm__("FUN_L00_00217658"); extern void select_hero_grapple_swing_target(void) __asm__("FUN_L00_00221ee0"); extern void FUN_L05_0024cee8(int, int); extern void create_class_5c3_moby(void *, void *, void *, float, float) __asm__("FUN_L05_002d4168"); -extern PadState D_0013CA40_p2523C8 __asm__("D_0013C940"); -extern int D_00141660_lui __asm__("D_00141660") NOT_SDA; +extern int D_00141660_lui __asm__("D_00141660") NOT_SDA; extern unsigned char D_0013D5C8_2523C8[] __asm__("D_0013D4DC"); extern HeroTableRow2C D_L05_0017C088[]; int hero_item_input_r1_double_press_timer_gp __asm__("D_L05_0015F674") = 0; @@ -727,7 +724,7 @@ int process_hero_primary_item_input(void) { if (item->state != 0) { break; } - if ((D_0013CA40_p2523C8.held & 0xA) || + if ((controller_state.held & 0xA) || (((*(Hero *)((char *)&hero)).state.current == 1 || (*(Hero *)((char *)&hero)).state.current == 0x1E) && (*(Hero *)((char *)&hero)).state_timer > scale_game_frames(0x14))) { @@ -797,7 +794,7 @@ int process_hero_primary_item_input(void) { break; } if ((*(Hero *)((char *)&hero)).anim_frame >= (float)rec->f10 && - (D_0013CA40_p2523C8.held & 0xA) && + (controller_state.held & 0xA) && pad_pressed_within(mask, scale_game_frames(0xF), 0)) { hero_set_state(0x15, 1); break; @@ -823,7 +820,7 @@ int process_hero_primary_item_input(void) { if (!pad_pressed_within(mask, window, 0)) { break; } - if (D_0013CA40_p2523C8.held & 0xA) { + if (controller_state.held & 0xA) { hero_set_state(0x15, 1); break; } @@ -850,7 +847,7 @@ int process_hero_primary_item_input(void) { (*(Hero *)((char *)&hero)).state.control_mode == 5 || (*(Hero *)((char *)&hero)).state.current == 0x1E) { if (pad_pressed_within(mask, window, 0) || - ((D_0013CA40_p2523C8.held & mask) && + ((controller_state.held & mask) && (*(Hero *)((char *)&hero)).items[0].ready_frames > scale_game_frames(0xF))) { if ((*(Hero *)((char *)&hero)).swing_target_in_sight != 0) { if ((*(Hero *)((char *)&hero)).grapple_target_in_sight != 0) { @@ -921,9 +918,9 @@ int process_hero_primary_item_input(void) { break; } pv = (PVar *)((Moby *)(*(Hero *)((char *)&hero)).items[0].moby)->pvars; - if (((D_0013CA40_p2523C8.held & mask) && + if (((controller_state.held & mask) && (*(Hero *)((char *)&hero)).items[0].ready_frames > scale_game_frames(5)) || - (D_0013CA40_p2523C8.pressed & mask)) { + (controller_state.pressed & mask)) { if (get_ammo(-1)) { if ((*(Hero *)((char *)&hero)).item_anim_active == 0) { start_equipped_item_animation(); @@ -931,7 +928,7 @@ int process_hero_primary_item_input(void) { break; } } - if (D_0013CA40_p2523C8.held & mask) { + if (controller_state.held & mask) { if (!get_ammo(-1)) { if (!voice_is_playing((Moby *)(*(Hero *)((char *)&hero)).items[0].moby, pv->fC)) { @@ -967,7 +964,7 @@ int process_hero_primary_item_input(void) { held_frames = (*(Hero *)((char *)&hero)).items[0].ready_frames; if (pad_pressed_within( mask, window <= held_frames ? window : held_frames, &press_time1) || - ((D_0013CA40_p2523C8.held & 0x20) && held_frames > scale_game_frames(8) && + ((controller_state.held & 0x20) && held_frames > scale_game_frames(8) && held_frames < scale_game_frames(0x11))) { if (get_ammo(-1)) { if ((*(Hero *)((char *)&hero)).state.control_mode == 0xC || @@ -1011,7 +1008,7 @@ int process_hero_primary_item_input(void) { break; case ITEM_PRESS_ACTIVATED_DEVICE: if (((Moby *)(*(Hero *)((char *)&hero)).items[0].moby) != 0) { - if (D_0013CA40_p2523C8.pressed & mask) { + if (controller_state.pressed & mask) { start_equipped_item_animation(); } } @@ -1121,12 +1118,12 @@ int process_hero_primary_item_input(void) { (((*(Hero *)((char *)&hero)).state.control_mode == 2 || (*(Hero *)((char *)&hero)).state.control_mode == 4) && (*(Hero *)((char *)&hero)).grounded_frames != 0)) { - if ((D_0013CA40_p2523C8.held & 8) && (D_0013CA40_p2523C8.pressed & 8)) { + if ((controller_state.held & 8) && (controller_state.pressed & 8)) { hero_set_state(0x81, 1); } } } - if ((D_0013CA40_p2523C8.pressed & 8) && + if ((controller_state.pressed & 8) && (*(Hero *)((char *)&hero)).state.current != 0x81) { hero_item_input_r1_double_press_timer_gp = scale_game_frames(0x1E); } @@ -1164,7 +1161,7 @@ void update_hero_hoverboard_trick_animations(void) { int pad; hero_ptr->board_jump_land_frames = truncate_float_to_s32( predict_hero_trajectory_intercept_time(60.0f, hero_ptr->board_gravity, -1.0f)); - if (hero_ptr->trick_input != 0 && ((pad = pad_held[0]) & 0xF) != 0) { + if (hero_ptr->trick_input != 0 && ((pad = pad_held_words[0]) & 0xF) != 0) { hero_ptr->air_pose_index = 0; if (pad & 8) hero_ptr->air_pose_index = 1; @@ -1188,7 +1185,7 @@ void update_hero_hoverboard_trick_animations(void) { } { struct Hero *k = &hero; - if ((k->air_frames.s == 0 || (pad_held[0] & 0xF) == 0) && + if ((k->air_frames.s == 0 || (pad_held_words[0] & 0xF) == 0) && (unsigned int)(((unsigned char *)((char *)k->moby))[0x53] - 0x69) < 4 && k->anim_changing == 0 && k->anim_loop_frame < ((unsigned char *)((char *)k->moby))[0x51] && diff --git a/src/overlays/shared/hero/try_transition_hero_water_state.c b/src/overlays/shared/hero/try_transition_hero_water_state.c index de6bf9fce9..7df9da5276 100644 --- a/src/overlays/shared/hero/try_transition_hero_water_state.c +++ b/src/overlays/shared/hero/try_transition_hero_water_state.c @@ -1,4 +1,5 @@ /* Hero: tries the water state transition; split out of hero_set_state.c so it builds with the SN compiler on its own. */ +#include "rnc/input/pad_globals.h" #include "sda.h" #include "rnc/overlay/shared/hero/hero_set_state.h" #include "rnc/world/collision/collision_line.h" @@ -11,7 +12,6 @@ #include "rnc/math/fast_math.h" #include "rnc/game/item_state.h" -extern unsigned int pad_held_lui __asm__("D_0013CAE0") NOT_SDA; extern void queue_animation_update(int, int, void *, void *, void *, void *, int) __asm__("FUN_001ff308"); extern void hud_init_particles(void) __asm__("FUN_L00_00236268"); @@ -69,7 +69,7 @@ int try_transition_hero_water_state(void) { qcopy(&end, &start); end.f[2] += 0.3f; if (collision_line(&start, &end, 2, hero.moby, 0)) { - if (item_available[4] != 0 && (pad_held_lui & 10) != 0) { + if (item_available[4] != 0 && (((u32)pad_held_lui) & 10) != 0) { state = 0x35; goto change_state; } diff --git a/src/overlays/shared/mobys/update_all_mobys_profiled.c b/src/overlays/shared/mobys/update_all_mobys_profiled.c index 1677d8565e..15f105830d 100644 --- a/src/overlays/shared/mobys/update_all_mobys_profiled.c +++ b/src/overlays/shared/mobys/update_all_mobys_profiled.c @@ -44,7 +44,7 @@ void update_all_mobys_profiled(void) { s32 *class_profile_counters; s16 profile_label; - if ((*(u64 *)pad_held & 0x800000007LL) != 0x800000007LL) { + if ((*(u64 *)&pad_held_words[0] & 0x800000007LL) != 0x800000007LL) { update_all_mobys(); return; } diff --git a/src/overlays/shared/mobys/update_moby_proximity_interaction.c b/src/overlays/shared/mobys/update_moby_proximity_interaction.c index 4028b0daf9..27b91de4a4 100644 --- a/src/overlays/shared/mobys/update_moby_proximity_interaction.c +++ b/src/overlays/shared/mobys/update_moby_proximity_interaction.c @@ -1,4 +1,5 @@ /* Mobys: proximity interaction update. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/rendering/debug/debug_menu.h" #include "rnc/game/item_state.h" @@ -19,7 +20,6 @@ extern int D_L00_0015F5C4; extern char ship_proximity_local_offsets[] __asm__("D_L00_001BD880"); extern int D_L00_0015F630 __asm__("D_L00_0015F630"); -extern unsigned char D_0013CAE4[]; extern unsigned char l00_moby_followup_scene_gate[] __asm__("D_0013DD4B"); extern void start_scene(int) __asm__("FUN_L00_00298840"); extern void queue_scene_movie_with_game_language(int) __asm__("FUN_L00_00299460"); @@ -82,7 +82,7 @@ void update_moby_proximity_interaction(unsigned char *moby) { } if (*(short *)(proximity_state_data + 0xC) != 0) { int help_message_accepted = try_set_help_message(2, 0x53E4) != 0; - if ((*(int *)(((char *)&D_0013CAE4)) & 0x10) && help_message_accepted) { + if ((pad_pressed_words[0] & 0x10) && help_message_accepted) { if (current_level_index == 10 && hero.vehicle_mode == 1) { MOBY(moby)->state = 0x2A; MOBY(moby)->flags |= 0x41; diff --git a/src/overlays/shared/props/hydrodisplacer.c b/src/overlays/shared/props/hydrodisplacer.c index 61d4225a4e..307c26187b 100644 --- a/src/overlays/shared/props/hydrodisplacer.c +++ b/src/overlays/shared/props/hydrodisplacer.c @@ -162,7 +162,7 @@ void hydrodisplacer_update(Moby *moby) { if (pad_pressed_within(hero.items[0].button_mask, func_001F9850_2E0E50(8), 0) == 0) { break; } - if ((pad_held[0] & hero.items[0].button_mask) == 0) { + if ((pad_held_words[0] & hero.items[0].button_mask) == 0) { break; } if (hero.ground_moby == 0 || hero.air_frames.s != 0 || hero.ground_moby->oclass != 0x155) { diff --git a/src/overlays/shared/props/teleporter.c b/src/overlays/shared/props/teleporter.c index 4d95e5ecc7..1a05ddd22e 100644 --- a/src/overlays/shared/props/teleporter.c +++ b/src/overlays/shared/props/teleporter.c @@ -1,5 +1,6 @@ /* Shared moby class teleporter: activates, shows its children and draws its radius ring. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero.h" #include "rnc/globals.h" @@ -85,7 +86,6 @@ extern s32 D_0014C190[][64]; extern u8 D_0014C050[]; extern unsigned char D_0014C050[]; extern int alternate_animation_sequence_gp __asm__("D_0015EE20") __attribute__((sda)); -extern int D_0013CAE4[]; extern char *D_L01_0015FFD8; extern int D_L01_0015F594 __attribute__((sda)); extern float teleporter_child_motion_acceleration_gp __asm__("D_L01_00161F88") __attribute__((sda)); @@ -334,7 +334,7 @@ void teleporter_update(struct Moby *moby) { if (g->air_frames.s != 0) break; try_set_teleporter_help_message(moby); - if (!(D_0013CAE4[0] & 0x10)) + if (!(pad_pressed_words[0] & 0x10)) break; allocate_voice_for_target_entry(0, 0, (void *)moby); moby->state = 2; diff --git a/src/overlays/shared/props/trespasser_pad.c b/src/overlays/shared/props/trespasser_pad.c index d5f3ab5ef6..1ec4e67ef4 100644 --- a/src/overlays/shared/props/trespasser_pad.c +++ b/src/overlays/shared/props/trespasser_pad.c @@ -1,5 +1,7 @@ /* Shared moby class tresspasser_pad: the pad the hero uses the trespasser on, and its puzzle display. */ +#include "rnc/input/pad_globals.h" #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/camera/level_camera.h" #include "rnc/mobys/moby.h" #include "rnc/hero/hero.h" @@ -67,19 +69,6 @@ typedef struct Data { unsigned short h11E; } Data; -typedef struct Pad { - char p0[0x1A4]; - int i1A4; - char p1A8[0x18]; - union { - long l; - struct { - int lo; - int hi; - } w; - } b1C0; -} Pad; - typedef struct { int i0; char p4[0x20]; @@ -104,31 +93,29 @@ typedef struct { extern LevelCamera l02_camera_lui __asm__("D_L02_00167280") NOT_SDA; -extern char D_0013C940[]; -void draw_tresspasser_puzzle(char *moby) __asm__("FUN_L02_002d93e8"); +void draw_tresspasser_puzzle(char *moby) __asm__("FUN_L02_002d93e8"); extern int allocate_voice_for_target_entry(long, int, Moby *) __asm__("FUN_0022da68"); extern void func_L02_002DA728_2D9F08(Moby *) __asm__("FUN_L02_002d92f0"); extern void func_L02_002D9D48_2D9F08(void *, void *, Moby *) __asm__("FUN_L02_002d8910"); extern float advance_accelerated_scalar(float *, float *, float, float, float, float) __asm__("FUN_00213f38"); -extern void func_L02_002DA820_2D9F08(void) __asm__("FUN_L02_002d93e8"); -extern void func_L00_0025E590_2D9F08(Moby *, Data *) __asm__("FUN_L00_0025d538"); -extern float D_L02_001D33B0[4][4]; -extern Lvl D_L02_001BBB40_2D9F08 __asm__("D_L02_001BB830"); -extern int current_level_index_macro __asm__("D_0015ED84") MACRO_ADDR; -extern Vec_2D9F08 D_L02_00167440_2D9F08[] __asm__("D_L02_001673C0"); -extern float frame_time_sq_macro __asm__("D_0015ED70") MACRO_ADDR; -extern float frame_time_macro __asm__("D_0015ED6C") MACRO_ADDR; -extern int D_L02_0017EB08_lui __asm__("D_L02_0017EB08") NOT_SDA; -extern Idle D_L02_00179A10; -extern int D_L02_001BADE0_2D9F08[] __asm__("D_L02_001BAAD0"); -extern int D_L02_00161B1C_gp __asm__("D_L02_00161B1C") __attribute__((sda)); -extern int D_L02_00161AA8_gp __asm__("D_L02_00161AA8") __attribute__((sda)); -extern int D_L02_00161AA4_gp __asm__("D_L02_00161AA4") __attribute__((sda)); -extern int D_L02_00161AA0_gp __asm__("D_L02_00161AA0") __attribute__((sda)); -extern char D_0013E633_2D9F08[] __asm__("D_0013E533"); -extern int D_0013CAE4 NOT_SDA; +extern void func_L02_002DA820_2D9F08(void) __asm__("FUN_L02_002d93e8"); +extern void func_L00_0025E590_2D9F08(Moby *, Data *) __asm__("FUN_L00_0025d538"); +extern float D_L02_001D33B0[4][4]; +extern Lvl D_L02_001BBB40_2D9F08 __asm__("D_L02_001BB830"); +extern int current_level_index_macro __asm__("D_0015ED84") MACRO_ADDR; +extern Vec_2D9F08 D_L02_00167440_2D9F08[] __asm__("D_L02_001673C0"); +extern float frame_time_sq_macro __asm__("D_0015ED70") MACRO_ADDR; +extern float frame_time_macro __asm__("D_0015ED6C") MACRO_ADDR; +extern int D_L02_0017EB08_lui __asm__("D_L02_0017EB08") NOT_SDA; +extern Idle D_L02_00179A10; +extern int D_L02_001BADE0_2D9F08[] __asm__("D_L02_001BAAD0"); +extern int D_L02_00161B1C_gp __asm__("D_L02_00161B1C") __attribute__((sda)); +extern int D_L02_00161AA8_gp __asm__("D_L02_00161AA8") __attribute__((sda)); +extern int D_L02_00161AA4_gp __asm__("D_L02_00161AA4") __attribute__((sda)); +extern int D_L02_00161AA0_gp __asm__("D_L02_00161AA0") __attribute__((sda)); +extern char D_0013E633_2D9F08[] __asm__("D_0013E533"); extern void func_L00_002607A8_d92f0(void *a, float x) __asm__("FUN_L00_0025f730"); @@ -393,15 +380,16 @@ void tresspasser_pad_update(Moby *moby) { if (fast_dec_timer_s16(&pad_puzzle_state->h10)) { moby->state = 3; } - } else if (((Pad *)D_0013C940)->b1C0.l & 0xA00000000000) { + } else if (((struct PadStateWords *)&controller_state)->unmasked.held_pressed & + 0xA00000000000) { pad_puzzle_state->h11E |= 1; allocate_voice_for_target_entry(0, 0, moby); - if (((Pad *)D_0013C940)->b1C0.w.hi & 0x8000) { + if (((struct PadStateWords *)&controller_state)->unmasked.w.pressed & 0x8000) { pad_puzzle_state->fE4 = -(frame_time_macro * 6.2831855f); } else { pad_puzzle_state->fE4 = frame_time_macro * 6.2831855f; } - } else if (((Pad *)D_0013C940)->i1A4 & 0x1000) { + } else if (controller_state.pressed & 0x1000) { pad_puzzle_state->h11E |= 2; pad_puzzle_state->iE0 = pad_puzzle_state->iE0 - 1; if (pad_puzzle_state->iE0 == 0) { @@ -409,7 +397,7 @@ void tresspasser_pad_update(Moby *moby) { } else { allocate_voice_for_target_entry(1, 0, moby); } - } else if (((Pad *)D_0013C940)->i1A4 & 0x4000) { + } else if (controller_state.pressed & 0x4000) { pad_puzzle_state->h11E |= 2; pad_puzzle_state->iE0 = pad_puzzle_state->iE0 + 1; if (pad_puzzle_state->iE0 == 4) { @@ -422,7 +410,7 @@ void tresspasser_pad_update(Moby *moby) { set_hero_animation(0x58, 0, scale_game_frames(6)); } if (i != 12) { - if (((D_0013CAE4 & 0x10) && D_L02_00179A10.i0 == 0 && D_L02_00179A10.i24 == -1) || + if (((pad_pressed_lui & 0x10) && D_L02_00179A10.i0 == 0 && D_L02_00179A10.i24 == -1) || ((Hero *)(D_0013E633_2D9F08 + 0xE1D))->state.current != 0x72 || ((Hero *)(D_0013E633_2D9F08 + 0xE1D))->items[0].item_id != 0x1A) { moby->state = 1; diff --git a/src/overlays/shared/rendering/debug/update_debug_menu.c b/src/overlays/shared/rendering/debug/update_debug_menu.c index 5cdbc2b879..c2f32fe0fc 100644 --- a/src/overlays/shared/rendering/debug/update_debug_menu.c +++ b/src/overlays/shared/rendering/debug/update_debug_menu.c @@ -171,7 +171,7 @@ void draw_debug_text(s32 x, s32 y, s32 color, s32 text_address) { #include "rnc/input/pad_state.h" #include "rnc/rendering/debug/debug_menu.h" -extern struct PadStateWords D_0013C940; +#define controller_words (*(struct PadStateWords *)&controller_state) #include "rnc/overlay/shared/camera/level_camera.h" @@ -192,7 +192,7 @@ void update_debug_camera(void) { int moved; int free_look; DebugCameraTarget *target; - pad = &D_0013C940; + pad = &controller_words; moved = 0; if (pad->buttons.w.held & 0x800) return; @@ -205,7 +205,7 @@ void update_debug_camera(void) { { Vec4 step; if ((pad->buttons.held_pressed & 3) != 3) { - if (D_0013C940.buttons.w.held & 0x1000) { + if (controller_words.buttons.w.held & 0x1000) { if (free_look) { fast_vec_normalize(&step, l00_camera.unk350, g_debug_menu.movement_speed); fast_vec_add(l00_camera.pos.f, l00_camera.pos.f, &step); @@ -215,7 +215,7 @@ void update_debug_camera(void) { } moved = 1; } - if (D_0013C940.buttons.w.held & 0x4000) { + if (controller_words.buttons.w.held & 0x4000) { if (free_look) { fast_vec_normalize(&step, l00_camera.unk350, g_debug_menu.movement_speed); fast_vec_sub(l00_camera.pos.f, l00_camera.pos.f, &step); @@ -225,7 +225,7 @@ void update_debug_camera(void) { } moved = 1; } - if (D_0013C940.buttons.w.held & 1) { + if (controller_words.buttons.w.held & 1) { if (free_look) { fast_vec_normalize(&step, l00_camera.unk350 + 4, g_debug_menu.movement_speed); fast_vec_add(l00_camera.pos.f, l00_camera.pos.f, &step); @@ -235,7 +235,7 @@ void update_debug_camera(void) { } moved = 1; } - if (D_0013C940.buttons.w.held & 2) { + if (controller_words.buttons.w.held & 2) { if (free_look) { fast_vec_normalize(&step, l00_camera.unk350 + 4, g_debug_menu.movement_speed); fast_vec_sub(l00_camera.pos.f, l00_camera.pos.f, &step); @@ -256,9 +256,9 @@ void update_debug_camera(void) { g_debug_menu.movement_speed = 0; } - if (!(free_look && (D_0013C940.buttons.held_pressed & 3) == 3) && - (D_0013C940.buttons.w.held & 0xA000)) { - if (D_0013C940.buttons.w.held & 0x8000) + if (!(free_look && (controller_words.buttons.held_pressed & 3) == 3) && + (controller_words.buttons.w.held & 0xA000)) { + if (controller_words.buttons.w.held & 0x8000) g_debug_menu.yaw_speed -= 0.002f; else g_debug_menu.yaw_speed += 0.002f; @@ -288,8 +288,9 @@ void update_debug_camera(void) { g_debug_menu.yaw_speed = 0; } } - if ((D_0013C940.buttons.held_pressed & 3) == 3 && (D_0013C940.buttons.held_pressed & 0x5000)) { - if (D_0013C940.buttons.w.held & 0x1000) + if ((controller_words.buttons.held_pressed & 3) == 3 && + (controller_words.buttons.held_pressed & 0x5000)) { + if (controller_words.buttons.w.held & 0x1000) g_debug_menu.pitch_speed -= 0.002f; else g_debug_menu.pitch_speed += 0.002f; @@ -319,9 +320,9 @@ void update_debug_camera(void) { g_debug_menu.pitch_speed = 0; } - if (free_look && (D_0013C940.buttons.held_pressed & 3) == 3 && - (D_0013C940.buttons.held_pressed & 0xA000)) { - if (D_0013C940.buttons.w.held & 0x8000) + if (free_look && (controller_words.buttons.held_pressed & 3) == 3 && + (controller_words.buttons.held_pressed & 0xA000)) { + if (controller_words.buttons.w.held & 0x8000) g_debug_menu.roll_speed -= 0.002f; else g_debug_menu.roll_speed += 0.002f; @@ -350,8 +351,8 @@ void update_debug_camera(void) { g_debug_menu.roll_speed = 0; } - if (D_0013C940.buttons.held_pressed & 0xC) { - if (D_0013C940.buttons.w.held & 8) { + if (controller_words.buttons.held_pressed & 0xC) { + if (controller_words.buttons.w.held & 8) { g_debug_menu.vertical_speed += 0.004f; if (g_debug_menu.vertical_speed > 0.3f) g_debug_menu.vertical_speed = 0.3f; @@ -518,7 +519,7 @@ void update_debug_menu(void) { } scratch; s32 pressed; sound_update(); - pressed = D_0013C940.buttons.w.pressed; + pressed = controller_words.buttons.w.pressed; if (pressed & 0x500) { D_L00_0015F5C4 = g_debug_menu.unknown_a4; set_background_color(level_view_context.background_color[0], @@ -543,11 +544,11 @@ void update_debug_menu(void) { else if (g_debug_menu.selected_column == 2) g_debug_menu.selected_column = 5; } - if ((D_0013C940.buttons.w.pressed & 0x1000) && --g_debug_menu.selected_row < 0) { + if ((controller_words.buttons.w.pressed & 0x1000) && --g_debug_menu.selected_row < 0) { if (g_debug_menu.selected_column >= 3) g_debug_menu.selected_column = (g_debug_menu.selected_column + 3) % 6; g_debug_menu.selected_row = row_counts.rows[g_debug_menu.selected_column] - 1; - } else if (D_0013C940.buttons.w.pressed & 0x4000) { + } else if (controller_words.buttons.w.pressed & 0x4000) { if (++g_debug_menu.selected_row >= row_counts.rows[g_debug_menu.selected_column]) { if (g_debug_menu.selected_column < 3) g_debug_menu.selected_column = (g_debug_menu.selected_column + 9) % 6; @@ -558,7 +559,7 @@ void update_debug_menu(void) { g_debug_menu.selected_row = row_counts.rows[g_debug_menu.selected_column] - 1; switch (g_debug_menu.selected_column) { case DEBUG_COLUMN_UPDATE_FLAGS: - if (D_0013C940.buttons.w.pressed & 0x40) { + if (controller_words.buttons.w.pressed & 0x40) { s32 flag = 1 << g_debug_menu.selected_row; g_debug_menu.update_flags ^= flag; if (flag == 16) { @@ -572,12 +573,12 @@ void update_debug_menu(void) { case DEBUG_COLUMN_OPTIONS: switch (g_debug_menu.selected_row) { case DEBUG_OPTION_ROW_CONTROL_MODE: - if (D_0013C940.buttons.w.pressed & 0x50) { - if (D_0013C940.buttons.w.pressed & 0x40) { + if (controller_words.buttons.w.pressed & 0x50) { + if (controller_words.buttons.w.pressed & 0x40) { if (++g_debug_menu.control_mode >= 4) g_debug_menu.control_mode = 0; } - if (D_0013C940.buttons.w.pressed & 0x10) { + if (controller_words.buttons.w.pressed & 0x10) { if (--g_debug_menu.control_mode < 0) g_debug_menu.control_mode = 3; } @@ -606,11 +607,11 @@ void update_debug_menu(void) { } break; case DEBUG_OPTION_ROW_PROFILER_MODE: - if (D_0013C940.buttons.w.pressed & 0x40) { + if (controller_words.buttons.w.pressed & 0x40) { if (++g_debug_menu.profiler_mode >= 8) g_debug_menu.profiler_mode = 0; } - if (D_0013C940.buttons.w.pressed & 0x10) { + if (controller_words.buttons.w.pressed & 0x10) { if (--g_debug_menu.profiler_mode < 0) g_debug_menu.profiler_mode = 7; } @@ -620,25 +621,25 @@ void update_debug_menu(void) { g_debug_menu.occlusion_mode = 0; break; } - if (D_0013C940.buttons.w.pressed & 0x40) { + if (controller_words.buttons.w.pressed & 0x40) { if (++g_debug_menu.occlusion_mode >= 3) g_debug_menu.occlusion_mode = 0; } - if (D_0013C940.buttons.w.pressed & 0x10) { + if (controller_words.buttons.w.pressed & 0x10) { if (--g_debug_menu.occlusion_mode < 0) g_debug_menu.occlusion_mode = 2; } break; case DEBUG_OPTION_ROW_BOOKMARK: - if (D_0013C940.buttons.w.pressed & 0x50) + if (controller_words.buttons.w.pressed & 0x50) g_debug_menu.bookmark_enabled = !g_debug_menu.bookmark_enabled; break; case DEBUG_OPTION_ROW_INVINCIBILITY: - if (D_0013C940.buttons.w.pressed & 0x50) + if (controller_words.buttons.w.pressed & 0x50) g_debug_menu.invincibility_enabled = !g_debug_menu.invincibility_enabled; break; case DEBUG_OPTION_ROW_DRAW_DISTANCE_OVERRIDE: - if (D_0013C940.buttons.w.pressed & 0x50) { + if (controller_words.buttons.w.pressed & 0x50) { g_debug_menu.draw_distance_override = !g_debug_menu.draw_distance_override; if (g_debug_menu.draw_distance_override) { D_L00_00160F80 = 65536.0f; @@ -656,21 +657,21 @@ void update_debug_menu(void) { } break; case DEBUG_OPTION_ROW_COLLISION_MODE: - if (D_0013C940.buttons.w.pressed & 0x40) { + if (controller_words.buttons.w.pressed & 0x40) { if (++g_debug_menu.collision_mode >= 3) g_debug_menu.collision_mode = 0; } - if (D_0013C940.buttons.w.pressed & 0x10) { + if (controller_words.buttons.w.pressed & 0x10) { if (--g_debug_menu.collision_mode < 0) g_debug_menu.collision_mode = 2; } break; case DEBUG_OPTION_ROW_TELEVISION_MODE: - if (D_0013C940.buttons.w.pressed & 0x50) + if (controller_words.buttons.w.pressed & 0x50) g_debug_menu.television_mode = !g_debug_menu.television_mode; break; case DEBUG_OPTION_ROW_SCREEN_MODE: - if (D_0013C940.buttons.w.pressed & 0x50) { + if (controller_words.buttons.w.pressed & 0x50) { g_debug_menu.screen_mode = !g_debug_menu.screen_mode; if (g_debug_menu.screen_mode) { level_view_context.half_width = @@ -693,8 +694,8 @@ void update_debug_menu(void) { } break; case DEBUG_OPTION_ROW_SCENE_INDEX: - if (D_0013C940.buttons.w.pressed & 0x50) { - if (D_0013C940.buttons.w.pressed & 0x40) { + if (controller_words.buttons.w.pressed & 0x50) { + if (controller_words.buttons.w.pressed & 0x40) { g_debug_menu.scene_index++; while (g_debug_menu.scene_index == 36) g_debug_menu.scene_index = -1; @@ -710,8 +711,8 @@ void update_debug_menu(void) { g_debug_menu.unknown_a4 = 0; break; case DEBUG_OPTION_ROW_SEGMENT_INDEX: - if (D_0013C940.buttons.w.pressed & 0x50) { - if (D_0013C940.buttons.w.pressed & 0x40) { + if (controller_words.buttons.w.pressed & 0x50) { + if (controller_words.buttons.w.pressed & 0x40) { g_debug_menu.segment_index++; while (g_debug_menu.segment_index == 16) g_debug_menu.segment_index = 0; @@ -720,7 +721,7 @@ void update_debug_menu(void) { while (g_debug_menu.segment_index < 0) g_debug_menu.segment_index = 15; } - } else if (D_0013C940.buttons.w.pressed & 0x20) { + } else if (controller_words.buttons.w.pressed & 0x20) { s32 mission = g_debug_menu.segment_index; s32 index = mission + (current_level_index << 4); u8 *visited = visited52 + index; @@ -731,7 +732,7 @@ void update_debug_menu(void) { } break; case DEBUG_COLUMN_DRAW_FLAGS: - if (D_0013C940.buttons.w.pressed & 0x40) + if (controller_words.buttons.w.pressed & 0x40) g_debug_menu.draw_flags ^= 1 << g_debug_menu.selected_row; break; case DEBUG_COLUMN_ITEM_COUNTS: { @@ -744,37 +745,37 @@ void update_debug_menu(void) { } else { count = ¤t_bolt_count; } - if (D_0013C940.buttons.w.held & 8) { - if (D_0013C940.buttons.w.pressed & 0x40) + if (controller_words.buttons.w.held & 8) { + if (controller_words.buttons.w.pressed & 0x40) *count += 60; - if (D_0013C940.buttons.w.pressed & 0x20) { + if (controller_words.buttons.w.pressed & 0x20) { if (*count > 60) *count -= 60; else *count = 0; } - } else if (D_0013C940.buttons.w.held & 2) { - if (D_0013C940.buttons.w.pressed & 0x40) + } else if (controller_words.buttons.w.held & 2) { + if (controller_words.buttons.w.pressed & 0x40) *count += 600; - if (D_0013C940.buttons.w.pressed & 0x20) { + if (controller_words.buttons.w.pressed & 0x20) { if (*count > 600) *count -= 600; else *count = 0; } } else { - if (D_0013C940.buttons.w.pressed & 0x40) + if (controller_words.buttons.w.pressed & 0x40) *count += 1; - if (D_0013C940.buttons.w.pressed & 0x20) { + if (controller_words.buttons.w.pressed & 0x20) { if (*count > 0) *count -= 1; } } if (*count > limit) *count = limit; - if (D_0013C940.buttons.w.pressed & 0x10) + if (controller_words.buttons.w.pressed & 0x10) item_text_variant[debug_menu_item_ids[g_debug_menu.selected_row]]++; - if (D_0013C940.buttons.w.pressed & 0x80) + if (controller_words.buttons.w.pressed & 0x80) item_text_variant[debug_menu_item_ids[g_debug_menu.selected_row]]--; { s32 item = debug_menu_item_ids[g_debug_menu.selected_row]; @@ -787,7 +788,7 @@ void update_debug_menu(void) { } case DEBUG_COLUMN_FOG: if (g_debug_menu.selected_row == 0) { - u64 buttons = D_0013C940.buttons.held_pressed; + u64 buttons = controller_words.buttons.held_pressed; if (buttons & 0x800000040ULL) D_L00_0015F448 += 1024.0f; if (buttons & 0x400000010ULL) @@ -798,7 +799,7 @@ void update_debug_menu(void) { D_L00_0015F448 = 0.0f; } if (g_debug_menu.selected_row == 2) { - u64 buttons = D_0013C940.buttons.held_pressed; + u64 buttons = controller_words.buttons.held_pressed; if (buttons & 0x800000040ULL) D_L00_0015F44C += 1024.0f; if (buttons & 0x400000010ULL) @@ -809,7 +810,7 @@ void update_debug_menu(void) { D_L00_0015F44C = D_L00_0015F448; } if (g_debug_menu.selected_row == 1) { - u64 buttons = D_0013C940.buttons.held_pressed; + u64 buttons = controller_words.buttons.held_pressed; if (buttons & 0x800000040ULL) D_L00_0015F450 -= 2.55f; if (buttons & 0x400000010ULL) @@ -820,7 +821,7 @@ void update_debug_menu(void) { D_L00_0015F450 = 0.0f; } if (g_debug_menu.selected_row == 3) { - u64 buttons = D_0013C940.buttons.held_pressed; + u64 buttons = controller_words.buttons.held_pressed; if (buttons & 0x800000040ULL) D_L00_0015F454 -= 2.55f; if (buttons & 0x400000010ULL) @@ -831,31 +832,31 @@ void update_debug_menu(void) { D_L00_0015F454 = 0.0f; } if (g_debug_menu.selected_row == 4) { - if (D_L00_0015F444 < 255 && (D_0013C940.buttons.held_pressed & 0x800000040ULL)) + if (D_L00_0015F444 < 255 && (controller_words.buttons.held_pressed & 0x800000040ULL)) ++D_L00_0015F444; - if (D_L00_0015F444 > 0 && (D_0013C940.buttons.held_pressed & 0x400000010ULL)) + if (D_L00_0015F444 > 0 && (controller_words.buttons.held_pressed & 0x400000010ULL)) --D_L00_0015F444; } if (g_debug_menu.selected_row == 5) { - if (D_L00_0015F445 < 255 && (D_0013C940.buttons.held_pressed & 0x800000040ULL)) + if (D_L00_0015F445 < 255 && (controller_words.buttons.held_pressed & 0x800000040ULL)) ++D_L00_0015F445; - if (D_L00_0015F445 > 0 && (D_0013C940.buttons.held_pressed & 0x400000010ULL)) + if (D_L00_0015F445 > 0 && (controller_words.buttons.held_pressed & 0x400000010ULL)) --D_L00_0015F445; } if (g_debug_menu.selected_row == 6) { - if (D_L00_0015F446 < 255 && (D_0013C940.buttons.held_pressed & 0x800000040ULL)) + if (D_L00_0015F446 < 255 && (controller_words.buttons.held_pressed & 0x800000040ULL)) ++D_L00_0015F446; - if (D_L00_0015F446 > 0 && (D_0013C940.buttons.held_pressed & 0x400000010ULL)) + if (D_L00_0015F446 > 0 && (controller_words.buttons.held_pressed & 0x400000010ULL)) --D_L00_0015F446; } update_fog(); break; case DEBUG_COLUMN_CAMERA_ACTUATOR_AND_CAPTURE: - if (g_debug_menu.selected_row == 0 && (D_0013C940.buttons.w.pressed & 0x50)) + if (g_debug_menu.selected_row == 0 && (controller_words.buttons.w.pressed & 0x50)) g_debug_menu.battle_camera_enabled = !g_debug_menu.battle_camera_enabled; - if (g_debug_menu.selected_row == 1 && (D_0013C940.buttons.w.pressed & 0x50)) + if (g_debug_menu.selected_row == 1 && (controller_words.buttons.w.pressed & 0x50)) g_debug_menu.actuator_enabled = !g_debug_menu.actuator_enabled; - if (g_debug_menu.selected_row == 2 && (D_0013C940.buttons.w.pressed & 0xF0)) { + if (g_debug_menu.selected_row == 2 && (controller_words.buttons.w.pressed & 0xF0)) { char *directory = level_directory_macro; char *path_format = level_file_path_format_gp; s32 i = 0, found, fd, size; @@ -926,7 +927,7 @@ void update_debug_menu(void) { } } } - if (g_debug_menu.selected_row == 3 && (D_0013C940.buttons.w.pressed & 0xF0)) { + if (g_debug_menu.selected_row == 3 && (controller_words.buttons.w.pressed & 0xF0)) { s32 fd; sprintf(scratch.start_point.path, level_file_path_format, diff --git a/src/overlays/shared/ui/hud/draw_hud_item_selector_panel.c b/src/overlays/shared/ui/hud/draw_hud_item_selector_panel.c index b5570f168f..b7cbe63df7 100644 --- a/src/overlays/shared/ui/hud/draw_hud_item_selector_panel.c +++ b/src/overlays/shared/ui/hud/draw_hud_item_selector_panel.c @@ -1,5 +1,6 @@ /* HUD panels: item and radial selectors, health, bolt counter and gauges. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/ui/vendor/vendor_item_info.h" #include "rnc/hero/hero.h" #include "rnc/globals.h" @@ -201,20 +202,6 @@ typedef struct { int w7C; } Obj; -typedef struct { - u8 p0[0x148]; - float unk148; - float unk14C; - u8 p150[0x70]; - int w1C0; - int w1C4; - u8 p1C8[4]; - int w1CC; - u8 p1D0[8]; - int w1D8; -} G_t; - -extern G_t D_0013C940; extern int D_L00_0017E504 NOT_SDA; extern int D_L00_0015FA90; extern int D_L00_0015F780_gp __asm__("D_L00_0015F780") __attribute__((sda)); @@ -260,9 +247,9 @@ void update_hud_item_selector_selection_and_visibility(Obj *hud_element) { hud_element->w7C = scale_game_frames(0xB4); hud_element->w6C = 0x18; if (fast_dec_timer_s16(D_00141622)) - D_0013C940.w1CC = 2; - x = D_0013C940.unk148; - y = D_0013C940.unk14C; + controller_state.mode = 2; + x = controller_state.analog_prev[2]; + y = controller_state.analog_prev[3]; mag = square_root(x * x + y * y); if (mag != 0.0f) { x /= mag; @@ -270,14 +257,15 @@ void update_hud_item_selector_selection_and_visibility(Obj *hud_element) { } stick_angle = fast_arc_tan(x, y); if ((hud_element->w78 >> 24) == 0) { - if ((D_0013C940.w1C4 & 0xF000) || mag < 0.5f || --hud_element->w78 == -1) { + if ((((s32)controller_state.pressed_unmasked) & 0xF000) || mag < 0.5f || + --hud_element->w78 == -1) { hud_element->w74 = -1; hud_element->w78 = 0x10000FF; } } slot_step = 0; previous_selected_slot_index = hud_element->w74; - if ((hud_element->w78 >> 24) == 1 && (D_0013C940.w1C0 & 0x10)) { + if ((hud_element->w78 >> 24) == 1 && (((s32)controller_state.held_unmasked) & 0x10)) { if (mag > 0.9f) { a = stick_angle + 3.1415927f + 3.1415927f + 1.5707964f + 3.1415927f / (float)D_L00_0015FA90; @@ -305,10 +293,11 @@ void update_hud_item_selector_selection_and_visibility(Obj *hud_element) { if (hud_item_selector_slot_angle_offset_gp > 0.0f) slot_step = 1; } - } else if (D_0013C940.w1D8 == 0 && (D_0013C940.w1C4 & 0xF000)) { + } else if (controller_state.stick_moved == 0 && + (((s32)controller_state.pressed_unmasked) & 0xF000)) { int pad_slot_index; pad_slot_index = previous_selected_slot_index; - if (D_0013C940.w1C4 & 0x1000) { + if (((s32)controller_state.pressed_unmasked) & 0x1000) { int slot_lookup; if (pad_slot_index == -1) slot_lookup = D_L00_0017DC20; @@ -316,7 +305,7 @@ void update_hud_item_selector_selection_and_visibility(Obj *hud_element) { slot_lookup = D_L00_0015FAC0_c[D_L00_0015F72C][pad_slot_index].unk10; pad_slot_index = slot_lookup; } - if (D_0013C940.w1C4 & 0x4000) { + if (((s32)controller_state.pressed_unmasked) & 0x4000) { int slot_lookup; if (pad_slot_index == -1) slot_lookup = D_L00_0017DC24; @@ -324,7 +313,7 @@ void update_hud_item_selector_selection_and_visibility(Obj *hud_element) { slot_lookup = D_L00_0015FAC0_c[D_L00_0015F72C][pad_slot_index].unk14; pad_slot_index = slot_lookup; } - if (D_0013C940.w1C4 & 0x8000) { + if (((s32)controller_state.pressed_unmasked) & 0x8000) { int slot_lookup; if (pad_slot_index == -1) slot_lookup = D_L00_0017DC18; @@ -332,7 +321,7 @@ void update_hud_item_selector_selection_and_visibility(Obj *hud_element) { slot_lookup = D_L00_0015FAC0_c[D_L00_0015F72C][pad_slot_index].unk8; pad_slot_index = slot_lookup; } - if (D_0013C940.w1C4 & 0x2000) { + if (((s32)controller_state.pressed_unmasked) & 0x2000) { int slot_lookup; if (pad_slot_index == -1) slot_lookup = D_L00_0017DC1C; @@ -356,7 +345,7 @@ void update_hud_item_selector_selection_and_visibility(Obj *hud_element) { counters[1] = 0; else if (counters[1] < D_L00_0015F780_gp) counters[1]++; - if (!(D_0013C940.w1C0 & 0x10)) { + if (!(((s32)controller_state.held_unmasked) & 0x10)) { int sel = hud_element->w74; if (sel >= 0 && (id = D_L00_0015FAC0_c[D_L00_0015F72C][sel].unk18) != 0) { VendorItemInfo *rr; @@ -635,9 +624,9 @@ void update_hud_radial_selector_selection_and_visibility(Obj *hud_element) { hud_element->w7C = scale_game_frames(0xB4); hud_element->w6C = 0x18; - D_0013C940.w1CC = 2; - x = D_0013C940.unk148; - y = D_0013C940.unk14C; + controller_state.mode = 2; + x = controller_state.analog_prev[2]; + y = controller_state.analog_prev[3]; input_magnitude = square_root(x * x + y * y); if (input_magnitude != 0.0f) { x /= input_magnitude; @@ -645,7 +634,8 @@ void update_hud_radial_selector_selection_and_visibility(Obj *hud_element) { } selection_angle = fast_arc_tan(x, y); if ((hud_element->w78 >> 24) == 0 && D_L00_0017E504 != 0) { - if ((D_0013C940.w1C4 & 0xF000) || input_magnitude < 0.5f || --hud_element->w78 == -1) { + if ((((s32)controller_state.pressed_unmasked) & 0xF000) || input_magnitude < 0.5f || + --hud_element->w78 == -1) { hud_element->w74 = -1; hud_element->w78 = 0x10000FF; } @@ -659,30 +649,30 @@ void update_hud_radial_selector_selection_and_visibility(Obj *hud_element) { ((float)slot_count / 6.2831855f)) % slot_count; } - if (D_0013C940.w1C4 & 0xF000) { + if (((s32)controller_state.pressed_unmasked) & 0xF000) { pad_slot_index = hud_element->w74; - if (D_0013C940.w1C4 & 0x1000) { + if (((s32)controller_state.pressed_unmasked) & 0x1000) { if (pad_slot_index == -1) next_slot_index = D_L00_0017DC40; else next_slot_index = D_L00_0015FAC0_c[D_L00_0015F72C][pad_slot_index].unk10; pad_slot_index = next_slot_index; } - if (D_0013C940.w1C4 & 0x4000) { + if (((s32)controller_state.pressed_unmasked) & 0x4000) { if (pad_slot_index == -1) next_slot_index = D_L00_0017DC44; else next_slot_index = D_L00_0015FAC0_c[D_L00_0015F72C][pad_slot_index].unk14; pad_slot_index = next_slot_index; } - if (D_0013C940.w1C4 & 0x8000) { + if (((s32)controller_state.pressed_unmasked) & 0x8000) { if (pad_slot_index == -1) next_slot_index = D_L00_0017DC38; else next_slot_index = D_L00_0015FAC0_c[D_L00_0015F72C][pad_slot_index].unk8; pad_slot_index = next_slot_index; } - if (D_0013C940.w1C4 & 0x2000) { + if (((s32)controller_state.pressed_unmasked) & 0x2000) { if (pad_slot_index == -1) next_slot_index = D_L00_0017DC3C; else @@ -697,7 +687,7 @@ void update_hud_radial_selector_selection_and_visibility(Obj *hud_element) { } else if (counters[1] < D_L00_0015F780_gp) { counters[1]++; } - if (!(D_0013C940.w1C0 & 0x10)) { + if (!(((s32)controller_state.held_unmasked) & 0x10)) { if (hud_element->w74 == -1) D_00141610[0] = 0; else diff --git a/src/overlays/shared/ui/menus/initialize_pause_menu.c b/src/overlays/shared/ui/menus/initialize_pause_menu.c index dacba7c129..7a6db104f4 100644 --- a/src/overlays/shared/ui/menus/initialize_pause_menu.c +++ b/src/overlays/shared/ui/menus/initialize_pause_menu.c @@ -1,5 +1,6 @@ /* Pause menu: init, update, page drawing and close. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/game/overlay_game_state.h" #include "rnc/globals.h" #include "asm.h" @@ -911,13 +912,6 @@ void draw_pause_menu_pages(int transfer_only) { do_gif_paging(); } -typedef struct { - char pad0[0x1C4]; - int flags; -} E_2779c8; - -extern E_2779c8 D_0013C940_lui __asm__("D_0013C940") NOT_SDA; - int process_active_menu_object_actions(int x) __asm__("FUN_L00_002779c8"); int process_active_menu_object_actions(int x) { @@ -926,10 +920,10 @@ int process_active_menu_object_actions(int x) { if ((s32)D_L00_001B9CF0.owner->unk40 != x) { return 0; } - if ((D_0013C940_lui.flags & 0xD00) && D_L00_001B9CF0.unk124 == 0) { + if ((((s32)controller_state_lui.pressed_unmasked) & 0xD00) && D_L00_001B9CF0.unk124 == 0) { return 1; } - if (D_0013C940_lui.flags & 0x10) { + if (((s32)controller_state_lui.pressed_unmasked) & 0x10) { transition_owner = (s32)D_L00_001B9CF0.owner->unk38; if (transition_owner != 0) { D_L00_001B9CF0.unk8 = (struct Own *)transition_owner; diff --git a/src/overlays/shared/ui/menus/pause_menu_entry_input.c b/src/overlays/shared/ui/menus/pause_menu_entry_input.c index 226b3721e6..b466b8318b 100644 --- a/src/overlays/shared/ui/menus/pause_menu_entry_input.c +++ b/src/overlays/shared/ui/menus/pause_menu_entry_input.c @@ -1,5 +1,6 @@ /* Pause menu: entry input. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/game/overlay_game_state.h" #include "asm.h" #include "rnc/data_labels.h" @@ -8,19 +9,12 @@ #include "rnc/globals.h" #include "sda.h" -typedef struct { - char pad[0x1C4]; - volatile s32 f1C4; -} G_7c410; - -extern G_7c410 D_0013C940_7c410 __asm__("D_0013C940"); - extern s32 D_L00_00184414 NOT_SDA; s32 pause_menu_entry_input(s32 object_address) __asm__("FUN_L00_0027c410"); s32 pause_menu_entry_input(s32 object_address) { - s32 flags_snapshot = D_0013C940_7c410.f1C4; - s32 owner_unk38_address; + s32 flags_snapshot = ((s32)((volatile struct PadState *)&controller_state)->pressed_unmasked); + s32 owner_unk38_address; struct GameState *game_state; if (flags_snapshot & 0xD00) { if (*(s32 *)(object_address + 0x30) & 0x20) { @@ -40,7 +34,7 @@ s32 pause_menu_entry_input(s32 object_address) { return -1; } } - if (D_0013C940_7c410.f1C4 & 0x20) { + if (((s32)((volatile struct PadState *)&controller_state)->pressed_unmasked) & 0x20) { D_0013D384 = 0; D_L00_0015F5C0 = -1; D_L00_0015F570 = 1; diff --git a/src/overlays/shared/ui/menus/process_unlock_code_input.c b/src/overlays/shared/ui/menus/process_unlock_code_input.c index 6cb343c274..991c1e6673 100644 --- a/src/overlays/shared/ui/menus/process_unlock_code_input.c +++ b/src/overlays/shared/ui/menus/process_unlock_code_input.c @@ -1,5 +1,6 @@ /* Menus: unlock code input. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "asm.h" #include "rnc/game/item_state.h" #include "rnc/audio/voices/allocate_voice_for_bank_entry.h" @@ -25,18 +26,17 @@ extern char D_0013D388[]; extern short unlock_code_input_count __asm__("D_L00_001603F8") __attribute__((sda)); extern short unlock_code_input_sequence[] __asm__("D_L00_001BA4A8"); extern unsigned char D_0013A4E0[]; -extern unsigned char D_0013C940[]; extern unsigned char l00_unlock_code_comparison_table[] __asm__("D_L00_001B9BA0"); void process_unlock_code_input(void) __asm__("FUN_L00_002831c0"); void process_unlock_code_input(void) { - char *pad = (char *)((char *)&D_0013C940); - int staged_candidate_index_limit, candidate_index_limit; - int va, vb, vc; - int pressed, direction, count, j, code, index, matched; - if ((*(long *)(pad + 0x1C0) & 0xF) == 6) { - pressed = *(int *)(pad + 0x1C4); + struct PadState *pad = &controller_state; + int staged_candidate_index_limit, candidate_index_limit; + int va, vb, vc; + int pressed, direction, count, j, code, index, matched; + if ((*(long *)&pad->held_unmasked & 0xF) == 6) { + pressed = *(s32 *)&pad->pressed_unmasked; if (!(pressed & 0xF0A0)) return; diff --git a/src/overlays/shared/vehicles/giant_clank_pad.c b/src/overlays/shared/vehicles/giant_clank_pad.c index 34f4979cff..0d55e8dea8 100644 --- a/src/overlays/shared/vehicles/giant_clank_pad.c +++ b/src/overlays/shared/vehicles/giant_clank_pad.c @@ -1,5 +1,6 @@ /* Shared moby class giant_clank_pad: the pad where the hero becomes Giant Clank. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero.h" #include "rnc/mobys/moby.h" @@ -16,11 +17,10 @@ extern void request_music_track(int, int) __asm__("FUN_L01_0027a248"); extern void set_race_camera(void *, void *, int, int) __asm__("FUN_L00_00216f90"); extern void enter_hero_vehicle_mode(int, int, struct Moby *) __asm__("FUN_L00_00210a08"); -extern int D_L15_0015F5C4; -extern struct Moby *l15_moby_array __asm__("D_L15_0015FFD8"); -extern int D_L15_0015F594 __attribute__((sda)); -extern u8 D_0014C050[]; -extern u32 D_0013CAE4 NOT_SDA; +extern int D_L15_0015F5C4; +extern struct Moby *l15_moby_array __asm__("D_L15_0015FFD8"); +extern int D_L15_0015F594 __attribute__((sda)); +extern u8 D_0014C050[]; void giant_clank_pad_update(struct Moby *moby) __asm__("FUN_L15_002ed068"); @@ -68,7 +68,7 @@ void giant_clank_pad_update(struct Moby *moby) { } else if (hero.vehicle_mode == 2 && current_level_index != 0x12) { try_set_help_message(4, 0x3aa5); } - if (!(D_0013CAE4 & 0x10)) + if (!(((u32)pad_pressed_lui) & 0x10)) return; if (D_L15_0015F594 != 4) return; diff --git a/src/overlays/shared/vendor/vendor.c b/src/overlays/shared/vendor/vendor.c index d2b62cff88..c494c70c34 100644 --- a/src/overlays/shared/vendor/vendor.c +++ b/src/overlays/shared/vendor/vendor.c @@ -1,4 +1,5 @@ /* Shared moby class vendor: the Gadgetron vendor and its effects. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero.h" #include "rnc/math/fast_math.h" @@ -99,7 +100,6 @@ void draw_offset_textured_effect_quad(void *, int, float, float) __asm__( extern void draw_geometry_quad(void *, void *, int) __asm__("FUN_001f7d30"); extern V_2a57a8 hero_pos __asm__("D_0013F3D0") NOT_SDA; -extern s32 D_0013CAE4_lui __asm__("D_0013CAE4") NOT_SDA; extern s32 D_L00_0015F5CC_2a57a8 __asm__("D_L00_0015F5CC"); void FUN_L00_002a5040_2a57a8(void) __asm__("FUN_L00_002a5040"); @@ -404,7 +404,7 @@ void vendor_update(P_2a57a8 *vendor_moby) { help_message_succeeded = 0; if (help_message_allowed) help_message_succeeded = try_set_help_message(1, 0x53E3) != 0; - if ((D_0013CAE4_lui & 0x10) && interaction_allowed && help_message_succeeded) { + if ((pad_pressed_lui & 0x10) && interaction_allowed && help_message_succeeded) { open_vendor_menu(vendor_moby); vendor_moby->b20 = 3; } diff --git a/src/overlays/shared/vendor/vendor_menu.c b/src/overlays/shared/vendor/vendor_menu.c index 053ba8954c..e5b55b0f83 100644 --- a/src/overlays/shared/vendor/vendor_menu.c +++ b/src/overlays/shared/vendor/vendor_menu.c @@ -1,4 +1,5 @@ /* Vendor menu: loads the vendor moby assets, builds the item rows, opens, updates and closes the menu, handles purchases and plays the exit cutscene. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "sda.h" #include "rnc/overlay/shared/world/level_globals.h" @@ -1151,22 +1152,22 @@ void update_vendor_menu(void) { case VENDOR_MENU_CLOSING: if (vendor_menu.mode == 0 || vendor_menu.state == 2) { if ((g_debug_menu.update_flags & 2) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { reset_frame_counters(); } if ((g_debug_menu.update_flags & 2) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { update_visible_mobys(); FUN_0022dc50(); } noop_main_callback(vendor_moby_update_label, 3); if ((g_debug_menu.update_flags & 1) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { coordinate_hero_frame_update(); } noop_main_callback(vendor_hero_update_label, 7); if ((g_debug_menu.update_flags & 4) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { update_parts(); } noop_main_callback(vendor_part_update_label, 5); @@ -1224,7 +1225,7 @@ void update_vendor_menu(void) { } FUN_00201a28(); if ((g_debug_menu.update_flags & 2) || - ((g_debug_menu.update_flags & 0x10) && (D_0013CAE4 & 0x200))) { + ((g_debug_menu.update_flags & 0x10) && (((u32)pad_pressed_lui) & 0x200))) { update_game_frame_and_idle_counters(); } break; diff --git a/src/overlays/shared/weapons/bomb_glove.c b/src/overlays/shared/weapons/bomb_glove.c index 5b3a94a62b..39f6131686 100644 --- a/src/overlays/shared/weapons/bomb_glove.c +++ b/src/overlays/shared/weapons/bomb_glove.c @@ -1,5 +1,6 @@ /* Shared moby class bomb_glove: the bomb glove held by the hero, which aims the throw arc and throws bombs. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/hero/hero.h" #include "rnc/globals.h" @@ -66,10 +67,8 @@ extern CollisionHit coll_hit __asm__("D_L00_00173E40") NOT_SDA; extern f32 frame_time MACRO_ADDR; extern f32 frame_time_sq_macro __asm__("D_0015ED70") MACRO_ADDR; extern s32 D_0015EEA4; -extern u32 D_0013CAE4 NOT_SDA; extern LevelCamera l00_camera_lui __asm__("D_L00_00166C80") NOT_SDA; extern CollisionHit coll_hit __asm__("D_L00_00173E40"); -extern s32 pad_held_lui[] __asm__("D_0013CAE0") NOT_SDA; extern u8 bomb_glove_aimed_range_modifier[] __asm__("D_0013E52A"); extern struct Moby *D_L00_001ABA00_lui[] __asm__("D_L00_001ABA00") NOT_SDA; extern float frame_time_sq_macro __asm__("D_0015ED70") MACRO_ADDR; @@ -144,7 +143,7 @@ void aim_throw_arc(V2c2488 *origin_position, *(s32 *)&throw_velocity[2] = 0; throw_velocity[2] = FUN_L00_0025abf0(origin_position, &effective_target_position, horizontal_speed, -speed, 0); - if (pad_held_lui[0] & 5) { + if (pad_held_words_lui[0] & 5) { k = scale_ticks(bomb_glove_aimed_range_modifier[0]) * 2.5f + 8.5f; k = k / horizontal_speed; } else { @@ -208,7 +207,7 @@ void bomb_glove_update(struct Moby *moby) { hero_set_state(0x1E, 1); if (fast_dec_timer(&bomb_glove_vars->timer) && !hero.item_use_locked) { if ((hero.item_anim_active && hero.item_anim_frames == scale_game_frames(0x11)) || - ((D_0013CAE4 & hero.items[0].button_mask) && hero.state.current == 0x1E && + ((((u32)pad_pressed_lui) & hero.items[0].button_mask) && hero.state.current == 0x1E && get_ammo(-1)) || (hero.state.current == 0x23 && hero.state_timer == scale_game_frames(0x10))) { allocate_hero_voice_for_entry(0x1A, 0); diff --git a/src/overlays/shared/weapons/bomb_glove_bomb.c b/src/overlays/shared/weapons/bomb_glove_bomb.c index e8a1ff7690..b2e8b434c9 100644 --- a/src/overlays/shared/weapons/bomb_glove_bomb.c +++ b/src/overlays/shared/weapons/bomb_glove_bomb.c @@ -904,7 +904,7 @@ void launch_bomb(float *pos, unsigned char *moby, float *velocity) { } total = frame_time_sq * 11.0f; rp = throw_arc_velocity; - if (pad_held[0] & 5) { + if (pad_held_words[0] & 5) { height = convert_integer_to_float(D_0013E520.bA) * 2.5f + 8.5f; } else { height = 8.5f; diff --git a/src/overlays/shared/weapons/decoy_glove.c b/src/overlays/shared/weapons/decoy_glove.c index fb7c14ba4c..6dfd3447db 100644 --- a/src/overlays/shared/weapons/decoy_glove.c +++ b/src/overlays/shared/weapons/decoy_glove.c @@ -1,4 +1,5 @@ /* Shared moby class decoy_glove. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/mobys/moby.h" #include "rnc/hero/hero.h" @@ -87,7 +88,6 @@ extern void mine_spawn_drops(void *, void *) __asm__("FUN_L00_0025f800"); extern int allocate_voice_for_target_entry(int, int, void *) __asm__("FUN_0022da68"); extern void mark_moby_for_removal() __asm__("FUN_0020c828"); extern u8 D_0013E539_lui __asm__("D_0013E539") NOT_SDA; -extern char D_0013CAE4[]; /* Same camera step as func_L00_002C88A8, writing the following vector in the target data. */ /* Ported from rac1-decomp (src/overlays/shared/vendor_002D1168.c: func_L00_002D3608), where it is exact; names translated to the US level program. */ @@ -261,7 +261,7 @@ void decoy_glove_update(unsigned char *moby) { if (hero_data->item_anim_active && hero_data->item_anim_frames == scale_game_frames(0x11)) goto L3D10; - if (*(int *)(((char *)&D_0013CAE4)) & hero_data->items[0].button_mask) { + if (pad_pressed_words[0] & hero_data->items[0].button_mask) { if (hero_data->state.current == 0x1E && get_ammo(-1)) goto L3D10; } diff --git a/src/overlays/shared/weapons/glove_of_doom.c b/src/overlays/shared/weapons/glove_of_doom.c index 266a43194f..8a12048f8c 100644 --- a/src/overlays/shared/weapons/glove_of_doom.c +++ b/src/overlays/shared/weapons/glove_of_doom.c @@ -107,7 +107,6 @@ extern CollisionHit coll_hit __asm__("D_L00_00173E40") NOT_SDA; extern f32 frame_time MACRO_ADDR; extern f32 frame_time_sq_macro __asm__("D_0015ED70") MACRO_ADDR; extern s32 D_0015EEA4; -extern u32 D_0013CAE4 NOT_SDA; extern CollisionHit coll_hit __asm__("D_L00_00173E40"); extern float frame_time_sq_macro __asm__("D_0015ED70") MACRO_ADDR; extern DeliveryStats D_00141680; @@ -159,7 +158,7 @@ void compute_glove_of_doom_launch_velocity(V2c7320 *origin_position, *(s32 *)&launch_velocity[2] = 0; launch_velocity[2] = fn_2c7320(origin_position, &effective_target_position, horizontal_speed, -speed, 0); - if (pad_held[0] & 5) { + if (pad_held_words[0] & 5) { k = 3.5f / horizontal_speed; } else { k = 2.5f / horizontal_speed; @@ -316,7 +315,7 @@ void glove_of_doom_update(struct Moby *moby) { } if (fast_dec_timer(&glove_carrier_vars->timer) && !hero.item_use_locked) { if ((hero.item_anim_active && hero.item_anim_frames == scale_game_frames(0x11)) || - ((D_0013CAE4 & hero.items[0].button_mask) && hero.state.current == 0x1E && + ((((u32)pad_pressed_lui) & hero.items[0].button_mask) && hero.state.current == 0x1E && get_ammo(-1)) || (hero.state.current == 0x23 && hero.state_timer == scale_game_frames(0x10))) { allocate_hero_voice_for_entry(0x1A, 0); diff --git a/src/overlays/shared/weapons/metal_detector.c b/src/overlays/shared/weapons/metal_detector.c index 027df8e46b..bb21070aff 100644 --- a/src/overlays/shared/weapons/metal_detector.c +++ b/src/overlays/shared/weapons/metal_detector.c @@ -112,8 +112,6 @@ extern void spawn_bolt_by_value(void *, void *, void *, s32, s32, s32) __asm__(" extern void mark_moby_for_removal(void *) __asm__("FUN_0020c828"); extern void FUN_L00_002d2a90_u(void) __asm__("FUN_L00_002d2a90"); -extern struct PadState controller_state_lui __asm__("D_0013C940") NOT_SDA; - /* Ported from rac1-decomp src/overlays/shared/vendor_002D1168.c (func_L00_002D3F40) */ /* Draws the trail of fading ring sprites for a moby. */ diff --git a/src/overlays/shared/weapons/mine_glove.c b/src/overlays/shared/weapons/mine_glove.c index bff48bb9dc..5584bd02ca 100644 --- a/src/overlays/shared/weapons/mine_glove.c +++ b/src/overlays/shared/weapons/mine_glove.c @@ -1,5 +1,6 @@ /* Shared moby class mine_glove: the mine glove held by the hero, with its launch velocity. */ +#include "rnc/input/pad_globals.h" #include "types.h" #include "rnc/game/item_state.h" #include "rnc/game/game_globals.h" @@ -68,16 +69,15 @@ extern void FUN_L00_0024f7c8(void *, int, void *); /* Float arguments first: the order they are evaluated in gives retail's registers. */ extern void FUN_L00_002c1928_f(f32, f32, f32, f32 *, f32 *, f32 *) __asm__("FUN_L00_002c1928"); -extern CollisionHit coll_hit __asm__("D_L00_00173E40") NOT_SDA; -extern f32 frame_time_sq_macro __asm__("D_0015ED70") MACRO_ADDR; -extern u32 D_0013CAE4 NOT_SDA; -extern CollisionHit coll_hit __asm__("D_L00_00173E40"); -extern Vec4 D_L00_00166DC0; -extern short D_L00_001B07B0[]; -extern f32 frame_scale_inv_macro __asm__("D_0015ED68") MACRO_ADDR; -extern f32 frame_time_macro __asm__("D_0015ED6C") MACRO_ADDR; -extern s32 current_level_index_macro __asm__("D_0015ED84") MACRO_ADDR; -extern s32 D_0015EEA4_macro __asm__("D_0015EEA4") MACRO_ADDR; +extern CollisionHit coll_hit __asm__("D_L00_00173E40") NOT_SDA; +extern f32 frame_time_sq_macro __asm__("D_0015ED70") MACRO_ADDR; +extern CollisionHit coll_hit __asm__("D_L00_00173E40"); +extern Vec4 D_L00_00166DC0; +extern short D_L00_001B07B0[]; +extern f32 frame_scale_inv_macro __asm__("D_0015ED68") MACRO_ADDR; +extern f32 frame_time_macro __asm__("D_0015ED6C") MACRO_ADDR; +extern s32 current_level_index_macro __asm__("D_0015ED84") MACRO_ADDR; +extern s32 D_0015EEA4_macro __asm__("D_0015EEA4") MACRO_ADDR; /* coll_hit's normal as a whole quadword (CollisionHit names only x/y/z) */ extern Vec4 D_L00_00166DC0 NOT_SDA; extern float frame_time_sq_macro __asm__("D_0015ED70") MACRO_ADDR; @@ -180,7 +180,7 @@ void mine_glove_update(struct Moby *moby) { hero_set_state(0x1E, 1); if (fast_dec_timer(&mine_glove_vars->timer58) && !hero.item_use_locked) { if ((hero.item_anim_active && hero.item_anim_frames == scale_game_frames(0x11)) || - ((D_0013CAE4 & hero.items[0].button_mask) && hero.state.current == 0x1E && + ((((u32)pad_pressed_lui) & hero.items[0].button_mask) && hero.state.current == 0x1E && get_ammo(-1)) || (hero.state.current == 0x23 && hero.state_timer == scale_game_frames(0x10))) { allocate_hero_voice_for_entry(0x1A, 0); diff --git a/src/overlays/shared/weapons/morphoray.c b/src/overlays/shared/weapons/morphoray.c index 670f04bb5b..3fbf2847a9 100644 --- a/src/overlays/shared/weapons/morphoray.c +++ b/src/overlays/shared/weapons/morphoray.c @@ -1532,7 +1532,7 @@ void morphoray_update(Moby *moby) { ((Hero *)((char *)&hero))->state.control_mode == 12 || ((Hero *)((char *)&hero))->state.control_mode == 4 || ((Hero *)((char *)&hero))->state.control_mode == 5)) && - (*(int *)pad_held & ((Hero *)((char *)&hero))->items[0].button_mask) != 0 && !busy && + (pad_held_words[0] & ((Hero *)((char *)&hero))->items[0].button_mask) != 0 && !busy && in_range) { if (((Hero *)((char *)&hero))->item_anim_active == 0) { start_equipped_item_animation(); diff --git a/src/overlays/shared/weapons/pyrocitor.c b/src/overlays/shared/weapons/pyrocitor.c index ed457d431e..55ff660c9a 100644 --- a/src/overlays/shared/weapons/pyrocitor.c +++ b/src/overlays/shared/weapons/pyrocitor.c @@ -100,8 +100,6 @@ extern f32 pyrocitor_flame_zero_length_random_range_gp __asm__("D_L00_00161528") __attribute__((sda)); extern s32 pyrocitor_ammo_use_interval_frames_gp __asm__("D_L00_00161530") __attribute__((sda)); extern f32 D_L00_001601E8; -/* Fakematch: a second name for the pad state makes the button tests rebuild its address as retail does. */ -extern struct PadState controller_state_lui __asm__("D_0013C940"); extern unsigned short D_00141BD8 NOT_SDA; extern short pyrocitor_spark_lookup_index_and_flags_gp __asm__("D_L00_0016152C") __attribute__((sda)); @@ -579,6 +577,7 @@ void pyrocitor_update(struct Moby *moby) { pyrocitor_vars->light = -1; } } + /* Fakematch: the second pad name rebuilds the address for these button tests. */ if ((controller_state_lui.held & hero.items[0].button_mask) && !hero.item_use_locked && get_ammo(-1)) { moby->state = 3; diff --git a/src/overlays/shared/weapons/swingshot.c b/src/overlays/shared/weapons/swingshot.c index 4296cb2c83..c0e7ba0997 100644 --- a/src/overlays/shared/weapons/swingshot.c +++ b/src/overlays/shared/weapons/swingshot.c @@ -646,7 +646,7 @@ child_ready:; hero.unk5B4 = 0; if ((*(u8 **)(vars + 0x14)) != 0 && 3.5f < FUN_001ff450_2c6158((*(u8 **)(vars + 0x14)) + 0x10, &hero.motion.pos)) { - if ((pad_held[0] & hero.items[0].button_mask) == 0) { + if ((pad_held_words[0] & hero.items[0].button_mask) == 0) { hero.unk988 = 1; hero_set_state(0, 0); effect = hero_idle_sequence(0); diff --git a/src/overlays/shared/weapons/taunter.c b/src/overlays/shared/weapons/taunter.c index b9acedd3f8..a8e89e12b7 100644 --- a/src/overlays/shared/weapons/taunter.c +++ b/src/overlays/shared/weapons/taunter.c @@ -1,6 +1,7 @@ /* Shared moby class taunter: the taunter held by the hero, which lures nearby enemies, and its effect quads. */ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/overlay/shared/rendering/point_light.h" #include "rnc/globals.h" #include "rnc/hero/hero.h" @@ -105,7 +106,6 @@ void FUN_L00_002b7568_c(void) __asm__("FUN_L00_002b7568"); extern int D_0015EEA4; extern s32 D_0015EEA4; extern s32 D_L00_0015F5CC; -extern u32 D_0013C940[]; extern Ring D_00141680; extern Moby *D_001ABA00_b6bc8[] __asm__("D_L00_001ABA00"); extern s16 D_L00_001B07B0[] __asm__("D_L00_001B07B0"); @@ -497,9 +497,9 @@ void taunter_update(Moby *taunter_moby) { taunter_vars->cnt18 = 0; } if (voice_is_playing(taunter_moby, taunter_vars->anim) == 0) { - activation_button_bits = D_0013C940[0x1A4 / 4] & hero.items[0].button_mask; + activation_button_bits = ((u32)controller_state.pressed) & hero.items[0].button_mask; if ((activation_button_bits != 0 || - ((D_0013C940[0x1A0 / 4] & hero.items[0].button_mask) != 0 && + ((((u32)controller_state.held) & hero.items[0].button_mask) != 0 && taunter_vars->retry >= 0x11)) && hero.item_use_locked == 0) { if (activation_button_bits != 0) { @@ -529,7 +529,7 @@ void taunter_update(Moby *taunter_moby) { goto end; } if (taunter_vars->anim < 0) { - if ((D_0013C940[0x1A0 / 4] & hero.items[0].button_mask) != 0 && + if ((((u32)controller_state.held) & hero.items[0].button_mask) != 0 && hero.item_use_locked == 0) taunter_vars->retry++; else @@ -540,7 +540,7 @@ void taunter_update(Moby *taunter_moby) { } } else { taunter_vars->retry++; - if ((pad_held[0] & hero.items[0].button_mask) != 0 || + if ((pad_held_words[0] & hero.items[0].button_mask) != 0 || scale_game_frames(0x1E) >= taunter_vars->cnt18) { if (hero.item_use_locked == 0) goto L7340; diff --git a/src/overlays/shared/weapons/wrench.c b/src/overlays/shared/weapons/wrench.c index 7c3387088d..1f2597d126 100644 --- a/src/overlays/shared/weapons/wrench.c +++ b/src/overlays/shared/weapons/wrench.c @@ -646,7 +646,7 @@ void wrench_update(WrenchMoby *wrench_moby) { wrench_moby->parent = player->moby; player_state = player->state; if (player_state == 1) { - if (pad_held[0] & 0xA) + if (pad_held_words[0] & 0xA) draw_target_reticle( (int)wrench_moby, 0xFF917267, 1.0f, 0.0f, 0, 0x25, -1, 90.0f, 4); wrench_vars->aim_hit = 0; diff --git a/src/ui/menus/options/sound_options_menu.c b/src/ui/menus/options/sound_options_menu.c index 262cc96dcc..421b92fdb0 100644 --- a/src/ui/menus/options/sound_options_menu.c +++ b/src/ui/menus/options/sound_options_menu.c @@ -1,15 +1,10 @@ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/ui/menus/menu_system.h" #include "sda.h" #include "rnc/audio/mixer/snd_set_playback_mode.h" #include "rnc/audio/voice_pool.h" -struct SoundMenuInput { - u8 pad_0[0x1C0]; - s32 held_buttons; - s32 pressed_buttons; -}; - struct SoundMenu { u8 pad_0[0x14]; s32 sound_owner; @@ -19,15 +14,14 @@ struct SoundMenu { s32 selected_option; }; -extern struct SoundMenuInput D_0013C940; -extern s32 D_001D5D14 NOT_SDA; -extern s32 music_volume __asm__("D_0015EDEC") MACRO_ADDR; -extern s32 sound_volume __asm__("D_0015EDF0") MACRO_ADDR; -extern s32 playback_mode __asm__("D_0015EDE8") MACRO_ADDR; -extern s32 selected_level_index_lui __asm__("D_001A0314") NOT_SDA; -extern s32 allocate_voice_for_target_entry(s32 flags, - s32 sound_index, - s32 sound_owner) __asm__("func_0022DA68"); +extern s32 D_001D5D14 NOT_SDA; +extern s32 music_volume __asm__("D_0015EDEC") MACRO_ADDR; +extern s32 sound_volume __asm__("D_0015EDF0") MACRO_ADDR; +extern s32 playback_mode __asm__("D_0015EDE8") MACRO_ADDR; +extern s32 selected_level_index_lui __asm__("D_001A0314") NOT_SDA; +extern s32 allocate_voice_for_target_entry(s32 flags, + s32 sound_index, + s32 sound_owner) __asm__("func_0022DA68"); s32 sound_options_menu(struct SoundMenu *menu) __asm__("FUN_0021cb30"); @@ -40,10 +34,10 @@ s32 sound_options_menu(struct SoundMenu *menu) { s32 previous_sound_volume; s32 scaled_sound_volume; - if ((D_0013C940.pressed_buttons & 0xD00) && (D_001D5D14 == 0)) { + if ((((s32)controller_state.pressed_unmasked) & 0xD00) && (D_001D5D14 == 0)) { return 1; } - if (D_0013C940.pressed_buttons & 0x10) { + if (((s32)controller_state.pressed_unmasked) & 0x10) { struct MenuPage *back_page = menu_system.current->back; if (back_page != 0) { @@ -53,10 +47,10 @@ s32 sound_options_menu(struct SoundMenu *menu) { } } previous_selection = menu->selected_option; - if (D_0013C940.pressed_buttons & 0x1000) { + if (((s32)controller_state.pressed_unmasked) & 0x1000) { menu->selected_option = (previous_selection + 2) % 3; } - if (D_0013C940.pressed_buttons & 0x4000) { + if (((s32)controller_state.pressed_unmasked) & 0x4000) { menu->selected_option = (menu->selected_option + 1) % 3; } if ((menu->selected_option != previous_selection) || @@ -69,7 +63,7 @@ s32 sound_options_menu(struct SoundMenu *menu) { previous_music_volume = music_volume; previous_sound_volume = sound_volume; sound_volume_ptr = &sound_volume; - if (D_0013C940.held_buttons & 0x2000) { + if (((s32)controller_state.held_unmasked) & 0x2000) { if (menu->selected_option == 0) { sound_volume = (previous_sound_volume + 3 < 0x401) ? previous_sound_volume + 3 : 0x400; } @@ -77,7 +71,7 @@ s32 sound_options_menu(struct SoundMenu *menu) { music_volume = (previous_music_volume + 3 < 0x401) ? previous_music_volume + 3 : 0x400; } } - if (D_0013C940.held_buttons & 0x8000) { + if (((s32)controller_state.held_unmasked) & 0x8000) { if (menu->selected_option == 0) { sound_volume = (sound_volume - 3 <= 0) ? 0 : sound_volume - 3; } @@ -93,7 +87,7 @@ s32 sound_options_menu(struct SoundMenu *menu) { voice_pool.group_4_volume = scaled_sound_volume; voice_pool.group_5_volume = *sound_volume_ptr; } - if (D_0013C940.pressed_buttons & 0x40) { + if (((s32)controller_state.pressed_unmasked) & 0x40) { if (menu->selected_option == 2) { playback_mode = !playback_mode; } diff --git a/src/ui/menus/save_data/loading_data_menu.c b/src/ui/menus/save_data/loading_data_menu.c index 10781bc4c9..8160bff414 100644 --- a/src/ui/menus/save_data/loading_data_menu.c +++ b/src/ui/menus/save_data/loading_data_menu.c @@ -1,4 +1,5 @@ #include "types.h" +#include "rnc/input/pad_state.h" #include "rnc/ui/menus/menu_system.h" #include "asm.h" @@ -7,13 +8,6 @@ #include "rnc/game/options.h" #include "rnc/game/transitions.h" -struct LoadMenuControllerState { - u8 pad_0[0x1B4]; - s32 held_buttons; - u8 pad_1B8[0xC]; - s32 pressed_buttons; -}; - struct LoadMenuMixerState { u8 pad_0[0x48]; s32 group_0_volume; @@ -33,8 +27,6 @@ struct LoadMenuDescriptor { s32 selected_save_slot; }; -extern struct LoadMenuControllerState controller_state __asm__("D_0013C940"); - #include "rnc/save/memory_card_state.h" extern s16 D_0013E05A[]; @@ -75,12 +67,12 @@ s32 loading_data_menu(struct LoadMenuDescriptor *menu) { return 0; } } - if (controller_state.pressed_buttons & 0xD00) { + if (((s32)controller_state.pressed_unmasked) & 0xD00) { if (menu_system.close_locked == 0) { return 1; } } - if (controller_state.pressed_buttons & 0x10) { + if (((s32)controller_state.pressed_unmasked) & 0x10) { back_page = menu_system.current->back; if (back_page != 0) { menu_system.next = back_page; @@ -95,9 +87,9 @@ s32 loading_data_menu(struct LoadMenuDescriptor *menu) { if (((memory_card_state.state < 3) && (memory_card_state.pending_state < 0)) && (memory_card_state.card[0].type == 2)) { if (menu->flags & 1) { - buttons = controller_state.held_buttons; + buttons = controller_state.raw_pressed; } else { - buttons = controller_state.pressed_buttons; + buttons = ((s32)controller_state.pressed_unmasked); } menu->selected_save_slot = (s32)selected_save_slot; if ((buttons & 0x1000) && (selected_save_slot != 0)) {