;*************************************************************************
;  B5C-H8F2.INS    ( H89 RTC clock code for BYE5xx
;   09/06/85	     w/ FBE UTI board)
;
;  v1	September 1985	 Adam Koczarski  206-827-9198
;  v2	October   1985 - Had century and year reversed...Oops
;
; This is to be inserted in the BYE5 code right after IF TIMEON label following
; the machine insert.
;
;****************************************************************************
;
CLKA	EQU	0D4H	;CLOCK ADDRESS PORT
CLKD	EQU	0D2H	;CLOCK DATA PORT
PPIX	EQU	0D7H	;8255 COMMAND PORT
;
;
TIME:
	CALL	CREAD		; read data from clock chip
	LDA	TBFR+4
	STA	RTCBUF+0	; Hour
	LDA	TBFR+5
	STA	RTCBUF+1	; Minute
	LDA	TBFR+6
	STA	RTCBUF+2	; Second
	LDA	TBFR+0
	STA	RTCBUF+3	; Century
	LDA	TBFR+1
	STA	RTCBUF+4	; Year
	LDA	TBFR+2
	STA	RTCBUF+5	; Month
	LDA	TBFR+3
	STA	RTCBUF+6	; Day
	LDA	RTCBUF		; Pick up BCD HH
	CALL	BCDBIN		; And convert to binary
	STA	CCHOUR		; For BYE5
	LDA	RTCBUF+1	; BCD MM
	CALL	BCDBIN
	STA	CCMIN		; To binary for BYE5
	RET			; And return (for now..)
;
;=========
;
; Time/Date buffer consists of 7 bytes of packed BCD-encoded information
; located in buffer TBFR.   Time/Date buffer is of the following format:
;
;	 TBFR  + 0	= century
;	       + 1	= year
;	       + 2	= month
;	       + 3	= day
;	       + 4	= hour
;	       + 5	= minute
;	       + 6	= second
;
CREAD:
	DI
	MVI	A,81H
	OUT	PPIX
	MVI	A,80H
	OUT	CLKA
	EI
;
	LXI	H,TBFR
	LXI	D,ADRTBL
	MVI	B,7
TDLOOP:	LDAX	D
	OUT	CLKA
	IN	CLKD
	MOV	M,A
	INX	H
	INX	D
	DCR	B
	JNZ	TDLOOP
	RET
;
TBFR:	DS	7		;Real-time clock buffer - see above
ADRTBL:	DB	8EH,89H,87H,86H,84H,83H,82H ;Clock memory addr's
;
;***************************************************************************
