Skip to navigation

Revs on the BBC Micro

Track geometry: GetSegmentVector

Name: GetSegmentVector [Show more] Type: Subroutine Category: Track geometry Summary: Fetch a segment vector from the track data file 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: * BuildCarObjects (Part 3 of 3) calls GetSegmentVector * GetTrackSegment (Part 1 of 3) calls GetSegmentVector

Arguments: Y The index of the coordinate in the track data blocks Returns: (SS T) The Y-th entry from xTrackSegmentI as a 16-bit signed integer (TT U) The Y-th entry from yTrackSegmentI as a 16-bit signed integer (UU V) The Y-th entry from zTrackSegmentI as a 16-bit signed integer
.GetSegmentVector LDA #0 \ Zero the high bytes of (SS T), (TT U) and (UU V) STA SS STA TT STA UU LDA xTrackSegmentI,Y \ Set T = the Y-th entry from xTrackSegmentI STA T BPL coor1 \ If the byte we just fetched is negative, decrement DEC SS \ the high byte in SS to &FF, so (SS T) has the correct \ sign .coor1 LDA yTrackSegmentI,Y \ Set U = the Y-th entry from yTrackSegmentI STA U BPL coor2 \ If the byte we just fetched is negative, decrement DEC TT \ the high byte in TT to &FF, so (TT U) has the correct \ sign .coor2 LDA zTrackSegmentI,Y \ Set V = the Y-th entry from zTrackSegmentI STA V BPL coor3 \ If the byte we just fetched is negative, decrement DEC UU \ the high byte in UU to &FF, so (UU V) has the correct \ sign .coor3 LDA directionFacing \ If our car is facing fowards, jump to coor5 to return BEQ coor5 \ from the subroutine \ We are facing backwards, so we need to negate the \ coordinate we just fetched LDX #2 \ We are about to negate the following 16-bit variables: \ \ (SS T) \ (TT U) \ (UU V) \ \ so set a counter in X to use as an index that loops \ through 2, 1 and 0, as: \ \ (TT U) = (SS+1 U+1) \ (UU V) = (SS+2 U+2) \ \ The following comments are for (SS T), but the same \ process applies for (TT U) and (UU V) .coor4 LDA #0 \ Set (SS T) = 0 - (SS T) SEC \ SBC T,X \ starting with the low bytes STA T,X LDA #0 \ And then the high bytes SBC SS,X STA SS,X DEX \ Decrement the loop counter to move on to the next \ variable BPL coor4 \ Loop back until we have negated all three 16-bit \ variables .coor5 RTS \ Return from the subroutine