;This program is for CLOse MONitor by:
;1. HOTKEY: L_CTRL+L_ALT+BackSpace
;2. MOUSE: Move the mouse to RIGHT and BOTTOM,
;          then press LEFT button to close, press RIGHT button to open

;N2F ENTRY AX=0CBBCH RETURN AX=0BBCCH

INCLUDE MACRO
CODE    SEGMENT
        ORG 100H
        ASSUME CS:CODE,DS:CODE
START:
        JMP BEGIN
;;CS:[103H]
        DB 'CLOMON'
;;CS:[109H]
MON_STAT DB 1 ;MONITOR STATUS 1=OPEN 0=CLOSE
;;CS:[10AH]
DELAY   DB 4
;;CS:[10BH]
ACTIVE  DB 1  ;Mouse calling & auto close function flag. 1=ENABLE 0=DISABLE
;;CS:[10CH]
TIME    DW 0
COUNT   DW 0  ;COUNTER
MOUSE   DW 0
RIGHT   DW 192
BOTTOM  DW 632

;----------------------------

N2F     PROC
        CMP AX,0CBBCH
        JNZ TO_OLD_2F
        MOV AX,0BBCCH
        PUSH CS
        POP BX
        IRET
TO_OLD_2F:
        DB 0EAH
O2FOFF  DW 0
O2FSEG  DW 0
N2F     ENDP

;----------------------------

N9      PROC
        PUSH AX
        MOV AX,CS:TIME
        MOV CS:COUNT,AX
        POP AX

        DB 0EAH
O9OFF   DW 0
O9SEG   DW 0
N9      ENDP

;----------------------------

CLOMON  PROC NEAR
        PUSHF
        PUSH AX
        PUSH BX
        PUSH CX
        PUSH DX
        PUSH DS
        PUSH ES

        PUSH CS
        POP DS

        CMP MOUSE,0
        JZ NO_MOUSE

        CALL INIT_R_B

        MOV AX,3
        INT 33H
        CMP DX,10
        JA CMP_R_B
        CMP CX,10
        JA CMP_R_B

        CMP BX,1
        JNZ CMP_BX_2
        MOV ACTIVE,0
        JMP CLOMON_QUIT

CMP_BX_2:
        CMP BX,2
        JNZ GO_CLOMON_QUIT
        MOV ACTIVE,1

GO_CLOMON_QUIT:
        JMP CLOMON_QUIT

CMP_R_B:
        CMP DX,BOTTOM
        JB NO_MOUSE
        CMP CX,RIGHT
        JB NO_MOUSE

        CMP ACTIVE,1
        JNZ READ_KEY

        CMP BX,1
        JZ CLOSE_IT
        CMP BX,2
        JZ OPEN_IT

NO_MOUSE:
        CMP ACTIVE,0
        JZ READ_KEY
        CMP COUNT,0
        JZ READ_KEY
        DEC COUNT
        CMP COUNT,0
        JZ CLOSE_IT

READ_KEY:
        DEC DELAY
        CMP DELAY,0
        JZ GO_ON
        JMP CLOMON_QUIT
GO_ON:
        MOV DELAY,4
        MOV AX,0
        MOV ES,AX
        CMP BYTE PTR ES:[0418H],00000011B ;L-CTRL_L-ALT
        JNZ CLOMON_QUIT
        IN AL,60H
        CMP AL,14 ;BackSpace
        JZ IS_BACKSPACE
        CMP AL,13 ;'+'
        JZ IS_PLUS
        CMP AL,12 ;'-'
        JNZ CLOMON_QUIT

        CALL INIT_KEY
        MOV ACTIVE,0
        JMP CLOMON_QUIT
IS_PLUS:
        MOV ACTIVE,1
        CALL INIT_KEY
        JMP CLOMON_QUIT

IS_BACKSPACE:
        CALL INIT_KEY
POP_UP:
        CMP MON_STAT,0
        JZ OPEN_IT

CLOSE_IT:
        MOV AX,1201H ;CLOSE THE MONITOR
        MOV BL,36H
        INT 10H
        MOV MON_STAT,0
        JMP SHORT POP_UP_END

OPEN_IT:
        MOV AX,1200H ;OPEN THE MONITOR
        MOV BL,36H
        INT 10H
        MOV MON_STAT,1
        MOV AX,TIME
        MOV COUNT,AX
POP_UP_END:

CLOMON_QUIT:
        POP ES
        POP DS
        POP DX
        POP CX
        POP BX
        POP AX
        POPF
        DB 0EAH
OFF8    DW ?
SEG8    DW ?
CLOMON  ENDP

INIT_KEY PROC
        IN AL,61H
        MOV AH,AL
        OR AL,80H
        OUT 61H,AL
        MOV AL,AH
        OUT 61H,AL
        CLI
        MOV AL,20H
        OUT 20H,AL
        RET
INIT_KEY ENDP

INIT_R_B PROC
        PUSH DS
        PUSH CS
        POP DS

        MOV AH,0FH
        INT 10H


;----------------------------------------

        CMP AL,0   ;320x200x16 TEXT
        JZ IS_320X200

        CMP AL,1   ;320x200x16 TEXT
        JZ IS_320X200

        CMP AL,4   ;320x200x16 GRAPHICS
        JZ IS_320X200

        CMP AL,5   ;320x200x16 GRAPHICS
        JZ IS_320X200

        CMP AL,0DH ;320x200x16 GRAPHICS
        JZ IS_320X200

        CMP AL,13H ;320x200x256 GRAPHICS
        JZ IS_320X200


;----------------------------------------

        CMP AL,3   ;25x80x16 TEXT
        JZ IS_640X200

        CMP AL,2   ;25x80x16 TEXT
        JZ IS_640X200

        CMP AL,0EH ;640x200x16  GRAPHICS
        JZ IS_640X200

        CMP AL,06H ;640x200x2   GRAPHICS
        JZ IS_640X200

;----------------------------------------

        CMP AL,5CH ;640x400x256 GRAPHICS
        JZ IS_640X400

;----------------------------------------

        CMP AL,10H ;640x350x16  GRAPHICS
        JZ IS_640X350

        
        CMP AL,0FH ;640x350x2   GRAPHICS
        JZ IS_640X350
        
;----------------------------------------

        CMP AL,5DH ;640x480x256 GRAPHICS
        JZ IS_640X480

        CMP AL,12H ;640x480x16  GRAPHICS
        JZ IS_640X480

        CMP AL,11H ;640x480x2   GRAPHICS
        JZ IS_640X480

        CMP AL,50H ;640x480x16 TEXT
        JZ IS_640X480

        CMP AL,51H ;640x473x16 TEXT
        JZ IS_640X480

;----------------------------------------

        CMP AL,5BH ;800x600x16  GRAPHICS
        JZ IS_800X600

        CMP AL,5EH ;800x600x256 GRAPHICS
        JZ IS_800X600

;----------------------------------------

        CMP AL,5FH ;1024x768x16 GRAPHICS
        JZ IS_1024x768

        CMP AL,62H;1024x768x256 GRAPHICS
        JZ IS_1024x768

        CMP AL,60H  ;1024x768x4 GRAPHICS
        JZ IS_1024x768

;----------------------------------------

        CMP AL,7   ;720x350x2  TEXT
        JZ IS_720X350

;----------------------------------------


IS_320X200:
        MOV BOTTOM,192
        MOV RIGHT,312
        JMP SHORT INIT_R_B_RET

IS_640X200:
        MOV BOTTOM,192
        MOV RIGHT,632
        JMP SHORT INIT_R_B_RET

IS_640X350:
        MOV BOTTOM,342
        MOV RIGHT,632
        JMP SHORT INIT_R_B_RET

IS_640X400:
        MOV BOTTOM,392
        MOV RIGHT,632
        JMP SHORT INIT_R_B_RET

IS_640X480:
        MOV BOTTOM,460
        MOV RIGHT,632
        JMP SHORT INIT_R_B_RET

IS_800X600:
        MOV BOTTOM,592
        MOV RIGHT,792
        JMP SHORT INIT_R_B_RET

IS_1024X768:
        MOV BOTTOM,760
        MOV RIGHT,1000
        JMP SHORT INIT_R_B_RET

IS_720X350:
        MOV BOTTOM,342
        MOV RIGHT,712
        JMP SHORT INIT_R_B_RET


INIT_R_B_RET:
        POP DS
        RET
INIT_R_B ENDP

;--------------------------------------

BEGIN:
        CALL CHK_MYSELF
        JNC GOON_EXEC
REKEY_LOOP:
        MOV AH,0
        INT 16H
        CMP AH,15H ;'Y'
        JZ GOON_EXEC
        CMP AH,31H ;'N'
        JNZ REKEY_LOOP
        MOV AX,4C05H
        INT 21H

GOON_EXEC:

        MOV AX,1100H
        MOV BX,1000H
        MOV CX,10
        MOV DX,219
        LEA BP,MY_DOT
        INT 10H

        CMP WORD PTR DS:[5DH],'?-'
        JZ HELP
        CMP WORD PTR DS:[5DH],'H-'
        JNZ NO_HELP
HELP:
        MOV AH,1
        MOV CX,100H
        INT 10H

        CLS 26
        DCS2 MSG0,80,52,0
        DISPSTR HELPMSG
        MOV AX,0CBBCH
        INT 2FH
        CMP AX,0BBCCH
        JNZ HELP_EXIT
        MOV AX,1
        INT 33H
        DCS2 MSG9,47,30,1808H
RE_KEY:
        MOV AH,0
        INT 16H
        CMP AH,1
        JNZ RE_KEY
        MOV AX,2
        INT 33H
HELP_EXIT:
        MOV AH,1
        MOV CX,506H
        INT 10H

        MOV AX,4C00H
        INT 21H

NO_HELP:
        CLS 7
        DCS2 MSG0,80,30,0
        DCS MSG1,216H,35
        XOR AX,AX
        INT 33H
        MOV MOUSE,AX

        MOV CL,DS:[80H]
        XOR CH,CH
        MOV DI,81H
        ADD DI,CX
        MOV AL,''
        STOSB

        CMP CX,0
        JNZ PARA_LEN_OK
        JMP NO_PARA

PARA_LEN_OK:
        MOV SI,81H
        LEA DI,TIME_BUF

LOOP_EMPTY:
        LODSB
        CMP AL,32
        JZ LOOP_EMPTY
        CMP AL,9
        JZ LOOP_EMPTY
        CMP AL,13
        JNZ DEC_SI
        JMP NO_PARA

DEC_SI:
        DEC SI
PARA_LOOP:
        LODSB
        CMP AL,''
        JZ PARA_END
        CMP AL,'0'
        JB PARA_ERR
        CMP AL,'9'
        JA PARA_ERR

        CMP PARA_LEN,2
        JA PARA_ERR

        CMP PARA_LEN,0
        JA NOT_0
        OR AL,AL
        JZ PARA_LOOP
NOT_0:
        SUB AL,'0'
        STOSB
        INC PARA_LEN

        LOOP PARA_LOOP
        JMP SHORT PARA_END

PARA_ERR:
        DISPSTR MSG3
        MOV AX,4C02H
        INT 21H

PARA_END:
        MOV CL,PARA_LEN
        MOV CH,0
        CMP CX,0
        JNZ JMP1
        JMP NO_PARA
JMP1:
        MOV BL,0
        LEA SI,TIME_BUF
        LODSB
        CMP CX,2
        JNZ STORE_TIME
        MOV BL,10
        MUL BL
        MOV BL,AL
        LODSB

STORE_TIME:
        ADD AL,BL
        MOV AH,0
        PUSH AX
        MOV BX,1092
        MUL BX
        PUSH AX

        MOV AX,0CBBCH
        INT 2FH
        CMP AX,0BBCCH
        JNZ FIRST_INST
        MOV DS,BX
        POP AX

        MOV DS:[10CH],AX
        MOV DS:[10EH],AX

        PUSH CS
        POP DS
        PUSH CS
        POP ES

        POP CX ;CX=AX TIME
        JCXZ TIME_0
        JMP HAVE_EXIST

TIME_0:
        DCS2 MSG8,35,107,416H
        JMP HAVE_EXIST


FIRST_INST:
        POP AX
        MOV TIME,AX
        MOV COUNT,AX

        DISPSTR MSG4
        POP AX
        CALL H2D
        DISPSTR MSG5

NO_PARA:
        MOV AX,0CBBCH
        INT 2FH
        CMP AX,0BBCCH
        JZ HAVE_EXIST

        DCS MSG1,216H,35

        MOV AX,3508H
        INT 21H
        MOV OFF8,BX
        MOV SEG8,ES
        LEA DX,CLOMON
        MOV AX,2508H
        INT 21H

        MOV AX,3509H
        INT 21H
        MOV O9OFF,BX
        MOV O9SEG,ES
        LEA DX,N9
        MOV AX,2509H
        INT 21H

        MOV AX,352FH
        INT 21H
        MOV O2FOFF,BX
        MOV O2FSEG,ES

        LEA DX,N2F
        MOV AX,252FH
        INT 21H

        LOCATE 600H
        LEA DX,BEGIN+1
        INT 27H

HAVE_EXIST:
        MOV AX,0CBBCH
        INT 2FH
        MOV DS,BX
        MOV BL,DS:[10BH] ;ACTIVE FLAG
        PUSH BX
        INT 3
        OR BL,BL
        JZ TIME_IS_0

        MOV AX,DS:[10CH]
        OR AX,AX
        JZ TIME_IS_0

        PUSH AX

        PUSH CS
        POP ES
        PUSH CS
        POP DS
        DISPSTR MSG4


        POP AX
        XOR DX,DX
        MOV BX,1092
        DIV BX
        CALL H2D
        DISPSTR MSG5

TIME_IS_0:
        PUSH CS
        POP ES
        PUSH CS
        POP DS
        DCS2 MSG2,37,28,616H

        POP BX
        CMP BL,1
        JZ IS_ACTIVE
        DISPSTR MSG6
        JMP SHORT GO_HOME
IS_ACTIVE:
        DISPSTR MSG7
GO_HOME:
        MOV AX,4C03H
        INT 21H


MSG0    DB 'CLOse MONitor utility v3.50  '
        DB '(C)opyright DWGsoft Group. DEC,1995 Ûà Üá: Ýâ Þã ßä'
MSG1    DB ' /H/O/T/_/K/E/Y/:/ L-CTRL__L-ALT__BackSpace ',13,10
MSG2    DB '  CLOse MONitor have residented !  '
MSG3    DB 10,10,13,9,'Parameter ERROR! Must be 0 to 60 (MINUTES) & -H or -? (GET HELP)',10,13,36
MSG4    DB 10,10,13,9,' The monitor will be CLOSE without PRESSING A KEY in $'
MSG5    DB ' minutes.',13,10,36
MSG6    DB 13,9,9,' Mouse active & auto close function is DISABLE !',10,13,36
MSG7    DB 13,9,9,' Mouse active & auto close function is ENABLE !',10,13,36
MSG8    DB ' Auto close function is CANCELED ! '
MSG9    DB 'CLOMON has been insatalled. You can do it now !'

HELPMSG DB 10,13,9,9,9,"User's guide for CLOMON v3.50"
        DB 10,13,9,'A.  How to install ?'
        DB 10,13,'Type CLOMON in DOS prompt.'
        DB 10,13,9,'1. C:>CLOMON   Means close monitor by HOTKEY or MOUSE'
        DB 10,13,9,'2. C:>CLOMON x (x from 0 to 60)'
        DB 10,13,9,'   C:>CLOMON 3 Means monitor will be close'
        DB 10,13,9,9,'       without pressing a key in 3 minutes.'
        DB 10,13,9,'   C:>CLOMON 0 Means CANCEL autoclose fnction.'
        DB 10,10,13,9,'B.  How to active it ?'
        DB 10,13,'Active CLOMON in two ways:'
        DB 10,13,9,'1. HOTKEY: L_CTRL+L_ALT+BackSpace'
        DB 10,13,9,'2. MOUSE: Move the mouse to RIGHT and BOTTOM,'
        DB 10,13,9,9,'  then press LEFT button to close, press RIGHT button to open'
        DB 10,10,13,9,'C.  Special Function :'
        DB    10,13,9,'1. DISABLE or ENABLE  MOUSE CALLING and AUTOCLOSE function'
        DB    10,13,9,'a. Move the mouse to the TOP & LEFT,'
        DB    10,13,9,'   press LEFT BUTTON to DISABLE it.'
        DB    10,13,9,'   press RIGHT BUTTON to ENABLE it.'
        DB    10,13,9,'b. Press L_CTRL+L_ALT+"+" ("-") to ENABLE (DISABLE) it.',36

PARA_LEN DB 0
INCLUDE NAME2

OLDSIZE DD 3070
INCLUDE CMPROC
TIME_BUF:
CODE    ENDS
        END START
