Skip to navigation

The Theme: UpdateAliens (Part 3 of 5)

Name: UpdateAliens (Part 3 of 5) [Show more] Type: Subroutine Category: The Theme Summary: If alien slot 33 is free and there's an alien waiting to take off, promote it into slot 33 Deep dive: Alien feeding and growth patterns
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

Look at alien slot 33, and: * If the alien in slot 33 has been destroyed, clear the slot * If slot 33 is clear, then check slots 31 and 32 to see if either of then contains an alien in state 22 (i.e. an alien that has finished feeding and is ready to take off), and if so, move that alien into slot 33, promoting it to state 23 in the process
\ At this point Y = 33, so we now process alien slot 33 LDX alienSlot-30,Y \ If alien slot 33 contains a negative number, then the BMI upal12 \ slot is already empty, so jump to upal12 to move on to \ skip the following LDA alienObjectId,X \ If the object ID of the alien in slot 33 is positive, BPL upal15 \ then we already have an alien moving towards the town, \ so jump to upal15 to skip the STA alienSlot-30,Y \ Clear out slot 33 by setting it to a negative number \ (we know A is negative because we just passed through \ a BPL instruction) .upal12 LDY #31 \ We now work our way through alien slots 31 and 32, \ so set a counter in Y for the slot number .upal13 LDX alienSlot-30,Y \ If alien slot Y contains a negative number, then the BMI upal14 \ slot is empty, so jump to upal14 to skip the following LDA alienState,X \ If the alien's state is not 22, jump to upal14 to skip CMP #22 \ the following BNE upal14 STX alienToMove \ Set this alien as the one to move towards Acornsville \ in this iteration of the main loop by setting \ alienToMove to the alien number in X LDA #23 \ Set the alien's state to 23 STA alienState,X BNE upal15 \ Jump to upal15 to exit the loop (this BNE is \ effectively a JMP as A is never zero) .upal14 INY \ Increment the counter to point to the next alien slot CPY #33 \ Loop back until we have done alien slots 31 and 32 BNE upal13