Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
tim_loader.c
Go to the documentation of this file.
1#include "engine/game.h"
2#include <libgs.h>
3#include <libetc.h>
4#include <libsnd.h>
5
6/* Small variables, addressed through $gp (see the Makefile) */
8
9/* Makes `obj` the TIM loader the methods work on */
11 TIM_LOADER = obj;
12}
13
14/* TIM loader method: where in VRAM the next image goes */
16 TIM_LOADER->imageX = x;
17 TIM_LOADER->imageY = y;
18}
19
20/* TIM loader method: where in VRAM the next CLUT goes */
22 TIM_LOADER->clutX = x;
23 TIM_LOADER->clutY = y;
24}
25
26/* TIM loader method: sends a TIM's CLUT (4 and 8-bit images) and image to VRAM */
27void timLoaderLoad(void *tim) {
28 RECT clut;
29 RECT image;
30 TimCursor p;
31 s32 flag;
32 s32 mode;
33 s32 hasClut;
34
35 p.word = tim;
36 p.word++;
37 flag = *p.word++;
38 hasClut = flag & 8;
39 mode = flag & 7;
40 if (hasClut) {
41 switch (mode) {
42 case 0:
43 case 1:
44 clut.x = TIM_LOADER->clutX;
45 clut.y = TIM_LOADER->clutY;
46 clut.w = p.block->w;
47 clut.h = p.block->h;
48 LoadImage(&clut, p.block->pixels);
49 break;
50 }
51 p.byte += p.block->size;
52 }
53 image.x = TIM_LOADER->imageX;
54 image.y = TIM_LOADER->imageY;
55 image.w = p.block->w;
56 image.h = p.block->h;
57 LoadImage(&image, p.block->pixels);
58 TIM_LOADER->w = image.w;
59 TIM_LOADER->h = image.h;
60}
61
62/*
63 * TIM loader method: loads every TIM of an archive side by side, 0x40 halfwords apart, unpacking
64 * the RLEN ones
65 */
66void timLoaderLoadArchive(void *archive) {
68 s32 i;
69 s32 compressed;
70 u8 *data;
71 u8 *src;
72 u8 *dst;
73 s32 c;
74 s32 n;
75 s32 k;
76
77 for (i = 0;; i++) {
78 data = FILE_CACHE.getArchiveEntry(i, archive);
79 /* the table ends with an offset of 0: the entry is the archive itself */
80 if (data == archive) {
81 break;
82 }
83 src = data;
84 compressed = *(u32 *)src == RLEN_MAGIC; /* the entry's first word */
85 dst = data;
86 if (compressed) {
87 dst = buf;
88 src += 8;
89 while ((c = *src) != 0) {
90 if (c & 0x80) {
91 n = c & 0x7F;
92 src++;
93 for (k = 0; k < n; k++) {
94 *dst++ = *src;
95 }
96 src++;
97 } else {
98 n = *src++;
99 for (k = 0; k < n; k++) {
100 *dst++ = *src++;
101 }
102 }
103 }
104 dst = buf;
105 }
106 timLoaderLoad(dst);
107 DrawSync(0);
108 TIM_LOADER->imageX += 0x40;
109 }
110 HEAP.free(buf);
111}
112
113/* TIM loader method: the buffer that RLEN TIMs are unpacked to */
115 TIM_LOADER->bufferSize = size;
116}
117
118/* Clears a TIM loader, gives it its methods and binds it */
120 HEAP.zero(obj, sizeof(TimLoader));
121 obj->load = timLoaderLoad;
124 obj->bind = bindTimLoader;
127 bindTimLoader(obj);
128 obj->bufferSize = 0xA800;
129}
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
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
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
#define MEM_MODE
the current mode's: freed by main whenever the mode task ends
Definition heap.h:17
void *(* getArchiveEntry)(s32 index, void *archive)
Definition file.h:97
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
u16 h
Definition gfx.h:312
u_long pixels[0]
Definition gfx.h:313
u16 w
in halfwords
Definition gfx.h:311
u32 size
in bytes, this header included
Definition gfx.h:308
Uploads TIM images to VRAM (initTimLoader); acts on TIM_LOADER.
Definition gfx.h:325
s32 bufferSize
for the RLE-compressed images
Definition gfx.h:333
void(* setClutPos)()
(x, y)
Definition gfx.h:337
s32 clutY
Definition gfx.h:332
s32 imageX
Definition gfx.h:329
void(* setImagePos)()
(x, y)
Definition gfx.h:336
void(* setBufferSize)()
(size)
Definition gfx.h:339
void(* load)()
(TIM)
Definition gfx.h:335
u16 w
size of the last image
Definition gfx.h:326
void(* loadArchive)()
(archive): each image 64 halfwords to the right
Definition gfx.h:338
s32 clutX
Definition gfx.h:331
u16 h
Definition gfx.h:327
void(* bind)()
(loader)
Definition gfx.h:334
s32 imageY
Definition gfx.h:330
void bindTimLoader(TimLoader *obj)
Makes obj the TIM loader the methods work on.
Definition tim_loader.c:10
void timLoaderSetImagePos(s32 x, s32 y)
TIM loader method: where in VRAM the next image goes.
Definition tim_loader.c:15
static TimLoader * TIM_LOADER
Small variables, addressed through $gp (see the Makefile)
Definition tim_loader.c:7
void timLoaderSetClutPos(s32 x, s32 y)
TIM loader method: where in VRAM the next CLUT goes.
Definition tim_loader.c:21
void timLoaderLoad(void *tim)
TIM loader method: sends a TIM's CLUT (4 and 8-bit images) and image to VRAM.
Definition tim_loader.c:27
void initTimLoader(TimLoader *obj)
Clears a TIM loader, gives it its methods and binds it.
Definition tim_loader.c:119
void timLoaderLoadArchive(void *archive)
TIM loader method: loads every TIM of an archive side by side, 0x40 halfwords apart,...
Definition tim_loader.c:66
void timLoaderSetBufferSize(s32 size)
TIM loader method: the buffer that RLEN TIMs are unpacked to.
Definition tim_loader.c:114
Where timLoaderLoad is in a TIM: its words, then its blocks, which their sizes in bytes take it past.
Definition gfx.h:318
u8 * byte
Definition gfx.h:320
u_long * word
Definition gfx.h:319
TimBlock * block
Definition gfx.h:321