<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Mon, 26 Apr 2004 19:01:09 +0100
From   : Richard Gellman <splodge@...>
Subject: Re: Analogue Port Fire Buttons

Pete Turnbull wrote:

>On Apr 26,  8:29, Joel D. Snape wrote:
>  
>
>>Can anybody out there help a 14 year old newcomer to the field? I
>>would like to know how you check to see if the fire buttons are
>>pressed on a Joystick connected to the Analogue port for a plotter
>>program I am trying to write.
>>    
>>
>
>In BASIC, ADVAL(0) returns the state of the fire buttons and the ADC
>channels.  ADVAL(0) DIV 256 tells you which ADC channel last finished a
>conversion.  ADVAL(0) AND 3 gives the state of the buttons; bit 0 is
>set (odd numbers) if the left fire button is pressed, and bit 1 is set
>(result is 2 or 3) if the right-hand button is pressed.
>
>In assembly language, OSBYTE &80 provides the equivalent of ADVAL.  On
>entry, if X=0 then it reads the buttons and channel status; on exit the
>bottom two bits of X contain the button data and Y contains the channel
>number (or zero if no channel has completed a conversion).
>  
>
*donates two pennies coin of the realm*

 From a more low level perspective, a little mentioned fact (at least 
certainly not something particulary drawn to in the accompanying user 
guides) is that the fire buttons are not connected to the ADC chip. 
While the 15-pin D connector at the back does indeed offer 4 analogue 
channels and two fire button inputs, only the analogue channels go to 
the UPD7002 ADC chip.

The "fire" buttons are in fact connected to the slow peripheral bus, aka 
the VIA-A. If you're planning to do a low-level implementation, then 
you'll find that while getting info out of the ADC is easy enoug, 
getting your accesses right with the VIA is a little harder. You need to 
disable interrupts, set the B side to the right address, and take a look 
at the A side, get the data you want, then clear interrupts again.

Failure to deal with the SEI/CLI pair will result in your BBC Micro 
making nasty noises at you or otherwise buggering things up ;)

-- Richard Gellman
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>