.DrawTrack LDA #&80 \ Set P = &80, to use as the low byte of (Q P) in the STA P \ DrawVergeEdge that we call below LDA horizonListIndex \ Set A = X = horizonListIndex + 40 CLC \ ADC #40 \ So X is the index within the track verge buffer of the TAX \ horizon line's left verge (adding 40 moves the index \ from xVergeRightHi to xVergeLeftHi, which are 40 bytes \ apart in memory) CMP #49 \ If A >= 49, jump to dtra1 BCS dtra1 LDA #49 \ Set A = 49, so A has a minimum value of 49 .dtra1 STA vergeDepthOfField \ Set vergeDepthOfField = A \ = max(49, horizonListIndex + 40) \ = max(9, horizonListIndex) + 40 \ \ This sets the depth of field for displaying verge \ marks to at least entry 9 in the verge buffer, which \ is past all the sections (0 to 5) and past the first \ three segments (6 to 8) \ \ Adding 40 then points the index to the left verge LDA #LO(leftSegment) \ Set A to the low byte of leftSegment, so the call to \ MapSegmentsToLines populates the leftSegment table \ The following set R and MM to zero, to use as the low \ bytes in (S R) and (NN MM), though this is only \ because LO(leftSegment) happens to be zero; moving \ leftSegment off a page boundary would break this code STA R \ Set R = 0 to use as the low byte in (S R) STA MM \ Set MM = 0 to use as the low byte in (NN MM) LDY segmentListPointer \ Set Y to index of the last entry in the track segment \ list for the left side of the track JSR MapSegmentsToLines \ Populate the leftSegment table with a mapping of track \ lines on-screen to the verge buffer for the left side \ of the track LDY #0 \ Set Y = 0, so the call to DrawVergeEdge draws the \ leftVergeStart verge (the left edge of the left verge) STY pixelMaskVerge \ Set pixelMaskVerge = 0 LDA vergeDepthOfField \ Set A = vergeDepthOfField, so we only draw the next \ verge for segments that are within the verge depth of \ field JSR DrawVergeEdge \ Draw the left edge of the left verge (leftVergeStart) LDA #8 \ Set pixelMaskVerge = 8 STA pixelMaskVerge LDY #0 \ Set pixelMaskNoVerge = 0 STY pixelMaskNoVerge INY \ Set Y = 1, so the call to DrawVergeEdge draws the \ leftTrackStart verge (the right edge of the left \ verge) LDA horizonListIndex \ Set A = horizonListIndex + 40, so we draw the next CLC \ verge all the way from the horizon to the player ADC #40 JSR DrawVergeEdge \ Draw the right edge of the left verge (leftTrackStart) LDA vergeDepthOfField \ Set A = vergeDepthOfField to pass to the \ SetVergeBackground routine LDX #%00000100 \ Set X = %00000100 to pass to SetVergeBackground as a \ bit mask to use when calculating the background \ colours JSR SetVergeBackground \ Update the background colour table for any verges that \ overlap the left edge of the screen STY vergeTopLeft \ SetVergeBackground sets Y to the track line just above \ the segment at vergeDepthOfField (i.e. the furthest \ segment that might contain a verge), so store this in \ vergeTopLeft LDA horizonListIndex \ Set A = horizonListIndex TAX \ Set X = horizonListIndex CMP #9 \ If A >= 9, jump to dtra1 BCS dtra2 LDA #9 \ Set A = 9, so A has a minimum value of 9 .dtra2 STA vergeDepthOfField \ Set vergeDepthOfField = A \ = max(9, horizonListIndex) + 40 \ \ This sets the depth of field for displaying verge \ marks to at least entry 9 in the verge buffer, which \ is past all the sections (0 to 5) and past the first \ three segments (6 to 8) LDX horizonListIndex \ Set X = horizonListIndex \ \ So X is the index in the track verge buffer for the \ horizon line's right verge LDA #LO(rightSegment) \ Set A to the low byte of rightSegment, so the call to \ MapSegmentsToLines populates the rightSegment table LDY segmentListRight \ Set Y to index of the last entry in the track segment \ list for the right side of the track JSR MapSegmentsToLines \ Populate the rightSegment table with a mapping of \ track lines on-screen to the verge buffer for the \ right side of the track LDA #28 \ Set pixelMaskNoVerge = 28 STA pixelMaskNoVerge LDA #16 \ Set pixelMaskVerge = 16 STA pixelMaskVerge LDY #2 \ Set Y = 2, so the call to DrawVergeEdge draws the \ rightVergeStart verge (the left edge of the right \ verge) LDA horizonListIndex \ Set A = horizonListIndex so we draw the next verge all \ the way from the horizon to the player JSR DrawVergeEdge \ Draw the left edge of the right verge \ (rightVergeStart) LDA #28 \ Set pixelMaskVerge = 28 STA pixelMaskVerge LDY #3 \ Set Y = 3, so the call to DrawVergeEdge draws the \ rightGrassStart verge (the right edge of the right \ verge) LDA vergeDepthOfField \ Set A = vergeDepthOfField, so we only draw the next \ verge for segments that are within the verge depth of \ field JSR DrawVergeEdge \ Draw the right edge of the right verge \ (rightGrassStart) LDA vergeDepthOfField \ Set A = vergeDepthOfField to pass to the \ SetVergeBackground routine LDX #%00010100 \ Set X = %00010100 to pass to SetVergeBackground as a \ bit mask to use when calculating the background \ colours JSR SetVergeBackground \ Update the background colour table for any verges that \ overlap the left edge of the screen STY vergeTopRight \ SetVergeBackground sets Y to the track line just above \ the segment at vergeDepthOfField (i.e. the furthest \ segment that might contain a verge), so store this in \ vergeTopRight RTS \ Return from the subroutineName: DrawTrack [Show more] Type: Subroutine Category: Drawing the track Summary: Draw the track into the screen buffer Deep dive: Drawing the track vergesContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 2 of 5) calls DrawTrack
[X]
Subroutine DrawVergeEdge (category: Drawing the track)
Draw one of the four track verge edges into the screen buffer
[X]
Subroutine MapSegmentsToLines (category: Drawing the track)
Map verges in the track segment list to track lines in the track view
[X]
Subroutine SetVergeBackground (category: Drawing the track)
Update the background colour table for any verges that overlap the left edge of the screen
[X]
Label dtra1 is local to this routine
[X]
Label dtra2 is local to this routine
[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 leftSegment in workspace Main variable workspace
For each track line, the index of the segment within the track segment list for the left verge
[X]
Variable pixelMaskNoVerge in workspace Zero page
Offset within the vergePixelMask table for segments that are too far away to show a verge, i.e. those outside the verge depth of field
[X]
Variable pixelMaskVerge in workspace Zero page
Offset within the vergePixelMask table for segments that are close enough to show a verge, i.e. those within the verge depth of field
[X]
Variable rightSegment in workspace Main variable workspace
For each track line, the index of the segment within the track segment list for the right verge
[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 vergeDepthOfField in workspace Zero page
The index into the verge buffer of the furthest verge mark, so for segments further from the player than this point, we do not draw verge marks
[X]
Variable vergeTopLeft in workspace Zero page
The track line just above the segment at vergeDepthOfField (i.e. the furthest segment that might contain a verge) when drawing the left verge
[X]
Variable vergeTopRight in workspace Zero page
The track line just above the segment at vergeDepthOfField (i.e. the furthest segment that might contain a verge) when drawing the right verge