DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/voodoo_types.h
00001 /***************************************************************************/
00002 /*        Portion of this software comes with the following license:       */
00003 /***************************************************************************/
00004 /*
00005 
00006     Copyright Aaron Giles
00007     All rights reserved.
00008 
00009     Redistribution and use in source and binary forms, with or without
00010     modification, are permitted provided that the following conditions are
00011     met:
00012 
00013         * Redistributions of source code must retain the above copyright
00014           notice, this list of conditions and the following disclaimer.
00015         * Redistributions in binary form must reproduce the above copyright
00016           notice, this list of conditions and the following disclaimer in
00017           the documentation and/or other materials provided with the
00018           distribution.
00019         * Neither the name 'MAME' nor the names of its contributors may be
00020           used to endorse or promote products derived from this software
00021           without specific prior written permission.
00022 
00023     THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
00024     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00025     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026     DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
00027     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00031     STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00032     IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033     POSSIBILITY OF SUCH DAMAGE.
00034 
00035 ***************************************************************************/
00036 
00037 
00038 #ifndef DOSBOX_VOODOO_TYPES_H
00039 #define DOSBOX_VOODOO_TYPES_H
00040 
00041 #include "cross.h"
00042 
00043 /***************************************************************************
00044     TYPE DEFINITIONS
00045 ***************************************************************************/
00046 
00047 
00048 /* 8-bit values */
00049 typedef Bit8u                                           UINT8;
00050 typedef Bit8s                                           INT8;
00051 
00052 /* 16-bit values */
00053 typedef Bit16u                                          UINT16;
00054 typedef Bit16s                                          INT16;
00055 
00056 /* 32-bit values */
00057 #ifndef _WINDOWS_
00058 typedef Bit32u                                          UINT32;
00059 typedef Bit32s                                          INT32;
00060 #endif
00061 
00062 /* 64-bit values */
00063 #ifndef _WINDOWS_
00064 typedef Bit64u                                          UINT64;
00065 typedef Bit64s                                          INT64;
00066 #endif
00067 
00068 /* core components of the attotime structure */
00069 typedef INT64 attoseconds_t;
00070 typedef INT32 seconds_t;
00071 
00072 
00073 /* the attotime structure itself */
00074 typedef struct _attotime attotime;
00075 struct _attotime
00076 {
00077         seconds_t               seconds;
00078         attoseconds_t   attoseconds;
00079 };
00080 
00081 #define ATTOSECONDS_PER_SECOND_SQRT             ((attoseconds_t)1000000000)
00082 #define ATTOSECONDS_PER_SECOND                  (ATTOSECONDS_PER_SECOND_SQRT * ATTOSECONDS_PER_SECOND_SQRT)
00083 
00084 /* convert between hertz (as a double) and attoseconds */
00085 #define ATTOSECONDS_TO_HZ(x)                    ((double)ATTOSECONDS_PER_SECOND / (double)(x))
00086 #define HZ_TO_ATTOSECONDS(x)                    ((attoseconds_t)(ATTOSECONDS_PER_SECOND / (x)))
00087 
00088 
00089 /* poly_param_extent describes information for a single parameter in an extent */
00090 typedef struct _poly_param_extent poly_param_extent;
00091 struct _poly_param_extent
00092 {
00093         float           start;                                          /* parameter value at starting X,Y */
00094         float           dpdx;                                           /* dp/dx relative to starting X */
00095 };
00096 
00097 
00098 #define MAX_VERTEX_PARAMS                                       6
00099 
00100 /* poly_extent describes start/end points for a scanline, along with per-scanline parameters */
00101 typedef struct _poly_extent poly_extent;
00102 struct _poly_extent
00103 {
00104         INT32           startx;                                         /* starting X coordinate (inclusive) */
00105         INT32           stopx;                                          /* ending X coordinate (exclusive) */
00106         poly_param_extent param[MAX_VERTEX_PARAMS];     /* starting and dx values for each parameter */
00107 };
00108 
00109 
00110 /* an rgb_t is a single combined R,G,B (and optionally alpha) value */
00111 typedef UINT32 rgb_t;
00112 
00113 /* an rgb15_t is a single combined 15-bit R,G,B value */
00114 typedef UINT16 rgb15_t;
00115 
00116 /* macros to assemble rgb_t values */
00117 #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))
00118 #define MAKE_RGB(r,g,b)         (MAKE_ARGB(255,r,g,b))
00119 
00120 /* macros to extract components from rgb_t values */
00121 #define RGB_ALPHA(rgb)          (((rgb) >> 24) & 0xff)
00122 #define RGB_RED(rgb)            (((rgb) >> 16) & 0xff)
00123 #define RGB_GREEN(rgb)          (((rgb) >> 8) & 0xff)
00124 #define RGB_BLUE(rgb)           ((rgb) & 0xff)
00125 
00126 /* common colors */
00127 #define RGB_BLACK                       (MAKE_ARGB(255,0,0,0))
00128 #define RGB_WHITE                       (MAKE_ARGB(255,255,255,255))
00129 
00130 /***************************************************************************
00131     INLINE FUNCTIONS
00132 ***************************************************************************/
00133 
00134 /*-------------------------------------------------
00135     rgb_to_rgb15 - convert an RGB triplet to
00136     a 15-bit OSD-specified RGB value
00137 -------------------------------------------------*/
00138 
00139 INLINE rgb15_t rgb_to_rgb15(rgb_t rgb)
00140 {
00141         return ((RGB_RED(rgb) >> 3) << 10) | ((RGB_GREEN(rgb) >> 3) << 5) | ((RGB_BLUE(rgb) >> 3) << 0);
00142 }
00143 
00144 
00145 /*-------------------------------------------------
00146     rgb_clamp - clamp an RGB component to 0-255
00147 -------------------------------------------------*/
00148 
00149 INLINE UINT8 rgb_clamp(INT32 value)
00150 {
00151         if (value < 0)
00152                 return 0;
00153         if (value > 255)
00154                 return 255;
00155         return (UINT8)value;
00156 }
00157 
00158 
00159 /*-------------------------------------------------
00160     pal1bit - convert a 1-bit value to 8 bits
00161 -------------------------------------------------*/
00162 
00163 INLINE UINT8 pal1bit(UINT8 bits)
00164 {
00165         return (bits & 1) ? 0xff : 0x00;
00166 }
00167 
00168 
00169 /*-------------------------------------------------
00170     pal2bit - convert a 2-bit value to 8 bits
00171 -------------------------------------------------*/
00172 
00173 INLINE UINT8 pal2bit(UINT8 bits)
00174 {
00175         bits &= 3;
00176         return (bits << 6) | (bits << 4) | (bits << 2) | bits;
00177 }
00178 
00179 
00180 /*-------------------------------------------------
00181     pal3bit - convert a 3-bit value to 8 bits
00182 -------------------------------------------------*/
00183 
00184 INLINE UINT8 pal3bit(UINT8 bits)
00185 {
00186         bits &= 7;
00187         return (bits << 5) | (bits << 2) | (bits >> 1);
00188 }
00189 
00190 
00191 /*-------------------------------------------------
00192     pal4bit - convert a 4-bit value to 8 bits
00193 -------------------------------------------------*/
00194 
00195 INLINE UINT8 pal4bit(UINT8 bits)
00196 {
00197         bits &= 0xf;
00198         return (bits << 4) | bits;
00199 }
00200 
00201 
00202 /*-------------------------------------------------
00203     pal5bit - convert a 5-bit value to 8 bits
00204 -------------------------------------------------*/
00205 
00206 INLINE UINT8 pal5bit(UINT8 bits)
00207 {
00208         bits &= 0x1f;
00209         return (bits << 3) | (bits >> 2);
00210 }
00211 
00212 
00213 /*-------------------------------------------------
00214     pal6bit - convert a 6-bit value to 8 bits
00215 -------------------------------------------------*/
00216 
00217 INLINE UINT8 pal6bit(UINT8 bits)
00218 {
00219         bits &= 0x3f;
00220         return (bits << 2) | (bits >> 4);
00221 }
00222 
00223 
00224 /*-------------------------------------------------
00225     pal7bit - convert a 7-bit value to 8 bits
00226 -------------------------------------------------*/
00227 
00228 INLINE UINT8 pal7bit(UINT8 bits)
00229 {
00230         bits &= 0x7f;
00231         return (bits << 1) | (bits >> 6);
00232 }
00233 
00234 
00235 /* rectangles describe a bitmap portion */
00236 typedef struct _rectangle rectangle;
00237 struct _rectangle
00238 {
00239         int                             min_x;                  /* minimum X, or left coordinate */
00240         int                             max_x;                  /* maximum X, or right coordinate (inclusive) */
00241         int                             min_y;                  /* minimum Y, or top coordinate */
00242         int                             max_y;                  /* maximum Y, or bottom coordinate (inclusive) */
00243 };
00244 
00245 /* Standard MIN/MAX macros */
00246 #ifndef MIN
00247 #define MIN(x,y)                        ((x) < (y) ? (x) : (y))
00248 #endif
00249 #ifndef MAX
00250 #define MAX(x,y)                        ((x) > (y) ? (x) : (y))
00251 #endif
00252 
00253 
00254 inline float u2f(UINT32 v)
00255 {
00256         union {
00257                 float ff;
00258                 UINT32 vv;
00259         } u;
00260         u.vv = v;
00261         return u.ff;
00262 }
00263 
00264 
00265 /* Macros for normalizing data into big or little endian formats */
00266 #define FLIPENDIAN_INT16(x)     (((((UINT16) (x)) >> 8) | ((x) << 8)) & 0xffff)
00267 #define FLIPENDIAN_INT32(x)     ((((UINT32) (x)) << 24) | (((UINT32) (x)) >> 24) | \
00268         (( ((UINT32) (x)) & 0x0000ff00) << 8) | (( ((UINT32) (x)) & 0x00ff0000) >> 8))
00269 #define FLIPENDIAN_INT64(x)     \
00270         (                                                                                               \
00271                 (((((UINT64) (x)) >> 56) & ((UINT64) 0xFF)) <<  0)      |       \
00272                 (((((UINT64) (x)) >> 48) & ((UINT64) 0xFF)) <<  8)      |       \
00273                 (((((UINT64) (x)) >> 40) & ((UINT64) 0xFF)) << 16)      |       \
00274                 (((((UINT64) (x)) >> 32) & ((UINT64) 0xFF)) << 24)      |       \
00275                 (((((UINT64) (x)) >> 24) & ((UINT64) 0xFF)) << 32)      |       \
00276                 (((((UINT64) (x)) >> 16) & ((UINT64) 0xFF)) << 40)      |       \
00277                 (((((UINT64) (x)) >>  8) & ((UINT64) 0xFF)) << 48)      |       \
00278                 (((((UINT64) (x)) >>  0) & ((UINT64) 0xFF)) << 56)              \
00279         )
00280 
00281 #define ACCESSING_BITS_0_15                             ((mem_mask & 0x0000ffff) != 0)
00282 #define ACCESSING_BITS_16_31                    ((mem_mask & 0xffff0000) != 0)
00283 
00284 // constants for expression endianness
00285 enum endianness_t
00286 {
00287         ENDIANNESS_LITTLE,
00288         ENDIANNESS_BIG
00289 };
00290 const endianness_t ENDIANNESS_NATIVE = ENDIANNESS_LITTLE;
00291 #define ENDIAN_VALUE_LE_BE(endian,leval,beval)  (((endian) == ENDIANNESS_LITTLE) ? (leval) : (beval))
00292 #define NATIVE_ENDIAN_VALUE_LE_BE(leval,beval)  ENDIAN_VALUE_LE_BE(ENDIANNESS_NATIVE, leval, beval)
00293 #define BYTE4_XOR_LE(a)                                 ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,3))
00294 
00295 #define BYTE_XOR_LE(a)                                  ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(0,1))
00296 
00297 #define profiler_mark_start(x)  do { } while (0)
00298 #define profiler_mark_end()             do { } while (0)
00299 
00300 
00301 /* Highly useful macro for compile-time knowledge of an array size */
00302 #define ARRAY_LENGTH(x)         (sizeof(x) / sizeof(x[0]))
00303 
00304 INLINE INT32 mul_32x32_shift(INT32 a, INT32 b, INT8 shift)
00305 {
00306         INT32 result;
00307 
00308 #if defined(_MSC_VER) && defined(_M_IX86)
00309     __asm
00310     {
00311         mov   eax,a
00312         imul  b
00313         mov   cl,shift
00314         shrd  eax,edx,cl
00315         mov   result,eax
00316     }
00317 #else
00318         INT64 tmp = (INT64)a * (INT64)b;
00319         tmp >>= shift;
00320         result = (INT32)tmp;
00321 #endif
00322 
00323         return result;
00324 }
00325 
00326 
00327 typedef void (*poly_draw_scanline_func)(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata);
00328 
00329 INLINE rgb_t rgba_bilinear_filter(rgb_t rgb00, rgb_t rgb01, rgb_t rgb10, rgb_t rgb11, UINT8 u, UINT8 v)
00330 {
00331         UINT32 ag0, ag1, rb0, rb1;
00332 
00333         rb0 = (rgb00 & 0x00ff00ff) + ((((rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff)) * u) >> 8);
00334         rb1 = (rgb10 & 0x00ff00ff) + ((((rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff)) * u) >> 8);
00335         rgb00 >>= 8;
00336         rgb01 >>= 8;
00337         rgb10 >>= 8;
00338         rgb11 >>= 8;
00339         ag0 = (rgb00 & 0x00ff00ff) + ((((rgb01 & 0x00ff00ff) - (rgb00 & 0x00ff00ff)) * u) >> 8);
00340         ag1 = (rgb10 & 0x00ff00ff) + ((((rgb11 & 0x00ff00ff) - (rgb10 & 0x00ff00ff)) * u) >> 8);
00341 
00342         rb0 = (rb0 & 0x00ff00ff) + ((((rb1 & 0x00ff00ff) - (rb0 & 0x00ff00ff)) * v) >> 8);
00343         ag0 = (ag0 & 0x00ff00ff) + ((((ag1 & 0x00ff00ff) - (ag0 & 0x00ff00ff)) * v) >> 8);
00344 
00345         return ((ag0 << 8) & 0xff00ff00) | (rb0 & 0x00ff00ff);
00346 }
00347 
00348 typedef struct _poly_vertex poly_vertex;
00349 struct _poly_vertex
00350 {
00351         float           x;                                                      /* X coordinate */
00352         float           y;                                                      /* Y coordinate */
00353         float           p[MAX_VERTEX_PARAMS];           /* interpolated parameter values */
00354 };
00355 
00356 
00357 typedef struct _tri_extent tri_extent;
00358 struct _tri_extent
00359 {
00360         INT16           startx;                                         /* starting X coordinate (inclusive) */
00361         INT16           stopx;                                          /* ending X coordinate (exclusive) */
00362 };
00363 
00364 /* tri_work_unit is a triangle-specific work-unit */
00365 typedef struct _tri_work_unit tri_work_unit;
00366 struct _tri_work_unit
00367 {
00368         tri_extent                      extent[8]; /* array of scanline extents */
00369 };
00370 
00371 #endif