home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / video / tsvga.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-03-09  |  21.9 KB  |  672 lines

  1. {*********************************************************}
  2. {*                    TSVGA.PAS 1.00                     *}
  3. {*        Copyright (c) T P Systems, Inc. 1994.          *}
  4. {*                  All rights reserved.                 *}
  5. {*********************************************************}
  6.  
  7. (*  Implements standard VGA video functions of Int 10. In so far as
  8.     possible the formats of these routines is the same as those in
  9.     SVGA.
  10. *)
  11.  
  12. {$A-,B-,E+,F+,I-,N-,O+,R-,S-,V-,X+}
  13.  
  14. Unit TsVga;
  15.  
  16. interface
  17.  
  18. uses
  19.   Dos,
  20.   OpConst,
  21.   OpString,
  22.   OpCrt;
  23.  
  24. var
  25.   BiosMode    : byte absolute $0040:$0049;
  26.   BiosRows    : byte absolute $0040:$0084;
  27.   BiosCols    : byte absolute $0040:$004A;
  28.   BiosCharH   : byte absolute $0040:$0085;
  29.  
  30. const
  31.   MaxScreenModes = 10;
  32.  
  33.   {new error codes}
  34.   ecVgaFuncNotSupported = 3993;
  35.   ecVgaFuncFailed       = 3994;
  36.   ecVgaNotActive        = 3995;
  37.   ecInvalidFontFile     = 3996;
  38.   ecScrResolNotSupported= 3997;
  39.   ecNotRomFont          = 3998;
  40.   ecStateNotSaved       = 3999;
  41.  
  42. type
  43.   ScreenModePtr = ^ScreenModeRec;
  44.   ScreenModeRec = record
  45.     smVidMode  : word;
  46.     smFontSize : byte;
  47.     smRows     : byte;
  48.     smCols     : byte;
  49.     smIsText   : boolean;
  50.     smPixW     : word;
  51.     smPixH     : word;
  52.     smColors   : word;    {number of colors supported}
  53.   end;
  54.  
  55.   ScreenModeArPtr = ^ScreenModeArray;
  56.   ScreenModeArray = array[1..MaxScreenModes] of ScreenModeRec;
  57.   ModeSet = set of 0..$13;
  58.   RowSet = set of 12..60;
  59.   FontSet = set of 8..16;
  60.  
  61. const
  62.   StdTextModes : ModeSet = [0,1,2,3,7];
  63.  
  64.   StdEgaFonts : FontSet = [8, 14];
  65.   StdVgaFonts : FontSet = [8, 14, 16];
  66.  
  67.   {Standard font screen resolutions for text}
  68.   StdEgaRows : RowSet = [25, 43];
  69.   {for text modes below the smPixH value is equivalent to scan lines}
  70.   StdEgaModes : ScreenModeArray = (
  71.     (smVidMode: $03; smFontSize: 14; smRows: 25; smCols: 80; smIsText: true;
  72.      smPixW: 640; smPixH: 350; smColors: 16),
  73.     (smVidMode: $03; smFontSize:  8; smRows: 43; smCols: 80; smIsText: true;
  74.      smPixW: 640; smPixH: 350; smColors: 16),
  75.     (smVidMode: $01; smFontSize: 14; smRows: 25; smCols: 40; smIsText: true;
  76.      smPixW: 320; smPixH: 350; smColors: 16),
  77.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  78.      smPixW:   0; smPixH:   0; smColors: 0),
  79.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  80.      smPixW:   0; smPixH:   0; smColors: 0),
  81.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  82.      smPixW:   0; smPixH:   0; smColors: 0),
  83.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  84.      smPixW:   0; smPixH:   0; smColors: 0),
  85.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  86.      smPixW:   0; smPixH:   0; smColors: 0),
  87.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  88.      smPixW:   0; smPixH:   0; smColors: 0),
  89.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  90.      smPixW:   0; smPixH:   0; smColors: 0));
  91.  
  92.   {Non-standard font screen resolutions for text}
  93.   SplEgaRows : RowSet = [26, 29, 31, 35, 38];
  94.   {for text modes below the smPixH value is equivalent to scan lines}
  95.   SplEgaModes : ScreenModeArray = (
  96.     (smVidMode: $03; smFontSize: 13; smRows: 26; smCols: 80; smIsText: true;
  97.      smPixW: 640; smPixH: 350; smColors: 16),
  98.     (smVidMode: $03; smFontSize: 12; smRows: 29; smCols: 80; smIsText: true;
  99.      smPixW: 640; smPixH: 350; smColors: 16),
  100.     (smVidMode: $03; smFontSize: 11; smRows: 31; smCols: 80; smIsText: true;
  101.      smPixW: 640; smPixH: 350; smColors: 16),
  102.     (smVidMode: $03; smFontSize: 10; smRows: 35; smCols: 80; smIsText: true;
  103.      smPixW: 640; smPixH: 350; smColors: 16),
  104.     (smVidMode: $03; smFontSize:  9; smRows: 38; smCols: 80; smIsText: true;
  105.      smPixW: 640; smPixH: 350; smColors: 16),
  106.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  107.      smPixW:   0; smPixH:   0; smColors: 0),
  108.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  109.      smPixW:   0; smPixH:   0; smColors: 0),
  110.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  111.      smPixW:   0; smPixH:   0; smColors: 0),
  112.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  113.      smPixW:   0; smPixH:   0; smColors: 0),
  114.     (smVidMode: $00; smFontSize:  0; smRows:  0; smCols:  0; smIsText: false;
  115.      smPixW:   0; smPixH:   0; smColors: 0));
  116.  
  117.   StdVgaRows : RowSet = [12, 14, 21, 25, 28, 30, 43, 50, 60];
  118.   {for text modes below the smPixH value is equivalent to scan lines}
  119.   StdVgaModes : ScreenModeArray = (
  120.     (smVidMode: $01; smFontSize: 16; smRows: 25; smCols: 40; smIsText: true;
  121.      smPixW: 360; smPixH: 400; smColors: 16),
  122.     (smVidMode: $03; smFontSize: 16; smRows: 25; smCols: 80; smIsText: true;
  123.      smPixW: 720; smPixH: 400; smColors: 16),
  124.     (smVidMode: $03; smFontSize: 16; smRows: 12; smCols: 80; smIsText: true;
  125.      smPixW: 720; smPixH: 200; smColors: 16),
  126.     (smVidMode: $03; smFontSize: 14; smRows: 14; smCols: 80; smIsText: true;
  127.      smPixW: 720; smPixH: 200; smColors: 16),
  128.     (smVidMode: $01; smFontSize: 16; smRows: 21; smCols: 40; smIsText: true;
  129.      smPixW: 360; smPixH: 350; smColors: 16),
  130.     (smVidMode: $03; smFontSize: 14; smRows: 28; smCols: 80; smIsText: true;
  131.      smPixW: 720; smPixH: 400; smColors: 16),
  132.     (smVidMode: $12; smFontSize: 16; smRows: 30; smCols: 80; smIsText: false;
  133.      smPixW: 640; smPixH: 480; smColors: 16),
  134.     (smVidMode: $03; smFontSize:  8; smRows: 43; smCols: 80; smIsText: true;
  135.      smPixW: 720; smPixH: 350; smColors: 16),
  136.     (smVidMode: $03; smFontSize:  8; smRows: 50; smCols: 80; smIsText: true;
  137.      smPixW: 720; smPixH: 400; smColors: 16),
  138.     (smVidMode: $12; smFontSize:  8; smRows: 60; smCols: 80; smIsText: false;
  139.      smPixW: 640; smPixH: 480; smColors: 16));
  140.  
  141.   {Non-standard font screen resolutions for text}
  142.   SplVgaRows : RowSet = [26, 29, 30, 31, 33, 35, 36, 38, 40, 44];
  143.   {for text modes below the smPixH value is equivalent to scan lines}
  144.   SplVgaModes : ScreenModeArray = (
  145.     (smVidMode: $03; smFontSize: 15; smRows: 26; smCols: 80; smIsText: true;
  146.      smPixW: 720; smPixH: 400; smColors: 16),
  147.     (smVidMode: $03; smFontSize: 12; smRows: 29; smCols: 80; smIsText: true;
  148.      smPixW: 720; smPixH: 350; smColors: 16),
  149.     (smVidMode: $03; smFontSize: 13; smRows: 30; smCols: 80; smIsText: true;
  150.      smPixW: 720; smPixH: 400; smColors: 16),
  151.     (smVidMode: $03; smFontSize: 11; smRows: 31; smCols: 80; smIsText: true;
  152.      smPixW: 720; smPixH: 350; smColors: 16),
  153.     (smVidMode: $03; smFontSize: 12; smRows: 33; smCols: 80; smIsText: true;
  154.      smPixW: 720; smPixH: 400; smColors: 16),
  155.     (smVidMode: $03; smFontSize: 10; smRows: 35; smCols: 80; smIsText: true;
  156.      smPixW: 720; smPixH: 350; smColors: 16),
  157.     (smVidMode: $03; smFontSize: 11; smRows: 36; smCols: 80; smIsText: true;
  158.      smPixW: 720; smPixH: 400; smColors: 16),
  159.     (smVidMode: $03; smFontSize:  9; smRows: 38; smCols: 80; smIsText: true;
  160.      smPixW: 720; smPixH: 350; smColors: 16),
  161.     (smVidMode: $03; smFontSize: 10; smRows: 40; smCols: 80; smIsText: true;
  162.      smPixW: 720; smPixH: 400; smColors: 16),
  163.     (smVidMode: $03; smFontSize:  9; smRows: 44; smCols: 80; smIsText: true;
  164.      smPixW: 720; smPixH: 400; smColors: 16));
  165.  
  166. type
  167.  
  168.   VgaStatePtr = ^VgaStateTable;
  169.   VgaStateTable = record
  170.     vsTable     : pointer;     {address of static functionality table}
  171.     vsMode      : byte;        {video mode}
  172.     vsCols      : word;        {column/row}
  173.     vsBufLen    : word;        {display buffer length}
  174.     vsAddr      : word;        {starting address of buffer}
  175.     vsCurPos    : array [1..8] of word;  {array of 8 cursor positions}
  176.     vsCurType   : word;        {cursor type}
  177.     vsActPage   : byte;        {active page}
  178.     vsCrtCtrl   : word;        {CRT Controller base address}
  179.     vsVal3x8    : byte;        {current value of 3x8 register}
  180.     vsVal3x9    : byte;        {current value of 3x9 register}
  181.     vsRows      : byte;        {rows on screen}
  182.     vsCharHigh  : word;        {character height - bytes/char}
  183.     vsActDisp   : byte;        {active display code}
  184.     vsInActDisp : byte;        {inactive display code}
  185.     vsNrColors  : word;        {number of colors available in current mode}
  186.     vsNrPages   : byte;        {number of display pages in current mode}
  187.     vsNrScanLns : byte;        {number of scan lines - coded}
  188.     vsPriCharBlk: byte;        {primary character block}
  189.     vsSecCharBlk: byte;        {secondary character block}
  190.     vsMiscInfo  : byte;        {miscellaneous state info - bit mapped}
  191.     vsRes1      : array[1..3] of byte;  {reserved}
  192.     vsVidMem    : byte;        {video memory available - coded}
  193.     vsPtrState  : byte;        {save pointer state - bit mapped}
  194.     vsRes2      : array[1..13] of byte; {reserved}
  195.   end;
  196.  
  197. const
  198.   {bit masks for vsMiscInfo byte above}
  199.   vsAllModes     = $01;         {all modes on all displays active}
  200.   vsGrayScale    = $02;         {gray scale summing is active}
  201.   vsMonoDisp     = $04;         {mono display is attached}
  202.   vsNoAutoPal    = $08;         {mode set auto palette loading disabled}
  203.   vsCurEmul      = $10;         {cursor emulation is active}
  204.   vsBlink        = $20;         {on=blink, off=background intensity}
  205.  
  206.   {scan line array}
  207.   ScanLines : array[0..3] of word = (200, 350, 400, 480);
  208.  
  209.   {Save Video State Bit Masks}
  210.   ssHardware           = $0001;
  211.   ssBios               = $0002;
  212.   ssDac                = $0004;
  213.   ssSvga               = $0008;
  214.   ssAllVga             = $0007;
  215.   ssAllSvga            = $000F;
  216.  
  217. var
  218.   CurVideoMode : integer;
  219.   CurScreenRows : integer;
  220.   CurScreenCols : integer;
  221.  
  222. const
  223.   CurBlinkOff  : boolean = false;
  224.   OrigBlinkOff : boolean = false;
  225.  
  226. {*****************************************************************
  227.   VGA Routines -- some will work with EGA
  228. ******************************************************************}
  229.  
  230. function ReturnVgaInfo(VI: VgaStatePtr): word;
  231.   {-Returns status 0 if successful and VgaStateTable filled in or if fails,
  232.     returns ecVgaFuncFailed.}
  233.  
  234. function SetVgaMode(Mode: word; Clear: boolean): word;
  235.   {-Sets VGA mode. Clears display memory if Clear. Returns standard Vga status.}
  236.  
  237. function ReturnCurVgaMode(var Mode: word): word;
  238.   {-Returns status and current video mode in Mode.  Bit 7 indicates whether
  239.     video display memory was cleared on last set mode.}
  240.  
  241. function ReturnVgaSaveBufferSize(var Size: word; States: word): word;
  242.   {-Returns status and size of save state buffer in Size (in bytes).  Must be
  243.     called before SaveVgaState to get size of required buffer. States is
  244.     bit mapped to indicate which states are to be saved.  See bit masks above.}
  245.  
  246. function SaveVgaState(Buf: pointer; States: word): word;
  247.   {-Returns status of saving video states specified in States.  Buf points
  248.     to a save buffer of size determined by ReturnVgaSaveBufferSize. No checking
  249.     that Buf points to area large enough. States must be same as used in
  250.     ReturnSaveBufferSize.}
  251.  
  252. function RestoreVgaState(Buf: pointer; States: word): word;
  253.   {-Returns status of restoring video states specified in States.  Buf must
  254.     point to buffer that was previously saved with SaveSvgaState and States
  255.     must be same as used previously.}
  256.  
  257. function ReturnScreenMode(ScreenModes: ScreenModeArPtr;
  258.                           var ScreenMode: ScreenModeRec): boolean;
  259.   {-Searches ScreenModes for a mode with matching smRows and smCols and/or
  260.     smVidMode and  returns true plus the appropriate ScreenModeRec.}
  261.  
  262. function SetVgaFont(FontName: string; ScrMode: ScreenModeRec;
  263.                     FontBuf: pointer): word;
  264.   {-If FontName is blank, a the appropriate standard ROM based font will
  265.     be loaded. Otherwise it loads user fonts in file FontName for the
  266.     appropriate number of screen rows. FontBuf points to a buffer of
  267.     appropriate size that has already been allocated. This assumes the video
  268.     display adpater is already in the appropriate video mode and scan lines
  269.     are set for text mode cases. If successful, it returns 0; otherwise the
  270.     error.}
  271.  
  272. function PreservePalette(On: boolean): word;
  273.   {-Supported only on VGA. If On then with a set mode the palette is not
  274.     changed to the default. Returns ecVgaFuncNotSupported if it fails.}
  275.  
  276. function SetScanLines(Lines: word): word;
  277.   {-Supported only on VGA.  Selects scan lines for text modes.  Valid
  278.     values of Lines are 200, 350, 400.  Returns ecVgaFuncNotSupported or
  279.     ecVgaNotActive if function fails.}
  280.  
  281. function DisableVideoRefresh(Off: boolean): word;
  282.   {-If Off is true, disables video refresh which blanks the screen.  If Off
  283.     is false, the video refresh is enabled.  Returns status of action.}
  284.  
  285. {**********************************************************}
  286.  
  287. implementation
  288.  
  289. type
  290.   OS = record
  291.     O,S : word;
  292.   end;
  293.  
  294. function ReturnVgaInfo(VI: VgaStatePtr): word; assembler;
  295.   {-Returns status 0 if successful and VgaStateTable filled in or if fails,
  296.     returns ecVgaFuncFailed.}
  297. asm
  298.   push bx
  299.   push di
  300.   push es
  301.   mov  ax,$1B00
  302.   xor  bx,bx
  303.   mov  di,OS(VI).S
  304.   mov  es,di
  305.   mov  di,OS(VI).O
  306.   int  $10
  307.   cmp  al,$1B
  308.   je   @1
  309.   mov  ax,ecVgaFuncFailed
  310.   jmp  @2
  311. @1:
  312.   xor  ax,ax
  313. @2:
  314.   pop  es
  315.   pop  di
  316.   pop  bx
  317. end;
  318.  
  319. function SetVgaMode(Mode: word; Clear: boolean): word; assembler;
  320.   {-Sets VGA mode. Clears display memory if Clear.  Returns standard Vga status.}
  321. asm
  322.   push bx
  323.   mov  ax,Mode
  324.   mov  ah,0
  325.   mov  bl,Clear
  326.   xor  bl,1
  327.   ror  bl,1
  328.   or   al,bl
  329.   int  $10
  330.   xor  ax,ax
  331.   pop  bx
  332. end;
  333.  
  334. function ReturnCurVgaMode(var Mode: word): word; assembler;
  335.   {-Returns status and current video mode in Mode.  Bit 7 is always
  336.     cleared to be compatible with SVGA function.}
  337. asm
  338.   push bx
  339.   push si
  340.   push ds
  341.   mov  ah,$0F
  342.   int  $10
  343.   xor  ah,ah
  344.   and  al,$7F
  345.   lds  si,Mode
  346.   mov  word ptr [si],ax
  347.   xor  ax,ax
  348.   pop  ds
  349.   pop  si
  350.   pop  bx
  351. end;
  352.  
  353. function ReturnVgaSaveBufferSize(var Size: word; States: word): word; assembler;
  354.   {-Returns status and size of save state buffer in Size (in bytes).  Must be
  355.     called before SaveVgaState to get size of required buffer. States is
  356.     bit mapped to indicate which states are to be saved.  See bit masks above.}
  357. asm
  358.   push bx
  359.   push cx
  360.   push si
  361.   push ds
  362.   mov  ah,$1C
  363.   mov  al,0
  364.   mov  cx,States
  365.   int  $10
  366.   cmp  al,$1C
  367.   je   @1
  368.   mov  ax,ecVgaFuncFailed
  369.   jmp  @2
  370. @1:
  371.   lds  si,Size
  372.   shl  bx,1          {bx returns size in 64 byte blocks}
  373.   shl  bx,1
  374.   shl  bx,1
  375.   shl  bx,1
  376.   shl  bx,1
  377.   shl  bx,1
  378.   mov  word ptr [si],bx
  379.   xor  ax,ax
  380. @2:
  381.   pop  ds
  382.   pop  si
  383.   pop  cx
  384.   pop  bx
  385. end;
  386.  
  387. function SaveVgaState(Buf: pointer; States: word): word; assembler;
  388.   {-Returns status of saving video states specified in States.  Buf points
  389.     to a save buffer of size determined by ReturnVgaSaveBufferSize. No checking
  390.     that Buf points to area large enough. States must be same as used in
  391.     ReturnSaveBufferSize. Should be followed by RestoreVgaState since Phoenix
  392.     AT Systems BIOS reference says saving modifies video registers.}
  393. asm
  394.   push bx
  395.   push cx
  396.   push es
  397.   mov  ah,$1C
  398.   mov  al,1
  399.   mov  cx,States
  400.   mov  es,OS(Buf).S
  401.   mov  bx,OS(Buf).O
  402.   int  $10
  403.   cmp  al,$1C
  404.   je   @1
  405.   mov  ax,ecVgaFuncFailed
  406.   jmp  @2
  407. @1:
  408.   xor  ax,ax
  409. @2:
  410.   pop  es
  411.   pop  cx
  412.   pop  bx
  413. end;
  414.  
  415. function RestoreVgaState(Buf: pointer; States: word): word; assembler;
  416.   {-Returns status of restoring video states specified in States.  Buf must
  417.     point to buffer that was previously saved with SaveSvgaState and States
  418.     must be same as used previously.}
  419. asm
  420.   push bx
  421.   push cx
  422.   push es
  423.   mov  ah,$1C
  424.   mov  al,2
  425.   mov  cx,States
  426.   mov  es,OS(Buf).S
  427.   mov  bx,OS(Buf).O
  428.   int  $10
  429.   cmp  al,$1C
  430.   je   @1
  431.   mov  ax,ecVgaFuncFailed
  432.   jmp  @2
  433. @1:
  434.   xor  ax,ax
  435. @2:
  436.   pop  es
  437.   pop  cx
  438.   pop  bx
  439. end;
  440.  
  441. procedure SetTypematicRate(Delay, Rate: byte);  {!!1.35}
  442.   {-Sets keyboard typematic features. See Phoenix System BIOS manual page 143.
  443.     Text applications when using an underlying graphics mode, usually need
  444.     to have key repeat rate slowed down.}
  445. begin
  446.   asm
  447.     mov ax,$0305
  448.     mov bh,Delay
  449.     mov bl,Rate
  450.     int $16
  451.   end;
  452. end;
  453.  
  454. const
  455.   {key repeat rates for each video mode to take into account slower screen}
  456.   { 0 = 30 chars/sec; $14 = 5 chars/sec }
  457.   VGAKeyRate : array [1..4] of byte = (0, $12, 0, $12);
  458.  
  459. function ReturnScreenMode(ScreenModes: ScreenModeArPtr;
  460.                           var ScreenMode: ScreenModeRec): boolean;
  461.   {-Searches ScreenModes for a mode with matching smRows and smCols and/or
  462.     smVidMode and returns true plus the appropriate ScreenModeRec.}
  463. var
  464.   i : byte;
  465. begin
  466.   ReturnScreenMode := false;
  467.   if ScreenMode.smVidMode = 0 then begin
  468.     for i := 1 to MaxScreenModes do begin
  469.       if (ScreenMode.smRows = ScreenModes^[i].smRows) and
  470.          (ScreenMode.smCols = ScreenModes^[i].smCols) then begin
  471.         ScreenMode := ScreenModes^[i];
  472.         ReturnScreenMode := true;
  473.         Exit;
  474.       end;
  475.     end;
  476.   end else begin
  477.     for i := 1 to MaxScreenModes do begin
  478.       if (ScreenMode.smVidMode = ScreenModes^[i].smVidMode) then begin
  479.         if ((ScreenMode.smRows <> 0) and (ScreenMode.smCols <> 0)) then begin
  480.           if (ScreenMode.smRows = ScreenModes^[i].smRows) and
  481.              (ScreenMode.smCols = ScreenModes^[i].smCols) then begin
  482.             ScreenMode := ScreenModes^[i];
  483.             ReturnScreenMode := true;
  484.             Exit;
  485.           end;
  486.         end else begin
  487.           ScreenMode := ScreenModes^[i];
  488.           ReturnScreenMode := true;
  489.           Exit;
  490.         end;
  491.       end;
  492.     end;
  493.   end;
  494. end;
  495.  
  496. function SetVgaFont(FontName: string; ScrMode: ScreenModeRec;
  497.                     FontBuf: pointer): word;
  498.   {-If FontName is blank, a the appropriate standard ROM based font will
  499.     be loaded. Otherwise it loads user fonts in file FontName for the
  500.     appropriate number of screen rows. FontBuf points to a buffer of
  501.     appropriate size that has already been allocated. This assumes the video
  502.     display adpater is already in the appropriate video mode and scan lines
  503.     are set for text mode cases. If successful, it returns 0; otherwise the
  504.     error.}
  505. var
  506.   F : file;
  507.   BufSize : word;
  508.   Status : word;
  509.   Standard : boolean;
  510.   Regs : Registers;
  511. begin
  512.   Standard := (FontName = '');
  513.   with ScrMode do begin
  514.     if not Standard then begin
  515.       BufSize := Word(256)*smFontSize;
  516.       Assign(F, FontName);
  517.       Reset(F, 1);
  518.       Status := IOResult;
  519.       if Status <> 0 then begin
  520.         SetVgaFont := Status;
  521.         Exit;
  522.       end;
  523.       if FileSize(F) <> BufSize then begin
  524.         Close(F);
  525.         Status := IOResult;
  526.         SetVgaFont := ecInvalidFontFile;
  527.         Exit;
  528.       end;
  529.       BlockRead(F, FontBuf^, BufSize);
  530.       Close(F);
  531.       Status := IOResult;
  532.       if Status <> 0 then begin
  533.         SetVgaFont := Status;
  534.         Exit;
  535.       end;
  536.     end;
  537.     with Regs do begin
  538.       AH := $11;
  539.       BL := 0;
  540.       if Standard then begin
  541.         if smIsText then begin
  542.           case smFontSize of
  543.             8  : AL := $12;
  544.             14 : AL := $11;
  545.             16 : AL := $14;
  546.             else begin
  547.               SetVgaFont := ecNotRomFont;
  548.               Exit;
  549.             end;
  550.           end;
  551.         end else begin
  552.           case smFontSize of
  553.             8  : AL := $23;
  554.             14 : AL := $22;
  555.             16 : AL := $24;
  556.             else begin
  557.               SetVgaFont := ecNotRomFont;
  558.               Exit;
  559.             end;
  560.           end;
  561.           DL := smRows;
  562.         end;
  563.       end else begin
  564.         if smIsText then begin
  565.           AL := $10;
  566.           BH := smFontSize;
  567.           CX := 256;
  568.           DX := 0;
  569.         end else begin
  570.           AL := $21;
  571.           CX := smFontSize;
  572.           DL := smRows
  573.         end;
  574.         ES := OS(FontBuf).S;
  575.         BP := OS(FontBuf).O;
  576.       end;
  577.     end;
  578.   end;
  579.   Intr($10, Regs);
  580.   SetVgaFont := 0;
  581. end;
  582.  
  583. function PreservePalette(On: boolean): word; assembler;
  584.   {-Supported only on VGA. If On then with a set mode the palette is not
  585.     changed to the default. Returns ecVgaFuncNotSupported if it fails.}
  586. asm
  587.   push bx
  588.   mov  ah,$12
  589.   mov  al,On
  590.   mov  bl,$31
  591.   int  $10
  592.   cmp  al,$12
  593.   je   @1
  594.   mov  ax,ecVgaFuncNotSupported
  595.   jmp  @2
  596. @1:
  597.   xor  ax,ax
  598. @2:
  599.   pop  bx
  600. end;
  601.  
  602.  
  603. function SetScanLines(Lines: word): word; assembler;
  604.   {-Supported only on VGA.  Selects scan lines for text modes.  Valid
  605.     values of Lines are 200, 350, 400.  Returns ecVgaFuncNotSupported or
  606.     ecVgaNotActive if function fails. Since some adapters use non-standard
  607.     scan lines for some of their text modes, if the Lines values is not
  608.     valid, the function does nothing and does not return an error; thus it
  609.     depends on the proprietary mode setting to set the correct number of
  610.     scan lines.}
  611. asm
  612.   push bx
  613.   mov  ah,$12
  614.   mov  bl,$30
  615.   mov  al,2       {assume 400 scan lines}
  616.   cmp  Lines,400
  617.   je   @4
  618.   cmp  Lines,350
  619.   je   @5
  620.   cmp  Lines,200
  621.   jne  @2         {its not a standard number of scan lines so do nothing}
  622. @6:
  623.   mov  al,0
  624.   jmp  @4
  625. @5:
  626.   mov  al,1
  627. @4:
  628.   int  $10
  629.   cmp  al,$12
  630.   je   @2
  631.   cmp  al,0
  632.   je   @1
  633.   mov  ax,ecVgaFuncNotSupported
  634.   jmp  @3
  635. @1:
  636.   mov  ax,ecVgaNotActive
  637.   jmp  @3
  638. @2:
  639.   xor  ax,ax
  640. @3:
  641.   pop  bx
  642. end;
  643.  
  644. function DisableVideoRefresh(Off: boolean): word; assembler;
  645.   {-If Off is true, disables video refresh which blanks the screen.  If Off
  646.     is false, the video refresh is enabled.  Returns status of action.}
  647. asm
  648.   push bx
  649.   push bp        {this call is known to trash bp}
  650.   mov  ah,$12
  651.   mov  al,Off
  652.   mov  bl,$36
  653.   int  $10
  654.   cmp  al,$12
  655.   je   @1
  656.   mov  ax,ecVgaFuncNotSupported
  657.   jmp  @2
  658. @1:
  659.   xor  ax,ax
  660. @2:
  661.   pop  bp
  662.   pop  bx
  663. end;
  664.  
  665. {**********************************************************}
  666.  
  667. begin
  668.   CurVideoMode  := Lo(LastMode);
  669.   CurScreenRows := Integer(ScreenHeight);
  670.   CurScreenCols := Integer(ScreenWidth);
  671. end.
  672.