.DrawPolygon LDY screenBufferType \ If screenBufferType >= 2 then we are drawing into the CPY #2 \ column buffer, so jump to poly2 as the column is BCS poly2 \ always drawn in one stage \ If we get here then screenBufferType must be 0 or 1 \ and we are drawing into the left or right row buffer \ \ The left row buffer covers the leftmost 256 bytes of \ each screen row, while the right row buffer covers the \ remaining 64 bytes \ \ It would be possible to draw the polygon into both \ buffers at once, but drawing it separately is more \ efficient as we don't need to manage the x-coordinate \ as a 16-bit value JSR GetPolygonLines \ Calculate the horizontal lines that make up the filled \ polygon and prepare them for drawing into the screen \ buffer BCS poly1 \ If the call to GetPolygonLines set the C flag then the \ polygon is not visible in the screen buffer and should \ not be drawn, so jump to poly1 to skip the following JSR DrawPolygonLines \ Draw the polygon into the screen buffer, drawing the \ shape from top to bottom, horizontal and line by line LDY screenBufferType \ Set A to the following: LDA polygonGoesRight,Y \ \ * polygonGoesRight when screenBufferType = 0 (we \ have just drawn into the left row buffer) \ \ * polygonIsToLeft when screenBufferType = 1 (we \ have just drawn into the right row buffer) CMP #1 \ If A = 1 then we do not need to draw in the other row BEQ poly3 \ buffer, because the polygon we just drew does not \ extend beyond the relevant edge of the buffer \ \ More specifically: \ \ * If we have just drawn into the left row buffer and \ polygonGoesRight = 1, then the polygon does not \ extend right out of the left row buffer, so we \ don't need to draw anything into the right row \ buffer \ \ * If we have just drawn into the right row buffer \ and polygonGoesLeft = 1, then the polygon does not \ extend left out of the right row buffer, so we \ don't need to draw anything into the left row \ buffer \ \ In either case, jump to poly3 to return from the \ subroutine without drawing the polygon into the other \ row buffer .poly1 \ We have drawn the relevant parts of the polygon into \ either the left row buffer or right row buffer and the \ polygon extends into the other row buffer, so now we \ draw the polygon into the other row buffer JSR FlipBufferType \ Flip the buffer type between 0 and 1 to swap between \ the left row buffer and right row buffer, and \ configure the new buffer accordingly .poly2 JSR GetPolygonLines \ Calculate the horizontal lines that make up the filled \ polygon and prepare them for drawing into the screen \ buffer BCS poly3 \ If the call to GetPolygonLines set the C flag then the \ polygon is not visible in the screen buffer and should \ not be drawn, so jump to poly3 to skip the following JSR DrawPolygonLines \ Draw the polygon into the screen buffer, drawing the \ shape from top to bottom, horizontal and line by line .poly3 RTS \ Return from the subroutineName: DrawPolygon [Show more] Type: Subroutine Category: Drawing polygons Summary: Draw a polygonContext: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawObject calls DrawPolygon * DrawOneFaceTile calls DrawPolygon * DrawTwoFaceTile calls DrawPolygon
Arguments: polygonType Bits 6 and 7 determine the type of polygon to draw (the calling subroutine is in brackets): * %00xxxxxx = quadrilateral (DrawOneFaceTile) * %01xxxxxx = object polygon (DrawObject) * %10xxxxxx = first triangle (DrawTwoFaceTile) * %11xxxxxx = second triangle (DrawTwoFaceTile) screenBufferType The type of buffer to use: * 0 = left row buffer (for up/down pan) for the first 256 bytes of the 320-byte row * 1 = right row buffer (for up/down pan) for the last 64 bytes of the 320-byte row * 2 = column buffer (for left/right pan) drawViewAngles The point data: * When drawing tile faces, this points to polygonPoint * When drawing object polygons, this points to a list of object-relative numbers of polygon points triangleStartPoint When drawing a two-face tile as a pair of triangles, this is the number of the starting point to use (0 or 1)
[X]
Subroutine DrawPolygonLines (Part 1 of 4) (category: Drawing polygons)
Draw an analysed polygon into the screen buffer
[X]
Subroutine FlipBufferType (category: Screen buffer)
Flip the buffer type between buffer type 0 (left row buffer) and buffer type 1 (right row buffer)
[X]
Subroutine GetPolygonLines (Part 2 of 6) (category: Drawing polygons)
The main entry point for the routine to calculate the horizontal lines in filled polygon and prepare them for drawing on-screen
[X]
Label poly1 is local to this routine
[X]
Label poly2 is local to this routine
[X]
Label poly3 is local to this routine
[X]
Variable polygonGoesRight in workspace Zero page
A flag to record whether the polygon we are drawing extends to the right of the screen buffer we are drawing in
[X]
Variable screenBufferType in workspace Zero page
The type of screen buffer that is currently being used