| 1 | /* |
| 2 | * Glide64 - Glide video plugin for Nintendo 64 emulators. |
| 3 | * Copyright (c) 2002 Dave2001 |
| 4 | * Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | //**************************************************************** |
| 22 | // |
| 23 | // Glide64 - Glide Plugin for Nintendo 64 emulators |
| 24 | // Project started on December 29th, 2001 |
| 25 | // |
| 26 | // Authors: |
| 27 | // Dave2001, original author, founded the project in 2001, left it in 2002 |
| 28 | // Gugaman, joined the project in 2002, left it in 2002 |
| 29 | // Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002 |
| 30 | // Hiroshi 'KoolSmoky' Morii, joined the project in 2007 |
| 31 | // |
| 32 | //**************************************************************** |
| 33 | // |
| 34 | // To modify Glide64: |
| 35 | // * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me. |
| 36 | // * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all. |
| 37 | // |
| 38 | //**************************************************************** |
| 39 | |
| 40 | #ifndef RDP_H |
| 41 | #define RDP_H |
| 42 | |
| 43 | extern char out_buf[2048]; |
| 44 | |
| 45 | extern wxUint32 frame_count; // frame counter |
| 46 | |
| 47 | //GlideHQ support |
| 48 | #ifdef TEXTURE_FILTER |
| 49 | #include "../GlideHQ/Ext_TxFilter.h" |
| 50 | #endif |
| 51 | |
| 52 | #define MAX_CACHE 1024*4 |
| 53 | #define MAX_TRI_CACHE 768 // this is actually # of vertices, not triangles |
| 54 | #define MAX_VTX 256 |
| 55 | |
| 56 | #define MAX_TMU 2 |
| 57 | |
| 58 | #define TEXMEM_2MB_EDGE 2097152 |
| 59 | |
| 60 | // Supported flags |
| 61 | #define SUP_TEXMIRROR 0x00000001 |
| 62 | |
| 63 | // Clipping flags |
| 64 | #define CLIP_XMAX 0x00000001 |
| 65 | #define CLIP_XMIN 0x00000002 |
| 66 | #define CLIP_YMAX 0x00000004 |
| 67 | #define CLIP_YMIN 0x00000008 |
| 68 | #define CLIP_WMIN 0x00000010 |
| 69 | #define CLIP_ZMAX 0x00000020 |
| 70 | #define CLIP_ZMIN 0x00000040 |
| 71 | |
| 72 | // Flags |
| 73 | #define ZBUF_ENABLED 0x00000001 |
| 74 | #define ZBUF_DECAL 0x00000002 |
| 75 | #define ZBUF_COMPARE 0x00000004 |
| 76 | #define ZBUF_UPDATE 0x00000008 |
| 77 | #define ALPHA_COMPARE 0x00000010 |
| 78 | #define FORCE_BL 0x00000020 |
| 79 | #define CULL_FRONT 0x00001000 // * must be here |
| 80 | #define CULL_BACK 0x00002000 // * must be here |
| 81 | #define FOG_ENABLED 0x00010000 |
| 82 | |
| 83 | #define CULLMASK 0x00003000 |
| 84 | #define CULLSHIFT 12 |
| 85 | |
| 86 | // Update flags |
| 87 | #define UPDATE_ZBUF_ENABLED 0x00000001 |
| 88 | |
| 89 | #define UPDATE_TEXTURE 0x00000002 // \ Same thing! |
| 90 | #define UPDATE_COMBINE 0x00000002 // / |
| 91 | |
| 92 | #define UPDATE_CULL_MODE 0x00000004 |
| 93 | #define UPDATE_LIGHTS 0x00000010 |
| 94 | #define UPDATE_BIASLEVEL 0x00000020 |
| 95 | #define UPDATE_ALPHA_COMPARE 0x00000040 |
| 96 | #define UPDATE_VIEWPORT 0x00000080 |
| 97 | #define UPDATE_MULT_MAT 0x00000100 |
| 98 | #define UPDATE_SCISSOR 0x00000200 |
| 99 | #define UPDATE_FOG_ENABLED 0x00010000 |
| 100 | |
| 101 | #define CMB_MULT 0x00000001 |
| 102 | #define CMB_SET 0x00000002 |
| 103 | #define CMB_SUB 0x00000004 |
| 104 | #define CMB_ADD 0x00000008 |
| 105 | #define CMB_A_MULT 0x00000010 |
| 106 | #define CMB_A_SET 0x00000020 |
| 107 | #define CMB_A_SUB 0x00000040 |
| 108 | #define CMB_A_ADD 0x00000080 |
| 109 | #define CMB_SETSHADE_SHADEALPHA 0x00000100 |
| 110 | #define CMB_INTER 0x00000200 |
| 111 | #define CMB_MULT_OWN_ALPHA 0x00000400 |
| 112 | #define CMB_COL_SUB_OWN 0x00000800 |
| 113 | |
| 114 | #define uc(x) coord[x<<1] |
| 115 | #define vc(x) coord[(x<<1)+1] |
| 116 | |
| 117 | #if defined(_MSC_VER) |
| 118 | #define DECLAREALIGN16VAR(var) __declspec(align(16)) float var |
| 119 | #elif defined(__GNUG__) |
| 120 | #define DECLAREALIGN16VAR(var) float (var) __attribute__ ((aligned(16))) |
| 121 | #endif |
| 122 | |
| 123 | #ifdef __ARM_NEON__ |
| 124 | #include "arm_neon.h" |
| 125 | #endif |
| 126 | |
| 127 | // Vertex structure |
| 128 | typedef struct |
| 129 | { |
| 130 | float x, y, z, q; |
| 131 | float u0, v0, u1, v1; |
| 132 | float coord[4]; |
| 133 | float w; |
| 134 | wxUint16 flags; |
| 135 | |
| 136 | wxUint8 b; // These values are arranged like this so that *(wxUint32*)(VERTEX+?) is |
| 137 | wxUint8 g; // ARGB format that glide can use. |
| 138 | wxUint8 r; |
| 139 | wxUint8 a; |
| 140 | |
| 141 | float f; //fog |
| 142 | |
| 143 | float vec[3]; // normal vector |
| 144 | |
| 145 | float sx, sy, sz; |
| 146 | float x_w, y_w, z_w, u0_w, v0_w, u1_w, v1_w, oow; |
| 147 | wxUint8 not_zclipped; |
| 148 | wxUint8 screen_translated; |
| 149 | wxUint8 uv_scaled; |
| 150 | wxUint32 uv_calculated; // like crc |
| 151 | wxUint32 shade_mod; |
| 152 | wxUint32 color_backup; |
| 153 | |
| 154 | float ou, ov; |
| 155 | |
| 156 | int number; // way to identify it |
| 157 | int scr_off, z_off; // off the screen? |
| 158 | } VERTEX; |
| 159 | |
| 160 | // Clipping (scissors) |
| 161 | typedef struct { |
| 162 | wxUint32 ul_x; |
| 163 | wxUint32 ul_y; |
| 164 | wxUint32 lr_x; |
| 165 | wxUint32 lr_y; |
| 166 | } SCISSOR; |
| 167 | |
| 168 | #ifdef TEXTURE_FILTER |
| 169 | extern wxUint32 texfltr[]; |
| 170 | extern wxUint32 texenht[]; |
| 171 | extern wxUint32 texcmpr[]; |
| 172 | extern wxUint32 texhirs[]; |
| 173 | |
| 174 | typedef struct { |
| 175 | wxUint16 tile_ul_s; |
| 176 | wxUint16 tile_ul_t; |
| 177 | wxUint16 tile_width; |
| 178 | wxUint16 tile_height; |
| 179 | wxUint16 tex_width; |
| 180 | wxUint16 tex_size; |
| 181 | wxUint32 dxt; |
| 182 | } LOAD_TILE_INFO; |
| 183 | #endif |
| 184 | |
| 185 | // #warning no screenshot support |
| 186 | /* |
| 187 | typedef struct { |
| 188 | const wxChar * format; |
| 189 | const wxChar * extension; |
| 190 | wxBitmapType type; |
| 191 | } SCREEN_SHOT_FORMAT; |
| 192 | |
| 193 | extern const int NumOfFormats; |
| 194 | extern SCREEN_SHOT_FORMAT ScreenShotFormats[]; |
| 195 | */ |
| 196 | typedef struct { |
| 197 | int card_id; |
| 198 | int lang_id; |
| 199 | |
| 200 | wxUint32 res_x, scr_res_x; |
| 201 | wxUint32 res_y, scr_res_y; |
| 202 | wxUint32 res_data, res_data_org; |
| 203 | |
| 204 | int advanced_options; |
| 205 | int texenh_options; |
| 206 | int ssformat; |
| 207 | int vsync; |
| 208 | |
| 209 | int show_fps; |
| 210 | int clock; |
| 211 | int clock_24_hr; |
| 212 | |
| 213 | int filtering; |
| 214 | int fog; |
| 215 | int buff_clear; |
| 216 | int swapmode; |
| 217 | int lodmode; |
| 218 | #ifdef PAULSCODE |
| 219 | int autoframeskip; |
| 220 | int maxframeskip; |
| 221 | #endif |
| 222 | int aspectmode; |
| 223 | int use_hotkeys; |
| 224 | |
| 225 | //Frame buffer emulation options |
| 226 | #define fb_emulation (1<<0) //frame buffer emulation |
| 227 | #define fb_hwfbe (1<<1) //hardware frame buffer emualtion |
| 228 | #define fb_motionblur (1<<2) //emulate motion blur |
| 229 | #define fb_ref (1<<3) //read every frame |
| 230 | #define fb_read_alpha (1<<4) //read alpha |
| 231 | #define fb_hwfbe_buf_clear (1<<5) //clear auxiliary texture frame buffers |
| 232 | #define fb_depth_render (1<<6) //enable software depth render |
| 233 | #define fb_optimize_texrect (1<<7) //fast texrect rendering with hwfbe |
| 234 | #define fb_ignore_aux_copy (1<<8) //do not copy auxiliary frame buffers |
| 235 | #define fb_useless_is_useless (1<<10) // |
| 236 | #define fb_get_info (1<<11) //get frame buffer info |
| 237 | #define fb_read_back_to_screen (1<<12) //render N64 frame buffer to screen |
| 238 | #define fb_read_back_to_screen2 (1<<13) //render N64 frame buffer to screen |
| 239 | #define fb_cpu_write_hack (1<<14) //show images writed directly by CPU |
| 240 | |
| 241 | #define fb_emulation_enabled ((settings.frame_buffer&fb_emulation)>0) |
| 242 | #define fb_hwfbe_enabled ((settings.frame_buffer&(fb_emulation|fb_hwfbe))==(fb_emulation|fb_hwfbe)) |
| 243 | #define fb_depth_render_enabled ((settings.frame_buffer&fb_depth_render)>0) |
| 244 | |
| 245 | wxUint32 frame_buffer; |
| 246 | enum FBCRCMODE { |
| 247 | fbcrcNone = 0, |
| 248 | fbcrcFast = 1, |
| 249 | fbcrcSafe = 2} fb_crc_mode; |
| 250 | |
| 251 | #ifdef TEXTURE_FILTER |
| 252 | //Texture filtering options |
| 253 | int ghq_fltr; |
| 254 | int ghq_enht; |
| 255 | int ghq_cmpr; |
| 256 | int ghq_hirs; |
| 257 | int ghq_use; |
| 258 | int ghq_enht_cmpr; |
| 259 | int ghq_enht_tile; |
| 260 | int ghq_enht_f16bpp; |
| 261 | int ghq_enht_gz; |
| 262 | int ghq_enht_nobg; |
| 263 | int ghq_hirs_cmpr; |
| 264 | int ghq_hirs_tile; |
| 265 | int ghq_hirs_f16bpp; |
| 266 | int ghq_hirs_gz; |
| 267 | int ghq_hirs_altcrc; |
| 268 | int ghq_cache_save; |
| 269 | int ghq_cache_size; |
| 270 | int ghq_hirs_let_texartists_fly; |
| 271 | int ghq_hirs_dump; |
| 272 | #endif |
| 273 | |
| 274 | //Debug |
| 275 | int autodetect_ucode; |
| 276 | int ucode; |
| 277 | int logging; |
| 278 | int elogging; |
| 279 | int log_clear; |
| 280 | int run_in_window; |
| 281 | int filter_cache; |
| 282 | int unk_as_red; |
| 283 | int log_unk; |
| 284 | int unk_clear; |
| 285 | int wireframe; |
| 286 | int wfmode; |
| 287 | |
| 288 | // Special fixes |
| 289 | int offset_x, offset_y; |
| 290 | int scale_x, scale_y; |
| 291 | int fast_crc; |
| 292 | int alt_tex_size; |
| 293 | int use_sts1_only; |
| 294 | int flame_corona; //hack for zeldas flame's corona |
| 295 | int increase_texrect_edge; // add 1 to lower right corner coordinates of texrect |
| 296 | int decrease_fillrect_edge; // sub 1 from lower right corner coordinates of fillrect |
| 297 | int texture_correction; // enable perspective texture correction emulation. is on by default |
| 298 | int stipple_mode; //used for dithered alpha emulation |
| 299 | wxUint32 stipple_pattern; //used for dithered alpha emulation |
| 300 | int force_microcheck; //check microcode each frame, for mixed F3DEX-S2DEX games |
| 301 | int force_quad3d; //force 0xb5 command to be quad, not line 3d |
| 302 | int clip_zmin; //enable near z clipping |
| 303 | int clip_zmax; //enable far plane clipping; |
| 304 | int adjust_aspect; //adjust screen aspect for wide screen mode |
| 305 | int force_calc_sphere; //use spheric mapping only, Ridge Racer 64 |
| 306 | int pal230; //set special scale for PAL games |
| 307 | int correct_viewport; //correct viewport values |
| 308 | int zmode_compare_less; //force GR_CMP_LESS for zmode=0 (opaque)and zmode=1 (interpenetrating) |
| 309 | int old_style_adither; //apply alpha dither regardless of alpha_dither_mode |
| 310 | int n64_z_scale; //scale vertex z value before writing to depth buffer, as N64 does. |
| 311 | |
| 312 | //Special game hacks |
| 313 | #define hack_ASB (1<<0) //All-Star Baseball games |
| 314 | #define hack_Banjo2 (1<<1) //Banjo Tooie |
| 315 | #define hack_BAR (1<<2) //Beetle Adventure Racing |
| 316 | #define hack_Chopper (1<<3) //Chopper Attack |
| 317 | #define hack_Diddy (1<<4) //diddy kong racing |
| 318 | #define hack_Fifa98 (1<<5) //FIFA - Road to World Cup 98 |
| 319 | #define hack_Fzero (1<<6) //F-Zero |
| 320 | #define hack_GoldenEye (1<<7) //Golden Eye |
| 321 | #define hack_Hyperbike (1<<8) //Top Gear Hyper Bike |
| 322 | #define hack_ISS64 (1<<9) //International Superstar Soccer 64 |
| 323 | #define hack_KI (1<<10) //Killer Instinct |
| 324 | #define hack_Knockout (1<<11) //Knockout Kings 2000 |
| 325 | #define hack_Lego (1<<12) //LEGO Racers |
| 326 | #define hack_MK64 (1<<13) //Mario Kart |
| 327 | #define hack_Megaman (1<<14) //Megaman64 |
| 328 | #define hack_Makers (1<<15) //Mischief-makers |
| 329 | #define hack_WCWnitro (1<<16) //WCW Nitro |
| 330 | #define hack_Ogre64 (1<<17) //Ogre Battle 64 |
| 331 | #define hack_Pilotwings (1<<18) //Pilotwings |
| 332 | #define hack_PMario (1<<19) //Paper Mario |
| 333 | #define hack_PPL (1<<20) //pokemon puzzle league requires many special fixes |
| 334 | #define hack_RE2 (1<<21) //Resident Evil 2 |
| 335 | #define hack_Starcraft (1<<22) //StarCraft64 |
| 336 | #define hack_Supercross (1<<23) //Supercross 2000 |
| 337 | #define hack_TGR (1<<24) //Top Gear Rally |
| 338 | #define hack_TGR2 (1<<25) //Top Gear Rally 2 |
| 339 | #define hack_Tonic (1<<26) //tonic trouble |
| 340 | #define hack_Yoshi (1<<27) //Yoshi Story |
| 341 | #define hack_Zelda (1<<28) //zeldas hacks |
| 342 | wxUint32 hacks; |
| 343 | |
| 344 | //wrapper settings |
| 345 | int wrpResolution; |
| 346 | int wrpVRAM; |
| 347 | int wrpFBO; |
| 348 | int wrpAnisotropic; |
| 349 | |
| 350 | } SETTINGS; |
| 351 | |
| 352 | typedef struct |
| 353 | { |
| 354 | wxUint8 hk_ref; |
| 355 | wxUint8 hk_motionblur; |
| 356 | wxUint8 hk_filtering; |
| 357 | } HOTKEY_INFO; |
| 358 | |
| 359 | typedef struct |
| 360 | { |
| 361 | int num_tmu; |
| 362 | int max_tex_size; |
| 363 | int sup_large_tex; |
| 364 | int sup_mirroring; |
| 365 | int sup_32bit_tex; |
| 366 | int has_2mb_tex_boundary; |
| 367 | int tex_UMA; |
| 368 | int gamma_correction; |
| 369 | FxI32 gamma_table_size; |
| 370 | FxU32 *gamma_table_r; |
| 371 | FxU32 *gamma_table_g; |
| 372 | FxU32 *gamma_table_b; |
| 373 | wxUint32 tmem_ptr[MAX_TMU]; |
| 374 | wxUint32 tex_min_addr[MAX_TMU]; |
| 375 | wxUint32 tex_max_addr[MAX_TMU]; |
| 376 | } VOODOO; |
| 377 | |
| 378 | // This structure is what is passed in by rdp:settextureimage |
| 379 | typedef struct { |
| 380 | wxUint8 format; // format: ARGB, IA, ... |
| 381 | wxUint8 size; // size: 4,8,16, or 32 bit |
| 382 | wxUint16 width; // used in settextureimage |
| 383 | wxUint32 addr; // address in RDRAM to load the texture from |
| 384 | int set_by; // 0-loadblock 1-loadtile |
| 385 | } TEXTURE_IMAGE; |
| 386 | |
| 387 | // This structure is a tile descriptor (as used by rdp:settile and rdp:settilesize) |
| 388 | typedef struct |
| 389 | { |
| 390 | // rdp:settile |
| 391 | wxUint8 format; // format: ARGB, IA, ... |
| 392 | wxUint8 size; // size: 4,8,16, or 32 bit |
| 393 | wxUint16 line; // size of one row (x axis) in 64 bit words |
| 394 | wxUint16 t_mem; // location in texture memory (in 64 bit words, max 512 (4MB)) |
| 395 | wxUint8 palette; // palette # to use |
| 396 | wxUint8 clamp_t; // clamp or wrap (y axis)? |
| 397 | wxUint8 mirror_t; // mirroring on (y axis)? |
| 398 | wxUint8 mask_t; // mask to wrap around (ex: 5 would wrap around 32) (y axis) |
| 399 | wxUint8 shift_t; // ??? (scaling) |
| 400 | wxUint8 clamp_s; // clamp or wrap (x axis)? |
| 401 | wxUint8 mirror_s; // mirroring on (x axis)? |
| 402 | wxUint8 mask_s; // mask to wrap around (x axis) |
| 403 | wxUint8 shift_s; // ??? (scaling) |
| 404 | |
| 405 | // rdp:settilesize |
| 406 | wxUint16 ul_s; // upper left s coordinate |
| 407 | wxUint16 ul_t; // upper left t coordinate |
| 408 | wxUint16 lr_s; // lower right s coordinate |
| 409 | wxUint16 lr_t; // lower right t coordinate |
| 410 | |
| 411 | float f_ul_s; |
| 412 | float f_ul_t; |
| 413 | |
| 414 | // these are set by loadtile |
| 415 | wxUint16 t_ul_s; // upper left s coordinate |
| 416 | wxUint16 t_ul_t; // upper left t coordinate |
| 417 | wxUint16 t_lr_s; // lower right s coordinate |
| 418 | wxUint16 t_lr_t; // lower right t coordinate |
| 419 | |
| 420 | wxUint32 width; |
| 421 | wxUint32 height; |
| 422 | |
| 423 | // uc0:texture |
| 424 | wxUint8 on; |
| 425 | float s_scale; |
| 426 | float t_scale; |
| 427 | |
| 428 | wxUint16 org_s_scale; |
| 429 | wxUint16 org_t_scale; |
| 430 | } TILE; |
| 431 | |
| 432 | // This structure forms the lookup table for cached textures |
| 433 | typedef struct { |
| 434 | wxUint32 addr; // address in RDRAM |
| 435 | wxUint32 crc; // CRC check |
| 436 | wxUint32 palette; // Palette # |
| 437 | wxUint32 width; // width |
| 438 | wxUint32 height; // height |
| 439 | wxUint32 format; // format |
| 440 | wxUint32 size; // size |
| 441 | wxUint32 last_used; // what frame # was this texture last used (used for replacing) |
| 442 | |
| 443 | wxUint32 line; |
| 444 | |
| 445 | wxUint32 flags; // clamp/wrap/mirror flags |
| 446 | |
| 447 | wxUint32 realwidth; // width of actual texture |
| 448 | wxUint32 realheight; // height of actual texture |
| 449 | wxUint32 lod; |
| 450 | wxUint32 aspect; |
| 451 | |
| 452 | wxUint8 set_by; |
| 453 | wxUint8 texrecting; |
| 454 | |
| 455 | int f_mirror_s; |
| 456 | int f_mirror_t; |
| 457 | int f_wrap_s; |
| 458 | int f_wrap_t; |
| 459 | |
| 460 | float scale_x; // texture scaling |
| 461 | float scale_y; |
| 462 | float scale; // general scale to 256 |
| 463 | |
| 464 | GrTexInfo t_info; // texture info (glide) |
| 465 | wxUint32 tmem_addr; // addres in texture memory (glide) |
| 466 | |
| 467 | int uses; // 1 triangle that uses this texture |
| 468 | |
| 469 | int splits; // number of splits |
| 470 | int splitheight; |
| 471 | |
| 472 | float c_off; // ul center texel offset (both x and y) |
| 473 | float c_scl_x; // scale to lower-right center-texel x |
| 474 | float c_scl_y; // scale to lower-right center-texel y |
| 475 | |
| 476 | wxUint32 mod, mod_color, mod_color1, mod_color2, mod_factor; |
| 477 | #ifdef TEXTURE_FILTER |
| 478 | uint64 ricecrc; |
| 479 | int is_hires_tex; |
| 480 | #endif |
| 481 | } CACHE_LUT; |
| 482 | |
| 483 | // Lights |
| 484 | typedef struct { |
| 485 | float r, g, b, a; // color |
| 486 | float dir_x, dir_y, dir_z; // direction towards the light source |
| 487 | float x, y, z, w; // light position |
| 488 | float ca, la, qa; |
| 489 | wxUint32 nonblack; |
| 490 | wxUint32 nonzero; |
| 491 | } LIGHT; |
| 492 | |
| 493 | typedef enum { |
| 494 | ci_main, //0, main color image |
| 495 | ci_zimg, //1, depth image |
| 496 | ci_unknown, //2, status is unknown |
| 497 | ci_useless, //3, status is unclear |
| 498 | ci_old_copy, //4, auxiliary color image, copy of last color image from previous frame |
| 499 | ci_copy, //5, auxiliary color image, copy of previous color image |
| 500 | ci_copy_self, //6, main color image, it's content will be used to draw into itself |
| 501 | ci_zcopy, //7, auxiliary color image, copy of depth image |
| 502 | ci_aux, //8, auxiliary color image |
| 503 | ci_aux_copy //9, auxiliary color image, partial copy of previous color image |
| 504 | } CI_STATUS; |
| 505 | |
| 506 | // Frame buffers |
| 507 | typedef struct |
| 508 | { |
| 509 | wxUint32 addr; //color image address |
| 510 | wxUint8 format; |
| 511 | wxUint8 size; |
| 512 | wxUint16 width; |
| 513 | wxUint16 height; |
| 514 | CI_STATUS status; |
| 515 | int changed; |
| 516 | } COLOR_IMAGE; |
| 517 | |
| 518 | typedef struct |
| 519 | { |
| 520 | GrChipID_t tmu; |
| 521 | wxUint32 addr; //address of color image |
| 522 | wxUint32 end_addr; |
| 523 | wxUint32 tex_addr; //address in video memory |
| 524 | wxUint32 width; //width of color image |
| 525 | wxUint32 height; //height of color image |
| 526 | wxUint8 format; //format of color image |
| 527 | wxUint8 size; //format of color image |
| 528 | wxUint8 clear; //flag. texture buffer must be cleared |
| 529 | wxUint8 drawn; //flag. if equal to 1, this image was already drawn in current frame |
| 530 | wxUint32 crc; //checksum of the color image |
| 531 | float scr_width; //width of rendered image |
| 532 | float scr_height; //height of rendered image |
| 533 | wxUint32 tex_width; //width of texture buffer |
| 534 | wxUint32 tex_height; //height of texture buffer |
| 535 | int tile; // |
| 536 | wxUint16 tile_uls; //shift from left bound of the texture |
| 537 | wxUint16 tile_ult; //shift from top of the texture |
| 538 | wxUint32 v_shift; //shift from top of the texture |
| 539 | wxUint32 u_shift; //shift from left of the texture |
| 540 | float lr_u; |
| 541 | float lr_v; |
| 542 | float u_scale; //used to map vertex u,v coordinates into hires texture |
| 543 | float v_scale; //used to map vertex u,v coordinates into hires texture |
| 544 | CACHE_LUT * cache; //pointer to texture cache item |
| 545 | GrTexInfo info; |
| 546 | wxUint16 t_mem; |
| 547 | } TBUFF_COLOR_IMAGE; |
| 548 | |
| 549 | typedef struct |
| 550 | { |
| 551 | GrChipID_t tmu; |
| 552 | wxUint32 begin; //start of the block in video memory |
| 553 | wxUint32 end; //end of the block in video memory |
| 554 | wxUint8 count; //number of allocated texture buffers |
| 555 | int clear_allowed; //stack of buffers can be cleared |
| 556 | TBUFF_COLOR_IMAGE images[256]; |
| 557 | } TEXTURE_BUFFER; |
| 558 | |
| 559 | #define NUMTEXBUF 92 |
| 560 | |
| 561 | struct RDP_Base{ |
| 562 | float vi_width; |
| 563 | float vi_height; |
| 564 | |
| 565 | int window_changed; |
| 566 | |
| 567 | float offset_x, offset_y, offset_x_bak, offset_y_bak; |
| 568 | |
| 569 | float scale_x, scale_1024, scale_x_bak; |
| 570 | float scale_y, scale_768, scale_y_bak; |
| 571 | |
| 572 | float view_scale[3]; |
| 573 | float view_trans[3]; |
| 574 | float clip_min_x, clip_max_x, clip_min_y, clip_max_y; |
| 575 | float clip_ratio; |
| 576 | |
| 577 | int updatescreen; |
| 578 | |
| 579 | wxUint32 tri_n; // triangle counter |
| 580 | wxUint32 debug_n; |
| 581 | |
| 582 | // Program counter |
| 583 | wxUint32 pc[10]; // DList PC stack |
| 584 | wxUint32 pc_i; // current PC index in the stack |
| 585 | int dl_count; // number of instructions before returning |
| 586 | int LLE; |
| 587 | |
| 588 | // Segments |
| 589 | wxUint32 segment[16]; // Segment pointer |
| 590 | |
| 591 | // Marks the end of DList execution (done in uc?:enddl) |
| 592 | int halt; |
| 593 | |
| 594 | // Next command |
| 595 | wxUint32 cmd0; |
| 596 | wxUint32 cmd1; |
| 597 | wxUint32 cmd2; |
| 598 | wxUint32 cmd3; |
| 599 | |
| 600 | // Clipping |
| 601 | SCISSOR scissor_o; |
| 602 | SCISSOR scissor; |
| 603 | int scissor_set; |
| 604 | |
| 605 | // Colors |
| 606 | wxUint32 fog_color; |
| 607 | wxUint32 fill_color; |
| 608 | wxUint32 prim_color; |
| 609 | wxUint32 blend_color; |
| 610 | wxUint32 env_color; |
| 611 | wxUint32 SCALE; |
| 612 | wxUint32 CENTER; |
| 613 | wxUint32 prim_lodmin, prim_lodfrac; |
| 614 | wxUint16 prim_depth; |
| 615 | wxUint16 prim_dz; |
| 616 | wxUint8 K4; |
| 617 | wxUint8 K5; |
| 618 | enum { |
| 619 | noise_none, |
| 620 | noise_combine, |
| 621 | noise_texture |
| 622 | } noise; |
| 623 | |
| 624 | float col[4]; // color multiplier |
| 625 | float coladd[4]; // color add/subtract |
| 626 | float shade_factor; |
| 627 | |
| 628 | float col_2[4]; |
| 629 | |
| 630 | wxUint32 cmb_flags, cmb_flags_2; |
| 631 | |
| 632 | // othermode_l flags |
| 633 | int acmp; // 0 = none, 1 = threshold, 2 = dither |
| 634 | int zsrc; // 0 = pixel, 1 = prim |
| 635 | wxUint8 alpha_dither_mode; |
| 636 | |
| 637 | // Matrices |
| 638 | DECLAREALIGN16VAR(model[4][4]); |
| 639 | DECLAREALIGN16VAR(proj[4][4]); |
| 640 | DECLAREALIGN16VAR(combined[4][4]); |
| 641 | DECLAREALIGN16VAR(dkrproj[3][4][4]); |
| 642 | |
| 643 | DECLAREALIGN16VAR(model_stack[32][4][4]); // 32 deep, will warn if overflow |
| 644 | int model_i; // index in the model matrix stack |
| 645 | int model_stack_size; |
| 646 | |
| 647 | // Textures |
| 648 | TEXTURE_IMAGE timg; // 1 for each tmem address |
| 649 | TILE tiles[8]; // 8 tile descriptors |
| 650 | wxUint8 tmem[4096]; // 4k tmem |
| 651 | wxUint32 addr[512]; // 512 addresses (used to determine address loaded from) |
| 652 | #ifdef TEXTURE_FILTER |
| 653 | LOAD_TILE_INFO load_info[512]; // 512 addresses. inforamation about tile loading. |
| 654 | #endif |
| 655 | |
| 656 | int cur_tile; // current tile |
| 657 | int mipmap_level; |
| 658 | int last_tile; // last tile set |
| 659 | int last_tile_size; // last tile size set |
| 660 | |
| 661 | int t0, t1; |
| 662 | int best_tex; // if no 2-tmus, which texture? (0 or 1) |
| 663 | int tex; |
| 664 | int filter_mode; |
| 665 | |
| 666 | // Texture palette |
| 667 | wxUint16 pal_8[256]; |
| 668 | wxUint32 pal_8_crc[16]; |
| 669 | wxUint32 pal_256_crc; |
| 670 | wxUint8 tlut_mode; |
| 671 | int LOD_en; |
| 672 | int Persp_en; |
| 673 | int persp_supported; |
| 674 | int force_wrap; |
| 675 | #ifdef TEXTURE_FILTER |
| 676 | wxUint16 pal_8_rice[512]; |
| 677 | #endif |
| 678 | |
| 679 | // Lighting |
| 680 | wxUint32 num_lights; |
| 681 | LIGHT light[12]; |
| 682 | float light_vector[12][3]; |
| 683 | float lookat[2][3]; |
| 684 | int use_lookat; |
| 685 | |
| 686 | // Combine modes |
| 687 | wxUint32 cycle1, cycle2, cycle_mode; |
| 688 | wxUint8 c_a0, c_b0, c_c0, c_d0, c_Aa0, c_Ab0, c_Ac0, c_Ad0; |
| 689 | wxUint8 c_a1, c_b1, c_c1, c_d1, c_Aa1, c_Ab1, c_Ac1, c_Ad1; |
| 690 | |
| 691 | wxUint8 fbl_a0, fbl_b0, fbl_c0, fbl_d0; |
| 692 | wxUint8 fbl_a1, fbl_b1, fbl_c1, fbl_d1; |
| 693 | |
| 694 | wxUint8 uncombined; // which is uncombined: 0x01=color 0x02=alpha 0x03=both |
| 695 | |
| 696 | // float YUV_C0, YUV_C1, YUV_C2, YUV_C3, YUV_C4; //YUV textures conversion coefficients |
| 697 | |
| 698 | // What needs updating |
| 699 | wxUint32 update; |
| 700 | wxUint32 flags; |
| 701 | |
| 702 | int first; |
| 703 | |
| 704 | wxUint32 tex_ctr; // incremented every time textures are updated |
| 705 | |
| 706 | int allow_combine; // allow combine updating? |
| 707 | |
| 708 | int s2dex_tex_loaded; |
| 709 | wxUint16 bg_image_height; |
| 710 | |
| 711 | // Debug stuff |
| 712 | wxUint32 rm; // use othermode_l instead, this just as a check for changes |
| 713 | wxUint32 render_mode_changed; |
| 714 | wxUint32 geom_mode; |
| 715 | |
| 716 | wxUint32 othermode_h; |
| 717 | wxUint32 othermode_l; |
| 718 | |
| 719 | // used to check if in texrect while loading texture |
| 720 | wxUint8 texrecting; |
| 721 | |
| 722 | //frame buffer related slots. Added by Gonetz |
| 723 | wxUint32 cimg, ocimg, zimg, tmpzimg, vi_org_reg; |
| 724 | COLOR_IMAGE maincimg[2]; |
| 725 | wxUint32 last_drawn_ci_addr; |
| 726 | wxUint32 main_ci, main_ci_end, main_ci_bg, main_ci_last_tex_addr, zimg_end, last_bg; |
| 727 | wxUint32 ci_width, ci_height, ci_size, ci_end; |
| 728 | wxUint32 zi_width; |
| 729 | int zi_lrx, zi_lry; |
| 730 | wxUint8 ci_count, num_of_ci, main_ci_index, copy_ci_index, copy_zi_index; |
| 731 | int swap_ci_index, black_ci_index; |
| 732 | wxUint32 ci_upper_bound, ci_lower_bound; |
| 733 | int motionblur, fb_drawn, fb_drawn_front, read_previous_ci, read_whole_frame; |
| 734 | CI_STATUS ci_status; |
| 735 | TBUFF_COLOR_IMAGE * cur_image; //image currently being drawn |
| 736 | TBUFF_COLOR_IMAGE * tbuff_tex; //image, which corresponds to currently selected texture |
| 737 | TBUFF_COLOR_IMAGE * aTBuffTex[2]; |
| 738 | wxUint8 cur_tex_buf; |
| 739 | wxUint8 acc_tex_buf; |
| 740 | int skip_drawing; //rendering is not required. used for frame buffer emulation |
| 741 | |
| 742 | //fog related slots. Added by Gonetz |
| 743 | float fog_multiplier, fog_offset; |
| 744 | enum { |
| 745 | fog_disabled, |
| 746 | fog_enabled, |
| 747 | fog_blend, |
| 748 | fog_blend_inverse |
| 749 | } |
| 750 | fog_mode; |
| 751 | }; |
| 752 | |
| 753 | struct RDP : public RDP_Base |
| 754 | { |
| 755 | // Clipping |
| 756 | int clip; // clipping flags |
| 757 | VERTEX *vtx1; //[256] copy vertex buffer #1 (used for clipping) |
| 758 | VERTEX *vtx2; //[256] copy vertex buffer #2 |
| 759 | VERTEX *vtxbuf; // current vertex buffer (reset to vtx, used to determine current vertex buffer) |
| 760 | VERTEX *vtxbuf2; |
| 761 | int n_global; // Used to pass the number of vertices from clip_z to clip_tri |
| 762 | int vtx_buffer; |
| 763 | |
| 764 | CACHE_LUT *cache[MAX_TMU]; //[MAX_CACHE] |
| 765 | CACHE_LUT *cur_cache[MAX_TMU]; |
| 766 | wxUint32 cur_cache_n[MAX_TMU]; |
| 767 | int n_cached[MAX_TMU]; |
| 768 | |
| 769 | // Vertices |
| 770 | VERTEX *vtx; //[MAX_VTX] |
| 771 | int v0, vn; |
| 772 | |
| 773 | COLOR_IMAGE *frame_buffers; //[NUMTEXBUF+2] |
| 774 | TEXTURE_BUFFER texbufs[2]; |
| 775 | |
| 776 | char RomName[21]; |
| 777 | |
| 778 | RDP(); |
| 779 | ~RDP(); |
| 780 | void Reset(); |
| 781 | }; |
| 782 | |
| 783 | |
| 784 | void SetWireframeCol (); |
| 785 | void ChangeSize (); |
| 786 | void GoToFullScreen(); |
| 787 | |
| 788 | extern RDP rdp; |
| 789 | extern SETTINGS settings; |
| 790 | extern HOTKEY_INFO hotkey_info; |
| 791 | extern VOODOO voodoo; |
| 792 | |
| 793 | extern GrTexInfo fontTex; |
| 794 | extern GrTexInfo cursorTex; |
| 795 | extern wxUint32 offset_font; |
| 796 | extern wxUint32 offset_cursor; |
| 797 | extern wxUint32 offset_textures; |
| 798 | extern wxUint32 offset_texbuf1; |
| 799 | |
| 800 | extern int ucode_error_report; |
| 801 | |
| 802 | /* |
| 803 | extern wxString pluginPath; |
| 804 | extern wxString iniPath; |
| 805 | */ |
| 806 | // RDP functions |
| 807 | void rdp_reset (); |
| 808 | |
| 809 | extern const char *ACmp[]; |
| 810 | extern const char *Mode0[]; |
| 811 | extern const char *Mode1[]; |
| 812 | extern const char *Mode2[]; |
| 813 | extern const char *Mode3[]; |
| 814 | extern const char *Alpha0[]; |
| 815 | #define Alpha1 Alpha0 |
| 816 | extern const char *Alpha2[]; |
| 817 | #define Alpha3 Alpha0 |
| 818 | extern const char *FBLa[]; |
| 819 | extern const char *FBLb[]; |
| 820 | extern const char *FBLc[]; |
| 821 | extern const char *FBLd[]; |
| 822 | extern const char *str_zs[]; |
| 823 | extern const char *str_yn[]; |
| 824 | extern const char *str_offon[]; |
| 825 | extern const char *str_cull[]; |
| 826 | // I=intensity probably |
| 827 | extern const char *str_format[]; |
| 828 | extern const char *str_size[]; |
| 829 | extern const char *str_cm[]; |
| 830 | extern const char *str_lod[]; |
| 831 | extern const char *str_aspect[]; |
| 832 | extern const char *str_filter[]; |
| 833 | extern const char *str_tlut[]; |
| 834 | extern const char *CIStatus[]; |
| 835 | |
| 836 | #define FBL_D_1 2 |
| 837 | #define FBL_D_0 3 |
| 838 | |
| 839 | #ifndef max |
| 840 | #define max(a,b) (((a) > (b)) ? (a) : (b)) |
| 841 | #endif |
| 842 | #ifndef min |
| 843 | #define min(a,b) (((a) < (b)) ? (a) : (b)) |
| 844 | #endif |
| 845 | #ifndef TRUE |
| 846 | #define TRUE 1 |
| 847 | #endif |
| 848 | #ifndef FALSE |
| 849 | #define FALSE 0 |
| 850 | #endif |
| 851 | #ifndef HIWORD |
| 852 | #define HIWORD(a) ((unsigned int)(a) >> 16) |
| 853 | #endif |
| 854 | #ifndef LOWORD |
| 855 | #define LOWORD(a) ((a) & 0xFFFF) |
| 856 | #endif |
| 857 | |
| 858 | // Convert from u0/v0/u1/v1 to the real coordinates without regard to tmu |
| 859 | __inline void ConvertCoordsKeep (VERTEX *v, int n) |
| 860 | { |
| 861 | for (int i=0; i<n; i++) |
| 862 | { |
| 863 | v[i].uc(0) = v[i].u0; |
| 864 | v[i].vc(0) = v[i].v0; |
| 865 | v[i].uc(1) = v[i].u1; |
| 866 | v[i].vc(1) = v[i].v1; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | // Convert from u0/v0/u1/v1 to the real coordinates based on the tmu they are on |
| 871 | __inline void ConvertCoordsConvert (VERTEX *v, int n) |
| 872 | { |
| 873 | for (int i=0; i<n; i++) |
| 874 | { |
| 875 | v[i].uc(rdp.t0) = v[i].u0; |
| 876 | v[i].vc(rdp.t0) = v[i].v0; |
| 877 | v[i].uc(rdp.t1) = v[i].u1; |
| 878 | v[i].vc(rdp.t1) = v[i].v1; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | __inline void AllowShadeMods (VERTEX *v, int n) |
| 883 | { |
| 884 | for (int i=0; i<n; i++) |
| 885 | { |
| 886 | v[i].shade_mod = 0; |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | __inline void AddOffset (VERTEX *v, int n) |
| 891 | { |
| 892 | for (int i=0; i<n; i++) |
| 893 | { |
| 894 | v[i].x += rdp.offset_x; |
| 895 | v[i].y += rdp.offset_y; |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | __inline void CalculateFog (VERTEX *v) |
| 900 | { |
| 901 | if (rdp.flags & FOG_ENABLED) |
| 902 | { |
| 903 | if (v->w < 0.0f) |
| 904 | v->f = 0.0f; |
| 905 | else |
| 906 | v->f = min(255.0f, max(0.0f, v->z_w * rdp.fog_multiplier + rdp.fog_offset)); |
| 907 | v->a = (wxUint8)v->f; |
| 908 | } |
| 909 | else |
| 910 | { |
| 911 | v->f = 1.0f; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | void newSwapBuffers(); |
| 916 | extern int SwapOK; |
| 917 | |
| 918 | // ** utility functions |
| 919 | void load_palette (wxUint32 addr, wxUint16 start, wxUint16 count); |
| 920 | void setTBufTex(wxUint16 t_mem, wxUint32 cnt); |
| 921 | |
| 922 | #endif // ifndef RDP_H |