6502-OS/util/parity.h65

42 lines
1.2 KiB
Plaintext

.ifndef INCLUDE_PARITY
INCLUDE_PARITY = 1
;;********************************************************************************
;; @file
;; @brief Macros for calculating parity
;; @ingroup libs
;;********************************************************************************
.import count_set_bits
;;********************************************************************************
;; @macro Calculate even parity
;; @modifies A, X, Y
;; @returns A: 0 - even number of set bits, 1 - uneven number of set bits
;; @returns Y: The number of set bits in the byte
;;********************************************************************************
.macro CalculateEvenParity
jsr count_set_bits
tya
and #1
.endmacro
;;********************************************************************************
;; @macro Calculate odd parity
;; @details
;; Count the number of set bits in Y.
;;
;; @modifies A, X, Y
;; @returns A: 1 - even number of set bits, 0 - uneven number of set bits
;; @returns Y: The number of set bits in the byte
;;********************************************************************************
.macro CalculateOddParity
jsr count_set_bits
tya
and #1
eor #1
.endmacro
.endif ; guard