Initial. Don't... just don't ask.

This commit is contained in:
Ryan McGrath 2011-02-24 00:22:00 -08:00
commit 00bae13bba
586 changed files with 129057 additions and 0 deletions

152
utils/gtf/gtf.h Normal file
View file

@ -0,0 +1,152 @@
/****************************************************************************
*
* VESA Generalized Timing Formula (GTF)
* Version 1.0
*
* ========================================================================
*
* The contents of this file are subject to the SciTech MGL Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.scitechsoft.com/mgl-license.txt
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
*
* The Initial Developer of the Original Code is SciTech Software, Inc.
* All Rights Reserved.
*
* ========================================================================
*
* Developed by: SciTech Software, Inc.
*
* Language: ANSI C
* Environment: Any
*
* Description: Header file for generating GTF compatible timings given a
* set of input requirements. Translated from the original GTF
* 1.14 spreadsheet definition.
*
*
****************************************************************************/
#ifndef __GTF_H
#define __GTF_H
#ifndef __SCITECH_H
#include "scitech.h"
#endif
/*---------------------- Macros and type definitions ----------------------*/
/* Define the structures for holding the horizontal and vertical
* CRTC parameters for a mode.
*
* Note: The sync timings are defined in both VGA compatible timings
* (sync start and sync end positions) and also in GTF compatible
* modes with the front porch, sync width and back porch defined.
*/
typedef struct {
int hTotal; /* Horizontal total */
int hDisp; /* Horizontal displayed */
int hSyncStart; /* Horizontal sync start */
int hSyncEnd; /* Horizontal sync end */
int hFrontPorch; /* Horizontal front porch */
int hSyncWidth; /* Horizontal sync width */
int hBackPorch; /* Horizontal back porch */
} GTF_hCRTC;
typedef struct {
int vTotal; /* Vertical total */
int vDisp; /* Vertical displayed */
int vSyncStart; /* Vertical sync start */
int vSyncEnd; /* Vertical sync end */
int vFrontPorch; /* Vertical front porch */
int vSyncWidth; /* Vertical sync width */
int vBackPorch; /* Vertical back porch */
} GTF_vCRTC;
/* Define the main structure for holding generated GTF timings */
typedef struct {
GTF_hCRTC h; /* Horizontal CRTC paremeters */
GTF_vCRTC v; /* Vertical CRTC parameters */
char hSyncPol; /* Horizontal sync polarity */
char vSyncPol; /* Vertical sync polarity */
char interlace; /* 'I' for Interlace, 'N' for Non */
double vFreq; /* Vertical frequency (Hz) */
double hFreq; /* Horizontal frequency (KHz) */
double dotClock; /* Pixel clock (Mhz) */
} GTF_timings;
/* Define the structure for holding standard GTF formula constants */
typedef struct {
double margin; /* Margin size as percentage of display */
double cellGran; /* Character cell granularity */
double minPorch; /* Minimum front porch in lines/chars */
double vSyncRqd; /* Width of V sync in lines */
double hSync; /* Width of H sync as percent of total */
double minVSyncBP; /* Minimum vertical sync + back porch (us) */
double m; /* Blanking formula gradient */
double c; /* Blanking formula offset */
double k; /* Blanking formula scaling factor */
double j; /* Blanking formula scaling factor weight */
} GTF_constants;
#define GTF_lockVF 1 /* Lock to vertical frequency */
#define GTF_lockHF 2 /* Lock to horizontal frequency */
#define GTF_lockPF 3 /* Lock to pixel clock frequency */
/*-------------------------- Function Prototypes --------------------------*/
#ifdef __cplusplus
extern "C" { /* Use "C" linkage when in C++ mode */
#endif
/* Generate a set of timings for a mode from the GTF formulas. This will
* allow you to generate a set of timings by specifying the type as:
*
* 1. Vertical frequency
* 2. Horizontal frequency
* 3. Pixel clock
*
* Generally if you want to find the timings for a specific vertical
* frequency, you may want to generate a first set of timings given the
* desired vertical frequency, which will give you a specific horizontal
* frequency and dot clock. You can then adjust the dot clock to a value
* that is known to be available on the underlying hardware, and then
* regenerate the timings for that particular dot clock to determine what
* the exact final timings will be.
*
* Alternatively if you only have a fixed set of dot clocks available such
* as on older controllers, you can simply run through the set of available
* dot clocks, and generate a complete set of all available timings that
* can be generated with the set of available dot clocks (and filter out
* unuseable values say < 60Hz and > 120Hz).
*/
void GTF_calcTimings(double hPixels,double vLines,double freq,int type,
ibool wantMargins,ibool wantInterlace,GTF_timings *timings);
/* Functions to read and write the current set of GTF formula constants.
* These constants should be left in the default state that is defined
* by the current version of the GTF specification. However newer DDC
* monitos that support the GTF specification may be able to pass back a
* table of GTF constants to fine tune the GTF timings for their particular
* requirements.
*/
void GTF_getConstants(GTF_constants *constants);
void GTF_setConstants(GTF_constants *constants);
#ifdef __cplusplus
} /* End of "C" linkage for C++ */
#endif
#endif /* __GTF_H */

441
utils/gtf/gtfcalc.c Normal file
View file

@ -0,0 +1,441 @@
/****************************************************************************
*
* VESA Generalized Timing Formula (GTF)
* Version 1.1
*
* ========================================================================
*
* The contents of this file are subject to the SciTech MGL Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.scitechsoft.com/mgl-license.txt
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
*
* The Initial Developer of the Original Code is SciTech Software, Inc.
* All Rights Reserved.
*
* ========================================================================
*
* Developed by: SciTech Software, Inc.
*
* Language: ANSI C
* Environment: Any.
*
* Description: C module for generating GTF compatible timings given a set
* of input requirements. Translated from the original GTF
* 1.14 spreadsheet definition.
*
* Compile with #define TESTING to build a command line test
* program.
*
* NOTE: The code in here has been written for clarity and
* to follow the original GTF spec as closely as
* possible.
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include "gtf.h"
/*------------------------- Global Variables ------------------------------*/
static GTF_constants GC = {
1.8, /* Margin size as percentage of display */
8, /* Character cell granularity */
1, /* Minimum front porch in lines/chars */
3, /* Width of V sync in lines */
8, /* Width of H sync as percent of total */
550, /* Minimum vertical sync + back porch (us) */
600, /* Blanking formula gradient */
40, /* Blanking formula offset */
128, /* Blanking formula scaling factor */
20, /* Blanking formula scaling factor weight */
};
/*-------------------------- Implementation -------------------------------*/
static double round(double v)
{
return floor(v + 0.5);
}
static void GetInternalConstants(GTF_constants *c)
/****************************************************************************
*
* Function: GetInternalConstants
* Parameters: c - Place to store the internal constants
*
* Description: Calculates the rounded, internal set of GTF constants.
* These constants are different to the real GTF constants
* that can be set up for the monitor. The calculations to
* get these real constants are defined in the 'Work Area'
* after the constants are defined in the Excel spreadsheet.
*
****************************************************************************/
{
c->margin = GC.margin;
c->cellGran = round(GC.cellGran);
c->minPorch = round(GC.minPorch);
c->vSyncRqd = round(GC.vSyncRqd);
c->hSync = GC.hSync;
c->minVSyncBP = GC.minVSyncBP;
if (GC.k == 0)
c->k = 0.001;
else
c->k = GC.k;
c->m = (c->k / 256) * GC.m;
c->c = (GC.c - GC.j) * (c->k / 256) + GC.j;
c->j = GC.j;
}
void GTF_calcTimings(double hPixels,double vLines,double freq,
int type,ibool wantMargins,ibool wantInterlace,GTF_timings *t)
/****************************************************************************
*
* Function: GTF_calcTimings
* Parameters: hPixels - X resolution
* vLines - Y resolution
* freq - Frequency (Hz, KHz or MHz depending on type)
* type - 1 - vertical, 2 - horizontal, 3 - dot clock
* margins - True if margins should be generated
* interlace - True if interlaced timings to be generated
* t - Place to store the resulting timings
*
* Description: Calculates a set of GTF timing parameters given a specified
* resolution and vertical frequency. The horizontal frequency
* and dot clock will be automatically generated by this
* routines.
*
* For interlaced modes the CRTC parameters are calculated for
* a single field, so will be half what would be used in
* a non-interlaced mode.
*
****************************************************************************/
{
double interlace,vFieldRate,hPeriod;
double topMarginLines,botMarginLines;
double leftMarginPixels,rightMarginPixels;
double hPeriodEst,vSyncBP,vBackPorch;
double vTotalLines,vFieldRateEst;
double hTotalPixels,hTotalActivePixels,hBlankPixels;
double idealDutyCycle,hSyncWidth,hSyncBP,hBackPorch;
double idealHPeriod;
double vFreq,hFreq,dotClock;
GTF_constants c;
/* Get rounded GTF constants used for internal calculations */
GetInternalConstants(&c);
/* Move input parameters into appropriate variables */
vFreq = hFreq = dotClock = freq;
/* Round pixels to character cell granularity */
hPixels = round(hPixels / c.cellGran) * c.cellGran;
/* For interlaced mode halve the vertical parameters, and double
* the required field refresh rate.
*/
if (wantInterlace) {
vLines = round(vLines / 2);
vFieldRate = vFreq * 2;
dotClock = dotClock * 2;
interlace = 0.5;
}
else {
vFieldRate = vFreq;
interlace = 0;
}
/* Determine the lines for margins */
if (wantMargins) {
topMarginLines = round(c.margin / 100 * vLines);
botMarginLines = round(c.margin / 100 * vLines);
}
else {
topMarginLines = 0;
botMarginLines = 0;
}
if (type != GTF_lockPF) {
if (type == GTF_lockVF) {
/* Estimate the horizontal period */
hPeriodEst = ((1/vFieldRate) - (c.minVSyncBP/1000000)) /
(vLines + (2*topMarginLines) + c.minPorch + interlace) * 1000000;
/* Find the number of lines in vSync + back porch */
vSyncBP = round(c.minVSyncBP / hPeriodEst);
}
else if (type == GTF_lockHF) {
/* Find the number of lines in vSync + back porch */
vSyncBP = round((c.minVSyncBP * hFreq) / 1000);
}
/* Find the number of lines in the V back porch alone */
vBackPorch = vSyncBP - c.vSyncRqd;
/* Find the total number of lines in the vertical period */
vTotalLines = vLines + topMarginLines + botMarginLines + vSyncBP
+ interlace + c.minPorch;
if (type == GTF_lockVF) {
/* Estimate the vertical frequency */
vFieldRateEst = 1000000 / (hPeriodEst * vTotalLines);
/* Find the actual horizontal period */
hPeriod = (hPeriodEst * vFieldRateEst) / vFieldRate;
/* Find the actual vertical field frequency */
vFieldRate = 1000000 / (hPeriod * vTotalLines);
}
else if (type == GTF_lockHF) {
/* Find the actual vertical field frequency */
vFieldRate = (hFreq / vTotalLines) * 1000;
}
}
/* Find the number of pixels in the left and right margins */
if (wantMargins) {
leftMarginPixels = round(hPixels * c.margin) / (100 * c.cellGran);
rightMarginPixels = round(hPixels * c.margin) / (100 * c.cellGran);
}
else {
leftMarginPixels = 0;
rightMarginPixels = 0;
}
/* Find the total number of active pixels in image + margins */
hTotalActivePixels = hPixels + leftMarginPixels + rightMarginPixels;
if (type == GTF_lockVF) {
/* Find the ideal blanking duty cycle */
idealDutyCycle = c.c - ((c.m * hPeriod) / 1000);
}
else if (type == GTF_lockHF) {
/* Find the ideal blanking duty cycle */
idealDutyCycle = c.c - (c.m / hFreq);
}
else if (type == GTF_lockPF) {
/* Find ideal horizontal period from blanking duty cycle formula */
idealHPeriod = (((c.c - 100) + (sqrt((pow(100-c.c,2)) +
(0.4 * c.m * (hTotalActivePixels + rightMarginPixels +
leftMarginPixels) / dotClock)))) / (2 * c.m)) * 1000;
/* Find the ideal blanking duty cycle */
idealDutyCycle = c.c - ((c.m * idealHPeriod) / 1000);
}
/* Find the number of pixels in blanking time */
hBlankPixels = round((hTotalActivePixels * idealDutyCycle) /
((100 - idealDutyCycle) * 2 * c.cellGran)) * (2 * c.cellGran);
/* Find the total number of pixels */
hTotalPixels = hTotalActivePixels + hBlankPixels;
/* Find the horizontal back porch */
hBackPorch = round((hBlankPixels / 2) / c.cellGran) * c.cellGran;
/* Find the horizontal sync width */
hSyncWidth = round(((c.hSync/100) * hTotalPixels) / c.cellGran) * c.cellGran;
/* Find the horizontal sync + back porch */
hSyncBP = hBackPorch + hSyncWidth;
if (type == GTF_lockPF) {
/* Find the horizontal frequency */
hFreq = (dotClock / hTotalPixels) * 1000;
/* Find the horizontal period */
hPeriod = 1000 / hFreq;
/* Find the number of lines in vSync + back porch */
vSyncBP = round((c.minVSyncBP * hFreq) / 1000);
/* Find the number of lines in the V back porch alone */
vBackPorch = vSyncBP - c.vSyncRqd;
/* Find the total number of lines in the vertical period */
vTotalLines = vLines + topMarginLines + botMarginLines + vSyncBP
+ interlace + c.minPorch;
/* Find the actual vertical field frequency */
vFieldRate = (hFreq / vTotalLines) * 1000;
}
else {
if (type == GTF_lockVF) {
/* Find the horizontal frequency */
hFreq = 1000 / hPeriod;
}
else if (type == GTF_lockHF) {
/* Find the horizontal frequency */
hPeriod = 1000 / hFreq;
}
/* Find the pixel clock frequency */
dotClock = hTotalPixels / hPeriod;
}
/* Find the vertical frame frequency */
if (wantInterlace) {
vFreq = vFieldRate / 2;
dotClock = dotClock / 2;
}
else
vFreq = vFieldRate;
/* Return the computed frequencies */
t->vFreq = vFreq;
t->hFreq = hFreq;
t->dotClock = dotClock;
/* Determine the vertical timing parameters */
t->h.hTotal = hTotalPixels;
t->h.hDisp = hTotalActivePixels;
t->h.hSyncStart = t->h.hTotal - hSyncBP;
t->h.hSyncEnd = t->h.hTotal - hBackPorch;
t->h.hFrontPorch = t->h.hSyncStart - t->h.hDisp;
t->h.hSyncWidth = hSyncWidth;
t->h.hBackPorch = hBackPorch;
/* Determine the vertical timing parameters */
t->v.vTotal = vTotalLines;
t->v.vDisp = vLines;
t->v.vSyncStart = t->v.vTotal - vSyncBP;
t->v.vSyncEnd = t->v.vTotal - vBackPorch;
t->v.vFrontPorch = t->v.vSyncStart - t->v.vDisp;
t->v.vSyncWidth = c.vSyncRqd;
t->v.vBackPorch = vBackPorch;
/* Mark as GTF timing using the sync polarities */
t->interlace = (wantInterlace) ? 'I' : 'N';
t->hSyncPol = '-';
t->vSyncPol = '+';
}
void GTF_getConstants(GTF_constants *constants)
{ *constants = GC; }
void GTF_setConstants(GTF_constants *constants)
{ GC = *constants; }
#ifdef TESTING_GTF
int main(int argc,char *argv[])
{
FILE *f;
double xPixels,yPixels,freq;
ibool interlace;
GTF_timings t;
if (argc != 5 && argc != 6) {
printf("Usage: GTFCALC <xPixels> <yPixels> <freq> [[Hz] [KHz] [MHz]] [I]\n");
printf("\n");
printf("where <xPixels> is the horizontal resolution of the mode, <yPixels> is the\n");
printf("vertical resolution of the mode. The <freq> value will be the frequency to\n");
printf("drive the calculations, and will be either the vertical frequency (in Hz)\n");
printf("the horizontal frequency (in KHz) or the dot clock (in MHz). To generate\n");
printf("timings for an interlaced mode, add 'I' to the end of the command line.\n");
printf("\n");
printf("For example to generate timings for 640x480 at 60Hz vertical:\n");
printf("\n");
printf(" GTFCALC 640 480 60 Hz\n");
printf("\n");
printf("For example to generate timings for 640x480 at 31.5KHz horizontal:\n");
printf("\n");
printf(" GTFCALC 640 480 31.5 KHz\n");
printf("\n");
printf("For example to generate timings for 640x480 with a 25.175Mhz dot clock:\n");
printf("\n");
printf(" GTFCALC 640 480 25.175 MHz\n");
printf("\n");
printf("GTFCALC will print a summary of the results found, and dump the CRTC\n");
printf("values to the UVCONFIG.CRT file in the format used by SciTech Display Doctor.\n");
return 1;
}
/* Get values from command line */
xPixels = atof(argv[1]);
yPixels = atof(argv[2]);
freq = atof(argv[3]);
interlace = ((argc == 6) && (argv[5][0] == 'I'));
/* Compute the CRTC timings */
if (toupper(argv[4][0]) == 'H')
GTF_calcTimings(xPixels,yPixels,freq,GTF_lockVF,false,interlace,&t);
else if (toupper(argv[4][0]) == 'K')
GTF_calcTimings(xPixels,yPixels,freq,GTF_lockHF,false,interlace,&t);
else if (toupper(argv[4][0]) == 'M')
GTF_calcTimings(xPixels,yPixels,freq,GTF_lockPF,false,interlace,&t);
else {
printf("Unknown command line!\n");
return 1;
}
/* Dump summary info to standard output */
printf("CRTC values for %.0fx%.0f @ %.2f %s\n", xPixels, yPixels, freq, argv[4]);
printf("\n");
printf(" hTotal = %-4d vTotal = %-4d\n",
t.h.hTotal, t.v.vTotal);
printf(" hDisp = %-4d vDisp = %-4d\n",
t.h.hDisp, t.v.vDisp);
printf(" hSyncStart = %-4d vSyncStart = %-4d\n",
t.h.hSyncStart, t.v.vSyncStart);
printf(" hSyncEnd = %-4d vSyncEnd = %-4d\n",
t.h.hSyncEnd, t.v.vSyncEnd);
printf(" hFrontPorch = %-4d vFrontPorch = %-4d\n",
t.h.hFrontPorch, t.v.vFrontPorch);
printf(" hSyncWidth = %-4d vSyncWidth = %-4d\n",
t.h.hSyncWidth, t.v.vSyncWidth);
printf(" hBackPorch = %-4d vBackPorch = %-4d\n",
t.h.hBackPorch, t.v.vBackPorch);
printf("\n");
printf(" Interlaced = %s\n", (t.interlace == 'I') ? "Yes" : "No");
printf(" H sync pol = %c\n", t.hSyncPol);
printf(" V sync pol = %c\n", t.vSyncPol);
printf("\n");
printf(" Vert freq = %.2f Hz\n", t.vFreq);
printf(" Horiz freq = %.2f KHz\n", t.hFreq);
printf(" Dot Clock = %.2f Mhz\n", t.dotClock);
fprintf(stderr,"Modeline %c%ix%i@%.0f%c %.3f %i %i %i %i %i %i %i %i %s %chsync %cvsync\n",
'"',t.h.hDisp,t.v.vDisp,t.vFreq,'"',
t.dotClock,
t.h.hDisp,
t.h.hSyncStart,
t.h.hSyncEnd,
t.h.hTotal,
t.v.vDisp,
t.v.vSyncStart,
t.v.vSyncEnd,
t.v.vTotal,
(t.interlace == 'I') ? "Interlace" : "",
t.hSyncPol,
t.vSyncPol
);
/* Dump to file in format used by SciTech Display Doctor */
if ((f = fopen("UVCONFIG.CRT","wt")) != NULL) {
fprintf(f, "[%.0f %.0f]\n", xPixels, yPixels);
fprintf(f, "%d %d %d %d '%c' %s\n",
t.h.hTotal, t.h.hDisp,
t.h.hSyncStart, t.h.hSyncEnd,
t.hSyncPol, (t.interlace == 'I') ? "I" : "NI");
fprintf(f, "%d %d %d %d '%c'\n",
t.v.vTotal, t.v.vDisp,
t.v.vSyncStart, t.v.vSyncEnd,
t.vSyncPol);
fprintf(f, "%.2f\n", t.dotClock);
fclose(f);
}
return 0;
}
#endif /* TESTING */

506
utils/gtf/scitech.h Normal file
View file

@ -0,0 +1,506 @@
/****************************************************************************
*
* SciTech Multi-platform Graphics Library
*
* ========================================================================
*
* The contents of this file are subject to the SciTech MGL Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.scitechsoft.com/mgl-license.txt
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
*
* The Initial Developer of the Original Code is SciTech Software, Inc.
* All Rights Reserved.
*
* ========================================================================
*
* Language: ANSI C
* Environment: any
*
* Description: General header file for operating system portable code.
*
****************************************************************************/
#ifndef __SCITECH_H
#define __SCITECH_H
/* We have the following defines to identify the compilation environment:
*
* __16BIT__ Compiling for 16 bit code (any environment)
* __32BIT__ Compiling for 32 bit code (any environment)
* __MSDOS__ Compiling for MS-DOS (includes __WINDOWS16__, __WIN386__)
* __REALDOS__ Compiling for MS-DOS (excludes __WINDOWS16__)
* __MSDOS16__ Compiling for 16 bit MS-DOS
* __MSDOS32__ Compiling for 32 bit MS-DOS
* __WINDOWS__ Compiling for Windows
* __WINDOWS16__ Compiling for 16 bit Windows (__MSDOS__ also defined)
* __WINDOWS32__ Compiling for 32 bit Windows
* __WIN32_VXD__ Compiling for a 32-bit C based VxD
* __OS2__ Compiling for OS/2
* __OS2_16__ Compiling for 16 bit OS/2
* __OS2_32__ Compiling for 32 bit OS/2
* __UNIX__ Compiling for Unix
* __QNX__ Compiling for the QNX realtime OS (Unix compatible)
* __LINUX__ Compiling for the Linux OS (Unix compatible)
* __FREEBSD__ Compiling for the FreeBSD OS (Unix compatible)
* __BEOS__ Compiling for the BeOS (Unix compatible)
* __SMX32__ Compiling for the SMX 32-bit Real Time OS
* __DRIVER__ Compiling for a 32-bit binary compatible driver
*
* __INTEL__ Compiling for Intel CPU's
* __ALPHA__ Compiling for DEC Alpha CPU's
* __MIPS__ Compiling for MIPS CPU's
* __PPC__ Compiling for PowerPC CPU's
* __MC68K__ Compiling for Motorola 680x0
*
*/
#ifdef __SC__
#if __INTSIZE == 4
#define __SC386__
#endif
#endif
#ifdef __GNUC__
#if !defined(__BEOS__)
#define __cdecl /* GCC doesn't know about __cdecl modifiers */
#endif
#define __FLAT__ /* GCC is always 32 bit flat model */
#define __HAS_BOOL__ /* Latest GNU C++ has ibool type */
#include <stdio.h> /* Bring in for definition of NULL */
#endif
#ifdef __BORLANDC__
#if (__BORLANDC__ >= 0x500) || defined(CLASSLIB_DEFS_H)
#define __HAS_BOOL__ /* Borland C++ 5.0 and later define ibool type */
#endif
#endif
/*---------------------------------------------------------------------------
* Determine the compile time environment. This must be done for each
* supported platform so that we can determine at compile time the target
* environment, hopefully without requiring #define's from the user.
*-------------------------------------------------------------------------*/
/* 32-bit binary compatible driver. Compiled as Win32, but as OS neutral */
#ifdef __DRIVER__
#ifndef __32BIT__
#define __32BIT__
#endif
#undef __WINDOWS__
#undef _WIN32
#undef __WIN32__
#undef __NT__
/* 32-bit Windows VxD compile environment */
#elif defined(__vtoolsd_h_) || defined(VTOOLSD)
#include <vtoolsc.h>
#define __WIN32_VXD__
#ifndef __32BIT__
#define __32BIT__
#endif
#define _MAX_PATH 256
#ifndef __WINDOWS32__
#define __WINDOWS32__
#endif
/* 32-bit SMX compile environment */
#elif defined(__SMX32__)
#ifndef __MSDOS__
#define __MSDOS__
#endif
#ifndef __32BIT__
#define __32BIT__
#endif
#ifndef __REALDOS__
#define __REALDOS__
#endif
/* 32-bit extended DOS compile environment */
#elif defined(__MSDOS__) || defined(__MSDOS32__) || defined(__DOS__) || defined(__DPMI32__) || (defined(M_I86) && !defined(__SC386__)) || defined(TNT)
#ifndef __MSDOS__
#define __MSDOS__
#endif
#if defined(__MSDOS32__) || defined(__386__) || defined(__FLAT__) || defined(__NT__) || defined(__SC386__)
#ifndef __MSDOS32__
#define __MSDOS32__
#endif
#ifndef __32BIT__
#define __32BIT__
#endif
#ifndef __REALDOS__
#define __REALDOS__
#endif
/* 16-bit Windows compile environment */
#elif (defined(_Windows) || defined(_WINDOWS)) && !defined(__DPMI16__)
#ifndef __16BIT__
#define __16BIT__
#endif
#ifndef __WINDOWS16__
#define __WINDOWS16__
#endif
#ifndef __WINDOWS__
#define __WINDOWS__
#endif
#ifndef __MSDOS__
#define __MSDOS__
#endif
/* 16-bit DOS compile environment */
#else
#ifndef __16BIT__
#define __16BIT__
#endif
#ifndef __MSDOS16__
#define __MSDOS16__
#endif
#ifndef __REALDOS__
#define __REALDOS__
#endif
#endif
/* 32-bit Windows compile environment */
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#ifndef __32BIT__
#define __32BIT__
#endif
#ifndef __WINDOWS32__
#define __WINDOWS32__
#endif
#ifndef _WIN32
#define _WIN32 /* Microsoft Win32 SDK headers use _WIN32 */
#endif
#ifndef WIN32
#define WIN32 /* OpenGL headers use WIN32 */
#endif
#ifndef __WINDOWS__
#define __WINDOWS__
#endif
/* 16-bit OS/2 compile environment */
#elif defined(__OS2_16__)
#ifndef __OS2__
#define __OS2__
#endif
#ifndef __16BIT__
#define __16BIT__
#endif
/* 32-bit OS/2 compile environment */
#elif defined(__OS2__) || defined(__OS2_32__)
#ifndef __OS2__
#define __OS2__
#endif
#ifndef __OS2_32__
#define __OS2_32__
#endif
#ifndef __32BIT__
#define __32BIT__
#endif
/* 32-bit QNX compile environment */
#elif defined(__QNX__)
#ifndef __32BIT__
#define __32BIT__
#endif
#ifndef __UNIX__
#define __UNIX__
#endif
/* 32-bit Linux compile environment */
#elif defined(__LINUX__) || defined(linux)
#ifndef __LINUX__
#define __LINUX__
#endif
#ifndef __32BIT__
#define __32BIT__
#endif
#ifndef __UNIX__
#define __UNIX__
#endif
/* 32-bit FreeBSD compile environment */
#elif defined(__FREEBSD__)
#ifndef __32BIT__
#define __32BIT__
#endif
#ifndef __UNIX__
#define __UNIX__
#endif
/* 32-bit BeOS compile environment */
#elif defined(__BEOS__)
#ifndef __32BIT__
#define __32BIT__
#endif
#ifndef __UNIX__
#define __UNIX__
#endif
#else
#error This platform is not currently supported!
#endif
/* Determine the CPU type that we are compiling for */
#if defined(__M_ALPHA) || defined(__ALPHA_) || defined(__ALPHA) || defined(__alpha)
#ifndef __ALPHA__
#define __ALPHA__
#endif
#elif defined(__M_PPC) || defined(__POWERC)
#ifndef __PPC__
#define __PPC__
#endif
#elif defined(__M_MRX000)
#ifndef __MIPS__
#define __MIPS__
#endif
#else
#ifndef __INTEL__
#define __INTEL__ /* Assume Intel if nothing found */
#endif
#endif
/* We have the following defines to define the calling conventions for
* publicly accesible functions:
*
* _PUBAPI - Compiler default calling conventions for all public 'C' functions
* _ASMAPI - Calling conventions for all public assembler functions
* _DLLAPI - Calling conventions for all DLL exported functions
* _DLLVAR - Modifier to export/import globals in 32 bit DLL's
* _EXPORT - Expands to _export when compiling a DLL
* _VARAPI - Modifiers for variables; Watcom C++ mangles C++ globals
*/
#if defined(_MSC_VER) && defined(_WIN32) && !defined(__SC__)
#define __PASCAL __stdcall
#define __export
#define __import
#else
#define __PASCAL __pascal
#endif
#ifdef __WATCOMC__
#if (__WATCOMC__ >= 1050)
#define _VARAPI __cdecl
#else
#define _VARAPI
#endif
#else
#define _VARAPI
#endif
#if defined(__IBMC__) || defined(__IBMCPP__)
#define PTR_DECL_IN_FRONT
#endif
#if defined(__WINDOWS__)
#ifdef BUILD_DLL
#define _DLLASM __export __cdecl
#define _EXPORT __export
#ifdef __WINDOWS32__
#define _DLLAPI __export __PASCAL
#define _DLLVAR __export
#else
#define _DLLAPI __export __far __pascal
#define _DLLVAR
#endif
#else
#define _DLLASM __cdecl
#define _EXPORT
#ifdef __WINDOWS32__
#define _DLLAPI __PASCAL
#define _DLLVAR __import
#else
#define _DLLAPI __far __pascal
#define _DLLVAR
#endif
#endif
#else
#if !defined(__BEOS__)
#define _EXPORT
#endif
#define _DLLAPI
#define _DLLVAR
#endif
/* Define the calling conventions for all public functions. For simplicity
* we define all public functions as __cdecl calling conventions, so that
* they are the same across all compilers and runtime DLL's.
*/
#define _PUBAPI __cdecl
#define _ASMAPI __cdecl
/* Determine the syntax for declaring a function pointer with a
* calling conventions override. Most compilers require the calling
* convention to be declared in front of the '*', but others require
* it to be declared after the '*'. We handle both in here depending
* on what the compiler requires.
*/
#ifdef PTR_DECL_IN_FRONT
#define _DLLAPIP * _DLLAPI
#define _DLLASMP * _DLLASM
#define _PUBAPIP * _PUBAPI
#define _ASMAPIP * _ASMAPI
#else
#define _DLLAPIP _DLLAPI *
#define _DLLASMP _DLLASM *
#define _PUBAPIP _PUBAPI *
#define _ASMAPIP _ASMAPI *
#endif
/* Useful macros */
#define PRIVATE static
#define PUBLIC
/* This HAS to be 0L for 16-bit real mode code to work!!! */
#ifndef NULL
# define NULL 0L
#endif
#ifndef MAX
# define MAX(a,b) ( ((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
# define MIN(a,b) ( ((a) < (b)) ? (a) : (b))
#endif
#ifndef ABS
# define ABS(a) ((a) >= 0 ? (a) : -(a))
#endif
#ifndef SIGN
# define SIGN(a) ((a) > 0 ? 1 : -1)
#endif
/* General typedefs */
#ifndef __GENDEFS
#define __GENDEFS
#if defined(__BEOS__)
#include <SupportDefs.h>
#else
#ifdef __LINUX__
#include <sys/types.h>
#ifdef __STRICT_ANSI__
typedef unsigned short ushort;
typedef unsigned long ulong;
typedef unsigned int uint;
#endif
#else
#if !(defined(__QNXNTO__) && defined(GENERAL_STRUCT))
typedef unsigned short ushort;
typedef unsigned long ulong;
#endif
typedef unsigned int uint;
#endif
typedef unsigned char uchar;
#endif
typedef int ibool; /* Integer boolean type */
#ifdef USE_BOOL /* Only for older code */
#ifndef __cplusplus
#define bool ibool /* Standard C */
#else
#ifndef __HAS_BOOL__
#define bool ibool /* Older C++ compilers */
#endif
#endif /* __cplusplus */
#endif /* USE_BOOL */
#endif /* __GENDEFS */
/* Boolean truth values */
#undef false
#undef true
#undef NO
#undef YES
#undef FALSE
#undef TRUE
#define false 0
#define true 1
#define NO 0
#define YES 1
#define FALSE 0
#define TRUE 1
/* Inline debugger interrupts for Watcom C++ and Borland C++ */
#ifdef __WATCOMC__
void DebugInt(void);
#pragma aux DebugInt = \
"int 3";
void DebugVxD(void);
#pragma aux DebugVxD = \
"int 1";
#elif defined(__BORLANDC__)
#define DebugInt() __emit__(0xCC)
#define DebugVxD() {__emit__(0xCD); __emit__(0x01);}
#elif defined(_MSC_VER)
#define DebugInt() _asm int 0x3
#define DebugVxD() _asm int 0x1
#else
#define DebugInt()
#define DebugVxD()
#endif
/*---------------------------------------------------------------------------
* Set of debugging macros used by the libraries. If the debug flag is
* set, they are turned on depending on the setting of the flag. User code
* can override the default functions called when a check fails, and the
* MGL does this so it can restore the system from graphics mode to display
* an error message. These functions also log information to the
* scitech.log file in the root directory of the hard drive when problems
* show up.
*
* If you set the value of CHECKED to be 2, it will also enable code to
* insert hard coded debugger interrupt into the source code at the line of
* code where the check fail. This is useful if you run the code under a
* debugger as it will break inside the debugger before exiting with a
* failure condition.
*
* Also for code compiled to run under Windows, we also call the
* OutputDebugString function to send the message to the system debugger
* such as Soft-ICE or WDEB386. Hence if you get any non-fatal warnings you
* will see those on the debugger terminal as well as in the log file.
*-------------------------------------------------------------------------*/
extern void (*_CHK_fail)(int fatal,const char *msg,const char *cond,const char *file,int line);
void _CHK_defaultFail(int fatal,const char *msg,const char *cond,const char *file,int line);
#ifdef CHECKED
# define CHK(x) x
#if CHECKED > 1
# define CHECK(p) \
((p) ? (void)0 : DebugInt(), \
_CHK_fail(1,"Check failed: '%s', file %s, line %d\n", \
#p, __FILE__, __LINE__))
# define WARN(p) \
((p) ? (void)0 : DebugInt(), \
_CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
#p, __FILE__, __LINE__))
#else
# define CHECK(p) \
((p) ? (void)0 : \
_CHK_fail(1,"Check failed: '%s', file %s, line %d\n", \
#p, __FILE__, __LINE__))
# define WARN(p) \
((p) ? (void)0 : \
_CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
#p, __FILE__, __LINE__))
#endif
#else
# define CHK(x)
# define CHECK(p) ((void)0)
# define WARN(p) ((void)0)
#endif
#endif /* __SCITECH_H */