1 /****************************************************************************
3 * SciTech Multi-platform Graphics Library
5 * ========================================================================
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
27 * Description: General header file for operating system portable code.
29 ****************************************************************************/
34 /* We have the following defines to identify the compilation environment:
36 * __16BIT__ Compiling for 16 bit code (any environment)
37 * __32BIT__ Compiling for 32 bit code (any environment)
38 * __MSDOS__ Compiling for MS-DOS (includes __WINDOWS16__, __WIN386__)
39 * __REALDOS__ Compiling for MS-DOS (excludes __WINDOWS16__)
40 * __MSDOS16__ Compiling for 16 bit MS-DOS
41 * __MSDOS32__ Compiling for 32 bit MS-DOS
42 * __WINDOWS__ Compiling for Windows
43 * __WINDOWS16__ Compiling for 16 bit Windows (__MSDOS__ also defined)
44 * __WINDOWS32__ Compiling for 32 bit Windows
45 * __WIN32_VXD__ Compiling for a 32-bit C based VxD
46 * __NT_DRIVER__ Compiling for a 32-bit C based NT device driver
47 * __OS2__ Compiling for OS/2
48 * __OS2_16__ Compiling for 16 bit OS/2
49 * __OS2_32__ Compiling for 32 bit OS/2
50 * __UNIX__ Compiling for Unix
51 * __QNX__ Compiling for the QNX realtime OS (Unix compatible)
52 * __LINUX__ Compiling for the Linux OS (Unix compatible)
53 * __FREEBSD__ Compiling for the FreeBSD OS (Unix compatible)
54 * __BEOS__ Compiling for the BeOS (Unix compatible)
55 * __SMX32__ Compiling for the SMX 32-bit Real Time OS
56 * __ENEA_OSE__ Compiling for the OSE embedded OS
57 * __RTTARGET__ Compiling for the RTTarget 32-bit embedded OS
58 * __MACOS__ Compiling for the MacOS platform (PowerPC)
59 * __DRIVER__ Compiling for a 32-bit binary compatible driver
60 * __CONSOLE__ Compiling for a fullscreen OS console mode
61 * __SNAP__ Compiling as a Snap executeable or dynamic library
63 * __INTEL__ Compiling for Intel CPU's
64 * __ALPHA__ Compiling for DEC Alpha CPU's
65 * __MIPS__ Compiling for MIPS CPU's
66 * __PPC__ Compiling for PowerPC CPU's
67 * __MC68K__ Compiling for Motorola 680x0
69 * __BIG_ENDIAN__ Compiling for a big endian processor
79 /* Determine some things that are compiler specific */
83 /* G++ currently fucks this up! */
89 #define __cdecl __attribute__ ((cdecl))
90 #define __stdcall __attribute__ ((stdcall))
92 #define __FLAT__ /* GCC is always 32 bit flat model */
93 #define __HAS_BOOL__ /* Latest GNU C++ has ibool type */
94 #define __HAS_LONG_LONG__ /* GNU C supports long long type */
95 #include <stdio.h> /* Bring in for definition of NULL */
99 #if (__BORLANDC__ >= 0x500) || defined(CLASSLIB_DEFS_H)
100 #define __HAS_BOOL__ /* Borland C++ 5.0 defines ibool type */
102 #if (__BORLANDC__ >= 0x502) && !defined(VTOOLSD) && !defined(__SMX32__)
103 #define __HAS_INT64__ /* Borland C++ 5.02 supports __int64 type */
107 #if defined(_MSC_VER) && !defined(__SC__) && !defined(VTOOLSD) && !defined(__SMX32__)
108 #define __HAS_INT64__ /* Visual C++ supports __int64 type */
111 #if defined(__WATCOMC__) && (__WATCOMC__ >= 1100) && !defined(VTOOLSD) && !defined(__SMX32__)
112 #define __HAS_INT64__ /* Watcom C++ 11.0 supports __int64 type */
115 /*---------------------------------------------------------------------------
116 * Determine the compile time environment. This must be done for each
117 * supported platform so that we can determine at compile time the target
118 * environment, hopefully without requiring #define's from the user.
119 *-------------------------------------------------------------------------*/
121 /* 32-bit binary compatible driver. Compiled as Win32, but as OS neutral */
131 /* 32-bit Snap exe or dll. Compiled as Win32, but as OS neutral */
132 #elif defined(__SNAP__)
141 /* 32-bit Windows VxD compile environment */
142 #elif defined(__vtoolsd_h_) || defined(VTOOLSD)
144 #define __WIN32_VXD__
148 #define _MAX_PATH 256
151 /* 32-bit Windows NT driver compile environment: TODO!! */
152 #elif defined(__NT_DRIVER__)
153 #include "ntdriver.h"
157 #define _MAX_PATH 256
160 /* 32-bit SMX compile environment */
161 #elif defined(__SMX32__)
172 /* 32-bit Enea OSE environment */
173 #elif defined(__ENEA_OSE__)
181 /* 32-bit RTTarget-32 environment */
182 #elif defined(__RTTARGET__)
190 /* 32-bit extended DOS compile environment */
191 #elif defined(__MSDOS__) || defined(__MSDOS32__) || defined(__DOS__) || defined(__DPMI32__) || (defined(M_I86) && (!defined(__SC386__) && !defined(M_I386))) || defined(TNT)
195 #if defined(__MSDOS32__) || defined(__386__) || defined(__FLAT__) || defined(__NT__) || defined(__SC386__)
209 /* 16-bit Windows compile environment */
210 #elif (defined(_Windows) || defined(_WINDOWS)) && !defined(__DPMI16__)
214 #ifndef __WINDOWS16__
215 #define __WINDOWS16__
224 /* 16-bit DOS compile environment */
240 /* 32-bit Windows compile environment */
241 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
245 #ifndef __WINDOWS32__
246 #define __WINDOWS32__
249 #define _WIN32 /* Microsoft Win32 SDK headers use _WIN32 */
252 #define WIN32 /* OpenGL headers use WIN32 */
258 /* 32-bit OS/2 VDD compile environment */
259 /* We're assuming (for now) that CL386 must be used */
260 #elif defined(MSDOS) && defined(M_I386)
261 /* fixes necessary to compile with CL386 */
262 #define __cdecl _cdecl
263 typedef unsigned int size_t;
267 /* This should probably be somewhere else... */
268 /* Inline eligible functions (we have no CRT libs for CL386) */
269 #pragma intrinsic (strcpy, strcmp, strlen, strcat)
270 #pragma intrinsic (memcmp, memcpy, memset)
276 #define CCHMAXPATH 256
277 #define _MAX_PATH 256
285 /* 16-bit OS/2 compile environment */
286 #elif defined(__OS2_16__)
299 /* 32-bit OS/2 compile environment */
300 #elif defined(__OS2__) || defined(__OS2_32__)
316 /* 32-bit QNX compile environment */
317 #elif defined(__QNX__)
325 #define stricmp strcasecmp
327 #if !defined(__PHOTON__) && !defined(__X11__)
333 /* 32-bit Linux compile environment */
334 #elif defined(__LINUX__) || defined(linux)
345 #define stricmp strcasecmp
353 /* 32-bit FreeBSD compile environment */
354 #elif defined(__FREEBSD__)
365 #define stricmp strcasecmp
373 /* 32-bit BeOS compile environment */
374 #elif defined(__BEOS__)
382 #define stricmp strcasecmp
385 /* Unsupported OS! */
387 #error This platform is not currently supported!
390 /* Determine the CPU type that we are compiling for */
392 #if defined(__M_ALPHA) || defined(__ALPHA_) || defined(__ALPHA) || defined(__alpha)
396 #elif defined(__M_PPC) || defined(__POWERC)
400 #elif defined(__M_MRX000)
406 #define __INTEL__ /* Assume Intel if nothing found */
410 /* We have the following defines to define the calling conventions for
411 * publicly accesible functions:
413 * _PUBAPI - Compiler default calling conventions for all public 'C' functions
414 * _ASMAPI - Calling conventions for all public assembler functions
415 * _VARAPI - Modifiers for variables; Watcom C++ mangles C++ globals
416 * _STDCALL - Win32 __stdcall where possible, __cdecl if not supported
419 #if defined(_MSC_VER) && defined(_WIN32) && !defined(__SC__)
420 #define __PASCAL __stdcall
422 #define __PASCAL __pascal
425 #if defined(NO_STDCALL)
426 #define _STDCALL __cdecl
428 #define _STDCALL __stdcall
432 #if (__WATCOMC__ >= 1050)
433 #define _VARAPI __cdecl
441 #if defined(__IBMC__) || defined(__IBMCPP__)
442 #define PTR_DECL_IN_FRONT
445 /* Define the calling conventions for all public functions. For simplicity
446 * we define all public functions as __cdecl calling conventions, so that
447 * they are the same across all compilers and runtime DLL's.
450 #define _PUBAPI __cdecl
451 #define _ASMAPI __cdecl
453 /* Determine the syntax for declaring a function pointer with a
454 * calling conventions override. Most compilers require the calling
455 * convention to be declared in front of the '*', but others require
456 * it to be declared after the '*'. We handle both in here depending
457 * on what the compiler requires.
460 #ifdef PTR_DECL_IN_FRONT
461 #define _PUBAPIP * _PUBAPI
462 #define _ASMAPIP * _ASMAPI
464 #define _PUBAPIP _PUBAPI *
465 #define _ASMAPIP _ASMAPI *
470 #define PRIVATE static
473 /* This HAS to be 0L for 16-bit real mode code to work!!! */
481 # define MAX(a,b) ( ((a) > (b)) ? (a) : (b))
484 # define MIN(a,b) ( ((a) < (b)) ? (a) : (b))
487 # define ABS(a) ((a) >= 0 ? (a) : -(a))
490 # define SIGN(a) ((a) > 0 ? 1 : -1)
493 /* General typedefs */
497 #if defined(__BEOS__)
498 #include <SupportDefs.h>
501 #include <sys/types.h>
502 #ifdef __STRICT_ANSI__
503 typedef unsigned short ushort;
504 typedef unsigned long ulong;
505 typedef unsigned int uint;
511 #if !(defined(__QNXNTO__) && defined(GENERAL_STRUCT))
512 typedef unsigned short ushort;
513 typedef unsigned long ulong;
515 typedef unsigned int uint;
517 typedef unsigned char uchar;
519 typedef int ibool; /* Integer boolean type */
520 #ifdef USE_BOOL /* Only for older code */
522 #define bool ibool /* Standard C */
525 #define bool ibool /* Older C++ compilers */
527 #endif /* __cplusplus */
528 #endif /* USE_BOOL */
529 #endif /* __GENDEFS */
531 /* More general typedefs compatible with Linux kernel code */
536 typedef unsigned char u8;
538 typedef unsigned short u16;
541 typedef unsigned long u32;
544 typedef unsigned int u32;
550 #ifdef __HAS_LONG_LONG__
551 #define __NATIVE_INT64__
552 typedef long long s64;
553 typedef unsigned long long u64;
554 #elif defined(__HAS_INT64__) && !defined(__16BIT__)
555 #define __NATIVE_INT64__
557 typedef unsigned __int64 u64;
564 /* Boolean truth values */
579 /* Inline debugger interrupts for Watcom C++ and Borland C++ */
583 #pragma aux DebugInt = \
586 #pragma aux DebugVxD = \
588 #elif defined(__BORLANDC__)
589 #define DebugInt() __emit__(0xCC)
590 #define DebugVxD() {__emit__(0xCD); __emit__(0x01);}
591 #elif defined(_MSC_VER)
592 #define DebugInt() _asm int 0x3
593 #define DebugVxD() _asm int 0x1
594 #elif defined(__GNUC__)
595 #define DebugInt() asm volatile ("int $0x3")
596 #define DebugVxD() asm volatile ("int $0x1")
598 void _ASMAPI DebugInt(void);
599 void _ASMAPI DebugVxD(void);
602 /* Macros to break once and never break again */
604 #define DebugIntOnce() \
606 static ibool firstTime = true; \
613 #define DebugVxDOnce() \
615 static ibool firstTime = true; \
622 /* Macros for linux string compatibility functions */
625 #define stricmp strcasecmp
626 #define strnicmp strncasecmp
629 /* Macros for NT driver string compatibility functions */
632 #define stricmp _stricmp
633 #define strnicmp _strnicmp
636 /* Get rid of some helaciously annoying Visual C++ warnings! */
638 #if defined(_MSC_VER) && !defined(__MWERKS__) && !defined(__SC__)
639 #pragma warning(disable:4761) /* integral size mismatch in argument; conversion supplied */
640 #pragma warning(disable:4244) /* conversion from 'unsigned short ' to 'unsigned char ', possible loss of data */
641 #pragma warning(disable:4018) /* '<' : signed/unsigned mismatch */
642 #pragma warning(disable:4305) /* 'initializing' : truncation from 'const double' to 'float' */
645 /*---------------------------------------------------------------------------
646 * Set of debugging macros used by the libraries. If the debug flag is
647 * set, they are turned on depending on the setting of the flag. User code
648 * can override the default functions called when a check fails, and the
649 * MGL does this so it can restore the system from graphics mode to display
650 * an error message. These functions also log information to the
651 * scitech.log file in the root directory of the hard drive when problems
654 * If you set the value of CHECKED to be 2, it will also enable code to
655 * insert hard coded debugger interrupt into the source code at the line of
656 * code where the check fail. This is useful if you run the code under a
657 * debugger as it will break inside the debugger before exiting with a
660 * Also for code compiled to run under Windows, we also call the
661 * OutputDebugString function to send the message to the system debugger
662 * such as Soft-ICE or WDEB386. Hence if you get any non-fatal warnings you
663 * will see those on the debugger terminal as well as in the log file.
664 *-------------------------------------------------------------------------*/
667 extern "C" { /* Use "C" linkage when in C++ mode */
670 extern void (*_CHK_fail)(int fatal,const char *msg,const char *cond,const char *file,int line);
671 void _CHK_defaultFail(int fatal,const char *msg,const char *cond,const char *file,int line);
677 ((p) ? (void)0 : DebugInt(), \
678 _CHK_fail(1,"Check failed: '%s', file %s, line %d\n", \
679 #p, __FILE__, __LINE__))
681 ((p) ? (void)0 : DebugInt(), \
682 _CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
683 #p, __FILE__, __LINE__))
687 _CHK_fail(1,"Check failed: '%s', file %s, line %d\n", \
688 #p, __FILE__, __LINE__))
691 _CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
692 #p, __FILE__, __LINE__))
694 # define LOGFATAL(msg) \
695 _CHK_fail(1,"Fatal error: '%s', file %s, line %d\n", \
696 msg, __FILE__, __LINE__)
697 # define LOGWARN(msg) \
698 _CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
699 msg, __FILE__, __LINE__)
702 # define CHECK(p) ((void)0)
703 # define WARN(p) ((void)0)
704 # define LOGFATAL(msg) ((void)0)
705 # define LOGWARN(msg) ((void)0)
709 } /* End of "C" linkage for C++ */
712 #endif /* __SCITECH_H */