add bit branch/set/reset macros
This commit is contained in:
parent
2a13ce0ca4
commit
b778b4dcd1
117
util/bit_macros.h65
Normal file
117
util/bit_macros.h65
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
;;********************************************************************************
|
||||||
|
;; @macro Use the bbs instruction by providing the bit as a mask
|
||||||
|
;; @details
|
||||||
|
;; This is useful when having a enum with bitmasks, which might change later.
|
||||||
|
;; @param mask: A byte where a single bit is set
|
||||||
|
;; @param addr: The zero page address to test
|
||||||
|
;; @param label: The label to jump to when the bit is set
|
||||||
|
;;********************************************************************************
|
||||||
|
.macro bbs mask,addr,label
|
||||||
|
.if mask = %00000001
|
||||||
|
bbs0 addr,label
|
||||||
|
.elseif mask = %00000010
|
||||||
|
bbs1 addr,label
|
||||||
|
.elseif mask = %00000100
|
||||||
|
bbs2 addr,label
|
||||||
|
.elseif mask = %00001000
|
||||||
|
bbs3 addr,label
|
||||||
|
.elseif mask = %00010000
|
||||||
|
bbs4 addr,label
|
||||||
|
.elseif mask = %00100000
|
||||||
|
bbs5 addr,label
|
||||||
|
.elseif mask = %01000000
|
||||||
|
bbs6 addr,label
|
||||||
|
.elseif mask = %10000000
|
||||||
|
bbs7 addr,label
|
||||||
|
.else
|
||||||
|
.fatal .sprintf("bbs macro got invalid mask: %x", mask)
|
||||||
|
.endif
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
;;********************************************************************************
|
||||||
|
;; @macro Use the bbr instruction by providing the bit as a mask
|
||||||
|
;; @details
|
||||||
|
;; This is useful when having a enum with bitmasks, which might change later.
|
||||||
|
;; @param mask: A byte where a single bit is set
|
||||||
|
;; @param addr: The zero page address to test
|
||||||
|
;; @param label: The label to jump to when the bit is clear
|
||||||
|
;;********************************************************************************
|
||||||
|
.macro bbr mask,addr,label
|
||||||
|
.if mask = %00000001
|
||||||
|
bbr0 addr,label
|
||||||
|
.elseif mask = %00000010
|
||||||
|
bbr1 addr,label
|
||||||
|
.elseif mask = %00000100
|
||||||
|
bbr2 addr,label
|
||||||
|
.elseif mask = %00001000
|
||||||
|
bbr3 addr,label
|
||||||
|
.elseif mask = %00010000
|
||||||
|
bbr4 addr,label
|
||||||
|
.elseif mask = %00100000
|
||||||
|
bbr5 addr,label
|
||||||
|
.elseif mask = %01000000
|
||||||
|
bbr6 addr,label
|
||||||
|
.elseif mask = %10000000
|
||||||
|
bbr7 addr,label
|
||||||
|
.else
|
||||||
|
.fatal .sprintf("bbr macro got invalid mask: 0x%x", mask)
|
||||||
|
.endif
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
;;********************************************************************************
|
||||||
|
;; @macro Use the smb instruction by providing the bit as a mask
|
||||||
|
;; @details
|
||||||
|
;; This is useful when having a enum with bitmasks, which might change later.
|
||||||
|
;; @param mask: A byte where a single bit is set
|
||||||
|
;; @param addr: The zero page address to update
|
||||||
|
;;********************************************************************************
|
||||||
|
.macro smb mask,addr
|
||||||
|
.if mask = %00000001
|
||||||
|
smb0 addr
|
||||||
|
.elseif mask = %00000010
|
||||||
|
smb1 addr
|
||||||
|
.elseif mask = %00000100
|
||||||
|
smb2 addr
|
||||||
|
.elseif mask = %00001000
|
||||||
|
smb3 addr
|
||||||
|
.elseif mask = %00010000
|
||||||
|
smb4 addr
|
||||||
|
.elseif mask = %00100000
|
||||||
|
smb5 addr
|
||||||
|
.elseif mask = %01000000
|
||||||
|
smb6 addr
|
||||||
|
.elseif mask = %10000000
|
||||||
|
smb7 addr
|
||||||
|
.else
|
||||||
|
.fatal .sprintf("smb macro got invalid mask: 0x%x", mask)
|
||||||
|
.endif
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
;;********************************************************************************
|
||||||
|
;; @macro Use the rmb instruction by providing the bit as a mask
|
||||||
|
;; @details
|
||||||
|
;; This is useful when having a enum with bitmasks, which might change later.
|
||||||
|
;; @param mask: A byte where a single bit is set
|
||||||
|
;; @param addr: The zero page address to update
|
||||||
|
;;********************************************************************************
|
||||||
|
.macro rmb mask,addr
|
||||||
|
.if mask = %00000001
|
||||||
|
rmb0 addr
|
||||||
|
.elseif mask = %00000010
|
||||||
|
rmb1 addr
|
||||||
|
.elseif mask = %00000100
|
||||||
|
rmb2 addr
|
||||||
|
.elseif mask = %00001000
|
||||||
|
rmb3 addr
|
||||||
|
.elseif mask = %00010000
|
||||||
|
rmb4 addr
|
||||||
|
.elseif mask = %00100000
|
||||||
|
rmb5 addr
|
||||||
|
.elseif mask = %01000000
|
||||||
|
rmb6 addr
|
||||||
|
.elseif mask = %10000000
|
||||||
|
rmb7 addr
|
||||||
|
.else
|
||||||
|
.fatal .sprintf("rmb macro got invalid mask: 0x%x", mask)
|
||||||
|
.endif
|
||||||
|
.endmacro
|
Loading…
Reference in New Issue
Block a user