[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Apple II Random Events?
Michael J. Mahon (mahon@cup.hp.com) wrote:
: Rubywand wrote:
: >
: > Gabriel Morales writes ...
: > >
: > > I was wondering:
: > >
: > > How does an Apple II, say using the BASIC RND command, determine a
: > > random number?
: > >
:
: <stuff deleted>
: > A pretty good way to mix things up is to place code which calls the
: > RND() function inside some subroutine which gets frequently accessed and
: > where the the number of RND() calls is not predictable. For instance,
: > you could place ZZ= RND(1) inside a Get Key routine ...
: >
: > 50 REM GET A KEY (RETURNS ASCII CODE IN AC)
: > 60 ZZ= RND(1): ZZ= PEEK(49152): IF ZZ<128 THEN 60
: > 70 AC= ZZ-128: ZZ= PEEK(49168): RETURN
A quick trick for Applesoft programmers waiting for a keypress...
Technically, you are supposed to wait for the keypress by watching $C000
(49152, or -16384 for you old-timers); when the keypress arrives, the high
bit is set, and the keypress stays in the one-bit keyboard buffer until it
is reset with a call to the keyboard strobe at $C010 (=49168 or -16368).
So your code looks like this--
REM GET Q1$:
60000 KB%=PEEK (-16384):ON KB%>127 GOTO 60005:REM Here do all the stuff
you want to do while waiting for a keypress; I have one program, for
instance, which uses this opportunity to read and display the IIgs clock!
60002 GOTO 60000
60005 Q1$=CHR$(KB%-128) : ST=PEEK(-16368):RETURN
Well, it just so happens that you can save yourself the effort by
replacing line 60005 as follows:
60005 GET Q1$ : RETURN
You see, you wait for the keypress by watching the keyboard input location
as usual. Once the keystroke arrives, if you don't clear the strobe, you
can issue a GET instruction. GET will wait for the keypress, but since
the keypress has already arrived (you made sure of that by waiting until
it arrived before you called GET), GET never has a chance to display the
cursor. Instead, it passes the keypress straight to your string variable
and clears the keyboard strobe for you.
Just another short-cut from a long-time Applesoft Ace...
--Dave Althoff, ][.
--
/^\ _ _ *** Closed for the season 8-( ***
/XXX\ /X\ /X\_ _ /X\__ _ _ _____
/XXXXX\ /XXX\ _/XXXX\_ /X\ /XXXXX\ /X\ /X\ /XXXXX
_/XXXXXXX\__/XXXXX\/XXXXXXXX\_/XXX\_/XXXXXXX\__/XXX\_/XXX\_/\_/XXXXXX