diff --git a/src/racing/actors.c b/src/racing/actors.c index 341ea8cfd8..ee13940fe1 100644 --- a/src/racing/actors.c +++ b/src/racing/actors.c @@ -1157,7 +1157,7 @@ void spawn_course_actors(void) { /** * @brief Loads actor textures, course specific actor textures. * Calls to init_course_vehicles and place_course_actors - * + * */ void init_actors_and_load_textures(void) { set_segment_base_addr(3, (void *) gNextFreeMemoryAddress); @@ -1818,18 +1818,18 @@ void destroy_destructable_actor(struct Actor *actor) { Player *player; switch (actor->type) { - case ACTOR_BANANA: - banana = (struct BananaActor *)actor; - switch (banana->state) { - case FIRST_BANANA_BUNCH_BANANA: - case BANANA_BUNCH_BANANA: - destroy_banana_in_banana_bunch(banana); - break; - case HELD_BANANA: - player = &gPlayers[banana->playerId]; - player->soundEffects &= ~0x00040000; - /* fallthrough */ - case BANANA_ON_GROUND: + case ACTOR_BANANA: + banana = (struct BananaActor *)actor; + switch (banana->state) { + case FIRST_BANANA_BUNCH_BANANA: + case BANANA_BUNCH_BANANA: + destroy_banana_in_banana_bunch(banana); + break; + case HELD_BANANA: + player = &gPlayers[banana->playerId]; + player->soundEffects &= ~0x00040000; + /* fallthrough */ + case BANANA_ON_GROUND: banana->flags = -0x8000; banana->unk_04 = 0x003C; banana->state = DESTROYED_BANANA; diff --git a/src/racing/actors.h b/src/racing/actors.h index 8c0b2e2b2a..a9cb138301 100644 --- a/src/racing/actors.h +++ b/src/racing/actors.h @@ -83,13 +83,13 @@ void destroy_actor(struct Actor*); s16 try_remove_destructable_item(Vec3f, Vec3s, Vec3f, s16); s16 add_actor_to_empty_slot(Vec3f, Vec3s, Vec3f, s16); s16 spawn_actor_at_pos(Vec3f, s16); -s32 query_and_resolve_collision_player_actor(Player*, Vec3f, f32, f32, f32); -s32 collision_mario_sign(Player*, struct Actor*); -s32 collision_piranha_plant(Player*, struct PiranhaPlant*); -s32 collision_yoshi_egg(Player*, struct YoshiValleyEgg*); -s32 collision_tree(Player*, struct Actor*); -s32 query_collision_player_vs_actor_item(Player*, struct Actor*); -s32 query_collision_actor_vs_actor(struct Actor*, struct Actor*); +bool query_and_resolve_collision_player_actor(Player*, Vec3f, f32, f32, f32); +bool collision_mario_sign(Player*, struct Actor*); +bool collision_piranha_plant(Player*, struct PiranhaPlant*); +bool collision_yoshi_egg(Player*, struct YoshiValleyEgg*); +bool collision_tree(Player*, struct Actor*); +bool query_collision_player_vs_actor_item(Player*, struct Actor*); +bool query_collision_actor_vs_actor(struct Actor*, struct Actor*); void destroy_destructable_actor(struct Actor*); void play_sound_on_destructible_actor_collision(struct Actor*, struct Actor*); void evaluate_actor_collision_between_two_destructible_actors(struct Actor*, struct Actor*); diff --git a/src/racing/actors_extended.c b/src/racing/actors_extended.c index 73a3d10736..8e8efefd5f 100644 --- a/src/racing/actors_extended.c +++ b/src/racing/actors_extended.c @@ -606,12 +606,12 @@ s32 use_green_shell_item(Player *player) { // rotate to match player orientation mtxf_translate_vec3f_mat3(startingPos, player->orientationMatrix); - + // move to player position startingPos[0] += player->pos[0]; startingPos[1] += player->pos[1]; startingPos[2] += player->pos[2]; - + // spawn the shell actorIndex = add_actor_to_empty_slot(startingPos, startingRot, startingVelocity, ACTOR_GREEN_SHELL); if (actorIndex < 0) { @@ -848,8 +848,8 @@ s32 use_banana_item(Player *player) { /** * Strikes players with thunder - * - * @param Activating player (not to be struck) + * + * @param Activating player (not to be struck) */ void use_thunder_item(Player *player) { s32 index; diff --git a/src/racing/actors_extended.h b/src/racing/actors_extended.h index 89aa28e5a9..cb8f0c6cab 100644 --- a/src/racing/actors_extended.h +++ b/src/racing/actors_extended.h @@ -1,7 +1,7 @@ #ifndef ACTORS_EXTENDED_H #define ACTORS_EXTENDED_H -#include "common_structs.h" +#include #include "actor_types.h" /** @cond */ @@ -16,7 +16,7 @@ void func_802B0648(struct BananaBunchParent*); void func_802B0788(s16, struct BananaBunchParent*, Player*); s32 func_802B09C0(s16); void update_actor_banana_bunch(struct BananaBunchParent*); -s32 is_shell_exist(s16); +bool is_shell_exist(s16); void update_actor_triple_shell(TripleShellParent*, s16); s32 use_banana_bunch_item(Player*); s32 use_triple_shell_item(Player*, s16); diff --git a/src/racing/collision.c b/src/racing/collision.c index 1986721fcf..4676e84d10 100644 --- a/src/racing/collision.c +++ b/src/racing/collision.c @@ -1327,7 +1327,6 @@ u16 actor_terrain_collision(Collision *collision, f32 boundingBoxSize, f32 x1, f } } sectionIndex++; - } return flags; } @@ -1570,7 +1569,7 @@ void add_collision_triangle(Vtx *vtx1, Vtx *vtx2, Vtx *vtx3, s8 surfaceType, u16 if ((triangle->vtx1->v.flag == 4) && (triangle->vtx2->v.flag == 4) && (triangle->vtx3->v.flag == 4)) { - + return; } @@ -1776,7 +1775,7 @@ void set_vtx_from_quadrangle(u32 line, s8 surfaceType, u16 sectionId) { vtx2 = vtxBuffer[vert2]; vtx3 = vtxBuffer[vert3]; vtx4 = vtxBuffer[vert4]; - + // Triangle 1 add_collision_triangle(vtx1, vtx2, vtx3, surfaceType, sectionId); // Triangle 2 @@ -1914,6 +1913,7 @@ void generate_collision_grid(void) { s32 courseLengthX; s32 courseLengthZ; s32 index; + courseLengthX = (s32) gCourseMaxX - gCourseMinX; courseLengthZ = (s32) gCourseMaxZ - gCourseMinZ; @@ -1958,7 +1958,7 @@ void generate_collision_grid(void) { gCollisionGrid[index].triangle = gNumCollisionTriangles; } gCollisionGrid[index].numTriangles++; - gCollisionIndices[gNumCollisionTriangles] = (s16) i; + gCollisionIndices[gNumCollisionTriangles] = (u16) i; gNumCollisionTriangles++; } } @@ -2181,7 +2181,7 @@ u16 process_collision(Player *player, KartTyre *tyre, f32 tyre2X, f32 tyre2Y, f3 } // If the surface flags are not set then try setting them. - + courseLengthX = (s32) gCourseMaxX - gCourseMinX; courseLengthZ = (s32) gCourseMaxZ - gCourseMinZ; diff --git a/src/racing/collision.h b/src/racing/collision.h index 975ebfe893..b93e4b4d41 100644 --- a/src/racing/collision.h +++ b/src/racing/collision.h @@ -1,7 +1,7 @@ #ifndef collision_H #define collision_H -#include "common_structs.h" +#include #define COLLISION 0x1 #define NO_COLLISION 0x0 @@ -35,7 +35,7 @@ void generate_collision_mesh_with_defaults(Gfx*); void generate_collision_mesh_with_default_section_id(Gfx*, s8); void generate_collision_mesh(Gfx*, s8, u16); void find_and_set_tile_size(uintptr_t, s32, s32); -void set_vertex_colours(u32, u32, s32, s8, u8, u8, u8); +void set_vertex_colours(uintptr_t, u32, s32, s8, u8, u8, u8); void find_vtx_and_set_colours(uintptr_t, s8, u8, u8, u8); void subtract_scaled_vector(Vec3f, f32, Vec3f); diff --git a/src/racing/math_util.c b/src/racing/math_util.c index 5d74ab6306..84f92e9358 100644 --- a/src/racing/math_util.c +++ b/src/racing/math_util.c @@ -127,7 +127,7 @@ void *vec3f_copy_return(Vec3f dest, Vec3f src) { dest[1] = src[1]; dest[2] = src[2]; //! @warning function returns address of local variable - return &dest; + return &dest; } void vec3s_copy(Vec3s dest, Vec3s src) { diff --git a/src/racing/memory.c b/src/racing/memory.c index bbd5568b6c..2a300d63e7 100644 --- a/src/racing/memory.c +++ b/src/racing/memory.c @@ -15,7 +15,7 @@ s32 sGfxSeekPosition; s32 sPackedSeekPosition; -u32 sPoolFreeSpace; +uintptr_t sPoolFreeSpace; struct MainPoolBlock *sPoolListHeadL; struct MainPoolBlock *sPoolListHeadR; @@ -31,10 +31,10 @@ s32 memoryPadding[2]; * @brief Returns the address of the next available memory location and updates the memory pointer * to reference the next location of available memory based provided size to allocate. * @param size of memory to allocate. - * @return Address of free memory + * @return Address of free memory */ -void *get_next_available_memory_addr(u32 size) { - u32 *freeSpace = (u32 *)gNextFreeMemoryAddress; +void *get_next_available_memory_addr(uintptr_t size) { + uintptr_t freeSpace = (uintptr_t) gNextFreeMemoryAddress; size = ALIGN16(size); gNextFreeMemoryAddress += size; return freeSpace; @@ -84,7 +84,7 @@ void move_segment_table_to_dmem(void) { /** * @brief Sets the starting location for allocating memory and calculates pool size. - * + * * Default memory size, 701.984 Kilobytes. */ void initialize_memory_pool(uintptr_t poolStart, uintptr_t poolEnd) { @@ -100,8 +100,8 @@ void initialize_memory_pool(uintptr_t poolStart, uintptr_t poolEnd) { /** * @brief Allocates memory and adjusts gFreeMemorySize. */ -void *allocate_memory(u32 size) { - u32 *freeSpace; +void *allocate_memory(size_t size) { + uintptr_t freeSpace; size = ALIGN16(size); gFreeMemorySize -= size; @@ -121,7 +121,7 @@ UNUSED void func_802A7D54(s32 arg0, s32 arg1) { */ void *load_data(uintptr_t startAddr, uintptr_t endAddr) { void *allocated; - u32 size = endAddr - startAddr; + uintptr_t size = endAddr - startAddr; allocated = allocate_memory(size); if (allocated != 0) { @@ -130,7 +130,7 @@ void *load_data(uintptr_t startAddr, uintptr_t endAddr) { return (void *) allocated; } -UNUSED void main_pool_init(u32 start, u32 end) { +UNUSED void main_pool_init(uintptr_t start, uintptr_t end) { start = ALIGN16(start); end = ALIGN16(end - 15); @@ -149,7 +149,7 @@ UNUSED void main_pool_init(u32 start, u32 end) { * specified side of the pool (MEMORY_POOL_LEFT or MEMORY_POOL_RIGHT). * If there is not enough space, return NULL. */ -UNUSED void *main_pool_alloc(u32 size, u32 side) { +UNUSED void *main_pool_alloc(uintptr_t size, uintptr_t side) { struct MainPoolBlock *newListHead; void *addr = NULL; @@ -178,7 +178,7 @@ UNUSED void *main_pool_alloc(u32 size, u32 side) { * newer blocks are freed as well. * Return the amount of free space left in the pool. */ -UNUSED u32 main_pool_free(void *addr) { +UNUSED uintptr_t main_pool_free(void *addr) { struct MainPoolBlock *block = (struct MainPoolBlock *) ((u8 *) addr - 8); struct MainPoolBlock *oldListHead = (struct MainPoolBlock *) ((u8 *) addr - 8); @@ -200,7 +200,7 @@ UNUSED u32 main_pool_free(void *addr) { return sPoolFreeSpace; } // main_pool_realloc -UNUSED void *main_pool_realloc(void *addr, u32 size) { +UNUSED void *main_pool_realloc(void *addr, uintptr_t size) { void *newAddr = NULL; struct MainPoolBlock *block = (struct MainPoolBlock *) ((u8 *) addr - 8); @@ -211,13 +211,13 @@ UNUSED void *main_pool_realloc(void *addr, u32 size) { return newAddr; } -UNUSED s32 main_pool_available(void) { +UNUSED uintptr_t main_pool_available(void) { return sPoolFreeSpace - 8; } -UNUSED u32 main_pool_push_state(void) { +UNUSED uintptr_t main_pool_push_state(void) { struct MainPoolState *prevState = gMainPoolState; - u32 freeSpace = sPoolFreeSpace; + uintptr_t freeSpace = sPoolFreeSpace; struct MainPoolBlock *lhead = sPoolListHeadL; struct MainPoolBlock *rhead = sPoolListHeadR; @@ -233,7 +233,7 @@ UNUSED u32 main_pool_push_state(void) { * Restore pool state from a previous call to main_pool_push_state. Return the * amount of free space left in the pool. */ -UNUSED u32 main_pool_pop_state(void) { +UNUSED uintptr_t main_pool_pop_state(void) { sPoolFreeSpace = gMainPoolState->freeSpace; sPoolListHeadL = gMainPoolState->listHeadL; sPoolListHeadR = gMainPoolState->listHeadR; @@ -243,9 +243,9 @@ UNUSED u32 main_pool_pop_state(void) { // similar to sm64 dma_read UNUSED void *func_802A80B0(u8 *dest, u8 *srcStart, u8 *srcEnd) { void *addr; - u32 size = srcStart - dest; - addr = main_pool_alloc(size, (u32) srcEnd); - + uintptr_t size = srcStart - dest; + addr = main_pool_alloc(size, (uintptr_t) srcEnd); + if (addr != 0) { osInvalDCache(addr, size); @@ -268,12 +268,12 @@ UNUSED void *load_segment(s32 segment, u8 *srcStart, u8 *srcEnd, u8 *side) { // Similar to sm64 load_to_fixed_pool_addr? UNUSED void *func_802A8190(s32 arg0, u8 *arg1) { - //u32 srcSize = ALIGN16(srcEnd - srcStart); - //u32 destSize = ALIGN16((u8 *) sPoolListHeadR - destAddr); + //uintptr_t srcSize = ALIGN16(srcEnd - srcStart); + //uintptr_t destSize = ALIGN16((u8 *) sPoolListHeadR - destAddr); void *addr; - u32 temp_v0 = D_802B8CD4[arg0].unk4; - u32 temp_v1 = D_802B8CD4[arg0].unk8; - u32 temp_v2 = D_802B8CD4[arg0].unk2; + uintptr_t temp_v0 = D_802B8CD4[arg0].unk4; + uintptr_t temp_v1 = D_802B8CD4[arg0].unk8; + uintptr_t temp_v2 = D_802B8CD4[arg0].unk2; addr = func_802A80B0((u8 *) temp_v0, (u8 *) temp_v1, arg1); //dest = main_pool_alloc(destSize, MEMORY_POOL_RIGHT); @@ -300,7 +300,7 @@ UNUSED void func_802A81EC(void) { } while (phi_s0 != 3); } -UNUSED struct AllocOnlyPool *alloc_only_pool_init(u32 size, u32 side) { +UNUSED struct AllocOnlyPool *alloc_only_pool_init(uintptr_t size, uintptr_t side) { void *addr; struct AllocOnlyPool *subPool = NULL; @@ -316,13 +316,13 @@ UNUSED struct AllocOnlyPool *alloc_only_pool_init(u32 size, u32 side) { return subPool; } -UNUSED u32 func_802A82AC(s32 arg0) { - u32 temp_v0; - u32 phi_v1; +UNUSED uintptr_t func_802A82AC(s32 arg0) { + uintptr_t temp_v0; + uintptr_t phi_v1; temp_v0 = D_801502A0 - arg0; phi_v1 = 0; - if (temp_v0 >= (u32) gDisplayListHead) { + if (temp_v0 >= (uintptr_t) gDisplayListHead) { D_801502A0 = temp_v0; phi_v1 = temp_v0; } @@ -334,7 +334,7 @@ UNUSED u32 func_802A82AC(s32 arg0) { */ u8 *dma_compressed_vtx(u8 *start, u8 *end) { u8 *freeSpace; - u32 size; + uintptr_t size; size = ALIGN16(end - start); freeSpace = (u8 *) gNextFreeMemoryAddress; @@ -344,12 +344,12 @@ u8 *dma_compressed_vtx(u8 *start, u8 *end) { } // unused mio0 decode func. -UNUSED s32 func_802A8348(s32 arg0, s32 arg1, s32 arg2) { - u32 offset; +UNUSED uintptr_t func_802A8348(s32 arg0, s32 arg1, s32 arg2) { + uintptr_t offset; UNUSED void *pad; uintptr_t oldAddr; void *newAddr; - + offset = ALIGN16(arg1 * arg2); oldAddr = gNextFreeMemoryAddress; newAddr = (void *) (oldAddr + offset); @@ -357,7 +357,7 @@ UNUSED s32 func_802A8348(s32 arg0, s32 arg1, s32 arg2) { osInvalDCache(newAddr, offset); osPiStartDma(&gDmaIoMesg, 0, 0, (uintptr_t) &_other_texturesSegmentRomStart[SEGMENT_OFFSET(arg0)], newAddr, offset, &gDmaMesgQueue); osRecvMesg(&gDmaMesgQueue, &gMainReceivedMesg, 1); - + func_80040030((u8 *) newAddr, (u8 *) oldAddr); gNextFreeMemoryAddress += offset; return oldAddr; @@ -370,7 +370,7 @@ UNUSED u8 *func_802A841C(u8* arg0, s32 arg1, s32 arg2) { temp_a0 = temp_v0 + arg2; arg1 = ALIGN16(arg1); arg2 = ALIGN16(arg2); - + osInvalDCache(temp_a0, arg1); osPiStartDma(&gDmaIoMesg, 0, 0, (uintptr_t) &_other_texturesSegmentRomStart[SEGMENT_OFFSET(arg0)],temp_a0, arg1, &gDmaMesgQueue); osRecvMesg(&gDmaMesgQueue, &gMainReceivedMesg, 1); @@ -395,8 +395,8 @@ u8 *dma_textures(u8 texture[], size_t arg1, size_t arg2) { return temp_v0; } -u32 MIO0_0F(u8 *arg0, u32 arg1, u32 arg2) { - u32 oldHeapEndPtr; +uintptr_t MIO0_0F(u8 *arg0, uintptr_t arg1, uintptr_t arg2) { + uintptr_t oldHeapEndPtr; void *temp_v0; arg1 = ALIGN16(arg1); @@ -497,7 +497,7 @@ void unpack_lights(Gfx *arg0, UNUSED u8 *arg1, s8 arg2) { } void unpack_displaylist(Gfx *arg0, u8 *args, UNUSED s8 opcode) { - u32 temp_v0 = args[sPackedSeekPosition++]; + uintptr_t temp_v0 = args[sPackedSeekPosition++]; uintptr_t temp_t7 = ((args[sPackedSeekPosition++]) << 8 | temp_v0) * 8; arg0[sGfxSeekPosition].words.w0 = 0x06000000; // Segment seven addr @@ -507,7 +507,7 @@ void unpack_displaylist(Gfx *arg0, u8 *args, UNUSED s8 opcode) { // end displaylist void unpack_end_displaylist(Gfx *arg0, UNUSED u8 *arg1, UNUSED s8 arg2) { - arg0[sGfxSeekPosition].words.w0 = G_ENDDL << 24; + arg0[sGfxSeekPosition].words.w0 = (uintptr_t)(uint8_t)G_ENDDL << 24; arg0[sGfxSeekPosition].words.w1 = 0; sGfxSeekPosition++; } @@ -533,70 +533,70 @@ void unpack_cull_displaylist(Gfx *arg0, UNUSED u8 *arg1, UNUSED s8 arg2) { sGfxSeekPosition++; } -void unpack_combine_mode1(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_combine_mode1(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetCombineMode(G_CC_MODULATERGBA, G_CC_MODULATERGBA)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; } -void unpack_combine_mode2(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_combine_mode2(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetCombineMode(G_CC_MODULATERGBDECALA, G_CC_MODULATERGBDECALA)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; } -void unpack_combine_mode_shade(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_combine_mode_shade(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; } -void unpack_combine_mode4(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_combine_mode4(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetCombineMode(G_CC_MODULATERGBDECALA, G_CC_MODULATERGBDECALA)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; } -void unpack_combine_mode5(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_combine_mode5(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; } -void unpack_render_mode_opaque(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_render_mode_opaque(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; } -void unpack_render_mode_tex_edge(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_render_mode_tex_edge(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetRenderMode(G_RM_AA_ZB_TEX_EDGE, G_RM_AA_ZB_TEX_EDGE2)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; } -void unpack_render_mode_translucent(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_render_mode_translucent(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetRenderMode(G_RM_AA_ZB_XLU_SURF, G_RM_AA_ZB_XLU_SURF2)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; } -void unpack_render_mode_opaque_decal(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_render_mode_opaque_decal(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetRenderMode(G_RM_AA_ZB_OPA_DECAL, G_RM_AA_ZB_OPA_DECAL)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; } -void unpack_render_mode_translucent_decal(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 arg2) { +void unpack_render_mode_translucent_decal(Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2) { Gfx macro[] = {gsDPSetRenderMode(G_RM_AA_ZB_XLU_DECAL, G_RM_AA_ZB_XLU_DECAL)}; arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; @@ -605,9 +605,9 @@ void unpack_render_mode_translucent_decal(Gfx *arg0, UNUSED u8 *arg1, UNUSED u32 void unpack_tile_sync(Gfx *gfx, u8 *args, s8 opcode) { Gfx tileSync[] = { gsDPTileSync() }; - u32 temp_a0; - u32 lo; - u32 hi; + uintptr_t temp_a0; + uintptr_t lo; + uintptr_t hi; s32 width; s32 height; @@ -682,9 +682,9 @@ void unpack_tile_sync(Gfx *gfx, u8 *args, s8 opcode) { gfx[sGfxSeekPosition].words.w1 = tileSync->words.w1; sGfxSeekPosition++; - lo = (G_SETTILE << 24) | (fmt << 21) | (siz << 19) | (line << 9) | tmem; + lo = ((uintptr_t)(uint8_t)G_SETTILE << 24) | (fmt << 21) | (siz << 19) | (line << 9) | tmem; hi = ((cmt) << 18) | ((maskt) << 14) | ((cms) << 8) | ((masks) << 4); - + gfx[sGfxSeekPosition].words.w0 = lo; gfx[sGfxSeekPosition].words.w1 = hi; sGfxSeekPosition++; @@ -692,7 +692,7 @@ void unpack_tile_sync(Gfx *gfx, u8 *args, s8 opcode) { lrs = (width - 1) << 2; lrt = (height - 1) << 2; - lo = (G_SETTILESIZE << 24); + lo = ((uintptr_t)(uint8_t)G_SETTILESIZE << 24); hi = (lrs << 12) | lrt; gfx[sGfxSeekPosition].words.w0 = lo; @@ -701,20 +701,20 @@ void unpack_tile_sync(Gfx *gfx, u8 *args, s8 opcode) { } void unpack_tile_load_sync(Gfx *gfx, u8 *args, s8 opcode) { - UNUSED u32 var; + UNUSED uintptr_t var; Gfx tileSync[] = { gsDPTileSync() }; Gfx loadSync[] = { gsDPLoadSync() }; - u32 arg; - u32 lo; - u32 hi; - u32 addr; - u32 width; - u32 height; - u32 fmt; - u32 siz; - u32 tmem; - u32 tile; + uintptr_t arg; + uintptr_t lo; + uintptr_t hi; + uintptr_t addr; + uintptr_t width; + uintptr_t height; + uintptr_t fmt; + uintptr_t siz; + uintptr_t tmem; + uintptr_t tile; switch (opcode) { case 32: @@ -763,7 +763,7 @@ void unpack_tile_load_sync(Gfx *gfx, u8 *args, s8 opcode) { // Generate gfx - lo = (G_SETTIMG << 24) | (fmt << 21) | (siz << 19); + lo = ((uintptr_t)(uint8_t)G_SETTIMG << 24) | (fmt << 21) | (siz << 19); gfx[sGfxSeekPosition].words.w0 = lo; gfx[sGfxSeekPosition].words.w1 = addr; sGfxSeekPosition++; @@ -772,7 +772,7 @@ void unpack_tile_load_sync(Gfx *gfx, u8 *args, s8 opcode) { gfx[sGfxSeekPosition].words.w1 = tileSync->words.w1; sGfxSeekPosition++; - lo = (G_SETTILE << 24) | (fmt << 21) | (siz << 19) | tmem; + lo = ((uintptr_t)(uint8_t)G_SETTILE << 24) | (fmt << 21) | (siz << 19) | tmem; hi = tile << 24; gfx[sGfxSeekPosition].words.w0 = lo; @@ -783,7 +783,7 @@ void unpack_tile_load_sync(Gfx *gfx, u8 *args, s8 opcode) { gfx[sGfxSeekPosition].words.w1 = loadSync->words.w1; sGfxSeekPosition++; - lo = G_LOADBLOCK << 24; + lo = (uintptr_t)(uint8_t)G_LOADBLOCK << 24; hi = (tile << 24) | (MIN((width * height) - 1, 0x7FF) << 12) | CALC_DXT(width, G_IM_SIZ_16b_BYTES); gfx[sGfxSeekPosition].words.w0 = lo; @@ -793,6 +793,7 @@ void unpack_tile_load_sync(Gfx *gfx, u8 *args, s8 opcode) { void unpack_texture_on(Gfx *arg0, UNUSED u8 *args, UNUSED s8 arg2) { Gfx macro[] = { gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON) }; + arg0[sGfxSeekPosition].words.w0 = macro->words.w0; arg0[sGfxSeekPosition].words.w1 = macro->words.w1; sGfxSeekPosition++; @@ -807,42 +808,42 @@ void unpack_texture_off(Gfx *arg0, UNUSED u8 *args, UNUSED s8 arg2) { } void unpack_vtx1(Gfx *gfx, u8 *args, UNUSED s8 arg2) { - u32 temp_t7; - u32 temp_t7_2; + uintptr_t temp_t7; + uintptr_t temp_t7_2; - u32 temp = args[sPackedSeekPosition++]; - u32 temp2 = ((args[sPackedSeekPosition++] << 8) | temp) * 0x10; + uintptr_t temp = args[sPackedSeekPosition++]; + uintptr_t temp2 = ((args[sPackedSeekPosition++] << 8) | temp) * 0x10; temp = args[sPackedSeekPosition++]; temp_t7 = temp & 0x3F; temp = args[sPackedSeekPosition++]; temp_t7_2 = temp & 0x3F; - gfx[sGfxSeekPosition].words.w0 = (G_VTX << 24) | (temp_t7_2 * 2 << 16) | (((temp_t7 << 10) + ((0x10 * temp_t7) - 1))); + gfx[sGfxSeekPosition].words.w0 = ((uintptr_t)(uint8_t)G_VTX << 24) | (temp_t7_2 * 2 << 16) | (((temp_t7 << 10) + ((0x10 * temp_t7) - 1))); gfx[sGfxSeekPosition].words.w1 = 0x04000000 + temp2; sGfxSeekPosition++; } void unpack_vtx2(Gfx *gfx, u8 *args, s8 arg2) { - u32 temp_t9; - u32 temp_v1; - u32 temp_v2; + uintptr_t temp_t9; + uintptr_t temp_v1; + uintptr_t temp_v2; temp_v1 = args[sPackedSeekPosition++]; temp_v2 = ((args[sPackedSeekPosition++] << 8) | temp_v1) * 0x10; temp_t9 = arg2 - 50; - gfx[sGfxSeekPosition].words.w0 = (G_VTX << 24) | ((temp_t9 << 10) + (((temp_t9) * 0x10) - 1)); + gfx[sGfxSeekPosition].words.w0 = ((uintptr_t)(uint8_t)G_VTX << 24) | ((temp_t9 << 10) + (((temp_t9) * 0x10) - 1)); gfx[sGfxSeekPosition].words.w1 = 0x4000000 + temp_v2; sGfxSeekPosition++; } void unpack_triangle(Gfx *gfx, u8 *args, UNUSED s8 arg2) { - u32 temp_v0; - u32 phi_a0; - u32 phi_a2; - u32 phi_a3; + uintptr_t temp_v0; + uintptr_t phi_a0; + uintptr_t phi_a2; + uintptr_t phi_a3; temp_v0 = args[sPackedSeekPosition++]; @@ -859,19 +860,19 @@ void unpack_triangle(Gfx *gfx, u8 *args, UNUSED s8 arg2) { phi_a2 |= (temp_v0 & 3) * 8; phi_a3 = (temp_v0 >> 2) & 0x1F; } - gfx[sGfxSeekPosition].words.w0 = (G_TRI1 << 24); + gfx[sGfxSeekPosition].words.w0 = ((uintptr_t)(uint8_t)G_TRI1 << 24); gfx[sGfxSeekPosition].words.w1 = ((phi_a0 * 2) << 16) | ((phi_a2 * 2) << 8) | (phi_a3 * 2); sGfxSeekPosition++; } void unpack_quadrangle(Gfx *gfx, u8 *args, UNUSED s8 arg2) { - u32 temp_v0; - u32 phi_t0; - u32 phi_a3; - u32 phi_a0; - u32 phi_t2; - u32 phi_t1; - u32 phi_a2; + uintptr_t temp_v0; + uintptr_t phi_t0; + uintptr_t phi_a3; + uintptr_t phi_a0; + uintptr_t phi_t2; + uintptr_t phi_t1; + uintptr_t phi_a2; temp_v0 = args[sPackedSeekPosition++]; @@ -905,17 +906,17 @@ void unpack_quadrangle(Gfx *gfx, u8 *args, UNUSED s8 arg2) { phi_a2 = (temp_v0 >> 2) & 0x1F; } gfx[sGfxSeekPosition].words.w0 = - (G_TRI2 << 24) | ((phi_a0 * 2) << 16) | ((phi_a3 * 2) << 8) | (phi_t0 * 2); + ((uintptr_t)(uint8_t)G_TRI2 << 24) | ((phi_a0 * 2) << 16) | ((phi_a3 * 2) << 8) | (phi_t0 * 2); gfx[sGfxSeekPosition].words.w1 = ((phi_t2 * 2) << 16) | ((phi_t1 * 2) << 8) | (phi_a2 * 2); sGfxSeekPosition++; } void unpack_spline_3D(Gfx *gfx, u8 *arg1, UNUSED s8 arg2) { - u32 temp_v0; - u32 phi_a0; - u32 phi_t0; - u32 phi_a3; - u32 phi_a2; + uintptr_t temp_v0; + uintptr_t phi_a0; + uintptr_t phi_t0; + uintptr_t phi_a3; + uintptr_t phi_a2; temp_v0 = arg1[sPackedSeekPosition++]; @@ -938,7 +939,7 @@ void unpack_spline_3D(Gfx *gfx, u8 *arg1, UNUSED s8 arg2) { temp_v0 = arg1[sPackedSeekPosition++]; phi_a0 |= (temp_v0 & 0xF) * 2; } - gfx[sGfxSeekPosition].words.w0 = (G_LINE3D << 24); + gfx[sGfxSeekPosition].words.w0 = ((uintptr_t)(uint8_t)G_QUAD << 24); gfx[sGfxSeekPosition].words.w1 = ((phi_a0 * 2) << 24) | ((phi_t0 * 2) << 16) | ((phi_a3 * 2) << 8) | (phi_a2 * 2); sGfxSeekPosition++; @@ -954,7 +955,7 @@ UNUSED void func_802A9AEC(void) { * The opcodes range from 0 to 87 which are used to run the relevant unpack function. * The file pointer increments when arguments are used. This way, * displaylist_unpack will always read an opcode and not an argument by accident. - * + * * @warning opcodes that do not contain a definition in the switch are ignored. If an undefined opcode * contained arguments the unpacker might try to unpack those arguments. * This issue is prevented so long as the packed file adheres to correct opcodes and unpack code @@ -984,7 +985,7 @@ void displaylist_unpack(uintptr_t *data, uintptr_t finalDisplaylistOffset, u32 a // Break when the eof has been reached denoted by opcode 0xFF if (opcode == 0xFF) break; - + switch (opcode) { case 0x0: unpack_lights(gfx, packed_dl, opcode); @@ -1257,9 +1258,9 @@ void displaylist_unpack(uintptr_t *data, uintptr_t finalDisplaylistOffset, u32 a struct UnkStr_802AA7C8 { u8 *unk0; - u32 unk4; - u32 unk8; - u32 unkC; + uintptr_t unk4; + uintptr_t unk8; + uintptr_t unkC; }; void decompress_textures(u32 *arg0) { @@ -1268,10 +1269,10 @@ void decompress_textures(u32 *arg0) { struct UnkStr_802AA7C8 *phi_s0 = (struct UnkStr_802AA7C8 *) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); struct UnkStr_802AA7C8 *temp_s0; - u32 temp_t2; + uintptr_t temp_t2; u8 *temp_a0; - u32 phi_v0; - u32 sp20; + uintptr_t phi_v0; + uintptr_t sp20; phi_v0 = 0; temp_s0 = phi_s0; diff --git a/src/racing/memory.h b/src/racing/memory.h index a1bde7e912..6fbdc0c05c 100644 --- a/src/racing/memory.h +++ b/src/racing/memory.h @@ -8,7 +8,7 @@ struct MainPoolBlock { }; struct MainPoolState { - u32 freeSpace; + uintptr_t freeSpace; struct MainPoolBlock *listHeadL; struct MainPoolBlock *listHeadR; struct MainPoolState *prev; @@ -41,31 +41,31 @@ struct AllocOnlyPool { extern f32 vtxStretchY; -void *get_next_available_memory_addr(u32); +void *get_next_available_memory_addr(uintptr_t); uintptr_t set_segment_base_addr(s32, void*); void *get_segment_base_addr(s32); void *segmented_to_virtual(const void *); void move_segment_table_to_dmem(void); void initialize_memory_pool(uintptr_t, uintptr_t); void *decompress_segments(u8*, u8*); -void *allocate_memory(u32); +void *allocate_memory(size_t); void *load_data(uintptr_t, uintptr_t); void func_802A7D54(s32, s32); -void main_pool_init(u32, u32); -void *main_pool_alloc(u32, u32); -u32 main_pool_free(void*); -void *main_pool_realloc(void*, u32); -s32 main_pool_available(void); -u32 main_pool_push_state(void); -u32 main_pool_pop_state(void); +void main_pool_init(uintptr_t, uintptr_t); +void *main_pool_alloc(uintptr_t, uintptr_t); +uintptr_t main_pool_free(void*); +void *main_pool_realloc(void*, uintptr_t); +uintptr_t main_pool_available(void); +uintptr_t main_pool_push_state(void); +uintptr_t main_pool_pop_state(void); void *func_802A80B0(u8*, u8*, u8*); void func_802A81EC(void); -struct AllocOnlyPool *alloc_only_pool_init(u32, u32); -u32 func_802A82AC(s32); -s32 func_802A8348(s32, s32, s32); +struct AllocOnlyPool *alloc_only_pool_init(uintptr_t, uintptr_t); +uintptr_t func_802A82AC(s32); +uintptr_t func_802A8348(s32, s32, s32); u8 *dma_textures(u8*, u32, u32); -u32 MIO0_0F(u8*, u32, u32); +uintptr_t MIO0_0F(u8*, uintptr_t, uintptr_t); void func_802A8844(void); void unpack_lights(Gfx*, u8*, s8); void unpack_displaylist(Gfx*, u8*, s8); @@ -73,16 +73,16 @@ void unpack_end_displaylist(Gfx*, u8*, s8); void unpack_set_geometry_mode(Gfx*, u8*, s8); void unpack_clear_geometry_mode(Gfx*, u8*, s8); void unpack_cull_displaylist(Gfx*, u8*, s8); -void unpack_combine_mode1(Gfx*, u8*, u32); -void unpack_combine_mode2(Gfx*, u8*, u32); -void unpack_combine_mode_shade(Gfx*, u8*, u32); -void unpack_combine_mode4(Gfx*, u8*, u32); -void unpack_combine_mode5(Gfx*, u8*, u32); -void unpack_render_mode_opaque(Gfx*, u8*, u32); -void unpack_render_mode_tex_edge(Gfx*, u8*, u32); -void unpack_render_mode_translucent(Gfx*, u8*, u32); -void unpack_render_mode_opaque_decal(Gfx*, u8*, u32); -void unpack_render_mode_translucent_decal(Gfx*, u8*, u32); +void unpack_combine_mode1(Gfx*, u8*, uintptr_t); +void unpack_combine_mode2(Gfx*, u8*, uintptr_t); +void unpack_combine_mode_shade(Gfx*, u8*, uintptr_t); +void unpack_combine_mode4(Gfx*, u8*, uintptr_t); +void unpack_combine_mode5(Gfx*, u8*, uintptr_t); +void unpack_render_mode_opaque(Gfx*, u8*, uintptr_t); +void unpack_render_mode_tex_edge(Gfx*, u8*, uintptr_t); +void unpack_render_mode_translucent(Gfx*, u8*, uintptr_t); +void unpack_render_mode_opaque_decal(Gfx*, u8*, uintptr_t); +void unpack_render_mode_translucent_decal(Gfx*, u8*, uintptr_t); void unpack_tile_sync(Gfx*, u8*, s8); void unpack_tile_load_sync(Gfx*, u8*, s8); void unpack_texture_on(Gfx*, u8*, s8); diff --git a/src/racing/race_logic.c b/src/racing/race_logic.c index 1c690e5123..5c9772b71a 100644 --- a/src/racing/race_logic.c +++ b/src/racing/race_logic.c @@ -504,7 +504,7 @@ f32 func_8028EE8C(s32 arg0) { f32 temp_v1 = gPlayers[arg0].copy_rotation_z; f32 temp_f14 = D_8015F8D0[2] - temp_v0; f32 temp_f16 = temp_v1 - D_8015F8D0[2]; - return gCourseTimer - ((0.01666666f * temp_f14) / (temp_f14 + temp_f16)); + return gCourseTimer - ((COURSE_TIMER_ITER_f * temp_f14) / (temp_f14 + temp_f16)); } void func_8028EEF0(s32 i) { @@ -836,7 +836,7 @@ void func_8028F970(void) { return; } } - + if (gEnableDebugMode) { if (gModeSelection == BATTLE) { // do stuff? @@ -1108,7 +1108,7 @@ void func_802903B0(void) { void func_802903D8(Player *playerOne, Player *playerTwo) { f32 sp70 = (playerOne->boundingBoxSize + playerTwo->boundingBoxSize) - 5.0f; f32 temp_f0; - f32 sp74; + f32 sp74; Vec3f sp60; Vec3f sp54; f32 temp_f0_2; diff --git a/src/racing/render_courses.c b/src/racing/render_courses.c index 0dc3c13207..b4c8caf6f5 100644 --- a/src/racing/render_courses.c +++ b/src/racing/render_courses.c @@ -125,12 +125,12 @@ void render_course_segments(uintptr_t addr, struct UnkStruct_800DC5EC *arg1) { index = arg1->pathCounter; } else if (player->collision.surfaceDistance[2] > 30.0f) { index = arg1->pathCounter; - } else { + } else { index = temp_v0_3; } } else if (camera->collision.surfaceDistance[2] > 30.0f) { index = arg1->pathCounter; - } else { + } else { index = sp1E; } } else { @@ -163,7 +163,7 @@ void render_course_segments(uintptr_t addr, struct UnkStruct_800DC5EC *arg1) { index = arg1->pathCounter; } else if (player->collision.surfaceDistance[2] > 30.0f) { index = arg1->pathCounter; - } else { + } else { index = temp_v0_3; } break; @@ -173,14 +173,13 @@ void render_course_segments(uintptr_t addr, struct UnkStruct_800DC5EC *arg1) { index = get_section_id(camera->collision.meshIndexZX); if (camera->collision.surfaceDistance[2] > 30.0f) { index = arg1->pathCounter; - } else if (index == 255) { + } else if (index == 255) { index = arg1->pathCounter; } } arg1->pathCounter = index; index = ((index - 1) * 4) + var_a3; - gSPDisplayList(gDisplayListHead++, gfx[index]); } @@ -940,48 +939,48 @@ void render_moo_moo_farm(struct UnkStruct_800DC5EC *arg0) { if ((temp_s0 < 14) && (temp_s0 > 10)) { if ((temp_s1 == 2) || (temp_s1 == 3) || (temp_s1 == 1)) - // + // gSPDisplayList(gDisplayListHead++, d_course_moo_moo_farm_dl_13FF8); - + } else if (temp_s0 < 16) { gSPDisplayList(gDisplayListHead++, d_course_moo_moo_farm_dl_13FF8); } else if (temp_s0 < 19) { - if (temp_s1 != 2) + if (temp_s1 != 2) gSPDisplayList(gDisplayListHead++, d_course_moo_moo_farm_dl_13FF8); - + } else if (temp_s0 < 20) { - if (temp_s1 == 0) + if (temp_s1 == 0) gSPDisplayList(gDisplayListHead++, d_course_moo_moo_farm_dl_13FF8); - + } gDPSetCombineMode(gDisplayListHead++, G_CC_MODULATEI, G_CC_MODULATEI); gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2); if ((temp_s0 >= 16) && (temp_s0 < 24)) { - if ((temp_s1 == 2) || (temp_s1 == 3)) + if ((temp_s1 == 2) || (temp_s1 == 3)) // d_course_moo_moo_farm_packed_dl_5410 gSPDisplayList(gDisplayListHead++, ((uintptr_t)0x07005410)); - + } else if (temp_s0 < 9) { - if (temp_s1 == 2) + if (temp_s1 == 2) // d_course_moo_moo_farm_packed_dl_5410 gSPDisplayList(gDisplayListHead++, ((uintptr_t)0x07005410)); - + } if (temp_s0 < 4) { if (temp_s1 != 0) gSPDisplayList(gDisplayListHead++, d_course_moo_moo_farm_dl_14060); - + } else if (temp_s0 < 8) { if (temp_s1 == 2) gSPDisplayList(gDisplayListHead++, d_course_moo_moo_farm_dl_14060); - + } else if (temp_s0 >= 22) { gSPDisplayList(gDisplayListHead++, d_course_moo_moo_farm_dl_14060); } else if (temp_s0 >= 18) { if ((temp_s1 == 0) || (temp_s1 == 3)) gSPDisplayList(gDisplayListHead++, d_course_moo_moo_farm_dl_14060); - + } gDPSetCombineMode(gDisplayListHead++, G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA); gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_TEX_EDGE, G_RM_AA_ZB_TEX_EDGE2); @@ -1412,7 +1411,7 @@ void func_80295D88(void) { gCourseMaxX = 0; gCourseMaxY = 0; gCourseMaxZ = 0; - + D_8015F59C = 0; D_8015F5A0 = 0; func_80295D6C(); diff --git a/src/racing/skybox_and_splitscreen.c b/src/racing/skybox_and_splitscreen.c index 0245992b0b..66a149e80f 100644 --- a/src/racing/skybox_and_splitscreen.c +++ b/src/racing/skybox_and_splitscreen.c @@ -471,7 +471,7 @@ void func_802A4A0C(Vtx *vtx, struct UnkStruct_800DC5EC *arg1, UNUSED s32 arg2, U vtx[2].v.ob[1] = temp_t5; vtx[4].v.ob[1] = temp_t5; vtx[7].v.ob[1] = temp_t5; - + init_rdp(); gDPSetRenderMode(gDisplayListHead++, G_RM_OPA_SURF, G_RM_OPA_SURF2); gSPClearGeometryMode(gDisplayListHead++, G_ZBUFFER | G_LIGHTING);