.gpol4 LDA #%11000000 \ Set bit 6 of xPolygonPointScale to indicate that the STA xPolygonPointScale \ pixel x-coordinate of this polygon point needs to be \ stored as a two-byte number LDY polygonEdgeCount \ We now loop through all the points in the polygon, so \ set Y to count through the number of edges in the \ polygon that we are drawing (as that's also the number \ of unique points in the polygon) .gpol5 LDA (drawViewAngles),Y \ Set X to the offset within the drawing tables of the TAX \ Y-th point in the polygon LDA drawViewYawLo,X \ Set the following: CLC \ ADC bufferOriginLo \ (A T) = drawViewYaw(Hi Lo) + bufferOrigin(Hi Lo) STA T \ LDA drawViewYawHi,X \ for the Y-th polygon point, so this adds the yaw angle ADC bufferOriginHi \ offset in bufferOrigin(Hi Lo) to the polygon point \ \ The yaw angles in drawViewYaw(Hi Lo) are relative to \ the origin in the centre of the screen (i.e. the \ direction of the viewer's gaze), so this converts the \ yaw angle from having the origin in the centre to \ having the origin on the left edge of the buffer ASL T \ Set (A T) = (A T) * 8 ROL A \ ROL T \ So (A T) contains the yaw angle in pixels, which is ROL A \ the same as a pixel x-coordinate, with the integer ROL T \ part in A and the fractional part in T ROL A \ \ Also, the top three bits of the original A are in the \ bottom two bits of T and the C flag, as all but the \ first instruction are rotations rather than shifts STA xPolygonPointLo,X \ Store the pixel x-coordinate for the Y-th point of the \ polygon in the xPolygonPointLo table, storing the \ result at the offset given in the drawViewAngles table \ (i.e. in the correct place for the polygon point \ number in Y) \ \ This stores the low byte of the two-byte value in \ (A T) * 8, so now we calculate and store the high byte LDA T \ Rotate the C flag into bit 0 of T and put the result ROL A \ in A, so top three bits of the original A are now in \ the bottom three bits of A AND #%00000111 \ Clear all the other bits in A, so A just contains the \ top three bits of the original A \ \ In other words, A now contains the overflow from the \ left-shifted (A T), which spilled out into a third top \ byte when the multiplication was applied CMP #%00000100 \ If bit 2 of A is set then bit 7 of the original A must BCC gpol6 \ have been set so the original yaw angle must have been ORA #%11111000 \ negative, so set bits 3 to 7 of the top byte .gpol6 STA xPolygonPointHi,X \ Store the pixel x-coordinate for the Y-th point of the \ polygon in the xPolygonPointHi table, storing the \ result at the offset given in the drawViewAngles table \ (i.e. in the correct place for the polygon point \ number in Y) \ \ This stores the high byte of the two-byte value in \ (A T) * 8 \ \ So this calculation is for polygon points that have a \ pixel x-coordinate greater than 255 (as recorded by \ the set bit 6 in xPolygonPointScale) DEY \ Decrement the point counter in Y BPL gpol5 \ Loop back until we have converted all the polygon \ point yaw angles into pixel x-coordinates JMP gpol9 \ Jump to part 5 to continue analysing the polygonName: GetPolygonLines (Part 3 of 6) [Show more] Type: Subroutine Category: Drawing polygons Summary: Convert all the polygon point yaw angles into pixel x-coordinates (for larger yaw angles that convert into a 16-bit x-coordinate)Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Variable bufferOriginHi in workspace Zero page
The offset to add to yaw angles for the current screen buffer to convert them from having the origin in the buffer centre to having the origin on the left edge of the buffer (high byte)
[X]
Variable bufferOriginLo in workspace Zero page
The offset to add to yaw angles for the current screen buffer to convert them from having the origin in the buffer centre to having the origin on the left edge of the buffer (low byte)
[X]
Variable drawViewAngles in workspace Zero page
The address in drawViewAngles(1 0) of the pitch and yaw angles of the tile and polygon points that we are drawing in the landscape view
[X]
Variable drawViewYawHi (category: Drawing the landscape)
Storage for the yaw angles of tiles and object points for drawing the current landscape view (high bytes)
[X]
Variable drawViewYawLo (category: Drawing the landscape)
Storage for the yaw angles of tiles and object points for drawing the current landscape view (low bytes)
[X]
Label gpol5 is local to this routine
[X]
Label gpol6 is local to this routine
[X]
Label gpol9 in subroutine GetPolygonLines (Part 5 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 xPolygonPointHi (category: Drawing polygons)
Pixel x-coordinates for all the points in the polygon that we are currently drawing (high bytes)
[X]
Variable xPolygonPointLo (category: Drawing polygons)
Pixel x-coordinates for all the points in the polygon that we are currently drawing (low bytes)
[X]
Variable xPolygonPointScale in workspace Zero page
A flag to record whether the pixel x-coordinate of the polygon points being processed fit into one or two bytes