From 7a5bfbbf56fdbdaa80bd697fbee461ffbf004026 Mon Sep 17 00:00:00 2001 From: Snesrev Date: Tue, 4 Apr 2023 18:24:59 +0200 Subject: [PATCH] Misc cleanup --- src/funcs.h | 4 -- src/sm_80.c | 42 ++++--------- src/sm_81.c | 150 +++++++++++++++++++-------------------------- src/sm_84.c | 18 ++---- src/sm_85.c | 2 +- src/sm_86.c | 18 ++---- src/sm_88.c | 135 +++++++++++++++++----------------------- src/sm_8b.c | 51 +++++---------- src/sm_8d.c | 4 +- src/sm_90.c | 149 ++++++++++++++------------------------------ src/sm_94.c | 74 +++++++--------------- src/sm_a0.c | 87 +------------------------- src/sm_a2.c | 21 +++---- src/sm_a3.c | 14 ++--- src/sm_a4.c | 17 ++--- src/sm_a5.c | 10 +-- src/sm_a6.c | 8 +-- src/sm_a7.c | 62 +++++++------------ src/sm_a8.c | 12 ++-- src/sm_b2.c | 4 +- src/sm_cpu_infra.c | 30 ++++++++- src/sm_rtl.c | 15 +---- src/sm_rtl.h | 3 +- src/types.h | 1 + src/variables.h | 39 ++++++------ 25 files changed, 338 insertions(+), 632 deletions(-) diff --git a/src/funcs.h b/src/funcs.h index ddbffd6..42e3efb 100644 --- a/src/funcs.h +++ b/src/funcs.h @@ -1825,8 +1825,6 @@ void EnemyProjectileCollHandler(void); void EnemyProjectileCollHandler_Multibox(void); void EnemySamusCollHandler(void); void EnemySamusCollHandler_Multibox(void); -void Enemy_AddPos_X(uint16 k, uint32 amount32); -void Enemy_AddPos_Y(uint16 k, uint32 amount32); void Enemy_GrappleReact_CancelBeam_A0(void); void Enemy_GrappleReact_HurtSamus_A0(void); void Enemy_GrappleReact_KillEnemy_A0(void); @@ -1853,8 +1851,6 @@ void Enemy_NormalShotAI_A0(void); void Enemy_NormalShotAI_SkipSomeParts_A0(void); void Enemy_NormalTouchAI_A0(void); void Enemy_NormalTouchAI_SkipDeathAnim_A0(void); -void Enemy_SubPos_X(uint16 k, uint32 amount32); -void Enemy_SubPos_Y(uint16 k, uint32 amount32); void Enemy_SwitchToFrozenAi(void); void EprojProjCollDet(void); void EprojSamusCollDetect(void); diff --git a/src/sm_80.c b/src/sm_80.c index f8a5ad5..2f66e4b 100644 --- a/src/sm_80.c +++ b/src/sm_80.c @@ -1897,8 +1897,7 @@ void HandleAutoscrolling_X(void) { // 0x80A528 if (scrolls[(uint16)(v2 + 1)]) return; var933 = layer1_x_pos & 0xFF00; - uint16 v5 = (__PAIR32__(var939 - absolute_moved_last_frame_x, var939) - (absolute_moved_last_frame_x | 0x20000)) >> 16; - + uint16 v5 = var939 - absolute_moved_last_frame_x - 2; if ((int16)(v5 - (layer1_x_pos & 0xFF00)) < 0) { v4 = var933; } else { @@ -1911,9 +1910,7 @@ void HandleAutoscrolling_X(void) { // 0x80A528 } } else { var933 = (layer1_x_pos & 0xFF00) + 256; - if ((uint16)(absolute_moved_last_frame_x - + var939 - + 2) >= var933) { + if ((uint16)(absolute_moved_last_frame_x + var939 + 2) >= var933) { v4 = var933; } else { var939 += absolute_moved_last_frame_x + 2; @@ -1942,7 +1939,7 @@ void HandleScrollingWhenTriggeringScrollRight(void) { // 0x80A641 uint16 RegWord = Mult8x8((uint16)(layer1_y_pos + 128) >> 8, room_width_in_scrolls); if (!scrolls[(uint16)(RegWord + 1 + v1)]) { var933 = layer1_x_pos & 0xFF00; - uint16 v4 = (__PAIR32__(var939 - absolute_moved_last_frame_x, var939) - (absolute_moved_last_frame_x | 0x20000)) >> 16; + uint16 v4 = var939 - absolute_moved_last_frame_x - 2; if ((int16)(v4 - (layer1_x_pos & 0xFF00)) < 0) v4 = var933; layer1_x_pos = v4; @@ -2020,7 +2017,7 @@ void HandleAutoscrolling_Y(void) { // 0x80A731 if (!scrolls[(uint16)(room_width_in_scrolls + v5)]) { var937 = var933 + (layer1_y_pos & 0xFF00); if (var937 < layer1_y_pos) { - uint16 v9 = (__PAIR32__(var939 - absolute_moved_last_frame_y, var939) - (absolute_moved_last_frame_y | 0x20000)) >> 16; + uint16 v9 = var939 - absolute_moved_last_frame_y - 2; if ((int16)(v9 - var937) < 0) { v8 = var937; } else { @@ -2057,7 +2054,7 @@ void HandleScrollingWhenTriggeringScrollDown(void) { // 0x80A893 if ((uint16)(var933 + v2) < layer1_y_pos || !scrolls[(uint16)(room_width_in_scrolls + r20)] && (var937 = var933 + (layer1_y_pos & 0xFF00), var937 < layer1_y_pos)) { - uint16 v3 = (__PAIR32__(var939 - absolute_moved_last_frame_y, var939) - (absolute_moved_last_frame_y | 0x20000)) >> 16; + uint16 v3 = var939 - absolute_moved_last_frame_y - 2; if ((int16)(v3 - var937) < 0) v3 = var937; layer1_y_pos = v3; @@ -2391,11 +2388,8 @@ void Irq_FollowDoorTransition(void) { uint8 DoorTransition_Right(void) { // 0x80AE7E uint16 v2 = door_transition_frame_counter; - uint16 v0 = (__PAIR32__(samus_door_transition_speed, samus_door_transition_subspeed) + - __PAIR32__(samus_x_pos, samus_x_subpos)) >> 16; - samus_x_subpos += samus_door_transition_subspeed; - samus_x_pos = v0; - samus_prev_x_pos = v0; + AddToHiLo(&samus_x_pos, &samus_x_subpos, __PAIR32__(samus_door_transition_speed, samus_door_transition_subspeed)); + samus_prev_x_pos = samus_x_pos; layer1_x_pos += 4; layer2_x_pos += 4; UpdateScrollVarsUpdateMap(); @@ -2408,12 +2402,8 @@ uint8 DoorTransition_Right(void) { // 0x80AE7E uint8 DoorTransition_Left(void) { // 0x80AEC2 uint16 v2 = door_transition_frame_counter; - uint16 v0 = (__PAIR32__(samus_x_pos, samus_x_subpos) - __PAIR32__( - samus_door_transition_speed, - samus_door_transition_subspeed)) >> 16; - samus_x_subpos -= samus_door_transition_subspeed; - samus_x_pos = v0; - samus_prev_x_pos = v0; + AddToHiLo(&samus_x_pos, &samus_x_subpos, -IPAIR32(samus_door_transition_speed, samus_door_transition_subspeed)); + samus_prev_x_pos = samus_x_pos; layer1_x_pos -= 4; layer2_x_pos -= 4; UpdateScrollVarsUpdateMap(); @@ -2425,11 +2415,8 @@ uint8 DoorTransition_Down(void) { // 0x80AF02 uint16 v6 = door_transition_frame_counter; if (door_transition_frame_counter) { if (door_transition_frame_counter < 0x39) { - uint16 v0 = (__PAIR32__(samus_door_transition_speed, samus_door_transition_subspeed) - + __PAIR32__(samus_y_pos, samus_y_subpos)) >> 16; - samus_y_subpos += samus_door_transition_subspeed; - samus_y_pos = v0; - samus_prev_y_pos = v0; + AddToHiLo(&samus_y_pos, &samus_y_subpos, __PAIR32__(samus_door_transition_speed, samus_door_transition_subspeed)); + samus_prev_y_pos = samus_y_pos; layer1_y_pos += 4; layer2_y_pos += 4; UpdateScrollVarsUpdateMap(); @@ -2461,11 +2448,8 @@ uint8 DoorTransition_Down(void) { // 0x80AF02 uint8 DoorTransition_Up(void) { // 0x80AF89 uint16 v6 = door_transition_frame_counter; if (door_transition_frame_counter) { - uint16 v0 = (__PAIR32__(samus_y_pos, samus_y_subpos) - - __PAIR32__(samus_door_transition_speed, samus_door_transition_subspeed)) >> 16; - samus_y_subpos -= samus_door_transition_subspeed; - samus_y_pos = v0; - samus_prev_y_pos = v0; + AddToHiLo(&samus_y_pos, &samus_y_subpos, -IPAIR32(samus_door_transition_speed, samus_door_transition_subspeed)); + samus_prev_y_pos = samus_y_pos; layer1_y_pos -= 4; layer2_y_pos -= 4; if (door_transition_frame_counter >= 5) { diff --git a/src/sm_81.c b/src/sm_81.c index 061e534..671b146 100644 --- a/src/sm_81.c +++ b/src/sm_81.c @@ -1804,10 +1804,10 @@ void ConfigureWindow1ForExpandingSquare(void) { // 0x81A5F6 } void SetupInitialExpandingSquareHDMA(void) { // 0x81A61C - expanding_square_topbottom_margin_right_pos = 0; - expanding_square_topbottom_margin_left_pos = -1; - LOBYTE(expanding_square_left_pos) = 127; - LOBYTE(expanding_square_right_pos) = -127; + expand_sq_topbottom_margin_right_pos = 0; + expand_sq_topbottom_margin_left_pos = -1; + LOBYTE(expand_sq_left_pos) = 127; + LOBYTE(expand_sq_right_pos) = -127; hdma_window_1_left_pos[0].field_0 = 111; hdma_window_1_left_pos[0].field_1 = 34; hdma_window_1_left_pos[0].field_2 = -98; @@ -1901,8 +1901,8 @@ void FileSelectMap_5_ExpandingSquare(void) { // 0x81A725 hdma_window_1_left_pos[2].field_0 = hdma_window_1_left_pos[1].field_0; hdma_window_1_right_pos[1].field_0 = hdma_window_1_left_pos[1].field_0; hdma_window_1_right_pos[2].field_0 = hdma_window_1_left_pos[1].field_0; - LOBYTE(expanding_square_left_pos) = expanding_square_left_pos - kExpandingSquareTransitionSpeed; - LOBYTE(expanding_square_right_pos) = kExpandingSquareTransitionSpeed + expanding_square_right_pos; + LOBYTE(expand_sq_left_pos) = expand_sq_left_pos - kExpandingSquareTransitionSpeed; + LOBYTE(expand_sq_right_pos) = kExpandingSquareTransitionSpeed + expand_sq_right_pos; } } @@ -2107,26 +2107,26 @@ void FileSelectMap_7_PrepExpandSquareTransToRoomMap(void) { // 0x81AAAC v1->vram_dst = (reg_BG2SC & 0xFC) << 8; vram_write_queue_tail = v0 + 7; - expanding_square_timer = kRoomSelectMapExpandingSquareTimers[area_index]; + expand_sq_timer = kRoomSelectMapExpandingSquareTimers[area_index]; int v2 = (uint16)(4 * area_index) >> 1; - expanding_square_left_pos = kAreaSelectMapLabelPositions[v2]; - expanding_square_right_pos = expanding_square_left_pos; - expanding_square_top_pos = kAreaSelectMapLabelPositions[v2 + 1]; - expanding_square_bottom_pos = expanding_square_top_pos; - expanding_square_left_subpos = 0; - expanding_square_right_subpos = 0; - expanding_square_top_subpos = 0; - expanding_square_bottom_subpos = 0; + expand_sq_left_pos = kAreaSelectMapLabelPositions[v2]; + expand_sq_right_pos = expand_sq_left_pos; + expand_sq_top_pos = kAreaSelectMapLabelPositions[v2 + 1]; + expand_sq_bottom_pos = expand_sq_top_pos; + expand_sq_left_subpos = 0; + expand_sq_right_subpos = 0; + expand_sq_top_subpos = 0; + expand_sq_bottom_subpos = 0; const ExpandingSquareVels *vels = &kExpandingSquareVels[area_index]; - expanding_square_left_subvel = vels->left_subvel; - expanding_square_left_vel = vels->left_vel; - expanding_square_right_subvel = vels->right_subvel; - expanding_square_right_vel = vels->right_vel; - expanding_square_top_subvel = vels->top_subvel; - expanding_square_top_vel = vels->top_vel; - expanding_square_bottom_subvel = vels->bottom_subvel; - expanding_square_bottom_vel = vels->bottom_vel; + expand_sq_left_subvel = vels->left_subvel; + expand_sq_left_vel = vels->left_vel; + expand_sq_right_subvel = vels->right_subvel; + expand_sq_right_vel = vels->right_vel; + expand_sq_top_subvel = vels->top_subvel; + expand_sq_top_vel = vels->top_vel; + expand_sq_bottom_subvel = vels->bottom_subvel; + expand_sq_bottom_vel = vels->bottom_vel; SetupRoomSelectMapExpandingSquareTransHDMA(); reg_HDMAEN = 12; WriteReg(HDMAEN, 0xC); @@ -2136,16 +2136,16 @@ void FileSelectMap_7_PrepExpandSquareTransToRoomMap(void) { // 0x81AAAC void SetupRoomSelectMapExpandingSquareTransHDMA(void) { // 0x81ABA7 uint16 k = 0; - uint16 v0 = expanding_square_top_pos; + uint16 v0 = expand_sq_top_pos; AddExpandingSqTransLeftIndirHDMA(v0, k, 0x9E22); k = AddExpandingSqTransRightIndirHDMA(v0, k, 0x9E20); - uint16 v2 = expanding_square_bottom_pos - expanding_square_top_pos; - if ((uint8)expanding_square_bottom_pos == (uint8)expanding_square_top_pos) + uint16 v2 = expand_sq_bottom_pos - expand_sq_top_pos; + if ((uint8)expand_sq_bottom_pos == (uint8)expand_sq_top_pos) v2 = 1; AddExpandingSqTransLeftIndirHDMA(v2, k, 0x9E32); k = AddExpandingSqTransRightIndirHDMA(v2, k, 0x9E36); - uint16 v4 = -32 - expanding_square_bottom_pos; - if ((uint8)expanding_square_bottom_pos == 0xE0) + uint16 v4 = -32 - expand_sq_bottom_pos; + if ((uint8)expand_sq_bottom_pos == 0xE0) v4 = 1; AddExpandingSqTransLeftIndirHDMA(v4, k, 0x9E22); k = AddExpandingSqTransRightIndirHDMA(v4, k, 0x9E20); @@ -2191,32 +2191,20 @@ void FileSelectMap_8_ExpandSquareTransToRoomSelectMap(void) { // 0x81AC66 } uint16 HandleRoomSelectMapExpandingSquareTrans(void) { // 0x81AC84 - uint16 v0 = (__PAIR32__(expanding_square_left_vel, expanding_square_left_subvel) - + __PAIR32__(expanding_square_left_pos, expanding_square_left_subpos)) >> 16; - expanding_square_left_subpos += expanding_square_left_subvel; - if (sign16(v0 - 1)) - v0 = 1; - expanding_square_left_pos = v0; - uint16 v1 = (__PAIR32__(expanding_square_right_vel, expanding_square_right_subvel) - + __PAIR32__(expanding_square_right_pos, expanding_square_right_subpos)) >> 16; - expanding_square_right_subpos += expanding_square_right_subvel; - if (!sign16(v1 - 256)) - v1 = 255; - expanding_square_right_pos = v1; - uint16 v2 = (__PAIR32__(expanding_square_top_vel, expanding_square_top_subvel) - + __PAIR32__(expanding_square_top_pos, expanding_square_top_subpos)) >> 16; - expanding_square_top_subpos += expanding_square_top_subvel; - if (sign16(v2 - 1)) - v2 = 1; - expanding_square_top_pos = v2; - uint16 v3 = (__PAIR32__(expanding_square_bottom_vel, expanding_square_bottom_subvel) - + __PAIR32__(expanding_square_bottom_pos, expanding_square_bottom_subpos)) >> 16; - expanding_square_bottom_subpos += expanding_square_bottom_subvel; - if (!sign16(v3 - 224)) - v3 = 224; - expanding_square_bottom_pos = v3; + AddToHiLo(&expand_sq_left_pos, &expand_sq_left_subpos, __PAIR32__(expand_sq_left_vel, expand_sq_left_subvel)); + if (sign16(expand_sq_left_pos - 1)) + expand_sq_left_pos = 1; + AddToHiLo(&expand_sq_right_pos, &expand_sq_right_subpos, __PAIR32__(expand_sq_right_vel, expand_sq_right_subvel)); + if (!sign16(expand_sq_right_pos - 256)) + expand_sq_right_pos = 255; + AddToHiLo(&expand_sq_top_pos, &expand_sq_top_subpos, __PAIR32__(expand_sq_top_vel, expand_sq_top_subvel)); + if (sign16(expand_sq_top_pos - 1)) + expand_sq_top_pos = 1; + AddToHiLo(&expand_sq_bottom_pos, &expand_sq_bottom_subpos, __PAIR32__(expand_sq_bottom_vel, expand_sq_bottom_subvel)); + if (!sign16(expand_sq_bottom_pos - 224)) + expand_sq_bottom_pos = 224; SetupRoomSelectMapExpandingSquareTransHDMA(); - return --expanding_square_timer; + return --expand_sq_timer; } void FileSelectMap_9_InitRoomSelectMap(void) { // 0x81AD17 @@ -2405,29 +2393,29 @@ void FileSelectMap_16_LoadPalettes(void) { // 0x81AFD3 void FileSelectMap_20_SetupExpandingSquare(void) { // 0x81AFF6 reg_HDMAEN = 0; QueueSfx1_Max6(0x3C); - expanding_square_timer = kRoomSelectMapExpandingSquareTimers[area_index] - 12; - expanding_square_left_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].left_subvel + expand_sq_timer = kRoomSelectMapExpandingSquareTimers[area_index] - 12; + expand_sq_left_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].left_subvel + (uint16)(16 * area_index)); - expanding_square_left_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].left_vel + (uint16)(16 * area_index)); - expanding_square_right_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].right_subvel + expand_sq_left_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].left_vel + (uint16)(16 * area_index)); + expand_sq_right_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].right_subvel + (uint16)(16 * area_index)); - expanding_square_right_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].right_vel + expand_sq_right_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].right_vel + (uint16)(16 * area_index)); - expanding_square_top_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].top_subvel + expand_sq_top_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].top_subvel + (uint16)(16 * area_index)); - expanding_square_top_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].top_vel + (uint16)(16 * area_index)); - expanding_square_bottom_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].bottom_subvel + expand_sq_top_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].top_vel + (uint16)(16 * area_index)); + expand_sq_bottom_subvel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].bottom_subvel + (uint16)(16 * area_index)); - expanding_square_bottom_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].bottom_vel + expand_sq_bottom_vel = *(uint16 *)((uint8 *)&kExpandingSquareVels[0].bottom_vel + (uint16)(16 * area_index)); - expanding_square_left_pos = 8; - expanding_square_right_pos = 248; - expanding_square_top_pos = 8; - expanding_square_bottom_pos = 216; - expanding_square_left_subpos = 0; - expanding_square_right_subpos = 0; - expanding_square_top_subpos = 0; - expanding_square_bottom_subpos = 0; + expand_sq_left_pos = 8; + expand_sq_right_pos = 248; + expand_sq_top_pos = 8; + expand_sq_bottom_pos = 216; + expand_sq_left_subpos = 0; + expand_sq_right_subpos = 0; + expand_sq_top_subpos = 0; + expand_sq_bottom_subpos = 0; SetupRoomSelectMapExpandingSquareTransHDMA(); ++menu_index; reg_HDMAEN = 12; @@ -2445,25 +2433,13 @@ void FileSelectMap_20_SetupExpandingSquare(void) { // 0x81AFF6 } void FileSelectMap_21_MoveExpandingSquare(void) { // 0x81B0BB - uint16 v0 = (__PAIR32__(expanding_square_left_pos, expanding_square_left_subpos) - - __PAIR32__(expanding_square_left_vel, expanding_square_left_subvel)) >> 16; - expanding_square_left_subpos -= expanding_square_left_subvel; - expanding_square_left_pos = v0; - uint16 v1 = (__PAIR32__(expanding_square_right_pos, expanding_square_right_subpos) - - __PAIR32__(expanding_square_right_vel, expanding_square_right_subvel)) >> 16; - expanding_square_right_subpos -= expanding_square_right_subvel; - expanding_square_right_pos = v1; - uint16 v2 = (__PAIR32__(expanding_square_top_pos, expanding_square_top_subpos) - - __PAIR32__(expanding_square_top_vel, expanding_square_top_subvel)) >> 16; - expanding_square_top_subpos -= expanding_square_top_subvel; - expanding_square_top_pos = v2; - uint16 v3 = (__PAIR32__(expanding_square_bottom_pos, expanding_square_bottom_subpos) - - __PAIR32__(expanding_square_bottom_vel, expanding_square_bottom_subvel)) >> 16; - expanding_square_bottom_subpos -= expanding_square_bottom_subvel; - expanding_square_bottom_pos = v3; + AddToHiLo(&expand_sq_left_pos, &expand_sq_left_subpos, -IPAIR32(expand_sq_left_vel, expand_sq_left_subvel)); + AddToHiLo(&expand_sq_right_pos, &expand_sq_right_subpos, -IPAIR32(expand_sq_right_vel, expand_sq_right_subvel)); + AddToHiLo(&expand_sq_top_pos, &expand_sq_top_subpos, -IPAIR32(expand_sq_top_vel, expand_sq_top_subvel)); + AddToHiLo(&expand_sq_bottom_pos, &expand_sq_bottom_subpos, -IPAIR32(expand_sq_bottom_vel, expand_sq_bottom_subvel)); SetupRoomSelectMapExpandingSquareTransHDMA(); DrawAreaSelectMapLabels(); - if ((--expanding_square_timer & 0x8000) != 0) { + if ((--expand_sq_timer & 0x8000) != 0) { menu_index -= 15; reg_TM = 17; reg_TMW = 0; diff --git a/src/sm_84.c b/src/sm_84.c index ad1c200..9d70529 100644 --- a/src/sm_84.c +++ b/src/sm_84.c @@ -2601,23 +2601,17 @@ const uint8 *PlmInstr_SpawnEyeDoorSmokeProjectile(const uint8 *plmp, uint16 k) { const uint8 *PlmInstr_MoveUpAndMakeBlueDoorFacingRight(const uint8 *plmp, uint16 k) { // 0x84D7C3 int v2 = k >> 1; - uint16 v3 = (__PAIR32__(plm_block_indices[v2] - room_width_in_blocks, plm_block_indices[v2]) - - __PAIR32__(room_width_in_blocks, room_width_in_blocks)) >> 16; - plm_block_indices[v2] = v3; - uint16 v4 = v3; - WriteLevelDataBlockTypeAndBts(v3, 0xC041); - sub_84D7EF(v4); + uint16 blk = (plm_block_indices[v2] -= room_width_in_blocks * 2); + WriteLevelDataBlockTypeAndBts(blk, 0xC041); + sub_84D7EF(blk); return plmp; } const uint8 *PlmInstr_MoveUpAndMakeBlueDoorFacingLeft(const uint8 *plmp, uint16 k) { // 0x84D7DA int v2 = k >> 1; - uint16 v3 = (__PAIR32__(plm_block_indices[v2] - room_width_in_blocks, plm_block_indices[v2]) - - __PAIR32__(room_width_in_blocks, room_width_in_blocks)) >> 16; - plm_block_indices[v2] = v3; - uint16 v4 = v3; - WriteLevelDataBlockTypeAndBts(v3, 0xC040); - sub_84D7EF(v4); + uint16 blk = (plm_block_indices[v2] -= room_width_in_blocks * 2); + WriteLevelDataBlockTypeAndBts(blk, 0xC040); + sub_84D7EF(blk); return plmp; } diff --git a/src/sm_85.c b/src/sm_85.c index 0c82587..2cacc6d 100644 --- a/src/sm_85.c +++ b/src/sm_85.c @@ -379,7 +379,7 @@ static CoroutineRet CloseMessageBox_Async(void) { // 0x858589 CoroutineRet DisplayMessageBox_Async(uint16 a) { // 0x858080 COROUTINE_BEGIN(coroutine_state_3, 0) - message_box_index = a; + message_box_index = a; CancelSoundEffects(); InitializePpuForMessageBoxes(); ClearMessageBoxBg3Tilemap(); diff --git a/src/sm_86.c b/src/sm_86.c index 5695cae..e34645c 100644 --- a/src/sm_86.c +++ b/src/sm_86.c @@ -4401,18 +4401,14 @@ uint16 Eproj_FuncE722(uint16 k) { // 0x86E722 void Eproj_FuncE73E_MoveXY(uint16 k) { // 0x86E73E int v1 = k >> 1; if (((g_word_7E97DC[v1] + 64) & 0x80) != 0) { - AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], - -(int32)__PAIR32__(enemy_projectile_x_vel[v1], enemy_projectile_E[v1])); + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], -IPAIR32(enemy_projectile_x_vel[v1], enemy_projectile_E[v1])); } else { - AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], - __PAIR32__(enemy_projectile_x_vel[v1], enemy_projectile_E[v1])); + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], __PAIR32__(enemy_projectile_x_vel[v1], enemy_projectile_E[v1])); } if (((g_word_7E97DC[v1] + 128) & 0x80) != 0) { - AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], - -(int32)__PAIR32__(enemy_projectile_y_vel[v1], enemy_projectile_F[v1])); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], -IPAIR32(enemy_projectile_y_vel[v1], enemy_projectile_F[v1])); } else { - AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], - __PAIR32__(enemy_projectile_y_vel[v1], enemy_projectile_F[v1])); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], __PAIR32__(enemy_projectile_y_vel[v1], enemy_projectile_F[v1])); } } @@ -4929,10 +4925,8 @@ void EprojPreInstr_Sparks(uint16 k) { // 0x86F3F0 if (v3 < 4) enemy_projectile_y_vel[v1] = v3; } - AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], - __PAIR32__(enemy_projectile_y_vel[v1], enemy_projectile_x_vel[v1])); - AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], - __PAIR32__(enemy_projectile_F[v1], enemy_projectile_E[v1])); + AddToHiLo(&enemy_projectile_y_pos[v1], &enemy_projectile_y_subpos[v1], __PAIR32__(enemy_projectile_y_vel[v1], enemy_projectile_x_vel[v1])); + AddToHiLo(&enemy_projectile_x_pos[v1], &enemy_projectile_x_subpos[v1], __PAIR32__(enemy_projectile_F[v1], enemy_projectile_E[v1])); if ((nmi_frame_counter_byte & 3) == 0) CreateSpriteAtPos(enemy_projectile_x_pos[v1], enemy_projectile_y_pos[v1], 48, enemy_projectile_gfx_idx[v1]); } diff --git a/src/sm_88.c b/src/sm_88.c index 73f2dcf..ed32fbb 100644 --- a/src/sm_88.c +++ b/src/sm_88.c @@ -733,14 +733,14 @@ void MoveXrayDown(void) { // 0x888835 void CalculateXrayHdmaTable(void) { // 0x888896 int16 v0; if (samus_pose_x_dir == 4) - v0 = (__PAIR32__(samus_x_pos - layer1_x_pos, samus_x_pos) - (layer1_x_pos | 0x30000)) >> 16; + v0 = samus_x_pos - layer1_x_pos - 3; else v0 = samus_x_pos - layer1_x_pos + 3; uint16 v1; if (samus_movement_type == 5) - v1 = (__PAIR32__(samus_y_pos - layer1_y_pos, samus_y_pos) - (layer1_y_pos | 0xC0000)) >> 16; + v1 = samus_y_pos - layer1_y_pos - 12; else - v1 = (__PAIR32__(samus_y_pos - layer1_y_pos, samus_y_pos) - (layer1_y_pos | 0x100000)) >> 16; + v1 = samus_y_pos - layer1_y_pos - 16; if (v0 < 0) { if (samus_pose_x_dir != 4) { off_screen: @@ -1958,7 +1958,6 @@ void CallFxRisingFunc(uint32 ea) { static const uint8 kLavaSoundEffects[8] = { 0x12, 0x13, 0x14, 0x12, 0x13, 0x14, 0x12, 0x13 }; void HdmaobjPreInstr_LavaAcidBG3YScroll(uint16 k) { // 0x88B3B0 - unsigned int v1; // kr00_4 int16 v2; int16 v3; int16 v4; @@ -1968,9 +1967,7 @@ void HdmaobjPreInstr_LavaAcidBG3YScroll(uint16 k) { // 0x88B3B0 if (!time_is_frozen_flag) { CallFxRisingFunc(fx_rising_function_bank_88 | 0x880000); FxHandleTide(); - v1 = __PAIR32__(fx_y_offset, fx_y_suboffset) + __PAIR32__(fx_base_y_pos, fx_base_y_subpos); - lava_acid_y_pos = HIWORD(v1); - lava_acid_y_subpos = v1; + SetHiLo(&lava_acid_y_pos, &lava_acid_y_subpos, __PAIR32__(fx_y_offset, fx_y_suboffset) + __PAIR32__(fx_base_y_pos, fx_base_y_subpos)); bg3_xpos = reg_BG1HOFS; *(uint16 *)mother_brain_indirect_hdma = 0; bg3_ypos = 0; @@ -2072,6 +2069,7 @@ void Handle_LavaAcidBG2YScroll_Func3(uint16 v0) { // 0x88B5A9 v3 = (v3 - 2) & 0x1E; } while (--n >= 0); } + static const SpawnHdmaObject_Args unk_88C40F = { 0x42, 0x11, 0xd856 }; static const SpawnHdmaObject_Args unk_88C41F = { 0x42, 0x0f, 0xd847 }; void FxTypeFunc_6_Water(void) { // 0x88C3FF @@ -2127,61 +2125,45 @@ void CallFxRisingFunction(uint32 ea) { } void HdmaobjPreInstr_WaterBG3XScroll(uint16 k) { // 0x88C48E - unsigned int v1; // kr00_4 - int16 v2; - int16 v3; - int16 v9; - uint16 v4; - fx_layer_blending_config_c = fx_layer_blending_config_b; - if (!time_is_frozen_flag) { - CallFxRisingFunction(fx_rising_function_bank_88 | 0x880000); - FxHandleTide(); - v1 = __PAIR32__(fx_y_offset, fx_y_suboffset) + __PAIR32__(fx_base_y_pos, fx_base_y_subpos); - fx_y_pos = HIWORD(v1); - fx_y_subpos = v1; - v2 = (__PAIR32__(fx_y_offset, fx_y_suboffset) + __PAIR32__(fx_base_y_pos, fx_base_y_subpos)) >> 16; - if (v2 < 0) - goto LABEL_6; - v3 = v2 - layer1_y_pos; - if (v3 <= 0) { - v4 = (v3 ^ 0x1F) & 0x1F | 0x100; - goto LABEL_8; - } - if ((uint16)v3 < 0x100) - v4 = (uint8)~(uint8)v3; - else - LABEL_6: - v4 = 0; -LABEL_8: - bg3_ypos = v4; - int v5 = (uint8)hdma_object_index >> 1; - uint16 r20 = layer1_x_pos + (int8)HIBYTE(hdma_object_C[v5]); - if (hdma_object_B[v5]-- == 1) { - hdma_object_B[v5] = 10; - hdma_object_A[v5] = (hdma_object_A[v5] + 2) & 0x1E; - } - uint8 v7 = hdma_object_A[v5]; - for (int i = 30; (i & 0x80) == 0; i -= 2) { - *(uint16 *)&mother_brain_indirect_hdma[v7 + 4] = g_word_88C46E[i >> 1] + r20; - v7 = (v7 - 2) & 0x1E; - } - if ((fx_liquid_options & 1) != 0) - hdma_object_C[(uint8)hdma_object_index >> 1] += 64; - if ((fx_y_pos & 0x8000) == 0) { - v9 = fx_y_pos - layer1_y_pos + 256; - if (v9 < 0) { - v9 = (fx_y_pos - layer1_y_pos) & 0xF | 0x100; -LABEL_22: - hdma_object_table_pointers[(uint8)hdma_object_index >> 1] = 3 * (((v9 ^ 0x1FF) + 1) & 0x3FF) + 0xC645; - return; - } - if ((uint16)v9 < 0x200) - goto LABEL_22; - } - v9 = 511; - goto LABEL_22; + if (time_is_frozen_flag) + return; + CallFxRisingFunction(fx_rising_function_bank_88 | 0x880000); + FxHandleTide(); + SetHiLo(&fx_y_pos, &fx_y_subpos, __PAIR32__(fx_y_offset, fx_y_suboffset) + __PAIR32__(fx_base_y_pos, fx_base_y_subpos)); + int16 v3 = fx_y_pos - layer1_y_pos; + if ((int16)fx_y_pos < 0) { + bg3_ypos = 0; + } else if (v3 <= 0) { + bg3_ypos = (v3 ^ 0x1F) & 0x1F | 0x100; + } else if ((uint16)v3 < 0x100) { + bg3_ypos = (uint8)~v3; + } else { + bg3_ypos = 0; } + int v5 = k >> 1; + uint16 r20 = layer1_x_pos + (int8)HIBYTE(hdma_object_C[v5]); + if (hdma_object_B[v5]-- == 1) { + hdma_object_B[v5] = 10; + hdma_object_A[v5] = (hdma_object_A[v5] + 2) & 0x1E; + } + uint8 v7 = hdma_object_A[v5]; + for (int i = 30; (i & 0x80) == 0; i -= 2) { + *(uint16 *)&mother_brain_indirect_hdma[v7 + 4] = g_word_88C46E[i >> 1] + r20; + v7 = (v7 - 2) & 0x1E; + } + if ((fx_liquid_options & 1) != 0) + hdma_object_C[k >> 1] += 64; + int16 v9 = fx_y_pos - layer1_y_pos + 256; + if ((int16)fx_y_pos < 0) { + v9 = 511; + } else if (v9 >= 0) { + if ((uint16)v9 >= 0x200) + v9 = 511; + } else { + v9 = v9 & 0xF | 0x100; + } + hdma_object_table_pointers[k >> 1] = 3 * (((v9 ^ 0x1FF) + 1) & 0x3FF) + 0xC645; } const uint8 *HdmaobjInstr_SetFlagB_Copy3(uint16 k, const uint8 *hdp) { // 0x88C582 @@ -2190,31 +2172,24 @@ const uint8 *HdmaobjInstr_SetFlagB_Copy3(uint16 k, const uint8 *hdp) { // 0x88C } void HdmaobjPreInstr_WaterBG2XScroll(uint16 k) { // 0x88C589 - int16 v1; - g_word_7E9C44 = reg_BG2HOFS; - if (time_is_frozen_flag) - goto LABEL_4; - if ((fx_liquid_options & 2) == 0) { - hdma_object_channels_bitmask[(uint8)k >> 1] = 0; -LABEL_4: + if (time_is_frozen_flag) { HdmaobjPreInstr_WaterBG2XScroll_Func1(k); - goto LABEL_6; + } else if ((fx_liquid_options & 2) == 0) { + hdma_object_channels_bitmask[(uint8)k >> 1] = 0; + HdmaobjPreInstr_WaterBG2XScroll_Func1(k); + } else { + HdmaobjPreInstr_WaterBG2XScroll_Func2(k); } - HdmaobjPreInstr_WaterBG2XScroll_Func2(k); -LABEL_6: - if ((fx_y_pos & 0x8000) != 0) - goto LABEL_10; - v1 = fx_y_pos - layer1_y_pos + 256; - if (v1 >= 0) { - if ((uint16)v1 < 0x200) - goto LABEL_11; -LABEL_10: + int16 v1 = fx_y_pos - layer1_y_pos + 256; + if ((int16)fx_y_pos < 0) { v1 = 511; - goto LABEL_11; + } else if (v1 >= 0) { + if ((uint16)v1 >= 0x200) + v1 = 511; + } else { + v1 = (fx_y_pos - layer1_y_pos) & 0xF | 0x100; } - v1 = (fx_y_pos - layer1_y_pos) & 0xF | 0x100; -LABEL_11: hdma_object_table_pointers[(uint8)k >> 1] = 3 * ((v1 ^ 0x1FF) & 0x3FF) + 0xCF46; } diff --git a/src/sm_8b.c b/src/sm_8b.c index eb0f87b..65f0396 100644 --- a/src/sm_8b.c +++ b/src/sm_8b.c @@ -1534,10 +1534,8 @@ void CreditsObject_ProcessOne(void) { // 0x8B996A int i; CallCreditsObjectFunc(cinematic_var24 | 0x8B0000, 0); - uint16 v0 = (__PAIR32__(cinematic_var10, cinematic_var9) + 0x8000) >> 16; - cinematic_var9 += 0x8000; - cinematic_var10 = v0; - if (!sign16(v0 - enemy_projectile_pre_instr[0] - 8)) { + AddToHiLo(&cinematic_var10, &cinematic_var9, 0x8000); + if (!sign16(cinematic_var10 - enemy_projectile_pre_instr[0] - 8)) { enemy_projectile_pre_instr[0] = cinematic_var10; for (i = cinematic_var21; ; ) { const uint16 *v2 = (const uint16 *)RomPtr_8C(i); @@ -1795,10 +1793,8 @@ uint16 CinematicSprInstr_9CE1(uint16 k, uint16 j) { // 0x8B9CE1 } void CinematicFunc_Func2(void) { // 0x8B9D17 - uint16 v0 = (__PAIR32__(g_word_7E199B, g_word_7E1999) + __PAIR32__(cinematic_var8, cinematic_var7)) >> 16; - cinematic_var7 += g_word_7E1999; - cinematic_var8 = v0; - if (sign16(v0 + 7)) { + AddToHiLo(&cinematic_var8, &cinematic_var7, __PAIR32__(g_word_7E199B, g_word_7E1999)); + if (sign16(cinematic_var8 + 7)) { reg_TM = 16; cinematic_function = FUNC16(CinematicFunctionNone); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BA0F5, FUNC16(CinematicFunctionNone)); @@ -1828,10 +1824,8 @@ uint16 CinematicSprInstr_9D5D(uint16 k, uint16 j) { // 0x8B9D5D } void CinematicFunc_Func4(void) { // 0x8B9D90 - uint16 v0 = (__PAIR32__(g_word_7E199B, g_word_7E1999) + __PAIR32__(cinematic_var8, cinematic_var7)) >> 16; - cinematic_var7 += g_word_7E1999; - cinematic_var8 = v0; - if (sign16(v0 + 176)) { + AddToHiLo(&cinematic_var8, &cinematic_var7, __PAIR32__(g_word_7E199B, g_word_7E1999)); + if (sign16(cinematic_var8 + 176)) { reg_TM = 16; cinematic_function = FUNC16(CinematicFunctionNone); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BA0FB, FUNC16(CinematicFunctionNone)); @@ -1864,10 +1858,8 @@ uint16 CinematicSprInstr_9DD6(uint16 k, uint16 j) { // 0x8B9DD6 } void CinematicFunc_Func5(void) { // 0x8B9E12 - uint16 v0 = (__PAIR32__(g_word_7E199F, g_word_7E199D) + __PAIR32__(cinematic_var10, cinematic_var9)) >> 16; - cinematic_var9 += g_word_7E199D; - cinematic_var10 = v0; - if (!sign16(v0 - 163)) { + AddToHiLo(&cinematic_var10, &cinematic_var9, __PAIR32__(g_word_7E199F, g_word_7E199D)); + if (!sign16(cinematic_var10 - 163)) { reg_TM = 16; cinematic_function = FUNC16(CinematicFunctionNone); SpawnCinematicSpriteObject(addr_kCinematicSpriteObjectDef_8BA101, FUNC16(CinematicFunctionNone)); @@ -4738,17 +4730,13 @@ static const uint16 kCinematicFunction_Intro_Func121_Tab0[32] = { // 0x8BDCA5 0, 0x8000, 0, 0x8000, 0xffff, 0x8000, 0xffff, 0x8000, 0, 0x8000, 0, 0x8000, 0xffff, 0x8000, 0xffff, 0x8000, }; void CinematicFunction_Intro_Func121(void) { - int16 v1; - if (cinematic_var13) --cinematic_var13; else CinematicFunction_Intro_Func122(); cinematic_var5 = (uint8)(cinematic_var5 - 4); - int v0 = (uint16)(4 * cinematic_var14) >> 1; - v1 = (kCinematicFunction_Intro_Func121_Tab0[v0 + 1] + __PAIR32__(cinematic_var8, cinematic_var7)) >> 16; - cinematic_var7 += kCinematicFunction_Intro_Func121_Tab0[v0 + 1]; - cinematic_var8 = kCinematicFunction_Intro_Func121_Tab0[v0] + v1; + int v0 = 2 * cinematic_var14; + AddToHiLo(&cinematic_var8, &cinematic_var7, __PAIR32__(kCinematicFunction_Intro_Func121_Tab0[v0], kCinematicFunction_Intro_Func121_Tab0[v0 + 1])); cinematic_var14 = (cinematic_var14 + 1) & 0xF; cinematic_var6 -= 8; if (sign16(cinematic_var6 - 1456)) { @@ -4761,15 +4749,11 @@ void CinematicFunction_Intro_Func121(void) { static const uint16 kCinematicFunction_Intro_Func123_Tab0[16] = { 1, 0, 1, 0, 1, 0, 0xffff, 0, 0xffff, 0, 1, 0, 1, 0, 0xffff, 0 }; void CinematicFunction_Intro_Func123(void) { // 0x8BDD42 - int16 v1; - CinematicFunction_Intro_Func122(); if (cinematic_var5 != 224) cinematic_var5 = (uint8)(cinematic_var5 - 1); - int v0 = (uint16)(4 * cinematic_var14) >> 1; - v1 = (kCinematicFunction_Intro_Func123_Tab0[v0 + 1] + __PAIR32__(cinematic_var8, cinematic_var7)) >> 16; - cinematic_var7 += kCinematicFunction_Intro_Func123_Tab0[v0 + 1]; - cinematic_var8 = kCinematicFunction_Intro_Func123_Tab0[v0] + v1; + int v0 = 2 * cinematic_var14; + AddToHiLo(&cinematic_var8, &cinematic_var7, __PAIR32__(kCinematicFunction_Intro_Func123_Tab0[v0], kCinematicFunction_Intro_Func123_Tab0[v0 + 1])); cinematic_var14 = (cinematic_var14 + 1) & 7; cinematic_var6 -= 2; if (sign16(cinematic_var6 - 1184)) { @@ -4785,16 +4769,9 @@ void CinematicFunction_Intro_Func123(void) { // 0x8BDD42 static const uint16 g_word_8BDE43[16] = { 0, 0x6f7b, 0x4a52, 0x1ce7, 0, 0x5ad6, 0x4a52, 0x35ad, 0x2529, 0x7fff, 0x56b5, 0x294a, 0x4210, 0x2d6b, 0x18c6, 0x7fff }; void CinematicFunction_Intro_Func124(void) { // 0x8BDDCD - unsigned int v2; // kr04_4 - CinematicFunction_Intro_Func122(); - uint16 v0 = (__PAIR32__(cinematic_var13, cinematic_var14) - 256) >> 16; - cinematic_var14 -= 256; - cinematic_var13 = v0; - v2 = __PAIR32__(v0, cinematic_var14) + __PAIR32__(cinematic_var8, cinematic_var7); - uint16 v1 = (__PAIR32__(v0, cinematic_var14) + __PAIR32__(cinematic_var8, cinematic_var7)) >> 16; - cinematic_var7 = v2; - cinematic_var8 = v1; + AddToHiLo(&cinematic_var13, &cinematic_var14, -256); + AddToHiLo(&cinematic_var8, &cinematic_var7, __PAIR32__(cinematic_var13, cinematic_var14)); if (sign16(cinematic_var6 - 384) && (cinematic_var12 & 3) == 0 && cinematic_var5 != 16) cinematic_var5 = (uint8)(cinematic_var5 + 2); if (sign16(cinematic_var6 - 32)) { diff --git a/src/sm_8d.c b/src/sm_8d.c index b9f73ef..fe587d6 100644 --- a/src/sm_8d.c +++ b/src/sm_8d.c @@ -224,9 +224,7 @@ void PalPreInstr_CheckEnemy0Health(uint16 k) { // 0x8DE2E0 void PalPreInstr_SamusInHeat(uint16 k) { // 0x8DE379 if ((equipped_items & 0x21) == 0) { - uint16 v1 = (__PAIR32__(samus_periodic_damage, samus_periodic_subdamage) + 0x4000) >> 16; - samus_periodic_subdamage += 0x4000; - samus_periodic_damage = v1; + AddToHiLo(&samus_periodic_damage, &samus_periodic_subdamage, 0x4000); if ((nmi_frame_counter_word & 7) == 0 && samus_health > 0x46) QueueSfx3_Max6(0x2D); } diff --git a/src/sm_90.c b/src/sm_90.c index 44be9a1..272f059 100644 --- a/src/sm_90.c +++ b/src/sm_90.c @@ -150,10 +150,7 @@ void Samus_Animate_LavaFx(void) { // 0x9081C0 } else { if ((game_time_frames & 7) == 0 && !sign16(samus_health - 71)) QueueSfx3_Max3(0x2D); - uint16 v0 = (__PAIR32__(kSamusPhys_LavaDamagePerFrame, kSamusPhys_LavaSubdamagePerFrame) - + __PAIR32__(samus_periodic_damage, samus_periodic_subdamage)) >> 16; - samus_periodic_subdamage += kSamusPhys_LavaSubdamagePerFrame; - samus_periodic_damage = v0; + AddToHiLo(&samus_periodic_damage, &samus_periodic_subdamage, __PAIR32__(kSamusPhys_LavaDamagePerFrame, kSamusPhys_LavaSubdamagePerFrame)); Samus_Animate_SubmergedLavaAcid(); } } else { @@ -169,10 +166,7 @@ void Samus_Animate_AcidFx(void) { // 0x908219 if ((lava_acid_y_pos & 0x8000) == 0 && sign16(lava_acid_y_pos - r18)) { if ((game_time_frames & 7) == 0 && !sign16(samus_health - 71)) QueueSfx3_Max3(0x2D); - uint16 v0 = (__PAIR32__(kSamusPhys_AcidDamagePerFrame, kSamusPhys_AcidSubdamagePerFrame) - + __PAIR32__(samus_periodic_damage, samus_periodic_subdamage)) >> 16; - samus_periodic_subdamage += kSamusPhys_AcidSubdamagePerFrame; - samus_periodic_damage = v0; + AddToHiLo(&samus_periodic_damage, &samus_periodic_subdamage, __PAIR32__(kSamusPhys_AcidDamagePerFrame, kSamusPhys_AcidSubdamagePerFrame)); Samus_Animate_SubmergedLavaAcid(); } else { Samus_Animate_NoFx(); @@ -199,14 +193,12 @@ void Samus_Animate_SubmergedLavaAcid(void) { // 0x90824C atmospheric_gfx_y_pos[3] = lava_acid_y_pos; atmospheric_gfx_x_pos[0] = samus_x_pos + 6; atmospheric_gfx_x_pos[1] = samus_x_pos; - *(uint32 *)&atmospheric_gfx_x_pos[2] = __PAIR32__(samus_x_pos - (samus_x_pos >= 0xFFFA), samus_x_pos) - - ((int)(samus_x_pos >= 0xFFFA) | 0x60000); + atmospheric_gfx_x_pos[2] = samus_x_pos; + atmospheric_gfx_x_pos[3] = samus_x_pos - 6; if ((game_time_frames & 1) == 0) QueueSfx2_Max6(0x10); } - if (samus_pose == kPose_00_FaceF_Powersuit - || samus_pose == kPose_9B_FaceF_VariaGravitySuit - || (equipped_items & 0x20) != 0) { + if (samus_pose == kPose_00_FaceF_Powersuit || samus_pose == kPose_9B_FaceF_VariaGravitySuit || (equipped_items & 0x20) != 0) { samus_anim_frame_buffer = 0; } } @@ -1062,7 +1054,7 @@ void Samus_MoveY_WithSpeedCalc(void) { // 0x9090E2 if (samus_y_speed != 5) AddToHiLo(&samus_y_speed, &samus_y_subspeed, __PAIR32__(samus_y_accel, samus_y_subaccel)); } else { - AddToHiLo(&samus_y_speed, &samus_y_subspeed, -(int32)__PAIR32__(samus_y_accel, samus_y_subaccel)); + AddToHiLo(&samus_y_speed, &samus_y_subspeed, -IPAIR32(samus_y_accel, samus_y_subaccel)); } if (samus_y_dir != 2) amt = -amt; @@ -1115,11 +1107,10 @@ void Samus_MorphedBouncingMovement(void) { // 0x9091D1 samus_y_subspeed = 0; samus_y_speed = 0; int32 amt = __PAIR32__(extra_samus_y_displacement, extra_samus_y_subdisplacement); - if (amt < 0) { + if (amt < 0) Samus_MoveUp(amt); - } else { + else Samus_MoveDown(amt + INT16_SHL16(1)); - } } else { Samus_CheckStartFalling(); Samus_MoveY_WithSpeedCalc(); @@ -1328,34 +1319,21 @@ void Samus_ScrollFinishedHook_SporeSpawnFight(void) { // 0x909589 void Samus_HandleScroll_X(void) { // 0x9095A0 static const uint16 kSamus_HandleScroll_X_FaceLeft[4] = { 0xa0, 0x50, 0x20, 0xe0 }; static const uint16 kSamus_HandleScroll_X_FaceRight[4] = { 0x60, 0x40, 0x20, 0xe0 }; - - if (samus_prev_x_pos == samus_x_pos) { HandleAutoscrolling_X(); return; } - // r18 = layer1_x_pos; - if (knockback_dir || samus_movement_type == 16 || samus_x_accel_mode == 1) { - if (samus_pose_x_dir == 4) { -LABEL_9: - ideal_layer1_xpos = samus_x_pos - kSamus_HandleScroll_X_FaceRight[camera_distance_index >> 1]; - goto LABEL_11; - } - } else if (samus_pose_x_dir != 4) { - goto LABEL_9; + if ((knockback_dir || samus_movement_type == 16 || samus_x_accel_mode == 1) ^ (samus_pose_x_dir != 4)) { + ideal_layer1_xpos = samus_x_pos - kSamus_HandleScroll_X_FaceRight[camera_distance_index >> 1]; + } else { + ideal_layer1_xpos = samus_x_pos - kSamus_HandleScroll_X_FaceLeft[camera_distance_index >> 1]; } - ideal_layer1_xpos = samus_x_pos - kSamus_HandleScroll_X_FaceLeft[camera_distance_index >> 1]; -LABEL_11: if (ideal_layer1_xpos != layer1_x_pos) { if ((int16)(ideal_layer1_xpos - layer1_x_pos) < 0) { - uint16 v1 = (__PAIR32__(layer1_x_pos, layer1_x_subpos) - __PAIR32__(absolute_moved_last_frame_x, absolute_moved_last_frame_x_fract)) >> 16; - layer1_x_subpos -= absolute_moved_last_frame_x_fract; - layer1_x_pos = v1; + AddToHiLo(&layer1_x_pos, &layer1_x_subpos, -IPAIR32(absolute_moved_last_frame_x, absolute_moved_last_frame_x_fract)); HandleScrollingWhenTriggeringScrollLeft(); } else { - uint16 v0 = (__PAIR32__(absolute_moved_last_frame_x, absolute_moved_last_frame_x_fract) + __PAIR32__(layer1_x_pos, layer1_x_subpos)) >> 16; - layer1_x_subpos += absolute_moved_last_frame_x_fract; - layer1_x_pos = v0; + AddToHiLo(&layer1_x_pos, &layer1_x_subpos, __PAIR32__(absolute_moved_last_frame_x, absolute_moved_last_frame_x_fract)); HandleScrollingWhenTriggeringScrollRight(); } } @@ -1372,41 +1350,33 @@ void Samus_HandleScroll_Y(void) { // 0x90964F ideal_layer1_ypos = samus_y_pos - up_scroller; if (ideal_layer1_ypos != layer1_y_pos) { if ((int16)(ideal_layer1_ypos - layer1_y_pos) < 0) { - uint16 v1 = (__PAIR32__(layer1_y_pos, layer1_y_subpos) - - __PAIR32__(absolute_moved_last_frame_y, absolute_moved_last_frame_y_fract)) >> 16; - layer1_y_subpos -= absolute_moved_last_frame_y_fract; - layer1_y_pos = v1; + AddToHiLo(&layer1_y_pos, &layer1_y_subpos, -IPAIR32(absolute_moved_last_frame_y, absolute_moved_last_frame_y_fract)); HandleScrollingWhenTriggeringScrollUp(); } else { - uint16 v0 = (__PAIR32__(absolute_moved_last_frame_y, absolute_moved_last_frame_y_fract) - + __PAIR32__(layer1_y_pos, layer1_y_subpos)) >> 16; - layer1_y_subpos += absolute_moved_last_frame_y_fract; - layer1_y_pos = v0; + AddToHiLo(&layer1_y_pos, &layer1_y_subpos, __PAIR32__(absolute_moved_last_frame_y, absolute_moved_last_frame_y_fract)); HandleScrollingWhenTriggeringScrollDown(); } } } } -static const uint16 g_word_909EAD = 1; - void Samus_CalcDistanceMoved_X(void) { // 0x9096C0 if ((int16)(samus_x_pos - samus_prev_x_pos) >= 0) { - absolute_moved_last_frame_x_fract = samus_x_subpos - samus_prev_x_subpos; - absolute_moved_last_frame_x = g_word_909EAD + ((__PAIR32__(samus_x_pos, samus_x_subpos) - __PAIR32__(samus_prev_x_pos, samus_prev_x_subpos)) >> 16); + SetHiLo(&absolute_moved_last_frame_x, &absolute_moved_last_frame_x_fract, + __PAIR32__(samus_x_pos, samus_x_subpos) - __PAIR32__(samus_prev_x_pos, samus_prev_x_subpos) + (1 << 16)); } else { - absolute_moved_last_frame_x_fract = samus_prev_x_subpos - samus_x_subpos; - absolute_moved_last_frame_x = g_word_909EAD + ((__PAIR32__(samus_prev_x_pos, samus_prev_x_subpos) - __PAIR32__(samus_x_pos, samus_x_subpos)) >> 16); + SetHiLo(&absolute_moved_last_frame_x, &absolute_moved_last_frame_x_fract, + __PAIR32__(samus_prev_x_pos, samus_prev_x_subpos) - __PAIR32__(samus_x_pos, samus_x_subpos) + (1 << 16)); } } void Samus_CalcDistanceMoved_Y(void) { // 0x9096FF if ((int16)(samus_y_pos - samus_prev_y_pos) >= 0) { - absolute_moved_last_frame_y_fract = samus_y_subpos - samus_prev_y_subpos; - absolute_moved_last_frame_y = g_word_909EAD + ((__PAIR32__(samus_y_pos, samus_y_subpos) - __PAIR32__(samus_prev_y_pos, samus_prev_y_subpos)) >> 16); + SetHiLo(&absolute_moved_last_frame_y, &absolute_moved_last_frame_y_fract, + __PAIR32__(samus_y_pos, samus_y_subpos) - __PAIR32__(samus_prev_y_pos, samus_prev_y_subpos) + (1 << 16)); } else { - absolute_moved_last_frame_y_fract = samus_prev_y_subpos - samus_y_subpos; - absolute_moved_last_frame_y = g_word_909EAD + ((__PAIR32__(samus_prev_y_pos, samus_prev_y_subpos) - __PAIR32__(samus_y_pos, samus_y_subpos)) >> 16); + SetHiLo(&absolute_moved_last_frame_y, &absolute_moved_last_frame_y_fract, + __PAIR32__(samus_prev_y_pos, samus_prev_y_subpos) - __PAIR32__(samus_y_pos, samus_y_subpos) + (1 << 16)); } } @@ -1655,6 +1625,7 @@ int32 Samus_CalcBaseSpeed_X(uint16 k) { // 0x909A7E static Pair_Bool_Amt Samus_CalcBaseSpeed_NoDecel_X(uint16 k) { // 0x909B1F SamusSpeedTableEntry *sste = get_SamusSpeedTableEntry(k); + bool rv = false; if ((samus_x_accel_mode & 1) != 0) { int32 delta = samus_x_decel_mult ? __PAIR32__(Mult8x8(samus_x_decel_mult, sste->decel) >> 8, Mult8x8(samus_x_decel_mult, HIBYTE(sste->decel_sub))) : @@ -1670,10 +1641,10 @@ static Pair_Bool_Amt Samus_CalcBaseSpeed_NoDecel_X(uint16 k) { // 0x909B1F if (IsGreaterThanQuirked(samus_x_base_speed, samus_x_base_subspeed, sste->max_speed, sste->max_speed_sub)) { samus_x_base_speed = sste->max_speed; samus_x_base_subspeed = sste->max_speed_sub; - return (Pair_Bool_Amt) { true, __PAIR32__(samus_x_base_speed, samus_x_base_subspeed) }; + rv = true; } } - return (Pair_Bool_Amt) { false, __PAIR32__(samus_x_base_speed, samus_x_base_subspeed) }; + return (Pair_Bool_Amt) { rv, __PAIR32__(samus_x_base_speed, samus_x_base_subspeed) }; } uint16 Samus_DetermineSpeedTableEntryPtr_X(void) { // 0x909BD1 @@ -1710,7 +1681,6 @@ void Samus_DetermineAccel_Y(void) { // 0x909C5B static const uint16 g_word_909EA7 = 0; static const uint16 g_word_909EA9 = 0; static const uint16 g_word_909EAB = 0; - static const uint16 g_word_909EAD = 1; if ((equipped_items & 0x20) != 0) goto LABEL_7; @@ -4595,13 +4565,9 @@ void Samus_ShinesparkMove_X(void) { // 0x90D132 int16 v4; samus_shine_timer = 15; - uint16 v0 = (__PAIR32__(samus_y_accel, samus_y_subaccel) + __PAIR32__(samus_x_extra_run_speed, samus_x_extra_run_subspeed)) >> 16; - samus_x_extra_run_subspeed += samus_y_subaccel; - samus_x_extra_run_speed = v0; - if (!sign16(v0 - 15)) { - samus_x_extra_run_speed = 15; - samus_x_extra_run_subspeed = 0; - } + AddToHiLo(&samus_x_extra_run_speed, &samus_x_extra_run_subspeed, __PAIR32__(samus_y_accel, samus_y_subaccel)); + if (!sign16(samus_x_extra_run_speed - 15)) + SetHiLo(&samus_x_extra_run_speed, &samus_x_extra_run_subspeed, INT16_SHL16(15)); int32 amt = 0; if (samus_pose_x_dir == 4) { amt = Samus_ClampSpeedHi(-(int32)Samus_CalcDisplacementMoveLeft(amt), 15); @@ -4637,7 +4603,6 @@ void Samus_ShinesparkMove_Y(void) { // 0x90D1FF samus_shine_timer = 15; AddToHiLo(&substate, &suit_pickup_light_beam_pos, __PAIR32__(samus_y_accel, samus_y_subaccel)); - AddToHiLo(&samus_y_speed, &samus_y_subspeed, __PAIR32__(substate, suit_pickup_light_beam_pos)); int32 amt = Samus_ClampSpeedHi(__PAIR32__(samus_y_speed, samus_y_subspeed), 14); amt -= __PAIR32__(extra_samus_y_displacement, extra_samus_y_subdisplacement); @@ -5025,7 +4990,7 @@ void ProjPreInstr_SpreadBomb(uint16 k) { // 0x90D8F7 AddToHiLo(&projectile_bomb_y_speed[v1], &projectile_timers[v1], __PAIR32__(samus_y_accel, samus_y_subaccel)); AddToHiLo(&projectile_y_pos[v1], &projectile_bomb_y_subpos[v1], __PAIR32__(projectile_bomb_y_speed[v1], projectile_timers[v1])); if (BlockCollSpreadBomb(k) & 1) { - AddToHiLo(&projectile_y_pos[v1], &projectile_bomb_y_subpos[v1], -(int32)__PAIR32__(projectile_bomb_y_speed[v1], projectile_timers[v1])); + AddToHiLo(&projectile_y_pos[v1], &projectile_bomb_y_subpos[v1], -IPAIR32(projectile_bomb_y_speed[v1], projectile_timers[v1])); if ((projectile_bomb_y_speed[v1] & 0x8000) != 0) { projectile_bomb_y_speed[v1] = 0; projectile_y_radius[v1] = 0; @@ -5879,11 +5844,8 @@ void Samus_Func8(void) { // 0x90E400 } void Samus_Func9(void) { // 0x90E41B - if (sign16(samus_y_speed - 5)) { - uint32 v0 = __PAIR32__(samus_y_accel, samus_y_subaccel) + __PAIR32__(samus_y_speed, samus_y_subspeed); - samus_y_speed = HIWORD(v0); - samus_y_subspeed = v0; - } + if (sign16(samus_y_speed - 5)) + AddToHiLo(&samus_y_speed, &samus_y_subspeed, __PAIR32__(samus_y_accel, samus_y_subaccel)); if ((samus_pose == kPose_29_FaceR_Fall || samus_pose == kPose_2A_FaceL_Fall || samus_pose == kPose_67_FaceR_Fall_Gun || samus_pose == kPose_68_FaceL_Fall_Gun) && !sign16(samus_y_speed - 5)) { @@ -6261,42 +6223,23 @@ void SamusMovementType_Xray(void) { // 0x90E94F } void Samus_HandlePeriodicDamage(void) { // 0x90E9CE - int16 v0; - int16 v1; - int16 v2; - - if (time_is_frozen_flag) - goto LABEL_10; - if ((equipped_items & 0x20) != 0) { - uint16 v4 = *(uint16 *)((uint8 *)&samus_periodic_subdamage + 1) >> 2; - LOBYTE(v1) = (uint16)(*(uint16 *)((uint8 *)&samus_periodic_subdamage + 1) >> 2) >> 8; - HIBYTE(v1) = *(uint16 *)((uint8 *)&samus_periodic_subdamage + 1) >> 2; - samus_periodic_subdamage = v1 & 0xFF00; - samus_periodic_damage = HIBYTE(v4); - } else if ((equipped_items & 1) != 0) { - uint16 v3 = *(uint16 *)((uint8 *)&samus_periodic_subdamage + 1) >> 1; - LOBYTE(v0) = (uint16)(*(uint16 *)((uint8 *)&samus_periodic_subdamage + 1) >> 1) >> 8; - HIBYTE(v0) = *(uint16 *)((uint8 *)&samus_periodic_subdamage + 1) >> 1; - samus_periodic_subdamage = v0 & 0xFF00; - samus_periodic_damage = HIBYTE(v3); + if (time_is_frozen_flag) { + samus_periodic_damage = samus_periodic_subdamage = 0; + return; } - if ((samus_periodic_damage & 0x8000) != 0) { + int32 t = __PAIR32__(samus_periodic_damage, samus_periodic_subdamage); + if (t < 0) { InvalidInterrupt_Crash(); return; } - v2 = (__PAIR32__(samus_health, samus_subunit_health) - __PAIR32__(samus_periodic_damage, samus_periodic_subdamage)) >> 16; - samus_subunit_health -= samus_periodic_subdamage; - samus_health = v2; - if (v2 >= 0) { -LABEL_10: - samus_periodic_subdamage = 0; - samus_periodic_damage = 0; - } else { - samus_subunit_health = 0; - samus_health = 0; - samus_periodic_subdamage = 0; - samus_periodic_damage = 0; - } + if ((equipped_items & 0x20) != 0) + t = (t >> 2) & 0xffff00; + else if ((equipped_items & 1) != 0) + t = (t >> 1) & 0xffff00; + AddToHiLo(&samus_health, &samus_subunit_health, -t); + if ((int16)samus_health < 0) + samus_health = samus_subunit_health = 0; + samus_periodic_damage = samus_periodic_subdamage = 0; } void Samus_PauseCheck(void) { // 0x90EA45 diff --git a/src/sm_94.c b/src/sm_94.c index 3f3781c..41f2829 100644 --- a/src/sm_94.c +++ b/src/sm_94.c @@ -578,8 +578,7 @@ LABEL_10: ci->ci_r18_r20 = v5 << 16; samus_x_subpos = 0; } else { - // todo: carry - int16 v4 = (__PAIR32__((ci->ci_r32 & 0xFFF8) - samus_x_radius, ci->ci_r32 & 0xFFF8) - __PAIR32__(samus_x_pos, samus_x_radius)) >> 16; + int16 v4 = (ci->ci_r32 & 0xFFF8) - samus_x_radius - samus_x_pos; if (v4 < 0) v4 = 0; ci->ci_r18_r20 = v4 << 16; @@ -616,8 +615,7 @@ LABEL_10: samus_y_subpos = 0; return 1; } else { - // todo: fix carry - int16 v4 = (__PAIR32__((ci->ci_r32 & 0xFFF8) - samus_y_radius, ci->ci_r32 & 0xFFF8) - __PAIR32__(samus_y_pos, samus_y_radius)) >> 16; + int16 v4 = (ci->ci_r32 & 0xFFF8) - samus_y_radius - samus_y_pos; if (v4 < 0) v4 = 0; ci->ci_r18_r20 = v4 << 16; @@ -2221,67 +2219,39 @@ static uint8 BlockReact_AA64(void) { // 0x94AA64 return rv; } -static const uint16 g_word_94AAD7[16] = { // 0x94AA9E - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, -}; static const uint16 g_word_94AAF7[16] = { - 0, 0, 0x10, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, + 0, 0, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static uint8 BlockReact_AA64_SpikeAir(CollInfo *ci) { - int16 v0; - int16 v2; - - if (!samus_invincibility_timer) { - v0 = *(uint16 *)&BTS[cur_block_index]; - if (v0 >= 0) { - int v1 = v0; - if (g_word_94AAF7[v1] | g_word_94AAD7[v1]) { - v2 = (g_word_94AAD7[v1] + __PAIR32__(samus_periodic_damage, samus_periodic_subdamage)) >> 16; - samus_periodic_subdamage += g_word_94AAD7[v1]; - samus_periodic_damage = g_word_94AAF7[v1] + v2; - samus_invincibility_timer = 60; - samus_knockback_timer = 10; - } + if (samus_invincibility_timer) + return 0; + int16 v0 = *(uint16 *)&BTS[cur_block_index]; + if (v0 >= 0) { + uint32 v = INT16_SHL16(g_word_94AAF7[v0]); + if (v) { + AddToHiLo(&samus_periodic_damage, &samus_periodic_subdamage, v); + samus_invincibility_timer = 60; + samus_knockback_timer = 10; } } return 0; } -static const uint16 g_word_94AB50[16] = { // 0x94AB17 - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, -}; static const uint16 g_word_94AB70[16] = { - 60, 16, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, + 60, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static uint8 BlockReact_AA64_SpikeBlock(CollInfo *ci) { - int16 v0; - int16 v2; - - if (!samus_invincibility_timer) { - v0 = *(uint16 *)&BTS[cur_block_index]; - if (v0 >= 0) { - int v1 = v0; - if (g_word_94AB70[v1] | g_word_94AB50[v1]) { - v2 = (g_word_94AB50[v1] + __PAIR32__(samus_periodic_damage, samus_periodic_subdamage)) >> 16; - samus_periodic_subdamage += g_word_94AB50[v1]; - samus_periodic_damage = g_word_94AB70[v1] + v2; - samus_invincibility_timer = 60; - samus_knockback_timer = 10; - } + if (samus_invincibility_timer) + return 1; + int16 v0 = *(uint16 *)&BTS[cur_block_index]; + if (v0 >= 0) { + uint32 v = INT16_SHL16(g_word_94AB70[v0]); + if (v) { + AddToHiLo(&samus_periodic_damage, &samus_periodic_subdamage, v); + samus_invincibility_timer = 60; + samus_knockback_timer = 10; } } return 1; diff --git a/src/sm_a0.c b/src/sm_a0.c index bad515a..f07e62b 100644 --- a/src/sm_a0.c +++ b/src/sm_a0.c @@ -3048,34 +3048,6 @@ uint16 IsSamusWithinEnemy_X(uint16 k, uint16 a) { // 0xA0AF0B return (int16)(SubtractThenAbs16(gEnemyData(k)->x_pos, samus_x_pos) - a) < 0; } -void Enemy_SubPos_X(uint16 k, uint32 amount32) { // 0xA0AF5A - EnemyData *E = gEnemyData(k); - uint32 t = __PAIR32__(E->x_pos, E->x_subpos) - amount32; - E->x_subpos = t; - E->x_pos = t >> 16; -} - -void Enemy_AddPos_X(uint16 k, uint32 amount32) { // 0xA0AF6C - EnemyData *E = gEnemyData(k); - uint32 t = __PAIR32__(E->x_pos, E->x_subpos) + amount32; - E->x_subpos = t; - E->x_pos = t >> 16; -} - -void Enemy_SubPos_Y(uint16 k, uint32 amount32) { // 0xA0AF7E - EnemyData *E = gEnemyData(k); - uint32 t = __PAIR32__(E->y_pos, E->y_subpos) - amount32; - E->y_subpos = t; - E->y_pos = t >> 16; -} - -void Enemy_AddPos_Y(uint16 k, uint32 amount32) { // 0xA0AF90 - EnemyData *E = gEnemyData(k); - uint32 t = __PAIR32__(E->y_pos, E->y_subpos) + amount32; - E->y_subpos = t; - E->y_pos = t >> 16; -} - uint16 SignExtend8(uint16 a) { // 0xA0AFEA // not quite sign extend return (a & 0x80) ? a | 0xff00 : a; @@ -3102,9 +3074,6 @@ static uint32 SineMult8bitInner(uint16 varE32, uint16 varE34) { // 0xA0B0DA b = -b; } return __PAIR32__(a, b); -// varE38 = b; -// varE36 = a; -// return a; } uint16 CosineMult8bit(uint16 a, uint16 varE32) { // 0xA0B0B2 @@ -3123,7 +3092,6 @@ uint32 SineMult8bitFull(uint16 a, uint16 varE32) { return SineMult8bitInner(varE32, (uint8)(a + 0x80)); } - Point32 ConvertAngleToXy(uint16 r18, uint16 r20) { // 0xA0B643 uint32 ss = kEquationForQuarterCircle[(r18 + 0x40) & 0x7F] * r20; uint32 tt = kEquationForQuarterCircle[(r18 + 0x80) & 0x7F] * r20; @@ -3282,8 +3250,6 @@ uint8 EnemyFunc_BBBF(uint16 k, int32 amt) { // 0xA0BBBF uint16 prod = Mult8x8((uint16)(E->y_pos - E->y_height) >> 4, room_width_in_blocks); uint16 i = (amt + __PAIR32__(E->x_pos, E->x_subpos)) >> 16; uint16 j; - //R22_ = r18 + E->x_subpos; - //r24 = i; if (sign32(amt)) j = i - E->x_width; else @@ -3295,62 +3261,30 @@ uint8 EnemyFunc_BBBF(uint16 k, int32 amt) { // 0xA0BBBF if ((--R26 & 0x8000) != 0) return 0; } - /* - r18 = 0; - if (sign32(amt)) { - v8 = R34 | 0xF; - v11 = E->x_width + 1 + v8 - E->x_pos; - if (v11 >= 0) - v11 = 0; - r20 = -v11; - } else { - v7 = (R34 & 0xFFF0) - E->x_width - E->x_pos; - if (v7 < 0) - v7 = 0; - r20 = v7; - }*/ return 1; } uint8 EnemyFunc_BC76(uint16 k, int32 amt) { // 0xA0BC76 - int16 v4; - EnemyData *E = gEnemyData(k); uint16 R26 = (E->x_pos - E->x_width) & 0xFFF0; R26 = (uint16)(E->x_width + E->x_pos - 1 - R26) >> 4; uint16 i = (amt + __PAIR32__(E->y_pos, E->y_subpos)) >> 16; uint16 j; - //R22_ = r18 + E->y_subpos; - //r24 = i; if (sign32(amt)) j = i - E->y_height; else j = E->y_height + i - 1; uint16 R34 = j; uint16 prod = Mult8x8(j >> 4, room_width_in_blocks); - v4 = (uint16)(E->x_pos - E->x_width) >> 4; + int16 v4 = (uint16)(E->x_pos - E->x_width) >> 4; for (int i = 2 * (prod + v4); (level_data[i >> 1] & 0x8000) == 0; i += 2) { if ((--R26 & 0x8000) != 0) return 0; } - /*r18 = 0; - if (sign32(amt)) { - v9 = R34 | 0xF; - v12 = E->y_height + 1 + v9 - E->y_pos; - if (v12 >= 0) - v12 = 0; - r20 = -v12; - } else { - v8 = (R34 & 0xFFF0) - E->y_height - E->y_pos; - if (v8 < 0) - v8 = 0; - r20 = v8; - }*/ return 1; } uint8 EnemyFunc_BF8A(uint16 k, uint16 a, int32 amt) { // 0xA0BF8A - int16 v6; uint16 v4; EnemyData *E = gEnemyData(k); @@ -3359,34 +3293,18 @@ uint8 EnemyFunc_BF8A(uint16 k, uint16 a, int32 amt) { // 0xA0BF8A if (a & 1) { uint16 j = (amt + __PAIR32__(E->y_pos, E->y_subpos)) >> 16; - //R22_ = r18 + E->y_subpos; - //r24 = j; v4 = E->y_height + j - 1; } else { uint16 v5 = (__PAIR32__(E->y_pos, E->y_subpos) - amt) >> 16; - //R22_ = E->y_subpos - r18; - //r24 = v5; v4 = v5 - E->y_height; } uint16 R34 = v4; uint16 prod = Mult8x8(v4 >> 4, room_width_in_blocks); - v6 = (uint16)(E->x_pos - E->x_width) >> 4; + int16 v6 = (uint16)(E->x_pos - E->x_width) >> 4; for (int i = 2 * (prod + v6); (level_data[i >> 1] & 0x8000) == 0; i += 2) { if ((--R26 & 0x8000) != 0) return 0; } -/* r18 = 0; - if (a & 1) { - v10 = (__PAIR32__((R34 & 0xFFF0) - E->y_height, R34 & 0xFFF0) - __PAIR32__(E->y_pos, E->y_height)) >> 16; - if (v10 < 0) - v10 = 0; - r20 = v10; - } else { - v13 = E->y_height + 1 + (R34 | 0xF) - E->y_pos; - if (v13 >= 0) - v13 = 0; - r20 = -v13; - }*/ return 1; } @@ -3718,7 +3636,6 @@ uint8 Enemy_MoveDown(uint16 k, int32 amount32) { // 0xA0C786 uint16 r30 = r28; uint32 new_pos = amount32 + __PAIR32__(E->y_pos, E->y_subpos); uint16 r24 = new_pos >> 16; // read by EnemyBlockCollVertReact_Slope_NonSquare -// R22_ = new_pos; if (sign32(amount32)) v5 = (new_pos >> 16) - E->y_height; else diff --git a/src/sm_a2.c b/src/sm_a2.c index dad24f9..0adf217 100644 --- a/src/sm_a2.c +++ b/src/sm_a2.c @@ -464,12 +464,9 @@ void MaridiaBeybladeTurtle_Func6(uint16 k) { // 0xA28F5F if (CheckIfEnemyTouchesSamus(k)) { Enemy_MaridiaTurtle *E = Get_MaridiaTurtle(k); E->mte_var_A = FUNC16(MaridiaBeybladeTurtle_Func9); - uint16 v2 = (__PAIR32__(extra_samus_x_displacement, extra_samus_x_subdisplacement) - - __PAIR32__(E->mte_var_E, E->mte_var_03)) >> 16; - extra_samus_x_subdisplacement -= E->mte_var_03; - if (sign16(v2 + 16)) - v2 = -16; - extra_samus_x_displacement = v2; + AddToHiLo(&extra_samus_x_displacement, &extra_samus_x_subdisplacement, -IPAIR32(E->mte_var_E, E->mte_var_03)); + if (sign16(extra_samus_x_displacement + 16)) + extra_samus_x_displacement = -16; } } @@ -498,8 +495,8 @@ void MaridiaBeybladeTurtle_Func8(uint16 k) { // 0xA28FEB MaridiaBeybladeTurtle_Func4(); Enemy_MaridiaTurtle *E = Get_MaridiaTurtle(k); if (Enemy_MoveRight_IgnoreSlopes(k, __PAIR32__(E->mte_var_E, E->mte_var_03))) { - Negate32(&E->mte_var_E, &E->mte_var_03, &E->mte_var_E, &E->mte_var_03); - Negate32(&E->mte_var_02, &E->mte_var_01, &E->mte_var_02, &E->mte_var_01); + SetHiLo(&E->mte_var_E, &E->mte_var_03, -IPAIR32(E->mte_var_E, E->mte_var_03)); + SetHiLo(&E->mte_var_02, &E->mte_var_01, -IPAIR32(E->mte_var_02, E->mte_var_01)); earthquake_type = 0; earthquake_timer = 16; QueueSfx2_Max6(0x1B); @@ -3631,7 +3628,7 @@ void TimedShutter_Func_10(uint16 k) { void TimedShutter_Func_11(void) { // 0xA2EC45 Enemy_TimedShutter *E = Get_TimedShutter(cur_enemy_index); - AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -(int32)__PAIR32__(E->tsr_var_00, E->tsr_var_01)); + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -IPAIR32(E->tsr_var_00, E->tsr_var_01)); int16 v3 = E->tsr_var_B - 16; if ((int16)(v3 - E->base.y_pos) >= 0) { E->base.y_pos = v3 + 7; @@ -3644,7 +3641,7 @@ void TimedShutter_Func_11(void) { // 0xA2EC45 void TimedShutter_Func_12(void) { // 0xA2EC86 Enemy_TimedShutter *E = Get_TimedShutter(cur_enemy_index); - AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -(int32)__PAIR32__(E->tsr_var_00, E->tsr_var_01)); + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -IPAIR32(E->tsr_var_00, E->tsr_var_01)); int16 v3 = E->tsr_var_C - 16; if ((int16)(v3 - E->base.y_pos) >= 0) { E->base.y_pos = v3 + 7; @@ -3657,7 +3654,7 @@ void TimedShutter_Func_12(void) { // 0xA2EC86 void TimedShutter_Func_13(void) { // 0xA2ECC7 Enemy_TimedShutter *E = Get_TimedShutter(cur_enemy_index); - AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -(int32)__PAIR32__(E->tsr_var_00, E->tsr_var_01)); + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -IPAIR32(E->tsr_var_00, E->tsr_var_01)); int16 v3 = E->tsr_var_D - 16; if ((int16)(v3 - E->base.y_pos) >= 0) { E->base.y_pos = v3 + 7; @@ -3670,7 +3667,7 @@ void TimedShutter_Func_13(void) { // 0xA2ECC7 void TimedShutter_Func_14(void) { // 0xA2ED08 Enemy_TimedShutter *E = Get_TimedShutter(cur_enemy_index); - AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -(int32)__PAIR32__(E->tsr_var_00, E->tsr_var_01)); + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -IPAIR32(E->tsr_var_00, E->tsr_var_01)); uint16 v3 = E->tsr_var_E - 16; if ((int16)(v3 - E->base.y_pos) >= 0) { E->base.y_pos = v3; diff --git a/src/sm_a3.c b/src/sm_a3.c index b5db31f..23f8a92 100644 --- a/src/sm_a3.c +++ b/src/sm_a3.c @@ -496,10 +496,8 @@ void Elevator_Init(void) { // 0xA394E6 E->base.current_instruction = addr_kElevator_Ilist_94D6; E->elevat_parameter_1 *= 2; E->elevat_var_A = E->base.y_pos; - if (elevator_status != 2) { - elevator_flags = 0; - elevator_status = 0; - } + if (elevator_status != 2) + elevator_flags = elevator_status = 0; if (__PAIR32__(elevator_status, elevator_flags)) { E->base.y_pos = E->elevat_parameter_2; Elevator_Func_4(); @@ -1544,7 +1542,7 @@ void MaridiaRefillCandy_Func_2(uint16 k) { // 0xA3B4A8 Enemy_MaridiaRefillCandy *E = Get_MaridiaRefillCandy(k); E->base.properties &= ~kEnemyProps_Invisible; if ((GetSamusEnemyDelta_Y(k) & 0x8000) != 0) { - Enemy_SubPos_Y(k, 0x8000); + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -0x8000); } else { --E->mrcy_var_D; MaridiaRefillCandy_Func_4(); @@ -1556,10 +1554,8 @@ void MaridiaRefillCandy_Func_2(uint16 k) { // 0xA3B4A8 void MaridiaRefillCandy_Func_3(uint16 k) { // 0xA3B4D6 Enemy_MaridiaRefillCandy *E = Get_MaridiaRefillCandy(k); int v2 = E->mrcy_var_00 >> 1; - if (E->mrcy_var_D) - Enemy_AddPos_X(k, __PAIR32__(g_word_A3B415[v2], g_word_A3B415[v2 + 1])); - else - Enemy_SubPos_X(k, __PAIR32__(g_word_A3B415[v2], g_word_A3B415[v2 + 1])); + int32 v = __PAIR32__(g_word_A3B415[v2], g_word_A3B415[v2 + 1]); + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, E->mrcy_var_D ? v : -v); if (!CheckIfEnemyIsOnScreen()) { MaridiaRefillCandy_Func_4(); return; diff --git a/src/sm_a4.c b/src/sm_a4.c index d5f85ff..df10a82 100644 --- a/src/sm_a4.c +++ b/src/sm_a4.c @@ -504,10 +504,7 @@ void Crocomire_Func_29(void) { // 0xA48C90 void Crocomire_Func_30(void) { // 0xA48C95 Enemy_Crocomire *E = Get_Crocomire(0); - if (!E->crocom_var_A - && (((__PAIR32__(E->base.x_pos - E->base.x_width, E->base.x_pos) - - __PAIR32__(samus_x_radius, E->base.x_width) - - __PAIR32__(samus_x_pos, (E->base.x_pos < E->base.x_width) + samus_x_radius)) >> 16) & 0x8000) != 0) { + if (!E->crocom_var_A && (int16)(E->base.x_pos - E->base.x_width - samus_x_radius - samus_x_pos) < 0) { NormalEnemyTouchAi(); samus_x_pos = E->base.x_pos - E->base.x_width - samus_x_radius; samus_prev_x_pos = samus_x_pos; @@ -1379,13 +1376,11 @@ void Crocomire_Func_72(void) { // 0xA499E5 AddToHiLo(&E->base.x_pos, &E->base.x_subpos, t); } Enemy_Crocomire *E2 = Get_Crocomire(0x80); - if (E2->crocom_var_D) { - if (E2->crocom_var_D-- == 1) { - E->crocom_var_E = 0; - E->base.current_instruction = addr_kCrocomire_Ilist_E14A; - E->base.instruction_timer = 1; - Crocomire_9BB3(); - } + if (E2->crocom_var_D && E2->crocom_var_D-- == 1) { + E->crocom_var_E = 0; + E->base.current_instruction = addr_kCrocomire_Ilist_E14A; + E->base.instruction_timer = 1; + Crocomire_9BB3(); } } diff --git a/src/sm_a5.c b/src/sm_a5.c index 7afad8d..ba85625 100644 --- a/src/sm_a5.c +++ b/src/sm_a5.c @@ -309,7 +309,7 @@ void Draygon_Func_11(void) { // 0xA58A00 Get_Draygon(cur_enemy_index)->base.y_pos = *(uint16 *)((uint8 *)&g_word_7E9002 + draygon_var_B); E->draygon_var_B -= 4; if (E->draygon_var_B) { - AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -(int32)__PAIR32__(E->draygon_var_D, E->draygon_var_E)); + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -IPAIR32(E->draygon_var_D, E->draygon_var_E)); } else { E->draygon_var_A = FUNC16(Draygon_Func_12); } @@ -347,7 +347,7 @@ void Draygon_Func_13(void) { // 0xA58A90 E->base.x_pos = E->draygon_var_00; } } else { - AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -(int32)__PAIR32__(E->draygon_var_D, E->draygon_var_E)); + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -IPAIR32(E->draygon_var_D, E->draygon_var_E)); } } @@ -455,7 +455,7 @@ void Draygon_Func_19(void) { // 0xA58CD4 } else { E->base.y_pos = CosineMult8bit(E->draygon_var_0D, 32) + 384; E->draygon_var_0D = (uint8)(E->draygon_var_0D + 1); - AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -(int32)__PAIR32__(E->draygon_var_D, E->draygon_var_E)); + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -IPAIR32(E->draygon_var_D, E->draygon_var_E)); } } @@ -473,7 +473,7 @@ void Draygon_Func_20(void) { // 0xA58D30 } E->base.y_pos = CosineMult8bit(E->draygon_var_0D, 32) + 384; E->draygon_var_0D = (uint8)(E->draygon_var_0D + 1); - AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -(int32)__PAIR32__(E->draygon_var_D, E->draygon_var_E)); + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -IPAIR32(E->draygon_var_D, E->draygon_var_E)); if ((int32)E->base.x_pos < 0 && sign16(E->base.x_pos + 80)) { LABEL_8: if (!samus_x_speed_divisor) { @@ -496,7 +496,7 @@ void Draygon_Func_21(uint16 k) { // 0xA58DB2 } else { E->base.y_pos = CosineMult8bit(E->draygon_var_0D, 32) + 384; E->draygon_var_0D = (uint8)(E->draygon_var_0D + 1); - AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -(int32)__PAIR32__(E->draygon_var_D, E->draygon_var_E)); + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -IPAIR32(E->draygon_var_D, E->draygon_var_E)); if ((int16)E->base.x_pos < 0 && sign16(E->base.x_pos + 80)) { E->draygon_var_A = FUNC16(Draygon_Func_4); E->base.x_pos = -80; diff --git a/src/sm_a6.c b/src/sm_a6.c index 3b128a5..4f455ba 100644 --- a/src/sm_a6.c +++ b/src/sm_a6.c @@ -400,12 +400,10 @@ void SpikeyPlatform_Func_1(void) { // 0xA68BB4 } void SpikeyPlatform_Func_2(void) { // 0xA68BDC - int16 v4; - Enemy_SpikeyPlatform *E = Get_SpikeyPlatform(cur_enemy_index); E->spm_var_01 = E->base.y_pos; int v1 = E->spm_var_02 >> 1; - Enemy_AddPos_Y(cur_enemy_index, __PAIR32__(kCommonEnemySpeeds_Linear[v1], kCommonEnemySpeeds_Linear[v1 + 1])); + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, __PAIR32__(kCommonEnemySpeeds_Linear[v1], kCommonEnemySpeeds_Linear[v1 + 1])); if ((int16)(E->base.y_pos - E->spm_var_D) >= 0) { E->spm_var_03 = 64; E->spm_var_A = FUNC16(SpikeyPlatform_Func_3); @@ -414,7 +412,7 @@ void SpikeyPlatform_Func_2(void) { // 0xA68BDC } if (SpikeyPlatform_Func_5(cur_enemy_index)) extra_samus_y_displacement += E->base.y_pos - E->spm_var_01; - v4 = E->spm_var_02 + 8; + int16 v4 = E->spm_var_02 + 8; if (!sign16(E->spm_var_02 - 504)) v4 = 512; E->spm_var_02 = v4; @@ -431,7 +429,7 @@ void SpikeyPlatform_Func_3(uint16 k) { // 0xA68C4A void SpikeyPlatform_Func_4(void) { // 0xA68C5D Enemy_SpikeyPlatform *E = Get_SpikeyPlatform(cur_enemy_index); E->spm_var_01 = E->base.y_pos; - Enemy_SubPos_Y(cur_enemy_index, 0x8000); + AddToHiLo(&E->base.y_pos, &E->base.y_subpos, -0x8000); if ((int16)(E->base.y_pos - E->spm_var_C) < 0) { E->spm_var_A = FUNC16(SpikeyPlatform_Func_1); E->base.y_pos = E->spm_var_C; diff --git a/src/sm_a7.c b/src/sm_a7.c index 4f73bcf..823b252 100644 --- a/src/sm_a7.c +++ b/src/sm_a7.c @@ -1048,31 +1048,24 @@ void KraidLint_ProduceLint(uint16 k) { // 0xA7B832 } void KraidLint_ChargeLint(uint16 k) { // 0xA7B868 - int16 v1; - - v1 = 0; - EnemyData *v2 = gEnemyData(k); - EnemyData *v3 = v2; - if ((v2->ai_preinstr & 1) != 0) + EnemyData *E = gEnemyData(k); + int16 v1 = 0; + if ((E->ai_preinstr & 1) != 0) v1 = 3584; - v2->palette_index = v1; - v2->x_pos = v2->ai_var_C + gEnemyData(0)->x_pos - v2->ai_var_B; - if (v3->ai_preinstr-- == 1) { - v3->ai_var_A = FUNC16(KraidLint_FireLint); + E->palette_index = v1; + E->x_pos = E->ai_var_C + gEnemyData(0)->x_pos - E->ai_var_B; + if (E->ai_preinstr-- == 1) { + E->ai_var_A = FUNC16(KraidLint_FireLint); QueueSfx3_Max6(0x1F); } } void KraidLint_FireLint(uint16 k) { // 0xA7B89B Enemy_Kraid *E = Get_Kraid(k); - uint16 x_subpos = E->base.x_subpos; - bool v3 = x_subpos < g_word_A7A926; - E->base.x_subpos = x_subpos - g_word_A7A926; - uint16 v4 = E->base.x_pos - (v3 + g_word_A7A928); - E->base.x_pos = v4; - if (sign16(v4 - 56)) + AddToHiLo(&E->base.x_pos, &E->base.x_subpos, -IPAIR32(g_word_A7A928, g_word_A7A926)); + if (sign16(E->base.x_pos - 56)) E->base.properties |= kEnemyProps_Tangible; - if (sign16(v4 - 32)) { + if (sign16(E->base.x_pos - 32)) { E->base.properties |= kEnemyProps_Invisible; E->kraid_var_A = FUNC16(Kraid_AlignEnemyToKraid); E->kraid_var_F = 300; @@ -1080,12 +1073,9 @@ void KraidLint_FireLint(uint16 k) { // 0xA7B89B E->kraid_var_B = 0; } if (CheckIfEnemyTouchesSamus(k)) { - uint16 v5 = (__PAIR32__(extra_samus_x_displacement, extra_samus_x_subdisplacement) - - __PAIR32__(g_word_A7A928, g_word_A7A926)) >> 16; - extra_samus_x_subdisplacement -= g_word_A7A926; - if (sign16(v5 + 16)) - v5 = -16; - extra_samus_x_displacement = v5; + AddToHiLo(&extra_samus_x_displacement, &extra_samus_x_subdisplacement, -IPAIR32(g_word_A7A928, g_word_A7A926)); + if (sign16(extra_samus_x_displacement + 16)) + extra_samus_x_displacement = -16; } } @@ -1100,10 +1090,8 @@ void KraidFingernail_WaitForLintXpos(uint16 k) { // 0xA7B907 void KraidEnemy_HandleFunctionTimer(uint16 k) { // 0xA7B92D Enemy_Kraid *E = Get_Kraid(k); - if (E->kraid_var_F) { - if (E->kraid_var_F-- == 1) - E->kraid_var_A = E->kraid_next; - } + if (E->kraid_var_F && E->kraid_var_F-- == 1) + E->kraid_var_A = E->kraid_next; } void Kraid_AlignEnemyToKraid(uint16 k) { // 0xA7B923 @@ -1433,9 +1421,8 @@ void KraidsFingernail_Fire(uint16 k) { // 0xA7BE8E } } EnemyData *v5 = gEnemyData(k); - if (Enemy_MoveDown(k, __PAIR32__(v5->ai_var_E, v5->ai_var_D))) { - Negate32(&v5->ai_var_E, &v5->ai_var_D, &v5->ai_var_E, &v5->ai_var_D); - } + if (Enemy_MoveDown(k, __PAIR32__(v5->ai_var_E, v5->ai_var_D))) + SetHiLo(&v5->ai_var_E, &v5->ai_var_D, -IPAIR32(v5->ai_var_E, v5->ai_var_D)); } void KraidsFoot_PrepareToLungeForward(void) { // 0xA7BF2D @@ -2015,14 +2002,9 @@ void Kraid_Raise_Handler(void) { // 0xA7C924 Kraid_RestrictSamusXtoFirstScreen_2(); if ((earthquake_timer & 5) == 0) Kraid_SpawnRandomQuakeProjs(); - uint16 v0 = 1; Enemy_Kraid *E0 = Get_Kraid(0); - if ((E0->base.y_pos & 2) == 0) - v0 = -1; - E0->base.x_pos += v0; - uint16 y_subpos = E0->base.y_subpos; - E0->base.y_subpos = y_subpos + 0x8000; - E0->base.y_pos = (__PAIR32__(E0->base.y_pos, y_subpos) - 0x8000) >> 16; + E0->base.x_pos += (E0->base.y_pos & 2) == 0 ? -1 : 1; + AddToHiLo(&E0->base.y_pos, &E0->base.y_subpos, -0x8000); if (sign16(E0->base.y_pos - 457)) { E0->base.x_pos = 176; Enemy_Kraid *E5 = Get_Kraid(0x140); @@ -2348,7 +2330,7 @@ void Phantoon_AdjustSpeedLeftSideClockwise(void) { // 0xA7D114 ++E->phant_var_D; } } else { - AddToHiLo(&E->phant_var_C, &E->phant_var_B, -(int32)__PAIR32__(g_word_A7CD79, g_word_A7CD77)); + AddToHiLo(&E->phant_var_C, &E->phant_var_B, -IPAIR32(g_word_A7CD79, g_word_A7CD77)); if (E->phant_var_C == g_word_A7CD7F || (int16)(E->phant_var_C - g_word_A7CD7F) < 0) { E->phant_var_C = g_word_A7CD7F + 1; E->phant_var_B = 0; @@ -2370,7 +2352,7 @@ void Phantoon_AdjustSpeedRightSideClockwise(void) { // 0xA7D193 uint16 phant_var_D = E->phant_var_D; if (phant_var_D) { if ((phant_var_D & 1) != 0) { - AddToHiLo(&E->phant_var_C, &E->phant_var_B, -(int32)__PAIR32__(g_word_A7CD87, g_word_A7CD85)); + AddToHiLo(&E->phant_var_C, &E->phant_var_B, -IPAIR32(g_word_A7CD87, g_word_A7CD85)); if (E->phant_var_C == g_word_A7CD8B || (int16)(E->phant_var_C - g_word_A7CD8B) < 0) { E->phant_var_C = g_word_A7CD8B + 1; E->phant_var_B = 0; @@ -2385,7 +2367,7 @@ void Phantoon_AdjustSpeedRightSideClockwise(void) { // 0xA7D193 } } } else { - AddToHiLo(&E->phant_var_C, &E->phant_var_B, -(int32)__PAIR32__(g_word_A7CD83, g_word_A7CD81)); + AddToHiLo(&E->phant_var_C, &E->phant_var_B, -IPAIR32(g_word_A7CD83, g_word_A7CD81)); if (E->phant_var_C == g_word_A7CD89 || (int16)(E->phant_var_C - g_word_A7CD89) < 0) { E->phant_var_C = (uint16)(g_word_A7CD89 + 2); E->phant_var_B = 0; diff --git a/src/sm_a8.c b/src/sm_a8.c index 9d3ed77..1d8cef7 100644 --- a/src/sm_a8.c +++ b/src/sm_a8.c @@ -1949,7 +1949,7 @@ void Beetom_Func_18(void) { // 0xA8B9C1 E->base.x_pos -= 8; if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { E->base.x_pos += 8; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-1, -16384))) + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, -16384)) E->beetom_var_C = FUNC16(Beetom_Func_7); } else { E->beetom_var_C = FUNC16(Beetom_Func_7); @@ -1968,7 +1968,7 @@ void Beetom_Func_19(void) { // 0xA8BA24 E->base.x_pos += 8; if (Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1))) { E->base.x_pos -= 8; - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(0, 0x4000))) + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, 0x4000)) E->beetom_var_C = FUNC16(Beetom_Func_6); } else { E->beetom_var_C = FUNC16(Beetom_Func_6); @@ -2010,7 +2010,7 @@ void Beetom_Func_20(void) { // 0xA8BA84 Beetom_Func_23(cur_enemy_index); else Beetom_Func_22(cur_enemy_index); - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-1, -16384))) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, -16384)) { E->beetom_var_09 ^= 1; E->beetom_var_C = FUNC16(Beetom_Func_15); } @@ -2022,7 +2022,7 @@ void Beetom_Func_21(void) { // 0xA8BAB7 Beetom_Func_23(cur_enemy_index); else Beetom_Func_22(cur_enemy_index); - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(0, 0x4000))) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, 0x4000)) { E->beetom_var_09 ^= 1; E->beetom_var_C = FUNC16(Beetom_Func_15); } @@ -2060,7 +2060,7 @@ void Beetom_Func_24(void) { // 0xA8BB55 Beetom_Func_27(cur_enemy_index); else Beetom_Func_26(cur_enemy_index); - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-1, -16384))) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, -16384)) { E->beetom_var_09 ^= 1; E->beetom_var_C = FUNC16(Beetom_Func_15); } @@ -2072,7 +2072,7 @@ void Beetom_Func_25(void) { // 0xA8BB88 Beetom_Func_27(cur_enemy_index); else Beetom_Func_26(cur_enemy_index); - if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(0, 0x4000))) { + if (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, 0x4000)) { E->beetom_var_09 ^= 1; E->beetom_var_C = FUNC16(Beetom_Func_15); } diff --git a/src/sm_b2.c b/src/sm_b2.c index 358c1c9..c02a431 100644 --- a/src/sm_b2.c +++ b/src/sm_b2.c @@ -721,7 +721,7 @@ void WalkingSpacePirates_FD44(void) { // 0xB2FD44 if (result) { EnemyFunc_BBBF(cur_enemy_index, INT16_SHL16(-9)); - if (!Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(-1, -14337))) { + if (!Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, -14337)) { if ((int16)(E->base.x_pos - E->sps_var_E) >= 0) return; } @@ -749,7 +749,7 @@ void WalkingSpacePirates_FDCE(void) { // 0xB2FDCE uint8 result = Enemy_MoveDown(cur_enemy_index, INT16_SHL16(1)); E->base.x_pos = E->sps_var_00; if (!result || - (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, __PAIR32__(0, 14336))) || + (Enemy_MoveRight_IgnoreSlopes(cur_enemy_index, 14336)) || (int16)(E->base.x_pos - E->sps_var_F) >= 0) { E->base.current_instruction = addr_kSpacePirates_Ilist_FC48; E->base.instruction_timer = 1; diff --git a/src/sm_cpu_infra.c b/src/sm_cpu_infra.c index 215386d..66e279b 100644 --- a/src/sm_cpu_infra.c +++ b/src/sm_cpu_infra.c @@ -195,8 +195,6 @@ static const uint32 kPatchedCarrys[] = { 0x84ba35, 0x84d6ae, 0x84d6bf, - 0x84d7f4, - 0x84d803, 0x84d812, 0x84daae, 0x84dbaa, @@ -273,6 +271,30 @@ static const uint32 kPatchedCarrys[] = { 0xA8a573, 0xA8a57f, 0xA8a58b, + + 0x84D7CB, // PlmInstr room_width + 0x84D7E2, + 0x84D7F4, + 0x84D803, + + 0x8888CD, + + 0x8888F0, + 0x8888E3, + + 0x80A5F3, + 0x80A845, + 0x80A925, + 0x80A6AA, + + 0x948D94, + 0x948E25, + + 0x9082A8, + 0x9082AE, + + 0xA48CA1, + 0xA48CA4, }; static uint8 kPatchedCarrysOrg[arraysize(kPatchedCarrys)]; @@ -662,7 +684,10 @@ void FixupCarry(uint32 addr) { *SnesRomPtr(addr) = 0; } +uint16 currently_installed_bug_fix_counter; + void RtlUpdateSnesPatchForBugfix() { + currently_installed_bug_fix_counter = bug_fix_counter; // Patch HandleMessageBoxInteraction logic { uint8 t[] = { 0x20, 0x50, 0x96, 0x60 }; PatchBytes(0x8584A3, t, sizeof(t)); } // while ((bug_fix_counter < 1 ? joypad1_newkeys : joypad1_lastkeys) == 0); @@ -859,7 +884,6 @@ Snes *SnesInit(const char *filename) { { uint8 t[] = { 0xA5, 0x12, 0x48, 0xA5, 0x14, 0x48, 0xA5, 0x16, 0x48, 0x22, 0xA7, 0xA6, 0xA0, 0x68, 0x85, 0x16, 0x68, 0x85, 0x14, 0x68, 0x85, 0x12, 0x6B }; PatchBytes(0xA7FF82, t, sizeof(t)); } { uint8 t[] = { 0x22, 0x82, 0xff, 0xa7 }; PatchBytes(0xa7b03a, t, sizeof(t)); } - RtlUpdateSnesPatchForBugfix(); for (size_t i = 0; i != arraysize(kPatchedCarrys); i++) { diff --git a/src/sm_rtl.c b/src/sm_rtl.c index 108d3f1..b3e21ed 100644 --- a/src/sm_rtl.c +++ b/src/sm_rtl.c @@ -7,10 +7,6 @@ #include "spc_player.h" #include "util.h" - - - - struct StateRecorder; static void RtlSaveMusicStateToRam_Locked(); @@ -417,7 +413,6 @@ bool RtlRunFrame(int inputs) { if (bug_fix_counter < kCurrentBugFixCounter) { bug_fix_counter = kCurrentBugFixCounter; StateRecorder_RecordPatchByte(&state_recorder, (uint8 *)&bug_fix_counter - g_ram, (uint8 *)&bug_fix_counter, 2); - RtlUpdateSnesPatchForBugfix(); } } } @@ -425,6 +420,9 @@ bool RtlRunFrame(int inputs) { StateRecorder_Record(&state_recorder, inputs); } + if (bug_fix_counter != currently_installed_bug_fix_counter) + RtlUpdateSnesPatchForBugfix(); + g_rtl_runframe(inputs, 0); snes_frame_counter++; @@ -495,13 +493,6 @@ void MemCpy(void *dst, const void *src, int size) { memcpy(dst, src, size); } -void Negate32(const uint16 *src_hi, const uint16 *src_lo, uint16 *dst_hi, uint16 *dst_lo) { - uint32 x = (uint32)*src_hi << 16 | *src_lo; - x = -(int)x; - *dst_lo = x; - *dst_hi = x >> 16; -} - PairU16 MakePairU16(uint16 k, uint16 j) { PairU16 r = { k, j }; return r; diff --git a/src/sm_rtl.h b/src/sm_rtl.h index 2417027..73f8e5e 100644 --- a/src/sm_rtl.h +++ b/src/sm_rtl.h @@ -153,6 +153,7 @@ void RtlReadSram(); void RtlWriteSram(); void RtlSaveSnapshot(const char *filename, bool saving_with_bug); void RtlUpdateSnesPatchForBugfix(); +extern uint16 currently_installed_bug_fix_counter; uint16 Mult8x8(uint8 a, uint8 b); uint16 SnesDivide(uint16 a, uint8 b); @@ -180,8 +181,6 @@ enum { kJoypadH_AnyDir = 0xf, }; -void Negate32(const uint16 *src_hi, const uint16 *src_lo, uint16 *dst_hi, uint16 *dst_lo); - struct OamEnt; struct VramWriteEntry; diff --git a/src/types.h b/src/types.h index 9c8ecfc..eab300a 100644 --- a/src/types.h +++ b/src/types.h @@ -153,6 +153,7 @@ typedef struct Rect16U { // Generate a pair of operands. #define __PAIR32__(high, low) (((uint32) (high) << 16) | (uint16)(low)) +#define IPAIR32(high, low) ((int32)(( (high) << 16) | (uint16)(low))) // Helper functions to represent some assembly instructions. diff --git a/src/variables.h b/src/variables.h index db7d156..813b15b 100644 --- a/src/variables.h +++ b/src/variables.h @@ -15,7 +15,6 @@ static inline void SetHiLo(uint16 *hi, uint16 *lo, uint32 t) { *hi = t >> 16; } - extern int32 *cur_coll_amt32; // Not used anymore @@ -1044,25 +1043,25 @@ extern int32 *cur_coll_amt32; #define hdma_table_2 ((uint16*)(g_ram+0x9D00)) #define hdma_window_1_left_pos ((ExpandingSquareTransitionHdma*)(g_ram+0x9E00)) #define hdma_window_1_right_pos ((ExpandingSquareTransitionHdma*)(g_ram+0x9E10)) -#define expanding_square_topbottom_margin_right_pos (*(uint16*)(g_ram+0x9E20)) -#define expanding_square_topbottom_margin_left_pos (*(uint16*)(g_ram+0x9E22)) -#define expanding_square_left_subpos (*(uint16*)(g_ram+0x9E30)) -#define expanding_square_left_pos (*(uint16*)(g_ram+0x9E32)) -#define expanding_square_right_subpos (*(uint16*)(g_ram+0x9E34)) -#define expanding_square_right_pos (*(uint16*)(g_ram+0x9E36)) -#define expanding_square_top_subpos (*(uint16*)(g_ram+0x9E38)) -#define expanding_square_top_pos (*(uint16*)(g_ram+0x9E3A)) -#define expanding_square_bottom_subpos (*(uint16*)(g_ram+0x9E3C)) -#define expanding_square_bottom_pos (*(uint16*)(g_ram+0x9E3E)) -#define expanding_square_left_subvel (*(uint16*)(g_ram+0x9E40)) -#define expanding_square_left_vel (*(uint16*)(g_ram+0x9E42)) -#define expanding_square_right_subvel (*(uint16*)(g_ram+0x9E44)) -#define expanding_square_right_vel (*(uint16*)(g_ram+0x9E46)) -#define expanding_square_top_subvel (*(uint16*)(g_ram+0x9E48)) -#define expanding_square_top_vel (*(uint16*)(g_ram+0x9E4A)) -#define expanding_square_bottom_subvel (*(uint16*)(g_ram+0x9E4C)) -#define expanding_square_bottom_vel (*(uint16*)(g_ram+0x9E4E)) -#define expanding_square_timer (*(uint16*)(g_ram+0x9E50)) +#define expand_sq_topbottom_margin_right_pos (*(uint16*)(g_ram+0x9E20)) +#define expand_sq_topbottom_margin_left_pos (*(uint16*)(g_ram+0x9E22)) +#define expand_sq_left_subpos (*(uint16*)(g_ram+0x9E30)) +#define expand_sq_left_pos (*(uint16*)(g_ram+0x9E32)) +#define expand_sq_right_subpos (*(uint16*)(g_ram+0x9E34)) +#define expand_sq_right_pos (*(uint16*)(g_ram+0x9E36)) +#define expand_sq_top_subpos (*(uint16*)(g_ram+0x9E38)) +#define expand_sq_top_pos (*(uint16*)(g_ram+0x9E3A)) +#define expand_sq_bottom_subpos (*(uint16*)(g_ram+0x9E3C)) +#define expand_sq_bottom_pos (*(uint16*)(g_ram+0x9E3E)) +#define expand_sq_left_subvel (*(uint16*)(g_ram+0x9E40)) +#define expand_sq_left_vel (*(uint16*)(g_ram+0x9E42)) +#define expand_sq_right_subvel (*(uint16*)(g_ram+0x9E44)) +#define expand_sq_right_vel (*(uint16*)(g_ram+0x9E46)) +#define expand_sq_top_subvel (*(uint16*)(g_ram+0x9E48)) +#define expand_sq_top_vel (*(uint16*)(g_ram+0x9E4A)) +#define expand_sq_bottom_subvel (*(uint16*)(g_ram+0x9E4C)) +#define expand_sq_bottom_vel (*(uint16*)(g_ram+0x9E4E)) +#define expand_sq_timer (*(uint16*)(g_ram+0x9E50)) #define g_word_7E9E80 ((uint16*)(g_ram+0x9E80)) #define scrolling_sky_bg2_indirect_hdma ((uint8*)(g_ram+0x9F00)) #define scrolling_sky_bg2_hdma_data ((uint16*)(g_ram+0x9F80))