]> icculus.org git repositories - taylor/freespace2.git/blob - include/pstypes.h
ryan's struct patch for gcc 2.95
[taylor/freespace2.git] / include / pstypes.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/GlobalIncs/PsTypes.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file containg global typedefs, constants and macros
16  *
17  * $Log$
18  * Revision 1.5  2002/06/17 06:33:08  relnev
19  * ryan's struct patch for gcc 2.95
20  *
21  * Revision 1.4  2002/06/09 04:41:14  relnev
22  * added copyright header
23  *
24  * Revision 1.3  2002/06/01 07:12:32  relnev
25  * a few NDEBUG updates.
26  *
27  * removed a few warnings.
28  *
29  * Revision 1.2  2002/05/28 06:28:20  theoddone33
30  * Filesystem mods, actually reads some data files now
31  *
32  * Revision 1.1.1.1  2002/05/03 03:28:12  root
33  * Initial import.
34  *
35  * 
36  * 34    6/16/00 3:16p Jefff
37  * sim of the year dvd version changes, a few german soty localization
38  * fixes
39  * 
40  * 33    10/05/99 2:29p Danw
41  * 
42  * 32    10/01/99 9:10a Daveb
43  * V 1.1 PATCH
44  * 
45  * 31    9/13/99 12:22a Dave
46  * Minor build update.
47  * 
48  * 30    8/28/99 4:54p Dave
49  * Fixed directives display for multiplayer clients for wings with
50  * multiple waves. Fixed hud threat indicator rendering color.
51  * 
52  * 29    8/09/99 4:18p Andsager
53  * Make french and german defines, needed specifically to enable language
54  * under launcher misc. tab
55  * 
56  * 28    7/20/99 1:49p Dave
57  * Peter Drake build. Fixed some release build warnings.
58  * 
59  * 27    7/18/99 5:19p Dave
60  * Jump node icon. Fixed debris fogging. Framerate warning stuff.
61  * 
62  * 26    7/15/99 9:21a Andsager
63  * FS2_DEMO check in
64  * 
65  * 25    7/09/99 9:51a Dave
66  * Added thick polyline code.
67  * 
68  * 24    6/29/99 10:35a Dave
69  * Interface polygon bitmaps! Whee!
70  * 
71  * 23    6/14/99 10:45a Dave
72  * Made beam weapons specify accuracy by skill level in the weapons.tbl
73  * 
74  * 22    6/03/99 10:15p Dave
75  * Put in temporary main hall screen.
76  * 
77  * 21    5/09/99 8:57p Dave
78  * Final E3 build preparations.
79  * 
80  * 20    4/25/99 7:43p Dave
81  * Misc small bug fixes. Made sun draw properly.
82  * 
83  * 19    4/25/99 3:03p Dave
84  * Removed E3_BUILD from pstypes
85  * 
86  * 18    4/25/99 3:02p Dave
87  * Build defines for the E3 build.
88  * 
89  * 17    4/15/99 1:29p Dave
90  * Remove multiplayer beta build define.
91  * 
92  * 16    4/15/99 1:24p Dave
93  * Final Beta 1 checkin.
94  * 
95  * 15    4/14/99 5:28p Dave
96  * Minor bug fixes.
97  * 
98  * 14    4/12/99 2:22p Dave
99  * More checks for dogfight stats.
100  * 
101  * 13    4/09/99 2:21p Dave
102  * Multiplayer beta stuff. CD checking.
103  * 
104  * 12    2/25/99 4:19p Dave
105  * Added multiplayer_beta defines. Added cd_check define. Fixed a few
106  * release build warnings. Added more data to the squad war request and
107  * response packets.
108  * 
109  * 11    2/23/99 2:29p Dave
110  * First run of oldschool dogfight mode. 
111  * 
112  * 10    2/07/99 8:51p Andsager
113  * Add inner bound to asteroid field.  Inner bound tries to stay astroid
114  * free.  Wrap when within and don't throw at ships inside.
115  * 
116  * 9     1/15/99 11:29a Neilk
117  * Fixed D3D screen/texture pixel formatting problem. 
118  * 
119  * 8     1/08/99 2:08p Dave
120  * Fixed software rendering for pofview. Super early support for AWACS and
121  * beam weapons.
122  * 
123  * 7     1/06/99 2:24p Dave
124  * Stubs and release build fixes.
125  * 
126  * 6     11/30/98 1:07p Dave
127  * 16 bit conversion, first run.
128  * 
129  * 5     11/05/98 4:18p Dave
130  * First run nebula support. Beefed up localization a bit. Removed all
131  * conditional compiles for foreign versions. Modified mission file
132  * format.
133  * 
134  * 4     10/13/98 9:28a Dave
135  * Started neatening up freespace.h. Many variables renamed and
136  * reorganized. Added AlphaColors.[h,cpp]
137  * 
138  * 3     10/07/98 11:28a Dave
139  * 
140  * 2     10/07/98 10:52a Dave
141  * Initial checkin.
142  * 
143  * 1     10/07/98 10:48a Dave
144  * 
145  * 75    8/20/98 5:30p Dave
146  * Put in handy multiplayer logfile system. Now need to put in useful
147  * applications of it all over the code.
148  * 
149  * 74    6/17/98 11:01a Lawrance
150  * set correct offset for English special font chars
151  * 
152  * 73    6/12/98 4:52p Hoffoss
153  * Added support for special characters in in forgeign languages.
154  * 
155  * 72    6/09/98 6:49p Lawrance
156  * Comment out UK_BUILD
157  * 
158  * 71    6/09/98 5:15p Lawrance
159  * French/German localization
160  * 
161  * 70    6/09/98 12:12p Hoffoss
162  * Added XSTR localization code.
163  * 
164  * 69    6/05/98 9:49a Lawrance
165  * OEM changes
166  * 
167  * 68    5/22/98 3:13p Allender
168  * no Int3()'s and Asserts
169  * 
170  * 67    5/20/98 12:59p John
171  * Turned optimizations on for debug builds.   Also turning on automatic
172  * function inlining.  Turned off the unreachable code warning.
173  * 
174  * 66    5/04/98 1:49p Allender
175  * make Int3's do nothing when InterplayQA is defined
176  * 
177  * 65    4/25/98 11:55p Lawrance
178  * compile out Int3() and Assert() for release demo build
179  * 
180  *
181  * $NoKeywords: $
182  *
183  */
184
185 #ifndef _PSTYPES_H
186 #define _PSTYPES_H
187
188
189 // Build defines.  Comment in/out for whatever build is necessary:
190 // #define OEM_BUILD                                            // enable for OEM builds
191 // #define MULTIPLAYER_BETA_BUILD                               // enable for multiplayer beta build
192 // #define E3_BUILD                                                     // enable for 3dfx E3 build                                             
193 // #define PRESS_TOUR_BUILD                     // enable for press tour build
194 #define FS2_DEMO                                        // enable demo build for FS2
195 // #define PD_BUILD                                             // fred documentation/evaluation build
196 //      #define FRENCH_BUILD                            // build for French (obsolete)
197 // #define GERMAN_BUILD                         // build for German (this is now used)
198 //#define RELEASE_REAL                                  // this means that it is an actual release candidate, not just an optimized/release build
199
200 // uncomment this #define for DVD version (makes popups say DVD instead of CD 2 or whatever): JCF 5/10/2000
201 // #define DVD_MESSAGE_HACK
202
203
204 #if defined(MULTIPLAYER_BETA_BUILD) || defined(E3_BUILD) || defined(RELEASE_REAL)
205         #define GAME_CD_CHECK
206 #endif
207
208 // 4127 is constant conditional (assert)
209 // 4100 is unreferenced formal parameters,
210 // 4514 is unreferenced inline function removed, 
211 // 4201 is nameless struct extension used. (used by windows header files)
212 // 4410 illegal size for operand... ie...       fxch st(1)
213 // 4611 is _setjmp warning.  Since we use setjmp alot, and we don't really use constructors or destructors, this warning doesn't really apply to us.
214 // 4725 is the pentium division bug warning, and I can't seem to get rid of it, even with this pragma.
215 //      JS: I figured out the disabling 4725 works, but not on the first function in the module.
216 //      So to disable this, I add in a stub function at the top of each module that does nothing.
217 // 4710 is inline function not expanded (who cares?)
218 // 4711 tells us an inline function was expanded (who cares?)
219 // 4702 unreachable code.  I care, but too many to deal with
220 // 4201 nonstandard extension used : nameless struct/union (happens a lot in Windows include headers)
221 // 4390 emptry control statement (triggered by nprintf and mprintf's inside of one-line if's, etc)
222 #ifndef PLAT_UNIX
223 #pragma warning(disable: 4127 4100 4514 4201 4410 4611 4725 4710 4711 4702 4201 4390)
224 #endif
225
226 #include <stdio.h>      // For NULL, etc
227 #include <stdlib.h>
228 #include <memory.h>
229 #include <malloc.h>
230 #include <string.h>
231
232 #ifdef PLAT_UNIX
233 #include "unix.h"
234 #endif
235 // value to represent an uninitialized state in any int or uint
236 #define UNINITIALIZED 0x7f8e6d9c
237
238 #if defined(DEMO) || defined(OEM_BUILD) // no change for FS2_DEMO
239         #define MAX_PLAYERS     1
240 #else
241         #define MAX_PLAYERS     12
242 #endif
243
244 #define MAX_TEAMS               3
245
246 #define USE_INLINE_ASM 1                // Define this to use inline assembly
247 #define STRUCT_CMP(a, b) memcmp((void *) &a, (void *) &b, sizeof(a))
248
249 #define LOCAL static                    // make module local varilable static.
250
251 typedef __int64 longlong;
252 typedef long fix;
253 typedef unsigned char ubyte;
254 typedef unsigned short ushort;
255 typedef unsigned int uint;
256
257 #define HARDWARE_ONLY
258
259 //Stucture to store clipping codes in a word
260 typedef struct ccodes {
261         ubyte vor,vand; //or is low byte, and is high byte
262 } ccodes;
263
264 typedef struct vector {
265         union {
266                 struct {
267                         float x,y,z;
268                 } xyz;
269                 float a1d[3];
270         };
271 } vector;
272
273 // A vector referenced as an array
274 typedef struct vectora {
275         float   xyz[3];
276 } vectora;
277
278 typedef struct vec2d {
279         float i,j;
280 } vec2d;
281
282 // Used for some 2d primitives, like gr_poly
283 typedef struct vert2df {
284         float x, y;
285 } vert2df;
286
287 typedef struct angles {
288         float   p, b, h;
289 } angles_t;
290
291 typedef struct matrix {
292         union {
293                 struct {
294                         vector  rvec, uvec, fvec;
295                 } v;
296                 float a2d[3][3];
297                 float a1d[9];
298         };
299 } matrix;
300
301 typedef struct uv_pair {
302         float u,v;
303 } uv_pair;
304
305 // Used to store rotated points for mines.
306 // Has flag to indicate if projected.
307 typedef struct vertex {
308         float           x, y, z;                                // world space position
309         float           sx, sy, sw;                     // screen space position (sw == 1/z)
310         float           u, v;                                   // texture position
311         ubyte           r, g, b, a;                     // color.  Use b for darkening;
312         ubyte           codes;                          // what sides of view pyramid this point is on/off.  0 = Inside view pyramid.
313         ubyte           flags;                          // Projection flags.  Indicates whether it is projected or not or if projection overflowed.
314         ubyte           pad[2];                         // pad structure to be 4 byte aligned.
315 } vertex;
316
317 #define BMP_AABITMAP                    (1<<0)                          // antialiased bitmap
318 #define BMP_TEX_XPARENT         (1<<1)                          // transparent texture
319 #define BMP_TEX_NONDARK         (1<<2)                          // nondarkening texture
320 #define BMP_TEX_OTHER                   (1<<3)                          // so we can identify all "normal" textures
321
322 // any texture type
323 #define BMP_TEX_ANY                             ( BMP_TEX_XPARENT | BMP_TEX_NONDARK | BMP_TEX_OTHER )
324
325 // max res == 1024x768. max texture size == 256
326 #define MAX_BMAP_SECTIONS_X                             4
327 #define MAX_BMAP_SECTIONS_Y                             3
328 #define MAX_BMAP_SECTION_SIZE                           256
329 typedef struct bitmap_section_info {
330         ushort sx[MAX_BMAP_SECTIONS_X];         // x offset of each section
331         ushort sy[MAX_BMAP_SECTIONS_Y];         // y offset of each section
332
333         ubyte num_x, num_y;                                             // number of x and y sections
334 } bitmap_section_info;
335
336 typedef struct bitmap {
337         short   w, h;           // Width and height
338         short   rowsize;        // What you need to add to go to next row
339         ubyte   bpp;            // How many bits per pixel it is. (7,8,15,16,24,32)
340         ubyte   flags;  // See the BMP_???? defines for values
341         uint    data;           // Pointer to data, or maybe offset into VRAM.
342         ubyte *palette; // If bpp==8, this is pointer to palette.   If the BMP_NO_PALETTE_MAP flag
343                                                         // is not set, this palette just points to the screen palette. (gr_palette)
344
345         bitmap_section_info sections;
346 } bitmap;
347
348 //This are defined in MainWin.c
349 extern void _cdecl WinAssert(char * text,char *filename, int line);
350 extern void _cdecl Error( char * filename, int line, char * format, ... );
351 extern void _cdecl Warning( char * filename, int line, char * format, ... );
352
353 #include "outwnd.h"
354
355 // To debug printf do this:
356 // mprintf(( "Error opening %s\n", filename ));
357 #ifndef NDEBUG
358 #define mprintf(args) outwnd_printf2 args
359 #define nprintf(args) outwnd_printf args
360 #else
361 #define mprintf(args) 
362 #define nprintf(args) 
363 #endif
364
365 #define LOCATION __FILE__,__LINE__
366
367 // To flag an error, you can do this:
368 // Error( __FILE__, __LINE__, "Error opening %s", filename );
369 // or, 
370 // Error( LOCATION, "Error opening %s", filename );
371
372 #if defined(NDEBUG)
373 #define Assert(x) do {} while (0)
374 #else
375 void gr_activate(int);
376 #define Assert(x) do { if (!(x)){ gr_activate(0); WinAssert(#x,__FILE__,__LINE__); gr_activate(1); } } while (0)
377 #endif
378
379 //#define Int3() _asm { int 3 }
380
381 #ifdef INTERPLAYQA
382         // Interplay QA version of Int3
383         #define Int3() do { } while (0) 
384
385         // define to call from Warning function above since it calls Int3, so without this, we
386         // get put into infinite dialog boxes
387         #define AsmInt3() _asm { int 3 }
388
389 #else
390         #if defined(NDEBUG)
391                 // No debug version of Int3
392                 #define Int3() do { } while (0) 
393         #else
394                 void debug_int3();
395
396                 // Debug version of Int3
397                 #define Int3() debug_int3()
398         #endif  // NDEBUG && DEMO
399 #endif  // INTERPLAYQA
400
401 #define min(a,b) (((a) < (b)) ? (a) : (b))
402 #define max(a,b) (((a) > (b)) ? (a) : (b))
403
404 #define PI                                      3.141592654f
405 #define PI2                                     (3.141592654f*2.0f)     // PI*2
406 #define ANG_TO_RAD(x)   ((x)*PI/180)
407
408
409 extern int      Fred_running;  // Is Fred running, or FreeSpace?
410 extern int Pofview_running;
411 extern int Nebedit_running;
412
413
414 //======================================================================================
415 //======          D E B U G    C O N S O L E   S T U F F        ========================
416 //======================================================================================
417
418 // Here is a a sample command to toggle something that would
419 // be called by doing "toggle it" from the debug console command window/
420
421 /*
422 DCF(toggle_it,"description")
423 {
424         if (Dc_command) {
425                 This_var = !This_var;
426         }
427
428         if (Dc_help)    {
429                 dc_printf( "Usage: sample\nToggles This_var on/off.\n" );
430         }
431
432         if (Dc_status)  {
433                 dc_printf( "The status is %d.\n", This_var );
434         }
435 */
436
437 class debug_command {
438         public:
439         char *name;
440         char *help;
441         void (*func)();
442         debug_command(char *name,char *help,void (*func)());    // constructor
443 };
444
445 #define DCF(function_name,help_text)                    \
446                 void dcf_##function_name();     \
447                 debug_command dc_##function_name(#function_name,help_text,dcf_##function_name); \
448                 void dcf_##function_name()              
449
450 // Starts the debug console
451 extern void debug_console( void (*func)() = NULL );
452
453 // The next three variables tell your function what to do.  It should
454 // only change something if the dc_command is set.   A minimal function
455 // needs to process the dc_command.   Usually, these will be called in
456 // these combinations:
457 // dc_command=true, dc_status=true  means process it and show status
458 // dc_help=true means show help only
459 // dc_status=true means show status only
460 // I would recommend doing this in each function:
461 // if (dc_command) { process command }
462 // if (dc_help) { print out help }
463 // if (dc_status) { print out status }
464 // with the last two being optional
465
466 extern int Dc_command;  // If this is set, then process the command
467 extern int Dc_help;             // If this is set, then print out the help text in the form, "usage: ... \nLong description\n" );
468 extern int Dc_status;           // If this is set, then print out the current status of the command.
469
470 void dc_get_arg(uint flags);            // Gets the next argument.   If it doesn't match the flags, this function will print an error and not return.
471 extern char *Dc_arg;            // The (lowercased) string value of the argument retrieved from dc_arg
472 extern char *Dc_arg_org;        // Dc_arg before it got converted to lowercase
473 extern uint Dc_arg_type;        // The type of dc_arg.
474 extern char *Dc_command_line;           // The rest of the command line, from the end of the last processed arg on.
475 extern int Dc_arg_int;          // If Dc_arg_type & ARG_INT or ARG_HEX is set, then this is the value
476 extern float Dc_arg_float;      // If Dc_arg_type & ARG_FLOAT is set, then this is the value
477
478 // Outputs text to the console
479 void dc_printf( char *format, ... );
480
481 // Each dc_arg_type can have one or more of these flags set.
482 // This is because some things can fit into two catagories.
483 // Like 1 can be an integer, a float, a string, or a true boolean
484 // value.
485 #define ARG_NONE                (1<<0)  // no argument
486 #define ARG_ANY         0xFFFFFFFF      // Anything.
487 #define ARG_STRING      (1<<1)  // any valid string
488 #define ARG_QUOTE               (1<<2)  // a quoted string
489 #define ARG_INT         (1<<3)  // a valid integer
490 #define ARG_FLOAT               (1<<4)  // a valid floating point number
491
492 // some specific commonly used predefined types. Can add up to (1<<31)
493 #define ARG_HEX         (1<<5)  // a valid hexadecimal integer. Note that ARG_INT will always be set also in this case.
494 #define ARG_TRUE                (1<<6)  // on, true, non-zero number
495 #define ARG_FALSE               (1<<7)  // off, false, zero
496 #define ARG_PLUS                (1<<8)  // Plus sign
497 #define ARG_MINUS               (1<<9)  // Minus sign
498 #define ARG_COMMA               (1<<10) // a comma
499
500 // A shortcut for boolean only variables.
501 // Example:  
502 // DCF_BOOL( lighting, Show_lighting )
503 //
504 #define DCF_BOOL( function_name, bool_variable )        \
505         void dcf_##function_name();     \
506         debug_command dc_##function_name(#function_name,"Toggles "#bool_variable,dcf_##function_name ); \
507         void dcf_##function_name()      {       \
508         if ( Dc_command )       {       \
509                 dc_get_arg(ARG_TRUE|ARG_FALSE|ARG_NONE);                \
510                 if ( Dc_arg_type & ARG_TRUE )   bool_variable = 1;      \
511                 else if ( Dc_arg_type & ARG_FALSE ) bool_variable = 0;  \
512                 else if ( Dc_arg_type & ARG_NONE ) bool_variable ^= 1;  \
513         }       \
514         if ( Dc_help )  dc_printf( "Usage: %s [bool]\nSets %s to true or false.  If nothing passed, then toggles it.\n", #function_name, #bool_variable );      \
515         if ( Dc_status )        dc_printf( "%s is %s\n", #function_name, (bool_variable?"TRUE":"FALSE") );      \
516 }
517
518
519 //======================================================================================
520 //======================================================================================
521 //======================================================================================
522
523
524
525 #include "fix.h"
526 #include "floating.h"
527
528 // Some constants for stuff
529 #define MAX_FILENAME_LEN        32                      // Length for filenames, ie "title.pcx"
530 #define MAX_PATH_LEN                    128             // Length for pathnames, ie "c:\bitmaps\title.pcx"
531
532 // contants and defined for byteswapping routines (useful for mac)
533
534 #define SWAPSHORT(x)    (                                                       \
535                                                 ((ubyte)x << 8) |                                       \
536                                                 (((ushort)x) >> 8)                      \
537                                                 )
538                                                 
539 #define SWAPINT(x)              (                                                       \
540                                                 (x << 24) |                                     \
541                                                 (((ulong)x) >> 24) |            \
542                                                 ((x & 0x0000ff00) << 8) |       \
543                                                 ((x & 0x00ff0000) >> 8)         \
544                                                 )
545
546 #ifndef MACINTOSH
547 #define INTEL_INT(x)    x
548 #define INTEL_SHORT(x)  x
549 #else
550 #define INTEL_INT(x)    SWAPINT(x)
551 #define INTEL_SHORT(x)  SWAPSHORT(x)
552 #endif
553
554 #define TRUE    1
555 #define FALSE   0
556
557 int myrand();
558
559
560
561 // Callback Loading function. 
562 // If you pass a function to this, that function will get called
563 // around 10x per second, so you can update the screen.
564 // Pass NULL to turn it off.
565 // Call this with the name of a function.  That function will
566 // then get called around 10x per second.  The callback function
567 // gets passed a 'count' which is how many times game_busy has
568 // been called since the callback was set.   It gets called
569 // one last time with count=-1 when you turn off the callback
570 // by calling game_busy_callback(NULL).   Game_busy_callback
571 // returns the current count, so you can tell how many times
572 // game_busy got called.
573 // If delta_step is above 0, then it will also make sure it 
574 // calls the callback each time count steps 'delta_step' even
575 // if 1/10th of a second hasn't elapsed.
576 extern int game_busy_callback( void (*callback)(int count), int delta_step = -1 );
577
578 // Call whenever loading to display cursor
579 extern void game_busy();
580
581
582 //=========================================================
583 // Functions to monitor performance
584 #ifndef NDEBUG
585
586 class monitor {
587         public:
588         char    *name;                  
589         int     value;                  // Value that gets cleared to 0 each frame.
590         int     min, max, sum, cnt;             // Min & Max of value.  Sum is used to calculate average 
591         monitor(char *name);    // constructor
592 };
593
594 // Creates a monitor variable
595 #define MONITOR(function_name)                          monitor mon_##function_name(#function_name)
596
597 // Increments a monitor variable
598 #define MONITOR_INC(function_name,inc)          do { mon_##function_name.value+=(inc); } while(0)
599
600 // Call this once per frame to update monitor file
601 void monitor_update();
602
603 #else
604
605 #define MONITOR(function_name)
606
607 #define MONITOR_INC(function_name,inc)          do { } while(0)
608
609 // Call this once per frame to update monitor file
610 #define monitor_update() do { } while(0)
611
612 #endif
613
614 #define NOX(s) s
615
616 char *XSTR(char *str, int index);
617
618 // Caps V between MN and MX.
619 template <class T> void CAP( T& v, T mn, T mx )
620 {
621         if ( v < mn )   {
622                 v = mn;
623         } else if ( v > mx )    {
624                 v = mx;
625         }
626 }
627
628 // ========================================================
629 // stamp checksum stuff
630 // ========================================================
631
632 // here is the define for the stamp for this set of code
633 #define STAMP_STRING "\001\001\001\001\002\002\002\002Read the Foundation Novels from Asimov.  I liked them." 
634 #define STAMP_STRING_LENGTH     80
635 #define DEFAULT_CHECKSUM_STRING         "\001\001\001\001"
636 #define DEFAULT_TIME_STRING                     "\002\002\002\002"
637
638 // macro to calculate the checksum for the stamp.  Put here so that we can use different methods
639 // for different applications.  Requires the local variable 'checksum' to be defined!!!
640 #define CALCULATE_STAMP_CHECKSUM() do { \
641                 int i, found;   \
642                                                         \
643                 checksum = 0;   \
644                 for ( i = 0; i < (int)strlen(ptr); i++ ) {      \
645                         found = 0;      \
646                         checksum += ptr[i];     \
647                         if ( checksum & 0x01 )  \
648                                 found = 1;      \
649                         checksum = checksum >> 1;       \
650                         if (found)      \
651                                 checksum |= 0x80000000; \
652                 }       \
653                 checksum |= 0x80000000; \
654         } while (0) ;
655
656 //=========================================================
657 // Memory management functions
658 //=========================================================
659
660 #ifndef NDEBUG
661         // Debug versions
662
663         // Returns 0 if not enough RAM.
664         int vm_init(int min_heap_size);
665
666         // Allocates some RAM.
667         void *vm_malloc( int size, char *filename=NULL, int line=-1 );
668
669         // 
670         char *vm_strdup( const char *ptr, char *filename, int line );
671
672         // Frees some RAM. 
673         void vm_free( void *ptr, char *filename=NULL, int line=-1 );
674
675         // Frees all RAM.
676         void vm_free_all();
677
678         // Easy to use macros
679         #define VM_MALLOC(size) vm_malloc((size),__FILE__,__LINE__)
680         #define VM_FREE(ptr) vm_free((ptr),__FILE__,__LINE__)
681
682         #define malloc(size) vm_malloc((size),__FILE__,__LINE__)
683         #define free(ptr) vm_free((ptr),__FILE__,__LINE__)
684         #define strdup(ptr) vm_strdup((ptr),__FILE__,__LINE__)
685         
686 #else
687         // Release versions
688
689         // Returns 0 if not enough RAM.
690         int vm_init(int min_heap_size);
691
692         // Allocates some RAM.
693 //      void *vm_malloc( int size );
694
695         // 
696 //      char *vm_strdup( const char *ptr );
697
698         // Frees some RAM. 
699 //      void vm_free( void *ptr );
700
701         // Frees all RAM.
702         void vm_free_all();
703
704         // Easy to use macros
705         #define VM_MALLOC(size) vm_malloc(size)
706         #define VM_FREE(ptr) vm_free(ptr)
707
708 //      #define malloc(size) vm_malloc(size)
709 //      #define free(ptr) vm_free(ptr)
710 //      #define strdup(ptr) vm_strdup(ptr)
711         #define vm_malloc(size) malloc(size)
712         #define vm_free(ptr) free(ptr)
713         #define vm_strdup(ptr) strdup(ptr)
714 #endif
715
716
717 #endif          // PS_TYPES_H
718