6502-OS/util/parity.h65

42 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

2023-12-31 14:56:24 +01:00
.ifndef INCLUDE_PARITY
INCLUDE_PARITY = 1
2024-08-08 21:11:25 +02:00
;;********************************************************************************
;; @file
;; @brief Macros for calculating parity
;; @ingroup libs
;;********************************************************************************
2023-12-31 14:56:24 +01:00
.import count_set_bits
;;********************************************************************************
;; @macro Calculate even parity
2024-08-08 20:39:25 +02:00
;; @modifies A, X, Y
2023-12-31 14:56:24 +01:00
;; @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.
;;
2024-08-08 20:39:25 +02:00
;; @modifies A, X, Y
2023-12-31 14:56:24 +01:00
;; @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