Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/config/config_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@
*/
#define ENABLE_MOTION_BLUR_DEBUG false

/**
* Enable a more detailed assert when various allocations fail and crash instantly
*/
#define ENABLE_DETAILED_ALLOC_ASSERTS false

#endif
19 changes: 19 additions & 0 deletions include/config/config_graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,23 @@
// Increase the size of small elements (improves readability on N64)
#define WIDESCREEN_N64_MODE true

/**
* Framebuffer splitting
* This allows you to dedicate 2MB to framebuffers. Overrides SYS_CFB_END.
* You shouldn't enable this unless you know what you're doing!
* HackerOOT's default sizes in config_memory.h are not suitable for these, you have to change them
* Since it takes 2MB, you need to have 2MB available. Not usable in 4MB mode by default.
*/
#define ENABLE_SPLIT_FRAMEBUFFERS false

/**
* Z-Buffer splitting
* This options allows you to dedicate 1MB to the Z-Buffer. Overrides SYS_CFB_END.
* You shouldn't enable this unless you know what you're doing!
* HackerOOT's default sizes in config_memory.h are not suitable for these, you have to change them
* This option can be enabled without ENABLE_SPLIT_FRAMEBUFFERS
* Costs 1MB. If enabled with ENABLE_SPLIT_FRAMEBUFFERS, costs 3MB. Not usable in 4MB mode by default.
*/
#define ENABLE_SPLIT_ZBUFFER false

#endif
5 changes: 5 additions & 0 deletions include/config/config_safeguards.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#undef ENABLE_DEBUG_HEAP
#undef INCLUDE_EXAMPLE_SCENE
#undef ENABLE_MOTION_BLUR_DEBUG
#undef ENABLE_DETAILED_ALLOC_ASSERTS

#define SHOW_CS_INFOS false
#define SHOW_INPUT_DISPLAY false
Expand All @@ -69,6 +70,7 @@
#define ENABLE_DEBUG_HEAP false
#define INCLUDE_EXAMPLE_SCENE false
#define ENABLE_MOTION_BLUR_DEBUG false
#define ENABLE_DETAILED_ALLOC_ASSERTS false
#endif


Expand Down Expand Up @@ -162,6 +164,7 @@
#undef ENABLE_DEBUG_SAVE
#undef MAP_SELECT_ON_FILE_1
#undef ENABLE_MOTION_BLUR_DEBUG
#undef ENABLE_DETAILED_ALLOC_ASSERTS

#define SKIP_N64_BOOT_LOGO true
#define BOOT_TO_SCENE false
Expand All @@ -186,6 +189,7 @@
#define ENABLE_DEBUG_SAVE false
#define MAP_SELECT_ON_FILE_1 true
#define ENABLE_MOTION_BLUR_DEBUG false
#define ENABLE_DETAILED_ALLOC_ASSERTS false
#endif

/**
Expand Down Expand Up @@ -222,6 +226,7 @@
#define IS_MAP_SELECT_ENABLED (IS_DEBUG && ENABLE_MAP_SELECT)
#define IS_DEBUG_SAVE_ENABLED (IS_DEBUG && ENABLE_DEBUG_SAVE)
#define CAN_INCLUDE_TEST_SCENES (!ENABLE_HACKEROOT || (IS_DEBUG && INCLUDE_TEST_SCENES))
#define FRAMEBUFFER_SPLIT (ENABLE_SPLIT_FRAMEBUFFERS) ? (((ENABLE_SPLIT_ZBUFFER) ? 3 : 2) << 20) : (ENABLE_SPLIT_ZBUFFER) ? (1 << 20) : 0

// In-game editors
#define IS_INV_EDITOR_ENABLED (IS_DEBUG && ENABLE_INV_EDITOR)
Expand Down
18 changes: 16 additions & 2 deletions spec
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,26 @@ endseg
beginseg
name "buffers"
flags NOLOAD
align 0x40
include "$(BUILD_DIR)/src/buffers/zbuffer.o"
include "$(BUILD_DIR)/src/buffers/gfxbuffers.o"
include "$(BUILD_DIR)/src/buffers/audio_heap.o"
#if !ENABLE_SPLIT_ZBUFFER
include "$(BUILD_DIR)/src/buffers/zbuffer.o"
#endif
endseg

#if ENABLE_SPLIT_ZBUFFER
beginseg
name "zbuffer"
flags NOLOAD
#if ENABLE_SPLIT_FRAMEBUFFERS
address 0x80500000 // framebuffers 1 and 2 in last two banks
#else
address 0x80700000 // framebuffers 1 and 2 are in their vanilla locations!
#endif
include "$(BUILD_DIR)/src/buffers/zbuffer.o"
endseg
#endif

#if ENABLE_F3DEX3
beginseg
name "F3DEX3_BrW_Text"
Expand Down
12 changes: 12 additions & 0 deletions src/code/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,18 @@ void* GameState_Alloc(GameState* gameState, size_t size, const char* file, int l
PRINTF("game_alloc(%08x) %08x-%08x [%s:%d]\n", size, ret, (uintptr_t)ret + size, file, line);
PRINTF(VT_RST);
}

#if ENABLE_DETAILED_ALLOC_ASSERTS
if (ret == NULL) {
char buff1[150];
char buff2[150];
sprintf(buff1, "\nGameState_Alloc:\nRequested: %d bytes\nAvailable: %d bytes", size,
(int)THA_GetRemaining(&gameState->tha));
sprintf(buff2, "\nIn file %s\nline %d", file, line);
Fault_AddHungupAndCrashImpl(buff1, buff2);
}
#endif

return ret;
}

Expand Down
4 changes: 4 additions & 0 deletions src/code/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ void Main(void* arg) {
SysCfb_Init(0);
systemHeapStart = (uintptr_t)_buffersSegmentEnd;
fb = (uintptr_t)SysCfb_GetFbPtr(0);
#if ENABLE_SPLIT_FRAMEBUFFERS // framebuffer 0 is not viable to mark end point of system heap because it moved
gSystemHeapSize = (uintptr_t)SysCfb_GetFbEnd() - systemHeapStart;
#else
gSystemHeapSize = fb - systemHeapStart;
#endif
// "System heap initalization"
PRINTF("システムヒープ初期化 %08x-%08x %08x\n", systemHeapStart, fb, gSystemHeapSize);
SystemHeap_Init((void*)systemHeapStart, gSystemHeapSize); // initializes the system heap
Expand Down
9 changes: 8 additions & 1 deletion src/code/sys_cfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ void SysCfb_Init(s32 n64dd) {
if (osMemSize >= 0x800000) {
// "8MB or more memory is installed"
PRINTF("8Mバイト以上のメモリが搭載されています\n");
tmpFbEnd = IS_DEBUG_HEAP_ENABLED ? 0x8044BE80 : SYS_CFB_END;
tmpFbEnd = IS_DEBUG_HEAP_ENABLED
? 0x8044BE80
: ((FRAMEBUFFER_SPLIT != 0) ? (0x80800000 - (FRAMEBUFFER_SPLIT)) : SYS_CFB_END);
if (n64dd == 1) {
PRINTF("RAM 8M mode (N64DD対応)\n"); // "RAM 8M mode (N64DD compatible)"
#if IS_DEBUG
Expand All @@ -38,8 +40,13 @@ void SysCfb_Init(s32 n64dd) {

// "The final address used by the system is %08x"
PRINTF("システムが使用する最終アドレスは %08x です\n", sSysCfbEnd);
#if ENABLE_SPLIT_FRAMEBUFFERS // split framebuffers
sSysCfbFbPtr[0] = 0x80700000;
sSysCfbFbPtr[1] = 0x80600000;
#else // vanilla (split nothing)
sSysCfbFbPtr[0] = sSysCfbEnd - (screenSize * 4);
sSysCfbFbPtr[1] = sSysCfbEnd - (screenSize * 2);
#endif
// "Frame buffer addresses are %08x and %08x"
PRINTF("フレームバッファのアドレスは %08x と %08x です\n", sSysCfbFbPtr[0], sSysCfbFbPtr[1]);
}
Expand Down
15 changes: 15 additions & 0 deletions src/code/z_bgcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,9 @@ void BgCheck_Allocate(CollisionContext* colCtx, PlayState* play, CollisionHeader
u32 customMemSize;
s32 useCustomSubdivisions;
s32 i;
#if ENABLE_DETAILED_ALLOC_ASSERTS
size_t thaRemaining = THA_GetRemaining(&play->state.tha);
#endif

colCtx->colHeader = colHeader;
customNodeListMax = -1;
Expand Down Expand Up @@ -1647,6 +1650,18 @@ void BgCheck_Allocate(CollisionContext* colCtx, PlayState* play, CollisionHeader

DynaPoly_Init(play, &colCtx->dyna);
DynaPoly_Alloc(play, &colCtx->dyna);

// bgcheck allocation is unsafe and could overflow.
// when it aligns the tail it doesn't check if it has room to do that.
// it is not caught, so a later assert would tell you that there is a negative amount of space remaining
#if ENABLE_DETAILED_ALLOC_ASSERTS
if (THA_IsCrash(&play->state.tha)) {
char buff[150];
sprintf(buff, "\nRequested: %d bytes\nAvailable: %d bytes",
(s32)(thaRemaining - THA_GetRemaining(&play->state.tha)), thaRemaining);
Fault_AddHungupAndCrashImpl("BgCheck_Allocate", buff);
}
#endif
}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/code/z_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,23 @@ s32 Object_SpawnPersistent(ObjectContext* objectCtx, s16 objectId) {
PRINTF("num=%d adrs=%x end=%x\n", objectCtx->numEntries,
(uintptr_t)objectCtx->slots[objectCtx->numEntries].segment + size, objectCtx->spaceEnd);

#if ENABLE_DETAILED_ALLOC_ASSERTS
if (!((objectCtx->numEntries < ARRAY_COUNT(objectCtx->slots)) &&
(((uintptr_t)objectCtx->slots[objectCtx->numEntries].segment + size) < (uintptr_t)objectCtx->spaceEnd))) {
char buff1[150];
sprintf(buff1,
"\nObject %d\nRequested: %d bytes\nAvailable: %d bytes\nNeed %d more.\n\nObject space was %d bytes",
objectId, (unsigned int)size, objectCtx->spaceEnd - objectCtx->slots[objectCtx->numEntries].segment,
(objectCtx->slots[objectCtx->numEntries].segment + size) - objectCtx->spaceEnd,
objectCtx->spaceEnd - objectCtx->spaceStart);
Fault_AddHungupAndCrashImpl("Persistent Object Alloc Failed!", buff1);
}
#else
ASSERT(((objectCtx->numEntries < ARRAY_COUNT(objectCtx->slots)) &&
(((uintptr_t)objectCtx->slots[objectCtx->numEntries].segment + size) < (uintptr_t)objectCtx->spaceEnd)),
"this->num < OBJECT_EXCHANGE_BANK_MAX && (this->status[this->num].Segment + size) < this->endSegment",
"../z_scene.c", 142);
#endif

DMA_REQUEST_SYNC(objectCtx->slots[objectCtx->numEntries].segment, gObjectTable[objectId].vromStart, size,
"../z_scene.c", 145);
Expand Down Expand Up @@ -167,7 +180,18 @@ void* func_800982FC(ObjectContext* objectCtx, s32 slot, s16 objectId) {

nextPtr = (void*)ALIGN16((uintptr_t)entry->segment + size);

#if ENABLE_DETAILED_ALLOC_ASSERTS
if (nextPtr > objectCtx->spaceEnd) {
char buff1[150];
sprintf(buff1,
"\nObject %d\nRequested: %d bytes\nAvailable: %d bytes\nNeed %d more.\n\nObject space was %d bytes",
objectId, (unsigned int)size, objectCtx->spaceEnd - entry->segment, nextPtr - objectCtx->spaceEnd,
objectCtx->spaceEnd - objectCtx->spaceStart);
Fault_AddHungupAndCrashImpl("Object Alloc Failed!", buff1);
}
#else
ASSERT(nextPtr < objectCtx->spaceEnd, "nextptr < this->endSegment", "../z_scene.c", 381);
#endif

// "Object exchange free size=%08x"
PRINTF("オブジェクト入れ替え空きサイズ=%08x\n", (uintptr_t)objectCtx->spaceEnd - (uintptr_t)nextPtr);
Expand Down