DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
libgraph.h
1#pragma once
2
3/* Vendor SDK declarations. The reconstruction is given no system include path at all — only the
4 game's own headers — which is why this is reached with quotes rather than as <libgraph.h>. */
5
6#include "common.h"
7
8#define SCE_GS_INTERLACE 1
9#define SCE_GS_NTSC 2
10#define SCE_GS_PAL 3
11#define SCE_GS_FIELD 1
12
13#define SCE_GS_PSMCT32 0
14#define SCE_GS_PSMCT24 1
15#define SCE_GS_PSMCT16 2
16#define SCE_GS_PSMT8 19
17#define SCE_GS_PSMT4 20
18#define SCE_GS_PSMZ24 49
19
20#define SCE_GS_ZGEQUAL 2
21
22#define SCE_GIF_PACKED_AD 14
23
24#define SCE_GS_PRIM 0
25#define SCE_GS_RGBAQ 1
26#define SCE_GS_UV 3
27#define SCE_GS_XYZF2 4
28#define SCE_GS_XYZ2 5
29#define SCE_GS_TEX0_1 6
30#define SCE_GS_CLAMP_1 8
31#define SCE_GS_XYZF3 12
32#define SCE_GS_TEX1_1 20
33#define SCE_GS_TEXA 59
34#define SCE_GS_TEXFLUSH 63
35#define SCE_GS_SCISSOR_1 64
36#define SCE_GS_ALPHA_1 66
37#define SCE_GS_TEST_1 71
38#define SCE_GS_FRAME_1 76
39#define SCE_GS_ZBUF_1 78
40#define SCE_GS_BITBLTBUF 80
41#define SCE_GS_TRXPOS 81
42#define SCE_GS_TRXREG 82
43#define SCE_GS_TRXDIR 83
44
45#define SCE_GS_PRIM_LINE 1
46#define SCE_GS_PRIM_SPRITE 6
47
48#define SCE_GS_ALWAYS 1
49
50#define SCE_GS_LOCAL_LOCAL 2
51
52/* Each register the display setup writes is a field layout rather than a number, so the setup
53 reads as the hardware state it is: a field the game changes is one assignment and the rest of
54 the register keeps whatever the SDK's defaults put there. */
55
56typedef struct {
57 u_long NLOOP : 15;
58 u_long EOP : 1;
59 u_long pad16 : 30;
60 u_long PRE : 1;
61 u_long PRIM : 11;
62 u_long FLG : 2;
63 u_long NREG : 4;
64 u_long REGS0 : 4;
65 u_long REGS1 : 4;
66 u_long REGS2 : 4;
67 u_long REGS3 : 4;
68 u_long REGS4 : 4;
69 u_long REGS5 : 4;
70 u_long REGS6 : 4;
71 u_long REGS7 : 4;
72 u_long REGS8 : 4;
73 u_long REGS9 : 4;
74 u_long REGS10 : 4;
75 u_long REGS11 : 4;
76 u_long REGS12 : 4;
77 u_long REGS13 : 4;
78 u_long REGS14 : 4;
79 u_long REGS15 : 4;
80} sceGifTag;
81
82typedef struct {
83 union {
84 u_long value;
85
86 struct {
87 u_long FBP : 9;
88 u_long pad9 : 7;
89 u_long FBW : 6;
90 u_long pad22 : 2;
91 u_long PSM : 6;
92 u_long pad30 : 2;
93 u_long FBMSK : 32;
94 };
95
96 struct {
97 u_long tbp0 : 9;
98 u_long pad09 : 7;
99 u_long tbw : 6;
100 u_long pad22_ : 2;
101 u_long psm : 6;
102 u_long pad30_ : 2;
103 u_long fbmsk : 32;
104 } bits;
105 };
106} sceGsFrame;
107
108typedef struct {
109 union {
110 u_long value;
111
112 struct {
113 u_long ZBP : 9;
114 u_long pad9 : 15;
115 u_long PSM : 4;
116 u_long pad28 : 4;
117 u_long ZMSK : 1;
118 u_long pad33 : 31;
119 };
120
121 struct {
122 u_long zbp : 9;
123 u_long pad09 : 15;
124 u_long psm : 4;
125 u_long pad28_ : 4;
126 u_long zmsk : 1;
127 u_long pad33_ : 31;
128 } bits;
129 };
130} sceGsZbuf;
131
132typedef struct {
133 u_long OFX : 16;
134 u_long pad16 : 16;
135 u_long OFY : 16;
136 u_long pad48 : 16;
138
139typedef struct {
140 u_long SCAX0 : 11;
141 u_long pad11 : 5;
142 u_long SCAX1 : 11;
143 u_long pad27 : 5;
144 u_long SCAY0 : 11;
145 u_long pad43 : 5;
146 u_long SCAY1 : 11;
147 u_long pad59 : 5;
149
150typedef struct {
151 u_long AC : 1;
152 u_long pad1 : 63;
154
155typedef struct {
156 u_long CLAMP : 1;
157 u_long pad1 : 63;
159
160typedef struct {
161 u_long DTHE : 1;
162 u_long pad1 : 63;
163} sceGsDthe;
164
165typedef struct {
166 union {
167 u_long value;
168
169 struct {
170 u_long ATE : 1;
171 u_long ATST : 3;
172 u_long AREF : 8;
173 u_long AFAIL : 2;
174 u_long DATE : 1;
175 u_long DATM : 1;
176 u_long ZTE : 1;
177 u_long ZTST : 2;
178 u_long pad19 : 45;
179 };
180
181 struct {
182 u_long ate : 1;
183 u_long atst : 3;
184 u_long aref : 8;
185 u_long afail : 2;
186 u_long date : 1;
187 u_long datm : 1;
188 u_long zte : 1;
189 u_long ztst : 2;
190 u_long pad19_ : 45;
191 } bits;
192 };
193} sceGsTest;
194
195typedef struct {
196 union {
197 u_long value;
198
199 struct {
200 u_long A : 2;
201 u_long B : 2;
202 u_long C : 2;
203 u_long D : 2;
204 u_long pad8 : 24;
205 u_long FIX : 8;
206 u_long pad40 : 24;
207 };
208
209 struct {
210 u_long a : 2;
211 u_long b : 2;
212 u_long c : 2;
213 u_long d : 2;
214 u_long pad08 : 24;
215 u_long fix : 8;
216 u_long pad40_ : 24;
217 } bits;
218 };
219} sceGsAlpha;
220
221typedef struct {
222 u_long TA0 : 8;
223 u_long pad8 : 7;
224 u_long AEM : 1;
225 u_long pad16 : 16;
226 u_long TA1 : 8;
227 u_long pad40 : 24;
228} sceGsTexa;
229
230typedef struct {
231 union {
232 u_long value;
233
234 struct {
235 u_long TBP0 : 14;
236 u_long TBW : 6;
237 u_long PSM : 6;
238 u_long TW : 4;
239 u_long TH : 4;
240 u_long TCC : 1;
241 u_long TFX : 2;
242 u_long CBP : 14;
243 u_long CPSM : 4;
244 u_long CSM : 1;
245 u_long CSA : 5;
246 u_long CLD : 3;
247 };
248
249 struct {
250 u_long tbp0 : 14;
251 u_long tbw : 6;
252 u_long psm : 6;
253 u_long tw : 4;
254 u_long th : 4;
255 u_long tcc : 1;
256 u_long tfx : 2;
257 u_long cbp : 14;
258 u_long cpsm : 4;
259 u_long csm : 1;
260 u_long csa : 5;
261 u_long cld : 3;
262 } bits;
263 };
264} sceGsTex0;
265
266/* The register built as one 64-bit word rather than field by field, which is how the SDK spells a
267 value nothing keeps a structure of. The width the block address is shifted by is the argument's
268 own — an int, so a 32-bit shift — and every other term is widened before it moves; that is what
269 puts a single `sll` among the `dsll`s. The two leading terms are in the order the game's code
270 evidences rather than the order the SDK is assumed to have written them: the buffer width first
271 is what matches and the block address first is not. Which one the *compiler* computes first says
272 nothing about it, and the block below is where that was measured. */
273#define SCE_GS_SET_TEX0(tbp0, tbw, psm, tw, th, tcc, tfx, cbp, cpsm, csm, csa, cld) \
274 (((u_long) (tbw) << 14) | (u_long) (tbp0) | ((u_long) (psm) << 20) | \
275 ((u_long) (tw) << 26) | ((u_long) (th) << 30) | ((u_long) (tcc) << 34) | \
276 ((u_long) (tfx) << 35) | ((u_long) (cbp) << 37) | ((u_long) (cpsm) << 51) | \
277 ((u_long) (csm) << 55) | ((u_long) (csa) << 56) | ((u_long) (cld) << 61))
278
279/* The mip-map register beside it, in field order: every term but the level bias and the fixed
280 filter settings is a constant at every call site, so what the term order decides here is which
281 of them the compiler can fold into one immediate. */
282#define SCE_GS_SET_TEX1(lcm, mxl, mmag, mmin, mtba, l, k) \
283 ((u_long) (lcm) | ((u_long) (mxl) << 2) | ((u_long) (mmag) << 5) | ((u_long) (mmin) << 6) | \
284 ((u_long) (mtba) << 9) | ((u_long) (l) << 19) | ((u_long) (k) << 32))
285
286/* The registers a transfer or a sprite is built out of, which are one 64-bit word each and have
287 no structure in the SDK. Term order is the game's own evidence rather than an assumption, and it
288 is *not* readable off which term the compiler computes first: `TRXPOS` proves both halves at
289 once. Written in field order it matches and written with the shifted term first it does not —
290 yet either way the shift is emitted ahead of the plain load. What a source order settles is the
291 operand order of the `|`, and reading it off the evaluation order is what gets it backwards. */
292#define SCE_GS_SET_BITBLTBUF(sbp, sbw, spsm, dbp, dbw, dpsm) \
293 ((u_long) (sbp) | ((u_long) (sbw) << 16) | ((u_long) (spsm) << 24) | \
294 ((u_long) (dbp) << 32) | ((u_long) (dbw) << 48) | ((u_long) (dpsm) << 56))
295
296#define SCE_GS_SET_TRXPOS(ssax, ssay, dsax, dsay, dir) \
297 ((u_long) (ssax) | ((u_long) (ssay) << 16) | ((u_long) (dsax) << 32) | \
298 ((u_long) (dsay) << 48) | ((u_long) (dir) << 59))
299
300#define SCE_GS_SET_TRXREG(rrw, rrh) ((u_long) (rrw) | ((u_long) (rrh) << 32))
301
302#define SCE_GS_SET_TRXDIR(xdir) ((u_long) (xdir))
303
304#define SCE_GS_SET_FRAME(fbp, fbw, psm, fbmsk) \
305 ((u_long) (fbp) | ((u_long) (fbw) << 16) | ((u_long) (psm) << 24) | ((u_long) (fbmsk) << 32))
306
307#define SCE_GS_SET_PRIM(prim, iip, tme, fge, abe, aa1, fst, ctxt, fix) \
308 ((u_long) (prim) | ((u_long) (iip) << 3) | ((u_long) (tme) << 4) | ((u_long) (fge) << 5) | \
309 ((u_long) (abe) << 6) | ((u_long) (aa1) << 7) | ((u_long) (fst) << 8) | \
310 ((u_long) (ctxt) << 9) | ((u_long) (fix) << 10))
311
312#define SCE_GS_SET_RGBAQ(r, g, b, a, q) \
313 ((u_long) (r) | ((u_long) (g) << 8) | ((u_long) (b) << 16) | ((u_long) (a) << 24) | \
314 ((u_long) (q) << 32))
315
316#define SCE_GS_SET_UV(u, v) ((u_long) (u) | ((u_long) (v) << 16))
317
318#define SCE_GS_SET_XYZF2(x, y, z, f) \
319 ((u_long) (x) | ((u_long) (y) << 16) | ((u_long) (z) << 32) | ((u_long) (f) << 56))
320
321typedef struct {
322 u_long LCM : 1;
323 u_long pad1 : 1;
324 u_long MXL : 3;
325 u_long MMAG : 1;
326 u_long MMIN : 3;
327 u_long MTBA : 1;
328 u_long pad10 : 9;
329 u_long L : 2;
330 u_long pad21 : 11;
331 u_long K : 12;
332 u_long pad44 : 20;
333} sceGsTex1;
334
335typedef struct {
336 u_long PRIM : 3;
337 u_long IIP : 1;
338 u_long TME : 1;
339 u_long FGE : 1;
340 u_long ABE : 1;
341 u_long AA1 : 1;
342 u_long FST : 1;
343 u_long CTXT : 1;
344 u_long FIX : 1;
345 u_long pad11 : 53;
346} sceGsPrim;
347
348typedef struct {
349 union {
350 u_long value;
351
352 struct {
353 u_long R : 8;
354 u_long G : 8;
355 u_long B : 8;
356 u_long A : 8;
357 u_long Q : 32;
358 };
359
360 struct {
361 u_long r : 8;
362 u_long g : 8;
363 u_long b : 8;
364 u_long a : 8;
365 u_long q : 32;
366 } bits;
367 };
368} sceGsRgbaq;
369
370typedef struct {
371 u_long X : 16;
372 u_long Y : 16;
373 u_long Z : 32;
374} sceGsXyz;
375
376/* Five registers rather than a layout the code states: nothing reconstructed reaches inside one,
377 and 40 bytes each is what the double buffer's own size leaves room for. */
381typedef struct sceGsDisplay {
382 u_int DX : 12;
383 u_int DY : 11;
384 u_int MAGH : 4;
385 u_int MAGV : 2;
386 u_int p0 : 3;
387 u_int DW : 12;
388 u_int DH : 11;
389 u_int p1 : 9;
391
392typedef struct {
393 u_long pmode;
394 u_long smode2;
395 u_long dispfb;
396 sceGsDisplay display;
397 u_long bgcolor;
399
400/* The eight register pairs sceGsSetDefDrawEnv fills, without the GIF tag that carries them: the
401 tag covers the clear beside them as well, so it belongs to the pair of them rather than to
402 either, which is also why sceGsSetHalfOffset is handed this and not the tag. */
403typedef struct {
404 sceGsFrame frame1;
405 u_long frame1addr;
406 sceGsZbuf zbuf1;
407 u_long zbuf1addr;
408 sceGsXyOffset xyoffset1;
409 u_long xyoffset1addr;
410 sceGsScissor scissor1;
411 u_long scissor1addr;
412 sceGsPrModeCont prmodecont;
413 u_long prmodecontaddr;
414 sceGsColClamp colclamp;
415 u_long colclampaddr;
416 sceGsDthe dthe;
417 u_long dtheaddr;
418 sceGsTest test1;
419 u_long test1addr;
421
422typedef struct {
423 sceGsTest test0;
424 u_long test0addr;
425 sceGsPrim prim;
426 u_long primaddr;
427 sceGsRgbaq rgbaq;
428 u_long rgbaqaddr;
429 sceGsXyz xyz2_0;
430 u_long xyz2_0addr;
431 sceGsXyz xyz2_1;
432 u_long xyz2_1addr;
433 sceGsTest test1;
434 u_long test1addr;
435} sceGsClear;
436
437typedef struct {
438 sceGsDispEnv disp0;
439 sceGsDispEnv disp1;
440 sceGifTag giftag0;
441 sceGsDrawEnv1 draw0;
442 sceGsClear clear0;
443 sceGifTag giftag1;
444 sceGsDrawEnv1 draw1;
445 sceGsClear clear1;
446} sceGsDBuff;
447
448/* The read-back packet the SDK builds and the game only ever passes by address. Its extent is the
449 one thing about it the image states, and it is what the executable gives gs_simage. */
450typedef struct {
451 u_long chain[7][2];
453
457typedef struct {
458 u_long chain[6][2];
460
461extern "C" {
462
463void sceGsResetGraph(short mode, short inter, short omode, short ffmd);
464
468void sceGsResetPath();
469
470int sceGsSyncV(int mode);
471int sceGsSyncPath(int mode, u_short timeout);
472void sceGsSyncVCallback(int (*callback)(int));
473void sceGsSetDefDBuff(sceGsDBuff *db, int psm, int w, int h, int ztest, int zpsm, int clear);
474void sceGsSwapDBuff(sceGsDBuff *db, int id);
475void sceGsSetHalfOffset(sceGsDrawEnv1 *env, short offx, short offy, short field);
476void sceGsSetDefStoreImage(sceGsStoreImage *si, short sbp, short sbw, short spsm, short ssax,
477 short ssay, short rrw, short rrh);
478void sceGsExecStoreImage(sceGsStoreImage *si, u_long128 *dest);
479void sceGsSetDefLoadImage(sceGsLoadImage *li, short dbp, short dbw, short dpsm, short dsax,
480 short dsay, short rrw, short rrh);
481void sceGsExecLoadImage(sceGsLoadImage *li, u_long128 *source);
482}
483
484#define R bits.r
485#define G bits.g
486#define B bits.b
487#define A bits.a
488#define FBP bits.tbp0
489#define FBW bits.tbw
490#define PSM bits.psm
491#define TBP0 bits.tbp0
492#define TBW bits.tbw
493#define CBP bits.cbp
494#define CPSM bits.cpsm