.export _asmentry

vic_irqreg	= $d019
vic_irqmask	= $d01a
vic_border	= $d020
vic_bg0		= $d021
vic_ctrl1	= $d011
vic_raster	= $d012
vic_ctrl2	= $d016
vic_addr	= $d018

cia_intctrl	= $dc0d

.code

_asmentry:

	jsr	cls

	ldx	#$00
	stx	vic_border
	stx	vic_bg0
showmsg:
	lda	msg1,x
	sta	$0400,x
	lda	msg2,x
	sta	$0400+24*40,x
	inx
	cpx	#$28
	bne	showmsg

	sei			; Disable interrupts
	lda	#<irq
	ldx	#>irq
	sta	$0314
	stx	$0315		; Set IRQ address
	lda	#$00
	sta	vic_raster	; Set raster line IRQ
	lda	#$7f
	sta	cia_intctrl
	lda	#$01
	sta	vic_irqmask	; Enable raster line IRQ
	cli			; Re-enable interrupts

hold:
	jmp	hold

irq:
	lda	#$01
	sta	vic_irqreg	; Acknowledge the interrupt

	jsr	colwash1
	jsr	colwash2
	jsr	scroll

	jmp	$ea31		; Normal OS iterrupt?

colwash1:
	lda	colour+$00
	sta	colour+$28
	ldx	#$00
@loop:
	lda	colour+$01,x
	sta	colour+$00,x
	lda	colour,x
	sta	$d800,x
	inx
	cpx	#$28
	bne	@loop
	rts

colwash2:
	ldx	#$28
	ldy	#$00
@loop:
	lda	colour-$01,x
	sta	$d800+24*40,y
	iny
	dex
	bne	@loop
	rts

scroll:
	lda	$0400+24*40
	sta     $0400+39+24*40
	ldx	#$00
@loop:
	lda	$0401+24*40,x
	sta	$0400+24*40,x
	inx
	cpx	#39
	bne	@loop
	rts

cls:
	ldy	#$00
	lda	#$20
@loop:
	sta	$0400,y
	sta	$0500,y
	sta	$0600,y
	sta	$06e8,y
	iny
	bne	@loop
	rts


;data tables for colours 

colour:
	.byte	$09,$09,$02,$02,$08 
	.byte	$08,$0a,$0a,$0f,$0f 
	.byte	$07,$07,$01,$01,$01 
	.byte	$01,$01,$01,$01,$01 
	.byte	$01,$01,$01,$01,$01 
	.byte	$01,$01,$01,$07,$07 
	.byte	$0f,$0f,$0a,$0a,$08 
	.byte	$08,$02,$02,$09,$09 
	.byte	$00,$00,$00,$00,$00 

;data for text message 

		;1234567890123456789012345678901234567890
msg1:
	.byte	"rfdedfrfdedfrrfdedfrrfdedfrrfdedfrfdedfr"
msg2:
	.byte	"qw      qw      qw      qw      qw      "

