; B5C-DS.INS	BYE5 Clock Insert for any 8080- or Z80-compatible
; 		computer with DateStamper running "high" (CCP not
;		protected).  Requires that the DS clock driver
;		entry address be pointed to by a vector at 0008H
;		or another available and safe RST call address.
;		The vector is set up by a utility like DSSET or
;		DSTOBYE, or by simply poking a C3h at 0008h and
;		the DS clock driver entry address at 0009h (LSB
;		first, of course).  The clock address is usually
;		displayed when DS itself loads, recent versions
;		(1.2 or later) of the ZCPR3 utility Z3LOC.COM
;		also display this information.
;
;		Written by Bruce Morgen, May 11, 1988 @14:39:59


; This insert (which is NOT an overlay) uses BYE5xx's "BCDBIN"
; code, so set the BYE5xx equate "BCD2BIN" to "YES".

;
; BYE5 saves and restores registers before/after calling TIME.
;
VECADD	EQU	0008H		; Choose an RST vector, normally
				; 0008h is available and safe.
TIME:
	LXI	H,DSBFR
	RST	VECADD/8	; Fill temp. buffer from DS,
;A jmp to the DS clock driver is initialized before BYE is run
	LXI	D,RTCBUF+2	; Point BYE seconds
	MOV	A,M		; DS seconds in A
	STAX	D		; To BYE
	DCX	H		; Decrement pointers
	DCX	D
	MOV	A,M		; DS minutes in A
	STAX	D		; To BYE
	CALL	BCDBIN		; Convert to binary
	STA	CCMIN		; for BYE
	DCX	H		; Decrement pointers
	DCX	D
	MOV	A,M		; DS hours in A
	STAX	D		; To BYE
	CALL	BCDBIN		; Convert to binary
	STA	CCHOUR		; for BYE
	DCX	H		; Point DS day
	LXI	D,RTCBUF+6	; and BYE day
	MVI	B,3		; Move 3 bytes
MCLKLP:
	MOV	A,M		; 8080-style move loop
	STAX	D
	DCX	H
	DCX	D
	DCR	B
	JNZ	MCLKLP
	XCHG			; HL points to BYE century
	MVI	M,19H		; Poke in current century
	RET			; All done...

; DateStamper's time buffer format (packed BCD):
DSBFR:	DS	1		; 00 - 99 (year)
	DS	1		;  1 - 12 (month)
	DS	1		;  1 - 31 (day)
	DS	1		; 00 - 23 (hour)
	DS	1		; 00 - 59 (minute)
	DS	1		; 00 - 59 (second)

;**********************************************************************
;
; This is the end of the TIME insert for BYE500 and up.
; Replace the existing BYE5 TIME code with this insert.
; It SHOULD work fine...
;
;**********************************************************************
