;Tic-Tac-Toe using the IR Link for ASH. ;By Sami Khawam(sKhawam@bigfoot.com) ; ; ; ;This is a very simple 2 players Tic-Tac-Toe game that ;demonstrate the use of the IR Link. However, the game ;can be played with the cable and without the IR Link. ; ;The "Linking with Ack" or the "Linking w/o Ack" modes ;can be used with this program. For more info on how ;to build and use the IR Link see my homepage: ; ; http://unet.univie.ac.at/~a9501901 ; ; ;The program is very simple to use. The keys used : ; ;Keys 9...1 : Check cases accoding to button position. ;Exit : Exit the game on both calcs. ;Clear : Clear the board on both calcs. ; ;The game can be played between a TI85 (or TI86) and ;a TI82. ; ; ;The game lacks of some essential features, because I made it ;very quickly: ; ;-There are no turns, a player can check as many cases ; as he wants.(be sure that the you opponents doesn't ; cheat ... ;) ;-The program doesn't detect if someone has won. ;-A piece can be erased by the other player. ; ; ; The PutByte was taken (and modified) from a disassembly of the ROM. ; ; GetByte is from Randy Gluvna (gluvna@home.com). Thanks. ; ; #INCLUDE "TI82.H" #INCLUDE "KEYS.INC" PORT = 000H .ORG START_ADDR .db "Tic-Tac-Toe using the IR Link",0 Start: ROM_CALL(CLEARLCD) ld a, '|' ld de, $04FF ; e will become 0 after inc call LineVert ld de, $09FF ; e will become 0 after inc call LineVert ld a, '-' ld de, $FF02 call LineHorz ld de, $FF05 call LineHorz ProgLoop: ld a, $C0 ; Set W1 and R1 out (PORT), a in a, (PORT) and 3 cp 3 jr nz, ReceiveCoin ld c, 'X' call GET_KEY cp G_MODE ; This one is from the jr z, ExitGame ; keyboard. cp G_CLEAR ; This one is from the jr z, ClearBoard ; keyboard. TestKeys: or a jr z, ProgLoop cp G_MODE ; This one is from the ret z ; other end. cp G_CLEAR ; This one is from the jr z, Start ; other end. cp G_1 jr z, Place1 cp G_2 jr z, Place2 cp G_4 jr z, Place4 cp G_3 jr z, Place3 cp G_5 jr z, Place5 cp G_6 jr z, Place6 cp G_7 jr z, Place7 cp G_8 jr z, Place8 cp G_9 jr z, Place9 jr ProgLoop Place1: ld hl, $0207 jr PrintChar Place2: ld hl, $0607 jr PrintChar Place3: ld hl, $0B07 jr PrintChar Place4: ld hl, $0204 jr PrintChar Place5: ld hl, $0604 jr PrintChar Place6: ld hl, $0B04 jr PrintChar Place7: ld hl, $0201 jr PrintChar Place8: ld hl, $0601 jr PrintChar Place9: ld hl, $0B01 PrintChar: ld (CURSOR_ROW), hl ld b, a ; The Key Scancode is now in b. ld a, c ROM_CALL(TX_CHARPUT) cp 'O' jp z, ProgLoop ld a, b ; The Key Scancode is now in a. call PutByte jp ProgLoop ReceiveCoin call GetByte ; We recieve a Key Scancode. ld c, 'O' jr TestKeys ExitGame: call PutByte ret z ClearBoard: call PutByte jp Start LineVert: ld b, 8 Vert: inc e ld (CURSOR_ROW), de ROM_CALL(TX_CHARPUT) djnz Vert ret LineHorz: ld b, 14 Horz: inc d ld (CURSOR_ROW), de ROM_CALL(TX_CHARPUT) djnz Horz ret ; Thanks for Randy Gluvna (gluvna@home.com) for this recieve routine. GetByte: push bc LD B,008H R0: LD DE,0FFFFH JR R2 R1: IN A,(PORT) AND 003H jr z, GB_End CP 003H JR NZ,R3 IN A,(PORT) AND 003H jr z, GB_End CP 003H JR NZ,R3 R2: DEC DE LD A,D OR E JR NZ,R1 jr GB_End R3: SUB 002H JR NC,R8 LD A,0D4H OUT (PORT),A RR C LD DE,0FFFFH R4: IN A,(PORT) AND 003H CP 002H JR Z,R5 DEC DE LD A,D OR E JR NZ,R4 jr GB_End R5: LD A,0C0H OUT (PORT),A LD D,004H R6: DEC D JR Z,R7 IN A,(PORT) AND 003H CP 003H JR NZ,R6 R7: DJNZ R0 LD A,C jr GB_End R8: LD A,0E8H OUT (PORT),A RR C LD DE,0FFFFH R9: IN A,(PORT) AND 003H CP 001H JR Z,R5 DEC DE LD A,D OR E JR NZ,R9 GB_End pop bc ret PutByte: push bc LD C,A LD B,8 ; 8 Bits PB_Next_Bit: LD A, $C0 ; Set W1 and R1 OUT (PORT),A Cont: RR C JR NC, PB_SendZero PB_SendOne: LD A, $E8 JR PB_Output_val PB_SendZero: LD A, $D4 PB_Output_val: OUT (PORT),A LD DE, $FFFF ; For time-out PB_Wait_for_W0_and_R0: IN A,(PORT) AND 3 JR Z, PB_Continue IN A,(PORT) AND 3 JR Z, PB_Continue DEC DE LD A,D OR E JR NZ, PB_Wait_for_W0_and_R0 JR PB_End ; If error return. PB_Continue: LD A, $C0 ; Set W1 and R1 OUT (PORT),A LD DE, $FFFF ; Reload time-out PB_Wait_for_W1_and_R1: DEC DE LD A,D OR E JR Z, PB_End IN A,(PORT) AND 3 CP 3 JR NZ, PB_Wait_for_W1_and_R1 DJNZ PB_Next_Bit ld DE, $06FF ; Small delay PB_EW: DEC DE LD A,D OR E JR NZ, PB_EW PB_End: POP BC RET .end