home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware 1 2 the Maxx
/
sw_1.zip
/
sw_1
/
PROGRAM
/
CBGRX100.ZIP
/
CONTRIB
/
LIBGRX
/
SRC
/
LIBGRX.H
< prev
next >
Wrap
Text File
|
1992-04-10
|
20KB
|
572 lines
/**
** LIBGRX.H
**
** Copyright (C) 1992, Csaba Biegl
** 820 Stirrup Dr, Nashville, TN, 37221
** csaba@vuse.vanderbilt.edu
**
** This file is distributed under the terms listed in the document
** "copying.cb", available from the author at the address above.
** A copy of "copying.cb" should accompany this file; if not, a copy
** should be available from where this file was obtained. This file
** may not be distributed without a verbatim copy of "copying.cb".
** You should also have received a copy of the GNU General Public
** License along with this program (it is in the file "copying");
** if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
** Cambridge, MA 02139, USA.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**/
#ifndef _LIBGRX_H_
#define _LIBGRX_H_
#ifndef NULL
# define NULL 0
#endif
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
/*
* get rid of these stupid keywords (Thanks Intel....)
*/
#if defined(__GNUC__) && !defined(near)
# define near
# define far
# define huge
#endif
/* ================================================================== */
/* VERSION SELECTION */
/* ================================================================== */
/*
* The GRXPLANES macro selects the version of the library to be compiled.
* An adapter support is included in the library if its corresponding bit
* is set:
* 1: 1 plane (Hercules) version (drivers TBD)
* 4: 4 plane (EGA VGA 16 color) version
* 8: 8 plane (VGA 256 color) version
* 16: 16 plane (VGA w/ HICOLOR DAC) version (drivers TBD)
* 32: 8 plane MODE X - like memory organization (drivers TBD)
* :
* : (future extensions)
* :
* 255: all versions
* 239: all versions but the 32K color VGA
* etc...
* Notes:
* The 16 plane version can not be compiled using Turbo C.
* Selecting a single mode version will result in a slightly smaller and
* faster (faster is true especially for the 256 and 32K color VGA modes)
* library.
* See also the notes about the video drivers needed for this library
*/
#define MODE_X 32
#if (GRXPLANES == 0) || (GRXPLANES == 0xff)
# undef GRXPLANES
#endif
#ifndef GRXPLANES
# ifdef __TURBOC__
# define GRXPLANES (1 | 4 | 8 | MODE_X) /* no 16 bit mode */
# endif
# ifdef __GNUC__
# define GRXPLANES (1 | 4 | 8 | 16 | MODE_X) /* all modes */
# endif
#endif
#if defined(__TURBOC__) && (GRXPLANES & 16)
# error Turbo C does not support the HiColor mode
#endif
/* ================================================================== */
/* COMPILATION OPTIONS */
/* ================================================================== */
/*
* _MAXVIDPLANESIZE
* If set use this value as the maximum size for a bitplane in video RAM.
* (Set it to 1M (limit by GO32) in 32-bit mode, to 64K for the 16-bit
* versions)
*/
#ifdef __TURBOC__
# define _MAXVIDPLANESIZE 0x10000UL
#endif
#ifdef __GNUC__
# define _MAXVIDPLANESIZE 0x100000UL
#endif
/*
* _MAXMEMPLANESIZE
* If set use this value as the maximum size for a bitplane in memory.
* (Not needed in 32-bit mode, set it to somewhat less than 64K for
* the 16-bit versions. Max value is 64K - 4*16 because of the way the
* offset to the bitplanes is calculated in 16 color modes.)
*/
#ifdef __TURBOC__
# define _MAXMEMPLANESIZE 0xffc0UL
#endif
/*
* _INLINE256
* If set, then the appropriate 256 color primitives will be
* expanded inline. (set pixel, read pixel)
* Also changes the method of pixel address calculations:
* instead of a packed long containing (x,y) pairs, true
* pixel addresses (base + y*xsize + x) will be calculated inline.
* This option is only effective when compiling a 256 color
* single mode library.
*/
#if (GRXPLANES == 8)
# ifdef __TURBOC__
# define _INLINE256 /* won't work beyond 320x200 !!! */
# endif
# ifdef __GNUC__
# define _INLINE256
# endif
#endif
/*
* _INLINE32K
* If set, then the appropriate 32K color primitives will be
* expanded inline. (set pixel, read pixel)
* Also changes the method of pixel address calculations:
* instead of a packed long containing (x,y) pairs, true
* pixel addresses (base + y*xsize + x) will be calculated inline.
* This option is only effective when compiling a 256 color
* single mode library.
*/
#if (GRXPLANES == 16)
# ifdef __GNUC__
# define _INLINE32K
# endif
#endif
/* ================================================================== */
/* PACK/UNPACK TWO SHORTS INTO A LONG INTEGER */
/* ================================================================== */
#ifdef __GNUC__
# define _PACK2SHORTS(h,l) (((h) << 16) | (l))
# define _UPPERWORD(x) ((int)(((unsigned long)(x)) >> 16))
# define _LOWERWORD(x) ((int)((unsigned short)(x)))
#endif
#ifdef __TURBOC__
# define _PACK2SHORTS(h,l) ((long)((void _seg *)(h) + (void near *)(l)))
# define _UPPERWORD(x) ((unsigned int)(void _seg *)(void far *)(x))
# define _LOWERWORD(x) ((unsigned int)(x))
#endif
/* ================================================================== */
/* INTERNALLY USED GLOBAL VARIABLES AND FUNCTIONS */
/* ================================================================== */
extern GrContext _GrContext; /* current graphics context */
extern GrContext _GrVidPage; /* the whole screen */
extern int _GrCurrentMode; /* current video mode */
extern int _GrCanBcopyInBlit; /* separate R/W pages in adapter */
extern int _GrBigFrameBuffer; /* set if frame buffer > 64K */
extern int _GrNumColors; /* number of colors */
extern int _GrFreeColors; /* number of free colors */
extern int _GrAdapterType; /* type of video adapter */
extern int _GrDriverIndex; /* low-level video routine selector */
extern int _GrRGBcolorMode; /* set if VGA DAC inited to RGB mode */
extern int _GrRdOnlyOffset; /* add for read-only video page */
extern int _GrWrOnlyOffset; /* add for write-only video page */
extern int _GrScreenX; /* screen width */
extern int _GrScreenY; /* screen height */
extern char _GrMouseDrawn; /* set if mouse drawn */
extern char _GrMouseCheck; /* set if mouse blocking needed */
extern int (*_GrMouseBlock)(GrContext *c,int x1,int y1,int x2,int y2);
extern void (*_GrMouseUnBlock)(void);
extern void (*_GrMouseUnInit)(void);
typedef void (*_GrScanLineProc)(int x1,int x2,int y,void *fillarg);
extern void _GrScanConvexPoly(int n,int pt[][2],_GrScanLineProc pc,void *ag);
/* ================================================================== */
/* CONTEXT ACCESS MACROS */
/* ================================================================== */
#define GC GrContext
#define GV GrVidRAM
#define GCM_INVALID 0
#define GCM_MYMEMORY 1 /* set if my context memory */
#define GCM_MYCONTEXT 2 /* set if my context structure */
#define XMAX(c) ((c)->gc_xmax)
#define YMAX(c) ((c)->gc_ymax)
#define XLO(c) ((c)->gc_xcliplo)
#define XHI(c) ((c)->gc_xcliphi)
#define YLO(c) ((c)->gc_ycliplo)
#define YHI(c) ((c)->gc_ycliphi)
#ifdef _INLINE256
# define BASE_ADDRESS(c) ((long)((c)->gc_baseaddr))
# define LINE_OFFSET(c) ((c)->gc_lineoffset)
# define PIX_OFFS(c,x,y) ((unsigned)(((y) * LINE_OFFSET(c)) + (x)))
# define PIX_ADDR(c,x,y) ((c)->gc_frameaddr + PIX_OFFS(c,x,y))
# define PIXEL_SIZE 1
#elif defined(_INLINE32K)
# define BASE_ADDRESS(c) ((long)((c)->gc_baseaddr))
# define LINE_OFFSET(c) ((c)->gc_lineoffset)
# define PIX_OFFS(c,x,y) ((unsigned)(((y) * LINE_OFFSET(c)) + ((x) << 1)))
# define PIX_ADDR(c,x,y) ((c)->gc_frameaddr + PIX_OFFS(c,x,y))
# define PIXEL_SIZE 2
#else
# define BASE_ADDRESS(c) (0L)
# define LINE_OFFSET(c) (0x10000L)
# define PIX_OFFS(c,x,y) _PACK2SHORTS(y,x)
# define PIX_ADDR(c,x,y) ((c)->gc_frameaddr + PIX_OFFS(c,x,y))
# define COORD_X(coord) _LOWERWORD(coord)
# define COORD_Y(coord) _UPPERWORD(coord)
# define PIXEL_SIZE 1
#endif
/* ================================================================== */
/* CURRENT CONTEXT ACCESS MACROS */
/* ================================================================== */
#define CURC (&_GrContext)
#define SCREEN (&_GrVidPage)
#define _GrMaxX XMAX(CURC)
#define _GrMaxY YMAX(CURC)
#define _GrSizeX (_GrMaxX + 1)
#define _GrSizeY (_GrMaxY + 1)
#define _GrLoX XLO(CURC)
#define _GrLoY YLO(CURC)
#define _GrHiX XHI(CURC)
#define _GrHiY YHI(CURC)
#define PIXEL_OFFS(x,y) PIX_OFFS(CURC,x,y)
#define PIXEL_ADDR(x,y) PIX_ADDR(CURC,x,y)
/* ================================================================== */
/* COLOR MANIPULATION MACROS */
/* ================================================================== */
#ifdef __TURBOC__
# define C_SET 0 /* color operation flags (XOR...) */
# define C_XOR (GrXOR >> 8)
# define C_OR (GrOR >> 8)
# define C_AND (GrAND >> 8)
# define C_COLOR 0xff /* masks out operation flags */
# define C_SIMPLE(c) (((c) & 0x300) == 0)
# define C_OPER(c) (((c) >> 8) & 3)
# define C_OPER2(c) (((c) >> 7) & 6)
#endif
#ifdef __GNUC__
# define C_SET 0 /* color operation flags (XOR...) */
# define C_XOR (GrXOR >> 16)
# define C_OR (GrOR >> 16)
# define C_AND (GrAND >> 16)
# define C_COLOR 0xffff /* masks out operation flags */
# define C_SIMPLE(c) (((c) & 0x30000) == 0)
# define C_OPER(c) (((c) >> 16) & 3)
# define C_OPER2(c) (((c) >> 15) & 6)
#endif
#define C_SET2 0
#define C_XOR2 (C_XOR << 1)
#define C_OR2 (C_OR << 1)
#define C_AND2 (C_AND << 1)
/* ================================================================== */
/* UTILITY MACROS */
/* ================================================================== */
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define IABS(x) (((x) < 0) ? -(x) : (x))
/*
* exchange two integers
*/
#define EXCHG(a,b) do { \
int __temp__ = (a); \
(a) = (b); \
(b) = __temp__; \
} while(0)
/*
* sort two values
*/
#define SORT2(a,b) do { \
if((a) > (b)) EXCHG(a,b); \
} while(0)
/*
* conditionally remove/restore mouse cursor for drawing primitives
*/
#define MOUSE_FLAG char _mouse_block_flag_
#define MOUSE_BLOCK(cxt,x1,y1,x2,y2) do { \
_mouse_block_flag_ = FALSE; \
if(_GrMouseCheck) { \
_mouse_block_flag_ = (*_GrMouseBlock)(cxt,x1,y1,x2,y2); \
} \
} while(0);
#define MOUSE_UNBLOCK() do { \
if(_mouse_block_flag_) (*_GrMouseUnBlock)(); \
} while(0);
/* ================================================================== */
/* MODE-DEPENDENT LOW-LEVEL DRIVER FUNCTIONS */
/* ================================================================== */
void _GrP4Init(int memsize);
void _GrPXInit(int memsize);
int _GrP1ReadPixel(long addr);
int _GrP4ReadPixel(long addr);
int _GrP8ReadPixel(long addr);
int _GrPHReadPixel(long addr);
int _GrPXReadPixel(long addr);
void _GrP1SetPixel(long addr,int color);
void _GrP4SetPixel(long addr,int color);
void _GrP8SetPixel(long addr,int color);
void _GrPHSetPixel(long addr,int color);
void _GrPXSetPixel(long addr,int color);
void _GrP1SetPixRow(long addr,int color,int width);
void _GrP4SetPixRow(long addr,int color,int width);
void _GrP8SetPixRow(long addr,int color,int width);
void _GrPHSetPixRow(long addr,int color,int width);
void _GrPXSetPixRow(long addr,int color,int width);
void _GrP1SetPixColumn(long addr,int color,int height);
void _GrP4SetPixColumn(long addr,int color,int height);
void _GrP8SetPixColumn(long addr,int color,int height);
void _GrPHSetPixColumn(long addr,int color,int height);
void _GrPXSetPixColumn(long addr,int color,int height);
void _GrP1SetPixBlock(long addr,int color,int w,int h);
void _GrP4SetPixBlock(long addr,int color,int w,int h);
void _GrP8SetPixBlock(long addr,int color,int w,int h);
void _GrPHSetPixBlock(long addr,int color,int w,int h);
void _GrPXSetPixBlock(long addr,int color,int w,int h);
void _GrP1DrawLine(long addr,int color,int dx,int dy);
void _GrP4DrawLine(long addr,int color,int dx,int dy);
void _GrP8DrawLine(long addr,int color,int dx,int dy);
void _GrPHDrawLine(long addr,int color,int dx,int dy);
void _GrPXDrawLine(long addr,int color,int dx,int dy);
void _GrP1DrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
void _GrP4DrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
void _GrP8DrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
void _GrPHDrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
void _GrPXDrawChar(long addr,int w,int h,char far *bits,int fg,int bg);
void _GrP1PixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
void _GrP4PixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
void _GrP8PixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
void _GrPHPixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
void _GrPXPixCopy(GC *dst,long daddr,GC *src,long saddr,int w,int h,int op);
void _GrP1FillPattern(int x,int y,int width,GrPattern *p);
void _GrP4FillPattern(int x,int y,int width,GrPattern *p);
void _GrP8FillPattern(int x,int y,int width,GrPattern *p);
void _GrPHFillPattern(int x,int y,int width,GrPattern *p);
void _GrPXFillPattern(int x,int y,int width,GrPattern *p);
/* ================================================================== */
/* SELECT LOW-LEVEL VIDEO ACCESS ROUTINES */
/* ================================================================== */
#if GRXPLANES == 1
# define _GrReadPixel(a) _GrP1ReadPixel(a)
# define _GrSetPixel(a,p) _GrP1SetPixel(a,p)
# define _GrSetPixRow(a,p,w) _GrP1SetPixRow(a,p,w)
# define _GrSetPixColumn(a,p,h) _GrP1SetPixColumn(a,p,h)
# define _GrSetPixBlock(a,p,w,h) _GrP1SetPixBlock(a,p,w,h)
# define _GrDrawLine(a,p,dx,dy) _GrP1DrawLine(a,p,dx,dy)
# define _GrDrawChar(a,w,h,b,fg,bg) _GrP1DrawChar(a,w,h,b,fg,bg)
# define _GrPixCopy(d,da,s,sa,w,h,o) _GrP1PixCopy(d,da,s,sa,w,h,o)
# define _GrFillPattern(x,y,wdt,p) _GrP1FillPattern(x,y,wdt,p)
# define _SINGLE_MODE_
#endif
#if GRXPLANES == 4
# define _GrReadPixel(a) _GrP4ReadPixel(a)
# define _GrSetPixel(a,p) _GrP4SetPixel(a,p)
# define _GrSetPixRow(a,p,w) _GrP4SetPixRow(a,p,w)
# define _GrSetPixColumn(a,p,h) _GrP4SetPixColumn(a,p,h)
# define _GrSetPixBlock(a,p,w,h) _GrP4SetPixBlock(a,p,w,h)
# define _GrDrawLine(a,p,dx,dy) _GrP4DrawLine(a,p,dx,dy)
# define _GrDrawChar(a,w,h,b,fg,bg) _GrP4DrawChar(a,w,h,b,fg,bg)
# define _GrPixCopy(d,da,s,sa,w,h,o) _GrP4PixCopy(d,da,s,sa,w,h,o)
# define _GrFillPattern(x,y,wdt,p) _GrP4FillPattern(x,y,wdt,p)
# define _SINGLE_MODE_
#endif
#if GRXPLANES == 8
# ifdef _INLINE256
# define _GrReadPixel(a) (*(unsigned char far *)(a))
# define _GrSetPixel(a,p) do { \
register unsigned char far *_aa_ = (unsigned char far *)(a); \
register unsigned int _pp_ = (unsigned int)(p); \
switch(C_OPER(_pp_)) { \
case C_XOR: *_aa_ ^= _pp_; break; \
case C_OR: *_aa_ |= _pp_; break; \
case C_AND: *_aa_ &= _pp_; break; \
default: *_aa_ = _pp_; break; \
} \
} while(0)
# else
# define _GrReadPixel(a) _GrP8ReadPixel(a)
# define _GrSetPixel(a,p) _GrP8SetPixel(a,p)
# endif
# define _GrSetPixRow(a,p,w) _GrP8SetPixRow(a,p,w)
# define _GrSetPixColumn(a,p,h) _GrP8SetPixColumn(a,p,h)
# define _GrSetPixBlock(a,p,w,h) _GrP8SetPixBlock(a,p,w,h)
# define _GrDrawLine(a,p,dx,dy) _GrP8DrawLine(a,p,dx,dy)
# define _GrDrawChar(a,w,h,b,fg,bg) _GrP8DrawChar(a,w,h,b,fg,bg)
# define _GrPixCopy(d,da,s,sa,w,h,o) _GrP8PixCopy(d,da,s,sa,w,h,o)
# define _GrFillPattern(x,y,wdt,p) _GrP8FillPattern(x,y,wdt,p)
# define _SINGLE_MODE_
#endif
#if GRXPLANES == 16
# ifdef _INLINE32K
# define _GrReadPixel(a) (*(unsigned short far *)(a))
# define _GrSetPixel(a,p) do { \
register unsigned short far *_aa_ = (unsigned short far *)(a); \
register unsigned int _pp_ = (unsigned int)(p); \
switch(C_OPER(_pp_)) { \
case C_XOR: *_aa_ ^= _pp_; break; \
case C_OR: *_aa_ |= _pp_; break; \
case C_AND: *_aa_ &= _pp_; break; \
default: *_aa_ = _pp_; break; \
} \
} while(0)
# else
# define _GrReadPixel(a) _GrPHReadPixel(a)
# define _GrSetPixel(a,p) _GrPHSetPixel(a,p)
# endif
# define _GrSetPixRow(a,p,w) _GrPHSetPixRow(a,p,w)
# define _GrSetPixColumn(a,p,h) _GrPHSetPixColumn(a,p,h)
# define _GrSetPixBlock(a,p,w,h) _GrPHSetPixBlock(a,p,w,h)
# define _GrDrawLine(a,p,dx,dy) _GrPHDrawLine(a,p,dx,dy)
# define _GrDrawChar(a,w,h,b,fg,bg) _GrPHDrawChar(a,w,h,b,fg,bg)
# define _GrPixCopy(d,da,s,sa,w,h,o) _GrPHPixCopy(d,da,s,sa,w,h,o)
# define _GrFillPattern(x,y,wdt,p) _GrPHFillPattern(x,y,wdt,p)
# define _SINGLE_MODE_
#endif
#if GRXPLANES == MODE_X
# define _GrReadPixel(a) _GrPXReadPixel(a)
# define _GrSetPixel(a,p) _GrPXSetPixel(a,p)
# define _GrSetPixRow(a,p,w) _GrPXSetPixRow(a,p,w)
# define _GrSetPixColumn(a,p,h) _GrPXSetPixColumn(a,p,h)
# define _GrSetPixBlock(a,p,w,h) _GrPXSetPixBlock(a,p,w,h)
# define _GrDrawLine(a,p,dx,dy) _GrPXDrawLine(a,p,dx,dy)
# define _GrDrawChar(a,w,h,b,fg,bg) _GrPXDrawChar(a,w,h,b,fg,bg)
# define _GrPixCopy(d,da,s,sa,w,h,o) _GrPXPixCopy(d,da,s,sa,w,h,o)
# define _GrFillPattern(x,y,wdt,p) _GrPXFillPattern(x,y,wdt,p)
# define _SINGLE_MODE_
#endif
#define ReadPixelIndex 0
#define SetPixelIndex 1
#define SetPixRowIndex 2
#define SetPixColumnIndex 3
#define SetPixBlockIndex 4
#define DrawLineIndex 5
#define DrawCharIndex 6
#define PixCopyIndex 7
#define FillPatternIndex 8
#define NumOfHandlers 9
typedef void (*handler)(void);
#ifndef _SINGLE_MODE_
extern int (*_GrReadPixel)(long);
extern void (*_GrSetPixel)(long,int);
extern void (*_GrSetPixRow)(long,int,int);
extern void (*_GrSetPixColumn)(long,int,int);
extern void (*_GrSetPixBlock)(long,int,int,int);
extern void (*_GrDrawLine)(long,int,int,int);
extern void (*_GrDrawChar)(long,int,int,char far *,int,int);
extern void (*_GrPixCopy)(GC *,long,GC *,long,int,int,int);
extern void (*_GrFillPattern)(int,int,int,GrPattern *);
extern handler _GrResetValues[];
extern handler *_GrResetAddresses[];
#endif
#if (GRXPLANES & 1)
# define USE_DRIVER_1(func) func
#else
# define USE_DRIVER_1(func) _GrVoidDriver
#endif
#if (GRXPLANES & 4)
# define USE_DRIVER_4(func) func
#else
# define USE_DRIVER_4(func) _GrVoidDriver
#endif
#if (GRXPLANES & 8)
# define USE_DRIVER_8(func) func
#else
# define USE_DRIVER_8(func) _GrVoidDriver
#endif
#if (GRXPLANES & 16)
# define USE_DRIVER_H(func) func
#else
# define USE_DRIVER_H(func) _GrVoidDriver
#endif
#if (GRXPLANES & MODE_X)
# define USE_DRIVER_X(func) func
#else
# define USE_DRIVER_X(func) _GrVoidDriver
#endif
#define HERC_DRIVER 1
#define VGA16_DRIVER 2
#define VGA256_DRIVER 3
#define VGA32K_DRIVER 4
#define MODE_X_DRIVER 5
#endif /* whole file */