.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 \ \ * 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) 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 subroutineName: ReadADCChannel [Show more] Type: Subroutine Category: Keyboard Summary: Read the joystick position from one of the ADC channelsContext: 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
[X]
Configuration variable OSBYTE = &FFF4
The address for the OSBYTE routine
[X]
Label radc1 is local to this routine
[X]
Label radc2 is local to this routine