Skip to navigation

Aviator on the BBC Micro

Visibility: ProcessLine (Part 3 of 7)

Name: ProcessLine (Part 3 of 7) [Show more] Type: Subroutine Category: Visibility Summary: If a line is part of a multi-point object, extract the other points in the line so we can check them all Deep dive: Visibility checks
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.plin2 \ If we get here, lineId >= 12 and Y contains the point \ ID for the line's start point \ \ We now run through the following process twice, first \ for the line's start point, and then for the line's \ end point LDA #2 \ Set pointCount = 2 to act as a counter so we can check STA pointCount \ the start point first, and then the end point .plin3 LDA pointStatus,Y \ If bit 7 of the point's status byte is clear, then the BPL plin4 \ point has not yet had its coordinates and visibility \ calculated, so skip the following instruction to move \ on to those calculations JMP plin17 \ Bit 7 of the point's status byte is set, which means \ we have already calculated this point's coordinates \ and visibility, so jump to plin17 to do the final \ distance and z-coordinate tests .plin4 \ We get here if we haven't already calculated the \ coordinates and visibility for the point whose ID is \ in Y, so that's what we do now TYA \ Store the point ID of this point on the stack and in PHA \ pointId. We are about to check whether this point is STA pointId \ part of a multi-point object, and if so we're going to \ add the IDs of all the other points in the object to \ the stack and then work our way through the stacked \ values, processing each of them in turn \ \ Adding the starting point ID to the stack and to \ pointId at the same time lets us use this ID as a \ backstop - in other words, we'll know we have \ processed all the other point that we added to the \ stack when we pull a value off the stack that matches \ the value of pointId (see parts 5 and 6 to see this in \ action) .plin5 LDA objectPoints,Y \ Fetch this point's entry from objectPoints, which \ will tell us if this point is related to any other \ points as part of a multi-point object CMP #40 \ If object ID < 40 then this point does not link to BCC plin8 \ another point, so it's the last point in a linked \ object - i.e. the ID of the object itself - so jump to \ plin8 to process the point and any others we already \ put on the stack \ If we get here then this point links to another point \ in objectPoints, so we now follow the links and add \ all of the point IDs to the stack and to the \ relatedPoints list, looping back until we reach the \ last point, at which point we jump to plin8 with a \ stack full of points SEC \ Subtract 40 from A to get the point ID of the new SBC #40 \ point to check STA objectAnchorPoint \ Store the new point's ID as the object's anchor point, \ so it contains the ID of the last point before the \ object ID at the end of the linked list of points TAY \ Copy the new point's ID into Y so we can use it as an \ index into pointStatus LDA pointStatus,Y \ If bit 7 of the new point's status byte is set, then BMI plin14 \ we have already calculated the coordinates and \ visibility for this new point, which means we have \ also done the rest of the points in the linked object, \ so jump down to plin14 to check the new points we \ added to the stack TYA \ Set A = the new point's ID PHA \ Store the new point's ID on the stack LDX relatedPoints \ If relatedPoints >= 49, then the relatedPoints list is CPX #49 \ full, so jump to plin11 to set this line as not being BCS plin11 \ visible INC relatedPoints \ Increment the value in relatedPoints, which contains \ the size of the list, as we are about to add a new \ entry to the end of the list LDX relatedPoints \ Add A, the new point's ID, to the end of the STA relatedPoints,X \ relatedPoints list BNE plin5 \ Jump back to plin5 to recurse through the new point \ (this BNE is effectively a JMP as A is never zero, \ because objectPoints does not contain a value of 40)