diff --git a/Makefile b/Makefile index ef6a832d..5fa6d4a7 100644 --- a/Makefile +++ b/Makefile @@ -130,7 +130,7 @@ $(METROTRK_FILES): MWCC_VERSION := 1.2.5 $(METROTRK_FILES): CFLAGS := $(CFLAGS_BASE) $(BASE_FILES): MWCC_VERSION := 1.2.5 $(BASE_FILES): CFLAGS := $(CFLAGS_BASE) -$(AI_FILES): MWCC_VERSION := 1.2.5e +$(AI_FILES): MWCC_VERSION := 1.2.5 $(AI_FILES): CFLAGS := $(CFLAGS_BASE) $(OS_FILES): MWCC_VERSION := 1.2.5 $(OS_FILES): CFLAGS := $(CFLAGS_BASE) diff --git a/asm/Kyoto/Audio/CSfxHandle.s b/asm/Kyoto/Audio/CSfxHandle.s index ce2d460f..1b91bbe4 100644 --- a/asm/Kyoto/Audio/CSfxHandle.s +++ b/asm/Kyoto/Audio/CSfxHandle.s @@ -5,7 +5,7 @@ .global mRefCount__10CSfxHandle mRefCount__10CSfxHandle: - .skip 0x8 + .skip 0x4 .section .text, "ax" diff --git a/include/Kyoto/Audio/CSfxHandle.hpp b/include/Kyoto/Audio/CSfxHandle.hpp index 363b9322..3431b46e 100644 --- a/include/Kyoto/Audio/CSfxHandle.hpp +++ b/include/Kyoto/Audio/CSfxHandle.hpp @@ -9,8 +9,8 @@ public: CSfxHandle(uint value); uint GetIndex() const { return mID & 0xFFF; } - static NullHandle() { return CSfxHandle(); } - bool operator=(const CSfxHandle& other) { mID = other.mID; } + static CSfxHandle NullHandle() { return CSfxHandle(); } + 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; } operator bool() const { return mID != 0; } diff --git a/obj_files.mk b/obj_files.mk index 46a246b1..4fcd42ce 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -587,7 +587,7 @@ KYOTO_2 :=\ $(BUILD_DIR)/src/Kyoto/Input/CDolphinController.o\ $(BUILD_DIR)/asm/Kyoto/DolphinCDvdFile.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/Animation/DolphinCSkinnedModel.o\ $(BUILD_DIR)/asm/Kyoto/Animation/DolphinCSkinRules.o\ diff --git a/src/Kyoto/Alloc/CSmallAllocPool.cpp b/src/Kyoto/Alloc/CSmallAllocPool.cpp index 7f2cbb7f..5cb2d047 100644 --- a/src/Kyoto/Alloc/CSmallAllocPool.cpp +++ b/src/Kyoto/Alloc/CSmallAllocPool.cpp @@ -14,33 +14,38 @@ CSmallAllocPool::CSmallAllocPool(uint len, void* mainData, void* bookKeeping) } void* CSmallAllocPool::FindFree(int len) { + u8* bookKeepingPtr; + s32 size = (s32)len / 2; if (xc_cachedBookKeepingOffset == nullptr) { xc_cachedBookKeepingOffset = x4_bookKeeping; } - u8* curKeepingOffset = static_cast(xc_cachedBookKeepingOffset); - u8* bookKeepingPtr = static_cast(x4_bookKeeping); - u8* bookKeepingEndPtr = bookKeepingPtr + (x8_numBlocks >> 1); + bookKeepingPtr = static_cast(x4_bookKeeping); + u8* bookKeepingEndPtr = bookKeepingPtr + ((u32)x8_numBlocks >> 1); u8* curKeepingIter = curKeepingOffset; - while (true) { - u8* tmpIter = nullptr; - if (static_cast(curKeepingIter)[0] != 0 || curKeepingIter == bookKeepingEndPtr){ - tmpIter = bookKeepingPtr; - if (curKeepingIter != bookKeepingEndPtr) { - u32 tmp = static_cast(curKeepingIter)[0]; - tmpIter = curKeepingIter + (tmp >> 5); + while(true) { + u8* iter; + if (static_cast(curKeepingIter)[0] != 0 || curKeepingIter == bookKeepingEndPtr) { + if (curKeepingIter == bookKeepingEndPtr) { + curKeepingIter = bookKeepingPtr; + } else { + s32 tmp = static_cast(curKeepingIter)[0]; + s32 reg = tmp >> 4; + curKeepingIter += (reg / 2); } } else { - tmpIter = curKeepingIter; - while (static_cast(tmpIter)[0] == 0) { - ++tmpIter; - if (tmpIter == curKeepingOffset || tmpIter == bookKeepingEndPtr || tmpIter == curKeepingIter + (len / 2)) { - break; + u8* tempIter = curKeepingIter + size; + iter = curKeepingIter + 1; + while (iter != curKeepingOffset && iter != bookKeepingEndPtr && iter != tempIter) { + if (static_cast(iter)[0] == 0) { + iter++; + } else { + break; + } } - } - if (tmpIter == curKeepingIter + (len / 2)) { - if (tmpIter == bookKeepingEndPtr) { + if (iter == curKeepingIter + size) { + if (iter == bookKeepingEndPtr) { xc_cachedBookKeepingOffset = bookKeepingPtr; } else { xc_cachedBookKeepingOffset = curKeepingIter; @@ -48,71 +53,68 @@ void* CSmallAllocPool::FindFree(int len) { return curKeepingIter; } - if (tmpIter == curKeepingOffset) { + if (iter == curKeepingOffset) { return nullptr; } - if (tmpIter == bookKeepingEndPtr) { - tmpIter = bookKeepingPtr; + if (iter == bookKeepingEndPtr) { + curKeepingIter = bookKeepingPtr; + } else { + curKeepingIter = iter; } } - curKeepingIter = tmpIter; - if (tmpIter == curKeepingOffset) { + if (curKeepingIter == curKeepingOffset) { return nullptr; } - } + }; } void* CSmallAllocPool::Alloc(uint size) { - u32 len = size >= 4 ? len = (size + 3) / 4 : 1; + u32 len = size >= 4 ? len = (size + 3) / 4 : 1; - if ((len & 1) != 0) { - len += 1; - } + if ((len & 1) != 0) { + len += 1; + } - u8* freePtr = static_cast(FindFree(len)); - if (freePtr == NULL) { - return NULL; - } + u8* freePtr = static_cast< u8* >(FindFree(len)); + if (freePtr == nullptr) { + return nullptr; + } - s32 sub = len - 2; - s32 blockSize = (sub >> 31) & 1; - blockSize = blockSize + sub; - u8* bookKeepingStart = static_cast(x4_bookKeeping); - blockSize >>= 1; - u8* bufPtr = GetPtrFromIndex(freePtr - bookKeepingStart); - *static_cast(freePtr) = (len << 4) | 0xf; - u8* freePtrIter = freePtr + 1; - while(blockSize--) { - *freePtrIter = 0xff; - ++freePtrIter; - } + s32 sub = len - 2; + u8* bufPtr = GetPtrFromIndex(freePtr - static_cast< u8* >(x4_bookKeeping)); + *static_cast< u8* >(freePtr) = (len << 4) | 0xf; + s32 blockSize = sub / 2; + u8* freePtrIter = freePtr + 1; + while (blockSize--) { + *freePtrIter = 0xff; + ++freePtrIter; + } - x18_numBlocksAvailable -= len; - ++x1c_numAllocs; + x18_numBlocksAvailable -= len; + ++x1c_numAllocs; - return bufPtr; + return bufPtr; } - bool CSmallAllocPool::Free(const void* arg0) { - s32 temp_r8 = GetIndexFromPtr(arg0); - s32 mask = (temp_r8 & 1) ? 0 : 4; - u32 temp_r9 = (u32)temp_r8 / 2; - s32 temp_r4_2 = GetEntryValue(temp_r9); - temp_r4_2 = (temp_r4_2 >> mask) & 0xF; - x18_numBlocksAvailable += temp_r4_2; - s32 var_r5 = temp_r4_2; - x1c_numAllocs -= 1; - x14_ = temp_r8; - if ((u32) temp_r8 == (u32) x10_) { - x10_ = -1; - } + s32 temp_r8 = GetIndexFromPtr(arg0); + s32 mask = (temp_r8 & 1) ? 0 : 4; + u32 temp_r9 = (u32)temp_r8 / 2; + s32 temp_r4_2 = GetEntryValue(temp_r9); + temp_r4_2 = (temp_r4_2 >> mask) & 0xF; + x18_numBlocksAvailable += temp_r4_2; + s32 var_r5 = temp_r4_2; + x1c_numAllocs -= 1; + x14_ = temp_r8; + if ((u32)temp_r8 == (u32)x10_) { + x10_ = -1; + } - u8* var_r3 = ((u8*)x4_bookKeeping) + temp_r9; - while (var_r5 != 0) { - *var_r3 = 0; - var_r5 -= 2; - ++var_r3; - } - return 1; + u8* var_r3 = ((u8*)x4_bookKeeping) + temp_r9; + while (var_r5 != 0) { + *var_r3 = 0; + var_r5 -= 2; + ++var_r3; + } + return 1; }