LDX frontSegmentIndex \ Set X to the index * 3 of the front track segment in \ the track segment buffer LDA thisSectionFlags \ Store bit 0 of the current section's flags on the LSR A \ stack using the C flag PHP LDA thisSectionFlags \ Set A to the current section's flags BCS gets6 \ If bit 0 of the current section's flag byte is set, \ then this is a curved section, so jump to gets6 with \ A set to the current section's flags, so the new \ track segment retains the same flags \ If we get here then this is a straight track section LDY objSectionSegmt+23 \ Set Y to the new front segment's segment number within \ the track section CPY #1 \ If Y < 1, jump to gets5 BCC gets5 CPY #10 \ If Y < 10, jump to gets6 with A set to BCC gets6 \ thisSectionFlags .gets5 \ If we get here then Y < 1 or Y >= 10 AND #%11111001 \ Clear bits 1 and 2 of the current section's flags in A \ to give this segment a black-and-white verge .gets6 STA W \ Store A in W, so W contains: \ \ * The current section's flags if this is a curve, or \ if this is a straight and the new segment's number \ within the track section is in the range 1 to 9 \ \ * The current section's flags with bits 1 and 2 \ cleared otherwise (i.e. if this is a straight and \ the new segment's number within the track section \ is not in the range 1 to 9) \ \ We use W to build the flags for the new track segment LDY objTrackSection+23 \ Set Y to the number * 8 of the track section for the \ new front segment LDA trackSectionSize,Y \ Set A to the size of the track section for the new \ front segment PLP \ If bit 0 of the current section's flag byte is clear, BCC gets7 \ then this is a straight section, so jump to gets7 with \ A set to the size of the track section for the new \ front segment \ If we get here then this is a curved track section LSR A \ Set Y = A / 2 TAY \ \ So Y contains half the size of the curved section LDA W \ Set A = W, which contains the flags we are building \ for the new track segment CPY objSectionSegmt+23 \ If Y = the new front segment's number within the track BEQ gets10 \ section, then the driver is exactly halfway round the \ curve, so jump to gets10 to store A in the track \ segment's flags BNE gets8 \ Otherwise jump to gets8 to clear bits 3-5 of A before \ storing it in the track segment's flags .gets7 \ If we get here then this is a straight section and A \ is set to the size of the track section for the new \ front segment SEC \ Set Y = A - the new front segment's number within the SBC objSectionSegmt+23 \ track section TAY \ \ So Y contains the length of the track section between \ the new front segment and the end of the section LDA W \ Set A = W, which contains the flags we are building \ for the new track segment CPY #7 \ If Y = 7, jump to gets10 to store A in the track BEQ gets10 \ segment's flags CPY #14 \ If Y = 14 or 21, jump to gets9 to clear bit 5 of A BEQ gets9 \ and store it in the track segment's flags CPY #21 BEQ gets9 \ Otherwise we clear bits 3-5 of A and store it in the \ track segment's flags .gets8 AND #%11100111 \ Clear bits 3 and 4 of A, so we don't show any corner \ markers for this segment .gets9 AND #%11011111 \ Clear bit 5 of A, so any markers for this segment are \ shown in white .gets10 AND thisSectionFlags \ Clear any bits in A that are already clear in the \ current section's flags, to ensure that the track \ segment's flags only have flags set if they are set in \ the track section's flags STA segmentFlags,X \ Set the flags for the new track segment to AName: GetTrackSegment (Part 2 of 3) [Show more] Type: Subroutine Category: Track geometry Summary: Set the flags for the new front segment in the track segment buffer Deep dive: Building a 3D track from sections and segments Data structures for the track calculations Corner markersContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
This part does the following: * Set the flags for the new front track segment in the track segment buffer Set the flags for the new track segment to the flags for the track section from the track data, but with these changes: Curve: * If the new front segment is not exactly halfway through the section, clear bits 3-5, to hide all corner markers (so they only get shown halfway through the section) Straight: * If the new front segment's segment number within the track section is not in the range 1 to 9, clear bits 1, 2 to show a black-and-white verge * If the distance yet to cover in this section = 7, leave bit 5 alone, so if red corner markers are configured, they are left as red * If the distance yet to cover in this section = 14 or 21, clear bit 5 to show all corner markers in white * If the distance yet to cover in this section <> 7, 14 or 21, clear bits 3-5, to hide all corner markers
[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 gets10 is local to this routine
[X]
Label gets5 is local to this routine
[X]
Label gets6 is local to this routine
[X]
Label gets7 is local to this routine
[X]
Label gets8 is local to this routine
[X]
Label gets9 is local to this routine
[X]
Variable objSectionSegmt in workspace Main variable workspace
Each object's segment number within the current track section, counting from the start of the section
[X]
Variable objTrackSection in workspace Main variable workspace
The number of the track section * 8 for each object
[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 trackSectionSize in workspace trackData
The length of each track section in terms of segments