.upal3 LDY #31 \ We run the following outer loop twice, once for alien \ slot 31 and again for alien slot 32, so set a counter \ in Y to iterate through 31 and 32 .upal4 LDX alienSlot-30,Y \ If alien slot Y contains a negative number, then the BMI upal6 \ slot is already empty, so jump to upal6 LDA alienState,X \ If the state of the alien in slot Y is 24, then skip CMP #24 \ the following two instructions BEQ upal5 LDA alienObjectId,X \ If the object ID of the alien in slot Y is positive, BPL upal11 \ jump to upal11 to move on to the next alien .upal5 \ If we get here then alien slot Y contains an alien \ (with ID 0 to 7), and either the alien's state is 24, \ or the alien's object ID is negative (which means it \ has been destroyed) LDA #254 \ Clear out slot Y by setting it to a negative number STA alienSlot-30,Y .upal6 \ We now run through aliens 7 to 0, until we find one \ with a positive object ID and a state of 0, and which \ is not already in the other slot. When we find it, \ we insert it into the slot, bump its state up to 1 \ and stop looking LDX #7 \ Set a loop counter in X to contain the alien's number .upal7 LDA alienObjectId,X \ If the alien's object ID is negative, jump to upal10 BMI upal10 \ to move on to the next alien, as this alien has been \ destroyed LDA alienState,X \ If the alien's state is non-zero, jump to upal10 to BNE upal10 \ move on to the next alien CPY #31 \ If we are processing alien slot 31 in the outer loop, BEQ upal8 \ skip the following two instructions CPX alienSlot+1 \ Compare the alien number with the contents of alien JMP upal9 \ slot 31 and skip the following instruction .upal8 CPX alienSlot+2 \ Compare the alien number with the contents of alien \ slot 32 .upal9 BEQ upal10 \ If the current alien number matches the contents of \ slot Y, jump to upal10 to move on to the next alien TXA \ Insert this alien number into alien slot Y STA alienSlot-30,Y STX U \ Store the alien number in U LDA #%10000000 \ Set bit 7 of A so the call to ResizeFeedingAlien sets \ the size of the alien to the first feeding stage JSR ResizeFeedingAlien \ Resize the alien to the first feeding stage LDX U \ Retrieve the alien number from U LDA #1 \ Set the alien's state to 1 STA alienState,X BNE upal11 \ Jump to upal11 to terminate the inner loop (this BNE \ is effectively a JMP as A is never zero) .upal10 DEX \ Decrement the inner loop alien counter BPL upal7 \ Loop back until we have worked our way through aliens \ 0 to 7 .upal11 INY \ Increment the alien counter CPY #33 \ Loop back until we have processed both alien slots 31 BNE upal4 \ and 32Name: UpdateAliens (Part 2 of 5) [Show more] Type: Subroutine Category: The Theme Summary: Manage alien slots 31 and 32, and if there's a vacancy, wake up a dormant alien, move it into the slot and start its feeding cycle Deep dive: Alien feeding and growth patternsContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
Look at alien slots 31 and 32, and for each one: * If the alien in the slot is in state 24, remove it from the slot * Otherwise check to see if the alien in the slot has been destroyed, and if so, empty the slot * If the slot is not empty, search the aliens for one is dormant (i.e. in state 0), isn't already in the other slot, and hasn't been destroyed, and put that into the slot, bumping its state up to 1 and setting the size of the alien to the correct size for the first feeding stage
[X]
Subroutine ResizeFeedingAlien (category: The Theme)
Change the size of an alien so it grows bigger as it feeds
[X]
Variable alienObjectId (category: The Theme)
Object IDs for each of the eight aliens
[X]
Variable alienSlot (category: The Theme)
Slots for up to three aliens that are ready to start moving towards the town
[X]
Variable alienState (category: The Theme)
The state of each of the eight aliens
[X]
Label upal10 is local to this routine
[X]
Label upal11 is local to this routine
[X]
Label upal4 is local to this routine
[X]
Label upal5 is local to this routine
[X]
Label upal6 is local to this routine
[X]
Label upal7 is local to this routine
[X]
Label upal8 is local to this routine
[X]
Label upal9 is local to this routine