1 /////////////////////////////////////////////////////////////////////////
2 // $Id: voodoo_types.h 13327 2017-10-23 20:01:25Z vruppert $
3 /////////////////////////////////////////////////////////////////////////
4
5 #include <math.h>
6
7 /***************************************************************************
8 TYPE DEFINITIONS
9 ***************************************************************************/
10
11 typedef Bit32u offs_t;
12
13 /* poly_param_extent describes information for a single parameter in an extent */
14 typedef struct _poly_param_extent poly_param_extent;
15 struct _poly_param_extent
16 {
17 float start; /* parameter value at starting X,Y */
18 float dpdx; /* dp/dx relative to starting X */
19 };
20
21
22 #define MAX_VERTEX_PARAMS 6
23 /* poly_extent describes start/end points for a scanline, along with per-scanline parameters */
24 typedef struct _poly_extent poly_extent;
25 struct _poly_extent
26 {
27 Bit16s startx; /* starting X coordinate (inclusive) */
28 Bit16s stopx; /* ending X coordinate (exclusive) */
29 poly_param_extent param[MAX_VERTEX_PARAMS]; /* starting and dx values for each parameter */
30 };
31
32 #ifndef TRUE
33 #define TRUE true
34 #endif
35 #ifndef FALSE
36 #define FALSE false
37 #endif
38
39
40 /* an rgb_t is a single combined R,G,B (and optionally alpha) value */
41 typedef Bit32u rgb_t;
42
43 /* an rgb15_t is a single combined 15-bit R,G,B value */
44 typedef Bit16u rgb15_t;
45
46 /* macros to assemble rgb_t values */
47 #define MAKE_ARGB(a,r,g,b) ((((rgb_t)(a) & 0xff) << 24) | (((rgb_t)(r) & 0xff) << 16) | (((rgb_t)(g) & 0xff) << 8) | ((rgb_t)(b) & 0xff))
48 #define MAKE_RGB(r,g,b) (MAKE_ARGB(255,r,g,b))
49
50 /* macros to extract components from rgb_t values */
51 #define RGB_ALPHA(rgb) (((rgb) >> 24) & 0xff)
52 #define RGB_RED(rgb) (((rgb) >> 16) & 0xff)
53 #define RGB_GREEN(rgb) (((rgb) >> 8) & 0xff)
54 #define RGB_BLUE(rgb) ((rgb) & 0xff)
55
56 /* common colors */
57 #define RGB_BLACK (MAKE_ARGB(255,0,0,0))
58 #define RGB_WHITE (MAKE_ARGB(255,255,255,255))
59
60 /***************************************************************************
61 INLINE FUNCTIONS
62 ***************************************************************************/
63
64 /*-------------------------------------------------
65 rgb_to_rgb15 - convert an RGB triplet to
66 a 15-bit OSD-specified RGB value
67 -------------------------------------------------*/
68
rgb_to_rgb15(rgb_t rgb)69 BX_CPP_INLINE rgb15_t rgb_to_rgb15(rgb_t rgb)
70 {
71 return ((RGB_RED(rgb) >> 3) << 10) | ((RGB_GREEN(rgb) >> 3) << 5) | ((RGB_BLUE(rgb) >> 3) << 0);
72 }
73
74
75 /*-------------------------------------------------
76 rgb_clamp - clamp an RGB component to 0-255
77 -------------------------------------------------*/
78
rgb_clamp(Bit32s value)79 BX_CPP_INLINE Bit8u rgb_clamp(Bit32s value)
80 {
81 if (value < 0)
82 return 0;
83 if (value > 255)
84 return 255;
85 return value;
86 }
87
88
89 /*-------------------------------------------------
90 pal1bit - convert a 1-bit value to 8 bits
91 -------------------------------------------------*/
92
pal1bit(Bit8u bits)93 BX_CPP_INLINE Bit8u pal1bit(Bit8u bits)
94 {
95 return (bits & 1) ? 0xff : 0x00;
96 }
97
98
99 /*-------------------------------------------------
100 pal2bit - convert a 2-bit value to 8 bits
101 -------------------------------------------------*/
102
pal2bit(Bit8u bits)103 BX_CPP_INLINE Bit8u pal2bit(Bit8u bits)
104 {
105 bits &= 3;
106 return (bits << 6) | (bits << 4) | (bits << 2) | bits;
107 }
108
109
110 /*-------------------------------------------------
111 pal3bit - convert a 3-bit value to 8 bits
112 -------------------------------------------------*/
113
pal3bit(Bit8u bits)114 BX_CPP_INLINE Bit8u pal3bit(Bit8u bits)
115 {
116 bits &= 7;
117 return (bits << 5) | (bits << 2) | (bits >> 1);
118 }
119
120
121 /*-------------------------------------------------
122 pal4bit - convert a 4-bit value to 8 bits
123 -------------------------------------------------*/
124
pal4bit(Bit8u bits)125 BX_CPP_INLINE Bit8u pal4bit(Bit8u bits)
126 {
127 bits &= 0xf;
128 return (bits << 4) | bits;
129 }
130
131
132 /*-------------------------------------------------
133 pal5bit - convert a 5-bit value to 8 bits
134 -------------------------------------------------*/
135
pal5bit(Bit8u bits)136 BX_CPP_INLINE Bit8u pal5bit(Bit8u bits)
137 {
138 bits &= 0x1f;
139 return (bits << 3) | (bits >> 2);
140 }
141
142
143 /*-------------------------------------------------
144 pal6bit - convert a 6-bit value to 8 bits
145 -------------------------------------------------*/
146
pal6bit(Bit8u bits)147 BX_CPP_INLINE Bit8u pal6bit(Bit8u bits)
148 {
149 bits &= 0x3f;
150 return (bits << 2) | (bits >> 4);
151 }
152
153
154 /*-------------------------------------------------
155 pal7bit - convert a 7-bit value to 8 bits
156 -------------------------------------------------*/
157
pal7bit(Bit8u bits)158 BX_CPP_INLINE Bit8u pal7bit(Bit8u bits)
159 {
160 bits &= 0x7f;
161 return (bits << 1) | (bits >> 6);
162 }
163
164
165 #define WORK_MAX_THREADS 16
166
167 /* rectangles describe a bitmap portion */
168 typedef struct _rectangle rectangle;
169 struct _rectangle
170 {
171 int min_x; /* minimum X, or left coordinate */
172 int max_x; /* maximum X, or right coordinate (inclusive) */
173 int min_y; /* minimum Y, or top coordinate */
174 int max_y; /* maximum Y, or bottom coordinate (inclusive) */
175 };
176
177 /* Standard MIN/MAX macros */
178 #ifndef MIN
179 #define MIN(x,y) ((x) < (y) ? (x) : (y))
180 #endif
181 #ifndef MAX
182 #define MAX(x,y) ((x) > (y) ? (x) : (y))
183 #endif
184
185
u2f(Bit32u v)186 BX_CPP_INLINE float u2f(Bit32u v)
187 {
188 union {
189 float ff;
190 Bit32u vv;
191 } u;
192 u.vv = v;
193 return u.ff;
194 }
195
196
197 #define ACCESSING_BITS_0_15 ((mem_mask & 0x0000ffff) != 0)
198 #define ACCESSING_BITS_16_31 ((mem_mask & 0xffff0000) != 0)
199
200 // constants for expression endianness
201 enum endianness_t
202 {
203 ENDIANNESS_LITTLE,
204 ENDIANNESS_BIG
205 };
206 const endianness_t ENDIANNESS_NATIVE = ENDIANNESS_LITTLE;
207 #define ENDIAN_VALUE_LE_BE(endian,leval,beval) (((endian) == ENDIANNESS_LITTLE) ? (leval) : (beval))
208 #define NATIVE_ENDIAN_VALUE_LE_BE(leval,beval) ENDIAN_VALUE_LE_BE(ENDIANNESS_NATIVE, leval, beval)
209 #define BYTE4_XOR_LE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,3))
210
211 #define BYTE_XOR_LE(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,1))
212
213 #define profiler_mark_start(x) do { } while (0)
214 #define profiler_mark_end() do { } while (0)
215
216
217 /* Highly useful macro for compile-time knowledge of an array size */
218 #define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
219
220 #define mul_32x32_shift _mul_32x32_shift
_mul_32x32_shift(Bit32s a,Bit32s b,Bit8s shift)221 BX_CPP_INLINE Bit32s _mul_32x32_shift(Bit32s a, Bit32s b, Bit8s shift)
222 {
223 Bit64s tmp = (Bit64s)a * (Bit64s)b;
224 tmp >>= shift;
225 Bit32s result = (Bit32s)tmp;
226
227 return result;
228 }
229
230
rgba_bilinear_filter(rgb_t rgb00,rgb_t rgb01,rgb_t rgb10,rgb_t rgb11,Bit8u u,Bit8u v)231 BX_CPP_INLINE rgb_t rgba_bilinear_filter(rgb_t rgb00, rgb_t rgb01, rgb_t rgb10, rgb_t rgb11, Bit8u u, Bit8u v)
232 {
233 Bit32u ag0, ag1, rb0, rb1;
234
235 rb0 = (rgb00 & 0x00ff00ff) + ((((rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff)) * u) >> 8);
236 rb1 = (rgb10 & 0x00ff00ff) + ((((rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff)) * u) >> 8);
237 rgb00 >>= 8;
238 rgb01 >>= 8;
239 rgb10 >>= 8;
240 rgb11 >>= 8;
241 ag0 = (rgb00 & 0x00ff00ff) + ((((rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff)) * u) >> 8);
242 ag1 = (rgb10 & 0x00ff00ff) + ((((rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff)) * u) >> 8);
243
244 rb0 = (rb0 & 0x00ff00ff) + ((((rb1 & 0x00ff00ff) - (rb0 & 0x00ff00ff)) * v) >> 8);
245 ag0 = (ag0 & 0x00ff00ff) + ((((ag1 & 0x00ff00ff) - (ag0 & 0x00ff00ff)) * v) >> 8);
246
247 return ((ag0 << 8) & 0xff00ff00) | (rb0 & 0x00ff00ff);
248 }
249
250 typedef struct _poly_vertex poly_vertex;
251 struct _poly_vertex
252 {
253 float x; /* X coordinate */
254 float y; /* Y coordinate */
255 float p[MAX_VERTEX_PARAMS]; /* interpolated parameter values */
256 };
257
258
259 typedef struct _tri_extent tri_extent;
260 struct _tri_extent
261 {
262 Bit16s startx; /* starting X coordinate (inclusive) */
263 Bit16s stopx; /* ending X coordinate (exclusive) */
264 };
265
266 /* tri_work_unit is a triangle-specific work-unit */
267 typedef struct _tri_work_unit tri_work_unit;
268 struct _tri_work_unit
269 {
270 tri_extent extent[8]; /* array of scanline extents */
271 };
272