Prev: 51842 Up: Map Next: 52046
51950: Find Door
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 13 further along y than a door that is not mirrored, or 13 back along x than a mirrored one.
Input
C Wall: 0 end x, 1 start x, 2 end y, 3 start y
IX Object record of the player's legs
Look through the door slots.
FindDoor 51950 LD IY,44527 Start at the slot of the first door.
51954 LD DE,65472 Set the offset to the previous door, which is 64 bytes back.
51957 LD B,4 Set the number of doors to check.
FindDoor_Loop 51959 LD A,(IY+0) Fetch the type of the object.
51962 SUB 6 Subtract the type of the first door.
51964 CP 4 Return if it is not one of the types 6 to 9 of the doors and the frames.
51966 RET NC
51967 LD A,C Fetch the wall to look in.
51968 AND A Jump to FindDoor_EndOfX if it is the end of x.
51969 JR Z,FindDoor_EndOfX
51971 DEC A Jump to FindDoor_StartOfX if it is the start of x.
51972 JR Z,FindDoor_StartOfX
51974 DEC A Jump to FindDoor_EndOfY if it is the end of y.
51975 JR Z,FindDoor_EndOfY
51977 LD A,(IY+2) 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 64.
51980 CP 64
51982 JR C,FindDoor_PlacePlayerBesideDoorX
FindDoor_Next 51984 ADD IY,DE Move on to the next door.
51986 DJNZ FindDoor_Loop Jump to FindDoor_Loop until all of the doors have been checked.
51988 RET Return.
Put the player in front of the door.
FindDoor_PlacePlayerBesideDoorY 51989 LD A,(IY+2) Set the y position of the player to be 13 further along than the door.
51992 ADD A,13
51994 LD (IX+2),A
FindDoor_PlacePlayerAtDoorHeight 51997 LD A,(IY+3) Copy the z position of the door to the player.
52000 LD (IX+3),A
52003 ADD A,12 Set the z position of the body to be 12 higher.
52005 LD (IX+35),A
52008 RET Return.
FindDoor_PlacePlayerBesideDoorX 52009 LD A,(IY+1) Set the x position of the player to be 13 back from the door.
52012 SUB 13
52014 LD (IX+1),A
52017 JR FindDoor_PlacePlayerAtDoorHeight Jump to FindDoor_PlacePlayerAtDoorHeight to set the height.
Test which wall this door is in.
FindDoor_EndOfX 52019 LD A,(IY+1) Fetch the x position of the object.
52022 CP 192 Jump to FindDoor_PlacePlayerBesideDoorY if the door is at the end of x.
52024 JR NC,FindDoor_PlacePlayerBesideDoorY
52026 JR FindDoor_Next Jump to FindDoor_Next to check the next door.
FindDoor_StartOfX 52028 LD A,(IY+1) Fetch the x position of the object.
52031 CP 64 Jump to FindDoor_PlacePlayerBesideDoorY if the door is at the start of x.
52033 JR C,FindDoor_PlacePlayerBesideDoorY
52035 JR FindDoor_Next Jump to FindDoor_Next to check the next door.
FindDoor_EndOfY 52037 LD A,(IY+2) Fetch the y position of the object.
52040 CP 192 Jump to FindDoor_PlacePlayerBesideDoorX if the door is at the end of y.
52042 JR NC,FindDoor_PlacePlayerBesideDoorX
52044 JR FindDoor_Next Jump to FindDoor_Next to check the next door.
Prev: 51842 Up: Map Next: 52046