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

  1. ;
  2. ;
  3. ; IR Remote v2.0 for the TI89 and the TI92+.
  4. ;
  5. ; A sample program for using the IR Link as a  Learning Remote Control.
  6. ;
  7. ;  by Sami Khawam (sKhawam@bigfoot.com)
  8. ;
  9. ;  http://sami.ticalc.org
  10. ;
  11. ; The programm is very simple to use. There are 8 keys functions
  12. ; represented by F1-F8 keys. To make the program record data
  13. ; from a remote control, press Enter and choose the key and then the
  14. ; frequency and the time base. If you don't know thoses value , eg.
  15. ; when dealing  with an unknow remote, you should experiment by using
  16. ; differents ones. Try also the classic Time Base/Frequency combinations
  17. ; like 15/38Khz and 12/32Khz.
  18. ;
  19. ; This programm needs the STANDART version of the IR Link.
  20. ; The IRLib library is needed.
  21. ;
  22. ;
  23. ;  If you haven't yet heard of the IR Link, take a look at my homepage:
  24. ;      http://sami.ticalc.org
  25. ;
  26.  
  27.  
  28.     include "doorsos.h"
  29.     include "graphlib.h"
  30.     include "userlib.h"
  31.    include "hexlib.h"
  32.    include "irlib.h"
  33.  
  34.     xdef    _ti89
  35.    xdef  _ti92plus
  36.     xdef    _main
  37.     xdef    _comment
  38.  
  39.  
  40.  
  41. ;************************* Start of Program **************************
  42.  
  43. _main:
  44.    clr      d3
  45.    clr      d4
  46.    clr      d5
  47.    jsr      graphlib::clr_scr2
  48.    SetFont  #1
  49.    WriteStr #8,#5,#0,_comment
  50.    SetFont  #2
  51.    WriteStr #0,#40,#1,Text1
  52.    WriteStr #0,#60,#1,Text2
  53.  
  54.    clr.b    $60000C
  55.    bset.b   #6,$60000C      ; Turn on control mode
  56.  
  57. Loop:
  58.    jsr      userlib::idle_loop
  59.  
  60.     cmp        #264,d0            ; exit
  61.     beq        Exit
  62.    cmp      #13,d0         ; Enter
  63.    beq      RecordRemote
  64.  
  65.    cmp      #268,d0        
  66.    blt      Loop
  67.    sub      #268,d0        ; 268 is the code for F1
  68.    cmp      #7,d0          ; 268+7=275, code for F8
  69.    bgt      Loop
  70.  
  71.    lea      CmdTable(PC),a0 ; Now A0 points to the data start.
  72.    lsl.w    #5,d0           ; Multiply by 32, since we use 32 bytes for each
  73.                             ; of the 5 commands.
  74.    add.l    d0,a0
  75.  
  76.    move.b   #30,d3            ; Tell the link that we are going to send
  77.    jsr      irlib::PutByte    ; 30 bytes.
  78.    bsr      SendHeader
  79.  
  80.    move.w   #29,d5
  81. SNextByte:
  82.    move.b   (a0)+,d3
  83.    jsr      irlib::PutByte
  84.    dbra.w   d5,SNextByte
  85.  
  86. ;   sub.w    #1,d5
  87. ;   cmp.w    #0,d5
  88. ;   bne      SNextByte
  89.  
  90.     bra        Loop
  91.  
  92. Exit:
  93.    jsr      doorsos::reset_link
  94.     rts
  95.  
  96. SendHeader:
  97.    move.b   (a0)+,d3       ; Send the time base.
  98.    jsr      irlib::PutByte
  99.    clr      d2
  100.    move.b   (a0)+,d2       ; Read the frequency information.
  101.    jsr      irlib::Freq2Delay
  102.    move.w   #15,d4         ; Send both of them.
  103.    jsr      irlib::PutLink
  104.    rts                     ; Return.
  105.  
  106.  
  107.  
  108.  
  109. RecordRemote
  110.    jsr      graphlib::clr_scr2
  111.    SetFont  #1
  112.    WriteStr #8,#5,#0,_comment
  113.    WriteStr #0,#30,#1,Text3
  114. RRKLoop:
  115.    jsr      userlib::idle_loop
  116.    cmp      #264,d0        ; exit. Return to main loop.
  117.    beq      _main
  118.    cmp      #268,d0        
  119.    blt      RRKLoop
  120.    sub      #268,d0        ; 268 is the code for F1
  121.    cmp      #7,d0          ; 268+7=275, code for F8
  122.    bgt      RRKLoop
  123.  
  124.    lea      CmdTable(PC),a3 ; Now A3 points to the data start.
  125.    lsl.w    #5,d0           ; Multiply by 32, since we use 32 bytes for each
  126.                             ; of the 5 commands.
  127.    add.l    d0,a3           ; a3 points now to the start of data.
  128.  
  129.    WriteStr #0,#40,#1,Text4 ; Get time base
  130.    move.w   #5,d1           ; Where to print the value.
  131.    move.w   #8,d2
  132.    clr      d5              ; Min time base = 0
  133.    move.b   #$FE,d6         ; Max time base = $FE
  134.    bsr      InputValue      ; Get time base from user.
  135.  
  136.    add      #1,a3
  137.  
  138.    WriteStr #0,#48,#1,Text5 ; Get freq
  139.    move.w   #6,d1          ; Where to print the value.
  140.    move.w   #13,d2
  141.    move.b   #30,d5          ; Min freq = 30Khz
  142.    move.b   #48,d6          ; Max freq = 48Khz
  143.    bsr      InputValue      ; Get time base from user.
  144.  
  145.    move.b   #$5E,d3           ; Tell the link that we want to receive
  146.    jsr      irlib::PutByte    ; 30 bytes.
  147.  
  148.    sub      #1,a3
  149.    move.l   a3,a0
  150.    bsr      SendHeader      ; Send the header.
  151.    move.l   a0,a3
  152.  
  153.    jsr      graphlib::clr_scr2
  154.    WriteStr #20,#10,#0,Text6
  155.  
  156.    bclr.b   #0,$60000E        ; Set R1
  157.    bclr.b   #1,$60000E        ; Set W1
  158.  
  159.    move.w   #1,-(a7)
  160.    jsr      doorsos::ST_busy
  161.    lea      2(a7),a7
  162.  
  163.  
  164. WaitSig:
  165.    tst.w    (doorsos::kb_vars+$1C)
  166.    beq      CheckLines
  167.    move.w   (doorsos::kb_vars+$1E),d0
  168.    clr.w    (doorsos::kb_vars+$1C)
  169.    cmp.w    #264,d0
  170.    beq      _main
  171. CheckLines:
  172.    btst.b   #2,$60000E
  173.    bne      ReceiveData
  174.    btst.b   #3,$60000E
  175.    bne      ReceiveData
  176.    bra      WaitSig
  177.  
  178. ;   move.l   #5,d1
  179. ;   move.l   #1,d2
  180.  
  181. ReceiveData:
  182.    move.w   #29,d5
  183. GNextByte:
  184.    jsr      irlib::GetByte
  185.    move.b   d3,(a3)+
  186.  
  187. ;   movem    d3-d5,-(a7)
  188. ;
  189. ;   clr.l    d0
  190. ;   move.b   d3,d0
  191. ;   move.l   #1,d3
  192. ;   jsr      hexlib::put_hex
  193. ;
  194. ;   add.l    #2,d2
  195. ;   cmp.l    #20,d2
  196. ;   blt      NoNewLine
  197. ;   add.l    #1,d1
  198. ;   clr.l    d1   
  199. ;NoNewLine
  200. ;   movem    (a7)+,d3-d5
  201.  
  202.    dbra.w   d5,GNextByte
  203.  
  204. ;   sub.w    #1,d5
  205. ;   cmp.w    #0,d5
  206. ;   bne      GNextByte
  207.  
  208.  
  209.    bra      _main
  210.  
  211.  
  212.  
  213.  
  214. ; InputValue
  215. ; Input: d1 ( row), d2 (column)
  216. ;        d5 ( min val), d6 ( max val )
  217. ;        a3 ( address where the byte will be stored )
  218. ; Output: (a3) contains byte read
  219. ;
  220. InputValue:
  221.    movem    d1-d6,-(a7)   ; Save the coordinates of the numbers
  222.  
  223.    move.b   (a3),d4       ; Read the data from memory.
  224.    clr.b    d0
  225.  
  226. Convert2BCD
  227.    subi.b   #10,d4
  228.    bcs      IVCont
  229.    addi.b   #$10,d0
  230.    bra      Convert2BCD
  231. IVCont
  232.    addi.b   #10,d4
  233.    or.b     d4,d0
  234.  
  235.    move.w   #1,d4
  236.     jsr        hexlib::put_hex
  237.  
  238.    jsr      userlib::idle_loop
  239.  
  240.    movem    (a7)+,d1-d6   ; Restore the coordinates of the numbers
  241.  
  242.    cmp      #KEY_DOWN,d0        ; down
  243.    beq      Decrement
  244.    cmp      #KEY_UP,d0        ; up
  245.    beq      Increment
  246.    cmp      #13,d0         ; Enter
  247.    beq      IVExit
  248.    bra      InputValue
  249. Decrement:
  250.    move.b   (a3),d0       ; Read the data from memory.
  251.    cmp.b    d5,d0
  252.    beq      InputValue
  253.    sub.b    #1,d0
  254.    move.b   d0,(a3)       ; Write data to memory.
  255.    bra      InputValue
  256. Increment:
  257.    move.b   (a3),d0       ; Read the data from memory.
  258.    cmp.b    d6,d0
  259.    beq      InputValue
  260.    add.b    #1,d0
  261.    move.b   d0,(a3)       ; Write data to memory.
  262.    bra      InputValue
  263. IVExit:
  264.     rts
  265.  
  266.  
  267.  
  268. CmdTable: 
  269.  
  270.    dc.b 10,32
  271.    dc.b 1,2,3,4,5,6,7,8,9,$Fe
  272.    dc.b 0,0,0,0,0,0,0,0,0,0
  273.    dc.b 0,0,0,0,0,0,0,0,0,0
  274.    dc.b 11,34
  275.    dc.b 0,0,0,0,0,0,0,0,0,0
  276.    dc.b 0,0,0,0,0,0,0,0,0,0
  277.    dc.b 0,0,0,0,0,0,0,0,0,0
  278.    dc.b 12,36
  279.    dc.b 0,0,0,0,0,0,0,0,0,0
  280.    dc.b 0,0,0,0,0,0,0,0,0,0
  281.    dc.b 0,0,0,0,0,0,0,0,0,0
  282.    dc.b 13,38
  283.    dc.b 0,0,0,0,0,0,0,0,0,0
  284.    dc.b 0,0,0,0,0,0,0,0,0,0
  285.    dc.b 0,0,0,0,0,0,0,0,0,0
  286.    dc.b 14,40
  287.    dc.b 0,0,0,0,0,0,0,0,0,0
  288.    dc.b 0,0,0,0,0,0,0,0,0,0
  289.    dc.b 0,0,0,0,0,0,0,0,0,0
  290.    dc.b 15,42
  291.    dc.b 0,0,0,0,0,0,0,0,0,0
  292.    dc.b 0,0,0,0,0,0,0,0,0,0
  293.    dc.b 0,0,0,0,0,0,0,0,0,0
  294.    dc.b 16,44
  295.    dc.b 0,0,0,0,0,0,0,0,0,0
  296.    dc.b 0,0,0,0,0,0,0,0,0,0
  297.    dc.b 0,0,0,0,0,0,0,0,0,0
  298.    dc.b 17,46
  299.    dc.b 0,0,0,0,0,0,0,0,0,0
  300.    dc.b 0,0,0,0,0,0,0,0,0,0
  301.    dc.b 0,0,0,0,0,0,0,0,0,0
  302.  
  303. Text1:   dc.b  "Enter to Record.",0
  304. Text2:   dc.b  "F1-F8 to Send.",0
  305. Text3:   dc.b  "Key (F1-F8) to Assing:",0
  306. Text4:   dc.b  "Time Base:",0
  307. Text5:   dc.b  "Frequency (KHz):",0
  308. Text6:   dc.b  "Waiting for data...",0
  309. _comment dc.b  "IR Remote by Sami Khawam",0
  310.     end
  311.