Prev: 51854 Up: Map Next: 51968
51892: Door opening or closing
Used by the routine at 51420.
Input
C Door properties byte at 60238
If bit 6 (64) of the door's properties byte is set, it means the door is in the process of opening or closing.
This routine determines which way the door is swinging based on its wall position and direction (opening vs closing). From this, the graphics frame address pointer is calculated.
51892 LD A,(60240) Graphic frame offset, based on the door's wall position and open/closed status, calculated at 50091
51895 LD B,A Store in B register
Determine if graphic pointer offset is negative or positive (e.g. closing vs opening)
51896 RLA Rotate bits left
51897 SBC A,A Subtract-with-carry means A register now contains 0 (positive) or 255 (negative)
51898 ADD A,A
51899 INC A
51900 LD E,A E register will now contain either 1 (positive) or 255 (negative)
51901 RLA We need a value for a 2-byte address pointer, so do the same for the high byte
51902 SBC A,A
51903 LD D,A D will either contain 0 - for positive - or 255 (-1) - for negative
DE now contains an offset of 1 or -1 to indicate which way to move the graphics address pointer, depending on whether the door is opening or closing.
51904 LD A,E Retrieve the original frame offset
51905 ADD A,B Add (or subtract if negative) the +1/-1 offset
51906 LD B,A
51907 AND 15 For the frame address pointer offset, we're only interested in the lowest 4 bits (0-3) as we just need to figure out a small offset to the graphics address pointer
51909 JR Z,51937 If it's now zero, the door is now fully opened or closed so we can skip the rest of the instructions in this block
51911 LD H,A Otherwise, copy the offset to the H register
51912 LD A,(60239) This is the pre-graphics properties data byte - for doors it's used to identify the number of animation frames to open or close this particular door (calculated at 50091)
51915 AND 15 Again, we only really need bits 0-3 here
51917 CP H Check calculated frame offset against the current frame offset
51918 JR C,51937 If calculated offset is now < stored byte, the door is fully opened or closed
51920 LD A,B Otherwise, store as the new current frame value offset
51921 LD (60240),A
51924 LD HL,(60241) Graphics address pointer to current door frame graphic at 38851 - doors start at 38867
51927 ADD HL,DE
51928 ADD HL,DE Graphics addresses are 2 bytes long, so add the frame offset (-1 or +1) twice
51929 LD (60241),HL ...and re-store the address pointer
51932 LD A,C Retrieve door properties byte (from 60238)
51933 OR 4 Set bit 2 (4) to indicate existing door graphic will need to be erased
51935 JR 51955
Door is now fully closed or open.
Play a 'crunch' sound effect to indicate the door has fully opened or closed.
51937 LD A,16
51939 LD (60246),A Sound effect duration counter for the 'crunch' that happens when a door is fully opened or closed
51942 LD A,(60240) Graphic frame number offset
51945 XOR 224 This XOR sets the frame offset by setting its top 3 bits from positive to negative or vice versa, reversing the frame animations for next time (closed to open, open to closed)
51947 LD (60240),A Re-store the updated frame offset value
51950 LD A,C Retrieve door properties byte (from 60238)
51951 AND 15 Keep bits 0-3
51953 XOR 8 Then toggle bit 3 which indicates whether the door is open or closed:
  • If the door was open, it's now closed
  • If the door was closed, it's now open
This entry point is used by the routines at 51611, 51813 and 51854.
51955 LD (60238),A Re-store the graphic properties byte, amended based on the various door checks and animations
This entry point is used by the routines at 51611, 51702 and 51854.
51958 JP 53885 Jump to the next routine.
The jump to these instructions is made from 51447 (skipping all the door checks) if Maroc is moving through a doorway.
51961 LD A,(60238) Door properties byte
51964 ADD A,128 If bit 7 is set (which it will be) Maroc has just gone through a doorway. Add 128 to reset this bit (back to 0) ready to move him to the next room.
51966 JR 51955
Prev: 51854 Up: Map Next: 51968