Skip to content

Commit e6e5236

Browse files
authored
fix: use swap in stead of 4 rotations (#123)
1 parent 91e491e commit e6e5236

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/part2/bcd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ First we load the score (stored in the wScore memory location) into register A.
9797

9898
The `and %11110000` operation masks the lower nibble (the ones digit) so that only the upper nibble (the tens digit) remains in `A`.
9999

100-
The `rrca` instructions perform a rotate right operation on `A` four times. This effectively shifts the tens digit to the lower nibble, making it ready to map to a digit tile.
100+
The `swap a` instruction swaps the upper nibble with the lower four bits, leaving the tens digit ready for us to display.
101101

102102
We then add the `DIGIT_OFFSET` constant to the tens digit to calculate the tile address for the digit. This address is stored in the `SCORE_TENS` VRAM location, which updates the display to show the tens digit.
103103

unbricked/bcd/main.asm

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,7 @@ IncreaseScorePackedBCD:
309309
UpdateScoreBoard:
310310
ld a, [wScore] ; Get the Packed score
311311
and %11110000 ; Mask the lower nibble
312-
rrca ; Move the upper nibble to the lower nibble (divide by 16)
313-
rrca
314-
rrca
315-
rrca
312+
swap a ; Move the upper nibble to the lower nibble (divide by 16)
316313
add a, DIGIT_OFFSET ; Offset + add to get the digit tile
317314
ld [SCORE_TENS], a ; Show the digit on screen
318315

0 commit comments

Comments
 (0)