Skip to navigation

Aviator on the BBC Micro

Keyboard: ReadADCChannel

Name: ReadADCChannel [Show more] Type: Subroutine Category: Keyboard Summary: Read the joystick position from one of the ADC channels
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ReadJoystick calls ReadADCChannel

Arguments: X The ADC channel to read: * 1 = joystick X * 2 = joystick Y Returns: A The joystick position, inverted and clipped to the range -118 to +116
.ReadADCChannel 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 TYA \ Copy Y to A, so the result is now in (A X) CMP #247 \ If A < 247, jump to radc1 to skip the next instruction BCC radc1 LDA #246 \ Set A = 246, so A now has a maximum value of 246 .radc1 CMP #12 \ If A >= 12, jump to radc2 to skip the next instruction BCS radc2 LDA #12 \ Set A = 12, so A now has a minimum value of 12 .radc2 \ By the time we get here, A is in the range 12 to 246 SEC \ Set A = A - 128, so A is now in the range -116 to +118 SBC #128 EOR #&FF \ Negate A using two's complement, so A is now in the CLC \ range -118 to +116 ADC #1 RTS \ Return from the subroutine