| Routines

30511: Check whether a character can answer the telephone that Sam is calling

Used by the routine at 30675. Returns with the carry flag set if the telephone that Sam is calling is both off-screen and not his own, or if there is a character close enough to the telephone to pick it up.
30511 | LD HL,32666 | 32666 holds the identifier of the telephone that Sam is calling
30514 | LD A,(HL) | Pick this up in A
30515 | AND 31 | E=x-coordinate of the leftmost column of the 8-tile-wide segment of the play area that contains the telephone (0, 8, 16,...248)
30517 | ADD A,A
30518 | ADD A,A
30519 | ADD A,A
30520 | LD E,A
30521 | LD A,(HL) | A=telephone identifier
30522 | CP 92 | Is Sam calling his office?
30524 | JR Z,30538 | Jump if so
30526 | LD A,E | A=telephone's x-coordinate (0, 8, 16,...248)
30527 | LD L,254 | HL=32766, which holds the leftmost column of the play area on screen
30529 | CP (HL) | Is the telephone that Sam is calling off screen to the left?
30530 | RET C | Return with the carry flag set if so
30531 | SUB 32 | Does the telephone that Sam is calling have an x-coordinate that is less than 32?
30533 | JR C,30538 | Jump if so (it's on screen)
30535 | CP (HL) | Is the telephone that Sam is calling off screen to the right?
30536 | CCF | Return with the carry flag set if so
30537 | RET C
Sam has called his office, or a telephone that is on screen. In this case, Sam will get an answer only if another character is close to the telephone.
30538 | LD L,154 | Collect the telephone identifier from 32666
30540 | LD A,(HL)
30541 | AND 224 | D=y-coordinate of the telephone (7, 13, 19, 25 or 31)
30543 | RRCA
30544 | RRCA
30545 | RRCA
30546 | LD D,A
30547 | RRCA
30548 | ADD A,D
30549 | ADD A,7
30551 | LD D,A
30552 | LD HL,55042 | Point HL at byte 2 of character buffer 215
30555 | LD B,15 | We will check the locations of characters 215-229
30557 | LD A,(HL) | A=character's y-coordinate
30558 | CP D | Does it match that of the telephone?
30559 | JR NZ,30569 | Jump to consider the next character if not
30561 | DEC L | L=1
30562 | LD A,(HL) | A=character's x-coordinate
30563 | INC L | L=2
30564 | AND 248 | Set the zero flag if the character is in the same 8-tile-wide segment of the play area as the telephone
30566 | CP E
30567 | SCF | Set the carry flag
30568 | RET Z | Return with the carry flag set if the character is close to the telephone
30569 | INC H | Next character
30570 | DJNZ 30557 | Jump back until every character has been checked
30572 | AND A | Reset the carry flag (there is no one close to the telephone)
30573 | RET |