.GetTrackAndMarkers LDA #0 \ Set horizonLine = 0, so we can calculate a new pitch STA horizonLine \ angle for the horizon in the following process JSR GetSectionAngles \ Get the yaw and pitch angles for the inner and outer \ track sections in the track section list and store the \ results in xVergeRight/Left and yVergeRight/Left LDA #255 \ Set edgeDistanceHi = 255, so GetSegmentAngles can set STA edgeDistanceHi \ it to the distance of the nearest verge LDA #13 \ Set edgeSegmentNumber = 13, as the default value for STA edgeSegmentNumber \ the number of the segment within the track segment \ list that is closest to the player's car LDA #0 \ Fetch the index details of the right track segments JSR GetSegmentDetails LDA #6 \ Get the yaw and pitch angles for the segments (and the JSR GetSegmentAngles \ verge marks and corner markers) along the right side \ of the track and store the results in xVergeRight, \ yVergeRight, xMarker and vergeDataRight LDA segmentListPointer \ Set segmentListRight = segmentListPointer STA segmentListRight \ \ So it contains the index of the last entry in the \ track segment list for the right side of the track LDA #%10000000 \ Fetch the index details of the left track segments JSR GetSegmentDetails LDA #46 \ Get the yaw and pitch angles for the segments (and the JSR GetSegmentAngles \ verge marks and corner markers) along the left side \ of the track and store the results in xVergeLeft, \ yVergeLeft, xMarker and vergeDataLeft LDA horizonListIndex \ If horizonListIndex < 40, then this is a valid index CMP #40 \ into the track verge buffer so jump to gtrm1 to skip BCC gtrm1 \ the following three instructions SEC \ Set horizonListIndex = horizonListIndex - 40 SBC #40 \ STA horizonListIndex \ so if we set horizonListIndex to the index for the \ outer track coordinates, this corrects the value to \ the index for the inner coordinates .gtrm1 TAY \ Set Y to the corrected value of horizonListIndex STY prevHorizonIndex \ Store the horizon section index in prevHorizonIndex, \ so we can refer to it in the next call to \ GetTrackAndMarkers LDA horizonLine \ If horizonLine < 79, then the horizon line is a valid CMP #79 \ number, so jump to gtrm2 to skip the following two BCC gtrm2 \ instructions LDA #78 \ Set horizonLine = 78, so the maximum value for the STA horizonLine \ horizon line is 78 .gtrm2 STA yVergeRight,Y \ Set the pitch angle for the right side of the horizon \ line in the track verge buffer to the updated value of \ horizonLine STA yVergeLeft,Y \ Set the pitch angle for the left side of the horizon \ line in the track verge buffer to the updated value of \ horizonLine LDA xVergeRightHi,Y \ Set A = xVergeRightHi - xVergeLeftHi for the horizon SEC \ section SBC xVergeLeftHi,Y JSR Absolute8Bit \ Set A = |A|, so A contains the arc of the track at \ the horizon (i.e. the track width on the section or \ segment at the horizon) in terms of the high bytes LSR A \ Set horizonTrackWidth = |A| / 2 STA horizonTrackWidth \ \ So horizonTrackWidth contains half the width of the \ track on the horizon, in terms of the high bytes RTS \ Return from the subroutineName: GetTrackAndMarkers [Show more] Type: Subroutine Category: Track geometry Summary: Calculate the 3D coordinates of the track and corner markers Deep dive: The track verges Corner markersContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 2 of 5) calls GetTrackAndMarkers
Other entry points: gtrm2+6 Calculate the following for segment Y: horizonTrackWidth = |xVergeRightHi - xVergeLeftHi| / 2
[X]
Subroutine Absolute8Bit (category: Maths (Arithmetic))
Calculate the absolute value (modulus) of an 8-bit number
[X]
Subroutine GetSectionAngles (Part 1 of 3) (category: Track geometry)
Get the yaw and pitch angles for the inner and outer track sections
[X]
Subroutine GetSegmentAngles (Part 1 of 3) (category: Track geometry)
Get the yaw and pitch angles for the inner or outer track segments
[X]
Subroutine GetSegmentDetails (category: Track geometry)
Get the details for the segment in front or behind
[X]
Variable edgeDistanceHi in workspace Zero page
High byte of the distance between the player's car and the nearest track edge
[X]
Variable edgeSegmentNumber in workspace Zero page
The number of the segment within the track segment list that is closest to the player's car
[X]
Label gtrm1 is local to this routine
[X]
Label gtrm2 is local to this routine
[X]
Variable horizonLine in workspace Zero page
The track line number of the horizon
[X]
Variable horizonListIndex in workspace Zero page
The track section or segment that's on the horizon, given in terms of the index within the track section list (or the track segment list)
[X]
Variable horizonTrackWidth (category: Track geometry)
The arc of the track at the horizon (i.e. the track width at the horizon), halved
[X]
Variable prevHorizonIndex in workspace Zero page
The value of horizonListIndex from the previous call to the GetTrackAndMarkers routine
[X]
Variable segmentListPointer in workspace Zero page
The index of the current entry in the track segment list
[X]
Variable segmentListRight in workspace Zero page
The index of the last entry in the track segment list for the right side of the track
[X]
Variable xVergeLeftHi (category: Track geometry)
High byte of segment yaw angles along the left track verge in front of the player (i.e. along the x-axis)
[X]
Variable xVergeRightHi (category: Track geometry)
High byte of segment yaw angles along the right track verge in front of the player (i.e. along the x-axis)
[X]
Variable yVergeLeft (category: Track geometry)
Segment pitch angles along the left track verge in front of the player (i.e. along the up-down y-axis)
[X]
Variable yVergeRight (category: Track geometry)
Segment pitch angles along the right track verge in front of the player (i.e. along the up-down y-axis)