home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 82 / asm / source / ash / remote82.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  9.9 KB  |  481 lines

  1. ;
  2. ;
  3. ;  This is a TI82 port of the programm for ASH.
  4. ;
  5. ; A sample program for using the IR Link as a  Learning Remote Control.
  6. ;  by Sami Khawam (sKhawam@bigfoot.com)
  7. ;  http://unet.univie.ac.at/~a9501901
  8. ;
  9. ; The programm is very simple to use. There are only 4 keys fonctions
  10. ; each one represented by an arrow key. To make the program record data
  11. ; from an remote control, press 2nd and choose the key and then the time
  12. ; base and the frequency. If you don't know thoses value you should 
  13. ; experiment by using differents ones.
  14. ; DO NOT specifie frequencies that are less than 30 KHz or more than
  15. ; 48 KHz!
  16. ;
  17. ; This programm needs the STANDART version of the IR Link.
  18. ;
  19. ; The PutByte and was taken (and modified) from a disassembly of the ROM.
  20. ; GetByte is from  Randy Gluvna (gluvna@home.com). Thanks.
  21. ;
  22.  
  23. #INCLUDE "TI82.H"
  24. #INCLUDE "KEYS.INC"
  25.  
  26. PORT = 000H
  27. Port = 000H
  28.  
  29. .ORG START_ADDR
  30. Name:
  31. .db "IR Remote "
  32. PName2:
  33. .db "by Sami Khawam",0
  34.  
  35. Start:
  36.         LD      A, $C0          ; Set W1 and R1
  37.         OUT     (Port),A
  38.  
  39.         ROM_CALL(CLEARLCD)
  40.  
  41.         set 3,(IY+05)
  42.         ld hl, PName2
  43.         ld de,$0000
  44.         ld ($800C),de
  45.         ROM_CALL(D_ZT_STR)
  46.  
  47.         res 3,(IY+05)
  48.         ld hl, Text1     
  49.         ld de,$0003
  50.         ld ($800C),de
  51.         ROM_CALL(D_ZT_STR)
  52.  
  53. ProgLoop:
  54.         CALL GET_KEY
  55.         or a
  56.         jr z, ProgLoop
  57.         cp $37
  58.         ret z
  59.         cp G_2nd 
  60.         jr z, RecordRemote
  61.  
  62.         dec a           ; Only less than 3
  63.         cp 4
  64.         jr nc, ProgLoop
  65.  
  66.         ld hl, CK_1
  67.         ld de, 32
  68.         ld b, a                 ; Get Offset
  69. AddNxt1:
  70.         add hl, de
  71.         djnz AddNxt1
  72.  
  73.         ; Now Send data
  74.         ld a, 30                ; Always 30 bytes.
  75.         call PutByte           ; Send the Byte
  76.         call SendHeader
  77.         ld b, 30
  78. NextByte:
  79.         ld a, (hl)              
  80.         call PutByte           ; Now we send all bytes.
  81.         inc hl
  82.         djnz NextByte
  83.         jr Start
  84.  
  85.  
  86.  
  87.  
  88.  
  89. RecordRemote
  90.         ROM_CALL(CLEARLCD)
  91.         ld hl, Text2     
  92.         ld de,$0001
  93.         ld ($800C),de
  94.         ROM_CALL(D_ZT_STR)
  95.  
  96. WaitKey:
  97.     call GET_KEY
  98.         or a
  99.         jr z, WaitKey
  100.         cp $37
  101.         jr z, Start
  102.  
  103.         dec a           ; Only less than 3
  104.         cp 4
  105.         jr nc, WaitKey
  106.  
  107.         ld hl, CK_1
  108.         ld de, 32
  109.         ld b, a                 ; Get Offset
  110. AddNxt2:
  111.         add hl, de
  112.         djnz AddNxt2
  113.  
  114.         push hl
  115.         ld hl, Text_TimeBase
  116.         ld de,$0002
  117.         ld ($800C),de
  118.         ROM_CALL(D_ZT_STR)
  119.         pop hl
  120.         call InputValue
  121.  
  122.         inc hl
  123.         push hl
  124.         ld hl, Text_Wait1
  125.         ld de,$0003
  126.         ld ($800C),de
  127.         ROM_CALL(D_ZT_STR)
  128.         pop hl
  129.         call InputValue
  130.  
  131.         ld a, $5E               ; $5E = 30d & $40, because we have 30 bytes 
  132.         call PutByte         
  133.  
  134.         dec hl
  135.         call SendHeader
  136.  
  137.         push hl
  138.         ROM_CALL(CLEARLCD)
  139.         ld hl, Text_Wait3     
  140.         ld de,$0103
  141.         ld ($800C),de
  142.         ROM_CALL(D_ZT_STR)
  143.         ROM_CALL(BUSY_ON)
  144. WaitSig:
  145.         in      a,(Port)
  146.         and     3
  147.         cp      3
  148.         jr      nz, DataComing
  149.         call    GET_KEY
  150.         cp      G_MODE
  151.         jr      z, Quit
  152.         jr      WaitSig
  153.  
  154. DataComing:
  155.         pop hl
  156.  
  157.         ld b, 30
  158. GNextByte:
  159.         push bc 
  160.         call GetByte
  161.         pop bc
  162.         ld (hl), a
  163.         inc hl
  164.         call PrintHex
  165.         djnz GNextByte
  166.         ROM_CALL(BUSY_OFF)
  167. WaitLoop:
  168.         call GET_KEY
  169.     or a    ; cp 0
  170.         jr z, WaitLoop
  171.         jp Start
  172. Quit
  173.         pop hl
  174.         jp Start
  175.  
  176.  
  177.  
  178.  
  179. InputValue
  180. IVLoop
  181.         ld de, (CURSOR_ROW)
  182.         set 3,(IY+05)
  183.         ld a, (hl)
  184. ;        #fncall D_A_DEC
  185.         call DispA
  186.         res 3,(IY+05)
  187.         ld (CURSOR_ROW),de
  188.         push hl
  189.         call GET_KEY
  190.         pop hl
  191.         or a
  192.         jr z, IVLoop
  193.         cp G_ENTER
  194.         ret z
  195.         cp G_UP
  196.         jr z, Increment
  197.         cp G_DOWN
  198.         jr z, Decrement
  199. Increment
  200.         ld a, (hl)
  201.         inc a
  202.         ld (hl), a
  203.         jr IVLoop
  204. Decrement
  205.         ld a, (hl)
  206.         dec a
  207.         ld (hl), a
  208.         jr IVLoop
  209.                 
  210.  
  211.  
  212. SendHeader
  213.         ld a, (hl)
  214.         call PutByte         
  215.         inc hl
  216.  
  217.         ld a, (hl)
  218.         sub 30
  219.         rr a
  220.         inc hl
  221.  
  222.         push hl
  223.  
  224.         ld hl, DelayTab
  225.         ld de, 2
  226.         ld b, a                 ; Get Offset
  227. AddNxt3:
  228.         add hl, de
  229.         djnz AddNxt3
  230.  
  231.         ld a, (hl)
  232.         call PutByte         
  233.         inc hl
  234.         ld a, (hl) 
  235.         call PutByte         
  236.         pop hl
  237.         ret
  238.  
  239.  
  240.  
  241.  
  242.  
  243. GetByte:
  244.         LD      B,008H          
  245. R0:
  246.         LD      DE,0FFFFH       
  247.         JR      R2              
  248. R1:
  249.         IN      A,(PORT)        
  250.         AND     003H            
  251.         RET     Z               
  252.         CP      003H            
  253.         JR      NZ,R3           
  254.         IN      A,(PORT)        
  255.         AND     003H            
  256.         RET     Z               
  257.         CP      003H            
  258.         JR      NZ,R3           
  259. R2:
  260.         DEC     DE              
  261.         LD      A,D             
  262.         OR      E               
  263.         JR      NZ,R1           
  264.         RET                     
  265. R3:
  266.         SUB     002H            
  267.         JR      NC,R8           
  268.         LD      A,0D4H          
  269.         OUT     (PORT),A        
  270.         RR      C               
  271.         LD      DE,0FFFFH       
  272. R4:
  273.         IN      A,(PORT)        
  274.         AND     003H            
  275.         CP      002H            
  276.         JR      Z,R5            
  277.         DEC     DE              
  278.         LD      A,D             
  279.         OR      E               
  280.         JR      NZ,R4           
  281.         RET                     
  282. R5:
  283.         LD      A,0C0H          
  284.         OUT     (PORT),A        
  285.         LD      D,004H          
  286. R6:
  287.         DEC     D               
  288.         JR      Z,R7            
  289.         IN      A,(PORT)        
  290.         AND     003H            
  291.         CP      003H            
  292.         JR      NZ,R6           
  293. R7:
  294.         DJNZ    R0              
  295.         LD      A,C             
  296.         RET                     
  297. R8:
  298.         LD      A,0E8H          
  299.         OUT     (PORT),A        
  300.         RR      C               
  301.         LD      DE,0FFFFH       
  302. R9:
  303.         IN      A,(PORT)        
  304.         AND     003H            
  305.         CP      001H            
  306.         JR      Z,R5            
  307.         DEC     DE              
  308.         LD      A,D             
  309.         OR      E               
  310.         JR      NZ,R9           
  311.         RET                     
  312.  
  313.  
  314.  
  315. PutByte:
  316.         push bc
  317.         LD      C,A
  318.         LD      B,8             ; 8 Bits
  319.  
  320. PB_Next_Bit:
  321.         ld d, B                 ; Only to see if it is working.
  322.         ld e, $01               ;
  323.         ld ($800C),de           ;
  324.         ld    A, B              ;
  325.         ROM_CALL(TX_CHARPUT)        ;
  326.  
  327.  
  328.         LD      A, $C0          ; Set W1 and R1
  329.         OUT     (Port),A
  330.  
  331. Cont:
  332.         RR      C
  333.         JR      NC, PB_SendZero
  334. PB_SendOne:
  335.         LD      A, $E8
  336.         JR      PB_Output_val
  337. PB_SendZero:
  338.         LD      A, $D4
  339. PB_Output_val:
  340.         OUT     (Port),A
  341.  
  342.         LD      DE, $FFFF       ; For time-out
  343. PB_Wait_for_W0_and_R0:
  344.         IN      A,(Port)
  345.         AND     3
  346.         JR      Z, PB_Continue
  347.         IN      A,(Port)
  348.         AND     3
  349.         JR      Z, PB_Continue
  350.         DEC     DE
  351.         LD      A,D
  352.         OR      E
  353.         JR      NZ, PB_Wait_for_W0_and_R0
  354.         JR      PB_End          ; If error return.
  355.  
  356. PB_Continue:
  357.         LD      A, $C0          ; Set W1 and R1
  358.         OUT     (Port),A
  359.  
  360.         LD      DE, $FFFF       ; Reload time-out
  361. PB_Wait_for_W1_and_R1:
  362.         DEC     DE
  363.         LD      A,D
  364.         OR      E
  365.         JR      Z, PB_End
  366.         IN      A,(Port)
  367.         AND     3
  368.         CP      3
  369.         JR      NZ, PB_Wait_for_W1_and_R1
  370.  
  371.         DJNZ    PB_Next_Bit
  372. PB_End:
  373.         POP    BC
  374.         RET
  375.  
  376.  
  377.  
  378. ;;;;;;;;;;;PrintHex function
  379. PrintHex:            ; de destroyed
  380.         push hl
  381.         push bc
  382.     push de
  383.  
  384.     ld b, a
  385.     and $0f0
  386.     rrca
  387.     rrca
  388.     rrca
  389.     rrca
  390.  
  391.     add a, 30h
  392.     cp $3a
  393.     jr c, hexnumber0
  394.     add a, $7
  395. hexnumber0:
  396.         ROM_CALL(TX_CHARPUT)
  397.  
  398.     ld a, b
  399.     and $0f
  400.  
  401.     add a, 30h
  402.     cp $3a
  403.     jr c, hexnumber1
  404.     add a, $7
  405. hexnumber1:
  406.         ROM_CALL(TX_CHARPUT)
  407.     pop de
  408.     pop bc
  409.         pop hl
  410.     ret
  411. ;;;;;;;;;end PrintHex function
  412.  
  413.  
  414.  
  415. DispA:                        ;Routine to Display A [By: Matthew Shepcar]
  416.         push hl
  417.     push de
  418.         ld l,a                    ;Loads a into l
  419.     ld h,0                    ;0 into H
  420. ;DispHL:                                        ;Displays HL [By: Matthew Shepcar]
  421.         xor a                                   ;Loads 0 into A
  422.         ROM_CALL(D_HL_DECI)                     ;Calls 4A33h
  423.         dec hl                                  ;Decrease it
  424.         ROM_CALL(D_ZT_STR)                      ;Put on screen and return
  425.         pop de
  426.         pop hl
  427.     ret
  428.  
  429.  
  430.  
  431.  
  432.  
  433. CK_1:
  434.  .db 10, 32
  435.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  436.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  437.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  438.  
  439.  .db 11, 34
  440.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  441.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  442.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  443.  
  444.  .db 12, 36
  445.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  446.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  447.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  448.  
  449.  .db 13, 38
  450.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  451.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  452.  .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  453.  
  454.  
  455. DelayTab:
  456. .db $0B, $0F 
  457. .db $0C, $10 
  458. .db $0D, $11 
  459. .db $0E, $12 
  460. .db $0F, $12 
  461. .db $0F, $13 
  462. .db $10, $14 
  463. .db $11, $14 
  464. .db $11, $15 
  465. .db $12, $15
  466.  
  467.  
  468. Text1:
  469.  .db "2nd to record.", 0
  470. Text2:
  471.  .db "Key to assign:", 0
  472. Text_TimeBase:
  473.  .db "Time base:", 0
  474. Text_Wait1:
  475.  .db "Frequency:", 0
  476. Text_Wait3:
  477.  .db "Getting "
  478. Text_Data:
  479.  .db "Data", $CE, 0
  480. .end
  481.