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