Prev: ED30 Up: Map Next: ED8A
ED36: Obtain an identifier for a character's current location
Used by the routine at 7C40. Returns with A=0xFF 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=0x00 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 (0xD7-0xE6)
ED36 LD L,$01 E=character's x-coordinate
ED38 LD E,(HL)
ED39 INC L D=character's y-coordinate
ED3A LD D,(HL)
ED3B LD L,$04 C=character's z-coordinate
ED3D LD C,(HL)
This entry point is used by the routine at 7190.
ED3E BIT 0,C Is the z-coordinate 1 (indoors)?
ED40 JR NZ,$ED47 Jump if so
ED42 LD A,D A=y-coordinate
ED43 CP $1F A=0xFF if the y-coordinate is less than 31, 0x00 otherwise
ED45 SBC A,A
ED46 RET C Return with A=0xFF 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 7996 and 7A39.
ED47 CALL $EAFF Check whether the character is on the sidewalk or road
ED4A LD A,$00 Return with A=0 if the character is on the sidewalk or road
ED4C RET NC
At this point we have determined that the character is on the front steps of or inside a building.
ED4D PUSH HL Save the character number
ED4E LD A,$25 L=0x0A (if 31<D), 0x0B (25<D<=31), 0x0C (19<D<=25), 0x0D (13<D<=19), 0x0E (7<D<=13) or 0x0F (1<D<=7)
ED50 LD L,$09
ED52 INC L
ED53 SUB $06
ED55 CP D
ED56 JR NC,$ED52
ED58 SUB D Set the zero flag if D=7, 13, 19, 25 or 31 (corresponding to the floor of a building)
ED59 ADD A,$06
ED5B PUSH AF Save A and the zero flag
ED5C LD H,$EF The region identifier tables are in page 0xEF
ED5E LD A,E A=x-coordinate
ED5F LD L,(HL) Point HL at one of the tables at EF10, EF48, EF70, EF98, EFC0 and EFE8
ED60 CP (HL) Find the first entry whose first byte is greater than A (the target x-coordinate)
ED61 INC HL
ED62 INC HL
ED63 INC HL
ED64 INC HL
ED65 JR NC,$ED60
ED67 DEC HL E=fourth byte of the entry (x-coordinate of the bottom of the staircase going up to the floor above)
ED68 LD E,(HL)
ED69 DEC HL D=third byte of the entry (x-coordinate of the top of the staircase going down to the floor below)
ED6A LD D,(HL)
ED6B DEC HL A=second byte of the entry (location identifier)
ED6C LD A,(HL)
ED6D CP $50 Is the second byte of the entry less than 0x50?
ED6F JR NC,$ED7A Jump if not
The second byte of the entry is less than 0x50, which is true only for the four entries in the region identifier table at EF10 that correspond to the shops.
ED71 POP AF Restore A and the zero flag (though the values are ignored at this point)
ED72 LD A,(HL) A=location identifier
ED73 BIT 0,C Set the zero flag if the z-coordinate is 1 (indoors)
ED75 POP HL Restore the character number to H
ED76 RET NZ Return if the z-coordinate is 1
ED77 SUB $02 Reset bit 2 of A, and set bit 1 (to indicate that the character is standing outside the door of a shop or house)
ED79 RET
The second byte of the entry (held in A) is at least 0x50, which means it corresponds to a location other than one of the four shops.
ED7A AND $0F Keep only bits 0-3 of the location identifier
ED7C CP $04 Is this location on the first floor of a building?
ED7E JR NZ,$ED84 Jump if not
ED80 POP AF Restore A and the zero flag
ED81 JR Z,$ED72 Jump if the y-coordinate corresponds to a floor of a building
ED83 PUSH AF Save A and the zero flag again
ED84 POP AF Restore A and the zero flag
ED85 LD A,(HL) A=location identifier
ED86 POP HL Restore the character number to H
ED87 RET Z Return if the y-coordinate corresponds to a floor of a building
ED88 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
ED89 RET
Prev: ED30 Up: Map Next: ED8A