.GetPolygonLines LDA xTileToDraw \ Set A to the drawing table offset plus the column ORA drawingTableOffset \ number of the tile we are currently drawing, so if we \ are drawing a tile, this is the offset of the first \ point of the tile in the drawing tables \ \ So A is the position in the drawViewYaw(Hi Lo) and \ drawViewPitch(Hi Lo) tables of the tile corners \ \ The four points are laid out with the front edge in \ one drawing table offset (0 or 32) and the back edge \ in the other drawing table offset (32 or 0), and the \ left-right points are together in the same offset \ \ Specifically, the four tile corners will be offset in \ the drawing tables in one of two layouts \ \ This is the layout when drawingTableOffset = 0: \ \ offset x offset x + 1 \ \ offset 32 + x offset 32 + x + 1 \ \ where x is xTileToDraw and the top row is the back row \ away from the viewer \ \ And this is the layout when drawingTableOffset = 32: \ \ offset 32 + x offset 32 + x + 1 \ \ offset x offset x + 1 \ \ So the offset in A will point to the drawing data for \ the top-left point above, i.e. the rear left tile \ corner from the perspective of the viewer \ \ Also, consider the above layouts and how we can move \ between the corners: \ \ * We can move from left to right by adding 1 to the \ offset, and from right to left by subtracting 1 \ \ * We can move between the top and bottom rows by \ using EOR #32 on the offset, as this will flip \ between x and x + 32 \ \ We use these calculations to work out which points in \ the drawing table we should map to points 1 to 5 in \ polygonPoint for use in the polygon-drawing process BIT polygonType \ If bit 7 of polygonType is set then we are drawing a BMI gpol1 \ two-face tile as a pair of triangles, so jump to gpol1 \ to do this BVS gpol7 \ If bit 7 of polygonType is clear and bit 6 is set then \ we are drawing an object, so jump to part 4 as the \ point numbers in polygonPoint are already set up \ correctly for the polygon \ If we get here then both bits 6 and 7 of polygonType \ are clear, so we are drawing a tile as a four-sided \ shape (quadrilateral) and A contains the offset of the \ rear left tile corner in the drawing tables \ \ For a quadrilateral, we number the points like \ this: \ \ 1. Rear left 4. Rear right \ \ 2. Front left 3. Front right \ \ We also set point 5 to be the same as point 1, so that \ the fourth edge from point 4 to point 5 is effectively \ from point 4 to point 1 STA polygonPoint \ Set the first quadrilateral point to the rear-left \ tile corner STA polygonPoint+4 \ Set the fifth quadrilateral point to A, so the fourth \ edge in the quadrilateral joins with the start of the \ first edge EOR #32 \ Set the second quadrilateral point to the front-left STA polygonPoint+1 \ tile corner CLC \ Set the third quadrilateral point to the front-right ADC #1 \ tile corner STA polygonPoint+2 EOR #32 \ Set the fourth quadrilateral point to the rear-right STA polygonPoint+3 \ tile corner LDX #4 \ Set X = 4 to set as the value of polygonEdgeCount as \ there are four edges in a quadrilateral .gpol3 STX polygonEdgeCount \ Set polygonEdgeCount to the value in X JMP gpol7 \ Jump to part 4 to continue analysing the polygonName: GetPolygonLines (Part 2 of 6) [Show more] Type: Subroutine Category: Drawing polygons Summary: The main entry point for the routine to calculate the horizontal lines in filled polygon and prepare them for drawing on-screenContext: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawPolygon calls GetPolygonLines
Arguments: polygonType The polygon type 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)
Returns: C flag Status flag: * Clear if the polygon is visible in the current screen buffer and should be drawn * Set if the polygon is not visible in the current screen buffer and should not be drawn yPolygonTop The y-coordinate of the top of the polygon (where higher y-coordinates are up the screen) yPolygonBottom The y-coordinate of the bottom of the polygon (where higher y-coordinates are up the screen) xPolygonLeft The pixel x-coordinates of the left edges of each pixel line in the polygon xPolygonRight The pixel x-coordinates of the right edges of each pixel line in the polygon
[X]
Variable drawingTableOffset in workspace Zero page
The offset to use within the various drawing data tables for the tile we are analysing
[X]
Label gpol1 in subroutine GetPolygonLines (Part 1 of 6)
[X]
Label gpol7 in subroutine GetPolygonLines (Part 4 of 6)
[X]
Variable polygonEdgeCount in workspace Zero page
The number of sides in the polygon we are drawing, which is one less than the number of points in the polygon's point list (as the last point in the list is always a repeat of the first point)
[X]
Variable polygonPoint in workspace Main variable workspace
Up to five coordinates for the points of the polygon being drawn
[X]
Variable polygonType in workspace Zero page
Bits 6 and 7 determine the type of polygon to draw in the DrawPolygon routine (the calling subroutine is in brackets)
[X]
Variable xTileToDraw in workspace Zero page
The column number of the tile we are currently drawing