Skip to navigation

Aviator on the BBC Micro

Keyboard: ProcessOtherKeys

Name: ProcessOtherKeys [Show more] Type: Subroutine Category: Keyboard Summary: Apply the undercarriage, brakes, flaps and fire keys Deep dive: The key logger
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * UpdateFlightModel (Part 3 of 4) calls ProcessOtherKeys

Arguments: X The offset within the key logger for the keys to check: * 4 = "U" or "B" (undercarriage, brakes) * 5 = "F" or SHIFT (flaps, fire)
Returns: A Returns the status of the relevant key presses: * 0 = neither key in the pair is being pressed, or a key is still being held down from a previous call to the routine, so it has already been processed * 1 = One of "U" and "F" (undercarriage, flaps) is being pressed * 128 = One of "B" and SHIFT (brakes, fire) is being pressed
.ProcessOtherKeys LDA keyLoggerLo,X \ Fetch the low byte for this key pair BNE poth2 \ If A is non-zero then a key from this key pair is \ being pressed, so jump down to poth2 to process the \ key press STA pressingUFBS-4,X \ Zero the relevant value in pressingUFBS (for U) or \ pressingUFBS+1 (for F) to indicate that the first key \ from this pair is not being held down STA pressingUFBS-4+3,X \ Zero the relevant value in pressingUFBS+3 (for B) or \ pressingUFBS+4 (for SHIFT) to indicate that the second \ key from this pair is not being held down .poth1 LDA #0 \ Set A = 0 as the return value RTS \ Return from the subroutine .poth2 TAY \ Copy the low value into Y, so we have: \ \ * Y = 4 if "U" is being pressed (undercarriage) \ * Y = 5 if "F" is being pressed (flaps) \ * Y = 7 if "B" is being pressed (brakes) \ * Y = 8 if SHIFT is being pressed (fire) LDA pressingUFBS-4,Y \ Fetch the relevant value from pressingUFBS to see if BNE poth1 \ the key press has already been processed, and if it is \ non-zero, this indicates that it is still being held \ down from a previous visit to this routine, so jump to \ poth1 to return a value of 0, so we can ignore the key \ press LDA ucStatus-4,Y \ Flip the value of the relevant status byte, as EOR #1 \ follows: STA ucStatus-4,Y \ \ * Flip ucStatus if "U" is being pressed \ * Flip flapsStatus if "F" is being pressed \ * Flip brakesStatus if "B" is being pressed \ * Flip brakesStatus+1 if SHIFT is being pressed \ (which has no effect) LDA #1 \ Set the relevant value in pressingUFBS to denote that STA pressingUFBS-4,Y \ this key is being pressed, so if we revisit this \ routine before the key is released, we don't keep on \ flipping the status byte CPY #7 \ If Y < 7, i.e. U or F are being pressed, jump to poth3 BCC poth3 \ to return a result of 1 LDA #128 \ Y >= 7, i.e. B or SHIFT are being pressed, so set \ A = 128 as the return value RTS \ Return from the subroutine .poth3 LDA #1 \ Set A = 1 as the return value RTS \ Return from the subroutine