Prev: 6B42 Up: Map Next: 6BD6
6B47: Draw Objects
Used by the routine at HandlerPlayer.
Goes through the map points (MapPoints), from the one that CurrentObject points to, and draws each one that is in view of the player's car. The map points are in order of their X position, so it stops at the first one which is more than 60 map units away horizontally. Map points which are too far away vertically are skipped.
Before After
draw-objects-before draw-objects-after
DrawObjects 6B47 LD BC,($5E19) Fetch the first map point that might be in view (CurrentObject).
Handle the next map point. A' is used to hold flags which say which side of the player's car the map point is on; bit 1 is set when it is to the right and bit 0 is set when it is higher up the map.
DrawObjects_Next 6B4B XOR A Prepare to clear the direction flags.
6B4C EX AF,AF' Exchange A with A' to clear the flags.
6B4D LD A,(BC) Fetch the X position of the map point.
6B4E INC BC Move on to the Y position of the map point.
6B4F LD D,A Keep the X position in D.
6B50 CALL ScaleValue_DivideByEight Call ScaleValue_DivideByEight to convert it to map units in DE.
6B53 LD HL,($5E05) Fetch the player's X position on the map (PlayerMapPosition).
6B56 AND A HL=HL - DE (the horizontal distance to the map point).
6B57 SBC HL,DE
6B59 JR NC,DrawObjects_CheckRangeX Jump to DrawObjects_CheckRangeX if the map point is not to the right of the player's car.
6B5B CALL NegateHL Call NegateHL to make the distance positive.
6B5E EX AF,AF' Switch to the flags.
6B5F XOR %00000010 Flip bit 1 (the map point is to the right).
6B61 EX AF,AF' Switch back.
DrawObjects_CheckRangeX 6B62 PUSH HL Stash the distance on the stack.
6B63 EX DE,HL Keep the distance in DE.
6B64 LD HL,$0060 Set the furthest distance in view, 0060.
6B67 AND A Take the distance away from the furthest distance in view.
6B68 SBC HL,DE
6B6A POP HL Restore the distance (HL) from the stack.
6B6B RET C Return if the map point is more than 60 units away horizontally.
6B6C LD A,L Fetch the horizontal distance (the low byte).
6B6D LD ($5E17),A Store the horizontal distance in Object_Distance_X.
6B70 LD A,(BC) Fetch the Y position of the map point.
6B71 INC BC Move on to the sprite ID of the map point.
6B72 LD D,A Keep the Y position in D.
6B73 CALL ScaleValue_DivideBySixteen Call ScaleValue_DivideBySixteen to convert it to map units in DE.
Pick the attributes for the objects; they depend on the time of day.
6B76 LD A,($5E43) Fetch the day/night flag (Flag_DayNight).
6B79 AND A If it is day time then jump to SetDayObjectAttributes.
6B7A JR Z,SetDayObjectAttributes
6B7C LD HL,$6BD6 Point HL at the night time object attributes (NightObjectAttributes).
This entry point is used by the routine at SetDayObjectAttributes.
DrawObjects_Sprite 6B7F LD A,(BC) Fetch the sprite ID of the map point.
6B80 INC BC Move on to the next map point.
6B81 LD ($5E1F),A Store the sprite ID in ActiveObject.
Cups, place names and collected cups all use the first attribute.
6B84 CP $20 Jump to DrawObjects_FirstAttribute if this is a cup (20).
6B86 JR Z,DrawObjects_FirstAttribute
6B88 CP $40 Jump to DrawObjects_FirstAttribute if this is a place name or a collected cup (40 or more).
6B8A JR NC,DrawObjects_FirstAttribute
6B8C ADD A,L Add the sprite ID to the pointer to find the attribute for this sprite.
6B8D LD L,A
6B8E LD A,H
6B8F ADC A,$00
6B91 LD H,A
DrawObjects_Attribute 6B92 LD A,($5E44) Fetch the background attribute (Background_Attribute).
6B95 OR (HL) Merge the colour of the object with the background.
6B96 LD ($5E42),A Store the attribute of the object in ObjectAttribute.
6B99 LD HL,($5E08) Fetch the player's Y position on the map (PlayerMapPositionY).
6B9C AND A HL=HL - DE (the vertical distance to the map point).
6B9D SBC HL,DE
6B9F JR NC,DrawObjects_CheckRangeY Jump to DrawObjects_CheckRangeY if the map point is not higher up the map than the player's car.
6BA1 CALL NegateHL Call NegateHL to make the distance positive.
6BA4 EX AF,AF' Switch to the flags.
6BA5 XOR %00000001 Flip bit 0 (the map point is higher up the map).
6BA7 EX AF,AF' Switch back.
DrawObjects_CheckRangeY 6BA8 PUSH HL Stash the distance on the stack.
6BA9 EX DE,HL Keep the distance in DE.
6BAA LD HL,$0060 Set the furthest distance in view, 0060.
6BAD AND A Take the distance away from the furthest distance in view.
6BAE SBC HL,DE
6BB0 POP HL Restore the distance (HL) from the stack.
6BB1 JR C,DrawObjects_Next Jump to DrawObjects_Next if the map point is more than 60 units away vertically.
6BB3 LD A,L Fetch the vertical distance (the low byte).
6BB4 LD ($5E18),A Store the vertical distance in Object_Distance_Y.
Use the flags to look up the quadrant of the map point.
6BB7 EX AF,AF' Switch to the direction flags.
6BB8 LD E,A Use the direction flags as the index into the quadrant table.
6BB9 LD D,$00 Clear the high byte of the index.
6BBB LD HL,$6BCF Point HL at the quadrant table (DrawObjects_QuadrantTable).
6BBE ADD HL,DE Add the index to the start of the table.
6BBF LD A,(HL) Fetch the quadrant.
6BC0 LD ($5E13),A Store the quadrant in Object_Quadrant.
6BC3 LD ($5E3A),BC Store the map point pointer in ObjectMapPointer.
6BC7 PUSH BC Stash BC on the stack.
6BC8 CALL PlaceObject Call PlaceObject to place the object on the screen.
6BCB POP BC Restore BC from the stack.
6BCC JP DrawObjects_Next Jump to DrawObjects_Next.
The quadrant for each combination of the flags in A'. Bit 1 of the quadrant is set when the object is to the left of the player's car.
DrawObjects_QuadrantTable 6BCF DEFB $02,$03,$01,$00
Use the first attribute for cups, place names and collected cups.
DrawObjects_FirstAttribute 6BD3 XOR A A=00 (this has no effect, as A is loaded again below).
6BD4 JR DrawObjects_Attribute Jump to DrawObjects_Attribute.
Prev: 6B42 Up: Map Next: 6BD6