I used BBR0-3 in my university project.
Basically, I had the input buttons wired up to a shift register which was fed in and then run through a debounce routine. It'd end up with a byte in Page0 with a bit set to '1' for each button that had been newly pressed. Used BBRx to branch over the processing code for each button if they were not pressed.
Could I have done it another way? absolutely, but as I had control over where this byte value was to be located, it was convenient to use BBR. Also a design goal of the project was to exercise as much of the instruction set as possible, so this helped achieve that, too.
relevant code snippet...Code:
; User input has changed
AND <ButtonNew ; Now A contains '1' for Positive Edge Button events only.
STA <ButtonOld ; ButtonOld is out of date anyway, so re-use it to store above value.
; Take Heap 1
BBR0 <ButtonOld, ?SkipTakeHeap1 ; If bit 0 clear, user has not pressed Take on Heap 1
LDA <HeapSelect ; If HeapSelect = 2 or 3, don't decrement.
CMP #2
BEQ ?SkipTakeHeap1
CMP #3
BEQ ?SkipTakeHeap1
LDA <Heap1 ; Don't decrement or record selection if Heap 1 isn't zero.
BEQ ?SkipTakeHeap1
LDA #1 ; Record that player has selected heap 1
STA <HeapSelect
DEC <Heap1 ; Decrement Heap.
?SkipTakeHeap1:
; Take Heap 2
BBR1 <ButtonOld, ?SkipTakeHeap2 ; If bit 1 clear, user has not pressed Take on Heap 2
LDA <HeapSelect ; If HeapSelect = 1 or 3, don't decrement.
CMP #1
BEQ ?SkipTakeHeap2
CMP #3
BEQ ?SkipTakeHeap2
LDA <Heap2 ; Don't decrement or record selection if Heap 2 isn't zero.
BEQ ?SkipTakeHeap2
LDA #2 ; Record that player has selected heap 2
STA <HeapSelect
DEC <Heap2 ; Decrement Heap.
?SkipTakeHeap2:
; Take Heap 3
BBR2 <ButtonOld, ?SkipTakeHeap3 ; If bit 2 clear, user has not pressed Take on Heap 3
LDA <HeapSelect ; If HeapSelect = 1 or 2, don't decrement.
CMP #1
BEQ ?SkipTakeHeap3
CMP #2
BEQ ?SkipTakeHeap3
LDA <Heap3 ; Don't decrement or record selection if Heap 3 isn't zero.
BEQ ?SkipTakeHeap3
LDA #3 ; Record that player has selected heap 3
STA <HeapSelect
DEC <Heap3 ; Decrement Heap.
?SkipTakeHeap3:
; Done Button
BBR3 <ButtonOld, ?SkipDone ; If bit 3 clear, user has not pressed Done
LDA <HeapSelect ; Check if player has done at least one by checking HeapSelect.
BEQ ?SkipDone ; If HeapSelect=0, cannot go to next player's turn.
JSR CheckVictory ; Check if the player has won. If they have, CheckVictory does not return.
LDA <Turn
BEQ ?TurnIsGreen ; If Z=1 then Turn=0, hence Green.
LDA #$FF ; If turn was 1 (red), overwrite A with FF so that INC A gives 0 (green).
?TurnIsGreen:
INC A ; If TurnIsGreen, A now=1 hence RED. If not, A now=0, hence GREEN.
STA <Turn
STZ <HeapSelect ; Clear HeapSelect
?SkipDone:
Also, on the WDC Microcontroller W65C134 these instructions are extremely useful as all the built-in I/O registers are mapped to Zero Page. I haven't actually written any software yet (still doing the hardware design), but I very much intend to make liberal use of these instructions on my current project that is designed around the '134.
_________________
Want to design a PCB for your project? I strongly recommend
KiCad. Its free, its multiplatform, and its easy to learn!
Also, I maintain KiCad libraries of
Retro Computing and
Arduino components you might find useful.