.DrawCarOrSign LDA objectStatus,X \ Set A to this object's status byte BMI dcas3 \ If bit 7 is set then the object is not visible, so \ jump to dcas3 to return from the subroutine without \ drawing anything AND #%00001111 \ Extract the object's object type from bits 0-3 and STA objectType \ store it in objectType LDA objYawAngleLo,X \ Set (A T) = objYawAngle for this object SEC \ - playerYawAngle SBC playerYawAngleLo \ STA T \ starting with the low bytes LDA objYawAngleHi,X \ And then the high bytes SBC playerYawAngleHi \ \ So (A T) now contains the amount that the object we \ are drawing is to the left or right of the player's \ car BPL dcas1 \ If the result is positive, jump to dcas1 to perform a \ positive comparison CMP #&E0 \ The result is negative, so check to see if A < -32, BCC dcas3 \ and if so, jump to dcas3 to return from the subroutine \ without drawing anything BCS dcas2 \ Jump to dcas2 (this BCS is effectively a JMP as we \ just passed through a BCC) .dcas1 CMP #32 \ The result is positive, so check to see if A >= 32, BCS dcas3 \ and if so, jump to dcas3 to return from the subroutine \ without drawing anything .dcas2 \ If we get here then -32 <= A < 32 ASL T \ Set (A T) = (A T) * 4 ROL A \ ASL T \ so -128 <= A < 128 ROL A CLC \ Set xPixelCoord = 80 + A ADC #80 \ STA xPixelCoord \ This moves xPixelCoord so that it is centred on the \ screen, as the centre x-coordinate of the screen is \ at 80 pixels LDA objectPitchAngle,X \ Set yPixelCoord to this object's pitch angle STA yPixelCoord LDA objectSize,X \ Set scaleUp to this object's size (i.e. the size of STA scaleUp \ the car) JSR DrawObject \ Draw the object on-screen .dcas3 LDX xStoreDraw \ Set X = xStoreDraw so X is unchanged by the routine \ call RTS \ Return from the subroutineName: DrawCarOrSign [Show more] Type: Subroutine Category: Drawing objects Summary: Draw a car or sign Deep dive: Object definitions Drawing a 3D car from 2D parts Road signsContext: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawCars calls DrawCarOrSign * MainDrivingLoop (Part 2 of 5) calls DrawCarOrSign
This routine is used to draw road signs and cars.
Arguments: X The car or sign to draw: * 0-19 = Draw the car for this driver number * 20-22 = Draw one of the three extra objects that make up the four-object car: * 20 = rear wing * 21 = body and helmet * 22 = front tyres * 23 = Draw the road sign xStoreDraw The value to restore into X at the end of the routine
Returns: X X is set to xStoreDraw
[X]
Subroutine DrawObject (category: Drawing objects)
Draw an object of a specific type
[X]
Label dcas1 is local to this routine
[X]
Label dcas2 is local to this routine
[X]
Label dcas3 is local to this routine
[X]
Variable objYawAngleHi in workspace Main variable workspace
High byte of each object's yaw angle
[X]
Variable objYawAngleLo in workspace Main variable workspace
Low byte of each object's yaw angle
[X]
Variable objectPitchAngle in workspace Main variable workspace
Each object's pitch angle
[X]
Variable objectSize in workspace Main variable workspace
The size of each of the objects (i.e. the scaled value of scaleUp for the object)
[X]
Variable objectStatus in workspace Stack variables
Various status flags for each object
[X]
Variable objectType in workspace Zero page
The type of object to draw (0 to 12)
[X]
Variable playerYawAngleHi in workspace Zero page
High byte of the player's yaw angle
[X]
Variable playerYawAngleLo in workspace Zero page
Low byte of the player's yaw angle
[X]
Variable xPixelCoord in workspace Zero page
The pixel x-coordinate of the centre of the current object
[X]
Variable xStoreDraw in workspace Zero page
Temporary storage for X so it can be preserved through calls to DrawCarInPosition, DrawCarOrSign and DrawSegmentEdge
[X]
Variable yPixelCoord in workspace Zero page
The pixel y-coordinate of the centre of the current object