From f50b0acb0c39dbd080f61c75100ceb915d448011 Mon Sep 17 00:00:00 2001 From: louist103 <35883445+louist103@users.noreply.github.com> Date: Sat, 18 May 2024 14:58:16 -0400 Subject: [PATCH] Cleanup notebook --- mm/include/z64bombers_notebook.h | 22 +++++++++++----------- mm/src/code/z_play_hireso.c | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/mm/include/z64bombers_notebook.h b/mm/include/z64bombers_notebook.h index 06438b62a..44c9e6036 100644 --- a/mm/include/z64bombers_notebook.h +++ b/mm/include/z64bombers_notebook.h @@ -38,20 +38,20 @@ typedef enum BombersNotebookEvent { typedef struct { /* 0x00 */ u8 loadState; - /* 0x01 */ UNK_TYPE1 pad01[0x3F]; - /* 0x40 */ void* scheduleDmaSegment; - /* 0x44 */ uintptr_t scheduleDmaSegmentStart; - /* 0x48 */ size_t scheduleDmaSegmentSize; - /* 0x4C */ DmaRequest dmaRequest; - /* 0x6C */ OSMesgQueue loadQueue; - /* 0x84 */ OSMesg loadMsg[1]; - /* 0x88 */ void* scheduleSegment; - /* 0x8C */ uintptr_t scheduleSegmentStart; - /* 0x90 */ size_t scheduleSegmentSize; + ///* 0x01 */ UNK_TYPE1 pad01[0x3F]; + ///* 0x40 */ void* scheduleDmaSegment; + ///* 0x44 */ uintptr_t scheduleDmaSegmentStart; + ///* 0x48 */ size_t scheduleDmaSegmentSize; + ///* 0x4C */ DmaRequest dmaRequest; + ///* 0x6C */ OSMesgQueue loadQueue; + ///* 0x84 */ OSMesg loadMsg[1]; + ///* 0x88 */ void* scheduleSegment; + ///* 0x8C */ uintptr_t scheduleSegmentStart; + ///* 0x90 */ size_t scheduleSegmentSize; /* 0x94 */ s32 cursorPageRow; /* 0x98 */ s32 cursorEntry; // Entries are 3 apart, see BOMBERS_NOTEBOOK_ENTRY_SIZE /* 0x9C */ s32 cursorPage; - /* 0xA0 */ UNK_TYPE1 padA0[0x4]; + ///* 0xA0 */ UNK_TYPE1 padA0[0x4]; /* 0xA4 */ s32 scrollAmount; /* 0xA8 */ s32 scrollOffset; } BombersNotebook; // size = 0xAC diff --git a/mm/src/code/z_play_hireso.c b/mm/src/code/z_play_hireso.c index 2cdb47b48..a115b3f85 100644 --- a/mm/src/code/z_play_hireso.c +++ b/mm/src/code/z_play_hireso.c @@ -1070,8 +1070,8 @@ void BombersNotebook_Draw(BombersNotebook* this, GraphicsContext* gfxCtx) { gfx = POLY_OPA_DISP; if (this->loadState == BOMBERS_NOTEBOOK_LOAD_STATE_DONE) { - gSPSegment(gfx++, 0x07, this->scheduleDmaSegment); - gSPSegment(gfx++, 0x08, this->scheduleSegment); + //gSPSegment(gfx++, 0x07, this->scheduleDmaSegment); + //gSPSegment(gfx++, 0x08, this->scheduleSegment); gfx = Gfx_SetupDL39(gfx); gDPSetCombineLERP(gfx++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); @@ -1115,6 +1115,9 @@ void BombersNotebook_Draw(BombersNotebook* this, GraphicsContext* gfxCtx) { void BombersNotebook_LoadFiles(BombersNotebook* this, s32 flag) { switch (this->loadState) { case BOMBERS_NOTEBOOK_LOAD_STATE_NONE: + // #region 2S2H [Port] Same as the comment in the update function. We don't need to use the built in DMA + // engine. We use the resource manager. + #if 0 if (this->scheduleDmaSegment == NULL) { break; } @@ -1122,6 +1125,7 @@ void BombersNotebook_LoadFiles(BombersNotebook* this, s32 flag) { osCreateMesgQueue(&this->loadQueue, this->loadMsg, ARRAY_COUNT(this->loadMsg)); DmaMgr_SendRequestImpl(&this->dmaRequest, this->scheduleSegment, this->scheduleSegmentStart, this->scheduleSegmentSize, 0, &this->loadQueue, OS_MESG_PTR(NULL)); + #endif this->loadState = BOMBERS_NOTEBOOK_LOAD_STATE_STARTED; // fallthrough case BOMBERS_NOTEBOOK_LOAD_STATE_STARTED: @@ -1155,7 +1159,9 @@ void BombersNotebook_Update(PlayState* play, BombersNotebook* this, Input* input s32 stickAdjY = input->rel.stick_y; s32 cursorEntryScan; - + // #region 2S2H [Port] We don't need to allocate anything because we don't use these segments. + // We also want to avoid using malloc here because using a size of zero still allocates some data. + #if 0 this->scheduleDmaSegmentStart = SEGMENT_ROM_START(schedule_dma_static_yar); this->scheduleDmaSegmentSize = SEGMENT_ROM_SIZE(schedule_dma_static_syms); this->scheduleSegmentStart = SEGMENT_ROM_START(schedule_static); @@ -1168,6 +1174,7 @@ void BombersNotebook_Update(PlayState* play, BombersNotebook* this, Input* input if (this->scheduleSegment == NULL) { this->scheduleSegment = ZeldaArena_Malloc(this->scheduleSegmentSize); } + #endif BombersNotebook_LoadFiles(this, OS_MESG_NOBLOCK); @@ -1348,9 +1355,12 @@ void BombersNotebook_Destroy(BombersNotebook* this) { if (this->loadState == BOMBERS_NOTEBOOK_LOAD_STATE_STARTED) { BombersNotebook_LoadFiles(this, OS_MESG_BLOCK); } + #if 0 if (this->scheduleDmaSegment != NULL) { ZeldaArena_Free(this->scheduleDmaSegment); this->scheduleDmaSegment = NULL; } + #endif //! @bug: Does not free malloc'd memory for schedule segment + // 2S2H [Port] "Fix" the bug by not allocating anything }