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

  1. {*********************************************************}
  2. {*                   TSSVGA.PAS 1.00                     *}
  3. {*        Copyright (c) T P Systems, Inc. 1994.          *}
  4. {*                  All rights reserved.                 *}
  5. {*********************************************************}
  6.  
  7. (*  Implements VESA Super VGA Standard VS891101 and other Int 10 routines *)
  8.  
  9. {$A-,B-,E+,F+,I-,N-,O+,R-,S-,V-,X+}
  10.  
  11. Unit TSSVGA;
  12.  
  13. interface
  14.  
  15. uses
  16.   OpConst,
  17.   OpString,
  18.   OpCrt,
  19.   TsVga;
  20.  
  21. const
  22.   VesaSignature = $41534556;        {'VESA' in reverse order}
  23.   VesaFunc      = $4F;
  24.  
  25.   {new error codes}
  26.   ecVesaNotSupported     = 3990;
  27.   ecVesaFuncFailed       = 3991;
  28.   ecVesaModeNotSupported = 3992;
  29.  
  30. type
  31.  
  32.   EnhDisplayType = (eEGA, eVGA, eVESA);
  33.  
  34.   ModeNumTablePtr = ^ModeNumTable;
  35.   ModeNumTable = array[1..1024] of word; {valid list terminated with $FFFF}
  36.  
  37.   VgaInfoBlockPtr = ^VgaInfoBlock;
  38.   VgaInfoBlock = record
  39.     viSign       : longint;
  40.     viVer        : word;
  41.     viOEMStr     : PChar;
  42.     viCapability : longint;  {all bits are reserved and not yet defined}
  43.     viModes      : ModeNumTablePtr;
  44.     viReserved   : array[1..238] of byte;
  45.   end;
  46.  
  47.   WindowId = (WinA, WinB);
  48.   WinGranUnits = word;          {smallest boundary in KB of video mem for win}
  49.   SvgaWinProc = procedure;
  50.  
  51.   ModeInfoBlockPtr = ^ModeInfoBlock;
  52.   ModeInfoBlock = record
  53.     {mandatory}
  54.     miModeAttrs        : word;  {bit masks defined below}
  55.     miWinAAttrs        : byte;  {bit masks defined below}
  56.     miWinBAttrs        : byte;  {bit masks defined below}
  57.     miWinGranularity   : WinGranUnits;
  58.     miWinSize          : word;  {size of window in KB}
  59.     miWinASeg          : word;  {segment address of windows}
  60.     miWinBSeg          : word;
  61.     miWinProc          : SvgaWinProc; {addr of windowing function}
  62.     miBytesPerScanLine : word;  {number of bytes per logical scan line}
  63.     {optional -- present if bit 1 of miModeAttrs is set}
  64.     {unfortunately most VESA implementations do not return the optional data}
  65.     miXResolution      : word;  {screen width: pixels for graph, chars for text}
  66.     miYResolution      : word;  {screen height}
  67.     miXFontSize        : byte;  {width of character cell in pixels}
  68.     miYFontSize        : byte;  {height of character cell}
  69.     miNumPlanes        : byte;  {number of memory planes}
  70.     miBitsPerPixel     : byte;  {number of bits that define color of a pixel}
  71.     miNumBanks         : byte;  {number of banks in which scan lines grouped}
  72.     miMemoryModel      : byte;  {see mmConstants below}
  73.     miBankSize         : byte;  {in kBytes}
  74.     miReserved         : array[1..227] of byte;
  75.   end;
  76.  
  77. const
  78.   {miModeAttr Masks}
  79.   miHardwareSupport    = $0001;
  80.   miOptDataAvail       = $0002;
  81.   miBIOSOutputSupport  = $0004;
  82.   miColorMode          = $0008;
  83.   miGraphicsMode       = $0010;
  84.  
  85.   {miWinXattrs Masks}
  86.   miWindowSupport      = $0001;
  87.   miWindowReadable     = $0002;
  88.   miWindowWriteable    = $0004;
  89.  
  90.   {miMemoryModel Constants}
  91.   mmText               = $00;
  92.   mmCGAGraph           = $01;
  93.   mmHercGraph          = $02;
  94.   mm4PlanePlanar       = $03;
  95.   mmPackedPixel        = $04;
  96.   mmNonChain           = $05;
  97.   {reserved for VESA $06..$0F}
  98.   {reserved for OEM  $10..$FF}
  99.  
  100.   MonoCrtcAddr         = $03B4;
  101.   ColorCrtcAddr        = $03D4;
  102.  
  103.   StdSvgaModes : ScreenModeArray = (
  104.     (smVidMode:$100; smFontSize: 16; smRows: 25; smCols: 80; smIsText: false;
  105.      smPixW: 640; smPixH: 400; smColors:256),
  106.     (smVidMode:$101; smFontSize: 16; smRows: 30; smCols: 80; smIsText: false;
  107.      smPixW: 640; smPixH: 480; smColors:256),
  108.     (smVidMode:$102; smFontSize: 16; smRows: 37; smCols:100; smIsText: false;
  109.      smPixW: 800; smPixH: 600; smColors: 16),
  110.     (smVidMode:$103; smFontSize: 16; smRows: 37; smCols:100; smIsText: false;
  111.      smPixW: 800; smPixH: 600; smColors:256),
  112.     (smVidMode:$104; smFontSize: 16; smRows: 48; smCols:128; smIsText: false;
  113.      smPixW:1024; smPixH: 768; smColors: 16),
  114.     (smVidMode:$105; smFontSize: 16; smRows: 48; smCols:128; smIsText: false;
  115.      smPixW:1024; smPixH: 768; smColors:256),
  116.     (smVidMode:$106; smFontSize: 16; smRows: 64; smCols:160; smIsText: false;
  117.      smPixW:1280; smPixH:1024; smColors: 16),
  118.     (smVidMode:$108; smFontSize:  8; smRows: 60; smCols: 80; smIsText: true;
  119.      smPixW: 720; smPixH: 480; smColors: 16),
  120.     (smVidMode:$109; smFontSize: 14; smRows: 25; smCols:132; smIsText: true;
  121.      smPixW:1056; smPixH: 350; smColors: 16),
  122.     (smVidMode:$10A; smFontSize:  8; smRows: 43; smCols:132; smIsText: true;
  123.      smPixW:1056; smPixH: 350; smColors: 16));
  124.  
  125. function ReturnSvgaInfo(VI: VgaInfoBlockPtr): word;
  126.   {-Returns status 0 if successful and VgaInfoBlock filled in or if fails,
  127.     returns ecVesaNotSupported or ecVesaFuncFailed.}
  128.  
  129. function FindSvgaMode(Mode: word; ModeTable: ModeNumTablePtr): boolean;
  130.   {-Searches ModeTable which is returned by ReturnSvgaInfo for Mode.  If
  131.     found returns true.}
  132.  
  133. function ReturnSvgaModeInfo(Mode: word; MI: ModeInfoBlockPtr): word;
  134.   {-Returns status 0 if successful and ModeInfoBlock filled in or if fails,
  135.     returns ecVesaNotSupported or ecVesaFuncFailed.}
  136.  
  137. function SetSvgaMode(Mode: word; Clear: boolean): word;
  138.   {-Sets SVGA mode and clears video memory if Clear = true.  Returns standard
  139.     VESA status.}
  140.  
  141. function ReturnCurSvgaMode(var Mode: word): word;
  142.   {-Returns status and current video mode in Mode.  Bit 7 of Mode is always
  143.     clear.  If you want to get whether the video memory was cleared or not,
  144.     you must use Int 10 standard function 0F.}
  145.  
  146. function ReturnSvgaSaveBufferSize(var Size: word; States: word): word;
  147.   {-Returns status and size of save state buffer in Size (in bytes).  Must be
  148.     called before SaveSvgaState to get size of required buffer. States is
  149.     bit mapped to indicate which states are to be saved.  See bit masks
  150.     in VGA.PAS.}
  151.  
  152. function SaveSvgaState(Buf: pointer; States: word): word;
  153.   {-Returns status of saving video states specified in States.  Buf points
  154.     to a save buffer of size determined by ReturnSaveBufferSize. No checking
  155.     that Buf points to area large enough. States must be same as used in
  156.     ReturnSaveBufferSize.}
  157.  
  158. function RestoreSvgaState(Buf: pointer; States: word): word;
  159.   {-Returns status of restoring video states specified in States.  Buf must
  160.     point to buffer that was previously saved with SaveSvgaState and States
  161.     must be same as used previously.}
  162.  
  163. function ReturnCpuVideoMemoryWindow(Window: WindowId;
  164.                                     var Position: WinGranUnits): word;
  165.   {-Returns status and Position of specified window.  See VESA spec for details
  166.     of usage.}
  167.  
  168. function SelectCpuVideoMemoryWindow(Window: WindowId;
  169.                                     Position: WinGranUnits): word;
  170.   {-Returns status of selecting specified window at Position returned by
  171.     ReturnCpuVideoMemoryWindow.}
  172.  
  173. procedure DirReturnCpuVideoMemoryWindow(Window: WindowId;
  174.                                         var Position: WinGranUnits;
  175.                                         WinProc : SvgaWinProc);
  176.   {-Similar to non-direct functions above, but makes direct far call to
  177.     WinProc returned by ReturnSvgaModeInfo above.  Does not return status,
  178.     but returns Position of specified window.  See VESA spec for details
  179.     of usage.}
  180.  
  181. procedure DirSelectCpuVideoMemoryWindow(Window: WindowId;
  182.                                         Position: WinGranUnits;
  183.                                         WinProc : SvgaWinProc);
  184.   {-Similar to non-direct functions above, but makes direct far call to
  185.     WinProc returned by ReturnSvgaModeInfo above.  Does not return status.
  186.     See VESA spec for details of usage.}
  187.  
  188. {**********************************************************}
  189.  
  190. implementation
  191.  
  192. type
  193.   OS = record
  194.     O, S : word;
  195.   end;
  196.  
  197. procedure SetStatus; assembler;
  198. asm
  199.   cmp  al,VesaFunc
  200.   je   @1
  201.   mov  ax,ecVesaNotSupported
  202.   jmp  @3
  203. @1:
  204.   cmp  ah,0
  205.   je   @2
  206.   mov  ax,ecVesaFuncFailed
  207.   jmp  @3
  208. @2:
  209.   xor  ax,ax
  210. @3:
  211. end;
  212.  
  213.  
  214. function ReturnSvgaInfo(VI: VgaInfoBlockPtr): word; assembler;
  215.   {-Returns status 0 if successful and VgaInfoBlock filled in or if fails,
  216.     returns ecVesaNotSupported or ecVesaFuncFailed.}
  217. asm
  218.   push es
  219.   push di
  220.   mov  ah,VesaFunc
  221.   mov  al,0
  222.   mov  di,OS(VI).S
  223.   mov  es,di
  224.   mov  di,OS(VI).O
  225.   int  $10
  226.   call SetStatus
  227.   pop  di
  228.   pop  es
  229. end;
  230.  
  231. function FindSvgaMode(Mode: word; ModeTable: ModeNumTablePtr): boolean;
  232.   {-Searches ModeTable which is returned by ReturnSvgaInfo for Mode.  If
  233.     found returns true.}
  234. var
  235.   M : word;
  236.   i : word;
  237. begin
  238.   i := 1;
  239.   M := ModeTable^[i];
  240.   while (M <> $FFFF) and (i < 1024) do begin
  241.     if M = Mode then begin
  242.       FindSvgaMode := true;
  243.       Exit;
  244.     end;
  245.     inc(i);
  246.     M := ModeTable^[i];
  247.   end;
  248.   FindSvgaMode := false;
  249. end;
  250.  
  251. function ReturnSvgaModeInfo(Mode: word; MI: ModeInfoBlockPtr): word; assembler;
  252.   {-Returns status 0 if successful and ModeInfoBlock filled in or if fails,
  253.     returns ecVesaNotSupported or ecVesaFuncFailed. Will return
  254.     ecVesaFuncFailed if Mode is not a VESA SVGA mode.}
  255. asm
  256.   push cx
  257.   push es
  258.   push di
  259.   mov  di,OS(MI).S
  260.   mov  es,di
  261.   mov  di,OS(MI).O
  262.   mov  cx,Mode
  263.   mov  ah,VesaFunc
  264.   mov  al,1
  265.   int  $10
  266.   call SetStatus
  267.   pop  di
  268.   pop  es
  269.   pop  cx
  270. end;
  271.  
  272. function SetSvgaMode(Mode: word; Clear: boolean): word; assembler;
  273.   {-Sets SVGA mode and clears video memory if Clear = true.  Returns standard
  274.     VESA status. Contrary to what the VESA standard implies some
  275.     implementations apparently will fail if mode is not a VESA SVGA mode.
  276.     Thus this one makes a check on the mode and uses Int 10 function 0 if
  277.     mode is less than $100.}
  278. asm
  279.   push bx
  280.   cmp  Mode,$100        {is it a VESA SVGA mode}
  281.   jb   @1               {no so use standard function}
  282.   mov  bx,Mode
  283.   and  bx,$7FFF
  284.   xor  al,al
  285.   mov  ah,Clear
  286.   xor  ah,1
  287.   ror  ah,1
  288.   or   bx,ax
  289.   mov  ah,VesaFunc
  290.   mov  al,2
  291.   int  $10
  292.   call SetStatus
  293.   jmp  @2
  294. @1:
  295.   mov  ax,Mode
  296.   mov  ah,Clear
  297.   xor  ah,1
  298.   ror  ah,1
  299.   or   al,ah
  300.   xor  ah,ah
  301.   int  $10
  302.   xor  ax,ax
  303. @2:
  304.   pop  bx
  305. end;
  306.  
  307.  
  308. function ReturnCurSvgaMode(var Mode: word): word; assembler;
  309.   {-Returns status and current video mode in Mode.  Bit 7 of Mode is always
  310.     clear.  If you want to get whether the video memory was cleared or not,
  311.     you must use Int 10 standard function 0F.}
  312. asm
  313.   push bx
  314.   push si
  315.   push ds
  316.   mov  ah,VesaFunc
  317.   mov  al,3
  318.   int  $10
  319.   lds  si,Mode
  320.   mov  word ptr [si],bx
  321.   call SetStatus
  322.   pop  ds
  323.   pop  si
  324.   pop  bx
  325. end;
  326.  
  327. function ReturnSvgaSaveBufferSize(var Size: word; States: word): word; assembler;
  328.   {-Returns status and size of save state buffer in Size (in bytes).  Must be
  329.     called before SaveSvgaState to get size of required buffer. States is
  330.     bit mapped to indicate which states are to be saved.  See bit masks above.}
  331. asm
  332.   push bx
  333.   push cx
  334.   push dx
  335.   push si
  336.   push ds
  337.   mov  ah,VesaFunc
  338.   mov  al,4
  339.   mov  cx,States
  340.   mov  dl,0
  341.   int  $10
  342.   lds  si,Size
  343.   shl  bx,1          {bx returns size in 64 byte blocks}
  344.   shl  bx,1
  345.   shl  bx,1
  346.   shl  bx,1
  347.   shl  bx,1
  348.   shl  bx,1
  349.   mov  word ptr [si],bx
  350.   call SetStatus
  351.   pop  ds
  352.   pop  si
  353.   pop  dx
  354.   pop  cx
  355.   pop  bx
  356. end;
  357.  
  358. function SaveSvgaState(Buf: pointer; States: word): word; assembler;
  359.   {-Returns status of saving video states specified in States.  Buf points
  360.     to a save buffer of size determined by ReturnSaveBufferSize. No checking
  361.     that Buf points to area large enough. States must be same as used in
  362.     ReturnSaveBufferSize. Should be followed by RestoreSvgaState since
  363.     Phoenix AT Systems BIOS reference says saving modifies the video registers}
  364. asm
  365.   push bx
  366.   push cx
  367.   push dx
  368.   push es
  369.   mov  ah,VesaFunc
  370.   mov  al,4
  371.   mov  dl,1
  372.   mov  cx,States
  373.   mov  es,OS(Buf).S
  374.   mov  bx,OS(Buf).O
  375.   int  $10
  376.   call SetStatus
  377.   pop  es
  378.   pop  dx
  379.   pop  cx
  380.   pop  bx
  381. end;
  382.  
  383. function RestoreSvgaState(Buf: pointer; States: word): word; assembler;
  384.   {-Returns stats of restoring video states specified in States.  Buf must
  385.     point to buffer that was previously saved with SaveSvgaState and States
  386.     must be same as used previously.}
  387. asm
  388.   push bx
  389.   push cx
  390.   push dx
  391.   push es
  392.   mov  ah,VesaFunc
  393.   mov  al,4
  394.   mov  dl,2
  395.   mov  cx,States
  396.   mov  es,OS(Buf).S
  397.   mov  bx,OS(Buf).O
  398.   int  $10
  399.   call SetStatus
  400.   pop  es
  401.   pop  dx
  402.   pop  cx
  403.   pop  bx
  404. end;
  405.  
  406. function ReturnCpuVideoMemoryWindow(Window: WindowId;
  407.                                     var Position: WinGranUnits): word; assembler;
  408.   {-Returns status and Position of specified window.  See VESA spec for details
  409.     of usage.}
  410. asm
  411.   push bx
  412.   push dx
  413.   push si
  414.   push ds
  415.   mov  ah,VesaFunc
  416.   mov  al,5
  417.   mov  bh,1
  418.   mov  bl,Window
  419.   int  $10
  420.   lds  si,Position
  421.   mov  word ptr [si],dx
  422.   call SetStatus
  423.   pop  ds
  424.   pop  si
  425.   pop  dx
  426.   pop  bx
  427. end;
  428.  
  429. function SelectCpuVideoMemoryWindow(Window: WindowId;
  430.                                     Position: WinGranUnits): word; assembler;
  431.   {-Returns status of selecting specified window at Position returned by
  432.     ReturnCpuVideoMemoryWindow.}
  433. asm
  434.   push bx
  435.   push dx
  436.   mov  ah,VesaFunc
  437.   mov  al,5
  438.   mov  bh,0
  439.   mov  bl,Window
  440.   mov  dx,Position
  441.   int  $10
  442.   call SetStatus
  443.   pop  dx
  444.   pop  bx
  445. end;
  446.  
  447. procedure DirReturnCpuVideoMemoryWindow(Window: WindowId;
  448.                                         var Position: WinGranUnits;
  449.                                         WinProc : SvgaWinProc); assembler;
  450.   {-Similar to non-direct functions above, but makes direct far call to
  451.     WinProc returned by ReturnSvgaModeInfo above.  Does not return status,
  452.     but returns Position of specified window.  See VESA spec for details
  453.     of usage.}
  454. asm
  455.   push ax
  456.   push bx
  457.   push dx
  458.   push si
  459.   push ds
  460.   mov  bh,1
  461.   mov  bl,Window
  462.   call WinProc
  463.   lds  si,Position
  464.   mov  word ptr [si],dx
  465.   pop  ds
  466.   pop  si
  467.   pop  dx
  468.   pop  bx
  469.   pop  ax
  470. end;
  471.  
  472. procedure DirSelectCpuVideoMemoryWindow(Window: WindowId;
  473.                                         Position: WinGranUnits;
  474.                                         WinProc : SvgaWinProc); assembler;
  475.   {-Similar to non-direct functions above, but makes direct far call to
  476.     WinProc returned by ReturnSvgaModeInfo above.  Does not return status.
  477.     See VESA spec for details of usage.}
  478. asm
  479.   push ax
  480.   push bx
  481.   push dx
  482.   mov  bh,0
  483.   mov  bl,Window
  484.   mov  dx,Position
  485.   call WinProc
  486.   pop  dx
  487.   pop  bx
  488.   pop  ax
  489. end;
  490.  
  491. {**********************************************************}
  492.  
  493. end.
  494.