home *** CD-ROM | disk | FTP | other *** search
/ Monster Disc 2: The Best of 1992 / MONSTER2.ISO / prog / djgpp / cbgrx102.a01 / CONTRIB / LIBGRX / SRC / LIBGRX.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-12  |  22.6 KB  |  653 lines

  1. /**
  2.  ** LIBGRX.H
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifndef _LIBGRX_H_
  25. #define _LIBGRX_H_
  26.  
  27. #ifndef NULL
  28. # define NULL        0
  29. #endif
  30.  
  31. #ifndef TRUE
  32. # define TRUE        1
  33. # define FALSE        0
  34. #endif
  35.  
  36. /*
  37.  * get rid of these stupid keywords (Thanks Intel....)
  38.  */
  39. #if defined(__GNUC__) && !defined(near)
  40. # define near
  41. # define far
  42. # define huge
  43. #endif
  44.  
  45.  
  46. /* ================================================================== */
  47. /*               VERSION SELECTION                  */
  48. /* ================================================================== */
  49.  
  50. /*
  51.  * The GRXPLANES macro selects the version of the library to be compiled.
  52.  * An adapter support is included in the library if its corresponding bit
  53.  * is set:
  54.  *    1:    1 plane (Hercules) version (drivers TBD)
  55.  *    4:    4 plane (EGA VGA 16 color) version
  56.  *    8:    8 plane (VGA 256 color) version
  57.  *     16:     16 plane (VGA w/ HICOLOR DAC) version
  58.  *     32:    8 plane MODE X - like memory organization (drivers TBD)
  59.  *     64:    8 plane IBM 8514A and compatibles
  60.  *    128:    8 plane S3 graphics accelerator
  61.  *                 :
  62.  *                 : (future extensions)
  63.  *                 :
  64.  *    255:      all versions
  65.  *    239:      all versions but the 32K color VGA
  66.  *          etc...
  67.  * Notes:
  68.  *   The 16 plane version can not be compiled using Turbo C.
  69.  *   Selecting a single mode version will result in a slightly smaller and
  70.  *    faster (faster is true especially for the 256 and 32K color VGA modes)
  71.  *    library.
  72.  *   See also the notes about the video drivers needed for this library
  73.  */
  74.  
  75. #define MODE_X        32
  76. #define MODE_8514A    64
  77. #define MODE_S3        128
  78.  
  79. #if (GRXPLANES == 0) || (GRXPLANES == 0xff)
  80. # undef GRXPLANES
  81. #endif
  82.  
  83. #ifndef GRXPLANES
  84. # ifdef __TURBOC__
  85. #   define GRXPLANES    (1 | 4 | 8 | MODE_X | MODE_8514A | MODE_S3)
  86. # endif
  87. # ifdef __GNUC__
  88. #   define GRXPLANES    (1 | 4 | 8 | 16 | MODE_X | MODE_8514A | MODE_S3)
  89. # endif
  90. #endif
  91.  
  92. #if defined(__TURBOC__) && (GRXPLANES & 16)
  93. # error Turbo C does not support the HiColor mode
  94. #endif
  95.  
  96.  
  97. /* ================================================================== */
  98. /*            COMPILATION OPTIONS                  */
  99. /* ================================================================== */
  100.  
  101. /*
  102.  * _MAXVIDPLANESIZE
  103.  *    If set use this value as the maximum size for a bitplane in video RAM.
  104.  *    (Set it to 1M (limit by GO32) in 32-bit mode, to 64K for the 16-bit
  105.  *    versions)
  106.  */
  107.  
  108. #ifdef __TURBOC__
  109. # define _MAXVIDPLANESIZE  0x10000UL
  110. #endif
  111.  
  112. #ifdef __GNUC__
  113. # define _MAXVIDPLANESIZE  0x100000UL
  114. #endif
  115.  
  116. /*
  117.  * _MAXMEMPLANESIZE
  118.  *    If set use this value as the maximum size for a bitplane in memory.
  119.  *    (Not needed in 32-bit mode, set it to somewhat less than 64K for
  120.  *    the 16-bit versions. Max value is 64K - 4*16 because of the way the
  121.  *    offset to the bitplanes is calculated in 16 color modes.)
  122.  */
  123.  
  124. #ifdef __TURBOC__
  125. # define _MAXMEMPLANESIZE  0xffc0UL
  126. #endif
  127.  
  128. /*
  129.  * _INLINE256
  130.  *    If set, then the appropriate 256 color primitives will be
  131.  *    expanded inline. (set pixel, read pixel)
  132.  *    Also changes the method of pixel address calculations:
  133.  *    instead of a packed long containing (x,y) pairs, true
  134.  *    pixel addresses (base + y*xsize + x) will be calculated inline.
  135.  *    This option is only effective when compiling a 256 color
  136.  *    single mode library.
  137.  */
  138. #if (GRXPLANES == 8)
  139. # ifdef __TURBOC__
  140. #   define _INLINE256        /* won't work beyond 320x200 !!! */
  141. # endif
  142. # ifdef __GNUC__
  143. #   define _INLINE256
  144. # endif
  145. #endif
  146.  
  147. /*
  148.  * _INLINE32K
  149.  *    If set, then the appropriate 32K color primitives will be
  150.  *    expanded inline. (set pixel, read pixel)
  151.  *    Also changes the method of pixel address calculations:
  152.  *    instead of a packed long containing (x,y) pairs, true
  153.  *    pixel addresses (base + y*xsize + x) will be calculated inline.
  154.  *    This option is only effective when compiling a 256 color
  155.  *    single mode library.
  156.  */
  157. #if (GRXPLANES == 16)
  158. # ifdef __GNUC__
  159. #   define _INLINE32K
  160. # endif
  161. #endif
  162.  
  163.  
  164. /* ================================================================== */
  165. /*        PACK/UNPACK TWO SHORTS INTO A LONG INTEGER              */
  166. /* ================================================================== */
  167.  
  168. #ifdef __GNUC__
  169. # define _PACK2SHORTS(h,l)    (((h) << 16) | (l))
  170. # define _UPPERWORD(x)        ((int)(((unsigned long)(x)) >> 16))
  171. # define _LOWERWORD(x)        ((int)((unsigned short)(x)))
  172. #endif
  173.  
  174. #ifdef __TURBOC__
  175. # define _PACK2SHORTS(h,l)    ((long)((void _seg *)(h) + (void near *)(l)))
  176. # define _UPPERWORD(x)        ((unsigned int)(void _seg *)(void far *)(x))
  177. # define _LOWERWORD(x)        ((unsigned int)(x))
  178. #endif
  179.  
  180.  
  181. /* ================================================================== */
  182. /*        INTERNALLY USED GLOBAL VARIABLES AND FUNCTIONS          */
  183. /* ================================================================== */
  184.  
  185. extern  GrContext _GrContext;        /* current graphics context */
  186. extern  GrContext _GrVidPage;        /* the whole screen */
  187.  
  188. extern  int  _GrCurrentMode;        /* current video mode */
  189. extern  int  _GrCanBcopyInBlit;        /* separate R/W pages in adapter */
  190. extern  int  _GrBigFrameBuffer;        /* set if frame buffer > 64K */
  191. extern  int  _GrNumColors;        /* number of colors */
  192. extern  int  _GrFreeColors;        /* number of free colors */
  193. extern  int  _GrAdapterType;        /* type of video adapter */
  194. extern  int  _GrDriverIndex;        /* low-level video routine selector */
  195. extern  int  _GrRGBcolorMode;        /* set if VGA DAC inited to RGB mode */
  196. extern  int  _GrRdOnlyOffset;        /* add for read-only video page */
  197. extern  int  _GrWrOnlyOffset;        /* add for write-only video page */
  198.  
  199. extern  int  _GrScreenX;        /* screen width  */
  200. extern  int  _GrScreenY;        /* screen height */
  201.  
  202. extern  char _GrMouseDrawn;        /* set if mouse drawn */
  203. extern  char _GrMouseCheck;        /* set if mouse blocking needed */
  204.  
  205. extern  int  (*_GrMouseBlock)(GrContext *c,int x1,int y1,int x2,int y2);
  206. extern  void (*_GrMouseUnBlock)(void);
  207. extern  void (*_GrMouseUnInit)(void);
  208.  
  209. typedef void (*_GrScanLineProc)(int x1,int x2,int y,void *fillarg);
  210.  
  211. extern  void _GrScanLineFill(int x1,int x2,int y,void *arg);
  212. extern  void _GrScanLinePatternFill(int x1,int x2,int y,void *arg);
  213.  
  214. extern  void _GrScanConvexPoly(int n,int pt[][2],_GrScanLineProc pc,void *ag);
  215. extern  void _GrScanPolygon(int n,int pt[][2],_GrScanLineProc pc,void *ag);
  216.  
  217. extern  int  _GrGenerateEllipse(int pt[][2],int cx,int cy,int rx,int ry);
  218. extern  int  _GrGenerateEllipseArc(int pt[][2],int cx,int cy,int rx,int ry,int start,int end);
  219. #ifdef __TURBOC__
  220. #define MAX_ELLIPSE_PTS 256
  221. #endif
  222. #ifdef __GNUC__
  223. #define MAX_ELLIPSE_PTS 1024
  224. #endif
  225.  
  226.  
  227. /* ================================================================== */
  228. /*               CONTEXT ACCESS MACROS                  */
  229. /* ================================================================== */
  230.  
  231. #define GC            GrContext
  232. #define GV            GrVidRAM
  233.  
  234. #define GCM_INVALID        0
  235. #define GCM_MYMEMORY        1        /* set if my context memory */
  236. #define GCM_MYCONTEXT        2        /* set if my context structure */
  237.  
  238. #define XMAX(c)            ((c)->gc_xmax)
  239. #define YMAX(c)            ((c)->gc_ymax)
  240.  
  241. #define XLO(c)            ((c)->gc_xcliplo)
  242. #define XHI(c)            ((c)->gc_xcliphi)
  243. #define YLO(c)            ((c)->gc_ycliplo)
  244. #define YHI(c)            ((c)->gc_ycliphi)
  245.  
  246. #ifdef _INLINE256
  247. # define BASE_ADDRESS(c)    ((long)((c)->gc_baseaddr))
  248. # define LINE_OFFSET(c)        ((c)->gc_lineoffset)
  249. # define PIX_OFFS(c,x,y)    ((unsigned)(((y) * LINE_OFFSET(c)) + (x)))
  250. # define PIX_ADDR(c,x,y)    ((c)->gc_frameaddr + PIX_OFFS(c,x,y))
  251. # define PIXEL_SIZE        1
  252. #elif defined(_INLINE32K)
  253. # define BASE_ADDRESS(c)    ((long)((c)->gc_baseaddr))
  254. # define LINE_OFFSET(c)        ((c)->gc_lineoffset)
  255. # define PIX_OFFS(c,x,y)    ((unsigned)(((y) * LINE_OFFSET(c)) + ((x) << 1)))
  256. # define PIX_ADDR(c,x,y)    ((c)->gc_frameaddr + PIX_OFFS(c,x,y))
  257. # define PIXEL_SIZE        2
  258. #else
  259. # define BASE_ADDRESS(c)    (0L)
  260. # define LINE_OFFSET(c)        (0x10000L)
  261. # define PIX_OFFS(c,x,y)    _PACK2SHORTS(y,x)
  262. # define PIX_ADDR(c,x,y)    ((c)->gc_frameaddr + PIX_OFFS(c,x,y))
  263. # define COORD_X(coord)        _LOWERWORD(coord)
  264. # define COORD_Y(coord)        _UPPERWORD(coord)
  265. # define PIXEL_SIZE        1
  266. #endif
  267.  
  268.  
  269. /* ================================================================== */
  270. /*            CURRENT CONTEXT ACCESS MACROS              */
  271. /* ================================================================== */
  272.  
  273. #define CURC        (&_GrContext)
  274. #define SCREEN        (&_GrVidPage)
  275.  
  276. #define _GrMaxX        XMAX(CURC)
  277. #define _GrMaxY        YMAX(CURC)
  278. #define _GrSizeX    (_GrMaxX + 1)
  279. #define _GrSizeY    (_GrMaxY + 1)
  280.  
  281. #define _GrLoX        XLO(CURC)
  282. #define _GrLoY        YLO(CURC)
  283. #define _GrHiX        XHI(CURC)
  284. #define _GrHiY        YHI(CURC)
  285.  
  286. #define PIXEL_OFFS(x,y) PIX_OFFS(CURC,x,y)
  287. #define PIXEL_ADDR(x,y) PIX_ADDR(CURC,x,y)
  288.  
  289.  
  290. /* ================================================================== */
  291. /*            COLOR MANIPULATION MACROS                  */
  292. /* ================================================================== */
  293.  
  294. #ifdef __TURBOC__
  295. # define C_SET        0        /* color operation flags (XOR...) */
  296. # define C_XOR        (GrXOR >> 8)
  297. # define C_OR        (GrOR  >> 8)
  298. # define C_AND        (GrAND >> 8)
  299. # define C_COLOR    0xff        /* masks out operation flags */
  300. # define C_SIMPLE(c)    (((c) & 0x300) == 0)
  301. # define C_OPER(c)    (((c) >> 8) & 3)
  302. # define C_OPER2(c)    (((c) >> 7) & 6)
  303. #endif
  304.  
  305. #ifdef __GNUC__
  306. # define C_SET        0        /* color operation flags (XOR...) */
  307. # define C_XOR        (GrXOR >> 16)
  308. # define C_OR        (GrOR  >> 16)
  309. # define C_AND        (GrAND >> 16)
  310. # define C_COLOR    0xffff        /* masks out operation flags */
  311. # define C_SIMPLE(c)    (((c) & 0x30000) == 0)
  312. # define C_OPER(c)    (((c) >> 16) & 3)
  313. # define C_OPER2(c)    (((c) >> 15) & 6)
  314. #endif
  315.  
  316. #define  C_SET2        0
  317. #define  C_XOR2        (C_XOR << 1)
  318. #define  C_OR2        (C_OR  << 1)
  319. #define  C_AND2        (C_AND << 1)
  320.  
  321.  
  322. /* ================================================================== */
  323. /*             UTILITY MACROS                      */
  324. /* ================================================================== */
  325.  
  326. #define MIN(a,b)    (((a) < (b)) ? (a) : (b))
  327. #define MAX(a,b)    (((a) > (b)) ? (a) : (b))
  328. #define IABS(x)        (((x) < 0) ?  -(x) : (x))
  329.  
  330. /*
  331.  * exchange two integers
  332.  */
  333. #define EXCHG(a,b) do {                            \
  334.     int __temp__ = (a);                            \
  335.     (a) = (b);                                \
  336.     (b) = __temp__;                            \
  337. } while(0)
  338.  
  339. /*
  340.  * sort two values
  341.  */
  342. #define SORT2(a,b) do {                            \
  343.     if((a) > (b)) EXCHG(a,b);                        \
  344. } while(0)
  345.  
  346. /*
  347.  * conditionally remove/restore mouse cursor for drawing primitives
  348.  */
  349. #define MOUSE_FLAG  char _mouse_block_flag_
  350.  
  351. #define MOUSE_BLOCK(cxt,x1,y1,x2,y2) do {                \
  352.     _mouse_block_flag_ = FALSE;                        \
  353.     if(_GrMouseCheck) {                            \
  354.     _mouse_block_flag_ = (*_GrMouseBlock)(cxt,x1,y1,x2,y2);        \
  355.     }                                    \
  356. } while(0);
  357.  
  358. #define MOUSE_UNBLOCK() do {                        \
  359.     if(_mouse_block_flag_) (*_GrMouseUnBlock)();            \
  360. } while(0);
  361.  
  362.  
  363. /* ================================================================== */
  364. /*           MODE-DEPENDENT LOW-LEVEL DRIVER FUNCTIONS          */
  365. /* ================================================================== */
  366.  
  367. /*
  368.  * Share most S3 and 8514A low-level drivers for now. Later the S3 could
  369.  * be optimized by using mixed direct frame buffer access and 8514/A-style
  370.  * programming where appropriate. Example:
  371.  *  _GrPSSetPixel  could be faster using direct access
  372.  *  _GrPSDrawLine  is faster with 8514/A style programming
  373.  */
  374. void _GrP4Init(int memsize);
  375. void _GrPXInit(int memsize);
  376.  
  377. int  _GrP1ReadPixel(GC *cxt,long addr);
  378. int  _GrP4ReadPixel(GC *cxt,long addr);
  379. int  _GrP8ReadPixel(GC *cxt,long addr);
  380. int  _GrPHReadPixel(GC *cxt,long addr);
  381. int  _GrPXReadPixel(GC *cxt,long addr);
  382. int  _GrPIReadPixel(GC *cxt,long addr);
  383. #define _GrPSReadPixel _GrPIReadPixel
  384.  
  385. void _GrP1SetPixel(long addr,int color);
  386. void _GrP4SetPixel(long addr,int color);
  387. void _GrP8SetPixel(long addr,int color);
  388. void _GrPHSetPixel(long addr,int color);
  389. void _GrPXSetPixel(long addr,int color);
  390. void _GrPISetPixel(long addr,int color);
  391. #define _GrPSSetPixel _GrPISetPixel
  392.  
  393. void _GrP1SetPixRow(long addr,int color,int width);
  394. void _GrP4SetPixRow(long addr,int color,int width);
  395. void _GrP8SetPixRow(long addr,int color,int width);
  396. void _GrPHSetPixRow(long addr,int color,int width);
  397. void _GrPXSetPixRow(long addr,int color,int width);
  398. void _GrPISetPixRow(long addr,int color,int width);
  399. #define _GrPSSetPixRow _GrPISetPixRow
  400.  
  401. void _GrP1SetPixColumn(long addr,int color,int height);
  402. void _GrP4SetPixColumn(long addr,int color,int height);
  403. void _GrP8SetPixColumn(long addr,int color,int height);
  404. void _GrPHSetPixColumn(long addr,int color,int height);
  405. void _GrPXSetPixColumn(long addr,int color,int height);
  406. void _GrPISetPixColumn(long addr,int color,int height);
  407. #define _GrPSSetPixColumn _GrPISetPixColumn
  408.  
  409. void _GrP1SetPixBlock(long addr,int color,int w,int h);
  410. void _GrP4SetPixBlock(long addr,int color,int w,int h);
  411. void _GrP8SetPixBlock(long addr,int color,int w,int h);
  412. void _GrPHSetPixBlock(long addr,int color,int w,int h);
  413. void _GrPXSetPixBlock(long addr,int color,int w,int h);
  414. void _GrPISetPixBlock(long addr,int color,int w,int h);
  415. #define _GrPSSetPixBlock _GrPISetPixBlock
  416.  
  417. void _GrP1DrawLine(long addr,int color,int dx,int dy);
  418. void _GrP4DrawLine(long addr,int color,int dx,int dy);
  419. void _GrP8DrawLine(long addr,int color,int dx,int dy);
  420. void _GrPHDrawLine(long addr,int color,int dx,int dy);
  421. void _GrPXDrawLine(long addr,int color,int dx,int dy);
  422. void _GrPIDrawLine(long addr,int color,int dx,int dy);
  423. #define _GrPSDrawLine _GrPIDrawLine
  424.  
  425. void _GrP1DrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
  426. void _GrP4DrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
  427. void _GrP8DrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
  428. void _GrPHDrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
  429. void _GrPXDrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
  430. void _GrPIDrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
  431. void _GrPSDrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
  432.  
  433. void _GrP1PixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
  434. void _GrP4PixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
  435. void _GrP8PixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
  436. void _GrPHPixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
  437. void _GrPXPixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
  438. void _GrPIPixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
  439. #define _GrPSPixCopy _GrPIPixCopy
  440.  
  441. void _GrP1FillPattern(int x,int y,int width,GrPattern *p);
  442. void _GrP4FillPattern(int x,int y,int width,GrPattern *p);
  443. void _GrP8FillPattern(int x,int y,int width,GrPattern *p);
  444. void _GrPHFillPattern(int x,int y,int width,GrPattern *p);
  445. void _GrPXFillPattern(int x,int y,int width,GrPattern *p);
  446. void _GrPIFillPattern(int x,int y,int width,GrPattern *p);
  447. void _GrPSFillPattern(int x,int y,int width,GrPattern *p);
  448.  
  449.  
  450. /* ================================================================== */
  451. /*        SELECT LOW-LEVEL VIDEO ACCESS ROUTINES              */
  452. /* ================================================================== */
  453.  
  454. #if GRXPLANES == 1
  455. # define _GrReadPixel(c,a)        _GrP1ReadPixel(c,a)
  456. # define _GrSetPixel(a,p)        _GrP1SetPixel(a,p)
  457. # define _GrSetPixRow(a,p,w)        _GrP1SetPixRow(a,p,w)
  458. # define _GrSetPixColumn(a,p,h)        _GrP1SetPixColumn(a,p,h)
  459. # define _GrSetPixBlock(a,p,w,h)    _GrP1SetPixBlock(a,p,w,h)
  460. # define _GrDrawLine(a,p,dx,dy)        _GrP1DrawLine(a,p,dx,dy)
  461. # define _GrDrawChar(a,w,h,b,fg,bg)    _GrP1DrawChar(a,w,h,b,fg,bg)
  462. # define _GrPixCopy(d,da,s,sa,w,h,o)    _GrP1PixCopy(d,da,s,sa,w,h,o)
  463. # define _GrFillPattern(x,y,wdt,p)    _GrP1FillPattern(x,y,wdt,p)
  464. # define _SINGLE_MODE_
  465. #endif
  466.  
  467. #if GRXPLANES == 4
  468. # define _GrReadPixel(c,a)        _GrP4ReadPixel(c,a)
  469. # define _GrSetPixel(a,p)        _GrP4SetPixel(a,p)
  470. # define _GrSetPixRow(a,p,w)        _GrP4SetPixRow(a,p,w)
  471. # define _GrSetPixColumn(a,p,h)        _GrP4SetPixColumn(a,p,h)
  472. # define _GrSetPixBlock(a,p,w,h)    _GrP4SetPixBlock(a,p,w,h)
  473. # define _GrDrawLine(a,p,dx,dy)        _GrP4DrawLine(a,p,dx,dy)
  474. # define _GrDrawChar(a,w,h,b,fg,bg)    _GrP4DrawChar(a,w,h,b,fg,bg)
  475. # define _GrPixCopy(d,da,s,sa,w,h,o)    _GrP4PixCopy(d,da,s,sa,w,h,o)
  476. # define _GrFillPattern(x,y,wdt,p)    _GrP4FillPattern(x,y,wdt,p)
  477. # define _SINGLE_MODE_
  478. #endif
  479.  
  480. #if GRXPLANES == 8
  481. # ifdef _INLINE256
  482. #   define _GrReadPixel(c,a)        (*(unsigned char far *)(a))
  483. #   define _GrSetPixel(a,p) do {                    \
  484.     register unsigned char far *_aa_ = (unsigned char far *)(a);    \
  485.     register unsigned int _pp_ = (unsigned int)(p);            \
  486.     switch(C_OPER(_pp_)) {                        \
  487.         case C_XOR: *_aa_ ^= _pp_; break;                \
  488.         case C_OR:  *_aa_ |= _pp_; break;                \
  489.         case C_AND: *_aa_ &= _pp_; break;                \
  490.         default:    *_aa_  = _pp_; break;                \
  491.     }                                \
  492.     } while(0)
  493. # else
  494. #   define _GrReadPixel(c,a)        _GrP8ReadPixel(c,a)
  495. #   define _GrSetPixel(a,p)        _GrP8SetPixel(a,p)
  496. # endif
  497. # define _GrSetPixRow(a,p,w)        _GrP8SetPixRow(a,p,w)
  498. # define _GrSetPixColumn(a,p,h)        _GrP8SetPixColumn(a,p,h)
  499. # define _GrSetPixBlock(a,p,w,h)    _GrP8SetPixBlock(a,p,w,h)
  500. # define _GrDrawLine(a,p,dx,dy)        _GrP8DrawLine(a,p,dx,dy)
  501. # define _GrDrawChar(a,w,h,b,fg,bg)    _GrP8DrawChar(a,w,h,b,fg,bg)
  502. # define _GrPixCopy(d,da,s,sa,w,h,o)    _GrP8PixCopy(d,da,s,sa,w,h,o)
  503. # define _GrFillPattern(x,y,wdt,p)    _GrP8FillPattern(x,y,wdt,p)
  504. # define _SINGLE_MODE_
  505. #endif
  506.  
  507. #if GRXPLANES == 16
  508. # ifdef _INLINE32K
  509. #   define _GrReadPixel(c,a)        (*(unsigned short far *)(a))
  510. #   define _GrSetPixel(a,p) do {                    \
  511.     register unsigned short far *_aa_ = (unsigned short far *)(a);  \
  512.     register unsigned int _pp_ = (unsigned int)(p);            \
  513.     switch(C_OPER(_pp_)) {                        \
  514.         case C_XOR: *_aa_ ^= _pp_; break;                \
  515.         case C_OR:  *_aa_ |= _pp_; break;                \
  516.         case C_AND: *_aa_ &= _pp_; break;                \
  517.         default:    *_aa_  = _pp_; break;                \
  518.     }                                \
  519.     } while(0)
  520. # else
  521. #   define _GrReadPixel(c,a)        _GrPHReadPixel(c,a)
  522. #   define _GrSetPixel(a,p)        _GrPHSetPixel(a,p)
  523. # endif
  524. # define _GrSetPixRow(a,p,w)        _GrPHSetPixRow(a,p,w)
  525. # define _GrSetPixColumn(a,p,h)        _GrPHSetPixColumn(a,p,h)
  526. # define _GrSetPixBlock(a,p,w,h)    _GrPHSetPixBlock(a,p,w,h)
  527. # define _GrDrawLine(a,p,dx,dy)        _GrPHDrawLine(a,p,dx,dy)
  528. # define _GrDrawChar(a,w,h,b,fg,bg)    _GrPHDrawChar(a,w,h,b,fg,bg)
  529. # define _GrPixCopy(d,da,s,sa,w,h,o)    _GrPHPixCopy(d,da,s,sa,w,h,o)
  530. # define _GrFillPattern(x,y,wdt,p)    _GrPHFillPattern(x,y,wdt,p)
  531. # define _SINGLE_MODE_
  532. #endif
  533.  
  534. #if GRXPLANES == MODE_X
  535. # define _GrReadPixel(c,a)        _GrPXReadPixel(c,a)
  536. # define _GrSetPixel(a,p)        _GrPXSetPixel(a,p)
  537. # define _GrSetPixRow(a,p,w)        _GrPXSetPixRow(a,p,w)
  538. # define _GrSetPixColumn(a,p,h)        _GrPXSetPixColumn(a,p,h)
  539. # define _GrSetPixBlock(a,p,w,h)    _GrPXSetPixBlock(a,p,w,h)
  540. # define _GrDrawLine(a,p,dx,dy)        _GrPXDrawLine(a,p,dx,dy)
  541. # define _GrDrawChar(a,w,h,b,fg,bg)    _GrPXDrawChar(a,w,h,b,fg,bg)
  542. # define _GrPixCopy(d,da,s,sa,w,h,o)    _GrPXPixCopy(d,da,s,sa,w,h,o)
  543. # define _GrFillPattern(x,y,wdt,p)    _GrPXFillPattern(x,y,wdt,p)
  544. # define _SINGLE_MODE_
  545. #endif
  546.  
  547. #if GRXPLANES == MODE_8514A
  548. # define _GrReadPixel(c,a)        _GrPIReadPixel(c,a)
  549. # define _GrSetPixel(a,p)        _GrPISetPixel(a,p)
  550. # define _GrSetPixRow(a,p,w)        _GrPISetPixRow(a,p,w)
  551. # define _GrSetPixColumn(a,p,h)        _GrPISetPixColumn(a,p,h)
  552. # define _GrSetPixBlock(a,p,w,h)    _GrPISetPixBlock(a,p,w,h)
  553. # define _GrDrawLine(a,p,dx,dy)        _GrPIDrawLine(a,p,dx,dy)
  554. # define _GrDrawChar(a,w,h,b,fg,bg)    _GrPIDrawChar(a,w,h,b,fg,bg)
  555. # define _GrPixCopy(d,da,s,sa,w,h,o)    _GrPIPixCopy(d,da,s,sa,w,h,o)
  556. # define _GrFillPattern(x,y,wdt,p)    _GrPIFillPattern(x,y,wdt,p)
  557. # define _SINGLE_MODE_
  558. #endif
  559.  
  560. #if GRXPLANES == MODE_S3
  561. # define _GrReadPixel(c,a)        _GrPSReadPixel(c,a)
  562. # define _GrSetPixel(a,p)        _GrPSSetPixel(a,p)
  563. # define _GrSetPixRow(a,p,w)        _GrPSSetPixRow(a,p,w)
  564. # define _GrSetPixColumn(a,p,h)        _GrPSSetPixColumn(a,p,h)
  565. # define _GrSetPixBlock(a,p,w,h)    _GrPSSetPixBlock(a,p,w,h)
  566. # define _GrDrawLine(a,p,dx,dy)        _GrPSDrawLine(a,p,dx,dy)
  567. # define _GrDrawChar(a,w,h,b,fg,bg)    _GrPSDrawChar(a,w,h,b,fg,bg)
  568. # define _GrPixCopy(d,da,s,sa,w,h,o)    _GrPSPixCopy(d,da,s,sa,w,h,o)
  569. # define _GrFillPattern(x,y,wdt,p)    _GrPSFillPattern(x,y,wdt,p)
  570. # define _SINGLE_MODE_
  571. #endif
  572.  
  573. #define ReadPixelIndex        0
  574. #define SetPixelIndex        1
  575. #define SetPixRowIndex        2
  576. #define SetPixColumnIndex    3
  577. #define SetPixBlockIndex    4
  578. #define DrawLineIndex        5
  579. #define DrawCharIndex        6
  580. #define PixCopyIndex        7
  581. #define FillPatternIndex    8
  582.  
  583. #define NumOfHandlers        9
  584. typedef void (*handler)(void);
  585.  
  586. #ifndef _SINGLE_MODE_
  587.   extern int  (*_GrReadPixel)(GC *,long);
  588.   extern void (*_GrSetPixel)(long,int);
  589.   extern void (*_GrSetPixRow)(long,int,int);
  590.   extern void (*_GrSetPixColumn)(long,int,int);
  591.   extern void (*_GrSetPixBlock)(long,int,int,int);
  592.   extern void (*_GrDrawLine)(long,int,int,int);
  593.   extern void (*_GrDrawChar)(long,int,int,char far *,int,int);
  594.   extern void (*_GrPixCopy)(GC *,long,GC *,long,int,int,int);
  595.   extern void (*_GrFillPattern)(int,int,int,GrPattern *);
  596.   extern handler  _GrResetValues[];
  597.   extern handler *_GrResetAddresses[];
  598. #endif
  599.  
  600. #if (GRXPLANES & 1) && defined(WANT_TO_INCLUDE_INCOMPLETE_MODES)
  601. # define USE_DRIVER_1(func)    func
  602. #else
  603. # define USE_DRIVER_1(func)    _GrVoidDriver
  604. #endif
  605.  
  606. #if (GRXPLANES & 4)
  607. # define USE_DRIVER_4(func)    func
  608. #else
  609. # define USE_DRIVER_4(func)    _GrVoidDriver
  610. #endif
  611.  
  612. #if (GRXPLANES & 8)
  613. # define USE_DRIVER_8(func)    func
  614. #else
  615. # define USE_DRIVER_8(func)    _GrVoidDriver
  616. #endif
  617.  
  618. #if (GRXPLANES & 16)
  619. # define USE_DRIVER_H(func)    func
  620. #else
  621. # define USE_DRIVER_H(func)    _GrVoidDriver
  622. #endif
  623.  
  624. #if (GRXPLANES & MODE_X) && defined(WANT_TO_INCLUDE_INCOMPLETE_MODES)
  625. # define USE_DRIVER_X(func)    func
  626. #else
  627. # define USE_DRIVER_X(func)    _GrVoidDriver
  628. #endif
  629.  
  630. #if (GRXPLANES & MODE_8514A)
  631. # define USE_DRIVER_I(func)    func
  632. #else
  633. # define USE_DRIVER_I(func)    _GrVoidDriver
  634. #endif
  635.  
  636. #if (GRXPLANES & MODE_S3)
  637. # define USE_DRIVER_S(func)    func
  638. #else
  639. # define USE_DRIVER_S(func)    _GrVoidDriver
  640. #endif
  641.  
  642. #define HERC_DRIVER        1
  643. #define VGA16_DRIVER        2
  644. #define VGA256_DRIVER        3
  645. #define VGA32K_DRIVER        4
  646. #define MODE_X_DRIVER        5
  647. #define IBM_8514A_DRIVER    6
  648. #define S3_DRIVER        7
  649.  
  650.  
  651. #endif /* whole file */
  652.  
  653.