
ENC_FILT0:
   Ds    1      ; filter stage 1
ENC_FILT1:
   DS    1      ; filter stage 2
ENC_FILT2:
   DS    1      ; filter stage 3
ENC_CURR:
   DS    1      ; current filtered encoder inputs
ENC_PREV:
   DS    1      ; previous filtered encoder inputs
   ...
   ...
   MOV   ENC_FILT2, ENC_FILT1  ; shift the filter
   MOV   ENC_FILT1, ENC_FILT0
   MOV   ENC_FILT0, P3         ; get encoder bits
;
   MOV   ENC_PREV, ENC_CURR    ; place current to prev
;
   MOV   A, ENC_FILT0          ; find stable bits
   XRL   A, ENC_FILT2
   MOV   B, A
   MOV   A, ENC_FILT1
   XRL   A, ENC_FILT2
   ORL   A, B                  ; 1's for unstable bits
   ANL   ENC_CURR, A           ; keep old if changing
   CPL   A                     ; 1's for new stable
   ANL   A, ENC_FILT0          ; get new stable bits
   ORL   ENC_CURR, A           ; produce full current
