                                BLANK   ASM '                  BLANK   COM(                                                 TITLE  DOS 2.0 Screen Blanking Program
PAGE 82,132
;------------------------------------------------------------------------
;  Program BLANK2.COM will blank screen after after two minutes of
;  inactivity.  This program by Gerard Perreault is based on
;  the program BLANK.COM submitted by Christopher Wiley in
;  PC World Volume 2, Number 4.  
;------------------------------------------------------------------------

;------------------------------------------------------------------------
;  Modified by Steve Cook 1-JUN-84      PC World Volume 2, Number 11.
;------------------------------------------------------------------------

;  Define the code segment, and set things up for a .COM program

CSEG	SEGMENT	PARA	PUBLIC	'CODE'
	ASSUME	CS:CSEG,DS:CSEG

;  Programs which are to be put through EXE2BIN must start at address
;  100H

	ORG	100H
 
START:	JMP	GO		;Jump around the data area

SWFLAG	DB	0		;Video not switched off (1 if TRUE)
KEYFLAG	DB	0		;No key input nor display since video off
COUNT	DW	0		;Timer count

AD6845	EQU	63H		;CRT control port base address
CRTMode EQU	65H		;Current state of CRT mode register

GO:
	MOV     AH,35H		;Get address at 1C vector (timer 18.2
	MOV	AL,1CH		;times per second frequency)
	INT	21H
	PUSH	ES		;Move ES:BX to DS:DX
	PUSH	BX
	POP	DX
	POP	DS
	MOV	AH,25H		;Set into interrupt 60H as replacement
	MOV	AL,60H
	INT	21H

	MOV	AH,35H		;Do same for keyboard interrupt
	MOV	AL,09H
	INT	21H
	PUSH	ES
	PUSH	BX
	POP	DX
	POP	DS
	MOV	AH,25H
	MOV	AL,61H
	INT	21H

	MOV	AH,35H		;Do same for video interrupt
	MOV	AL,10H
	INT	21H
	PUSH	ES
	PUSH	BX
	POP	DX
	POP	DS
	MOV	AH,25H
	MOV	AL,62H
	INT	21H

	PUSH	CS		;Now set new values in the vectors
	POP	DS		;1CH, 09H, AND 10H
	MOV	DX,OFFSET TICKER
	MOV	AH,25H
	MOV	AL,1CH		;... as TICKER
	INT	21H

	PUSH	CS
	POP	DS
	MOV	DX,OFFSET KEY_IN
	MOV	AH,25H
	MOV	AL,09H		;... as KEY_IN
	INT	21H

	PUSH	CS
        POP	DS
	MOV	DX,OFFSET VIDEO_OUT
	MOV	AH,25H
	MOV	AL,10H		;... as VIDEO_OUT
	INT	21H

	MOV	DX,(OFFSET END_PR)+100H	;Finished, leave resident and
	INT	27H		;add more room than needed to avoid 
				;INT 27H bug.

;  Process the 2CH interrupt which occures 18.2 times per second

TICKER:
	STI			;Restore interrupts
	PUSH	AX		;Save some registers
	PUSH	DS
	PUSH	CS		;Set the DS register the same as CS
	POP	DS
	CMP	SWFLAG,0	;Have we switched the video off?
	JNE	T01		;yes.
	INC	COUNT		;No, keep counting the clock pulses
	CMP	COUNT,0888H	;Unitl we get to 2 minutes
	JNAE	T02		;by the way, did we hit the limit?
        MOV	COUNT,0		;Yes, reset the count and
	PUSH	DX		;save these registers, too
	PUSH	ES		;Now to switch the video off...
	MOV	AX,0040H	;(Base address of ROM data area)
	MOV	ES,AX
	MOV	DX,ES:AD6845	;Get base address of the video controller
	ADD	DX,4		;Point to controller's mode register
	MOV	AL,ES:CRTMode	;Get current mode settings
	AND	AL,11110111B    ;clear the video enable bit to
	OUT	DX,AL		;Turn off the video.
	POP	ES
	POP	DX
	MOV	SWFLAG,1	;Flag that we have switched off
	JMP	SHORT T02	;standard exit.
T01:
	CMP	KEYFLAG,0	;We have switched off.  Has a key been
				;pressed or attempt been made to display
	JE	T02		;character since then?  No.
	PUSH	DX		;Yes.  Restore the video signal
	PUSH	ES
	MOV	AX,0040H	;First, point to the ROM data area
	MOV	ES,AX
	MOV	DX,ES:AD6845	;Get base address of video controller
	ADD	DX,4		;and point to controller mode register
	MOV	AL,ES:CRTMode	;Get the old mode settings and
	OUT	DX,AL		;restore them.
	POP	ES
	POP	DX
	MOV	KEYFLAG,0	;Reset the flags as: No key in/video
	MOV	SWFLAG,0	;not switched
	MOV	COUNT,0		;Reset (again) count to 0
T02:
	POP	DS              ;Standard exit.  Restore used registers
	POP	AX		;and process whatever was
	INT	60H		;at INT 1CH before this
	IRET			;program came into action.

; The user has pressed a key...
KEY_IN:
	STI			;Restore interrupts
	PUSH	AX		;save the registers which we will use
	PUSH	DS
	PUSH	CS		;set DS to the same as CS
	POP	DS
	CMP	SWFLAG,0	;Are we already switched off?
	JE	K01		;No.
	MOV	KEYFLAG,1	;Yes. Set the flag that we got a key
	INT	1CH
K01:
	MOV	COUNT,0		;Reset count to 0
	POP	DS		;Restore the saved register and inform
	POP	AX		;the system by causing the equivalent
	INT	61H		;of an INT 09H in this program.
	IRET

;  The system wants to output to the screen...
VIDEO_OUT:
	STI			;Restore interrupts
	PUSH	AX		;Save registers
	PUSH	DS
	PUSH	CS		;Make DS the same as CS
	POP	DS
	CMP	SWFLAG,0	;Have we switched the video off?
	JE	V01		;No.
	MOV	KEYFLAG,1	;Yes. Flag that we want video on
	INT	1CH
V01:	MOV	COUNT,0		;Reset the count to 0
	POP	DS		;Restore registers
	POP	AX
	INT	62H		;Process the video request
	IRET

END_PR:				;Used to determine length of program

CSEG	ENDS
	END	START
    5!SZ%`!5	!SZ%a!5!SZ%b!]%!%	!%!'P> u1>DrR  R@ &c &e $Z-> t&R@ &c &e Z    X`P> t  XaP> t  Xb