Prev: 9D17 Up: Map Next: 9D51
9D2E: Calculate overtake bonus
The bonus is 200 for each overtaken car and is reset on crashes.
One iteration runs per pending overtake. Each advances the BCD accumulator by 2, up to a limit of $80, and passes it to add_bonus as the middle digit pair, so the bonus awarded is the accumulator times 100: $02 gives 200, $04 gives 400 and so on. The counter is cleared once they have all been paid.
Used by the routine at main_loop.
calc_overtake_bonus 9D2E LD A,($A22B) If overtake_bonus_counter is zero then return
9D31 AND A
9D32 RET Z
9D33 LD B,A Set iterations to no. of overtakes
9D34 LD HL,$A13C Point HL at overtake_bonus_bcd
Increment bonus by 2 up to a max of 128.
cob_loop 9D37 LD A,(HL) Increment overtake_bonus_bcd by 2
9D38 ADD A,$02
9D3A DAA Perform BCD correction
9D3B CP $80 If A >= 128 then A = 128 (80 in BCD)
9D3D JR C,cob_store_bcd
9D3F LD A,$80
cob_store_bcd 9D41 LD (HL),A Store new overtake_bonus_bcd
9D42 EXX Bank
Set bonus to N * 100.
9D43 LD E,A Set middle digits, in effect multiplying the bonus by 100
9D44 XOR A Clear low digit
9D45 LD D,A Clear top two digits
9D46 CALL add_bonus Call add_bonus
9D49 EXX Unbank
9D4A DJNZ cob_loop Loop while B > 0
9D4C XOR A Clear overtake_bonus_counter
9D4D LD ($A22B),A
9D50 RET Return
Prev: 9D17 Up: Map Next: 9D51