.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 subroutineName: GetCarInSegment [Show more] Type: Subroutine Category: Car geometry Summary: Calculate the player car's position within the current segmentContext: 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)
[X]
Subroutine Multiply8x8 (category: Maths (Arithmetic))
Calculate (A T) = T * U
[X]
Subroutine ScaleCarInSegment (category: Car geometry)
Work out how far a car is within a segment by scaling the angle in which the car is pointing
[X]
Variable edgeDistanceLo in workspace Zero page
Low byte of the distance between the player's car and the nearest track edge