; Use Capture_IR to wait and then get an IR code, it will store it to (HL). ; If you want to compare two codes to check for a certain button, use Code_Compare. Code_Compare: ;Compares IR codes at (HL) and (DE). Returns Z for a match, otherwise NZ. ld a,(de) cp (hl) ret nz ;If they are not the same code length forget it ld b,a ;B is how many codes to check Code_Compare_Loop: ;Now we must check the codes ld c,(hl) ld a,(de) cp c jr nc,Code_Compare_NoSwitchNeeded ;This is if C > A. ld ixh,a ld a,c ld c,ixh ;Swap A and C Code_Compare_NoSwitchNeeded: ;A >= C now sub c cp 3 jr c,Code_Compare_Pulse_Match or a ;set NZ ret Code_Compare_Pulse_Match: inc hl inc de djnz Code_Compare_Loop xor a ;set z ret Capture_IR: ;This routine will store the codes received from an IR source, at HL. ;The byte at the initial (HL) is the number of flip-flops the IR makes... ;in other words, a logic level change push hl ld e,0 ;0 so far inc hl Capture_IR_GetFirstPulse: in a,(0) and 1 jr nz,Capture_IR_GetFirstPulse ld b,0 ;B stores the prior link state, we want it to register as Capture_IR_Loop: ;Now we must set up the timing ld a,44h ;32.768 kHz out (30h),a ld a,1 out (31h),a ld a,0A0h out (32h),a Capture_IR_PulseLoop: in a,(31h) bit 2,a jr nz,Capture_IR_Done in a,(0) and 1 cp b jr z,Capture_IR_PulseLoop ;We have a change in the logic level ld b,a ;Store the new change in a,(32h) ;Get the count ld (hl),a inc hl inc e jr Capture_IR_Loop Capture_IR_Done: pop hl ld (hl),e ;Store number of transitions Capture_IR_EndStart: ;Now pause to make sure the code is not repeating ld a,41h out (30h),a ld a,1 out (31h),a ld a,070h out (32h),a Capture_IR_EndLoop: in a,(31h) bit 2,a ret nz ;all done in a,(0) and 1 cp b ld b,a jr nz,Capture_IR_EndStart jr Capture_IR_EndLoop