home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 82 / asm / source / ash / ir_ttt82.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  7.8 KB  |  345 lines

  1.  
  2. ;Tic-Tac-Toe using the IR Link for ASH.
  3. ;By Sami Khawam(sKhawam@bigfoot.com)
  4. ;
  5. ;
  6. ;
  7. ;This is a very simple 2 players Tic-Tac-Toe game that
  8. ;demonstrate the use of the IR Link. However, the game
  9. ;can be played with the cable and without the IR Link.
  10. ;
  11. ;The "Linking with Ack" or the "Linking w/o Ack" modes
  12. ;can be used with this program. For more info on how
  13. ;to build and use the IR Link see my homepage:
  14. ;
  15. ;  http://unet.univie.ac.at/~a9501901
  16. ;
  17. ;
  18. ;The program is very simple to use. The keys used :
  19. ;
  20. ;Keys 9...1      : Check cases accoding to button position.
  21. ;Exit            : Exit the game on both calcs.
  22. ;Clear           : Clear the board on both calcs.
  23. ;
  24. ;The game can be played between a TI85 (or TI86) and
  25. ;a TI82.
  26. ;
  27. ;
  28. ;The game lacks of some essential features, because I made it
  29. ;very quickly:
  30. ;
  31. ;-There are no turns, a player can check as many cases
  32. ; as he wants.(be sure that the you opponents doesn't
  33. ; cheat ... ;)
  34. ;-The program doesn't detect if someone has won.
  35. ;-A piece can be erased by the other player.
  36. ;
  37. ;
  38. ; The PutByte was taken (and modified) from a disassembly of the ROM.
  39. ;
  40. ; GetByte is from  Randy Gluvna (gluvna@home.com). Thanks.
  41. ;
  42. ;
  43.  
  44. #INCLUDE "TI82.H"
  45. #INCLUDE "KEYS.INC"
  46.  
  47. PORT = 000H
  48.  
  49. .ORG START_ADDR
  50. .db "Tic-Tac-Toe using the IR Link",0
  51.  
  52.  
  53. Start:
  54.         ROM_CALL(CLEARLCD)
  55.  
  56.         ld      a, '|'
  57.  
  58.         ld      de, $04FF               ; e will become 0 after inc
  59.         call    LineVert
  60.  
  61.         ld      de, $09FF               ; e will become 0 after inc
  62.         call    LineVert
  63.  
  64.  
  65.         ld      a, '-'
  66.  
  67.         ld      de, $FF02
  68.         call    LineHorz
  69.  
  70.         ld      de, $FF05
  71.         call    LineHorz
  72.  
  73.  
  74. ProgLoop:
  75.  
  76.         ld      a, $C0          ; Set W1 and R1
  77.         out     (PORT), a
  78.  
  79.         in      a, (PORT)
  80.         and     3
  81.         cp      3
  82.         jr      nz, ReceiveCoin 
  83.  
  84.         ld      c, 'X'
  85.  
  86.         call    GET_KEY
  87.         cp      G_MODE                          ; This one is from the
  88.         jr      z, ExitGame                     ; keyboard.
  89.         cp      G_CLEAR                         ; This one is from the
  90.         jr      z, ClearBoard                   ; keyboard.
  91. TestKeys:
  92.         or      a
  93.         jr      z, ProgLoop
  94.         cp      G_MODE                          ; This one is from the
  95.         ret     z                               ; other end.
  96.         cp      G_CLEAR                         ; This one is from the
  97.         jr      z, Start                        ; other end.
  98.         cp      G_1
  99.         jr      z, Place1
  100.         cp      G_2
  101.         jr      z, Place2
  102.         cp      G_4
  103.         jr      z, Place4
  104.         cp      G_3
  105.         jr      z, Place3
  106.         cp      G_5
  107.         jr      z, Place5
  108.         cp      G_6
  109.         jr      z, Place6
  110.         cp      G_7
  111.         jr      z, Place7
  112.         cp      G_8
  113.         jr      z, Place8
  114.         cp      G_9
  115.         jr      z, Place9
  116.  
  117.         jr      ProgLoop
  118.  
  119.  
  120.  
  121. Place1:
  122.         ld      hl, $0207
  123.         jr      PrintChar
  124.  
  125. Place2:
  126.         ld      hl, $0607
  127.         jr      PrintChar
  128.  
  129. Place3:
  130.         ld      hl, $0B07
  131.         jr      PrintChar
  132.  
  133. Place4:
  134.         ld      hl, $0204
  135.         jr      PrintChar
  136.  
  137. Place5:
  138.         ld      hl, $0604
  139.         jr      PrintChar
  140.  
  141. Place6:
  142.         ld      hl, $0B04
  143.         jr      PrintChar
  144.  
  145. Place7:
  146.         ld      hl, $0201
  147.         jr      PrintChar
  148.  
  149. Place8:
  150.         ld      hl, $0601
  151.         jr      PrintChar
  152.  
  153. Place9:
  154.         ld      hl, $0B01
  155.  
  156.  
  157. PrintChar:
  158.         ld      (CURSOR_ROW), hl
  159.         ld      b, a                    ; The Key Scancode is now in b.
  160.         ld      a, c
  161.         ROM_CALL(TX_CHARPUT)
  162.         cp      'O'
  163.         jp      z, ProgLoop
  164.  
  165.         ld      a, b                    ; The Key Scancode is now in a.
  166.         call    PutByte                
  167.  
  168.         jp      ProgLoop
  169.  
  170.  
  171. ReceiveCoin
  172.         call    GetByte                ; We recieve a Key Scancode.
  173.         ld      c, 'O'
  174.         jr      TestKeys
  175.  
  176.  
  177. ExitGame:
  178.         call    PutByte
  179.         ret     z
  180.  
  181. ClearBoard:
  182.         call    PutByte
  183.         jp      Start
  184.         
  185.  
  186. LineVert:
  187.         ld      b, 8
  188. Vert:   inc     e
  189.         ld      (CURSOR_ROW), de
  190.         ROM_CALL(TX_CHARPUT)
  191.         djnz    Vert
  192.         ret 
  193.  
  194. LineHorz:
  195.         ld      b, 14
  196. Horz:   inc     d
  197.         ld      (CURSOR_ROW), de
  198.         ROM_CALL(TX_CHARPUT)
  199.         djnz    Horz
  200.         ret
  201.  
  202.  
  203.  
  204. ; Thanks for Randy Gluvna (gluvna@home.com) for this recieve routine.
  205.  
  206. GetByte:
  207.         push bc
  208.         LD      B,008H
  209. R0:
  210.         LD      DE,0FFFFH       
  211.         JR      R2              
  212. R1:
  213.         IN      A,(PORT)        
  214.         AND     003H            
  215.         jr      z, GB_End
  216.         CP      003H            
  217.         JR      NZ,R3           
  218.         IN      A,(PORT)        
  219.         AND     003H            
  220.         jr      z, GB_End
  221.         CP      003H            
  222.         JR      NZ,R3           
  223. R2:
  224.         DEC     DE              
  225.         LD      A,D             
  226.         OR      E               
  227.         JR      NZ,R1           
  228.         jr      GB_End
  229. R3:
  230.         SUB     002H            
  231.         JR      NC,R8           
  232.         LD      A,0D4H          
  233.         OUT     (PORT),A        
  234.         RR      C               
  235.         LD      DE,0FFFFH       
  236. R4:
  237.         IN      A,(PORT)        
  238.         AND     003H            
  239.         CP      002H            
  240.         JR      Z,R5            
  241.         DEC     DE              
  242.         LD      A,D             
  243.         OR      E               
  244.         JR      NZ,R4           
  245.         jr      GB_End
  246. R5:
  247.         LD      A,0C0H          
  248.         OUT     (PORT),A        
  249.         LD      D,004H          
  250. R6:
  251.         DEC     D               
  252.         JR      Z,R7            
  253.         IN      A,(PORT)        
  254.         AND     003H            
  255.         CP      003H            
  256.         JR      NZ,R6           
  257. R7:
  258.         DJNZ    R0              
  259.         LD      A,C             
  260.         jr      GB_End
  261. R8:
  262.         LD      A,0E8H          
  263.         OUT     (PORT),A        
  264.         RR      C               
  265.         LD      DE,0FFFFH       
  266. R9:
  267.         IN      A,(PORT)        
  268.         AND     003H            
  269.         CP      001H            
  270.         JR      Z,R5            
  271.         DEC     DE              
  272.         LD      A,D             
  273.         OR      E               
  274.         JR      NZ,R9           
  275. GB_End
  276.         pop bc
  277.         ret
  278.  
  279.  
  280.  
  281.  
  282. PutByte:
  283.         push    bc
  284.         LD      C,A
  285.         LD      B,8             ; 8 Bits
  286. PB_Next_Bit:
  287.         LD      A, $C0          ; Set W1 and R1
  288.         OUT     (PORT),A
  289.  
  290. Cont:
  291.         RR      C
  292.         JR      NC, PB_SendZero
  293. PB_SendOne:
  294.         LD      A, $E8
  295.         JR      PB_Output_val
  296. PB_SendZero:
  297.         LD      A, $D4
  298. PB_Output_val:
  299.         OUT     (PORT),A
  300.  
  301.         LD      DE, $FFFF       ; For time-out
  302. PB_Wait_for_W0_and_R0:
  303.         IN      A,(PORT)
  304.         AND     3
  305.         JR      Z, PB_Continue
  306.         IN      A,(PORT)
  307.         AND     3
  308.         JR      Z, PB_Continue
  309.         DEC     DE
  310.         LD      A,D
  311.         OR      E
  312.         JR      NZ, PB_Wait_for_W0_and_R0
  313.         JR      PB_End          ; If error return.
  314.  
  315. PB_Continue:
  316.         LD      A, $C0          ; Set W1 and R1
  317.         OUT     (PORT),A
  318.  
  319.         LD      DE, $FFFF       ; Reload time-out
  320. PB_Wait_for_W1_and_R1:
  321.         DEC     DE
  322.         LD      A,D
  323.         OR      E
  324.         JR      Z, PB_End
  325.         IN      A,(PORT)
  326.         AND     3
  327.         CP      3
  328.         JR      NZ, PB_Wait_for_W1_and_R1
  329.  
  330.         DJNZ    PB_Next_Bit
  331.  
  332.         ld      DE, $06FF              ; Small delay
  333. PB_EW:  
  334.         DEC     DE
  335.         LD      A,D
  336.         OR      E
  337.         JR      NZ, PB_EW
  338.  
  339. PB_End:
  340.         POP    BC
  341.         RET
  342.  
  343.  
  344. .end
  345.