Skip to navigation

Elite on the BBC Micro and NES

Version analysis of DKS2

This code appears in the following versions (click to see it in the source code):

Code variations between these versions are shown below.

Name: DKS2 Type: Subroutine Category: Keyboard Summary: Read the joystick position

Code variation 1 of 3A variation in the comments only

This variation is blank in the Cassette, Disc (flight), Disc (docked) and 6502 Second Processor versions.

This routine is never called in the Electron version, as the Electron doesn't have ADC channels as standard and doesn't support joysticks (though a lot of the joystick code from the other versions is still present, it just isn't called).
Return the value of ADC channel in X (used to read the joystick). The value will be inverted if the game has been configured to reverse both joystick channels (which can be done by pausing the game and pressing J).
Arguments: X The ADC channel to read: * 1 = joystick X * 2 = joystick Y
Returns: (A X) The 16-bit value read from channel X, with the value inverted if the game has been configured to reverse the joystick

Code variation 2 of 3A variation in the comments only

This variation is blank in the 6502 Second Processor version.

Other entry points: DKS2-1 Contains an RTS
.DKS2

Code variation 3 of 3Related to Elite's use of the Tube

Tap on a block to expand it, and tap it again to revert.

LDA #128 \ Call OSBYTE with A = 128 to fetch the 16-bit value JSR OSBYTE \ from ADC channel X, returning (Y X), i.e. the high \ byte in Y and the low byte in X \ \ * Channel 1 is the x-axis: 0 = right, 65520 = left \ \ * Channel 2 is the y-axis: 0 = down, 65520 = up TYA \ Copy Y to A, so the result is now in (A X)
LDA KTRAN+7,X \ Fetch either the joystick X value or joystick Y value \ from the key logger buffer, depending on the value of \ X (i.e. fetch either KTRAN+8 or KTRAN+0)
 EOR JSTE               \ The high byte A is now EOR'd with the value in
                        \ location JSTE, which contains &FF if both joystick
                        \ channels are reversed and 0 otherwise (so A now
                        \ contains the high byte but inverted, if that's what
                        \ the current settings say)

 RTS                    \ Return from the subroutine