home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 83 / asm / source / routines / linktutorial.txt < prev    next >
Encoding:
Text File  |  2001-07-01  |  8.1 KB  |  274 lines

  1. ================================================================================================
  2. ===================================Link Tutorial by Merlijn=====================================
  3. ===========================================for ti83=============================================
  4.  
  5. ._______________________________________________________________________________________________.
  6. |                                                |    
  7. |    I'm programming for the ti83 for a year now and I always wanted to make a link        |
  8. |    game. But there was no link tutorial availeble. I asked around and everybody said    |
  9. |    that the Ztetris source should help me. Sadly enough doesn't zeteris' link work at    |
  10. |    all. Therefor did I decide to make a link tutorial for all you out there.        |
  11. |    Aim of this tutorial send and receive bytes for multiplayer games.            |
  12. |    E-mail me for questions, bugs, modifications and improvements. Mezzy30@hotmail.com    |
  13. |    Special thanx to Tijl Coosemans for his routines.                    |
  14. |_______________________________________________________________________________________________|
  15.  
  16.     Disclaimer:
  17.     I'm not responsible for damage to your calc, health ect. No one may publish this tutorial
  18.     whithout my permission. If you use this routine give me credits.
  19.  
  20.     First you should know that the Ti-83 and other calcs use three cables to link. A white,
  21.     a Red and a Yellow. The Yellow one the zero, so you can't set power on that one.
  22.     The Red and the White can be changed into high or low. Usually the lines are both set
  23.     low. This also accures after every romcall. The linkport is port number '0'.
  24.     
  25.     
  26.     Now to set the lines use the following code:
  27.  
  28.     ld a,0d1h    ;load value of lines into a, set red high
  29.     out (0),a    ;syntax for linkport, linkport has been set
  30.  
  31.     for other set values look in the table below.
  32.  
  33.     0d0h    both lines low
  34.     0d1h    red high, white low
  35.     0d2h    white high, red low
  36.     0d3h    both lines high
  37.  
  38.  
  39.     If you want to read the port use this:
  40.  
  41.     in a,(0)    ; check linkport
  42.         and 3        ; upper bits are not important
  43.         cp 2        ; 2 means white is active
  44.  
  45.     for other read values look in the table below.
  46.  
  47.     3    both lines low
  48.     2    red high, white low
  49.     1    white high, red low
  50.     0    both lines high
  51.  
  52.     
  53.     It is important to know that if one of the calcs sets the red wire high and the other sets
  54.     the white wire high it will result that when you read the linkport both lines are high (0).
  55.  
  56.     0d0h    3    both lines low
  57.     0d1h    2    red high, white low
  58.     0d2h    1    white high, red low
  59.     0d3h    0    both lines high
  60.  
  61.     0d1h+0d2h=>0    (every calc have to set one of the wires)
  62.  
  63.     I've written a program, 'READSET' to set and to read the port. 'READSET' can be found at ticalc.org
  64.  
  65.  
  66.     Now we want to send bytes and receive bytes. I used the send/receive code from venus and added a
  67.     synchronising routine made myselve to it. Take a look at the source it will explain itselve. 
  68.     
  69.  
  70.     -----header-----
  71.     #define     player      saferam1
  72.  
  73.  
  74.     start: 
  75.         in a,(0)        ;check linkport
  76.         and 3            ;upper bits are not important
  77.         cp 2            ;1 means red is high
  78.             jp z,youplayertwo    ;if true other player wants to receive
  79.             ld   a,0D1h        ;ld set red wire high
  80.             out  (0),a        ;required syntax
  81.  
  82.     youplayerone:  
  83.             ld a,1            ;set you player one
  84.             ld (player),a        ;save it
  85.         in a,(0)        ;check linkport
  86.             and 3            ;upper bits are not important
  87.             cp 0            ;0 means both high, wait until player two has entered
  88.             jp z,intro        ;if true other player wants to rec
  89.  
  90.         ld a,0ffh        ;resets the keypad.
  91.         out (1),a
  92.         ld a,KeyRow_Pad        ;enables the arrow keys
  93.         out (1),a
  94.         ld a,KeyRow_Top        ;enables the top keys
  95.         out (1),a  
  96.  
  97.             in a,(1)        ;check keys
  98.             cp KMode        ;quit if mode pressed
  99.             ret z
  100.             jp  youplayerone
  101.  
  102.     youplayertwo:
  103.         ld a,2            ;set you player two
  104.         ld (player),a        ;save it
  105.         ld   a,0D2h        ;set white wire high, so playerone continues
  106.         out  (0),a        ;required syntax
  107.  
  108.     delay:
  109.         in a,(0)        ;check linkport
  110.         and 3            ;upper bits are not important
  111.         cp 1            ;1 means white high, this happens if playerone set both low
  112.         jp nz,delay        ;check again
  113.  
  114.     intro:
  115.         bcall(_cleargbuf)    ;this will set both lines low and clear the graphbuffer
  116.  
  117.     mainloop:
  118.  
  119.     ----your program----
  120.  
  121.         call sendreceive    ;call sendreceive routine
  122.         jp mainloop        ;loop again
  123.  
  124.     sendreceive:
  125.         ld a,(player)
  126.         cp 1
  127.         jp z,send_than_receive    ;to have a fast link calcs have to do the opposite
  128.         cp 2
  129.         jp z,receive_than_send    ;to have a fast link calcs have to do the opposite
  130.  
  131.     send_than_receive:
  132.         ld a,(byte_to_send)    ;the byte you want to send
  133.         ld c,a            ;we actually send c
  134.         call sendbyte        ;call send routine
  135.         call receivebyte    ;call receive routine
  136.         ld a,e            ;we actually receive e
  137.         ld (received_byte)    ;save received byte
  138.         ret            ;return to mainloop
  139.  
  140.     receive_than_send:
  141.         call receivebyte    ;call receive routine
  142.         ld a,e            ;we actually receive e
  143.         ld (received_byte)    ;save received byte
  144.         ld a,(byte_to_send)    ;the byte you want to send
  145.         ld c,a            ;we actually send c
  146.         call sendbyte        ;call send routine
  147.         ret            ;return to mainloop
  148.  
  149. ;====================send routines from venus and synchronising by Merlijn=======================
  150.  
  151.     sendbyte:            ;input: white high, output: continue if red and white high
  152.         IN   A,(0)        ;check linkport
  153.             AND  3                  ;upper bits are not important
  154.             CP   1            ;1 means white is high
  155.         ret z            ;if true other player wants to send
  156.         ld a,0D2h        ;ld set white wire high
  157.             out (0),a        ;required syntax to send a to the linkport
  158.     sendbytewait:
  159.          IN   A,(0)        ;check linkport
  160.             AND  3                  ;upper bits are not important
  161.             CP   0            ;0 means red and white are high
  162.         jp   nz,sendbytewait    ;not true check again
  163.  
  164.         ld   a,0        ;set timer to zero
  165.     wait2:                ;create small delay so other can check port for double activety
  166.         inc a            ;increase timer 
  167.         cp 20            ;compare to 20
  168.         jp nz,wait2        ;not true increase more
  169.                         ;-----------end of synchronising-------------
  170.          di
  171.         ld    b,8
  172.     vnSendByteLoop:
  173.         rr    c        ;c is the byte to send
  174.     vnSendBit0:
  175.         ld    a,0D1h
  176.         jr    nc,vnSendBit
  177.     vnSendBit1:
  178.         inc    a
  179.     vnSendBit:
  180.         out    (0),a
  181.         ld    de,0
  182.     vnSendBitLoop1:
  183.         dec    de
  184.         ld    a,d
  185.         or    e
  186.         ret    z
  187.         in    a,(0)
  188.         and    0Ch
  189.         jr    nz,vnSendBitLoop1
  190.         ld    a,0D0h
  191.         out    (0),a
  192.         ld    de,0
  193.     vnSendBitLoop2:
  194.         dec    de
  195.         ld    a,d
  196.         or    e
  197.         ret    z
  198.         in    a,(0)
  199.         and    0Ch
  200.         cp    0Ch
  201.         jr    nz,vnSendBitLoop2
  202.         djnz    vnSendByteLoop
  203.         or    a    
  204.  
  205.         ld a,0D0h        ;ld set no wire high for next transmission
  206.                out (0),a        ;required syntax
  207.     
  208.         ret
  209.  
  210. ;=========================End of send routine====================================================
  211. ;=========================receive routine from venus and synchronising by Merlijn================
  212.  
  213.     receivebyte:            ;input: red high, output: continue if red and white high
  214.         IN   A,(0)        ;check linkport
  215.             AND  3                  ;upper bits are not important
  216.             CP   2            ;2 means red is high
  217.         ret z            ;if true other player wants to receive
  218.         ld   a,0D1h        ;ld set red wire high
  219.             out  (0),a        ;required syntax
  220.     receivebyte2:
  221.          IN   A,(0)        ;check linkport
  222.             AND  3                  ;upper bits are not important
  223.             CP   0            ;0 means red and white are high
  224.         jp   nz,receivebyte2    ;not true check again
  225.  
  226.         ld   a,0        ;set timer to zero
  227.         
  228.     wait:                ;create small delay so other can check port for double activety
  229.         inc a            ;increase timer
  230.         cp 40            ;compare to 40 
  231.         jp nz,wait        ;not true increase again
  232.                         ;-----------end of synchronising-------------
  233.          di
  234.         ld    b,8
  235.     vnReceiveByteLoop:
  236.         in    a,(0)
  237.         and    0Ch
  238.         ld    d,8
  239.         cp    d
  240.     vnReceiveBit1:
  241.         ld    a,0D1h
  242.         jr    nz,vnReceiveBit
  243.     vnReceiveBit0:
  244.         inc    a
  245.         ld    d,4
  246.     vnReceiveBit:
  247.         rr    e        ;e is the received byte 
  248.         out    (0),a
  249.         ld    hl,0
  250.     vnReceiveBitLoop:
  251.         dec    hl
  252.         ld    a,h
  253.         or    l
  254.         ret    z
  255.         in    a,(0)
  256.         and    d
  257.         jr    z,vnReceiveBitLoop
  258.         ld    a,0D0h
  259.         out    (0),a
  260.         ld    d,16
  261.     vnBitReceivedLoop:
  262.         dec    d
  263.         jr    nz,vnBitReceivedLoop
  264.         djnz    vnReceiveByteLoop
  265.         or    a
  266.  
  267.         ld a,0D0h        ;ld set no wire high for next transmission
  268.               out (0),a        ;required syntax
  269.  
  270.         ret
  271.  
  272. ;=======================End of receive routine===================================================
  273.  
  274.     Test it and make great link games.