Skip to navigation


Drawing the track: DrawSteepToRight

Name: DrawSteepToRight [Show more] Type: Subroutine Category: Drawing the track Summary: Draw a verge edge with a steep gradient from left to right Deep dive: Drawing the track verges
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawSegmentEdge (Part 6 of 7) calls DrawSteepToRight

Arguments: X The pixel number to start drawing from, in the range 0 to 7, as it is measured across the two edge bytes that we draw in this routine Y The track line to draw on (0 to 79) SS The scaled yaw delta along the edge to draw TT The scaled pitch delta along the edge to draw RR The pitch angle of the current segment (we stop drawing the edge when Y reaches this value) UU The number of the dash data block where we start drawing JJ The right pixel byte when drawing the edge in the screen buffer, i.e. the fill byte to the right of the edge (S R) Address of the first dash data block in the memory page containing the pixels at the start of the previous edge (Q P) Address of the second dash data block in the memory page containing the pixels at the start of the previous edge (NN MM) Address of the third dash data block in this sequence, i.e. the first memory page of the next dash data block
.DrawSteepToRight LDA jumpSteepRight,X \ Modify the BCC instruction at stlr1 below so that STA stlr1+1 \ it jumps to the destination given in the X-th entry in \ the jumpSteepRight lookup table LDA TT \ Set A = -TT EOR #&FF \ CLC \ This is the starting value for the cumulative slope ADC #1 \ error, which we tally up in A CLC \ Clear the C flag so the next instruction effectively \ becomes a JMP .stlr1 BCC stlr2 \ This instruction was modified above, so it jumps to \ the address specified in the jumpSteepRight table, as \ follows: \ \ * stlr2 when X = 0 \ * stlr3 when X = 1 \ * stlr4 when X = 2 \ * stlr5 when X = 3 \ * stlr6 when X = 4 \ * stlr7 when X = 5 \ * stlr8 when X = 6 \ * stlr9 when X = 7 .stlr2 LDX #0 \ Draw the edge in pixel 0 of the first dash data block JSR DrawVergeByteLeft \ (the leftmost pixel) and draw a fill byte in the \ second dash data block \ \ If we have reached the pitch angle of the current \ segment, then we have reached the end of the edge to \ draw, in which case DrawVergeByteLeft will jump to \ StopDrawingEdge to abort this edge and return us two \ routines up the call stack, to DrawSegmentEdge \ We now do the slope error calculation for pixel 0 of \ the first dash data block ADC SS \ Set A = A + SS, to add the yaw delta to the slope \ error BCC stlr2 \ If the addition didn't overflow, skip to the next \ pixel to step along the y-axis, as the cumulative \ pitch deltas haven't yet added up to a multiple of TT \ If we get here then the pitch deltas have added up to \ a whole line and the addition has overflowed, so we \ need to draw a pixel SBC TT \ If we get here then the cumulative yaw deltas in SS \ have added up to a multiple of the pitch delta in TT, \ so we subtract TT from the slope error (which we can \ do as we know the C flag is set) .stlr3 LDX #1 \ Draw the edge in pixel 1 of the first dash data block JSR DrawVergeByteLeft \ (the second pixel) and draw a fill byte in the second \ dash data block, or abort the drawing and return to \ DrawSegmentEdge if we've finished drawing the edge ADC SS \ Repeat the slope error calculation for pixel 1 BCC stlr3 \ of the first dash data block SBC TT .stlr4 LDX #2 \ Draw the edge in pixel 2 of the first dash data block JSR DrawVergeByteLeft \ (the third pixel) and draw a fill byte in the second \ dash data block, or abort the drawing and return to \ DrawSegmentEdge if we've finished drawing the edge ADC SS \ Repeat the slope error calculation for pixel 2 BCC stlr4 \ of the first dash data block SBC TT .stlr5 LDX #3 \ Draw the edge in pixel 3 of the first dash data block JSR DrawVergeByteLeft \ (the rightmost pixel) and draw a fill byte in the \ second dash data block, or abort the drawing and \ return to DrawSegmentEdge if we've finished drawing \ the edge ADC SS \ Repeat the slope error calculation for pixel 3 BCC stlr5 \ of the first dash data block SBC TT INC UU \ Increment UU so we now draw in the right pair of dash \ data blocks (i.e. the second and third dash data \ blocks of the three that we set up) .stlr6 LDX #0 \ Draw the edge in pixel 0 of the second dash data block JSR DrawVergeByteRight \ (the leftmost pixel) and draw a fill byte in the third \ dash data block, or abort the drawing and return to \ DrawSegmentEdge if we've finished drawing the edge ADC SS \ Repeat the slope error calculation for pixel 0 BCC stlr6 \ of the second dash data block SBC TT .stlr7 LDX #1 \ Draw the edge in pixel 1 of the second dash data block JSR DrawVergeByteRight \ (the second pixel) and draw a fill byte in the third \ dash data block, or abort the drawing and return to \ DrawSegmentEdge if we've finished drawing the edge ADC SS \ Repeat the slope error calculation for pixel 1 BCC stlr7 \ of the second dash data block SBC TT .stlr8 LDX #2 \ Draw the edge in pixel 2 of the second dash data block JSR DrawVergeByteRight \ (the third pixel) and draw a fill byte in the third \ dash data block, or abort the drawing and return to \ DrawSegmentEdge if we've finished drawing the edge ADC SS \ Repeat the slope error calculation for pixel 2 BCC stlr8 \ of the second dash data block SBC TT .stlr9 LDX #3 \ Draw the edge in pixel 3 of the second dash data block JSR DrawVergeByteRight \ (the rightmost pixel) and draw a fill byte in the \ third dash data block, or abort the drawing and return \ to DrawSegmentEdge if we've finished drawing the edge ADC SS \ Repeat the slope error calculation for pixel 2 BCC stlr9 \ of the second dash data block SBC TT INC S \ Increment S to move (S R) on to the next page, to move \ it right by two dash data blocks INC Q \ Increment Q to move (Q P) on to the next page, to move \ it right by two dash data blocks INC NN \ Increment NN to move (NN MM) on to the next page, to \ move it right by two dash data blocks INC UU \ Increment UU to the number of the next dash data block \ to the right LDX S \ If (S R) hasn't yet reached the rightmost dash data CPX #HI(dashData39)+1 \ block (i.e. it hasn't gone past block 39, which is at BNE stlr2 \ the right edge of the screen), then jump back to shlr2 \ to keep drawing RTS \ Return from the subroutine