Skip to navigation


Graphics: DrawCanopyView

Name: DrawCanopyView [Show more] Type: Subroutine Category: Graphics Summary: Draw the main view out of the canopy Deep dive: Flicker-free animation through colour cycling
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainLoop (Part 13 of 15) calls DrawCanopyView
.DrawCanopyView JSR ModifyDrawRoutine \ Modify the drawing routines to use the current colour \ cycle LDA linesToShowEnd \ If linesToShowEnd is non-zero, jump to view1 to skip BNE view1 \ the following instruction, as there are lines in the \ linesToShow list that we need to draw BEQ view6 \ linesToShowEnd is zero, which means the linesToShow \ list is empty, so there is nothing to draw, so we \ jump down to view6 to flip the colours (this BEQ is \ effectively a JMP as we know A is zero) .view1 LDA #0 \ Set lineCounter = 0 to act as a counter in the STA lineCounter \ following loop, where we loop through the linesToShow \ list .view2 TAX \ Set lineId to the next line ID from the linesToShow LDA linesToShow,X \ list STA lineId BNE view3 \ If lineId is non-zero, jump to view3, as this is not \ the horizon JSR DrawHalfHorizon \ The line ID is 0, which is the horizon, so draw half \ of the horizon line (as only half of the horizon is \ stored in line 0) LDA lineId \ Retrieve the line's ID, as it will have been corrupted \ by the call to DrawHalfHorizon, and fall through into \ view3 to draw the other half of the horizon .view3 TAX \ Set M to the point ID for the line's end point LDY lineEndPointId,X STY M LDA #0 \ Zero the end point's status byte, so it is no longer STA pointStatus,Y \ marked as having had its coordinates and visibility \ calculated LDY lineStartPointId,X \ Set L to the point ID for the line's start point STY L STA pointStatus,Y \ Zero the start point's status byte, so it is no longer \ marked as having had its coordinates and visibility \ calculated JSR DrawClippedLine \ Draw the line, clipping it to the canopy view if \ required INC lineCounter \ Increment the loop counter LDA lineCounter \ Loop back to draw the next line from the linesToShow CMP linesToShowEnd \ list BCC view2 JSR DrawGunSights \ Draw the gun sights, if shown \ We now flip the screens between the old screen (which \ is being shown in white) and the new one (which we \ just drew in black) LDA colourCycle \ If bit 7 of colourCycle is set, i.e. %11110000, jump BMI view4 \ down to view4 to hide colour 1 and show colour 2 \ If we get here then colourCycle is %00001111 LDX #2 \ Set logical colour 2 to black, to hide the old canopy JSR SetColourToBlack \ view in colour 2 LDX #1 \ Set logical colour 1 to white, to show the new canopy JSR SetColourToWhite \ view that we just drew in colour 1 JMP view5 \ Now that we have cycled the colours, jump down to \ view5 .view4 \ If we get here then colourCycle is %11110000 LDX #1 \ Set logical colour 1 to black, to hide the old canopy JSR SetColourToBlack \ view in colour 1 LDX #2 \ Set logical colour 2 to white, to show the new JSR SetColourToWhite \ view that we just drew in colour 2 .view5 JSR EraseCanopyLines \ Erase the lines that are now hidden, and which are \ stored in the relevant line buffer .view6 JSR FlipColours \ Flip the values of colourCycle and colourLogic to \ cycle to the next colour state RTS \ Return from the subroutine