| Routines

30675: Deal with Sam when he's on the phone

Used by the routine at 29912 when bit 4 at 32764 is set (by the routine at 30458), indicating that Sam is on the phone.
30675 | LD HL,32667 | The telephone call status flags are stored at 32667
30678 | BIT 6,(HL) | Has someone asked Sam 'WHO'S THERE?'
30680 | JP NZ,30575 | Jump if so
30683 | BIT 1,(HL) | Is the telephone call still in progress?
30685 | JR Z,30691 | Jump if so
30687 | CALL 61923 | Hang up if 'h' was pressed
30690 | RET |
The telephone call is still in progress.
30691 | BIT 7,(HL) | Has Sam picked up a telephone that was ringing?
30693 | JR Z,30707 | Jump if not
30695 | CALL 61923 | Hang up if 'h' was pressed
30698 | LD A,(32723) | A=ID of the telephone that Sam is holding
30701 | LD HL,27467 | The ringing phone location table is at 27467
30704 | JP 30627 | Check whether there is a message for Sam
30707 | BIT 5,(HL) | Is the destination telephone ringing?
30709 | JR Z,30726 | Jump if not
30711 | CALL 61923 | Hang up if 'h' was pressed
30714 | CALL 30511 | Is the telephone that Sam is calling either off-screen or close enough to a character that can pick it up?
30717 | RET NC | Return if not
30718 | LD A,(32666) | A=ID of the telephone that Sam is calling
30721 | LD HL,27506 | The phone message table is at 27506
30724 | JR 30704 | Check whether Sam has called someone who has a message for him
Sam is still dialling the telephone number.
30726 | BIT 4,(HL) | Are we currently making the sound effect of a digit being dialled?
30728 | JR NZ,30768 | Jump if so
30730 | CALL 61923 | Check for keypresses and hang up if 'h' was pressed
30733 | RET Z | Return if no key with an ASCII code in the range 48-127 was pressed
30734 | CP 58 | Was the ASCII code of the keypress greater than 57 ('9')?
30736 | RET NC | Return if so
30737 | CP 48 | Was the ASCII code less than 48 ('0')?
30739 | RET C | Return if so
30740 | LD HL,32657 | Store the ASCII code of the digit in the first available space at 32658
30743 | INC L
30744 | BIT 5,(HL)
30746 | JR NZ,30743
30748 | LD (HL),A
30749 | SUB 48 | A=digit that was dialled (0-9)
30751 | JR NZ,30755 | Jump unless '0' was dialled
30753 | LD A,10 | The digit '0' will give 10 clicks
30755 | INC A | A=1-11
30756 | LD (58900),A | Store this in byte 20 of Sam's buffer
30759 | LD L,155 | HL=32667 (telephone call status flags)
30761 | LD (HL),16 | Set bit 4
30763 | LD A,42 | Message 42: 'I DIALLED {number}'
30765 | JP 30154 | Queue this message urgently
The sound effect of a digit being dialled is currently in progress.
30768 | LD HL,58888 | Set Sam's main action timer (in byte 8 of his buffer) to 3
30771 | LD (HL),3
30773 | LD L,20 | Point HL at byte 20 of Sam's buffer
30775 | DEC (HL) | Are there any more clicks to make?
30776 | JP NZ,60521 | Make a click if so
Sam has finished dialling a digit of the telephone number. Check whether the number dialled so far is valid.
30779 | LD HL,32667 | Clear all the telephone call status flags at 32667
30782 | LD (HL),0
30784 | LD L,146 | Collect the ASCII code of the first digit that was dialled from 32658
30786 | LD A,(HL)
30787 | CP 48 | Was it '0'?
30789 | JR Z,30817 | Jump if so (no telephone numbers start with 0)
30791 | INC L | Add the ASCII codes of the second and third digits to the first
30792 | ADD A,(HL)
30793 | INC L
30794 | ADD A,(HL)
30795 | INC L | Point HL at the fourth digit
30796 | CP 171 | Set the zero flag if '999' was dialled
30798 | LD A,112 | 112 is the ID of the telephone in the police station
30800 | JR Z,30810 | Jump if Sam has dialled the police
30802 | BIT 5,(HL) | Has Sam dialled four digits yet?
30804 | RET Z | Return if not
30805 | CALL 31255 | Has Sam dialled a valid telephone number?
30808 | JR NZ,30817 | Jump if not
30810 | LD HL,32723 | 32723 holds the ID of the telephone Sam is holding
30813 | CP (HL) | Does it match the ID of the telephone Sam is calling?
30814 | JP NZ,31244 | Jump if not to place the call
30817 | LD A,47 | Message 47: ' THE NUMBER WAS UNOBTAINABLE'
30819 | JP 30617 | Disconnect the call and queue this message urgently