Include Page
	Title	Video 7

Include V_Part1.A
Ega_Style	equ		True		;
Mcga_Style	equ		True		;

; describe the adapter
		db	7
	; string 15 	'....5....0....5'
		db	'Video 7        '
		db	7		; number of modes
; mode 0
		dw	800,600,16	; screen dimensions, colors
		db	6		; 6 bit color
		db	Vga+false	; uses DAC, not simulation
		db	80,60		; PanH/V
; mode 1
		dw	1024,768,16
		db	6
		db	Vga+false
		db	100,76
; mode 2
		dw	320,400,256
		db	6
		db	Vga+TRUE	; simulation
		db	32,40
; mode 3
		dw	640,400,256
		db	6
		db	Vga+false
		db	32,20
; mode 4
		dw	640,480,256
		db	6
		db	Vga+false
		db	32,24
; mode 5
		dw	640,480,256
		db	6
		db	Vga+TRUE	; simulation
		db	64,48
; mode 6
		dw	800,600,256
		db	6
		db	Vga+false
		db	40,30

S_Wide label byte
		db	true		;
		db	true		;
		db	false		; double-wide
		db	true		;
		db	true		;
		db	true		;
		db	true		;

ModeSet label byte
		db	62h		; Video7 SVGA 800x600x16
		db	65h		; Video7 SVGA 1024x768x16
		db	66h		; Video7 SVGA 640x400x256
		db	66h		; Video7 SVGA 640x400x256
		db	67h		; Video7 SVGA 640x480x256
		db	66h		; Video7 SVGA 640x400x256
		db	69h		; Video7 SVGA 800x600x256

Include V_Part2.A
Video7Ex	equ		6F05h		; Video7 extended setmode

MoveSimple_

CalcAddress_

Check64k_

SetMode proc near
		mov		al,ModeSet[bx]	; the extended mode number
		mov		bl,al		;  to bl
		mov		ax,Video7Ex	; set Video7 extended
		int		Video		;  mode
		ret
SetMode endp

SetPalette_

DisplayRow proc near
		or		al,al		; zero?
		jz		V0		;
		dec		al		; one?
		jz		V1		;
		dec		al		; two?
		jz		V2		;
		dec		al		; three?
		jz		V3		;
		dec		al		; four?
		jz		V4		;
		dec		al		; five?
		jz		V5		;
		jmp short	V6		; six
V0:		CalcEga		100		; calc es:di and bank switch
		jmp short	V16		;
V1:		CalcEga		128		; calc es:di and bank switch
		jmp short	V16		;
V2:		DoubleWide			; mode 2 is a simulation
V3:
V4:		mov		ax,640		;
		jmp		V256		;
V5:		SkipOneRowOf	6		; Simulate 640x480
		mov		ax,640		;
		jne		V256		; not row 5, display it
		ret				; else skip
V6:		mov		ax,800		;
		jmp short	V256		;
V16:		WriteEga			;
		ret
V256:		DisplaySVGA			;
DisplayRow endp

New_BankSet	equ		false

; dx:ax is Video segment:offset, bank switch and set es:di
BankSet proc near
; set es:di
IF New_BankSet
		mov		di,ax		;
		mov		ax,GraphicsRAM	; A000
		mov		es,ax		; es:di -> A000:address
; bank switch
		mov		ax,dx		; bank number
		cmp		al,CurrentBank	; do we need to switch?
		je		Video7BankOk	;
		mov		CurrentBank,al	;
		and		ax,15		;
		mov		bl,al		; save bank in BL <--
		mov		dx,3C4h		; could
		mov		ax,0EA06h	;  this be
		out		dx,ax		;   "enable extensions"?

;	Set Bank for 256 color modes
;
;	Routine: set_256_bank
;	Entry: DX = bank to set and DS=CS
;	Exit: Correct bank set, AX,BX,DX are
;		destroyed. SC_INDEX has been changed.
;
;	Assume: Extensions are enabled. The active page variable has
;		been properly initialized with a call to this routine
;		while DX=0.
;
SC_INDEX	equ	3C4h
ER_PAGE_SEL	equ	0F9h
MISC_INPUT	equ	3CCh
MISC_OUTPUT	equ	3C2h
ER_BANK_SEL	equ	0F6h

		mov	dx,SC_INDEX		;bank bit 0
		mov	ah,bl
		and	ah,1
		mov	al,ER_PAGE_SEL
		out	dx,ax

		mov	ah,bl			;bank bit 1
		and	ah,2
		shl	ah,1
		shl	ah,1
		shl	ah,1
		shl	ah,1
		mov	dx,MISC_INPUT
		in	al,dx
		and	al,not 20h
		mov	dx,MISC_OUTPUT
		or	al,ah
		out	dx,al

		mov	dx,SC_INDEX		;bank bit 2.
		mov	al,ER_BANK_SEL
		out	dx,al			;get ER_BANK_SEL register
		inc	dx
		in	al,dx
		mov	ah,al
; duplicate bit 2 into bit 0 (set read and write bank equal)
		shr	bl,1
		shr	bl,1
		add	bl,7
		not	bl
		and	bl,5
		and	ah,0F0h			;clear bank select bits
		or	ah,bl
		mov	al,ah
		out	dx,al
ELSE
		mov		di,ax		;
		mov		ax,GraphicsRAM	; A000
		mov		es,ax		; es:di -> A000:address
; bank switch
		mov		ax,dx		; bank number
		cmp		al,CurrentBank	; do we need to switch?
		je		Video7BankOk	;
		mov		CurrentBank,al	;
		and		ax,15		;
		mov		ch,al
		mov		dx,3C4h
		mov		ax,0EA06h
		out		dx,ax
		mov		ah,ch
		and		ah,1
		mov		al,0F9h
		out		dx,ax
		mov		al,ch
		and		al,1100b
		mov		ah,al
		shr		ah,1
		shr		ah,1
		or		ah,al
		mov		al,0F6h
		out		dx,al
		inc		dx
		in		al,dx
		dec		dx
		and		al,not 1111b
		or		ah,al
		mov		al,0F6h
		out		dx,ax
		mov		ah,ch
		mov		cl,4
		shl		ah,cl
		and		ah,100000b
		mov		dl,0CCh
		in		al,dx
		mov		dl,0C2h
		and		al,not 100000b
		or		al,ah
		out		dx,al
ENDIF
Video7BankOk:	ret
BankSet endp

		end
