Prev: EAF8 Up: Map Next: EB83
EB13: Obtain descriptors for a character's current location
Used by the routines at 710E, EBBB, ED8C, F308 and FA05. Looks for a location descriptor that corresponds to the character's current location and returns with A and C (and possibly also B) holding values derived from that descriptor.
A location descriptor is a single byte (Q) if the location is on the sidewalk or road, or a sequence of two bytes ((Q,Q'), where bit 7 of Q is reset), or a sequence of three bytes ((Q,Q',Q''), where bit 7 of Q is set). For the location it corresponds to, a descriptor indicates the directions in which a character may move, and the directions that would require a change of z-coordinate; it may also indicate whether there is a door that can close at the location, and whether any movement from the location requires special handling by a separate routine (e.g. on the edge of a roof, or just behind the jail cell door).
The single-byte location descriptors (Q) that correspond to locations on the sidewalk or road can be found in the table at C400. The blocks of two- and three-byte location descriptors for locations not on the sidewalk or road are organised by x-coordinate; the LSBs and MSBs of their addresses can be found in the tables at C500 and C600.
The first byte, Q, of a multi-byte location descriptor indicates the y-coordinate (y) and z-coordinate(s) (z) of the location to which the descriptor corresponds. In a two-byte descriptor (bit 7 of Q reset), bits 1-5 of Q hold y-4, and z is 2 if bit 6 is set, or 1 otherwise. In a three-byte descriptor (bit 7 of Q set), bits 0-4 of Q hold y-4, and z is determined by bits 5 and 6: if bit 6 is set, z=1 or 2 (meaning that the location is next to the entrance to a building); otherwise, z=2 if bit 5 is set or 1 if it's reset.
This routine returns with A holding the location type indicator (1-5), and C and B holding the values derived from the relevant location descriptor:
A C B Meaning
1 Q - The sidewalk or the road
3 Q' Q'' At the (open) entrance to a building
4 Q' Q'' Behind or in front of a closed door
5 Q' Q'' Location requires special handling
2 Q' - Regular location (none of the above)
The value in C (Q or Q') is the direction descriptor, which indicates the directions that are available, and (when A=1 or 5) the directions that require special handling:
Bit Meaning if set
7 Access to the left is granted
6 Access to the right is granted
5 There is a step going up to the left
4 There is a step going up to the right
3 There is a step going down to the left
2 There is a step going down to the right
1 Character's z-coordinate will be 2 after going up to the left (when A=1), or moving left requires special handling (when A=5; see EC45)
0 Character's z-coordinate will be 2 after going up to the right (when A=1), or moving right requires special handling (when A=5; see EC45)
When A=3, B returns holding Q'', the third byte of the location descriptor. Bit 0 of this byte is set if there is a door that can close at the given location; bits 2-7 indicate whether the adjacent location in the corresponding direction is inside (set) or outside (reset) the building, and therefore may require a transition of the character's z-coordinate between 1 and 2 (see 76BC):
Bit Direction
7 Left
6 Right
5 Up/left
4 Up/right
3 Down/left
2 Down/right
When A=5, B returns holding Q'', the third byte of the location descriptor; this byte determines the address of the routine to handle movement to the left or right at a special location (see EC45).
Input
H Character number (0xD7-0xE6)
EB13 CALL $EAF8 Is the character on the sidewalk or the road?
EB16 JR C,$EB20 Jump if not
EB18 LD (HL),L Set the character's z-coordinate to 4 (on the sidewalk or road)
EB19 LD D,$C4 Collect a location descriptor from the table at C400
EB1B LD A,(DE)
EB1C LD C,A Copy the location descriptor to C
EB1D LD A,$01 A=1 (character is on the sidewalk or the road)
EB1F RET
The character is not on the sidewalk or the road.
EB20 LD A,(HL) A=character's z-coordinate
EB21 CP $04 Is the character outside?
EB23 JR NZ,$EB27 Jump if not
EB25 LD (HL),$02 Set the character's z-coordinate to 2
EB27 LD A,D A=y, the character's y-coordinate (6-35)
EB28 SUB $04 B=4*(y-4)
EB2A ADD A,A
EB2B ADD A,A
EB2C LD B,A
EB2D BIT 0,(HL) Is the character indoors?
EB2F JR NZ,$EB33 Jump if so
EB31 SET 7,B B=128+4*(y-4) if the character's z-coordinate is 2
Now B holds a value indicating the character's y-coordinate (bits 2-6: y-4) and z-coordinate (bit 7: z-1).
EB33 EX DE,HL L=character's x-coordinate
EB34 LD H,$C5 Collect an LSB from the table at C500
EB36 LD A,(HL)
EB37 SUB $02 Subtract 2 from this LSB
EB39 INC H Point HL at an MSB in the table at C600
EB3A LD H,(HL) Pick up the MSB in H
EB3B LD E,L E=character's x-coordinate
EB3C LD L,A Now HL holds 2 less than the address formed by the LSB and MSB just collected from the tables at C500 and C600
The loop that iterates over the location descriptors for the character's x-coordinate begins here.
EB3D INC L Move HL along the location descriptor table
This entry point is used by the routine at ED30.
EB3E INC L Point HL at the first byte of a location descriptor
EB3F JR Z,$EB45 Jump if we reached a page boundary
EB41 LD A,(HL) Pick up the first byte (Q) of the location descriptor
EB42 INC A Have we reached the end of the location descriptors for the character's x-coordinate?
EB43 JR NZ,$EB4A Jump if not
The character is not at any of the locations to which the location descriptors for his x-coordinate correspond.
EB45 LD C,$C0 Bits 7 and 6 set: the character can move left or right only
EB47 LD A,$02 A=2: regular location
EB49 RET
Here we examine a location descriptor and check whether the character is at the location to which it corresponds.
EB4A DEC A A=Q (first byte of the location descriptor)
EB4B INC L Point HL at the second byte of the location descriptor
EB4C ADD A,A Is bit 7 of Q set (meaning this location is next to the entrance to a building or requires special handling)?
EB4D JR C,$EB56 Jump if so
EB4F CP B Is the character at the location to which the location descriptor corresponds?
EB50 JR NZ,$EB3E Move along to the next location descriptor if not
EB52 LD C,(HL) C=Q' (second byte of the location descriptor)
EB53 LD A,$02 A=2: regular location
EB55 RET
The location descriptor being examined has bit 7 of its first byte set, which means that it corresponds to a location that is next to the entrance to a building, or a location that requires special handling.
EB56 ADD A,A Is bit 6 of Q set (meaning this location is next to the entrance to a building)?
EB57 JR C,$EB62 Jump if so
EB59 CP B Is the character at the location to which the location descriptor corresponds?
EB5A JR NZ,$EB3D Move along to the next location descriptor if not
EB5C LD A,$05 A=5: this location requires special handling
EB5E LD C,(HL) Collect the second and third bytes of the location descriptor (Q' and Q'') in C and B
EB5F INC L
EB60 LD B,(HL)
EB61 RET
The location descriptor being examined has bits 7 and 6 of its first byte set, which means that it corresponds to a location that is next to the entrance to a building (where a character's z-coordinate may be 1 or 2).
EB62 LD C,B C=4*(y-4) (where y is the character's y-coordinate)
EB63 RES 7,C
EB65 CP C Is the character at the location to which the location descriptor corresponds?
EB66 JR NZ,$EB3D Move along to the next location descriptor if not
The character is standing next to the entrance to a building. Check whether a closed door is in his way.
EB68 INC L Point HL at the third byte of the location descriptor
EB69 BIT 0,(HL) Is there a door at this location?
EB6B JR Z,$EB7E Jump if not
EB6D LD A,E A=x, the character's x-coordinate
EB6E INC A A=INT((x+1)/8)
EB6F RRCA
EB70 RRCA
EB71 RRCA
EB72 AND $1F
EB74 PUSH HL Save the location descriptor pointer briefly
EB75 LD L,A Point HL at the entry in the table of Z values at BD00 that corresponds to the door
EB76 LD H,$BD
EB78 BIT 2,(HL) Set the zero flag if the door is open
EB7A POP HL Restore the location descriptor pointer to HL
EB7B JP NZ,$ED30 Jump if the door is closed to find the location descriptor that corresponds to the character's z-coordinate (1=behind the door, 2=in front of it)
EB7E LD A,$03 A=3: the character is standing next to the open entrance to a building
EB80 DEC L Point HL at the second byte of the location descriptor
EB81 JR $EB5E Jump back to collect the second and third bytes (Q' and Q'') in C and B
Prev: EAF8 Up: Map Next: EB83