diff --git a/src/sm_b3.c b/src/sm_b3.c index ffc9c3f..74e0360 100644 --- a/src/sm_b3.c +++ b/src/sm_b3.c @@ -1127,21 +1127,24 @@ void Botwoon_Func_25(void) { // 0xB39D4D } void Botwoon_Func_26(uint16 k) { // 0xB39DC0 - printf("Botwoon_Func_26 possible bug - overwritten r18\n"); Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); uint16 x = E->base.x_pos - E->botwoon_var_56; uint16 y = E->base.y_pos - E->botwoon_var_57; + uint16 r22 = CalculateAngleFromXY(x, y); - if (x || y) { + if (x || y) { // bugfix: real game overwrote r18 + uint16 v1; if (E->botwoon_var_33) { E->base.layer = 7; E->base.properties |= kEnemyProps_Tangible; - r22 += 256; + v1 = addr_kBotwoon_Ilist_9389; } else { E->base.layer = 2; E->base.properties &= ~kEnemyProps_Tangible; + // Added hysteresis: Compute a weighted average + E->botwoon_var_45 = (uint8)(E->botwoon_var_45 + (int8)(r22 - E->botwoon_var_45) * 3 / 4); + v1 = g_off_B3946B[E->botwoon_var_45 >> 5]; } - uint16 v1 = g_off_B3946B[r22 >> 5]; if (v1 != E->botwoon_var_3B) { E->base.current_instruction = v1; E->botwoon_var_3B = v1; diff --git a/src/sm_cpu_infra.c b/src/sm_cpu_infra.c index 66e279b..876cf36 100644 --- a/src/sm_cpu_infra.c +++ b/src/sm_cpu_infra.c @@ -3,17 +3,12 @@ #include "snes/cpu.h" #include "snes/snes.h" #include "tracing.h" - - - - - #include "ida_types.h" #include "variables.h" #include "funcs.h" #include "sm_rtl.h" #include "util.h" - +#include "enemy_types.h" #include void RtlRunFrameCompare(uint16 input, int run_what); @@ -418,6 +413,16 @@ uint32 PatchBugs(uint32 mode, uint32 addr) { } else if (FixBugHook(0xa5a018)) { // Draygon_Func_42 uses undefined varE24 value REMOVED_varE24 = 0; + } else if (FixBugHook(0xb39ddb)) { + // Botwoon_Func_26 uses regs that are overwritten + // This made the flicker slightly worse, so added hysteresis + Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); + REMOVED_R18 = E->base.x_pos - E->botwoon_var_56; + REMOVED_R20 = E->base.y_pos - E->botwoon_var_57; + } else if (FixBugHook(0xB39E13)) { + // add botwoon hysteresis + Enemy_Botwoon *E = Get_Botwoon(cur_enemy_index); + REMOVED_R22 = E->botwoon_var_45 = (uint8)(E->botwoon_var_45 + (int8)(REMOVED_R22 - E->botwoon_var_45) * 3 / 4); } return 0; diff --git a/src/variables.h b/src/variables.h index 813b15b..3143859 100644 --- a/src/variables.h +++ b/src/variables.h @@ -20,6 +20,7 @@ extern int32 *cur_coll_amt32; // Not used anymore #define REMOVED_R18 *(uint16*)(g_ram + 18) #define REMOVED_R20 *(uint16*)(g_ram + 20) +#define REMOVED_R22 *(uint16*)(g_ram + 22) #define INT16_SHL8(x) ((int16)(x) << 8) #define INT16_SHL16(x) ((int16)(x) << 16)