.tred35 \ If we get here then at least one of xEdgeStartHi and \ xEdgeEndHi is non-zero LDA xEdgeStartLo \ Set xEdgeDelta = xEdgeStart(Hi Lo) - xEdgeEnd(Hi Lo) SEC \ SBC xEdgeEndLo \ So xEdgeDelta contains the x-axis delta along the edge STA xEdgeDelta \ we are tracing (we can discard the high byte as we LDA xEdgeStartHi \ know it will be zero) SBC xEdgeEndHi BPL tred36 \ If the result is positive, jump to tred36 to skip the \ following, as the delta is already the correct sign \ for the absolute value \ If we get here then xEdgeDelta is negative and the \ start point is to the left of the end point LDA #0 \ Negate xEdgeDelta as follows: SEC \ SBC xEdgeDelta \ xEdgeDelta = 0 - xEdgeDelta STA xEdgeDelta \ \ So xEdgeDelta is positive and contains the absolute \ value of the x-axis delta LDX #&E8 \ Set A to the opcode for the INX instruction, so we \ trace along the edge by incrementing X LDA #%00000000 \ Set A to use as the high byte in yEdgeDeltaHi for a \ positive 16-bit number LDY #&E6 \ Set Y to the opcode for the INC zp instruction, so we \ trace along the edge by incrementing Y JMP tred37 \ Jump to tred37 to keep going .tred36 \ If we get here then xEdgeDelta is positive and the \ start point is to the right of the end point LDX #&CA \ Set A to the opcode for the DEX instruction, so we \ trace along the edge by decrementing X LDA #%11111111 \ Set A to use as the high byte in yEdgeDeltaHi for a \ negative 16-bit number LDY #&C6 \ Set Y to the opcode for the DEC zp instruction, so we \ trace along the edge by decrementing Y .tred37 STY T \ Store the INC/DEC opcode in T so we can retrieve it \ in parts 7 and 8 STA yEdgeDeltaHi \ Set the high byte of yEdgeDelta(Hi Lo) to be negative \ when we are moving along the x-axis from right to left \ and positive when we are moving along the x-axis from \ left to right LDY xEdgeDelta \ Set the status flags on the comparison of xEdgeDelta CPY yEdgeDeltaLo \ and yEdgeDeltaLo, so we can decide which axis has the \ longer side along the polygon edge (and therefore \ which axis we should step along when tracing the edge) LDY yEdgeStartLo \ Set (A Y) = (xPolygonAddrHi yEdgeStartLo) to use as LDA xPolygonAddrHi \ the storage address in the modification below BCS tred46 \ If xEdgeDelta >= yEdgeDeltaLo then the x-axis delta is \ the biggest and the edge has a shallow gradient, so \ jump to part 8 to trace the edge by stepping along the \ x-axis \ Otherwise the edge has a steep gradient, so fall \ through into part 7 to trace the edge by stepping \ along the y-axisName: TracePolygonEdge (Part 6 of 8) [Show more] Type: Subroutine Category: Drawing polygons Summary: Trace a polygon edge where the start or end point x-coordinates are two-byte numbersContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Label tred36 is local to this routine
[X]
Label tred37 is local to this routine
[X]
Label tred46 in subroutine TracePolygonEdge (Part 8 of 8)
[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 xEdgeEndHi in workspace Zero page
The x-coordinate of the end point in the polygon edge being processed (high byte)
[X]
Variable xEdgeEndLo in workspace Zero page
The x-coordinate of the end point in the polygon edge being processed (low byte)
[X]
Variable xEdgeStartHi in workspace Zero page
The x-coordinate of the start point in the polygon edge being processed (high 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 xPolygonAddrHi in workspace Zero page
The high byte of the address of the table where we store the x-coordinate of the polygon line being processed, so this is either HI(xPolygonLeft) or HI(xPolygonRight)
[X]
Variable yEdgeDeltaHi in workspace Zero page
The difference in pitch angle between two polygon points, i.e. the delta along the y-axis (high 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)
[X]
Variable yEdgeStartLo in workspace Zero page
The y-coordinate of the start point in the polygon edge being processed (low byte)