DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
nowload.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#include "common.h"
4
5#include <eekernel.h>
6#include <libdma.h>
7#include <libgraph.h>
8#include <libpkt.h>
9
10#include <cstdio>
11
12#include "dataread.hpp"
13#include "mainselect.hpp"
14#include "mglib.hpp"
15#include "nowload.hpp"
16#include "rect.hpp"
17#include "snd.hpp"
18#include "texture.hpp"
19#include "tim2.hpp"
20
21int end_flag = 1;
22
23u_int now_load[2000] __attribute__((aligned(64)));
24sceGsDBuff nowloadDB;
26CTexture nl_tex;
27CTexture nl_tex2;
28
29int now_loding_flag;
30int nl_start_cnt;
31float col_cnt;
32float col_add;
33int logo_count;
37static int count;
38int map_title_no;
39int now_loding_off;
40int now_loading_vsync_end;
44static int VSyncField;
45
46int check_now_loading() {
47 return end_flag;
48}
49
50void clear_now_loading_vsync_end() {
51 now_loading_vsync_end = 0;
52}
53
54int check_now_loading_vsync_end() {
55 return now_loading_vsync_end;
56}
57
58void wait_now_loading_vsync() {
59 if (end_flag == 0) {
60 clear_now_loading_vsync_end();
61
62 do {
63
64 } while (check_now_loading_vsync_end() == 0);
65 }
66}
67
68void now_loading_off() {
69 now_loding_off = 1;
70}
71
79void init_now_loading(int title_number) {
80 end_flag = 1;
81
82 if (now_loding_off != 0) {
83 now_loding_off = 0;
84 return;
85 }
86
87#ifdef PAL
88 u_char raw_archive[320000];
89#else
90 u_char raw_archive[64000];
91#endif
92 u_char *archive = raw_archive;
93 int archive_size;
94 int misalignment = (int) archive % 64;
95
96 if (misalignment != 0) {
97 archive += 64 - misalignment;
98 }
99
100 now_loding_flag = 0;
101
102 char image_directory[64] = "img";
103
104 if (LanguageCode > LANG_JAPANESE) {
105 sprintf(image_directory, "img_%d", LanguageCode);
106 }
107
108 char path[64] = "";
109
110 if (title_number < 5) {
111 sprintf(path, "%s/mt0%d.tm2", image_directory, title_number + 1);
112 } else if (title_number < 100) {
113 sprintf(path, "%s/mt%d.tm2", image_directory, title_number);
114 } else {
115 sprintf(path, "%s/mt%d.tm2", image_directory, title_number - 99);
116 }
117
118 if (title_number == 0x321) {
119 sprintf(path, "%s/title.img", image_directory);
120
121 if (LoadFile2(path, archive, &archive_size, 0) == 0) {
122 return;
123 }
124
125#ifdef PAL
126 LoadTexture("SCElogo", archive, &nl_tex, 8000, 10000);
127 LoadTexture("L5logo", archive, &nl_tex2, 9500, 10100);
128#else
129 LoadTexture("SCElogo", archive, &nl_tex, 0x1A40, 10000);
130 LoadTexture("L5logo", archive, &nl_tex2, 8000, 0x2774);
131#endif
132 } else {
133 if (path[0] == '\0') {
134 return;
135 }
136
137 if (LoadFile2(path, archive, &archive_size, 0) == 0) {
138 return;
139 }
140
141#ifdef PAL
142 LoadTexture((TM2_head *) archive, &nl_tex, 8000, 9000);
143#else
144 LoadTexture((TM2_head *) archive, &nl_tex, 0x1A40, 8000);
145#endif
146 }
147
148 map_title_no = title_number;
149 nl_start_cnt = 20;
150 sceGsSetDefDBuff(&nowloadDB, 0, 640, SCREEN_HALF_HEIGHT, 2, 0x31, 1);
151 nowloadDB.clear0.rgbaq.R = 0;
152 nowloadDB.clear0.rgbaq.G = 0;
153 nowloadDB.clear0.rgbaq.B = 0;
154 nowloadDB.clear0.rgbaq.A = 0x80;
155 nowloadDB.clear1.rgbaq.R = 0;
156 nowloadDB.clear1.rgbaq.G = 0;
157 nowloadDB.clear1.rgbaq.B = 0;
158 nowloadDB.clear1.rgbaq.A = 0x80;
159 sceVif1PkInit(&nlPacket, now_load);
160 col_cnt = 0.0f;
161 col_add = 1.0f;
162 count = 0;
163 logo_count = 0;
164 end_flag = 0;
165 now_loading_vsync_end = 1;
166 MGInitVSyncCallBack(VSyncCallBack_Load);
167}
168
176int VSyncCallBack_Load(int field) {
177 (void) field;
178
179 if (end_flag) {
180 now_loading_vsync_end = 1;
181 return 0;
182 }
183
184 VSyncField = !((*(volatile u_long *) 0x12001000 >> 13) & 1);
185
186 if (nl_start_cnt == 0) {
187 sceDmaSync(DmaCH1, 0, 0);
188 sceVif1PkReset(&nlPacket);
189
190 if (map_title_no == 0x321) {
191 if (logo_count == 0) {
192#ifdef PAL
193 // Languages past the first two show a full-screen logo image instead.
194 if (LanguageCode >= LANG_ENGLISH_UK) {
195 set2DSprite(&nlPacket, &nl_tex, CRect_i_(0, 0x10, 0x280, 0x1C0), CRect_i_(0, 0, 0x280, 0x1C0), (u_char) (int) col_cnt);
196 } else {
197 set2DSprite(&nlPacket, &nl_tex, CRect_i_(0x60, 0xC0, 0x1C0, 0x40), CRect_i_(0, 0, 0x1C0, 0x40), (u_char) (int) col_cnt);
198 }
199#else
200 set2DSprite(&nlPacket, &nl_tex, CRect_i_(0x60, 0xC0, 0x1C0, 0x40), CRect_i_(0, 0, 0x1C0, 0x40), (u_char) (int) col_cnt);
201#endif
202 }
203
204 if (logo_count == 1) {
205 set2DSprite(&nlPacket, &nl_tex2, CRect_i_(0x100, 0xA0, 0x80, 0x80), CRect_i_(0, 0, 0x80, 0x80), (u_char) (int) col_cnt);
206 }
207
208 if (count == 0) {
209 col_cnt += col_add * 2.0f;
210 }
211
212 if (col_cnt > 128.0f) {
213#ifdef PAL_TIMING
214 // The logo holds keep their NTSC duration at 50 fields a second.
215 count = 183;
216#else
217 count = 220;
218#endif
219 col_cnt = 128.0f;
220 col_add *= -1.0f;
221 }
222
223 if (col_cnt < 0.0f) {
224#ifdef PAL_TIMING
225 count = 83;
226#else
227 count = 100;
228#endif
229 col_cnt = 0.0f;
230 col_add *= -1.0f;
231
232 if (logo_count == 1) {
233 end_flag = 1;
234 }
235
236 logo_count++;
237 }
238
239 count--;
240
241 if (count < 0) {
242 count = 0;
243 }
244 } else {
245 set2DSprite(&nlPacket, &nl_tex, CRect_i_(0x80, 0xA0, 0x180, 0x80), CRect_i_(0, 0, 0x180, 0x80), (u_char) (int) col_cnt);
246
247 if (count == 0) {
248 col_cnt += col_add;
249 }
250
251 if (col_cnt > 128.0f) {
252 count = 120;
253 col_cnt = 128.0f;
254 col_add *= -1.0f;
255 }
256
257 if (col_cnt < 0.0f) {
258 end_flag = 1;
259 col_cnt = 0.0f;
260 }
261
262 count--;
263
264 if (count < 0) {
265 count = 0;
266 }
267 }
268
269 sceVif1PkEnd(&nlPacket, 0);
270 sceVif1PkTerminate(&nlPacket);
271 iFlushCache(0);
272 sceDmaSend(DmaCH1, nlPacket.pBase);
273 }
274
275 nl_start_cnt--;
276
277 if (nl_start_cnt < 0) {
278 nl_start_cnt = 0;
279 }
280
281 sceGsDrawEnv1 *draw = DBuffID != 0 ? &nowloadDB.draw1 : &nowloadDB.draw0;
282 sceGsSetHalfOffset(draw, 0x800, 0x800, VSyncField);
283 iSyncDCache(&nowloadDB, (u_char *) &nowloadDB + sizeof(nowloadDB));
284 sceGsSwapDBuff(&nowloadDB, DBuffID);
285 DBuffID = !DBuffID;
286 sceDmaSync(DmaCH2, 0, 0);
287 now_loading_vsync_end = 1;
288 return 0;
289}
290
298void LoadTexture(char *name, u_char *archive, CTexture *texture, int image_address, int palette_address) {
299 SetTextureInfo(texture, name, archive);
300 sceGsTex0 *tex0 = (sceGsTex0 *) &texture->tex0;
301 sceGsLoadImage load;
302 sceGsSetDefLoadImage(&load, (short) image_address, tex0->TBW, tex0->PSM, 0, 0, texture->width, texture->height);
303 FlushCache(0);
304 sceGsExecLoadImage(&load, (u_long128 *) texture->image[0]);
305
306 if (texture->bpp == 0) {
307 sceGsSetDefLoadImage(&load, (short) palette_address, 1, 0, 0, 0, 8, 2);
308 }
309
310 if (texture->bpp == 1) {
311 sceGsSetDefLoadImage(&load, (short) palette_address, 1, 0, 0, 0, 16, 16);
312 }
313
314 FlushCache(0);
315
316 if (texture->bpp < 2) {
317 sceGsExecLoadImage(&load, (u_long128 *) texture->clut);
318 }
319
320 tex0->TBP0 = image_address;
321 tex0->bits.tcc = 1;
322 tex0->CBP = palette_address;
323}
324
332void LoadTexture(TM2_head *image, CTexture *texture, int image_address, int palette_address) {
333 SetTextureInfo(texture, "maptitle", image);
334 sceGsTex0 *tex0 = (sceGsTex0 *) &texture->tex0;
335 sceGsLoadImage load;
336 sceGsSetDefLoadImage(&load, (short) image_address, tex0->TBW, tex0->PSM, 0, 0, texture->width, texture->height);
337 FlushCache(0);
338 sceGsExecLoadImage(&load, (u_long128 *) texture->image[0]);
339
340 if (texture->bpp == 0) {
341 sceGsSetDefLoadImage(&load, (short) palette_address, 1, 0, 0, 0, 8, 2);
342 }
343
344 if (texture->bpp == 1) {
345 sceGsSetDefLoadImage(&load, (short) palette_address, 1, 0, 0, 0, 16, 16);
346 }
347
348 FlushCache(0);
349
350 if (texture->bpp < 2) {
351 sceGsExecLoadImage(&load, (u_long128 *) texture->clut);
352 }
353
354 tex0->TBP0 = image_address;
355 tex0->bits.tcc = 1;
356 tex0->CBP = palette_address;
357}
short height
Definition texture.hpp:54
short bpp
Definition texture.hpp:55
u_int * image[4]
Definition texture.hpp:59
u_int * clut
Definition texture.hpp:60
short width
Definition texture.hpp:53
u_long tex0
Definition texture.hpp:57