![]() |
Routines |
| Prev: CA82 | Up: Map | Next: CB4E |
|
Used by the routine at PlacePlayerAtDoor.
Looks for the door in a particular wall of the room, and puts the player in the doorway in front of it. The doors are the first of the objects that were made for the room, and take two slots each (with their frames), so every other slot is checked, starting at the last, until one is found that does not hold a door (or up to four are checked).
The position that the player is put at is not the same as that of the door, but is the place that the door holds for it, which is 0D further along y than a door that is not mirrored, or 0D back along x than a mirrored one.
|
||||||||||
|
Look through the door slots.
|
||||||||||
| FindDoor | CAEE | LD IY,$ADEF | Start at the slot of the first door. | |||||||
| CAF2 | LD DE,$FFC0 | Set the offset to the previous door, which is 40 bytes back. | ||||||||
| CAF5 | LD B,$04 | Set the number of doors to check. | ||||||||
| FindDoor_Loop | CAF7 | LD A,(IY+$00) | Fetch the type of the object. | |||||||
| CAFA | SUB $06 | Subtract the type of the first door. | ||||||||
| CAFC | CP $04 | Return if it is not one of the types 06 to 09 of the doors and the frames. | ||||||||
| CAFE | RET NC | |||||||||
| CAFF | LD A,C | Fetch the wall to look in. | ||||||||
| CB00 | AND A | Jump to FindDoor_EndOfX if it is the end of x. | ||||||||
| CB01 | JR Z,FindDoor_EndOfX | |||||||||
| CB03 | DEC A | Jump to FindDoor_StartOfX if it is the start of x. | ||||||||
| CB04 | JR Z,FindDoor_StartOfX | |||||||||
| CB06 | DEC A | Jump to FindDoor_EndOfY if it is the end of y. | ||||||||
| CB07 | JR Z,FindDoor_EndOfY | |||||||||
| CB09 | LD A,(IY+$02) | Jump to FindDoor_PlacePlayerBesideDoorX if the door is at the start of y, which is where the y position of the object is less than 40. | ||||||||
| CB0C | CP $40 | |||||||||
| CB0E | JR C,FindDoor_PlacePlayerBesideDoorX | |||||||||
| FindDoor_Next | CB10 | ADD IY,DE | Move on to the next door. | |||||||
| CB12 | DJNZ FindDoor_Loop | Jump to FindDoor_Loop until all of the doors have been checked. | ||||||||
| CB14 | RET | Return. | ||||||||
|
Put the player in front of the door.
|
||||||||||
| FindDoor_PlacePlayerBesideDoorY | CB15 | LD A,(IY+$02) | Set the y position of the player to be 0D further along than the door. | |||||||
| CB18 | ADD A,$0D | |||||||||
| CB1A | LD (IX+$02),A | |||||||||
| FindDoor_PlacePlayerAtDoorHeight | CB1D | LD A,(IY+$03) | Copy the z position of the door to the player. | |||||||
| CB20 | LD (IX+$03),A | |||||||||
| CB23 | ADD A,$0C | Set the z position of the body to be 0C higher. | ||||||||
| CB25 | LD (IX+$23),A | |||||||||
| CB28 | RET | Return. | ||||||||
| FindDoor_PlacePlayerBesideDoorX | CB29 | LD A,(IY+$01) | Set the x position of the player to be 0D back from the door. | |||||||
| CB2C | SUB $0D | |||||||||
| CB2E | LD (IX+$01),A | |||||||||
| CB31 | JR FindDoor_PlacePlayerAtDoorHeight | Jump to FindDoor_PlacePlayerAtDoorHeight to set the height. | ||||||||
|
Test which wall this door is in.
|
||||||||||
| FindDoor_EndOfX | CB33 | LD A,(IY+$01) | Fetch the x position of the object. | |||||||
| CB36 | CP $C0 | Jump to FindDoor_PlacePlayerBesideDoorY if the door is at the end of x. | ||||||||
| CB38 | JR NC,FindDoor_PlacePlayerBesideDoorY | |||||||||
| CB3A | JR FindDoor_Next | Jump to FindDoor_Next to check the next door. | ||||||||
| FindDoor_StartOfX | CB3C | LD A,(IY+$01) | Fetch the x position of the object. | |||||||
| CB3F | CP $40 | Jump to FindDoor_PlacePlayerBesideDoorY if the door is at the start of x. | ||||||||
| CB41 | JR C,FindDoor_PlacePlayerBesideDoorY | |||||||||
| CB43 | JR FindDoor_Next | Jump to FindDoor_Next to check the next door. | ||||||||
| FindDoor_EndOfY | CB45 | LD A,(IY+$02) | Fetch the y position of the object. | |||||||
| CB48 | CP $C0 | Jump to FindDoor_PlacePlayerBesideDoorX if the door is at the end of y. | ||||||||
| CB4A | JR NC,FindDoor_PlacePlayerBesideDoorX | |||||||||
| CB4C | JR FindDoor_Next | Jump to FindDoor_Next to check the next door. | ||||||||
| Prev: CA82 | Up: Map | Next: CB4E |