diff --git a/Runtime/GuiSys/CGuiTextSupport.hpp b/Runtime/GuiSys/CGuiTextSupport.hpp index 02dc0b22e..34254908a 100644 --- a/Runtime/GuiSys/CGuiTextSupport.hpp +++ b/Runtime/GuiSys/CGuiTextSupport.hpp @@ -78,6 +78,8 @@ class CGuiTextSupport { zeus::CColor x28_outlineColor; zeus::CColor x2c_geometryColor; bool x30_imageBaseline = false; + s32 x30_; // new in PAL/JP + s32 x34_; // "" s32 x34_extentX; s32 x38_extentY; float x3c_curTime = 0.f; diff --git a/Runtime/Memory/CCircularBuffer.cpp b/Runtime/Memory/CCircularBuffer.cpp new file mode 100644 index 000000000..4f000ee76 --- /dev/null +++ b/Runtime/Memory/CCircularBuffer.cpp @@ -0,0 +1,57 @@ +#include "Runtime/Memory/CCircularBuffer.hpp" + +namespace metaforce { +CCircularBuffer::CCircularBuffer(void* buf, s32 len, EOwnership ownership) +: x0_canDelete(buf != nullptr), x4_ptr(reinterpret_cast(buf)), x8_bufferLen(len) { + if (ownership == EOwnership::Owned) + x0_canDelete = false; +} +CCircularBuffer::~CCircularBuffer() { + if (x0_canDelete) { + delete x4_ptr; + } +} + +s32 CCircularBuffer::GetAllocatedAmount() const { + s32 res = x10_nextFreeAddr - xc_; + return (x14_ == -1) ? res : res + (x8_bufferLen - x14_); +} + +bool CCircularBuffer::IsWrappedMemory(s32 offset, s32 len) { + return x14_ > -1 && x14_ >= offset && (x14_ < (offset + len)); +} + +void* CCircularBuffer::Alloc(s32 len) { + if ((x8_bufferLen - x10_nextFreeAddr) >= len && !IsWrappedMemory(x10_nextFreeAddr, len)) { + s32 offset = x10_nextFreeAddr; + x10_nextFreeAddr = offset + len; + return x4_ptr + offset; + } else if (xc_ >= len && !IsWrappedMemory(0, len)) { + u32 r3 = xc_; + xc_ = 0; + x10_nextFreeAddr = len; + x14_ = r3; + return x4_ptr; + } + + return nullptr; +} + +void CCircularBuffer::Free(void* ptr, s32 r5) { + if (x14_ <= -1) { + xc_ += r5; + } else if (ptr == x4_ptr) { + x14_ = -1; + xc_ = r5; + } else { + x14_ += r5; + } + + if (x14_ != -1 || xc_ != x10_nextFreeAddr) { + return; + } + + x10_nextFreeAddr = 0; + xc_ = 0; +} +} // namespace metaforce diff --git a/Runtime/Memory/CCircularBuffer.hpp b/Runtime/Memory/CCircularBuffer.hpp new file mode 100644 index 000000000..b177d6585 --- /dev/null +++ b/Runtime/Memory/CCircularBuffer.hpp @@ -0,0 +1,25 @@ +#pragma once +#include "Runtime/GCNTypes.hpp" + +namespace metaforce { +class CCircularBuffer { +public: + enum class EOwnership { Unowned, Owned }; + +private: + bool x0_canDelete; + u8* x4_ptr; + s32 x8_bufferLen; + s32 xc_ = 0; + s32 x10_nextFreeAddr = 0; + s32 x14_ = -1; + +public: + CCircularBuffer(void* buf, s32 len, EOwnership ownership = EOwnership::Owned); + ~CCircularBuffer(); + s32 GetAllocatedAmount() const; + bool IsWrappedMemory(s32 offset, s32 len); + void* Alloc(s32 len); + void Free(void* ptr, s32 r5); +}; +} // namespace metaforce \ No newline at end of file