Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmupen64plus/mupen64plus-video-z64/src/rdp.h
2 views
1
/*
2
* z64
3
*
4
* Copyright (C) 2007 ziggy
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
* (at your option) 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 along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
**/
21
22
#ifndef _RDP_H_
23
#define _RDP_H_
24
25
#include <stdint.h>
26
#include <stdio.h>
27
#include <stdlib.h>
28
#include <string.h>
29
30
#define M64P_PLUGIN_PROTOTYPES 1
31
#include "m64p_types.h"
32
#include "m64p_common.h"
33
#include "m64p_plugin.h"
34
#include "m64p_vidext.h"
35
#include "m64p_config.h"
36
37
#define LSB_FIRST 1 // TODO : check for platform
38
#ifdef LSB_FIRST
39
#define BYTE_ADDR_XOR 3
40
#define WORD_ADDR_XOR 1
41
#define BYTE4_XOR_BE(a) ((a) ^ 3) /* read/write a byte to a 32-bit space */
42
#else
43
#define BYTE_ADDR_XOR 0
44
#define WORD_ADDR_XOR 0
45
#define BYTE4_XOR_BE(a) (a)
46
#endif
47
48
49
50
#define RDP_PIXEL_SIZE_4BIT 0
51
#define RDP_PIXEL_SIZE_8BIT 1
52
#define RDP_PIXEL_SIZE_16BIT 2
53
#define RDP_PIXEL_SIZE_32BIT 3
54
55
#define RDP_FORMAT_RGBA 0
56
#define RDP_FORMAT_YUV 1
57
#define RDP_FORMAT_CI 2
58
#define RDP_FORMAT_IA 3
59
#define RDP_FORMAT_I 4
60
61
#define RDP_CYCLE_TYPE_1 0
62
#define RDP_CYCLE_TYPE_2 1
63
#define RDP_CYCLE_TYPE_COPY 2
64
#define RDP_CYCLE_TYPE_FILL 3
65
66
typedef uint32_t rdpColor_t;
67
68
#define RDP_GETC32_R(c) ( ((c)>>24) & 0xff )
69
#define RDP_GETC32_G(c) ( ((c)>>16) & 0xff )
70
#define RDP_GETC32_B(c) ( ((c)>> 8) & 0xff )
71
#define RDP_GETC32_A(c) ( ((c)>> 0) & 0xff )
72
73
#define RDP_GETC16_R(c) ( ((c)>>11) & 0x1f )
74
#define RDP_GETC16_G(c) ( ((c)>> 6) & 0x1f )
75
#define RDP_GETC16_B(c) ( ((c)>> 1) & 0x1f )
76
#define RDP_GETC16_A(c) ( ((c)>> 0) & 0x1 )
77
78
struct rdpRect_t {
79
uint16_t xl, yl, xh, yh; // 10.2 fixed-point
80
};
81
82
struct rdpTexRect_t {
83
int tilenum;
84
uint16_t xl, yl, xh, yh; // 10.2 fixed-point
85
int16_t s, t; // 10.5 fixed-point
86
int16_t dsdx, dtdy; // 5.10 fixed-point
87
};
88
89
extern const char *rdpImageFormats[];
90
91
// TODO put ct ... palette in a bitfield
92
struct rdpTile_t {
93
uint16_t line;
94
uint16_t tmem;
95
uint16_t sl, tl, sh, th; // 10.2 fixed-point
96
uint16_t w, h;
97
int8_t format, size;
98
int8_t mask_t, shift_t, mask_s, shift_s;
99
int8_t ct, mt, cs, ms;
100
int8_t palette;
101
};
102
103
struct rdpCombineModes_t {
104
uint32_t w1, w2;
105
};
106
107
#define RDP_GETCM_SUB_A_RGB0(cm) (((cm).w1 >> 20) & 0xf)
108
#define RDP_GETCM_MUL_RGB0(cm) (((cm).w1 >> 15) & 0x1f)
109
#define RDP_GETCM_SUB_A_A0(cm) (((cm).w1 >> 12) & 0x7)
110
#define RDP_GETCM_MUL_A0(cm) (((cm).w1 >> 9) & 0x7)
111
#define RDP_GETCM_SUB_A_RGB1(cm) (((cm).w1 >> 5) & 0xf)
112
#define RDP_GETCM_MUL_RGB1(cm) (((cm).w1 >> 0) & 0x1f)
113
114
#define RDP_GETCM_SUB_B_RGB0(cm) (((cm).w2 >> 28) & 0xf)
115
#define RDP_GETCM_SUB_B_RGB1(cm) (((cm).w2 >> 24) & 0xf)
116
#define RDP_GETCM_SUB_A_A1(cm) (((cm).w2 >> 21) & 0x7)
117
#define RDP_GETCM_MUL_A1(cm) (((cm).w2 >> 18) & 0x7)
118
#define RDP_GETCM_ADD_RGB0(cm) (((cm).w2 >> 15) & 0x7)
119
#define RDP_GETCM_SUB_B_A0(cm) (((cm).w2 >> 12) & 0x7)
120
#define RDP_GETCM_ADD_A0(cm) (((cm).w2 >> 9) & 0x7)
121
#define RDP_GETCM_ADD_RGB1(cm) (((cm).w2 >> 6) & 0x7)
122
#define RDP_GETCM_SUB_B_A1(cm) (((cm).w2 >> 3) & 0x7)
123
#define RDP_GETCM_ADD_A1(cm) (((cm).w2 >> 0) & 0x7)
124
125
#define RDP_COMBINE_MASK11 ((0xfu<<20)|(0x1fu<<15)|(0x7u<<12)|(0x7u<<9))
126
#define RDP_COMBINE_MASK12 ((0xfu<<28)|(0x7u<<15)|(0x7u<<12)|(0x7u<<9))
127
#define RDP_COMBINE_MASK21 ((0xfu<<5)|(0x1fu<<0))
128
#define RDP_COMBINE_MASK22 ((0xfu<<24)|(0x7u<<21)|(0x7u<<18)|(0x7u<<6)|(0x7u<<3)|(0x7u<<0))
129
130
static const rdpCombineModes_t rdpCombineMasks[4] = {
131
{ ~RDP_COMBINE_MASK21, ~RDP_COMBINE_MASK22 },
132
{ ~0u, ~0u },
133
{ ~(RDP_COMBINE_MASK11|RDP_COMBINE_MASK21), ~(RDP_COMBINE_MASK12|RDP_COMBINE_MASK22) },
134
{ ~(RDP_COMBINE_MASK11|RDP_COMBINE_MASK21), ~(RDP_COMBINE_MASK12|RDP_COMBINE_MASK22) },
135
};
136
137
struct rdpOtherModes_t {
138
uint32_t w1, w2;
139
};
140
141
#define RDP_OM_MISSING1 (~((3<<20)|0x80000|0x40000|0x20000|0x10000|0x08000| \
142
0x04000|0x02000|0x01000|0x00800|0x00400|0x00200| \
143
0x00100|(3<<6)|(3<<4)))
144
#define RDP_OM_MISSING2 (~(0xffff0000|0x4000|0x2000|0x1000|(3<<10)|(3<<8)| \
145
0x80|0x40|0x20|0x10|0x08|0x04|0x02|0x01))
146
147
#define RDP_GETOM_CYCLE_TYPE(om) (((om).w1 >> 20) & 0x3)
148
#define RDP_GETOM_PERSP_TEX_EN(om) (((om).w1 & 0x80000) ? 1 : 0)
149
#define RDP_GETOM_DETAIL_TEX_EN(om) (((om).w1 & 0x40000) ? 1 : 0)
150
#define RDP_GETOM_SHARPEN_TEX_EN(om) (((om).w1 & 0x20000) ? 1 : 0)
151
#define RDP_GETOM_TEX_LOD_EN(om) (((om).w1 & 0x10000) ? 1 : 0)
152
#define RDP_GETOM_EN_TLUT(om) (((om).w1 & 0x08000) ? 1 : 0)
153
#define RDP_GETOM_TLUT_TYPE(om) (((om).w1 & 0x04000) ? 1 : 0)
154
#define RDP_GETOM_SAMPLE_TYPE(om) (((om).w1 & 0x02000) ? 1 : 0)
155
#define RDP_GETOM_MID_TEXEL(om) (((om).w1 & 0x01000) ? 1 : 0)
156
#define RDP_GETOM_BI_LERP0(om) (((om).w1 & 0x00800) ? 1 : 0)
157
#define RDP_GETOM_BI_LERP1(om) (((om).w1 & 0x00400) ? 1 : 0)
158
#define RDP_GETOM_CONVERT_ONE(om) (((om).w1 & 0x00200) ? 1 : 0)
159
#define RDP_GETOM_KEY_EN(om) (((om).w1 & 0x00100) ? 1 : 0)
160
#define RDP_GETOM_RGB_DITHER_SEL(om) (((om).w1 >> 6) & 0x3)
161
#define RDP_GETOM_ALPHA_DITHER_SEL(om) (((om).w1 >> 4) & 0x3)
162
#define RDP_GETOM_BLEND_M1A_0(om) (((om).w2 >> 30) & 0x3)
163
#define RDP_GETOM_BLEND_M1A_1(om) (((om).w2 >> 28) & 0x3)
164
#define RDP_GETOM_BLEND_M1B_0(om) (((om).w2 >> 26) & 0x3)
165
#define RDP_GETOM_BLEND_M1B_1(om) (((om).w2 >> 24) & 0x3)
166
#define RDP_GETOM_BLEND_M2A_0(om) (((om).w2 >> 22) & 0x3)
167
#define RDP_GETOM_BLEND_M2A_1(om) (((om).w2 >> 20) & 0x3)
168
#define RDP_GETOM_BLEND_M2B_0(om) (((om).w2 >> 18) & 0x3)
169
#define RDP_GETOM_BLEND_M2B_1(om) (((om).w2 >> 16) & 0x3)
170
#define RDP_GETOM_FORCE_BLEND(om) (((om).w2 & 0x4000) ? 1 : 0)
171
#define RDP_GETOM_ALPHA_CVG_SELECT(om) (((om).w2 & 0x2000) ? 1 : 0)
172
#define RDP_GETOM_CVG_TIMES_ALPHA(om) (((om).w2 & 0x1000) ? 1 : 0)
173
#define RDP_GETOM_Z_MODE(om) (((om).w2 >> 10) & 0x3)
174
#define RDP_GETOM_CVG_DEST(om) (((om).w2 >> 8) & 0x3)
175
#define RDP_GETOM_COLOR_ON_CVG(om) (((om).w2 & 0x80) ? 1 : 0)
176
#define RDP_GETOM_IMAGE_READ_EN(om) (((om).w2 & 0x40) ? 1 : 0)
177
#define RDP_GETOM_Z_UPDATE_EN(om) (((om).w2 & 0x20) ? 1 : 0)
178
#define RDP_GETOM_Z_COMPARE_EN(om) (((om).w2 & 0x10) ? 1 : 0)
179
#define RDP_GETOM_ANTIALIAS_EN(om) (((om).w2 & 0x08) ? 1 : 0)
180
#define RDP_GETOM_Z_SOURCE_SEL(om) (((om).w2 & 0x04) ? 1 : 0)
181
#define RDP_GETOM_DITHER_ALPHA_EN(om) (((om).w2 & 0x02) ? 1 : 0)
182
#define RDP_GETOM_ALPHA_COMPARE_EN(om) (((om).w2 & 0x01) ? 1 : 0)
183
184
#define RDP_BLEND_MASK1 ((3u<<30)|(3u<<26)|(3u<<22)|(3u<<18))
185
#define RDP_BLEND_MASK2 ((3u<<28)|(3u<<24)|(3u<<20)|(3u<<16))
186
187
static const rdpOtherModes_t rdpBlendMasks[4] = {
188
{ ~0u, ~RDP_BLEND_MASK2 },
189
{ ~0u, ~0u },
190
{ ~0u, ~(RDP_BLEND_MASK1|RDP_BLEND_MASK2) },
191
{ ~0u, ~(RDP_BLEND_MASK1|RDP_BLEND_MASK2) },
192
};
193
194
struct rdpState_t {
195
rdpCombineModes_t combineModes;
196
rdpOtherModes_t otherModes;
197
rdpColor_t blendColor;
198
rdpColor_t primColor;
199
rdpColor_t envColor;
200
rdpColor_t fogColor;
201
rdpColor_t fillColor;
202
int primitiveZ;
203
int primitiveDeltaZ;
204
rdpRect_t clip;
205
uint8_t k5, clipMode;
206
};
207
208
extern rdpState_t rdpState;
209
extern uint32_t rdpChanged;
210
//extern rdpColor_t rdpTlut[];
211
#define rdpTlut ((uint16_t *) (rdpTmem + 0x800))
212
extern uint8_t rdpTmem[];
213
extern int rdpFbFormat;
214
extern int rdpFbSize;
215
extern int rdpFbWidth;
216
extern uint32_t rdpFbAddress;
217
extern uint32_t rdpZbAddress;
218
extern int rdpTiFormat;
219
extern int rdpTiSize;
220
extern int rdpTiWidth;
221
extern uint32_t rdpTiAddress;
222
extern rdpTile_t rdpTiles[8];
223
extern int rdpTileSet;
224
225
#define RDP_BITS_COMBINE_MODES (1<<0)
226
#define RDP_BITS_OTHER_MODES (1<<1)
227
#define RDP_BITS_CLIP (1<<2)
228
#define RDP_BITS_BLEND_COLOR (1<<3)
229
#define RDP_BITS_PRIM_COLOR (1<<4)
230
#define RDP_BITS_ENV_COLOR (1<<5)
231
#define RDP_BITS_FOG_COLOR (1<<6)
232
#define RDP_BITS_FB_SETTINGS (1<<7)
233
#define RDP_BITS_ZB_SETTINGS (1<<8)
234
#define RDP_BITS_TI_SETTINGS (1<<9)
235
#define RDP_BITS_TMEM (1<<10)
236
#define RDP_BITS_TLUT (1<<11)
237
#define RDP_BITS_TILE_SETTINGS (1<<12)
238
#define RDP_BITS_FILL_COLOR (1<<13)
239
#define RDP_BITS_MISC (1<<14)
240
241
// return where the data in rdram came from at this address in tmem
242
uint32_t rdpGetTmemOrigin(int tmem, int * line, int * stop, int * fromFormat, int * size);
243
244
245
int rdp_init();
246
int rdp_dasm(uint32_t * rdp_cmd_data, int rdp_cmd_cur, int length, char *buffer);
247
void rdp_process_list(void);
248
int rdp_store_list(void);
249
250
void rdp_log(m64p_msg_level level, const char *msg, ...);
251
252
#ifdef RDP_DEBUG
253
254
extern uint32_t rdpTraceBuf[];
255
extern int rdpTracePos;
256
257
extern int rdp_dump;
258
259
#define DUMP if (!rdp_dump) ; else LOG
260
261
static void LOG(const char * s, ...)
262
{
263
va_list ap;
264
va_start(ap, s);
265
vfprintf(stderr, s, ap);
266
va_end(ap);
267
}
268
#define LOGERROR LOG
269
270
#else // RDP_DEBUG
271
272
#define DUMP(...) rdp_log(M64MSG_VERBOSE, __VA_ARGS__)
273
#define LOG(...) rdp_log(M64MSG_VERBOSE, __VA_ARGS__)
274
#define LOGERROR(...) rdp_log(M64MSG_WARNING, __VA_ARGS__)
275
276
#endif // RDP_DEBUG
277
278
279
#endif // _RDP_H_
280
281