1 //------------------------------------------------------------------------- 2 /* 3 Copyright (C) 1997, 2005 - 3D Realms Entertainment 4 5 This file is part of Shadow Warrior version 1.2 6 7 Shadow Warrior is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; either version 2 10 of the License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 16 See the GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 22 Original Source: 1997 - Frank Maddin and Jim Norwood 23 Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms 24 */ 25 //------------------------------------------------------------------------- 26 27 #ifndef TYPES_H 28 29 #define TYPES_H 30 31 // CTW ADDITION (from Duke 3d TYPES.H) 32 typedef unsigned char uint8; 33 typedef uint8 byte; 34 typedef signed char int8; 35 36 typedef unsigned short int uint16; 37 typedef uint16 word; 38 typedef short int int16; 39 40 typedef unsigned int uint32; 41 typedef int int32; 42 typedef uint32 dword; 43 44 typedef int32 fixed; 45 typedef int32 boolean; 46 typedef float float32; 47 typedef double float64; 48 //typedef long double float128; 49 typedef float64 appfloat; 50 51 #define MAXINT32 0x7fffffff 52 #define MININT32 -0x80000000 53 #define MAXUINT32 0xffffffff 54 #define MINUINT32 0 55 56 #define MAXINT16 0x7fff 57 #define MININT16 -0x8000 58 #define MAXUINT16 0xffff 59 #define MINUINT16 0 60 // CTW ADDITION END 61 62 #define FALSE 0 63 #define TRUE (!FALSE) 64 65 #ifndef NULL 66 #define NULL 0 67 #endif 68 69 #define OFF 0 70 #define ON (!OFF) 71 72 typedef unsigned char BOOL; 73 typedef BOOL *BOOLp; 74 typedef BOOL *fBOOLp; 75 76 77 typedef signed char CHAR; 78 typedef CHAR *CHARp; 79 typedef CHAR *fCHARp; 80 81 #define MINCHAR ((CHAR) -128) 82 #define MAXCHAR ((CHAR) 127) 83 84 85 typedef short SHORT; 86 typedef SHORT *SHORTp; 87 typedef SHORT *fSHORTp; 88 89 typedef unsigned short USHORT; 90 typedef USHORT *USHORTp; 91 typedef USHORT *fUSHORTp; 92 93 typedef unsigned char UCHAR; 94 typedef UCHAR *UCHARp; 95 typedef UCHAR *fUCHARp; 96 97 #define MINUCHAR ((UCHAR) 0) 98 #define MAXUCHAR ((UCHAR) 255) 99 100 101 typedef UCHARp TEXT; 102 typedef fUCHARp fTEXT; 103 104 105 typedef UCHAR BYTE; 106 typedef BYTE *BYTEp; 107 typedef BYTE *fBYTEp; 108 109 #define MINBYTE ((BYTE) 0) 110 #define MAXBYTE ((BYTE) 255) 111 112 113 typedef int INT; 114 typedef int *INTp; 115 typedef int *fINTp; 116 117 #define MININT (-32768) 118 #define MAXINT 32767 119 120 typedef unsigned int WORD; 121 typedef WORD *WORDp; 122 typedef WORD *fWORDp; 123 124 #define MINWORD ((WORD) 0) 125 #define MAXWORD ((WORD) 65535U) 126 127 128 typedef int LONG; 129 typedef LONG *LONGp; 130 typedef LONG *fLONGp; 131 132 typedef 133 union { 134 LONG l; 135 struct { 136 WORD lsw; 137 WORD msw; 138 } w; 139 } DD, * DDp, * fDDp; 140 141 #define MINLONG (-2147483648L) 142 #define MAXLONG (2147483647L) 143 144 145 typedef unsigned int ULONG; 146 typedef ULONG *ULONGp; 147 typedef ULONG *fULONGp; 148 149 #define MINULONG (0L) 150 #define MAXULONG (ULONG(-1)) 151 152 typedef float FLOAT; 153 typedef FLOAT *FLOATp; 154 typedef FLOAT *fFLOATp; 155 156 157 #define VOID void 158 159 typedef VOID *nPTR; 160 typedef VOID *fPTR; 161 162 #if 0 163 #define FN pascal 164 #define fFN pascal 165 #define cFN cdecl 166 #define fcFN cdecl 167 #else 168 #define FN 169 #define fFN 170 #define cFN 171 #define fcFN 172 #endif 173 174 typedef VOID FN VOIDfn (VOID); 175 typedef BOOL FN BOOLfn (VOID); 176 typedef CHAR FN CHARfn (VOID); 177 typedef SHORT FN SHORTfn(VOID); 178 typedef UCHAR FN UCHARfn(VOID); 179 typedef TEXT FN TEXTfn (VOID); 180 typedef fTEXT FN fTEXTfn(VOID); 181 typedef BYTE FN BYTEfn (VOID); 182 typedef int FN INTfn (VOID); 183 typedef WORD FN WORDfn (VOID); 184 typedef LONG FN LONGfn (VOID); 185 typedef ULONG FN ULONGfn(VOID); 186 187 typedef VOID fFN VOIDfFN (VOID); 188 typedef BOOL fFN BOOLfFN (VOID); 189 typedef CHAR fFN CHARfFN (VOID); 190 typedef SHORT fFN SHORTfFN(VOID); 191 typedef UCHAR fFN UCHARfFN(VOID); 192 typedef TEXT fFN TEXTfFN (VOID); 193 typedef fTEXT fFN fTEXTfFN(VOID); 194 typedef BYTE fFN BYTEfFN (VOID); 195 typedef int fFN INTfFN (VOID); 196 typedef WORD fFN WORDfFN (VOID); 197 typedef LONG fFN LONGfFN (VOID); 198 typedef ULONG fFN ULONGfFN(VOID); 199 200 /* 201 =========================== 202 = 203 = FAST calculations 204 = 205 =========================== 206 */ 207 208 // For fast DIVision of integers 209 210 #define DIV2(x) ((x) >> 1) 211 #define DIV4(x) ((x) >> 2) 212 #define DIV8(x) ((x) >> 3) 213 #define DIV16(x) ((x) >> 4) 214 #define DIV32(x) ((x) >> 5) 215 #define DIV64(x) ((x) >> 6) 216 #define DIV128(x) ((x) >> 7) 217 #define DIV256(x) ((x) >> 8) 218 219 // Constants used in fast mods 220 221 #define C_MOD2 1 222 #define C_MOD4 3 223 #define C_MOD8 7 224 #define C_MOD16 15 225 #define C_MOD32 31 226 #define C_MOD64 63 227 #define C_MOD128 127 228 #define C_MOD256 255 229 230 // Fast mods of select 2 power numbers 231 232 #define MOD2(x) ((x) & C_MOD2) 233 #define MOD4(x) ((x) & C_MOD4) 234 #define MOD8(x) ((x) & C_MOD8) 235 #define MOD16(x) ((x) & C_MOD16) 236 #define MOD32(x) ((x) & C_MOD32) 237 #define MOD64(x) ((x) & C_MOD64) 238 #define MOD128(x) ((x) & C_MOD128) 239 #define MOD256(x) ((x) & C_MOD256) 240 241 // Fast mods of any power of 2 242 243 #define MOD_P2(number,modby) ((number) & ((modby)-1)) 244 245 // Truncates to select 2 power numbers 246 247 #define TRUNC2(x) ((x) & ~C_MOD2) 248 #define TRUNC4(x) ((x) & ~C_MOD4) 249 #define TRUNC8(x) ((x) & ~C_MOD8) 250 #define TRUNC16(x) ((x) & ~C_MOD16) 251 #define TRUNC32(x) ((x) & ~C_MOD32) 252 #define TRUNC64(x) ((x) & ~C_MOD64) 253 #define TRUNC128(x) ((x) & ~C_MOD128) 254 #define TRUNC256(x) ((x) & ~C_MOD256) 255 256 #define POWER2_TRUNC(number,truncby) ((number) & ~((truncby)-1)) 257 258 // moves value to closest power of 2 pixel boundry 259 260 #define BOUND_2PIX(x) ( TRUNC2((x) + MOD2(x)) ) 261 #define BOUND_4PIX(x) ( TRUNC4((x) + MOD4(x)) ) 262 #define BOUND_8PIX(x) ( TRUNC8((x) + MOD8(x)) ) 263 #define BOUND_16PIX(x) ( TRUNC16((x) + MOD16(x)) ) 264 #define BOUND_32PIX(x) ( TRUNC32((x) + MOD32(x)) ) 265 #define BOUND_64PIX(x) ( TRUNC64((x) + MOD64(x)) ) 266 #define BOUND_128PIX(x) ( TRUNC128((x) + MOD128(x)) ) 267 #define BOUND_256PIX(x) ( TRUNC256((x) + MOD256(x)) ) 268 269 #define BOUND_POWER2_PIX(x,bound) ( POWER2_TRUNC((x,bound) + POWER2_MOD(x,bound)) ) 270 271 // A few muls with shifts and adds 272 // probably not needed with good compiler 273 #define MUL2(x) ((x)*2) 274 #define MUL3(x) (((x)<<1) + (x)) 275 #define MUL5(x) (((x)<<2) + (x)) 276 #define MUL6(x) (((x)<<2) + (x) + (x)) 277 #define MUL7(x) (((x)<<2) + (x) + (x) + (x)) 278 #define MUL8(x) ((x)*8) 279 #define MUL9(x) (((x)<<3) + (x)) 280 #define MUL10(x) (((x)<<3) + (x) + (x)) 281 #define MUL11(x) (((x)<<3) + (x) + (x) + (x)) 282 #define MUL12(x) (((x)<<3) + ((x)<<2)) 283 #define MUL13(x) (((x)<<3) + ((x)<<2) + (x)) 284 #define MUL14(x) (((x)<<3) + ((x)<<2) + (x) + (x)) 285 #define MUL15(x) (((x)<<3) + ((x)<<2) + (x) + (x) + (x)) 286 #define MUL16(x) ((x)*16) 287 288 289 /* 290 =========================== 291 = 292 = Bit manipulation 293 = 294 =========================== 295 */ 296 297 #define TEST(flags,mask) ((flags) & (mask)) 298 #define SET(flags,mask) ((flags) |= (mask)) 299 #define RESET(flags,mask) ((flags) &= ~(mask)) 300 #define FLIP(flags,mask) ((flags) ^= (mask)) 301 302 // mask definitions 303 304 #define BIT(shift) (1<<(shift)) 305 306 /* 307 =========================== 308 = 309 = Miscellaneous 310 = 311 =========================== 312 */ 313 314 //#define ABS(num) ((num) < 0 ? -(num) : (num)) 315 316 #define BETWEEN(x,low,high) (((x) >= (low)) && ((x) <= (high))) 317 318 #endif 319 320