Added Memory H and C, thanks @Mc-muffin

This commit is contained in:
2026-09-02 23:07:29 -05:00
committed by Timothy O'Barr
parent f66b4d170e
commit 5af2fc0015
4 changed files with 631 additions and 39 deletions
+2 -2
View File
@@ -254,7 +254,7 @@ segments:
- [0x047A20, asmtu, cs4/Seimei/fslib/lib/fslibsd] - [0x047A20, asmtu, cs4/Seimei/fslib/lib/fslibsd]
- [0x0484C0, asmtu, cs4/Seimei/fslib/lib/fslibsdsynth] - [0x0484C0, asmtu, cs4/Seimei/fslib/lib/fslibsdsynth]
- [0x04AA50, asmtu, cs4/Seimei/fslib/lib/fslibvu0] - [0x04AA50, asmtu, cs4/Seimei/fslib/lib/fslibvu0]
- [0x04ABC0, asmtu, cs4/Seimei/src/Memory] - [0x04ABC0, c, cs4/Seimei/src/Memory]
- [0x04B150, asmtu, cs4/Seimei/src/Map] - [0x04B150, asmtu, cs4/Seimei/src/Map]
- [0x04FBC0, asmtu, cs4/Seimei/src/String] - [0x04FBC0, asmtu, cs4/Seimei/src/String]
- [0x04FD50, asmtu, cs4/Seimei/src/My] - [0x04FD50, asmtu, cs4/Seimei/src/My]
@@ -269,7 +269,7 @@ segments:
- [0x059C60, asmtu, cs4/Seimei/src/Dss] - [0x059C60, asmtu, cs4/Seimei/src/Dss]
- [0x05ACB0, asmtu, cs4/Seimei/src/Damage] - [0x05ACB0, asmtu, cs4/Seimei/src/Damage]
- [0x05B3B0, asmtu, cs4/Seimei/src/Hmd] - [0x05B3B0, asmtu, cs4/Seimei/src/Hmd]
- [0x05E360, asmtu, cs4/Seimei/src/Binder] - [0x05E360, c, cs4/Seimei/src/Binder]
- [0x05E980, asmtu, cs4/Seimei/src/Ene] - [0x05E980, asmtu, cs4/Seimei/src/Ene]
- [0x060DF0, asmtu, cs4/Seimei/src/EneAct] - [0x060DF0, asmtu, cs4/Seimei/src/EneAct]
- [0x062F40, asmtu, cs4/Seimei/src/EneThk] - [0x062F40, asmtu, cs4/Seimei/src/EneThk]
+56 -28
View File
@@ -1,21 +1,21 @@
{ {
"measures": { "measures": {
"fuzzy_match_percent": 1.1858957, "fuzzy_match_percent": 1.3313618,
"total_code": "956924", "total_code": "956924",
"matched_code": "10556", "matched_code": "11948",
"matched_code_percent": 1.1031178, "matched_code_percent": 1.248584,
"total_data": "8579152", "total_data": "8579152",
"matched_data": "453732", "matched_data": "511092",
"matched_data_percent": 5.2887745, "matched_data_percent": 5.957372,
"total_functions": 2901, "total_functions": 2901,
"matched_functions": 49, "matched_functions": 56,
"matched_functions_percent": 1.6890727, "matched_functions_percent": 1.9303689,
"complete_code": "6052", "complete_code": "8980",
"complete_code_percent": 0.63244313, "complete_code_percent": 0.9384235,
"complete_data": "5140", "complete_data": "511200",
"complete_data_percent": 0.05991268, "complete_data_percent": 5.958631,
"total_units": 215, "total_units": 215,
"complete_units": 3 "complete_units": 5
}, },
"units": [ "units": [
{ {
@@ -2791,29 +2791,45 @@
{ {
"name": "cs4/Seimei/src/Memory", "name": "cs4/Seimei/src/Memory",
"measures": { "measures": {
"fuzzy_match_percent": 100.0,
"total_code": "1392", "total_code": "1392",
"matched_code": "1392",
"matched_code_percent": 100.0,
"total_data": "57360", "total_data": "57360",
"matched_data": "57360",
"matched_data_percent": 100.0,
"total_functions": 7, "total_functions": 7,
"total_units": 1 "matched_functions": 7,
"matched_functions_percent": 100.0,
"complete_code": "1392",
"complete_code_percent": 100.0,
"complete_data": "57360",
"complete_data_percent": 100.0,
"total_units": 1,
"complete_units": 1
}, },
"sections": [ "sections": [
{ {
"name": ".text", "name": ".text",
"size": "1424", "size": "1424",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
}, },
{ {
"name": ".data", "name": ".data",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
}, },
{ {
"name": ".bss", "name": ".bss",
"size": "57344", "size": "57344",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
}, },
{ {
"name": ".sbss", "name": ".sbss",
"size": "16", "size": "16",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
} }
], ],
@@ -2821,41 +2837,48 @@
{ {
"name": "FreeMemory", "name": "FreeMemory",
"size": "448", "size": "448",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
}, },
{ {
"name": "AllocateMemory", "name": "AllocateMemory",
"size": "544", "size": "544",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
}, },
{ {
"name": "SetFixMemoryEndIndex", "name": "SetFixMemoryEndIndex",
"size": "20", "size": "20",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
}, },
{ {
"name": "MemFree", "name": "MemFree",
"size": "44", "size": "44",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
}, },
{ {
"name": "MemAllocAlignReal", "name": "MemAllocAlignReal",
"size": "60", "size": "60",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
}, },
{ {
"name": "MemAllocReal", "name": "MemAllocReal",
"size": "68", "size": "68",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
}, },
{ {
"name": "MemInit", "name": "MemInit",
"size": "208", "size": "208",
"fuzzy_match_percent": 100.0,
"metadata": {} "metadata": {}
} }
], ],
"metadata": { "metadata": {
"complete": false, "complete": true,
"source_path": "../src/cs4/Seimei/src/Memory.c", "source_path": "../src/cs4/Seimei/src/Memory.c",
"progress_categories": [ "progress_categories": [
"" ""
@@ -4231,7 +4254,12 @@
"total_functions": 7, "total_functions": 7,
"matched_functions": 6, "matched_functions": 6,
"matched_functions_percent": 85.71429, "matched_functions_percent": 85.71429,
"total_units": 1 "complete_code": "1536",
"complete_code_percent": 100.0,
"complete_data": "448700",
"complete_data_percent": 100.0,
"total_units": 1,
"complete_units": 1
}, },
"sections": [ "sections": [
{ {
@@ -4316,7 +4344,7 @@
} }
], ],
"metadata": { "metadata": {
"complete": false, "complete": true,
"source_path": "../src/cs4/Seimei/src/Binder.c", "source_path": "../src/cs4/Seimei/src/Binder.c",
"progress_categories": [ "progress_categories": [
"" ""
@@ -22974,22 +23002,22 @@
{ {
"name": "Kuon", "name": "Kuon",
"measures": { "measures": {
"fuzzy_match_percent": 1.1858957, "fuzzy_match_percent": 1.3313618,
"total_code": "956924", "total_code": "956924",
"matched_code": "10556", "matched_code": "11948",
"matched_code_percent": 1.1031178, "matched_code_percent": 1.248584,
"total_data": "8579152", "total_data": "8579152",
"matched_data": "453732", "matched_data": "511092",
"matched_data_percent": 5.2887745, "matched_data_percent": 5.957372,
"total_functions": 2901, "total_functions": 2901,
"matched_functions": 49, "matched_functions": 56,
"matched_functions_percent": 1.6890727, "matched_functions_percent": 1.9303689,
"complete_code": "6052", "complete_code": "8980",
"complete_code_percent": 0.63244313, "complete_code_percent": 0.9384235,
"complete_data": "5140", "complete_data": "511200",
"complete_data_percent": 0.05991268, "complete_data_percent": 5.958631,
"total_units": 215, "total_units": 215,
"complete_units": 3 "complete_units": 5
} }
} }
] ]
+539 -7
View File
@@ -1,15 +1,547 @@
#include "common.h" #include "common.h"
#include "Memory.h"
INCLUDE_ASM("config/asm/nonmatchings/cs4/Seimei/src/Memory", FreeMemory); allocmng AllocMng[2048];
u_int LastAddr;
u_int UseMemSize;
u_int MaxHeapSize;
INCLUDE_ASM("config/asm/nonmatchings/cs4/Seimei/src/Memory", AllocateMemory); int _stack_size;
int _end;
INCLUDE_ASM("config/asm/nonmatchings/cs4/Seimei/src/Memory", SetFixMemoryEndIndex); inline int MemGetHeapSize()
{
int ret;
memset(&AllocMng, 0, sizeof(AllocMng));
ret = (unsigned int)&_end + ((unsigned int)&_stack_size + 0x1000);
ret += 0x14000;
return 0x2000000 - ret;
}
INCLUDE_ASM("config/asm/nonmatchings/cs4/Seimei/src/Memory", MemFree); inline allocmng *MemSetLP(void * lp, allocmng *temp_v1, int size)
{
int i;
INCLUDE_ASM("config/asm/nonmatchings/cs4/Seimei/src/Memory", MemAllocAlignReal);
INCLUDE_ASM("config/asm/nonmatchings/cs4/Seimei/src/Memory", MemAllocReal); if (lp == 0) {
return 0;
}
temp_v1 = &AllocMng[0];
for (i = 0; temp_v1 != &AllocMng[2048]; temp_v1++)
{
if (!temp_v1->bUse)
{
temp_v1->bUse = 1;
temp_v1->addr = (u_int)lp;
temp_v1->size = size;
return temp_v1;
}
// temp_v1++;
}
INCLUDE_ASM("config/asm/nonmatchings/cs4/Seimei/src/Memory", MemInit); return 0;
}
void MemInit(void)
{
void* lp;
allocmng *temp_v1 = AllocMng;
int sz = MemGetHeapSize() - 0x10;
lp = (void *)malloc(sz);
LastAddr = (int)lp + sz;
temp_v1 = MemSetLP(lp, temp_v1, sz);
temp_v1->addrB = temp_v1->addr;
UseMemSize = 0;
MaxHeapSize = sz;
}
void * MemAllocReal(unsigned int size /* r11 */, char * lpFuncName /* r5 */, char * lpUseName /* r2 */)
{
void * lpAddr; // r2
if (size == 0) return NULL;
lpAddr = AllocateMemory(size, 0x10, lpFuncName, lpUseName);
UseMemSize += size;
return lpAddr;
}
void * MemAllocAlignReal(unsigned int size /* r11 */, unsigned int align /* r2 */, char * lpFuncName /* r2 */, char * lpUseName /* r2 */)
{
void * lpAddr; // r2
if (size == 0) return NULL;
lpAddr = AllocateMemory(size, align, lpFuncName, lpUseName);
UseMemSize += size;
return lpAddr;
}
/*
Compile unit: C:\cs4\Seimei\src\Memory.c
Producer: MW MIPS C Compiler
Language: C
Code range: 0x0014AF40 -> 0x0014AF6C
*/
void MemFree(void * lpMem /* r2 */) {
if (lpMem != NULL) {
UseMemSize -= FreeMemory(lpMem);
}
}
static inline allocmng *getLpBaseMng(u_int size, u_int align) { // or macro?
allocmng * lpBaseMng;
unsigned int AlignAddr;
unsigned int AlignSize;
unsigned int OldEndAddr;
lpBaseMng = AllocMng;
while (1) {
if (lpBaseMng->bUse != 0 && lpBaseMng->bFree != 0) {
AlignAddr = ~(align - 1) & (lpBaseMng->addrB + align - 1);
AlignAddr += size;
if (AlignAddr <= lpBaseMng->addr + lpBaseMng->size) {
return lpBaseMng;
}
}
lpBaseMng++;
if (lpBaseMng == &AllocMng[0x800]) {
lpBaseMng = NULL;
break;
}
}
return lpBaseMng;
}
static inline allocmng *findUnusedAllocMng() { // or macro?
allocmng * lpBaseMng;
lpBaseMng = AllocMng;
while (1) {
if (lpBaseMng->bUse == 0) {
lpBaseMng->bUse = 1;
break;
} else {
lpBaseMng++;
if (lpBaseMng == (&AllocMng[0x800])) {
lpBaseMng = NULL;
break;
}
}
}
return lpBaseMng;
}
static inline allocmng *findUnusedAllocMngAligned(u_int size, unsigned int align) { // or macro?
allocmng * lpBaseMng;
if (align == 0) {
lpBaseMng = NULL;
} else {
lpBaseMng = AllocMng;
while (1) {
if (lpBaseMng->bUse == 0) {
lpBaseMng->bUse = 1;
lpBaseMng->addr = align;
lpBaseMng->size = size;
break;
} else {
lpBaseMng++;
if (lpBaseMng == (&AllocMng[0x800])) {
lpBaseMng = NULL;
break;
}
}
}
}
return lpBaseMng;
}
static inline int getAlignedAddress(int addr, volatile int align) { // ???
return (addr + align - 1) & ~(align - 1);
}
/*
Compile unit: C:\cs4\Seimei\src\Memory.c
Producer: MW MIPS C Compiler
Language: C
Code range: 0x0014AF20 -> 0x0014AF34
*/
void SetFixMemoryEndIndex(void) {
FixMemEndIndex = AllocMng->prev->no;
}
/*
Compile unit: C:\cs4\Seimei\src\Memory.c
Producer: MW MIPS C Compiler
Language: C
Code range: 0x0014AD00 -> 0x0014AF20
*/
static void * AllocateMemory(u_int size /* r2 */, u_int align /* r2 */, char * lpFuncName /* r2 */, char * lpUseName)
{
// Range: 0x14AD00 -> 0x14AF20
allocmng * lpBaseMng; // r9 $t1
unsigned int AlignAddr; // r10 $t2
unsigned int AlignSize; // r8 $t0
unsigned int OldEndAddr; // r9 $t1
allocmng* var_t0;
u_int temp_v0, temp_a3;
if ((lpBaseMng = getLpBaseMng(size, align)) != NULL) {
lpBaseMng->bFree = 0;
AlignAddr = getAlignedAddress(lpBaseMng->addrB, align);
OldEndAddr = lpBaseMng->addr + lpBaseMng->size, temp_a3 = AlignAddr + size;
if (temp_a3 == OldEndAddr) {
lpBaseMng->addr = AlignAddr;
lpBaseMng->size = size;
lpBaseMng->lpfuncname = lpFuncName;
return (void *)lpBaseMng->addr;
}
var_t0 = findUnusedAllocMng();
var_t0->addr = temp_a3;
var_t0->addrB = var_t0->addr;
var_t0->size = OldEndAddr - temp_a3;
var_t0->bFree = 1;
var_t0->next = lpBaseMng->next;
var_t0->next->prev = var_t0;
var_t0->prev = lpBaseMng;
lpBaseMng->next = var_t0;
lpBaseMng->addr = AlignAddr;
lpBaseMng->size = size;
lpBaseMng->lpfuncname = lpFuncName;
return (void *)lpBaseMng->addr;
}
// Line Numbers suggest bad instruction in inline function
var_t0 = AllocMng;
AlignAddr = getAlignedAddress(var_t0->addr, align);
temp_v0 = (AlignAddr - var_t0->addr);
lpBaseMng = findUnusedAllocMngAligned(size, AlignAddr);
lpBaseMng->addrB = var_t0->addr;
lpBaseMng->lpfuncname = lpFuncName;
var_t0->addr = AlignAddr + size;
var_t0->addrB = var_t0->addr;
var_t0->size -= size + temp_v0;
if (var_t0->prev != NULL) {
var_t0->prev->next = lpBaseMng;
lpBaseMng->prev = var_t0->prev;
}
var_t0->prev = lpBaseMng;
lpBaseMng->next = var_t0;
return (void* ) lpBaseMng->addr;
}
static u_int FreeMemory(void * lpMem /* r2 */)
{
allocmng * lpBaseMng; allocmng * lpAllocMng;
allocmng * lpLinkMng;
unsigned int FreeAddr;
unsigned int EndAddr;
unsigned int FreeSize;
lpBaseMng = AllocMng;
for(lpAllocMng = lpBaseMng; lpAllocMng != &AllocMng[2048]; lpAllocMng++) {
if (lpAllocMng->bUse == 0) { continue; }
if (lpAllocMng->bFree != 0) { continue; }
if (lpAllocMng->addr != (int)lpMem) { continue; }
FreeSize = lpAllocMng->size;
lpLinkMng = lpAllocMng->prev;
while ((!!lpLinkMng && (lpLinkMng->bFree != 0))) {
EndAddr = lpAllocMng->addr + lpAllocMng->size;
lpAllocMng->addr = lpLinkMng->addrB;
lpAllocMng->addrB = lpAllocMng->addr;
lpAllocMng->size = EndAddr - lpAllocMng->addr;
lpAllocMng->prev = (allocmng *)lpLinkMng->prev;
if (lpAllocMng->prev) { lpAllocMng->prev->next = lpAllocMng; }
lpLinkMng->bUse = 0;
lpLinkMng->bFree = 0;
lpLinkMng->next = (allocmng *)0x0;
lpLinkMng->prev = (allocmng *)0x0;
lpLinkMng = lpAllocMng->prev;
}
lpLinkMng = lpAllocMng->next;
while (!!lpLinkMng && (lpLinkMng->bFree != 0)) {
EndAddr = lpLinkMng->addr + lpLinkMng->size;
lpAllocMng->size = EndAddr - lpAllocMng->addrB;
lpAllocMng->addr = lpAllocMng->addrB;
lpAllocMng->next = (allocmng *)lpLinkMng->next;
if (lpAllocMng->next) { lpAllocMng->next->prev = lpAllocMng; }
lpLinkMng->bUse = 0;
lpLinkMng->bFree = 0;
lpLinkMng->next = (allocmng *)0x0;
lpLinkMng->prev = (allocmng *)0x0; lpLinkMng = lpAllocMng->next;
}
if (lpLinkMng == lpBaseMng) {
lpBaseMng->size = lpBaseMng->addr - lpAllocMng->addrB + lpBaseMng->size;
lpBaseMng->addr = lpAllocMng->addrB;
lpBaseMng->addrB = lpBaseMng->addr;
if (lpAllocMng->prev) { lpAllocMng->prev->next = lpBaseMng; }
lpBaseMng->prev = lpAllocMng->prev;
lpAllocMng->bUse = 0;
lpAllocMng->bFree = 0;
lpAllocMng->next = 0;
lpAllocMng->prev = 0;
} else {
lpAllocMng->bFree = 1;
}
return FreeSize;
}
return 0;
}
+34 -2
View File
@@ -1,7 +1,39 @@
#ifndef MEMORY_H #ifndef MEMORY_H
#define MEMORY_H #define MEMORY_H
#include "common.h"
typedef struct _allocmng {
// Members
unsigned char bUse; // offset 0x0, size 0x1
unsigned char bFree; // offset 0x1, size 0x1
unsigned short no; // offset 0x2, size 0x2
unsigned int addr; // offset 0x4, size 0x4
unsigned int addrB; // offset 0x8, size 0x4
unsigned int size; // offset 0xC, size 0x4
struct _allocmng * prev; // offset 0x10, size 0x4
struct _allocmng * next; // offset 0x14, size 0x4
char * lpfuncname; // offset 0x18, size 0x4
} allocmng;
static int FixMemEndIndex; // size: 0x4, address: 0x257940
extern allocmng AllocMng[2048]; // size: 0xE000, address: 0x784BC0
extern u_int LastAddr; // size: 0x4, address: 0x257944
extern u_int UseMemSize; // size: 0x4, address: 0x25794C
extern u_int MaxHeapSize; // size: 0x4, address: 0x257948
__declspec(data) extern int _stack_size; // size: 0x4, address: 0x100000
__declspec(data) extern int _end; // size: 0x4, address: 0xA63380
void MemInit(); void MemInit();
static u_int FreeMemory(void * lpMem /* r2 */);
static void * AllocateMemory(unsigned int size /* r2 */, unsigned int align /* r2 */, char * lpFuncName /* r2 */, char * lpUseName);
void SetFixMemoryEndIndex();
void MemFree(void * lpMem /* r2 */);
void * MemAllocAlignReal(unsigned int size /* r11 */, unsigned int align /* r2 */, char * lpFuncName /* r2 */, char * lpUseName /* r2 */); void * MemAllocAlignReal(unsigned int size /* r11 */, unsigned int align /* r2 */, char * lpFuncName /* r2 */, char * lpUseName /* r2 */);
void * MemAllocReal(unsigned int size /* r11 */, char * lpFuncName /* r5 */, char * lpUseName /* r2 */);
#endif #endif