wwstd.h 7.5 KB

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