Skip to navigation

Aviator on the BBC Micro

Visibility: ProcessRunwayLine (Part 4 of 5)

Name: ProcessRunwayLine (Part 4 of 5) [Show more] Type: Subroutine Category: Visibility Summary: Construct the dashes down the middle of the runway
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.prun12 \ By the time we get here, (xTemp1 yTemp1 zTemp1) \ contains the vector from the anchor point (point 1) to \ point 4, which is the vector from one side of the \ runway to the other \ \ We now want to halve the (xTemp1 yTemp1 zTemp1) \ vector, to give the vector from one side of the runway \ to the line of dashes down the middle \ \ As a reminder, the runway outline looks like this: \ \ 2 3 \ +-------+ \ | : | \ | : | \ | : | \ | : | \ | : | \ +-------+ \ 1 4 \ \ so we now calculate (xTemp1 yTemp1 zTemp1) to be the \ vector from the left edge of the runway to the dashes \ in the middle LDX #2 \ Set a counter in X to work through the three axes of \ the (xTemp1 yTemp1 zTemp1) vector (the comments below \ cover the iteration for the x-axis) .prun13 CLC \ Clear the C flag, to use when (xTemp1Hi xTemp1Lo) is \ positive LDA xTemp1Hi,X \ If xTemp1Hi is positive, skip the next instruction BPL prun14 SEC \ Set the C flag, to use when (xTemp1Hi xTemp1Lo) is \ negative .prun14 ROR A \ Shift (xTemp1Hi xTemp1Lo) to the right by one place, STA xTemp1Hi,X \ inserting the C flag into the top bit of xTemp1Hi, LDA xTemp1Lo,X \ which ensures that we retain the same sign ROR A STA xTemp1Lo,X DEX \ Decrement the loop counter to move to the next axis BPL prun13 \ Loop back until we have halved xTemp1, yTemp1 and \ zTemp1 \ (xTemp1 yTemp1 zTemp1) now contains the vector from \ one side of the runway to the line of dashes down the \ middle LDY #2 \ Set point 21's coordinates to point 2's coordinates + LDX #21 \ (xTemp1 yTemp1 zTemp1) JSR AddTempToPoint LDY #1 \ Set point 5's coordinates to point 1's coordinates + LDX #5 \ (xTemp1 yTemp1 zTemp1) JSR AddTempToPoint \ So we've now calculated points 5 and 21 as follows: \ \ 2 21 3 \ +-------+ \ | : | \ | : | \ | : | \ | : | \ | : | \ +-------+ \ 1 5 4 \ \ Next, we make a backup of the (xTemp1 yTemp1 zTemp1) \ vector in (xDashesVector yDashesVector zDashesVector) LDX #5 \ Set a counter for six bytes .prun15 LDA xTemp1Lo,X \ Copy the X-th byte of xTemp1Lo to the X-th byte of STA xDashesVectorLo,X \ xDashesVectorLo DEX \ Decrement the loop counter BPL prun15 \ Loop back until we have copied all six bytes \ So (xDashesVector yDashesVector zDashesVector) now \ contains the vector from one side of the runway to the \ line of dashes down the middle \ We now zero variables T, U, V, W, G and H LDX #5 \ Set a counter for six bytes LDA #0 \ Set A = 0 so we can zero the variables .prun16 STA T,X \ Zero the X-th byte from T DEX \ Decrement the loop counter BPL prun16 \ Loop back until we have zeroed all six bytes \ In part 2 above, we set (xTemp2Top xTemp2Hi) etc. to \ the vector from the anchor point (i.e. point 1) to \ point 2 LDX #2 \ Set a counter in X to work through the three axes (the \ comments below cover the iteration for the x-axis) \ For each axis in turn, we .prun17 LDA #0 \ Set R = 0 STA R LDA xTemp2Top,X \ Set A = xTemp2Top BPL prun18 \ If xTemp2Top is positive, skip the following \ instruction DEC R \ Decrement R to %11111111 \ So by this point, R contains the correct bits to \ rotate into bit 7 of A to retain the sign of A .prun18 \ Set (xTemp1Hi A T) = (xTemp2Top xTemp2Hi 0) / 2 \ \ keeping the sign intact by feeding in bits from R LSR R \ We start with the top byte ROR A STA xTemp1Hi,X LDA xTemp2Hi,X \ Then the high byte ROR A ROR T,X \ And then the low byte LDY #2 \ We now shift right by three places, so set a counter \ in Y .prun19 LSR R \ Set (xTemp1Hi A T) = (xTemp1Hi A T) / 2 ROR xTemp1Hi,X \ ROR A \ keeping the sign intact by feeding in bits from R ROR T,X DEY \ Decrement the loop counter BPL prun19 \ Loop back until we have shifted right by three places \ In all, the above does the following: \ \ (xTemp1Hi A T) = (xTemp2Top xTemp2Hi 0) / 16 \ \ while retaining the sign STA xTemp1Lo,X \ Set (xTemp1Hi xTemp1Lo T) = (xTemp1Hi A T) \ = (xTemp2Top xTemp2Hi 0) / 16 DEX \ Decrement the loop counter to move to the next axis BPL prun17 \ Loop back until we have processed all three axes \ So we have now calculated the vector from point 1 to \ point 2, divided by 16, with the result stored in the \ xTemp1 vector and the variables T, U and V used for \ the lowest bytes, like this: \ \ x-coordinate = (xTemp1Hi xTemp1Lo T) \ y-coordinate = (yTemp1Hi yTemp1Lo U) \ z-coordinate = (zTemp1Hi zTemp1Lo V) \ \ In other words, the xTemp1/T/U/V vector contains 1/16 \ of the full vector between points 5 and 21 LDX #LO(xTemp2Lo) \ Set X so the call to CopyPointToWork copies the \ coordinates to (xTemp2, yTemp2, zTemp2) LDY #5 \ Set Y so the call to CopyPointToWork copies the \ coordinates from point 5 JSR CopyPointToWork \ Copy the coordinates from point 5 to \ (xTemp2, yTemp2, zTemp2) \ So (xTemp2, yTemp2, zTemp2) now contains the \ coordinates of point 5 \ We now calculate the start and end points for the \ dashes in the middle of the runway by starting at \ point 5, and moving up the middle line in steps of \ 1/16 of the distance between points 5 and 21 .prun20 LDX #2 \ Set a counter in X to work through the three axes (the \ comments below cover the iteration for the x-axis) .prun21 CLC \ Set (xTemp2Hi xTemp2Lo W) += (xTemp1Hi xTemp1Lo T) LDA W,X \ ADC T,X \ starting with the lowest bytes STA W,X LDA xTemp2Lo,X \ Then the middle bytes ADC xTemp1Lo,X STA xTemp2Lo,X LDA xTemp2Hi,X \ And then the highest bytes ADC xTemp1Hi,X STA xTemp2Hi,X DEX \ Decrement the loop counter to move to the next axis BPL prun21 \ Loop back until we have added all three axes \ On the first iteration through this code, the full \ (xTemp2Hi xTemp2Lo W) vector contains a point 1/16 \ of the way from point 5 to point 21 LDX #LO(xTemp2Lo) \ Set X so the call to CopyWorkToPoint copies the \ coordinates from (xTemp2, yTemp2, zTemp2) INY \ Increment Y so the call to CopyPointToWork copies the \ coordinates from the next point along the dash line \ (which will be point 6 on the first iteration through \ this code, then point 7, and so on) JSR CopyWorkToPoint \ Copy the coordinates from (xTemp2, yTemp2, zTemp2) \ to point Y, the next point along the dash line CPY #19 \ Loop back to prun20 to move another 1/16 along the BNE prun20 \ dash line, until we have done point 19, meaning we \ have set the coordinates for points 6 through 19 \ (i.e. we have added 14 points, two for each of the \ seven dashes in the middle of the runway) LDX #19 \ Set the status byte for points 1 to 19 to indicate JSR SetPointVisibility \ that their coordinates and visibility have been \ calculated