Skip to navigation

Aviator on the BBC Micro

Main loop: MainLoop (Part 1 of 15)

Name: 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 loop
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainLoop (Part 15 of 15) calls MainLoop
.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 model