Skip to navigation


Drawing lines: EraseCanopyLines

Name: EraseCanopyLines [Show more] Type: Subroutine Category: Drawing lines Summary: Draw all the lines from a line buffer to erase them Deep dive: Line buffers
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawCanopyView calls EraseCanopyLines

We call this routine from DrawCanopyView, after drawing all the new lines and just before we flip colours. See the DrawCanopyView routine for more details of the colour-cycling system that this forms part of. This is what the EraseCanopyLines routine does: If colourCycle = %00001111, then colour 1 is white and colour 2 is black: * Draw the lines in line buffer 1, using AND logic and bit pattern %00001111 * Colour 2 on-screen is %11110000, so AND'ing with %00001111 gives 0 * So this erases all the lines in buffer 1, which are on-screen in colour 2 i.e. we erase all the lines in line buffer 1 from the hidden screen If colourCycle = %11110000, then colour 1 is black and colour 2 is white: * Draw the lines in line buffer 2, using AND logic and bit pattern %11110000 * Colour 1 is %00001111, so AND'ing with %11110000 gives 0 * So this erases all the lines in buffer 2, which are on-screen in colour 1 i.e. we erase all the lines in line buffer 2 from the hidden screen
.EraseCanopyLines LDA #%00000000 \ Set colourLogic = %00000000 so when we draw a line, it STA colourLogic \ erases it JSR ModifyDrawRoutine \ Modify the drawing routines to use AND logic and the \ bit patterns that match colourCycle .ecal1 LDA colourCycle \ If bit 7 of colourCycle is clear, i.e. %00001111, jump BPL ecal3 \ down to ecal3 \ If we get here, colourCycle is %11110000 LDX lineBuffer2Count \ If lineBuffer2Count <> 47, line buffer 2 is not CPX #47 \ empty, so jump down to ecal2 to draw the next line BNE ecal2 \ from the buffer RTS \ Return from the subroutine .ecal2 DEC lineBuffer2Count \ Decrement the value in lineBuffer2Count as we are \ about to draw the next line from buffer 2 JMP ecal5 \ Jump down to ecal5 to draw the next line from buffer 2 .ecal3 LDX lineBuffer1Count \ If lineBuffer1Count <> -1, line buffer 1 is not CPX #255 \ empty, so jump down to ecal4 to draw the next line BNE ecal4 \ from the buffer RTS \ Return from the subroutine .ecal4 DEC lineBuffer1Count \ Decrement the value in lineBuffer1Count as we are \ about to draw the next line from buffer 1 .ecal5 \ We now fetch the next line from the line buffer LDA lineBufferR,X \ Set R to the start x-coordinate from lineBufferR STA R STA xTemp1Lo \ Set the x-coordinate of (R, S) = (xTemp1Lo, yTemp1Lo) \ so we can access it in the DrawCanopyLine routine LDA lineBufferW,X \ Set W to the max/min x-coordinate from lineBufferW STA W LDA lineBufferS,X \ Set S to the start y-coordinate from lineBufferS STA S STA yTemp1Lo \ Set the y-coordinate of (R, S) = (xTemp1Lo, yTemp1Lo) \ so we can access it in the DrawCanopyLine routine LDA lineBufferG,X \ Set G to max/min y-coordinate from lineBufferG STA G LDA lineBufferT,X \ Set T to the |x-delta| from lineBufferT STA T LDA lineBufferU,X \ Set U to the |y-delta| from lineBufferU STA U LDA lineBufferV,X \ Set V to the direction from lineBufferV STA V JSR DrawCanopyLine \ Draw the line (to erase it) JMP ecal1 \ Loop back to ecal1 to erase the next line EQUB &17 \ This byte appears to be unused