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

  1. ;
  2. ;
  3. ;  IR Link Library v1.0 for the TI89 and 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, decoding...).
  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. ;  This library is accualy an executable asm program. When executed
  16. ;  the user will be able to change the settings of the library.
  17. ;  Currently there are 3 settings you can change:
  18. ;
  19. ;  -Swap Lines: On/Off .
  20. ;   This option is useful if you have unintetionaly swaped the red
  21. ;   and the white wires of the calc-ir_link connection. Use it
  22. ;   if you dont want to solder the cable again.
  23. ;
  24. ;  -Timeout duration:
  25. ;   Set the duration that the calc should try to transfer data
  26. ;   when it doesn't receive anything.
  27. ;
  28. ;  -Linking Delay:
  29. ;   Set the linking delay. Maybe useful if connected with a
  30. ;   slower calc(eg. TI82), or if you are getting errors.
  31. ;
  32. ;  If you haven't yet heard of the IR Link, take a look at my homepage:
  33. ;      http://sami.ticalc.org
  34. ;
  35. ;
  36. ;  Thanks for Antoine Mercier for having ported
  37. ;  the PutByte routine from the TI85.
  38. ;
  39. ;
  40. ;  Sami Khawam
  41.  
  42.  
  43.    include  "doorsos.h"
  44.    include "graphlib.h"
  45.     include "userlib.h"
  46.    include "hexlib.h"
  47.    xdef  _main
  48.     xdef    _ti92plus
  49.     xdef    _ti89
  50.    xdef  _comment
  51.    xdef  irlib@0000
  52.    xdef  irlib@0001
  53.    xdef  irlib@0002
  54.    xdef  irlib@0003
  55.    xdef  irlib@0004
  56.  
  57.  
  58.  
  59. ;************** Start of program ***************
  60.  
  61. _main:
  62.  
  63.    move.w   #40,d5          ; d5 contains the cursor position
  64.  
  65. ClearScreen:
  66.    jsr      graphlib::clr_scr
  67.    SetFont  #2
  68.    WriteStr #18,#1,#1,_comment
  69.    WriteStr #45,#20,#1,Text1
  70.    SetFont  #1
  71.    WriteStr #8,#40,#1,Text2
  72.    WriteStr #8,#56,#1,Text3
  73.    WriteStr #8,#72,#1,Text4
  74.  
  75.  
  76. DrawCur:
  77.   
  78.    move.w   #4,-(a7)
  79.    move.w   d5,-(a7)
  80.    move.w   #1,-(a7)
  81.    move.w   #26,-(a7)                ; This is the '>>' charachter.
  82.    jsr      userlib::DrawCharXY
  83.    lea      8(a7),a7
  84.  
  85.  
  86. PrintState:
  87.    btst.b   #0,(SwapL)
  88.    beq      PrintOff
  89.    WriteStr #120,#40,#1,Text5
  90.    bra      PrintDelays
  91. PrintOff
  92.    WriteStr #120,#40,#1,Text6
  93.  
  94.  
  95. PrintDelays:
  96.    clr.l    d0
  97.    move.w   (Timeout),d0
  98.    move.l   #7,d1
  99.    move.l   #15,d2
  100.    move.l   #3,d4
  101.    jsr      hexlib::put_hex
  102.  
  103.    clr.l    d0
  104.    move.w   (LDelay),d0
  105.    move.l   #9,d1
  106.    move.l   #15,d2
  107.    move.l   #3,d4
  108.    jsr      hexlib::put_hex
  109.  
  110. MainLoop:
  111.  
  112.    jsr    userlib::idle_loop
  113.  
  114.  
  115.    cmp      #KEY_DOWN,d0            ; Down
  116.    beq      CurDown
  117.    cmp      #KEY_UP,d0              ; Up
  118.    beq      CurUp
  119.    cmp      #KEY_RIGHT,d0           ; Right
  120.    beq      CurRight
  121.    cmp      #KEY_LEFT,d0            ; Left
  122.    beq      CurLeft
  123.    cmp      #264,d0                 ; Exit
  124.     beq        Exit
  125.    bra      MainLoop
  126.  
  127. CurDown:
  128.    cmp      #72,d5
  129.    bge      MainLoop
  130.    add.w    #16,d5
  131.    bra      ClearScreen
  132. CurUp:
  133.    cmp      #40,d5
  134.    ble      MainLoop
  135.    sub.w    #16,d5
  136.    bra      ClearScreen
  137.  
  138. CurRight:
  139.    cmp      #40,d5
  140.    bne      CheckTO
  141. SwpL
  142.    bchg.b   #0,(SwapL)
  143.    bra      ClearScreen
  144. CheckTO
  145.    cmp      #56,d5
  146.    bne      CheckDE1
  147.    add.w    #$0100,(Timeout)
  148.    bra      PrintDelays
  149. CheckDE1
  150.    cmp      #72,d5
  151.    bne      MainLoop
  152.    add.w    #$0100,(LDelay)
  153.    bra      PrintDelays
  154.  
  155. CurLeft:
  156.    cmp      #40,d5
  157.    beq      SwpL
  158.    cmp      #56,d5
  159.    bne      CheckDE2
  160.    sub.w    #$0100,(Timeout)
  161.    bra      PrintDelays
  162. CheckDE2
  163.    cmp      #72,d5
  164.    bne      MainLoop
  165.    sub.w    #$0100,(LDelay)
  166.    bra      PrintDelays
  167.  
  168.  
  169. Exit:
  170.    jsr      doorsos::reset_link
  171.     rts
  172.  
  173. ;************** Start of library ***************
  174.  
  175.  
  176.  
  177. ; **********************************************
  178. ;
  179. ; PutByte:  Send a byte to the IR Link
  180. ; Input:    d3.b  Byte to send
  181. ; Output:   none
  182. ; Destroyed: d4
  183. ;
  184. ;
  185. ;
  186. ; PutLink:  Send a byte/word or longword to the IR Link
  187. ; Input:    d3  data to send
  188. ;           d4  number of bits -1 (7...31)
  189. ; Output:   none
  190. ; Destroyed: none
  191. ;
  192. ; Thanks for Antoine Mercier for having ported
  193. ; those routine from the TI85.
  194. ;
  195.  
  196. irlib@0000:
  197. PutByte:
  198.    move.w   #7,d4          
  199. irlib@0001:
  200. PutLink:
  201.    movem    d2-d4,-(a7)
  202.    clr.b    $60000C
  203.    bset.b   #6,$60000C      ; Turn on control mode
  204.  
  205.    btst.b   #0,(SwapL)
  206.    beq      nextbit
  207.    not.l    d3
  208.  
  209. nextbit:
  210.    bclr.b   #0,$60000E        ; rouge haut
  211.     bclr.b    #1,$60000E            ; blanc haut
  212.    lsr.l    #1,d3
  213.     bcc        pbsend0
  214. pbsend1:
  215.     bset.b    #1,$60000E            ; blanc bas
  216.     bra        pbsuite
  217. pbsend0:
  218.     bset.b    #0,$60000E            ; rouge bas
  219. pbsuite:
  220.    move.w   (Timeout),d2
  221. ;  move.w   #$FFFF,d2
  222. waitforR0:
  223.     btst.b    #2,$60000E
  224.     bne        suite1
  225.     btst.b    #2,$60000E
  226.     bne        suite1
  227.    dbra.w   d2,waitforR0
  228.     bra        pbfin
  229. suite1:
  230.    move.w   (Timeout),d2
  231. ;  move.w   #$FFFF,d2
  232. waitforW0:
  233.     btst.b    #3,$60000E
  234.     bne        suite2
  235.     btst.b    #3,$60000E
  236.     bne        suite2
  237.    dbra.w   d2,waitforW0
  238.     bra        pbfin
  239. suite2:
  240.     bclr.b    #0,$60000E            ; rouge haut
  241.     bclr.b    #1,$60000E            ; blanc haut
  242.    move.w   (Timeout),d2
  243. ;  move.w   #$FFFF,d2
  244. waitforR1:
  245.     btst.b    #2,$60000E
  246.     beq        suite3
  247.     btst.b    #2,$60000E
  248.     beq        suite3
  249.    dbra.w   d2,waitforR1
  250.     bra        pbfin
  251. suite3:
  252.    move.w   (Timeout),d2
  253. ;  move.w   #$FFFF,d2
  254. waitforW1:
  255.     btst.b    #3,$60000E
  256.     beq        suite4
  257.     btst.b    #3,$60000E
  258.     beq        suite4
  259.    dbra.w   d2,waitforW1
  260.     bra        pbfin
  261. suite4:
  262. ;   sub.w    #1,d4
  263. ;   cmp.w    #0,d4
  264. ;   bne      nextbit
  265.    dbra.w   d4,nextbit
  266.  
  267.    move.w   (LDelay),d2
  268. ;  move.w   #$08FF,d2
  269. Delay:
  270.    nop
  271.    dbra.w   d2,Delay
  272.  
  273.  
  274. pbfin:
  275.     bclr.b    #0,$60000E            ; rouge haut
  276.     bclr.b    #1,$60000E            ; blanc haut
  277.    movem    (a7)+,d2-d4
  278.     rts
  279.  
  280. ;*****************************************************
  281.  
  282.  
  283. ; **********************************************
  284. ;
  285. ; GetByte:  Get a byte from the IR Link
  286. ; Input:    none
  287. ; Output:   d3.b  Byte received
  288. ; Destroyed: d4
  289. ;
  290. ;
  291. ;
  292. ; PutLink:  Get a byte/word of longword from the IR Link   -DOESN'T WORK
  293. ; Input:    d4.w  Number of Bits
  294. ; Output:   d3    data received
  295. ; Destroyed: none
  296. ;
  297. ; The GetLink routine DOES NOT WORK!
  298. ;
  299. ;
  300. irlib@0002:
  301. GetByte:
  302.    move.w   #7,d4          
  303. irlib@0003:
  304. GetLink:                    ; Doesn't work with d4 != 8
  305.    movem    d1-d2,-(a7)   
  306.    clr.l    d3
  307.    clr.b    $60000C
  308.    bset.b   #6,$60000C      ; Turn on control mode
  309. GLNextBit
  310.    move.w   (Timeout),d2
  311. ;  move.w   #$FFFF,d2
  312. GLWaitChange:
  313.     btst.b    #2,$60000E
  314.    bne      GLGet0
  315.    btst.b   #3,$60000E
  316.    bne      GLGet1
  317.    btst.b   #2,$60000E
  318.    bne      GLGet0
  319.    btst.b   #3,$60000E
  320.    bne      GLGet1
  321.    dbra.w   d2,GLWaitChange
  322.    bra      GLEnd
  323. GLGet0:
  324.    bset.b   #1,$60000E        ; Set W0
  325.    lsr.l    #1,d3
  326.    move.w   (Timeout),d2
  327. GLWaitR1:
  328.    btst.b   #2,$60000E
  329.    beq      GLSetHigh
  330.    btst.b   #2,$60000E
  331.    beq      GLSetHigh
  332.    dbra.w   d2,GLWaitR1
  333.    bra      GLEnd
  334. GLGet1:
  335.    bset.b   #0,$60000E        ; Set R0
  336.    lsr.l    #1,d3
  337.    ori      #$80,d3         
  338.    move.w   (Timeout),d2
  339. GLWaitW1:
  340.    btst.b   #3,$60000E
  341.    beq      GLSetHigh
  342.    btst.b   #3,$60000E
  343.    beq      GLSetHigh
  344.    dbra.w   d2,GLWaitW1
  345.    bra      GLEnd
  346. GLSetHigh
  347.    bclr.b   #0,$60000E        ; Set R1
  348.    bclr.b   #1,$60000E        ; Set W1
  349.    move.w   #$0010,d2
  350. GLWaitR1_2:
  351.    btst.b   #2,$60000E
  352.    beq      GLCont1
  353.    btst.b   #2,$60000E
  354.    beq      GLCont1
  355.    dbra.w   d2,GLWaitR1_2
  356. GLCont1:
  357.    move.w   #$0010,d2
  358. GLWaitW1_2:
  359.    btst.b   #3,$60000E
  360.    beq      GLCont2
  361.    btst.b   #3,$60000E
  362.    beq      GLCont2
  363.    dbra.w   d2,GLWaitW1_2
  364. GLCont2:
  365.    dbra.w   d4,GLNextBit
  366. GLEnd:
  367.    bclr.b   #0,$60000E        ; Set R1
  368.    bclr.b   #1,$60000E        ; Set W1
  369.  
  370.    btst.b   #0,(SwapL)
  371.    beq      GLNoSwap
  372.    not.l    d3
  373.  
  374. GLNoSwap
  375.    movem    (a7)+,d1-d2
  376.     rts
  377.  
  378. ;*****************************************************
  379. ;
  380. ; Convert between frequency in KHz to delay units needed by the IR Link.
  381. ; Input:    d2.b  Freq in KHz.
  382. ; Output:   d3.w  contains the 2 delay values.
  383. ; Used:     a2
  384. ;
  385. irlib@0004:
  386. Freq2Delay:
  387.    sub.b    #30,d2         ; Substract 30KHz from it.
  388.    andi     #30,d2         
  389.    lea      DelayTab(PC),a2 ; Now A2 points to the delay table.
  390.    move.w   0(a2,d2),d3    ; Copy the 2 delay values corresponding
  391.                            ; to the freq to d3.
  392.    rts
  393.  
  394.  
  395.  
  396.  
  397. ;*****************************************************
  398.  
  399.  
  400. DelayTab:                        ; To convert between KHz and delay units.
  401.    dc.b $0F,$0B
  402.    dc.b $10,$0C
  403.    dc.b $11,$0D
  404.    dc.b $12,$0E
  405.    dc.b $12,$0F
  406.    dc.b $13,$0F 
  407.    dc.b $14,$10
  408.    dc.b $14,$11
  409.    dc.b $15,$11
  410.    dc.b $15,$12
  411.  
  412. LDelay:
  413.          dc.w  $00FF
  414. Timeout:
  415.          dc.w  $FFFF
  416. SwapL:
  417.          dc.w  0
  418.  
  419. Text1:   dc.b  "Settings",0
  420. Text2:   dc.b  "Swap Lines:",0
  421. Text3:   dc.b  "Timeout duration:",0
  422. Text4:   dc.b  "Linking Delay:",0
  423. Text5:   dc.b  "On ",0
  424. Text6:   dc.b  "Off",0
  425.  
  426. _comment dc.b  "IR Link Library",0
  427.  
  428.     end
  429.