{----------------------------------------------------------------------------
  Mode13h - DOS 16bit realmode (Turbo Pascal version)
  Copyright (c) 1994,95 by J.E. Hoffmann
  All rights reserved
 ----------------------------------------------------------------------------}
{$A+,B-,D-,E-,F-,G+,I-,L-,N-,O-,P-,Q-,R-,S-,T-,V-,X+,Y-}
unit _VGAPas;



interface



const
  {--General Register----------------------------------------}
  GR_InputStatus1            = $3DA;


  {--Cathode Ray Tube Controller-----------------------------}
  CC_Index                   = $3D4;
  CC_Data                    = $3D5;

  cc_HorizontalTotal         = $00;
  cc_HorizontalDisplayEnd    = $01;
  cc_StartHorizontalBlanking = $02;
  cc_EndHorizontalBlanking   = $03;
  cc_StartHorizontalRetrace  = $04;
  cc_EndHorizontalRetrace    = $05;
  cc_VerticalTotal           = $06;
  cc_Overflow                = $07;
  cc_PresetRowScan           = $08;
  cc_MaximumScanLine         = $09;
  cc_CursorStart             = $0A;
  cc_CursorEnd               = $0B;
  cc_StartAddressHigh        = $0C;
  cc_StartAddressLow         = $0D;
  cc_CursorLocationHigh      = $0E;
  cc_CursorLocationLow       = $0F;
  cc_StartVerticalRetrace    = $10;
  cc_EndVerticalRetrace      = $11;
  cc_VerticalDisplayEnd      = $12;
  cc_Offset                  = $13;
  cc_UnderlineLocation       = $14;
  cc_StartVerticalBlanking   = $15;
  cc_EndVerticalBlanking     = $16;
  cc_ModeControl             = $17;
  cc_LineCompare             = $18;


  {--Graphics Controller-----------------------------}
  GC_Index                   = $3CE;
  GC_Data                    = $3CF;

  gc_SetReset                = $00;
  gc_EnableSetReset          = $01;
  gc_ColorCompare            = $02;
  gc_DataRotate              = $03;
  gc_ReadMapSelect           = $04;
  gc_Mode                    = $05;
  gc_Miscellaneous           = $06;
  gc_ColorDontCare           = $07;
  gc_BitMask                 = $08;


  {--Sequencer Controller-----------------------------}
  SC_Index                   = $3C4;
  SC_Data                    = $3C5;

  sc_Reset                   = $00;
  sc_ClockingMode            = $01;
  sc_MapMask                 = $02;
  sc_CharacterMapSelect      = $03;
  sc_MemoryMode              = $04;


  {--Attribute Controller-----------------------------}
  AC_Write                   = $3C0;
  AC_Read                    = $3C1;

  ac_ModeControl             = $10;
  ac_OverScanColor           = $11;
  ac_ColorPlaneEnable        = $12;
  ac_HorizontalPixPanning    = $13;
  ac_ColorSelect             = $14;


  {--Digital Analog Converter-------------------------}
  DC_PELAddressReadMode_W    = $3C7;
  DC_PELAddressReadMode_R    = $3C8;
  DC_PELAddressWriteMode     = $3C8;
  DC_PELData                 = $3C9;
  DC_DACState                = $3C7;
  DC_PELMask                 = $3C6;


  red                        = 0;
  green                      = 1;
  blue                       = 2;

  xSize        :Word = 320;
  TexXSize     :Integer = 256;
  TexYSize     :Integer = 256;
  _VirtualVSeg :Word = $A000;



type
  TRGB      = array[red..blue] of Byte;
  TDACBlock = array[0..255] of TRGB;



procedure Init13h;
procedure Done13h;
procedure InitVBuffer;
procedure DoneVBuffer;
procedure IsColorVGA;
procedure WaitVertRetrace;
procedure ClearScreen(Col :Byte);
procedure ShowVBuffer;
procedure SetDACBlock(StartReg :Byte; Count :Integer; var Block);



implementation



procedure Init13h; external;
procedure Done13h; external;
procedure IsColorVGA; external;
procedure WaitVertRetrace; external;
procedure ClearScreen(Col :Byte); external;
procedure ShowVBuffer; external;
procedure SetDACBlock(StartReg :Byte; Count :Integer; var Block); external;
{$L _VGAPAS.OBJ}



procedure InitVBuffer;
var
  P :Pointer;
begin
  Getmem(P,$FFFF);
  asm
    mov ax,[WORD PTR P+2]
    mov [_VirtualVSeg],ax
  end;
end;



procedure DoneVBuffer;
var
  P :Pointer;
begin
  asm
    mov ax,[_VirtualVSeg]
    mov [WORD PTR P+2],ax
    xor ax,ax
    mov [WORD PTR P],ax
  end;
  FreeMem(P,$FFFF);
end;



end.