Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
files.c
Go to the documentation of this file.
1/* The overlay's images and the files of its image sets; the panels' fades; the
2 gym levels' trainings; and the third object's data, with the state all three
3 objects share */
4
5#include "menus/gym.h"
6
7/* Loads the overlay's TIM archive into VRAM */
9 TimLoader loader;
10
11 initTimLoader(&loader);
12 loader.setImagePos(0x240, 0x100);
14}
15
20
21/* Starts loading a file of STGTRAIN_files, unless it is the one loaded */
23 if (index < 0) {
24 return 0;
25 }
26 if (index != STGTRAIN_state.fileIndex) {
31 }
32 return 1;
33}
34
35/* The requested file, or NULL while it loads */
42
43/* Frees the loaded file of STGTRAIN_files */
49
50/* The set's sprite bank, where its sprites start and its size: the two
51 words after the set's offsets */
53 STGTRAIN_bankCursor.set = header;
54 /* the offsets count bytes from the file's start */
59 return 1;
60}
61
62/* The set's animations */
64 s32 i;
65
66 STGTRAIN_animCursor.set = header;
67 for (i = 0; i < 6; i++) {
68 if (STGTRAIN_animCursor.set->anims[i] != 0) {
69 /* an offset in bytes, as the bank's */
71 } else {
72 STGTRAIN_state.sets[set].anims[i] = NULL;
73 }
74 }
75 return 1;
76}
77
78/* The images of a set: the rest of its offsets */
80 s32 i;
81
83 STGTRAIN_state.sets[set].imageCount = header->count - 7;
84 for (i = 0; i < STGTRAIN_state.sets[set].imageCount; i++) {
86 }
87 return 1;
88}
89
90/* Reads an image set of the loaded file */
92 if (STGTRAIN_state.data != NULL && set < 9) {
93 STGTRAIN_state.sets[set].id = set;
94 /* the file starts with the sets' offsets */
97 if (STGTRAIN_setCursor.set->count == 0) {
98 return 0;
99 }
101 return 0;
102 }
105 }
106 }
107 return 0;
108}
109
110/* Loads the images of a set into VRAM side by side, unpacking the
111 run-length encoded ones ("RLEN") first */
113 TimLoader loader;
114 s32 x;
115 s32 y;
116 s32 clutX;
117 s32 clutY;
118 u8 *buf;
119 u8 *src;
120 u8 *image;
121 s32 i;
122 s32 j;
123 s32 n;
124 u8 c;
125 s32 magic;
126
127 if (set != STGTRAIN_state.sets[set].id) {
128 return 0;
129 }
130 x = pos[0];
131 y = pos[1];
132 clutX = pos[2];
133 clutY = pos[3];
134 initTimLoader(&loader);
135 STGTRAIN_state.sets[set].imageY = y;
136 buf = HEAP.alloc(0xA800, 2);
137 for (i = 0; i < STGTRAIN_state.sets[set].imageCount; i++) {
138 STGTRAIN_state.sets[set].imageX[i] = x + i * 0x40;
139 loader.setImagePos(x + i * 0x40, y);
140 src = STGTRAIN_state.sets[set].images[i];
141 /* a TIM, or "RLEN" and a word, then the packed TIM: its first word
142 tells. The match depends on the magic read before image is set:
143 with the copy right after the load, cse puts the load in image */
144 magic = *(s32 *)src;
145 image = src;
146 if (magic == RLEN_MAGIC) {
147 /* and on image set before src moves on, or src + 8 is taken
148 from image */
149 image = buf;
150 src += 8;
151 while ((c = *src) != 0) {
152 if (c & 0x80) {
153 n = c & 0x7F;
154 src++;
155 for (j = 0; j < n; j++) {
156 *image++ = *src;
157 }
158 src++;
159 } else {
160 n = *src++;
161 for (j = 0; j < n; j++) {
162 *image++ = *src++;
163 }
164 }
165 }
166 image = buf;
167 }
168 /* the TIM's CLUT x, after its id, flags and CLUT block size */
169 loader.setClutPos(clutX + *(s16 *)(image + 0xC), clutY);
170 loader.load(image);
171 }
172 HEAP.free(buf);
173 return 1;
174}
175
176/* The file of an entry of STGTRAIN_files */
178 return STGTRAIN_files[index].file;
179}
180
181/* Where the image of an entry of STGTRAIN_files goes (y << 16 | x) */
183 return STGTRAIN_files[index].y << 16 | STGTRAIN_files[index].x;
184}
185
186/* Whether an entry of STGTRAIN_files draws its effect at the Digimon's depth */
190
191/* The sprite bank of an image set */
195
196/* Where an image set's sprites start in its bank */
200
201/* The size of an image set's sprite bank (nothing calls it) */
205
206/* An animation of an image set */
208 return STGTRAIN_state.sets[set].anims[i];
209}
210
211/* The trainings of a gym level, counting them */
213 s32 i;
214
215 if (index < 1 || index > 14) {
216 index = 0;
217 }
219 for (i = 0; i < 16; i++) {
220 if (STGTRAIN_gymTrainings[index][i].id != 0) {
222 }
223 }
224 return STGTRAIN_gymTrainings[index];
225}
226
227/* A training of a gym level, by its id */
229 s32 i;
230
231 if (index < 1 || index > 14) {
232 index = 0;
233 }
234 for (i = 0; i < 16; i++) {
235 if (STGTRAIN_gymTrainings[index][i].id == id) {
236 return &STGTRAIN_gymTrainings[index][i];
237 }
238 }
239 return NULL;
240}
241
242/* The data: the rest of the overlay's, with the state all three objects
243 share */
244/* the points each intensity of a training costs */
246 1, 5, 10,
247};
248/* The trainings of each gym level, by STGTRAIN_findGymTraining: {id, stat, other}, 0 ends */
250 {
251 {1, 1, 0}, {2, 2, 0}, {3, 3, 0}, {4, 4, 0},
252 {5, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
253 {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
254 {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
255 },
256 {
257 {1, 1, 0}, {2, 2, 0}, {3, 3, 0}, {4, 4, 0},
258 {5, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
259 {6, 8, 16}, {7, 9, 2}, {8, 10, 5}, {9, 11, 1},
260 {10, 12, 4}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
261 },
262 {
263 {1, 1, 0}, {2, 2, 0}, {3, 3, 0}, {4, 4, 0},
264 {5, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
265 {6, 8, 16}, {7, 9, 2}, {8, 10, 5}, {9, 11, 1},
266 {10, 12, 4}, {12, 14, 3}, {0, 0, 0}, {0, 0, 0},
267 },
268 {
269 {1, 1, 0}, {2, 2, 0}, {3, 3, 0}, {4, 4, 0},
270 {5, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
271 {6, 8, 16}, {7, 9, 2}, {8, 10, 5}, {9, 11, 1},
272 {10, 12, 4}, {11, 13, 15}, {12, 14, 3}, {0, 0, 0},
273 },
274 {
275 {13, 1, 0}, {14, 2, 0}, {15, 3, 0}, {16, 4, 0},
276 {5, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
277 {6, 8, 16}, {7, 9, 2}, {8, 10, 5}, {9, 11, 1},
278 {10, 12, 4}, {11, 13, 15}, {12, 14, 3}, {0, 0, 0},
279 },
280 {
281 {13, 1, 0}, {14, 2, 0}, {15, 3, 0}, {16, 4, 0},
282 {5, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
283 {6, 8, 16}, {7, 9, 2}, {20, 10, 5}, {9, 11, 1},
284 {10, 12, 4}, {11, 13, 15}, {12, 14, 3}, {0, 0, 0},
285 },
286 {
287 {13, 1, 0}, {14, 2, 0}, {15, 3, 0}, {16, 4, 0},
288 {17, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
289 {6, 8, 16}, {7, 9, 2}, {20, 10, 5}, {9, 11, 1},
290 {10, 12, 4}, {11, 13, 15}, {12, 14, 3}, {0, 0, 0},
291 },
292 {
293 {1, 1, 0}, {2, 2, 0}, {3, 3, 0}, {4, 4, 0},
294 {5, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
295 {6, 8, 16}, {19, 9, 2}, {8, 10, 5}, {9, 11, 1},
296 {22, 12, 4}, {11, 13, 15}, {12, 14, 3}, {0, 0, 0},
297 },
298 {
299 {13, 1, 0}, {14, 2, 0}, {15, 3, 0}, {16, 4, 0},
300 {17, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
301 {6, 8, 16}, {19, 9, 2}, {20, 10, 5}, {9, 11, 1},
302 {22, 12, 4}, {11, 13, 15}, {12, 14, 3}, {0, 0, 0},
303 },
304 {
305 {1, 1, 0}, {2, 2, 0}, {3, 3, 0}, {4, 4, 0},
306 {5, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
307 {6, 8, 16}, {7, 9, 2}, {8, 10, 5}, {21, 11, 1},
308 {10, 12, 4}, {23, 13, 15}, {12, 14, 3}, {0, 0, 0},
309 },
310 {
311 {13, 1, 0}, {14, 2, 0}, {15, 3, 0}, {16, 4, 0},
312 {17, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
313 {6, 8, 16}, {7, 9, 2}, {20, 10, 5}, {21, 11, 1},
314 {10, 12, 4}, {23, 13, 15}, {12, 14, 3}, {0, 0, 0},
315 },
316 {
317 {13, 1, 0}, {14, 2, 0}, {15, 3, 0}, {16, 4, 0},
318 {5, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
319 {18, 8, 16}, {19, 9, 2}, {8, 10, 5}, {21, 11, 1},
320 {22, 12, 4}, {23, 13, 15}, {12, 14, 3}, {0, 0, 0},
321 },
322 {
323 {13, 1, 0}, {14, 2, 0}, {15, 3, 0}, {16, 4, 0},
324 {17, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
325 {18, 8, 16}, {19, 9, 2}, {20, 10, 5}, {21, 11, 1},
326 {22, 12, 4}, {23, 13, 15}, {12, 14, 3}, {0, 0, 0},
327 },
328 {
329 {13, 1, 0}, {14, 2, 0}, {15, 3, 0}, {16, 4, 0},
330 {17, 5, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
331 {18, 8, 16}, {19, 9, 2}, {20, 10, 5}, {21, 11, 1},
332 {22, 12, 4}, {23, 13, 15}, {24, 14, 3}, {0, 0, 0},
333 },
334};
335/* The trainings: their name and description in the text file, and the
336 frames of their icon */
338 {0, 0, {0, 0, 0, 0}},
339 {19, 43, {0, 1, 2, 3}},
340 {20, 44, {4, 5, 6, 7}},
341 {21, 45, {8, 9, 10, 11}},
342 {22, 46, {12, 13, 14, 15}},
343 {23, 47, {16, 17, 18, 19}},
344 {29, 53, {20, 21, 22, 23}},
345 {30, 54, {24, 25, 26, 27}},
346 {31, 55, {28, 29, 30, 31}},
347 {32, 56, {32, 33, 34, 35}},
348 {33, 57, {36, 37, 38, 39}},
349 {34, 58, {40, 41, 42, 43}},
350 {35, 59, {95, 96, 97, 98}},
351 {24, 48, {45, 46, 47, 48}},
352 {25, 49, {49, 50, 51, 52}},
353 {26, 50, {53, 54, 55, 56}},
354 {27, 51, {57, 58, 59, 60}},
355 {28, 52, {61, 62, 63, 64}},
356 {36, 60, {65, 66, 67, 68}},
357 {37, 61, {71, 72, 73, 74}},
358 {38, 62, {75, 76, 77, 78}},
359 {39, 63, {79, 80, 81, 82}},
360 {40, 64, {83, 84, 85, 86}},
361 {41, 65, {87, 88, 89, 90}},
362 {42, 66, {91, 92, 93, 94}},
363};
364/* the discs number their files differently */
365#if VERSION_US || VERSION_JP
367 {591, 82, 31, 0},
368 {591, 82, 31, 0},
369 {1070, 79, 31, 0},
370 {625, 78, 27, 0},
371 {626, 79, 24, 1},
372 {627, 79, 31, 0},
373 {628, 79, 31, 0},
374 {755, 79, 31, 0},
375 {756, 81, 31, 1},
376 {1071, 79, 31, 0},
377 {629, 47, 35, 1},
378 {630, 79, 31, 0},
379 {757, 79, 31, 1},
380 {591, 82, 31, 0},
381 {1070, 79, 31, 0},
382 {625, 78, 27, 0},
383 {626, 79, 24, 1},
384 {627, 79, 31, 0},
385 {628, 79, 31, 0},
386 {755, 79, 31, 0},
387 {756, 81, 31, 1},
388 {1071, 79, 31, 0},
389 {629, 47, 35, 1},
390 {630, 79, 31, 0},
391 {757, 79, 31, 1},
392};
393#elif VERSION_EU
395 {606, 82, 31, 0},
396 {606, 82, 31, 0},
397 {1086, 79, 31, 0},
398 {640, 78, 27, 0},
399 {641, 79, 24, 1},
400 {642, 79, 31, 0},
401 {643, 79, 31, 0},
402 {770, 79, 31, 0},
403 {771, 81, 31, 1},
404 {1087, 79, 31, 0},
405 {644, 47, 35, 1},
406 {645, 79, 31, 0},
407 {772, 79, 31, 1},
408 {606, 82, 31, 0},
409 {1086, 79, 31, 0},
410 {640, 78, 27, 0},
411 {641, 79, 24, 1},
412 {642, 79, 31, 0},
413 {643, 79, 31, 0},
414 {770, 79, 31, 0},
415 {771, 81, 31, 1},
416 {1087, 79, 31, 0},
417 {644, 47, 35, 1},
418 {645, 79, 31, 0},
419 {772, 79, 31, 1},
420};
421#endif
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
signed short s16
Definition common.h:9
unsigned char u8
Definition common.h:8
#define RLEN_MAGIC
The first word of "RLEN" data, which its unpacked size follows.
Definition file.h:103
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
s32 STGTRAIN_requestFile(s32 index)
Starts loading a file of STGTRAIN_files, unless it is the one loaded.
Definition files.c:22
void STGTRAIN_freeFile(void)
Frees the loaded file of STGTRAIN_files.
Definition files.c:44
TrainEntry STGTRAIN_gymTrainings[14][16]
The trainings of each gym level, by STGTRAIN_findGymTraining: {id, stat, other}, 0 ends.
Definition files.c:249
TrainFile STGTRAIN_files[]
the discs number their files differently
Definition files.c:394
s32 STGTRAIN_readSetAnims(TrainSetHeader *header, s32 set)
The set's animations.
Definition files.c:63
s32 STGTRAIN_readSet(s32 set)
Reads an image set of the loaded file.
Definition files.c:91
TrainEntry * STGTRAIN_findGymTraining(s32 index, s32 id)
A training of a gym level, by its id.
Definition files.c:228
TrainSpriteBank * STGTRAIN_getBank(s32 set)
The sprite bank of an image set.
Definition files.c:192
TrainEntry * STGTRAIN_getGymTrainings(s32 index)
The trainings of a gym level, counting them.
Definition files.c:212
s32 STGTRAIN_getFileId(s32 index)
The file of an entry of STGTRAIN_files.
Definition files.c:177
s32 STGTRAIN_readSetImages(TrainSetHeader *header, s32 set)
The images of a set: the rest of its offsets.
Definition files.c:79
TrainInfo STGTRAIN_trainings[]
The trainings: their name and description in the text file, and the frames of their icon.
Definition files.c:337
TrainCursor STGTRAIN_animCursor
Definition files.c:431
s32 STGTRAIN_readSetBank(TrainSetHeader *header, s32 set)
The set's sprite bank, where its sprites start and its size: the two words after the set's offsets.
Definition files.c:52
u8 * STGTRAIN_getFile(void)
The requested file, or NULL while it loads.
Definition files.c:36
TrainCursor STGTRAIN_bankCursor
Definition files.c:430
s32 STGTRAIN_intensityCosts[]
the points each intensity of a training costs
Definition files.c:245
s32 STGTRAIN_getFileEffectSameDepth(s32 index)
Whether an entry of STGTRAIN_files draws its effect at the Digimon's depth.
Definition files.c:187
TrainAnim * STGTRAIN_getAnim(s32 set, s32 i)
An animation of an image set.
Definition files.c:207
TrainCursor STGTRAIN_imageCursor
Definition files.c:432
void STGTRAIN_loadImages(void)
Loads the overlay's TIM archive into VRAM.
Definition files.c:8
s32 STGTRAIN_loadSet(s32 set, s32 *pos)
Loads the images of a set into VRAM side by side, unpacking the run-length encoded ones ("RLEN") firs...
Definition files.c:112
s32 STGTRAIN_getBankSize(s32 set)
The size of an image set's sprite bank (nothing calls it)
Definition files.c:202
TrainState STGTRAIN_state
Definition files.c:422
s32 STGTRAIN_getFilePos(s32 index)
Where the image of an entry of STGTRAIN_files goes (y << 16 | x)
Definition files.c:182
s32 STGTRAIN_getBankOffset(s32 set)
Where an image set's sprites start in its bank.
Definition files.c:197
TrainCursor STGTRAIN_setCursor
Definition files.c:433
STGTRAIN.PRO: the gyms, where the partners train their stats.
void STGTRAIN_startFade(PanelAnim *fade, s32 fadeIn)
s32 STGTRAIN_updateLerp(MenuLerp *lerp)
void STGTRAIN_startLerp(MenuLerp *lerp, s32 from, s32 to, s32 frames)
#define STGTRAIN_FILE_IMAGES
Definition gym.h:21
s32 STGTRAIN_updateFade(PanelAnim *fade)
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
void(* free)(s32 file)
Definition file.h:93
void *(* load)(u32 file)
Definition file.h:92
s32(* isLoading)(s32 file)
Definition file.h:88
void(* request)(s32 file)
Definition file.h:90
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
void *(* alloc)(s32 size, s32 tag)
Definition heap.h:29
void(* zero)(void *ptr, s32 size)
Definition heap.h:32
void(* free)(void *ptr)
Definition heap.h:27
Uploads TIM images to VRAM (initTimLoader); acts on TIM_LOADER.
Definition gfx.h:325
void(* setClutPos)()
(x, y)
Definition gfx.h:337
void(* setImagePos)()
(x, y)
Definition gfx.h:336
void(* load)()
(TIM)
Definition gfx.h:335
void(* loadArchive)()
(archive): each image 64 halfwords to the right
Definition gfx.h:338
A sprite animation: its frames follow the header.
Definition gym.h:34
An entry of a gym level's trainings (STGTRAIN_gymTrainings)
Definition gym.h:326
An entry of STGTRAIN_files: a file and where its image goes.
Definition gym.h:288
s32 y
Definition gym.h:291
s32 file
Definition gym.h:289
s32 effectSameDepth
0 draws the effect one depth in front of the Digimon (STGTRAIN_updateActor)
Definition gym.h:292
s32 x
Definition gym.h:290
TrainSpriteBank * bank
Definition gym.h:299
s32 imageY
Definition gym.h:306
s32 bankOffset
Definition gym.h:300
s32 imageCount
Definition gym.h:304
s32 bankSize
in bytes
Definition gym.h:301
s32 imageX[4]
Definition gym.h:305
TrainAnim * anims[6]
Definition gym.h:302
u8 * images[4]
Definition gym.h:303
A training (STGTRAIN_trainings)
Definition gym.h:333
The header of an image set in the loaded file: offsets into it, then the bank's offset of its first s...
Definition gym.h:311
s32 images[1]
Definition gym.h:315
s32 anims[6]
Definition gym.h:314
s32 count
of the offsets
Definition gym.h:312
A sprite bank's header, as the animated sprite reads it: its sprites start bankOffset bytes from it (...
Definition gym.h:57
The overlay's helpers and the file they load (STGTRAIN_state)
Definition gym.h:340
TrainImageSet sets[9]
Definition gym.h:344
s32 fileIndex
Definition gym.h:343
s32 tableCount
the entries of the last getTable
Definition gym.h:341
u8 * data
the loaded file of STGTRAIN_files
Definition gym.h:342
void initTimLoader(TimLoader *obj)
Clears a TIM loader, gives it its methods and binds it.
Definition tim_loader.c:119
Where readSet and its helpers read the loaded file.
Definition gym.h:319
TrainSetHeader * set
Definition gym.h:322
s32 * w
Definition gym.h:321
u8 * bytes
the file's offsets count bytes from its start
Definition gym.h:320