Skip to navigation

Revs on the BBC Micro

Track geometry: GetVergeAndMarkers (Part 1 of 4)

Name: GetVergeAndMarkers (Part 1 of 4) [Show more] Type: Subroutine Category: Track geometry Summary: Get the details for a segment's corner markers and verge marks Deep dive: The track verges Corner markers
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * GetSegmentAngles (Part 2 of 3) calls GetVergeAndMarkers * GetSegmentAngles (Part 3 of 3) calls GetVergeAndMarkers

The track verge, which is shown in black-and-white or red-and-white verge marks according to the track data, extends outwards from the track edge, where the track edge is the line defined by the segment vectors. This routine calculates the verge colours and the coordinates of the outside of the verge, and it also calculates the coordinates and colours of the corner markers for this track segment.
Arguments: X The offset from xSegmentCoordILo of the segment's 3D coordinates, i.e. the segment number * 3, with: * X for inner track segment coordinates * X + 120 for outer track segment coordinates LL The segment's pitch angle, from the point of view of the player scaleUp The scale up factor for the segment scaleDown The scale down factor for the segment Results: xVergeRight Entries in the second part of the track segment list for the coordinates of the outside of the right track verge (i.e. indexes 22 to 37, which correspond to the yaw angles in the track segment list in indexes 6 to 21) xVergeLeft Entries in the second part of the track segment list for the coordinates of the outside of the left track verge (i.e. indexes 22 to 37, which correspond to the yaw angles in the track segment list in indexes 6 to 21) yVergeRight Pitch angles for the entries in the track segment list (i.e. indexes 6 to 21) for the right verge yVergeLeft Pitch angles for the entries in the track segment list (i.e. indexes 6 to 21) for the left verge xMarker Distance in the x-axis between the track edge and the corner marker for this segment (if there is one) vergeDataRight Data (such as colour) for this segment's right verge vergeDataLeft Data (such as colour) for this segment's left verge
.GetVergeAndMarkers LDY segmentDirection \ Set Y to segmentDirection, which will be 0 when our \ car is facing in the same direction as the segment we \ are checking, or 1 if it's the opposite direction \ \ This determines whether we are creating the left or \ right verge, with 0 for the left verge and 1 for the \ right verge CPX #120 \ If X >= 120, jump to gmar1 to subtract 120 from the BCS gmar1 \ offset LDA segmentFlags,X \ Set A to the flags for this track segment from the \ track segment buffer BCC gmar2 \ Jump to gmar2 (this BCC is effectively a JMP as we \ just passed through a BCS) .gmar1 LDA segmentFlags-120,X \ Set A to the flags for this track segment from the \ track segment buffer .gmar2 AND segmentFlagMask,Y \ Extract the relevant bits of the segment's flags: STA W \ \ W = A AND %00101101 if Y = 0 (right verge) \ %00110011 if Y = 1 (left verge) \ \ So when we are processing the right verge, we extract \ these flags into W while zeroing the rest: \ \ * Bit 0 (section shape) \ * Bit 2 (colour of right verge marks) \ * Bit 3 (show right corner markers) \ * Bit 5 (corner marker colours) \ \ and when we are processing the left verge, we extract \ these flags into W while zeroing the rest: \ \ * Bit 0 (section shape) \ * Bit 1 (colour of left verge marks) \ * Bit 4 (show left corner markers) \ * Bit 5 (corner marker colours) AND #%00000111 \ Set Y = bits 0-2 of W, so Y is in the range 0 to 7, TAY \ where the possible values are as follows: \ \ * Y = 0 = %000 = black right, black left, straight \ * Y = 1 = %001 = black right, black left, curve \ * Y = 2 = %010 = black right, red left, straight \ * Y = 3 = %011 = black right, red left, curve \ * Y = 4 = %100 = red right, black left, straight \ * Y = 5 = %101 = red right, black left, curve \ * Y = 6 = %110 = red right, red left, straight \ * Y = 7 = %111 = red right, red left, curve LDA vergeColour,Y \ When we are processing the right verge, we know bit 1 STA V \ is clear, so the possible values of Y are as follows: \ \ * Y = 0 = %000 = black right, black left, straight \ * Y = 1 = %001 = black right, black left, curve \ * Y = 4 = %100 = red right, black left, straight \ * Y = 5 = %101 = red right, black left, curve \ \ When we are processing the left verge, we know bit 2 \ is clear, so the possible values of Y are as follows: \ \ * Y = 0 = %000 = black right, black left, straight \ * Y = 1 = %001 = black right, black left, curve \ * Y = 2 = %010 = black right, red left, straight \ * Y = 3 = %011 = black right, red left, curve \ \ So if Y = 0 or 1, then we know that the verge we are \ processing is black-and-white, otherwise it is \ red-and-white \ \ These instructions set V to the Y-th entry in the \ vergeColour table, which contains the following: \ \ * 0 when Y = 0 to 1 (black-and-white verge) \ * 1 when Y = 2 to 7 (red-and-white verge) \ \ So V = 0 if this is a black-and-white verge \ 1 if this is a red-and-white verge LDA segmentCounter \ If segmentCounter >= 3 then jump to gmar3 to process CMP #3 \ the segment's corner markers in part 2 BCS gmar3 JMP gmar9 \ Otherwise segmentCounter is 0 to 2, so jump to gmar9 \ to skip the corner markers and move on to the verge \ marks in part 4