;Compile into a .COM file
TITLE   CGA test program
.MODEL SMALL
.STACK

.8086           ;Use 8086 code
.DATA

AUTHOR		DB	"Made by Dennis Katsonis",0ah,0dh,24h

.CODE
MAIN    PROC    NEAR          ; Start of program

	MOV	AX,@DATA
	MOV	DS,AX

	MOV     AX,0B800h
	MOV     ES,AX           ;and ES to start of video mem for CGA
	XOR     DI,DI
	MOV     AX,0005h
	INT     10h

	MOV     CX,8000d
LOOP1:
	DEC     CX

	CALL	RANDOM
	MOV	ES:[DI],BH
	INC     DI
	TEST    CX,CX
	JNE     LOOP1
	MOV     CX,8000d        ;copy 8000 bytes (8000 x 4 = 32000 pixels)
	MOV     DI,8192         ;point DI to second half of video mem
				;which is NOT immediately after the first half

LOOP2:
	DEC     CX
	CALL	RANDOM

	MOV	ES:[DI],BL
	INC     DI
	TEST    CX,CX
	JNE     LOOP2

	MOV     AH,07h
	INT     21h             ;Wait for a keypress
	MOV     AX,0003h                ;Set back to text mode
	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

RANDOM	PROC	NEAR
	ADD	AX,CX	;Creates a random number
	PUSH	CX
	MOV	CL,3
	SHL	BX,CL		;This does not use the MUL opcode
	ADD	BX,AX	;but uses left shift's to multiply
	POP	CX

	RET
RANDOM	ENDP


END	 MAIN			; Set starting address!
