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_DEANPOLY_H
29 #define ICB_DEANPOLY_H
30 
31 namespace ICB {
32 
33 #define GPUCODE_MODE_SHADE_TEX (1 << 0)
34 #define GPUCODE_MODE_SEMI_TRANS (1 << 1)
35 
36 // GPU Primitive codes. Please remember that 3 and 4 point lines require the pad field setting to 0x55555555.
37 #define GPUCODE_POLY_F3 (0x20)
38 #define GPUCODE_POLY_FT3 (0x24)
39 #define GPUCODE_POLY_G3 (0x30)
40 #define GPUCODE_POLY_GT3 (0x34)
41 #define GPUCODE_POLY_F4 (0x28)
42 #define GPUCODE_POLY_FT4 (0x2c)
43 #define GPUCODE_POLY_G4 (0x38)
44 #define GPUCODE_POLY_GT4 (0x3c)
45 
46 #define GPUCODE_SPRT (0x64)
47 #define GPUCODE_SPRT_8 (0x74)
48 #define GPUCODE_SPRT_16 (0x7c)
49 
50 #define GPUCODE_TILE (0x60)
51 #define GPUCODE_TILE_1 (0x68)
52 #define GPUCODE_TILE_8 (0x70)
53 #define GPUCODE_TILE_16 (0x78)
54 
55 #define GPUCODE_LINE_F2 (0x40)
56 #define GPUCODE_LINE_G2 (0x50)
57 #define GPUCODE_LINE_F3 (0x48)
58 #define GPUCODE_LINE_G3 (0x58)
59 #define GPUCODE_LINE_F4 (0x4c)
60 #define GPUCODE_LINE_G4 (0x5c)
61 
62 #define GPUSIZE_POLY_F3 (4 + 3)
63 #define GPUSIZE_POLY_FT3 (7 + 3)
64 #define GPUSIZE_POLY_G3 (6 + 3)
65 #define GPUSIZE_POLY_GT3 (9 + 3)
66 #define GPUSIZE_POLY_F4 (5 + 4)
67 #define GPUSIZE_POLY_FT4 (9 + 4)
68 #define GPUSIZE_POLY_G4 (8 + 4)
69 #define GPUSIZE_POLY_GT4 (12 + 4)
70 
71 #define GPUSIZE_SPRT (4 + 1)
72 #define GPUSIZE_SPRT_8 (3 + 1)
73 #define GPUSIZE_SPRT_16 (3 + 1)
74 
75 #define GPUSIZE_TILE (3 + 1)
76 #define GPUSIZE_TILE_1 (2 + 1)
77 #define GPUSIZE_TILE_8 (2 + 1)
78 #define GPUSIZE_TILE_16 (2 + 1)
79 
80 #define GPUSIZE_LINE_F2 (3 + 2)
81 #define GPUSIZE_LINE_G2 (4 + 2)
82 #define GPUSIZE_LINE_F3 (5 + 3)
83 #define GPUSIZE_LINE_G3 (7 + 3)
84 #define GPUSIZE_LINE_F4 (6 + 4)
85 #define GPUSIZE_LINE_G4 (9 + 4)
86 
87 #define GPUSIZE_DR_TPAGE (1)
88 #define GPUSIZE_TAG (4)
89 
90 #define GPUSIZE_TPOLY_F3 (GPUSIZE_DR_TPAGE + GPUSIZE_POLY_F3 + GPUSIZE_TAG)
91 #define GPUSIZE_TPOLY_F4 (GPUSIZE_DR_TPAGE + GPUSIZE_POLY_F4 + GPUSIZE_TAG)
92 #define GPUSIZE_TPOLY_G3 (GPUSIZE_DR_TPAGE + GPUSIZE_POLY_G3 + GPUSIZE_TAG)
93 #define GPUSIZE_TPOLY_G4 (GPUSIZE_DR_TPAGE + GPUSIZE_POLY_G4 + GPUSIZE_TAG)
94 
95 #define GPUSIZE_TLINE_F2 (GPUSIZE_DR_TPAGE + GPUSIZE_LINE_F3 + GPUSIZE_TAG)
96 #define GPUSIZE_TLINE_G2 (GPUSIZE_DR_TPAGE + GPUSIZE_LINE_G2 + GPUSIZE_TAG)
97 #define GPUSIZE_TLINE_F3 (GPUSIZE_DR_TPAGE + GPUSIZE_LINE_F3 + GPUSIZE_TAG)
98 #define GPUSIZE_TLINE_G3 (GPUSIZE_DR_TPAGE + GPUSIZE_LINE_G3 + GPUSIZE_TAG)
99 #define GPUSIZE_TLINE_F4 (GPUSIZE_DR_TPAGE + GPUSIZE_LINE_F4 + GPUSIZE_TAG)
100 #define GPUSIZE_TLINE_G4 (GPUSIZE_DR_TPAGE + GPUSIZE_LINE_G4 + GPUSIZE_TAG)
101 
102 #define GPUSIZE_TSPRT (GPUSIZE_DR_TPAGE + GPUSIZE_SPRT + GPUSIZE_TAG)
103 #define GPUSIZE_TSPRT_8 (GPUSIZE_DR_TPAGE + GPUSIZE_SPRT_8 + GPUSIZE_TAG)
104 #define GPUSIZE_TSPRT_16 (GPUSIZE_DR_TPAGE + GPUSIZE_SPRT_16 + GPUSIZE_TAG)
105 
106 #define GPUSIZE_TTILE (GPUSIZE_DR_TPAGE + GPUSIZE_TILE + GPUSIZE_TAG)
107 #define GPUSIZE_TTILE_1 (GPUSIZE_DR_TPAGE + GPUSIZE_TILE_1 + GPUSIZE_TAG)
108 #define GPUSIZE_TTILE_8 (GPUSIZE_DR_TPAGE + GPUSIZE_TILE_8 + GPUSIZE_TAG)
109 #define GPUSIZE_TTILE_16 (GPUSIZE_DR_TPAGE + GPUSIZE_TILE_16 + GPUSIZE_TAG)
110 
111 #define setTcode(p, tc) (*(uint32 *)&(((P_TAG *)(p))->r0) = (uint32)(tc))
112 
113 #define zeroTagPoly(p) (setaddr((&(p)->tag_poly), 0), setlen((&(p)->tag_poly), 0) = 0)
114 
115 #define setlen(p, _len) (((P_TAG *)(p))->len = (uint8)(_len))
116 
117 #define setTDrawTPageSize(p, s) setlen((p), (s)), setTcode((p), _get_mode(0, 1, 0))
118 
119 #define setTDrawTPage(p) setTDrawTPageSize((p), 1)
120 
121 #define setTPolyF3(p) setTDrawTPageSize((p), GPUSIZE_TPOLY_F3), setcode(&((p)->tag_poly), GPUCODE_POLY_F3), zeroTagPoly((p))
122 #define setTPolyF4(p) setTDrawTPageSize((p), GPUSIZE_TPOLY_F4), setcode(&((p)->tag_poly), GPUCODE_POLY_F4), zeroTagPoly((p))
123 
124 #define setTPolyG3(p) setTDrawTPageSize((p), GPUSIZE_TPOLY_G3), setcode(&((p)->tag_poly), GPUCODE_POLY_G3), zeroTagPoly((p))
125 #define setTPolyG4(p) setTDrawTPageSize((p), GPUSIZE_TPOLY_G4), setcode(&((p)->tag_poly), GPUCODE_POLY_G4), zeroTagPoly((p))
126 
127 #define setTLineF2(p) setTDrawTPageSize((p), GPUSIZE_TLINE_F2), setcode(&((p)->tag_poly), GPUCODE_LINE_F2), zeroTagPoly((p))
128 #define setTLineG2(p) setTDrawTPageSize((p), GPUSIZE_TLINE_G2), setcode(&((p)->tag_poly), GPUCODE_LINE_G2), zeroTagPoly((p))
129 #define setTLineF3(p) setTDrawTPageSize((p), GPUSIZE_TLINE_F3), setcode(&((p)->tag_poly), GPUCODE_LINE_F3), zeroTagPoly((p)), ((p)->pad) = 0x55555555
130 #define setTLineG3(p) setTDrawTPageSize((p), GPUSIZE_TLINE_G3), setcode(&((p)->tag_poly), GPUCODE_LINE_G3), zeroTagPoly((p)), ((p)->pad) = 0x55555555
131 #define setTLineF4(p) setTDrawTPageSize((p), GPUSIZE_TLINE_F4), setcode(&((p)->tag_poly), GPUCODE_LINE_F4), zeroTagPoly((p)), ((p)->pad) = 0x55555555
132 #define setTLineG4(p) setTDrawTPageSize((p), GPUSIZE_TLINE_G4), setcode(&((p)->tag_poly), GPUCODE_LINE_G4), zeroTagPoly((p)), ((p)->pad) = 0x55555555
133 
134 #define setTSprt(p) setTDrawTPageSize((p), GPUSIZE_TSPRT), setcode(&((p)->tag_poly), GPUCODE_SPRT), zeroTagPoly((p))
135 #define setTSprt8(p) setTDrawTPageSize((p), GPUSIZE_TSPRT_8), setcode(&((p)->tag_poly), GPUCODE_SPRT_8), zeroTagPoly((p))
136 #define setTSprt16(p) setTDrawTPageSize((p), GPUSIZE_TSPRT_16), setcode(&((p)->tag_poly), GPUCODE_SPRT_16), zeroTagPoly((p))
137 
138 #define setTTile(p) setTDrawTPageSize((p), GPUSIZE_TTILE), setcode(&((p)->tag_poly), GPUCODE_TILE), zeroTagPoly((p))
139 #define setTTile1(p) setTDrawTPageSize((p), GPUSIZE_TTILE_1), setcode(&((p)->tag_poly), GPUCODE_TILE_1), zeroTagPoly((p))
140 #define setTTile8(p) setTDrawTPageSize((p), GPUSIZE_TTILE_8), setcode(&((p)->tag_poly), GPUCODE_TILE_8), zeroTagPoly((p))
141 #define setTTile16(p) setTDrawTPageSize((p), GPUSIZE_TTILE_16), setcode(&((p)->tag_poly), GPUCODE_TILE_16), zeroTagPoly((p))
142 
143 #define setTSemiTrans(p, abe) setSemiTrans(&((p)->tag_poly), (abe))
144 #define setTABRMode(p, abr) setTcode((p), _get_mode(0, 1, (abr << 5)))
145 #define setTSprtTPage(p, tp) setTcode((p), _get_mode(0, 1, (tp)))
146 #define setTSprtTPageABR(p, t, a) setTcode((p), _get_mode(0, 1, (((t)&0x19f) | ((a) << 5))))
147 
148 #define addPrimSize(ot, p, size) (p)->tag = ((*(ot)) | ((size) << 24)), *((ot)) = (((uint32)(p) << 8) >> 8)
149 
150 typedef struct __tpoly_f3 {
151 	P_TAG tag;
152 	OT_tag tag_poly;
153 	uint8 r0, g0, b0, code;
154 	int32 x0, y0;
155 	int32 x1, y1;
156 	int32 x2, y2;
157 } TPOLY_F3; // Flat Triangle with ABR control
158 
159 typedef struct __tpoly_f4 {
160 	P_TAG tag;
161 	OT_tag tag_poly;
162 	uint8 r0, g0, b0, code;
163 	int32 x0, y0;
164 	int32 x1, y1;
165 	int32 x2, y2;
166 	int32 x3, y3;
167 } TPOLY_F4; // Flat Quadrangle with ABR control
168 
169 typedef struct __tpoly_g3 {
170 	P_TAG tag;
171 	OT_tag tag_poly;
172 	uint8 r0, g0, b0, code;
173 	int32 x0, y0;
174 	uint8 r1, g1, b1, pad1;
175 	int32 x1, y1;
176 	uint8 r2, g2, b2, pad2;
177 	int32 x2, y2;
178 } TPOLY_G3; // Gouraud Triangle with ABR control
179 
180 typedef struct __tpoly_g4 {
181 	P_TAG tag;
182 	OT_tag tag_poly;
183 	uint8 r0, g0, b0, code;
184 	int32 x0, y0;
185 	uint8 r1, g1, b1, pad1;
186 	int32 x1, y1;
187 	uint8 r2, g2, b2, pad2;
188 	int32 x2, y2;
189 	uint8 r3, g3, b3, pad3;
190 	int32 x3, y3;
191 } TPOLY_G4; // Gouraud Quadrangle with ABR control
192 
193 typedef struct __tline_f2 {
194 	P_TAG tag;
195 	OT_tag tag_poly;
196 	uint8 r0, g0, b0, code;
197 	int32 x0, y0;
198 	int32 x1, y1;
199 } TLINE_F2; // Unconnected Flat Line with ABR control
200 
201 typedef struct __tline_g2 {
202 	P_TAG tag;
203 	OT_tag tag_poly;
204 	uint8 r0, g0, b0, code;
205 	int32 x0, y0;
206 	uint8 r1, g1, b1, p1;
207 	int32 x1, y1;
208 } TLINE_G2; // Unconnected Gouraud Line with ABR control
209 
210 typedef struct __tline_f3 {
211 	P_TAG tag;
212 	OT_tag tag_poly;
213 	uint8 r0, g0, b0, code;
214 	int32 x0, y0;
215 	int32 x1, y1;
216 	int32 x2, y2;
217 	uint32 pad;
218 } TLINE_F3; // 2 connected Flat Line with ABR control
219 
220 typedef struct __tline_g3 {
221 	P_TAG tag;
222 	OT_tag tag_poly;
223 	uint8 r0, g0, b0, code;
224 	int32 x0, y0;
225 	uint8 r1, g1, b1, p1;
226 	int32 x1, y1;
227 	uint8 r2, g2, b2, p2;
228 	int32 x2, y2;
229 	uint32 pad;
230 } TLINE_G3; // 2 connected Gouraud Line with ABR control
231 
232 typedef struct __tline_f4 {
233 	P_TAG tag;
234 	OT_tag tag_poly;
235 	uint8 r0, g0, b0, code;
236 	int32 x0, y0;
237 	int32 x1, y1;
238 	int32 x2, y2;
239 	int32 x3, y3;
240 	uint32 pad;
241 } TLINE_F4; // 3 connected Flat Line Quadrangle with ABR control
242 
243 typedef struct __tline_g4 {
244 	P_TAG tag;
245 	OT_tag tag_poly;
246 	uint8 r0, g0, b0, code;
247 	int32 x0, y0;
248 	uint8 r1, g1, b1, p1;
249 	int32 x1, y1;
250 	uint8 r2, g2, b2, p2;
251 	int32 x2, y2;
252 	uint8 r3, g3, b3, p3;
253 	int32 x3, y3;
254 	uint32 pad;
255 } TLINE_G4; // 3 connected Gouraud Line with ABR control
256 
257 // Sprite Primitive Definitions
258 typedef struct __tsprt {
259 	P_TAG tag;
260 	OT_tag tag_poly;
261 	uint8 r0, g0, b0, code;
262 	int32 x0, y0;
263 	uint8 u0, v0;
264 	uint16 clut;
265 	int16 w, h;
266 } TSPRT; // Free size Sprite with TPage/ABR control
267 
268 typedef struct __tsprt_16 {
269 	P_TAG tag;
270 	OT_tag tag_poly;
271 	uint8 r0, g0, b0, code;
272 	int32 x0, y0;
273 	uint8 u0, v0;
274 	uint16 clut;
275 } TSPRT_16; // 16x16 Sprite with TPage/ABR control
276 
277 typedef struct __tsprt_8 {
278 	P_TAG tag;
279 	OT_tag tag_poly;
280 	uint8 r0, g0, b0, code;
281 	int32 x0, y0;
282 	uint8 u0, v0;
283 	uint16 clut;
284 } TSPRT_8; // 8x8 Sprite with TPage/ABR control
285 
286 typedef struct __ttile {
287 	P_TAG tag;
288 	OT_tag tag_poly;
289 	uint8 r0, g0, b0, code;
290 	int32 x0, y0;
291 	int16 w, h;
292 } TTILE; // free size Tile with ABR control
293 
294 typedef struct __ttile16 {
295 	P_TAG tag;
296 	OT_tag tag_poly;
297 	uint8 r0, g0, b0, code;
298 	int32 x0, y0;
299 } TTILE_16; // 16x16 Tile with ABR control
300 
301 typedef struct __ttile_8 {
302 	P_TAG tag;
303 	OT_tag tag_poly;
304 	uint8 r0, g0, b0, code;
305 	int32 x0, y0;
306 } TTILE_8; // 8x8 Tile with ABR control
307 
308 typedef struct __ttile_1 {
309 	P_TAG tag;
310 	OT_tag tag_poly;
311 	uint8 r0, g0, b0, code;
312 	int32 x0, y0;
313 } TTILE_1; // 1x1 Tile with ABR control
314 
315 } // End of namespace ICB
316 
317 #endif // __DEANPOLY_H
318