mirror of
https://github.com/zeldaret/tww.git
synced 2026-07-09 06:03:22 -04:00
JAISequenceHeap
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#ifndef JAISEQUENCEHEAP_H
|
||||
#define JAISEQUENCEHEAP_H
|
||||
|
||||
#include "dolphin/types.h"
|
||||
|
||||
namespace JAInter {
|
||||
class HeapBlock {
|
||||
public:
|
||||
HeapBlock();
|
||||
|
||||
u8 getStatus() { return mStatus; }
|
||||
void setStatus(u8 status) { mStatus = status; }
|
||||
void* getPointer() { return mPointer; }
|
||||
void setPointer(void* pointer) { mPointer = pointer; }
|
||||
// TODO
|
||||
u32 getUseCounter() {}
|
||||
void setUseCounter(u32) {}
|
||||
u32 getDataNumber() {}
|
||||
void setDataNumber(u32) {}
|
||||
u32 getEndAddress() {}
|
||||
void setEndAddress(u32) {}
|
||||
|
||||
/* 0x00 */ u8 mStatus;
|
||||
/* 0x04 */ void* mPointer;
|
||||
/* 0x08 */ u32 field_0x8;
|
||||
/* 0x0C */ u32 field_0xc;
|
||||
/* 0x10 */ u32 field_0x10;
|
||||
};
|
||||
|
||||
namespace HeapMgr {
|
||||
void init(u8, u32, u8, u32);
|
||||
JAInter::HeapBlock* getAutoHeapPointer();
|
||||
void* checkOnMemory(u32, u8*);
|
||||
void releaseAutoHeapPointer(u8);
|
||||
u8 checkUsefulAutoHeapPosition();
|
||||
void* getFreeAutoHeapPointer(u8, u32);
|
||||
void* getFreeStayHeapPointer(u32, u32);
|
||||
void setAutoHeapLoadedFlag(u8, u8);
|
||||
|
||||
extern HeapBlock* sAutoHeap;
|
||||
extern HeapBlock* sStayHeap;
|
||||
extern u32 sAutoHeapCount;
|
||||
extern u32 sStayHeapCount;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* JAISEQUENCEHEAP_H */
|
||||
@@ -4,49 +4,145 @@
|
||||
//
|
||||
|
||||
#include "JSystem/JAudio/JAISequenceHeap.h"
|
||||
#include "dolphin/types.h"
|
||||
#include "JSystem/JAudio/JAIBasic.h"
|
||||
#include "JSystem/JAudio/JAIGlobalParameter.h"
|
||||
#include "JSystem/JKernel/JKRSolidHeap.h"
|
||||
|
||||
JAInter::HeapBlock* JAInter::HeapMgr::sAutoHeap;
|
||||
JAInter::HeapBlock* JAInter::HeapMgr::sStayHeap;
|
||||
u32 JAInter::HeapMgr::sAutoHeapCount;
|
||||
u32 JAInter::HeapMgr::sStayHeapCount;
|
||||
|
||||
/* 80294F5C-8029531C .text init__Q27JAInter7HeapMgrFUcUlUcUl */
|
||||
void JAInter::HeapMgr::init(unsigned char, unsigned long, unsigned char, unsigned long) {
|
||||
/* Nonmatching */
|
||||
void JAInter::HeapMgr::init(u8 param_1, u32 param_2, u8 param_3, u32 param_4) {
|
||||
sAutoHeap = new (JAIBasic::getCurrentJAIHeap(), 0x20) HeapBlock[param_3];
|
||||
JUT_ASSERT_MSG(38, sAutoHeap, "JAIHeapMgr::initHeap Cannot Alloc Heap!!\n");
|
||||
for (u32 i = 0; i < param_3; i++) {
|
||||
sAutoHeap[i].mStatus = 0;
|
||||
sAutoHeap[i].field_0xc = 0;
|
||||
sAutoHeap[i].field_0x8 = -1;
|
||||
sAutoHeap[i].field_0x10 = -1;
|
||||
sAutoHeap[i].mPointer = new (JAIBasic::getCurrentJAIHeap(), 0x20) u8[param_4];
|
||||
}
|
||||
sStayHeap = new (JAIBasic::getCurrentJAIHeap(), 0x20) HeapBlock[param_1];
|
||||
JUT_ASSERT_MSG(48, sStayHeap, "JAIHeapMgr::initHeap Cannot Alloc Heap!!\n");
|
||||
sStayHeap->mPointer = new (JAIBasic::getCurrentJAIHeap(), 0x20) u8[param_2];
|
||||
for (u32 i = 0; i < param_1; i++) {
|
||||
sStayHeap[i].mStatus = 0;
|
||||
sStayHeap[i].field_0xc = 0;
|
||||
sStayHeap[i].field_0x8 = -1;
|
||||
sStayHeap[i].field_0x10 = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 8029531C-80295324 .text getAutoHeapPointer__Q27JAInter7HeapMgrFv */
|
||||
void JAInter::HeapMgr::getAutoHeapPointer() {
|
||||
/* Nonmatching */
|
||||
JAInter::HeapBlock* JAInter::HeapMgr::getAutoHeapPointer() {
|
||||
return sAutoHeap;
|
||||
}
|
||||
|
||||
/* 80295324-8029541C .text checkOnMemory__Q27JAInter7HeapMgrFUlPUc */
|
||||
void JAInter::HeapMgr::checkOnMemory(unsigned long, unsigned char*) {
|
||||
/* Nonmatching */
|
||||
void* JAInter::HeapMgr::checkOnMemory(u32 param_1, u8* param_2) {
|
||||
for (u8 i = 0; i < JAIGlobalParameter::getParamAutoHeapMax(); i++) {
|
||||
if (param_1 != sAutoHeap[i].field_0x8) {
|
||||
continue;
|
||||
}
|
||||
if (sAutoHeap[i].mStatus == 1) {
|
||||
return (void*)-1;
|
||||
}
|
||||
if (param_2) {
|
||||
*param_2 = i;
|
||||
}
|
||||
return sAutoHeap[i].getPointer();
|
||||
}
|
||||
for (u8 i = 0; i < sStayHeapCount; i++) {
|
||||
if (param_1 != sStayHeap[i].field_0x8) {
|
||||
continue;
|
||||
}
|
||||
if (param_2) {
|
||||
*param_2 = 0xff;
|
||||
}
|
||||
return sStayHeap[i].getPointer();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 8029541C-80295440 .text releaseAutoHeapPointer__Q27JAInter7HeapMgrFUc */
|
||||
void JAInter::HeapMgr::releaseAutoHeapPointer(unsigned char) {
|
||||
void JAInter::HeapMgr::releaseAutoHeapPointer(u8 param_1) {
|
||||
/* Nonmatching */
|
||||
if (param_1 == 0xff) {
|
||||
return;
|
||||
}
|
||||
sAutoHeap[param_1].field_0x10 = -1;
|
||||
}
|
||||
|
||||
/* 80295440-80295518 .text checkUsefulAutoHeapPosition__Q27JAInter7HeapMgrFv */
|
||||
void JAInter::HeapMgr::checkUsefulAutoHeapPosition() {
|
||||
/* Nonmatching */
|
||||
u8 JAInter::HeapMgr::checkUsefulAutoHeapPosition() {
|
||||
int i = 0;
|
||||
u32 r29 = -1;
|
||||
int r28 = 0;
|
||||
for (; i < JAIGlobalParameter::getParamAutoHeapMax(); i++) {
|
||||
if (sAutoHeap[i].field_0x8 == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == JAIGlobalParameter::getParamAutoHeapMax()) {
|
||||
for (i = 0; i < JAIGlobalParameter::getParamAutoHeapMax(); i++) {
|
||||
if (r29 > sAutoHeap[i].field_0xc && sAutoHeap[i].field_0x10 == -1) {
|
||||
r28 = i;
|
||||
r29 = sAutoHeap[i].field_0xc;
|
||||
}
|
||||
}
|
||||
if (r29 != -1) {
|
||||
i = r28;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/* 80295518-80295560 .text getFreeAutoHeapPointer__Q27JAInter7HeapMgrFUcUl */
|
||||
void JAInter::HeapMgr::getFreeAutoHeapPointer(unsigned char, unsigned long) {
|
||||
void* JAInter::HeapMgr::getFreeAutoHeapPointer(u8 param_1, u32 param_2) {
|
||||
/* Nonmatching */
|
||||
sAutoHeap[param_1].field_0x8 = param_2;
|
||||
void* result = sAutoHeap[param_1].mPointer;
|
||||
sAutoHeap[param_1].field_0x10 = sAutoHeapCount;
|
||||
sAutoHeap[param_1].field_0xc = sAutoHeapCount;
|
||||
sAutoHeapCount++;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* 80295560-80295658 .text getFreeStayHeapPointer__Q27JAInter7HeapMgrFUlUl */
|
||||
void JAInter::HeapMgr::getFreeStayHeapPointer(unsigned long, unsigned long) {
|
||||
void* JAInter::HeapMgr::getFreeStayHeapPointer(u32 param_1, u32 param_2) {
|
||||
/* Nonmatching */
|
||||
if (sStayHeapCount >= JAIGlobalParameter::getParamStayHeapMax()) {
|
||||
return NULL;
|
||||
}
|
||||
void* r30 = sStayHeap[0].getPointer();
|
||||
void* r29 = sStayHeap[sStayHeapCount].getPointer();
|
||||
if (u32(r29) + param_1 < u32(r30) + JAIGlobalParameter::getParamStayHeapSize() && sStayHeapCount < JAIGlobalParameter::getParamStayHeapMax()) {
|
||||
r29 = sStayHeap[sStayHeapCount].getPointer();
|
||||
sStayHeap[sStayHeapCount].field_0x8 = param_2;
|
||||
r30 = (void*)(u32(sStayHeap[sStayHeapCount].getPointer()) + ALIGN_PREV(param_1, 32));
|
||||
if (IS_NOT_ALIGNED(param_1, 32)) {
|
||||
r30 = (void*)(u32(r30) + 32);
|
||||
}
|
||||
sStayHeapCount++;
|
||||
if (sStayHeapCount < JAIGlobalParameter::getParamStayHeapMax()) {
|
||||
sStayHeap[sStayHeapCount].setPointer(r30);
|
||||
}
|
||||
} else {
|
||||
r29 = NULL;
|
||||
}
|
||||
return r29;
|
||||
}
|
||||
|
||||
/* 80295658-8029566C .text setAutoHeapLoadedFlag__Q27JAInter7HeapMgrFUcUc */
|
||||
void JAInter::HeapMgr::setAutoHeapLoadedFlag(unsigned char, unsigned char) {
|
||||
/* Nonmatching */
|
||||
void JAInter::HeapMgr::setAutoHeapLoadedFlag(u8 param_1, u8 param_2) {
|
||||
sAutoHeap[param_1].setStatus(param_2);
|
||||
}
|
||||
|
||||
/* 8029566C-80295684 .text __ct__Q27JAInter9HeapBlockFv */
|
||||
JAInter::HeapBlock::HeapBlock() {
|
||||
/* Nonmatching */
|
||||
field_0xc = 0;
|
||||
field_0x8 = -1;
|
||||
field_0x10 = -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user