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

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