This is what
Thwaite and
Concentration Room use. For 69, it produces $0000 = $06 and A = $09. For 246, it produces $0000 = $24 and A = $06.
Code:
; 8-bit binary to decimal converter
; copyright 2010 Damian Yerrick
; License: WTFPL http://www.wtfpl.net/
.macro bcd8bit_iter value
.local skip
cmp value
bcc skip
sbc value
skip:
rol highDigits
.endmacro
;;
; Converts a decimal number to two or three BCD digits
; in no more than 84 cycles.
; @param A the number to change
; @return A: low digit; $0000: upper digits as nibbles
.proc bcd8bit
highDigits = 0
asl highDigits
asl highDigits
; Each iteration takes 11 if subtraction occurs or 10 if not.
; But if 80 is subtracted, 40 and 20 aren't, and if 200 is
; subtracted, 80 is not, and at least one of 40 and 20 is not.
; So this part takes up to 6*11-2 cycles.
bcd8bit_iter #200
bcd8bit_iter #100
bcd8bit_iter #80
bcd8bit_iter #40
bcd8bit_iter #20
bcd8bit_iter #10
rts
.endproc
And it uses the "base 100" trick because of this lack of cascading.
Code:
;;
; Adds between 1 and 255 points to the score.
; X, Y, and memory (apart from score) are unchanged.
.proc addScore
clc
adc score1s
bcc notOver256
inc score100s
inc score100s
adc #55
notOver256:
cmp #100
bcc notOver100
sbc #100
inc score100s
bcs notOver256
notOver100:
sta score1s
lda bgDirty
ora #BG_DIRTY_STATUS
sta bgDirty
rts
.endproc