progress on some MemoryUtil functions

This commit is contained in:
shibbo 2021-10-18 23:37:08 -04:00
parent f0a7a9aceb
commit fd1b6e9af3
6 changed files with 137 additions and 9 deletions

View File

@ -2072,12 +2072,12 @@ fixed16ToFloat__2MRFPQ29JGeometry8TVec3<f>RCQ29JGeometry8TVec3<s>Uc,MathUtil.o,U
getRotatedAxisY__2MRFPQ29JGeometry8TVec3<f>RCQ29JGeometry8TVec3<f>,MathUtil.o,Util.a,false,
getRotatedAxisZ__2MRFPQ29JGeometry8TVec3<f>RCQ29JGeometry8TVec3<f>,MathUtil.o,Util.a,false,
JMASqrt__Ff,MathUtil.o,Util.a,false,
__ct__Q22MR19CurrentHeapRestorerFP7JKRHeap,MemoryUtil.o,Util.a,false,
__dt__Q22MR19CurrentHeapRestorerFv,MemoryUtil.o,Util.a,false,
alloc__Q22MR18NewDeleteAllocatorFP12MEMAllocatorUl,MemoryUtil.o,Util.a,false,
free__Q22MR18NewDeleteAllocatorFP12MEMAllocatorPv,MemoryUtil.o,Util.a,false,
__ct__Q22MR19CurrentHeapRestorerFP7JKRHeap,MemoryUtil.o,Util.a,true,shibboleet
__dt__Q22MR19CurrentHeapRestorerFv,MemoryUtil.o,Util.a,true,shibboleet
alloc__Q22MR18NewDeleteAllocatorFP12MEMAllocatorUl,MemoryUtil.o,Util.a,true,shibboleet
free__Q22MR18NewDeleteAllocatorFP12MEMAllocatorPv,MemoryUtil.o,Util.a,true,shibboleet
getHomeButtonLayoutAllocator__2MRFv,MemoryUtil.o,Util.a,false,
getCurrentHeap__2MRFv,MemoryUtil.o,Util.a,false,
getCurrentHeap__2MRFv,MemoryUtil.o,Util.a,true,shibboleet
getAproposHeapForSceneArchive__2MRFf,MemoryUtil.o,Util.a,false,
getStationedHeapNapa__2MRFv,MemoryUtil.o,Util.a,false,
getStationedHeapGDDR3__2MRFv,MemoryUtil.o,Util.a,false,
@ -2085,11 +2085,11 @@ getSceneHeapNapa__2MRFv,MemoryUtil.o,Util.a,false,
getSceneHeapGDDR3__2MRFv,MemoryUtil.o,Util.a,false,
getHeapNapa__2MRFPC7JKRHeap,MemoryUtil.o,Util.a,false,
getHeapGDDR3__2MRFPC7JKRHeap,MemoryUtil.o,Util.a,false,
becomeCurrentHeap__2MRFP7JKRHeap,MemoryUtil.o,Util.a,false,
isEqualCurrentHeap__2MRFP7JKRHeap,MemoryUtil.o,Util.a,false,
becomeCurrentHeap__2MRFP7JKRHeap,MemoryUtil.o,Util.a,true,shibboleet
isEqualCurrentHeap__2MRFP7JKRHeap,MemoryUtil.o,Util.a,true,shibboleet
adjustHeapSize__2MRFP10JKRExpHeapPCc,MemoryUtil.o,Util.a,false,
copyMemory__2MRFPvPCvUl,MemoryUtil.o,Util.a,false,
fillMemory__2MRFPvUcUl,MemoryUtil.o,Util.a,false,
fillMemory__2MRFPvUcUl,MemoryUtil.o,Util.a,true,shibboleet
zeroMemory__2MRFPvUl,MemoryUtil.o,Util.a,false,
calcCheckSum__2MRFPCvUl,MemoryUtil.o,Util.a,false,
allocFromWPadHeap__2MRFUl,MemoryUtil.o,Util.a,false,

1 Symbol Name Object File Library Archive Matching Author
2072 getRotatedAxisY__2MRFPQ29JGeometry8TVec3<f>RCQ29JGeometry8TVec3<f> MathUtil.o Util.a false
2073 getRotatedAxisZ__2MRFPQ29JGeometry8TVec3<f>RCQ29JGeometry8TVec3<f> MathUtil.o Util.a false
2074 JMASqrt__Ff MathUtil.o Util.a false
2075 __ct__Q22MR19CurrentHeapRestorerFP7JKRHeap MemoryUtil.o Util.a false true shibboleet
2076 __dt__Q22MR19CurrentHeapRestorerFv MemoryUtil.o Util.a false true shibboleet
2077 alloc__Q22MR18NewDeleteAllocatorFP12MEMAllocatorUl MemoryUtil.o Util.a false true shibboleet
2078 free__Q22MR18NewDeleteAllocatorFP12MEMAllocatorPv MemoryUtil.o Util.a false true shibboleet
2079 getHomeButtonLayoutAllocator__2MRFv MemoryUtil.o Util.a false
2080 getCurrentHeap__2MRFv MemoryUtil.o Util.a false true shibboleet
2081 getAproposHeapForSceneArchive__2MRFf MemoryUtil.o Util.a false
2082 getStationedHeapNapa__2MRFv MemoryUtil.o Util.a false
2083 getStationedHeapGDDR3__2MRFv MemoryUtil.o Util.a false
2085 getSceneHeapGDDR3__2MRFv MemoryUtil.o Util.a false
2086 getHeapNapa__2MRFPC7JKRHeap MemoryUtil.o Util.a false
2087 getHeapGDDR3__2MRFPC7JKRHeap MemoryUtil.o Util.a false
2088 becomeCurrentHeap__2MRFP7JKRHeap MemoryUtil.o Util.a false true shibboleet
2089 isEqualCurrentHeap__2MRFP7JKRHeap MemoryUtil.o Util.a false true shibboleet
2090 adjustHeapSize__2MRFP10JKRExpHeapPCc MemoryUtil.o Util.a false
2091 copyMemory__2MRFPvPCvUl MemoryUtil.o Util.a false
2092 fillMemory__2MRFPvUcUl MemoryUtil.o Util.a false true shibboleet
2093 zeroMemory__2MRFPvUl MemoryUtil.o Util.a false
2094 calcCheckSum__2MRFPCvUl MemoryUtil.o Util.a false
2095 allocFromWPadHeap__2MRFUl MemoryUtil.o Util.a false

View File

@ -15,6 +15,7 @@
#include "Game/Util/MathUtil.h"
#include "Game/Util/MemoryUtil.h"
#include "Game/Util/MtxUtil.h"
#include "Game/Util/MutexHolder.h"
#include "Game/Util/ObjUtil.h"
#include "Game/Util/PlayerUtil.h"
#include "Game/Util/SceneUtil.h"

View File

@ -1,10 +1,46 @@
#pragma once
#include <revolution.h>
#include <revolution/mem.h>
#include "JSystem/JKernel/JKRHeap.h"
class JKRHeap;
namespace MR {
void becomeCurrentHeap(JKRHeap *);
JKRHeap* getCurrentHeap();
bool isEqualCurrentHeap(JKRHeap *);
void copyMemory(void *, const void *, u32);
void fillMemory(void *, u8, u32);
void fillMemory(void *, u8, size_t);
void zeroMemory(void *, u32);
s32 calcCheckSum(const void *, u32);
class CurrentHeapRestorer {
public:
CurrentHeapRestorer(JKRHeap *);
~CurrentHeapRestorer();
JKRHeap* _0;
};
class NewDeleteAllocator {
public:
static void* alloc(MEMAllocator *, u32);
static void free(MEMAllocator *, void *);
};
template<int T>
class JKRHeapAllocator {
public:
static void* alloc(MEMAllocator *pAllocator, u32 size) {
return JKRHeapAllocator<T>::sHeap->alloc(size, 0);
}
static void free(MEMAllocator *pAllocator, void *pData) {
JKRHeapAllocator<T>::sHeap->free(pData);
}
static JKRHeap* sHeap;
};
};

View File

@ -0,0 +1,13 @@
#pragma once
#include "revolution.h"
class JKRHeap;
namespace MR {
template<int T>
class MutexHolder {
public:
static OSMutex sMutex;
};
};

View File

@ -0,0 +1,16 @@
#pragma once
#include<revolution.h>
// this inherits JKRDisposer
class JKRHeap {
public:
void* alloc(u32, int);
void becomeCurrentHeap();
void free(void *);
static JKRHeap* sCurrentHeap;
static JKRHeap* sRootHeap;
};

View File

@ -1,4 +1,6 @@
#include "Game/Util.h"
#include <stdio.h>
#include <string.h>
namespace MR {
#ifdef NON_MATCHING
@ -17,4 +19,64 @@ namespace MR {
return (v3 << 16) | v2;
}
#endif
CurrentHeapRestorer::CurrentHeapRestorer(JKRHeap *pHeap) {
_0 = JKRHeap::sCurrentHeap;
OSLockMutex(&MR::MutexHolder<1>::sMutex);
MR::becomeCurrentHeap(pHeap);
}
CurrentHeapRestorer::~CurrentHeapRestorer() {
MR::becomeCurrentHeap(_0);
OSUnlockMutex(&MR::MutexHolder<1>::sMutex);
}
void* NewDeleteAllocator::alloc(MEMAllocator *pAllocator, u32 size) {
return new u8[size];
}
void NewDeleteAllocator::free(MEMAllocator *pAllocator, void *pData) {
delete[] (u8*)pData;
}
// MR::getHomeButtonLayoutAllocator
JKRHeap* getCurrentHeap() {
return JKRHeap::sCurrentHeap;
}
// MR::getAproposHeapForSceneArchive
// MR::getStationedHeapNapa
// MR::getStationedHeapGDDR3
// MR::getSceneHeapNapa
// MR::getSceneHeapGDDR3
// MR::getHeapNapa
// MR::getHeapGDDR3
void becomeCurrentHeap(JKRHeap *pHeap) {
OSLockMutex(&MR::MutexHolder<1>::sMutex);
pHeap->becomeCurrentHeap();
OSUnlockMutex(&MR::MutexHolder<1>::sMutex);
}
bool isEqualCurrentHeap(JKRHeap *pHeap) {
return pHeap == JKRHeap::sCurrentHeap;
}
// MR::adjustHeapSize
// MR::copyMemory
void fillMemory(void *pDest, u8 a2, size_t size) {
if (a2 == 0) {
MR::zeroMemory(pDest, size);
}
else {
memset(pDest, a2, size);
}
}
// MR::zeroMemory
// MR::calcCheckSum
// MR::allocFromWPadHeap
// MR::freeFromWPadHeap
};