Skip to navigation


Track geometry: UpdateVectorNumber

Name: UpdateVectorNumber [Show more] Type: Subroutine Category: Track geometry Summary: Move to the next segment vector along the track in the direction we are facing Deep dive: Building a 3D track from sections and segments
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * GetFirstSegment calls UpdateVectorNumber

Returns: thisVectorNumber Set to the number of the next segment vector along the track in the direction in which we are facing
.UpdateVectorNumber LDA directionFacing \ If our car is facing backwards, jump to uvec1 BMI uvec1 LDY thisVectorNumber \ Set Y to the current segment vector number INY \ Increment Y to point to the next segment vector number \ along the track CPY trackVectorCount \ If Y <> trackVectorCount, then we have not reached the BNE uvec3 \ last vector, so jump to uvec3 to store the new value \ of thisVectorNumber LDY #0 \ If we get here then we have reached the last vector, \ so set Y = 0 to wrap around to the first vector BEQ uvec3 \ Jump to uvec3 to set thisVectorNumber = 0 (this BEQ is \ effectively a JMP as Y is always zero) .uvec1 \ If we get here then our car is facing backwards LDY thisVectorNumber \ Set Y to the current segment vector number BNE uvec2 \ If Y <> 0, then we are not on the first segment \ vector, so jump to uvec2 to decrement to the previous \ vector LDY trackVectorCount \ Set Y = trackVectorCount, so we wrap around to the \ last vector .uvec2 DEY \ Decrement Y to point to the previous segment vector \ number, i.e. backwards along the track .uvec3 STY thisVectorNumber \ Update thisVectorNumber with the new value that we set \ above .uvec4 RTS \ Return from the subroutine