Skip to navigation

Revs on the BBC Micro

Car geometry: ScaleCarInSegment

Name: ScaleCarInSegment [Show more] Type: Subroutine Category: Car geometry Summary: Work out how far a car is within a segment by scaling the angle in which the car is pointing
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * GetCarInSegment calls ScaleCarInSegment

This routine takes a car's heading within a segment, as follows: 0 | 26 | / | / _- 46 |/_-´ +--------- 64 and scales it like this: 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 A is in the range 0 to 63
Returns: A The scaled value of A, shown as A' above
.ScaleCarInSegment CMP #26 \ If A < 26, jump to scar2 BCC scar2 CMP #46 \ If A < 46, jump to scar1 BCC scar1 \ If we get here then A >= 46 CLC \ Set A = A + 190 ADC #190 RTS \ Return from the subroutine .scar1 \ If we get here then 26 <= A < 46 ASL A \ Set A = A << 2 + 52 ASL A \ = 4 * A + 52 CLC ADC #52 RTS \ Return from the subroutine .scar2 \ If we get here then A < 26 STA T \ Set T = A ASL A \ Set A = A << 1 + T CLC \ = A * 2 + A ADC T \ = 3 * A ASL A RTS \ Return from the subroutine