Skip to navigation


Drawing objects: DrawCornerMarkers

Name: DrawCornerMarkers [Show more] Type: Subroutine Category: Drawing objects Summary: Draw any visible corner markers Deep dive: Corner markers
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 2 of 5) calls DrawCornerMarkers

Arguments: markersToDraw The number of corner markers to draw - 1
.DrawCornerMarkers LDY #0 \ We work our way through the markers we need to draw, \ using Y as the marker number, counting up from 0 to \ markersToDraw - 1 .corn1 CPY markersToDraw \ If Y = markersToDraw, then we have drawn all the BEQ corn7 \ markers, so jump to corn7 to reset markersToDraw to \ zero and return from the subroutine LDX markerListIndex,Y \ Set X = markerListIndex for marker Y, so X contains \ the index of the corresponding entry in the track \ segment list for this corner markers STY markerNumber \ Store the marker number in markerNumber, so we can \ retrieve it at the end of the loop LDA markerData,Y \ If bit 5 of markerData for marker Y is clear, then the AND #%00100000 \ marker is white, so jump to corn2 to skip the BEQ corn2 \ following two instructions LDA #%00001111 \ Map logical colour 2 in the colour palette to physical STA colourPalette+2 \ colour 1 (red in the track view), so the corner marker \ is drawn in red rather than white .corn2 LDA xMarkerHi,Y \ Set (U A) = (xMarkerHi xMarkerLo) for marker Y STA U \ LDA xMarkerLo,Y \ So (U A) contains the x-axis distance between the \ track edge and the marker ASL A \ Set (U A) = (U A) << 1 ROL U \ = xMarker * 2 STA T \ Set (U T) = (U A) \ = xMarker * 2 CLC \ Set (A V) = (U A) + X-th value from xVergeRight ADC xVergeRightLo,X \ STA V \ starting with the low bytes LDA xVergeRightHi,X \ And then the high bytes ADC U \ \ So (A V) contains the verge's x-coordinate plus the \ distance between the track edge and the marker \ (doubled), to give the x-coordinate of the marker CMP #24 \ If A < 24, jump to corn3 BCC corn3 CMP #232 \ If A < 232, i.e. 24 <= A < 232, jump to corn6 to move BCC corn6 \ on to the next loop .corn3 \ If we get here then A < 24 or A >= -24, so the marker \ is on-screen ASL V \ Set (A V) = (A V) << 2 ROL A \ ASL V \ so A < 96 or A >= -96 ROL A CLC \ Set xPixelCoord = A + 80 ADC #80 \ STA xPixelCoord \ where 80 is the x-coordinate of the middle of the \ screen (as the screen is 160 pixels wide) LDA yVergeRight,X \ Set yPixelCoord = X-th value from yVergeRight STA yPixelCoord \ \ Which is the pitch angle (i.e. y-coordinate) of \ the verge that has the corner markers LDY #2 \ Set Y = 2 so the following loop shifts (U T) left by \ two places .corn4 ASL T \ Set (U T) = (U T) << 1 ROL U DEY \ Decrement the shift counter BNE corn4 \ Loop back until we have left-shifted by Y places LDA U \ Set A = U, so we now have: \ \ (A T) = (U T) << 2 \ = xMarker * 2 * 2 BPL corn5 \ If A is positive, jump to corn5 to skip the following EOR #&FF \ A is negative, so negate A using two's complement, so CLC \ A now contains |A| ADC #1 .corn5 STA scaleUp \ Set scaleUp = |A| \ \ So the size of the corner marker is based on the \ x-axis distance between the track edge and the marker LDA #6 \ Set objectType = 6, the object type for a corner STA objectType \ marker JSR DrawObject \ Draw the corner marker .corn6 LDA #%11110000 \ Map logical colour 2 in the colour palette to physical STA colourPalette+2 \ colour 1 (white in the track view), which sets it back \ to the default value LDY markerNumber \ Set Y to the marker number that we stored in \ markerNumber at the start of the loop INY \ Increment the marker number to draw the next loop JMP corn1 \ Loop back to corn1 .corn7 LDA #0 \ Reset markersToDraw to zero as we have drawn all the STA markersToDraw \ corner markers RTS \ Return from the subroutine