;............................................................................
;
;title		mfix.ins
;version	2.00
;date		04/07/86
;written by	Kevin Murphy
;
; vers 2.00     - new release for METAL/Z-MSG vers 1.4xx or later
;		  and BYE503 or later. Needed to support the TIME CHECK 
;		  feature in MEXIT.
;..............................................................................
; >>> comments <<<
;..............................................................................
;
; Find and DELETE the line in BYE503 or newer which reads:
; *---->   SRUDEF:   RET
;
; INSERT this file in it's place
;
; BCD2BIN equate must be set to YES in BYE5xx
;..............................................................................
; >>> equates <<<
;..............................................................................
;
MAXCALS	EQU	10	;maximum number of calls per day if exceeded 
			;tell him why, and hang up
			;set to zero for no maximum
			;This is bypassed if the user has unlimited time
;
;			;metal buffer pointers	
UTIME	EQU	69	;pointer to time
UDATE	EQU	66	;pointer to date
UMINS	EQU	79	;mins on today, so far
UD	EQU	124	;date of umins 
UM	EQU	125	;month of umins
UTC	EQU	126	;times called on this day
;
;..............................................................................
; >>> main routine <<<
;..............................................................................
;enter with address of user record in DE
;
SRUDEF:
	XCHG			;get user address in HL
	SHLD	USER		;save it
	LHLD	USER		;get it back, (incase we slip a routine in )
	LXI	B,UDATE+1	;point to current day 
	DAD	B
	MOV	A,M		;get day, and save it in A
	LHLD	USER		;point to day of last umins update
	LXI	B,UD		;
	DAD	B		;
	MOV	B,M		;get the minson day
	CMP	B		;compare
	JNZ	OKDAY		;no match, no problem, 
;
	LHLD	USER		;get base pointer
	LXI	B,UDATE		;add date offset
	DAD	B
	MOV	A,M		;get month
	LHLD	USER		;get pointer again
	LXI	B,UM		;add offset
	DAD	B
	MOV	B,M		;get check month
	CMP	B		;compare
	JNZ	OKDAY		;no match, no problem,  
;
;same day...
;
	LXI	B,UTIME		;
	CALL	GET		;convert it
	STA	HOUR		;save it
	LXI	B,UTIME+1	;
	CALL	GET		;convert it
	STA	MIN		;save it
;
	LDA	MXTIME		;check wheel
	CPI	0		;is it a normal user ?
	JZ	NOMAX		;no
;
	LHLD	USER		;make sure we have not exceeded max calls
	LXI	B,UTC		;point to times called today
	DAD	B
	MOV	B,M		;get it in B
;
	MVI	A,MAXCALS	;get max times allowed
	CPI	0		;is it zero
	JZ	NOMAX		;then skip this stuff
;
	SUB	B
	JZ	KILLER		;if it was a match, say he's been on forever
	JC	KILLER
;
NOMAX:
;
	LHLD	USER		;point to minutes on to day
	LXI	B,UMINS		;
	DAD	B
	MOV	A,M		;get value 
	CPI	0		;if no update, no problem
	RZ			;return to metal
;
	MOV	B,A		;do routine 
	LDA	MIN		;get login minutes in c
	CPI	0		;did hour just turn ???
	JZ	DOHOUR		;yep, set up to previous hour + 60 mins
	MOV	C,A		;do it
;
SUBTR:
;
	DCR	C		;dec
	JZ	DOHOUR		;if zero, drop the hour count
	DCR	B		;dec lop count
	JNZ	SUBTR		;loop till done
	MOV	A,C		;get new minute value 
	STA	MIN		;save it
	LDA	HOUR		;reset log in time in bye
	MOV	D,A
	LDA	MIN
	MOV	E,A
	CALL	RMLTIM		;use a short cut to extended bdos
	RET			;get your butt back to metal 
;
;...............................
;
OKDAY:
	LHLD	USER		;point to minutes on to day
	LXI	B,UMINS		;zero time on today
	DAD	B
	MVI	M,0
	RET
;
;................................
;
DOHOUR:				;increment hour, reset minutes
	LDA	HOUR		;get binary hour
	DCR	A		;dec
	STA	HOUR		;save new count	
LOADMIN:
	MVI	C,60		;restart minutes at 60
	JMP	SUBTR		;go back to loop
;
;................................
;
GET:				;convert bcd byte pointed to by HL
				;to binary byte in A
	LHLD	USER		;get base address
	DAD	B		;add in off set
	MOV	A,M		;get 1st
	CALL	BCDBIN		;convert BCD to binary
	RET			;return to sender, result in A
;
;................................
;
KILLER:				;exceeded maximum number of calls for the day
	LXI	H,TOOMANY	;tell them they have called to many times
	CALL	PRINTB		;print local and remote
	CALL	PATCH		;patch up bye
	JMP	LOGOFF		;logout, sign off, and all that
;
;..............................................................................
; >>> db area <<<
;..............................................................................
;
USER:	DW	00		
HOUR:	DB	0
MIN:	DB	0
TOOMANY: DB	7,CR,LF,'[You''ve called too many times today !]',CR,LF,0 
;
;..............................................................................
; >>> end of insert <<<
;..............................................................................
;   <eof>	mfix2xx.ins
;..............................................................................
