Prev: EBAE Up: Map Next: EC58
EBBB: Make a character move left
Used by the routines at ECE1, F5CE, F600 and F6E9. Turns the character round if he's facing right; otherwise moves him left, or up and to the left, or down and to the left (in that order of preference, and if possible). Returns with the carry flag set unless the character could not move.
Input
H Character number (0xD7-0xE6)
EBBB CALL $EB85 Make the character stand up if he's lying down
EBBE RET C Return if the character was lying down
EBBF BIT 7,(HL) Set the zero flag if the character is facing left
EBC1 LD DE,$A019 Point DE at the direction indicator table at A019
EBC4 JR Z,$EBD0 Jump if the character is facing left
The character is facing right, so we make him turn round first. This entry point is also used by the routine at EBAE to make a character who is facing left turn round.
EBC6 CALL $E9C8 Update the SRB for the character's current animatory state and location
EBC9 XOR $80 Flip bit 7 of the character's animatory state, thus turning him round
This entry point is used by the routine at EB85.
EBCB CALL $E9D5 Update the character's animatory state and location and update the SRB
EBCE SCF Set the carry flag to indicate that the character was moved
EBCF RET
This entry point is used by the routine at EB9B (with DE=A218, A318, A418 or A518) to move a character up or down, and by the routine at EBAE (with DE=A119) to make a character move right.
EBD0 PUSH HL Save the character buffer pointer briefly
EBD1 PUSH DE Save the pointer to the direction indicator table
EBD2 CALL $EB13 Obtain descriptors for the character's current location
EBD5 POP HL Point HL at the direction indicator table (A019, A119, A218, A318, A418 or A518)
EBD6 LD E,A E=location type indicator (1-5; see EB13)
EBD7 LD A,C A=direction descriptor (see EB13)
EBD8 AND (HL) Does this direction indicator correspond to a direction that is available at the character's current location?
EBD9 JR NZ,$EBE2 Jump if so
EBDB INC L Point HL at the next byte in the direction indicator table
EBDC BIT 2,L Have we reached the end of the direction indicator table?
EBDE JR Z,$EBD7 Jump back if not
EBE0 POP HL Restore the character buffer pointer to HL
EBE1 RET Return with the carry flag reset (the character did not move)
Now A=0x80, 0x40, 0x20, 0x10, 0x08 or 0x04; the bit set in A indicates the direction in which the character has chosen to move next:
Bit Direction
7 Left
6 Right
5 Up and to the left
4 Up and to the right
3 Down and to the left
2 Down and to the right
EBE2 LD D,A D=direction indicator (0x80, 0x40, 0x20, 0x10, 0x08 or 0x04)
EBE3 POP HL Restore the character buffer pointer to HL
EBE4 BIT 7,(HL) Set the zero flag if the character is facing left
EBE6 LD A,$54 A=0x54: bits 6 (right), 4 (up/right) and 2 (down/right) set
EBE8 JR NZ,$EBEB Jump if the character is facing right
EBEA ADD A,A A=0xA8: bits 7 (left), 5 (up/left) and 3 (down/left) set
EBEB AND D Is the character facing the direction in which he wants to move?
EBEC JR Z,$EBC6 Make him turn round if not
The character is facing the direction in which he wants to move. Now we examine the character's current location to determine whether the desired move requires any special handling.
EBEE LD L,$04 Point HL at byte 0x04 of the character's buffer
EBF0 LD A,E A=location type indicator for the character's current location (1-5; see EB13)
EBF1 DEC A Is the character on the sidewalk or the road?
EBF2 JR NZ,$EC04 Jump if not
The character is on the sidewalk or the road. In this case we need to check whether the character is going up a step, and change his z-coordinate accordingly.
EBF4 LD A,D A=direction indicator (0x80, 0x40, 0x20, 0x10, 0x08 or 0x04)
EBF5 AND $30 Check bits 4 and 5: is the character going to move up a step?
EBF7 JR Z,$EC07 Jump if not
EBF9 RRCA Slide bits 5 and 4 of A into bits 1 and 0
EBFA RRCA
EBFB RRCA
EBFC RRCA
EBFD AND C Will going up the step change the character's z-coordinate to 2?
EBFE JR Z,$EC07 Jump if not
EC00 LD (HL),$02 Set the character's z-coordinate to 2
EC02 JR $EC07
The character is not on the sidewalk or the road.
EC04 RRCA Is the location type indicator 3 (at the open entrance to a building) or 5 (a location that requires special handling)?
EC05 JR NC,$EC39 Jump if so
Finally we can move the character midstride in the desired direction and update the SRB accordingly. This entry point is used by the routines at 7B5C and FC00. The address of this entry point is also found at A016; it is used to handle a character who is moving from one of a set of certain special locations, but it does not actually do anything special.
EC07 LD L,$00 Point HL at byte 0x00 of the character's buffer
EC09 LD C,$05 Point BC at byte 0x05 of the character's buffer
EC0B LD B,H
EC0C LD A,(HL) A=character's animatory state
EC0D XOR $02 A=character's post-midstride animatory state
EC0F LD (BC),A Save this in byte 0x05 of the character's buffer
EC10 INC L Point HL at byte 0x01 of the character's buffer
EC11 INC C Point BC at byte 0x06 of the character's buffer
EC12 RLCA A=-1 if the character is facing left, 1 if he's facing right
EC13 SBC A,A
EC14 ADD A,A
EC15 CPL
EC16 ADD A,(HL) Add the character's current x-coordinate to obtain his post-midstride x-coordinate
EC17 LD (BC),A Save this in byte 0x06 of the character's buffer
EC18 INC L Point HL at byte 0x02 of the character's buffer
EC19 INC C Point BC at byte 0x07 of the character's buffer
EC1A LD A,D A=direction indicator (0x80, 0x40, 0x20, 0x10, 0x08 or 0x04)
EC1B AND $3C Is the character going up or down a step?
EC1D JR Z,$EC26 Jump if not
EC1F AND $30 Is the character going up a step?
EC21 JR Z,$EC25 Jump if not
EC23 LD A,$FE A=-2
EC25 INC A A=-1 if the character is going up a step, or 1 if he's going down a step
EC26 ADD A,(HL) Add the character's y-coordinate; now the carry flag is set if the character will be going up a step
EC27 LD L,$00 Point HL at byte 0x00 of the character's buffer
EC29 LD (BC),A Save the character's post-midstride y-coordinate in byte 0x07 of his buffer
EC2A LD A,(HL) A=character's animatory state
EC2B PUSH AF Save the carry flag briefly
EC2C CALL $E9C8 Update the SRB for the character's current animatory state and location
EC2F POP AF Restore the carry flag
EC30 JR NC,$EC33 Jump unless the character is going up a step
EC32 DEC D D=character's new y-coordinate
EC33 INC A A=character's new animatory state
EC34 CALL $E9D5 Update the character's animatory state and location and update the SRB
EC37 SCF Set the carry flag to indicate that the character was moved
EC38 RET
The location type indicator is 3 (at the open entrance to a building) or 5 (a location that requires special handling).
EC39 RRCA Is the location type indicator 5 (a location that requires special handling)?
EC3A JR NC,$EC45 Jump if so
The character is standing at the open entrance to a building.
EC3C DEC (HL) Set the zero flag if the character is indoors
EC3D LD (HL),$01 Set the character's z-coordinate to 1 (indoors)
EC3F LD A,D A=direction indicator (0x80, 0x40, 0x20, 0x10, 0x08 or 0x04)
EC40 CALL $76BC Adjust the character's z-coordinate according to whether he is going to enter or exit the building, and, if dealing with Sam, check whether he is entering a house without a key
EC43 JR $EC07 Move the character midstride
The character is at a location that may require special handling depending on the direction in which he is going.
EC45 LD A,D A=direction indicator (0x80, 0x40, 0x20, 0x10, 0x08 or 0x04)
EC46 RLCA Move bits 7 (left) and 6 (right) into bits 1 and 0 for comparison with bits 1 and 0 of the direction descriptor in C
EC47 RLCA
EC48 AND C Is the character moving in a direction that requires special handling (e.g. off the edge of a roof)?
EC49 JR Z,$EC07 Jump if not to move the character midstride
The character's next move requires special handling.
EC4B LD A,B A=Q'', the third byte of the location descriptor (1-7; see EB13)
EC4C ADD A,$9F A=0xA0-0xA6
EC4E PUSH HL Save the character number briefly
EC4F LD H,A Collect in HL the special location handler routine address (7B5C, EC07 or FB52) from A016, A116, A216, A316, A416, A516 or A616
EC50 LD L,$16
EC52 LD A,(HL)
EC53 INC L
EC54 LD H,(HL)
EC55 LD L,A
EC56 EX (SP),HL Restore the character number to H, and copy the special location handler routine address onto the stack
EC57 RET To 7B5C (if Q''=7), EC07 (Q''=1) or FB52 (Q''=2, 3, 4, 5 or 6)
Prev: EBAE Up: Map Next: EC58