Skip to navigation

Elite on the BBC Micro

Keyboard: DK4 [Master version]

Name: DK4 [Show more] Type: Subroutine Category: Keyboard Summary: Scan for pause, configuration and secondary flight keys Deep dive: The key logger
Context: See this subroutine in context in the source code Variations: See code variations for this subroutine in the different versions References: This subroutine is called as follows: * DOKEY calls DK4

Scan for pause and configuration keys, and if this is a space view, also scan for secondary flight controls. Specifically: * Scan for the pause button (COPY) and if it's pressed, pause the game and process any configuration key presses until the game is unpaused (DELETE) * If this is a space view, scan for secondary flight keys and update the relevant bytes in the key logger
.DK4 LDX KL \ Fetch the key pressed from byte #0 of the key logger CPX #&8B \ If COPY is not being pressed, jump to DK2 below, BNE DK2 \ otherwise let's process the configuration keys .FREEZE \ COPY is being pressed, so we enter a loop that \ listens for configuration keys, and we keep looping \ until we detect a DELETE key press. This effectively \ pauses the game when COPY is pressed, and unpauses \ it when DELETE is pressed JSR WSCAN \ Call WSCAN to wait for the vertical sync, so the whole \ screen gets drawn JSR RDKEY \ Scan the keyboard for a key press and return the \ ASCII code of the key pressed in X (or 0 for no key \ press) CPX #'Q' \ If "Q" is not being pressed, skip to DK6 BNE DK6 LDX #&FF \ "Q" is being pressed, so set DNOIZ to &FF to turn the STX DNOIZ \ sound off LDX #&51 \ Set X to &51, which is the internal key for "S" on the \ BBC Micro. This is set to ensure that X has the same \ value at this point as the BBC Micro version of this \ routine would .DK6 LDY #0 \ We now want to loop through the keys that toggle \ various settings, so set a counter in Y to work our \ way through them .DKL4 JSR DKS3 \ Call DKS3 to scan for the key given in Y, and toggle \ the relevant setting if it is pressed INY \ Increment Y to point to the next toggle key CPY #9 \ Check to see whether we have reached the last toggle \ key BNE DKL4 \ If not, loop back to check for the next toggle key LDA VOLUME \ Fetch the current volume setting into A CPX #'.' \ If "." is being pressed (i.e. the ">" key) then jump BEQ VOLUP \ to VOLUP to increase the volume CPX #',' \ If "," is not being pressed (i.e. the "<" key) then BNE NOVOL \ jump to NOVOL to skip the following DEC A \ The volume down key is being pressed, so decrement the \ volume level in A EQUB &24 \ Skip the next instruction by turning it into &24 &1A, \ or BIT &001A, which does nothing apart from affect the \ flags .VOLUP INC A \ The volume up key is being pressed, so increment the \ volume level in A TAY \ Copy the new volumen level to Y AND #%11111000 \ If any of bits 3-7 are set, skip to MAXVOL as we have BNE MAXVOL \ either increased the volume past the maximum volume of \ 7, or we have decreased it below 0 to -1, and in \ neither case do we want to change the volume as we are \ already at the maximum or minimum level STY VOLUME \ Store the new volume level in VOLUME .MAXVOL PHX \ Store X on the stack so we can retrieve it below after \ making a beep JSR BEEP \ Call the BEEP subroutine to make a short, high beep at \ the new volume level LDY #10 \ Wait for 10/50 of a second (0.2 seconds) JSR DELAY PLX \ Restore the value of X we stored above .NOVOL CPX #'B' \ If "B" is not being pressed, skip to DK7 BNE nobit LDA BSTK \ Toggle the value of BSTK between 0 and &FF EOR #&FF STA BSTK STA JSTK \ Configure JSTK to the same value, so when the Bitstik \ is enabled, so is the joystick STA JSTE \ Configure JSTE to the same value, so when the Bitstik \ is enabled, the joystick is configured with reversed \ channels BPL P%+5 \ If we just toggled the Bitstik off (i.e. to 0, which \ is positive), then skip the following two instructions JSR BELL \ We just enabled the Bitstik, so give two standard JSR BELL \ system beeps .nobit CPX #'S' \ If "S" is not being pressed, jump to DK7 BNE DK7 LDA #0 \ "S" is being pressed, so set DNOIZ to 0 to turn the STA DNOIZ \ sound on .DK7 CPX #&1B \ If ESCAPE is not being pressed, skip over the next BNE P%+5 \ instruction JMP DEATH2 \ ESCAPE is being pressed, so jump to DEATH2 to end \ the game CPX #&7F \ If DELETE is not being pressed, we are still paused, BNE FREEZE \ so loop back up to keep listening for configuration \ keys, otherwise fall through into the rest of the \ key detection code, which unpauses the game .DK2 RTS \ Return from the subroutine