Routines
 Prev: 7C3F Up: Map Next: 7CC7
7C40: Check whether a character will soon be entering or leaving the hotel
Used by the routine at ED8C. Checks whether a character will soon be entering or leaving the hotel, and if so, determines where he should start climbing the front steps (depending on his current location), or through which door he should leave (left or right, depending on his destination).
Input
H Character number (0xD7-0xE6)
7C40 CALL \$ED36 Obtain an identifier for the character's current location
7C43 PUSH AF Save the identifier
7C44 AND A Is the character on the sidewalk or the road?
7C45 JR NZ,\$7C70 Jump if not
The character is on the sidewalk or the road.
7C47 LD L,\$0C Collect the character's destination location identifier from byte 0x0C of his buffer
7C49 LD A,(HL)
7C4A AND \$F0 Keep only the region identifier bits (bits 4-7)
7C4C CP \$90 Is the character going to the hotel?
7C4E JR NZ,\$7C6E Jump if not
The character is on the sidewalk or road, and destined for somewhere inside or outside the hotel. Figure out which entrance (left or right) the character should use, based on his current location and his destination.
7C50 LD A,(HL) A=destination location identifier
7C51 CP \$95 Set the carry flag if the destination is on the first floor or the front steps of the hotel
7C53 LD L,\$0A Point HL at byte 0x0A of the character's buffer
7C55 LD A,(HL) A=x' (the character's destination x-coordinate)
7C56 JR C,\$7C5A Jump if the destination is on the first floor or the front steps of the hotel (in which case 75<=x'<=82)
7C58 LD A,\$4F Assume x'=79 (the x-coordinate of the middle of the doorsteps of the hotel)
7C5A LD L,\$01 Add x (the character's current x-coordinate)
7C5D SUB \$9E Reset the carry flag if 158-x'<=x<=285-x'
7C5F RLCA
7C60 LD A,\$58 This is the x-coordinate of the rightmost front doorstep of the hotel
7C62 JR NC,\$7C66 Jump if x>=158-x' (the character will enter the hotel from the right)
7C64 LD A,\$43 This is the x-coordinate of the leftmost front doorstep of the hotel
7C66 LD BC,\$FFA8 Point BC at the first byte of the entry that corresponds to the hotel in the data table of building entrance x-coordinates at FF98
7C69 LD (BC),A Set the first byte to 0x43 or 0x58
7C6A ADD A,\$02 Set the second byte of the entry to 0x45 or 0x5A
7C6C INC C
7C6D LD (BC),A
7C6E POP AF Restore the identifier for the character's current location to A
7C6F RET
The character is not on the sidewalk or the road.
7C70 CP \$95 If the character's location identifier is at least 0x95, then he's not on the first floor or the front steps of the hotel
7C72 JR NC,\$7C6E Jump if this is the case
7C74 CP \$91 Is the character on the front steps of the hotel (below the level of the first floor)?
7C76 JR Z,\$7C8F Jump if so
7C78 AND \$F0 Keep only the region identifier bits (bits 4-7)
7C7A CP \$90 Is the character on the first floor of the hotel?
7C7C JR NZ,\$7C6E Jump if not
The character is on the first floor of the hotel.
7C7E LD L,\$0A Point HL at byte 0x0A of the character's buffer
7C80 LD A,(HL) A=x' (character's destination x-coordinate)
7C81 LD L,\$01 Add x (the character's current x-coordinate; 75<=x<=82)
7C84 SUB \$9E Reset the carry flag if 158-x<=x'<=285-x
7C86 RLCA
7C87 LD D,\$4C Set D (which holds the x-coordinate of the top of the steps going down to the sidewalk below) to 76 (x-coordinate of the left-hand entrance of the hotel)
7C89 JR C,\$7C6E Jump if x'<158-x (the character will exit the hotel on the left)
7C8B LD D,\$51 This is the x-coordinate of the right-hand entrance of the hotel
The character is on the front steps of the hotel (below the level of the first floor).
7C8F LD L,\$0D Set the location/destination indicator in byte 0x0D of the character's buffer to 0 (the front steps of the hotel count as part of the sidewalk if the character is going somewhere other than the hotel)
7C91 LD (HL),\$00
7C93 DEC L L=0x0C
7C94 LD A,(HL) A=destination location identifier
7C95 AND \$F0 Keep only the region identifier bits (bits 4-7)
7C97 CP \$90 Is the character going to the hotel?
7C99 JR NZ,\$7C6E Jump if not
The character is on the front steps of the hotel (below the level of the first floor), and his destination is somewhere inside or outside the hotel.
7C9B INC L Set byte 0x0D of the character's buffer to 1 (indicating that the character is not on the sidewalk or the road, and is in the same region as his destination)
7C9C INC (HL)
7C9D DEC L L=0x0C
7C9E LD A,(HL) A=destination location identifier
7C9F CP \$95 Is the destination on or below the first floor of the hotel?
7CA1 JR C,\$7CC2 Jump if so
The character is on the front steps of the hotel (below the level of the first floor), and his destination is somewhere inside the hotel, above the first floor.
7CA3 LD L,\$01 Point HL at byte 0x01 of the character's buffer
7CA5 LD B,L B=1 (go right)
7CA6 LD A,(HL) A=x (the character's x-coordinate)
7CA7 CP \$4F Set the carry flag if x<79
7CA9 LD A,\$4C This is the x-coordinate of the left edge of the front door of the hotel
7CAB JR C,\$7CAF Jump if x<79
7CAD LD A,\$52 This is the x-coordinate of the right edge of the front door of the hotel
7CAF CP (HL) Compare A (76 or 82) with x (the character's x-coordinate)
7CB0 DEC HL Point HL at byte 0x00 of the character's buffer
7CB1 JR C,\$7CBB Jump if x is 77 or 78, or greater than 82 (meaning the character should go left to reach the hotel entrance)
7CB3 BIT 7,(HL) Is the character facing right?
7CB5 JR NZ,\$7C6E Jump if so
7CB7 POP AF Restore the identifier for the character's current location to A (though it is ignored)
7CB8 LD A,B A=1 (go right) or 2 (go left)
7CB9 POP BC Drop the return address from the stack