Skip to navigation

Aviator on the BBC Micro

Utility routines: NextRandomNumber

Name: NextRandomNumber [Show more] Type: Subroutine Category: Utility routines Summary: Point to the next item in the randomNumbers list Deep dive: Random numbers
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyFlightModel (Part 3 of 7) calls NextRandomNumber * ExplodeAlien calls NextRandomNumber

The pointer for the randomNumbers list is stored in the first location. Each call to this routine increments the pointer through 0 to 10, after which it wraps back round to 0. Returns: A Points to the next number in the randomNumbers list
.NextRandomNumber LDA randomNumbers \ Set A = randomNumbers + 1 CLC \ ADC #1 \ so A points to the next item in the randomNumbers list CMP #11 \ If A < 11, skip the following instruction as the BCC rand1 \ pointer hasn't yet reached the end of the list LDA #0 \ A >= 11, which is past the end of the list, so set \ A = 0 to set the pointer back at the start of the list .rand1 STA randomNumbers \ Store the updated pointer in randomNumbers RTS \ Return from the subroutine