Skip to navigation

Elite on the BBC Micro and NES

Keyboard: DKJ1

[Elite-A, Parasite]

Name: DKJ1 [Show more] Type: Subroutine Category: Keyboard Summary: Read joystick and flight controls
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DOKEY_FLIGHT calls DKJ1

Specifically, scan the keyboard for the speed up and slow down keys, and read the joystick's fire button and X and Y axes, storing the results in the key logger and the joystick position variables. This routine is only called if joysticks are enabled (JSTK = non-zero).
.DKJ1 LDA auto \ If auto is non-zero, then the docking computer is BNE auton \ currently activated, so jump to auton in DOKEY so the \ docking computer can "press" the flight keys for us LDY #1 \ Update the key logger for key 1 in the KYTB table, so JSR DKS1 \ KY1 will be &FF if "?" (slow down) is being pressed INY \ Update the key logger for key 2 in the KYTB table, so JSR DKS1 \ KY2 will be &FF if Space (speed up) is being pressed JSR scan_fire \ Call scan_fire to check whether the joystick's fire \ button is being pressed, which clears bit 4 in A if \ the fire button is being pressed, and sets it if it \ is not being pressed EOR #%00010000 \ Flip bit 4 so that it's set if the fire button has STA KY7 \ been pressed, and store the result in the keyboard \ logger at location KY7, which is also where the A key \ (fire lasers) key is logged LDX #1 \ Call DKS2 to fetch the value of ADC channel 1 (the JSR DKS2 \ joystick X value) into (A X), and OR A with 1. This ORA #1 \ ensures that the high byte is at least 1, and then we STA JSTX \ store the result in JSTX LDX #2 \ Call DKS2 to fetch the value of ADC channel 2 (the JSR DKS2 \ joystick Y value) into (A X), and EOR A with JSTGY. EOR JSTGY \ JSTGY will be &FF if the game is configured to STA JSTY \ reverse the joystick Y channel, so this EOR does \ exactly that, and then we store the result in JSTY JMP DK4_FLIGHT \ We are done scanning the joystick flight controls, \ so jump to DK4_FLIGHT to scan for other keys, using a \ tail call so we can return from the subroutine there