TITLE	A VGA ASSEMBLY demo
.MODEL SMALL		       ;Use a small memory model
.286				       ;Use 286 code
.STACK				       ;Set default stack

.DATA
AUTHOR		DB	"Made by Dennis Katsonis.",0Ah,0Dh,24h
NOVGA		DB	"This program needs a VGA card!",0Ah,0Dh,24h

.CODE

MAIN	PROC	FAR	      ; Start of program

	MOV	AX,@DATA	; Copy new data segment to AX
	MOV	DS,AX		; Copy AX to data segment reg.
	MOV	ES,AX		; Copy AX to extra segment reg.

	MOV	AX,1200h	;Test for VGA card
	MOV	BL,36h
	INT	10h
	.IF	AL != 12h
		LEA	DX,NOVGA	;and tell the user
		MOV	AH,09h
		INT	21h
		MOV	AX,4C00h     ; Send exit code to dos
		INT	21h	     ; Send command to DOS
	.ENDIF

	XOR	AH,AH
	MOV	AL,13h
	INT	10h		     ;Set 320 x 200 x 256
	MOV	AX,0A000h	     ;Mov videomem address to AX
	MOV	ES,AX		     ;Then to ES
	MOV	DX,3C8h 	     ;Output to video card we as setting
	MOV	AL,1		     ;colours from colour 1 up
	OUT	DX,AL
	INC	DX		     ;change dx to point to pallete data
	XOR	AL,AL
	OUT	DX,AL
	OUT	DX,AL
	OUT	DX,AL
	MOV	CX,63
SETGRAY:
	DEC	CX
	INC	AL		     ;Change to next colour
	OUT	DX,AL		     ;Set red, green and blue values
	OUT	DX,AL		     ;the same.
	OUT	DX,AL
	TEST	CX,CX		     ;See if were done, test cx,cx is faster
	JNE	SETGRAY 	     ;than cmp cx,0
	MOV	CX,64000
	XOR	DI,DI
GLOOP:

	MOV	ES:[DI],DL
	INC	DI
	DEC	CX
	TEST	CX,CX
	JNE	GLOOP

	MOV	AH,07h
	INT	21h		;Wait for a keypress



	XOR	AH,AH
	MOV	AL,03h
	INT	10h

	LEA	DX,AUTHOR	;and tell the user
	MOV	AH,09h
	INT	21h

	MOV	AX,4C00h	 ; Send exit code to dos
	INT	21h		; Send command to DOS
	RET
MAIN	ENDP			; Set end of program
	END	 MAIN			; Set starting address!
					; Hard to explain. Read the book.
