;6502SDK sample file
;
; This program (for Commodore 64) puts a real time clock
; on the screen. It can be called from BASIC, doesn't care about
; interrupts and I/O and makes use of the Time Of Day clock.
;
; It was published in Commodore Computer Club #61 - 1989
;

; T.O.D. clock v1.0 by Valerio Gionco
;
; origin in $C000 - 49152
;

	org $c000
	
	nop
lc000:	jsr $aefd
	jsr $b79e
	cpx #$01
	bpl $c00e
	jmp $c17e
lc00e:	lda $dd0f
	and #$7f
	sta $dd0f
	jsr $aefd
	jsr $ad9e
	jsr $b6a3
	cmp #$07
	beq $c026
	jmp $af08
Lc026:	ldy #$00
	lda ($22),y
	cmp #$30
	beq $c035
	cmp #$31
	beq $c044
	jmp $af08
lc035:	iny
	lda ($22),y
	jsr $c09c
	sec
	sbc #$30
	sta $dd0b
	jmp $c058
lc044:	iny
	lda ($22),y
	cmp #$30
	bmi $c0a5
	cmp #$33
	bpl $c0a5
	sec
	sbc #$30
	clc
	adc #$0a
	sta $dd0b
lc058:	jsr $c07d
	sta $dd0a
	jsr $c07d
	sta $dd09
	iny
	lda ($22),y
	cmp #$41
	beq $c0ad
	cmp #$50
	bne $c07a
	lda $dd0b
	ora #$80
	sta $dd0b
	jmp $c0ad

lc07a:	jmp $af08
lc07d:	iny
	lda ($22),y
	jsr $c09c
	sec
	sbc #$30
	cmp #$06
	bpl $c0a5
	asl a
	asl a
	asl a
	asl a
	sta $fb
	iny
	lda ($22),y
	jsr $c09c
	sec
	sbc #$30
	ora $fb
	rts
lc09c:	cmp #$30
	bmi $c0a5
	cmp #$3a
	bpl $c0a5
	rts
lc0ac:  jsr $c177
	ldx #$0e
	jmp ($0300)
lc0ad:	jsr $c177
	sei
	lda #$bd
	sta $0314
	lda #$c0
	sta $0315
	cli
	rts
	dec $02
	bne $c0e6
	lda #$0f
	sta $02
	jsr $c0e9
	jsr $c164
	lda #$20
	sta $0408
	sta $0409
	
	lda #$0d
	sta $040b
	lda #$3a
	sta $0402
	jsr $c125
	jsr $c132
	jsr $c13f
lc0e6:	jmp $ea31

lc0e9:	lda $dd0b
	and #$0f
	cmp #$3a
	bpl $c0fd
	adc #$30
	sta $0401
	lda #$30
	sta $0400
	rts
	cmp #$0d
	bmi $c116
	sec
	sbc #$0c
	sta $fb
	lda $dd0b
	and #$80
	eor $fb
	eor #$80
	sta $dd0b
	jsr $c177
	rts
lc116:	sec
	sbc #$0a
	clc
	adc #$30
	sta $0401
	lda #$31
	sta $0400
	rts
lc164:	lda $dd0a
	jsr $c152
	sta $0403
	sty $0404
	rts
lc125:	lda $dd09
	jsr $c152
	sta $0406
	sty $0407
	rts
lc132:	lda $dd08


	cmp #$04
	bmi $c14c
	lda #$20
	sta $0405
	rts
lc14c:	lda #$3a
	sta $040c
	rts
lc152:	tax
	and #$0f
	clc
	adc #$30
	tay
	txa
	and #$f0
	clc
	ror a
	ror a
	ror a
	ror a
	adc #$30
	rts
lc13f:	lda $dd0b
	and #$80
	beq $c171
	lda #$10
	sta $040a
 	rts
lc171:	lda #$01
	sta $040a
	rts
lc177:	lda $dd08
	sta $dd08
	rts
lc17e:	sei
	lda #$31
	sta $0314
	lda #$ea
	sta $0315
	cli
	lda #$20
	ldx #$0c
lc18e:	sta $03ff,x
	dex
	bne $c18e
	rts
