From 7f909b4f75dbc8b6affe0af9c6e0be096447000f Mon Sep 17 00:00:00 2001 From: "Matthias@Dell" Date: Sun, 31 Dec 2023 14:56:24 +0100 Subject: [PATCH] add parity --- util/parity.h65 | 35 +++++++++++++++++++++++++++++++++++ util/parity.s65 | 23 +++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 util/parity.h65 create mode 100644 util/parity.s65 diff --git a/util/parity.h65 b/util/parity.h65 new file mode 100644 index 0000000..3b78ad3 --- /dev/null +++ b/util/parity.h65 @@ -0,0 +1,35 @@ +.ifndef INCLUDE_PARITY +INCLUDE_PARITY = 1 + +.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 diff --git a/util/parity.s65 b/util/parity.s65 new file mode 100644 index 0000000..3ef087c --- /dev/null +++ b/util/parity.s65 @@ -0,0 +1,23 @@ +.export count_set_bits +;;******************************************************************************** +;; @function Initialize the PS2 keyboard +;; @details +;; Count the number of set bits in Y. +;; +;; @modifies: A, X, Y +;; @returns Y: The number of set bits in the byte +;;******************************************************************************** +.proc count_set_bits + ldx #8 + ldy #0 ; number of set bits +@loop: + dex + beq @done + ror + bcc @loop +@set: + iny + bra @loop +@done: + rts +.endproc