From 2da776c9c00eb715f5954fc6d920f7725f4b27af Mon Sep 17 00:00:00 2001 From: someone2639 Date: Thu, 27 May 2021 00:15:06 -0400 Subject: [PATCH 1/5] s32 model ID to make the code cleaner --- include/level_commands.h | 11 ++++++----- include/types.h | 2 +- src/engine/level_script.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/level_commands.h b/include/level_commands.h index 1772a62b..a4dcabda 100644 --- a/include/level_commands.h +++ b/include/level_commands.h @@ -215,12 +215,13 @@ CMD_HH(layer, model) #define LOAD_MODEL_FROM_GEO(model, geo) \ - CMD_BBH(0x22, 0x08, model), \ - CMD_PTR(geo) + CMD_BBH(0x22, 0x0C, 0), \ + CMD_PTR(geo), \ + CMD_W(model) // unk8 is float, but doesn't really matter since CMD23 is unused #define CMD23(model, unk4, unk8) \ - CMD_BBH(0x22, 0x08, model), \ + CMD_BBH(0x22, 0x08, 0), \ CMD_PTR(unk4), \ CMD_W(unk8) @@ -229,7 +230,7 @@ CMD_HHHHHH(posX, posY, posZ, angleX, angleY, angleZ), \ CMD_W(behParam), \ CMD_PTR(beh), \ - CMD_HH(0, model) + CMD_W(model) #define OBJECT(model, posX, posY, posZ, angleX, angleY, angleZ, behParam, beh) \ OBJECT_WITH_ACTS(model, posX, posY, posZ, angleX, angleY, angleZ, behParam, beh, 0x1F) @@ -238,7 +239,7 @@ CMD_BBH(0x25, 0x10, 0), \ CMD_W(behArg), \ CMD_PTR(beh), \ - CMD_HH(0, model) + CMD_W(model) #define WARP_NODE(id, destLevel, destArea, destNode, flags) \ CMD_BBBB(0x26, 0x08, id, destLevel), \ diff --git a/include/types.h b/include/types.h index 475655cf..6e62e8c2 100644 --- a/include/types.h +++ b/include/types.h @@ -54,7 +54,7 @@ typedef s16 Trajectory; typedef s16 PaintingData; typedef uintptr_t BehaviorScript; typedef u8 Texture; -typedef u16 ModelID; +typedef s32 ModelID; enum SpTaskState { SPTASK_STATE_NOT_STARTED, diff --git a/src/engine/level_script.c b/src/engine/level_script.c index daeff54c..8ee3cc0c 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -379,7 +379,7 @@ static void level_cmd_load_model_from_dl(void) { s16 layer = CMD_GET(u16, 0x8); void *dl_ptr = CMD_GET(void *, 4); - if (model < 65536) { + if (model < ARRAY_COUNT(gLoadedGraphNodes)) { gLoadedGraphNodes[model] = (struct GraphNode *) init_graph_node_display_list(sLevelPool, 0, layer, dl_ptr); } @@ -388,11 +388,11 @@ static void level_cmd_load_model_from_dl(void) { } static void level_cmd_load_model_from_geo(void) { - ModelID arg0 = CMD_GET(ModelID, 2); - void *arg1 = CMD_GET(void *, 4); + ModelID model = CMD_GET(ModelID, 8); + void *geo = CMD_GET(void *, 4); - if (arg0 < 65536) { - gLoadedGraphNodes[arg0] = process_geo_layout(sLevelPool, arg1); + if (model < ARRAY_COUNT(gLoadedGraphNodes)) { + gLoadedGraphNodes[model] = process_geo_layout(sLevelPool, geo); } sCurrentCmd = CMD_NEXT; @@ -410,7 +410,7 @@ static void level_cmd_23(void) { // load an f32, but using an integer load instruction for some reason (hence the union) arg2.i = CMD_GET(s32, 8); - if (model < 65536) { + if (model < ARRAY_COUNT(gLoadedGraphNodes)) { // GraphNodeScale has a GraphNode at the top. This // is being stored to the array, so cast the pointer. gLoadedGraphNodes[model] = @@ -428,7 +428,7 @@ static void level_cmd_init_mario(void) { gMarioSpawnInfo->areaIndex = 0; gMarioSpawnInfo->behaviorArg = CMD_GET(u32, 4); gMarioSpawnInfo->behaviorScript = CMD_GET(void *, 8); - gMarioSpawnInfo->unk18 = gLoadedGraphNodes[CMD_GET(ModelID, 0xE)]; + gMarioSpawnInfo->unk18 = gLoadedGraphNodes[CMD_GET(ModelID, 0xC)]; gMarioSpawnInfo->next = NULL; sCurrentCmd = CMD_NEXT; @@ -440,7 +440,7 @@ static void level_cmd_place_object(void) { struct SpawnInfo *spawnInfo; if (sCurrAreaIndex != -1 && ((CMD_GET(u8, 2) & val7) || CMD_GET(u8, 2) == 0x1F)) { - model = CMD_GET(ModelID, 0x1A); + model = CMD_GET(ModelID, 0x18); spawnInfo = alloc_only_pool_alloc(sLevelPool, sizeof(struct SpawnInfo)); spawnInfo->startPos[0] = CMD_GET(s16, 4); From bd79934f00b80e0979371de494e914a16d177f2b Mon Sep 17 00:00:00 2001 From: someone2639 Date: Thu, 27 May 2021 00:21:37 -0400 Subject: [PATCH 2/5] make model count a define so it's easier to change in case you need memory --- enhancements/debug_box.patch | 2 +- include/config.h | 2 ++ src/engine/level_script.c | 6 +++--- src/game/area.c | 5 +++-- src/game/area.h | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/enhancements/debug_box.patch b/enhancements/debug_box.patch index f51cedfb..2ec23b9f 100644 --- a/enhancements/debug_box.patch +++ b/enhancements/debug_box.patch @@ -9,7 +9,7 @@ index af9d0156..c68a7f6e 100644 +#include "debug_box.h" struct SpawnInfo gPlayerSpawnInfos[1]; - struct GraphNode *D_8033A160[0x100]; + struct GraphNode *gGraphNodePointers[0x100]; @@ -363,6 +364,8 @@ void render_game(void) { if (gCurrentArea != NULL && !gWarpTransition.pauseRendering) { geo_process_root(gCurrentArea->unk04, D_8032CE74, D_8032CE78, gFBSetColor); diff --git a/include/config.h b/include/config.h index 840274a9..964caf61 100644 --- a/include/config.h +++ b/include/config.h @@ -62,6 +62,8 @@ //#define SKIP_TITLE_SCREEN // Uncomment this if you want to keep the mario head and not skip it //#define KEEP_MARIO_HEAD +// Number of possible unique model ID's (keep it higher than 256) +#define MODEL_ID_COUNT 0x10000 /* Coordinate overflow fix setting: * Scales the world down by this factor, increasing how far you can render on diff --git a/src/engine/level_script.c b/src/engine/level_script.c index 8ee3cc0c..84aa69f4 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -379,7 +379,7 @@ static void level_cmd_load_model_from_dl(void) { s16 layer = CMD_GET(u16, 0x8); void *dl_ptr = CMD_GET(void *, 4); - if (model < ARRAY_COUNT(gLoadedGraphNodes)) { + if (model < ARRAY_COUNT(gGraphNodePointers)) { gLoadedGraphNodes[model] = (struct GraphNode *) init_graph_node_display_list(sLevelPool, 0, layer, dl_ptr); } @@ -391,7 +391,7 @@ static void level_cmd_load_model_from_geo(void) { ModelID model = CMD_GET(ModelID, 8); void *geo = CMD_GET(void *, 4); - if (model < ARRAY_COUNT(gLoadedGraphNodes)) { + if (model < ARRAY_COUNT(gGraphNodePointers)) { gLoadedGraphNodes[model] = process_geo_layout(sLevelPool, geo); } @@ -410,7 +410,7 @@ static void level_cmd_23(void) { // load an f32, but using an integer load instruction for some reason (hence the union) arg2.i = CMD_GET(s32, 8); - if (model < ARRAY_COUNT(gLoadedGraphNodes)) { + if (model < ARRAY_COUNT(gGraphNodePointers)) { // GraphNodeScale has a GraphNode at the top. This // is being stored to the array, so cast the pointer. gLoadedGraphNodes[model] = diff --git a/src/game/area.c b/src/game/area.c index dafadf13..3298ef98 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -1,5 +1,6 @@ #include +#include "config.h" #include "prevent_bss_reordering.h" #include "area.h" #include "sm64.h" @@ -23,7 +24,7 @@ #include "level_table.h" struct SpawnInfo gPlayerSpawnInfos[1]; -struct GraphNode *D_8033A160[0x10000]; +struct GraphNode *gGraphNodePointers[MODEL_ID_COUNT]; struct Area gAreaData[8]; struct WarpTransition gWarpTransition; @@ -36,7 +37,7 @@ s16 gPauseScreenMode; s16 gSaveOptSelectIndex; struct SpawnInfo *gMarioSpawnInfo = &gPlayerSpawnInfos[0]; -struct GraphNode **gLoadedGraphNodes = D_8033A160; +struct GraphNode **gLoadedGraphNodes = gGraphNodePointers; struct Area *gAreas = gAreaData; struct Area *gCurrentArea = NULL; struct CreditsEntry *gCurrCreditsEntry = NULL; diff --git a/src/game/area.h b/src/game/area.h index d746caa7..fa6c8e1b 100644 --- a/src/game/area.h +++ b/src/game/area.h @@ -120,7 +120,7 @@ struct WarpTransition extern struct GraphNode **gLoadedGraphNodes; extern struct SpawnInfo gPlayerSpawnInfos[]; -extern struct GraphNode *D_8033A160[]; +extern struct GraphNode *gGraphNodePointers[MODEL_ID_COUNT]; extern struct Area gAreaData[]; extern struct WarpTransition gWarpTransition; extern s16 gCurrCourseNum; From 0ee319a3003d900be6fcf7f73d7a073392a9a85c Mon Sep 17 00:00:00 2001 From: someone2639 Date: Thu, 27 May 2021 00:34:53 -0400 Subject: [PATCH 3/5] more modularity; fixed an assert in sm64.ld so it doesnt trip if ext ram is defined --- include/level_commands.h | 5 +++-- sm64.ld | 4 +++- src/engine/level_script.c | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/level_commands.h b/include/level_commands.h index a4dcabda..c7804aa8 100644 --- a/include/level_commands.h +++ b/include/level_commands.h @@ -210,9 +210,10 @@ CMD_BBH(0x20, 0x04, 0x0000) #define LOAD_MODEL_FROM_DL(model, dl, layer) \ - CMD_BBH(0x21, 0x0C, 0), \ + CMD_BBH(0x21, 0x10, 0), \ CMD_PTR(dl), \ - CMD_HH(layer, model) + CMD_W(layer), \ + CMD_W(model) #define LOAD_MODEL_FROM_GEO(model, geo) \ CMD_BBH(0x22, 0x0C, 0), \ diff --git a/sm64.ld b/sm64.ld index 32537a49..976b232d 100755 --- a/sm64.ld +++ b/sm64.ld @@ -231,7 +231,9 @@ SECTIONS __mainPoolSize = RAM_END - .; __expansionRamStart = 0x80400000; - ASSERT((. <= __expansionRamStart), "Error: RDRAM expanded into Expansion RAM, despite Expansion RAM not being defined.") + #ifndef USE_EXT_RAM + ASSERT((. <= __expansionRamStart), "Error: RDRAM expanded into Expansion RAM, despite Expansion RAM not being defined.") + #endif BEGIN_SEG(entry, 0x10000000) diff --git a/src/engine/level_script.c b/src/engine/level_script.c index 84aa69f4..cb8598ba 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -375,8 +375,8 @@ static void level_cmd_end_area(void) { } static void level_cmd_load_model_from_dl(void) { - ModelID model = CMD_GET(ModelID, 0xA); - s16 layer = CMD_GET(u16, 0x8); + ModelID model = CMD_GET(ModelID, 0xC); + s16 layer = CMD_GET(u32, 0x8); void *dl_ptr = CMD_GET(void *, 4); if (model < ARRAY_COUNT(gGraphNodePointers)) { From b6c9fba41ac4191f5ee94306b71f35bf83801b1c Mon Sep 17 00:00:00 2001 From: someone2639 Date: Thu, 27 May 2021 00:37:03 -0400 Subject: [PATCH 4/5] u32 model ID because that makes more sense! --- include/types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/types.h b/include/types.h index 6e62e8c2..5548eab8 100644 --- a/include/types.h +++ b/include/types.h @@ -54,7 +54,7 @@ typedef s16 Trajectory; typedef s16 PaintingData; typedef uintptr_t BehaviorScript; typedef u8 Texture; -typedef s32 ModelID; +typedef u32 ModelID; enum SpTaskState { SPTASK_STATE_NOT_STARTED, From 6beb1dfa9ee9790a5dbe51165b39f1f6ae62c2ef Mon Sep 17 00:00:00 2001 From: someone2639 Date: Thu, 27 May 2021 01:21:05 -0400 Subject: [PATCH 5/5] made the level script code more clear in what it was comparing --- src/engine/level_script.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engine/level_script.c b/src/engine/level_script.c index cb8598ba..24c83bb0 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -379,7 +379,7 @@ static void level_cmd_load_model_from_dl(void) { s16 layer = CMD_GET(u32, 0x8); void *dl_ptr = CMD_GET(void *, 4); - if (model < ARRAY_COUNT(gGraphNodePointers)) { + if (model < MODEL_ID_COUNT) { gLoadedGraphNodes[model] = (struct GraphNode *) init_graph_node_display_list(sLevelPool, 0, layer, dl_ptr); } @@ -391,7 +391,7 @@ static void level_cmd_load_model_from_geo(void) { ModelID model = CMD_GET(ModelID, 8); void *geo = CMD_GET(void *, 4); - if (model < ARRAY_COUNT(gGraphNodePointers)) { + if (model < MODEL_ID_COUNT) { gLoadedGraphNodes[model] = process_geo_layout(sLevelPool, geo); } @@ -410,7 +410,7 @@ static void level_cmd_23(void) { // load an f32, but using an integer load instruction for some reason (hence the union) arg2.i = CMD_GET(s32, 8); - if (model < ARRAY_COUNT(gGraphNodePointers)) { + if (model < MODEL_ID_COUNT) { // GraphNodeScale has a GraphNode at the top. This // is being stored to the array, so cast the pointer. gLoadedGraphNodes[model] =