| Routines

FA4D: Deal with water fired from the pistol at certain phases

Used by the routine at F9AB. On entry, A is equal to 1 if the water is at phase 3 of its trajectory (at which point it may hit a cup), or 2 if it's at phase 6 or above (at which point it may hit a plant or the floor). In the following, 'water' may refer to either water or sherry.
Input
A | 1 or 2
H | 0xD6 (water)
L | 0x13
FA4D | DEC A | Is the water at the right phase to fill a cup?
FA4E | JR NZ,$FA7E | Jump if not
FA50 | LD L,$02 | Point HL at byte 0x02 of the water's buffer
FA52 | LD A,(HL) | A=water's y-coordinate
FA53 | SUB $0E | All cups have a y-coordinate of 14
FA55 | RET NZ | Return if the water's not at the right height
FA56 | LD L,A | L=0x00
FA57 | DEC A | A=-1
FA58 | BIT 7,(HL) | Is the water travelling to the left?
FA5A | JR Z,$FA5E | Jump if so
FA5C | LD A,$03 |
FA5E | INC L | L=0x01
FA5F | ADD A,(HL) | Now A=x-coordinate of the spot the water is hitting
FA60 | CALL $7609 | Is this the x-coordinate of one of the cups?
FA63 | RET NZ | Return if not
FA64 | LD HL,$7FEB | 7FEB holds the inventory flags
FA67 | BIT 4,(HL) | Set the zero flag if there's water (not sherry) in the pistol
FA69 | LD HL,$DC77 | H=0xDC, L=0x77
FA6C | JR Z,$FA70 | Jump if there's water in the pistol
FA6E | LD L,$7C |
FA70 | INC H | Point HL at a cup graphic data table
FA71 | CP (HL) | Is this the right data table for the cup?
FA72 | JR NZ,$FA70 | Jump back to check the next table if not
FA74 | DEC L | Point HL at the appropriate UDG reference table
Now HL points at the start of the appropriate UDG reference table for the cup:
HL | Cup | Contents
--- | --- | ---
DD76 | Leftmost cup in the boys' skool | Water
DD7B | Leftmost cup in the boys' skool | Sherry
DE76 | Middle cup in the boys' skool | Water
DE7B | Middle cup in the boys' skool | Sherry
DF76 | Rightmost cup in the boys' skool | Water
DF7B | Rightmost cup in the boys' skool | Sherry
E076 | Cup in the girls' skool | Water
E07B | Cup in the girls' skool | Sherry
FA75 | CALL $6C18 | Alter the appropriate UDG and attribute references in the play area to show the cup filled with water or sherry
FA78 | POP HL | Drop the return address (to the routine at F9AB) from the stack
FA79 | LD H,$D6 | 0xD6=water
FA7B | JP $74CF | Remove the water from sight
The water is at phase 6 or above of its trajectory. Has it hit the floor?
FA7E | DEC (HL) | Decrement the water animation phase identifier in byte 0x13 of the water's buffer from 0x9C to 0x9B; this has the effect of bringing us back through this section of code (via the routine at F9AB) until the water has hit either a plant or the floor
FA7F | CALL $774F | Is the water's y-coordinate 3 (top floor), 10 (middle floor) or 17 (bottom floor)?
FA82 | JR NZ,$FA93 | Jump if not
FA84 | CP $11 | Did it hit the bottom floor?
FA86 | JR Z,$FA78 | Terminate the water if so
The water has reached the level of the top or middle floor. We terminate it here if it's inside the boys' skool or the girls' skool. (Note that it hasn't necessarily hit the floor at this point; for example, it may have been fired from the top of the stairs above the stage down onto the stage, in which case it will terminate in mid-air above the stage, at the level of the middle floor.) Otherwise we let it continue till it hits the ground.
FA88 | DEC L | L=0x01
FA89 | LD A,(HL) | A=water's x-coordinate
FA8A | CP $60 | Terminate the water if A<96 (it's inside the boys' skool) or A>=160 (it's inside the girls' skool)
FA8C | JR C,$FA78
FA8E | CP $A0
FA90 | JR NC,$FA78
FA92 | RET |
The water hasn't hit a cup or the floor. Has it hit a plant pot?
FA93 | CALL $F986 | Has the water hit a plant pot?
FA96 | RET NZ | Return if not
FA97 | LD A,($7FEB) | 7FEB holds the inventory flags
FA9A | BIT 4,A | Has the pistol got sherry in it?
FA9C | JR NZ,$FA78 | Terminate the sherry if so (sherry does not make plants grow)
FA9E | POP DE | Drop the return address (to the routine at F9AB) from the stack
FA9F | CALL $61B4 | Update the SRB for the water's current animatory state and location
FAA2 | INC D | Now D=y-coordinate of the plant
FAA3 | LD L,$13 | Initialise the counter that determines the phases of growth of the watered plant
FAA5 | LD (HL),$16
FAA7 | INC L | Store the x-coordinate of the plant in byte 0x14 of the buffer for retrieval later when it starts growing
FAA8 | LD (HL),E
FAA9 | LD E,$00 | The plant's initial x-coordinate will be 0 (which is certainly off-screen at the moment, since the leftmost plant pot is at x-coordinate 91)
FAAB | LD A,E | And its initial animatory state will be 0x00 (ERIC standing, facing left), so it's a good thing it will be off-screen!
FAAC | CALL $7746 | Place address FAAF (below) into bytes 0x11 and 0x12 of the plant's buffer and update the SRB for the plant's appearance
The address of this entry point is placed into bytes 0x11 and 0x12 of the plant's buffer by the instruction above just after the plant has been watered.
FAAF | LD L,$13 | Byte 0x13 holds the counter that determines the phases of growth (and death) of the plant
FAB1 | DEC (HL) | Is the plant ready to die?
FAB2 | JR NZ,$FAC3 | Jump if not
FAB4 | LD A,($7FED) | 7FED holds ERIC's secondary status flags
FAB7 | CP $02 | Is ERIC standing on a plant or plant pot?
FAB9 | JR NZ,$FAC0 | Jump if not
FABB | LD A,$10 | Set bit 4 at 7FED, indicating that ERIC is going to take a fall (even if ERIC's standing on a different plant pot; this is a bug)
FABD | LD ($7FED),A
FAC0 | JP $74CF | Kill the plant
The plant is not dead yet. Plan its next move.
FAC3 | LD A,(HL) | Pick up the plant lifespan counter in A
FAC4 | CP $08 | Is it time for the plant to start growing?
FAC6 | JR NZ,$FAD1 | Jump if not
FAC8 | INC L | E=x-coordinate of the plant (stored in byte 0x14 earlier)
FAC9 | LD E,(HL)
FACA | LD L,$02 | Point HL at byte 0x02 of the plant's buffer
FACC | LD D,(HL) | D=y-coordinate of the plant
FACD | LD A,$2A | 0x2A: flower, half-grown
FACF | JR $FAD8 |
FAD1 | CP $04 | Is it time for the plant to reach full height?
FAD3 | RET NZ | Return if not
FAD4 | CALL $61B4 | Update the SRB for the plant's current animatory state
FAD7 | INC A | A=0x2B: flower, fully grown
FAD8 | CALL $6130 | Update the plant's animatory state and update the SRB
FADB | LD A,($7FED) | 7FED holds ERIC's status flags
FADE | CP $02 | Is ERIC standing on a plant?
FAE0 | RET NZ | Return if not
FAE1 | LD A,($D201) | A=ERIC's x-coordinate
FAE4 | LD L,$01 | Point HL at byte 0x01 of the plant's buffer (which holds its x-coordinate)
FAE6 | CP (HL) | Is ERIC standing on this plant?
FAE7 | RET NZ | Return if not
FAE8 | LD H,$D2 | 0xD2=ERIC
FAEA | CALL $61B4 | Update the SRB for ERIC's current animatory state and location
FAED | DEC D | ERIC will rise one level as the plant grows
FAEE | JP $6130 | Update ERIC's location and update the SRB