DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
dispctrl.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 230
4
5#include "dispctrl.hpp"
6
7#include <cstring>
8
9#include "bound.hpp"
10#include "debugfont.hpp"
11#include "mglib.hpp"
12#include "rect.hpp"
13#include "snd.hpp"
14#include "texture.hpp"
15
19struct PTS_HEADER {
20 int unk_00;
21 int count;
22 int unk_08[2];
23};
24
25STATIC_ASSERT(sizeof(PTS_HEADER) == 0x10);
26
30struct PTS_ENTRY {
31 char name[16];
32 int offset;
33 int unk_14[7];
34};
35
36STATIC_ASSERT(sizeof(PTS_ENTRY) == 0x30);
37
39 return sizeof(CBound);
40}
41
42void openGiftag(sceVif1Packet *packet) {
43 sceVif1PkCnt(packet, 0);
44 sceVif1PkOpenDirectCode(packet, 0);
45 sceVif1PkOpenGifTag(packet, *reinterpret_cast<u_long128 *>(&GiftagAD));
46}
47
55void closeGiftag(sceVif1Packet *packet) {
56 sceVif1PkCloseGifTag(packet);
57 sceVif1PkCloseDirectCode(packet);
58}
59
61 CTexture *tex;
62 int draw_x;
63 int draw_y;
64 int draw_width;
65 int draw_height;
66 char *text_pos;
67 unsigned int font_tbp;
68 unsigned int font_tbw;
69 unsigned int dest_tbp;
70 unsigned int dest_tbw;
71 sceGsTex0 font_tex0;
72 sceGsTex0 dest_tex0;
73 sceGsTest test;
74 sceGsZbuf zbuf;
75 sceGsTex0 frame_tex0;
76 float q;
77 int pen_x;
78 int pen_y;
79 CRect_i_ dst;
80 CRect_i_ src;
81 u_long bottom_y;
82 u_long right_x;
83 int character;
84 int index;
85 int column;
86 int row;
87
88 draw_x = this->x;
89 draw_y = this->y;
90 draw_width = this->width;
91 draw_height = this->height;
92 text_pos = this->text;
93
94 tex = TexManager.GetTexture("ankfnt24", -1);
95 font_tex0 = *reinterpret_cast<sceGsTex0 *>(&tex->tex0);
96 font_tbp = font_tex0.TBP0;
97 font_tbw = font_tex0.TBW;
98
99 tex = TexManager.GetTexture(this->texture_name, -1);
100 dest_tex0 = *reinterpret_cast<sceGsTex0 *>(&tex->tex0);
101 dest_tbp = dest_tex0.TBP0;
102 dest_tbw = dest_tex0.TBW;
103
104 openGiftag(Vif1Packet);
105
106 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEXFLUSH, 0);
107 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEX0_1, *reinterpret_cast<u_long *>(&dest_tex0));
108 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_FRAME_1, SCE_GS_SET_FRAME(dest_tbp >> 5, dest_tbw, dest_tex0.PSM, 0));
109
110 mgTexa.AEM = 1;
111 mgTexa.TA0 = static_cast<u_char>(this->alpha);
112 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEXA, *reinterpret_cast<u_long *>(&mgTexa));
113
114 test = mgPixelTest;
115 test.bits.ate = 0;
116 test.bits.zte = 1;
117 test.bits.ztst = SCE_GS_ALWAYS;
118 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEST_1, *reinterpret_cast<u_long *>(&test));
119
120 zbuf = mgZBuffer;
121 zbuf.bits.zmsk = 1;
122 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_ZBUF_1, *reinterpret_cast<u_long *>(&zbuf));
123
124 q = 1.0f;
125 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_PRIM, 4);
126 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_RGBAQ, SCE_GS_SET_RGBAQ(1, 1, 1, 0x80, *reinterpret_cast<u_int *>(&q)));
127
128#ifdef PAL
129 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_XYZ2, 0x78806C00);
130#else
131 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_XYZ2, 0x79006C00);
132#endif
133 right_x = (draw_width << 4) + 0x6C00;
134 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_XYZ2, right_x | (GS_Y_OFFSET << 16));
135 bottom_y = static_cast<u_long>((draw_height << 4) + GS_Y_OFFSET) << 16;
136 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_XYZ2, bottom_y | 0x6C00);
137 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_XYZ2, right_x | bottom_y);
138 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEXFLUSH, 0);
139
140 MGGetFBuffTex(&frame_tex0);
141 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_FRAME_1, SCE_GS_SET_FRAME(frame_tex0.TBP0 >> 5, frame_tex0.TBW, frame_tex0.PSM, 0));
142 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEST_1, *reinterpret_cast<u_long *>(&mgPixelTest));
143 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_ZBUF_1, *reinterpret_cast<u_long *>(&mgZBuffer));
144
145 pen_x = 0;
146 pen_y = 0;
147
148 while ((character = *text_pos) != 0) {
149 if (character == 0x20) {
150 pen_x += 8;
151 text_pos++;
152 continue;
153 }
154
155 if (character == 0x0A) {
156 pen_y += 16;
157 pen_x = 0;
158 text_pos++;
159 continue;
160 }
161
162 index = static_cast<u_char>(*reinterpret_cast<u_char *>(text_pos) - 0x21);
163 column = index % 16;
164 row = index >> 4;
165
166 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_BITBLTBUF, SCE_GS_SET_BITBLTBUF(font_tbp, font_tbw, SCE_GS_PSMCT24, dest_tbp, dest_tbw, SCE_GS_PSMCT24));
167 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TRXPOS, SCE_GS_SET_TRXPOS(column * 8, row * 16, pen_x, pen_y, 0));
168 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TRXREG, SCE_GS_SET_TRXREG(8, 16));
169 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TRXDIR, SCE_GS_SET_TRXDIR(SCE_GS_LOCAL_LOCAL));
170
171 pen_x += 8;
172 text_pos++;
173 }
174
175 this->length = 0;
176 sceVif1PkAddGsAD(Vif1Packet, SCE_GS_TEXFLUSH, 0);
177 closeGiftag(Vif1Packet);
178
179 src.x = 0;
180 src.y = 0;
181 src.width = draw_width;
182 src.height = draw_height;
183 dst.x = draw_x;
184 dst.y = draw_y;
185 dst.width = draw_width - 1;
186 dst.height = draw_height - 1;
187 tex = TexManager.GetTexture(this->texture_name, -1);
188 set2DSprite(Vif1Packet, tex, dst, src, 0x40);
189}
190
191u_int *SearchPTS(u_int *archive, char *name) {
192 int i;
193 PTS_HEADER *header;
194 PTS_ENTRY *entry;
195 char *base_name;
196 char ch;
197
198 header = reinterpret_cast<PTS_HEADER *>(archive);
199
200 if (header == 0) {
201 return 0;
202 }
203
204 entry = reinterpret_cast<PTS_ENTRY *>(header + 1);
205 base_name = name;
206
207 while ((ch = *name) != 0) {
208 if (ch == '/') {
209 base_name = name + 1;
210 }
211
212 name++;
213 }
214
215 for (i = 0; i < header->count; i++, entry++) {
216 if (strcmp(base_name, entry->name) == 0) {
217 return reinterpret_cast<u_int *>(reinterpret_cast<char *>(header) + entry->offset);
218 }
219 }
220
221 return 0;
222}
223
224u_int *SearchPTS(u_int *archive, int index) {
225 PTS_HEADER *header = reinterpret_cast<PTS_HEADER *>(archive);
226
227 if (header == 0) {
228 return 0;
229 }
230
231 if (index >= header->count) {
232 return 0;
233 }
234
235 int offset = *reinterpret_cast<int *>(reinterpret_cast<char *>(archive) + index * 0x30 + 0x20);
236 return reinterpret_cast<u_int *>(reinterpret_cast<char *>(archive) + offset);
237}
238
239void CDispCtrl::FadeOutStart(float fade_speed) {
240 this->speed = fade_speed;
241 rate = 0.0f;
242 mode = 1;
243}
244
245void CDispCtrl::FadeInStart(float fade_speed) {
246 this->speed = fade_speed;
247 rate = 128.0f;
248 mode = 2;
249}
250
251void CDispCtrl::FadeInit(float start_rate) {
252 this->rate = start_rate;
253 mode = -1;
254}
255
257 return rate;
258}
259
261 if (mode != 1) {
262 return rate;
263 }
264
265 if (rate == 0.0f && speed == 0.0f) {
266 return rate;
267 }
268
269 rate += speed;
270
271 if (rate > 128.0f) {
272 rate = 128.0f;
273 }
274
275 for (s32 x = 0; x < 640; x += 64) {
276 for (s32 y = 0; y < SCREEN_HALF_HEIGHT; y += 32) {
277 CRect_i_ rect;
278 rect.x = x * 16;
279 rect.y = y * 16;
280 rect.width = 1024;
281 rect.height = 512;
282 MGFillBox(rect, 0, 0, 0, static_cast<u8>(rate));
283 }
284 }
285
286 if (rate >= 128.0f) {
287 rate = 128.0f;
288 speed = 0.0f;
289 }
290
291 return rate;
292}
293
295 if (mode != 2) {
296 return rate;
297 }
298
299 if (rate == 0.0f && speed == 0.0f) {
300 return rate;
301 }
302
303 rate -= speed;
304
305 if (rate < 0.0f) {
306 rate = 0.0f;
307 }
308
309 for (s32 x = 0; x < 640; x += 64) {
310 for (s32 y = 0; y < SCREEN_HALF_HEIGHT; y += 32) {
311 CRect_i_ rect;
312 rect.x = x * 16;
313 rect.y = y * 16;
314 rect.width = 1024;
315 rect.height = 512;
316 MGFillBox(rect, 0, 0, 0, static_cast<u8>(rate));
317 }
318 }
319
320 if (rate <= 0.0f) {
321 rate = 0.0f;
322 speed = 0.0f;
323 }
324
325 return rate;
326}
virtual int Sizeof()
Definition dispctrl.cpp:38
void Draw()
Definition dispctrl.cpp:60
char * texture_name
Definition gameloop.cpp:164
char text[0x200]
Definition gameloop.cpp:167
void FadeInit(float start_rate)
Definition dispctrl.cpp:251
void FadeOutStart(float fade_speed)
Definition dispctrl.cpp:239
float GetRate()
Definition dispctrl.cpp:256
float speed
Definition dispctrl.hpp:40
float FadeOut(sceVif1Packet *packet)
Definition dispctrl.cpp:260
float rate
Definition dispctrl.hpp:39
float FadeIn(sceVif1Packet *packet)
Definition dispctrl.cpp:294
void FadeInStart(float fade_speed)
Definition dispctrl.cpp:245
s32 x
Definition rect.hpp:18
s32 width
Definition rect.hpp:20
s32 height
Definition rect.hpp:21
s32 y
Definition rect.hpp:19
u_long tex0
Definition texture.hpp:57
Definition dispctrl.cpp:30
int offset
Definition dispctrl.cpp:32
char name[16]
Definition dispctrl.cpp:31