	;
	; Clock.asm
	;
	; Intel 8008 source code file.  Reads RTC and displays time
	; on port 0,1,2
	;
	; Copyright 2006 by Len Bayles
	;



	; page 0

	cpu 	8008

	org  00h			; rst 0
	jmp init

	org  08h			; rst 1
	hlt

	org  10h			; rst 2
	hlt

	org  18h			; rst 3
	hlt

	org  20h			; rst 4
	hlt

	org  28h			; rst 5
	hlt

	org  30h			; rst 6
	hlt

	org  38h			; rst 7
	hlt

init:
	lhi	03fh			; Control Reg 
	lli	0f0h
	lmi	00fh			; Stop clock, point to Int Reg

	lhi	03fh			; Int Reg
	lli	0ffh
	lmi	000h			; Dissable Ints

	lhi	03fh			; Control Reg 
	lli	0f0h
	lmi	005h			; Point to Setting Reg

	lhi	03fh			; Setting Reg
	lli	0ffh
	lmi	001h			; Set for 24 hr

	lhi	03fh			; Control Reg 
	lli	0f0h
	lmi	001h			; Start Clock

	lam				; Read DCF - Data Change Flag

clock:
	lhi	03fh			; Control Reg 
	lli	0f0h
	lam				; Read DCF - Data Change Flag

	ndi	080h			; Maks DCF bit

	jz clock

cdisplay:
	lhi	03fh			; Seconds Reg 
	lli	0f2h
	lcm				; Put Seconds in c

	lhi	03fh			; Tens Seconds Reg 
	lli	0f3h
	ldm				; Put Ten Seconds in d

	cal merge

	out 10h				; Output Seconds


	lhi	03fh			; Minutes Reg 
	lli	0f4h
	lcm				; Put Minutes in c

	lhi	03fh			; Tens Minutes Reg 
	lli	0f5h
	ldm				; Put Tens Minutes in d

	cal merge

	out 12h				; Output Minutes


	lhi	03fh			; Hours Reg 
	lli	0f6h
	lcm				; Put Hours in c

	lhi	03fh			; Tens Hours Reg 
	lli	0f7h
	ldm				; Put Ten Hours in d

	cal merge

	out 14h				; Output Hours

	jmp clock

merge:
	lai	0fh			; Load Mask into a
	ndc				; And with c reg
	lca				; Store back in c

	lai	0fh			; Load Mask into a
	ndd				; And with d reg
	rlc				; Rotate into high nible
	rlc
	rlc
	rlc

	orc				; OR back in lower bits

	ret


