.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
vic_spr0col	= $d027
vic_spr1col	= $d028
vic_spr2col	= $d029
vic_spr3col	= $d02a
vic_spr4col	= $d02b
vic_spr5col	= $d02c
vic_spr6col	= $d02d
vic_spr7col	= $d02e
vic_spr0y	= $d001
vic_spr1y	= $d003
vic_spr2y	= $d005
vic_spr3y	= $d007
vic_spr4y	= $d009
vic_spr5y	= $d00b
vic_spr6y	= $d00d
vic_spr7y	= $d00f

cia_intctrl	= $dc0d

scrline		= $0400+12*40
colline		= $d800+12*40

.code

_asmentry:

	jsr	cls

	ldx	#$00
	stx	vic_border
	stx	vic_bg0
showmsg:
	lda	msg,x
	sta	scrline,x
	inx
	cpx	#$28
	bne	showmsg
	dex
	stx	msgp

	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	colwash
	jsr	scroll
	jsr	spranim

	jmp	$ea31		; Normal OS iterrupt?

colwash:
	lda	colour+$00
	sta	colour+$28
	;sta	vic_border
	ldx	#$00
@loop:
	lda	colour+$01,x
	sta	colour+$00,x
	lda	colour,x
	sta	colline,x
	inx
	cpx	#$28
	bne	@loop
	rts

scroll:
	ldx	scrx
	dex
	bpl	@nomove

	ldx	#$00
@loop:
	lda	scrline+1,x
	sta	scrline,x
	inx
	cpx	#39
	bne	@loop
	inc	msgp
	ldx	msgp
	lda	msg,x
	sta	scrline+39
	ldx	#7

@nomove:
	stx	scrx
	stx	vic_ctrl2

	rts

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


spranim:
	;ldx	#7
@loop:
	;lda	colour,x
	;inc	vic_spr0col,x
	;dex
	;bpl	@loop

	inc	vic_spr0y
	inc	vic_spr0y
	inc	vic_spr1y
	inc	vic_spr1y
	inc	vic_spr2y
	inc	vic_spr2y
	inc	vic_spr2y
	inc	vic_spr3y
	inc	vic_spr3y
	inc	vic_spr3y

	inc	vic_spr4y
	inc	vic_spr5y
	inc	vic_spr6y
	inc	vic_spr7y

	rts


;data
scrx:
	.byte	0

msgp:
	.byte	0

;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 

colour_mess:
	.byte	$01,$01,$01,$0f,$0f 
	.byte	$0c,$0c,$0b,$0b,$0c 
	.byte	$0c,$0f,$0f,$01,$01 
	.byte	$01,$0f,$0f,$0c,$0c 
	.byte	$0b,$0b,$0c,$0c,$0f 
	.byte	$0f,$01,$01,$01,$0f 
	.byte	$0f,$0c,$0c,$0b,$0b 
	.byte	$0c,$0c,$01,$01,$01 
	.byte	$0f,$0c,$0b,$0c,$0f 

;data for text message 

	      ;0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
msg:
	.byte "          if there is only one wish in my life, it is that dorot"
	.byte "hy never said 'no' and that the stars did not fade and the moon "
	.byte "turn to ash.  as this wish will never ever be filled the rain co"
	.byte "ntinues to fall and wash away any evidence of my existance here."

