diff --git a/src/engine/level_script.c b/src/engine/level_script.c index ad327cdb..006f4701 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -314,15 +314,22 @@ static void level_cmd_init_level(void) { } extern s32 gTlbEntries; +extern u8 gTlbSegments[32]; //This clears all the temporary bank TLB maps. group0, common1 and behavourdata are always loaded, //and they're also loaded first, so that means we just leave the first 3 indexes mapped. void unmap_tlbs(void) { - while (gTlbEntries > 3) + s32 i; + for (i = 0; i < 32; i++) { - osUnmapTLB(gTlbEntries); - gTlbEntries--; + if (gTlbSegments[i] && i != 0x17 && i != 0x16 && i != 0x13) + { + osUnmapTLB(gTlbEntries); + gTlbSegments[i] = 0; + gTlbEntries--; + } + } } diff --git a/src/game/farcall_helpers.h b/src/game/farcall_helpers.h index 99a9cc0f..d42daf15 100644 --- a/src/game/farcall_helpers.h +++ b/src/game/farcall_helpers.h @@ -21,6 +21,9 @@ #include "mario.h" #include "save_file.h" #include "game_init.h" +#include "obj_behaviors_2.h" +#include "level_headers.h" +#include "level_misc_macros.h" #define o gCurrentObject diff --git a/src/game/memory.c b/src/game/memory.c index 16d13ec5..a4733879 100644 --- a/src/game/memory.c +++ b/src/game/memory.c @@ -28,7 +28,6 @@ #define ALIGN4(val) (((val) + 0x3) & ~0x3) #define ALIGN8(val) (((val) + 0x7) & ~0x7) #define ALIGN16(val) (((val) + 0xF) & ~0xF) -//#define ALIGN(val, alignment) (((val) + ((alignment) - 1)) & ~((alignment) - 1)) struct MainPoolState { u32 freeSpace; @@ -307,6 +306,7 @@ void *dynamic_dma_read(u8 *srcStart, u8 *srcEnd, u32 side, u32 alignment, u32 bs #define TLB_PAGE_SIZE 4096 //Blocksize of TLB transfers. Larger values can be faster to transfer, but more wasteful of RAM. s32 gTlbEntries = 0; +u8 gTlbSegments[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; void mapTLBPages(uintptr_t virtualAddress, uintptr_t physicalAddress, s32 length) { @@ -344,6 +344,7 @@ void *load_segment(s32 segment, u8 *srcStart, u8 *srcEnd, u32 side, u8 *bssStart u8 *realAddr = (u8 *)ALIGN((uintptr_t)addr, TLB_PAGE_SIZE); set_segment_base_addr(segment, realAddr); mapTLBPages(segment << 24, VIRTUAL_TO_PHYSICAL(realAddr), (srcEnd - srcStart) + ((uintptr_t)bssEnd - (uintptr_t)bssStart)); + gTlbSegments[segment] = gTlbEntries; } } else