home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
windows
/
grafwk50.zip
/
VGA640.A86
< prev
next >
Wrap
Text File
|
1991-01-07
|
18KB
|
871 lines
COMMENT %
GRAPHIC WORKSHOP standard VGA, 640x480 screen driver
COPYRIGHT (C) 1990 ALCHEMY MINDWORKS INC.
VERSION 1.1
portions copyright (C) 1990 Gregory D. Weeks
permision granted for Alchemy Mindworks to distribute.
This driver was adapted from the skeletal driver
supplied with graphic workshop 3.4. It will drive
a standard VGA card to 320x480 and do the bitblits
in such a manner that it looks like a 640x480 screen
is available. Nothing is free. There really isn't
640 columns, but it still looks better than 320x200.
This driver is designed to be assembled with A86.
%
VERSION EQU 1 ;VERSION NUMBER
SUBVERSION EQU 1 ;SUBVERSION NUMBER
_AOFF EQU 6 ;STACK OFFSET
; these are the maximum possible screen sizes
TLI_WIDE EQU 640 ;maximum screen width in pixels
TLI_DEEP EQU 480 ;maximum screen depth in lines
TLI_SCREENSEG EQU 0A000H ;segment of tseng card video buffer
TLI_BYTES EQU 128 ;maximum width of planar modes in bytes
;THIS MACRO SELECTS AN EGA PLANE
EGAPLANE MACRO
MOV AL,2
MOV DX,03C4H
OUT DX,AL
INC DX
MOV AL,#1
OUT DX,AL
#EM
ORG 0000H ;ORIGIN FOR LOADABLE DRIVER
DB 'ALCHDRV2' ;SIGNATURE - DON'T CHANGE THIS
;THE FOLLOWING ARE THE POINTERS TO THE CALLABLE ROUTINES AND THE COMMON
;DATA. THE SEGMENTS ARE FILLED IN BY GRAPHIC WORKSHOP. DON'T CHANGE ANYTHING.
DISPATCH:
DW VGA_on ;FAR POINTER TO VGA MODE SELECT
DW ?
line_address DW VGA_line ;FAR POINTER TO VGA LINE DISPLAY
DW ?
DW VGA_off ;FAR POINTER TO VGA MODE DESELECT
DW ?
DW VGA_PALETTE ;FAR POINTER TO VGA PALETTE SET
DW ?
DW VGA_OVERSCAN ;FAR POINTER TO VGA OVERSCAN SET
DW ?
DW EGA_on ;FAR POINTER TO EGA MODE SELECT
DW ?
DW EGA_LINE ;FAR POINTER TO EGA LINE DISPLAY
DW ?
DW EGA_off ;FAR POINTER TO EGA MODE DESELECT
DW ?
DW EGA_PALETTE ;FAR POINTER TO EGA PALETTE SET
DW ?
DW MONO_on ;FAR POINTER TO MONO MODE SELECT
DW ?
DW MONO_FRAME ;FAR POINTER TO MONO PAGE DISPLAY
DW ?
DW MONO_LINE ;FAR POINTER TO MONO LINE DISPLAY
DW ?
DW MONO_off ;FAR POINTER TO MONO MODE DESELECT
DW ?
DW 0,0 ;NULL ONE
DW 0,0 ;NULL TWO
DW 0,0 ;NULL THREE
DW 0,0 ;NULL FOUR
V_VGAWIDE DW TLI_WIDE ;VGA SCREEN WIDTH
V_VGADEEP DW TLI_DEEP ;VGA SCREEN DEPTH
V_VGASCRNSEG DW TLI_SCREENSEG ;VGA SCREEN SEGMENT
V_EGAWIDE DW TLI_WIDE ;EGA SCREEN WIDTH
V_EGADEEP DW TLI_DEEP ;EGA SCREEN DEPTH
V_EGABYTES DW TLI_BYTES ;EGA SCREEN BYTES
V_EGASCRNSEG DW TLI_SCREENSEG ;EGA SCREEN SEGMENT
V_MONOWIDE DW TLI_WIDE ;MONO SCREEN WIDTH
V_MONODEEP DW TLI_DEEP ;MONO SCREEN DEPTH
V_MONOBYTES DW TLI_BYTES ;BYTE WIDTH ON MONOCHROME SCREEN
V_MONOSCRNSEG DW TLI_SCREENSEG ;MONOCHROME SCREEN SEGMENT
;THESE VERSION NUMBERS REFLECT THE DRIVER TEMPLATE VERSION AND THE
;VERSION OF THE DRIVER ITSELF. YOU CAN CHANGE THE SUBVERSION VALUE
;TO REFLECT CHANGES IN YOUR DRIVER. THE VERSION VALUE MUST REMAIN
;UNCHANGED OR GRAPHIC WORKSHOP MAY REJECT YOUR DRIVER.
DW VERSION
DW SUBVERSION
;THE DESCRIPTION APPEARS IN THE F10 "ABOUT" BOX IN GRAPHIC
;WORKSHOP WHEN AN EXTERNAL DRIVER IS BEING USED. IT CAN'T
;EXCEED 24 CHARACTERS AND MUST BE NULL TERMINATED
DB 'VGA in pseudo 640x480',0
Installed dw 00000h ; moniter,memory - descriptions at end of file
;THIS ROUTINE SELECTS THE VGA 256 COLOUR MODE
;THE HEIGHT AND WIDTH OF THE IMAGE ARE ON THE STACK - THESE
;MAY BE USEFUL IF YOU WANT TO PICK ONE OF SEVERAL AVAILABLE
;MODES BASED ON THE AREA OF THE PICTURE TO BE DISPLAYED
VGA_on:
push bp
mov bp,sp
push ds
mov ds,cs
mov ax,[bp+_AOFF] ; cols
mov bx,[bp+_AOFF+2] ; rows
mov si,VGA_mode
call pick_mode
mov V_VGAWIDE,ax
mov V_VGADEEP,bx
cmp cx,13h
je >l5
mov ax,Strange_line
mov line_address,ax
call Set_320x480Mode
mov ax,V_VGAWIDE
shr ax,1 ; width/4
shr ax,1
shr ax,1 ; every other column
mov cx,V_VGADEEP ;depth of screen in the current mode
sub dx,dx
mov si,SCREENTABLE
mov [si],dx
add si,2
dec cx
l2:
add dx,ax
mov [si],dx
add si,2
loop l2
jmp >l9
l5:
mov ax,cx
int 10h
mov ax,VGA_line
mov line_address,ax
mov cx,V_VGADEEP ;depth of screen in the current mode
sub dx,dx
mov si,SCREENTABLE
mov [si],dx
add si,2
dec cx
l2:
add dx,V_VGAWIDE
mov [si],dx
add si,2
loop l2
l9:
pop ds,bp
retf
Strange_line:
push bp
mov bp,sp
push ds
push es
mov si,[bp + _AOFF + 0] ;OFFSET OF SOURCE
mov ds,[bp + _AOFF + 2] ;SEGMENT OF SOURCE
mov bx,[bp + _AOFF + 6] ;GET LINE NUMBER
cmp bx,cs:V_VGADEEP
if ge jmp Strange_line_exit
shl bx,1
mov di,cs:[screentable + bx]
cld
mov cx,[bp + _AOFF + 4]
cmp cx,0
je Strange_line_exit
cmp cx,cs:V_VGAWIDE
jl >l1
mov cx,cs:V_VGAWIDE
l1:
mov ax,cs:V_VGASCRNSEG
mov es,ax
shr cx,1
shr cx,1
shr cx,1
EGAPLANE 1
push si,di,cx
l3:
movsb
add si,7
loop l3
EGAPLANE 2
pop cx,di,si
add si,2
push si,di,cx
l3:
movsb
add si,7
loop l3
EGAPLANE 4
pop cx,di,si
add si,2
push si,di,cx
l3:
movsb
add si,7
loop l3
EGAPLANE 8
pop cx,di,si
add si,2
l3:
movsb
add si,7
loop l3
EGAPLANE 0FH
Strange_line_exit:
pop es,ds,bp
retf
;THIS ROUTINE DISPLAYS A VGA LINE
;THE FIRST ARGUMENT ON THE STACK (2 WORDS) IS A FAR POINTER TO
;THE LINE. THE SECOND ARGUMENT IS THE LENGTH OF THE LINE IN PIXELS
VGA_line:
push bp
mov bp,sp
push ds
push es
mov si,[bp + _AOFF + 0] ;OFFSET OF SOURCE
mov ds,[bp + _AOFF + 2] ;SEGMENT OF SOURCE
mov bx,[bp + _AOFF + 6] ;GET LINE NUMBER
cmp bx,cs:V_VGADEEP
jge VGA_line_exit
shl bx,1
mov di,cs:[screentable + bx]
cld
mov cx,[bp + _AOFF + 4]
cmp cx,0
je VGA_line_exit
cmp cx,cs:V_VGAWIDE
jl >l1
mov cx,cs:V_VGAWIDE
l1:
mov ax,cs:V_VGASCRNSEG
mov es,ax
rep movsb
VGA_line_exit:
pop es,ds,bp
retf
;THIS ROUTINE SETS THE VGA PALETTE
;THE FIRST ARGUMENT ON THE STACK IS A FAR POINTER TO
;THE PALETTE DATA. THE SECOND ARGUMENT IS THE NUMBER OF COLOURS.
VGA_PALETTE:
call cs:[check_gray]
PUSH BP
MOV BP,SP
PUSH DS
MOV SI,[BP + _AOFF + 0] ;OFFSET OF SOURCE
MOV DS,[BP + _AOFF + 2] ;SEGMENT OF SOURCE
MOV CX,[BP + _AOFF + 4] ;NUMBER OF COLOURS
CMP CX,0 ;CHECK FOR NASTIES
JG GVP0
JMP GVPX
;WE'LL SET THE PALLETTE USING DIRECT REGISTERS RATHER
;THAN A BIOS CALL AS IT LOOKS NICER, however if
;gray scale summing is active, we'll use the BIOS
GVP0:
cmp cs:b gray_VGA,0
je >l2
push si,cx
mov es,ds
mov di,si
l1:
lodsb
shr al,1
shr al,1
stosb
lodsb
shr al,1
shr al,1
stosb
lodsb
shr al,1
shr al,1
stosb
loop l1
pop cx,si
mov dx,si
mov bx,0
mov ax,1012h
int 10h
jmp GVPX
l2:
MOV DX,03C6H
MOV AL,0FFH
OUT DX,AL
MOV BX,0
GVP1: PUSH CX
MOV DX,03C8H
MOV AL,BL
INC BX
OUT DX,AL
INC DX
LODSB
SHR AL,1
SHR AL,1
OUT DX,AL
LODSB
SHR AL,1
SHR AL,1
OUT DX,AL
LODSB
SHR AL,1
SHR AL,1
OUT DX,AL
POP CX
LOOP GVP1
GVPX:
POP DS
POP BP
RETF
check_gray dw do_check_gray
gray_VGA db 0
; test for gray scale summing
do_check_gray:
push ax,bx,cx,dx,es,ds,di
mov ax,1b00h
mov es,cs
mov di,gray_test_area
mov bx,0
int 10h
mov al,es:[gray_test_area+2dh]
and al,00000010xb
mov cs:gray_VGA,al
mov ax,gray_ret
mov cs:check_gray,ax
pop di,ds,es,dx,cx,bx,ax
gray_ret:
ret
;THIS ROUTINE SETS THE VGA OVERSCAN.
;THE FIRST STACK ARGUMENT IS THE COLOUR NUMBER.
VGA_OVERSCAN:
PUSH BP
MOV BP,SP
MOV AX,1001H
MOV BX,[BP + _AOFF + 0]
XCHG BH,BL
INT 10H
POP BP
RETF
;THIS ROUTINE SELECTS THE EGA 16 COLOUR MODE
;THE HEIGHT AND WIDTH OF THE IMAGE ARE ON THE STACK - THESE
;MAY BE USEFUL IF YOU WANT TO PICK ONE OF SEVERAL AVAILABLE
;MODES BASED ON THE AREA OF THE PICTURE TO BE DISPLAYED
EGA_on:
push bp
mov bp,sp
push ds
mov ds,cs
mov ax,[bp+_AOFF] ; cols
mov bx,[bp+_AOFF+2] ; rows
mov si,EGA_mode
call pick_mode
mov V_EGAWIDE,ax
mov V_EGADEEP,bx
add ax,7
shr ax,1
shr ax,1
shr ax,1
mov V_EGABYTES,AX
mov ax,cx
int 10h
mov cx,V_EGADEEP ;depth of screen in the current mode
sub dx,dx
mov bx,dx
mov si,SCREENTABLE
mov [si],dx
add si,2
dec cx
l2:
add dx,V_EGABYTES
l1:
mov [si],dx
add si,2
loop l2
pop ds,bp
retf
;THIS ROUTINE DISPLAYS AN EGA LINE
;THE FIRST ARGUMENT ON THE STACK (2 WORDS) IS A FAR POINTER TO
;THE LINE. THE SECOND ARGUMENT IS THE LENGTH OF THE LINE IN BYTES
EGA_LINE:
PUSH BP
MOV BP,SP
PUSH DS
PUSH ES
MOV SI,[BP + _AOFF + 0] ;OFFSET OF SOURCE
MOV DS,[BP + _AOFF + 2] ;SEGMENT OF SOURCE
MOV BX,[BP + _AOFF + 6] ;GET LINE NUMBER
CMP BX,cs:V_EGADEEP
if GE jmp long SHOWEGAX
SHL BX,1
MOV DI,CS:[SCREENTABLE+BX]
MOV AX,0A000H
MOV ES,AX
MOV BX,[BP + _AOFF + 4] ;LENGTH OF MOVE IN BYTES
MOV CX,BX ; this part does an even # of bytes
EGAPLANE 1
CLD
PUSH DI
rep movsb
POP DI
MOV CX,BX
EGAPLANE 2
PUSH DI
rep movsb
POP DI
MOV CX,BX
EGAPLANE 4
PUSH DI
rep movsb
POP DI
MOV CX,BX
EGAPLANE 8
PUSH DI
rep movsb
POP DI
EGAPLANE 0FH
SHOWEGAX: POP ES
POP DS
POP BP
RETF
;THIS ROUTINE SETS THE EGA PALETTE
;THE FIRST ARGUMENT ON THE STACK IS A FAR POINTER TO
;THE PALETTE DATA. THE SECOND ARGUMENT IS THE NUMBER OF COLOURS.
EGA_PALETTE:
PUSH BP
MOV BP,SP
PUSH DS
MOV SI,[BP + _AOFF + 0] ;OFFSET OF SOURCE
MOV DS,[BP + _AOFF + 2] ;SEGMENT OF SOURCE
MOV CX,[BP + _AOFF + 4] ;NUMBER OF COLOURS
SUB BX,BX
CMP CX,16
JLE EGA_PALETTE1
MOV CX,16
EGA_PALETTE1: MOV BH,[SI]
MOV AX,1000H
INT 10H
INC BL
INC SI
LOOP EGA_PALETTE1
POP DS
POP BP
RETF
;THIS ROUTINE SELECTS THE 2 COLOUR MODE
;THE HEIGHT AND WIDTH OF THE IMAGE ARE ON THE STACK - THESE
;MAY BE USEFUL IF YOU WANT TO PICK ONE OF SEVERAL AVAILABLE
;MODES BASED ON THE AREA OF THE PICTURE TO BE DISPLAYED
MONO_on:
push bp
mov bp,sp
push ds
mov ds,cs
mov ax,[bp+_AOFF] ; cols
mov bx,[bp+_AOFF+2] ; rows
mov si,MONO_mode
call pick_mode
mov V_MONOWIDE,ax
mov V_MONODEEP,bx
add ax,7
shr ax,1
shr ax,1
shr ax,1
mov V_MONOBYTES,AX
mov ax,cx
int 10h
mov cx,V_MONODEEP ;depth of screen in the current mode
sub dx,dx
mov bx,dx
mov si,SCREENTABLE
mov [si],dx
add si,2
dec cx
l2:
add dx,V_MONOBYTES
mov [si],dx
add si,2
loop l2
pop ds,bp
retf
UPDATE_MOVE EQU 2
UPDATE_PAD EQU 4
UPDATE_ADJUST EQU 6
;THIS ROUTINE DISPLAYS A FULL MONOCHROME PAGE
;THE FIRST ARGUMENT ON THE STACK IS A FAR POINTER TO THE PAGE
;THE SECOND ARGUMENT IS THE WIDTH OF THE BITMAP (IN BYTES)
;THE THIRD ARGUMENT IS THE NUMBER OF LINES TO DISPLAY
;NOTE: THE SOURCE BUFFER MAY BE BIGGER THAN 64K.
MONO_FRAME:
PUSH BP
MOV BP,SP
SUB SP,UPDATE_ADJUST
PUSH DS
PUSH ES
MOV AX,cs:V_MONOSCRNSEG ;POINT TO THE SCREEN
MOV ES,AX
MOV AX,[BP + _AOFF + 4] ;GET THE WIDTH OF MOVE
MOV [BP - UPDATE_MOVE],AX ;SAVE IT LOCALLY
MOV WORD PTR [BP - UPDATE_PAD],0 ;SET ADJUSTMENT
CMP AX,cs:V_MONOBYTES ;IF THE MOVE IS LESS THAN
JL UPDATE0 ;SCREEN WIDTH, GO FOR IT
SUB AX,cs:V_MONOBYTES ;ELSE, SET MOVE WIDTH
MOV [BP - UPDATE_PAD],AX ;...AND THE AMOUNT TO
MOV AX,cs:V_MONOBYTES ;...ADJUST THE POINTER
MOV [BP - UPDATE_MOVE],AX ;...AFTER EACH LINE
UPDATE0: MOV SI,[BP + _AOFF + 0] ;OFFSET OF BITMAP
MOV DS,[BP + _AOFF + 2] ;SEGMENT OF BITMAP
MOV CX,[BP + _AOFF + 6] ;NUMBER OF LINES
CLD ;CLEAR DIRECTION FLAG
SUB BX,BX
UPDATE1: PUSH CX ;SAVE COUNT (LINE NUMBER)
MOV DI,CS:[SCREENTABLE + BX]
ADD BX,2 ;POINT TO NEXT LINE
MOV CX,[BP - UPDATE_MOVE] ;GET THE MOVE SIZE
rep movsb
ADD SI,[BP - UPDATE_PAD] ;ADJUST THE POINTER
CMP SI,0F800H ;ARE WE WITHIN 2K OF TOP?
JL UPDATE2 ;IF NOT, CARRY ON
MOV AX,SI ;SEE HOW MANY SEGMENTS ARE
MOV CL,4 ;...IN SI (SI DIV 4)
SHR AX,CL
MOV CX,DS ;ADD THEM TO THE DATA SEGMENT
ADD CX,AX ;...(YOU CAN'T JUST ADD DS,AX)
MOV DS,CX
AND SI,000FH ;ADJUST SI (SI MOD 16)
UPDATE2: POP CX ;GET COUNT BACK
LOOP UPDATE1 ;DECREMENT AND LOOP
POP ES
POP DS
ADD SP,UPDATE_ADJUST
POP BP
RETF
;THIS ROUTINE DISPLAYS A SINGLE MONOCHROME LINE
;THE FIRST ARGUMENT ON THE STACK IS A FAR POINTER TO THE LINE
;THE SECOND ARGUMENT IS THE LINE NUMBER
;THE THIRD ARGUMENT IS THE WIDTH OF THE BITMAP (IN BYTES)
MONO_LINE:
PUSH BP
MOV BP,SP
PUSH DS
PUSH ES
MOV AX,cs:V_MONOSCRNSEG ;POINT TO THE SCREEN
MOV ES,AX
MOV CX,[BP + _AOFF + 6] ;GET THE WIDTH OF MOVE
CMP CX,0
JE MONO_LINE2
CMP CX,cs:V_MONOBYTES
JL MONO_LINE1
MOV CX,cs:V_MONOBYTES
MONO_LINE1: MOV SI,[BP + _AOFF + 0] ;OFFSET OF BITMAP
MOV DS,[BP + _AOFF + 2] ;SEGMENT OF BITMAP
MOV BX,[BP + _AOFF + 4] ;NUMBER OF LINE
SHL BX,1
CLD ;CLEAR DIRECTION FLAG
MOV DI,CS:[SCREENTABLE + BX]
rep movsb
MONO_LINE2: POP ES
POP DS
POP BP
RETF
; This routine selects text mode after all the graphics modes
; are finished.
VGA_off:
EGA_off:
MONO_off:
mov ax,0003h
int 10h
retf
;
;
;this part goes through all available modes to try to find one that is
; larger than the picture or the same size as the picture.
pick_mode:
l3:
cmp ax,[si]
ja >l1
cmp bx,[si+2]
jbe >l2
l1:
add si,10
cmp w[si],0
jne l3
sub si,10
l2:
; this part goes backwards through the list of modes to make sure the card
; and monitor can handle the mode.
mov cx,Installed
sub dx,dx
mov dl,ch ; cx is memory available
mov ch,dh ; dx is the monitor
l2:
cmp cx,[si+4]
jl >l1
cmp dx,3
je >l4 ; any mode monitor
cmp dx,[si+6]
je >l4 ; monitor and required are the same
cmp w[si+6],0
je >l4 ; VGA monitor is all that's needed
l1:
sub si,10
jmp l2
l4:
mov ax,[si]
mov bx,[si+2]
mov cx,[si+8]
ret
;
;
Set_320x480Mode:
push ds
mov ds,cs
mov ax,12h
int 10h ;let BIOS clear memory and set vertical registers
call save_sync
MOV AX,13h
INT 10h
call load_sync
;disable chain 4
MOV DX,03C4h
MOV AL,4
OUT DX,AL
MOV DX,03C5h
MOV AL,6
OUT DX,AL
;unprotect crtc registers
MOV DX,03D4h
MOV AL,11h
OUT DX,AL
MOV DX,03D5h
IN AL,DX
AND AL,7
PUSH AX
MOV DX,03D4h
MOV AL,11h
OUT DX,AL
POP AX
MOV DX,03D5h
OUT DX,AL
;load crtc registers
MOV DX,03D4h
MOV AL,6
OUT DX,AL
MOV DX,03D5h
MOV AL,0DH
OUT DX,AL
MOV DX,03D4h
MOV AL,7
OUT DX,AL
MOV DX,03D5h
MOV AL,3Eh
OUT DX,AL
MOV DX,03D4h
MOV AL,9
OUT DX,AL
MOV DX,03D5h
MOV AL,40h
OUT DX,AL
MOV DX,03D4h
MOV AL,10h
OUT DX,AL
MOV DX,03D5h
MOV AL,0EAh
OUT DX,AL
MOV DX,03D4h
MOV AL,12h
OUT DX,AL
MOV DX,03D5h
MOV AL,0DFh
OUT DX,AL
MOV DX,03D4h
MOV AL,14h
OUT DX,AL
MOV DX,03D5h
MOV AL,0
OUT DX,AL
MOV DX,03D4h
MOV AL,15h
OUT DX,AL
MOV DX,03D5h
MOV AL,0E7h
OUT DX,AL
MOV DX,03D4h
MOV AL,16h
OUT DX,AL
MOV DX,03D5h
MOV AL,6
OUT DX,AL
MOV DX,03D4h
MOV AL,17h
OUT DX,AL
MOV DX,03D5h
MOV AL,0E3h
OUT DX,AL
MOV DX,03D4h
MOV AL,11h
OUT DX,AL
MOV DX,03D5h
MOV AL,0ACh
OUT DX,AL
pop ds
RET
;
save_sync:
mov dx,3cch
in al,dx
mov sync_save_byte,al
;
load_sync:
mov ah,sync_save_byte
and al,0c0h
mov dx,03cch
in al,dx
jmp $+2
and al,00111111xb
or al,ah
mov dx,03c2h
out dx,al
ret
;
sync_save_byte db 0
even
;THIS IS A LINE START LOOKUP TABLE
gray_test_area: db 40h dup(?)
SCREENTABLE: DW TLI_DEEP DUP(?) ;LINE START TABLE
;These are the modes supported. the tables have the format:
; columns,rows,memory,monitor,mode
; where memory is 0 256k
; 1 512k
; 2 1024k
;
; and monitor is 0 standard VGA
; 1 800x600 capable Multisync
; 2 1024x768 interlace capable 8514 equivalent
; 3 1024x768 interlace capable multisync
;
VGA_mode:
dw 320,200,0,0,13h
dw 640,480,0,0,2eh
dw 0
EGA_mode:
dw 320,200,0,0,0dh
dw 640,350,0,0,10h
dw 640,480,0,0,12h
dw 0
MONO_mode:
dw 640,350,0,0,10h
dw 640,480,0,0,11h
dw 0