.GetSectionAngles LDA newSectionFetched \ If newSectionFetched = 0, then we have not fetched a BEQ gsec1 \ new track section since the last call, so jump to \ gsec1 to skip the following call to ShuffleSectionList JSR ShuffleSectionList \ Shuffle the track section list along by one so we can \ insert the new section, updating sectionListValid and \ sectionListPointer accordingly LDA #0 \ Reset newSectionFetched to 0 so we don't call the STA newSectionFetched \ ShuffleSectionList routine again until the next new \ section has been fetched .gsec1 LDY sectionListStart \ If sectionListStart = 6, then the track section list CPY #6 \ is zero-length, so return from the subroutine (as BEQ GetSectionAngles-1 \ GetSectionAngles-1 contains an RTS) \ \ This never happens with the Silverstone track, as for \ this track, sectionListStart is in the range 2 to 5 \ (as sectionListSize is in the range 1 to 4) LDY sectionListValid \ If sectionListValid = 6 then there are no valid CPY #6 \ entries in the track section list, so jump to gsec4 to BEQ gsec4 \ skip the spinning process (as we only apply spin to \ valid sections in the list) \ Otherwise we now loop from Y = sectionListValid up to \ 5 to work through the valid entries in the list, \ applying the yaw angle spin to each one, and skipping \ entry number sectionListPointer as we are going to \ update that entry below .gsec2 CPY sectionListPointer \ If Y = sectionListPointer, jump to gsec3 to move on to BEQ gsec3 \ the next entry in the list, as we are going to update \ this entry below STY T \ Store Y in T so we can retrieve it below when applying \ spin to the left verge TYA \ Set Y = Y + 40 CLC \ ADC #40 \ So Y now points to the section for the right verge TAY JSR SpinTrackSection \ Apply the car's current spin to the right verge track \ section in Y: \ \ * Reset vergeDataRight to zero \ \ * Subtract spinYawAngle from the yaw angles in \ xVergeRightLo, xVergeRightHi \ \ * Subtract spinPitchAngle from the pitch angle in \ yVergeRight \ \ * Update horizonListIndex and horizonLine LDY T \ Retrieve the original value of Y that we stored above JSR SpinTrackSection \ Apply the car's current spin to the left verge track \ section in T: \ \ * Reset vergeDataLeft to zero \ \ * Subtract spinYawAngle from the yaw angles in \ xVergeLeftLo, xVergeLeftHi \ \ * Subtract spinPitchAngle from the pitch angle in \ yVergeLeft \ \ * Update horizonListIndex and horizonLine .gsec3 INY \ Increment the loop counter in Y CPY #6 \ Loop back until we have updated all the valid entries BCC gsec2 \ in the track section listName: GetSectionAngles (Part 1 of 3) [Show more] Type: Subroutine Category: Track geometry Summary: Get the yaw and pitch angles for the inner and outer track sections Deep dive: Data structures for the track calculations The track vergesContext: See this subroutine in context in the source code References: This subroutine is called as follows: * GetTrackAndMarkers calls GetSectionAngles
This routine does the following: * Part 1: If we have fetched a new track section since the last call, shuffle the track section list along by one so we can insert the new section * Part 1: Go through the track section list and apply spin to each valid entry (for both the right and left track section), skipping the entry pointed to by the sectionListPointer * Update the entry at sectionListPointer as follows: * Part 2: Calculate the track section number for this entry, relative to the front segment in the track segment buffer * Part 3: Store the yaw and pitch angles for this section in the xVergeRight/Left and yVergeRight/Left tables
Returns: xVergeRight Updated yaw angles for the entries in the track section list (i.e. indexes 0 to 5) for the right verge xVergeLeft Updated yaw angles for the entries in the track section list (i.e. indexes 0 to 5) for the left verge yVergeRight Updated pitch angles for the entries in the track section list (i.e. indexes 0 to 5) for the right verge yVergeLeft Updated pitch angles for the entries in the track section list (i.e. indexes 0 to 5) for the left verge horizonLine Updated to cater for the pitch angles of the updated track sections horizonListIndex Updated to the index of the track section that contains the horizon (i.e. the index within the track section list)
Other entry points: GetSectionAngles-1 Contains an RTS
[X]
Entry point GetSectionAngles-1 in subroutine GetSectionAngles (Part 1 of 3) (category: Track geometry)
Contains an RTS
[X]
Subroutine ShuffleSectionList (category: Track geometry)
Shuffle the track section list along by one position
[X]
Subroutine SpinTrackSection (category: Track geometry)
Apply spin to a section in the track section list
[X]
Label gsec1 is local to this routine
[X]
Label gsec2 is local to this routine
[X]
Label gsec3 is local to this routine
[X]
Label gsec4 in subroutine GetSectionAngles (Part 2 of 3)
[X]
Variable newSectionFetched (category: Track geometry)
Flag that determines whether a new track section has been fetched
[X]
Variable sectionListPointer in workspace Zero page
The index of the current entry in the track section list, as we only update one entry in the list on each iteration of the main driving loop
[X]
Variable sectionListStart in workspace Zero page
The start index of the track section list that's used when calculating the positions of the track verges
[X]
Variable sectionListValid in workspace Zero page
The index of the first valid entry in the track section list