Skip to navigation

Aviator on the BBC Micro

Scoring: UpdateScore

Name: UpdateScore [Show more] Type: Subroutine Category: Scoring Summary: Increase the score by a specified number of points
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ScoreHitPoints calls UpdateScore * ScorePoints calls UpdateScore

Arguments: (X A) The number of points to add to the score (in BCD)
.UpdateScore SED \ The scores are stored in BCD format, so first of all \ we set the D flag to switch arithmetic to decimal CLC \ We now want to add (X A) points to the score in ADC scoreLo \ (scoreHi scoreLo), so we start by adding the low bytes STA scoreLo \ and store the result in scoreLo TXA \ And then we add the high bytes and store the result ADC scoreHi \ in scoreHi STA scoreHi BCS scor1 \ If the addition overflowed (so the high byte is \ greater than &99), jump to scor1 to return from the \ subroutine CPX #&99 \ If X is not &99, jump to scor1 to return from the BNE scor1 \ subroutine (in practice, this routine is only ever \ called with X = 0, so we should never get here) LDA #0 \ If we get here then X = &99 and the addition of the STA scoreLo \ high bytes overflowed, so reset the score to zero STA scoreHi .scor1 CLD \ Clear the D flag to switch arithmetic back to normal RTS \ Return from the subroutine