add parity
This commit is contained in:
parent
b60ff7be12
commit
7f909b4f75
35
util/parity.h65
Normal file
35
util/parity.h65
Normal 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
23
util/parity.s65
Normal 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
|
Loading…
Reference in New Issue
Block a user