memwipehi:					; this routine clears all ram from $a0 to $0180
	load_a #00				; and $0120 to $01ff
	load_x #e0
loophi:
	dec_x					
	store_a $a0,x			; write 00 to ram at $[a0 + x]
	store_a $0120,x			; write 00 to ram at $[0120 + x]
	comp_x #00				 
	bne loophi				; loop while x != 00
	nop
	nop
memwipelo:					; this routine clears ram from $0000 to $0080
	load_a #00			
	load_x #80
looplo:
	dec_x					; while x != 0, decrement x, write 0 to ram at x
	store_a $00,x
	comp_x #00
	bne looplo
	nop
	nop
	nop
	nop
	nop
vars:
	define textarea $0000	; start of character display area
	define stri $015a		; string array loop counter
	define numchars $0159	; number of chars currently displayed
	define charxarr $0150	; start of array of char x position values
	define charcarr $0160	; start of array of char character code values
	define chari $0158		; add char procedure char index 
	define inchari $0157	; draw/update loop char index
	define strlen 0b		; length of string to be scrolled
	define maxchars 03		; max chars to display at once
	define xtrigger 06		; x left boundary at which new char is added
	define initxpos 0e		; initial x offset for new char
message:					
	.text "hello woof "		; string to be scrolled
init:
	load_a #ff			; chari will get incd to 0 at end of init via addchar
	store_a chari
	load_a #00			; zero out some vars
	store_a inchari
	store_a stri
	store_a numchars
	jsr addchar			; add the first char
draw:					; draw/update char loop
	load_y inchari		; get current char arr index
	load_a charcarr,y	; get current char code
	load_x charxarr,y	; get current char x position
	print textarea		; print the char at the x position
mvchar:
	dec_x				; decrement the char x pos
	load_y inchari		; get current char arr index
	store_x charxarr,y	; update the char x position array
	comp_x #xtrigger	; check left boundary (x trigger) for char
	beq newchar			; we hit left boundary, time to add a new char
nextchar:
	inc inchari			; increment char arr index
	load_a inchari
	comp numchars
	bmi draw			; draw chararr[i] if i < chararr length (numchars)
	load_a #00			; hit end of char arr, wrap i to 0
	store_a inchari
	jump draw			; draw chararr[0]
newchar:
	jsr addchar			
	jump nextchar		
addchar:				; add a new character to chararr from the string
	inc chari			; increment char index
	load_a chari
	comp #maxchars
	bmi skipchri		; if char index < max allowed chars, append new char to end of array
	load_a #00			; otherwise, wrap the char index to 0 and store the next char from the string there
	store_a chari
skipchri:
	load_a #initxpos	; set x pos for new char
	load_y chari
	store_a charxarr,y
	load_y stri			; get string index
	load_a message,y	; read new char code from message string
	load_y chari		; store new char code in char code arr
	store_a charcarr,y
	inc stri
	load_a stri			; wrap stri back to 0 on strlen
	comp #strlen
	bmi skipstri
	load_a #00
	store_a stri
skipstri:
	load_a numchars		; limit numchar to maxchars by skipping inc
	comp #maxchars
	beq skipnchr
	inc numchars
skipnchr:
	rts