
 1000  *--------------------------------
 1010  *      DEMONSTRATE PARITY SUBROUTINE
 1020  *--------------------------------
 1030  PRHEX  .EQ $FDDA
 1040  COUT   .EQ $FDED
 1050  DEMO   LDA #0       FOR CHAR = $00 TO $7F
 1060         STA CHAR
 1070  .1     LDA CHAR
 1080         JSR PARITY   MERGE WITH PARITY BIT
 1090         JSR PRHEX    PRINT AS TWO HEX DIGITS
 1100         LDA #$A0     SPACE
 1110         JSR COUT     SEPARATE WITH TWO SPACES
 1120         JSR COUT
 1130         INC CHAR     NEXT CHAR
 1140         BPL .1
 1150         RTS          RETURN
 1160  *--------------------------------
 1170  CHAR   .BS 1
 1180  *--------------------------------
 1190  *      COMPUTE PARITY BIT AND MERGE WITH CHAR
 1200  *      CALL:  (A) = 7-BIT CHARACTER, HIGH BIT IGNORED
 1210  *    RETURN:  (A) = SAME CHARACTER, WITH PARITY IN HIGH BIT
 1220  *--------------------------------
 1230  PARITY LDX #1       OR #0 FOR EVEN PARITY
 1240         ASL          SHIFT PARITY POSITION OUT
 1250         PHA          SAVE SHIFTED CHAR
 1260  .1     BPL .2       IF NEXT BIT = 0
 1270         INX          IF NEXT BIT = 1, COUNT IT
 1280  .2     ASL          SHIFT IN NEXT BIT
 1290         BNE .1       IF ANY REMAINING BITS = 1
 1300         TXA          GET 1-BIT COUNT
 1310         LSR          PUT PARITY BIT INTO CARRY
 1320         PLA          ORIGINAL CHAR BUT SHIFTED
 1330         ROR          MERGE PARITY BIT
 1340         RTS

