Prev: 7654 Up: Map Next: 7744
76AC: Control the flight of a catapult pellet
The address of this uninterruptible subcommand routine is placed into bytes 0x11 and 0x12 of a catapult pellet's buffer by the routine at 775B. It controls the pellet from the beginning of its flight to the end, including any collisions with cups, trees, other characters, and teachers' heads.
Input
H 0xD5 (BOY WANDER's pellet) or 0xD6 (ERIC's pellet)
76AC LD L,$13 Byte 0x13 of the pellet's buffer holds the distance left to travel
76AE DEC (HL) Has the pellet finished travelling?
76AF JP Z,$74CF Terminate the pellet if so
76B2 LD A,(HL) A=distance left to travel
76B3 CP $05 Does the pellet have fewer than 5 spaces left to travel?
76B5 JR C,$76CD Jump if so (to check for hittable obstacles)
The pellet is merrily wending its way through the air. It's not ready to hit anything vulnerable yet, or has simply failed to do so. The only thing that can stop it at the moment is a wall, door or window.
76B7 LD L,$00 Point HL at byte 0x00 of the pellet's buffer
76B9 LD A,(HL) A=pellet's animatory state
76BA RLCA Set the carry flag if the pellet is travelling to the left
76BB CCF
76BC SBC A,A A=-1 if the pellet is travelling leftwards, 1 if rightwards
76BD ADD A,A
76BE INC A
76BF INC L Add the pellet's x-coordinate to obtain that of the location directly in front of the pellet
76C0 ADD A,(HL)
76C1 LD E,A Store this in E
76C2 INC L L=0x02
76C3 LD D,(HL) D=pellet's y-coordinate
76C4 CALL $7654 Check for closed doors, windows and walls in the pellet's path
76C7 JP C,$74CF Terminate the pellet if there is one
76CA JP $7250 Otherwise just advance the pellet one space
The pellet is ready to hit a vulnerable character, cup or tree.
76CD CALL $7615 Has the pellet hit a water- or sherry-filled cup?
76D0 JR NZ,$76E3 Jump if not
The pellet has hit a water- or sherry-filled cup, or a conker in the tree. The A register holds the animatory state of the object (drop of water/sherry, or conker) that the pellet will become.
76D2 LD L,$12 Place the address of the uninterruptible subcommand routine at 74C8 into bytes 0x11 and 0x12 of the catapult pellet's buffer
76D4 LD (HL),$74
76D6 DEC L
76D7 LD (HL),$C8
76D9 PUSH AF Save the new animatory state of the transmuted pellet
76DA CALL $61B4 Update the SRB for the pellet's current location
76DD POP AF Restore the transmuted pellet's animatory state to A
76DE DEC D The projectile will ascend two levels
76DF DEC D
76E0 JP $6130 Update the projectile's location and update the SRB
The pellet hasn't hit a water- or sherry-filled cup. Has it hit a teacher?
76E3 LD L,$01 Point HL at byte 0x01 of the pellet's buffer
76E5 LD E,(HL) E=pellet's x-coordinate
76E6 INC L L=0x02
76E7 LD D,(HL) D=pellet's y-coordinate
76E8 LD B,$05 There are 5 teachers who can be hit by a pellet
76EA CALL $74A2 Has the pellet hit any of these teachers?
76ED JR NZ,$771B Jump if not
76EF LD C,$00 Point BC at byte 0x00 of the stricken teacher's buffer
76F1 LD A,(BC) A=animatory state of this teacher
76F2 AND $07 Is the teacher already sitting on the floor?
76F4 CP $06
76F6 JR NZ,$7712 Jump if not
76F8 LD L,$13 Place 6 into byte 0x13 of the pellet's buffer (the distance the pellet will travel after bouncing off the teacher's head)
76FA LD (HL),A
This section of code controls the pellet's motion on its ascent from the teacher's head.
76FB LD L,$13 Byte 0x13 of the pellet's buffer holds the distance left to travel
76FD DEC (HL) Decrement this
76FE JP Z,$74CF Terminate the pellet if its journey is over
7701 CALL $7615 Has the pellet hit a water- or sherry-filled cup?
7704 JR Z,$76D2 Jump if so
7706 CALL $61B4 Update the SRB for the pellet's current location
7709 DEC D Has the pellet hit the ceiling on the top floor?
770A JR NZ,$770D Jump if not (having raised the pellet one level)
770C INC D D=1; this makes the pellet hover just below the ceiling on the top floor before disappearing, which is a bug
770D CALL $7746 Replace the address of this routine in bytes 0x11 and 0x12 of the pellet's buffer with 7710 (the address of the next instruction)
7710 JR $76FB
The pellet has hit a teacher who's standing up.
7712 LD C,$12 Point BC at byte 0x12 of the teacher's buffer
7714 LD A,(BC) A=MSB of a routine address, or 0
7715 PUSH BC
7716 AND A Is there an uninterruptible subcommand routine address in bytes 0x11 and 0x12 of the teacher's buffer?
7717 JP Z,$751F Jump if not (this teacher can be knocked over)
771A POP BC
The pellet hasn't hit any liquid-containing cups or vulnerable teachers. Has it hit any kids?
771B LD D,$CE 0xCE=BOY WANDER
771D LD B,$05 There are 5 kids who can be knocked over
771F CALL $6CAC Has the pellet hit any of them?
7722 JP NC,$7842 Knock them down if so
The pellet hasn't hit any liquid-containing cups, teachers or kids. Has it hit a conker in the tree?
7725 LD L,$13 Byte 0x13 of the pellet's buffer holds the distance left to travel
7727 LD A,(HL) Pick this up in A
7728 DEC A Is there only one space left to travel?
7729 JP Z,$76B7 Jump if so
772C LD L,$02 Point HL at byte 0x02 of the pellet's buffer
772E LD A,(HL) A=pellet's y-coordinate
772F CP $04 Was the pellet fired on the top floor?
7731 JR NC,$773C Jump if not
7733 DEC L L=0x01
7734 LD A,(HL) A=pellet's x-coordinate
7735 CP $80 Jump if the pellet is to the right of the tree (it was fired in the girls' skool)
7737 JR NC,$773C
7739 CP $60 Set the carry flag if A>=96 (i.e. the pellet is in the tree)
773B CCF
773C JP NC,$76B7 Jump unless the pellet will knock a conker out of the tree
773F LD A,$37 0x37: animatory state of a conker
7741 JP $76D2 Transmute the pellet into a conker
Prev: 7654 Up: Map Next: 7744