      .8086

CODE  SEGMENT BYTE PUBLIC
      ASSUME CS:CODE

;*****************************************************************************
;
; GRAPHICS DRIVER FOR VEGA DELUXE 640x480 16 color mode
;
; Copyright 1986,1987,1988 Protel Technology Pty. Ltd.
;
; Written By  : N.M.Martin
; Last Change : 2-June-1988
;*****************************************************************************

public    GETDRIVERTYPE
public    DRAW
public    HLINE
public    VLINE
public    PLOTPIXEL
public    READPIXEL
public    CLEARGRAPH
public    GRAPHMODE
public    TEXTMODE1
public    FULLCHAR
public    FASTCHAR
public    SAVEMENU
public    LOADMENU
public    XBIG
public    YBIG
public    BIGCOLORS
public    BIGBACKCOLORS
public    COLORSETS
public    ARROWCURSOR
public    SETBACKGROUND
public    MENUMEMREQUIRED
public    RAWPLOT
public    ARC
public    GETDRIVERNAME

;*****************************************************************************
; This Table is the external reference point for this driver. The order and
; number of elements in it must not be changed or a program crash will result.
;*****************************************************************************

GETDRIVERTYPE:   Jmp    _GETDRIVERTYPE
DRAW:            Jmp    _DRAW
HLINE:           Jmp    _HLINE
VLINE:           Jmp    _VLINE
PLOTPIXEL:       Jmp    _PLOTPIXEL
READPIXEL:       Jmp    _READPIXEL
CLEARGRAPH:      Jmp    _CLEARGRAPH
GRAPHMODE:       Jmp    _GRAPHMODE
TEXTMODE1:       Jmp    _TEXTMODE
FULLCHAR:        Jmp    _FULLCHAR
FASTCHAR:        Jmp    _FASTCHAR
SAVEMENU:        Jmp    _SAVEMENU
LOADMENU:        Jmp    _LOADMENU
XBIG:            Jmp    _XBIG
YBIG:            Jmp    _YBIG
BIGCOLORS:       Jmp    _BIGCOLORS
BIGBACKCOLORS:   jmp    _BIGBACKCOLORS
COLORSETS:       Jmp    _COLORSETS
ARROWCURSOR:     Jmp    _ARROWCURSOR
SETBACKGROUND:   Jmp    _SETBACKGROUND
MENUMEMREQUIRED: Jmp    _MENUMEMREQUIRED
RAWPLOT:         Jmp    _RAWPLOT
ARC:             Jmp    _ARC

; This gets all jumps tables and external/global definitions

;*****************************************************************************
; The Driver name below mus remain in the same position and have the same    ;
; length between then quotes.                                                ;
;*****************************************************************************

GETDRIVERNAME:    DB  32,'VEGA DELUXE 640x480 16 Color    '

MaxX          Equ 640          ;Number of Pix in X Direction
MaxY          Equ 480          ;Number of Pix in Y Direction
StatusLine    Equ 23           ;Number of Y Pix Reserved For Status Line
MaxColors     Equ 15           ;Largest Color Number that the driver supports
MaxBackColors Equ 15           ;Largest Background Color the driver supports
MenuMem       Equ 32000        ;Memory to store a screen menu
MaxSets       Equ 0            ;Number of available color sets

INCLUDE GCOMMON.ASM
;Gets RAWPLOT
;     DRAW
;     FASTCHAR
;     FULLCHAR
;     _PLOTPOINT
;     _GETDRIVERTYPE
;     _BIGCOLORS
;     _BIGBACKCOLORS
;     _XBIG
;     _YBIG
;     _COLORSETS


;These routines are common for all graphics drivers


;*************************************************;
SetGraph Proc Near
; This routines sets up the graphics system for
; drawing. It Takes the color in SI and sets
; segment registers and inits the hardware.
;*************************************************;
      mov     ax,0A000h;
      mov     es,ax
      or      si,si
      jns     No_Xor

      push    dx
      mov     dx,3ceh
      mov     al,3                     ;set Rotate/Mode register address
      out     dx,al
      inc     dx                       ;Point at register
      mov     al,18h                   ;set for xoring
      out     dx,al
      pop     dx
No_xor:
      ret
SetGraph Endp

;*********************************************;
ResetGraph proc Near                          ;
; Resets the EGA hardware to state where an   ;
; exit from the program would be acceptable.  ;
; The Driver should always leave the hardware ;
; in such a state.                            ;
;*********************************************;
      mov      dx,3ceh
      mov      al,3                    ;set Rotate/Mode register address
      out      dx,al
      inc      dx                      ;Point at register
      mov      al,0                    ;set for Normal
      out      dx,al

      dec      dx
      mov      al,8                    ;set bit mask register address
      out      dx,al
      inc      dx                      ;Point at register
      mov      al,0ffh
      out      dx,al                   ;set bit mask

      mov      dx,3c4h
      mov      al,2                    ;set Planes To Work On address
      out      dx,al
      inc      dx                      ;Point at register
      mov      ax,0ffh                 ;all planes
      out      dx,al

      ret
ResetGraph endp


;********************************************;
_READPIXEL Proc NEAR                         ;
; Return the color of the pixel at (Rpx,Rpy) ;
; X = Cx                                     ;
; Y = Dx                                     ;
; Return Ax = color                          ;
;********************************************;
Rpx	equ	[bp+6]
Rpy   	equ	[bp+4]
      push    bp
      mov     bp,sp
      mov     ax,0A000h;
      mov     es,ax
      mov     Dx,rpy                   ;y
      mov     Cx,rpx                   ;x

      mov     ax,80                    ; yoff := (y*80)
      mul     dx                       ;Result in ax
      Mov     bx,ax                    ;bx = yoffset now
                                       ;Low 3 bits of x give pix position
                                       ;up  7 bits of x give byte offset;
      mov     dx,cx                    ;cx = x and dx = x
      shr     dx,1                     ;dx is x coordinate;
      shr     dx,1
      shr     dx,1
      add     bx,dx                    ;bx = byte now
      and     cx,7                     ;3 bits give offset to use as count
      mov     dx,0080h;
      shr     dx,cl
      mov     ch,dl

      ;bx = offset
      ;ch = bit mask

      mov     ah,3
ReadPixLoop:
      mov     dx,3ceh
      mov     al,4                     ;select graphics controller
      out     dx,al                    ;read map select register 4

      inc     dx                       ;dx = 3cfh
      mov     al,ah                    ;select bit plane
      out     dx,al

      mov     al,es:0[bx]              ;read byte

      shl     cl,1                     ;bit 0 of cl = 0
      and     al,ch                    ;mask data byte with bit mask
      jz      SetBit0
      or      cl,1                     ;bit0 of cl = 1
SetBit0:
      dec     ah
      jge     ReadPixloop
      and     cx,000fh
      mov     ax,cx                    ;return function value in ax
      push    ax
      call    ResetGraph
      pop     ax
      pop     bp
      ret     6
_READPIXEL endp


;*************************************;
_CLEARGRAPH proc NEAR                 ;
; Set all pixels on the screen to the ;
; background color.                   ;
;*************************************;
      Call     ResetGraph
      mov      cx,0A000h
      mov      es,cx
      cld
      mov      cx,4B00h
      mov      ax,0
      mov      di,0

      rep stosw
      ret
_CLEARGRAPH endp


;*********************************************
_TEXTMODE proc NEAR                          ;
; Places the graphics hardware into textmode ;
;*********************************************
      mov    ax,0003h
      int    10h
      ret
_TEXTMODE endp


;**********************************************;
_GRAPHMODE proc NEAR                           ;
; Places the graphics hardware into Graph Mode ;
;**********************************************;
      mov    ax,0010h
      int    10h
      ;call   check_vega
      ;jnc    NoVega
      call   Set_Hires
NoVega:
      ret
_GRAPHMODE endp


;*********************************************;
_SAVEMENU proc NEAR                           ;
; This routine saves the area of the top left ;
; hand of the screen used to store data under ;
; the pop-up menu.                            ;
; The area is 320 pixels horizontal and 200   ;
; pixels vertical                             ;
; StoreOfs and storeSeg point to an area of   ;
; memory where the screen data can be stored. ;
;*********************************************;
storeOfs equ [bp+6]
storeSeg equ [bp+8]

      push     ds
      push     bp
      mov      bp,sp

      mov     di,StoreOfs              ;BX = offset to store data
      mov     ax,StoreSeg
      mov     ds,ax                    ;DS = Seg to store data
      mov     ax,0a000h
      mov     es,ax

      mov     dx,3ceh
      mov     al,4                     ;select graphics controller
      out     dx,al                    ;read map select register 4
      inc     dx                       ;dx = 3cfh

      mov     cx,200                   ;200 lines;
      mov     si,0                     ;where get byte from

SaveMenuL1:
      mov     bx,40

SaveMenuL2:
      mov     ah,3

ReadPLoop:
      mov     al,ah                    ;select bit plane
      out     dx,al
      mov     al,es:0[si]              ;read byte
      mov     ds:0[di],al              ;store byte
      inc     di
      dec     ah
      jge     ReadPloop

      inc     si
      dec     bx
      jnz     SaveMenuL2

      add     si,40                    ;Go to next row of data
      loop    SaveMenuL1

      call    ResetGraph
      pop     bp
      pop     ds
      ret     4
_SAVEMENU endp


;***********************************************;
_LOADMENU proc NEAR                             ;
; This routine retrives the stored screen data  ;
; and places in into the area of the top left   ;
; hand of the screen.                           ;
; The area is 320 pixels horizontal and 200     ;
; pixels vertical                               ;
; LoadOfs and LoadSeg point to the area in mem  ;
; where the data was stashed.                   ;
;***********************************************;
LoadOfs equ [bp+6]
LoadSeg equ [bp+8]

      push     ds
      push     bp
      mov      bp,sp

      mov     di,LoadOfs	       ;BX = offset to store data
      mov     ax,LoadSeg
      mov     ds,ax                    ;DS = Seg to store data
      mov     ax,0a000h
      mov     es,ax

      mov     dx,3ceh
      mov     al,8
      out     dx,al

      inc     dx
      mov     al,0ffh                  ;set all bit planes on
      out     dx,al

      mov     dx,3c4h
      mov     al,2
      out     dx,al
      inc     dx

      mov     cx,200                   ;200 lines;
      mov     si,0                     ;where get byte from

LoadMenuL1:
      mov     bx,40

LoadMenuL2:
      mov     ah,8
WritePLoop:
      mov     al,ah
      out     dx,al                    ; set bit plane for next byte

      mov     al,ds:0[di]              ;get stored byte
      mov     es:0[si],al              ;Write byte
      inc     di
      shr     ah,1
      jnz     WritePloop

      inc     si
      dec     bx
      jnz     LoadMenuL2

      add     si,40                    ;Go to next row of data
      loop    LoadMenuL1

      call    ResetGraph
      pop     bp
      pop     ds
      ret     4
_LOADMENU endp





;*****************************************
HPoint Proc Near
; Subroutine called by Hline.
; X = Ax
; Byte offset in y axis in BX
;*****************************************
	push	ax
	push	bx
	Push	cx

	mov	dx,ax		;Ax = x and dx = x
	shr	dx,1		;dx is x coordinate;
	shr	dx,1
	shr	dx,1
	add	bx,dx		;bx = byte now
	mov	cx,ax
	and	cx,7		;3 bits give offset to use as count
	mov	dx,0080h;
	shr	dx,cl		;dl := ormask
	mov	di,dx		;save it in di

	mov	dx,3ceh
	mov	al,8		;set bit mask register address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,di
	out	dx,al		;set bit mask

	mov	al,es:0[bx]    	;Latch Data into Internal Registers
	xor	al,al
	Mov	es:0[bx],al    	;now set all pixels to 0
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,SI		;Get Color
	out	dx,al
	mov	al,0ffh
	Mov	es:0[bx],al    	;Set pixel to new color
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,0fh		;Color Back To All
	out	dx,al

	pop	cx
	pop	bx
	pop	ax
	ret
HPoint endp



;*******************************************;
_HLINE proc NEAR                            ;
; Draws a horizontal line between 2 points  ;
;(hlx1,hly) and (hlx2,hly)                  ;
;*******************************************;
hlx1	equ	[bp+10]
hlx2	equ	[bp+8]
hly	equ	[bp+6]
hlcolor	equ	[bp+4]

	push	bp
	mov	bp,sp

        ;First Check if Hline OutSide of 0..Maxy
        Mov     dx,hly
        or      dx,0
        js      Houtside
        cmp     dx,MaxY
        jnb     Houtside

        Mov     cx,hlx1
        cmp     cx,MaxX                  ;if x1 > MaxY then exit
        jnb     Houtside
        Mov     cx,hlx2                  ;if x2 < 0 then exit;
        or      cx,0
        js      Houtside
        Jmp     CoordsOK

HoutSide:
        jmp     hfinish

CoordsOK:
	mov	si,hlcolor 	;si = color
        Call    SetGraph
	mov	dx,hly     	;dx = y
	mov	ax,80		;yoff := (y*80)
	mul	dx		;Result in ax
	Mov	bx,ax		;bx = yoffset now
	Mov	DI,bx		;DI = yoffset
	mov	cx,hlx2    	;get x2 to dx
	mov	dx,hlx1    	;get x1 to cx
	sub	cx,dx		;x2 := x2 - x1	< 10 then no byte fill
	jnz	hnotzero
	jmp	Honepix
HNotZero:
	cmp	cx,20
	jns	LongLine       	;jump if > than 20 pixels
				;Cx = count bx = yoffset dx = x1
	jmp	HsmallLine

LongLine:			;Now Deal With byte on left end;
	mov	cx,hlx1
	mov	dx,cx		;cx = x1 and dx = x1
	shr	dx,1
	shr	dx,1
	shr	dx,1
	add	bx,dx		;bx = byte now
	and	cx,7		;3 bits give offset to use as count
	mov	dx,00FFh		;Get Mask 1 For line Start
	shr	dx,cl		;dl := ormask
	mov	ah,dl		;save it

	mov	dx,3ceh
	mov	al,8		;set bit mask register address
	out	dx,al
	inc	dx		;Point at register
	mov	al,ah
	out	dx,al		;set bit mask
	mov	al,es:0[bx]	;Latch Data into Internal Registers
	xor	al,al
	Mov	es:0[bx],al	;now set all pixels to 0
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,SI		;Get Color
	out	dx,al
	mov	al,0ffh
	Mov	es:0[bx],al	;now First byte is Fixed for x1
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,0ffh		;Set all Color
	out	dx,al

;Now Deal With byte on Right end
	mov	ax,hlx2
	mov	dx,ax		;ax = x2 and dx = x2
	shr	dx,1
	shr	dx,1
	shr	dx,1
	mov	bx,DI
	add	bx,dx		;bx = byte now
	and	ax,7		;3 bits give offset to use as count
	mov	cx,7
	sub	cx,ax		; $ff shl (7-(x and 7))
	mov	dx,00FFh	;Get Mask 2 For line end
	shl	dx,cl		;dl := ormask
	mov	ah,dl		;save it

	mov	dx,3ceh
	mov	al,8		;set bit mask register address
	out	dx,al
	inc	dx		;Point at register
	mov	al,ah
	out	dx,al		;set bit mask
	mov	al,es:0[bx]	;Latch Data into Internal Registers
	xor	al,al
	Mov	es:0[bx],al	;now set all pixels to 0
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,SI		;Get Color
	out	dx,al
	mov	al,0ffh
	Mov	es:0[bx],al	;now First byte is Fixed for x2
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,0fh		;Set All Color
	out	dx,al

;Have Now Dealt with byte on each end of line

	mov	ax,hlx1
	shr	ax,1		;Get x1
	shr	ax,1
	shr	ax,1

	mov	cx,hlx2	;get x2
	shr	cx,1
	shr	cx,1
	shr	cx,1
	sub	cx,ax		;fill(start,(X2 Shr 3)-(X1 Shr 3)-1);
	dec	cx		;Cx = byte count;
	mov	bx,di		;get back y offset
	add	bx,ax		;Point at first byte again
	inc	bx		;Start Fill At Next Byte

	mov	dx,3ceh
	mov	al,8		;set bit mask register address
	out	dx,al
	inc	dx		;Point at register
	mov	al,0ffh		;All bits now
	out	dx,al		;set bit mask

HLloop:
	mov	al,es:0[bx]	;Latch Data into Internal Registers
	xor	al,al
	Mov	es:0[bx],al	;now set all pixels to 0
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,SI		;Get Color
	out	dx,al
	mov	al,0ffh
	Mov	es:0[bx],al	;Set pixel to new color
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,0fh		;Color Back To All
	out	dx,al
	inc	bx
	loop	HLloop
	Jmp short	HFinish


HsmallLine:
	Mov	ax,dx
        inc     cx
HsmallLoop:			;ax = x1	cx = pixel count
	call	Hpoint
	inc	ax
	loop	HSmallLoop
	Jmp short	Hfinish

Honepix:
	mov	ax,dx		;Get X1
	call	Hpoint

Hfinish:
	call	ResetGraph
	pop	bp
	ret     8
_HLINE  endp



;*******************************************;
_VLINE proc NEAR                            ;
; Draws a vertical line between 2 points    ;
;(vlx,vly1) and (vlx,vly2)                  ;
;********************************************
vlx	equ	[bp+10]
vly1	equ	[bp+8]
vly2	equ	[bp+6]
vlcolor	equ	[bp+4]

	push	bp
	mov	bp,sp
	mov	si,vlcolor		;si = color
        Call    SetGraph
	mov	dx,vly1 	;dx = y1 lower
	mov	ax,80		;yoff := (y*80)
	mul	dx		;Result in ax
	Mov	bx,ax		;bx = yoffset now
				;Low 3 bits of x give pix position
				;up	7 bits of x give byte offset;
	mov	cx,vlx
	mov	dx,cx		;cx = x and dx = x
	shr	dx,1		;dx is x coordinate;
	shr	dx,1
	shr	dx,1
	add	bx,dx		;bx = start byte now
	and	cx,7		;3 bits give offset to use as count
	mov	dx,0080h;
	shr	dx,cl		;dl := ormask
	mov	ah,dl		;save it

	mov	dx,3ceh
	mov	al,8		;set bit mask register address
	out	dx,al
	inc	dx		;Point at register
	mov	al,ah
	out	dx,al		;set bit mask

	mov	dx,vly1		;dx = lowest y cord
	mov	cx,vly2    	;cx := upper y cord
	sub	cx,dx		;cx := count
	jnz	VLloop
	inc	cx

VLloop:
	mov	al,es:0[bx]    	;Latch Data into Internal Registers
	xor	al,al
	Mov	es:0[bx],al    	;now set all pixels to 0
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,SI		;Set Color Mask
	out	dx,al
	mov	al,0ffh
	Mov	es:0[bx],al    	;now do operation on set pixels
	mov	dx,3c4h
	mov	al,2		;set Planes To Work On address
	out	dx,al
	inc	dx		;Point at register
	mov	ax,15		;Set Full Color Mask
	out	dx,al
	add	bx,80
	loop	VLloop
	call	ResetGraph
	pop	bp
	ret     8
_VLINE  endp



;******************************************;
_ARROWCURSOR proc NEAR                     ;
; Draws a cursor on the screen at location ;
; (acx,acy)                                ;
;******************************************;
acx   equ      [bp+6]
acy   equ      [bp+4]
      push     bp
      mov      bp,sp

      mov      si,-1
      Call     SetGraph

      mov     cx,acx	               ;get x
      mov     dx,acy		       ;get y

      mov      bx,1                    ;y := 0
      call     ArrowPoints

      inc      dx                      ;y := 1
      mov      bx,2
      call     ArrowPoints

      inc      dx                      ;y := 2
      mov      bx,3
      call     ArrowPoints

      inc      dx                      ;y := 3
      mov      bx,4
      call     ArrowPoints

      inc      dx                      ;y := 4
      mov      bx,5
      call     ArrowPoints

      inc      dx                      ;y := 5
      mov      bx,6
      call     ArrowPoints

      inc      dx                      ;y := 6
      mov      bx,7
      call     ArrowPoints

      inc      dx                      ;y := 7
      mov      bx,8
      call     ArrowPoints

      inc      dx                      ;y := 8
      mov      bx,9
      call     ArrowPoints

      inc      dx                      ;y := 9
      mov      bx,10
      call     ArrowPoints

      inc      dx                      ;y := 10
      mov      bx,11
      call     ArrowPoints

      inc      dx                      ;y := 11
      mov      bx,12
      call     ArrowPoints

      inc      dx                      ;y := 12
      mov      bx,6
      call     ArrowPoints

      inc      dx                      ;y := 13
      mov      bx,5
      call     ArrowPoints

      inc      dx                      ;y := 14
      mov      bx,4
      call     ArrowPoints

      inc      dx                      ;y := 15
      mov      bx,3
      call     ArrowPoints

      inc      dx                      ;y := 16
      mov      bx,2
      call     ArrowPoints

      inc      dx                      ;y := 17
      call     Point                   ;x := 0

      call    ResetGraph
      pop     bp
      ret     4
_ARROWCURSOR endp


;*****************************************
ArrowPoints Proc Near
; Sub_Routine for ArrowCursor
; X = cx
; Yoffset = Dx
; bx = count of x
;*****************************************
      Push    cx
Ploop:
      call    Point
      inc     cx       ;next x
      dec     bx
      jnz     Ploop
      pop     cx
      ret
ArrowPoints endp


;********************************************************;
_SETBACKGROUND Proc Near                                 ;
; Sets the current background color to BackColor         ;
; Procedure SetBackGround(BackColor,ColorSet : integer); ;
;********************************************************;
BackColor equ      [bp+6]
ColorSet  equ      [bp+4]
      push     bp
      mov      bp,sp
      mov      ax,BackColor
      and      ax,15
      cmp      ax,6
      jne      Not6                    ;if color = 6 then color := 20;
      mov      ax,20
      jmp      EndBack
Not6:
      and      ax,8                    ;if (color > 15) then color := color + 48;
      jz       Less15
      mov      ax,backcolor
      and      ax,15
      add      ax,48
      jmp      EndBack

Less15:
      mov      ax,backcolor
      and      ax,15

EndBack:
      mov      bh,al
      mov      ax,1000H;
      mov      bl,0
      Int      10h
      pop      bp
      ret 4
_SETBACKGROUND endp


;********************************************;
Point Proc Near                              ;
; X = Cx                                     ;
; Y = Dx                                     ;
; SI = color                                 ;
; Internal procedure called by Draw,PlotPixel;
; and others to set a pixel to givan color.  ;
; If the hardware can draw vectors DRAW may  ;
; not need to call this routine.             ;
;********************************************;
      or      cx,0
      js      outside
      or      dx,0
      js      outside
      cmp     dx,MaxY-StatusLine       ;if y bigger than 329 then no carry
      jnb     outside                  ;Jump if carry not set
      cmp     cx,MaxX                  ;if x bigger than 639 then no carry
      jnb     outside                  ;Jump if carry not set

      Push    cx
      Push    dx
      push    bx
      push    ax

      mov     ax,80                    ; yoff := (y*80)
      mul     dx                       ;Result in ax
      Mov     bx,ax                    ;bx = yoffset now
                                       ;Low 3 bits of x give pix position
                                       ;up  7 bits of x give byte offset;
      mov     dx,cx                    ;cx = x and dx = x
      shr     dx,1                     ;dx is x coordinate;
      shr     dx,1
      shr     dx,1
      add     bx,dx                    ;bx = byte now
      and     cx,7                     ;3 bits give offset to use as count
      mov     dx,0080h;
      shr     dx,cl                    ;dl := ormask
      mov     ah,dl                    ;save it

      mov      dx,3ceh
      mov      al,8                    ;set bit mask register address
      out      dx,al
      inc      dx                      ;Point at register
      mov      al,ah
      out      dx,al                   ;set bit mask

      mov      al,es:0[bx]             ;Latch Data into Internal Registers
      xor      al,al
      Mov      es:0[bx],al             ;now set all pixels to 0

      mov      dx,3c4h
      mov      al,2                    ;set Planes To Work On address
      out      dx,al
      inc      dx                      ;Point at register
      mov      ax,SI                   ;Get Color
      out      dx,al
      mov      al,0ffh
      Mov      es:0[bx],al             ;now do operation on set pixels
      mov      dx,3c4h
      mov      al,2                    ;set Planes To Work On Reg address
      out      dx,al
      inc      dx                      ;Point at register
      mov      ax,0fh                  ;Set  all Color
      out      dx,al

      pop      ax
      pop      bx
      pop      dx
      pop      cx
outside:
      ret
Point endp


;******************************************;
TEXTPOINT Proc Near                        ;
; X = Cx                                   ;
; Y = Dx                                   ;
; SI = color                               ;
; Variation of point routine that allows   ;
; plotting in the status line at the base  ;
; of the screen.                           ;
;******************************************;
      or      cx,0
      js      Toutside
      or      dx,0
      js      Toutside
      cmp     dx,MaxY                  ;if y bigger then no carry
      jnb     Toutside                 ;Jump if carry not set
      cmp     cx,MaxX                  ;if x bigger then no carry
      jnb     Toutside                 ;Jump if carry not set

      Push    dx
      Push    cx
      push    bx
      push    ax

      mov     ax,80                    ; yoff := (y*80)
      mul     dx                       ;Result in ax
      Mov     bx,ax                    ;bx = yoffset now
                                       ;Low 3 bits of x give pix position
                                       ;up  7 bits of x give byte offset;
      mov     dx,cx                    ;cx = x and dx = x
      shr     dx,1                     ;dx is x coordinate;
      shr     dx,1
      shr     dx,1
      add     bx,dx                    ;bx = byte now
      and     cx,7                     ;3 bits give offset to use as count
      mov     dx,0080h;
      shr     dx,cl                    ;dl := ormask
      mov     ah,dl                    ;save it

      mov      dx,3ceh
      mov      al,8                    ;set bit mask register address
      out      dx,al
      inc      dx                      ;Point at register
      mov      al,ah
      out      dx,al                   ;set bit mask

      mov      al,es:0[bx]             ;Latch Data into Internal Registers
      xor      al,al
      Mov      es:0[bx],al             ;now set all pixels to 0

      mov      dx,3c4h
      mov      al,2                    ;set Planes To Work On address
      out      dx,al
      inc      dx                      ;Point at register
      mov      ax,SI                   ;Get Color
      out      dx,al

      mov      al,0ffh
      Mov      es:0[bx],al             ;now do operation on set pixels
      mov      dx,3c4h
      mov      al,2                    ;set Planes To Work On Reg address
      out      dx,al
      inc      dx                      ;Point at register
      mov      ax,0fh                  ;Set  all Color
      out      dx,al

      pop      ax
      pop      bx
      pop      cx
      pop      dx
Toutside:
      ret
TEXTPOINT endp

;------	VEGA HiRes (640x480) Data:

VerChk	db	'VEGA BIOS Code, ',0    ;VEGA BIOS Version string subset

;
;	Alt. Mode 10: 640 x 480 16-color graphics (>64k ram):
;
HiRes_Params	label	byte
	db	80, 36, 14
	dw	0B400h
	db	001h, 00Fh, 000h, 006h
	db	0ABh
	db	064h, 04Fh, 053h, 021h, 053h, 000h
	db	0F0h, 01Fh, 000h, 000h, 000h, 000h
	db	000h, 000h, 000h, 000h, 0E0h, 02Ch
	db	0DFh, 028h, 00Fh, 0E1h, 00Ch, 0E3h
	db	0FFh
	db	000h, 001h, 002h, 003h, 004h, 005h
	db	014h, 007h, 038h, 039h, 03Ah, 03Bh
	db	03Ch, 03Dh, 03Eh, 03Fh, 001h, 000h
	db	00Fh, 000h
	db	000h, 000h, 000h, 000h, 000h, 000h
	db	005h, 00Fh, 0FFh


Emulate label	dword			;Far pointer to Emulate routine
EmulOff	dw	0
EmulSeg	dw	0

;------	End of VEGA Data...


;
;	Set VEGA HiRes (640x480) mode
;
Set_Hires	proc	near

	push	bp

;Find Out how much the code has been moved
        call     dummy
dummy:
        pop      bx
        sub      bx,offset(dummy)        ;bx = point to start of section

	mov	ax,0C000H
	mov	es,ax

	mov	ax,es:28H               ;Get offset of emulation routine
	mov	cs:EmulOff[bx],ax       ;Save offset
	mov	cs:EmulSeg[bx],es	;and segment

	push	cs			;Copy code segment
	pop	es			;into ES
	lea	di,HiRes_Params 	;Get address of HiRes parameters
        add     di,bx                   ;fix up offset
	mov	dx,3D4h 		;Get CRT port address
	mov	ax,9			;Get special mode
	call	cs:Emulate[bx]		;Set EGA registers from param table

	mov	ax,040H			;Get the bios data segment
	mov	es,ax
	mov	word ptr es:[4AH],80	;Set the number of columns
	mov	byte ptr es:[84H],33	;Set the number of rows

	mov	dx,3DAh			;Get status port address (Color)...
	in	al,dx			;Set attribute flip-flop
	mov	dx,3C0h
	mov	al,20h
	out	dx,al			;Enable palette

	pop	bp
	ret
Set_Hires	endp

;------	End of VEGA Code...


; Force the assembler to produce 4096 byte Binary file.

CodeLength = $ - GETDRIVERTYPE
db 4096-CodeLength DUP(0)


CODE  ends
      end

