Skip to navigation

Revs on the BBC Micro

Track geometry: GetSegmentDetails

Name: GetSegmentDetails [Show more] Type: Subroutine Category: Track geometry Summary: Get the details for the segment in front or behind Deep dive: Data structures for the track calculations The track verges
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * GetTrackAndMarkers calls GetSegmentDetails

Arguments: A The direction in which to fetch a segment: * Bit 7 clear = forwards (right) * Bit 7 set = backwards (left) In other words, fetch the track segments from the right or left verges, according to the way we are facing
Returns: segmentOffset The offset to use for this segment: * 0 when our car is facing in direction A * 120 when our car is facing opposite direction A segmentDirection The relative direction of our car: * 0 when our car is facing in direction A * 1 when our car is facing opposite direction A X Returns: * frontSegmentIndex when our car is facing in direction A * frontSegmentIndex + 120 when our car is facing the opposite direction to A (so we use the outer xSegmentCoordOLo rather than the inner xSegmentCoordILo)
.GetSegmentDetails LDX frontSegmentIndex \ Set X to the index * 3 of the front track segment in \ the track segment buffer EOR directionFacing \ If bit 7 of A and bit 7 of directionFacing are the BPL segd1 \ same, jump to segd1 TXA \ Set X = X + 120 CLC ADC #120 TAX LDA #120 \ Set A = 120, so segmentOffset gets set to 120 SEC \ Set the C flag, so segmentDirection gets set to 1 BNE segd2 \ Jump to segd2 (this BNE is effectively a JMP as A is \ never zero) .segd1 LDA #0 \ Set A = 0, so segmentOffset gets set to 0 CLC \ Clear the C flag, so segmentDirection gets set to 0 .segd2 STA segmentOffset \ Set segmentOffset = A LDA #0 \ Set segmentDirection to the C flag ROL A STA segmentDirection RTS \ Return from the subroutine