Routines

30555: Make BOY WANDER fire now and then


Used by tables of A&P numbers 32, 46 and 50.
Also used by routine at 63492.

H 206 (BOY WANDER)

30555 3A12D5 LD A,(54546) Pick up byte 18 of buffer 213
30558 A7 AND A Is there a controlling routine address in bytes 17 and 18?
30559 C0 RET NZ Return if so (this buffer is in use)
30560 6F LD L,A
30561 CB46 BIT 0,(HL) Is BOY WANDER midstride?
30563 C0 RET NZ Return if so
30564 2C INC L
30565 7E LD A,(HL) A=BOY WANDER's x-coordinate
30566 E603 AND 3
30568 C0 RET NZ Return unless BOY WANDER's x-coordinate is divisible by 4
30569 CD4F77 CALL 30543 Is BOY WANDER on the top, middle, or bottom floor?
30572 C0 RET NZ Return if not
30573 CD9162 CALL 25233 A=random number
30576 0F RRCA
30577 D0 RET NC Return half the time
30578 CD646D CALL 28004 Is there a teacher nearby?
30581 D8 RET C Return if so
30582 C1 POP BC
30583 C1 POP BC
30584 CDB461 CALL 25012 Update SRB for BOY WANDER's current animatory state and location
30587 2E14 LD L,20 Store BOY WANDER's current animatory state in byte 20 of his buffer for the time being
30589 77 LD (HL),A
30590 E6F0 AND 240
30592 C60A ADD A,10 A=26 or 154: BOY WANDER raising arm to fire
30594 CD4677 CALL 30534 Update SRB for this animatory state and hand over to 30597
30597 CDB461 CALL 25012 Update SRB for BOY WANDER's current animatory state
30600 3C INC A A=27 or 155: BOY WANDER firing catapult
30601 CD4677 CALL 30534 Update SRB for this animatory state and hand over to 30604
30604 2E11 LD L,17 Replace the address of the controlling routine in bytes 17 and 18 of BOY WANDER's buffer with that of 30643
30606 36B3 LD (HL),179
30608 3A12D5 LD A,(54546) Pick up byte 18 of buffer 213
30611 A7 AND A Is this buffer already being used?
30612 C0 RET NZ Return if so
30613 06D5 LD B,213 Use buffer 213 for BOY WANDER's catapult pellet

This entry point is used by the routine at 63861 with H=210 (ERIC) and B=214:
30615 2E00 LD L,0
30617 7E LD A,(HL)
30618 E680 AND 128 A=128 if pellet will travel right, 0 if left
30620 C64F ADD A,79 A=79 or 207: catapult pellet travelling left/right
30622 2C INC L Collect the initial coordinates of the pellet from the firing character's buffer
30623 5E LD E,(HL)
30624 2C INC L
30625 56 LD D,(HL)
30626 60 LD H,B H=buffer to be used for pellet (214 if ERIC's, 213 if BOY WANDER's)
30627 72 LD (HL),D Fill in the initial coordinates and animatory state of the pellet
30628 2D DEC L
30629 73 LD (HL),E
30630 2D DEC L
30631 77 LD (HL),A
30632 2E11 LD L,17 Place the address of the pellet-controlling routine at 30380 into bytes 17 and 18 of the pellet's buffer
30634 36AC LD (HL),172
30636 2C INC L
30637 3676 LD (HL),118
30639 2C INC L L=19
30640 360D LD (HL),13 The pellet will travel 13 spaces
30642 C9 RET