Skip to navigation


Drawing the track: DrawSegmentEdge (Part 6 of 7)

Name: DrawSegmentEdge (Part 6 of 7) [Show more] Type: Subroutine Category: Drawing the track Summary: Calculate the dash data block for the edge Deep dive: Drawing the track verges
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

This part draws the edge for this segment by jumping to the correct drawing routine, depending on the gradient and direction of the edge.
LDA SS \ If SS < TT, then the edge has a steep gradient, so CMP TT \ jump to dver26 to jump to the correct drawing routine BCC dver26 LDA objectPalette \ Set A to the first verge pixel mask that we stored in \ part 3, which is always a four-pixel, single colour \ pixel byte CMP #%11111111 \ If the background colour of the verge pixel mask is BEQ dver21 \ green, jump to dver21 to skip the following LDA backgroundLeft \ Extract bits 0-1 from backgroundLeft, which contain AND #%00000011 \ the colour from the left side of the verge pixel mask, \ i.e. the pixels on the left side of this verge edge CMP #3 \ If %ab = 3, so the colour to the left of the verge BEQ dver21 \ edge is green, jump to dver21 to skip the following \ Otherwise, disable the DrawGrass routines LDA #&60 \ Set A to the opcode for the RTS instruction STA DrawGrassLeft \ Modify the DrawGrassLeft routine to start with an RTS, \ so it returns without doing anything (so it's \ effectively disabled) STA DrawGrassRight \ Modify the DrawGrassRight routine to start with an \ RTS, so it returns without doing anything (so it's \ effectively disabled) BNE dver23 \ Jump to dver23 (this BNE is effectively a JMP as A is \ never zero) .dver21 LDA #&E0 \ Set A to the opcode for the CPX #128 instruction STA DrawGrassLeft \ Revert the DrawGrassLeft routine to start with a CPX \ instruction, so it runs as normal STA DrawGrassRight \ Revert the DrawGrassRight routine start with a CPX \ instruction, so it runs as normal LDA vergeType \ Set A to the type of verge we are drawing CMP #2 \ Set bit 7 of A if vergeType >= 2, so we get: ROR A \ \ * Bit 7 clear when we are drawing leftVergeStart or \ leftTrackStart \ \ * Bit 7 set when we are drawing rightVergeStart or \ rightGrassStart EOR VV \ If bit 7 of VV is the same as bit 7 of A, then: BPL dver23 \ \ * We are drawing the left track verge and drawing \ the edge from left to right (both bits are clear) \ \ * We are drawing the right track verge and drawing \ the edge from right to left (both bits are set) \ \ In either case, jump to dver23 to skip modifying the \ DrawVergeByteLeft and DrawVergeByteRight routines \ If we get here, then: \ \ * We are drawing the left track verge and drawing \ the edge from right to left \ \ * We are drawing the right track verge and drawing \ the edge from left to right \ \ We now modify both the DrawVergeByteLeft and \ DrawVergeByteRight routines to increment or decrement \ Y on entry, and to do nothing on exit (which flips the \ modifications we did in part 3, which made them do \ nothing on entry and the update of Y on exit) LDA verl5 \ Fetch the instruction that the DrawVergeByteLeft and \ DrawVergeByteRight routines currently execute on exit \ (which will be INY or DEY) STA verl1 \ Modify the instruction at verl1, so the \ DrawVergeByteLeft routine now does this action on \ entry instead STA verb1 \ Modify the instruction at verb1, so the \ DrawVergeByteRight routine now does this action on \ entry instead LDA #&EA \ Set A to the opcode for the NOP instruction STA verl5 \ Modify the instruction at verl5, so the \ DrawVergeByteLeft routine now does nothing on exit STA verb5 \ Modify the instruction at verb5, so the \ DrawVergeByteRight routine now does nothing on exit \ We also do the first increment or decrement, to get \ things set up correctly, depending on the sign in WW, \ which determines whether the edge is going up or down \ the screen LDA WW \ If WW is positive, then the line is heading up the BPL dver22 \ screen, to jump to dver22 to decrement Y before \ drawing the edge INY \ WW is negative, so the line is heading down the \ screen, so increment Y JMP dver23 \ Jump to dver23 to draw the edge .dver22 DEY \ WW is positive, so decrement Y and fall through into \ dver23 to draw the edge .dver23 \ If we get here then SS >= TT, so the edge has a \ gradient shallow LDA VV \ If VV is positive, jump to dver25 to draw the edge BPL dver25 \ from left to right JSR DrawShallowToLeft \ VV is negative, so draw the edge from right to left .dver24 JMP dver28 \ Jump to dver28 to clean up and return from the \ subroutine .dver25 JSR DrawShallowToRight \ VV is positive, so draw the edge from left to right JMP dver28 \ Jump to dver28 to clean up and return from the \ subroutine .dver26 \ If we get here then SS < TT, so the edge has a steep \ gradient LDA VV \ If VV is positive, jump to dver27 to draw the edge BPL dver27 \ from left to right JSR DrawSteepToLeft \ VV is negative, so draw the edge from right to left JMP dver28 \ Jump to dver28 to clean up and return from the \ subroutine .dver27 JSR DrawSteepToRight \ VV is positive, so draw the edge from left to right