add parity

This commit is contained in:
Matthias@Dell 2023-12-31 14:56:24 +01:00
parent b60ff7be12
commit 7f909b4f75
2 changed files with 58 additions and 0 deletions

35
util/parity.h65 Normal file
View File

@ -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

23
util/parity.s65 Normal file
View File

@ -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