.HookSectionFrom STY yStore \ Store the section number in yStore, so we can retrieve \ it at the end of the hook routine LDA trackSectionFrom,Y \ Set thisVectorNumber = the Y-th trackSectionFrom, just STA thisVectorNumber \ like the code that we overwrote with the call to the \ hook routine TYA \ Set Y = Y / 8 LSR A \ LSR A \ So Y now contains the number of the track section (as LSR A \ trackSectionFrom contains the track section * 8) TAY LDA trackYawAngleLo,Y \ Set (yawAngleHi yawAngleLo) to this section's entry STA yawAngleLo \ from (trackYawAngleHi trackYawAngleLo) LDA trackYawAngleHi,Y STA yawAngleHi LDA trackSlope,Y \ Set segmentSlope to this section's entry from STA segmentSlope \ trackSlope LDA trackSubConfig,Y \ Set A to this section's configuration byte LSR A \ Set A = A >> 2, with bit 6 cleared, bit 7 set to the ROR A \ bit 0 of the trackSubConfig entry, and the C flag set \ to bit 1 of the trackSubConfig entry STA subSection \ Store A in subSection, so it contains the index \ from bits 2-7 of trackSubConfig, and bit 7 is set if \ bit 0 of trackSubConfig is set LDA #14 \ Set A = 7, with bit 7 set to the C flag (so if this ROR A \ section's trackSubConfig has bit 1 set, then A is 135, \ otherwise it is 7) STA &23B3 \ Modify the GetSectionAngles routine, at instruction \ #4 after gsec11, to test prevHorizonIndex against the \ value we just calculated in A rather than 7 \ \ So if this section's trackSubConfig has bit 1 set, the \ test becomes prevHorizonIndex <= 135, which is always \ true, so this modification makes us never set the \ horizon line to 7 for sections that have bit 1 of \ trackSubConfig set LDA #0 \ Set subSectionSegment = 0, so we start counting from STA subSectionSegment \ the first segment in the sub-section BIT directionFacing \ If we are facing backwards along the track, jump to BMI from1 \ from1 to skip the following call to SetSegmentVector JSR SetSegmentVector \ We are facing forwards along the track, so calculate \ and store the current segment vector .from1 LDY yStore \ Retrieve the section number from yStore LDA thisVectorNumber \ Set A to the Y-th trackSectionFrom that we set above, \ so the routine sets A to the segment vector number, \ just like the code that we overwrote with the call to \ the hook routine RTS \ Return from the subroutineName: HookSectionFrom [Show more] Type: Subroutine Category: Extra tracks Summary: Initialise and calculate the current segment vector Deep dive: Secrets of the extra tracks Dynamic track generation in the extra tracks Code hooks in the extra tracksContext: See this subroutine in context in the source code References: This subroutine is called as follows: * newContentHi calls HookSectionFrom * newContentLo calls HookSectionFrom
This routine is called from GetSectionCoords when fetching the coordinates for a track section. It initialises the segment vector calculation process by doing the following: * Fetch the section's yaw angle from the trackYawAngle tables * Fetch the section's slope from the trackSlope table * Initialise the sub-section and sub-section segment variables * Modify the GetSectionAngles routine so the horizon level check is skipped if the section's trackSubConfig has bit 1 set * If we are facing forwards along the track, calculate and store the current segment vector
Arguments: Y The number of the track section * 8 whose coordinates we want to fetch
[X]
Subroutine SetSegmentVector (category: Extra tracks)
Add the yaw angle and height deltas to the yaw angle and height (for curved sections) and calculate the segment vector
[X]
Configuration variable directionFacing = &0025
[X]
Label from1 is local to this routine
[X]
Variable segmentSlope (category: Extra tracks)
The height above ground of the current track sub-section
[X]
Variable subSection (category: Extra tracks)
The number of the current sub-section
[X]
Variable subSectionSegment (category: Extra tracks)
The number of the segment within the current sub-section, counting from the start of the sub-section
[X]
Configuration variable thisVectorNumber = &0002
[X]
Configuration variable trackSectionFrom = &5905
[X]
Variable trackSlope (category: Extra tracks)
The slope at the start of each track section
[X]
Variable trackSubConfig (category: Extra tracks)
Configuration data for each section that defines the sub-section numbers, and horizon calculations
[X]
Variable trackYawAngleHi (category: Extra tracks)
The high byte of the yaw angle of the start of each track section (i.e. the direction of the track at that point)
[X]
Variable trackYawAngleLo (category: Extra tracks)
The low byte of the yaw angle of the start of each track section (i.e. the direction of the track at that point)
[X]
Configuration variable yStore = &001B
[X]
Variable yawAngleHi (category: Extra tracks)
High byte of the current yaw angle of the track, i.e. the angle at which the track is pointing along the ground
[X]
Variable yawAngleLo (category: Extra tracks)
Low byte of the current yaw angle of the track, i.e. the angle at which the track is pointing along the ground