Skip to navigation

Aviator on the BBC Micro

Visibility: UpdateLinesToShow

Name: UpdateLinesToShow [Show more] Type: Subroutine Category: Visibility Summary: Update the linesToShow list, moving any lines that aren't visible into the linesToHide list Deep dive: Visibility checks
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainLoop (Part 5 of 15) calls UpdateLinesToShow
.UpdateLinesToShow LDX linesToShowEnd \ If the linesToShow list is empty, jump to upll5 to BEQ upll5 \ return from the subroutine, as there is nothing to \ process LDA #255 \ Set linesToShowPointer = 255, to use as a pointer STA linesToShowPointer \ to the end of the new linesToShow list as we build it \ up in-situ LDA #0 \ Set lineCounter = 0, to use as a line counter as we STA lineCounter \ loop through the linesToShow list .upll1 LDX lineCounter \ Set lineId to the ID of the next line in the LDA linesToShow,X \ linesToShow list STA lineId LDA #1 \ Set HH = 1, so in the following call to ProcessLine STA HH \ we do not check the line's distance against \ maxLineDistance in the visibility checks JSR ProcessLine \ Check whether this line is visible, returning the \ result in showLine LDA lineId \ If lineId = 0, then this is the runway, so skip the BEQ upll2 \ following instruction to keep the line in the list LDX showLine \ If showLine is non-zero then this line is not visible, BNE upll3 \ so jump to upll3 .upll2 \ If we get here then we want to keep this line in the \ linesToShow list INC linesToShowPointer \ Increment the linesToShowPointer pointer to point to \ the next free slot in the new list we are creating LDX linesToShowPointer \ Store the line ID at the end of the new list we are STA linesToShow,X \ creating JMP upll4 \ Jump down to upll4 to move on to the next line in the \ list .upll3 \ If we get here then we do not want to keep this line \ in the linesToShow list, so we need to move it to the \ linesToHide list INC linesToHideEnd \ Increment linesToHideEnd to point to the next free \ entry at the end of the linesToHide list LDX linesToHideEnd \ Add the line ID to the end of the linesToHide list STA linesToHide,X .upll4 INC lineCounter \ Increment the loop counter to point to the next line \ in the linesToShow list LDA lineCounter \ Loop back to process the next line from linesToShow CMP linesToShowEnd \ until we have worked our way to the end BCC upll1 LDA linesToShowPointer \ Set linesToShowEnd = linesToShowPointer + 1 ADC #0 \ STA linesToShowEnd \ so it points to the index of the first empty entry in \ the newly processed linesToShow list .upll5 RTS \ Return from the subroutine