Prev: 9CC2 Up: Map Next: 9D17
9CD6: Add a bonus
The bonus value is passed as five BCD digits in DE and A like: 0bDDDDddddEEEEeeeeAAAAxxxxx, where x is not used.
The bonus value must have a single sequence of zeroes, e.g. "55000" is okay, but "50500" is not.
Used by the routines at calc_overtake_bonus, smash_handler and main_loop_12.
Input
A Low nibble of bonus
DE High four nibbles of bonus
bonus 9CD6 LD B,A Preserve A
9CD7 LD HL,$9D57 -> Byte after bonus digits buffer
9CDA LD C,$FF Flag, set to $FF while digits are zero
9CDC LD A,B Needless move
9CDD CALL bonus_digit Call bonus_digit -- final digit first
9CE0 SET 7,(HL) Top-bit terminate the bonus string
9CE2 LD A,B Load lowest digit
9CE3 CALL bonus_high_nibble Call bonus_high_nibble
9CE6 LD A,E Load middle digits
9CE7 CALL bonus_digit Call bonus_digit
9CEA LD A,E Load middle digits
9CEB CALL bonus_high_nibble Call bonus_high_nibble
9CEE LD A,D Load high digits
9CEF CALL bonus_digit Call bonus_digit
9CF2 LD A,D Load high digits
9CF3 CALL bonus_high_nibble Call bonus_high_nibble
9CF6 JR bonus_exit Exit via bonus_exit
bonus_high_nibble 9CF8 RRA Shift the high digit down
9CF9 RRA
9CFA RRA
9CFB RRA
bonus_digit 9CFC AND $0F Mask off low nibble
9CFE JR NZ,bonus_non_zero If A is not zero goto bonus_non_zero
Digit is zero.
9D00 RLC C Jump if the flag in C is set
9D02 JR C,bonus_store
We saw a non-zero-to-zero transition, so terminate.
9D04 POP AF Discard return address
9D05 JR bonus_exit Exit via bonus_exit
bonus_non_zero 9D07 LD C,$00 Set flag to zero now we've seen a non-zero digit
bonus_store 9D09 ADD A,$30 Turn digit to ASCII
9D0B DEC HL Write digit out in reverse
9D0C LD (HL),A
9D0D RET Return
bonus_exit 9D0E LD ($9D9C),HL Self modify 'LD HL,xxxx' @ 9D9B -- bonus score pointer
9D11 LD A,$01 Set the trigger_bonus_flag
9D13 LD ($A22C),A
9D16 LD A,B A = B, then fall into increment_score with the bonus preserved
Prev: 9CC2 Up: Map Next: 9D17