Link CSmallAllocPool.cpp, minor fixes

This commit is contained in:
Phillip Stephens 2022-09-15 20:37:46 -07:00
parent 79301314e9
commit 7f768f8405
5 changed files with 74 additions and 72 deletions

View File

@ -130,7 +130,7 @@ $(METROTRK_FILES): MWCC_VERSION := 1.2.5
$(METROTRK_FILES): CFLAGS := $(CFLAGS_BASE) $(METROTRK_FILES): CFLAGS := $(CFLAGS_BASE)
$(BASE_FILES): MWCC_VERSION := 1.2.5 $(BASE_FILES): MWCC_VERSION := 1.2.5
$(BASE_FILES): CFLAGS := $(CFLAGS_BASE) $(BASE_FILES): CFLAGS := $(CFLAGS_BASE)
$(AI_FILES): MWCC_VERSION := 1.2.5e $(AI_FILES): MWCC_VERSION := 1.2.5
$(AI_FILES): CFLAGS := $(CFLAGS_BASE) $(AI_FILES): CFLAGS := $(CFLAGS_BASE)
$(OS_FILES): MWCC_VERSION := 1.2.5 $(OS_FILES): MWCC_VERSION := 1.2.5
$(OS_FILES): CFLAGS := $(CFLAGS_BASE) $(OS_FILES): CFLAGS := $(CFLAGS_BASE)

View File

@ -5,7 +5,7 @@
.global mRefCount__10CSfxHandle .global mRefCount__10CSfxHandle
mRefCount__10CSfxHandle: mRefCount__10CSfxHandle:
.skip 0x8 .skip 0x4
.section .text, "ax" .section .text, "ax"

View File

@ -9,8 +9,8 @@ public:
CSfxHandle(uint value); CSfxHandle(uint value);
uint GetIndex() const { return mID & 0xFFF; } uint GetIndex() const { return mID & 0xFFF; }
static NullHandle() { return CSfxHandle(); } static CSfxHandle NullHandle() { return CSfxHandle(); }
bool operator=(const CSfxHandle& other) { mID = other.mID; } void operator=(const CSfxHandle& other) { mID = other.mID; }
bool operator==(const CSfxHandle& other) { return mID == other.mID; } bool operator==(const CSfxHandle& other) { return mID == other.mID; }
bool operator!=(const CSfxHandle& other) { return mID != other.mID; } bool operator!=(const CSfxHandle& other) { return mID != other.mID; }
operator bool() const { return mID != 0; } operator bool() const { return mID != 0; }

View File

@ -587,7 +587,7 @@ KYOTO_2 :=\
$(BUILD_DIR)/src/Kyoto/Input/CDolphinController.o\ $(BUILD_DIR)/src/Kyoto/Input/CDolphinController.o\
$(BUILD_DIR)/asm/Kyoto/DolphinCDvdFile.o\ $(BUILD_DIR)/asm/Kyoto/DolphinCDvdFile.o\
$(BUILD_DIR)/asm/Kyoto/Alloc/CMediumAllocPool.o\ $(BUILD_DIR)/asm/Kyoto/Alloc/CMediumAllocPool.o\
$(BUILD_DIR)/asm/Kyoto/Alloc/CSmallAllocPool.o\ $(BUILD_DIR)/src/Kyoto/Alloc/CSmallAllocPool.o\
$(BUILD_DIR)/asm/Kyoto/Alloc/CGameAllocator.o\ $(BUILD_DIR)/asm/Kyoto/Alloc/CGameAllocator.o\
$(BUILD_DIR)/asm/Kyoto/Animation/DolphinCSkinnedModel.o\ $(BUILD_DIR)/asm/Kyoto/Animation/DolphinCSkinnedModel.o\
$(BUILD_DIR)/asm/Kyoto/Animation/DolphinCSkinRules.o\ $(BUILD_DIR)/asm/Kyoto/Animation/DolphinCSkinRules.o\

View File

@ -14,33 +14,38 @@ CSmallAllocPool::CSmallAllocPool(uint len, void* mainData, void* bookKeeping)
} }
void* CSmallAllocPool::FindFree(int len) { void* CSmallAllocPool::FindFree(int len) {
u8* bookKeepingPtr;
s32 size = (s32)len / 2;
if (xc_cachedBookKeepingOffset == nullptr) { if (xc_cachedBookKeepingOffset == nullptr) {
xc_cachedBookKeepingOffset = x4_bookKeeping; xc_cachedBookKeepingOffset = x4_bookKeeping;
} }
u8* curKeepingOffset = static_cast<u8*>(xc_cachedBookKeepingOffset); u8* curKeepingOffset = static_cast<u8*>(xc_cachedBookKeepingOffset);
u8* bookKeepingPtr = static_cast<u8*>(x4_bookKeeping); bookKeepingPtr = static_cast<u8*>(x4_bookKeeping);
u8* bookKeepingEndPtr = bookKeepingPtr + (x8_numBlocks >> 1); u8* bookKeepingEndPtr = bookKeepingPtr + ((u32)x8_numBlocks >> 1);
u8* curKeepingIter = curKeepingOffset; u8* curKeepingIter = curKeepingOffset;
while(true) { while(true) {
u8* tmpIter = nullptr; u8* iter;
if (static_cast<u8*>(curKeepingIter)[0] != 0 || curKeepingIter == bookKeepingEndPtr) { if (static_cast<u8*>(curKeepingIter)[0] != 0 || curKeepingIter == bookKeepingEndPtr) {
tmpIter = bookKeepingPtr; if (curKeepingIter == bookKeepingEndPtr) {
if (curKeepingIter != bookKeepingEndPtr) { curKeepingIter = bookKeepingPtr;
u32 tmp = static_cast<u8*>(curKeepingIter)[0]; } else {
tmpIter = curKeepingIter + (tmp >> 5); s32 tmp = static_cast<u8*>(curKeepingIter)[0];
s32 reg = tmp >> 4;
curKeepingIter += (reg / 2);
} }
} else { } else {
tmpIter = curKeepingIter; u8* tempIter = curKeepingIter + size;
while (static_cast<u8*>(tmpIter)[0] == 0) { iter = curKeepingIter + 1;
++tmpIter; while (iter != curKeepingOffset && iter != bookKeepingEndPtr && iter != tempIter) {
if (tmpIter == curKeepingOffset || tmpIter == bookKeepingEndPtr || tmpIter == curKeepingIter + (len / 2)) { if (static_cast<u8*>(iter)[0] == 0) {
iter++;
} else {
break; break;
} }
} }
if (tmpIter == curKeepingIter + (len / 2)) { if (iter == curKeepingIter + size) {
if (tmpIter == bookKeepingEndPtr) { if (iter == bookKeepingEndPtr) {
xc_cachedBookKeepingOffset = bookKeepingPtr; xc_cachedBookKeepingOffset = bookKeepingPtr;
} else { } else {
xc_cachedBookKeepingOffset = curKeepingIter; xc_cachedBookKeepingOffset = curKeepingIter;
@ -48,18 +53,19 @@ void* CSmallAllocPool::FindFree(int len) {
return curKeepingIter; return curKeepingIter;
} }
if (tmpIter == curKeepingOffset) { if (iter == curKeepingOffset) {
return nullptr; return nullptr;
} }
if (tmpIter == bookKeepingEndPtr) { if (iter == bookKeepingEndPtr) {
tmpIter = bookKeepingPtr; curKeepingIter = bookKeepingPtr;
} else {
curKeepingIter = iter;
} }
} }
curKeepingIter = tmpIter; if (curKeepingIter == curKeepingOffset) {
if (tmpIter == curKeepingOffset) {
return nullptr; return nullptr;
} }
} };
} }
void* CSmallAllocPool::Alloc(uint size) { void* CSmallAllocPool::Alloc(uint size) {
@ -70,17 +76,14 @@ void* CSmallAllocPool::Alloc(uint size) {
} }
u8* freePtr = static_cast< u8* >(FindFree(len)); u8* freePtr = static_cast< u8* >(FindFree(len));
if (freePtr == NULL) { if (freePtr == nullptr) {
return NULL; return nullptr;
} }
s32 sub = len - 2; s32 sub = len - 2;
s32 blockSize = (sub >> 31) & 1; u8* bufPtr = GetPtrFromIndex(freePtr - static_cast< u8* >(x4_bookKeeping));
blockSize = blockSize + sub;
u8* bookKeepingStart = static_cast<u8*>(x4_bookKeeping);
blockSize >>= 1;
u8* bufPtr = GetPtrFromIndex(freePtr - bookKeepingStart);
*static_cast< u8* >(freePtr) = (len << 4) | 0xf; *static_cast< u8* >(freePtr) = (len << 4) | 0xf;
s32 blockSize = sub / 2;
u8* freePtrIter = freePtr + 1; u8* freePtrIter = freePtr + 1;
while (blockSize--) { while (blockSize--) {
*freePtrIter = 0xff; *freePtrIter = 0xff;
@ -93,7 +96,6 @@ void* CSmallAllocPool::Alloc(uint size) {
return bufPtr; return bufPtr;
} }
bool CSmallAllocPool::Free(const void* arg0) { bool CSmallAllocPool::Free(const void* arg0) {
s32 temp_r8 = GetIndexFromPtr(arg0); s32 temp_r8 = GetIndexFromPtr(arg0);
s32 mask = (temp_r8 & 1) ? 0 : 4; s32 mask = (temp_r8 & 1) ? 0 : 4;