
	TITLE	'LOGOFF TRANSIENT PROGRAM FOR CP/NET-86'
;***************************************************************
;***************************************************************
;**                                                           **
;**      L O G O F F   T R A N S I E N T   P R O G R A M      **
;**		   F O R   C P / N E T - 8 6
;**                                                           **
;***************************************************************
;***************************************************************
;
; EQUATES
;
M	EQU	BYTE PTR 0[BX]
;
BDOS	EQU	224
BUFF	EQU	0080H
PRINT	EQU	9
VERSION	EQU	12
LOGOFF	EQU	65
CFGTBL	EQU	69
NOACTV	EQU	11101111B 
;
START:
	MOV	BX,0
	ADD	BX,SP
	MOV	SP,(Offset CCPSTACK)+2
	PUSH	BX			; SAVE CCP STACK POINTER
	MOV	CL,VERSION
	INT	BDOS			; GET VERSION NUMBER
	MOV	AL,BH
	AND	AL,00000010B 
	JNZ	L_1	
	JMP	VERSIONERR		; CP/NET MUST BE LOADED
L_1:
	MOV	DL,0			; DEFAULT MSTR ID = 00H
	MOV	BX,BUFF
	MOV	AL,M			; GET # CHARS IN THE COMMAND TAIL
	OR	AL,AL
	JZ	DOLOGOFF		; DEFAULT LOGOFF IF EMPTY COMMAND TAIL
	MOV	CL,AL			; A = # CHARS IN COMMAND TAIL
	XOR	AL,AL
SCANBLNKS:
	INC	BX
	MOV	AL,M
	CMP	AL,' '
	JNZ	PASTBLNKS		; SKIP LEADING BLANKS
	DEC	CL
	JNZ	SCANBLNKS
	JMPS	DOLOGOFF
PASTBLNKS:
	CMP	AL,'['
	JNZ	LOGOFFERR
SCANMSTRID:
	LAHF
	INC	BX
	SAHF
	DEC	CL
	JZ	LOGOFFERR
	MOV	AL,M
	CMP	AL,']'
	JZ	DOLOGOFF
	SUB	AL,'0'
	CMP	AL,10
	JB	UPDATEID
	ADD	AL,('0'-'A'+10) AND 0FFH
	CMP	AL,16
	JNB	LOGOFFERR
UPDATEID:
	LAHF
	XCHG	AL,AH
	PUSH	AX
	MOV	AL,DL
	ADD	AL,AL
	ADD	AL,AL
	ADD	AL,AL
	ADD	AL,AL
	MOV	DL,AL			; ACCUM * 16
	POP	AX
	XCHG	AL,AH
	ADD	AL,DL
	MOV	DL,AL
	JMPS	SCANMSTRID
DOLOGOFF:
	MOV	CL,LOGOFF
	INT	BDOS
	INC	AL
	JNZ	LOGOFFOK
	MOV	DX,(Offset LOGOFFAILEDMSG)
	JMPS	PRINTMSG
VERSIONERR:
	MOV	DX,(Offset VERSIONERRMSG)
	JMPS	PRINTMSG
LOGOFFERR:
	MOV	DX,(Offset LOGOFFERRMSG)
PRINTMSG:
	MOV	CL,PRINT
	INT	BDOS
	JMPS	EXIT
LOGOFFOK:
	MOV	CL,CFGTBL
	INT	BDOS			; GET CONFIG TABLE ADDRESS
	MOV	AL,ES:M
	AND	AL,NOACTV		; TURN OFF ACTIVE BIT
	MOV	ES:M,AL
EXIT:
	POP	BX
	MOV	SP,BX			; RESTORE CCP STACK POINTER
	RET
L_2	EQU	$
	DSEG
	ORG	Offset L_2
;
; LOCAL DATA SEGMENT
;
VERSIONERRMSG	RS	0
	DB	'CP/NET-86 is not loaded.'
	DB	'$'
LOGOFFERRMSG	RS	0
	DB	'Illegal LOGOFF Command.'
	DB	'$'
LOGOFFAILEDMSG	RS	0
	DB	'LOGOFF Failed.'
	DB	'$'
LCLSTACK	RS	0
	DW	0C7C7H,0C7C7H,0C7C7H,0C7C7H,0C7C7H
	DW	0C7C7H,0C7C7H,0C7C7H,0C7C7H,0C7C7H
CCPSTACK	RS	0
	DW	(Offset $)-(Offset $)
;
	END
