Prev: 28463 Up: Map Next: 28708
28476: Place Object
Used by the routine at DrawObjects.
Works out where an object found by DrawObjects is on the screen and draws it. The object's slot in the table at Object_1_State is found (or a free slot is used), the old sprite is erased, the new one is drawn and coloured, and then the car is checked to see if it has hit the object. The car is at the centre of the play area, so the screen position of the object is its distance from the car (Object_Distance_X and Object_Distance_Y) added to, or subtracted from, the position of the car (152 and 104).
Before After
place-object-before place-object-after
Work out the Y position. Return if the object is off the top or bottom of the screen.
PlaceObject 28476 LD A,(24083) Fetch the quadrant of the object (Object_Quadrant) and keep it in C.
28479 LD C,A
28480 INC A Increment A by one.
28481 AND %00000011 Keep only bits 0-1.
28483 BIT 1,A Test bit 1.
28485 LD A,(24088) Fetch the vertical distance from the car (Object_Distance_Y).
28488 JR NZ,PlaceObject_AddCarY Jump to PlaceObject_AddCarY if bit 1 was set.
28490 NEG Make the distance negative.
PlaceObject_AddCarY 28492 ADD A,104 A=A + 104 (the Y position of the car).
28494 CP 192 Return if the Y position is 192 or more.
28496 RET NC
28497 CP 16 Return if the Y position is less than 16.
28499 RET C
28500 LD (24085),A Write the Y position to Object_Screen_Y.
28503 LD H,A Keep the Y position in H.
Work out the X position. Return if the object is off the left or right of the screen.
28504 LD A,(24087) Fetch the horizontal distance from the car (Object_Distance_X).
28507 CP 88 Return if the distance is 88 or more.
28509 RET NC
28510 BIT 1,C Jump to PlaceObject_AddCarX if the object is to the right of the car.
28512 JR Z,PlaceObject_AddCarX
28514 NEG Make the distance negative.
PlaceObject_AddCarX 28516 ADD A,152 A=A + 152 (the X position of the car).
28518 LD (24084),A Write the X position to Object_Screen_X.
28521 LD L,A Keep the X position in L.
Collected cups are not drawn, and place names are drawn as a fuel pump (sprite 7).
28522 LD A,(24095) Fetch the sprite ID of the map point (ActiveObject).
28525 CP 96 Return if this is a collected cup.
28527 RET Z
28528 CP 32 Jump to PlaceObject_Sprite if this is a cup.
28530 JR Z,PlaceObject_Sprite
28532 BIT 6,A Jump to PlaceObject_Sprite if this is not a place name.
28534 JR Z,PlaceObject_Sprite
28536 LD A,7 Use the fuel pump sprite, 7.
PlaceObject_Sprite 28538 LD (24094),A Write the sprite ID to ObjectSpriteID.
28541 PUSH HL Stash the screen position on the stack.
28542 EX DE,HL Keep the screen position in DE.
Look for the object in the table of objects that are already on the screen; it is the same object if it is within 10 pixels in both directions.
28543 LD B,7 Set the slot counter to 7 (the number of object slots).
28545 LD HL,24145 Point HL at the X position of the first object (Object_1_X).
PlaceObject_Search 28548 LD A,(HL) Fetch the X position of the object in the slot.
28549 SUB E Subtract the new X position.
28550 JP P,PlaceObject_CompareX Jump to PlaceObject_CompareX if the difference is positive.
28553 NEG Make the difference positive.
PlaceObject_CompareX 28555 CP 10 Jump to PlaceObject_Next if the object is 10 or more pixels away.
28557 JR NC,PlaceObject_Next
28559 INC HL Move on to the Y position.
28560 LD A,(HL) Fetch the Y position of the object in the slot.
28561 SUB D Subtract the new Y position.
28562 JP P,PlaceObject_CompareY Jump to PlaceObject_CompareY if the difference is positive.
28565 NEG Make the difference positive.
PlaceObject_CompareY 28567 CP 10 Jump to PlaceObject_Skip if the object is 10 or more pixels away.
28569 JR NC,PlaceObject_Skip
The object is already on the screen. Store its old state so that the old sprite is erased when the new one is drawn.
28571 PUSH HL Stash the address of the Y position on the stack.
28572 DEC HL Move back to the sprite ID.
28573 DEC HL
28574 PUSH HL Point IX at the object (using the stack to do so).
28575 POP IX
28577 LD A,(24094) Fetch the new sprite ID (ObjectSpriteID).
28580 LD (HL),A Write the new sprite ID to the object.
28581 CALL StoreEntity Copy the details of the object using StoreEntity.
28584 POP HL Restore the address of the Y position from the stack.
28585 POP DE Restore the screen position from the stack.
28586 JR PlaceObject_Store Jump to PlaceObject_Store.
Move on to the next object.
PlaceObject_Next 28588 INC HL Increment HL by one.
PlaceObject_Skip 28589 INC HL Increment HL by two (to the X position of the next object).
28590 INC HL
28591 DJNZ PlaceObject_Search Decrease the slot counter by one and loop back to PlaceObject_Search until all of the slots have been checked.
The object is not on the screen yet, so look for a free slot.
28593 POP DE Restore the screen position from the stack.
28594 LD HL,24144 Point HL at the first object slot (Object_1_State).
28597 LD B,7 Set the slot counter to 7 (the number of object slots).
28599 XOR A Set A to 0.
28600 LD (24098),A Write A to Actor_SpriteID (there is no old sprite to erase).
This entry point is used by the routine at NextObjectSlot.
PlaceObject_FindSlot 28603 LD A,(HL) Fetch the sprite ID of the slot.
28604 AND A Test whether the slot is empty.
28605 JR NZ,NextObjectSlot Jump to NextObjectSlot if the slot is used.
28607 INC HL Move on to the Y position.
28608 INC HL
Store the object in its slot.
PlaceObject_Store 28609 LD (HL),D Write the Y position.
28610 DEC HL Move back to the X position.
28611 LD (HL),E Write the X position.
28612 DEC HL Move back to the sprite ID.
28613 LD A,(24094) Fetch the new sprite ID (ObjectSpriteID).
28616 OR %10000000 Set bit 7 (so that HandlerObjects knows that the object is still in view).
28618 LD (HL),A Write the sprite ID.
28619 PUSH HL IX=HL (using the stack to do so).
28620 POP IX
28622 LD A,(24095) Fetch the sprite ID of the map point (ActiveObject).
28625 CP 32 Jump to PlaceObject_Draw if this is a cup.
28627 JR Z,PlaceObject_Draw
28629 AND %01111111 Keep only bits 0-6.
28631 CALL DisplayPlaceName Display the place name using DisplayPlaceName.
Erase the old sprite, draw the new one and colour it.
PlaceObject_Draw 28634 CALL DisplayEntity Draw the object using DisplayEntity.
28637 LD L,(IX+1) Fetch the X position of the object.
28640 LD H,(IX+2) Fetch the Y position of the object.
28643 LD A,(24130) Fetch the attribute of the object (ObjectAttribute) and keep it in D.
28646 LD D,A
28647 CALL ColouriseSprite_Position Colour the object using ColouriseSprite_Position.
Check if the car is near enough to the object to have hit it.
28650 LD A,(24087) Fetch the horizontal distance from the car (Object_Distance_X).
28653 CP 10 Return if the object is 10 or more pixels away in X.
28655 RET NC
28656 LD A,(24088) Fetch the vertical distance from the car (Object_Distance_Y).
28659 CP 10 Return if the object is 10 or more pixels away in Y.
28661 RET NC
28662 LD A,(24095) Fetch the sprite ID of the map point (ActiveObject).
28665 CP 32 Jump to CollectCup if this is a cup.
28667 JR Z,CollectCup
28669 BIT 6,A Jump to HitObject if this is not a place name.
28671 JR Z,HitObject
The car has reached a place. Add 80 points the first time that this place is visited, and then refuel.
28673 LD C,A Keep the place in C.
28674 LD A,(24143) Fetch the last place visited (LastPlaceVisited).
28677 CP C Jump to PlaceObject_Refuel if this is the same place as the last one.
28678 JR Z,PlaceObject_Refuel
28680 LD A,C Fetch the place.
28681 LD (24143),A Write the place as the last place visited (LastPlaceVisited).
28684 LD BC,80 Set the points to award, 0080.
28687 CALL AddPointsToScore Add the points to the score using AddPointsToScore.
PlaceObject_Refuel 28690 LD HL,49407 Set the fuel to a full tank, 49407.
28693 LD (24074),HL Write the fuel to Fuel_LSB.
28696 LD A,(24134) Fetch the step counter of the sound (SoundCounter).
28699 AND %01111111 Keep only bits 0-6.
28701 RET NZ Return if a sound is already being made.
28702 LD A,7 Set the step counter to 7 which starts the refuel sound.
28704 LD (24134),A Write the step counter to SoundCounter.
28707 RET Return.
Prev: 28463 Up: Map Next: 28708