<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 16 May 2002 10:44:49 +0100
From   : jgh@... (Jonathan Graham Harston)
Subject: Re: BBC joystick code

On Tue, 30 Apr 2002, Nic Bwts wrote:
> I have been searching the web for people who program BBC micros because
> I am looking for an example of some assembley code that makes use of
> joysticks. To be more precise I am looking for examples of code that
> make use of the analogue to digital coverter interupt routine. I have
> read the user guides but they give no examples of the code needed to do
> this. I hope you can help as I have been searching for two months now
 
Why do you need the ADC interupt?  If polling will suffice, just call
ADVAL:
 
LDA #&80
LDX #adc_channel  :\ 1, 2, 3 or 4
JSR OSBYTE
\ Returns YX holding ADC value
 
If you wnt to use the ADC Conversion Finished event, something like the
following would do it:
 
EVENTV=&200                      :\ Event vector
OSBYTE=&FFF4                     :\ OS Byte operations
 
.OldEvntV:DEFW 0                 :\ To store previous vector value
 
.SetUpEvent
PHP:SEI                          :\ Stop interupts while changing vectors
LDA EVNTV:STA OldEvntV
LDA EVNTV+1:STA OldEvntV+1
LDA #MyEvent AND 255:STA EVNTV
LDA #MyEvent DIV 256:STA EVNTV+1
PLP                              :\ Restore interupts
LDA #14
LDX #3                           :\ ADC is event 3
JSR OSBYTE                       :\ Enable ADC event
... etc ...
 
The following code will be called on any event:
 
.MyEvent
PHP                              :\ Must save all registers
CMP #3
BEQ MyADCEvent                   :\ Is it event 3 - ADC?
PLP                              :\ Restore status
JMP (OldEvent)                   :\ Chain to next handler
.MyADCEvent                      :\ Y holds channel just converted
PHP                              :\ Save P register
TXA:PHA                          :\ Save X register
TYA:PHA:TAX                      :\ Save Y and transfer channel to X
LDA #&80:JSR OSBYTE              :\ Read the ADC value
... etc ...
do something with the value
... etc ...
PLA:TAY                          :\ Restore Y register
PLA:TAX                          :\ Restore X register
PLA:PLP                          :\ Restore A and P
JMP (OldEvent)                   :\ Daisy-chain onwards
 
-- 
J.G.Harston (JGH BBC PD Library) 70 Camm Street, Walkley, SHEFFIELD S6 3TR
jgh@...                - Running on BBCs & Masters with SJ MDFS FileServer
Z80+6502/CoPro+Tubes/Econet+SJ - - - - - - - http://www.mdfs.net/User/JGH/
 Never, ever, EVER, *EVER*, *E*V*E*R* use an apostrophe to make a plural
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>