wwstd.h (7726B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /*************************************************************************** 17 ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ** 18 *************************************************************************** 19 * * 20 * Project Name : wwstd.h * 21 * * 22 * File Name : WWLIB.H * 23 * * 24 * Programmer : Jeff Wilson * 25 * * 26 * Start Date : March 1, 1994 * 27 * * 28 * Last Update : March 1, 1994 [] * 29 * * 30 *-------------------------------------------------------------------------* 31 * Functions: * 32 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 33 34 #ifndef WWSTD_H 35 #define WWSTD_H 36 37 38 // 39 // Win 95 includes 40 // 41 42 #ifndef WIN32 43 #ifndef _WIN32 // Denzil 6/2/98 Watcom 11.0 complains without this check 44 #define _WIN32 45 #endif // _WIN32 46 #define WIN32 1 47 #define WIN32_LEAN_AND_MEAN 48 #include <windows.h> 49 #include <windowsx.h> 50 #else 51 #include <windows.h> 52 #include <windowsx.h> 53 #endif 54 55 // Note: SKB 4/11/94 56 // Before this library is done, this needs to be able to be set to TRUE. 57 // Once it is, the FALSE parts should be removed from the source code. 58 #define LIB_EXTERNS_RESOLVED FALSE 59 60 61 #include <stdio.h> 62 #include <stdlib.h> 63 #include <dos.h> 64 //#include <bios.h> 65 66 //================================ 67 68 // TRUE and FALSE are defined in pltypes.h 69 70 #ifndef IBM 71 #define IBM TRUE 72 #endif 73 74 #ifndef AMIGA 75 #define AMIGA FALSE 76 #endif 77 78 #ifndef SEGA 79 #define SEGA FALSE 80 #endif 81 82 /* 83 ** Common constants used in normal code. 84 */ 85 #define WW_ERROR -1 86 87 #if (0) //PG 88 #ifdef NULL 89 #undef NULL 90 #endif 91 92 #ifndef NULL 93 #define NULL 0L 94 #endif 95 96 #ifdef VOID 97 #undef VOID 98 #endif 99 #endif 100 101 #define PRIVATE static 102 #define PUBLIC /* Routines & data don't have a specifier */ 103 104 #ifdef __cplusplus 105 #define __CPPARGS ... 106 #else 107 #define __CPPARGS 108 #endif 109 110 // This macro will get the size (in elements) of the specified array. 111 #ifdef GET_SIZE 112 #undef GET_SIZE 113 #endif 114 #define GET_SIZE(a) ((sizeof(a) / sizeof(*a))) 115 116 //#pragma option -Jg 117 // Returns the absolute value of the number. 118 #ifdef ABS 119 #undef ABS 120 #endif 121 template<class T> T ABS(T a) 122 { 123 return (a < 0) ? -a : a; 124 } 125 //int ABS(int); 126 //long ABS(long); 127 128 // Returns the minimum of the two numbers. 129 #ifdef MIN 130 #undef MIN 131 #endif 132 template<class T> T MIN(T a, T b) 133 { 134 return (b < a) ? b : a; 135 }; 136 //PG 137 //short MIN(short, short); 138 //int MIN(int, int); 139 //long MIN(long, long); 140 141 // Returns the maximum of the two numbers. 142 #ifdef MAX 143 #undef MAX 144 #endif 145 template<class T> T MAX(T a, T b) 146 { 147 return (b > a) ? b : a; 148 }; 149 //short MAX(short, short); 150 //int MAX(int, int); 151 //long MAX(long, long); 152 //#pragma option -Jgd 153 154 // Returns the low word of a long 155 #define LOW_WORD(a) ((unsigned short)((long)(a) & 0x0000FFFFL)) 156 157 // Returns the high word of a long 158 #define HIGH_WORD(a) ((unsigned long)(a) >> 16) 159 160 // Merges to shorts to become a long 161 #define MAKE_LONG(a,b) (((long)(a) << 16) | (long)((b)&0x0000FFFFL)) 162 163 /* 164 ** Macro allows our routines to act like 165 ** sprintf etc.. 166 */ 167 #ifdef AssembleTo 168 #undef AssembleTo 169 #endif 170 171 #define AssembleTo(dest,fmt)\ 172 {\ 173 va_list argptr;\ 174 if (fmt != (dest))\ 175 {\ 176 va_start (argptr, fmt);\ 177 vsprintf ((dest), fmt, argptr);\ 178 va_end (argptr);\ 179 }\ 180 } 181 182 #if (0)//PG 183 // type definitions 184 //======================================= 185 typedef void VOID; 186 187 //================================================== 188 // Pharlape defines these for use so we use their 189 // typedefs! 190 // typedef unsigned char BOOL; 191 // typedef signed long LONG; 192 // typedef unsigned long ULONG; 193 //================================================== 194 #ifndef PRIVATE 195 #define PRIVATE static 196 #endif 197 198 // The purpose of the INT and UINT is for efficiency. It says that while a short int (16 bit) 199 // has enough precision, it is more efficient to pass in an int (32 bits). For efficiency, most 200 // WORD and UWORD should be an INT or UINT, especially on the stack and structures that will 201 // not be in large arrays. When size efficiency is more important then speed, use WORD UWORD. 202 203 #define VOID void 204 205 //#pragma warn -eas 206 #define TRUE 1 207 #define FALSE 0 208 209 /* 210 ** The "bool" integral type was defined by the C++ comittee in 211 ** November of '94. Until the compiler supports this, use the following 212 ** definition. 213 */ 214 #ifndef __BORLANDC__ 215 #ifndef TRUE_FALSE_DEFINED 216 #define TRUE_FALSE_DEFINED 217 enum {false=0,true=1}; 218 typedef int bool; 219 #endif 220 #endif 221 //#define true 1 222 //#define false 0 223 224 #define BOOL int // 32 bits for speed. use CHAR for size optimizations. 225 #if(0) 226 #ifndef HMI_DRIVER 227 #define INT int 228 #define UINT unsigned int 229 #define BYTE char 230 #define UBYTE unsigned char 231 #define UCHAR unsigned char 232 #define WORD signed short 233 #define UWORD unsigned short 234 #define USHORT unsigned short 235 236 #define LONG signed long 237 #define ULONG unsigned long 238 #define REALPTR unsigned long 239 240 #define FARPTR char far * 241 242 #endif 243 #endif 244 #endif //PG 245 246 /* 247 ** The type of processor running on this system as 248 ** returned by Processor(). 249 */ 250 #define PROC_80386 0 251 #define PROC_80486 1 252 #define PROC_PENTIUM 2 253 254 255 // Inline Routines 256 //様様様様様様様様 257 // 258 // These Template functions are generally used 259 // by classes when they havce over loaded > and <. 260 // 261 #ifdef __cplusplus 262 template<class T> T Min(T a, T b) 263 { 264 return (a<b ? a : b); 265 } 266 267 template<class T> inline T Max(T a, T b) 268 { 269 return (a>b ? a : b); 270 } 271 272 template<class T> T Abs(T a) 273 { 274 return ((a<0) ? -(a) : a); 275 } 276 277 template<class T> VOID minimize(T &a, T b) 278 { 279 if( b<a ) 280 a=b; 281 } 282 283 template<class T> VOID maximize(T &a, T b) 284 { 285 if( b>a ) 286 a=b; 287 } 288 #endif 289 290 /* 291 ** Macros that control bit settings in a variable. 292 */ 293 #define Bit_Flags_On(a,b) a |= (b) 294 #define Bit_Flags_Off(a,b) a &= (~(b)) 295 #define Bit_Flags_Value(a,b) (a & (b)) 296 #define Bit_Flags_Flip(a,b) a ^= (b) 297 298 // Template replacements for the user defines above 299 #ifdef __cplusplus 300 template<class T> VOID BitFlagsOn(T &a, T b) 301 { 302 a |= (b); 303 } 304 305 template<class T> VOID BitFlagsOff(T &a, T b) 306 { 307 a &= (~(b)); 308 } 309 310 template<class T> T BitFlagsValue(T a, T b) 311 { 312 return (a & (b)); 313 } 314 315 template<class T> VOID BitFlagsFlip(T &a, T b) 316 { 317 a ^= (b); 318 } 319 #endif 320 321 typedef enum : unsigned short { 322 TBLACK, 323 PURPLE, 324 CYAN, 325 GREEN, 326 LTGREEN, 327 YELLOW, 328 PINK, 329 BROWN, 330 RED, 331 LTCYAN, 332 LTBLUE, 333 BLUE, 334 BLACK, 335 GREY, 336 LTGREY, 337 WHITE, 338 COLOR_PADDING=0x1000 339 } ColorType; 340 341 342 #endif