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