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

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