;=========================================================
;Very poor VGA demo that just puts lines.  Have a look
;and see how VGA graphics are dome.
;=========================================================

TITLE   Crappy VGA graphics demonstration

.MODEL SMALL                           ;Sets it for a SMALL memory model
.286                                   ; Use 286 code
.STACK 100h                            ; Set small stack

.DATA

NOVGA           DB      "A VGA card is needed, sorry!",0ah,0dh,24h
AUTHOR          DB      "Made by Dennis Katsonis.",0ah,0dh,24h


.CODE

MAIN    PROC    NEAR          ; Start of program

	MOV     AX,@DATA
	MOV     DS,AX
	
	MOV     AX,1200h        ;Test for VGA card
	MOV     BL,36h
	INT     10h
				 ;Exit if not detected
	.IF     AL != 12h
		MOV     DX,OFFSET NOVGA ;and tell the user
		MOV     AH,09h
		INT     21h
		MOV     AX,4C01h     ; 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
	PUSH    ES                   ;Save ES
	MOV     AX,0A000h            ;Mov videomem address to AX
	MOV     ES,AX                ;Then to ES
	XOR     DI,DI
	MOV     DX,3C8h              ;Output to video card we as setting
	MOV     AL,1                 ;colours from colour 0 up
	INC     DX                   ;change dx to point to pallete
	XOR     BX,BX
	XOR     AH,AH
	MOV     CX,63
SETRED:                              ;Set gradual red colours
        INC     BL                   ;nect colour register
	MOV     AL,BL
        OUT     DX,AL                ;Output red balue
	MOV     AL,AH
        OUT     DX,AL                ;and green
        OUT     DX,AL                ;and blue
	DEC     CX
        TEST    CX,CX                ;have we done 63 colours?
	JNE     SETRED
	XOR     BX,BX
	MOV     CX,63
SETGREEN:                         ;and green
	INC     BL
	MOV     AL,AH
	OUT     DX,AL
	MOV     AL,BL
	OUT     DX,AL
	MOV     AL,AH
	OUT     DX,AL
	DEC     CX
	TEST    CX,CX
	JNE     SETGREEN
	XOR     BX,BX
	MOV     CX,63
SETBLUE:                              ;and blue
	INC     BL
	MOV     AL,AH
	OUT     DX,AL
	OUT     DX,AL
	MOV     AL,BL
	OUT     DX,AL
	DEC     CX
	TEST    CX,CX
	JNE     SETBLUE

	MOV     CX,64000             ;Set CX to 64000 (64000 pixels)
	XOR     DL,DL
	XOR     AL,AL
GLOOP:
	MOV     ES:[DI],DL           ;Put colour DL at Videomem + DI
	DEC     CX                   ;One down, more to go....
	INC     DI                   ;Increment offset
	INC     DL                   ;Increment colour
	TEST    CX,CX                ;See if 64000 pixels done
	JNE     GLOOP                ;If not done, repeat


	MOV     AH,07h
	INT     21h             ;Wait for a keypress

	POP     ES              ;Restore ES
	XOR     AH,AH
	MOV     AL,03h
	INT     10h
	MOV     DX,OFFSET AUTHOR         ;Print my name
	MOV     AH,09h
	INT     21h
	MOV     AX,4C00h         ; Send exit code to dos
	INT     21h             ; Send command to DOS

MAIN    ENDP                    ; Set end of program
	END      MAIN                   ; Set starting address!
                                        ; 
