![]() |
Routines |
| Prev: 6F2F | Up: Map | Next: 7024 |
|
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 (98 and 68).
|
||||||||
|
Work out the Y position. Return if the object is off the top or bottom of the screen.
|
||||||||
| PlaceObject | 6F3C | LD A,($5E13) | Fetch the quadrant of the object (Object_Quadrant) and keep it in C. | |||||
| 6F3F | LD C,A | |||||||
| 6F40 | INC A | Increment A by one. | ||||||
| 6F41 | AND %00000011 | Keep only bits 0-1. | ||||||
| 6F43 | BIT 1,A | Test bit 1. | ||||||
| 6F45 | LD A,($5E18) | Fetch the vertical distance from the car (Object_Distance_Y). | ||||||
| 6F48 | JR NZ,PlaceObject_AddCarY | Jump to PlaceObject_AddCarY if bit 1 was set. | ||||||
| 6F4A | NEG | Make the distance negative. | ||||||
| PlaceObject_AddCarY | 6F4C | ADD A,$68 | A=A + 68 (the Y position of the car). | |||||
| 6F4E | CP $C0 | Return if the Y position is C0 or more. | ||||||
| 6F50 | RET NC | |||||||
| 6F51 | CP $10 | Return if the Y position is less than 10. | ||||||
| 6F53 | RET C | |||||||
| 6F54 | LD ($5E15),A | Write the Y position to Object_Screen_Y. | ||||||
| 6F57 | 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.
|
||||||||
| 6F58 | LD A,($5E17) | Fetch the horizontal distance from the car (Object_Distance_X). | ||||||
| 6F5B | CP $58 | Return if the distance is 58 or more. | ||||||
| 6F5D | RET NC | |||||||
| 6F5E | BIT 1,C | Jump to PlaceObject_AddCarX if the object is to the right of the car. | ||||||
| 6F60 | JR Z,PlaceObject_AddCarX | |||||||
| 6F62 | NEG | Make the distance negative. | ||||||
| PlaceObject_AddCarX | 6F64 | ADD A,$98 | A=A + 98 (the X position of the car). | |||||
| 6F66 | LD ($5E14),A | Write the X position to Object_Screen_X. | ||||||
| 6F69 | LD L,A | Keep the X position in L. | ||||||
|
Collected cups are not drawn, and place names are drawn as a fuel pump (sprite 07).
|
||||||||
| 6F6A | LD A,($5E1F) | Fetch the sprite ID of the map point (ActiveObject). | ||||||
| 6F6D | CP $60 | Return if this is a collected cup. | ||||||
| 6F6F | RET Z | |||||||
| 6F70 | CP $20 | Jump to PlaceObject_Sprite if this is a cup. | ||||||
| 6F72 | JR Z,PlaceObject_Sprite | |||||||
| 6F74 | BIT 6,A | Jump to PlaceObject_Sprite if this is not a place name. | ||||||
| 6F76 | JR Z,PlaceObject_Sprite | |||||||
| 6F78 | LD A,$07 | Use the fuel pump sprite, 07. | ||||||
| PlaceObject_Sprite | 6F7A | LD ($5E1E),A | Write the sprite ID to ObjectSpriteID. | |||||
| 6F7D | PUSH HL | Stash the screen position on the stack. | ||||||
| 6F7E | 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 0A pixels in both directions.
|
||||||||
| 6F7F | LD B,$07 | Set the slot counter to 07 (the number of object slots). | ||||||
| 6F81 | LD HL,$5E51 | Point HL at the X position of the first object (Object_1_X). | ||||||
| PlaceObject_Search | 6F84 | LD A,(HL) | Fetch the X position of the object in the slot. | |||||
| 6F85 | SUB E | Subtract the new X position. | ||||||
| 6F86 | JP P,PlaceObject_CompareX | Jump to PlaceObject_CompareX if the difference is positive. | ||||||
| 6F89 | NEG | Make the difference positive. | ||||||
| PlaceObject_CompareX | 6F8B | CP $0A | Jump to PlaceObject_Next if the object is 0A or more pixels away. | |||||
| 6F8D | JR NC,PlaceObject_Next | |||||||
| 6F8F | INC HL | Move on to the Y position. | ||||||
| 6F90 | LD A,(HL) | Fetch the Y position of the object in the slot. | ||||||
| 6F91 | SUB D | Subtract the new Y position. | ||||||
| 6F92 | JP P,PlaceObject_CompareY | Jump to PlaceObject_CompareY if the difference is positive. | ||||||
| 6F95 | NEG | Make the difference positive. | ||||||
| PlaceObject_CompareY | 6F97 | CP $0A | Jump to PlaceObject_Skip if the object is 0A or more pixels away. | |||||
| 6F99 | 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.
|
||||||||
| 6F9B | PUSH HL | Stash the address of the Y position on the stack. | ||||||
| 6F9C | DEC HL | Move back to the sprite ID. | ||||||
| 6F9D | DEC HL | |||||||
| 6F9E | PUSH HL | Point IX at the object (using the stack to do so). | ||||||
| 6F9F | POP IX | |||||||
| 6FA1 | LD A,($5E1E) | Fetch the new sprite ID (ObjectSpriteID). | ||||||
| 6FA4 | LD (HL),A | Write the new sprite ID to the object. | ||||||
| 6FA5 | CALL StoreEntity | Copy the details of the object using StoreEntity. | ||||||
| 6FA8 | POP HL | Restore the address of the Y position from the stack. | ||||||
| 6FA9 | POP DE | Restore the screen position from the stack. | ||||||
| 6FAA | JR PlaceObject_Store | Jump to PlaceObject_Store. | ||||||
|
Move on to the next object.
|
||||||||
| PlaceObject_Next | 6FAC | INC HL | Increment HL by one. | |||||
| PlaceObject_Skip | 6FAD | INC HL | Increment HL by two (to the X position of the next object). | |||||
| 6FAE | INC HL | |||||||
| 6FAF | 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.
|
||||||||
| 6FB1 | POP DE | Restore the screen position from the stack. | ||||||
| 6FB2 | LD HL,$5E50 | Point HL at the first object slot (Object_1_State). | ||||||
| 6FB5 | LD B,$07 | Set the slot counter to 07 (the number of object slots). | ||||||
| 6FB7 | XOR A | Set A to 00. | ||||||
| 6FB8 | LD ($5E22),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 | 6FBB | LD A,(HL) | Fetch the sprite ID of the slot. | |||||
| 6FBC | AND A | Test whether the slot is empty. | ||||||
| 6FBD | JR NZ,NextObjectSlot | Jump to NextObjectSlot if the slot is used. | ||||||
| 6FBF | INC HL | Move on to the Y position. | ||||||
| 6FC0 | INC HL | |||||||
|
Store the object in its slot.
|
||||||||
| PlaceObject_Store | 6FC1 | LD (HL),D | Write the Y position. | |||||
|
See Invisible Obstacles.
|
||||||||
| 6FC2 | DEC HL | Move back to the X position. | ||||||
| 6FC3 | LD (HL),E | Write the X position. | ||||||
| 6FC4 | DEC HL | Move back to the sprite ID. | ||||||
| 6FC5 | LD A,($5E1E) | Fetch the new sprite ID (ObjectSpriteID). | ||||||
| 6FC8 | OR %10000000 | Set bit 7 (so that HandlerObjects knows that the object is still in view). | ||||||
| 6FCA | LD (HL),A | Write the sprite ID. | ||||||
| 6FCB | PUSH HL | IX=HL (using the stack to do so). | ||||||
| 6FCC | POP IX | |||||||
| 6FCE | LD A,($5E1F) | Fetch the sprite ID of the map point (ActiveObject). | ||||||
| 6FD1 | CP $20 | Jump to PlaceObject_Draw if this is a cup. | ||||||
| 6FD3 | JR Z,PlaceObject_Draw | |||||||
| 6FD5 | AND %01111111 | Keep only bits 0-6. | ||||||
| 6FD7 | CALL DisplayPlaceName | Display the place name using DisplayPlaceName. | ||||||
|
Erase the old sprite, draw the new one and colour it.
|
||||||||
| PlaceObject_Draw | 6FDA | CALL DisplayEntity | Draw the object using DisplayEntity. | |||||
| 6FDD | LD L,(IX+$01) | Fetch the X position of the object. | ||||||
| 6FE0 | LD H,(IX+$02) | Fetch the Y position of the object. | ||||||
| 6FE3 | LD A,($5E42) | Fetch the attribute of the object (ObjectAttribute) and keep it in D. | ||||||
| 6FE6 | LD D,A | |||||||
| 6FE7 | CALL ColouriseSprite_Position | Colour the object using ColouriseSprite_Position. | ||||||
|
Check if the car is near enough to the object to have hit it.
|
||||||||
| 6FEA | LD A,($5E17) | Fetch the horizontal distance from the car (Object_Distance_X). | ||||||
|
See Immune To Obstacles.
|
||||||||
| 6FED | CP $0A | Return if the object is 0A or more pixels away in X. | ||||||
| 6FEF | RET NC | |||||||
| 6FF0 | LD A,($5E18) | Fetch the vertical distance from the car (Object_Distance_Y). | ||||||
| 6FF3 | CP $0A | Return if the object is 0A or more pixels away in Y. | ||||||
| 6FF5 | RET NC | |||||||
| 6FF6 | LD A,($5E1F) | Fetch the sprite ID of the map point (ActiveObject). | ||||||
| 6FF9 | CP $20 | Jump to CollectCup if this is a cup. | ||||||
| 6FFB | JR Z,CollectCup | |||||||
| 6FFD | BIT 6,A | Jump to HitObject if this is not a place name. | ||||||
| 6FFF | JR Z,HitObject | |||||||
|
The car has reached a place. Add 50 points the first time that this place is visited, and then refuel.
|
||||||||
| 7001 | LD C,A | Keep the place in C. | ||||||
| 7002 | LD A,($5E4F) | Fetch the last place visited (LastPlaceVisited). | ||||||
| 7005 | CP C | Jump to PlaceObject_Refuel if this is the same place as the last one. | ||||||
| 7006 | JR Z,PlaceObject_Refuel | |||||||
| 7008 | LD A,C | Fetch the place. | ||||||
| 7009 | LD ($5E4F),A | Write the place as the last place visited (LastPlaceVisited). | ||||||
| 700C | LD BC,$0050 | Set the points to award, 0050. | ||||||
| 700F | CALL AddPointsToScore | Add the points to the score using AddPointsToScore. | ||||||
| PlaceObject_Refuel | 7012 | LD HL,$C0FF | Set the fuel to a full tank, C0FF. | |||||
| 7015 | LD ($5E0A),HL | Write the fuel to Fuel_LSB. | ||||||
| 7018 | LD A,($5E46) | Fetch the step counter of the sound (SoundCounter). | ||||||
| 701B | AND %01111111 | Keep only bits 0-6. | ||||||
| 701D | RET NZ | Return if a sound is already being made. | ||||||
| 701E | LD A,$07 | Set the step counter to 07 which starts the refuel sound. | ||||||
| 7020 | LD ($5E46),A | Write the step counter to SoundCounter. | ||||||
| 7023 | RET | Return. | ||||||
| Prev: 6F2F | Up: Map | Next: 7024 |