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