.MainLoop LDA linesToHideEnd \ Store the index of the end of the linesToHide list in STA previousListEnd \ previousListEnd so we can check it at the end of the \ main loop JSR SpawnAlien \ If the Theme is enabled and the current wave does not \ yet have eight aliens in it, spawn a new alien JSR UpdateKeyLogger \ Scan for key presses and update the key logger LDA firingStatus \ If firingStatus is non-zero, then we have already BNE main2 \ fired our gun and the bullets are still in the air, so \ jump to main2 to skip firing bullets, as we can't fire \ any more bullets until the current ones expire JSR UpdateFlightModel \ Process any key presses in the key logger and update \ the matrices and flight model LDA firingStatus \ If the call to UpdateFlightModel has left firingStatus BEQ main3 \ set to zero, then the fire key is not being pressed, \ so jump to main3 to skip firing bullets \ The call to UpdateFlightModel had changed firingStatus \ from zero to non-zero, which means the fire key is \ being pressed, so we now need to add two bullets to \ the scene LDA #2 \ Set gunSoundCounter = 2, so we make two firing sounds STA gunSoundCounter \ below, one for each bullet LDY #33 \ We now copy the status bytes for objects 30 to 33 (the \ four alien objects), copying the four bytes between \ objectStatus+30 and objectStatus+33 into the four \ bytes at alienStatus, so set up a counter in Y that \ can also act as the offset .main1 LDA objectStatus,Y \ Copy the Y-th byte of objectStatus to alienStatus-30, STA alienStatus-30,Y \ to give this: \ \ objectStatus+30 -> alienStatus \ objectStatus+31 -> alienStatus+1 \ objectStatus+32 -> alienStatus+2 \ objectStatus+33 -> alienStatus+3 DEY \ Decrement the loop counter CPY #30 \ Loop back until we have copied all four bytes BCS main1 \ We now add the bullet lines (line IDs 60 and 61) to \ the linesToShow list, so they get displayed LDY linesToShowEnd \ Set Y to the first free entry at the end of the \ linesToShow list LDA #60 \ Append line 60 to the end of the linesToShow list STA linesToShow,Y INY \ Increment Y to point to the next free entry in the \ list LDA #61 \ Append line 61 to the end of the linesToShow list STA linesToShow,Y INY \ Increment Y to point to the next free entry in the \ list STY linesToShowEnd \ Update linesToShowEnd with the updated index of the \ next free entry, which is two more than it was before \ we added the bullet lines JMP main3 \ Skip the following instruction, as we have already \ processed the key logger .main2 JSR UpdateFlightModel \ Process any key presses in the key logger and update \ the matrices and flight modelName: MainLoop (Part 1 of 15) [Show more] Type: Subroutine Category: Main loop Summary: Start the main loop by processing gunfire and bullets Deep dive: Program flow of the main game loopContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainLoop (Part 15 of 15) calls MainLoop
[X]
Subroutine SpawnAlien (category: The Theme)
If the Theme is enabled and the current wave does not yet have eight aliens in it, spawn a new alien
[X]
Subroutine UpdateFlightModel (Part 1 of 4) (category: Flight model)
Apply any axis control key presses to the current axis values
[X]
Subroutine UpdateKeyLogger (category: Keyboard)
Scan the keyboard for keys in the two key tables and update the key logger
[X]
Variable alienStatus (category: The Theme)
Storage for the object status bytes for the four alien objects
[X]
Variable firingStatus in workspace Main variable workspace
Firing status
[X]
Variable gunSoundCounter in workspace Main variable workspace
Counter for the number of firing sounds we make when firing our guns (which makes the sound of two shots)
[X]
Variable linesToHideEnd in workspace Zero page
The index of the last entry in the linesToHide list
[X]
Variable linesToShow in workspace Main variable workspace
A list of line IDs for lines that are visible
[X]
Variable linesToShowEnd in workspace Zero page
The index of the first empty entry in the linesToShow list
[X]
Label main1 is local to this routine
[X]
Label main2 is local to this routine
[X]
Label main3 in subroutine MainLoop (Part 2 of 15)
[X]
Variable objectStatus in workspace Main variable workspace
Each object's status byte
[X]
Variable previousListEnd in workspace Main variable workspace
Used to store the value of linesToHideEnd at the start of each iteration of the main loop, so we can refer to it at the end of the main loop to see if we have added anything to the list during the main loop