mirror of
https://github.com/SMGCommunity/Petari.git
synced 2024-11-24 14:09:51 +00:00
progress on some MemoryUtil functions
This commit is contained in:
parent
f0a7a9aceb
commit
fd1b6e9af3
16
csv/Util.csv
16
csv/Util.csv
@ -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,
|
||||
|
|
@ -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"
|
||||
|
@ -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;
|
||||
};
|
||||
};
|
13
include/Game/Util/MutexHolder.h
Normal file
13
include/Game/Util/MutexHolder.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "revolution.h"
|
||||
|
||||
class JKRHeap;
|
||||
|
||||
namespace MR {
|
||||
template<int T>
|
||||
class MutexHolder {
|
||||
public:
|
||||
static OSMutex sMutex;
|
||||
};
|
||||
};
|
16
include/JSystem/JKernel/JKRHeap.h
Normal file
16
include/JSystem/JKernel/JKRHeap.h
Normal 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;
|
||||
};
|
@ -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
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user