home *** CD-ROM | disk | FTP | other *** search
- {*********************************************************}
- {* TSSVGA.PAS 1.00 *}
- {* Copyright (c) T P Systems, Inc. 1994. *}
- {* All rights reserved. *}
- {*********************************************************}
-
- (* Implements VESA Super VGA Standard VS891101 and other Int 10 routines *)
-
- {$A-,B-,E+,F+,I-,N-,O+,R-,S-,V-,X+}
-
- Unit TSSVGA;
-
- interface
-
- uses
- OpConst,
- OpString,
- OpCrt,
- TsVga;
-
- const
- VesaSignature = $41534556; {'VESA' in reverse order}
- VesaFunc = $4F;
-
- {new error codes}
- ecVesaNotSupported = 3990;
- ecVesaFuncFailed = 3991;
- ecVesaModeNotSupported = 3992;
-
- type
-
- EnhDisplayType = (eEGA, eVGA, eVESA);
-
- ModeNumTablePtr = ^ModeNumTable;
- ModeNumTable = array[1..1024] of word; {valid list terminated with $FFFF}
-
- VgaInfoBlockPtr = ^VgaInfoBlock;
- VgaInfoBlock = record
- viSign : longint;
- viVer : word;
- viOEMStr : PChar;
- viCapability : longint; {all bits are reserved and not yet defined}
- viModes : ModeNumTablePtr;
- viReserved : array[1..238] of byte;
- end;
-
- WindowId = (WinA, WinB);
- WinGranUnits = word; {smallest boundary in KB of video mem for win}
- SvgaWinProc = procedure;
-
- ModeInfoBlockPtr = ^ModeInfoBlock;
- ModeInfoBlock = record
- {mandatory}
- miModeAttrs : word; {bit masks defined below}
- miWinAAttrs : byte; {bit masks defined below}
- miWinBAttrs : byte; {bit masks defined below}
- miWinGranularity : WinGranUnits;
- miWinSize : word; {size of window in KB}
- miWinASeg : word; {segment address of windows}
- miWinBSeg : word;
- miWinProc : SvgaWinProc; {addr of windowing function}
- miBytesPerScanLine : word; {number of bytes per logical scan line}
- {optional -- present if bit 1 of miModeAttrs is set}
- {unfortunately most VESA implementations do not return the optional data}
- miXResolution : word; {screen width: pixels for graph, chars for text}
- miYResolution : word; {screen height}
- miXFontSize : byte; {width of character cell in pixels}
- miYFontSize : byte; {height of character cell}
- miNumPlanes : byte; {number of memory planes}
- miBitsPerPixel : byte; {number of bits that define color of a pixel}
- miNumBanks : byte; {number of banks in which scan lines grouped}
- miMemoryModel : byte; {see mmConstants below}
- miBankSize : byte; {in kBytes}
- miReserved : array[1..227] of byte;
- end;
-
- const
- {miModeAttr Masks}
- miHardwareSupport = $0001;
- miOptDataAvail = $0002;
- miBIOSOutputSupport = $0004;
- miColorMode = $0008;
- miGraphicsMode = $0010;
-
- {miWinXattrs Masks}
- miWindowSupport = $0001;
- miWindowReadable = $0002;
- miWindowWriteable = $0004;
-
- {miMemoryModel Constants}
- mmText = $00;
- mmCGAGraph = $01;
- mmHercGraph = $02;
- mm4PlanePlanar = $03;
- mmPackedPixel = $04;
- mmNonChain = $05;
- {reserved for VESA $06..$0F}
- {reserved for OEM $10..$FF}
-
- MonoCrtcAddr = $03B4;
- ColorCrtcAddr = $03D4;
-
- StdSvgaModes : ScreenModeArray = (
- (smVidMode:$100; smFontSize: 16; smRows: 25; smCols: 80; smIsText: false;
- smPixW: 640; smPixH: 400; smColors:256),
- (smVidMode:$101; smFontSize: 16; smRows: 30; smCols: 80; smIsText: false;
- smPixW: 640; smPixH: 480; smColors:256),
- (smVidMode:$102; smFontSize: 16; smRows: 37; smCols:100; smIsText: false;
- smPixW: 800; smPixH: 600; smColors: 16),
- (smVidMode:$103; smFontSize: 16; smRows: 37; smCols:100; smIsText: false;
- smPixW: 800; smPixH: 600; smColors:256),
- (smVidMode:$104; smFontSize: 16; smRows: 48; smCols:128; smIsText: false;
- smPixW:1024; smPixH: 768; smColors: 16),
- (smVidMode:$105; smFontSize: 16; smRows: 48; smCols:128; smIsText: false;
- smPixW:1024; smPixH: 768; smColors:256),
- (smVidMode:$106; smFontSize: 16; smRows: 64; smCols:160; smIsText: false;
- smPixW:1280; smPixH:1024; smColors: 16),
- (smVidMode:$108; smFontSize: 8; smRows: 60; smCols: 80; smIsText: true;
- smPixW: 720; smPixH: 480; smColors: 16),
- (smVidMode:$109; smFontSize: 14; smRows: 25; smCols:132; smIsText: true;
- smPixW:1056; smPixH: 350; smColors: 16),
- (smVidMode:$10A; smFontSize: 8; smRows: 43; smCols:132; smIsText: true;
- smPixW:1056; smPixH: 350; smColors: 16));
-
- function ReturnSvgaInfo(VI: VgaInfoBlockPtr): word;
- {-Returns status 0 if successful and VgaInfoBlock filled in or if fails,
- returns ecVesaNotSupported or ecVesaFuncFailed.}
-
- function FindSvgaMode(Mode: word; ModeTable: ModeNumTablePtr): boolean;
- {-Searches ModeTable which is returned by ReturnSvgaInfo for Mode. If
- found returns true.}
-
- function ReturnSvgaModeInfo(Mode: word; MI: ModeInfoBlockPtr): word;
- {-Returns status 0 if successful and ModeInfoBlock filled in or if fails,
- returns ecVesaNotSupported or ecVesaFuncFailed.}
-
- function SetSvgaMode(Mode: word; Clear: boolean): word;
- {-Sets SVGA mode and clears video memory if Clear = true. Returns standard
- VESA status.}
-
- function ReturnCurSvgaMode(var Mode: word): word;
- {-Returns status and current video mode in Mode. Bit 7 of Mode is always
- clear. If you want to get whether the video memory was cleared or not,
- you must use Int 10 standard function 0F.}
-
- function ReturnSvgaSaveBufferSize(var Size: word; States: word): word;
- {-Returns status and size of save state buffer in Size (in bytes). Must be
- called before SaveSvgaState to get size of required buffer. States is
- bit mapped to indicate which states are to be saved. See bit masks
- in VGA.PAS.}
-
- function SaveSvgaState(Buf: pointer; States: word): word;
- {-Returns status of saving video states specified in States. Buf points
- to a save buffer of size determined by ReturnSaveBufferSize. No checking
- that Buf points to area large enough. States must be same as used in
- ReturnSaveBufferSize.}
-
- function RestoreSvgaState(Buf: pointer; States: word): word;
- {-Returns status of restoring video states specified in States. Buf must
- point to buffer that was previously saved with SaveSvgaState and States
- must be same as used previously.}
-
- function ReturnCpuVideoMemoryWindow(Window: WindowId;
- var Position: WinGranUnits): word;
- {-Returns status and Position of specified window. See VESA spec for details
- of usage.}
-
- function SelectCpuVideoMemoryWindow(Window: WindowId;
- Position: WinGranUnits): word;
- {-Returns status of selecting specified window at Position returned by
- ReturnCpuVideoMemoryWindow.}
-
- procedure DirReturnCpuVideoMemoryWindow(Window: WindowId;
- var Position: WinGranUnits;
- WinProc : SvgaWinProc);
- {-Similar to non-direct functions above, but makes direct far call to
- WinProc returned by ReturnSvgaModeInfo above. Does not return status,
- but returns Position of specified window. See VESA spec for details
- of usage.}
-
- procedure DirSelectCpuVideoMemoryWindow(Window: WindowId;
- Position: WinGranUnits;
- WinProc : SvgaWinProc);
- {-Similar to non-direct functions above, but makes direct far call to
- WinProc returned by ReturnSvgaModeInfo above. Does not return status.
- See VESA spec for details of usage.}
-
- {**********************************************************}
-
- implementation
-
- type
- OS = record
- O, S : word;
- end;
-
- procedure SetStatus; assembler;
- asm
- cmp al,VesaFunc
- je @1
- mov ax,ecVesaNotSupported
- jmp @3
- @1:
- cmp ah,0
- je @2
- mov ax,ecVesaFuncFailed
- jmp @3
- @2:
- xor ax,ax
- @3:
- end;
-
-
- function ReturnSvgaInfo(VI: VgaInfoBlockPtr): word; assembler;
- {-Returns status 0 if successful and VgaInfoBlock filled in or if fails,
- returns ecVesaNotSupported or ecVesaFuncFailed.}
- asm
- push es
- push di
- mov ah,VesaFunc
- mov al,0
- mov di,OS(VI).S
- mov es,di
- mov di,OS(VI).O
- int $10
- call SetStatus
- pop di
- pop es
- end;
-
- function FindSvgaMode(Mode: word; ModeTable: ModeNumTablePtr): boolean;
- {-Searches ModeTable which is returned by ReturnSvgaInfo for Mode. If
- found returns true.}
- var
- M : word;
- i : word;
- begin
- i := 1;
- M := ModeTable^[i];
- while (M <> $FFFF) and (i < 1024) do begin
- if M = Mode then begin
- FindSvgaMode := true;
- Exit;
- end;
- inc(i);
- M := ModeTable^[i];
- end;
- FindSvgaMode := false;
- end;
-
- function ReturnSvgaModeInfo(Mode: word; MI: ModeInfoBlockPtr): word; assembler;
- {-Returns status 0 if successful and ModeInfoBlock filled in or if fails,
- returns ecVesaNotSupported or ecVesaFuncFailed. Will return
- ecVesaFuncFailed if Mode is not a VESA SVGA mode.}
- asm
- push cx
- push es
- push di
- mov di,OS(MI).S
- mov es,di
- mov di,OS(MI).O
- mov cx,Mode
- mov ah,VesaFunc
- mov al,1
- int $10
- call SetStatus
- pop di
- pop es
- pop cx
- end;
-
- function SetSvgaMode(Mode: word; Clear: boolean): word; assembler;
- {-Sets SVGA mode and clears video memory if Clear = true. Returns standard
- VESA status. Contrary to what the VESA standard implies some
- implementations apparently will fail if mode is not a VESA SVGA mode.
- Thus this one makes a check on the mode and uses Int 10 function 0 if
- mode is less than $100.}
- asm
- push bx
- cmp Mode,$100 {is it a VESA SVGA mode}
- jb @1 {no so use standard function}
- mov bx,Mode
- and bx,$7FFF
- xor al,al
- mov ah,Clear
- xor ah,1
- ror ah,1
- or bx,ax
- mov ah,VesaFunc
- mov al,2
- int $10
- call SetStatus
- jmp @2
- @1:
- mov ax,Mode
- mov ah,Clear
- xor ah,1
- ror ah,1
- or al,ah
- xor ah,ah
- int $10
- xor ax,ax
- @2:
- pop bx
- end;
-
-
- function ReturnCurSvgaMode(var Mode: word): word; assembler;
- {-Returns status and current video mode in Mode. Bit 7 of Mode is always
- clear. If you want to get whether the video memory was cleared or not,
- you must use Int 10 standard function 0F.}
- asm
- push bx
- push si
- push ds
- mov ah,VesaFunc
- mov al,3
- int $10
- lds si,Mode
- mov word ptr [si],bx
- call SetStatus
- pop ds
- pop si
- pop bx
- end;
-
- function ReturnSvgaSaveBufferSize(var Size: word; States: word): word; assembler;
- {-Returns status and size of save state buffer in Size (in bytes). Must be
- called before SaveSvgaState to get size of required buffer. States is
- bit mapped to indicate which states are to be saved. See bit masks above.}
- asm
- push bx
- push cx
- push dx
- push si
- push ds
- mov ah,VesaFunc
- mov al,4
- mov cx,States
- mov dl,0
- int $10
- lds si,Size
- shl bx,1 {bx returns size in 64 byte blocks}
- shl bx,1
- shl bx,1
- shl bx,1
- shl bx,1
- shl bx,1
- mov word ptr [si],bx
- call SetStatus
- pop ds
- pop si
- pop dx
- pop cx
- pop bx
- end;
-
- function SaveSvgaState(Buf: pointer; States: word): word; assembler;
- {-Returns status of saving video states specified in States. Buf points
- to a save buffer of size determined by ReturnSaveBufferSize. No checking
- that Buf points to area large enough. States must be same as used in
- ReturnSaveBufferSize. Should be followed by RestoreSvgaState since
- Phoenix AT Systems BIOS reference says saving modifies the video registers}
- asm
- push bx
- push cx
- push dx
- push es
- mov ah,VesaFunc
- mov al,4
- mov dl,1
- mov cx,States
- mov es,OS(Buf).S
- mov bx,OS(Buf).O
- int $10
- call SetStatus
- pop es
- pop dx
- pop cx
- pop bx
- end;
-
- function RestoreSvgaState(Buf: pointer; States: word): word; assembler;
- {-Returns stats of restoring video states specified in States. Buf must
- point to buffer that was previously saved with SaveSvgaState and States
- must be same as used previously.}
- asm
- push bx
- push cx
- push dx
- push es
- mov ah,VesaFunc
- mov al,4
- mov dl,2
- mov cx,States
- mov es,OS(Buf).S
- mov bx,OS(Buf).O
- int $10
- call SetStatus
- pop es
- pop dx
- pop cx
- pop bx
- end;
-
- function ReturnCpuVideoMemoryWindow(Window: WindowId;
- var Position: WinGranUnits): word; assembler;
- {-Returns status and Position of specified window. See VESA spec for details
- of usage.}
- asm
- push bx
- push dx
- push si
- push ds
- mov ah,VesaFunc
- mov al,5
- mov bh,1
- mov bl,Window
- int $10
- lds si,Position
- mov word ptr [si],dx
- call SetStatus
- pop ds
- pop si
- pop dx
- pop bx
- end;
-
- function SelectCpuVideoMemoryWindow(Window: WindowId;
- Position: WinGranUnits): word; assembler;
- {-Returns status of selecting specified window at Position returned by
- ReturnCpuVideoMemoryWindow.}
- asm
- push bx
- push dx
- mov ah,VesaFunc
- mov al,5
- mov bh,0
- mov bl,Window
- mov dx,Position
- int $10
- call SetStatus
- pop dx
- pop bx
- end;
-
- procedure DirReturnCpuVideoMemoryWindow(Window: WindowId;
- var Position: WinGranUnits;
- WinProc : SvgaWinProc); assembler;
- {-Similar to non-direct functions above, but makes direct far call to
- WinProc returned by ReturnSvgaModeInfo above. Does not return status,
- but returns Position of specified window. See VESA spec for details
- of usage.}
- asm
- push ax
- push bx
- push dx
- push si
- push ds
- mov bh,1
- mov bl,Window
- call WinProc
- lds si,Position
- mov word ptr [si],dx
- pop ds
- pop si
- pop dx
- pop bx
- pop ax
- end;
-
- procedure DirSelectCpuVideoMemoryWindow(Window: WindowId;
- Position: WinGranUnits;
- WinProc : SvgaWinProc); assembler;
- {-Similar to non-direct functions above, but makes direct far call to
- WinProc returned by ReturnSvgaModeInfo above. Does not return status.
- See VESA spec for details of usage.}
- asm
- push ax
- push bx
- push dx
- mov bh,0
- mov bl,Window
- mov dx,Position
- call WinProc
- pop dx
- pop bx
- pop ax
- end;
-
- {**********************************************************}
-
- end.