Botwoon_Func_26 overwrote R18

This commit is contained in:
Snesrev
2023-04-04 20:19:39 +02:00
parent 6261da13e1
commit 30f4cfd958
3 changed files with 19 additions and 10 deletions

View File

@@ -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;

View File

@@ -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 <time.h>
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;

View File

@@ -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)