.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

msgp		= 251

delcnt		= 3

dotlen		= 240
dotcol1		= $d800
dotcol2		= dotcol1+dotlen
dotcol3		= dotcol2+dotlen

.code

_asmentry:

	;jsr	cls

	ldx	#<msg
	ldy	#>msg
	stx	msgp
	sty	msgp+1

	ldx	#$00
	stx	vic_border
	stx	vic_bg0

	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

	lda	#$00
hold:
	ldx	#$00

@loop:
	inc	dotcol1,x
	inc	dotcol2,x
	inc	dotcol3,x
	inx
	cpx	#dotlen
	bne	@loop

	jmp	hold


orig_hold:
	ldx	#$00

@loop:
@l1:
	inc	dotcol1,x
	beq	@l1
@l2:
	inc	dotcol2,x
	beq	@l2
@l3:
	inc	dotcol3,x
	beq	@l2
	inx
	cpx	#dotlen
	bne	@loop

	jmp	hold

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

	dec	delay
	beq	@scroll
	jmp	@irqend

@scroll:
	lda	#delcnt
	sta	delay

	ldx	scry
	dex
	bpl	@nomove

	ldx	#$00
@loop1:
	lda	$0400+40*19,x
	sta	$0400+40*18,x

	lda	$0400+40*20,x
	sta	$0400+40*19,x

	lda	$0400+40*21,x
	sta	$0400+40*20,x

	lda	$0400+40*22,x
	sta	$0400+40*21,x

	lda	$0400+40*23,x
	sta	$0400+40*22,x

	lda	$0400+40*24,x
	sta	$0400+40*23,x

	inx
	cpx	#40
	bne	@loop1

	ldy	#$00
@loop2:
	lda	(msgp),y
	sta	$0400+24*40,y
	iny
	cpy	#40
	bne	@loop2

	lda	(msgp),y
	cmp	#$ff
	bne	@noreset
	ldx	#<msg
	ldy	#>msg
	stx	msgp
	sty	msgp+1
	jmp	@noadd

@noreset:
	clc
	lda	#40
	adc	msgp
	sta	msgp
	bcc	@noadd
	inc	msgp+1

@noadd:
	ldx	#7

@nomove:
	stx	scry
	txa
	ora	#$10
	sta	vic_ctrl1

@irqend:
	jmp	$ea31		; Normal OS iterrupt?

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


;data
scry:
	.byte	0

delay:
	.byte	delcnt

;data for text message 

		;0123456789012345678901234567890123456789
msg:
	.byte	"            CALL OF CTHULU              "
	.byte	"                                        "
	.byte	" no one knew where they came from, or   "
	.byte	" which twisted dimension could have     "
	.byte	" born such foul creatures.              "
	.byte	"                                        "
	.byte	" only the writings of the mad arab      "
	.byte	" locked away in the NECROMICON gave     "
	.byte	" names to the insults you will have to  "
	.byte	" destroy; else the world itself is      "
	.byte	" eaten up as they awake from their      "
	.byte	" aeon old slumbers to reclaim the       "
	.byte	" universe.                              "
	.byte	"                                        "
	.byte	" blinded since birth you are only hope  "
	.byte	" against the horrors that have been     "
	.byte	" visited upon the earth....             "
	.byte	"                                        "
	.byte	" the fate of billions rests on your     "
	.byte	" shoulders.                             "
	.byte	"                                        "
	.byte	"                                        "
	.byte	"                                        "
	.byte	"                                        "
	.byte	"                                        "
	.byte	$ff

