1 // license:BSD-3-Clause 2 // copyright-holders:Ryan Holtz 3 4 #ifndef _VIDEO_N64TYPES_H_ 5 #define _VIDEO_N64TYPES_H_ 6 7 #include "video/rgbutil.h" 8 9 struct misc_state_t 10 { misc_state_tmisc_state_t11 misc_state_t() 12 { 13 m_max_level = 0; 14 m_min_level = 0; 15 } 16 17 int32_t m_fb_format; // Framebuffer pixel format index (0 - I, 1 - IA, 2 - CI, 3 - RGBA) 18 int32_t m_fb_size; // Framebuffer pixel size index (0 - 4bpp, 1 - 8bpp, 2 - 16bpp, 3 - 32bpp) 19 int32_t m_fb_width; // Framebuffer width, in pixels 20 int32_t m_fb_height; // Framebuffer height, in pixels 21 uint32_t m_fb_address; // Framebuffer source address offset (in bytes) from start of RDRAM 22 23 uint32_t m_zb_address; // Z-buffer source address offset (in bytes) from start of RDRAM 24 25 int32_t m_ti_format; // Format for Texture Interface (TI) transfers 26 int32_t m_ti_size; // Size (in bytes) of TI transfers 27 int32_t m_ti_width; // Width (in pixels) of TI transfers 28 uint32_t m_ti_address; // Destination address for TI transfers 29 30 uint32_t m_max_level; // Maximum LOD level for texture filtering 31 uint32_t m_min_level; // Minimum LOD level for texture filtering 32 33 uint16_t m_primitive_z; // Forced Z value for current primitive, if applicable 34 uint16_t m_primitive_dz; // Forced Delta-Z value for current primitive, if applicable 35 }; 36 37 #if 0 38 class color_t 39 { 40 public: 41 color_t() 42 { 43 c = 0; 44 } 45 46 color_t(uint32_t color) 47 { 48 set(color); 49 } 50 51 color_t(uint8_t a, uint8_t r, uint8_t g, uint8_t b) 52 { 53 set(a, r, g, b); 54 } 55 56 inline void set(color_t& other) 57 { 58 c = other.c; 59 } 60 61 inline void set(uint32_t color) 62 { 63 i.a = (color >> 24) & 0xff; 64 i.r = (color >> 16) & 0xff; 65 i.g = (color >> 8) & 0xff; 66 i.b = color & 0xff; 67 } 68 69 void set(uint8_t a, uint8_t r, uint8_t g, uint8_t b) 70 { 71 i.a = a; 72 i.r = r; 73 i.g = g; 74 i.b = b; 75 } 76 77 inline void set_direct(uint32_t color) 78 { 79 c = color; 80 } 81 82 uint32_t get() 83 { 84 return i.a << 24 | i.r << 16 | i.g << 8 | i.b; 85 } 86 87 union 88 { 89 uint32_t c; 90 #ifdef LSB_FIRST 91 struct { uint8_t a, b, g, r; } i; 92 #else 93 struct { uint8_t r, g, b, a; } i; 94 #endif 95 }; 96 }; 97 #else 98 #define color_t rgbaint_t 99 #endif 100 101 enum 102 { 103 BIT_DEPTH_32 = 0, 104 BIT_DEPTH_16, 105 106 BIT_DEPTH_COUNT 107 }; 108 109 struct n64_tile_t 110 { 111 int32_t format; // Image data format: RGBA, YUV, CI, IA, I 112 int32_t size; // Size of texel element: 4b, 8b, 16b, 32b 113 int32_t line; // Size of tile line in bytes 114 int32_t tmem; // Starting tmem address for this tile in bytes 115 int32_t palette; // Palette number for 4b CI texels 116 int32_t ct, mt, cs, ms; // Clamp / mirror enable bits for S / T direction 117 int32_t mask_t, shift_t, mask_s, shift_s; // Mask values / LOD shifts 118 int32_t lshift_s, rshift_s, lshift_t, rshift_t; 119 int32_t wrapped_mask_s, wrapped_mask_t; 120 bool clamp_s, clamp_t; 121 rgbaint_t mm, invmm; 122 rgbaint_t wrapped_mask; 123 rgbaint_t mask; 124 rgbaint_t invmask; 125 rgbaint_t lshift; 126 rgbaint_t rshift; 127 rgbaint_t sth; 128 rgbaint_t stl; 129 rgbaint_t clamp_st; 130 uint16_t sl, tl, sh, th; // 10.2 fixed-point, starting and ending texel row / column 131 int32_t num; 132 }; 133 134 struct span_base_t 135 { 136 int32_t m_span_dr; 137 int32_t m_span_dg; 138 int32_t m_span_db; 139 int32_t m_span_da; 140 int32_t m_span_ds; 141 int32_t m_span_dt; 142 int32_t m_span_dw; 143 int32_t m_span_dz; 144 int32_t m_span_dymax; 145 int32_t m_span_dzpix; 146 int32_t m_span_drdy; 147 int32_t m_span_dgdy; 148 int32_t m_span_dbdy; 149 int32_t m_span_dady; 150 int32_t m_span_dzdy; 151 }; 152 153 struct combine_modes_t 154 { 155 int32_t sub_a_rgb0; 156 int32_t sub_b_rgb0; 157 int32_t mul_rgb0; 158 int32_t add_rgb0; 159 int32_t sub_a_a0; 160 int32_t sub_b_a0; 161 int32_t mul_a0; 162 int32_t add_a0; 163 164 int32_t sub_a_rgb1; 165 int32_t sub_b_rgb1; 166 int32_t mul_rgb1; 167 int32_t add_rgb1; 168 int32_t sub_a_a1; 169 int32_t sub_b_a1; 170 int32_t mul_a1; 171 int32_t add_a1; 172 }; 173 174 struct color_inputs_t 175 { 176 // combiner inputs 177 color_t* combiner_rgbsub_a[2]; 178 color_t* combiner_rgbsub_b[2]; 179 color_t* combiner_rgbmul[2]; 180 color_t* combiner_rgbadd[2]; 181 182 color_t* combiner_alphasub_a[2]; 183 color_t* combiner_alphasub_b[2]; 184 color_t* combiner_alphamul[2]; 185 color_t* combiner_alphaadd[2]; 186 187 // blender input 188 color_t* blender1a_rgb[2]; 189 color_t* blender1b_a[2]; 190 color_t* blender2a_rgb[2]; 191 color_t* blender2b_a[2]; 192 }; 193 194 struct other_modes_t 195 { 196 int32_t cycle_type; 197 bool persp_tex_en; 198 bool detail_tex_en; 199 bool sharpen_tex_en; 200 bool tex_lod_en; 201 bool en_tlut; 202 bool tlut_type; 203 bool sample_type; 204 bool mid_texel; 205 bool bi_lerp0; 206 bool bi_lerp1; 207 bool convert_one; 208 bool key_en; 209 int32_t rgb_dither_sel; 210 int32_t alpha_dither_sel; 211 int32_t blend_m1a_0; 212 int32_t blend_m1a_1; 213 int32_t blend_m1b_0; 214 int32_t blend_m1b_1; 215 int32_t blend_m2a_0; 216 int32_t blend_m2a_1; 217 int32_t blend_m2b_0; 218 int32_t blend_m2b_1; 219 int32_t tex_edge; 220 int32_t force_blend; 221 int32_t blend_shift; 222 bool alpha_cvg_select; 223 bool cvg_times_alpha; 224 int32_t z_mode; 225 int32_t cvg_dest; 226 bool color_on_cvg; 227 uint8_t image_read_en; 228 bool z_update_en; 229 bool z_compare_en; 230 bool antialias_en; 231 bool z_source_sel; 232 int32_t dither_alpha_en; 233 int32_t alpha_compare_en; 234 int32_t alpha_dither_mode; 235 }; 236 237 struct rectangle_t 238 { 239 uint16_t m_xl; // 10.2 fixed-point 240 uint16_t m_yl; // 10.2 fixed-point 241 uint16_t m_xh; // 10.2 fixed-point 242 uint16_t m_yh; // 10.2 fixed-point 243 }; 244 245 struct rdp_poly_state 246 { 247 n64_rdp* m_rdp; /* pointer back to the RDP state */ 248 249 misc_state_t m_misc_state; /* miscellaneous rasterizer bits */ 250 other_modes_t m_other_modes; /* miscellaneous rasterizer bits (2) */ 251 span_base_t m_span_base; /* span initial values for triangle rasterization */ 252 rectangle_t m_scissor; /* screen-space scissor bounds */ 253 uint32_t m_fill_color; /* poly fill color */ 254 n64_tile_t m_tiles[8]; /* texture tile state */ 255 uint8_t m_tmem[0x1000]; /* texture cache */ 256 int32_t tilenum; /* texture tile index */ 257 bool flip; /* left-major / right-major flip */ 258 bool rect; /* primitive is rectangle (vs. triangle) */ 259 }; 260 261 #define RDP_CVG_SPAN_MAX (1024) 262 263 // This is enormous and horrible 264 struct rdp_span_aux 265 { 266 uint32_t m_unscissored_rx; 267 uint16_t m_cvg[RDP_CVG_SPAN_MAX]; 268 color_t m_memory_color; 269 color_t m_pixel_color; 270 color_t m_inv_pixel_color; 271 color_t m_blended_pixel_color; 272 273 color_t m_combined_color; 274 color_t m_combined_alpha; 275 color_t m_texel0_color; 276 color_t m_texel0_alpha; 277 color_t m_texel1_color; 278 color_t m_texel1_alpha; 279 color_t m_next_texel_color; 280 color_t m_next_texel_alpha; 281 color_t m_blend_color; /* constant blend color */ 282 color_t m_prim_color; /* flat primitive color */ 283 color_t m_prim_alpha; /* flat primitive alpha */ 284 color_t m_env_color; /* generic color constant ('environment') */ 285 color_t m_env_alpha; /* generic alpha constant ('environment') */ 286 color_t m_fog_color; /* generic color constant ('fog') */ 287 color_t m_shade_color; /* gouraud-shaded color */ 288 color_t m_shade_alpha; /* gouraud-shaded alpha */ 289 color_t m_key_scale; /* color-keying constant */ 290 color_t m_noise_color; /* noise */ 291 color_t m_lod_fraction; /* Z-based LOD fraction for this poly */ 292 color_t m_prim_lod_fraction; /* fixed LOD fraction for this poly */ 293 color_t m_k4; 294 color_t m_k5; 295 color_inputs_t m_color_inputs; 296 uint32_t m_current_pix_cvg; 297 uint32_t m_current_mem_cvg; 298 uint32_t m_current_cvg_bit; 299 int32_t m_shift_a; 300 int32_t m_shift_b; 301 int32_t m_precomp_s; 302 int32_t m_precomp_t; 303 int32_t m_blend_enable; 304 bool m_pre_wrap; 305 int32_t m_dzpix_enc; 306 uint8_t* m_tmem; /* pointer to texture cache for this polygon */ 307 bool m_start_span; 308 rgbaint_t m_clamp_diff[8]; 309 }; 310 311 struct z_decompress_entry_t 312 { 313 uint32_t shift; 314 uint32_t add; 315 }; 316 317 struct cv_mask_derivative_t 318 { 319 uint8_t cvg; 320 uint8_t cvbit; 321 uint8_t xoff; 322 uint8_t yoff; 323 }; 324 325 class span_param_t 326 { 327 public: 328 union 329 { 330 uint32_t w; 331 #ifdef LSB_FIRST 332 struct { uint16_t l; int16_t h; } h; 333 #else 334 struct { int16_t h; uint16_t l; } h; 335 #endif 336 }; 337 }; 338 339 #endif // _VIDEO_N64TYPES_H_ 340