NEW
  AUTO 3,1
*--------------------------------------
* Driver For DS1216E
*--------------------------------------
NCLK.START		php
				sei
				sta $CFFF				Make cards release $C8xx space
				sta $C300
				lda $C304				Reset DS1216E comparison register with READ A2=1
				ldy #7					Read 8 bytes...

.1				lda DS1216E.PATTERN,y
				phy
				ldy #8					....of 8 bits

.2				ldx #0
				lsr
				bcc .3
				inx

.3				bit $C300,x				Write Pattern bit in A0, with A2=0
				dey
				bne .2

				ply
				dey
				bpl .1

				ldx #7

.4				ldy #8

.5				lda $C304				Read Byte...

				lsr
				ror DS1216E.DATA,x

				dey
				bne .5

				lda DS1216E.DATA,x
				pha
				lsr
				lsr
				lsr
				lsr
				tay
				pla
				and #$0F

				clc

				.HS	2C					Bit Absolute to skip adc #$0A

.6				adc #$0A
				dey
				bpl .6			

				sta DS1216E.DATA,x
				dex
				bpl .4
				
				lda	DS1216E.DATA+4		Get HH
				sta	TIMELO+1
				lda	DS1216E.DATA+5		Get mm
				sta	TIMELO
				lda	DS1216E.DATA+1		Get MM
				asl
				asl
				asl
				asl
				asl
				ora	DS1216E.DATA+2		Get DD
				sta	DATELO
				lda	DS1216E.DATA		Get YY
				rol	
				sta	DATELO+1			

				plp
				rts
*--------------------------------------
DS1216E.PATTERN	.HS	5CA33AC55CA33AC5	Reverted 7->0
DS1216E.DATA	.BS 8					Reverted YY MM DD Day HH mm SS CS
*--------------------------------------
NCLK.LEN		.EQ *-NCLK.START
*--------------------------------------
MAN
SAVE usr/src/prodos.fx/prodos.s.nclk
LOAD usr/src/prodos.fx/prodos.s
ASM
