[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reading Joystick Position
"Simon Williams" <email@luddite.ca> wrote in message
11222119.WSIVWKSM@news.telusplanet.net">news:11222119.WSIVWKSM@news.telusplanet.net...
>
>
> On Mon, 18 Nov 2002 20:51:36 -0600 "Joel"
<joelbuckley54.nospam.@hotmail.com> wrote:
>
> > You have the right addresses, but the wrong technique.
> > Accessing $C070 (49266) starts a quad timer (all four Paddle inputs).
> > The paddles provide the R in an RC time constant.
> > The timer outputs show up as the hi bit of those 4 addresses.
> > After the timers time out, the hi bit goes from high to low.
> > A software timing loop determines the PDL value.
> > It's fast (12 microseconds per tic), so you can't duplicate this with
Peeks
> > from Applesoft.
> > Here's the routine.
> > $FB1E
> > PREAD LDA $C070 start timers, enter with paddle # in X
> > LDY #0
> > NOP
> > NOP
> > PREAD2 LDA $C064,X
> > BPL RTS2D
> > INY
> > BNE PREAD2
> > DEY ; 255 max
> > RTS2D RTS
>
> Hmmm. think I've got it: to get the X-Y coords of the Joystick, I would
> need to call this routine twice with LDX #0 and LDX #1 respectively.
> Each time thru I would need to return to sender and store $C064,X.
No.
There is no address that contains the paddle value 0-255.
The hi bit of C064,X simply tells us if the timer has timed out.
Register Y contains the paddle value, having recorded how many
times we went through the loop before the timer flipped.
> If this works the way I think it does, then it is possible to read
> either coordinate seperately.
> Is this routine part of ProDOS or BASIC.SYSTEM or would I need to make
> it part of my program?
> SW
This routine is part of the monitor ROM and is called by Applesoft PDL(x).
As long as your program hasn't switched out the monitor ROM you can call it.
As some others have alluded to, you have to be careful when calling this
routine more than once.
All timers are started simultaneously, but they may not all end at the same
time.
If you retrigger a timer when it hasn't timed out from the last trigger, you
may get a bogus result.
This is easy to do.
If you want to read to paddles in a row (like X,Y joystick)
with the standard routine if the first paddle has a low value, it returns
quickly.
If you immediately go to read the second paddle, it may not have timed out
from the trigger to read the first one.
So you really want to kill some time between reading the first and second
paddle.
After storing the Y value, you could just loop until it hits 255.
(Though I'm not certain that's still long enough.)
This would make the read routine a constant length, where as now it runs
faster the lower the paddle value is.
Alternately you could rewrite the paddle read routine to read them both
simultaneously.
The code is pretty tight now, so you might lose some resolution on a double
read routine
(maybe only 128 values instead of 255).
JB