
	TITLE	'LOGIN TRANSIENT PROGRAM FOR CP/NET-86'
;***************************************************************
;***************************************************************
;**                                                           **
;**       L O G I N   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		      **
;**                                                           **
;***************************************************************
;***************************************************************
;
;  EQUATION OF FIXED DATA
;
M	EQU	BYTE PTR 0[BX]
;
BDOS	EQU	224		;BDOS ENTRY POINT
BUFF	EQU	0080H
;
;  EQUATION OF BDOS FUNCTION CODE
;
PRINT	EQU	9
VERSION	EQU	12
LOGIN	EQU	64
CFGTBL	EQU	69
ACTIVE	EQU	00010000B 
;
;
	CSEG
	ORG	100H
;
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		; JUMP IF CP/NET NOT LOADED
L_1:
	MOV	DX,(OFFSET PASSWORDMSG)
	MOV	BX,BUFF
	MOV	AL,M			; GET # CHARS IN THE COMMAND TAIL
	OR	AL,AL
	JNZ	L_2	
	JMP	DOLOGIN			; DEFAULT LOGIN IF EMPTY COMMAND TAIL
L_2:
	PUSH	DX			; SAVE LOGIN MSG ADDRESS
	MOV	CL,AL			; A = # CHARS IN COMMAND TAIL
	XOR	AL,AL
	MOV	CH,AL			; B WILL ACCUMULATE MASTER ID
SCANBLNKS:
	INC	BX
	MOV	AL,M
	CMP	AL,' '
	JNZ	PASTBLNKS		; SKIP PAST LEADING BLANKS
	DEC	CL
	JNZ	SCANBLNKS
	JMPS	PRELOGIN		; JUMP IF COMMAND TAIL EXHAUSTED
;
PASTBLNKS:
	CMP	AL,'['
	JZ	SCANMSTRID
	POP	DX			; DISCARD OLD LOGIN MSG ADR
	MOV	DX,(OFFSET BLANKMSG)
	PUSH	DX			; PUSH NEW LOGIN MSG ADR
SCANLFTBRKT:
	MOV	AL,M
	CMP	AL,'['
	JZ	SCANMSTRID
	LAHF
	INC	DX
	SAHF
	MOV	SI,DX			;UPDATE THE PASSWORD
	MOV	[SI],AL
	LAHF
	INC	BX
	SAHF
	DEC	CL
	JNZ	SCANLFTBRKT
	JMPS	PRELOGIN
;
SCANMSTRID:
	LAHF
	INC	BX
	SAHF
	DEC	CL
	JZ	LOGINERR
	MOV	AL,M
	CMP	AL,']'
	JZ	PRELOGIN
	SUB	AL,'0'
	CMP	AL,10
	JB	UPDATEID
	ADD	AL,('0'-'A'+10) AND 0FFH
	CMP	AL,16
	JNB	LOGINERR
UPDATEID:
	LAHF
	XCHG	AL,AH
	PUSH	AX
	MOV	AL,CH
	ADD	AL,AL
	ADD	AL,AL
	ADD	AL,AL
	ADD	AL,AL
	MOV	CH,AL			; ACCUM * 16
	POP	AX
	XCHG	AL,AH
	ADD	AL,CH
	MOV	CH,AL
	JMPS	SCANMSTRID
PRELOGIN:
	MOV	AL,CH
	POP	DX
	MOV	SI,DX
	MOV	[SI],AL
DOLOGIN:
	MOV	CL,LOGIN
	INT	BDOS
	INC	AL
	JNZ	LOGINOK
	MOV	DX,(OFFSET LOGINFAILEDMSG)
	JMPS	PRINTMSG
;
VERSIONERR:
	MOV	DX,(OFFSET VERSIONERRMSG)
	JMPS	PRINTMSG
;
LOGINERR:
	MOV	DX,(OFFSET LOGINERRMSG)
PRINTMSG:
	MOV	CL,PRINT
	INT	BDOS
	JMPS	EXIT
;
LOGINOK:
	MOV	CL,CFGTBL
	INT	BDOS			; GET CONFIGURATION TABLE ADDRESS
	MOV	AL,ES:M
	OR	AL,ACTIVE		; SET ACTIVE BIT TRUE
	MOV	ES:M,AL
EXIT:
	POP	BX
	MOV	SP,BX			; RESTORE CCP STACK POINTER
	IRET
;
;
;
L_3	EQU	$
	DSEG
	ORG	OFFSET L_3
;
; LOCAL DATA SEGMENT
;
PASSWORDMSG	RS	0
	DB	00H			; MASTER ID #
	DB	'PASSWORD'		; PASSWORD
VERSIONERRMSG	RS	0
	DB	'CP/NET-86 is not loaded.'
	DB	'$'
LOGINERRMSG	RS	0
	DB	'Illegal LOGIN Command.'
	DB	'$'
LOGINFAILEDMSG	RS	0
	DB	'LOGIN Failed.'
	DB	'$'
LCLSTACK	RS	0
	DW	0C7C7H,0C7C7H,0C7C7H,0C7C7H,0C7C7H
	DW	0C7C7H,0C7C7H,0C7C7H,0C7C7H,0C7C7H
CCPSTACK	RS	0
	DW	(OFFSET $)-(OFFSET $)
BLANKMSG	RS	0
	DB	00H			; MASTER ID #
	DB	'        '		; PASSWORD
	END
