| ← C73D | Map | C7E8 → |
C76D: Fill the free inhabitant slots with wheels
|
When the wheel swarm trigger is set, clears it and fills every free inhabitant record with a wheel. Each new wheel sits 16 pixels below the last, under the wheel that set the trigger.
|
|||
|
The new wheels are ordinary inhabitants, run by the wheel handler.
|
|||
| spawn_wheel_swarm | C76D | LD A,(wheel_swarm_trigger) | Do nothing unless the wheel swarm trigger is set. |
| C770 | OR A | ||
| C771 | RET Z | ||
| C772 | XOR A | Consume the trigger (one-shot). | |
| C773 | LD (wheel_swarm_trigger),A | ||
| C776 | LD C,$03 | Find the record of the wheel that set the trigger among the inhabitant records; none found means done. | |
| C778 | LD IY,inhabitant_records | ||
| spawn_wheel_swarm_0 | C77C | LD A,(IY+$08) | |
| C77F | CP $0D | ||
| C781 | JR Z,spawn_wheel_swarm_1 | ||
| C783 | LD DE,$0010 | ||
| C786 | ADD IY,DE | ||
| C788 | INC C | ||
| C789 | LD A,$08 | ||
| C78B | CP C | ||
| C78C | JR NZ,spawn_wheel_swarm_0 | ||
| C78E | RET | ||
| spawn_wheel_swarm_1 | C78F | LD B,C | Point IX at that source object's sprite record to read its position. |
| C790 | LD DE,$0009 | ||
| C793 | LD IX,object_table | ||
| spawn_wheel_swarm_2 | C797 | ADD IX,DE | |
| C799 | DJNZ spawn_wheel_swarm_2 | ||
| C79B | XOR A | Reset the vertical stack offset to 0. | |
| C79C | LD (clone_stack_offset),A | ||
|
Fill every free inhabitant slot that is left with a new wheel, each stacked 16 pixels below the last.
|
|||
| C79F | LD C,$02 | Step to the next inhabitant record; stop after the last inhabitant; skip occupied records. | |
| C7A1 | LD IY,obj2_record | ||
| spawn_wheel_swarm_3 | C7A5 | LD DE,$0010 | Walk on to the next record. |
| C7A8 | ADD IY,DE | ||
| C7AA | INC C | ||
| C7AB | LD A,C | ||
| C7AC | CP $08 | ||
| C7AE | RET Z | ||
| C7AF | LD A,(IY+$08) | ||
| C7B2 | OR A | ||
| C7B3 | JR NZ,spawn_wheel_swarm_3 | ||
| C7B5 | LD (IY+$08),$0D | Claim the free record as a wheel. | |
| C7B9 | PUSH IY | Point IY at the new slot's sprite record. | |
| C7BB | LD B,C | ||
| C7BC | LD DE,$0009 | ||
| C7BF | LD IY,object_table | ||
| spawn_wheel_swarm_4 | C7C3 | ADD IY,DE | |
| C7C5 | DJNZ spawn_wheel_swarm_4 | ||
| C7C7 | LD A,(IX+$00) | Give the new wheel the source wheel's X. | |
| C7CA | LD (IY+$00),A | ||
| C7CD | LD A,(clone_stack_offset) | Advance the vertical stack offset one sprite down. | |
| C7D0 | ADD A,$10 | ||
| C7D2 | LD (clone_stack_offset),A | ||
| C7D5 | LD A,(IX+$01) | Give the new wheel the source wheel's Y, lowered by the stack offset. | |
| C7D8 | LD HL,clone_stack_offset | ||
| C7DB | ADD A,(HL) | ||
| C7DC | LD (IY+$01),A | ||
| C7DF | POP IY | Restore the record pointer, set B to the wheel's object type, and initialize the record. | |
| C7E1 | LD B,$0D | ||
| C7E3 | CALL spawn_object_init | ||
| C7E6 | JR spawn_wheel_swarm_3 | Loop to fill the next free slot. | |
| ← C73D | Map | C7E8 → |
