.DOKEY JSR RDKEY ; Scan the keyboard for a key press and return the ; internal code of the key pressed in X ;JSR U% ; These instructions are commented out in the original ;JMP DK15 ; source LDA auto ; If auto is 0, then the docking computer is not BEQ DK15 ; currently activated, so jump to DK15 to skip the ; docking computer manoeuvring code below .auton JSR ZINF ; Call ZINF to reset the INWK ship workspace LDA #96 ; Set nosev_z_hi = 96 STA INWK+14 ORA #%10000000 ; Set sidev_x_hi = -96 STA INWK+22 STA TYPE ; Set the ship type to -96, so the negative value will ; let us check in the DOCKIT routine whether this is our ; ship that is activating its docking computer, rather ; than an NPC ship docking LDA DELTA ; Set the ship speed to DELTA (our speed) STA INWK+27 JSR DOCKIT ; Call DOCKIT to calculate the docking computer's moves ; and update INWK with the results ; We now "press" the relevant flight keys, depending on ; the results from DOCKIT, starting with the pitch keys LDA INWK+27 ; Fetch the updated ship speed from byte #27 into A CMP #22 ; If A < 22, skip the next instruction BCC P%+4 LDA #22 ; Set A = 22, so the maximum speed during docking is 22 STA DELTA ; Update DELTA to the new value in A LDA #$FF ; Set A = $FF, which we can insert into the key logger ; to "fake" the docking computer working the keyboard LDX #(KY1-KLO) ; Set X to the offset of KY1 within the KLO table, so we ; "press" KY1 below ("?", slow down) LDY INWK+28 ; If the updated acceleration in byte #28 is zero, skip BEQ DK11 ; to DK11 BMI P%+4 ; If the updated acceleration is negative, skip the ; following instruction LDX #(KY2-KLO) ; Set X to the offset of KY2 within the KLO table, so we ; "press" KY2 with the next instruction (Space, speed ; up) STA KLO,X ; Store $FF in either KY1 or KY2 to "press" the relevant ; key, depending on whether the updated acceleration is ; negative (in which case we "press" KY1, "?", to slow ; down) or positive (in which case we "press" KY2, ; Space, to speed up) .DK11 ; We now "press" the relevant roll keys, depending on ; the results from DOCKIT LDA #128 ; Set A = 128, which indicates no change in roll when ; stored in JSTX (i.e. the centre of the roll indicator) LDX #(KY3-KLO) ; Set X to the offset of KY3 within the KLO table, so we ; "press" KY3 below ("<", increase roll) ASL INWK+29 ; Shift ship byte #29 left, which shifts bit 7 of the ; updated roll counter (i.e. the roll direction) into ; the C flag BEQ DK12 ; If the remains of byte #29 is zero, then the updated ; roll counter is zero, so jump to DK12 set JSTX to 128, ; to indicate there's no change in the roll BCC P%+4 ; If the C flag is clear, skip the following instruction LDX #(KY4-KLO) ; Set X to the offset of KY4 within the KLO table, so we ; "press" KY4 below (">", decrease roll) BIT INWK+29 ; We shifted the updated roll counter to the left above, BPL DK14 ; so this tests bit 6 of the original value, and if it ; is clear (i.e. the magnitude is less than 64), jump to ; DK14 to "press" the key and leave JSTX unchanged LDA #64 ; The magnitude of the updated roll is 64 or more, so STA JSTX ; set JSTX to 64 (so the roll decreases at half the ; maximum rate) LDA #0 ; And set A = 0 so we do not "press" any keys (so if the ; docking computer needs to make a serious roll, it does ; so by setting JSTX directly rather than by "pressing" ; a key) .DK14 STA KLO,X ; Store A in either KY3 or KY4, depending on whether ; the updated roll rate is increasing (KY3) or ; decreasing (KY4) LDA JSTX ; Fetch A from JSTX so the next instruction has no ; effect .DK12 STA JSTX ; Store A in JSTX to update the current roll rate ; We now "press" the relevant pitch keys, depending on ; the results from DOCKIT LDA #128 ; Set A = 128, which indicates no change in pitch when ; stored in JSTX (i.e. the centre of the pitch ; indicator) LDX #(KY5-KLO) ; Set X to the offset of KY5 within the KLO table, so we ; "press" KY5 below ("X", decrease pitch, pulling the ; nose up) ASL INWK+30 ; Shift ship byte #30 left, which shifts bit 7 of the ; updated pitch counter (i.e. the pitch direction) into ; the C flag BEQ DK13 ; If the remains of byte #30 is zero, then the updated ; pitch counter is zero, so jump to DK13 set JSTY to ; 128, to indicate there's no change in the pitch BCS P%+4 ; If the C flag is set, skip the following instruction LDX #(KY6-KLO) ; Set X to the offset of KY6 within the KLO table, so we ; "press" KY6 below ("S", increase pitch, so the nose ; dives) STA KLO,X ; Store 128 in either KY5 or KY6 to "press" the relevant ; key, depending on whether the pitch direction is ; negative (in which case we "press" KY5, "X", to ; decrease the pitch, pulling the nose up) or positive ; (in which case we "press" KY6, "S", to increase the ; pitch, pushing the nose down) LDA JSTY ; Fetch A from JSTY so the next instruction has no ; effect .DK13 STA JSTY ; Store A in JSTY to update the current pitch rate .DK15 LDX JSTX ; Set X = JSTX, the current roll rate (as shown in the ; RL indicator on the dashboard) LDA #14 ; Set A to 14, which is the amount we want to alter the ; roll rate by if the roll keys are being pressed LDY KY3 ; If the "<" key is not being pressed, skip the next BEQ P%+5 ; instruction JSR BUMP2 ; The "<" key is being pressed, so call the BUMP2 ; routine to increase the roll rate in X by A LDY KY4 ; If the ">" key is not being pressed, skip the next BEQ P%+5 ; instruction JSR REDU2 ; The "<" key is being pressed, so call the REDU2 ; routine to decrease the roll rate in X by A, taking ; the keyboard auto re-centre setting into account STX JSTX ; Store the updated roll rate in JSTX ;ASL A ; This instruction is commented out in the original ; source LDX JSTY ; Set X = JSTY, the current pitch rate (as shown in the ; DC indicator on the dashboard) LDY KY5 ; If the "X" key is not being pressed, skip the next BEQ P%+5 ; instruction JSR REDU2 ; The "X" key is being pressed, so call the REDU2 ; routine to decrease the pitch rate in X by A, taking ; the keyboard auto re-centre setting into account LDY KY6 ; If the "S" key is not being pressed, skip the next BEQ P%+5 ; instruction JSR BUMP2 ; The "S" key is being pressed, so call the BUMP2 ; routine to increase the pitch rate in X by A STX JSTY ; Store the updated roll rate in JSTY LDA JSTK ; If JSTK is zero, then we are configured to use the BEQ ant ; keyboard rather than the joystick, so jump to ant to ; skip the following LDA auto ; If the docking computer is currently activated, jump BNE ant ; to ant to skip the following ; If we get here then the joystick is configured and the ; docking computer is not activated, so we now centre ; the roll and pitch rates if required LDX #128 ; Set X to 128, which is the centre value for roll and ; pitch, and represents no change to the current roll or ; pitch LDA KY3 ; If the joystick is being moved left or right, jump to ORA KY4 ; termite to skip the following instruction BNE termite STX JSTX ; Set JSTX = 128 to set the roll rate to zero .termite LDA KY5 ; If the joystick is being moved up or down, jump to ant ORA KY6 ; to skip the following instruction, so pressing buttons BNE ant ; on the controller overrides the docking computer STX JSTY ; Set JSTX = 128 to set the pitch rate to zero .ant ; Fall through into DK4 to scan for other keysName: DOKEY [Show more] Type: Subroutine Category: Keyboard Summary: Scan for the seven primary flight controls and apply the docking computer manoeuvring code Deep dive: The key logger The docking computerContext: See this subroutine in context in the source code References: This subroutine is called as follows: * TT17 calls DOKEY
Scan for the seven primary flight controls (or the equivalent on joystick), pause and configuration keys, and secondary flight controls, and update the key logger accordingly. Specifically, this part clears the key logger and updates it for the seven primary flight controls, and updates the pitch and roll rates accordingly. We then end up at DK4 to scan for other keys, beyond the seven primary flight controls.
[X]
Subroutine BUMP2 (category: Dashboard)
Bump up the value of the pitch or roll dashboard indicator
[X]
Label DK11 is local to this routine
[X]
Label DK12 is local to this routine
[X]
Label DK13 is local to this routine
[X]
Label DK14 is local to this routine
[X]
Label DK15 is local to this routine
[X]
Subroutine DOCKIT (category: Flight)
Apply docking manoeuvres to the ship in INWK
[X]
Variable JSTK in workspace Option variables
Keyboard or joystick configuration setting
[X]
Subroutine RDKEY (category: Keyboard)
Scan the keyboard for key presses
[X]
Subroutine REDU2 (category: Dashboard)
Reduce the value of the pitch or roll dashboard indicator
[X]
Subroutine ZINF (category: Universe)
Reset the INWK workspace and orientation vectors
[X]
Label ant is local to this routine
[X]
Label termite is local to this routine