| Routines

64D7: Make a character go to a random location

Used by command lists 0x12, 0x14, 0x1C, 0x28, 0x2A, 0x42, 0x44, 0x4E and 0x58 to make a character go to a place at random. The random locations are arranged in eight groups of four. The group of locations that is suitable for a particular character to choose from is determined by byte 0x24 of the character's buffer.
Input
H | Character number (0xB7-0xD1)
64D7 | LD L,$24 | Point HL at byte 0x24 of the character's buffer
64D9 | LD E,(HL) | Pick up the contents in E
64DA | EX DE,HL |
64DB | CALL $6291 | A=random number
64DE | AND $03 | A=0xD3, 0xD4, 0xD5 or 0xD6
64E0 | ADD A,$D3
64E2 | LD H,A | Point HL at an entry in the table of random locations
64E3 | LD E,$01 | Point DE at byte 0x01 of the character's buffer
64E5 | LD A,(DE) | A=character's x-coordinate
64E6 | CP (HL) | Is the character already at this x-coordinate?
64E7 | JR Z,$64DB | Get another random location if so
64E9 | LD E,$05 | Copy the random location's coordinates into bytes 0x05 and 0x06 of the character's buffer, thus making it his next destination
64EB | LDI
64ED | LDI
64EF | EX DE,HL | Transfer the character number back to H
64F0 | JP $6469 | Send the character on his way
The contents of byte 0x24 of each character's buffer are as follows:
H | Character | Address | Byte
--- | --- | --- | ---
0xB7 | Little girl no. 1 | B724 | 0x24
0xB8 | Little girl no. 2 | B824 | 0x24
0xB9 | Little girl no. 3 | B924 | 0x24
0xBA | Little girl no. 4 | BA24 | 0x26
0xBB | Little girl no. 5 | BB24 | 0x26
0xBC | Little girl no. 6 | BC24 | 0x26
0xBD | Little girl no. 7 | BD24 | 0x26
0xBE | Little boy no. 1 | BE24 | 0x28
0xBF | Little boy no. 2 | BF24 | 0x28
0xC0 | Little boy no. 3 | C024 | 0x28
0xC1 | Little boy no. 4 | C124 | 0x2A
0xC2 | Little boy no. 5 | C224 | 0x2A
0xC3 | Little boy no. 6 | C324 | 0x2A
0xC4 | Little boy no. 7 | C424 | 0x2A
0xC5 | Little boy no. 8 | C524 | 0x2A
0xC6 | Little boy no. 9 | C624 | 0x2C
0xC7 | Little boy no. 10 | C724 | 0x2C
0xC8 | MR WACKER | C824 | 0x30
0xC9 | MR WITHIT | C924 | 0x30
0xCA | MR ROCKITT | CA24 | 0x44
0xCB | MR CREAK | CB24 | 0x44
0xCC | MISS TAKE | CC24 | 0x26
0xCD | ALBERT | CD24 | 0x2C
0xCE | BOY WANDER | CE24 | 0x2E
0xCF | ANGELFACE | CF24 | 0x2E
0xD0 | EINSTEIN | D024 | 0x2C
0xD1 | HAYLEY | D124 | 0x24
The eight groups of random locations used by this routine are:
E | D=0xD3 | D=0xD4 | D=0xD5 | D=0xD6
--- | --- | --- | --- | ---
0x24 | 129,17 | 144,17 | 136,17 | 189,17
0x26 | 189,17 | 189,10 | 170,17 | 182,3
0x28 | 38,3 | 10,10 | 10,17 | 66,17
0x2A | 38,3 | 10,17 | 109,17 | 75,17
0x2C | 112,17 | 145,17 | 158,17 | 37,3
0x2E | 189,10 | 183,17 | 137,17 | 72,17
0x30 | 157,17 | 38,3 | 10,17 | 92,17
0x44 | 38,3 | 90,3 | 10,17 | 90,17