Prev: 72AA Up: Map Next: 7376
72B1: Control a policeman (2)
The address of this primary command routine is placed into bytes 0x08 and 0x09 of a policeman's buffer by the routine at 72AA. It makes the policeman continue patrol duty, and chase and pick up Sam when appropriate.
Input
H 0xDE or 0xDF (policeman)
72B1 CALL $F698 Exit now if the policeman is midstride
72B4 CALL $7CFE Is Sam wanted by the police at the moment?
72B7 RRA
72B8 JR NC,$7324 Jump if not
72BA LD L,$08 Change the address of the primary command routine in bytes 0x08 and 0x09 of the policeman's buffer to 72BE (below)
72BC LD (HL),$BE
This entry point is used when the policeman is not chasing Sam.
72BE CALL $F698 Exit now if the policeman is midstride
72C1 CALL $7CFE Is Sam wanted by the police at the moment?
72C4 RRA
72C5 JR C,$72D5 Jump if so
72C7 LD L,$1D Clear any disguise identifier and timeout counter in byte 0x1D of the policeman's buffer
72C9 LD (HL),$00
72CB LD L,$03 Reset bit 7 of byte 0x03 of the policeman's buffer (no need to run if Sam's not wanted by the police)
72CD RES 7,(HL)
72CF LD L,$08 Change the address of the primary command routine in bytes 0x08 and 0x09 of the policeman's buffer to 72B1
72D1 LD (HL),$B1
72D3 JR $7324 Determine the policeman's next move
Sam is wanted by the police.
72D5 CALL $7377 Make the policeman start chasing Sam if he spots him, or go to Sam's last known whereabouts if Sam's disguise has become known to the police
72D8 JR NC,$72EB Jump if the policeman is now doing either of those things
72DA LD DE,$7FDC 7FDC holds the y-coordinate of the location the police should be heading for to get Sam
72DD LD A,(DE) Pick it up in A
72DE AND A Do the police know where they should be heading to get Sam?
72DF JR Z,$7324 Jump if not to make the policeman continue to go about his normal business
72E1 DEC E DE=7FDB
72E2 LD BC,$0003 Copy the coordinates and location identifier of the spot to which the police should be heading to get Sam into byte 0x0A-0x0C of the policeman's buffer, thus making it his destination
72E5 LD L,$0A
72E7 EX DE,HL
72E8 LDIR
72EA EX DE,HL
72EB LD L,$03 Set bit 7 of byte 0x03 of the policeman's buffer (to make him run)
72ED SET 7,(HL)
72EF LD L,$08 Change the address of the primary command routine in bytes 0x08 and 0x09 of the policeman's buffer to 72F5 (below)
72F1 LD (HL),$F5
72F3 JR $7324
This entry point is used when the policeman is chasing Sam or heading to his last known whereabouts.
72F5 CALL $7CFE Should the police be chasing Sam at the moment?
72F8 RRA
72F9 JR NC,$72BE Jump if not
72FB LD A,($7FC9) Collect the ID of Sam's current disguise from 7FC9
72FE ADD A,$A0 B=0xA0-0xA7
7300 LD B,A
7301 EX DE,HL Transfer the policeman's character number to D briefly
7302 LD C,$15 Point BC at byte 0x15 of one of the pages 0xA0-0xA7, which hold the values 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02 and 0x01
7304 LD HL,$7FE8 The disguise status flags are stored at 7FE8
7307 LD A,(BC) Set the zero flag if Sam's disguise is unknown to the police
7308 AND (HL)
7309 EX DE,HL Transfer the policeman's character number back to H
730A JR Z,$731B Jump if Sam's disguise is unknown to the police
730C CALL $710E Is the policeman close enough to Sam to pick him up?
730F JR NC,$731B Jump if not
7311 XOR A Clear the y-coordinate of the spot to which the police should run to get Sam at 7FDC (Sam has been caught)
7312 LD ($7FDC),A
7315 LD L,$1D Clear any disguise ID and timeout counter in byte 0x1D of the policeman's buffer
7317 LD (HL),A
7318 JP $7B9A End the game if Sam has less than $46, or make the policeman pick Sam up
Sam's disguise is unknown to the police, or the policeman is not close enough to Sam to pick him up.
731B CALL $F698 Exit now if the policeman is midstride
731E CALL $7377 Make the policeman start chasing Sam if his disguise becomes known
7321 CALL $717C Make the policeman switch a light on if possible
7324 CALL $ED8C Determine the next move the policeman should make to reach his destination
This entry point is used by the routine at F600 with A=1-6.
7327 CP $05 Is the character standing behind or in front of a closed door?
7329 JP NC,$F67C Jump if so
732C AND A Is the character already at his destination?
732D JP NZ,$F63C Jump if not
The policeman has reached his destination.
7330 LD L,$08 Collect the LSB of the primary command routine address from byte 0x08 of the policeman's buffer
7332 LD A,(HL)
7333 CP $F5 Is the primary command routine address 72F5 (which is true if the policeman was either chasing Sam or heading towards his last known whereabouts)?
7335 JR C,$7360 If not, send the policeman to a randomly chosen spot on the sidewalk or road
7337 LD DE,$7FDC Collect the y-coordinate of the location to which the police should run to get Sam from 7FDC
733A LD A,(DE)
733B AND A Do the police know where to run to get Sam?
733C JR Z,$734B Jump if not
733E LD L,$02 Point HL at byte 0x02 of the policeman's buffer
7340 CP (HL) Compare the policeman's y-coordinate with that of the spot to which the police should run to get Sam
7341 DEC DE DE=7FDB
7342 JR NZ,$7355 Jump unless the policeman's y-coordinate matches
7344 DEC L L=0x01
7345 LD A,(DE) A=x-coordinate of the spot to which the police should run to get Sam
7346 SUB (HL) Does it match the policeman's x-coordinate?
7347 JR NZ,$7355 Jump if not
7349 INC E Set 7FDC to 0 now that a policeman has made it to the spot to which the police should run to get Sam
734A LD (DE),A
734B LD L,$03 Reset bit 7 of byte 0x03 of the policeman's buffer (to make him stop running)
734D RES 7,(HL)
734F LD L,$08 Change the address of the primary command routine in bytes 0x08 and 0x09 of the policeman's buffer to 72BE (above)
7351 LD (HL),$BE
7353 JR $7360 Send the policeman to a randomly chosen spot on the sidewalk or road
7355 LD L,$0A Copy the coordinates and location identifier of the spot to which the police should run to get Sam from 7FDB into bytes 0x0A-0x0C of the policeman's buffer, thus making it his destination
7357 LD BC,$0003
735A EX DE,HL
735B LDIR
735D EX DE,HL Point HL back at the policeman's buffer
735E JR $7324 Determine the policeman's next move
This entry point is used by the routine at 72AA. It sets the policeman's destination to a randomly chosen spot on the sidewalk or road.
7360 CALL $F17F Get a random number in A
7363 OR $00 The operand of this OR instruction is changed by the routine at 7500: to 0x00 (using the event entry at 5FE0), or to 0xC0 (using the event entry at 6097) to keep the policeman close to Sam's office
7365 AND $FD Discard bit 1
7367 LD E,A Copy this x-coordinate to E
7368 CALL $EB05 Set the carry flag if there is no sidewalk at this x-coordinate
736B ADC A,$22 A=34 (if there is sidewalk) or 35 (if there is no sidewalk)
736D SUB E
736E LD D,A Copy this y-coordinate to D
736F LD C,$00 Clear bit 0 of C to indicate that the destination is not indoors
7371 CALL $7194 Set the policeman's destination to the coordinates in E, D and C
7374 JR $7324 Determine the policeman's next move
Prev: 72AA Up: Map Next: 7376