.main17 JSR UpdateFuelGauge \ Update the fuel gauge LDX #&DC \ Scan the keyboard to see if "T" is being pressed JSR ScanKeyboard BNE main18 \ If "T" is not being pressed, jump to main18 LDA pressingT \ If pressingT is non-zero, then we are still pressing BNE main19 \ "T" having already toggled the engine, so jump down \ to main19 so we don't keep switching the engine on and \ off by accident LDA propellorStatus \ If propellorStatus is non-zero, then the propellor is BNE main20 \ broken and we can't turn on the engine, so jump to \ main20 to skip the following \ At this point, we know that "T" is being pressed, \ pressingT is zero (so we haven't yet acted on the key \ press), and propellorStatus is zero (so the propellor \ is working), so now we toggle the engine status to \ switch it on or off LDA engineStatus \ Fetch the value of engineStatus and invert bit 0 so it EOR #1 \ changes to the opposite state JSR SetEngine \ Set the engine status to the value in A LDA #1 \ Set A = 1 to use as the new value of pressingT below, BNE main19 \ so that holding down "T" won't keep toggling the \ engine status .main18 LDA #0 \ "T" is not being pressed, so set A = 0 to use as the \ new value of pressingT .main19 STA pressingT \ Set pressingT = A, so we don't try toggling the engine \ again until we release the "T" keyName: MainLoop (Part 11 of 15) [Show more] Type: Subroutine Category: Main loop Summary: Process engine start and stop Deep dive: Program flow of the main game loopContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Subroutine ScanKeyboard (category: Keyboard)
Scan the keyboard for a specific key
[X]
Subroutine SetEngine (category: Flight model)
Set the engine status
[X]
Subroutine UpdateFuelGauge (category: Dashboard)
Update the fuel gauge every 16 iterations of the main loop
[X]
Variable engineStatus in workspace Main variable workspace
Engine status
[X]
Label main18 is local to this routine
[X]
Label main19 is local to this routine
[X]
Label main20 in subroutine MainLoop (Part 12 of 15)
[X]
Variable pressingT in workspace Main variable workspace
Set to 0 in the main loop if "T" is not being pressed, otherwise set to 1, to prevent holding down "T" from constantly switching the engine on and off
[X]
Variable propellorStatus in workspace Main variable workspace
Propellor status