Back to Skool Routines
28767: Check for closed door in front of a character
Used by the routines at 25843 and 28814. Returns with the carry flag set if the character is facing a closed door, and C holding the door identifier:
1 Left study door
2 Right study door
4 Science lab storeroom door
8 Boys' skool door
16 Skool gate
H Character number (183-214)
28767 LD L,0 Pick up the character's animatory state in A
28769 LD A,(HL)
28770 RLCA Set A=-1 if the character is facing left, 1 if facing right
28771 CCF
28772 SBC A,A
28773 ADD A,A
28774 INC A
28775 INC L Byte 1 of the character's buffer holds his x-coordinate
28776 ADD A,(HL) Add this to A
28777 LD E,A Now E=x-coordinate of location directly in front of character
28778 INC L L=2
28779 LD D,(HL) Pick up the character's y-coordinate in D
28780 PUSH HL
28781 LD HL,47422 Point HL at the base address of the table containing locations of doors
28784 LD BC,1281 B=5, C=1
28787 LD A,E A=x-coordinate of location directly in front of character
28788 CP (HL) Compare this with the x-coordinate of the door
28789 INC HL
28790 JR NZ,28796 Jump if the x-coordinates don't match
28792 LD A,D A=y-coordinate of character
28793 CP (HL) Do the y-coordinates match?
28794 JR Z,28804 Jump if so (character is standing at this door)
28796 INC HL
28797 RLC C Move the set bit in C one place to the left
28799 DJNZ 28787 Jump back to consider remaining doors
28801 POP HL
28802 XOR A Reset the carry flag: no door in front of character
28803 RET
The character is standing in front of a door.
28804 LD A,(32756) Pick up the doors flags from 32756
28807 AND C Check the bit corresponding to the door
28808 POP HL
28809 RET NZ Return with the carry flag reset if the door is open
28810 SCF Set the carry flag: door is closed
28811 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