#include        "ion.inc"
#define data savesscreen

#ifdef TI83P
  .org    progstart-2
   .db     $BB,$6D
#else
   .org    progstart
#endif


   ret
   jr      nc,init
desc:
        .db     "Lantons Ant",0

init:
	di
	ld	de,3
        ld      (8265h-$8265+apdram),de
        ld      (8269h-$8265+apdram),de
	call	getrands

        ld      (8267h-$8265+apdram),de
	call	getrands
        ld      (826Bh-$8265+apdram),de
;	ld	b,0



mainloop:
	ld	a,0feh
	out	(1),a
	in	a,(1)
	cp	255
	ret	nz
        ld      de,(8265h-$8265+apdram)
	push	de
	pop	bc
        ld      de,(8267h-$8265+apdram)
	call	dotheant
        ld      (8267h-$8265+apdram),de
	push	bc
	pop	de
        ld      (8265h-$8265+apdram),de
        ld      de,(8269h-$8265+apdram)
	push	de
	pop	bc
        ld      de,(826Bh-$8265+apdram)
	call	dotheant
        ld      (826Bh-$8265+apdram),de
	push	bc
	pop	de
        ld      (8269h-$8265+apdram),de
	jr	mainloop



dotheant:
	ld	a,c
	or	a
	jp	nz,check2
	dec	d
check2:
	dec	a
	jp	nz,check3
	dec	e
check3:
	dec	a
	jp	nz,check4
	inc	d
check4:
	dec	a
	jp	nz,check5
	inc	e
check5:
	ld	a,d
	cp	255
	jp	nz,check55
	ld	d,95
	ld	a,d
check55:
	cp	96
	jp	c,check6
	ld	d,0
check6:
	ld	a,e
	cp	255
	jp	nz,check65
	ld	e,63
	ld	a,e
check65:
	cp	64
	jp	c,realcont
	ld	e,0
realcont
	

	push	de
	push	bc
	ld	a,d
        call    vectorc
	push	af
	push	hl
	xor	(hl)
	ld	(hl),a
        ld      a,(826Dh-$8265+apdram)
	inc	a
        ld      (826dh-$8265+apdram),a
	cp	35
	jr	nz,overhere
        bcall	_grbufcpy
	xor	a
        ld      (826dh-$8265+apdram),a
overhere:
	pop	hl
	pop	af
	pop	bc
	pop	de
	and	(hl)
	or	a
	jp	z,secondadd
	dec	c
	ld	a,c
	cp	255
	ret	nz
	ld	c,3
	ret
secondadd:
	inc	c
	ld	a,c
	cp	4
	ret	nz
	ld	c,0
	ret

vectorc = iongetpixel
vector1 = ionrandom

getrands:
	ld	b,96
        call    vector1
	ld	d,a
	ld	b,64
        call    vector1                 
	ld	e,a
	ret

.end
