DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
dataalloc.hpp
1#pragma once
2
3#include "common.h"
4
5#include <cstdio>
6
7#include "dataalloc_fwd.hpp"
8
12void *operator new(size_t size, u_long128 *block);
16void *operator new[](size_t size, u_long128 *block);
17
21template <int Kind>
23public:
24 u_char *base;
25 u_char *buffer;
26 int used;
27 int limit;
29 CDataAlloc2(int limit = -1);
30
31 u_char *Alloc(int quads);
32 u_char *Alloc64(int quads);
33 void Align64();
34
36 void Reset() { used = 0; }
37};
38
42template <int Kind, int Size>
44public:
45 u_long128 block[Size];
46 int used;
48 CDataAlloc() { used = 0; }
49
50 u_char *Alloc(int quads);
51 u_char *Alloc64(int quads);
52 void Align64();
53};
54
55template <>
56class CDataAlloc2<1> {
57public:
58 u_char *base;
59 u_char *buffer;
60 int used;
61 int limit;
64 CDataAlloc2(int limit);
65
66 u_char *Alloc(int quads);
67 u_char *Alloc64(int quads);
68 void Align64();
69
71 void Reset() { used = 0; }
72};
73
74extern "C" void *__ct__14CDataAlloc2_1_Fi(void *self, int limit);
75
76template <>
77class CDataAlloc<1, 6000> {
78public:
79 u_long128 block[6000];
80 int used;
82 CDataAlloc();
83
84 u_char *Alloc(int quads);
85 u_char *Alloc64(int quads);
86 void Align64();
87};
88
89template <>
90class CDataAlloc<1, 1690000> {
91public:
92 u_long128 block[1690000];
93 int used;
95 CDataAlloc() { used = 0; }
96
97 u_char *Alloc(int quads);
98 u_char *Alloc64(int quads);
99 void Align64();
100};
101
102template <int Kind, int Size>
103u_char *CDataAlloc<Kind, Size>::Alloc(int quads) {
104 u_char *allocation;
105
106 if (used + quads > Size) {
107 printf("Alocation Error! %d/%d\n", used, Size);
108
109 while (1)
110 ;
111 }
112
113 allocation = (u_char *) block + used * 16;
114 used += quads;
115 return allocation;
116}
117
118template <int Kind, int Size>
119u_char *CDataAlloc<Kind, Size>::Alloc64(int quads) {
120 Align64();
121
122 u_char *allocation = (u_char *) block + used * 16;
123 used += quads;
124
125 if (used >= Size) {
126 printf("Alocation Error! %d/%d\n", used, Size);
127
128 while (1)
129 ;
130 }
131
132 return allocation;
133}
134
135#ifndef PORT
136template <int Kind, int Size>
138 /* Falls through as it stands; flipping the branch turns the whole alignment step off. */
139 asm {
140 bne $0, $0, done
141 }
142
143 u_int slack = (u_int) ((u_char *) block + used * 16) & 63;
144
145 if (slack) {
146 used += (64 - slack) >> 4;
147 }
148
149 if (used >= Size) {
150 printf("Alocation Error! %d/%d\n", used, Size);
151
152 while (1)
153 ;
154 }
155
156done:;
157}
158#endif
159
163extern CDataAlloc2<1> TextureData;
167extern CDataAlloc2<1> VisualData;
171extern CDataAlloc2<1> MotionData;
175extern CDataAlloc2<1> WaterData;
179extern CDataAlloc2<1> VariousData;
183extern CDataAlloc2<1> ActiveData0;
187extern CDataAlloc2<1> ActiveData1;
191extern CDataAlloc<1, 1690000> GlobalDataBuffer;
195extern CDataAlloc2<1> workbuffer;
196
198extern CDataAlloc2<1> MenuEffectCashBuffer;
void Reset()
Definition dataalloc.hpp:36
u_char * base
Definition dataalloc.hpp:24
u_char * buffer
Definition dataalloc.hpp:25
u_long128 block[Size]
Definition dataalloc.hpp:45