summaryrefslogtreecommitdiff
path: root/src/heapbar.S
blob: 4f86fbe37ba0f2af72e7e7bd9acfb5354c074a88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# memory debugger - fun!
# GX stuff is implemented in C++, this just gets the lowlevel info

#ifndef __MWERKS__
.set r0,0;   .set r1,1;   .set r2,2; .set r3,3;   .set r4,4
.set r5,5;   .set r6,6;   .set r7,7;   .set r8,8;   .set r9,9
.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14
.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19
.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24
.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29
.set r30,30; .set r31,31; .set f0,0; .set f2,2; .set f3,3
#endif

#define HEAP_EGGRootMEM1 1
#define HEAP_EGGRootMEM2 2

.extern cppGXStart
.extern cppGXEnd
.extern cppProcessHeap
.extern MEMGetTotalFreeSizeForExpHeap
.extern GameHeap1
.extern GameHeap2

.set sp,1
.set rtoc,2
.set this,31

.text

.align 4

.global doHeapBar

doHeapBar:
	blr
	
	stwu sp, -0x10(sp)
	mflr r0
	stw r0, 0x14(sp)
	
	stw this, 0xC(sp)
	
	#lis r3, EGGTSystem_Pointer@h
	#ori r3, r3, EGGTSystem_Pointer@l
	#lwz this, 0(r3)
	
	bl cppGXStart
	
	#lwz r3, 0x18(this)
	#lis r3, dSys_c__RootHeapMEM1@h
	#ori r3, r3, dSys_c__RootHeapMEM1@l
	lis r3, GameHeap1@h
	ori r3, r3, GameHeap1@l
	lwz r3, 0(r3)
	li r4, HEAP_EGGRootMEM1
	bl asmProcessHeap
	
	#lwz r3, 0x1C(this)
	#lis r3, dSys_c__RootHeapMEM2@h
	#ori r3, r3, dSys_c__RootHeapMEM2@l
	lis r3, GameHeap2@h
	ori r3, r3, GameHeap2@l
	lwz r3, 0(r3)
	li r4, HEAP_EGGRootMEM2
	bl asmProcessHeap
	
	bl cppGXEnd
	
	lwz this, 0xC(sp)
	lwz r0, 0x14(sp)
	mtlr r0
	addi sp, sp, 0x10
	blr



asmProcessHeap:
	
	stwu sp, -0x10(sp)
	mflr r0
	stw r0, 0x14(sp)
	
	stw r31, 0xC(sp)
	stw r30, 0x8(sp)
	
	mr r31, r3
	mr r30, r4
	
	# get all the required data from the heap
	# cppProcessHeap(u32 freeSize, u32 heapSize, int heapID, char *name)
	
	# get free size first so the function doesn't destroy our volatile regs
	# because I'm too lazy to save them >.>
	lwz r3, 0x10(r31)
	bl MEMGetTotalFreeSizeForExpHeap
	
	# get name
	lwz r6, 0x34(r31)
	
	# get heapID
	mr r5, r30
	
	# get heap size
	# this was a fucking pain to figure out -_-
	lwz r4, 0x10(r31)		# get the MEMiHeapHead*
	lwz r7, 0x18(r4)		# get heapStart
	lwz r8, 0x1C(r4)		# get heapEnd
	sub r4, r8, r7			# heapSize = heapEnd - heapStart probably
	
	# now do it
	bl cppProcessHeap
	
	lwz r30, 0x8(sp)
	lwz r31, 0xC(sp)
	lwz r0, 0x14(sp)
	mtlr r0
	addi sp, sp, 0x10
	blr