1 /** 2 ** libgrx.h ---- GRX library private include file 3 ** 4 ** Copyright (c) 1995 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221 5 ** [e-mail: csaba@vuse.vanderbilt.edu] 6 ** 7 ** This file is part of the GRX graphics library. 8 ** 9 ** The GRX graphics library is free software; you can redistribute it 10 ** and/or modify it under some conditions; see the "copying.grx" file 11 ** for details. 12 ** 13 ** This library is distributed in the hope that it will be useful, 14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 ** 17 **/ 18 19 #ifndef __LIBGRX_H_INCLUDED__ 20 #define __LIBGRX_H_INCLUDED__ 21 22 #define USE_GRX_INTERNAL_DEFINITIONS 23 24 /* The LCC compiler on Linux requires this */ 25 #if defined(__LCC__) && defined(__linux__) 26 /* make alloca work ... */ 27 # define __USE_MISC 28 #endif 29 30 #ifdef _AIX 31 #define _BIG_ENDIAN 32 #endif 33 34 #include <stdlib.h> 35 #include <stdio.h> 36 #include <string.h> 37 38 #ifndef __GRX20_H_INCLUDED__ 39 #include "grx20.h" 40 #endif 41 42 #ifndef NULL 43 #define NULL ((void *)(0)) 44 #endif 45 46 #ifndef FALSE 47 #define FALSE 0 48 #endif 49 50 #ifndef TRUE 51 #define TRUE 1 52 #endif 53 54 /* 55 ** identify the compiler / system 56 ** and check for special restrictions 57 */ 58 /* DEC alpha chips have special alignment 59 ** restrictions. We'll have do care about them */ 60 #if !defined(__alpha__) && defined(__alpha) 61 #define __alpha__ __alpha 62 #endif 63 64 65 /* Casting a lvalue on the left side of an assignment 66 ** causes error or warnings on several compilers: 67 ** 68 ** LCC v4.0 69 ** Watcom C++ v11.0 70 ** SUN cc v4.0 71 ** GCC v > 3 72 */ 73 #if !defined(NO_LEFTSIDE_LVALUE_CAST) && \ 74 ( defined(__LCC__) \ 75 || defined(__WATCOMC__) \ 76 || (defined(__GNUC__) && (__GNUC__>=3)) \ 77 || defined(__SUNPRO_C) ) 78 #define NO_LEFTSIDE_LVALUE_CAST 79 #endif 80 /* Casting a pointer on the left side of an assignment 81 ** also cuses problems on several systems: 82 ** 83 ** LCC v4.0 84 ** Watcom C++ v11.0 85 */ 86 #if !defined(NO_LEFTSIDE_PTR_CAST) && \ 87 ( defined(__LCC__) \ 88 || defined(__WATCOMC__) ) 89 #define NO_LEFTSIDE_PTR_CAST 90 #endif 91 92 /* some CPU allow misaligned access to non byte location */ 93 #if defined(__TURBOC__) \ 94 || defined(_MSC_VER) \ 95 || defined(__386__) \ 96 || defined(__i386__) \ 97 || defined(__i386) \ 98 || defined(__x86_64__) 99 /* x86 can write to misalgined 16bit locations */ 100 # define MISALIGNED_16bit_OK 101 #endif 102 103 #if defined(__386__) \ 104 || defined(__i386__) \ 105 || defined(__i386) \ 106 || defined(__x86_64__) 107 /* x86 can write to misalgined 32bit locations */ 108 # define MISALIGNED_32bit_OK 109 #endif 110 111 112 /* need some n-bit types */ 113 /* char should always be 8bit and short 16bit ... */ 114 #define GR_int8 char 115 #define GR_int16 short 116 #if defined(__alpha__) || (defined(_MIPS_SZLONG) && _MIPS_SZLONG == 64) || defined(__x86_64__) 117 #define GR_int32 int 118 #define GR_int64 long 119 #define GR_PtrInt long 120 #else 121 #define GR_int32 long 122 #define GR_PtrInt int 123 #endif 124 125 /* signed and unsigned variants of the above */ 126 typedef signed GR_int8 GR_int8s; 127 typedef signed GR_int16 GR_int16s; 128 typedef signed GR_int32 GR_int32s; 129 typedef unsigned GR_int8 GR_int8u; 130 typedef unsigned GR_int16 GR_int16u; 131 typedef unsigned GR_int32 GR_int32u; 132 #ifdef GR_int64 133 typedef signed GR_int64 GR_int64s; 134 typedef unsigned GR_int64 GR_int64u; 135 #endif 136 137 138 /* 139 ** get system endian 140 */ 141 #include <machine/endian.h> 142 143 #if 0 144 #if !defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) 145 # if defined(__TURBOC__) \ 146 || defined(__WATCOMC__) \ 147 || defined(_MSC_VER) \ 148 || defined(__alpha__) \ 149 || (defined(__LCC__) && defined(__i386__)) \ 150 || (defined(__GNUC__) && \ 151 (defined(__i386__) || defined(__x86_64__))) 152 # define _LITTLE_ENDIAN 153 # else 154 # include <asm/byteorder.h> 155 # ifdef __LITTLE_ENDIAN 156 # define _LITTLE_ENDIAN 157 # endif 158 # ifdef __BIG_ENDIAN 159 # define _BIG_ENDIAN 160 # endif 161 # endif 162 #endif 163 #endif 164 165 #if 0 166 #if defined(__BYTE_ORDER__) && !defined(BYTE_ORDER) 167 # define BYTE_ORDER __BYTE_ORDER__ 168 # define LITTLE_ENDIAN __LITTLE_ENDIAN__ 169 # define BIG_ENDIAN __BIG_ENDIAN__ 170 #endif 171 #if !defined(BYTE_ORDER) && defined(_LITTLE_ENDIAN) 172 #define LITTLE_ENDIAN 0x1234 173 #define BIG_ENDIAN 0x4321 174 #define BYTE_ORDER LITTLE_ENDIAN 175 #endif 176 #if !defined(BYTE_ORDER) && defined(_BIG_ENDIAN) 177 #define LITTLE_ENDIAN 0x1234 178 #define BIG_ENDIAN 0x4321 179 #define BYTE_ORDER BIG_ENDIAN 180 #endif 181 #ifndef BYTE_ORDER 182 #error Unknown byte ordering ! 183 #endif 184 #endif 185 186 #define BYTE_ORDER _BYTE_ORDER 187 #define LITTLE_ENDIAN _LITTLE_ENDIAN 188 #define BIG_ENDIAN _BIG_ENDIAN 189 190 #ifndef HARDWARE_BYTE_ORDER 191 #define HARDWARE_BYTE_ORDER BYTE_ORDER 192 #endif 193 194 /* 195 * Debug support 196 */ 197 #if defined(DEBUG) && !defined(__GRXDEBUG_H_INCLUDED__) 198 # include "grxdebug.h" 199 #endif 200 #ifndef DBGPRINTF 201 # define DBGPRINTF(chk,x) 202 # define GRX_ENTER() 203 # define GRX_LEAVE() 204 # define GRX_RETURN(x) return x 205 #endif 206 207 /* simple pointer arithmetic */ 208 #define ptrdiff(a,b) ( ((GR_int8 far *)(a)) - ((GR_int8 far *)(b)) ) 209 #define ptradd(P,SKIP) ( (void *)( ((GR_int8 *)(P))+(SKIP)) ) 210 #ifdef NO_LEFTSIDE_LVALUE_CAST 211 #define ptrinc(P,SKIP) do (P) = ptradd((P),(SKIP)); while (0) 212 #else 213 #define ptrinc(P,SKIP) do ((GR_int8 *)(P)) += (SKIP); while (0) 214 #endif 215 216 /* 217 * function inline 218 */ 219 #ifdef __GNUC__ 220 #define INLINE __inline__ 221 #endif 222 #ifndef INLINE 223 #define INLINE 224 #endif 225 226 227 /* 228 * global library data structures 229 */ 230 extern struct _GR_driverInfo _GrDriverInfo; 231 extern struct _GR_contextInfo _GrContextInfo; 232 extern struct _GR_colorInfo _GrColorInfo; 233 extern struct _GR_mouseInfo _GrMouseInfo; 234 235 #define GrDriverInfo (&_GrDriverInfo) 236 #define GrContextInfo (&_GrContextInfo) 237 #define GrColorInfo (&_GrColorInfo) 238 #define GrMouseInfo (&_GrMouseInfo) 239 240 #define DRVINFO (&_GrDriverInfo) 241 #define CXTINFO (&_GrContextInfo) 242 #define CLRINFO (&_GrColorInfo) 243 #define MOUINFO (&_GrMouseInfo) 244 245 #define CURC (&(CXTINFO->current)) 246 #define SCRN (&(CXTINFO->screen)) 247 #define FDRV (&(DRVINFO->fdriver)) 248 #define SDRV (&(DRVINFO->sdriver)) 249 #define VDRV ( (DRVINFO->vdriver)) 250 251 /* 252 * banking stuff 253 */ 254 #ifndef BANKHOOK 255 #define BANKHOOK 256 #endif 257 258 #ifndef RWBANKHOOK 259 #define RWBANKHOOK 260 #endif 261 262 #ifdef __TURBOC__ 263 # define BANKPOS(offs) ((unsigned short)(offs)) 264 # define BANKNUM(offs) (((unsigned short *)(&(offs)))[1]) 265 # define BANKLFT(offs) (_AX = -(int)(BANKPOS(offs)),(_AX ? _AX : 0xffffU)) 266 #endif 267 268 #ifndef BANKPOS 269 #define BANKPOS(offs) ((GR_int16u)(offs)) 270 #endif 271 #ifndef BANKNUM 272 #define BANKNUM(offs) ((int)((GR_int32u)(offs) >> 16)) 273 #endif 274 #ifndef BANKLFT 275 #define BANKLFT(offs) (0x10000 - BANKPOS(offs)) 276 #endif 277 278 #define SETBANK(bk) do { \ 279 register int _bankval_ = (bk); \ 280 DRVINFO->curbank = _bankval_; \ 281 (*DRVINFO->setbank)(_bankval_); \ 282 BANKHOOK; \ 283 } while(0) 284 285 #define SRWBANK(rb,wb) do { \ 286 DRVINFO->curbank = (-1); \ 287 (*DRVINFO->setrwbanks)((rb),(wb)); \ 288 RWBANKHOOK; \ 289 } while(0) 290 291 #define CHKBANK(bk) do { \ 292 register int _bankval_ = (bk); \ 293 if(_bankval_ != DRVINFO->curbank) { \ 294 DRVINFO->curbank = _bankval_; \ 295 (*DRVINFO->setbank)(_bankval_); \ 296 BANKHOOK; \ 297 } \ 298 } while(0) 299 300 /* 301 * color stuff 302 */ 303 extern int _GR_firstFreeColor; /* can't access all colors on all systems */ 304 extern int _GR_lastFreeColor; /* eg. X11 and other windowing systems */ 305 int _GrResetColors(void); /* like GrResetColors but return true on success */ 306 307 #ifdef __TURBOC__ 308 # define C_OPER(color) (unsigned int)(((unsigned char *)(&(color)))[3] & 15) 309 #endif 310 311 #ifndef C_OPER 312 #define C_OPER(color) (unsigned int)(((GrColor)(color) >> 24) & 15) 313 #endif 314 #define C_WRITE (int)(GrWRITE >> 24) 315 #define C_XOR (int)(GrXOR >> 24) 316 #define C_OR (int)(GrOR >> 24) 317 #define C_AND (int)(GrAND >> 24) 318 #define C_IMAGE (int)(GrIMAGE >> 24) 319 #define C_COLOR GrCVALUEMASK 320 321 /* 322 * mouse stuff 323 */ 324 #define mouse_block(c,x1,y1,x2,y2) { \ 325 int __mouse_block_flag = 0; \ 326 mouse_addblock(c,x1,y1,x2,y2); 327 #define mouse_addblock(c,x1,y1,x2,y2) \ 328 if(MOUINFO->docheck && (c)->gc_onscreen) { \ 329 __mouse_block_flag |= (*MOUINFO->block)((c),(x1),(y1),(x2),(y2)); \ 330 } 331 #define mouse_unblock() \ 332 if(__mouse_block_flag) { \ 333 (*MOUINFO->unblock)(__mouse_block_flag); \ 334 } \ 335 } 336 337 /* 338 * internal utility functions 339 */ 340 GrFrameDriver *_GrFindFrameDriver(GrFrameMode mode); 341 GrFrameDriver *_GrFindRAMframeDriver(GrFrameMode mode); 342 343 void _GrCloseVideoDriver(void); 344 void _GrDummyFunction(void); 345 346 347 #endif /* whole file */ 348 349