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

  1. ;
  2. ;REC80 Remote Control for the TI82 for ASH.
  3. ;
  4. ;  by Sami Khawam (sKhawam@bigfoot.com)
  5. ;
  6. ;  http://unet.univie.ac.at/~a9501901
  7. ;
  8. ;
  9. ;This software uses the IR Link as a remote control
  10. ;for controling many devices. For informations on
  11. ;how to build and how to use the IR Link see my
  12. ;home page:
  13. ;
  14. ; http://unet.univie.ac.at/~a9501901
  15. ;
  16. ;
  17. ;This software enable to control all the devices that
  18. ;uses the REC80 protocol. This protol is used by many
  19. ;manufacturers, among them:
  20. ;
  21. ; Akai, Cannon, Goldstar, Hitachi, Kenwood, NEC, Onkyo
  22. ; Pioneer, TEAC, Yamaha and many of other Japanese
  23. ; manufacturers.
  24. ;
  25. ;
  26. ;The REC80 code is formed by 4 bytes: 2 Group bytes
  27. ;and 2 Command bytes. The second byte of the Group
  28. ;and the Command is the complement of the first one.
  29. ;
  30. ;This version doesn't support the extended REC80
  31. ;protocol. In the extended REC80 the second Group
  32. ;byte isn't the complement of the first one, which
  33. ;extends the range of devices that can be used.
  34. ;If you want extended REC80 protocol see the rec80e
  35. ;program.
  36. ;
  37. ;For the Groups and Commands codes, see rem34bg by
  38. ;Bjorn Gahm.
  39. ;
  40. ;
  41. ;The use of the programm is very easy. Only some
  42. ;keys are needed:
  43. ;
  44. ;-Up,Down:       Inc- and Derement the Command byte.
  45. ;-Left,Right:    Inc- and Derement the Group byte.
  46. ;-Enter:         Send the signal.
  47. ;
  48. ;
  49. ;
  50. ;Thanks for Antoine Mercier for his excellent All_phlps
  51. ;program.
  52. ;Thanks for Andreas Ess for his excellent functions pack.
  53. ;
  54. ;--
  55. ; Sami Khawam (sKhawam@bigfoot.com)
  56. ;
  57. ; http://unet.univie.ac.at/~a9501901
  58.  
  59.  
  60. #INCLUDE "TI82.H"
  61. #INCLUDE "KEYS.INC"
  62.  
  63. PORT = 000H
  64.  
  65. .ORG START_ADDR
  66. .db "REC80 Remote Control by SK",0
  67.  
  68. Code    =       APD_BUF
  69.  
  70.     LD A,$C0                        ; Set W1 and R1
  71.         OUT (PORT),A
  72.  
  73. Loop:
  74.         ROM_CALL(CLEARLCD)
  75.         ROM_CALL(BUSY_OFF)
  76.         ld hl,Text
  77.  
  78.         ld de,$0001
  79.         ld (CURSOR_ROW),de
  80.         ROM_CALL(D_ZT_STR)            
  81.  
  82.         ld de,$0003
  83.         ld (CURSOR_ROW),de
  84.         ROM_CALL(D_ZT_STR)            
  85.  
  86.         ld de,$0005
  87.         ld (CURSOR_ROW),de
  88.         ROM_CALL(D_ZT_STR)            
  89.  
  90.         ld a, (Group1)
  91.         cpl
  92.         ld (Group2), a
  93.  
  94.         push hl
  95.         ld a,(Group1)
  96.         call DispAHex
  97.         ld a,(Group2)
  98.         call DispAHex
  99.     pop hl
  100.  
  101.         ld a, (Command1)
  102.         cpl
  103.         ld (Command2), a
  104.  
  105.         ld de,$0006
  106.         ld (CURSOR_ROW),de
  107.         ROM_CALL(D_ZT_STR)            
  108.  
  109.         ld a,(Command1)
  110.         call DispAHex
  111.         ld a,(Command2)
  112.         call DispAHex
  113.  
  114. Loop1:
  115.         call GET_KEY
  116.         cp G_MODE
  117.         ret z
  118.         cp G_LEFT
  119.         jr z,dec_Grp
  120.         cp G_RIGHT
  121.         jr z,inc_Grp
  122.         cp G_DOWN
  123.         jr z,dec_Cmd
  124.         cp G_UP
  125.         jr z,inc_Cmd
  126.         cp G_ENTER
  127.         jr z,SendData
  128.         jr Loop1
  129.  
  130. dec_Grp:
  131.         ld a,(Group1)
  132.         dec a
  133.         ld (Group1), a
  134.         jp Loop
  135. inc_Grp:
  136.         ld a,(Group1)
  137.         inc a
  138.         ld (Group1), a
  139.         jp Loop
  140. dec_Cmd:
  141.         ld a,(Command)
  142.     dec a
  143.         ld (Command),a
  144.         jp Loop
  145. inc_Cmd:
  146.         ld a,(Command)
  147.     inc a
  148.         ld (Command),a
  149.         jp Loop
  150.  
  151. SendData:
  152.  
  153.         ld      hl, Code
  154.         xor     a
  155.         ld      b, 30
  156. ClearCode:
  157.         ld      (hl), a
  158.         djnz    ClearCode
  159.  
  160.         call Encode
  161.  
  162.  
  163.         ld      hl, Data
  164.         ld      b,7                             ; We load it into b for djnz
  165.         call    SendBytes                      ; Send the Bytes
  166.  
  167.         ld      hl, Code
  168.         ld      b, 20                           ; We load it into b for djnz
  169.         call    SendBytes                      ; Send the Bytes
  170.  
  171.         jp      Loop
  172.  
  173.  
  174. SendBytes
  175.         ld      a, (hl)
  176.         call    PutByte                         ; Send the Byte
  177.         inc     hl
  178.         djnz    SendBytes
  179.         ret
  180.  
  181.  
  182. PutByte:
  183.     push bc
  184.     LD C,A
  185.     LD B,8                            ; 8 Bits
  186. PB_Next_Bit:
  187.         ROM_CALL(BUSY_ON)
  188.     LD A,$C0                        ; Set W1 and R1
  189.         OUT (PORT),A
  190. Cont:
  191.     RR C
  192.     JR NC,PB_SendZero
  193. PB_SendOne:
  194.     LD A,$E8
  195.     JR PB_Output_val
  196. PB_SendZero:
  197.     LD A,$D4
  198. PB_Output_val:
  199.         OUT (PORT),A
  200.     LD DE,$FFFF                        ; For time-out
  201. PB_Wait_for_W0_and_R0:
  202.         IN A,(PORT)
  203.     AND 3
  204.     JR Z,PB_Continue
  205.         IN A,(PORT)
  206.     AND 3
  207.     JR Z,PB_Continue
  208.     DEC DE
  209.     LD A,D
  210.     OR E
  211.     JR NZ,PB_Wait_for_W0_and_R0
  212.     JR PB_End                        ; If error return.
  213. PB_Continue:
  214.     LD A,$C0                        ; Set W1 and R1
  215.         OUT (PORT),A
  216.     LD DE,$FFFF                        ; Reload time-out
  217. PB_Wait_for_W1_and_R1:
  218.     DEC DE
  219.     LD A,D
  220.     OR E
  221.     JR Z,PB_End
  222.         IN A,(PORT)
  223.     AND 3
  224.     CP 3
  225.     JR NZ,PB_Wait_for_W1_and_R1
  226.     DJNZ PB_Next_Bit
  227. PB_End:
  228.     POP BC
  229.     ret
  230.  
  231.  
  232.  
  233.  
  234.  
  235. ; This function encodes the data and stores it in 'Code'
  236.  
  237. Encode:              
  238.         ld      hl, Code
  239.         ld      de, Group
  240.         ld      c, 8
  241.         ld      a, 4
  242.  
  243. ENextByte
  244.         push    af
  245.         ld      b, 8
  246.         ld      a, (de)
  247.  
  248. ENextBit
  249.         call    ShiftL1
  250.         call    ShiftL
  251.         rla     
  252.         jr      nc, EZero
  253.         call    ShiftL
  254.         call    ShiftL
  255. EZero
  256.         djnz    ENextBit
  257.         pop     af
  258.         inc     de
  259.         dec     a
  260.         jr      nz, ENextByte
  261.  
  262.         ld      b, 16
  263. ENStp1
  264.         call    ShiftL1
  265.         djnz    ENStp1
  266.  
  267.         ld      b, 4
  268. ENStp2
  269.         call    ShiftL
  270.         djnz    ENStp2
  271.  
  272.         call    ShiftL1
  273.  
  274.         ld      a, (hl)
  275.         ld      b, c
  276. ShiftRest
  277.         sla     a
  278.         djnz    ShiftRest
  279.         ld      (hl), a
  280.  
  281.         ret
  282.  
  283.  
  284. ShiftL:
  285.         push    af
  286.         ld      a, (hl)
  287.         sla     a
  288. SLCont:
  289.         ld      (hl), a
  290.         dec     c
  291.         jr      nz, EndSL
  292.         inc     hl
  293.         ld      c, 8
  294. EndSL:
  295.         pop     af
  296.         ret
  297.  
  298.  
  299. ShiftL1:
  300.         push    af
  301.         ld      a, (hl)
  302.         scf
  303.         rla
  304.         jr      SLCont
  305.  
  306.  
  307. DispAHex:                       
  308.     push bc
  309.     push de
  310.  
  311.     ld b, a
  312.     and $0f0
  313.     rrca
  314.     rrca
  315.     rrca
  316.     rrca
  317.  
  318.     add a, 30h
  319.     cp $3a
  320.     jr c, hexnumber0
  321.     add a, $7
  322. hexnumber0:
  323.         ROM_CALL(TX_CHARPUT)
  324.  
  325.     ld a, b
  326.     and $0f
  327.  
  328.     add a, 30h
  329.     cp $3a
  330.     jr c, hexnumber1
  331.     add a, $7
  332. hexnumber1:
  333.         ROM_CALL(TX_CHARPUT)
  334.     pop de
  335.     pop bc
  336.     ret
  337.  
  338.  
  339. Group:
  340. Group1:
  341.  .db $42
  342. Group2:
  343.  .db $BF
  344. Command:
  345. Command1:
  346.  .db $20
  347. Command2:
  348.  .db 0
  349.  
  350. Data:
  351.  .db 23, 21, $0F, $13, $FF, $FF, 0       ; Data + Header
  352.  
  353. Text:
  354.  .db "Grp: Left,Right "
  355.  .db "Cmd: Up,Down",0
  356.  .db "Send: Enter",0
  357.  .db "Group   : ",0
  358.  .db "Command : ",0
  359.  
  360.  
  361. .end
  362.