Skip to navigation

Revs on the BBC Micro

Drawing objects: DrawCarOrSign

Name: 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 signs
Context: 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
.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 subroutine