98e75f2d |
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 | |
c35c7a7e |
225 | /* game specific settings */ |
226 | int special_alt_tex_size; |
227 | int special_use_sts1_only; |
228 | int special_force_calc_sphere; |
229 | int special_correct_viewport; |
230 | int special_increase_texrect_edge; |
231 | int special_decrease_fillrect_edge; |
232 | int special_texture_correction; |
233 | int special_pal230; |
234 | int special_stipple_mode; |
235 | int special_stipple_pattern; |
236 | int special_force_microcheck; |
237 | int special_force_quad3d; |
238 | int special_clip_zmin; |
239 | int special_clip_zmax; |
240 | int special_fast_crc; |
241 | int special_adjust_aspect; |
242 | int special_zmode_compare_less; |
243 | int special_old_style_adither; |
244 | int special_n64_z_scale; |
245 | int special_optimize_texrect; |
246 | int special_ignore_aux_copy; |
247 | int special_hires_buf_clear; |
248 | int special_fb_read_alpha; |
249 | int special_useless_is_useless; |
250 | int special_fb_crc_mode; |
251 | int special_filtering; |
252 | int special_fog; |
253 | int special_buff_clear; |
254 | int special_swapmode; |
255 | int special_aspect; |
256 | int special_lodmode; |
257 | int special_fb_smart; |
258 | int special_fb_hires; |
259 | int special_fb_read_always; |
260 | int special_read_back_to_screen; |
261 | int special_detect_cpu_write; |
262 | int special_fb_get_info; |
263 | int special_fb_render; |
264 | |
98e75f2d |
265 | //Frame buffer emulation options |
266 | #define fb_emulation (1<<0) //frame buffer emulation |
267 | #define fb_hwfbe (1<<1) //hardware frame buffer emualtion |
268 | #define fb_motionblur (1<<2) //emulate motion blur |
269 | #define fb_ref (1<<3) //read every frame |
270 | #define fb_read_alpha (1<<4) //read alpha |
271 | #define fb_hwfbe_buf_clear (1<<5) //clear auxiliary texture frame buffers |
272 | #define fb_depth_render (1<<6) //enable software depth render |
273 | #define fb_optimize_texrect (1<<7) //fast texrect rendering with hwfbe |
274 | #define fb_ignore_aux_copy (1<<8) //do not copy auxiliary frame buffers |
275 | #define fb_useless_is_useless (1<<10) // |
276 | #define fb_get_info (1<<11) //get frame buffer info |
277 | #define fb_read_back_to_screen (1<<12) //render N64 frame buffer to screen |
278 | #define fb_read_back_to_screen2 (1<<13) //render N64 frame buffer to screen |
279 | #define fb_cpu_write_hack (1<<14) //show images writed directly by CPU |
280 | |
281 | #define fb_emulation_enabled ((settings.frame_buffer&fb_emulation)>0) |
282 | #define fb_hwfbe_enabled ((settings.frame_buffer&(fb_emulation|fb_hwfbe))==(fb_emulation|fb_hwfbe)) |
283 | #define fb_depth_render_enabled ((settings.frame_buffer&fb_depth_render)>0) |
284 | |
285 | wxUint32 frame_buffer; |
286 | enum FBCRCMODE { |
287 | fbcrcNone = 0, |
288 | fbcrcFast = 1, |
289 | fbcrcSafe = 2} fb_crc_mode; |
290 | |
291 | #ifdef TEXTURE_FILTER |
292 | //Texture filtering options |
293 | int ghq_fltr; |
294 | int ghq_enht; |
295 | int ghq_cmpr; |
296 | int ghq_hirs; |
297 | int ghq_use; |
298 | int ghq_enht_cmpr; |
299 | int ghq_enht_tile; |
300 | int ghq_enht_f16bpp; |
301 | int ghq_enht_gz; |
302 | int ghq_enht_nobg; |
303 | int ghq_hirs_cmpr; |
304 | int ghq_hirs_tile; |
305 | int ghq_hirs_f16bpp; |
306 | int ghq_hirs_gz; |
307 | int ghq_hirs_altcrc; |
308 | int ghq_cache_save; |
309 | int ghq_cache_size; |
310 | int ghq_hirs_let_texartists_fly; |
311 | int ghq_hirs_dump; |
312 | #endif |
313 | |
314 | //Debug |
315 | int autodetect_ucode; |
316 | int ucode; |
317 | int logging; |
318 | int elogging; |
319 | int log_clear; |
320 | int run_in_window; |
321 | int filter_cache; |
322 | int unk_as_red; |
323 | int log_unk; |
324 | int unk_clear; |
325 | int wireframe; |
326 | int wfmode; |
327 | |
328 | // Special fixes |
329 | int offset_x, offset_y; |
330 | int scale_x, scale_y; |
331 | int fast_crc; |
332 | int alt_tex_size; |
333 | int use_sts1_only; |
334 | int flame_corona; //hack for zeldas flame's corona |
335 | int increase_texrect_edge; // add 1 to lower right corner coordinates of texrect |
336 | int decrease_fillrect_edge; // sub 1 from lower right corner coordinates of fillrect |
337 | int texture_correction; // enable perspective texture correction emulation. is on by default |
338 | int stipple_mode; //used for dithered alpha emulation |
339 | wxUint32 stipple_pattern; //used for dithered alpha emulation |
340 | int force_microcheck; //check microcode each frame, for mixed F3DEX-S2DEX games |
341 | int force_quad3d; //force 0xb5 command to be quad, not line 3d |
342 | int clip_zmin; //enable near z clipping |
343 | int clip_zmax; //enable far plane clipping; |
344 | int adjust_aspect; //adjust screen aspect for wide screen mode |
345 | int force_calc_sphere; //use spheric mapping only, Ridge Racer 64 |
346 | int pal230; //set special scale for PAL games |
347 | int correct_viewport; //correct viewport values |
348 | int zmode_compare_less; //force GR_CMP_LESS for zmode=0 (opaque)and zmode=1 (interpenetrating) |
349 | int old_style_adither; //apply alpha dither regardless of alpha_dither_mode |
350 | int n64_z_scale; //scale vertex z value before writing to depth buffer, as N64 does. |
351 | |
352 | //Special game hacks |
353 | #define hack_ASB (1<<0) //All-Star Baseball games |
354 | #define hack_Banjo2 (1<<1) //Banjo Tooie |
355 | #define hack_BAR (1<<2) //Beetle Adventure Racing |
356 | #define hack_Chopper (1<<3) //Chopper Attack |
357 | #define hack_Diddy (1<<4) //diddy kong racing |
358 | #define hack_Fifa98 (1<<5) //FIFA - Road to World Cup 98 |
359 | #define hack_Fzero (1<<6) //F-Zero |
360 | #define hack_GoldenEye (1<<7) //Golden Eye |
361 | #define hack_Hyperbike (1<<8) //Top Gear Hyper Bike |
362 | #define hack_ISS64 (1<<9) //International Superstar Soccer 64 |
363 | #define hack_KI (1<<10) //Killer Instinct |
364 | #define hack_Knockout (1<<11) //Knockout Kings 2000 |
365 | #define hack_Lego (1<<12) //LEGO Racers |
366 | #define hack_MK64 (1<<13) //Mario Kart |
367 | #define hack_Megaman (1<<14) //Megaman64 |
368 | #define hack_Makers (1<<15) //Mischief-makers |
369 | #define hack_WCWnitro (1<<16) //WCW Nitro |
370 | #define hack_Ogre64 (1<<17) //Ogre Battle 64 |
371 | #define hack_Pilotwings (1<<18) //Pilotwings |
372 | #define hack_PMario (1<<19) //Paper Mario |
373 | #define hack_PPL (1<<20) //pokemon puzzle league requires many special fixes |
374 | #define hack_RE2 (1<<21) //Resident Evil 2 |
375 | #define hack_Starcraft (1<<22) //StarCraft64 |
376 | #define hack_Supercross (1<<23) //Supercross 2000 |
377 | #define hack_TGR (1<<24) //Top Gear Rally |
378 | #define hack_TGR2 (1<<25) //Top Gear Rally 2 |
379 | #define hack_Tonic (1<<26) //tonic trouble |
380 | #define hack_Yoshi (1<<27) //Yoshi Story |
381 | #define hack_Zelda (1<<28) //zeldas hacks |
382 | wxUint32 hacks; |
383 | |
384 | //wrapper settings |
385 | int wrpResolution; |
386 | int wrpVRAM; |
387 | int wrpFBO; |
388 | int wrpAnisotropic; |
389 | |
390 | } SETTINGS; |
391 | |
392 | typedef struct |
393 | { |
394 | wxUint8 hk_ref; |
395 | wxUint8 hk_motionblur; |
396 | wxUint8 hk_filtering; |
397 | } HOTKEY_INFO; |
398 | |
399 | typedef struct |
400 | { |
401 | int num_tmu; |
402 | int max_tex_size; |
403 | int sup_large_tex; |
404 | int sup_mirroring; |
405 | int sup_32bit_tex; |
406 | int has_2mb_tex_boundary; |
407 | int tex_UMA; |
408 | int gamma_correction; |
409 | FxI32 gamma_table_size; |
410 | FxU32 *gamma_table_r; |
411 | FxU32 *gamma_table_g; |
412 | FxU32 *gamma_table_b; |
413 | wxUint32 tmem_ptr[MAX_TMU]; |
414 | wxUint32 tex_min_addr[MAX_TMU]; |
415 | wxUint32 tex_max_addr[MAX_TMU]; |
416 | } VOODOO; |
417 | |
418 | // This structure is what is passed in by rdp:settextureimage |
419 | typedef struct { |
420 | wxUint8 format; // format: ARGB, IA, ... |
421 | wxUint8 size; // size: 4,8,16, or 32 bit |
422 | wxUint16 width; // used in settextureimage |
423 | wxUint32 addr; // address in RDRAM to load the texture from |
424 | int set_by; // 0-loadblock 1-loadtile |
425 | } TEXTURE_IMAGE; |
426 | |
427 | // This structure is a tile descriptor (as used by rdp:settile and rdp:settilesize) |
428 | typedef struct |
429 | { |
430 | // rdp:settile |
431 | wxUint8 format; // format: ARGB, IA, ... |
432 | wxUint8 size; // size: 4,8,16, or 32 bit |
433 | wxUint16 line; // size of one row (x axis) in 64 bit words |
434 | wxUint16 t_mem; // location in texture memory (in 64 bit words, max 512 (4MB)) |
435 | wxUint8 palette; // palette # to use |
436 | wxUint8 clamp_t; // clamp or wrap (y axis)? |
437 | wxUint8 mirror_t; // mirroring on (y axis)? |
438 | wxUint8 mask_t; // mask to wrap around (ex: 5 would wrap around 32) (y axis) |
439 | wxUint8 shift_t; // ??? (scaling) |
440 | wxUint8 clamp_s; // clamp or wrap (x axis)? |
441 | wxUint8 mirror_s; // mirroring on (x axis)? |
442 | wxUint8 mask_s; // mask to wrap around (x axis) |
443 | wxUint8 shift_s; // ??? (scaling) |
444 | |
445 | // rdp:settilesize |
446 | wxUint16 ul_s; // upper left s coordinate |
447 | wxUint16 ul_t; // upper left t coordinate |
448 | wxUint16 lr_s; // lower right s coordinate |
449 | wxUint16 lr_t; // lower right t coordinate |
450 | |
451 | float f_ul_s; |
452 | float f_ul_t; |
453 | |
454 | // these are set by loadtile |
455 | wxUint16 t_ul_s; // upper left s coordinate |
456 | wxUint16 t_ul_t; // upper left t coordinate |
457 | wxUint16 t_lr_s; // lower right s coordinate |
458 | wxUint16 t_lr_t; // lower right t coordinate |
459 | |
460 | wxUint32 width; |
461 | wxUint32 height; |
462 | |
463 | // uc0:texture |
464 | wxUint8 on; |
465 | float s_scale; |
466 | float t_scale; |
467 | |
468 | wxUint16 org_s_scale; |
469 | wxUint16 org_t_scale; |
470 | } TILE; |
471 | |
472 | // This structure forms the lookup table for cached textures |
473 | typedef struct { |
474 | wxUint32 addr; // address in RDRAM |
475 | wxUint32 crc; // CRC check |
476 | wxUint32 palette; // Palette # |
477 | wxUint32 width; // width |
478 | wxUint32 height; // height |
479 | wxUint32 format; // format |
480 | wxUint32 size; // size |
481 | wxUint32 last_used; // what frame # was this texture last used (used for replacing) |
482 | |
483 | wxUint32 line; |
484 | |
485 | wxUint32 flags; // clamp/wrap/mirror flags |
486 | |
487 | wxUint32 realwidth; // width of actual texture |
488 | wxUint32 realheight; // height of actual texture |
489 | wxUint32 lod; |
490 | wxUint32 aspect; |
491 | |
492 | wxUint8 set_by; |
493 | wxUint8 texrecting; |
494 | |
495 | int f_mirror_s; |
496 | int f_mirror_t; |
497 | int f_wrap_s; |
498 | int f_wrap_t; |
499 | |
500 | float scale_x; // texture scaling |
501 | float scale_y; |
502 | float scale; // general scale to 256 |
503 | |
504 | GrTexInfo t_info; // texture info (glide) |
505 | wxUint32 tmem_addr; // addres in texture memory (glide) |
506 | |
507 | int uses; // 1 triangle that uses this texture |
508 | |
509 | int splits; // number of splits |
510 | int splitheight; |
511 | |
512 | float c_off; // ul center texel offset (both x and y) |
513 | float c_scl_x; // scale to lower-right center-texel x |
514 | float c_scl_y; // scale to lower-right center-texel y |
515 | |
516 | wxUint32 mod, mod_color, mod_color1, mod_color2, mod_factor; |
517 | #ifdef TEXTURE_FILTER |
518 | uint64 ricecrc; |
519 | int is_hires_tex; |
520 | #endif |
521 | } CACHE_LUT; |
522 | |
523 | // Lights |
524 | typedef struct { |
525 | float r, g, b, a; // color |
526 | float dir_x, dir_y, dir_z; // direction towards the light source |
527 | float x, y, z, w; // light position |
528 | float ca, la, qa; |
529 | wxUint32 nonblack; |
530 | wxUint32 nonzero; |
531 | } LIGHT; |
532 | |
533 | typedef enum { |
534 | ci_main, //0, main color image |
535 | ci_zimg, //1, depth image |
536 | ci_unknown, //2, status is unknown |
537 | ci_useless, //3, status is unclear |
538 | ci_old_copy, //4, auxiliary color image, copy of last color image from previous frame |
539 | ci_copy, //5, auxiliary color image, copy of previous color image |
540 | ci_copy_self, //6, main color image, it's content will be used to draw into itself |
541 | ci_zcopy, //7, auxiliary color image, copy of depth image |
542 | ci_aux, //8, auxiliary color image |
543 | ci_aux_copy //9, auxiliary color image, partial copy of previous color image |
544 | } CI_STATUS; |
545 | |
546 | // Frame buffers |
547 | typedef struct |
548 | { |
549 | wxUint32 addr; //color image address |
550 | wxUint8 format; |
551 | wxUint8 size; |
552 | wxUint16 width; |
553 | wxUint16 height; |
554 | CI_STATUS status; |
555 | int changed; |
556 | } COLOR_IMAGE; |
557 | |
558 | typedef struct |
559 | { |
560 | GrChipID_t tmu; |
561 | wxUint32 addr; //address of color image |
562 | wxUint32 end_addr; |
563 | wxUint32 tex_addr; //address in video memory |
564 | wxUint32 width; //width of color image |
565 | wxUint32 height; //height of color image |
566 | wxUint8 format; //format of color image |
567 | wxUint8 size; //format of color image |
568 | wxUint8 clear; //flag. texture buffer must be cleared |
569 | wxUint8 drawn; //flag. if equal to 1, this image was already drawn in current frame |
570 | wxUint32 crc; //checksum of the color image |
571 | float scr_width; //width of rendered image |
572 | float scr_height; //height of rendered image |
573 | wxUint32 tex_width; //width of texture buffer |
574 | wxUint32 tex_height; //height of texture buffer |
575 | int tile; // |
576 | wxUint16 tile_uls; //shift from left bound of the texture |
577 | wxUint16 tile_ult; //shift from top of the texture |
578 | wxUint32 v_shift; //shift from top of the texture |
579 | wxUint32 u_shift; //shift from left of the texture |
580 | float lr_u; |
581 | float lr_v; |
582 | float u_scale; //used to map vertex u,v coordinates into hires texture |
583 | float v_scale; //used to map vertex u,v coordinates into hires texture |
584 | CACHE_LUT * cache; //pointer to texture cache item |
585 | GrTexInfo info; |
586 | wxUint16 t_mem; |
587 | } TBUFF_COLOR_IMAGE; |
588 | |
589 | typedef struct |
590 | { |
591 | GrChipID_t tmu; |
592 | wxUint32 begin; //start of the block in video memory |
593 | wxUint32 end; //end of the block in video memory |
594 | wxUint8 count; //number of allocated texture buffers |
595 | int clear_allowed; //stack of buffers can be cleared |
596 | TBUFF_COLOR_IMAGE images[256]; |
597 | } TEXTURE_BUFFER; |
598 | |
599 | #define NUMTEXBUF 92 |
600 | |
601 | struct RDP_Base{ |
602 | float vi_width; |
603 | float vi_height; |
604 | |
605 | int window_changed; |
606 | |
607 | float offset_x, offset_y, offset_x_bak, offset_y_bak; |
608 | |
609 | float scale_x, scale_1024, scale_x_bak; |
610 | float scale_y, scale_768, scale_y_bak; |
611 | |
612 | float view_scale[3]; |
613 | float view_trans[3]; |
614 | float clip_min_x, clip_max_x, clip_min_y, clip_max_y; |
615 | float clip_ratio; |
616 | |
617 | int updatescreen; |
618 | |
619 | wxUint32 tri_n; // triangle counter |
620 | wxUint32 debug_n; |
621 | |
622 | // Program counter |
623 | wxUint32 pc[10]; // DList PC stack |
624 | wxUint32 pc_i; // current PC index in the stack |
625 | int dl_count; // number of instructions before returning |
626 | int LLE; |
627 | |
628 | // Segments |
629 | wxUint32 segment[16]; // Segment pointer |
630 | |
631 | // Marks the end of DList execution (done in uc?:enddl) |
632 | int halt; |
633 | |
634 | // Next command |
635 | wxUint32 cmd0; |
636 | wxUint32 cmd1; |
637 | wxUint32 cmd2; |
638 | wxUint32 cmd3; |
639 | |
640 | // Clipping |
641 | SCISSOR scissor_o; |
642 | SCISSOR scissor; |
643 | int scissor_set; |
644 | |
645 | // Colors |
646 | wxUint32 fog_color; |
647 | wxUint32 fill_color; |
648 | wxUint32 prim_color; |
649 | wxUint32 blend_color; |
650 | wxUint32 env_color; |
651 | wxUint32 SCALE; |
652 | wxUint32 CENTER; |
653 | wxUint32 prim_lodmin, prim_lodfrac; |
654 | wxUint16 prim_depth; |
655 | wxUint16 prim_dz; |
656 | wxUint8 K4; |
657 | wxUint8 K5; |
658 | enum { |
659 | noise_none, |
660 | noise_combine, |
661 | noise_texture |
662 | } noise; |
663 | |
664 | float col[4]; // color multiplier |
665 | float coladd[4]; // color add/subtract |
666 | float shade_factor; |
667 | |
668 | float col_2[4]; |
669 | |
670 | wxUint32 cmb_flags, cmb_flags_2; |
671 | |
672 | // othermode_l flags |
673 | int acmp; // 0 = none, 1 = threshold, 2 = dither |
674 | int zsrc; // 0 = pixel, 1 = prim |
675 | wxUint8 alpha_dither_mode; |
676 | |
677 | // Matrices |
678 | DECLAREALIGN16VAR(model[4][4]); |
679 | DECLAREALIGN16VAR(proj[4][4]); |
680 | DECLAREALIGN16VAR(combined[4][4]); |
681 | DECLAREALIGN16VAR(dkrproj[3][4][4]); |
682 | |
683 | DECLAREALIGN16VAR(model_stack[32][4][4]); // 32 deep, will warn if overflow |
684 | int model_i; // index in the model matrix stack |
685 | int model_stack_size; |
686 | |
687 | // Textures |
688 | TEXTURE_IMAGE timg; // 1 for each tmem address |
689 | TILE tiles[8]; // 8 tile descriptors |
690 | wxUint8 tmem[4096]; // 4k tmem |
691 | wxUint32 addr[512]; // 512 addresses (used to determine address loaded from) |
692 | #ifdef TEXTURE_FILTER |
693 | LOAD_TILE_INFO load_info[512]; // 512 addresses. inforamation about tile loading. |
694 | #endif |
695 | |
696 | int cur_tile; // current tile |
697 | int mipmap_level; |
698 | int last_tile; // last tile set |
699 | int last_tile_size; // last tile size set |
700 | |
701 | int t0, t1; |
702 | int best_tex; // if no 2-tmus, which texture? (0 or 1) |
703 | int tex; |
704 | int filter_mode; |
705 | |
706 | // Texture palette |
707 | wxUint16 pal_8[256]; |
708 | wxUint32 pal_8_crc[16]; |
709 | wxUint32 pal_256_crc; |
710 | wxUint8 tlut_mode; |
711 | int LOD_en; |
712 | int Persp_en; |
713 | int persp_supported; |
714 | int force_wrap; |
715 | #ifdef TEXTURE_FILTER |
716 | wxUint16 pal_8_rice[512]; |
717 | #endif |
718 | |
719 | // Lighting |
720 | wxUint32 num_lights; |
721 | LIGHT light[12]; |
722 | float light_vector[12][3]; |
723 | float lookat[2][3]; |
724 | int use_lookat; |
725 | |
726 | // Combine modes |
727 | wxUint32 cycle1, cycle2, cycle_mode; |
728 | wxUint8 c_a0, c_b0, c_c0, c_d0, c_Aa0, c_Ab0, c_Ac0, c_Ad0; |
729 | wxUint8 c_a1, c_b1, c_c1, c_d1, c_Aa1, c_Ab1, c_Ac1, c_Ad1; |
730 | |
731 | wxUint8 fbl_a0, fbl_b0, fbl_c0, fbl_d0; |
732 | wxUint8 fbl_a1, fbl_b1, fbl_c1, fbl_d1; |
733 | |
734 | wxUint8 uncombined; // which is uncombined: 0x01=color 0x02=alpha 0x03=both |
735 | |
736 | // float YUV_C0, YUV_C1, YUV_C2, YUV_C3, YUV_C4; //YUV textures conversion coefficients |
737 | |
738 | // What needs updating |
739 | wxUint32 update; |
740 | wxUint32 flags; |
741 | |
742 | int first; |
743 | |
744 | wxUint32 tex_ctr; // incremented every time textures are updated |
745 | |
746 | int allow_combine; // allow combine updating? |
747 | |
748 | int s2dex_tex_loaded; |
749 | wxUint16 bg_image_height; |
750 | |
751 | // Debug stuff |
752 | wxUint32 rm; // use othermode_l instead, this just as a check for changes |
753 | wxUint32 render_mode_changed; |
754 | wxUint32 geom_mode; |
755 | |
756 | wxUint32 othermode_h; |
757 | wxUint32 othermode_l; |
758 | |
759 | // used to check if in texrect while loading texture |
760 | wxUint8 texrecting; |
761 | |
762 | //frame buffer related slots. Added by Gonetz |
763 | wxUint32 cimg, ocimg, zimg, tmpzimg, vi_org_reg; |
764 | COLOR_IMAGE maincimg[2]; |
765 | wxUint32 last_drawn_ci_addr; |
766 | wxUint32 main_ci, main_ci_end, main_ci_bg, main_ci_last_tex_addr, zimg_end, last_bg; |
767 | wxUint32 ci_width, ci_height, ci_size, ci_end; |
768 | wxUint32 zi_width; |
769 | int zi_lrx, zi_lry; |
770 | wxUint8 ci_count, num_of_ci, main_ci_index, copy_ci_index, copy_zi_index; |
771 | int swap_ci_index, black_ci_index; |
772 | wxUint32 ci_upper_bound, ci_lower_bound; |
773 | int motionblur, fb_drawn, fb_drawn_front, read_previous_ci, read_whole_frame; |
774 | CI_STATUS ci_status; |
775 | TBUFF_COLOR_IMAGE * cur_image; //image currently being drawn |
776 | TBUFF_COLOR_IMAGE * tbuff_tex; //image, which corresponds to currently selected texture |
777 | TBUFF_COLOR_IMAGE * aTBuffTex[2]; |
778 | wxUint8 cur_tex_buf; |
779 | wxUint8 acc_tex_buf; |
780 | int skip_drawing; //rendering is not required. used for frame buffer emulation |
781 | |
782 | //fog related slots. Added by Gonetz |
783 | float fog_multiplier, fog_offset; |
784 | enum { |
785 | fog_disabled, |
786 | fog_enabled, |
787 | fog_blend, |
788 | fog_blend_inverse |
789 | } |
790 | fog_mode; |
791 | }; |
792 | |
793 | struct RDP : public RDP_Base |
794 | { |
795 | // Clipping |
796 | int clip; // clipping flags |
797 | VERTEX *vtx1; //[256] copy vertex buffer #1 (used for clipping) |
798 | VERTEX *vtx2; //[256] copy vertex buffer #2 |
799 | VERTEX *vtxbuf; // current vertex buffer (reset to vtx, used to determine current vertex buffer) |
800 | VERTEX *vtxbuf2; |
801 | int n_global; // Used to pass the number of vertices from clip_z to clip_tri |
802 | int vtx_buffer; |
803 | |
804 | CACHE_LUT *cache[MAX_TMU]; //[MAX_CACHE] |
805 | CACHE_LUT *cur_cache[MAX_TMU]; |
806 | wxUint32 cur_cache_n[MAX_TMU]; |
807 | int n_cached[MAX_TMU]; |
808 | |
809 | // Vertices |
810 | VERTEX *vtx; //[MAX_VTX] |
811 | int v0, vn; |
812 | |
813 | COLOR_IMAGE *frame_buffers; //[NUMTEXBUF+2] |
814 | TEXTURE_BUFFER texbufs[2]; |
815 | |
816 | char RomName[21]; |
817 | |
818 | RDP(); |
819 | ~RDP(); |
820 | void Reset(); |
821 | }; |
822 | |
823 | |
824 | void SetWireframeCol (); |
825 | void ChangeSize (); |
826 | void GoToFullScreen(); |
827 | |
828 | extern RDP rdp; |
829 | extern SETTINGS settings; |
830 | extern HOTKEY_INFO hotkey_info; |
831 | extern VOODOO voodoo; |
832 | |
833 | extern GrTexInfo fontTex; |
834 | extern GrTexInfo cursorTex; |
835 | extern wxUint32 offset_font; |
836 | extern wxUint32 offset_cursor; |
837 | extern wxUint32 offset_textures; |
838 | extern wxUint32 offset_texbuf1; |
839 | |
840 | extern int ucode_error_report; |
841 | |
842 | /* |
843 | extern wxString pluginPath; |
844 | extern wxString iniPath; |
845 | */ |
846 | // RDP functions |
847 | void rdp_reset (); |
848 | |
849 | extern const char *ACmp[]; |
850 | extern const char *Mode0[]; |
851 | extern const char *Mode1[]; |
852 | extern const char *Mode2[]; |
853 | extern const char *Mode3[]; |
854 | extern const char *Alpha0[]; |
855 | #define Alpha1 Alpha0 |
856 | extern const char *Alpha2[]; |
857 | #define Alpha3 Alpha0 |
858 | extern const char *FBLa[]; |
859 | extern const char *FBLb[]; |
860 | extern const char *FBLc[]; |
861 | extern const char *FBLd[]; |
862 | extern const char *str_zs[]; |
863 | extern const char *str_yn[]; |
864 | extern const char *str_offon[]; |
865 | extern const char *str_cull[]; |
866 | // I=intensity probably |
867 | extern const char *str_format[]; |
868 | extern const char *str_size[]; |
869 | extern const char *str_cm[]; |
870 | extern const char *str_lod[]; |
871 | extern const char *str_aspect[]; |
872 | extern const char *str_filter[]; |
873 | extern const char *str_tlut[]; |
874 | extern const char *CIStatus[]; |
875 | |
876 | #define FBL_D_1 2 |
877 | #define FBL_D_0 3 |
878 | |
879 | #ifndef max |
880 | #define max(a,b) (((a) > (b)) ? (a) : (b)) |
881 | #endif |
882 | #ifndef min |
883 | #define min(a,b) (((a) < (b)) ? (a) : (b)) |
884 | #endif |
885 | #ifndef TRUE |
886 | #define TRUE 1 |
887 | #endif |
888 | #ifndef FALSE |
889 | #define FALSE 0 |
890 | #endif |
891 | #ifndef HIWORD |
892 | #define HIWORD(a) ((unsigned int)(a) >> 16) |
893 | #endif |
894 | #ifndef LOWORD |
895 | #define LOWORD(a) ((a) & 0xFFFF) |
896 | #endif |
897 | |
898 | // Convert from u0/v0/u1/v1 to the real coordinates without regard to tmu |
899 | __inline void ConvertCoordsKeep (VERTEX *v, int n) |
900 | { |
901 | for (int i=0; i<n; i++) |
902 | { |
903 | v[i].uc(0) = v[i].u0; |
904 | v[i].vc(0) = v[i].v0; |
905 | v[i].uc(1) = v[i].u1; |
906 | v[i].vc(1) = v[i].v1; |
907 | } |
908 | } |
909 | |
910 | // Convert from u0/v0/u1/v1 to the real coordinates based on the tmu they are on |
911 | __inline void ConvertCoordsConvert (VERTEX *v, int n) |
912 | { |
913 | for (int i=0; i<n; i++) |
914 | { |
915 | v[i].uc(rdp.t0) = v[i].u0; |
916 | v[i].vc(rdp.t0) = v[i].v0; |
917 | v[i].uc(rdp.t1) = v[i].u1; |
918 | v[i].vc(rdp.t1) = v[i].v1; |
919 | } |
920 | } |
921 | |
922 | __inline void AllowShadeMods (VERTEX *v, int n) |
923 | { |
924 | for (int i=0; i<n; i++) |
925 | { |
926 | v[i].shade_mod = 0; |
927 | } |
928 | } |
929 | |
930 | __inline void AddOffset (VERTEX *v, int n) |
931 | { |
932 | for (int i=0; i<n; i++) |
933 | { |
934 | v[i].x += rdp.offset_x; |
935 | v[i].y += rdp.offset_y; |
936 | } |
937 | } |
938 | |
939 | __inline void CalculateFog (VERTEX *v) |
940 | { |
941 | if (rdp.flags & FOG_ENABLED) |
942 | { |
943 | if (v->w < 0.0f) |
944 | v->f = 0.0f; |
945 | else |
946 | v->f = min(255.0f, max(0.0f, v->z_w * rdp.fog_multiplier + rdp.fog_offset)); |
947 | v->a = (wxUint8)v->f; |
948 | } |
949 | else |
950 | { |
951 | v->f = 1.0f; |
952 | } |
953 | } |
954 | |
955 | void newSwapBuffers(); |
956 | extern int SwapOK; |
957 | |
958 | // ** utility functions |
959 | void load_palette (wxUint32 addr, wxUint16 start, wxUint16 count); |
960 | void setTBufTex(wxUint16 t_mem, wxUint32 cnt); |
961 | |
962 | #endif // ifndef RDP_H |