1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #ifndef ICB_LIBGPU_H_
29 #define ICB_LIBGPU_H_
30 
31 namespace ICB {
32 
33 
34 // For storing user data in the OT entry e.g. texture pointer
35 extern void *OTusrData;
36 
37 #define OTSetUser(usr) OTusrData = (usr)
38 
39 // For choosing which texture to store in the OT list
40 #define ChooseTexture(texture) OTSetUser((texture))
41 
42 /*
43  * Primitive list:
44  *
45  *      Name     |Size*1|Shade  |Vertex |Texture| Function
46  *      ---------+------+-------+-------+-------+------------------------
47  *      POLY_F3  | 6    |Flat   |   3   |OFF    | Flat Triangle
48  *      POLY_FT3 | 9    |Flat   |   3   |ON     | Flat Textured Triangle
49  *      POLY_G3  | 8    |Gouraud|   3   |OFF    | Gouraud Triangle
50  *      POLY_GT3 |11    |Gouraud|   3   |ON     | Gouraud Textured Triangle
51  *      POLY_F4  | 7    |Flat   |   4   |OFF    | Flat Quadrangle
52  *      POLY_FT4 |11    |Flat   |   4   |ON     | Flat Textured Quadrangle
53  *      POLY_G4  |10    |Gouraud|   4   |OFF    | Gouraud Quadrangle
54  *      POLY_GT4 |14    |Gouraud|   4   |ON     | Gouraud Textured Quadrangle
55  *      ---------+------+-------+-------+-------+------------------------
56  *      LINE_F2  | 5    |Flat   |   2   | -     | unconnected Flat Line
57  *      LINE_G2  | 6    |Gouraud|   2   | -     | unconnected Gouraud Line
58  *      LINE_F3  | 7    |Flat   |   3   | -     | 3-connected Flat Line
59  *      LINE_G3  | 9    |Gouraud|   3   | -     | 3-connected Gouraud Line
60  *      LINE_F4  | 8    |Flat   |   4   | -     | 4-connected Flat Line
61  *      LINE_G4  |11    |Gouraud|   4   | -     | 4-connected Gouraud Line
62  *      ---------+------+-------+-------+-------+------------------------
63  *      SPRT     | 6    |Flat   |   1   |ON     | free size Sprite
64  *      SPRT_16  | 5    |Flat   |   1   |ON     | 16x16 Sprite
65  *      SPRT_8   | 5    |Flat   |   1   |ON     | 8x8 Sprite
66  *      ---------+------+-------+-------+-------+------------------------
67  *      TILE     | 5    |Flat   |   1   |OFF    | free size Sprite
68  *      TILE_16  | 4    |Flat   |   1   |OFF    | 16x16 Sprite
69  *      TILE_8   | 4    |Flat   |   1   |OFF    | 8x8 Sprite
70  *      TILE_1   | 4    |Flat   |   1   |OFF    | 1x1 Sprite
71  *      ---------+------+-------+-------+-------+------------------------
72  *      DR_TWIN  | 3    |   -   |   -   | -     | Texture Window
73  *      DR_AREA  | 3    |   -   |   -   | -     | Drawing Area
74  *      DR_OFFSET| 3    |   -   |   -   | -     | Drawing Offset
75  *      DR_MODE  | 3    |   -   |   -   | -     | Drawing Mode
76  *      DR_ENV   |16    |   -   |   -   | -     | Drawing Environment
77  *      DR_MOVE  | 6    |   -   |   -   | -     | MoveImage
78  *      DR_LOAD  |17    |   -   |   -   | -     | LoadImage
79  *      DR_TPAGE | 2    |   -   |   -   | -     | Drawing TPage
80  *      DR_STP   | 3    |   -   |   -   | -     | Drawing STP
81  *
82  *  *1: in int32-word
83  *
84  * Texture Attributes:
85  *  abr: ambient rate
86  *      abr 0   1   2   3
87  *      -------------------------------------
88  *      Front   0.5 1.0 0.5 -1.0
89  *      Back    0.5 1.0 1.0  1.0
90  *
91  *  tp: texture mode
92  *       tp 0   1   2
93  *       -----------------------------
94  *       depth  4bit    8bit    16bit
95  *       color  CLUT    CLUT    DIRECT
96  */
97 
98 /*
99  *  Time-out Cycle
100  */
101 #define WAIT_TIME 0x800000
102 
103 /*
104  *  General Macros
105  */
106 #define limitRange(x, l, h) ((x) = ((x) < (l) ? (l) : (x) > (h) ? (h) : (x)))
107 
108 /*
109  *  Set/Add Vector/Rectangle Attributes
110  */
111 #define setVector(v, _x, _y, _z) (v)->vx = _x, (v)->vy = _y, (v)->vz = _z
112 
113 #define applyVector(v, _x, _y, _z, op) (v)->vx op _x, (v)->vy op _y, (v)->vz op _z
114 
115 #define copyVector(v0, v1) (v0)->vx = (v1)->vx, (v0)->vy = (v1)->vy, (v0)->vz = (v1)->vz
116 
117 #define addVector(v0, v1) (v0)->vx += (v1)->vx, (v0)->vy += (v1)->vy, (v0)->vz += (v1)->vz
118 
119 #define dumpVector(str, v) GPU_printf("%s=(%d,%d,%d)\n", str, (v)->vx, (v)->vy, (v)->vz)
120 
121 #define dumpMatrix(x)                                                                                                                                                              \
122 	GPU_printf("\t%5d,%5d,%5d\n", (x)->m[0][0], (x)->m[0][1], (x)->m[0][2]), GPU_printf("\t%5d,%5d,%5d\n", (x)->m[1][0], (x)->m[1][1], (x)->m[1][2]),                          \
123 	    GPU_printf("\t%5d,%5d,%5d\n", (x)->m[2][0], (x)->m[2][1], (x)->m[2][2])
124 
125 #define setRECT(r, _x, _y, _w, _h) (r)->x = (_x), (r)->y = (_y), (r)->w = (_w), (r)->h = (_h)
126 
127 /*
128  *  Set Primitive Attributes
129  */
130 #define setTPage(p, tp, abr, x, y) ((p)->tpage = getTPage(tp, abr, x, y))
131 
132 #define setClut(p, x, y) ((p)->clut = getClut(x, y))
133 
134 /*
135  * Set Primitive Colors
136  */
137 #define setRGB0(p, _r0, _g0, _b0) (p)->r0 = _r0, (p)->g0 = _g0, (p)->b0 = _b0
138 
139 #define setRGB1(p, _r1, _g1, _b1) (p)->r1 = _r1, (p)->g1 = _g1, (p)->b1 = _b1
140 
141 #define setRGB2(p, _r2, _g2, _b2) (p)->r2 = _r2, (p)->g2 = _g2, (p)->b2 = _b2
142 
143 #define setRGB3(p, _r3, _g3, _b3) (p)->r3 = _r3, (p)->g3 = _g3, (p)->b3 = _b3
144 
145 /*
146  * Set Primitive Screen Points
147  */
148 #define setXY0(p, _x0, _y0) (p)->x0 = (_x0), (p)->y0 = (_y0)
149 
150 #define setXY2(p, _x0, _y0, _x1, _y1) (p)->x0 = (_x0), (p)->y0 = (_y0), (p)->x1 = (_x1), (p)->y1 = (_y1)
151 
152 #define setXY3(p, _x0, _y0, _x1, _y1, _x2, _y2) (p)->x0 = (_x0), (p)->y0 = (_y0), (p)->x1 = (_x1), (p)->y1 = (_y1), (p)->x2 = (_x2), (p)->y2 = (_y2)
153 
154 #define setXY4(p, _x0, _y0, _x1, _y1, _x2, _y2, _x3, _y3)                                                                                                                          \
155 	(p)->x0 = (_x0), (p)->y0 = (_y0), (p)->x1 = (_x1), (p)->y1 = (_y1), (p)->x2 = (_x2), (p)->y2 = (_y2), (p)->x3 = (_x3), (p)->y3 = (_y3)
156 
157 #define setXYWH(p, _x0, _y0, _w, _h)                                                                                                                                               \
158 	(p)->x0 = (_x0), (p)->y0 = (_y0), (p)->x1 = (_x0) + (_w), (p)->y1 = (_y0), (p)->x2 = (_x0), (p)->y2 = (_y0) + (_h), (p)->x3 = (_x0) + (_w), (p)->y3 = (_y0) + (_h)
159 
160 /*
161  * Set Primitive Width/Height
162  */
163 #define setWH(p, _w, _h) (p)->w = _w, (p)->h = _h
164 
165 /*
166  * Set Primitive Texture Points
167  */
168 #define setUV0(p, _u0, _v0) (p)->u0 = (_u0), (p)->v0 = (_v0)
169 
170 #define setUV3(p, _u0, _v0, _u1, _v1, _u2, _v2) (p)->u0 = (_u0), (p)->v0 = (_v0), (p)->u1 = (_u1), (p)->v1 = (_v1), (p)->u2 = (_u2), (p)->v2 = (_v2)
171 
172 #define setUV4(p, _u0, _v0, _u1, _v1, _u2, _v2, _u3, _v3)                                                                                                                          \
173 	(p)->u0 = (_u0), (p)->v0 = (_v0), (p)->u1 = (_u1), (p)->v1 = (_v1), (p)->u2 = (_u2), (p)->v2 = (_v2), (p)->u3 = (_u3), (p)->v3 = (_v3)
174 
175 #define setUVWH(p, _u0, _v0, _w, _h)                                                                                                                                               \
176 	(p)->u0 = (_u0), (p)->v0 = (_v0), (p)->u1 = (_u0) + (_w), (p)->v1 = (_v0), (p)->u2 = (_u0), (p)->v2 = (_v0) + (_h), (p)->u3 = (_u0) + (_w), (p)->v3 = (_v0) + (_h)
177 
178 /*
179  * Primitive Handling Macros
180  */
181 #define setusr(p, _usr) (((P_TAG *)(p))->usr = (void *)(_usr))
182 #define setz(p, _z) (((P_TAG *)(p))->z0 = (uint16)(_z))
183 #define setlen(p, _len) (((P_TAG *)(p))->len = (uint8)(_len))
184 #define setaddr(p, _addr) (((P_TAG *)(p))->addr = (void *)(_addr))
185 #define setcode(p, _code) (((P_TAG *)(p))->code = (uint8)(_code))
186 
187 #define getlen(p) (uint8)(((P_TAG *)(p))->len)
188 #define getcode(p) (uint8)(((P_TAG *)(p))->code)
189 #define getaddr(p) (void *)(((P_TAG *)(p))->addr)
190 
191 #define nextPrim(p) (void *)(((P_TAG *)(p))->addr)
192 #define isendprim(p) ((((P_TAG *)(p))->addr) == (void *)UINTPTR_MAX)
193 
194 #define addPrim(ot, p) setaddr(p, getaddr(ot)), setaddr(ot, p), setz(p, 0), setusr(p, 0)
195 #define addPrimZ(ot, p, z0) setaddr(p, getaddr(ot)), setaddr(ot, p), setz(p, z0), setusr(p, 0)
196 #define addPrimZUsr(ot, p, z0, usr) setaddr(p, getaddr(ot)), setaddr(ot, p), setz(p, z0), setusr(p, usr)
197 #define addPrims(ot, p0, p1) setaddr(p1, getaddr(ot)), setaddr(ot, p0)
198 
199 #define catPrim(p0, p1) setaddr(p0, p1)
200 #define termPrim(p) setaddr(p, (void *)UINTPTR_MAX)
201 
202 #define setSemiTrans(p, abe) ((abe) ? setcode(p, getcode(p) | 0x02) : setcode(p, getcode(p) & ~0x02))
203 
204 #define setShadeTex(p, tge) ((tge) ? setcode(p, getcode(p) | 0x01) : setcode(p, getcode(p) & ~0x01))
205 
206 #define getTPage(tp, abr, x, y) ((((tp)&0x3) << 7) | (((abr)&0x3) << 5) | (((y)&0x100) >> 4) | (((x)&0x3ff) >> 6) | (((y)&0x200) << 2))
207 
208 #define getClut(x, y) ((y << 6) | ((x >> 4) & 0x3f))
209 
210 #define dumpTPage(tpage)                                                                                                                                                           \
211 	GPU_printf("tpage: (%d,%d,%d,%d)\n", ((tpage) >> 7) & 0x003, ((tpage) >> 5) & 0x003, ((tpage) << 6) & 0x7c0, (((tpage) << 4) & 0x100) + (((tpage) >> 2) & 0x200))
212 
213 #define dumpClut(clut) GPU_printf("clut: (%d,%d)\n", (clut & 0x3f) << 4, (clut >> 6))
214 
215 #define _get_mode(dfe, dtd, tpage) ((0xe1000000) | ((dtd) ? 0x0200 : 0) | ((dfe) ? 0x0400 : 0) | ((tpage)&0x9ff))
216 
217 #define setDrawTPage(p, dfe, dtd, tpage) setlen(p, 1), ((uint32 *)(p))[2] = _get_mode(dfe, dtd, tpage)
218 
219 #define _get_tw(tw)                                                                                                                                                                \
220 	(tw ? ((0xe2000000) | ((((tw)->y & 0xff) >> 3) << 15) | ((((tw)->x & 0xff) >> 3) << 10) | (((~((tw)->h - 1) & 0xff) >> 3) << 5) | (((~((tw)->w - 1) & 0xff) >> 3))) : 0)
221 
222 #define setTexWindow(p, tw) setlen(p, 2), ((uint32 *)(p))[1] = _get_tw(tw), ((uint32 *)(p))[2] = 0
223 
224 #define _get_len(rect) (((rect)->w * (rect)->h + 1) / 2 + 4)
225 
226 #define setDrawLoad(pt, rect)                                                                                                                                                      \
227 	(_get_len(rect) <= 16) ? ((setlen(pt, _get_len(rect))), ((pt)->code[0] = 0xa0000000), ((pt)->code[1] = *((uint32 *)&(rect)->x)),                                           \
228 	                          ((pt)->code[2] = *((uint32 *)&(rect)->w)), ((pt)->p[_get_len(rect) - 4] = 0x01000000))                                                           \
229 	                       : ((setlen(pt, 0)))
230 
231 /*  Primitive   Lentgh      Code                */
232 /*--------------------------------------------------------------------  */
233 /*                                  */
234 #define setPolyF3(p) setlen(p, 4 + 3), setcode(p, 0x20)
235 #define setPolyFT3(p) setlen(p, 7 + 3), setcode(p, 0x24)
236 #define setPolyG3(p) setlen(p, 6 + 3), setcode(p, 0x30)
237 #define setPolyGT3(p) setlen(p, 9 + 3), setcode(p, 0x34)
238 #define setPolyF4(p) setlen(p, 5 + 4), setcode(p, 0x28)
239 #define setPolyFT4(p) setlen(p, 9 + 4), setcode(p, 0x2c)
240 #define setPolyG4(p) setlen(p, 8 + 4), setcode(p, 0x38)
241 #define setPolyGT4(p) setlen(p, 12 + 4), setcode(p, 0x3c)
242 
243 #define setSprt8(p) setlen(p, 3 + 1), setcode(p, 0x74)
244 #define setSprt16(p) setlen(p, 3 + 1), setcode(p, 0x7c)
245 #define setSprt(p) setlen(p, 4 + 1), setcode(p, 0x64)
246 
247 #define setTile1(p) setlen(p, 2 + 1), setcode(p, 0x68)
248 #define setTile8(p) setlen(p, 2 + 1), setcode(p, 0x70)
249 #define setTile16(p) setlen(p, 2 + 1), setcode(p, 0x78)
250 #define setTile(p) setlen(p, 3 + 1), setcode(p, 0x60)
251 #define setLineF2(p) setlen(p, 3 + 2), setcode(p, 0x40)
252 #define setLineG2(p) setlen(p, 4 + 2), setcode(p, 0x50)
253 #define setLineF3(p) setlen(p, 5 + 3), setcode(p, 0x48), (p)->pad = 0x55555555
254 #define setLineG3(p) setlen(p, 7 + 3), setcode(p, 0x58), (p)->pad = 0x55555555, (p)->p2 = 0
255 #define setLineF4(p) setlen(p, 6 + 4), setcode(p, 0x4c), (p)->pad = 0x55555555
256 #define setLineG4(p) setlen(p, 9 + 4), setcode(p, 0x5c), (p)->pad = 0x55555555, (p)->p2 = 0, (p)->p3 = 0
257 
258 /*
259  * Rectangle:
260  */
261 typedef struct {
262 	int16 x, y; /* offset point on VRAM */
263 	int16 w, h; /* width and height */
264 } RECT16;
265 
266 typedef struct {
267 	int32 x, y; /* offset point on VRAM */
268 	int32 w, h; /* width and height */
269 } RECT32;
270 
271 typedef struct {
272 	void *addr;
273 	uint16 len;
274 	uint16 z0;
275 	void *usr;
276 	uint8 r0, g0, b0, code;
277 } P_TAG;
278 
279 typedef struct { uint8 r0, g0, b0, code; } P_CODE;
280 
281 typedef struct {
282 	void *addr;
283 	uint16 len;
284 	uint16 z0;
285 	void *usr;
286 	uint8 r0, g0, b0, code;
287 } OT_tag;
288 
289 typedef struct {
290 	P_TAG tag;
291 	uint8 r0, g0, b0, code;
292 } P_HEADER;
293 
294 /*
295  * Environment
296  */
297 typedef struct {
298 	P_TAG tag;
299 	uint32 code[15];
300 } DR_ENV; /* Packed Drawing Environment */
301 
302 typedef struct {
303 	RECT16 clip;       /* clip area */
304 	int16 ofs[2];      /* drawing offset */
305 	RECT16 tw;         /* texture window */
306 	uint16 tpage;     /* texture page */
307 	uint8 dtd;        /* dither flag (0:off, 1:on) */
308 	uint8 dfe;        /* flag to draw on display area (0:off 1:on) */
309 	uint8 isbg;       /* enable to auto-clear */
310 	uint8 r0, g0, b0; /* initital background color */
311 	DR_ENV dr_env;     /* reserved */
312 } DRAWENV;
313 
314 typedef struct {
315 	RECT16 disp;       /* display area */
316 	RECT16 screen;     /* display start point */
317 	uint8 isinter;    /* interlace 0: off 1: on */
318 	uint8 isrgb24;    /* RGB24 bit mode */
319 	uint8 pad0, pad1; /* reserved */
320 } DISPENV;
321 
322 /*
323  * Polygon Primitive Definitions
324  */
325 
326 typedef struct {
327 	P_TAG tag;
328 	uint8 r0, g0, b0, code;
329 	int32 x0, y0;
330 	int32 x1, y1;
331 	int32 x2, y2;
332 } POLY_F3; /* Flat Triangle */
333 
334 typedef struct {
335 	P_TAG tag;
336 	uint8 r0, g0, b0, code;
337 	int32 x0, y0;
338 	int32 x1, y1;
339 	int32 x2, y2;
340 	int32 x3, y3;
341 } POLY_F4; /* Flat Quadrangle */
342 
343 typedef struct {
344 	P_TAG tag;
345 	uint8 r0, g0, b0, code;
346 	int32 x0, y0;
347 	uint16 u0, v0;
348 	int32 x1, y1;
349 	uint16 u1, v1;
350 	int32 x2, y2;
351 	uint16 u2, v2;
352 } POLY_FT3; /* Flat Textured Triangle */
353 
354 typedef struct {
355 	P_TAG tag;
356 	uint8 r0, g0, b0, code;
357 	int32 x0, y0;
358 	uint16 u0, v0;
359 	int32 x1, y1;
360 	uint16 u1, v1;
361 	int32 x2, y2;
362 	uint16 u2, v2;
363 	int32 x3, y3;
364 	uint16 u3, v3;
365 } POLY_FT4; /* Flat Textured Quadrangle */
366 
367 typedef struct {
368 	P_TAG tag;
369 	uint8 r0, g0, b0, code;
370 	int32 x0, y0;
371 	uint8 r1, g1, b1, pad1;
372 	int32 x1, y1;
373 	uint8 r2, g2, b2, pad2;
374 	int32 x2, y2;
375 } POLY_G3; /* Gouraud Triangle */
376 
377 typedef struct {
378 	P_TAG tag;
379 	uint8 r0, g0, b0, code;
380 	int32 x0, y0;
381 	uint8 r1, g1, b1, pad1;
382 	int32 x1, y1;
383 	uint8 r2, g2, b2, pad2;
384 	int32 x2, y2;
385 	uint8 r3, g3, b3, pad3;
386 	int32 x3, y3;
387 } POLY_G4; /* Gouraud Quadrangle */
388 
389 typedef struct {
390 	P_TAG tag;
391 	uint8 r0, g0, b0, code;
392 	int32 x0, y0;
393 	uint16 u0, v0;
394 	uint8 r1, g1, b1, p1;
395 	int32 x1, y1;
396 	uint16 u1, v1;
397 	uint8 r2, g2, b2, p2;
398 	int32 x2, y2;
399 	uint16 u2, v2;
400 } POLY_GT3; /* Gouraud Textured Triangle */
401 
402 typedef struct {
403 	P_TAG tag;
404 	uint8 r0, g0, b0, code;
405 	int32 x0, y0;
406 	uint16 u0, v0;
407 	uint8 r1, g1, b1, p1;
408 	int32 x1, y1;
409 	uint16 u1, v1;
410 	uint8 r2, g2, b2, p2;
411 	int32 x2, y2;
412 	uint16 u2, v2;
413 	uint8 r3, g3, b3, p3;
414 	int32 x3, y3;
415 	uint16 u3, v3;
416 } POLY_GT4; /* Gouraud Textured Quadrangle */
417 
418 /*
419  * Line Primitive Definitions
420  */
421 typedef struct {
422 	P_TAG tag;
423 	uint8 r0, g0, b0, code;
424 	int32 x0, y0;
425 	int32 x1, y1;
426 } LINE_F2; /* Unconnected Flat Line */
427 
428 typedef struct {
429 	P_TAG tag;
430 	uint8 r0, g0, b0, code;
431 	int32 x0, y0;
432 	uint8 r1, g1, b1, p1;
433 	int32 x1, y1;
434 } LINE_G2; /* Unconnected Gouraud Line */
435 
436 typedef struct {
437 	P_TAG tag;
438 	uint8 r0, g0, b0, code;
439 	int32 x0, y0;
440 	int32 x1, y1;
441 	int32 x2, y2;
442 	uint32 pad;
443 } LINE_F3; /* 2 connected Flat Line */
444 
445 typedef struct {
446 	P_TAG tag;
447 	uint8 r0, g0, b0, code;
448 	int32 x0, y0;
449 	uint8 r1, g1, b1, p1;
450 	int32 x1, y1;
451 	uint8 r2, g2, b2, p2;
452 	int32 x2, y2;
453 	uint32 pad;
454 } LINE_G3; /* 2 connected Gouraud Line */
455 
456 typedef struct {
457 	P_TAG tag;
458 	uint8 r0, g0, b0, code;
459 	int32 x0, y0;
460 	int32 x1, y1;
461 	int32 x2, y2;
462 	int32 x3, y3;
463 	uint32 pad;
464 } LINE_F4; /* 3 connected Flat Line Quadrangle */
465 
466 typedef struct {
467 	P_TAG tag;
468 	uint8 r0, g0, b0, code;
469 	int32 x0, y0;
470 	uint8 r1, g1, b1, p1;
471 	int32 x1, y1;
472 	uint8 r2, g2, b2, p2;
473 	int32 x2, y2;
474 	uint8 r3, g3, b3, p3;
475 	int32 x3, y3;
476 	uint32 pad;
477 } LINE_G4; /* 3 connected Gouraud Line */
478 
479 /*
480  * Sprite Primitive Definitions
481  */
482 typedef struct {
483 	P_TAG tag;
484 	uint8 r0, g0, b0, code;
485 	int32 x0, y0;
486 	uint16 u0, v0;
487 	int16 w, h;
488 } SPRT; /* free size Sprite */
489 
490 typedef struct {
491 	P_TAG tag;
492 	uint8 r0, g0, b0, code;
493 	int32 x0, y0;
494 	uint16 u0, v0;
495 } SPRT_16; /* 16x16 Sprite */
496 
497 typedef struct {
498 	P_TAG tag;
499 	uint8 r0, g0, b0, code;
500 	int32 x0, y0;
501 	uint16 u0, v0;
502 } SPRT_8; /* 8x8 Sprite */
503 
504 /*
505  * Tile Primitive Definitions
506  */
507 typedef struct {
508 	P_TAG tag;
509 	uint8 r0, g0, b0, code;
510 	int32 x0, y0;
511 	int16 w, h;
512 } TILE; /* free size Tile */
513 
514 typedef struct {
515 	P_TAG tag;
516 	uint8 r0, g0, b0, code;
517 	int32 x0, y0;
518 } TILE_16; /* 16x16 Tile */
519 
520 typedef struct {
521 	P_TAG tag;
522 	uint8 r0, g0, b0, code;
523 	int32 x0, y0;
524 } TILE_8; /* 8x8 Tile */
525 
526 typedef struct {
527 	P_TAG tag;
528 	uint8 r0, g0, b0, code;
529 	int32 x0, y0;
530 } TILE_1; /* 1x1 Tile */
531 
532 /*
533  *  Special Primitive Definitions
534  */
535 typedef struct {
536 	P_TAG tag;
537 	uint32 code[2];
538 } DR_MODE; /* Drawing Mode */
539 
540 typedef struct {
541 	P_TAG tag;
542 	uint32 code[2];
543 } DR_TWIN; /* Texture Window */
544 
545 typedef struct {
546 	P_TAG tag;
547 	uint32 code[2];
548 } DR_AREA; /* Drawing Area */
549 
550 typedef struct {
551 	P_TAG tag;
552 	uint32 code[2];
553 } DR_OFFSET; /* Drawing Offset */
554 
555 typedef struct {/* MoveImage */
556 	P_TAG tag;
557 	uint32 code[5];
558 } DR_MOVE;
559 
560 typedef struct {/* LoadImage */
561 	P_TAG tag;
562 	uint32 code[3];
563 	uint32 p[13];
564 } DR_LOAD;
565 
566 typedef struct {
567 	P_TAG tag;
568 	uint32 code[1];
569 } DR_TPAGE; /* Drawing TPage */
570 
571 typedef struct {
572 	P_TAG tag;
573 	uint32 code[2];
574 } DR_STP; /* Drawing STP */
575 
576 /*
577  *  Font Stream Parameters
578  */
579 #define FNT_MAX_ID 8      /* max number of stream ID */
580 #define FNT_MAX_SPRT 1024 /* max number of sprites in all streams */
581 
582 /*
583  *  Multi-purpose Sony-TMD primitive
584  */
585 typedef struct {
586 	uint32 id;
587 	uint8 r0, g0, b0, p0; /* Color of vertex 0 */
588 	uint8 r1, g1, b1, p1; /* Color of vertex 1 */
589 	uint8 r2, g2, b2, p2; /* Color of vertex 2 */
590 	uint8 r3, g3, b3, p3; /* Color of vertex 3 */
591 	uint16 tpage, clut;   /* texture page ID, clut ID */
592 	uint8 u0, v0, u1, v1; /* texture corner point */
593 	uint8 u2, v2, u3, v3;
594 
595 	/* independent vertex model */
596 	SVECTOR x0, x1, x2, x3; /* 3D corner point */
597 	SVECTOR n0, n1, n2, n3; /* 3D corner normal vector */
598 
599 	/* Common vertex model */
600 	SVECTOR *v_ofs; /* offset to vertex database */
601 	SVECTOR *n_ofs; /* offset to normal database */
602 
603 	uint16 vert0, vert1; /* index of vertex */
604 	uint16 vert2, vert3;
605 	uint16 norm0, norm1; /* index of normal */
606 	uint16 norm2, norm3;
607 
608 } TMD_PRIM;
609 
610 /*
611  *  Multi-purpose TIM image
612  */
613 typedef struct {
614 	uint32 mode;   /* pixel mode */
615 	RECT16 *crect; /* CLUT rectangle on frame buffer */
616 	uint32 *caddr; /* CLUT address on main memory */
617 	RECT16 *prect; /* texture image rectangle on frame buffer */
618 	uint32 *paddr; /* texture image address on main memory */
619 } TIM_IMAGE;
620 
621 extern int32 LoadImage(RECT16 *rect, uint32 *p);
622 extern OT_tag *ClearOTag(OT_tag *ot, uint32 n);
623 extern OT_tag *ClearOTagR(OT_tag *ot, uint32 n);
624 extern void DrawOTag(OT_tag *p);
625 extern void DrawPrim(void *p);
626 
627 } // End of namespace ICB
628 
629 #endif /* _LIBGPU_H_ */
630