.tred26 INC tred13+1 \ Increment the low byte of the address in the STX \ instruction at tred13 to balance out the additional \ DEC tred13+1 that we do below when we rejoin the \ loop in part 2 LDX tred12 \ Modify the instruction at tred28 so it matches the STX tred28 \ modified instruction at tred12, so that's: \ \ * INX (if we are stepping right along the edge) \ \ * DEX (if we are stepping left along the edge) \ \ So in either case this steps us along the x-axis by \ one pixel LDX xEdgeStartLo \ Set X to the x-coordinate of the starting point, so we \ can start tracing from the start of the edge \ The loop below has the same structure as the loop in \ part 2 between tred11 and tred15, and which we enter \ via tred13, but in this version of the loop we do not \ store the coordinates of the edge, as the portion we \ are currently tracing is off-screen JMP tred29 \ Jump into the middle of the loop at tred29 to trace \ the edge but without storing the results .tred27 ADC xEdgeDelta \ Add the x-axis delta to the slope error in A, so we \ keep track of the slope error as we move along the \ y-axis BCC tred29 \ If the addition didn't overflow then we have not moved \ into a new x-coordinate with this step along the \ y-axis, so jump to tred29 so we do not move along the \ x-axis \ If we get here then the addition overflowed and the \ cumulative slope error along the x-axis has added up \ to a whole pixel, so we now need to step along the \ x-axis by a pixel SBC yEdgeDeltaLo \ Set A = A - yEdgeDeltaLo \ \ This updates the slope error in A \ \ This subtraction works as we just passed through a \ BCC, so we know the C flag is set .tred28 INX \ This instruction is modified above to: \ \ * INX (if we are stepping right along the edge) \ \ * DEX (if we are stepping left along the edge) \ \ So in either case this steps us along the x-axis by \ one pixel .tred29 DEC tred13+1 \ Decrement the low byte of the address in the STX \ instruction at tred13 so that it points to the table \ entry for the next y-coordinate down BEQ tred30 \ If we just decremented the low byte of the address to \ zero then we have finished stepping along the y-axis \ for this value of the high byte, so the next address \ we decrement it to will be on-screen \ \ We therefore jump to tred30 to set the address for the \ top of the screen and rejoin the edge-tracing loop in \ part 2 to keep tracing the edge DEY \ Decrement the pixel counter in Y BNE tred27 \ Loop back to keep tracing the polygon edge until we \ have worked our way through all the pixels along the \ y-axis JMP tred16 \ If we get here then we have finished tracing the edge \ and we didn't reach an on-screen portion, so jump to \ tred16 to return from the subroutine without changing \ drawPolygon (as we didn't draw anything in this \ routine) .tred30 DEC tred13+1 \ Decrement the low byte of the address in the STX \ instruction at tred13 to &FF (as we only get here when \ we have just decremented it to zero), so it now points \ to the address for the top line of the screen at a \ y-coordinate of 255 JMP tred14 \ Jump to tred25 to rejoin the normal edge-tracing loop \ in part 2 so we trace the rest of the edgeName: TracePolygonEdge (Part 4 of 8) [Show more] Type: Subroutine Category: Drawing polygons Summary: Trace a steep edge that starts off-screen, without storing the coordinates, until we reach the screen and return to part 2Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Label tred12 in subroutine TracePolygonEdge (Part 2 of 8)
[X]
Label tred13 in subroutine TracePolygonEdge (Part 2 of 8)
[X]
Label tred14 in subroutine TracePolygonEdge (Part 2 of 8)
[X]
Label tred16 in subroutine TracePolygonEdge (Part 2 of 8)
[X]
Label tred27 is local to this routine
[X]
Label tred28 is local to this routine
[X]
Label tred29 is local to this routine
[X]
Label tred30 is local to this routine
[X]
Variable xEdgeDelta in workspace Zero page
The scaled and signed x-axis delta between two polygon points when tracing the polygon edges (single byte)
[X]
Variable xEdgeStartLo in workspace Zero page
The x-coordinate of the start point in the polygon edge being processed (low byte)
[X]
Variable yEdgeDeltaLo in workspace Zero page
The difference in pitch angle between two polygon points, i.e. the delta along the y-axis (low byte)