| Routines

60726: Obtain an identifier for a character's current location

Used by the routine at 31808. Returns with A=255 if the character's z-coordinate is 2 or 4, and his y-coordinate is less than 31 (meaning he is on the fire escape of the apartment building next to no. 19, or falling from the roof of a building); with A=0 if he's on the sidewalk or the road; or with certain bits of A set or reset depending on the location:
Bit(s) | Meaning
--- | ---
0 | 0: On the floor of a shop or other building
1: On a staircase between floors, or on the front steps of a building below the first floor, or on the rim of a roof
1-3 | 000: On the front steps of a building below the first floor
001: Next to the entrance to a shop or other building (outside)
010: Shop or first floor of other building (inside)
011: Second floor of a building
100: Third floor of a building
101: Fourth floor of a building (could be the roof)
110: Fifth floor of a building (could be the roof)
4-7 | Region ID (see below)
The region ID in bits 4-7 corresponds to a certain shop or other building in the play area:
Region ID | Building
--- | ---
0001 | Left-hand shop under the apartments next to no. 74
0010 | Right-hand shop under the apartments next to no. 74
0011 | Shop under no. 17
0100 | Shop under no. 15
0101 | Apartment building next to no. 74
0110 | Police station
0111 | No. 27
1000 | No. 74
1001 | Hotel
1010 | No. 31
1011 | No. 19
1100 | No. 17
1101 | Unused
1110 | No. 15
1111 | Apartment building next to no. 19
In addition, on return E holds the x-coordinate of the bottom of the staircase going up to the floor above, and D holds the x-coordinate of the top of the staircase going down to the floor below.
Input
H | Character number (215-230)
60726 | LD L,1 | E=character's x-coordinate
60728 | LD E,(HL)
60729 | INC L | D=character's y-coordinate
60730 | LD D,(HL)
60731 | LD L,4 | C=character's z-coordinate
60733 | LD C,(HL)
This entry point is used by the routine at 29072.
60734 | BIT 0,C | Is the z-coordinate 1 (indoors)?
60736 | JR NZ,60743 | Jump if so
60738 | LD A,D | A=y-coordinate
60739 | CP 31 | A=255 if the y-coordinate is less than 31, 0 otherwise
60741 | SBC A,A
60742 | RET C | Return with A=255 if the y-coordinate is less than 31, and the z-coordinate is 2 or 4
This entry point is used by the routines at 31126 and 31289.
60743 | CALL 60159 | Check whether the character is on the sidewalk or road
60746 | LD A,0 | Return with A=0 if the character is on the sidewalk or road
60748 | RET NC
At this point we have determined that the character is on the front steps of or inside a building.
60749 | PUSH HL | Save the character number
60750 | LD A,37 | L=10 (if 31<D), 11 (25<D<=31), 12 (19<D<=25), 13 (13<D<=19), 14 (7<D<=13) or 15 (1<D<=7)
60752 | LD L,9
60754 | INC L
60755 | SUB 6
60757 | CP D
60758 | JR NC,60754
60760 | SUB D | Set the zero flag if D=7, 13, 19, 25 or 31 (corresponding to the floor of a building)
60761 | ADD A,6
60763 | PUSH AF | Save A and the zero flag
60764 | LD H,239 | The region identifier tables are in page 239
60766 | LD A,E | A=x-coordinate
60767 | LD L,(HL) | Point HL at one of the tables at 61200, 61256, 61296, 61336, 61376 and 61416
60768 | CP (HL) | Find the first entry whose first byte is greater than A (the target x-coordinate)
60769 | INC HL
60770 | INC HL
60771 | INC HL
60772 | INC HL
60773 | JR NC,60768
60775 | DEC HL | E=fourth byte of the entry (x-coordinate of the bottom of the staircase going up to the floor above)
60776 | LD E,(HL)
60777 | DEC HL | D=third byte of the entry (x-coordinate of the top of the staircase going down to the floor below)
60778 | LD D,(HL)
60779 | DEC HL | A=second byte of the entry (location identifier)
60780 | LD A,(HL)
60781 | CP 80 | Is the second byte of the entry less than 80?
60783 | JR NC,60794 | Jump if not
The second byte of the entry is less than 80, which is true only for the four entries in the region identifier table at 61200 that correspond to the shops.
60785 | POP AF | Restore A and the zero flag (though the values are ignored at this point)
60786 | LD A,(HL) | A=location identifier
60787 | BIT 0,C | Set the zero flag if the z-coordinate is 1 (indoors)
60789 | POP HL | Restore the character number to H
60790 | RET NZ | Return if the z-coordinate is 1
60791 | SUB 2 | Reset bit 2 of A, and set bit 1 (to indicate that the character is standing outside the door of a shop or house)
60793 | RET |
The second byte of the entry (held in A) is at least 80, which means it corresponds to a location other than one of the four shops.
60794 | AND 15 | Keep only bits 0-3 of the location identifier
60796 | CP 4 | Is this location on the first floor of a building?
60798 | JR NZ,60804 | Jump if not
60800 | POP AF | Restore A and the zero flag
60801 | JR Z,60786 | Jump if the y-coordinate corresponds to a floor of a building
60803 | PUSH AF | Save A and the zero flag again
60804 | POP AF | Restore A and the zero flag
60805 | LD A,(HL) | A=location identifier
60806 | POP HL | Restore the character number to H
60807 | RET Z | Return if the y-coordinate corresponds to a floor of a building
60808 | INC A | Set bit 0 of A to indicate that the character is on a staircase between two floors of a building, or on the front steps of a building below the first floor, or on the rim of a roof
60809 | RET |