#include "ion.inc" #define termites apdram ; each termite has x,y,state #define numterm 50 ; number of termites #define chips 500 #define changec 5 #ifdef TI83P .org progstart-2 .db $BB,$6D #else .org progstart #endif ret jr nc,init .db "Termites",0 init: ld bc,chips initchiploop push bc ld b,64 call ionrandom ld e,a ld b,96 call ionrandom call iongetpixel or (hl) ld (hl),a pop bc dec bc ld a,b or c jr nz,initchiploop ; bcall _getcsc ; cp $38 ; jr nz,realstart ; bcall _zeroop1 ; ld hl,$60*256+7 ; ld (op1),hl ; bcall _chkfindsym ; jr c,realstart ; inc de ; inc de ; ld hl,plotsscreen ; ex de,hl ; ld bc,756 ; ldir ;realstart: ld b,numterm ld hl,termites otherstart: inittermloop: push bc ld b,64 call ionrandom ld (hl),a inc hl ld b,96 call ionrandom ld (hl),a inc hl ld (hl),b inc hl ld (hl),b inc hl pop bc djnz inittermloop call ionfastcopy di termloop: ld a,$Fd out (1),a in a,(1) cp 191 ret z cp 254 call z,ionfastcopy ld b,numterm ld hl,termites termmoveloop: push bc ld e,(hl) inc hl ld d,(hl) inc hl push hl call getnewcoords ld a,d push de call iongetpixel pop de and (hl) pop hl jr z,nochip ld a,(hl) or a jr z,pickupchip putdownchip: ld (hl),0 dec hl ld d,(hl) dec hl ld e,(hl) inc hl inc hl call pixelon inc hl call forcedir dec hl jr nextterm nochip: dec hl ld (hl),d dec hl ld (hl),e inc hl inc hl jr nextterm pickupchip: ld (hl),1 dec hl ld (hl),d dec hl ld (hl),e inc hl inc hl call pixeloff nextterm: inc hl inc hl pop bc djnz termmoveloop jr termloop pixelon: push de push hl ld a,d call iongetpixel or (hl) ld (hl),a pop hl pop de ret pixeloff: push de push hl ld a,d call iongetpixel cpl and (hl) ld (hl),a pop hl pop de ret getnewcoords: inc hl call changedir ld a,(hl) or a jr z,moveleft dec a jr z,moveright dec a jr z,moveup inc e ld a,e cp 64 ret nz ld e,0 ret moveleft: dec d ld a,d cp 255 ret nz ld d,95 ret moveup: dec e ld a,e cp 255 ret nz ld e,63 ret moveright: inc d ld a,d cp 96 ret nz ld d,0 ret changedir: ld b,changec call ionrandom or a ret nz forcedir: ld b,4 call ionrandom ld (hl),a ret .end