; ; A sample program for using the IR Link as a Learning Remote Control. ; by Sami Khawam (sKhawam@bigfoot.com) ; http://unet.univie.ac.at/~a9501901 ; ; The programm is very simple to use. There are only 4 keys fonctions ; each one represented by an arrow key. To make the program record data ; from an remote control, press 2nd and choose the key and then the time ; base and the frequency. If you don't know thoses value you should ; experiment by using differents ones. ; DO NOT specifie frequencies that are less than 30 KHz or more than ; 48 KHz! ; ; This programm needs the STANDART version of the IR Link. ; ; The PutByte was taken (and modified) from a disassembly of the ROM. ; GetByte is from Randy Gluvna (gluvna@home.com). Thanks. ; Thanks for Andreas Ess for his function pack for usgard. ; #include usgard.h .org 0 PName: .db "IR Remote " PName2: .db "by Sami Khawam",0 PORT = 7 Start: LD A, $C0 ; Set W1 and R1 OUT (7),A call CLEARLCD set 3,(IY+05) ld hl, &PName2 ld de,$0300 ld ($800C),de call D_ZT_STR res 3,(IY+05) ld hl, &Text1 ld de,$0003 ld ($800C),de call D_ZT_STR ProgLoop: call GET_KEY or a jr z, ProgLoop cp K_EXIT ret z cp K_SECOND jr z, RecordRemote dec a ; Only less than 3 cp 4 jr nc, ProgLoop call BUSY_ON ld l, a ; Get Offset ld h, 32 call MUL_HL ld de, &CK_1 add hl, de ; Now Send data ld a, 30 ; Always 30 bytes. call &PutByte ; Send the Byte call &SendHeader ld b, 30 NextByte: ld a, (hl) call &PutByte ; Now we send all bytes. inc hl djnz NextByte call BUSY_OFF jr Start RecordRemote call CLEARLCD ld hl, &Text2 ld de,$0001 ld ($800C),de call D_ZT_STR WaitKey: call GET_KEY or a jr z, WaitKey cp K_EXIT jr z, Start dec a ; Only less than 3 cp 4 jr nc, WaitKey ld l, a ; Get Offset ld h, 32 call MUL_HL ld de, &CK_1 add hl, de push hl ld hl, &Text_TimeBase ld de,$0002 ld ($800C),de call D_ZT_STR pop hl call &InputValue inc hl push hl ld hl, &Text_Wait1 ld de,$0003 ld ($800C),de call D_ZT_STR pop hl call &InputValue ld a, $5E ; $5E = 30d & $40, because we have 30 bytes call &PutByte dec hl call &SendHeader push hl call CLEARLCD ld hl, &Text_Wait3 ld de,$0103 ld ($800C),de call D_ZT_STR call BUSY_ON WaitSig: in a,(7) and 3 cp 3 jr nz, DataComing call GET_KEY cp K_EXIT jr z, Quit jr WaitSig DataComing: pop hl ld b, 30 GNextByte: push bc call &GetByte ld (hl), a inc hl push hl #fncall D_A_HEX pop hl pop bc djnz GNextByte call BUSY_OFF call OTH_PAUSE jp &Start Quit: pop hl jp &Start InputValue IVLoop ld de, ($800C) set 3,(IY+05) ld a, (hl) #fncall D_A_DEC res 3,(IY+05) ld ($800C),de push hl call GET_KEY pop hl or a jr z, IVLoop cp K_ENTER ret z cp K_UP jr z, Increment cp K_DOWN jr z, Decrement Increment ld a, (hl) inc a ld (hl), a jr IVLoop Decrement ld a, (hl) dec a ld (hl), a jr IVLoop SendHeader ld a, (hl) call &PutByte inc hl ld a, (hl) sub 30 rr a inc hl push hl ld l, a ; Get Offset ld h, 2 call MUL_HL ld de, &DelayTab add hl, de ld a, (hl) call &PutByte inc hl ld a, (hl) call &PutByte pop hl ret ; Thanks for Randy Gluvna (gluvna@home.com) for this recieve routine. GetByte: push bc LD B,008H R0: LD DE,0FFFFH JR R2 R1: IN A,(PORT) AND 003H jr z, GB_End CP 003H JR NZ,R3 IN A,(PORT) AND 003H jr z, GB_End CP 003H JR NZ,R3 R2: DEC DE LD A,D OR E JR NZ,R1 jr GB_End R3: SUB 002H JR NC,R8 LD A,0D4H OUT (PORT),A RR C LD DE,0FFFFH R4: IN A,(PORT) AND 003H CP 002H JR Z,R5 DEC DE LD A,D OR E JR NZ,R4 jr GB_End R5: LD A,0C0H OUT (PORT),A LD D,004H R6: DEC D JR Z,R7 IN A,(PORT) AND 003H CP 003H JR NZ,R6 R7: DJNZ R0 LD A,C jr GB_End R8: LD A,0E8H OUT (PORT),A RR C LD DE,0FFFFH R9: IN A,(PORT) AND 003H CP 001H JR Z,R5 DEC DE LD A,D OR E JR NZ,R9 GB_End pop bc ret PutByte: push bc LD C,A LD B,8 ; 8 Bits PB_Next_Bit: ; ld d, B ; Only to see if it is working. ; ld e, $01 ; ; ld ($800C),de ; ; ld A, B ; ; call TX_CHARPUT ; LD A, $C0 ; Set W1 and R1 OUT (7),A Cont: RR C JR NC, PB_SendZero PB_SendOne: LD A, $E8 JR PB_Output_val PB_SendZero: LD A, $D4 PB_Output_val: OUT (7),A LD DE, $FFFF ; For time-out PB_Wait_for_W0_and_R0: IN A,(7) AND 3 JR Z, PB_Continue IN A,(7) AND 3 JR Z, PB_Continue DEC DE LD A,D OR E JR NZ, PB_Wait_for_W0_and_R0 JR PB_End ; If error return. PB_Continue: LD A, $C0 ; Set W1 and R1 OUT (7),A LD DE, $FFFF ; Reload time-out PB_Wait_for_W1_and_R1: DEC DE LD A,D OR E JR Z, PB_End IN A,(7) AND 3 CP 3 JR NZ, PB_Wait_for_W1_and_R1 DJNZ PB_Next_Bit PB_End: POP BC RET ;K_DOWN =$01 ;Down ;K_LEFT =$02 ;Left ;K_RIGHT =$03 ;Right ;K_UP =$04 ;Up CK_1: .db 10, 32 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 11, 34 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 12, 36 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 13, 38 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 DelayTab: .db $0B, $0F .db $0C, $10 .db $0D, $11 .db $0E, $12 .db $0F, $12 .db $0F, $13 .db $10, $14 .db $11, $14 .db $11, $15 .db $12, $15 Text1: .db "2nd to record.", 0 Text2: .db "Key to assign:", 0 Text_TimeBase: .db "Time base: ", 0 Text_Wait1: .db "Frequency: ", 0 Text_Wait3: .db "Getting " Text_Data: .db "Data", $CE, 0 .end