Skip to navigation


The Theme: UpdateAliens (Part 1 of 5)

Name: UpdateAliens (Part 1 of 5) [Show more] Type: Subroutine Category: The Theme Summary: Update the aliens so they progress through their feeding or attack cycles Deep dive: Scheduling tasks in the main loop Alien feeding and growth patterns
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainLoop (Part 6 of 15) calls UpdateAliens

We start by incrementing the state of any non-dormant aliens, so they slowly move through their feeding or take-off cycles.
.UpdateAliens LDA mainLoopCounter \ If the mainLoopCounter is a multiple of 128, jump to AND #127 \ upal3 to move on to part 2 (so we only do this part BNE upal3 \ on 2 out of every 256 iterations round the main loop) LDX #7 \ We now progress the state of each alien, from alien 7 \ down to alien 0, so set a loop counter in X .upal1 LDA alienState,X \ If the state of alien X is zero, jump to upal2 BEQ upal2 \ to move on to the next alien CMP #22 \ If the state of alien X is 22, jump to upal2 BEQ upal2 \ to move on to the next alien CMP #27 \ If the state of alien X is 27 or higher, jump BCS upal2 \ to upal2 to move on to the next alien INC alienState,X \ If we get here then the state of alien X is not 0, 22 \ or >= 27, i.e. it's 1-21 or 23-26, so increment the \ state to progress through the feeding and take-off \ stages .upal2 DEX \ Decrement the alien number BPL upal1 \ Loop back until we have progressed all eight aliens \ to the next state