; Simon 1.0 for ION ; By: Dan Englender #include "ion.inc" #define nummoves saferam3 #define movelist saferam3+1 #ifdef TI83P .org progstart-2 .db $BB,$6D #else .org progstart #endif ret jr nc,init desc: .db "Simon 1.0",0 init: res plotloc,(iy+plotflags) set textwrite,(iy+sgrflags) ld hl,blanktxt ld de,blanktxt+1 ld bc,40 ld (hl),' ' ldir ld (hl),0 ld hl,15*256+65 ld (pencol),hl ld hl,curtxt bcall _vputs ld hl,23*256+65 ld (pencol),hl ld hl,hightxt bcall _vputs ld a,(highscore) bcall _setxxop1 ld a,3 bcall _dispop1a ld hl,welcome1txt call disptextline1 ld hl,welcome2txt call disptextline2 ld ix,simonlogo ld bc,11*256+4 ld a,65 push af ld l,3 call ionlargesprite ld ix,tcpalogo ld bc,18*256+4 pop af ld l,63-19 call ionlargesprite call dispboard ld a,1 ld (nummoves),a ld b,4 call ionrandom ld (movelist),a mainloop: call dispmoves call getmoves jr nz,youlost ld a,(nummoves) cp 126 jr z,youwin ld l,a ld h,0 ld a,10 bcall _divhlbya or a call z,dispwowtext call addmove jr mainloop quitter2: pop hl youlost: ld hl,blanktxt call disptextline1 ld hl,sorry1txt call disptextline1 ld hl,sorry2txt call disptextline2 call ionfastcopy lostloop: xor a out (1),a in a,(1) inc a jr z,lostloop ld a,(highscore) ld b,a ld a,(nummoves) dec a cp b ret c ret z ld (highscore),a ld hl,newhightxt call disptextline1 ld hl,blanktxt call disptextline2 call ionfastcopy hsloop: xor a out (1),a in a,(1) inc a jr nz,hsloop jr lostloop youwin: ld hl,youwin1txt call disptextline1 ld hl,youwin2txt call disptextline2 jr lostloop-3 addmove: ld a,(nummoves) ld c,a ld b,0 ld hl,movelist add hl,bc inc a ld (nummoves),a ld b,4 call ionrandom ld (hl),a ret dispmoves: ld hl,15*256+81 ld (pencol),hl ld a,(nummoves) dec a push af bcall _setxxop1 ld a,3 bcall _dispop1a pop af ld b,a inc b ld hl,movelist dispmovesloop: push hl push bc ld a,(hl) call disppiece pop bc pop hl inc hl djnz dispmovesloop ret disppiece: push af call fillon call ionfastcopy pop af call filloff call dispboard call ionfastcopy ret getmoves: ld hl,movelist ld a,(nummoves) ld b,a getmovesloop: ld a,$fd out (1),a in a,(1) cp 191 jp z,quitter2 ld a,$fe out (1),a in a,(1) ld c,0 rra jr nc,moved inc c rra jr nc,moved inc c rra jr nc,moved inc c rra jr nc,moved jr getmovesloop moved: push bc push hl ld a,c call disppiece pop hl pop bc ld a,c cp (hl) ret nz inc hl call waitnokey djnz getmovesloop waitnokey: ld a,$fe out (1),a in a,(1) cp 255 jr nz,waitnokey ret dispwowtext: ld hl,blanktxt call disptextline1 ld de,31*256+65 ld (pencol),de ld a,(nummoves) bcall _setxxop1 ld a,3 bcall _dispop1a ld hl,movestxt bcall _vputs ld hl,blanktxt call disptextline2 ld b,numwow call ionrandom ld b,a add a,a add a,a add a,b add a,b ld l,a ld h,0 ld de,wowtxt add hl,de call disptextline2 jp ionfastcopy filloff: push af call invertscreen pop af call fillcall call floodfill call invertscreen ret invertscreen: ld hl,plotsscreen ld bc,768 invertloop: ld a,(hl) cpl ld (hl),a inc hl dec bc ld a,b or c jr nz,invertloop ret fillon: ; a = space to fill call fillcall jp floodfill fillcall: ld de,savesscreen ld hl,plotsscreen ld bc,768 ldir sla a ld l,a ld h,0 ld de,disppixels add hl,de ld a,(hl) inc hl ld e,(hl) jp moredisppixel disppixels: .db 32,50 .db 5,32 .db 55,32 .db 32,5 dispboard: ld bc,0 ld de,63*256+63 ld h,1 bcall _iline ld b,d ld d,c bcall _iline ld d,b bcall _iline ld b,c ld d,c bcall _iline ld de,63 ld bc,95*256+63 bcall _iline ld de,12 ld hl,plotsscreen+11 ld b,63 db2l: ld a,1 or (hl) ld (hl),a add hl,de djnz db2l ld b,12 ld hl,plotsscreen+768-12 dbl1: ld (hl),$FF inc hl djnz dbl1 ld hl,0*256+63 call disppixel ld hl,63*256+63 call disppixel jp ionfastcopy disppixel: ld a,h ld e,l moredisppixel: call iongetpixel or (hl) ld (hl),a ret disptextline1: ld de,31*256+65 ld (pencol),de bcall _vputs ret disptextline2: ld de,37*256+65 ld (pencol),de bcall _vputs ret floodfill: ld de,128*256+0 ld bc,257 ld hl,savesscreen ld ix,plotsscreen jr increment floodfill2: ld de,1*256+0 ld bc,96*256+64 ld hl,savesscreen+767 ld ix,plotsscreen+767 call increment3 ld a,e ;check if there were squares filled in last time or a ret z jr floodfill increment: call loop ld a,d dec a jr nz,increment2 inc ix inc hl increment2: rrc d inc b ld a,b cp 97 jr nz,increment ld b,1 inc c ld a,c cp 65 jr nz,increment jr floodfill2 increment3: call loop ld a,d add a,128 jr nz,increment4 dec ix dec hl increment4: rlc d dec b jr nz,increment3 ld b,96 dec c jr nz,increment3 ret loop: ld a,d and (ix) cp d ret nz ld a,d and (hl) cp d ret z founddiff: ;we found a pixel that is a filler pixel now we fill the surrounding 4 pixels with filler pixels ld e,1 ;signals there is still squares being filled ld a,d or (hl) ;this speeds up the calc by 2 seconds by avoiding doing stuff over and over again ld (hl),a ;I timed it:) ld a,c dec a jr z,endup ld a,d or (ix-12) ld (ix-12),a endup: ld a,c cp 64 jr z,enddown ld a,d or (ix+12) ld (ix+12),a enddown: ld a,d rrca cp 128 jr z,cright or (ix) ld (ix),a endright: ld a,d rlc a cp 1 jr z,cleft or (ix) ld (ix),a ret cright: ld a,b cp 96 jr z,endright ld a,128 or (ix+1) ld (ix+1),a jr endright cleft: ld a,b dec a ret z ld a,1 or (ix-1) ld (ix-1),a ret sorry1txt: .db "Sorry,",0 sorry2txt: .db "You Lost ",0 newhightxt: .db "New High",0 highscore: .db 3 movestxt: .db " Moves!!!",0 wowtxt: .db "WOW!!",0 .db "Cool!",0 .db "Sweet",0 .db "!@#$%",0 .db "Nice ",0 .db "Yowza",0 .db "Yahoo",0 .db "Slick",0 #define numwow 8 youwin1txt: .db "You Won!!",0 youwin2txt: .db "Amazing",0 welcome1txt: .db "Welcome",0 welcome2txt: .db "To Simon",0 curtxt: .db "Cur: ",0 hightxt: .db "High: ",0 tcpalogo: .db $81,$01,$01,$04 .db $40,$81,$02,$08 .db $20,$41,$04,$10 .db $00,$00,$00,$00 .db $0F,$8E,$F0,$80 .db $16,$9B,$59,$C0 .db $06,$30,$59,$60 .db $06,$38,$73,$E0 .db $06,$1F,$43,$60 .db $0F,$0E,$E6,$70 .db $00,$00,$00,$00 .db $3F,$FF,$FF,$F8 .db $1F,$FF,$FF,$F0 .db $01,$D1,$17,$00 .db $00,$49,$24,$00 .db $00,$29,$28,$00 .db $00,$29,$28,$00 .db $00,$29,$28,$00 simonlogo: .db 0,64,6,0,120,131,137,104,65,135,201,104 .db 194,133,73,104,132,133,73,104,192,133 .db 73,104,120,172,105,88,12,200,41,88 .db 4,136,41,88,13,8,41,88,250,8,38,88 #ifdef TI83 #define blanktxt saferam2 #else #define blanktxt saferamp2 #endif .end