
 1000  *SAVE S.CRC BAD BIT FINDER
 1010  *--------------------------------
 1020  BUFFER .EQ $4000
 1030  LIMIT  .EQ $4102
 1040  *--------------------------------
 1050  CRC    .EQ $00,01
 1060  PNTR   .EQ $02,03
 1070  TPTR   .EQ $04,05
 1080  TMASK  .EQ $06
 1090  SPTR   .EQ $07,08
 1100  SMASK  .EQ $09
 1110  *--------------------------------
 1120  PRNTAX .EQ $F941
 1130  CROUT  .EQ $FD8E
 1140  PRBYTE .EQ $FDDA
 1150  COUT   .EQ $FDED
 1160  *--------------------------------
 3060  *--------------------------------
 3070  *   FIND WHICH BIT IS BAD IN BUFFER+CRC
 3080  *
 3090  *      RESULT IS BIT POSITION IN MESSAGE,
 3100  *      WHERE THE FIRST BIT OF THE MESSAGE IS BIT 0
 3110  *      AND (IN THIS CASE) THE LAST CRC BIT IS BIT $80F.
 3120  *
 3130  *      ALGORITHM BY BRUCE LOVE, AUSTRIALIA.
 3140  *--------------------------------
 3150  BIT.NUMBER .EQ $10,11
 3160  DUMMY.CRC  .EQ $12,13
 3170  *--------------------------------
 3180  FIND.BAD.BIT
 3190         LDA #$80F    TOTAL # BITS - 1
 3200         STA BIT.NUMBER    (WE WILL COUNT BACKWARDS)
 3210         LDA /$80F
 3220         STA BIT.NUMBER+1
 3230         LDA #$0001   STARTING POINT FOR BIT FINDER
 3240         STA DUMMY.CRC
 3250         LDA /$0001
 3260         STA DUMMY.CRC+1
 3270  .1     LDA CRC      COMPARE RECEIVED CRC WITH
 3280         CMP DUMMY.CRC        PROCESSED VALUE;
 3290         BNE .2       IF THEY MATCH, WE HAVE FOUND THE
 3300         LDA CRC+1    BAD BIT.
 3310         CMP DUMMY.CRC+1
 3320         BEQ .4       ...FOUND BAD BIT!
 3330  .2     LDA BIT.NUMBER        DECREMENT BIT COUNTER
 3340         BNE .3
 3350         DEC BIT.NUMBER+1
 3360         BMI .5       WENT TOO FAR
 3370  .3     DEC BIT.NUMBER
 3380         ASL DUMMY.CRC
 3390         ROL DUMMY.CRC+1
 3400         BCC .1
 3410         LDA DUMMY.CRC
 3420         EOR #$21
 3430         STA DUMMY.CRC
 3440         LDA DUMMY.CRC+1
 3450         EOR #$10
 3460         STA DUMMY.CRC+1
 3470         JMP .1
 3480  .4     LDA BIT.NUMBER+1  PRINT THE BIT NUMBER
 3490         JSR PRBYTE        (IF $8000, THE ERROR WAS
 3500         LDA BIT.NUMBER    NOT A SINGLE BIT)
 3510         JSR PRBYTE
 3520         JMP CROUT
 3530  .5     BRK
 3540  *--------------------------------

