Skip to navigation


Track geometry: GetSectionAngles (Part 2 of 3)

Name: GetSectionAngles (Part 2 of 3) [Show more] Type: Subroutine Category: Track geometry Summary: Calculate the track section number for this track section entry Deep dive: Data structures for the track calculations The track verges
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

This part of the routine calculates the number of the track section that we want to update, i.e. the section at entry sectionListPointer in the list.
.gsec4 LDA #6 \ Set A = (6 - sectionListPointer) * 8 SEC \ SBC sectionListPointer \ This calculates the following: ASL A \ ASL A \ * A = 1 * 8 for entry #5 ASL A \ * A = 2 * 8 for entry #4 \ * A = 3 * 8 for entry #3 \ * A = 4 * 8 for entry #2 \ * A = 5 * 8 for entry #1 \ * A = 6 * 8 for entry #0 BIT directionFacing \ If bit 7 of directionFacing is clear, then we are BPL gsec5 \ facing forwards, so jump to gsec5 \ If we get here then we are facing backwards STA T \ Set T = A LDA objTrackSection+23 \ Set Y to the number * 8 of the track section for the \ front segment of the track segment buffer CLC \ Set A = A + 8 - T ADC #8 \ = frontSection * 8 + 8 - T SEC \ = (frontSection + 1 - (T / 8)) * 8 SBC T \ \ So A contains: \ \ * (frontSection - 0) * 8 for entry #5 \ * (frontSection - 1) * 8 for entry #4 \ * (frontSection - 2) * 8 for entry #3 \ * (frontSection - 3) * 8 for entry #2 \ * (frontSection - 4) * 8 for entry #1 \ * (frontSection - 5) * 8 for entry #0 \ \ So A now contains the correct section number for \ entry number sectionListPointer BCS gsec6 \ If the subtraction didn't underflow, jump to gsec6 ADC trackSectionCount \ The subtraction underflowed, so add the total number \ of track sections * 8 given in trackSectionCount to \ wrap round to the correct section number (we know the \ C flag is clear as we just passed through a BCS) JMP gsec6 \ Jump to gsec6 .gsec5 \ If we get here then we are facing forwards CLC \ Set A = A + number * 8 of track section for the ADC objTrackSection+23 \ front segment \ = A + frontSection * 8 \ \ So A contains: \ \ * (1 + frontSection) * 8 for entry #5 \ * (2 + frontSection) * 8 for entry #4 \ * (3 + frontSection) * 8 for entry #3 \ * (4 + frontSection) * 8 for entry #2 \ * (5 + frontSection) * 8 for entry #1 \ * (6 + frontSection) * 8 for entry #0 \ \ So A now contains the correct section number for \ entry number sectionListPointer CMP trackSectionCount \ If A < trackSectionCount then A is a valid section BCC gsec6 \ number, so jump to gsec6 SBC trackSectionCount \ The addition took us past the highest track section \ number, so subtract the total number of track sections \ * 8 given in trackSectionCount to bring it down to the \ correct section number (we know the C flag is set as \ we just passed through a BCC)