[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Apple II Random Events?
Dave Althoff <dalloff@freenet.columbus.oh.us> wrote:
> Paul Guertin (pg@sff.net) wrote:
> : For extra credit, can you think of a situation where the optional
> : third argument to WAIT is useful?
>
> That would allow you to wait for a *particular* value. The expression you
> describe, WAIT -16384,128,0, checks only one bit. Using the third
> argument allows you to still check only one bit (using 128 for the second
> argument) but specifying an alternate bit pattern that you are actually
> looking for. So WAIT -16384,128,160 will wait until the SPACE BAR is
> pressed. This is useful because WAIT -16384,160,0 will wait for any
> keypress with an ASCII value greater than 32, since non-specified bits in
> the second argument are not checked.
>
> It was a guess...how did I do? 8-)
I'm working from memory here, but I don't think that is right. You are
on the right track, though.
The second argument to WAIT is the AND mask. WAIT -16384,128 means
"PEEK location -16384, AND the result with 128, and stop waiting if the
result is not zero. Rinse and repeat until then."
The third argument to WAIT is the XOR mask. The only bits in the XOR
mask that have any significance are ones that are also in the AND mask.
The simplest use of the third parameter is to test for a flag bit
becoming zero rather than one. For example, you could wait for paddle
button 0 (the OpenApple key) to be released using WAIT -16287,128,128.
This means "PEEK location -16287, XOR the result with 128, AND the
subsequent result with 128, and stop waiting if the result is not zero.
Rinse and repeat until then."
I will now check the Applesoft reference manual to confirm my
description. [Ruffling through bookshelf.]
Yep.
The Applesoft reference describes the third argument as the value to be
tested for, except that it is complemented: 1 where you want the
corresponding bit in the memory location to be 0, and vice versa. Only
bits listed in the second argument are significant. An easy way to
complement an 8-bit value is to subtract it from 255.
If you wanted to wait for a specific character to be pressed, _and_ you
weren't on a IIgs (keyboard buffering would kill this), then you could
use WAIT -16384,255,255-160.
As to your final statement about the behaviour of WAIT -16384,160,0: it
will actually wait for any character with bit 5 set, which is all ASCII
characters from $20 (SPACE) to $3F (?), including digits and most
symbols, or $60 (`) to $7F (DEL), including lower case letters; but not
control characters ($00-$1F) or characters from $40 (@) to $5F (_),
including upper case letters.
Here endeth the lesson. :-)
--
David Empson
dempson@actrix.gen.nz
Snail mail: P.O. Box 27-103, Wellington, New Zealand