Prev: 27650 Up: Map Next: 27731
27662: Grow Leaf
Used by the routine at UpdateFlower.
Looks for an inactive leaf object and, if there is one, starts a new leaf growing on the flower. The leaves alternate between the right and the left of the flower using bit 6 of LeafGrowth_Flags, and bit 0 of LeafGrowth_Flags is set to stop another leaf being added until the flower has moved again.
GrowLeaf 27662 LD HL,24212 HL=Leaf_1_State (the first leaf object).
27665 LD B,4 Set the leaf counter to 4.
27667 LD DE,8 DE=8 (the size of an object).
GrowLeaf_Loop 27670 LD A,(HL) Jump to GrowLeaf_Found if the leaf is inactive.
27671 AND A
27672 JR Z,GrowLeaf_Found
27674 ADD HL,DE Move onto the next leaf object.
27675 DJNZ GrowLeaf_Loop Decrease the leaf counter by one and loop back to GrowLeaf_Loop until all four leaves have been checked.
27677 RET Return.
GrowLeaf_Found 27678 LD A,(24085) A=LeafGrowth_Flags.
27681 XOR %01000000 Flip bit 6.
27683 OR %00000001 Set bit 0.
27685 LD (24085),A Write it back to LeafGrowth_Flags.
27688 PUSH HL Stash the leaf object on the stack.
27689 EX DE,HL DE=the leaf object.
27690 LD HL,24376 HL=DefaultState_Leaf (the default leaf).
27693 LD BC,8 BC=8 (the size of an object).
27696 LDIR Copy the default leaf into the leaf object.
27698 POP HL Restore the leaf object from the stack.
27699 LD A,(24085) A=LeafGrowth_Flags.
27702 AND %01000000 Keep only bit 6.
27704 LD DE,24205 DE=State_Flower_Pos_X (the X position of the flower).
27707 LD A,(DE) A=the X position of the flower.
27708 JR Z,GrowLeaf_Left Jump to GrowLeaf_Left if bit 6 was not set, to put the leaf on the left.
27710 ADD A,8 Add 8.
GrowLeaf_Position 27712 INC HL Move onto the X position of the leaf.
27713 LD (HL),A Write the X position.
27714 INC DE Move onto the Y position of the flower.
27715 INC HL Move onto the Y position of the leaf.
27716 LD A,(DE) A=the Y position of the flower.
27717 ADD A,7 Add 7.
27719 LD (HL),A Write the Y position.
27720 LD HL,24208 HL=State_Flower_Leaves (the number of leaves on the flower).
27723 INC (HL) Increment the number of leaves by one.
27724 RET Return.
GrowLeaf_Left 27725 SET 6,(HL) Set bit 6 of the state of the leaf (so it faces left).
27727 SUB 16 Subtract 16.
27729 JR GrowLeaf_Position Jump to GrowLeaf_Position.
Prev: 27650 Up: Map Next: 27731