.SetPlayerPositions LDA currentPlayer \ Set A to the number of the current player LDX #19 \ We are about to work our way through the ordered list \ of drivers in driversInOrder, so set a loop counter \ in X, starting at the end of the list (i.e. last \ place) .ppos1 CMP driversInOrder,X \ If the driver in position X in the list matches the BEQ ppos2 \ current player, jump to ppos2 DEX \ Decrement the driver number BPL ppos1 \ Loop back until we have gone through the whole table .ppos2 \ By this point, X contains the position within the \ driversInOrder list of the current player (or -1 if \ the current player doesn't appear in the list) STX currentPosition \ Store the current player's position in currentPosition JSR GetPositionBehind \ Set X to the number of the position behind this one STX positionBehind \ Store the position behind the current player in \ positionBehind LDX currentPosition \ Set X to the number of the position ahead of the JSR GetPositionAhead \ current player's position STX positionAhead \ Store the position ahead of the current player in \ positionAhead RTS \ Return from the subroutineName: SetPlayerPositions [Show more] Type: Subroutine Category: Drivers Summary: Set the current player's position, plus the positions behind and in frontContext: See this subroutine in context in the source code References: This subroutine is called as follows: * FinishRace calls SetPlayerPositions * MoveAndDrawCars calls SetPlayerPositions * ResetVariables calls SetPlayerPositions * SortDrivers calls SetPlayerPositions
[X]
Subroutine GetPositionAhead (category: Drivers)
Decrement X to the previous position number (from 19 to 0 and round again), which gives the position ahead of X
[X]
Subroutine GetPositionBehind (category: Drivers)
Increment X to the next position number (from 0 to 19 and round again), which gives the position behind X
[X]
Variable currentPlayer in workspace Zero page
The number of the current player
[X]
Variable currentPosition in workspace Zero page
The position of the current player
[X]
Variable driversInOrder in workspace Stack variables
A list of driver numbers in order
[X]
Variable positionAhead in workspace Zero page
The number of the position ahead of the current player's position
[X]
Variable positionBehind in workspace Zero page
The number of the position behind the current player's position
[X]
Label ppos1 is local to this routine
[X]
Label ppos2 is local to this routine