Routines

28767: Check for closed door in front of a character


Used by routines at 25843 and 28814

H Character number (183-214)

This routine returns with the carry flag set if the character is facing a closed door, and C holding a value indicating which door:
1 Left study door
2 Right study door
4 Science lab storeroom door
8 Boys' skool door
16 Skool gate

28767 2E00 LD L,0
28769 7E LD A,(HL) A=character's animatory state
28770 07 RLCA
28771 3F CCF
28772 9F SBC A,A
28773 87 ADD A,A
28774 3C INC A
28775 2C INC L
28776 86 ADD A,(HL)
28777 5F LD E,A Now E=x-coordinate of location directly in front of character
28778 2C INC L
28779 56 LD D,(HL) D=y-coordinate of character
28780 E5 PUSH HL
28781 213EB9 LD HL,47422 Point HL to base address of table containing locations of doors
28784 010105 LD BC,1281 B=5, C=1
28787 7B LD A,E A=x-coordinate of location directly in front of character
28788 BE CP (HL)
28789 23 INC HL
28790 2004 JR NZ,28796 Jump if the x-coordinates don't match
28792 7A LD A,D A=y-coordinate of character
28793 BE CP (HL) Do the y-coordinates match?
28794 2808 JR Z,28804 Jump if so (character is standing at this door)
28796 23 INC HL
28797 CB01 RLC C Move the set bit in C one place to the left
28799 10F2 DJNZ 28787 Jump back to consider remaining doors
28801 E1 POP HL
28802 AF XOR A Signal: no door in front of character
28803 C9 RET
28804 3AF47F LD A,(32756) Pick up the doors flags
28807 A1 AND C
28808 E1 POP HL
28809 C0 RET NZ Return if the door is already open
28810 37 SCF Signal: door needs opening
28811 C9 RET

Door location table:
Address Location Description C
47422 72,3 Left study door 1
47424 83,3 Right study door 2
47426 54,10 Science lab storeroom door 4
47428 94,17 Boys' skool door 8
47430 133,17 Skool gate 16