| Routines

25944: Determine Sam's location

Used by the routines at 28942, 29072 and 29218. Returns with Sam's x-, y- and z-coordinates (adjusted appropriately if Sam is falling, rolling, somersaulting or being carried) in E, D and A.
25944 | LD DE,(58881) | Collect Sam's x- and y-coordinates in E and D
25948 | LD A,(32764) | Pick up Sam's status flags from 32764
25951 | BIT 3,A | Is Sam rolling or somersaulting?
25953 | JR NZ,25967 | Jump if so
25955 | AND 129 | Is Sam either being carried by a gangster or policeman, or falling from the roof of a building?
25957 | LD A,(58884) | Return with A holding Sam's z-coordinate if not
25960 | RET Z
Sam is either being carried by a policeman, or falling from the roof of a building.
25961 | LD A,2 | 2=behind people on the sidewalk
25963 | LD DE,9896 | D=38, E=168 (out of reach)
25966 | RET |
Sam is rolling or somersaulting.
25967 | LD A,(58880) | A=Sam's animatory state
25970 | AND 127 | Discard bit 7 (the direction bit)
25972 | CP 15 | Is Sam horizontal at the moment (animatory state 15 or 31)?
25974 | JR C,25978 | Jump if not
25976 | INC E | Add 2 to Sam's x-coordinate if he's horizontal
25977 | INC E
25978 | LD A,E | A=x+2 if Sam's horizontal, or x otherwise (where x is Sam's x-coordinate)
25979 | CALL 60165 | Reset the carry flag if Sam is on or above the sidewalk, or set it if he's on or above the road
25982 | ADC A,34 | D=34 if Sam's on or above the sidewalk, 35 if he's on or above the road
25984 | SUB E
25985 | LD D,A
25986 | LD A,4 | 4=outside
25988 | RET |