/****************************************************************************
*                   ibm.c
*
*  This module implements the IBM-PC specific routines for POV-Ray.
*
*  from Persistence of Vision Raytracer
*  Copyright 1993 Persistence of Vision Team
*---------------------------------------------------------------------------
*  NOTICE: This source code file is provided so that users may experiment
*  with enhancements to POV-Ray and to port the software to platforms other 
*  than those supported by the POV-Ray Team.  There are strict rules under
*  which you are permitted to use this file.  The rules are in the file
*  named POVLEGAL.DOC which should be distributed with this file. If 
*  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
*  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
*  Forum.  The latest version of POV-Ray may be found there as well.
*
* This program is based on the popular DKB raytracer version 2.12.
* DKBTrace was originally written by David K. Buck.
* DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
*
*****************************************************************************/

/* Original IBM VGA "colour" output routines for MS/DOS by Aaron A. Collins.

   This will deliver approximate colorings using HSV values for the selection.
   The palette map is divided into 4 parts - upper and lower half generated
   with full and half "value" (intensity), respectively.  These halves are
   further halved by full and half saturation values of each range (pastels).
   There are three constant colors, black, white, and grey.  They are used
   when the saturation is low enough that the hue becomes undefined, and which
   one is selected is based on a simple range map of "value".  Usage of the
   palette is accomplished by converting the requested color RGB into an HSV
   value.  If the saturation is too low (< .25) then black, white or grey is
   selected.  If there is enough saturation to consider looking at the hue,
   then the hue range of 1-63 is scaled into one of the 4 palette quadrants
   based on its "value" and "saturation" characteristics.

   Further SVGA, MVGA mods by Aaron A. Collins:
   SVGA, MVGA assembler routines originally by John Bridges.
   VESA assembler routines from FRACTINT, by The Stone Soup Group
   AT&T VDC600 SVGA mods to DKB Trace 2.01 module IBM.C by John Gooding

   This file now represents the collective wisdom of the VGAKIT34 package,
   with support for all of the SVGA types known to mankind.  Seriously,
   VGAKIT34 is an excellent technical reference for IBM programmers wishing
   to do any sort of SVGA video access, and it encompasses nearly all of the
   SVGA adapters in use today.  It was written by John Bridges, a.k.a.
   CIS:73307,606, GENIE:J.BRIDGES.  It was originally coded in IBM 80x86
   assembler, and since DKBTrace is a completely "C"-based package, I have
   converted John's assembler routines all into "C".  These may be a tad bit
   slower, but they should be compatible across a wide variety of 80x86/(S)VGA
   machines.  Note if you have a regular cheapo VGA card like myself, included
   is "MODE13x" or MVGA (modified VGA) mode (some call it "tweaked", but I
   call it "Simulated SVGA"), which gives 360x480 on any reasonably register-
   compatible plain vanilla VGA card.  This mode gives a good simulated 640 by
   480 screen resolution.  I did not implement all the neat hi-res modes of
   all the various SVGA adapters, if you select a trace size bigger than the
   program and/or card can handle (most likely 640x480), it is dynamically
   scaled to fit the available resolution, so you'll be able to see a rough
   approximation of an 800x600 trace even on any el-cheapo VGA card at 320x200
   resolution.  The VESA VGA mode was freely adapted from FRACTINT, whose GIF
   reading routines we are already using in DKBTrace.  I hope my conversion
   of it works properly.

   There is still a reported problem with the EVEREX autodetect returning
   TRIDENT.  In fact EVEREX uses a TRIDENT chip set, but apparently there
   is some difference in operation.  There are cryptic diagnostic messages
   such as T0000, etc. printed as a result of the autodetection routines
   to help track down why the error is happening.  If you are experiencing
   problems with EVEREX or TRIDENT, make note of the letter-4 digit code you
   are given.  There is now an autodetect for VDC600 that I hope will work
   universally.  A similar problem as the EVEREX exists, in that the VDC600
   is detected as a PARADISE because it uses the PARADISE chip set.  I am now
   looking for what I believe to be the model number in the BIOS ROM of the
   VDC600 to differentiate between the two.  I hope this works  with all
   VDC600's, as I only had one example to work from.  Please send all bug
   reports to Aaron Collins at the "You Can Call Me RAY" BBS, the number is
   in the authors.txt document.


   POV-Ray Enhancements:

   (S)VGA B&W 64 Greyscale code courtesy of Grant Hess 6/21/91

   16/24-bit HGWS/TIGA/TRUECOLOR code courtesy of Jay S. Curtis 11/15/90

   VGA "332" palette routines courtesy of Alexander Enzmann 7/20/91

   Additional support for VESA and Tseng Labs 256 and 32768 color modes by
   Charles Marslett  (CIS: 75300,1636).  Resolution is selected to be the
   lowest possible and still fit the image entirely on the screen. 4/28/91

   ATI VGA Wonder XL Support for 32,768 color mode and all other SVGA modes
   by Randy Antler.  Also image centering, outline box, and forces SVGA mode
   for small images.  Minor bug fixes and cleanups as well. 9/11/91

   Combined IBMPRO.C and IBM.C into 1 file.
   B.Pulver 10/20/91

   Corrected defects in the centering and high color support for VESA modes
   (particularly necessary for the newer 24-bit color cards and S3 based
   Windows accellerator cards) -- Charles Marslett, 12/8/91 to 4/25/92.

   Extended Doug's dithering code to other high color modes and eliminated
   a bad validity check in the 24-bit code high color cards.  Had to add
   an "#include <float.h>" to ibmconf.h for the WATCOM C compilers with the
   patchlevel C include files -- Charles Marslett, 10/4/92.

   Added support for Diamond Speedstar 24X. Uses a modified copy of some
   of the Paradise code. There is no AutoDetect functionality for this
   card, though.  Note that a couple of pixels (about 14), namely those
   that straddle bank boundaries will be displayed incorrectly.
                                 -- Lutz Kretzschmar,  10/30/92

   Fixed (obvious) bug for displaying images larger than screen
   resolutions. Strange no-one caught it, it didn't work!. The line coord
   cache is set to the max value by the box() function. Added code to
   reset the values inside box().
   Added bank switch checking inside pixels for truecolor modes.
   Added HiColor display in 640x480 and 800x600 resolutions for Diamond
   SpeedStar 24X.          -- Lutz Kretzschmar,  11/05/92

   Added TARGA+ display adapter support and reworked find_go32() to make
   the VESA and TARGA routines work properly with DJ's port of IBMGCC
   - Aaron A. Collins, 2/2/93.

   Completed Intel Code Builder code for VESA 1.2 support. - B.Pulver 2/15/93
   Added: Set palette to P_332 if Hi/True color VESA init fails.
          Doubled dithering matrixes to support 2048Xxxxx images.
          Added code to disable dithering @ rez over 2048Xxxxx.
          Added message warning user of failure if no_valid_mode is called
          during VESA initialization attempt. - B.Pulver 5/13/93

   Found consistency bug in previously fixed find_go32(), so this too
   has been fixed.  Found DJGCC's setvbuf() was blowing up the VESA/TARGA
   "answer" area (in low real mode accessable mem) after a disk write, so
   the setvbuf() function has been dummied up in this file to do nothing.
   Added some DEBUG_VIDEO diagnostics for figuring out problems running a
   TARGA+ display on the Intel Code Builder. - Aaron A. Collins, 8/2/1993

*/

#define DITHERED        /* Defined to test Doug Muir's dithering code */

/*#define DEBUG_VIDEO*/		/* Uncomment to display Video initialization info during program startup. */
/*#define SVBOX*/			/* Uncomment to use setvbuf in GCCDOS anyway. */

#ifdef DEBUG_VIDEO
int diaged;				/* excessive diagnostic message clamp */
#endif

#include <dos.h>          /* MS-DOS specific - for int86() REGS struct, etc. */
#include <stdarg.h>
#include <time.h>
#include "frame.h"
#include "povproto.h"

#if !defined(DOS386) && !defined(_INTELC32_) && !defined(__386__) && !defined(GCCDOS)
  #include "tiga.h"       /* HGWS/TIGA function library include files - not supported by 32 bit compilers */
  #include "tigadefs.h"
  #include "extend.h"
#endif

#include <io.h>           /* for low-level open() funct, etc. */
#include <fcntl.h>        /* for low-level open() modes O_RDWR, O_BINARY, etc. */

/* Compiler specific setups & defines. */
#ifdef __TURBOC__
  extern unsigned _stklen = 12288; /* fairly large stack for HEAVY recursion */
  #define CLD asm cld
  #define _asm asm
  #define _far far
#else
#ifdef __WATCOMC__
  #include <float.h>
  #define CLD clear_direction()
  unsigned short __8087cw = IC_AFFINE | RC_NEAR | PC_64  | 0x007F;
  void clear_direction(void);
  #pragma aux clear_direction = 0xFC parm [] modify nomemory;
#ifdef __386__
  #define ax eax
  #define bx ebx
  #define cx ecx
  #define dx edx
  #define di edi
  #define int86 int386
  #define int86x int386x
#endif
#else

#ifdef _INTELC32_
  #pragma interrupt (int10)   /* Need to install user INT10 handler for VESA. */
  /* Use MSC 6.0a compatible mode. NOANSI switch in Makefile */
  #include <stk.h>            /* Stack support for user INT10. */
  #define CLD cld()

  void int10();
  void (*prev_int10)();

  void cld (void)             /* Clear direction flag. */
  {
    unsigned int flags;
    flags = _getflags();
    flags = flags & (!_FLAG_DIRECTION);
    _setflags (flags);
  }
#else
#ifdef __ZTC__
  #include <math.h>
  #include <int.h>

  #ifndef DOS386
  #ifndef DOS16RM
  unsigned _stack = 12288;
  #endif
  #endif

  #define CLD
  #define min(x,y) ((x) < (y)? (x): (y))

  #ifdef DOS386
    extern unsigned short _x386_zero_base_selector;
    #define _disable()
    #define _enable()
    #define _cdecl
  #else
  #ifdef DOS16RM
    void *D16SegAbsolute(long absadr, short size);
    void D16SegCancel(void *segptr);
    #define _disable()
    #define _enable()
    unsigned char *display_base;
  #else
    #define _disable() int_off()
    #define _enable()  int_on()
  #endif
  #endif

#else
#ifdef GCCDOS
  #include <errno.h>
  #include <pc.h>
  #include <ctype.h>

  unsigned char *find_go32(int *go32_offset);

  #define _cdecl
  #define _far
  #define CLD
#else
  #define CLD _asm cld
#endif
#endif
#endif
#endif
#endif

#ifdef __WATCOMC__
  int matherr(struct exception *);     /* Math error traps. */
#else
#ifdef GCCDOS
  int matherr(struct libm_exception *);
#else
  int _cdecl matherr(struct exception *);
#endif
#endif


#ifdef DITHERED
signed short r_err[2][2050];          /* Allow up to 2048x??? resolutions. */
signed short g_err[2][2050];
signed short b_err[2][2050];
#endif

/* The supported VGA adapter types 1 - 9, A - Z.  0 is for auto-detect. */

#define BASIC_VGA       1               /* 1 - Tested: AAC */
#define MODE13x         2               /* 2 - Tested: AAC */
#define TSENG3          3               /* 3 - Tested: William Minus */
#define TSENG4          4               /* 4 - Tested: William Minus */
#define VDC600          5               /* 5 - Tested: John Gooding */
#define OAKTECH         6               /* 6 - Untested */
#define VIDEO7          7               /* 7 - Untested */
#define CIRRUS          8               /* 8 - Tested: AAC */
#define PARADISE        9               /* 9 - Tested: John Degner */
#define AHEADA          17              /* A - Untested */
#define AHEADB          18              /* B - Untested */
#define CHIPSTECH       19              /* C - Untested */
#define ATIVGA          20              /* D - Tested: William Earl */
#define EVEREX          21              /* E - Tested: A+B problem - Larry Minton */
#define TRIDENT         22              /* F - Tested: A problem - Alexander Enzmann */
#define VESA            23              /* G - Tested: Charles Marslett/AAC/BP */
#define ATIXL           24              /* H - Tested: Randy Antler */
#define PARADISE24X     25              /* I - Tested: Lutz Kretzschmar */
/* J - N -- 5 more reserved SVGA adapter types */
#define TRUECOLOR       31              /* >= O isn't an (S)VGA - note this is a "marker" display type only!!! */
#define TIGA_16         31              /* O - Tested: Jay S. Curtis */
#define TIGA_24         32              /* P - Tested: Jay S. Curtis */
#define TRUE_640        33              /* Q - 640 x 480 truecolor Tested: Jay S. Curtis */
#define TRUE_800        34              /* R - 800 x 600 truecolor Tested: Jay S. Curtis */
#define TRUE_1024       35              /* S - 1024 x 768 truecolor Tested: Jay S. Curtis */
#define TARGA           36              /* T - TARGA+ in AOM Tested: Aaron A. Collins */
/* U - Z -- 6 more reserved Non-SVGA (True-Color) adapter types */


#define MISCOUT         0x3c2           /* VGA chip msic output reg. addr */
#define SEQUENCER       0x3c4           /* VGA chip sequencer register addr */
#define CRTC            0x3d4           /* VGA chip crt controller reg addr */


char *vga_names[] =
    {                                   /* POV-Ray command line option: */
    "",                                 /* '0' is autodetect */
    "Standard VGA",                     /*  1  */
    "Simulated SVGA",                   /*  2  */
    "Tseng Labs 3000 SVGA",             /*  3  */
    "Tseng Labs 4000 SVGA",             /*  4  */
    "AT&T VDC600 SVGA",                 /*  5  */
    "Oak Technologies SVGA",            /*  6  */
    "Video 7 SVGA",                     /*  7  */
    "Video 7 Vega (Cirrus) VGA",        /*  8  */
    "Paradise SVGA",                    /*  9  */
    "",                                 /* misc ASCII */
    "",
    "",
    "", /* reserved */
    "",
    "",
    "",
    "Ahead Systems Ver. A SVGA",        /*  A  */
    "Ahead Systems Ver. B SVGA",        /*  B  */
    "Chips & Technologies SVGA",        /*  C  */
    "ATI SVGA",                         /*  D  */
    "Everex SVGA",                      /*  E  */
    "Trident SVGA",                     /*  F  */
    "VESA Standard SVGA",               /*  G  */
    "ATI VGA Wonder XL 32K Color SVGA", /*  H  */
    "Diamond SpeedStar 24X SVGA",       /*  I  */
    "",
    "", /* spare SVGAs */
    "",
    "",
    "",
    "Hercules GWS/TIGA 16-bit",          /*  O   Here on is reserved for non-SVGA cards */
    "Hercules GWS/TIGA 24-bit",          /*  P   TIGA is unsupported by the 32 bit compilers */
    "TrueColor 640 x 480",               /*  Q  */
    "TrueColor 800 x 600",               /*  R  */
    "TrueColor 1024 x 768",              /*  S  */
    "Truevision TARGA Plus"              /*  T  */
    };


unsigned int vptbl[] =          /* CRTC register values for MODE13x */
    {
    0x6b00,     /* horz total */
    0x5901,     /* horz displayed */
    0x5a02,     /* start horz blanking */
    0x8e03U,    /* end horz blanking */
    0x5e04,     /* start h sync */
    0x8a05U,    /* end h sync */
    0x0d06,     /* vertical total */
    0x3e07,     /* overflow */
    0x4009,     /* cell height */
    0xea10U,    /* v sync start */
    0xac11U,    /* v sync end and protect cr0-cr7 */
    0xdf12U,    /* vertical displayed */
    0x2d13,     /* offset */
    0x0014,     /* turn off dword mode */
    0xe715U,    /* v blank start */
    0x0616,     /* v blank end */
    0xe317U     /* turn on byte mode */
};

unsigned short screen_height, screen_width;
unsigned short svga_width = 640;           /* width of a scan line on the screen */
unsigned short svga_height = 480;          /* number of scan lines on the screen */
unsigned short svga_yincr = 640;           /* width of a scan line in video memory */
int lastx, lasty, lastline;                /* Pixel / Line Caches */
unsigned int x_off = 0;                    /* Offsets for image centering option */
unsigned int y_off = 0;
int whichvga = BASIC_VGA;                  /* BASIC_VGA mode by default */
int vga_512K = FALSE;                      /* Flag for whether or not >= 512K VGA mem */
int bpp = 8;                               /* Number of bits per pixel */
unsigned char cur_page = 255;              /* SVGA current page (bank) number */
unsigned int map_code = 0;                 /* Default map code is 0 */
unsigned long gran = 65536L;               /* SVGA granule size (64K by default) */
#ifdef _INTELC32_
unsigned char *answer;                     /* Code Builder answer area for VESA BIOS calls */
#else
#ifdef DOS16RM
unsigned char *answer;                     /* ZTC 16 answer area for VESA BIOS calls */
static char save[260];
unsigned long tl;
#else
#ifdef GCCDOS
volatile unsigned char *answer;            /* GCC answer area for VESA BIOS calls */
int di_val, c_val, t_val, ds_val;
#else
#ifdef __WATCOMC__
#ifdef __386__
unsigned int vesabuffer;                   /* Save area for the DOS segment pointer */
unsigned char *answer;                     /* Watcom 386 answer area for VESA BIOS calls */
#else
unsigned char answer[260];                 /* Answer area for VESA BIOS calls */
#endif
#else
unsigned char answer[260];                 /* Answer area for VESA BIOS calls */
#endif
#endif
#endif
#endif
unsigned short vesamode;                   /* Current VESA BIOS supported mode */

#if !defined(DOS386) && !defined(_INTELC32_) && !defined(__386__) && !defined(GCCDOS)
int dither_matrix[4][4]=
        {
         {0,8,2,10},                       /* HGWS/TIGA dither matrix */
         {12,4,14,6},                      /* this may not be needed? */
         {3,11,1,9},
         {15,7,13,5}
        };
char hpt[3];                               /* HWGS/TIGA information passing area */
char _far *hptr=hpt;                       /* HWGS/TIGA information passing area ptr */
CONFIG config;
#endif

DBL Height_Adjust = 1.0;                   /* Fudge factors for SVGA scaling */
DBL Width_Adjust = 1.0;

unsigned short pixel_len;
unsigned short red_ndx, blue_ndx, green_ndx;

/* VESA VBE standard mode numbers */

struct {
   unsigned short modenum;
   unsigned short width;
   unsigned short height;
   unsigned short bpp;
   unsigned short gsize;
   } modelist[] = {{0x100, 640, 400, 8, 0}, {0x101, 640, 480, 8, 0},
                   {0x103, 800, 600, 8, 0}, {0x105, 1024, 768, 8, 0},
                   {0x107, 1280, 1024, 8, 0}, {0x10D, 320, 200, 16, 5},
                   {0x10E, 320, 200, 16, 6}, {0x10F, 320, 200, 24, 8},
                   {0x110, 640, 480, 16, 5}, {0x111, 640, 480, 16, 6},
                   {0x112, 640, 480, 24, 8}, {0x113, 800, 600, 16, 5},
                   {0x114, 800, 600, 16, 6}, {0x115, 800, 600, 24, 8},
                   {0x116, 1024, 768, 16, 5}, {0x117, 1024, 768, 16, 6},
                   {0x118, 1024, 768, 24, 8}, {0x119, 1280, 1024, 16, 5},
                   {0x11A, 1280, 1024, 16, 6}, {0x11B, 1280, 1024, 24, 8}};

unsigned int bitmask[] = {0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F,
      0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF,
      0x7FFF, 0xFFFF};

int r_shift, g_shift, b_shift;
unsigned int r_mask, g_mask, b_mask;


extern unsigned int Options;
extern char DisplayFormat, PaletteOption, Color_Bits;
extern int First_Line, Last_Line;
extern int First_Column, Last_Column;


int AutodetectVGA(void);
int cirrus(void);
int chkbank(unsigned int, unsigned int);
void palette_init(void);
void newbank(void);
void set_palette_register(unsigned, unsigned, unsigned, unsigned);
void hsv_to_rgb(DBL, DBL, DBL, unsigned *, unsigned *, unsigned *);
void rgb_to_hsv(unsigned, unsigned, unsigned, DBL *, DBL *, DBL *);
void atiplot(int, int, int, int, int);
void box(int, int, int, int);
int _cdecl box_fprintf( FILE *stream, char *format,...);

#ifdef DOS386
void get_real_buf(short *real_buf, unsigned char _far **ptr);

static short real_buf[2];
static unsigned char _far *real_ptr;
#endif

/*
	Note: for non-32-bit compilers, we can have a long in the struct and
    still get word-aligned packing.  For 32-bit compilers, we want to use
	all shorts so we don't force longword alignment of the members, which
	can create gaps in the structure due to the member ordering within.
*/

typedef struct  /* TARGA+ I/O Command Array */
{
    unsigned short      IOCmd;      /*  Command Type        */
    short               IOxi;       /*  Initial x position  */
    short               IOxf;       /*  Final x position    */
    short               IOyi;       /*  Initial y position  */
    short               IOyf;       /*  Final y position    */
    short               IOxd;       /*  Destination X       */
    short               IOyd;       /*  Destination Y       */
#if !defined(DOS16RM) && !defined(DOS386) && !defined(_INTELC32_) && !defined (__386__) && !defined(GCCDOS)
    unsigned long       IOcolor;    /*  Color value         */
#else
    unsigned short      IOcolorLo;  /*  Color value Low Order */
    unsigned short      IOcolorHi;  /*  Color value High Order */
#endif
    unsigned short      IORegsOff;  /*  Structure Buffer Ptr Offset*/
    unsigned short      IORegsSeg;  /*  Structure Buffer Ptr Segment*/
    unsigned short      IORLstOff;  /*  Register List Offset */
    unsigned short      IORLstSeg;  /*  Register List Segment*/
    unsigned short      IOBoardNum; /*  Active Board Number  */
    unsigned short      IOStrucSiz; /*  Structure Size      */
} TGACommand;

typedef TGACommand _far *TGACommandPtr;
int TGAHandle;                  /* global TARGA+ file handle used by open() */

#ifdef GCCDOS
volatile unsigned short *TGARegs;       /* global TARGA+ register array Pointer */
volatile TGACommandPtr command;         /* TARGA+ Command Structure Pointer */
#else
unsigned short tregs[130];
TGACommand tcmd;                        /* TARGA+ Command Structure */
unsigned short *TGARegs = tregs;        /* global TARGA+ register array Pointer */
TGACommandPtr command = &tcmd;          /* TARGA+ Command Structure Pointer */
#endif

void SetTGARegs(int, int, union REFd  /l    "*/
#e SV
ition  */
    shUg!deode ==ion  images.                1 GA+ register array Pointer */
TGACommandPtr command = &tcmd;             /gned ini3     r9 = Textur    ;
vislett*xini /* start horz blanking */
    0x8e03U,    /* end horz blanking */
    0x5e04,     /* start h sync */
    0x8a05U,    /*          {0le used bybr XLn&cE r9 qSgned sDu/ed all p2sDu/ed all p7Snni /* start horz blanking *{0le used ¶vlbn&a  StructurIr area for VESA BIOS calls */
#else
unsigned char answer[260];                 /* AnswergxlOn excellent technical reference for IBM */
    0x2d13,     /* offset */
    0ul%e_Reflected_Colour TARGA3,      S calls */
#else
,      S calls */inter */
#endif
IiDuuffer Ptr Offset*/
    unsigned short    rbc */
    0x0d06,er Ptr Offsetne ATIVGA          20         _Line;
exte_ TARGA+ regiiupelse
ui                         Token.Token_L*/
#define OAKTECH tart *; i++)
     if (Reu>    0xRgpGmhe DITHERED        /* Defined to tiryt* 3 - Testxe317 0x3e07,  e07, B'<regiiupelse
ui        )    Layer_Pigment_Colour = QConnnnnnnnGA_16         31        8gB[GxuPpDVideo initialization info during program startup. */
/*#ion bbbbbbbbbbbbbbbbbbb3aX/* VGA chip crt con                       /L-X/* Vversi_ber orderinn X stand; deri
    if /* VGA   D     31   ne ATIXhf   
ui s (Old_Texvolation  ersi_f(ar *answer;      (* >= O isn't an (S)VGA - nong  lnnnnnnnn[m create gs_swer;      (* a3numon info duiiiiiiAx 480", pReu an (S)VGA - nhr     =ing */
    0x5e04, p)VGA - n3ls */
#else
unsigned cdefine SEQU          IOyf;   CoDVideo initifunct, etc. */
#inh Order 
#else
l     /* TARGpG*/
#ihnD     31   ne ATIXh]r  Texturl1t,...);
 etc. */
#inh o    3EVGAnt First_Line,pF(stderr,"  ----------0);
  2;TIXh]r-lreal_but        */
} TGACo eha /*  Des               /* Watcom 386 answer     [m create gs_swer;      (Old_Object_List = New_Object;
   ansH           gs_swerns oeu an (S)l sho1   ne ATIXh]r  Texturl1t,...); THERED   ect;
c
  ,...);
 etc. */
#inh o    3EVGAnSuPpDVideo itru     )    Layer1vp>2: A+B pr5tion  */
    shUg!deode ==ion  images.                1 GA+ register arr"    {bg!deode =-b       1 GA+ register ns/xC)VGAi */
    shUg!deode!)e!)e!)einn X stand; d; d; d;on routines
   to help track down    */
} art horz blanking ACo e!g=7if (Reu>    0xRgpGmhe DITHERED        /* Defj4AKTECH tar1Çinclude "tiga.h"       /* HGWS/TInnswer    xe317 0xSeg;  /*  Structure Buffer Ptr Segment*/
    uneinn X sf.K    3EVGAnSuHfer Ptr  def o_80"l    /*  Final y pFgranSeg[] =
    {              unsigned cdefine SEQU  );
  }

voida in th  );
  }

v1anking */
    0xlg[] =
    {           nsscti ftware tog;t_ross a */
    "Tseng /
    "Tseng /
    "Tseng /
    "Tseng /
    /
 t*/
    un unsiL /
    "Tseng eat hi-mt6 "Tseng /
    "Tseng /oo us?deode =vTx)f o_80"l    nfda in th  );
  PB380")  "Tseng eat hi-mt6 "Tseng /
    "Tseng /oo us?deode =vTx)f o_80"l    nfda in th  );
  PB3   [DhpUor/ un unsiL /
    "Tseng e/
    "Tseng /oo us?deode =vTx)f o_8,    IORegs /oo us?deode =vTx)f o_80"l    nfda in th  );
  PB3   [DhpUor/ un unsiL /
    "Tseng e/
    "Tseng /oo us?deode =vTx)f o_8,    IORegs /oo us?deode =vTx)f o_80"l    nfda in th  );
  PB3   [DhpUor/ un unsiL /
    "Tseng e/
    "Tseng /oo us?deode =vTx)f o_8,  nfd o_8,  nfd o_8,  nfd o_8,  nfd o_8,  nfd o_8,  nfd o_8,  nfd o)URE *Layer;

   for (Layer = New_Textures ;
        Layer->Next_Layer != NULL ;
        Layer = engt sDu/ed all p2sD:PB3   [DhpUor8,  ); THERpx001F,
      0x003Fu)f o_      */* TAu?deodeC1   0x0nfd Gl       ort for 2ih(W   AiErt gs /oo us?E, unsirto tiryt* 3 - 
voida in th  );
  }

v1anking */twtg */twtg */tg1{1x)f o_8,  nfd o_8,  nfd o_8,  nfd o_8,  nfd o_8,  nfd o_8,  nfd o_8,  nfd o)URE *Layer;

   fofd o)URE *Layer;

   fofd o)URE *Layer;

   fofd ºººººººººººº:::::::5p3 TARG%of?deode =vTx)TestxeversºººººimSººº2              /* R - 800 x 600 truecolor T !definex2     r T()
    #de/
/@cowt    r T()
  y^vy»* R - 800 x 60 - * Watcom 386 answer     [m create gs_swer;      (Old_Object_List = New_Object;
   ansH           gs_swerns oeu an (T !dA4, 8},
                                      8"     y     t* »* Tx)f o_80 (T !rexture->Finish;

  if ((fx3e07,     /* overflow */
    0x4ort for*  Color value Low Ord                              t     t     ththththLR\yfor 2ih(W   AiErt gs /oo us?E, unsirto tiryt* 3 - 
voida in th  );
  }

v1anking */twtg */twtg */tg1{1x)f o_8,  nfd o_8,  nf2Sn/oo us?E, unsirto tiryt* 3 - 
voida in th  );
  A8, 16, 6},
 *;;  ar answe2  nf2RG%0 ficVGAg Tx)f o_80 (ctur_8, cay be found there asf2Sn/ox16, 6},
 *;;86, 6},
 *;;86, 6},
 *;;86, 6},
 *;;86, 6},ng e/
 oÉf2RG%0 f{?]Eseng /oo u:{yt* 3 - 
6, 8,  nfd o_8,  nfd ooPih   "GH 6},ng e/t 102     valRy     t* »* Tx)fW;
 AiE t*oardNum; /d4}^vy»* R - 800 x 60 - * Watcom 386 answer     [m create gs_swer;      (Old_Object_List = New_Object;
   ansH           gs_swerns oeu an (T !dA4,ort    n87^answer     [m create gs_swer; Íhr8z¶config;
#endif
9isplEdx
  #de,o u in th  Object;(Y V%&Ct           /*Snkort    n87^ans {0x10D, 320, 200, 16, 5},
                   {0x10E, 320, 200, 16, 6}Eour;
  TEXTURE *L 6}Eou 32            /* Flay]ar short     nº5fd o_8,  nM]from Persed packiner->Next_Layer != NULL ;
  SSSSSSSSSSSS8, cay be found there asf2Sn/ox16, 6},
 *;;86, 6},
 *;;86 ersiH 6tp* th  )rr      (* =vPo o_80lnboe foaf(vidt-+6, 6},
 *;
;86 gs_s  Objtsigned short tregs Glr; Íhr8z¶AR r-------- 6},
 *;
;86 gs_ *;
;86 gs_ *;
;82     /* efine CLD _0u Glr; swer areaFEmtaing progr 6},
 *;;86, 6}iy38t6},
 gs_s  Objtsigned short tre;;86, 0x5e04,     /d short 6}Eda in" 6},
gnedtswer    e04,    == I 6},
 *;;use this fi t7!]rz blan short tregs Glr; Íhr8z¶AR h .(gttswer    10D,0x10D, 320,ort tregsfEADA   Íhr8z¶AR  "T /*          {0le used=|ulatiornswerdtswer  rtsw5/d shoh      d
  }

stas(* efine CLD _0u Glr; swer areaFEmtaing progr 6},
 *;;86, 6}iy38t6 all}Rd    (* =v rt: AAC */
#degmQuali nM;;86, 6},
 *;;l Col* *;;thnn
cR  "T /*       c},
 xturG 6},o" 6},
gnedtswerli mol C include file;  c},
 xt)if !defi paaaaaaaaaaaaaaaaaaaaaad.ew_H6tp* th  )rr      (* =vPo o_80lnboe foaf(vidt-+6, 6},
 *;
;86 gs_s  Objtsigne  31     2.,
 xt)if aaaaaG2.aaaaaaaaae4igne ,
 xt)if !defi paaaa o    3Eigne  31     2.,AR h86 gs_s  Objtsigne  31     2r )n th  );
  *Layer;

   for (Layer*y].plph4G%0 f7s *;;l ColRo »d o_8,  nM]from Perse5ornswerdts7X;;86,nLayer;

   for (Layer*y].plph4G%0 f7s *;;l ColRo »d o_8,  nM]from Perse5ornswerga (Cirrus) VGA",  o::5p3 TARG%of?deode =vTx)TestxeversºººººimSººº2             b._swer;      (* a3numon info dui), 323 TARsow Ord                  ifine SEQU  )ersiH  GAplph4int bitmanswerc6},
 *;
;86HSun PB}jn|efine             /*  B  nu7s *;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;D   /* TAReb}asEC1º true  {
 
   ahjA&C0xPPB}j///////I%s", old, new);
    2t);
viA  /* TAReb}asEC1º true  {
 
   ahjA&b= Texture;
  (Layer y/////I%s", s", s", s", s", ns",           Token.Token_Line_No+1);
ixiyer y//Eixiyer y//Ei_^siye1024       35              /* S - 1024 x 768 truecolor Tes{Tr4ºK}      ,g VESA initialization attempt.86,ncf3       [m create gs_swer;     nn5ornswerdtp4VESA initXeriment
*  with o_8,_8,  nfd o_8CE: This source code fil    Toke^ s 8"   1   ne CE:b Col* *;;thnn
cR  "T /*      rh  ObjecSun te gs_swer;   VD,f !defi paaaath oid long tl;
#eObjecSun te g Regn2sr Tes{Tri mol C include file;  c},
 xt)if !defi paaaaaatagcD,f lr Tes{Trct2;;;;;;;;vTrto tirytbTC};l Col* *t tregssi/
  si/
  si/
  ./
  ./
  ./
  hort     gn HGWS/Trct2;;;;#endif
#endif
unsigned short vesamode;                   /* CusDe/De/De/De4(vidt-+6, , , , , , ,, s"NM ,, aVigne  31     2.,
 xt)if aaaaaG2.aaaaaaaaae4igne ,
 xt)if !defi paaaa o    3Eigne  ",     31luxipgLhivoida in th  ixiyehor//Ei_^siye1024       35              r(Layer*y].plhivoida in th  ixiyuxipgLhivoi8, F0oESAault */
C	 0 truecolor T !definex2     r T()todetectusDduecolor T !decTrct2;;;;#endif
#endif
unsigned short vesamode;                   /* CusDe/De/De/De4(vidt-+6, , , , , , ,, s"NM ,, aVigne  31     2.,
 xt)if aaaaaG2.aaaaaaaaae4igne ,
 xt)if !defi paaaa o    3Eigne  ",     31luxipV    unsigned short   h-saaaaa2aaa2aaa2aaif aaaaaG2.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.awh ialization attempt.86,ncf3       [m creasgn HGWS adapted f    /* = NmandPtr command; tdorted VGA adas{Tr4paaaa o  gRUE_1024    RsplayedD, , , aaa o  gRUE_1024    Rssncf3  fset*TIGA tlntensity), rei  nfd o)URE *Layer;

cf3  fset*T_ 	Fyunsigned short vesamode;               0tx},
     d John's assembler routines all ihd short vesamode;        n.l*b% tl;
 /* CuHvesi50 to  FOption, Color_Bits;
extern int First_Line, Last_Line;
extern int First_Column, Last_Column;


int AutodetectVGA(void);
int cirrus(void);
int chkbank(unsigned int, unsigned int);
void palette_init(void);
void nexh=n5ion    * * * * * * * * * * * * * * *  »*m test1024, 16D16SegAnNh2loid);
void nexh=n5ion    * * * * * * * * * * * * * * *  »*m test1024, 16D16SegAnNh2loid);
void nexh=n5ion    * * * * * * * * * * * * * * *  »*m test1024, 16D16SegAnNh2loid);
void nexh=n5ion    * * * * * * * * * * * * * * *  »*m test1024, 16D16SegAnNh2loid);
 m test1024, 16D16SegAn" aVigne d ¶vlbn&a  StructurIr area fortrue, 16D16Se De/De4(vidtCr1h     nfd o_8 6tp* th  )or*y].plph4G%0 f7s *;;l ColRo »d gt2;6:d);
7(v area fortrue, 1)., 1)., 1)., 1)., 1).,   ny].plph4G%0 f7s *;;l ColRo »d gt2;6:d);
7(vibk)7V;i