	.global main
main:
	mov	r0, #string	@ writestr(string)
	mov	r3, #writestr
	call	sp, r3
	
	mov	r1, #0x0	@ row
	mov	r2, #0x0	@ col
	mov	r3, #0x0	@ color
2:	mov	r0, #0x4100	@ row:	address			Row loop BEGIN
	sto	[r0], r1	@	store row
1:	mov	r0, #0x4101	@ col:	column address		Column loop BEGIN
	sto	[r0], r2	@	store column
	mov	r0, #0x4102	@ data:	data address
	sto	[r0], r3	@	store data
	
	mov	r0, #1		@ increment the column
	add	r2, r0		@	col = col + 1
	mov	r0, #320	@ next row if overrun
	tst	r2, r0		@	within range?
	movne	pc, #1b		@	go back to top of loop	Column loop END
	mov	r2, #0		@ reset column
	
	mov	r0, #1		@ increment the row
	add	r1, r0		@	row = row + 1
	mov	r0, #240	@ next color if overrun
	tst	r1, r0		@ 	within range?
	movne	pc, #2b		@	go back to top of loop	Row loop END
	mov	r1, #0		@ reset row
	
	mov	r0, #1		@ increment color
	add	r3, r0		@ 	color = color + 1
	mov	r0, #8		@ reset colors if overrun
	tst	r3, r0		@ 	(test color, #8)
	moveq	r3, #0		@ 	if so, reset them
	mov	r0, #0x4103	@ refresh
	sto	[r0], r0	@	do it
	mov	pc, #2b		@ go back to top of row loop	Color loop END
	
	mov	r0, #string2	@ writestr(string)
	mov	r3, #writestr
	call	sp, r3
	
	mov	r0, #0x0000
	sto	[r0], r0	@ kill us off

	.extern writestr
@ Note that they have to be spaced out, since these are 16bit loads
string: .string "H e l l o ,   w o r l d ! \n\000\000"
string2: .string "G o o d b y e ,   w o r l d ! \n\000\000"
