Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
gfx.h
Go to the documentation of this file.
1#ifndef DW3_GFX_H
2#define DW3_GFX_H
3
4/* Display, drawing layers, the drawing helpers and the screen fade (gfx/) */
5
6#include "common.h"
7#include <sys/types.h>
8#include <libgte.h>
9#include <libgpu.h>
10#include "engine/task.h"
11
12typedef struct Layer Layer;
13typedef struct DrawCallback DrawCallback;
14
15/* The graphics methods (GFX.funcs) */
16typedef struct GfxFuncs {
17 /* 0x00 */ void (*reset)(void);
18 /* 0x04 */ void (*allocPrimBuffers)(s32 size);
19 /* 0x08 */ void *(*getPrim)(void);
20 /* 0x0C */ void (*setPrim)(void *next);
21 /* 0x10 */ void (*freePrimBuffers)(void);
22 /* 0x14 */ void (*startVSync)(void);
23 /* 0x18 */ void (*drawFrame)();
24 /* 0x1C */ struct Layer *(*createLayer)(RECT *rect, s32 otShift, s32 id);
25 /* 0x20 */ s32 (*destroyLayer)(s32 id);
26 /* 0x24 */ void (*setDisplayMode)(s32 w, s32 h, s32 hires, s32 interlace);
27 /* 0x28 */ void (*setDisplayArea)();
28 /* 0x2C */ struct Layer *(*getLayer)(s32 id);
29 /* 0x30 */ void (*moveLayer)();
30 /* 0x34 */ s32 (*getFrameCount)(void);
31 /* 0x38 */ s32 (*getTime)(void);
32 /* 0x3C */ s32 (*getFrameTime)(void);
33} GfxFuncs;
34
35/* The screen the modes draw on (setDisplayMode, their layers' rects) */
36#define SCREEN_WIDTH 320
37#define SCREEN_HEIGHT 240
38
39/* The drawing layers GFX holds at most */
40#define LAYER_COUNT 30
41
42/* The layer over the whole screen that most modes create first and draw
43 their menus on (FIELDSTG and STDWTITL name theirs: FIELD_LAYER_BACK,
44 STDWTITL_TITLE_LAYER); the ones they add next take 0x1001 and up */
45#define SCREEN_LAYER 0x1000
46
47/*
48 * What a vsync adds to the 8.8 time counters: a frame of the 60 Hz game,
49 * or 1.2 of them at 50 Hz so that the game keeps its pace
50 */
51#define VSYNC_STEP_NTSC 0x100
52#define VSYNC_STEP_PAL 0x133
53
54/*
55 * The graphics state: double-buffered display, the GPU packet buffers that
56 * primitives are written to (getPrim/setPrim), and up to LAYER_COUNT drawing layers,
57 * each with its own ordering table, drawn in order by drawFrame.
58 * Times are in vsyncs; the counters keep 8 fractional bits.
59 */
60typedef struct GfxState {
61 /* 0x00 */ void (*vsyncFunc)(s32 arg);
62 /* 0x04 */ s32 vsyncArg;
63 /* 0x08 */ s32 frameCount;
64 /* 0x0C */ s32 frameCounter;
65 /* 0x10 */ s32 time; /* vsyncs since boot */
66 /* 0x14 */ s32 timeCounter;
67 /* 0x18 */ s32 frameTime; /* vsyncs that the last frame took */
69 /* 0x20 */ void *prim; /* next free byte of the packet buffer */
70 /* 0x24 */ void *primBufs[2];
71 /* 0x2C */ s32 primBufSize;
72 /* 0x30 */ s32 dispBuffer;
73 /* 0x34 */ s32 buffer; /* the one being drawn */
74 /* 0x38 */ DISPENV disp[2];
75 /* 0x60 */ struct Layer *layers[LAYER_COUNT];
77 /* 0x150 */ GfxFuncs funcs;
78} GfxState;
79
80/* Layer as its clip/scroll methods see it: the clip rect as unsigned */
81typedef struct LayerView {
82 /* 0x00 */ s16 x;
83 /* 0x02 */ s16 y;
84 /* 0x04 */ u16 w;
85 /* 0x06 */ u16 h;
86 /* 0x08 */ s16 ofs[2]; /* DRAWENV's fields on (Layer.env) */
87 /* 0x0C */ RECT tw;
88 /* 0x14 */ u16 tpage;
89 /* 0x16 */ u8 dtd;
90 /* 0x17 */ u8 dfe;
91 /* 0x18 */ u8 isbg;
92 /* 0x19 */ u8 bgR;
93 /* 0x1A */ u8 bgG;
94 /* 0x1B */ u8 bgB;
95 /* 0x1C */ DR_ENV drEnv;
96 /* 0x5C */ u_long *ot[2];
97 /* 0x64 */ s32 otLen;
98 /* 0x68 */ s32 otShift;
99 /* 0x6C */ s16 offsetX;
100 /* 0x6E */ s16 offsetY;
101 /* 0x70 */ s32 scrollX;
102 /* 0x74 */ s32 scrollY;
103 /* 0x78 */ s32 callbackCap;
104 /* 0x7C */ s32 callbackCount;
106} LayerView;
107
108typedef struct Rect16 {
113} Rect16;
114
115/* A function that a layer calls when it is drawn (Layer.addDrawCallback) */
117 /* 0x00 */ s32 priority;
118 /* 0x04 */ s32 param;
119 /* 0x08 */ void (*func)(s32 arg, void *layer, s32 param);
120 /* 0x0C */ s32 arg;
121 /* 0x10 */ struct DrawCallback *next;
122};
123
124/*
125 * A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering
126 * tables, one per buffer, a scroll position and a list of draw callbacks.
127 */
128struct Layer {
129 /* 0x00 */ DRAWENV env;
130 /* 0x5C */ u_long *ot[2];
131 /* 0x64 */ s32 otLen;
132 /* 0x68 */ s32 otShift;
133 /* 0x6C */ s16 offsetX;
134 /* 0x6E */ s16 offsetY;
135 /* 0x70 */ s32 scrollX;
136 /* 0x74 */ s32 scrollY;
137 /* 0x78 */ s32 callbackCap;
138 /* 0x7C */ s32 callbackCount;
140 /* 0x84 */ s32 keepView;
141 /* 0x88 */ s32 projection;
142 /* 0x8C */ MATRIX view[2];
144 /* 0xD0 */ MATRIX lightMatrix[2];
145 /* 0x110 */ void (*setClipPos)(); /* no prototype: callers would truncate s16 args */
146 /* 0x114 */ void (*setClipSize)(); /* no prototype: callers would truncate s16 args */
147 /* 0x118 */ void (*setOffset)(); /* no prototype: callers would truncate s16 args */
148 /* 0x11C */ void (*getScroll)();
149 /* 0x120 */ void (*setScroll)();
150 /* 0x124 */ void (*addScroll)();
151 /* 0x128 */ void (*getViewRect)();
152 /* 0x12C */ void (*setBgColor)(); /* no prototype: callers would truncate u8 args */
153 /* 0x130 */ void (*draw)(struct Layer *);
154 /* 0x134 */ void (*clearOt)(struct Layer *);
155 /* 0x138 */ u_long *(*getOtEntry)(struct Layer *, s32 depth);
156 /* 0x13C */ u_long *(*getOtEntryZ)(struct Layer *layer, s32 z);
157 /* 0x140 */ u_long *(*getOt)(struct Layer *);
158 /* 0x144 */ s32 (*getOtShift)();
159 /* 0x148 */ void (*allocCallbacks)();
160 /* 0x14C */ void (*addSortedCallback)();
161 /* 0x150 */ void (*addCallback)();
162 /* 0x154 */ void (*runCallbacks)(struct Layer *);
163 /* 0x158 */ void (*loadView)(struct Layer *);
164 /* 0x15C */ void (*setKeepView)();
165 /* 0x160 */ void (*loadLightMatrix)(struct Layer *);
166 /* 0x164 */ void (*setKeepLightMatrix)();
167 /* 0x168 */ void (*free)(struct Layer *);
168};
169
170/* A card's image (CardDrawer.card): 64 to a file, a 12-byte header and a
171 32x32 8-bit TIM */
172typedef struct CardImage {
173 /* 0x0 */ u8 color; /* from 1 */
174 /* 0x1 */ u8 ap;
175 /* 0x2 */ u8 hp;
176 /* 0x3 */ u8 kind; /* an index in CARD_KINDS */
177 /* 0x4 */ u8 unused4; /* 1-4 on the 60 option cards (a colour's first 4, its last two 1), 0 on the
178 Digimon; nothing reads it */
179 /* 0x5 */ u8 points; /* what it adds to its colour */
180 /* 0x6 */ u8 level; /* a Digimon's, 2-5 (CARDGAME shows its name); 0 on the other cards */
181 /* 0x7 */ u8 pad7; /* 0 on every card; nothing reads it */
182 /* 0x8 */ s16 rank; /* by strength, from 1 the strongest (0 on the two blank cards) */
183 /* 0xA */ s16 comboCard; /* the card (from 1) that three or more of it make
184 (CARDGAME_findCardSet), 0 for none */
185 /* 0xC */ u8 tim[0x620]; /* its header, a 256-colour CLUT block and the image block */
186} CardImage;
187
188/*
189 * Draws the cards' images (CardImage), from files 0x7E7-0x7EB. There are 320
190 * of them (the save has counts for 317). The methods act on the drawer that
191 * was set up last (CARD_DRAWER).
192 */
193typedef struct CardDrawer {
194 /* 0x00 */ CardImage *card;
195 /* 0x04 */ s32 imageX; /* VRAM position of the image grid */
196 /* 0x08 */ s32 imageY;
197 /* 0x0C */ s32 clutX;
198 /* 0x10 */ s32 clutY;
199 /* 0x14 */ s32 cellX; /* grid cell: 32x32 pixels, one CLUT row each */
200 /* 0x18 */ s32 cellY;
201 /* 0x1C */ s32 clutStride;
202 /* 0x20 */ s32 semiTrans;
203 /* 0x24 */ Layer *layer;
204 /* 0x28 */ u_long *ot;
205 /* 0x2C */ void (*setCard)(); /* (id) */
206 /* 0x30 */ void (*loadImage)();
207 /* 0x34 */ void (*draw)(); /* (x, y) */
208 /* 0x38 */ void (*setLayer)(); /* (id, depth) */
209 /* 0x3C */ void (*setImagePos)(); /* (x, y) */
210 /* 0x40 */ void (*setClutPos)(); /* (x, y) */
211 /* 0x44 */ void (*setCell)(); /* (x, y) */
212 /* 0x48 */ void (*setClutStride)(); /* (stride) */
213 /* 0x4C */ void (*setSemiTrans)(); /* (on) */
214 /* 0x50 */ s32 (*getKind)(void);
215} CardDrawer;
216
217/*
218 * Draws sprites from a sprite sheet (such as file 0x277, the menu graphics):
219 * a sheet has a table of frames, each made of textured parts, and can be
220 * scaled, rotated and tinted. Set up on the stack with initSpriteDrawer; its
221 * methods act on the drawer that was set up last (SPRITE_DRAWER).
222 */
223typedef struct SpriteDrawer {
224 /* 0x00 */ Layer *layer;
225 /* 0x04 */ u_long *ot;
226 /* 0x08 */ s32 tpageX; /* VRAM position of the sheet's texture */
227 /* 0x0C */ s32 tpageY;
228 /* 0x10 */ s32 clutX;
229 /* 0x14 */ s32 clutY;
230 /* 0x18 */ s32 altClutX; /* for the parts that are flagged */
231 /* 0x1C */ s32 altClutY;
232 /* 0x20 */ s32 clutRow; /* added to the CLUT y: palette animations */
233 /* 0x24 */ s32 followScroll; /* offset by the layer's scroll */
234 /* 0x28 */ CVECTOR color;
235 /* 0x2C */ s32 transformDirty;
236 /* 0x30 */ s32 pivotX;
237 /* 0x34 */ s32 pivotY;
238 /* 0x38 */ VECTOR scale; /* ScaleMatrix's */
239 /* 0x48 */ SVECTOR rot;
240 /* 0x50 */ MATRIX matrix;
241 /* 0x70 */ void (*bind)(); /* (drawer) */
242 /* 0x74 */ void (*setTexture)(); /* (x, y) */
243 /* 0x78 */ void (*setAltClut)(); /* (x, y) */
244 /* 0x7C */ void (*setLayerId)(); /* (id, depth) */
245 /* 0x80 */ void (*setLayer)(); /* (layer, depth) */
246 /* 0x84 */ void (*draw)(); /* (sheet, frame, x, y) */
247 /* 0x88 */ void (*setClutRow)(); /* (row) */
248 /* 0x8C */ void (*setScale)(); /* (x, y, z), ONE = 1.0 */
249 /* 0x90 */ void (*setRotation)(); /* (x, y, z); no prototype: callers would truncate s16 args */
250 /* 0x94 */ void (*setPivot)(); /* (x, y) */
251 /* 0x98 */ void (*setFollowScroll)(); /* (on) */
252 /* 0x9C */ void (*setColor)(); /* (CVECTOR *) */
254
255/*
256 * Stretch the drawer's next sprites by a fade level about the pivot (x, y)
257 * while the level is below ONE (a panel opening or closing), else draw them
258 * at full size. STRETCH_SPRITE stretches the width, STRETCH_SPRITE_V the
259 * height and ZOOM_SPRITE both. The game reads the level again at each use,
260 * so level must have no side effects; a static inline that reads it once
261 * does not match, which suggests the original was a macro too.
262 * A bare if/else, not do { } while (0): that wrapper changes GCC 2.8.1's
263 * code at most of the uses. It ends in its own else, whose statement takes
264 * the caller's ';', so it stays one statement as the unbraced body of an
265 * if/else too (no dangling else); it can't be used as an expression.
266 */
267#define STRETCH_SPRITE_BY(sprite, level, scaleX, scaleY, x, y) \
268 if ((level) != ONE) { \
269 (sprite).setScale(scaleX, scaleY, ONE); \
270 (sprite).setPivot(x, y); \
271 } else \
272 (sprite).setScale(ONE, ONE, ONE)
273#define STRETCH_SPRITE(sprite, level, x, y) STRETCH_SPRITE_BY(sprite, level, level, ONE, x, y)
274#define STRETCH_SPRITE_V(sprite, level, x, y) STRETCH_SPRITE_BY(sprite, level, ONE, level, x, y)
275#define ZOOM_SPRITE(sprite, level, x, y) STRETCH_SPRITE_BY(sprite, level, level, level, x, y)
276
277/*
278 * One part of a sprite sheet, a rectangle of its texture. A sheet starts with
279 * three offsets from its start: to its parts, to the list of its frame ids
280 * (bytes) and to its first frame, followed by those of the other frames. A
281 * frame is three s16, the part count, a CLUT row added to the parts' and the
282 * semi-transparency rate (-1: opaque), then an s16 part index, x and y for
283 * each part; they are drawn from the last to the first.
284 */
285typedef struct SpritePart {
286 /* 0x0 */ s16 u;
287 /* 0x2 */ s16 v;
288 /* 0x4 */ s16 w;
289 /* 0x6 */ s16 h;
290 /* 0x8 */ s16 clutX; /* added to the drawer's CLUT position */
291 /* 0xA */ s16 clutY;
292 /* 0xC */ s16 mode; /* 0: 4-bit texture, 1: 8-bit, with the drawer's other CLUT */
293} SpritePart;
294
295/* One frame of a sprite animation; frame 0xFF ends it (or loops it) */
296typedef struct AnimFrame {
297 /* 0x0 */ s16 frame;
298 /* 0x2 */ s16 duration;
299} AnimFrame;
300
301typedef struct AnimState {
302 /* 0x0 */ s16 index;
303 /* 0x2 */ s16 timer;
304} AnimState;
305
306/* A TIM's CLUT or image block */
307typedef struct TimBlock {
308 /* 0x0 */ u32 size; /* in bytes, this header included */
309 /* 0x4 */ u16 x;
310 /* 0x6 */ u16 y;
311 /* 0x8 */ u16 w; /* in halfwords */
312 /* 0xA */ u16 h;
313 /* 0xC */ u_long pixels[FLEXIBLE];
314} TimBlock;
315
316/* Where timLoaderLoad is in a TIM: its words, then its blocks, which their
317 sizes in bytes take it past */
318typedef union TimCursor {
319 u_long *word;
322} TimCursor;
323
324/* Uploads TIM images to VRAM (initTimLoader); acts on TIM_LOADER */
325typedef struct TimLoader {
326 /* 0x00 */ u16 w; /* size of the last image */
327 /* 0x02 */ u16 h;
328 /* 0x04 */ u8 pad4[4]; /* never read or written */
329 /* 0x08 */ s32 imageX;
330 /* 0x0C */ s32 imageY;
331 /* 0x10 */ s32 clutX;
332 /* 0x14 */ s32 clutY;
333 /* 0x18 */ s32 bufferSize; /* for the RLE-compressed images */
334 /* 0x1C */ void (*bind)(); /* (loader) */
335 /* 0x20 */ void (*load)(); /* (TIM) */
336 /* 0x24 */ void (*setImagePos)(); /* (x, y) */
337 /* 0x28 */ void (*setClutPos)(); /* (x, y) */
338 /* 0x2C */ void (*loadArchive)(); /* (archive): each image 64 halfwords to the right */
339 /* 0x30 */ void (*setBufferSize)(); /* (size) */
340} TimLoader;
341
342/* The next free primitive of the packet buffer (getPrim), written as the
343 kind that is drawn next */
344typedef union PrimPtr {
345 void *any;
346 SPRT *sprt;
347 POLY_F4 *f4;
348 POLY_FT4 *ft4;
349 DR_TPAGE *tpage;
350} PrimPtr;
351
352typedef struct Vec2 {
355} Vec2;
356
357/* ScreenFade.level when the screen is black: 0xFF in 8.8 fixed point */
358#define FADE_LEVEL_MAX 0xFF00
359
360/* Fades the whole screen to black and back with a subtractive rectangle */
361typedef struct ScreenFade {
363 /* 0x50 */ s32 layerId;
364 /* 0x54 */ s32 depth;
365 /* 0x58 */ s32 fadeIn; /* 0: to black */
366 /* 0x5C */ s32 level; /* 0-FADE_LEVEL_MAX */
367 /* 0x60 */ s32 levelStep;
368 /* 0x64 */ void (*start)(struct ScreenFade *fade, s32 fadeIn, s32 frames); /* TASK_DONE when done */
369} ScreenFade;
370
371Layer *getLayer(s32 id);
372Layer *createLayer(RECT *rect, s32 otShift, s32 id);
374void moveLayer(s32 id, s32 targetId, s32 delta);
375void layerClearOt(Layer *layer);
376u_long *layerGetOtEntryZ(Layer *layer, s32 z);
377u_long *layerGetOt(Layer *layer);
379void layerSetBgColor(LayerView *layer, s32 r, s32 g, s32 b); /* old-style: u8 r, g, b */
380void layerSetOffset(LayerView *layer, s32 x, s32 y); /* old-style: s16 x, y */
381void layerGetScroll(LayerView *layer, Vec2 *out);
382void layerSetScroll(LayerView *layer, s32 x, s32 y);
383void layerAddScroll(LayerView *layer, s32 dx, s32 dy);
384void layerSetClipPos(LayerView *layer, s32 x, s32 y); /* old-style: s16 x, y */
385void layerSetClipSize(LayerView *layer, s32 w, s32 h); /* old-style: s16 w, h */
386void layerGetViewRect(LayerView *layer, Rect16 *rect);
387void layerFree(Layer *layer);
388void layerResetCallbacks(Layer *layer);
389void layerAllocCallbacks(Layer *layer, s32 count);
390void layerAddSortedCallback(Layer *layer, void (*func)(s32, void *, s32), s32 arg, s32 priority, s32 param);
391void layerAddCallback(Layer *layer, void (*func)(s32, void *, s32), s32 arg);
392void layerRunCallbacks(Layer *layer);
393void layerSetKeepView(Layer *layer, s32 enable, s32 projection);
394void layerLoadView(Layer *layer);
395void layerSetKeepLightMatrix(Layer *layer, s32 enable);
396void layerLoadLightMatrix(Layer *layer);
397void layerSkipEmptyOt(Layer *layer);
398void layerDraw(Layer *layer);
399u_long *layerGetOtEntry(Layer *layer, s32 depth);
400Layer *newLayer(DRAWENV *env, s32 otShift);
402void removeLayerSlot(s32 index);
403void insertLayerSlot(s32 index, Layer *layer, s32 id);
404void initTimLoader(TimLoader *obj);
405void vsyncCallback(void);
406void startVSyncCallback(void);
407void drawFrame(s32 draw);
408s32 getFrameCount(void);
409s32 getTime(void);
410s32 getFrameTime(void);
411void resetGraphics(void);
412void allocPrimBuffers(s32 size);
413void *getPrim(void);
414void setPrim(void *next);
415void freePrimBuffers(void);
416void setDisplayMode(s32 w, s32 h, s32 hires, s32 interlace);
417void setDisplayArea(s32 x, s32 y, s32 w, s32 h);
418void bindCardDrawer(CardDrawer *obj);
419void cardDrawerSetCard(s32 id);
420void cardDrawerLoadImage(void);
422void cardDrawerSetImagePos(s32 x, s32 y);
423void cardDrawerSetClutPos(s32 x, s32 y);
424void cardDrawerSetCell(s32 x, s32 y);
425void cardDrawerSetClutStride(s32 stride);
427void cardDrawerDraw(s32 x, s32 y);
433void spriteDrawerSetLayer(Layer *layer, s32 arg1);
435void spriteDrawerDraw(s32 *sheet, s32 frame, s32 x, s32 y);
436void spriteDrawerSetScale(s32 x, s32 y, s32 z);
437void spriteDrawerSetRotation(s32 x, s32 y, s32 z); /* old-style: s16 x, y, z */
438void spriteDrawerSetPivot(s32 x, s32 y);
440void spriteDrawerSetColor(CVECTOR *color);
441void bindTimLoader(TimLoader *obj);
442void timLoaderSetImagePos(s32 x, s32 y);
443void timLoaderSetClutPos(s32 x, s32 y);
444void timLoaderLoad(void *tim);
445void timLoaderLoadArchive(void *archive);
446void timLoaderSetBufferSize(s32 size);
447void initSpriteDrawer(struct SpriteDrawer *obj);
448void initCardDrawer(CardDrawer *obj);
449void screenFadeStart(ScreenFade *task, s32 fadeIn, s32 duration);
451void drawScreenFade(struct ScreenFade *task);
452void updateScreenFade(struct ScreenFade *task);
453
454extern s16 OT_LENGTHS[];
455extern s32 CARD_IMAGE_FILES[];
456extern GfxState GFX;
457#if PAL_VIDEO
458/* The European version runs at 50 Hz (PAL) unless NTSC_MODE is set; its
459 clocks then advance 0x133, 60/50 of 0x100, per frame */
460extern s32 NTSC_MODE;
461extern s32 SHIFT_PAL_SCREEN; /* moves both display areas 0x18 lines down */
462#endif
463extern s32 CARD_KINDS[];
464
465#endif /* DW3_GFX_H */
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
#define FLEXIBLE
The length of an array that ends a struct and runs as far as each object of it needs: s32 seps[FLEXIB...
Definition common.h:29
signed short s16
Definition common.h:9
unsigned short u16
Definition common.h:10
unsigned char u8
Definition common.h:8
The task system and its registry (task/)
#define TASK_HEADER(Type)
Definition task.h:39
void spriteDrawerSetLayer(Layer *layer, s32 arg1)
Sprite drawer method: the layer and depth to draw to.
u_long * layerGetOtEntryZ(Layer *layer, s32 z)
Layer method: the OT entry for a 16-bit Z, scaled to the OT's length.
Definition layer.c:159
void layerLoadLightMatrix(Layer *layer)
Layer method: restores the light matrix that setKeepLightMatrix kept.
Definition layer.c:380
void * getPrim(void)
The next free byte of the packet buffer being drawn.
Definition display.c:150
void allocPrimBuffers(s32 size)
Allocates the two GPU packet buffers, size bytes each, at the end of the heap.
Definition display.c:142
void freePrimBuffers(void)
Frees the two packet buffers.
Definition display.c:160
void bindTimLoader(TimLoader *obj)
Makes obj the TIM loader the methods work on.
Definition tim_loader.c:10
s32 CARD_IMAGE_FILES[]
The card images, 64 cards to a file (cardDrawerSetCard), numbered in the Japanese disc as in the USA ...
void layerClearOt(Layer *layer)
Layer method: clears the OT of the buffer being drawn.
Definition layer.c:106
void spriteDrawerSetFollowScroll(s32 on)
Sprite drawer method: whether the sprites move with the layer's scroll.
void timLoaderSetImagePos(s32 x, s32 y)
TIM loader method: where in VRAM the next image goes.
Definition tim_loader.c:15
void layerFree(Layer *layer)
Layer method: frees its OTs and draw callbacks, once the GPU is done with them.
Definition layer.c:253
s32 cardDrawerGetKind(void)
Card drawer method: the kind of the current card (CARD_KINDS)
void setDisplayArea(s32 x, s32 y, s32 w, s32 h)
Shows the same VRAM area from both display buffers.
Definition display.c:203
void cardDrawerSetClutPos(s32 x, s32 y)
Card drawer method: the VRAM area of the CLUTs.
Definition card_drawer.c:56
void layerRunCallbacks(Layer *layer)
Layer method: runs the draw callbacks in order, then empties the list.
Definition layer.c:341
s32 findLayerSlot(s32 id)
The slot of the layer with this id; id 0 finds a free slot.
Definition layer.c:19
void layerSkipEmptyOt(Layer *layer)
Links every run of empty OT entries past itself, so the GPU skips it.
Definition layer.c:111
void drawScreenFade(struct ScreenFade *task)
A full-screen POLY_F4 with subtractive blending (tpage 0xE1000245)
Definition screen_fade.c:24
void layerAddCallback(Layer *layer, void(*func)(s32, void *, s32), s32 arg)
Layer method: adds a draw callback at the end of the list.
Definition layer.c:323
s32 NTSC_MODE
The European version runs at 50 Hz (PAL) unless NTSC_MODE is set; its clocks then advance 0x133,...
Definition eu_settings.c:14
void insertLayerSlot(s32 index, Layer *layer, s32 id)
Puts a layer at position index of the draw order, moving the later ones back.
Definition layer.c:43
u_long * layerGetOtEntry(Layer *layer, s32 depth)
Layer method: the OT entry at depth in the buffer being drawn.
Definition layer.c:154
void cardDrawerSetLayer(s32 id, s32 depth)
Card drawer method: the layer and depth to draw to.
Definition card_drawer.c:42
ScreenFade * createScreenFade(s32 layerId)
A screen fade task on a layer, idle until started.
Definition screen_fade.c:76
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
void vsyncCallback(void)
Every vsync: advances the time counters and the play time, runs GFX.vsyncFunc, shows the finished buf...
Definition display.c:14
void layerDraw(Layer *layer)
Layer method: sends the OT of the finished buffer, after its DRAWENV with the layer's offset.
Definition layer.c:130
void cardDrawerDraw(s32 x, s32 y)
Card drawer method: draws the card of the current cell at (x, y), a 32x32 sprite.
Definition card_drawer.c:78
void layerGetScroll(LayerView *layer, Vec2 *out)
Layer method: the scroll position, in pixels.
Definition layer.c:207
void spriteDrawerSetClutRow(s32 row)
Sprite drawer method: the CLUT row added to every part's.
void drawFrame(s32 draw)
Ends a frame: lets the layers run their draw callbacks, waits for the GPU and for the vsync that show...
Definition display.c:51
void layerAddSortedCallback(Layer *layer, void(*func)(s32, void *, s32), s32 arg, s32 priority, s32 param)
Layer method: adds a draw callback in order of priority, highest first.
Definition layer.c:280
void timLoaderSetClutPos(s32 x, s32 y)
TIM loader method: where in VRAM the next CLUT goes.
Definition tim_loader.c:21
void spriteDrawerSetColor(CVECTOR *color)
Sprite drawer method: the color the sprites are tinted with.
Layer * getLayer(s32 id)
The layer with id id, or NULL.
Definition layer.c:7
void spriteDrawerSetTexture(s32 x, s32 y)
Sprite drawer method: the VRAM position of the sheet's texture and CLUTs.
s32 SHIFT_PAL_SCREEN
moves both display areas 0x18 lines down
Definition eu_settings.c:15
void layerSetScroll(LayerView *layer, s32 x, s32 y)
Layer method: sets the scroll position (8.8 fixed point)
Definition layer.c:213
u_long * layerGetOt(Layer *layer)
Layer method: the OT of the buffer being drawn.
Definition layer.c:166
void cardDrawerSetCard(s32 id)
Card drawer method: picks the image of card id (0 or less: the first image of the first file)
Definition card_drawer.c:17
void layerGetViewRect(LayerView *layer, Rect16 *rect)
Layer method: the part of the scrolled world the clip rectangle shows.
Definition layer.c:245
void layerSetClipSize(LayerView *layer, s32 w, s32 h)
old-style: s16 w, h
void bindCardDrawer(CardDrawer *obj)
Makes obj the card drawer the methods work on.
Definition card_drawer.c:10
void screenFadeStart(ScreenFade *task, s32 fadeIn, s32 duration)
Starts fading the screen to black (fadeIn 0) or back, over duration frames.
Definition screen_fade.c:4
s32 destroyLayer(s32 id)
Frees the layer with id id; 0 if there is none.
Definition layer.c:71
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 spriteDrawerSetScale(s32 x, s32 y, s32 z)
Sprite drawer method: scales the sprites (ONE: as they are)
s32 layerGetOtShift(LayerView *layer)
Layer method: the OT size it was created with.
Definition layer.c:171
void cardDrawerLoadImage(void)
Card drawer method: loads the card's image and CLUT into its cell of VRAM.
Definition card_drawer.c:32
#define LAYER_COUNT
The drawing layers GFX holds at most.
Definition gfx.h:40
void resetGraphics(void)
Destroys every layer and clears the packet buffers' state; the first call just picks the buffers.
Definition display.c:123
void layerAllocCallbacks(Layer *layer, s32 count)
Layer method: room for count draw callbacks.
Definition layer.c:273
s32 CARD_KINDS[]
cardDrawerGetKind's kinds, by a card image's byte 3
void bindSpriteDrawer(SpriteDrawer *obj)
Makes obj the sprite drawer the methods work on.
void spriteDrawerSetLayerId(s32 id, s32 depth)
Sprite drawer method: the layer (by id) and depth to draw to.
Layer * newLayer(DRAWENV *env, s32 otShift)
Allocates a layer with its two OTs and methods.
Definition layer.c:385
s32 getTime(void)
The vsyncs since boot (in 60 Hz frames)
Definition display.c:111
void initTimLoader(TimLoader *obj)
Clears a TIM loader, gives it its methods and binds it.
Definition tim_loader.c:119
void setPrim(void *next)
Moves the packet buffer's free pointer past the primitives just written.
Definition display.c:155
void cardDrawerSetSemiTrans(s32 on)
Card drawer method: draws semi-transparent, or not.
Definition card_drawer.c:73
void setDisplayMode(s32 w, s32 h, s32 hires, s32 interlace)
Sets up the two display buffers: side by side in hi-res (interlaced 320x480 24-bit),...
Definition display.c:175
void layerSetKeepLightMatrix(Layer *layer, s32 enable)
Layer method: keeps the current light matrix for this buffer's drawing.
Definition layer.c:372
void layerSetOffset(LayerView *layer, s32 x, s32 y)
old-style: s16 x, y
void layerResetCallbacks(Layer *layer)
Layer method: empties the draw callbacks, but for the head entry, which sorts first.
Definition layer.c:263
void layerSetBgColor(LayerView *layer, s32 r, s32 g, s32 b)
old-style: u8 r, g, b
void cardDrawerSetCell(s32 x, s32 y)
Card drawer method: the cell a card is loaded to and drawn from.
Definition card_drawer.c:62
s16 OT_LENGTHS[]
A layer's ordering table length, by its otShift - 1.
Definition layer.c:422
void updateScreenFade(struct ScreenFade *task)
Moves the fade one frame on and draws it; TASK_DONE at the end, still drawn.
Definition screen_fade.c:46
void spriteDrawerSetPivot(s32 x, s32 y)
Sprite drawer method: the point the sprites scale and rotate around.
s32 getFrameCount(void)
The frames drawn since boot.
Definition display.c:106
void layerSetClipPos(LayerView *layer, s32 x, s32 y)
old-style: s16 x, y
Layer * createLayer(RECT *rect, s32 otShift, s32 id)
A new layer drawing to rect, with an OT of OT_LENGTHS[otShift - 1] entries; NULL when all are in use.
Definition layer.c:58
void initSpriteDrawer(struct SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
void spriteDrawerSetRotation(s32 x, s32 y, s32 z)
old-style: s16 x, y, z
void spriteDrawerSetAltClut(s32 x, s32 y)
Sprite drawer method: the other CLUT area, for parts that ask for it.
void cardDrawerSetClutStride(s32 stride)
Card drawer method: the CLUT rows between two columns of cells.
Definition card_drawer.c:68
s32 getFrameTime(void)
The vsyncs the last frame took (in 60 Hz frames)
Definition display.c:116
void layerAddScroll(LayerView *layer, s32 dx, s32 dy)
Layer method: scrolls by (dx, dy) (8.8 fixed point)
Definition layer.c:219
void cardDrawerSetImagePos(s32 x, s32 y)
Card drawer method: the VRAM area of the image cells.
Definition card_drawer.c:50
void layerSetKeepView(Layer *layer, s32 enable, s32 projection)
Layer method: keeps the current world-screen matrix and projection for this buffer's drawing.
Definition layer.c:357
void moveLayer(s32 id, s32 targetId, s32 delta)
Moves a layer to the position of another one (plus delta) in the draw order.
Definition layer.c:86
void spriteDrawerDraw(s32 *sheet, s32 frame, s32 x, s32 y)
Draws frame frame of a sprite sheet (see SpritePart) at (x, y): as sprites, changing the texture page...
void removeLayerSlot(s32 index)
Closes the gap of a removed layer in the draw order.
Definition layer.c:35
void initCardDrawer(CardDrawer *obj)
Clears a card drawer, gives it its methods and binds it.
void startVSyncCallback(void)
Installs vsyncCallback.
Definition display.c:42
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
void layerLoadView(Layer *layer)
Layer method: restores the view that setKeepView kept.
Definition layer.c:366
One frame of a sprite animation; frame 0xFF ends it (or loops it)
Definition gfx.h:296
s16 frame
Definition gfx.h:297
s16 duration
Definition gfx.h:298
s16 index
Definition gfx.h:302
s16 timer
Definition gfx.h:303
Draws the cards' images (CardImage), from files 0x7E7-0x7EB.
Definition gfx.h:193
void(* setCard)()
(id)
Definition gfx.h:205
s32 cellY
Definition gfx.h:200
Layer * layer
Definition gfx.h:203
void(* setClutPos)()
(x, y)
Definition gfx.h:210
s32 clutStride
Definition gfx.h:201
void(* setCell)()
(x, y)
Definition gfx.h:211
s32 clutX
Definition gfx.h:197
void(* draw)()
(x, y)
Definition gfx.h:207
u_long * ot
Definition gfx.h:204
s32 semiTrans
Definition gfx.h:202
void(* setClutStride)()
(stride)
Definition gfx.h:212
s32(* getKind)(void)
Definition gfx.h:214
void(* setImagePos)()
(x, y)
Definition gfx.h:209
s32 imageX
VRAM position of the image grid.
Definition gfx.h:195
void(* loadImage)()
Definition gfx.h:206
s32 imageY
Definition gfx.h:196
s32 clutY
Definition gfx.h:198
void(* setLayer)()
(id, depth)
Definition gfx.h:208
s32 cellX
grid cell: 32x32 pixels, one CLUT row each
Definition gfx.h:199
void(* setSemiTrans)()
(on)
Definition gfx.h:213
CardImage * card
Definition gfx.h:194
A card's image (CardDrawer.card): 64 to a file, a 12-byte header and a 32x32 8-bit TIM.
Definition gfx.h:172
u8 level
a Digimon's, 2-5 (CARDGAME shows its name); 0 on the other cards
Definition gfx.h:180
s16 comboCard
the card (from 1) that three or more of it make (CARDGAME_findCardSet), 0 for none
Definition gfx.h:183
u8 hp
Definition gfx.h:175
u8 color
from 1
Definition gfx.h:173
u8 unused4
1-4 on the 60 option cards (a colour's first 4, its last two 1), 0 on the Digimon; nothing reads it
Definition gfx.h:177
u8 ap
Definition gfx.h:174
u8 kind
an index in CARD_KINDS
Definition gfx.h:176
s16 rank
by strength, from 1 the strongest (0 on the two blank cards)
Definition gfx.h:182
u8 tim[0x620]
its header, a 256-colour CLUT block and the image block
Definition gfx.h:185
u8 points
what it adds to its colour
Definition gfx.h:179
u8 pad7
0 on every card; nothing reads it
Definition gfx.h:181
A function that a layer calls when it is drawn (Layer.addDrawCallback)
Definition gfx.h:116
s32 param
Definition gfx.h:118
void(* func)(s32 arg, void *layer, s32 param)
Definition gfx.h:119
struct DrawCallback * next
Definition gfx.h:121
s32 arg
Definition gfx.h:120
s32 priority
Definition gfx.h:117
The graphics methods (GFX.funcs)
Definition gfx.h:16
void(* reset)(void)
Definition gfx.h:17
s32(* getFrameTime)(void)
Definition gfx.h:32
s32(* getFrameCount)(void)
Definition gfx.h:30
void(* moveLayer)()
Definition gfx.h:29
void(* freePrimBuffers)(void)
Definition gfx.h:21
s32(* destroyLayer)(s32 id)
Definition gfx.h:25
void(* allocPrimBuffers)(s32 size)
Definition gfx.h:18
void(* setPrim)(void *next)
Definition gfx.h:20
void(* setDisplayMode)(s32 w, s32 h, s32 hires, s32 interlace)
Definition gfx.h:26
s32(* getTime)(void)
Definition gfx.h:31
void(* setDisplayArea)()
Definition gfx.h:27
void(* drawFrame)()
Definition gfx.h:23
void(* startVSync)(void)
Definition gfx.h:22
The graphics state: double-buffered display, the GPU packet buffers that primitives are written to (g...
Definition gfx.h:60
DISPENV disp[2]
Definition gfx.h:74
void * prim
next free byte of the packet buffer
Definition gfx.h:69
s32 frameTimeCounter
Definition gfx.h:68
void * primBufs[2]
Definition gfx.h:70
void(* vsyncFunc)(s32 arg)
Definition gfx.h:61
s32 buffer
the one being drawn
Definition gfx.h:73
GfxFuncs funcs
Definition gfx.h:77
struct Layer * layers[30]
Definition gfx.h:75
s32 vsyncArg
Definition gfx.h:62
s32 dispBuffer
Definition gfx.h:72
s32 timeCounter
Definition gfx.h:66
s32 frameCount
Definition gfx.h:63
s32 frameCounter
Definition gfx.h:64
s32 layerIds[30]
Definition gfx.h:76
s32 primBufSize
Definition gfx.h:71
s32 time
vsyncs since boot
Definition gfx.h:65
s32 frameTime
vsyncs that the last frame took
Definition gfx.h:67
Layer as its clip/scroll methods see it: the clip rect as unsigned.
Definition gfx.h:81
s16 y
Definition gfx.h:83
s16 offsetX
Definition gfx.h:99
s32 scrollX
Definition gfx.h:101
s32 otLen
Definition gfx.h:97
DrawCallback * callbacks
Definition gfx.h:105
s32 callbackCap
Definition gfx.h:103
s32 callbackCount
Definition gfx.h:104
u8 isbg
Definition gfx.h:91
u8 dtd
Definition gfx.h:89
u8 bgG
Definition gfx.h:93
s32 otShift
Definition gfx.h:98
u8 dfe
Definition gfx.h:90
s16 ofs[2]
DRAWENV's fields on (Layer.env)
Definition gfx.h:86
s16 offsetY
Definition gfx.h:100
DR_ENV drEnv
Definition gfx.h:95
u8 bgB
Definition gfx.h:94
s16 x
Definition gfx.h:82
s32 scrollY
Definition gfx.h:102
u16 h
Definition gfx.h:85
RECT tw
Definition gfx.h:87
u8 bgR
Definition gfx.h:92
u16 w
Definition gfx.h:84
u16 tpage
Definition gfx.h:88
u_long * ot[2]
Definition gfx.h:96
A drawing layer (GFX.funcs.createLayer): a DRAWENV with a pair of ordering tables,...
Definition gfx.h:128
s32 callbackCount
Definition gfx.h:138
void(* addCallback)()
Definition gfx.h:161
void(* getScroll)()
Definition gfx.h:148
void(* loadLightMatrix)(struct Layer *)
Definition gfx.h:165
void(* runCallbacks)(struct Layer *)
Definition gfx.h:162
void(* setScroll)()
Definition gfx.h:149
void(* setBgColor)()
no prototype: callers would truncate u8 args
Definition gfx.h:152
void(* setOffset)()
no prototype: callers would truncate s16 args
Definition gfx.h:147
s32(* getOtShift)()
Definition gfx.h:158
s32 projection
Definition gfx.h:141
void(* draw)(struct Layer *)
Definition gfx.h:153
DrawCallback * callbacks
Definition gfx.h:139
void(* loadView)(struct Layer *)
Definition gfx.h:163
void(* addScroll)()
Definition gfx.h:150
void(* clearOt)(struct Layer *)
Definition gfx.h:154
s32 keepView
Definition gfx.h:140
s32 otShift
Definition gfx.h:132
s32 scrollY
Definition gfx.h:136
s32 otLen
Definition gfx.h:131
s32 keepLightMatrix
Definition gfx.h:143
s32 callbackCap
Definition gfx.h:137
void(* setClipSize)()
no prototype: callers would truncate s16 args
Definition gfx.h:146
DRAWENV env
Definition gfx.h:129
void(* setKeepLightMatrix)()
Definition gfx.h:166
s16 offsetX
Definition gfx.h:133
MATRIX view[2]
Definition gfx.h:142
MATRIX lightMatrix[2]
Definition gfx.h:144
void(* allocCallbacks)()
Definition gfx.h:159
u_long * ot[2]
Definition gfx.h:130
void(* setKeepView)()
Definition gfx.h:164
void(* free)(struct Layer *)
Definition gfx.h:167
void(* setClipPos)()
no prototype: callers would truncate s16 args
Definition gfx.h:145
void(* addSortedCallback)()
Definition gfx.h:160
s32 scrollX
Definition gfx.h:135
s16 offsetY
Definition gfx.h:134
void(* getViewRect)()
Definition gfx.h:151
Definition gfx.h:108
s16 y
Definition gfx.h:110
u16 w
Definition gfx.h:111
u16 h
Definition gfx.h:112
s16 x
Definition gfx.h:109
Fades the whole screen to black and back with a subtractive rectangle.
Definition gfx.h:361
s32 depth
Definition gfx.h:364
s32 levelStep
Definition gfx.h:367
s32 fadeIn
0: to black
Definition gfx.h:365
void(* start)(struct ScreenFade *fade, s32 fadeIn, s32 frames)
TASK_DONE when done.
Definition gfx.h:368
s32 layerId
Definition gfx.h:363
s32 level
0-FADE_LEVEL_MAX
Definition gfx.h:366
Draws sprites from a sprite sheet (such as file 0x277, the menu graphics): a sheet has a table of fra...
Definition gfx.h:223
s32 clutRow
added to the CLUT y: palette animations
Definition gfx.h:232
s32 tpageY
Definition gfx.h:227
s32 transformDirty
Definition gfx.h:235
MATRIX matrix
Definition gfx.h:240
void(* setAltClut)()
(x, y)
Definition gfx.h:243
void(* setLayer)()
(layer, depth)
Definition gfx.h:245
s32 altClutX
for the parts that are flagged
Definition gfx.h:230
void(* setPivot)()
(x, y)
Definition gfx.h:250
s32 followScroll
offset by the layer's scroll
Definition gfx.h:233
s32 clutY
Definition gfx.h:229
void(* setScale)()
(x, y, z), ONE = 1.0
Definition gfx.h:248
s32 pivotX
Definition gfx.h:236
void(* setColor)()
(CVECTOR *)
Definition gfx.h:252
void(* bind)()
(drawer)
Definition gfx.h:241
s32 altClutY
Definition gfx.h:231
s32 pivotY
Definition gfx.h:237
SVECTOR rot
Definition gfx.h:239
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
Layer * layer
Definition gfx.h:224
CVECTOR color
Definition gfx.h:234
u_long * ot
Definition gfx.h:225
s32 tpageX
VRAM position of the sheet's texture.
Definition gfx.h:226
void(* setFollowScroll)()
(on)
Definition gfx.h:251
void(* setClutRow)()
(row)
Definition gfx.h:247
VECTOR scale
ScaleMatrix's.
Definition gfx.h:238
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setRotation)()
(x, y, z); no prototype: callers would truncate s16 args
Definition gfx.h:249
s32 clutX
Definition gfx.h:228
void(* setTexture)()
(x, y)
Definition gfx.h:242
One part of a sprite sheet, a rectangle of its texture.
Definition gfx.h:285
s16 h
Definition gfx.h:289
s16 v
Definition gfx.h:287
s16 u
Definition gfx.h:286
s16 clutX
added to the drawer's CLUT position
Definition gfx.h:290
s16 w
Definition gfx.h:288
s16 clutY
Definition gfx.h:291
s16 mode
0: 4-bit texture, 1: 8-bit, with the drawer's other CLUT
Definition gfx.h:292
A TIM's CLUT or image block.
Definition gfx.h:307
u16 h
Definition gfx.h:312
u16 x
Definition gfx.h:309
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
u16 y
Definition gfx.h:310
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
u8 pad4[4]
never read or written
Definition gfx.h:328
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
Definition gfx.h:352
s32 y
Definition gfx.h:354
s32 x
Definition gfx.h:353
The next free primitive of the packet buffer (getPrim), written as the kind that is drawn next.
Definition gfx.h:344
POLY_F4 * f4
Definition gfx.h:347
POLY_FT4 * ft4
Definition gfx.h:348
DR_TPAGE * tpage
Definition gfx.h:349
void * any
Definition gfx.h:345
SPRT * sprt
Definition gfx.h:346
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