2 Copyright (C) 2003 Rice1964
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #ifndef __RICE_RDP_GFX_H__
22 #define __RICE_RDP_GFX_H__
24 #define RSP_SPNOOP 0 // handle 0 gracefully
26 #define RSP_RESERVED0 2 // unknown
27 #define RSP_MOVEMEM 3 // move a block of memory (up to 4 words) to dmem
29 #define RSP_RESERVED1 5 // unknown
31 #define RSP_RESERVED2 7 // unknown
32 #define RSP_RESERVED3 8 // unknown
33 #define RSP_SPRITE2D 9 // sprite command
34 #define RSP_SPRITE2D_BASE 9 // sprite command
38 #define RSP_TRI1 (RSP_1ST-0)
39 #define RSP_CULLDL (RSP_1ST-1)
40 #define RSP_POPMTX (RSP_1ST-2)
41 #define RSP_MOVEWORD (RSP_1ST-3)
42 #define RSP_TEXTURE (RSP_1ST-4)
43 #define RSP_SETOTHERMODE_H (RSP_1ST-5)
44 #define RSP_SETOTHERMODE_L (RSP_1ST-6)
45 #define RSP_ENDDL (RSP_1ST-7)
46 #define RSP_SETGEOMETRYMODE (RSP_1ST-8)
47 #define RSP_CLEARGEOMETRYMODE (RSP_1ST-9)
48 #define RSP_LINE3D (RSP_1ST-10)
49 #define RSP_RDPHALF_1 (RSP_1ST-11)
50 #define RSP_RDPHALF_2 (RSP_1ST-12)
51 #define RSP_RDPHALF_CONT (RSP_1ST-13)
53 #define RSP_MODIFYVTX (RSP_1ST-13)
54 #define RSP_TRI2 (RSP_1ST-14)
55 #define RSP_BRANCH_Z (RSP_1ST-15)
56 #define RSP_LOAD_UCODE (RSP_1ST-16)
58 #define RSP_SPRITE2D_SCALEFLIP (RSP_1ST-1)
59 #define RSP_SPRITE2D_DRAW (RSP_1ST-2)
61 #define RSP_ZELDAVTX 1
62 #define RSP_ZELDAMODIFYVTX 2
63 #define RSP_ZELDACULLDL 3
64 #define RSP_ZELDABRANCHZ 4
65 #define RSP_ZELDATRI1 5
66 #define RSP_ZELDATRI2 6
67 #define RSP_ZELDALINE3D 7
68 #define RSP_ZELDARDPHALF_2 0xf1
69 #define RSP_ZELDASETOTHERMODE_H 0xe3
70 #define RSP_ZELDASETOTHERMODE_L 0xe2
71 #define RSP_ZELDARDPHALF_1 0xe1
72 #define RSP_ZELDASPNOOP 0xe0
73 #define RSP_ZELDAENDDL 0xdf
74 #define RSP_ZELDADL 0xde
75 #define RSP_ZELDALOAD_UCODE 0xdd
76 #define RSP_ZELDAMOVEMEM 0xdc
77 #define RSP_ZELDAMOVEWORD 0xdb
78 #define RSP_ZELDAMTX 0xda
79 #define RSP_ZELDAGEOMETRYMODE 0xd9
80 #define RSP_ZELDAPOPMTX 0xd8
81 #define RSP_ZELDATEXTURE 0xd7
82 #define RSP_ZELDASUBMODULE 0xd6
84 // 4 is something like a conditional DL
85 #define RSP_DMATRI 0x05
86 #define G_DLINMEM 0x07
90 #define RDP_SETCIMG 0xff
91 #define RDP_SETZIMG 0xfe
92 #define RDP_SETTIMG 0xfd
93 #define RDP_SETCOMBINE 0xfc
94 #define RDP_SETENVCOLOR 0xfb
95 #define RDP_SETPRIMCOLOR 0xfa
96 #define RDP_SETBLENDCOLOR 0xf9
97 #define RDP_SETFOGCOLOR 0xf8
98 #define RDP_SETFILLCOLOR 0xf7
99 #define RDP_FILLRECT 0xf6
100 #define RDP_SETTILE 0xf5
101 #define RDP_LOADTILE 0xf4
102 #define RDP_LOADBLOCK 0xf3
103 #define RDP_SETTILESIZE 0xf2
104 #define RDP_LOADTLUT 0xf0
105 #define RDP_RDPSETOTHERMODE 0xef
106 #define RDP_SETPRIMDEPTH 0xee
107 #define RDP_SETSCISSOR 0xed
108 #define RDP_SETCONVERT 0xec
109 #define RDP_SETKEYR 0xeb
110 #define RDP_SETKEYGB 0xea
111 #define RDP_FULLSYNC 0xe9
112 #define RDP_TILESYNC 0xe8
113 #define RDP_PIPESYNC 0xe7
114 #define RDP_LOADSYNC 0xe6
115 #define RDP_TEXRECT_FLIP 0xe5
116 #define RDP_TEXRECT 0xe4
121 #define RSP_ZELDA_MTX_MODELVIEW 0x00
122 #define RSP_ZELDA_MTX_PROJECTION 0x04
123 #define RSP_ZELDA_MTX_MUL 0x00
124 #define RSP_ZELDA_MTX_LOAD 0x02
125 #define RSP_ZELDA_MTX_PUSH 0x00
126 #define RSP_ZELDA_MTX_NOPUSH 0x01
131 // RSP_SETOTHERMODE_L sft: shift count
133 #define RSP_SETOTHERMODE_SHIFT_ALPHACOMPARE 0
134 #define RSP_SETOTHERMODE_SHIFT_ZSRCSEL 2
135 #define RSP_SETOTHERMODE_SHIFT_RENDERMODE 3
136 #define RSP_SETOTHERMODE_SHIFT_BLENDER 16
139 // RSP_SETOTHERMODE_H sft: shift count
141 #define RSP_SETOTHERMODE_SHIFT_BLENDMASK 0 // unsupported
142 #define RSP_SETOTHERMODE_SHIFT_ALPHADITHER 4
143 #define RSP_SETOTHERMODE_SHIFT_RGBDITHER 6
145 #define RSP_SETOTHERMODE_SHIFT_COMBKEY 8
146 #define RSP_SETOTHERMODE_SHIFT_TEXTCONV 9
147 #define RSP_SETOTHERMODE_SHIFT_TEXTFILT 12
148 #define RSP_SETOTHERMODE_SHIFT_TEXTLUT 14
149 #define RSP_SETOTHERMODE_SHIFT_TEXTLOD 16
150 #define RSP_SETOTHERMODE_SHIFT_TEXTDETAIL 17
151 #define RSP_SETOTHERMODE_SHIFT_TEXTPERSP 19
152 #define RSP_SETOTHERMODE_SHIFT_CYCLETYPE 20
153 #define RSP_SETOTHERMODE_SHIFT_COLORDITHER 22 // unsupported in HW 2.0
154 #define RSP_SETOTHERMODE_SHIFT_PIPELINE 23
156 // RSP_SETOTHERMODE_H gPipelineMode
157 #define RSP_PIPELINE_MODE_1PRIMITIVE (1 << RSP_SETOTHERMODE_SHIFT_PIPELINE)
158 #define RSP_PIPELINE_MODE_NPRIMITIVE (0 << RSP_SETOTHERMODE_SHIFT_PIPELINE)
160 // RSP_SETOTHERMODE_H gSetCycleType
161 #define CYCLE_TYPE_1 0
162 #define CYCLE_TYPE_2 1
163 #define CYCLE_TYPE_COPY 2
164 #define CYCLE_TYPE_FILL 3
166 // RSP_SETOTHERMODE_H gSetTextureLUT
167 #define TLUT_FMT_NONE (0 << RSP_SETOTHERMODE_SHIFT_TEXTLUT)
168 #define TLUT_FMT_UNKNOWN (1 << RSP_SETOTHERMODE_SHIFT_TEXTLUT)
169 #define TLUT_FMT_RGBA16 (2 << RSP_SETOTHERMODE_SHIFT_TEXTLUT)
170 #define TLUT_FMT_IA16 (3 << RSP_SETOTHERMODE_SHIFT_TEXTLUT)
172 // RSP_SETOTHERMODE_H gSetTextureFilter
173 #define RDP_TFILTER_POINT (0 << RSP_SETOTHERMODE_SHIFT_TEXTFILT)
174 #define RDP_TFILTER_AVERAGE (3 << RSP_SETOTHERMODE_SHIFT_TEXTFILT)
175 #define RDP_TFILTER_BILERP (2 << RSP_SETOTHERMODE_SHIFT_TEXTFILT)
177 // RSP_SETOTHERMODE_L gSetAlphaCompare
178 #define RDP_ALPHA_COMPARE_NONE (0 << RSP_SETOTHERMODE_SHIFT_ALPHACOMPARE)
179 #define RDP_ALPHA_COMPARE_THRESHOLD (1 << RSP_SETOTHERMODE_SHIFT_ALPHACOMPARE)
180 #define RDP_ALPHA_COMPARE_DITHER (3 << RSP_SETOTHERMODE_SHIFT_ALPHACOMPARE)
182 // RSP_SETOTHERMODE_L gSetRenderMode
183 #define Z_COMPARE 0x0010
184 #define Z_UPDATE 0x0020
185 #define ZMODE_DEC 0x0c00
189 // flags for RSP_SETGEOMETRYMODE
191 #define G_ZBUFFER 0x00000001
192 #define G_TEXTURE_ENABLE 0x00000002 // Microcode use only
193 #define G_SHADE 0x00000004 // enable Gouraud interp
195 #define G_SHADING_SMOOTH 0x00000200 // flat or smooth shaded
196 #define G_CULL_FRONT 0x00001000
197 #define G_CULL_BACK 0x00002000
198 #define G_CULL_BOTH 0x00003000 // To make code cleaner
199 #define G_FOG 0x00010000
200 #define G_LIGHTING 0x00020000
201 #define G_TEXTURE_GEN 0x00040000
202 #define G_TEXTURE_GEN_LINEAR 0x00080000
203 #define G_LOD 0x00100000 // NOT IMPLEMENTED
206 // G_SETIMG fmt: set image formats
208 #define TXT_FMT_RGBA 0
209 #define TXT_FMT_YUV 1
215 // G_SETIMG siz: set image pixel size
217 #define TXT_SIZE_4b 0
218 #define TXT_SIZE_8b 1
219 #define TXT_SIZE_16b 2
220 #define TXT_SIZE_32b 3
226 #define RDP_TXT_LOADTILE 7
227 #define RDP_TXT_RENDERTILE 0
229 #define RDP_TXT_NOMIRROR 0
230 #define RDP_TXT_WRAP 0
231 #define RDP_TXT_MIRROR 0x1
232 #define RDP_TXT_CLAMP 0x2
233 #define RDP_TXT_NOMASK 0
234 #define RDP_TXT_NOLOD 0
241 // Each of these indexes an entry in a dmem table
242 // which points to a 1-4 word block of dmem in
243 // which to store a 1-4 word DMA.
246 #define RSP_GBI1_MV_MEM_VIEWPORT 0x80
247 #define RSP_GBI1_MV_MEM_LOOKATY 0x82
248 #define RSP_GBI1_MV_MEM_LOOKATX 0x84
249 #define RSP_GBI1_MV_MEM_L0 0x86
250 #define RSP_GBI1_MV_MEM_L1 0x88
251 #define RSP_GBI1_MV_MEM_L2 0x8a
252 #define RSP_GBI1_MV_MEM_L3 0x8c
253 #define RSP_GBI1_MV_MEM_L4 0x8e
254 #define RSP_GBI1_MV_MEM_L5 0x90
255 #define RSP_GBI1_MV_MEM_L6 0x92
256 #define RSP_GBI1_MV_MEM_L7 0x94
257 #define RSP_GBI1_MV_MEM_TXTATT 0x96
258 #define RSP_GBI1_MV_MEM_MATRIX_1 0x9e // NOTE: this is in moveword table
259 #define RSP_GBI1_MV_MEM_MATRIX_2 0x98
260 #define RSP_GBI1_MV_MEM_MATRIX_3 0x9a
261 #define RSP_GBI1_MV_MEM_MATRIX_4 0x9c
263 # define RSP_GBI2_MV_MEM__VIEWPORT 8
264 # define RSP_GBI2_MV_MEM__LIGHT 10
265 # define RSP_GBI2_MV_MEM__POINT 12
266 # define RSP_GBI2_MV_MEM__MATRIX 14 /* NOTE: this is in moveword table */
267 # define RSP_GBI2_MV_MEM_O_LOOKATX (0*24)
268 # define RSP_GBI2_MV_MEM_O_LOOKATY (1*24)
269 # define RSP_GBI2_MV_MEM_O_L0 (2*24)
270 # define RSP_GBI2_MV_MEM_O_L1 (3*24)
271 # define RSP_GBI2_MV_MEM_O_L2 (4*24)
272 # define RSP_GBI2_MV_MEM_O_L3 (5*24)
273 # define RSP_GBI2_MV_MEM_O_L4 (6*24)
274 # define RSP_GBI2_MV_MEM_O_L5 (7*24)
275 # define RSP_GBI2_MV_MEM_O_L6 (8*24)
276 # define RSP_GBI2_MV_MEM_O_L7 (9*24)
282 // Each of these indexes an entry in a dmem table
283 // which points to a word in dmem in dmem where
284 // an immediate word will be stored.
287 #define RSP_MOVE_WORD_MATRIX 0x00 // NOTE: also used by movemem
288 #define RSP_MOVE_WORD_NUMLIGHT 0x02
289 #define RSP_MOVE_WORD_CLIP 0x04
290 #define RSP_MOVE_WORD_SEGMENT 0x06
291 #define RSP_MOVE_WORD_FOG 0x08
292 #define RSP_MOVE_WORD_LIGHTCOL 0x0a
293 #define RSP_MOVE_WORD_POINTS 0x0c
294 #define RSP_MOVE_WORD_PERSPNORM 0x0e
297 // These are offsets from the address in the dmem table
299 #define RSP_MV_WORD_OFFSET_NUMLIGHT 0x00
300 #define RSP_MV_WORD_OFFSET_CLIP_RNX 0x04
301 #define RSP_MV_WORD_OFFSET_CLIP_RNY 0x0c
302 #define RSP_MV_WORD_OFFSET_CLIP_RPX 0x14
303 #define RSP_MV_WORD_OFFSET_CLIP_RPY 0x1c
304 #define RSP_MV_WORD_OFFSET_FOG 0x00
305 #define RSP_MV_WORD_OFFSET_POINT_RGBA 0x10
306 #define RSP_MV_WORD_OFFSET_POINT_ST 0x14
307 #define RSP_MV_WORD_OFFSET_POINT_XYSCREEN 0x18
308 #define RSP_MV_WORD_OFFSET_POINT_ZSCREEN 0x1c
312 // flags to inhibit pushing of the display list (on branch)
313 #define RSP_DLIST_PUSH 0x00
314 #define RSP_DLIST_NOPUSH 0x01
318 // RSP_MTX: parameter flags
320 #define RSP_MATRIX_MODELVIEW 0x00
321 #define RSP_MATRIX_PROJECTION 0x01
323 #define RSP_MATRIX_MUL 0x00
324 #define RSP_MATRIX_LOAD 0x02
326 #define RSP_MATRIX_NOPUSH 0x00
327 #define RSP_MATRIX_PUSH 0x04
337 uint32 ucode_boot_size;
343 uint32 ucode_data_size;
346 uint32 dram_stack_size;
349 uint32 output_buff_size;
354 uint32 yield_data_ptr;
355 uint32 yield_data_size;
360 uint64 force_structure_alignment;
363 #define MAX_DL_STACK_SIZE 32
364 #define MAX_DL_COUNT 1000000
392 const unsigned char * ucode_name;
397 struct TileDescriptor
400 unsigned int dwFormat :3; // e.g. RGBA, YUV etc
401 unsigned int dwSize :2; // e.g 4/8/16/32bpp
402 unsigned int dwLine :9; // Ummm...
403 unsigned int dwPalette :4; // 0..15 - a palette index?
404 uint32 dwTMem; // Texture memory location
406 unsigned int bClampS :1;
407 unsigned int bClampT :1;
408 unsigned int bMirrorS :1;
409 unsigned int bMirrorT :1;
411 unsigned int dwMaskS :4;
412 unsigned int dwMaskT :4;
413 unsigned int dwShiftS :4;
414 unsigned int dwShiftT :4;
416 // Set by SetTileSize
417 unsigned int sl :10; // Upper left S - 8:3
418 unsigned int tl :10; // Upper Left T - 8:3
419 unsigned int sh :10; // Lower Right S
420 unsigned int th :10; // Lower Right T
434 unsigned int sl :10; // Upper left S - 8:3
435 unsigned int tl :10; // Upper Left T - 8:3
436 unsigned int sh :10; // Lower Right S
437 unsigned int th :10; // Lower Right T
438 unsigned int dxt :12;
441 typedef struct { // This is in Intel format
442 uint32 SourceImagePointer;
448 char SourceImageBitSize;
449 char SourceImageType;
450 short SubImageHeight;
452 short SourceImageOffsetT;
453 short SourceImageOffsetS;
456 } SpriteStruct; //Converted Sprint struct in Intel format
465 SpriteStruct *spritePtr;
471 unsigned int c2_m2b:2;
472 unsigned int c1_m2b:2;
473 unsigned int c2_m2a:2;
474 unsigned int c1_m2a:2;
475 unsigned int c2_m1b:2;
476 unsigned int c1_m1b:2;
477 unsigned int c2_m1a:2;
478 unsigned int c1_m1a:2;
479 } RDP_BlenderSetting;
488 unsigned int alpha_compare : 2; // 0..1
489 unsigned int depth_source : 1; // 2..2
491 // unsigned int render_mode : 13; // 3..15
492 unsigned int aa_en : 1; // 3
493 unsigned int z_cmp : 1; // 4
494 unsigned int z_upd : 1; // 5
495 unsigned int im_rd : 1; // 6
496 unsigned int clr_on_cvg : 1; // 7
498 unsigned int cvg_dst : 2; // 8..9
499 unsigned int zmode : 2; // 10..11
501 unsigned int cvg_x_alpha : 1; // 12
502 unsigned int alpha_cvg_sel : 1; // 13
503 unsigned int force_bl : 1; // 14
504 unsigned int tex_edge : 1; // 15 - Not used
506 unsigned int blender : 16; // 16..31
509 unsigned int blend_mask : 4; // 0..3 - not supported
510 unsigned int alpha_dither : 2; // 4..5
511 unsigned int rgb_dither : 2; // 6..7
513 unsigned int key_en : 1; // 8..8
514 unsigned int text_conv : 3; // 9..11
515 unsigned int text_filt : 2; // 12..13
516 unsigned int text_tlut : 2; // 14..15
518 unsigned int text_lod : 1; // 16..16
519 unsigned int text_sharpen : 1; // 17..18
520 unsigned int text_detail : 1; // 17..18
521 unsigned int text_persp : 1; // 19..19
522 unsigned int cycle_type : 2; // 20..21
523 unsigned int reserved : 1; // 22..22 - not supported
524 unsigned int atomic_prim : 1; // 23..23
526 unsigned int pad : 8; // 24..31 - padding
547 // The display list PC stack. Before this was an array of 10
548 // items, but this way we can nest as deeply as necessary.
558 int x0, y0, x1, y1, mode;
559 int left, top, right, bottom;
562 // Mask down to 0x003FFFFF?
563 #define RSPSegmentAddr(seg) ( gRSP.segments[((seg)>>24)&0x0F] + ((seg)&0x00FFFFFF) )
564 #define RDRAM_UWORD(addr) (*(uint32 *)((addr)+g_pRDRAMu8))
565 #define RDRAM_SWORD(addr) (*(s32 *)((addr)+g_pRDRAMu8))
566 #define RDRAM_UHALF(addr) (*(uint16 *)(((addr)^2)+g_pRDRAMu8))
567 #define RDRAM_SHALF(addr) (*(short *)(((addr)^2)+g_pRDRAMu8))
568 #define RDRAM_UBYTE(addr) (*(uint8 *)(((addr)^3)+g_pRDRAMu8))
569 #define RDRAM_SBYTE(addr) (*(s8 *)(((addr)^3)+g_pRDRAMu8))
570 #define pRDRAM_UWORD(addr) ((uint32 *)((addr)+g_pRDRAMu8))
571 #define pRDRAM_SWORD(addr) ((s32 *)((addr)+g_pRDRAMu8))
572 #define pRDRAM_UHALF(addr) ((uint16 *)(((addr)^2)+g_pRDRAMu8))
573 #define pRDRAM_SHALF(addr) ((short *)(((addr)^2)+g_pRDRAMu8))
574 #define pRDRAM_UBYTE(addr) ((uint8 *)(((addr)^3)+g_pRDRAMu8))
575 #define pRDRAM_SBYTE(addr) ((s8 *)(((addr)^3)+g_pRDRAMu8))
577 extern uint16 g_wRDPTlut[];
578 extern const char *textluttype[4];
580 extern const char *pszImgFormat[8];
581 extern const char *pszImgSize[4];
582 extern uint8 pnImgSize[4];
583 extern const char *textlutname[4];
585 extern SetImgInfo g_CI;
586 extern SetImgInfo g_ZI;
587 extern SetImgInfo g_TI;
588 extern TmemType g_Tmem;
590 extern DListStack gDlistStack[MAX_DL_STACK_SIZE];
592 extern int gDlistStackPointer;
594 void DLParser_Init();
595 void RDP_GFX_Reset();
597 void DLParser_Process(OSTask * pTask);
598 void RDP_DLParser_Process(void);
600 void PrepareTextures();
601 void RDP_InitRenderState();
602 void DisplayVertexInfo(uint32 dwAddr, uint32 dwV0, uint32 dwN);
603 void RSP_MoveMemLight(uint32 dwLight, uint32 dwAddr);
604 void RSP_MoveMemViewport(uint32 dwAddr);
605 void RDP_NOIMPL_WARN(const char* op);
606 void RSP_GFX_Force_Matrix(uint32 dwAddr);
607 void RSP_GFX_InitGeometryMode();
608 void RSP_SetUcode(int ucode, uint32 ucStart=0, uint32 ucDStart=0, uint32 cdSize=0);
609 uint32 CalcalateCRC(uint32* srcPtr, uint32 srcSize);
610 void RDP_GFX_PopDL();
612 extern Matrix matToLoad;
613 void LoadMatrix(uint32 addr);
615 unsigned int ComputeCRC32(unsigned int crc, const uint8 *buf, unsigned int len);
617 void TriggerDPInterrupt();
618 void TriggerSPInterrupt();
619 uint32 DLParser_CheckUcode(uint32 ucStart, uint32 ucDStart, uint32 ucSize, uint32 ucDSize);
621 bool IsUsedAsDI(uint32 addr);
623 #if defined(DEBUGGER)
624 void __cdecl LOG_UCODE(const char* szFormat, ...);
626 inline void LOG_UCODE(...) {}
629 #endif // __RICE_RDP_GFX_H__