COMMENT *

			     CLUBware  (tm)

	  CLREOS clears the screen from the current position to the end
		  of the screen.  Cursor is left at starting
		  position.

		   Copyright 1984 Rayhawk Automation N.W. Inc
				  P.O. Box 1427
				  Beaverton, Oregon   97075


	  Algorithm:
		  1) load type of crt display from 0000:463
		  2) turn off crt display
		  3) load current position from 0000:0450
		  4) determine number of blanks to end of screen
		  5) do repeated store into screen buffer to blank area
		  6) reactive crt display


	  CALL	  CLREOS ( FLAG% )

		  FLAG%       environment flag
			      = 0 means under basic interpreter
			      = 1 means under compiled basic
			      = 2 means under compiled business basic

									      *

;______________________________________________________________________________

;  Normal assembly directives

CODE	  SEGMENT PARA PUBLIC 'CODE'

	  ASSUME  CS:CODE

	  PUBLIC  CLREOS

ENV_FLAG	  EQU  WORD PTR [BP+6] ; address of environment flag on stack

;______________________________________________________________________________

CLREOS	  PROC	  FAR

	  PUSH	  AX		       ; save all registers used,
	  PUSH	  BX
	  PUSH	  CX
	  PUSH	  DX
	  PUSH	  DI
	  PUSH	  ES



;	  ...	  1) load type of crt display from 0000:463

	  SUB	  AX,AX 		     ; address system area
	  MOV	  ES,AX

	  MOV	  DX,WORD PTR ES:[463h]      ; load address of display adapter



;	  ...	  2) turn off crt display
;		     if this is a graphic display, wait for vertical retrace

	  ADD	  DX,4		       ; addres crt control port

	  CMP	  DX,3D8h	       ; graphic card?
	  JNE	  NOT_GRAPHIC

	  ADD	  DX,2		       ; address crt status port
VERT_RETRACE:
	  IN	  AL,DX 	       ; wait for vertical retrace
	  TEST	  AL,8
	  JZ	  VERT_RETRACE
	  SUB	  DX,2		       ; address crt mode port

NOT_GRAPHIC:

	  MOV	  AL,21h	       ; turn off the video signal
	  OUT	  DX,AL


;	  ...	  3) load environment flag showing compiled or interpreted

	  MOV	  BX,ENV_FLAG	       ; load address of environment flag


;	  ...	  4) load current position from 0000:0450 if compiled
;		      or from DS:[0056h] if interpreted


	  CMP	  WORD PTR DS:[BX],0	   ; check environment flag
	  JNE	  COMPILED

	  MOV	  CX,WORD PTR DS:[0056h]   ; load from basic space
	  XCHG	  CL,CH 		   ; basic has it reversed
	  DEC	  CL			   ; basic starts count from 1
	  DEC	  CH			   ;  instead of zero
	  JMP	  SHORT HAVE_POSITION

COMPILED:
	  MOV	  CX,WORD PTR ES:[450h]    ; load current position
					   ;  from system space
HAVE_POSITION:

	  SUB	  AH,AH 	       ; isolate row number in AX
	  MOV	  AL,CH
	  MOV	  BL,80 	       ; multiply row by 80 bytes per row
	  MUL	  BL
	  SUB	  CH,CH 	       ; add in column number
	  ADD	  AX,CX

	  MOV	  DI,AX
	  SHL	  DI,1		       ; multiply by 2 to account
				       ;  for attribute bytes



;	  ...	  5) determine number of blanks to end of screen

	  MOV	  CX,2000	       ; 2000 chars on entire screen
	  SUB	  CX,AX 	       ; cx now holds number of blanks



;	  ...	  6) do repeated store into screen buffer to blank area

	  MOV	  AX,0B000h	       ; screen seg for monochrome card
	  CMP	  DX,03D8h	       ; is this a graphic card?
	  JNE	  MONOCHROME

	  MOV	  AX,0B800h	       ; load screen seg for graphic card

MONOCHROME:

	  MOV	  ES,AX 	       ; address the screen buffer
	  MOV	  AX,0720h	       ; AH = 07 ( normal video attribute
				       ; AL = 20 ( blank
	  REP	  STOSW 	       ; store CX blanks



;	  ...	  7) reactive crt display


	  MOV	  AL,29h	       ; DX already has correct port
	  OUT	  DX,AL



	  POP	  ES
	  POP	  DI
	  POP	  DX
	  POP	  CX
	  POP	  BX
	  POP	  AX
	  RET	  2


CLREOS	  ENDP

;______________________________________________________________________________

CODE	  ENDS

	  END
