; Meister Mind 1.3 PhatOS Edition August 1, 1997 ; By Martin Hock (oxymoron@bigsky.net) ; My first ZShell program! Yay! ; Also the first program converted to PhatOS. ; Realize that the code in this thing is pretty sucky, as it is my first game. ; If you want to use any of the code, please give appropriate credit. ; You don't really need to give credit if you're just looking at how to use ; the new PhatOS methods. #include "TI-85.h" PCode = TEXT_MEM ;0,1,2,3 - Actual Pass Code (Opponent's Code) UCode = TEXT_MEM+4 ;4,5,6,7 - User-Inputted Code TCode = TEXT_MEM+8 ;8,9,10,11 - Temporary Code for processing (Contains PCode until modified) Selected = TEXT_MEM+12 ;Selected tile (0-3) ProgState = TEXT_MEM+13 SameSameNum = TEXT_MEM+14 SameDiffNum = TEXT_MEM+15 GuessNum = TEXT_MEM+16 randvar = TEXT_MEM+17 ;SuperPseudo Random Number (16 bit) .org $8E57 ;Note the org. Very important. .db "Meister Mind 1.3", 0 ;Program start ProgStart: call Initialize MenuStart: ROM_CALL(CLEARLCD) set 3,(IY+05) ld hl,$0000 ld de,MMTitle call TextPut res 3,(IY+05) ld hl,$0001 ld de,MMme1 call TextPut ld hl,$0002 ld de,MMme2 call TextPut ld hl,$0003 ld de,MMme3 call TextPut ld hl,$0004 ld de,MMme4 call TextPut MenuPress: call GET_KEY inc b cp $35 jp z,Play1Start cp $34 jp z,Play2Start cp $33 jr z,About cp $32 jr z,ExitPlace cp $37 jr z,ExitPlace jr MenuPress ExitPlace: ret About: ROM_CALL(CLEARLCD) set 3,(IY+05) ld hl,$0000 ld de,MMTitle call TextPut) res 3,(IY+05) ld hl,$0001 ld de,MMab1 call TextPut ld hl,$0002 ld de,MMab2 call TextPut ld hl,$0003 ld de,MMab3 call TextPut ld hl,$0004 ld de,MMab4 call TextPut ld hl,$0005 ld de,MMab5 call TextPut call KeyLoop jp MenuStart Play1Start: FatRand: ld a,r ;Refresh ld h,a ld l,b ;Key Delay ld (randvar),hl ld b,4 ld hl,PCode FRLoop: push bc push hl call SuperRand pop hl pop bc ld (hl),a inc hl djnz FRLoop jr GameStart SuperRand: ld hl,randvar call rand srl a srl a and $03 ld d,a inc hl call rand ld e,a ld a,1 ld hl,0 SRLoop: inc a cp 6 jr nz,SRMore ld a,0 SRMore: dec de call CP_HL_DE jr nz,SRLoop ret Play2Start: ROM_CALL(CLEARLCD) set 3,(IY+05) ld hl,$0000 ld de,MMTitle call TextPut res 3,(IY+05) ld hl,$0005 ld de,MMPlayer2 call TextPut call GetCode ld hl,UCode ld de,PCode ld b,4 CopyUCode: ld a,(hl) ld (de),a inc hl inc de djnz CopyUCode GameStart: ld hl,ProgState ld a,(hl) cp 1 jp z,ProgStart call MainScreen ld hl,GuessNum ld a,1 ld (hl),a GameLoop: push af call DispNum call FlipNum call GetCode ld hl,ProgState ld a,(hl) cp 1 jr z,YouQuit call PutCode call Analyze ld hl,ProgState ld a,(hl) cp 2 jr z,YouWin call PutClue) call FlipNum) pop af ld hl,GuessNum inc a ld (hl),a cp 11 jr nz,GameLoop jr YouLose YouQuit: pop af YouLose: ROM_CALL(CLEARLCD) set 3,(IY+05) ld hl,$0000 ld de,MMTitle call TextPut res 3,(IY+05) ld hl,$0001 ld de,MMYouLose1 call TextPut ld hl,$0002 ld de,MMYouLose2 call TextPut ld hl,$0003 ld de,MMCodeWas call TextPut call AnswerPut call KeyLoop jp ProgStart YouWin: pop af ROM_CALL(CLEARLCD) set 3,(IY+05) ld hl,$0000 ld de,MMTitle call TextPut res 3,(IY+05) ld hl,$0001 ld de,MMYouWin1 call TextPut ld hl,$0002 ld de,MMYouWin2 call TextPut ld hl,$0005 ld de,MMNumTries call TextPut call GetTries ld hl,$0003 ld de,MMCodeWas call TextPut call AnswerPut call KeyLoop jp ProgStart ;Subs rand: ;By Chris Busch ld a,(hl) ;;must be defined in text area ld b,a ld a,0 add a,b sla b sla b add a,b sla b sla b add a,b inc a ld (hl),a srl a ret Initialize: ld b,19 ld hl,TEXT_MEM InitLoop: ld (hl),0 inc hl djnz InitLoop TextPut: ;input: hl = screen location, de = location of string to place ld ($800C),hl ex de,hl ROM_CALL(D_ZT_STR) ret KeyLoop: ;output: a=key pressed call GET_KEY or a jr z, KeyLoop ret FlashKeyLoop: ld bc,0 FKLLoop: inc c ld a,c cp 255 call z,FlashIt call GET_KEY or a jr z,FKLLoop ret FlashIt: inc b ld a,b cp 50 call z,ReallyFlash ret ReallyFlash: ld b,0 push bc call z,FlipSel pop bc ret FatFlip: ;input: hl = address of top-left of screen chunk ld b,16 ;changed from 15 FFlipLoop: ld a,(hl) cpl ;NOT the a register ld (hl),a inc hl ld a,(hl) cpl ld (hl),a ld a,b ld bc,15 ;because hl was incremented, one less is subtracted add hl,bc ld b,a djnz FFlipLoop ret TinyFlip: ;input: hl = address of top-left of screen chunk ld b,8 TFlipLoop: ld a,(hl) cpl ;NOT the a register ld (hl),a ld a,b ld bc,16 add hl,bc ld b,a djnz TFlipLoop ret TinyPut: ;input: de=top of token address, hl=top of screen address ld b,7 TPLoop: ld a, (de) ; Load byte contained at DE location into A ld (hl), a ; Put it onto the screen!!! inc de ;Make token address go more one byte. ld a,b ;Temporarily store value of b in a so bc can be used. ld bc,16 add hl,bc ;Make screen go more one ROW. ld b,a ;Restore value of b. djnz TPLoop ;Decrement B, if 0 then get outta there ret TinyStream: ;input: de=top of 5-token address, hl=top of screen address ld b,40 TSLoop: ld a, (de) ; Load byte contained at DE location into A ld (hl), a ; Put it onto the screen!!! inc de ;Make token address go more one byte. ld a,b ;Temporarily store value of b in a so bc can be used. ld bc,16 add hl,bc ;Make screen go more one ROW. ld b,a ;Restore value of b. djnz TSLoop ;Decrement B, if 0 then get outta there ret FatPut: ;input: de=top of token address, hl=top of screen address ld b,16 FPLoop: ld a, (de) ; Load byte contained at DE location into A ld (hl), a ; Put it onto the screen!!! inc de ;Make token address go more one byte. inc hl ;Make screen address go more one byte. ld a, (de) ld (hl), a inc de ld a,b ;Temporarily store value of b in a so bc can be used. ld bc,15 add hl,bc ;Make screen go more one ROW. ld b,a ;Restore value of b. djnz FPLoop ;Decrement B, if 0 then get outta there ret DoublePut: ;input: de=top of token address, hl=top of screen address ld b,7 DPLoop: ld a, (de) ; Load byte contained at DE location into A push de call ConvertByte ld (hl),d ; Put it onto the screen!!! inc hl ld (hl),e ld a,b ;Temporarily store value of b in a so bc can be used. ld bc,15 add hl,bc ;Make screen go more one ROW. ld (hl),d ; Put it onto the screen again. inc hl ld (hl),e pop de inc de add hl,bc ld b,a ;Restore value of b. djnz DPLoop ;Decrement B, if 0 then get outta there ret ConvertByte: ;in: a, out: de. courtesy Andy Selle ld de,0 bit 0,a jr z,Bit2 set 0,e set 1,e Bit2: bit 1,a jr z,Bit3 set 2,e set 3,e Bit3: bit 2,a jr z,Bit4 set 4,e set 5,e Bit4: bit 3,a jr z,Bit5 set 6,e set 7,e Bit5 bit 4,a jr z,Bit6 set 0,d set 1,d Bit6: bit 5,a jr z,Bit7 set 2,d set 3,d Bit7: bit 6,a jr z,Bit8 set 4,d set 5,d Bit8: bit 7,a jr z,Bit9 set 6,d set 7,d Bit9: ret SelSpot: ld de,0 ld a,(Selected) add a,1 ld e,a sla e ld hl,VIDEO_MEM+768 add hl,de ret FlipSel: call SelSpot call FatFlip ret SelNext: call DispIt ld a,(Selected) cp 3 jr z,OverFlowSel inc a ld (Selected),a call FlipSel ret OverFlowSel: ld a,0 ld (Selected),a call FlipSel ret SelPrev: call DispIt ld a,(Selected) cp 0 jr z,UnderFlowSel dec a ld (Selected),a call FlipSel ret UnderFlowSel: ld a,3 ld (Selected),a call FlipSel ret DispIt: call SelSpot FindVal: push hl push hl ld hl,UCode ld de,(Selected) add hl,de ld de,0 ld e,(hl) sla e sla e sla e sla e sla e ld hl,FatToken0 add hl,de ld d,h ld e,l pop hl call FatPut pop hl ret IncIt: ld hl,UCode ld de,(Selected) add hl,de ld a,(hl) cp 5 jr z,OverFlowInc inc a ld (hl),a call DispIt call FatFlip ret OverFlowInc: ld a,0 ld (hl),a call DispIt call FatFlip ret DecIt: ld hl,UCode ld de,(Selected) add hl,de ld a,(hl) cp 0 jr z,UnderFlowDec dec a ld (hl),a call DispIt call FatFlip ret UnderFlowDec: ld a,5 ld (hl),a call DispIt call FatFlip ret Analyze: ld hl,PCode ld de,TCode ld b,4 CopyLoop: ld a,(hl) ld (de),a inc hl inc de djnz CopyLoop ld b,4 ld hl,TCode ld de,UCode SameSame: ld a,(hl) ld c,a ld a,(de) cp c jr nz,EndSS ld (hl),7 push hl ld h,d ld l,e ld (hl),8 ld hl,SameSameNum ld a,(hl) inc a ld (hl),a pop hl EndSS: inc hl inc de djnz SameSame ld hl,SameSameNum ld a,(hl) cp 4 jr nz,NotWin ld hl,ProgState ld a,2 ld (hl),a ret NotWin: ld b,4 ld hl,TCode SameDiff: push bc push hl ld de,UCode ld b,4 SameDiffLoop: ld a,(hl) ld c,a ld a,(de) cp c jr nz,EndSDL ld (hl),7 push hl ld h,d ld l,e ld (hl),8 ld hl,SameDiffNum ld a,(hl) inc a ld (hl),a pop hl EndSDL: inc de djnz SameDiffLoop pop hl pop bc inc hl djnz SameDiff ret Flush: ld b,12 ld hl,TEXT_MEM+4 FlushLoop: ld (hl),0 inc hl djnz FlushLoop ret GetCode: call Flush call DispIt call FlipSel ld hl,Selected ld (hl),1 call DispIt ld hl,Selected ld (hl),2 call DispIt ld hl,Selected ld (hl),3 call DispIt ld hl,Selected ld (hl),0 GCLoop: call FlashKeyLoop cp $04 jr z,IncItCall cp $01 jr z,DecItCall cp $02 jr z,SelPrevCall cp $03 jr z,SelNextCall cp $36 jr z,GCRet cp $09 jr z,GCRet cp $37 jr z,GCLose jr GCLoop IncItCall: call IncIt jr GCLoop DecItCall: call DecIt jr GCLoop SelPrevCall: call SelPrev jr GCLoop SelNextCall: call SelNext jr GCLoop GCRet: call FlipSel ret GCLose: ld hl,ProgState ld a,1 ld (hl),a ret GetNumAddr: ld de,0 ld e,(hl) ld hl,Zero sla e sla e ; * 8 sla e add hl,de ret GetTokenAddr: ld de,UCode ld hl,0 ld l,a add hl,de ld de,0 ld e,(hl) ld hl,Token0 sla e sla e ; * 8 sla e add hl,de ret DispNum: ld hl,GuessNum call GetNumAddr ld d,h ld e,l ld hl,VIDEO_MEM+784 call DoublePut ret NumPlace: ld hl,GuessNum ld a,(hl) cp 1 jr z,NumOne cp 2 jr z,NumTwo cp 3 jr z,NumThree cp 4 jr z,NumFour cp 5 jr z,NumFive cp 6 jr z,NumSix cp 7 jr z,NumSeven cp 8 jr z,NumEight cp 9 jr z,NumNine ld hl,VIDEO_MEM+649 ;NumTen ret NumOne: ld hl,VIDEO_MEM+128 ret NumTwo: ld hl,VIDEO_MEM+256 ret NumThree: ld hl,VIDEO_MEM+384 ret NumFour: ld hl,VIDEO_MEM+512 ret NumFive: ld hl,VIDEO_MEM+640 ret NumSix: ld hl,VIDEO_MEM+137 ret NumSeven: ld hl,VIDEO_MEM+265 ret NumEight: ld hl,VIDEO_MEM+393 ret NumNine: ld hl,VIDEO_MEM+521 ret FlipNum: call NumPlace call TinyFlip ret PutCode: call NumPlace ld a,0 inc hl PutCodeLoop: push af push hl push hl call GetTokenAddr ld d,h ld e,l pop hl call TinyPut pop hl pop af inc a inc hl cp 4 jr nz,PutCodeLoop ret PutClue: ld hl,SameSameNum call GetNumAddr ld d,h ld e,l push de call NumPlace pop de ld bc,5 add hl,bc call TinyPut ld hl,SameDiffNum call GetNumAddr ld d,h ld e,l push de call NumPlace pop de ld bc,6 add hl,bc call TinyPut ret AnswerPut: ld hl,PCode ld de,UCode ld b,4 CopyPCode: ld a,(hl) ld (de),a inc hl inc de djnz CopyPCode ld hl,GuessNum ld a,4 ld (hl),a call PutCode ret GetTries: ld hl,GuessNum call GetNumAddr ld d,h ld e,l ld hl,VIDEO_MEM+768+2 call DoublePut ret MainScreen: ROM_CALL(CLEARLCD) set 3,(IY+05) ld hl,$0000 ;Put "Meister Mind" down ld de,MMTitle call TextPut) res 3,(IY+05) ld hl,One ld d,h ld e,l ld hl,VIDEO_MEM+128 call TinyStream ;Put 1-5 down ld de,Six ld hl,VIDEO_MEM+137 call TinyStream ;Put 6-10 down ret ;Data Token0: ; /\ triangle .db %00010000 .db %00111000 .db %00111000 .db %01101100 .db %01110100 .db %11110110 .db %11111110 .db %00000000 Token1: ; \/ triangle .db %11111110 .db %11011110 .db %01011100 .db %01101100 .db %00111000 .db %00111000 .db %00010000 .db %00000000 Token2: ; cross .db %00111000 .db %00111000 .db %11100110 .db %11110110 .db %11111110 .db %00111000 .db %00111000 .db %00000000 Token3: ; square .db %11111110 .db %11000110 .db %11110110 .db %11110110 .db %11111110 .db %11111110 .db %11111110 .db %00000000 Token4: ; circle .db %00111000 .db %01101100 .db %11110110 .db %11111110 .db %11111110 .db %01111100 .db %00111000 .db %00000000 Token5: ; diamond .db %00010000 .db %00111000 .db %01101100 .db %11111110 .db %01111100 .db %00111000 .db %00010000 .db %00000000 FatToken0: .db %00000001,%00000000 .db %00000011,%10000000 .db %00000011,%10000000 .db %00000111,%11000000 .db %00000111,%11000000 .db %00001111,%11100000 .db %00001111,%11100000 .db %00011110,%01110000 .db %00011110,%01110000 .db %00111111,%10011000 .db %00111111,%10011000 .db %01111111,%10011100 .db %01111111,%10011100 .db %11111111,%11111110 .db %11111111,%11111110 .db %00000000,%00000000 FatToken1: .db %11111111,%11111110 .db %11111111,%11111110 .db %01111001,%11111100 .db %01111001,%11111100 .db %00111001,%11111000 .db %00111001,%11111000 .db %00011110,%01110000 .db %00011110,%01110000 .db %00001111,%11100000 .db %00001111,%11100000 .db %00000111,%11000000 .db %00000111,%11000000 .db %00000011,%10000000 .db %00000011,%10000000 .db %00000001,%00000000 .db %00000000,%00000000 FatToken2: .db %00000111,%11000000 .db %00000111,%11000000 .db %00000111,%11000000 .db %00000111,%11000000 .db %00000111,%11000000 .db %11111100,%00111110 .db %11111100,%00111110 .db %11111111,%00111110 .db %11111111,%00111110 .db %11111111,%11111110 .db %00000111,%11000000 .db %00000111,%11000000 .db %00000111,%11000000 .db %00000111,%11000000 .db %00000111,%11000000 .db %00000000,%00000000 FatToken3: .db %11111111,%11111110 .db %11111111,%11111110 .db %11111000,%00011110 .db %11111000,%00011110 .db %11111111,%10011110 .db %11111111,%10011110 .db %11111111,%10011110 .db %11111111,%10011110 .db %11111111,%11111110 .db %11111111,%11111110 .db %11111111,%11111110 .db %11111111,%11111110 .db %11111111,%11111110 .db %11111111,%11111110 .db %11111111,%11111110 .db %00000000,%00000000 FatToken4: .db %00000111,%11000000 .db %00011111,%11110000 .db %00111110,%01111000 .db %01111110,%01111100 .db %01111111,%10011100 .db %11111111,%10011110 .db %11111111,%11111110 .db %11111111,%11111110 .db %11111111,%11111110 .db %11111111,%11111110 .db %01111111,%11111100 .db %01111111,%11111100 .db %00111111,%11111000 .db %00011111,%11110000 .db %00000111,%11000000 .db %00000000,%00000000 FatToken5: .db %00000001,%00000000 .db %00000011,%10000000 .db %00000111,%11000000 .db %00001111,%11100000 .db %00011110,%01110000 .db %00111110,%01111000 .db %01111111,%11111100 .db %11111111,%11111110 .db %01111111,%11111100 .db %00111111,%11111000 .db %00011111,%11110000 .db %00001111,%11100000 .db %00000111,%11000000 .db %00000011,%10000000 .db %00000001,%00000000 .db %00000000,%00000000 Zero: .db %00111000 .db %01000100 .db %10000010 .db %10000010 .db %10000010 .db %01000100 .db %00111000 .db %00000000 One: .db %00110000 .db %01010000 .db %00010000 .db %00010000 .db %00010000 .db %00010000 .db %11111110 .db %00000000 Two: .db %01111100 .db %10000010 .db %00000100 .db %00011000 .db %00100000 .db %01000000 .db %11111110 .db %00000000 Three: .db %01111100 .db %10000010 .db %00000010 .db %00111100 .db %00000010 .db %10000010 .db %01111100 .db %00000000 Four: .db %10000100 .db %10000100 .db %10000100 .db %01111110 .db %00000100 .db %00000100 .db %00000100 .db %00000000 Five: .db %11111110 .db %10000000 .db %10000000 .db %01111100 .db %00000010 .db %10000010 .db %01111100 .db %00000000 Six: .db %00111110 .db %01000000 .db %10000000 .db %11111100 .db %10000010 .db %10000010 .db %01111100 .db %00000000 Seven: .db %11111110 .db %00000100 .db %00001000 .db %00010000 .db %00100000 .db %01000000 .db %10000000 .db %00000000 Eight: .db %01111100 .db %10000010 .db %10000010 .db %01111100 .db %10000010 .db %10000010 .db %01111100 .db %00000000 Nine: .db %01111100 .db %10000010 .db %10000010 .db %01111110 .db %00000010 .db %10000010 .db %01111100 .db %00000000 Ten: .db %10011100 .db %10100010 .db %10100010 .db %10100010 .db %10100010 .db %10100010 .db %10011100 .db %00000000 MMTitle: .db " <* Meister Mind *> ",0 MMme1: .db "F1: 1 Player Game",0 MMme2: .db "F2: 2 Player Game",0 MMme3: .db "F3: About",0 MMme4: .db "F4: Exit",0 MMab1: .db "v1.3 PhatOS Edition",0 MMab2: .db "By Martin Hock",0 MMab3: .db "(oxymoron@bigsky.net)",0 MMab4: .db "Send me e-mail if you",0 MMab5: .db "like Meister Mind!",0 MMPlayer2: .db "Please enter code:",0 MMYouWin1: .db "CONGRATULATIONS!!!",0 MMYouWin2: .db "You win!",0 MMYouLose1: .db "Too bad.",0 MMYouLose2: .db "You lose.",0 MMCodeWas: .db "The code was:",0 MMNumTries: .db "Number of tries:",0 .end