;	DATE/TIME UPDATE ROUTINE
;	TO BE CALLED ONCE EVERY SECOND
;	DESTROYS ALL REGISTERS
;
	NAM	UPTIM
;
	ENT	UPTIM
;
	EXT	CLKCB
;
UPTIM:	MVI	C,2		; SEC, MIN BOTH 60
	LXI	H,CLKCB		; TIME BLOCK
	LXI	D,5		; ACCESS SECOND
	DAD	D
;
INRM1:	CALL	UPHEX		; INCREMENT
	MOV	A,M
	CPI	60H
	RNZ			; IF NOT 60, DONE
	MVI	M,0
	DCX	H
	DCR	C
	JNZ	INRM1
;
	CALL	UPHEX		; HOUR
	MOV	A,M
	CPI	24H
	RNZ			; IF NOT 24, DONE
	MVI	M,0
	DCX	H		; GOT TO DO DAY/MONTH/YEAR 
;
	CALL	UPHEX
	MOV	A,M
	CPI	29H
	RLT			; IF LESS THAN 29 ALWAYS GOOD
	PUSH	H		; SAVE 'DAY' ADDRESS
	DCX	H
	MOV	A,M		; GET MONTH
	CPI	10H		; TEST FOR OCT-NOV-DEC
	JLT	NOTOND
	SUI	6		; CONVERT
NOTOND:	MOV	C,A		; ADJUSTED MONTH
	MVI	B,0
	LXI	H,MONTBL-1
	DAD	B		; GET DAYS/MONTH BYTE
	MOV	A,M		; INTO 'A'
	POP	H		; RE-ADDRESS DAY
	CMP	M
	RGE			; IF A => M, OK - ELSE GO ON
	CPI	28H		; IS THIS FEB
	JNE	UPMON		; NO, INCREMENT MONTH
	INR	A		; CHANGE A TO 29H
	CMP	M		; IF NOT DAY 29, UPMON
	JNE	UPMON
;
	DCX	H
	DCX	H		; TEST FOR LEAP YEAR
	MOV	A,M
	ANI	01
	JNZ	UPMON0		; ODD MUST BE NON-LEAP
	MOV	A,M
	ANI	12H
	RZ			; IS LEAP - ALLOW 29
	CPI	12H
	REQ			; IS LEAP - ALLOW 29!
;
UPMON0:	INX	H
	INX	H		; BACK TO 'DAY'
UPMON:	MVI	M,1		; SET DAY 1 OF MONTH
	DCX	H		; ADDRESS MONTH
	CALL	UPHEX
	MOV	A,M
	CPI	13H		; IS IT MONTH 13?
	RNE
	MVI	M,1		; SET JANUARY
	DCX	H
	CALL	UPHEX		; NEW YEAR
	RET
;
MONTBL:	DB	31H,28H,31H,30H,31H,30H,31H,31H,30H,31H,30H,31H
;
UPHEX:	INR	M	; INCREMENT
	MOV	A,M
	ANI	0FH
	CPI	0AH
	RNE		; IF NOT (X)A, GOOD
	MVI	A,6	; ELSE ADD 6 TO MAKE (X+1)0
	ADD	M
	MOV	M,A
	RET
;
	END
