| Routines

775B: Make BOY WANDER fire his catapult now and then

The address of this continual subcommand routine is placed into bytes 0x17 and 0x18 of BOY WANDER's buffer by command lists 0x20, 0x2E and 0x32, and is also used by the routine at F804. It decides whether BOY WANDER should let rip with a pellet, and gets the catapult-firing action under way if so.
Input
H | 0xCE (BOY WANDER)
775B | LD A,($D512) | Pick up byte 0x12 of buffer 0xD5 (BOY WANDER's pellet)
775E | AND A | Is there a uninterruptible subcommand routine address in bytes 0x11 and 0x12 of the buffer?
775F | RET NZ | Return if so (this buffer is in use)
7760 | LD L,A | L=0x00
7761 | BIT 0,(HL) | Is BOY WANDER midstride?
7763 | RET NZ | Return if so
7764 | INC L | L=0x01
7765 | LD A,(HL) | A=BOY WANDER's x-coordinate
7766 | AND $03 | Return unless BOY WANDER's x-coordinate is divisible by 4
7768 | RET NZ
7769 | CALL $774F | Is BOY WANDER exactly on the top, middle, or bottom floor?
776C | RET NZ | Return if not
776D | CALL $6291 | A=random number
7770 | RRCA | Return half the time
7771 | RET NC
7772 | CALL $6D64 | Can any adults see BOY WANDER?
7775 | RET C | Return if so
7776 | POP BC | Drop the return address (6357)
7777 | POP BC | Pop the value of HL that was pushed on to the stack by the routine at 62D0 before coming here; RET will now take us back either to 62D0 to move the next character, or to the main loop
7778 | CALL $61B4 | Update the SRB for BOY WANDER's current animatory state and location
777B | LD L,$14 | Store BOY WANDER's current animatory state in byte 0x14 of his buffer for the time being
777D | LD (HL),A
777E | AND $F0 |
7780 | ADD A,$0A | A=0x1A or 0x9A: BOY WANDER raising his arm to fire
7782 | CALL $7746 | Update BOY WANDER's animatory state and hand over to 7785 (below)
7785 | CALL $61B4 | Update the SRB for BOY WANDER's current animatory state
7788 | INC A | A=0x1B or 0x9B: BOY WANDER firing the catapult
7789 | CALL $7746 | Update BOY WANDER's animatory state and hand over to 778C (below)
778C | LD L,$11 | Place the address of the uninterruptible subcommand routine at 77B3 into bytes 0x11 and 0x12 of BOY WANDER's buffer
778E | LD (HL),$B3
7790 | LD A,($D512) | Pick up byte 0x12 of buffer 0xD5 (BOY WANDER's pellet)
7793 | AND A | Is this buffer already being used?
7794 | RET NZ | Return if so
7795 | LD B,$D5 | Use buffer 0xD5 for BOY WANDER's catapult pellet
This entry point is used by the routine at F975 with H=0xD2 (ERIC) and B=0xD6 (ERIC's pellet).
7797 | LD L,$00 | Point HL at byte 0x00 of the shooter's character buffer
7799 | LD A,(HL) | A=shooter's animatory state
779A | AND $80 | A=0x80 if the pellet will travel right, 0x00 if left
779C | ADD A,$4F | A=0x4F/0xCF: catapult pellet travelling left/right
779E | INC L | Collect the initial coordinates of the pellet from the shooter's buffer into DE
779F | LD E,(HL)
77A0 | INC L
77A1 | LD D,(HL)
77A2 | LD H,B | H=buffer to be used for the pellet (0xD5 if it's BOY WANDER's, 0xD6 if it's ERIC's)
77A3 | LD (HL),D | Fill in the initial coordinates and animatory state of the pellet
77A4 | DEC L
77A5 | LD (HL),E
77A6 | DEC L
77A7 | LD (HL),A
77A8 | LD L,$11 | Place the address of the pellet-controlling uninterruptible subcommand routine at 76AC into bytes 0x11 and 0x12 of the pellet's buffer
77AA | LD (HL),$AC
77AC | INC L
77AD | LD (HL),$76
77AF | INC L | L=0x13
77B0 | LD (HL),$0D | The pellet will travel 13 spaces
77B2 | RET |