home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best Objectech Shareware Selections
/
UNTITLED.iso
/
boss
/
grap
/
util
/
015
/
svga256.asm
< prev
next >
Wrap
Assembly Source File
|
1993-03-07
|
17KB
|
614 lines
;****************************************************************************
;*
;* SuperVGA Test Library
;*
;* Copyright (C) 1993 Kendall Bennett.
;* All rights reserved.
;*
;* Filename: $RCSfile: svga256.asm $
;* Version: $Revision: 1.2 $
;*
;* Language: 80386 Assembler
;* Environment: IBM PC (MS DOS)
;*
;* Description: This source file contains code to initialise the SuperVGA
;* for bank switching and extended page flipping.
;*
;* It also contains code to draw pixels, clear the display
;* and perform page flipping for SuperVGA 256 color modes.
;*
;* $Id: svga256.asm 1.2 1993/03/07 04:05:36 kjb Exp $
;*
;* Revision History:
;* -----------------
;*
;* $Log: svga256.asm $
;* Revision 1.2 1993/03/07 04:05:36 kjb
;* Bug fixes.
;*
;* Revision 1.1 1993/03/03 10:26:38 kjb
;* Initial revision
;*
;****************************************************************************
IDEAL
JUMPS
P386 ; Use 386 instructions
INCLUDE "model.mac" ; Memory model macros
header init
INCLUDE "MGRAPH.EQU" ; Include Equates for Mgraph Routines
CRTC EQU 3D4h ; Port of CRTC registers
VGABufferSeg EQU 0A000h ; Segment of VGA display memory
FIRSTMODE EQU grVGA_320x200x256
MAXMODE EQU grSVGA_1280x1024x256
begcodeseg svga256
; Globals used by driver
OldBIOSMode db 0 ; Old video mode before graphics
Old50Lines db 0 ; 1 if old mode was 50 line VGA
CntDriver dw 0 ; Graphics driver number
CntMode dw 0 ; Graphics mode number
CntChipID dw 0 ; Graphics driver chip ID
CntColors dw gr256Color ; This is a 256 color driver
; The following information held in the status status area changes depending
; on which mode the driver is set up to be used in:
StatusArea:
XRes dw 0 ; Device resolution in x direction - 1
YRes dw 0 ; Device resolution in y direction - 1
BytesPerLine dw 0 ; Number of bytes in a line
PageSize dd 0 ; Graphics page size
MaxPage dw 0 ; Maximum number of video pages
OriginOffset dw 0 ; Offset of 0,0 into buffer
; Here we set up a series of tables that can be used to fill in the start of
; the status area for each mode supported by this driver, and the address's
; of the routines required for each particular driver mode:
ModeTabStart:
ModeVGA_320x200: dw 319 ; XRes
dw 199 ; YRes
dw 320 ; BytesPerLine
ModeSVGA_640x350: dw 639 ; XRes
dw 349 ; YRes
dw 640 ; BytesPerLine
ModeSVGA_640x400: dw 639 ; XRes
dw 399 ; YRes
dw 640 ; BytesPerLine
ModeSVGA_640x480: dw 639 ; XRes
dw 479 ; YRes
dw 640 ; BytesPerLine
ModeSVGA_800x600: dw 799 ; XRes
dw 599 ; YRes
dw 800 ; BytesPerLine
ModeSVGA_1024x768: dw 1023 ; XRes
dw 767 ; YRes
dw 1024 ; BytesPerLine
ModeSVGA_1280x1024: dw 1279 ; XRes
dw 1023 ; YRes
dw 1280 ; BytesPerLine
ModeTabSize = ($-ModeSVGA_1280x1024) ; Size of table in bytes
INCLUDE "SV_PORTS.ASM"
INCLUDE "SV_BANKS.ASM"
INCLUDE "SV_MODES.ASM"
INCLUDE "SV_PAGE.ASM"
INCLUDE "SV_MAXPG.ASM"
;----------------------------------------------------------------------------
; int _initSuperVGA(int driver,int chipID,int mode,int memory)
;----------------------------------------------------------------------------
; Routine to initialise the bank switching code for the SuperVGA, and setup
; internal tables of information about the video mode. If the video mode
; is not supported, we return -1.
;
; The value returned is a status number, where bit 0 represents extended
; page flipping is available, bit 1 that separate read/write banks are
; available.
;----------------------------------------------------------------------------
procstart __initSuperVGA
ARG driver:WORD, ChipID:WORD, mode:WORD, memory:WORD
enter 0,0
push si
push di
; Save the driver number and chip ID for later
mov ax,[ChipID]
mov [CntChipID],ax
mov ax,[driver]
mov [CntDriver],ax
; Load the Status area with info for the currently selected mode:
mov ax,[mode]
mov [CntMode],ax
cmp ax,MAXMODE ; AX := desired mode
jg @@Invalid ; invalid if greater than maximum
cmp ax,FIRSTMODE
jl @@Invalid ; invalid if less than first mode
cmp ax,grVGA_320x200x256
je @@ValidVGAMode
cmp ax,grSVGA_640x350x256
jl @@Invalid ; Mode is invalid
sub ax,grSVGA_640x350x256 - 1
jmp @@LoadValues
@@ValidVGAMode:
sub ax,FIRSTMODE
@@LoadValues:
mov cx,ModeTabSize ; Put size of table into cx
mul cl ; AX := Mode * ModeTabSize
mov si,ax
lea si,[ModeTabStart + si]
push cs
pop es ; Set up es to point to code seg
lea di,[StatusArea] ; DI := Start of status area
cld
rep movs [BYTE es:di],[BYTE es:si]
mov ax,[driver]
mov bx,[mode]
call loadSVGAMode ; Load the SuperVGA video mode
or ax,ax
jz @@Invalid ; Mode not supported on this adapter!
mov [maxpage],0 ; Clear maxpage variable
call SetupBanks ; Setup SuperVGA bank switching
call [InitSVGA] ; Initialise the SuperVGA
call SetupPaging ; Setup SuperVGA page flipping
mov ax,0 ; Assume no paging available
jc @@Done ; Extended page flipping not available
; Determine the number of pages available for the mode and the video page
; size.
xor ebx,ebx
mov bx,[memory]
shl ebx,10 ; EBX := video memory in bytes
mov ax,[mode]
call numPages ; Calculate the number of video pages
dec ax
mov [MaxPage],ax ; Save maximum page number
mov [DWORD pageSize],ebx
mov [WORD bytesPerLine],cx
mov ax,1 ; Extended paging is available
@@Done:
mov bx,[TwoBanks]
shl bx,1
or ax,bx ; Set the two banks flag
jmp @@Exit
@@Invalid:
mov ax,-1 ; Return failure!
@@Exit:
pop di
pop si
leave
ret
procend __initSuperVGA
;----------------------------------------------------------------------------
; int _setSuperVGAMode(void);
;----------------------------------------------------------------------------
; Routine sets the system into the SuperVGA graphics mode setup by the
; initSuperVGA routine. Note that this routine remembers if the EGA/VGA
; 43/50 line mode was set.
;
; If the video mode was not correctly set, we return false.
;----------------------------------------------------------------------------
procstart __setSuperVGAMode
push bp ; INT 10h Kills this!!!
push si ; so save all regs...
push di
push ds
mov ah,0Fh ; Get current video mode service
int 10h
mov [OldBIOSMode],al ; Save old video mode
mov [Old50Lines],0 ; Default to non-50 line mode
mov ax,1130h ; AH := INT 10h function number
; AL := Get character gen information
mov bh,00 ; Get contents of INT 1Fh
xor dl,dl ; Clear dl
int 10h ; Determine number of lines (in dl)
cmp dl,49 ; 50 line mode?
jne @@SetMode ; No, must have been 25 lines
mov [Old50Lines],1 ; Yes, 50 line mode was on
@@SetMode:
mov ax,[CntDriver]
mov bx,[CntMode]
call loadSVGAMode ; AX,BX := correct values for mode
int 10h ; Set the video mode
mov ax,40h
mov es,ax
xor ax,ax
cmp [BYTE es:49h],3 ; Mode is still text mode, did not set
jbe @@Exit
call [InitSVGA] ; Initialise bank switching on SuperVGA's
mov ax,1 ; Mode was correctly set
@@Exit:
pop ds
pop di ; Restore regs
pop si
pop bp ; Restore bp (after INT 10 trashes it)
ret
procend __setSuperVGAMode
;----------------------------------------------------------------------------
; void restoreMode(void)
;----------------------------------------------------------------------------
; Routine restores the original video mode that was set before graphics mode
; was entered.
;----------------------------------------------------------------------------
procstart _restoreMode
push bp ; INT 10h kills bp sometimes
push si ; Save all regs...
push di
call [ExitSVGA] ; Uninitialise the S