Skip to navigation

Revs on the BBC Micro

Car geometry: GetCarInSegment

Name: GetCarInSegment [Show more] Type: Subroutine Category: Car geometry Summary: Calculate the player car's position within the current segment
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MovePlayerOnTrack calls GetCarInSegment

This routine scales the value in A as follows: edgeDistanceLo * (A' / 256) * (Y / 256) where A' is A, scaled by the ScaleCarInSegment routine as follows: When Calculate Range of result A < 26 A' = 3 * A 0 to 78 26 <= A < 46 A' = 4 * A + 52 156 to 232 A >= 46 A' = A + 190 236 to 253
Arguments: A The number to be scaled Y Called with Y = 136 or 186
Returns: A edgeDistanceLo * A+ * (Y / 256)
.GetCarInSegment JSR ScaleCarInSegment \ Set U = A, scaled up by ScaleCarInSegment (let's call STA U \ it A') TYA \ Set (A T) = A * U JSR Multiply8x8 \ = Y * A' STA U \ Set (U T) = (A T) \ = Y * A' LDA edgeDistanceLo \ Set (A T) = A * U JSR Multiply8x8 \ = edgeDistanceLo * U \ = edgeDistanceLo * (Y * A' / 256) \ = edgeDistanceLo * A' * (Y / 256) \ \ So A = (A T) / 256 \ = edgeDistanceLo * (A' / 256) * (Y / 256) RTS \ Return from the subroutine