Prev: 6463 Up: Map Next: 64D4
6464: Make a character go to a location
Used by command lists 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x24, 0x26, 0x28, 0x2C, 0x2E, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E, 0x40, 0x42, 0x46, 0x48, 0x4A, 0x4C, 0x4E, 0x50, 0x52, 0x54, 0x56 and 0x58 to make a character go to a specified place.
Input
H Character number (0xB7-0xD1)
6464 LD L,$05 Copy the destination coordinates from the command list into bytes 0x05 and 0x06 of the character's buffer
6466 CALL $6264
This entry point is used by the routine at 64D7.
6469 LD L,$03 Replace the address of this routine in bytes 0x03 and 0x04 of the character's buffer with 647E (below)
646B LD (HL),$7E
646D LD L,$00 Point HL at byte 0x00 of the character's buffer
646F LD A,(HL) A=character's animatory state
6470 AND $07 Is the character sitting on a chair (kids only)?
6472 CP $04
6474 JR NZ,$647E Jump if not
The character is sitting on a chair. He'll have to stand up first.
6476 CALL $61B4 Update the SRB for the character's current animatory state
6479 AND $F8 A=animatory state of the character standing up
647B JP $6130 Update the character's animatory state and update the SRB
The second and subsequent calls to this routine (from 62D0) enter here:
647E LD L,$06 Collect the destination coordinates into DE
6480 LD D,(HL)
6481 DEC L
6482 LD E,(HL)
6483 LD L,$01 Point HL at byte 0x01 of the character's buffer
6485 LD A,E A=destination x-coordinate
6486 CP (HL) Compare it with the character's current x-coordinate
6487 INC HL L=0x02
6488 JR NZ,$648F Jump forward unless the character's current x-coordinate matches that of the destination
648A LD A,D A=destination y-coordinate
648B CP (HL) Is the character already at his destination?
648C JP Z,$638C Move to the next command in the command list if so
The character hasn't reached his destination yet.
648F CALL $63D2 Get the region identifier for the character's destination
Now A holds a region ID (0xBD-0xC4) corresponding to the character's destination:
ID Region
0xBD Top floor, left of the left study door in the boys' skool
0xBE Middle floor, left of the far wall of the Science Lab storeroom
0xBF Bottom floor (anywhere)
0xC0 Assembly hall stage
0xC1 Near the middle-floor window in the boys' skool
0xC2 Top floor, right of the left study door in the boys' skool
0xC3 Middle floor, girls' skool
0xC4 Top floor, girls' skool
6492 LD D,(HL) Collect the character's current coordinates into DE
6493 DEC L
6494 LD E,(HL)
6495 LD L,A L=destination region ID (0xBD-0xC4)
6496 CALL $63D2 A=region ID (0xBD-0xC4) for the character's current location
6499 CP L Will the character have to negotiate any staircases in order to reach his destination?
649A JR Z,$64C8 Jump if not (he's in the same region as his destination)
649C LD D,A D=region ID of the character's current location (0xBD-0xC4)
649D LD A,L A=destination region ID (0xBD-0xC4)
649E SUB $81 E=destination region ID minus 0x81 (0x3C-0x43)
64A0 LD E,A
64A1 LD A,(DE) Collect the appropriate staircase endpoint identifier
The staircase endpoint identifiers are arranged in bytes 0x3C-0x43 (corresponding to the destination) of pages 0xBD-0xC4 (corresponding to the current location) as follows:
0xBD 0xBE 0xBF 0xC0 0xC1 0xC2 0xC3 0xC4
BD3C 0xBD 0xBD 0xBD 0xBD 0xBD 0xBD 0xBD 0xBD
BE3C 0xBE 0xBE 0xBF 0xBF 0xBF 0xBF 0xBF 0xBF
BF3C 0xBF 0xC0 0xC0 0xC1 0xC1 0xC1 0xC2 0xC2
C03C 0xC0 0xC3 0xC3 0xC3 0xC4 0xC4 0xC3 0xC3
C13C 0xC1 0xC5 0xC5 0xC5 0xC5 0xC6 0xC5 0xC5
C23C 0xC2 0xC7 0xC7 0xC7 0xC7 0xC7 0xC7 0xC7
C33C 0xC3 0xC8 0xC8 0xC8 0xC8 0xC8 0xC8 0xCE
C43C 0xC4 0xCF 0xCF 0xCF 0xCF 0xCF 0xCF 0xCF
The staircase endpoint indentifier now in A (0xBD-0xC8, 0xCE or 0xCF) corresponds to the top or bottom of the first staircase the character will have to negotiate in order to reach his destination. The x-coordinate (x), direction indicator (d), appropriate routine address LSB (0x38 for 6438, 0x4D for 644D) and number of steps (n) for the staircase can be found in bytes 0x44-0x47 of pages 0xBD-0xC8 and 0xCE-0xCF, as follows:
ID x d LSB n Staircase endpoint
0xBD 26 0x00 0x4D 8 Top of the staircase leading down from the Revision Library
0xBE 19 0x80 0x38 8 Bottom of the staircase leading up to the Revision Library
0xBF 15 0x80 0x4D 8 Top of the staircase leading down to the bottom floor on the far left of the boys' skool
0xC0 22 0x00 0x38 8 Bottom of the staircase leading up to the middle floor on the far left of the boys' skool
0xC1 83 0x00 0x38 4 Bottom of the staircase leading up to the assembly hall stage
0xC2 176 0x80 0x38 8 Bottom of the staircase leading up to the middle floor in the girls' skool
0xC3 80 0x80 0x4D 4 Top of the staircase leading down from the assembly hall stage
0xC4 81 0x80 0x38 5 Bottom of the staircase leading up from the assembly hall stage
0xC5 85 0x00 0x4D 5 Top of the staircase leading down to the assembly hall stage
0xC6 91 0x00 0x38 8 Bottom of the staircase leading up to the head's study
0xC7 84 0x80 0x4D 8 Top of the staircase leading down from the head's study
0xC8 183 0x00 0x4D 8 Top of the staircase leading down to the bottom floor in the girls' skool
0xCE 186 0x00 0x38 8 Bottom of the staircase leading up to the top floor in the girls' skool
0xCF 179 0x80 0x4D 8 Top of the staircase leading down to middle floor in the girls' skool
64A2 LD D,A Place the staircase endpoint identifier in D
64A3 LD E,$44 Byte 0x44 holds the x-coordinate of the top or bottom of the staircase identified by D
64A5 LD L,$01 Point DE at byte 0x01 of the character's buffer, and HL at the staircase endpoint x-coordinate
64A7 EX DE,HL
64A8 LD A,(DE) A=character's current x-coordinate
64A9 CP (HL) Is the character already at the top or bottom of the appropriate staircase?
64AA JR NZ,$64C4 Jump forward if not
At this stage the character is standing at the top or bottom of the first staircase he will have to negotiate in order to reach his destination.
64AC INC L (HL)=0x00 if the character has to face left to ascend or descend the stairs, 0x80 otherwise
64AD DEC E E=0x00
64AE LD A,(DE) A=character's animatory state
64AF XOR (HL) Set the carry flag if the character has to turn round to negotiate the staircase
64B0 RLCA
64B1 EX DE,HL Swap DE and HL so that H holds the character number
64B2 JP C,$6430 Turn the character round if he's facing the wrong way
64B5 EX DE,HL Swap DE and HL back again
64B6 LD E,$0B Point DE at byte 0x0B of the character's buffer
64B8 INC L L=0x46
64B9 LD C,(HL) BC=6438 if the stairs are to be ascended, 644D if descended
64BA LD B,$64
64BC NOP
64BD INC L L=0x47
64BE LD A,(HL) A=1 + number of steps in the staircase
64BF LD (DE),A Place this number of steps in byte 0x0B of the character's buffer
64C0 EX DE,HL Swap DE and HL so that H holds the character number
64C1 JP $63B0 Copy the interruptible subcommand routine address from BC into bytes 0x09 and 0x0A of the character's buffer and jump to it
The character is not yet at the top or bottom of the appropriate staircase.
64C4 LD A,(HL) A=x-coordinate of the top or bottom of the staircase
64C5 EX DE,HL H=character number
64C6 JR $64CB Send the character towards the staircase
The character can reach his destination without negotiating any staircases.
64C8 LD L,$05 Point HL at byte 0x05 of the character's buffer
64CA LD A,(HL) A=x-coordinate of the character's destination
64CB LD L,$0B Place the x-coordinate of the top or bottom of the staircase, or the destination, into byte 0x0B of the character's buffer
64CD LD (HL),A
64CE LD BC,$63ED Place the address of the interruptible subcommand routine at 63ED into bytes 0x09 and 0x0A of the character's buffer and jump to it, thus guiding the character to this x-coordinate
64D1 JP $63B0
Prev: 6463 Up: Map Next: 64D4