--- grx.pas.orig	Fri Apr 25 02:10:07 2003
+++ grx.pas	Sun Mar 28 23:15:23 2004
@@ -188,34 +188,35 @@
 
 type
 
+  GrVideoModePtr = ^GrVideoMode;
+
   { The video driver descriptor structure }
   { struct _GR_videoDriver }
+  GrVideoDriverPtr = ^GrVideoDriver;
   GrVideoDriver = record
-    Name      : CString;        { driver name }
-    Adapter   : Char;           { adapter type }
-    Inherit   : ^GrVideoDriver; { inherit video modes from this }
-    Modes     : ^GrVideoMode;   { table of supported modes }
-    NModes    : Integer;        { number of modes }
-    Detect    : Pointer;
-    Init      : Pointer;
-    Reset     : Pointer;
-    SelectMode: Pointer;
-    DrvFlags  : Integer;
+    Name      : CString;           { driver name }
+    Adapter   : Integer;           { adapter type }
+    Inherit   : GrVideoDriverPtr;  { inherit video modes from this }
+    Modes     : GrVideoModePtr;    { table of supported modes }
+    NModes    : Integer;           { number of modes }
+    Detect    : function: Integer;
+    Init      : function (Options: CString): Integer;
+    Reset     : procedure;
+    SelectMode: function (Drv: GrVideoDriverPtr; w, h, BPP, txt: Integer; var ep: Cardinal): GrVideoModePtr;
+    DrvFlags  : Cardinal;
   end;
-  GrVideoDriverPtr = ^GrVideoDriver;
 
   { Video driver mode descriptor structure }
   { struct _GR_videoMode }
   GrVideoMode = record
-    Present     : Char;         { is it really available? }
-    BPP         : Char;       { log2 of # of colors }
-    Width,Height: ShortInt;    { video mode geometry }
+    Present     : ByteBool;         { is it really available? }
+    BPP         : Byte;             { log2 of # of colors }
+    Width,Height: ShortInt;         { video mode geometry }
     Mode        : ShortInt;         { BIOS mode number (if any) }
-    LineOffset  : Integer;         { scan line length }
-    PrivData    : Integer;        { driver can use it for anything }
-    ExtInfo     : ^GrVideoModeExt;   { extra info (maybe shared) }
+    LineOffset  : Integer;          { scan line length }
+    PrivData    : Integer;          { driver can use it for anything }
+    ExtInfo     : ^GrVideoModeExt;  { extra info (maybe shared) }
   end;
-  GrVideoModePtr = ^GrVideoMode;
 
   { Video driver mode descriptor extension structure. This is a separate
     structure accessed via a pointer from the main mode descriptor. The
@@ -223,6 +224,7 @@
     extended info. }
 
   { struct _GR_videoModeExt }
+  Int2 = array [0 .. 1] of Integer;
   GrVideoModeExt = record
     Mode        : Integer;                     { frame driver for this video mode }
     Drv         : ^GrFrameDriver;              { optional frame driver override }
@@ -230,15 +232,26 @@
     CPrec       : array [1 .. 3] of ByteCard;  { color component precisions }
     CPos        : array [1 .. 3] of ByteCard;  { color component bit positions }
     Flags       : Integer;                     { mode flag bits; see "grdriver.h" }
-    Setup       : Pointer;
-    SetVSize    : Pointer;
-    Scroll      : Pointer;
-    SetBank     : Pointer;
-    SetRWBanks  : Pointer;
-    LoadColor   : Pointer;
+    Setup       : function (var md: GrVideoMode; NoClear: Integer): Integer;
+    SetVSize    : function (var md: GrVideoMode; w, h: Integer; var Result: GrVideoMode): Integer;
+    Scroll      : function (var md: GrVideoMode; x, y: Integer; var Result: Int2): Integer;
+    SetBank     : procedure (bk: Integer);
+    SetRWBanks  : procedure (rb, wb: Integer);
+    LoadColor   : procedure (c, r, g, b: Integer);
     LFB_Selector: Integer;
   end;
 
+  GrFrameDriverPtr = ^GrFrameDriver;
+
+  GrFrameType = record
+    gf_BaseAddr  : array [0 .. 3] of MemPtr;  { base address of frame memory }
+    gf_Selector  : ShortInt;                  { frame memory segment selector }
+    gf_OnScreen  : ByteBool;                  { is it in video memory ? }
+    gf_MemFlags  : Byte;                      { memory allocation flags }
+    gf_LineOffset: Integer;                   { offset to next scan line in bytes }
+    gf_Driver    : GrFrameDriverPtr;          { frame access functions }
+  end;
+
   { The frame driver descriptor structure. }
 
   { struct _GR_frameDriver }
@@ -249,46 +262,45 @@
     Row_Align         : Integer; { scan line size alignment }
     Num_Planes        : Integer; { number of planes }
     Bits_Per_Pixel    : Integer; { bits per pixel }
-    Max_Plane_Size    : Integer; { maximum plane size in bytes }
-    Init              : Pointer;
-    ReadPixel         : Pointer;
-    DrawPixel         : Pointer;
-    DrawLine          : Pointer;
-    DrawHLine         : Pointer;
-    DrawVLine         : Pointer;
-    DrawBlock         : Pointer;
-    DrawBitmap        : Pointer;
-    DrawPattern       : Pointer;
-    BitBlt            : Pointer;
-    BltV2R            : Pointer;
-    BltR2V            : Pointer;
-    GetIndexedScanline: Pointer;
-    PutScanLine       : Pointer;
+    Max_Plane_Size    : MedInt;  { maximum plane size in bytes }
+    Init              : function (var md: GrVideoMode): Integer;
+    ReadPixel         : function (var c: GrFrameType; x, y: Integer): GrColor;
+    DrawPixel         : procedure (x, y: Integer; c: GrColor);
+    DrawLine          : procedure (x, y, dx, dy: Integer; c: GrColor);
+    DrawHLine         : procedure (x, y, w: Integer; c: GrColor);
+    DrawVLine         : procedure (x, y, h: Integer; c: GrColor);
+    DrawBlock         : procedure (x, y, w, h: Integer; c: GrColor);
+    DrawBitmap        : procedure (x, y, w, h: Integer; BMP: MemPtr; Pitch, Start: Integer; fg, bg: GrColor);
+    DrawPattern       : procedure (x, y, w: Integer; Patt: Byte; fg, bg: GrColor);
+    BitBlt            : procedure (var Dst: GrFrameType; dx, dy: Integer; var Src: GrFrameType; x, y, w, h: Integer; Op: GrColor);
+    BltV2R            : procedure (var Dst: GrFrameType; dx, dy: Integer; var Src: GrFrameType; x, y, w, h: Integer; Op: GrColor);
+    BltR2V            : procedure (var Dst: GrFrameType; dx, dy: Integer; var Src: GrFrameType; x, y, w, h: Integer; Op: GrColor);
+    GetIndexedScanline: function (var c: GrFrameType; x, y, w: Integer; var Index: Integer): GrColorsPtr;
+    PutScanLine       : procedure (x, y, w: Integer; scl: GrColorsPtr; Op: GrColor);
   end;
-  GrFrameDriverPtr = ^GrFrameDriver;
 
   { driver and mode info structure }
 
   { extern const struct _GR_driverInfo }
   GrDriverInfoType = record
-    VDriver    : ^GrVideoDriver; { the current video driver }
-    CurMode    : ^GrVideoMode;   { current video mode pointer }
-    ActMode    : GrVideoMode;    { copy of above, resized if virtual }
-    FDriver    : GrFrameDriver;  { frame driver for the current context }
-    SDriver    : GrFrameDriver;  { frame driver for the screen }
-    TDriver    : GrFrameDriver;  { a dummy driver for text modes }
-    MCode      : ByteCard;       { code for the current mode }
-    DefTW,DefTH: Integer;        { default text mode size }
-    DefGW,DefGH: Integer;        { default graphics mode size }
-    DefTC,DefGC: GrColor;        { default text and graphics colors }
-    VPosX,VPosY: Integer;        { current virtual viewport position }
-    ErrsFatal  : Integer;        { if set, exit upon errors }
-    ModeRestore: Integer;        { restore startup video mode if set }
-    SplitBanks : Integer;        { indicates separate R/W banks }
-    CurBank    : Integer;        { currently mapped bank }
-    MdSetHook  : Pointer;        { callback for mode set }
-    SetBank    : Pointer;        { banking routine }
-    SetRWBanks : Pointer;        { split banking routine }
+    VDriver    : GrVideoDriverPtr;             { the current video driver }
+    CurMode    : GrVideoModePtr;               { current video mode pointer }
+    ActMode    : GrVideoMode;                  { copy of above, resized if virtual }
+    FDriver    : GrFrameDriver;                { frame driver for the current context }
+    SDriver    : GrFrameDriver;                { frame driver for the screen }
+    TDriver    : GrFrameDriver;                { a dummy driver for text modes }
+    MCode      : Integer;                      { code for the current mode }
+    DefTW,DefTH: Integer;                      { default text mode size }
+    DefGW,DefGH: Integer;                      { default graphics mode size }
+    DefTC,DefGC: GrColor;                      { default text and graphics colors }
+    VPosX,VPosY: Integer;                      { current virtual viewport position }
+    ErrsFatal  : Integer;                      { if set, exit upon errors }
+    ModeRestore: Integer;                      { restore startup video mode if set }
+    SplitBanks : Integer;                      { indicates separate R/W banks }
+    CurBank    : Integer;                      { currently mapped bank }
+    MdSetHook  : procedure;                    { callback for mode set }
+    SetBank    : procedure (bk: Integer);      { banking routine }
+    SetRWBanks : procedure (rb, wb: Integer);  { split banking routine }
   end;
 
 var
@@ -351,33 +363,24 @@
   ================================================================== }
 
 type
-  GrFrameType = record
-    gf_BaseAddr  : array [0 .. 3] of MemPtr; { base address of frame memory }
-    gf_Selector  : ShortInt;                 { frame memory segment selector }
-    gf_OnScreen  : Char;                     { is it in video memory ? }
-    gf_MemFlags  : Char;                     { memory allocation flags }
-    gf_LineOffset: Integer;                  { offset to next scan line in bytes }
-    gf_Driver    : ^GrFrameDriver;           { frame access functions }
-  end;
-
   { struct _GR_context }
+  GrContextPtr = ^GrContext;
   GrContext = record
-    gc_Frame    : GrFrameType;  { frame buffer info }
-    gc_Root     : ^GrContext;   { context which owns frame }
-    gc_XMax     : Integer;      { max X coord (width  - 1) }
-    gc_YMax     : Integer;      { max Y coord (height - 1) }
-    gc_XOffset  : Integer;      { X offset from root's base }
-    gc_YOffset  : Integer;      { Y offset from root's base }
-    gc_XClipLo  : Integer;      { low X clipping limit }
-    gc_YClipLo  : Integer;      { low Y clipping limit }
-    gc_XClipHi  : Integer;      { high X clipping limit }
-    gc_YClipHi  : Integer;      { high Y clipping limit }
-    gc_UsrXBase : Integer;      { user window min X coordinate }
-    gc_UsrYBase : Integer;      { user window min Y coordinate }
-    gc_UsrWidth : Integer;      { user window width  }
-    gc_UsrHeight: Integer;      { user window height }
+    gc_Frame    : GrFrameType;   { frame buffer info }
+    gc_Root     : GrContextPtr;  { context which owns frame }
+    gc_XMax     : Integer;       { max X coord (width  - 1) }
+    gc_YMax     : Integer;       { max Y coord (height - 1) }
+    gc_XOffset  : Integer;       { X offset from root's base }
+    gc_YOffset  : Integer;       { Y offset from root's base }
+    gc_XClipLo  : Integer;       { low X clipping limit }
+    gc_YClipLo  : Integer;       { low Y clipping limit }
+    gc_XClipHi  : Integer;       { high X clipping limit }
+    gc_YClipHi  : Integer;       { high Y clipping limit }
+    gc_UsrXBase : Integer;       { user window min X coordinate }
+    gc_UsrYBase : Integer;       { user window min Y coordinate }
+    gc_UsrWidth : Integer;       { user window width  }
+    gc_UsrHeight: Integer;       { user window height }
   end;
-  GrContextPtr = ^GrContext;
 
   { extern const struct _GR_contextInfo }
   GrContextInfoType = record
@@ -472,11 +475,11 @@
 type
   { typedef struct } { framed box colors }
   GrFBoxColors = record
-    fbx_IntegerColor: Integer;
-    fbx_TopColor    : Integer;
-    fbx_RightColor  : Integer;
-    fbx_BottomColor : Integer;
-    fbx_LeftColor   : Integer;
+    fbx_IntColor   : GrColor;
+    fbx_TopColor   : GrColor;
+    fbx_RightColor : GrColor;
+    fbx_BottomColor: GrColor;
+    fbx_LeftColor  : GrColor;
   end;
 
 procedure GrClearScreen(bg:GrColor); asmname 'GrClearScreen';
@@ -503,7 +506,7 @@
 procedure GrPolygon(NumPts: Integer; var Points{ : array of PointType }; c: GrColor); asmname 'GrPolygon';
 procedure GrFilledConvexPolygon(NumPts: Integer; var Points{ : array of PointType }; c: GrColor); asmname 'GrFilledConvexPolygon';
 procedure GrFilledPolygon(NumPts: Integer; var Points{ : array of PointType }; c: GrColor); asmname 'GrFilledPolygon';
-procedure GrBitBlt(Dest: GrContextPtr; x, y: Integer; Src: GrContextPtr; x1, y1, x2, y2: Integer; op: GrColor); asmname 'GrBitBlt';
+procedure GrBitBlt(Dest: GrContextPtr; x, y: Integer; Src: GrContextPtr; x1, y1, x2, y2: Integer; Op: GrColor); asmname 'GrBitBlt';
 function  GrPixel(x, y:Integer):GrColor; asmname 'GrPixel';
 function  GrPixelC(c: GrContextPtr; x, y: Integer): GrColor; asmname 'GrPixelC';
 
@@ -521,12 +524,12 @@
 {                      (w = |x2-y1|)                               }
 {           Output data is valid until next GRX call !             }
 
-procedure GrPutScanline(x1,x2,yy: Integer;c: GrColorsPtr; op: GrColor); asmname 'GrPutScanline';
+procedure GrPutScanline(x1,x2,yy: Integer;c: GrColorsPtr; Op: GrColor); asmname 'GrPutScanline';
 { Input   x1: first x coordinate to be set                         }
 {         x2: last  x coordinate to be set                         }
 {         yy: y coordinate                                         }
 {         c : c[0..(|x2-x1|] hold the pixel data                   }
-{         op: Operation (GrWRITE/GrXOR/GrOR/GrAND/GrIMAGE)         }
+{         Op: Operation (GrWRITE/GrXOR/GrOR/GrAND/GrIMAGE)         }
 {                                                                  }
 { Note    c[..] data must fit GrCVALUEMASK otherwise the results   }
 {         are implementation dependend.                            }
@@ -544,7 +547,7 @@
 procedure GrBoxNC(x1, y1, x2, y2: Integer; c: GrColor); asmname 'GrBoxNC';
 procedure GrFilledBoxNC(x1, y1, x2, y2: Integer; c: GrColor); asmname 'GrFilledBoxNC';
 procedure GrFramedBoxNC(x1, y1, x2, y2, Wdt: Integer; protected var c: GrFBoxColors); asmname 'GrFramedBoxNC';
-procedure GrBitBltNC(Dest: GrContextPtr; x, y: Integer; Src: GrContextPtr; x1, y1, x2, y2: Integer; op: GrColor); asmname 'GrBitBltNC';
+procedure GrBitBltNC(Dest: GrContextPtr; x, y: Integer; Src: GrContextPtr; x1, y1, x2, y2: Integer; Op: GrColor); asmname 'GrBitBltNC';
 function  GrPixelNC(x, y:Integer):GrColor; asmname 'GrPixelNC';
 function  GrPixelCNC(c: GrContextPtr; x, y: Integer): GrColor; asmname 'GrPixelCNC';
 
@@ -592,41 +595,40 @@
 type
   { typedef struct _GR_fontHeader }  { font descriptor }
   GrFontHeader = record
-    Name        : CString;  { font name }
-    Family      : CString;  { font family name }
-    Proportional: Char;     { characters have varying width }
-    Scalable    : Char;     { derived from a scalable font }
-    Preloaded   : Char;     { set when linked Integero program }
-    Modified    : Char;     { "tweaked" font (resized, etc..) }
-    Width       : Integer;  { width (proportional=>average) }
-    Height      : Integer;  { font height }
-    Baseline    : Integer;  { baseline pixel pos (from top) }
-    ULPos       : Integer;  { underline pixel pos (from top) }
-    ULHeight    : Integer;  { underline width }
-    MinChar     : Integer;  { lowest character code in font }
-    NumChars    : Integer;  { number of characters in font }
+    Name        : CString;   { font name }
+    Family      : CString;   { font family name }
+    Proportional: ByteBool;  { characters have varying width }
+    Scalable    : ByteBool;  { derived from a scalable font }
+    Preloaded   : ByteBool;  { set when linked Integero program }
+    Modified    : ByteBool;  { "tweaked" font (resized, etc..) }
+    Width       : Cardinal;  { width (proportional=>average) }
+    Height      : Cardinal;  { font height }
+    Baseline    : Cardinal;  { baseline pixel pos (from top) }
+    ULPos       : Cardinal;  { underline pixel pos (from top) }
+    ULHeight    : Cardinal;  { underline width }
+    MinChar     : Cardinal;  { lowest character code in font }
+    NumChars    : Cardinal;  { number of characters in font }
   end;
 
   { typedef struct _GR_fontChrInfo } { character descriptor }
   GrFontChrInfo = record
-    Width : Integer;  { width of this character }
-    Offset: Integer;  { offset from start of bitmap }
+    Width : Cardinal;  { width of this character }
+    Offset: Cardinal;  { offset from start of bitmap }
   end;
 
   { typedef struct _GR_font } { the complete font }
-  AuxoffsType = array [1 .. 7] of Integer;
+  AuxOffsType = array [0 .. 6] of Integer;
   GrFont = record
     h       : GrFontHeader;  { the font info structure }
     BitMap  : MemPtr;        { character bitmap array }
     AuxMap  : MemPtr;        { map for rotated & underline chrs }
-    MinWidth: Integer;       { width of narrowest character }
-    MaxWidth: Integer;       { width of widest character }
-    AuxSize : Integer;       { allocated size of auxiliary map }
-    AuxNext : Integer;       { next free byte in auxiliary map }
-    AuxOffs : ^AuxoffsType;  { offsets to completed aux chars }
-    ChrInfo : array [1 .. 1] of GrFontChrInfo; { character info (not act. size) }
+    MinWidth: Cardinal;      { width of narrowest character }
+    MaxWidth: Cardinal;      { width of widest character }
+    AuxSize : Cardinal;      { allocated size of auxiliary map }
+    AuxNext : Cardinal;      { next free byte in auxiliary map }
+    AuxOffs : ^AuxOffsType;  { offsets to completed aux chars }
+    ChrInfo : array [1 .. 1] of GrFontChrInfo;  { character info (not act. size) }
   end;
-
   GrFontPtr = ^GrFont;
 
 var
@@ -657,11 +659,11 @@
 function  GrFontCharAuxBmp(var Font: GrFont; Chr, Dir, ul: Integer): MemPtr; asmname 'GrFontCharAuxBmp';
 
 type
-  GrColorTableP = ^GrColor;
+  GrColorTableP = ^GrColors;
 
   { typedef union _GR_textColor }   { text color union }
   GrTextColor = record
-  case 1..2 of
+  case 1 .. 2 of
     1: (v: GrColor);           { color value for "direct" text }
     2: (p: GrColorTableP);     { color table for attribute text }
   end;
@@ -689,7 +691,7 @@
     txr_LineOffset: Integer;     { offset in buffer(s) between rows }
     txr_XPos      : Integer;     { upper left corner X coordinate }
     txr_YPos      : Integer;     { upper left corner Y coordinate }
-    txr_ChrType   : Char;        { character type (see above) }
+    txr_ChrType   : ByteCard;    { character type (see above) }
   end;
 
 function  GrCharWidth(Chr: Integer; protected var Opt: GrTextOption): Integer; asmname 'GrCharWidth';
@@ -717,10 +719,10 @@
 
 type
   GrLineOption = record
-   No_Color   : GrColor;   { color used to draw line }
-   Lno_Width  : Integer;   { width of the line }
-   Lno_PattLen: Integer;   { length of the dash pattern }
-   Lno_DashPat: ^ByteCard; { draw/nodraw pattern }
+    No_Color   : GrColor;  { color used to draw line }
+    Lno_Width  : Integer;  { width of the line }
+    Lno_PattLen: Integer;  { length of the dash pattern }
+    Lno_DashPat: MemPtr;   { draw/nodraw pattern }
   end;
 
 procedure GrCustomLine(x1, y1, x2, y2: Integer; protected var o: GrLineOption); asmname 'GrCustomLine';
@@ -745,7 +747,7 @@
   GrBitmap = record
     bmp_IsPixMap: Integer;      { type flag for pattern union }
     bmp_Height  : Integer;      { bitmap height }
-    bmp_Data    : ^ByteCard;    { pointer to the bit pattern }
+    bmp_Data    : MemPtr;       { pointer to the bit pattern }
     bmp_FgColor : GrColor;      { foreground color for fill }
     bmp_BgColor : GrColor;      { background color for fill }
     bmp_MemFlags: Integer;      { set if dynamically allocated }
@@ -769,9 +771,10 @@
 
   { typedef union _GR_pattern }
   GrPattern = record
-    gp_IsPixMap: Integer;   { nonzero for pixmaps }
-    gp_BitMap  : GrBitmap;  { fill bitmap }
-    gp_PixMap  : GrPixmap;  { fill pixmap }
+  case 1 .. 3 of
+    1: (gp_IsPixMap: Integer);   { nonzero for pixmaps }
+    2: (gp_BitMap  : GrBitmap);  { fill bitmap }
+    3: (gp_PixMap  : GrPixmap);  { fill pixmap }
   end;
   GrPatternPtr = ^GrPattern;
 
@@ -820,11 +823,6 @@
   <e-mail>    - [stenclpmd@ba.telecom.sk] }
 
 type
-  { Original GRX decl:
-    GrImage = GrPixmap;
-    GrImagePtr = ^GrImage;
-       Pascal isn't case sensitive so GrImage conficts with GrIMAGE above.
-       Since we only need GrImagePtr we take a short cut here: }
   GrImagePtr = ^GrPixmap;
 
 { Flags for GrImageInverse() }
@@ -991,7 +989,7 @@
     Buttons: Integer;           { mouse button state }
     Key    : Integer;           { key code from keyboard }
     KBStat : Integer;           { keybd status (ALT, CTRL, etc..) }
-    DTime  : Integer;           { time since last event (msec) }
+    DTime  : MedInt;            { time since last event (msec) }
   end;
   GrMouseEventPtr = ^GrMouseEvent;
 
