NEW
  AUTO 3,1
*--------------------------------------
* Driver For ROMXce Clock
*--------------------------------------
* we can safely use $200, PCL/H, AIL/H (used by TCLK)
*--------------------------------------
XCLK.API.RTCBUF	.EQ $2B0
XCLK.API.RDCLK	.EQ $D8F0
*--------------------------------------
XCLK.START		.PH CLK

XCLK.START1		php
				sei
				ldx #XCLK.START2xx.L-1

.1				lda XCLK.START2xx,X
				sta XCLK.CODE2xx,X
				dex
				bpl .1

				jsr XCLK.CODE2xx
* Minutes
				lda XCLK.API.RTCBUF+1
				and #%01111111			59
				jsr XCLK.BCD2BIN
				sta GP.TIME
* Hour
				lda XCLK.API.RTCBUF+2
				and #%00111111			23
				jsr XCLK.BCD2BIN
				sta GP.TIME+1
* Day
				lda XCLK.API.RTCBUF+4
				and #%00111111			31
				jsr XCLK.BCD2BIN
				sta GP.DATE
* Year
				lda XCLK.API.RTCBUF+6	99
				jsr XCLK.BCD2BIN
				sta GP.DATE+1
* Month
				lda XCLK.API.RTCBUF+5
				and #%00011111			12
				jsr XCLK.BCD2BIN
				asl
				asl
				asl
				asl
				asl
				tsb GP.DATE
				rol GP.DATE+1

				plp
				rts

XCLK.BCD2BIN	tax
				and #$F0
				lsr						CC
				sta ZP.PCL				temp location
				lsr						CC
				lsr						CC
				adc ZP.PCL
				sta ZP.PCL

				txa
*				clc
				and #$0F
				adc ZP.PCL

				rts

XCLK.START2xx	bit IO.RROMBNK2
				sta $C070
				bit $FACA
				bit $FACA
				bit $FAFE
				jsr XCLK.API.RDCLK
				bit $F851
				bit IO.RRAMWRAMBNK1
				bit IO.RRAMWRAMBNK1
				rts

XCLK.START2xx.L	.EQ *-XCLK.START2xx
*--------------------------------------
XCLK.CODE2xx	.EQ XCLK.API.RTCBUF-XCLK.START2xx.L
*--------------------------------------
				.EP
*--------------------------------------
*				.LIST ON
XCLK.LEN		.EQ *-XCLK.START
				.LIST OFF
*--------------------------------------
* CONTROL SECTION :
*--------------------------------------
				.DO XCLK.LEN>125
				ERROR:XCLK Driver too big
				.FIN
*--------------------------------------
MAN
SAVE usr/src/prodos.fx/prodos.s.xclk
LOAD usr/src/prodos.fx/prodos.s
ASM
