	IF	IODRIVERBODY
	PAGE	*** CLOCK: DRIVER ***
CLOCKDRIVER	FDB	CLOCKOPEN
	FDB	CLOCKCLOSE
	FDB	CLOCKREADA
	FDB	ILLDEVICEOP	WRITEA IS A NO-NO
	FDB	CLOCKREADB
	FDB	CLOCKWRITEB
	FDB	ILLDEVICEOP	YOU UPDATE THE CLOCK, NOT REBUILD IT (CREATE)
	FDB	ILLDEVICEOP	RENAME IT TO WHAT? CLOCK-RADIO: ???
	FDB	ILLDEVICEOP	YOU CAN'T GET RID OF THE CLOCK, NEITHER
	FDB	ILLDEVICEOP	NO CONTROL FUNCTIONS
	FDB	CLOCKSTATUS	SAY "I'M A CLOCK, TICK-TOCK"
	FDB	CLOCKRESET	
	FDB	CLOCKPFRESTART	WHO UNPLUGGED ME???
*
CLOCKCLOSE	EQU	*	WHAT AM I SUPPOSED TO DO, PUT THE CLOCK AWAY??
CLOCKOPEN	EQU	*	HOW ABOUT LOOKING AT YOUR $9 TI CHEAPIE, MAC!
CLOCKPFRESTART	EQU	*	AM I SUPPOSED TO KEEP TIME WITH NO POWER???
	OKRTS		TOUGH!

*
CLOCKSPRUNG	JMP	ILLDEVICEOP

CLOCKSTATUS	CMPA	#SC:GETTYPE
	BNE	CLOCKSPRUNG
	LDX	SDOS+SDOS:IOBLOCKPTR
	JSR	SDOS+SDOS:CHECKRDLEN	HAS HE GOT A BYTE SPACE
	FDB	1
	LDX	SCBLK:RDBUF,X	GET THE BUFFER POINTER
	LDAA	#DVTYP.CLOCK	I'M ALIVE AND TICKING (HOPEFULLY!)
	STAA	DVTYP:TYPE,X
	OKRTS

CLOCKWRITEB	JSR	SDOS+SDOS:CHECKWRLEN	HAS HE GOT 6 BYTES?
	FDB	6
	LDX	SCBLK:WRBUF,X	WRITE BUFFER POINTER
	LDAB	#6
CLOCKWB1	LDAA	0,X
	INX
	PSHA
	DECB
	BNE	CLOCKWB1
	NOP			DON'T WANT TO UPDATE THE CLOCK WHILE SETTING IT
	SEI
	LDX	#SD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	DAY
	BSR	BCDTOASC
	STAA	DATE$:DAY
	STAB	DATE$:DAY+1
	LDAA	YEAR
	BSR	BCDTOASC
	STAA	DATE$:YEAR
	STAB	DATE$:YEAR+1
	LDX	#DATE$
	LDAA	#8
	RTS
*
BCDTOASC	TAB
	ANDB	#$F
	ADDB	#'0
	LSRA
	LSRA
	LSRA
	LSRA
	ADDA	#'0
	RTS
*
*
CLOCKTIME	JSR	DIVIDEBY60	NOW DIVIDEND HAS SECONDS
	LDX	#TIME$:SECONDS
	BSR	CLOCKMAKEXX
	LDX	#TIME$:MINUTES
	BSR	CLOCKMAKEXX
	LDX	#TIME$:HOURS
	BSR	CLOCKMAKEXX
	LDX	#TIME$
	LDAA	#8
	RTS
*
CLOCKMAKEXX	JSR	DIVIDEBY60
	ADDA	#'0
	ADDB	#'0
	STAB	0,X
	STAA	1,X
	RTS
*
*	DIVIDE BY 60 -- DIVIDE 3 BYTE "DIV60DIVIDEND" BY 60
*		DIVIDEND:=DIVIDEND/60
*		(A):=REMAINDER MOD 10
*		(B):=INT(REMAINDER/10)
DIVIDEBY60	EQU	*
	LDAB	#3*8+1	NUMBER OF BITS
	CLRA
DIVIDE60L	EQU	*
	ROLA
	CMPA	#60
	BCS	DIVIDE60L2
	SUBA	#60
	SEC
	$85		SKIP THE NEXT INSTRUCTION
DIVIDE60L2	CLC
	ROL	DIV60DIVIDEND+2
	ROL	DIV60DIVIDEND+1
	ROL	DIV60DIVIDEND+0
	DECB
	BNE	DIVIDE60L
	LDAB	#-1
DIVIDE60L3	INCB
	SUBA	#10
	BCC	DIVIDE60L3
	ADDA	#10
	RTS
	FIN	IODRIVERBODY
	IF	IODRIVERRAM
CLOCKDCB	FCB	1	CLOCK'S ALWAYS DONE
	FDB	0	LASTER
	FDB	CLOCKSTR
	FDB	NEXTDEVICEDCB
	FDB	CLOCKDRIVER
DIV60DIVIDEND	EQU	*
CLOCKBUFFER	FCB	0,0,0
DAY	FCB	0
MONTH	FCB	0
YEAR	FCB	0
CLOCKFRACTION	FCB	-1
CLOCKSTR	FCC	'CLOCK:'
	FCB	0
*
NEXTDEVICEDCB	SET	CLOCKDCB
*
TIME$	EQU	*
TIME$:HOURS	FCC	'00:'
TIME$:MINUTES	FCC	'00:'
TIME$:SECONDS	FCC	'00 '
DATE$	EQU	*
DATE$:MONTH	FCC	'00/'
DATE$:DAY	FCC	'00/'
DATE$:YEAR	FCC	'00'
*
	FIN	IODRIVERRAM
