From 44ffd330047437d35520271be38d5030a1609758 Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Sun, 13 Sep 2020 19:03:22 -0400 Subject: [PATCH] PR suggestions, game status macro --- include/common_structs.h | 2 +- include/macros.h | 2 ++ include/variables.h | 2 +- src/code_42e0_len_1f60.c | 20 ++++++++++---------- src/code_6000.c | 8 ++++---- src/code_e940_len_290.c | 2 +- src/code_ebd0_len_6a0.c | 4 ++-- src/code_fe0b0_len_5a0.c | 16 ++++++++-------- undefined_syms.txt | 2 +- 9 files changed, 30 insertions(+), 28 deletions(-) diff --git a/include/common_structs.h b/include/common_structs.h index b6b8c03e1c..c2c055aac6 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -879,7 +879,7 @@ typedef struct GameStatus { /* 0x0BA */ s16 bootGreen; /* 0x0BC */ s16 bootRed; /* 0x0BE */ char unk_BE[106]; - /* 0x128 */ f32 playerTraceNormal[3]; + /* 0x128 */ Vec3f playerTraceNormal; /* 0x134 */ u16 frameCounter; /* 0x136 */ char unk_136[2]; /* 0x138 */ s32 nextRNG; diff --git a/include/macros.h b/include/macros.h index d19e7e82e1..83b804cfa2 100644 --- a/include/macros.h +++ b/include/macros.h @@ -9,6 +9,8 @@ #define ASSERT(condition) if (!(condition)) { while (1) {} } +#define GAME_STATUS (*gGameStatusPtr) + #define SQ(x) (x*x) #endif diff --git a/include/variables.h b/include/variables.h index 672821344a..f2078ce060 100644 --- a/include/variables.h +++ b/include/variables.h @@ -12,7 +12,7 @@ extern ActionState gPlayerActionState; extern PlayerAnim gPlayerAnimation; extern PlayerStatus gPlayerStatus; extern GameStatus* gGameStatusPtr[1]; -extern s32 D_80074410; +extern s32 gRandSeed; extern StaticItem gItemTable[364]; extern s16 gMainGameState; /* 0 = battle, 1 = pause, 2 = world */ extern UNK_FUN_PTR(gCurrentUpdateFunction); diff --git a/src/code_42e0_len_1f60.c b/src/code_42e0_len_1f60.c index 0fd4cf8401..748d4678af 100644 --- a/src/code_42e0_len_1f60.c +++ b/src/code_42e0_len_1f60.c @@ -29,12 +29,12 @@ INCLUDE_ASM("code_42e0_len_1f60", _heap_realloc); INCLUDE_API_ASM("code_42e0_len_1f60", cosine); s32 sign(s32 val) { - s32 ret = -1; + s32 sign = -1; if (val >= 0) { - ret = val > 0; + sign = val > 0; } - return ret; + return sign; } INCLUDE_ASM("code_42e0_len_1f60", int_to_string); @@ -58,7 +58,7 @@ INCLUDE_ASM("code_42e0_len_1f60", dma_copy); INCLUDE_ASM("code_42e0_len_1f60", func_80029860); s32 _advance_rng(void) { - s32* rngVal = &D_80074410; + s32* rngVal = &gRandSeed; (*gGameStatusPtr)->nextRNG = *rngVal = (*rngVal * 0x5D588B65) + 1; @@ -72,18 +72,18 @@ INCLUDE_ASM("code_42e0_len_1f60", func_80029994); s32 INCLUDE_ASM("code_42e0_len_1f60", rand_int, s32 arg0); f32 signF(f32 val) { - f32 ret; + f32 sign; if (!(val > 0.0f)) { - ret = -1.0f; + sign = -1.0f; if (!(val < 0.0f)) { - ret = 0.0f; + sign = 0.0f; } } else { - ret = 1.0f; + sign = 1.0f; } - return ret; + return sign; } INCLUDE_API_ASM("code_42e0_len_1f60", round); @@ -104,7 +104,7 @@ f32 get_clamped_angle_diff(f32 a, f32 b) { f32 INCLUDE_ASM("code_42e0_len_1f60", atan2, f32 startX, f32 startZ, f32 endX, f32 endZ); f32 get_player_normal_yaw(void) { - return atan2(0, 0, (*gGameStatusPtr)->playerTraceNormal[0], (*gGameStatusPtr)->playerTraceNormal[2]); + return atan2(0, 0, (*gGameStatusPtr)->playerTraceNormal.x, (*gGameStatusPtr)->playerTraceNormal.z); } INCLUDE_ASM("code_42e0_len_1f60", get_player_normal_pitch); diff --git a/src/code_6000.c b/src/code_6000.c index 9054344dd6..da74756fa0 100644 --- a/src/code_6000.c +++ b/src/code_6000.c @@ -33,7 +33,7 @@ s32 func_8002ACDC(void) { } s32 heap_malloc(s32 size) { - if ((*gGameStatusPtr)->isBattle == 0) { + if (GAME_STATUS->isBattle == 0) { return general_heap_malloc(size); } else { return _heap_malloc(&D_803DA800, size); @@ -41,7 +41,7 @@ s32 heap_malloc(s32 size) { } s32 heap_free(s32 size) { - if ((*gGameStatusPtr)->isBattle != 0) { + if (GAME_STATUS->isBattle != 0) { return _heap_free(&D_803DA800, size); } else { return general_heap_free(size); @@ -56,7 +56,7 @@ s32 collision_heap_create(void) { } s32 collision_heap_malloc(s32 size) { - if (!(*gGameStatusPtr)->isBattle) { + if (!GAME_STATUS->isBattle) { return _heap_malloc(&D_80268000, size); } else { return _heap_malloc(&D_803DA800, size); @@ -64,7 +64,7 @@ s32 collision_heap_malloc(s32 size) { } s32 collision_heap_free(void* data) { - if ((*gGameStatusPtr)->isBattle) { + if (GAME_STATUS->isBattle) { return _heap_free(&D_803DA800, data); } else { return _heap_free(&D_80268000, data); diff --git a/src/code_e940_len_290.c b/src/code_e940_len_290.c index 6d95ed8450..2c432c4569 100644 --- a/src/code_e940_len_290.c +++ b/src/code_e940_len_290.c @@ -2,7 +2,7 @@ void func_80033540(void) { D_8009A650[0] |= 8; - (*gGameStatusPtr)->loadMenuState = 3; + GAME_STATUS->loadMenuState = 3; } INCLUDE_ASM("code_e940_len_290", func_80033568); diff --git a/src/code_ebd0_len_6a0.c b/src/code_ebd0_len_6a0.c index f08eaf1781..3aed5ddd7f 100644 --- a/src/code_ebd0_len_6a0.c +++ b/src/code_ebd0_len_6a0.c @@ -43,8 +43,8 @@ s16 func_80033830(add_val) { } void func_80033874(void) { - func_80137D88(0, (*gGameStatusPtr)->bootAlpha); - func_80137E10(0, (*gGameStatusPtr)->bootBlue, (*gGameStatusPtr)->bootGreen, (*gGameStatusPtr)->bootRed); + func_80137D88(0, GAME_STATUS->bootAlpha); + func_80137E10(0, GAME_STATUS->bootBlue, GAME_STATUS->bootGreen, GAME_STATUS->bootRed); } void start_battle_countdown(void) { diff --git a/src/code_fe0b0_len_5a0.c b/src/code_fe0b0_len_5a0.c index 1927f02339..8e46ef71b6 100644 --- a/src/code_fe0b0_len_5a0.c +++ b/src/code_fe0b0_len_5a0.c @@ -12,22 +12,22 @@ ApiStatus EnableSpriteShading(ScriptInstance* script, s32 isInitialCall) { } s32 getDemoState(ScriptInstance* script) { - set_variable(script, *script->ptrReadPos, (*gGameStatusPtr)->demoState); + set_variable(script, *script->ptrReadPos, GAME_STATUS->demoState); return ApiStatus_DONE2; } ApiStatus DemoPressButton(ScriptInstance* script, s32 isInitialCall) { - (*gGameStatusPtr)->demoButtonInput |= get_variable(script, *script->ptrReadPos); + GAME_STATUS->demoButtonInput |= get_variable(script, *script->ptrReadPos); return ApiStatus_DONE2; } ApiStatus DemoReleaseButton(ScriptInstance* script, s32 isInitialCall) { - (*gGameStatusPtr)->demoButtonInput &= ~get_variable(script, *script->ptrReadPos); + GAME_STATUS->demoButtonInput &= ~get_variable(script, *script->ptrReadPos); return ApiStatus_DONE2; } ApiStatus DemoSetButtons(ScriptInstance* script, s32 isInitialCall) { - (*gGameStatusPtr)->demoButtonInput = get_variable(script, *script->ptrReadPos); + GAME_STATUS->demoButtonInput = get_variable(script, *script->ptrReadPos); return ApiStatus_DONE2; } @@ -39,8 +39,8 @@ ApiStatus DemoJoystickRadial(ScriptInstance* script, s32 isInitialCall) { a = get_float_variable(script, *thisPos++); b = get_float_variable(script, *thisPos++); - (*gGameStatusPtr)->demoStickX = a * sin_deg(b); - (*gGameStatusPtr)->demoStickY = a * cos_deg(b); + GAME_STATUS->demoStickX = a * sin_deg(b); + GAME_STATUS->demoStickY = a * cos_deg(b); return ApiStatus_DONE2; } @@ -53,8 +53,8 @@ ApiStatus DemoJoystickXY(ScriptInstance* script, s32 isInitialCall) { x = get_float_variable(script, *thisPos++); y = get_float_variable(script, *thisPos++); - (*gGameStatusPtr)->demoStickX = x; - (*gGameStatusPtr)->demoStickY = y; + GAME_STATUS->demoStickX = x; + GAME_STATUS->demoStickY = y; return ApiStatus_DONE2; } diff --git a/undefined_syms.txt b/undefined_syms.txt index a0610a18c9..c790b2a8a0 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -1,5 +1,5 @@ gGameStatusPtr = 0x8007419C; -D_80074410 = 0x80074410; +gRandSeed = 0x80074410; gUIStatus = 0x8010EF58; gPlayerData = 0x8010F290; gPlayerActionState = 0x8010F07C;