Skip to navigation


Track geometry: GetFirstSegment

Name: 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 calculations
Context: 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
.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 subroutine