home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 92 / asm / source / fargo / irlib.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  5.3 KB  |  261 lines

  1. ;
  2. ;
  3. ;  IR Link Library v1.0 for the TI92
  4. ;
  5. ;      by Sami Khawam ( sKhawam@bigfoot.com )
  6. ;
  7. ;
  8. ;  This library will enable you to use the IR Link. There are only
  9. ;  4 routines now, but new routines will be added in the future ( like
  10. ;  remote control encoding, deconding...).
  11. ;
  12. ;  Although the ROM link routines can be used with the IR Link, this
  13. ;  library has it own linking routines ( work also without the IR Link ).
  14. ;
  15. ;
  16. ;  If you haven't yet heard of the IR Link, take a look at my homepage:
  17. ;      http://unet.univie.ac.at/~a9501901
  18. ;
  19. ;
  20. ;  Thanks for Antoine Mercier for having ported
  21. ;  the PutByte routine from the TI85.
  22. ;
  23. ;
  24. ;  Sami Khawam
  25.  
  26.  
  27.     include    "tios.h"
  28.     xdef    _library
  29.    xdef  irlib@0000
  30.    xdef  irlib@0001
  31.    xdef  irlib@0002
  32.    xdef  irlib@0003
  33.    xdef  irlib@0004
  34.  
  35. ;************** Start of library ***************
  36.  
  37.  
  38.  
  39. ; **********************************************
  40. ;
  41. ; PutByte:  Send a byte to the IR Link
  42. ; Input:    d3.b  Byte to send
  43. ; Output:   none
  44. ; Destroyed: d4
  45. ;
  46. ;
  47. ;
  48. ; PutLink:  Send a byte/word of longword to the IR Link
  49. ; Input:    d3  data to send
  50. ;           d4  number of bits -1 (7...31)
  51. ; Output:   none
  52. ; Destroyed: none
  53. ;
  54. ; Thanks for Antoine Mercier for having ported
  55. ; those routine from the TI85.
  56. ;
  57.  
  58. irlib@0000:
  59. PutByte:
  60.    move.w    #7,d4
  61. irlib@0001:
  62. PutLink
  63.     movem    d2-d4,-(a7)
  64.     clr.b    $60000C
  65.     bset.b    #6,$60000C            ; Turn on control mode
  66.  
  67. nextbit:
  68.     bclr.b    #0,$60000E            ; rouge haut
  69.     bclr.b    #1,$60000E            ; blanc haut
  70.     lsr.l    #1,d3
  71.     bcc        pbsend0
  72. pbsend1:
  73.     bset.b    #1,$60000E            ; blanc bas
  74.     bra        pbsuite
  75. pbsend0:
  76.     bset.b    #0,$60000E            ; rouge bas
  77. pbsuite:
  78.     move.w    #$FFFF,d2
  79. waitforR0:
  80.     btst.b    #2,$60000E
  81.     bne        suite1
  82.     btst.b    #2,$60000E
  83.     bne        suite1
  84.     dbne    d2,waitforR0
  85.     bra        pbfin
  86. suite1:
  87.     move.w    #$FFFF,d2
  88. waitforW0:
  89.     btst.b    #3,$60000E
  90.     bne        suite2
  91.     btst.b    #3,$60000E
  92.     bne        suite2
  93.     dbne    d2,waitforW0
  94.     bra        pbfin
  95. suite2:
  96.     bclr.b    #0,$60000E            ; rouge haut
  97.     bclr.b    #1,$60000E            ; blanc haut
  98.     move.w    #$FFFF,d2
  99. waitforR1:
  100.     btst.b    #2,$60000E
  101.     beq        suite3
  102.     btst.b    #2,$60000E
  103.     beq        suite3
  104.     dbne    d2,waitforR1
  105.     bra        pbfin
  106. suite3:
  107.     move.w    #$FFFF,d2
  108. waitforW1:
  109.     btst.b    #3,$60000E
  110.     beq        suite4
  111.     btst.b    #3,$60000E
  112.     beq        suite4
  113.     dbne    d2,waitforW1
  114.     bra        pbfin
  115. suite4:
  116.     dbne    d4,nextbit
  117. pbfin:
  118.     bclr.b    #0,$60000E            ; rouge haut
  119.     bclr.b    #1,$60000E            ; blanc haut
  120.     movem    (a7)+,d2-d4
  121.     rts
  122.  
  123. ;*****************************************************
  124.  
  125.  
  126. ; **********************************************
  127. ;
  128. ; GetByte:  Get a byte from the IR Link
  129. ; Input:    none
  130. ; Output:   d3.b  Byte received
  131. ; Destroyed: d4
  132. ;
  133. ;
  134. ;
  135. ; PutLink:  Get a byte/word of longword from the IR Link-DOESN'T WORK
  136. ; Input:    d4.w  Number of Bits
  137. ; Output:   d3    data received
  138. ; Destroyed: none
  139. ;
  140. ; The GetLink routine DOES NOT WORK!
  141. ;
  142. ;
  143. irlib@0002:
  144. GetByte:
  145.    move.w   #8,d4          
  146. irlib@0003:
  147. GetLink:                    ; Doesn't work with d4 != 8
  148.    movem    d1-d2,-(a7)   
  149.    clr.l    d3
  150. ;   clr.b    $60000C
  151. ;   bset.b   #6,$60000C      ; Turn on control mode
  152. GLNextBit
  153.     move.w    #$FFFF,d2
  154. GLWaitChange:
  155.     btst.b    #2,$60000E
  156.    bne      GLGet0
  157.    btst.b   #3,$60000E
  158.    bne      GLGet1
  159.    btst.b   #2,$60000E
  160.    bne      GLGet0
  161.    btst.b   #3,$60000E
  162.    bne      GLGet1
  163.     sub.w        #1,d2
  164.     cmp.w        #0,d2
  165.    bne      GLWaitChange
  166.    bra      GLEnd
  167. GLGet0:
  168.    bset.b   #1,$60000E        ; Set W0
  169.    lsr.l    #1,d3
  170. GLWaitR1:
  171.    btst.b   #2,$60000E
  172.    beq      GLSetHigh
  173.    btst.b   #2,$60000E
  174.    beq      GLSetHigh
  175.     sub.w        #1,d2
  176.     cmp.w        #0,d2
  177.    bne      GLWaitR1
  178.    bra      GLEnd
  179. GLGet1:
  180.    bset.b   #0,$60000E        ; Set R0
  181.    lsr.l    #1,d3
  182.    ori      #$80,d3         
  183. GLWaitW1:
  184.    btst.b   #3,$60000E
  185.    beq      GLSetHigh
  186.    btst.b   #3,$60000E
  187.    beq      GLSetHigh
  188.     sub.w        #1,d2
  189.     cmp.w        #0,d2
  190.    bne      GLWaitW1
  191.    bra      GLEnd
  192. GLSetHigh
  193.    bclr.b   #0,$60000E        ; Set R1
  194.    bclr.b   #1,$60000E        ; Set W1
  195.    move.w   #$0008,d2
  196. GLWaitR1_2:
  197.    btst.b   #2,$60000E
  198.    beq      GLCont1
  199.    btst.b   #2,$60000E
  200.    beq      GLCont1
  201.    sub.w    #1,d2
  202.    cmp.w    #0,d2
  203.    bne      GLWaitR1_2
  204. GLCont1:
  205.    move.w   #$0008,d2
  206. GLWaitW1_2:
  207.    btst.b   #3,$60000E
  208.    beq      GLCont2
  209.    btst.b   #3,$60000E
  210.    beq      GLCont2
  211.    sub.w    #1,d2
  212.    cmp.w    #0,d2
  213.    bne      GLWaitW1_2
  214. GLCont2:
  215.    sub.w    #1,d4
  216.    cmp.w    #0,d4
  217.    bne      GLNextBit
  218. GLEnd:
  219.    bclr.b   #0,$60000E        ; Set R1
  220.    bclr.b   #1,$60000E        ; Set W1
  221.    movem    (a7)+,d1-d2
  222.     rts
  223.  
  224. ;*****************************************************
  225. ;
  226. ; Convert between frequency in KHz to delay units needed by the IR Link.
  227. ; Input:    d2.b  Freq in KHz.
  228. ; Output:   d3.w  contains the 2 delay values.
  229. ; Used:     a2
  230. ;
  231. irlib@0004:
  232. Freq2Delay:
  233.    sub.b    #30,d2         ; Substract 30KHz from it.
  234.    andi     #30,d2         
  235.    lea      DelayTab(PC),a2 ; Now A2 points to the delay table.
  236.    move.w   0(a2,d2),d3    ; Copy the 2 delay values corresponding
  237.                            ; to the freq to d3.
  238.    rts
  239.  
  240.  
  241.  
  242.  
  243. ;*****************************************************
  244.  
  245.  
  246. DelayTab:                        ; To convert between KHz and delay units.
  247.    dc.b $0B,$0F 
  248.    dc.b $0C,$10 
  249.    dc.b $0D,$11 
  250.    dc.b $0E,$12 
  251.    dc.b $0F,$12 
  252.    dc.b $0F,$13 
  253.    dc.b $10,$14 
  254.    dc.b $11,$14 
  255.    dc.b $11,$15 
  256.    dc.b $12,$15
  257.  
  258. _library    dc.b    "irlib",0
  259.     end
  260.