DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
dataalloc2_1.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 744
4
5#include "dataalloc.hpp"
6
7u_char *CDataAlloc2<1>::Alloc(int quads) {
8 u_char *block;
9
10 if (used + quads > limit) {
11 printf("Alocation Error! %d/%d\n", used, limit);
12
13 while (1)
14 ;
15 }
16
17 block = base + used * 16;
18 used += quads;
19 return block;
20}
21
22u_char *CDataAlloc2<1>::Alloc64(int quads) {
23 Align64();
24
25 u_char *block = base + used * 16;
26 used += quads;
27
28 if (used >= limit) {
29 printf("Alocation Error! %d/%d\n", used, limit);
30
31 while (1)
32 ;
33 }
34
35 return block;
36}
37#ifndef PORT
39 /* Falls through as it stands; flipping the branch turns the whole alignment step off. */
40 asm {
41 bne $0, $0, done
42 }
43
44 int slack = (int) (base + used * 16) & 63;
45
46 if (slack) {
47 used += (64 - slack) >> 4;
48 }
49
50 if (used >= limit) {
51 printf("Alocation Error! %d/%d\n", used, limit);
52
53 while (1)
54 ;
55 }
56
57done:;
58}
59#endif
60u_char *CDataAlloc<1, 1690000>::Alloc64(int quads) {
61 Align64();
62
63 u_char *allocation = (u_char *) this->block + used * 16;
64 used += quads;
65
66 if (used >= 1690000) {
67 printf("Alocation Error! %d/%d\n", used, 1690000);
68
69 while (1)
70 ;
71 }
72
73 return allocation;
74}
75#ifndef PORT
77 /* Falls through as it stands; flipping the branch turns the whole alignment step off. */
78 asm {
79 bne $0, $0, done
80 }
81
82 u_int slack = (u_int) ((u_char *) block + used * 16) & 63;
83
84 if (slack) {
85 used += (64 - slack) >> 4;
86 }
87
88 if (used >= 1690000) {
89 printf("Alocation Error! %d/%d\n", used, 1690000);
90
91 while (1)
92 ;
93 }
94
95done:;
96}
97#endif
99 this->limit = limit;
100 used = 0;
101 buffer = 0;
102
103 /* A negative limit leaves the base alone rather than pointing it at nothing. */
104 if (limit < 0) {
105 return;
106 }
107
108 base = buffer;
109}