Skip to navigation

Revs on the BBC Micro

Tactics: GetSectionSteering

Name: GetSectionSteering [Show more] Type: Subroutine Category: Tactics Summary: Calculate the optimum steering for each track section Deep dive: Tactics of the non-player drivers
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * InitialiseDrivers calls GetSectionSteering * MainLoop (Part 2 of 6) calls GetSectionSteering * MainLoop (Part 5 of 6) calls GetSectionSteering

Arguments: X The class of race: * 0 = Novice * 1 = Amateur * 2 = Professional
Returns: X X is unchanged
.GetSectionSteering LDA trackBaseSpeed,X \ Set baseSpeed = the X-th byte of trackBaseSpeed STA baseSpeed \ \ so baseSpeed contains the base speed for cars at the \ chosen class or race, on this track \ \ For Silverstone, this is: \ \ * 134 for Novice \ * 146 for Amateur \ * 152 for Professional STA U \ Set U = baseSpeed LDA trackSectionCount \ Set Y = trackSectionCount >> 3 LSR A \ LSR A \ so Y contains the number of sections in this track LSR A TAY \ Now we copy Y bytes (one per track section) from \ trackSteering to sectionSteering, processing each \ byte as we go (i.e. taking the input from \ trackSteering and storing the result in \ sectionSteering): \ \ * Bit 7 of the result = bit 0 of the input \ \ * Bit 6 of the result = 0 \ \ * Bits 0-5 of the result are: \ \ * A >> 2 * U / 256 if bit 1 of the input is clear \ * A >> 2 if bit 1 of the input is set \ \ where A is the input from trackSteering and U is the \ base speed from above .slin1 LDA trackSteering,Y \ Fetch the Y-th byte from trackSteering as the input LSR A \ Shift bit 0 of the input into the C flag and store it PHP \ on the stack so we can put it into bit 7 of the result LSR A \ Shift bit 1 of the input into the C flag BCS slin2 \ If bit 1 of the input is set, skip the following \ instruction JSR Multiply8x8 \ Bit 1 of the input is clear, so set (A T) = A * U \ \ i.e. A = A * U / 256 .slin2 ASL A \ Set bit 7 of the result to bit 0 of the input PLP ROR A STA sectionSteering,Y \ Store the result in the Y-th byte of sectionSteering DEY \ Decrement the loop counter BPL slin1 \ Loop back until we have processed all Y bytes RTS \ Return from the subroutine