| Routines

29912: Deal with Sam

Called from the main loop at 61483 when one of Sam's status flags at 32764 is set, indicating that he is in the middle of an action. Returns with the zero flag set if Sam has finished the action by the end of the routine.
29912 | LD HL,58888 | Decrement Sam's main action timer in byte 8 of his buffer
29915 | DEC (HL)
29916 | RET NZ | Return unless it's time to deal with Sam
29917 | LD HL,29939 | We will continue at 29939 (below) after calling the routine to handle Sam
29920 | PUSH HL
29921 | LD L,198 | HL=29894
29923 | LD A,(32764) | Pick up Sam's status flags from 32764
29926 | INC L | Point HL at one of the entries in the table of Sam-handling routine addresses at 29896
29927 | INC L
29928 | RLCA
29929 | JR NC,29926
29931 | LD C,(HL) | Collect the routine address into BC
29932 | INC L
29933 | LD B,(HL)
29934 | PUSH BC | Push it onto the stack, ready for an indirect jump
29935 | LD HL,58880 | Point HL at byte 0 of Sam's buffer
29938 | RET | Make an indirect jump to the Sam-handling routine
We come here after the Sam-handling routine has returned.
29939 | LD HL,32764 | 32764 holds Sam's status flags
29942 | LD A,(HL) | Pick them up in A
29943 | AND A | Has Sam finished the action yet?
29944 | RET Z | Return with the zero flag set if so
29945 | LD A,(58888) | Collect Sam's main action timer from byte 8 of his buffer
29948 | AND A | Did the Sam-handling routine set the action timer to a non-zero value (meaning that the action is still in progress)?
29949 | RET NZ | Return with the zero flag reset if so
29950 | LD (HL),A | Otherwise clear all of Sam's status flags at 32764
29951 | RET | Return with the zero flag set