1 #ifndef _RDP_STATE_H
2 #define _RDP_STATE_H
3
4 #include <stdint.h>
5
6 #include <boolean.h>
7 #include <retro_inline.h>
8
9 #include "m64p_plugin.h"
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 #define MAXCMD 0x100000
16
17 #ifndef DP_INTERRUPT
18 #define DP_INTERRUPT 0x20
19 #endif
20
21 typedef struct
22 {
23 /* Next command */
24 uint32_t w2;
25 uint32_t w3;
26
27 uint32_t cmd_ptr;
28 uint32_t cmd_cur;
29 uint32_t cmd_data[MAXCMD + 32];
30 } RDPInfo;
31
32 extern RDPInfo __RDP;
33
34 /* Useful macros for decoding GBI command's parameters */
35
36 #ifndef _SHIFTL
37 #define _SHIFTL( v, s, w ) (((uint32_t)v & ((0x01 << w) - 1)) << s)
38 #endif
39
40 #ifndef _SHIFTR
41 #define _SHIFTR( v, s, w ) (((uint32_t)v >> s) & ((0x01 << w) - 1))
42 #endif
43
44 #ifndef SRA
45 #define SRA(exp, sa) ((signed)(exp) >> (sa))
46 #endif
47
48 #ifndef SIGN
49 #define SIGN(i, b) SRA((i) << (32 - (b)), (32 - (b)))
50 #endif
51
52 #ifndef GET_LOW
53 #define GET_LOW(x) (((x) & 0x003E) << 2)
54 #endif
55
56 #ifndef GET_MED
57 #define GET_MED(x) (((x) & 0x07C0) >> 3)
58 #endif
59
60 #ifndef GET_HI
61 #define GET_HI(x) (((x) >> 8) & 0x00F8)
62 #endif
63
64 /* Update flags */
65 #define UPDATE_ZBUF_ENABLED 0x00000001
66 #define UPDATE_TEXTURE 0x00000002 /* Same thing */
67 #define UPDATE_COMBINE 0x00000002 /* Same thing */
68
69 #define UPDATE_CULL_MODE 0x00000004
70 #define UPDATE_LIGHTS 0x00000010
71 #define UPDATE_BIASLEVEL 0x00000020
72 #define UPDATE_ALPHA_COMPARE 0x00000040
73 #define UPDATE_VIEWPORT 0x00000080
74 #define UPDATE_MULT_MAT 0x00000100
75 #define UPDATE_SCISSOR 0x00000200
76 #define UPDATE_FOG_ENABLED 0x00010000
77
78 typedef struct
79 {
80 uint32_t total;
81 uint32_t z;
82 uint16_t dz;
83 int32_t r, g, b, a, l;
84 } gdp_color;
85
86 typedef struct
87 {
88 int32_t xl, yl, xh, yh;
89 } gdp_rectangle;
90
91 typedef struct
92 {
93 int32_t clampdiffs, clampdifft;
94 int32_t clampens, clampent;
95 int32_t masksclamped, masktclamped;
96 int32_t notlutswitch, tlutswitch;
97 } gdp_faketile;
98
99 typedef struct
100 {
101 int32_t format; /* Controls the output format of the rasterized image:
102
103 000 - RGBA
104 001 - YUV
105 010 - Color Index
106 011 - Intensity Alpha
107 011 - Intensity
108 */
109 int32_t size; /* Size of an individual pixel in terms of bits:
110
111 00 - 4 bits
112 01 - 8 bits (Color Index)
113 10 - 16 bits (RGBA)
114 11 - 32 bits (RGBA)
115 */
116 int32_t line; /* size of one row (x axis) in 64 bit words */
117 int32_t tmem; /* location in texture memory (in 64 bit words, max 512 (4MB)) */
118 int32_t palette; /* palette # to use */
119 int32_t ct; /* clamp_t - Enable clamping in the T direction when texturing
120 primitives. */
121 int32_t mt; /* mirror_t - Enable mirroring in the T direction when texturing
122 primitives.*/
123 int32_t cs; /* clamp_s - Enable clamping in the S direction when texturing
124 primitives.*/
125 int32_t ms; /* mirror_s - Enable mirroring in the T direction when texturing
126 primitives.*/
127 int32_t mask_t; /* mask to wrap around (y axis) */
128 int32_t shift_t; /* level of detail shifting in the t direction (scaling) */
129 int32_t mask_s; /* mask to wrap around (x axis) */
130 int32_t shift_s; /* level of detail shift in the s direction (scaling) */
131 int32_t sl; /* lr_s - Lower right s coordinate (10.5 fixed point format) */
132 int32_t tl; /* lr_t - Lower right t coordinate (10.5 fixed point format) */
133 int32_t sh; /* ul_s - Upper left s coordinate (10.5 fixed point format) */
134 int32_t th; /* ul_t - Upper left t coordinate (10.5 fixed point format) */
135 gdp_faketile f;
136 } gdp_tile;
137
138 typedef struct
139 {
140 int32_t sub_a_rgb0; /* c_a0 */
141 int32_t sub_b_rgb0; /* c_b0 */
142 int32_t mul_rgb0; /* c_c0 */
143 int32_t add_rgb0; /* c_d0 */
144 int32_t sub_a_a0; /* c_Aa0 */
145 int32_t sub_b_a0; /* c_Ab0 */
146 int32_t mul_a0; /* c_Ac0 */
147 int32_t add_a0; /* c_Ad0 */
148
149 int32_t sub_a_rgb1; /* c_a1 */
150 int32_t sub_b_rgb1; /* c_b1 */
151 int32_t mul_rgb1; /* c_c1 */
152 int32_t add_rgb1; /* c_d1 */
153 int32_t sub_a_a1; /* c_Aa1 */
154 int32_t sub_b_a1; /* c_Ab1 */
155 int32_t mul_a1; /* c_Ac1 */
156 int32_t add_a1; /* c_Ad1 */
157 } gdp_combine_modes;
158
159 typedef struct
160 {
161 int stalederivs;
162 int dolod;
163 int partialreject_1cycle;
164 int partialreject_2cycle;
165 int special_bsel0;
166 int special_bsel1;
167 int rgb_alpha_dither;
168 } GDP_MODEDERIVS;
169
170 typedef struct
171 {
172 #if 0
173 int atomic_primitive_enable; /* Force primitive to be written to the
174 framebuffer before processing next primitive.
175 */
176 #endif
177 int cycle_type; /* Pipeline rasterization mode:
178 00 - 1 Cycle
179 01 - 2 Cycle
180 10 - Copy
181 11 - Fill
182 */
183 int persp_tex_en; /* Enable perspective correction on textures. */
184 int detail_tex_en; /* Enable detail texture. */
185 int sharpen_tex_en; /* Enable sharpen texture. */
186 int tex_lod_en; /* Enable texture level of detail (mipmapping). */
187 int en_tlut; /* Enable texture lookup table. This is useful when
188 textures are color mapped but the desired output
189 to the frame buffer is RGB. */
190 int tlut_type; /* Type of texels (texture color values) in TLUT table:
191
192 0 - 16 bit RGBA (0bRRRRRGGGGGBBBBBA)
193 1 - 16 bit IA (0xIIAA)
194 */
195 int sample_type; /* Type of texture sampling:
196
197 0 - 1x1 (point sample)
198 1 - 2x2
199 */
200 int mid_texel; /* Enable 2x2 half-texel sampling for texture filter. */
201 int bi_lerp0; /* Enables bilinear interpolation for cycle 0 when 1 Cycle
202 or 2 Cycle mode is enabled. */
203 int bi_lerp1; /* Enables bilinear interpolation for cycle 1 when 1 Cycle
204 or 2 Cycle mode is enabled. */
205 int convert_one; /* Color convert the texel outputted by the texture filter
206 on cycle 0. */
207 int key_en; /* Enable chroma keying. */
208 int rgb_dither_sel; /* Type of dithering is done to RGB values in 1 Cycle
209 or 2 Cycle modes:
210
211 00 - Magic square matrix
212 01 - Bayer matrix
213 10 - Noise
214 11 - No dither
215 */
216 int alpha_dither_sel; /* Type of dithering done to alpha values in 1 Cycle
217 or 2 Cycle modes:
218
219 00 - Pattern
220 01 - ~Pattern
221 10 - Noise
222 11 - No dither
223 */
224 int blend_m1a_0; /* Multiply blend 1a input in cycle 0. */
225 int blend_m1a_1; /* Multiply blend 1a input in cycle 1. */
226 int blend_m1b_0; /* Multiply blend 1b input in cycle 0. */
227 int blend_m1b_1; /* Multiply blend 1b input in cycle 1. */
228 int blend_m2a_0; /* Multiply blend 2a input in cycle 0. */
229 int blend_m2a_1; /* Multiply blend 2a input in cycle 1. */
230 int blend_m2b_0; /* Multiply blend 2b input in cycle 0. */
231 int blend_m2b_1; /* Multiply blend 2b input in cycle 1. */
232 int force_blend; /* Enable force blend. */
233 int alpha_cvg_select; /* Enable use of coverage bits in alpha calculation. */
234 int cvg_times_alpha; /* Enable multiplying coverage bits by alpha value
235 for final pixel alpha:
236
237 0 - Alpha = CVG
238 1 - Alpha = CVG * A
239 */
240 int z_mode; /* Mode select for Z buffer:
241
242 00 - Opaque
243 01 - Interpenetrating
244 10 - Transparent
245 11 - Decal
246 */
247 int cvg_dest; /* Mode select for handling coverage values:
248
249 00 - Clamp
250 01 - Wrap
251 10 - Force to full coverage
252 11 - Don't write back
253 */
254 int color_on_cvg; /* Only update color on coverage overflow. Useful
255 for transparent surfaces. */
256 int image_read_en; /* Enable coverage read/modify/write access to
257 frame buffer. */
258 int z_update_en; /* Enable writing new Z value if color write is
259 enabled. */
260 int z_compare_en; /* Enable conditional color write based on depth
261 comparison. */
262 int antialias_en; /* Enable anti-aliasing based on coverage bits if
263 force blend is not enabled. */
264 int z_source_sel; /* Select the source of the Z value:
265
266 0 - Pixel Z
267 1 - Primitive Z
268 */
269 int dither_alpha_en; /* Select source for alpha compare:
270
271 0 - Random noise
272 1 - Blend alpha
273 */
274 int alpha_compare_en; /* Enable conditional color write based on alpha compare. */
275 GDP_MODEDERIVS f;
276 } gdp_other_modes;
277
278 struct gdp_global
279 {
280 uint32_t flags;
281
282 int32_t ti_format; /* format: ARGB, IA, ... */
283 int32_t ti_size; /* size: 4, 8, 16, or 32-bit */
284 int32_t ti_width; /* used in rdp_settextureimage */
285 uint32_t ti_address; /* address in RDRAM to load the texture from */
286
287 int32_t primitive_lod_min;
288 int32_t primitive_lod_frac;
289 int32_t lod_frac;
290 gdp_color texel0_color;
291 gdp_color texel1_color;
292 gdp_color combined_color;
293 gdp_color prim_color;
294 gdp_color fill_color;
295 gdp_color blend_color;
296 gdp_color fog_color;
297 gdp_color env_color;
298 gdp_color key_width;
299 gdp_color key_scale;
300 gdp_color key_center;
301 int32_t k0, k1, k2, k3, k4, k5;
302 gdp_tile tile[8];
303 gdp_combine_modes combine;
304 gdp_other_modes other_modes;
305 gdp_rectangle __clip;
306 int scfield;
307 int sckeepodd;
308 uint8_t tmem[0x1000];
309 uint32_t zb_address;
310 int32_t fb_format;
311 int32_t fb_size;
312 int32_t fb_width;
313 uint32_t fb_address;
314 };
315
gdp_calculate_clamp_diffs(struct gdp_global * g_gdp,uint32_t i)316 static INLINE void gdp_calculate_clamp_diffs(struct gdp_global *g_gdp, uint32_t i)
317 {
318 g_gdp->tile[i].f.clampdiffs = ((g_gdp->tile[i].sh >> 2) - (g_gdp->tile[i].sl >> 2)) & 0x3ff;
319 g_gdp->tile[i].f.clampdifft = ((g_gdp->tile[i].th >> 2) - (g_gdp->tile[i].tl >> 2)) & 0x3ff;
320 }
321
322 void gdp_set_prim_color(uint32_t w0, uint32_t w1);
323
324 void gdp_set_prim_depth(uint32_t w0, uint32_t w1);
325
326 void gdp_set_env_color(uint32_t w0, uint32_t w1);
327
328 void gdp_set_fill_color(uint32_t w0, uint32_t w1);
329
330 void gdp_set_fog_color(uint32_t w0, uint32_t w1);
331
332 void gdp_set_blend_color(uint32_t w0, uint32_t w1);
333
334 void gdp_set_convert(uint32_t w0, uint32_t w1);
335
336 void gdp_set_key_r(uint32_t w0, uint32_t w1);
337
338 void gdp_set_key_gb(uint32_t w0, uint32_t w1);
339
340 int32_t gdp_set_tile(uint32_t w0, uint32_t w1);
341
342 int32_t gdp_set_tile_size_wrap(uint32_t w0, uint32_t w1);
343
344 void gdp_set_tile_size(uint32_t w0, uint32_t w1);
345
346 void gdp_set_combine(uint32_t w0, uint32_t w1);
347
348 void gdp_set_texture_image(uint32_t w0, uint32_t w1);
349
350 void gdp_set_scissor(uint32_t w0, uint32_t w1);
351
352 void gdp_set_other_modes(uint32_t w0, uint32_t w1);
353
354 void gdp_full_sync(uint32_t w0, uint32_t w1);
355
356 void gdp_pipe_sync(uint32_t w0, uint32_t w1);
357
358 void gdp_tile_sync(uint32_t w0, uint32_t w1);
359
360 void gdp_load_sync(uint32_t w0, uint32_t w1);
361
362 void gdp_no_op(uint32_t w0, uint32_t w1);
363
364 void gdp_invalid(uint32_t w0, uint32_t w1);
365
366 void gdp_set_mask_image(uint32_t w0, uint32_t w1);
367
368 void gdp_set_color_image(uint32_t w0, uint32_t w1);
369
rdp_read_data(uint32_t address)370 static INLINE uint32_t rdp_read_data(uint32_t address)
371 {
372 if ((*(uint32_t*)gfx_info.DPC_STATUS_REG) & 0x1) /* XBUS_DMEM_DMA enabled */
373 return ((uint32_t*)gfx_info.DMEM)[(address & 0xfff) >> 2];
374 return ((uint32_t*)gfx_info.RDRAM)[address >> 2];
375 }
376
377 bool RDP_Half1(uint32_t _c);
378
379 extern struct gdp_global g_gdp;
380
381 #ifdef __cplusplus
382 }
383 #endif
384
385 #endif
386