Skip to navigation

Drawing polygons: GetPolygonLines (Part 3 of 6)

Name: 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
.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 polygon