Metropoli BBS
VIEWER: compat.h MODE: TEXT (ASCII)
/*
Copyright (C) Magna Carta Software, Inc. 1988-1991.  All Rights Reserved
C COMMUNICATIONS TOOLKIT AND C WINDOWS TOOLKIT
COMPAT.H -- This file makes code campatible across Turbo C,
Microsoft C 5.0+/Quick C, Mix Power C and Watcom C.
NOTE: Include this file BEFORE the compiler header files.
*/

#if !defined(COMPAT_H_INCLUDED)
    #define COMPAT_H_INCLUDED

/*
THIS CODE DETECTS MSC, QUICK C, WATCOM C WATCOM C/386, INTEL CODE BUILDER
AND NDP C-386.
*/
#if (!defined(__POWERC) && !defined(__TURBOC__) && !defined(MSC))
    #if (!defined(_INTELC32_) && !defined(__HIGHC__))
        #if !defined(__WATCOMC__)
            #if defined(M_I86)
                #define MSC
            #elif !defined(__NDPC__)
                #define __NDPC__
            #endif
        #endif
    #endif
#endif

#if defined(__TURBOC__)
    #if (defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__))
        #define CCT_SMALL_DATA
    #endif
    /* MS-WINDOWS COMPATIBILITY MACROS */
    #if !defined(CCTW)
        #define DCB void
        #define COMSTAT void
        #include <dos.h>
    #endif
    /* ANSI COMPATIBILITY MACROS */
    #define FCALL_
    #define NEAR_               near
    #define FAR_                far
    #define HUGE_               huge
    #define CDECL_              cdecl
    #define INTERRUPT_          interrupt far


    /* MSC COMPATIBILITY MACROS */
    #define _disable()       disable()
    #define _enable()        enable()

    /* SYSTEM COMPATIBILITY MACROS */
    #define BIOS_SEG            0
    #define memavail()          coreleft()
    #define memcalloc(a, b)     calloc((a), (b))
    #define memfree(a)          free(a)

    /* CCT/ED COMPATIBILITY MACROS */
    #if defined(DOSX286)        /* using Phar Lap 286|DOS Extender */
        #include <pl286.h>
    #else
        #define install_cas_isr
        #define get_vector(a)       getvect((a))
        #define set_vector(a, b)    setvect((a), ((void interrupt (far *)())(b)))
    #endif

    /* SELF-COMPATIBILITY MACROS! */
    #if (defined(__TURBOC__) && !defined(__BORLANDC__))
        #define outpw(port, value)     outport((port),(value))
    #endif
#endif



#if defined(__POWERC)
    #if __POWERC < 200
        #error Version 2.0.0 or later of Power C required
    #elif __POWERC >= 200
        #pragma library "cctp20?.lib"
    #endif
    /* MS-WINDOWS COMPATIBILITY MACROS */
    #if !defined(CCTW)
        #define DCB void
        #define COMSTAT void
        #include <dos.h>
    #endif
    #if (defined(__TINY__) || defined(__SMALL_) || defined(__MEDIUM__))
        #define CCT_SMALL_DATA
    #endif
    #if defined(USE_PCTRACE)
        typedef void WINDOW;
        typedef void VSCREEN;
        typedef void BUFFER;    /* popup_menu, tsr_clock, field, startup ? */
    #endif

    /* ANSI COMPATIBILITY MACROS */
    #define FCALL_
    #define NEAR_               near
    #define FAR_                far
    #define HUGE_               huge
    #define CDECL_
    #define INTERRUPT_          interrupt far

    /* MSC COMPATIBILITY MACROS */
    #define _disable()          disable()
    #define _enable()           enable()

    /* SYSTEM COMPATIBILITY MACROS */
    #define get_vector(a)       getvect((a))
    #define install_cas_isr
    #define memavail()          coreleft()
    #define memcalloc(a, b)     calloc((a), (b))
    #define memfree(a)          free(a)
    #define outpw(port, value)  outport((port),(value))
    #define set_vector(a, b)    setvect((a), ((void interrupt (far *)())(b)))
#endif


#if defined(MSC)
    /* This identifier is defined under CCT/Windows */
    #if (!defined(CCTW) && !defined(_WINDOWS))
        #define DCB void
        #define COMSTAT void
    #endif
    /*
    The following macros make MS-DOS extensions more portable
    */
    #if (defined(M_I86TM) || defined(M_I86SM) || defined(M_I86MM))
        #define CCT_SMALL_DATA
    #endif
    #if defined(_MSC_VER)
        #if !defined(FCALL_)
            #define FCALL_ _fastcall
        #endif
        #define NEAR_   _near
        #define FAR_    _far
        #define HUGE_   _huge
        #define CDECL_  _cdecl
    #else
        #if !defined(FCALL_)
            #define FCALL_
        #endif
        #define NEAR_   near
        #define FAR_    far
        #define HUGE_   huge
        #define CDECL_  cdecl
    #endif
    #define INTERRUPT_  CDECL_ interrupt FAR_

    /* MEMORY-RELATED */
    #if defined(CTC)
        #include <commtool.h>
    #else
        #define memcalloc(a, b)    calloc((a), (b))
        #define memfree(a)         free(a)
    #endif

    /*
    The following macro creates a far pointer at a user-specified address
    Under MSC 5.0 ONLY, put this macro in comments and follow the
    instructions below to use the equivalent function.
    */
    #define MK_FP(seg,ofs)  ((void far *)((((unsigned long)(seg)) << 16) | (ofs)))

    #if 0
    /* MSC 5.0 ONLY!
    This function replaces the above macro due to a bug in the compiler.
    The function is in COMPAT.C and must be uncommented and compiled into
    the CWT library.
    */
    void far *MK_FP(unsigned pseg, unsigned poff);
    #endif

    /*
    The following 4 macros emulate BASIC's "peek" and "poke" routines.
    They are used internally.
    */
    #define poke(a,b,c)     (*((int  far*)MK_FP((a),(b))) = (int)(c))
    #define pokeb(a,b,c)    (*((char far*)MK_FP((a),(b))) = (char)(c))
    #define peek(a,b)       (*((int  far*)MK_FP((a),(b))))
    #define peekb(a,b)      (*((char far*)MK_FP((a),(b))))


    /* INTERRUPT-RELATED */
    /*
    This function allows an interrupt call to access the BP register
    (e.g. ES:BP is used in several EGA+ BIOS calls).
    This function emulates the intr() function found in Turbo C, Power C
    and Watcom C.
    */
    struct REGPACK {
        unsigned r_ax, r_bx, r_cx, r_dx;
        unsigned r_bp, r_si, r_di, r_ds, r_es, r_flags;
    };
    void FCALL_ intr(int intno, struct REGPACK *preg);
    #if defined(DOSX286)
        #include <pl286.h>
    #else
        #define get_vector(a)       _dos_getvect(a)
        #define install_cas_isr
        #define set_vector(a, b)    _dos_setvect((a), ((void (cdecl interrupt far *)())(b)))
    #endif
    #define FA_ARCH             _A_ARCH

    /* MISCELLANEOUS */
    unsigned long FCALL_        memavail(void);
    #define getdate(x)          _dos_getdate(x)
#if 0
    #define findfirst(a, b, c) _dos_findfirst((a), (c), (struct find_t *)(b))
    #define findnext(a)        _dos_findnext ((struct find_t *)(a))
    /* FILE-RELATED */
    struct ffblk {
        char        ff_reserved[21];
        char        ff_attrib;
        unsigned    ff_ftime;
        unsigned    ff_fdate;
        long        ff_fsize;
        char        ff_name[13];
    };

    /* BIOS CALLS */
    long    FCALL_ biostime(short service, long timeval);

    struct  time    {
        unsigned char   ti_min;     /* Minutes */
        unsigned char   ti_hour;    /* Hours */
        unsigned char   ti_hund;    /* Hundredths of seconds */
        unsigned char   ti_sec;     /* Seconds */
    };

    struct  date    {
        int         da_year;    /* Year - 1980 */
        char        da_day;     /* Day of the month */
        char        da_mon;     /* Month (1 = Jan) */
    };
    #define harderr(a)          _harderr(a)
    #define hardretn(a)         _hardretn(a)
#endif
#endif



/* WATCOM C */
#if defined(__WATCOMC__)
    #include <stddef.h>         /* WE HAVE TO DEFINE cdecl TO WATCOM C */
    #if (defined(M_I86TM) || defined(M_I86SM) || defined(M_I86MM))
        #define CCT_SMALL_DATA
    #endif
    #if defined(__386__)
        #include <wc386.h>
    #else
        #if defined(VERSION70)          /* define if using WC v7.0 */
            #define NEAR_           near
            #define FAR_            far
            #define HUGE_           huge
            #define CDECL_          cdecl
            #define strcmpi(a, b)   stricmp((a), (b))
            #define fputchar(a)     putchar(a)
        #else
            #define NEAR_           __near
            #define FAR_            __far
            #define HUGE_           __huge
            #define CDECL_          __cdecl
        #endif
        #if defined(CTF)
            #include <commtool.h>
        #else
            #define memcalloc(a, b)    calloc((a), (b))
            #define memfree(a)         free(a)
        #endif
    #endif
    #if !defined(CCTW)
        #define DCB void
        #define COMSTAT void
    #endif
    #define install_cas_isr
    #define FCALL_
    #define INTERRUPT_              interrupt far

    /* The following 4 macros emulate BASIC's "peek" and "poke" routines.
    They are used internally.
    */
    #define poke(a,b,c)     (*((short FAR_ *)MK_FP((a),(b))) = (short)(c))
    #define pokeb(a,b,c)    (*((char  FAR_ *)MK_FP((a),(b))) = (char)(c))
    #define peek(a,b)       (*((short FAR_ *)MK_FP((a),(b))))
    #define peekb(a,b)      (*((char  FAR_ *)MK_FP((a),(b))))
#if 0
    /* FILE I/O -- WATCOM uses POSIX rather than MSC conventions. These
    definitions allow code developed under a different compiler to run
    under Watcom C
    */
    struct ffblk {
        char            ff_reserved[21];
        char            ff_attrib;
        unsigned short  ff_ftime;
        unsigned short  ff_fdate;
        long            ff_fsize;
        char            ff_name[13];
    };
    #if defined(VERSION70)
        int findfirst(const char *pathname, struct ffblk *ffblk, int attrib);
        int findnext(struct ffblk *ffblk);
    #else
        #define findfirst(a, b, c) _dos_findfirst((a), (c), (struct find_t *)(b))
        #define findnext(a)        _dos_findnext ((struct find_t *)(a))
    #endif

    /* TIME AND DATE STRUCTURES FOR TC COMPATIBILITY */
    struct  time    {
        unsigned char   ti_min;     /* Minutes */
        unsigned char   ti_hour;    /* Hours */
        unsigned char   ti_hund;    /* Hundredths of seconds */
        unsigned char   ti_sec;     /* Seconds */
    };

    struct  date    {
        int         da_year;    /* Year - 1980 */
        char        da_day;     /* Day of the month */
        char        da_mon;     /* Month (1 = Jan) */
    };
#endif
    /* SOME MSC COMPATIBLITY MACROS, etc. */
    #define get_vector(a)       _dos_getvect(a)
    #define max(a,b)            (((a) > (b)) ? (a) : (b))
    #define min(a,b)            (((a) < (b)) ? (a) : (b))
    #define set_vector(a, b)    _dos_setvect((a), (void (INTERRUPT_ *)())(b))

    unsigned long memavail(void);
    #define FA_ARCH             _A_ARCH
#endif


#if defined(_INTELC32_)
    #include <icb.h>
#endif


#if defined(__NDPC__)
    #include <ndp386.h>
#endif

#if defined(__HIGHC__)
    #include <highc.h>
#endif

#if defined(_PHARLAP)
    #define REAL_SEG            0X34
#else
    #define REAL_SEG            0X0
#endif


/* 386 compatibility */
#if (!defined(__386__) && !defined(__NDPC__))
    #define setwordreg(a)   (regs.x.a)
    #define setbytereg(a)   (regs.h.a)
#endif


#if !defined(EOF) && !defined(__POWERC)
    #define EOF             (-1)
#endif


#endif
[ RETURN TO DIRECTORY ]