From ae817a97456b355dec6af53bdfe033784707b244 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Mon, 17 Aug 2026 15:06:39 -0400 Subject: [PATCH] Fix fakematches in JKRExpHeap and d_scope --- include/global.h | 2 +- src/JSystem/JKernel/JKRExpHeap.cpp | 38 ++++++---------- src/d/d_scope.cpp | 69 +++++++++++++----------------- 3 files changed, 42 insertions(+), 67 deletions(-) diff --git a/include/global.h b/include/global.h index 32bc78eaa..b25b6ac28 100644 --- a/include/global.h +++ b/include/global.h @@ -9,7 +9,7 @@ // Align X to the previous N bytes (N must be power of two) #define ALIGN_PREV(X, N) ((X) & ~((N)-1)) // Align X to the next N bytes (N must be power of two) -#define ALIGN_NEXT(X, N) ALIGN_PREV(((X) + (N)-1), N) +#define ALIGN_NEXT(X, N) ALIGN_PREV(((X) + (N-1)), N) #define IS_ALIGNED(X, N) (((X) & ((N)-1)) == 0) #define IS_NOT_ALIGNED(X, N) (((X) & ((N)-1)) != 0) diff --git a/src/JSystem/JKernel/JKRExpHeap.cpp b/src/JSystem/JKernel/JKRExpHeap.cpp index 4b6097da9..862a3de5c 100644 --- a/src/JSystem/JKernel/JKRExpHeap.cpp +++ b/src/JSystem/JKernel/JKRExpHeap.cpp @@ -133,22 +133,17 @@ static JKRExpHeap::CMemBlock* DBnewFreeBlock; static JKRExpHeap::CMemBlock* DBnewUsedBlock; /* 802B192C-802B1B88 .text allocFromHead__10JKRExpHeapFUli */ -// wrong register at end void* JKRExpHeap::allocFromHead(u32 size, int align) { - u32 foundOffset; - int foundSize; - CMemBlock* newFreeBlock; - CMemBlock* newUsedBlock; - CMemBlock* foundBlock; - size = ALIGN_NEXT(size, 4); - foundSize = -1; - foundOffset = 0; - foundBlock = NULL; + int foundSize = -1; + u32 foundOffset = 0; + CMemBlock* foundBlock = NULL; + CMemBlock* newFreeBlock = NULL; + CMemBlock* newUsedBlock = NULL; for (CMemBlock* block = mHeadFreeList; block; block = block->mNext) { - u32 offset = - ALIGN_PREV(align - 1 + (u32)block->getContent(), align) - (u32)block->getContent(); + u32 alignedContent = ALIGN_NEXT((u32)block->getContent(), align); + u32 offset = alignedContent - (u32)block->getContent(); if (block->size < size + offset) { continue; } @@ -217,22 +212,11 @@ void* JKRExpHeap::allocFromHead(u32 size, int align) { } else { CMemBlock* prev = foundBlock->mPrev; CMemBlock* next = foundBlock->mNext; - // Regalloc doesn't match - /* newFreeBlock = foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0); removeFreeBlock(foundBlock); if (newFreeBlock) { setFreeBlock(newFreeBlock, prev, next); } - */ - // Works but very fake match - // /* - size = (u32)foundBlock->allocFore(size, mCurrentGroupId, 0, 0, 0); - removeFreeBlock(foundBlock); - if (size) { - setFreeBlock((CMemBlock*)size, prev, next); - } - // */ appendUsedList(foundBlock); return foundBlock->getContent(); } @@ -692,13 +676,15 @@ void JKRExpHeap::joinTwoBlocks(CMemBlock* block) { OSReport(":::joinTwoBlocks [%x %x %x][%x %x %x]\n", block, block->mFlags, block->size, block->mNext, block->mNext->mFlags, block->mNext->size); OSReport(":::: endAddr = %x\n", endAddr); OSReport(":::: nextAddr = %x\n", nextAddr); - JKRGetCurrentHeap()->dump(); + JKRHeap* heap = JKRGetCurrentHeap(); + heap->dump(); OSPanic(__FILE__, DEMO_SELECT(1710, 1718), ":::: Bad Block\n"); } if (endAddr == nextAddr) { - block->size = next->size + sizeof(CMemBlock) + next->getAlignment() + block->size; - setFreeBlock(block, block->mPrev, next->mNext); + block->size = next->size + sizeof(CMemBlock) + (next->mFlags & 0x7f) + block->size; + CMemBlock* local_30 = next->mNext; + setFreeBlock(block, block->mPrev, local_30); } } diff --git a/src/d/d_scope.cpp b/src/d/d_scope.cpp index 73af723d1..dc11f3213 100644 --- a/src/d/d_scope.cpp +++ b/src/d/d_scope.cpp @@ -87,7 +87,6 @@ void dDlst_2DSCP_c::outFontDraw() { if (icon_no != 0xFF) { int x = pos_x + mpScp->mpTextBox->getBounds().i.x; - // for some reason y computation only match if split in two int y = line * (VERSION_SELECT(1, 1, 2, 2) - mpScp->mLineCount + pos_y * 2); int y2 = y + mpScp->mpTextBox->getBounds().i.y; fopMsgM_outFontDraw(sbutton_icon[i], sbutton_kage[i], x, y2, scale, &sbuttonTimer[i], 0xFF, icon_no); @@ -464,25 +463,20 @@ void dScp_wipeMove(sub_scp_class* i_Scp, f32 i_rate) { fopMsgM_paneScaleXY(&i_Scp->mWipePanel[i], i_rate); } - f32 px0 = i_Scp->mWipePanel[0].mSizeOrig.x / 2.0f * t; - f32 py0 = i_Scp->mWipePanel[0].mSizeOrig.y / 2.0f * t; - // self assign fake match reused from TP - px0 = px0; - py0 = py0; - fopMsgM_paneTrans(&i_Scp->mWipePanel[0], -px0, -py0); - f32 px1 = i_Scp->mWipePanel[1].mSizeOrig.x / 2.0f * t; - f32 py1 = i_Scp->mWipePanel[1].mSizeOrig.y / 2.0f * t; - px1 = px1; - py1 = py1; - fopMsgM_paneTrans(&i_Scp->mWipePanel[1], px1, -py1); - f32 px2 = i_Scp->mWipePanel[2].mSizeOrig.x / 2.0f * t; - f32 py2 = i_Scp->mWipePanel[2].mSizeOrig.y / 2.0f * t; - px2 = px2; - py2 = py2; - fopMsgM_paneTrans(&i_Scp->mWipePanel[2], -px2, py2); - f32 px3 = i_Scp->mWipePanel[3].mSizeOrig.x / 2.0f * t; - f32 py3 = i_Scp->mWipePanel[3].mSizeOrig.y / 2.0f * t; - fopMsgM_paneTrans(&i_Scp->mWipePanel[3], px3, py3); + f32 px; + f32 py; + px = i_Scp->mWipePanel[0].mSizeOrig.x / 2.0f * t; + py = i_Scp->mWipePanel[0].mSizeOrig.y / 2.0f * t; + fopMsgM_paneTrans(&i_Scp->mWipePanel[0], -px, -py); + px = i_Scp->mWipePanel[1].mSizeOrig.x / 2.0f * t; + py = i_Scp->mWipePanel[1].mSizeOrig.y / 2.0f * t; + fopMsgM_paneTrans(&i_Scp->mWipePanel[1], px, -py); + px = i_Scp->mWipePanel[2].mSizeOrig.x / 2.0f * t; + py = i_Scp->mWipePanel[2].mSizeOrig.y / 2.0f * t; + fopMsgM_paneTrans(&i_Scp->mWipePanel[2], -px, py); + px = i_Scp->mWipePanel[3].mSizeOrig.x / 2.0f * t; + py = i_Scp->mWipePanel[3].mSizeOrig.y / 2.0f * t; + fopMsgM_paneTrans(&i_Scp->mWipePanel[3], px, py); i_Scp->mWipePanel[4].mPosCenter.y = i_Scp->mWipePanel[0].mPosTopLeft.y - i_Scp->mWipePanel[4].mSize.y / 2.0f; i_Scp->mWipePanel[5].mPosCenter.y = i_Scp->mWipePanel[5].mSize.y / 2.0f + (i_Scp->mWipePanel[3].mPosTopLeft.y + i_Scp->mWipePanel[3].mSize.y); @@ -504,25 +498,20 @@ void dScp_wipeMove2(sub_scp_class* i_Scp, f32 i_rate) { fopMsgM_paneScaleXY(&i_Scp->mWipePanel[i], i_rate); } - // Same self-assigned temps trick as dScp_wipeMove. - f32 px0 = i_Scp->mWipePanel[0].mSizeOrig.x / 2.0f * t; - f32 py0 = i_Scp->mWipePanel[0].mSizeOrig.y / 2.0f * t; - px0 = px0; - py0 = py0; - fopMsgM_paneTrans(&i_Scp->mWipePanel[0], -px0, -py0); - f32 px1 = i_Scp->mWipePanel[1].mSizeOrig.x / 2.0f * t; - f32 py1 = i_Scp->mWipePanel[1].mSizeOrig.y / 2.0f * t; - px1 = px1; - py1 = py1; - fopMsgM_paneTrans(&i_Scp->mWipePanel[1], px1, -py1); - f32 px2 = i_Scp->mWipePanel[2].mSizeOrig.x / 2.0f * t; - f32 py2 = i_Scp->mWipePanel[2].mSizeOrig.y / 2.0f * t; - px2 = px2; - py2 = py2; - fopMsgM_paneTrans(&i_Scp->mWipePanel[2], -px2, py2); - f32 px3 = i_Scp->mWipePanel[3].mSizeOrig.x / 2.0f * t; - f32 py3 = i_Scp->mWipePanel[3].mSizeOrig.y / 2.0f * t; - fopMsgM_paneTrans(&i_Scp->mWipePanel[3], px3, py3); + f32 px; + f32 py; + px = i_Scp->mWipePanel[0].mSizeOrig.x / 2.0f * t; + py = i_Scp->mWipePanel[0].mSizeOrig.y / 2.0f * t; + fopMsgM_paneTrans(&i_Scp->mWipePanel[0], -px, -py); + px = i_Scp->mWipePanel[1].mSizeOrig.x / 2.0f * t; + py = i_Scp->mWipePanel[1].mSizeOrig.y / 2.0f * t; + fopMsgM_paneTrans(&i_Scp->mWipePanel[1], px, -py); + px = i_Scp->mWipePanel[2].mSizeOrig.x / 2.0f * t; + py = i_Scp->mWipePanel[2].mSizeOrig.y / 2.0f * t; + fopMsgM_paneTrans(&i_Scp->mWipePanel[2], -px, py); + px = i_Scp->mWipePanel[3].mSizeOrig.x / 2.0f * t; + py = i_Scp->mWipePanel[3].mSizeOrig.y / 2.0f * t; + fopMsgM_paneTrans(&i_Scp->mWipePanel[3], px, py); if (i_rate >= 1.f) { for (int i = 4; i < 8; i++) { @@ -1385,7 +1374,7 @@ static cPhs_State dScp_Create(msg_class* i_this) { dDlst_2DSCP_c::~dDlst_2DSCP_c() { } -msg_method_class l_dScp_Method = { +static msg_method_class l_dScp_Method = { (process_method_func)dScp_Create, (process_method_func)dScp_Delete, (process_method_func)dScp_Execute,