;
;**********************************************************************
;
; B5C-XERO.INS	A TIME insert for BYE500 and up
;  07/15/85	Note:  This is an insert--not an overlay
;			Wayne Masters
;			Potpourri, 408-378-7474
;
; Adapted from:
; MBC-XERO.ASM -- Version 1.0 -- 05/24/84 -- by Isaac Salzman
;
;	This insert is for a Xerox 820-II running BYE5. This
;	routine will only work on a Xerox 820-II, not an 820. It
;	will also (most likely) work on the 16/8 as well.
;
;	When called this routine will check the RTCBUF. If a '99H'
;	is in the first byte, the clock is initialized. Next the
;	seconds are checked, and if changed since last update of
;	RTC buffer, the clock is stopped, data copied to RTCBUF and
;	the clock is restarted. (If no change in seconds, the
;	routine returns immediately.)
;
;**********************************************************************
;
;
;Xerox clock initialization
;
XERCLK	EQU	0F039H		; Location of Xerox 820-II time vector
				; Monitor routine. When called, it returns
				; The addr of the 820's clock in high mem.
TIME:
	LXI	H,0		; Clear HL
	CALL	XERCLK		; Get pointer to TOD in HL
	MOV	A,M
	CALL	MOVETM
	STA	RTCBUF+6	; Get day
;
	INX	H
	MOV	A,M
	CALL	MOVETM
	STA	RTCBUF+5	; Get month
;
	INX	H
	MOV	A,M
	CALL	MOVETM
	STA	RTCBUF+4	; Get year
;
	INX	H
	MOV	A,M
	CALL	MOVETM
	STA	RTCBUF		; Update hours
;
	INX	H
	MOV	A,M
	CALL	MOVETM
	STA	RTCBUF+1	; Update minutes
;
	INX	H
	MOV	A,M
	CALL	MOVETM
	STA	RTCBUF+2	; Update seconds
;
	LDA	RTCBUF		; Get BCD HH
	CALL	BCDBIN		; And convert to binary
	STA	CCHOUR		; For BYE5
	LDA	RTCBUF+1	; Get BCD MM
	CALL	BCDBIN
	STA	CCMIN		; Binary for BYE5
	RET			; And return (for now..)
;
MOVETM:	MVI	B,0		; Clear reg B
CONV:	CPI	10		; Are we >= 10 ?
	JC	ADDREST		; No, add the rest
	SUI	10		; Subtract 10 from A
	MOV	C,A		; Put A in C (store it for a sec)
	MOV	A,B		; Put B in A
	ADI	16		; Add 16
	MOV	B,A		; Store it back in B
	MOV	A,C		; Get our original value back in A
	JMP	CONV
ADDREST:
	ADD	B		; Add the rest to what's in A
	RET			; Return
;
;**********************************************************************
;
; This is the end of the TIME insert for BYE500 and up. If you
; replace the existing TIME insert with this, and have a Xerox 820-II,
; it SHOULD work fine...
;
;**********************************************************************
;
