;Langant for Mirage, by Dan Englender
;Yes! I know it's not optimized...
;Feel free to use any of this code, but please give me credit.
#include        "ti83plus.inc"
#include		"mirage.inc"
#define data savesscreen
apdram	=	$9872

  .org    $9d93
   .db     $BB,$6D



   ret
   .db	1
	.db	%00000000,%00000000
	.db	%00000010,%00000000
	.db	%00000111,%00000000
	.db	%00011100,%10000000
	.db	%00010001,%11000000
	.db	%00100111,%00100000
	.db	%01100100,%01110000
	.db	%00101001,%11001000
	.db	%00011001,%00011100
	.db	%00001010,%01110000
	.db	%00000110,%01000000
	.db	%00000010,%10000000
	.db	%00000001,%10000000
	.db	%00000000,%10000000
	.db	%00000000,%00000000
desc:
        .db     "Lantons Ant",0

init:
	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    igetpix
	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



getrands:
	ld	b,96
        call    irandom
	ld	d,a
	ld	b,64
        call    irandom                 
	ld	e,a
	ret

.end
