.GetFirstSegment LDX frontSegmentIndex \ Set X to the index * 3 of the front track segment in \ the track segment buffer LDY #6 \ Set Y = 6 STY newSectionFetched \ Set newSectionFetched to a non-zero value to indicate \ that we have just fetched a new section (as the \ GetFirstSegment routine is only called when the \ player's car enters a new section LDA resetSectionList \ If resetSectionList = 0, then we do not need to reset BEQ getf1 \ the track section list, so jump to getf1 to skip the \ following instruction \ If we get here then resetSectionList is non-zero, \ which means we need to reset the track section list STY sectionListValid \ Set sectionListValid = 6 to indicate that the track \ section list contains no valid entries, so the list \ gets regenerated over the coming iterations .getf1 LDA directionFacing \ If our car is facing backwards, jump to getf2 BMI getf2 LDY objTrackSection+23 \ Set Y to the number * 8 of the track section for the \ front segment of the track segment buffer JSR GetSectionCoords \ Copy the start coordinates for the track section \ into xSegmentCoordI and xSegmentCoordO, and set \ thisVectorNumber to trackSectionFrom LDA trackSectionData,Y \ Set A = trackSectionData for the track section, so \ bits 0-2 can be set as the value for sectionListSize \ below JMP getf3 \ Jump to getf3 to skip the following .getf2 LDY sectionBehind \ Set Y to the number * 8 of the track section in \ sectionBehind JSR GetSectionCoords \ Copy the start coordinates for the track section \ into xSegmentCoordI and xSegmentCoordO, and set \ thisVectorNumber to trackSectionFrom JSR UpdateVectorNumber \ Update thisVectorNumber to the next vector along the \ track in the direction we are facing LDA #2 \ Set A = 2, to use as the value for sectionListSize \ below .getf3 AND #%00000111 \ Set sectionListSize = bits 0-2 from A STA sectionListSize LDY objTrackSection+23 \ Set Y to the number * 8 of the track section for the \ new front segment LDA trackSectionFlag,Y \ Set thisSectionFlags to the track section flags for STA thisSectionFlags \ the section containing the new front track segment LDA #0 \ Zero the flags for the front track segment STA segmentFlags,X RTS \ Return from the subroutineName: GetFirstSegment [Show more] Type: Subroutine Category: Track geometry Summary: Get the track section coordinates and flags from the track data and populate the first track segment Deep dive: Data structures for the track calculationsContext: See this subroutine in context in the source code References: This subroutine is called as follows: * GetTrackSegment (Part 1 of 3) calls GetFirstSegment
This routine is called when we move into a new track section, and is used to populate the front track segment with the data from the start of the new track section.
Arguments: sectionBehind The number * 8 of the track section behind us, for when we are facing backwards frontSegmentIndex The index * 3 of the new front track segment in the track segment buffer
Returns: sectionListSize Bits 0-2 from trackSectionData, or 2 if we are facing backwards xSegmentCoordI Start coordinates for the inside of the track section, stored in the new front track segment xSegmentCoordO Start coordinates for the outside of the track section, stored in the new front track segment thisVectorNumber The vector number from the start of the track section thisSectionFlags The track section flags for the section containing the new front track segment segmentFlags Zeroed for the new front track segment
[X]
Subroutine GetSectionCoords (category: Track geometry)
Copy two three-part 16-bit coordinates from the track section data
[X]
Subroutine UpdateVectorNumber (category: Track geometry)
Move to the next segment vector along the track in the direction we are facing
[X]
Variable directionFacing in workspace Zero page
The direction that our car is facing
[X]
Variable frontSegmentIndex in workspace Zero page
Used to store the index * 3 of the front track segment in the track segment buffer
[X]
Label getf1 is local to this routine
[X]
Label getf2 is local to this routine
[X]
Label getf3 is local to this routine
[X]
Variable newSectionFetched (category: Track geometry)
Flag that determines whether a new track section has been fetched
[X]
Variable objTrackSection in workspace Main variable workspace
The number of the track section * 8 for each object
[X]
Variable resetSectionList in workspace Zero page
Controls whether to reset the contents of the track section list
[X]
Variable sectionBehind in workspace Zero page
Used to store the number * 8 of the track section behind us when we drive backwards along the track
[X]
Variable sectionListSize in workspace Zero page
The size 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
[X]
Variable segmentFlags in workspace Main variable workspace
Flags for a track segment in the track segment buffer
[X]
Variable thisSectionFlags in workspace Zero page
The track section flags for the current track section
[X]
Variable trackSectionData in workspace trackData
Various data for the track section
[X]
Variable trackSectionFlag in workspace trackData
Various flags for the track section