[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Programming Question
In article <34832fc8.6734854@129.3.17.35>,
Edhel Iaur, Esq. <edhel@LOSETHECAPITALWORDSbigfoot.com> wrote:
>On 29 Nov 1997 21:36:54 GMT, retromod-Apple-II-newsgroups; rm -rf
>~;@vuse.vanderbilt.edu (Tilghman Lesher) wrote:
>
>>What you need to do is to program a loop, either a GOTO, if you need a main
>>programming loop or a FOR if you want timed response. Inside the loop,
>>place the following code (or GOSUB to it, if you want).
>>
>>IF PEEK(-16384) > 128 THEN KEY$ = CHR$(PEEK(-16384)):POKE -16368,0
>
>I just use "...THEN GET A$ : POKE..." :)
Actually, if you use GET A$, you don't need the following POKE. GET
automatically clears the keyboard when it's done.
If you use PEEK(-16384), be careful--the example quoted above contains a
bug. Characters PEEKed directly out of the keyboard have their high bits
set, whereas Applesoft normally expects characters to have their high bits
clear. Thus if you use the PEEK example, and then say something like
IF KEY$ = "A" THEN PRINT "Blurfl"
you'll never see "Blurfl" on the screen no matter now many times you press
the A key, because KEY$ contains CHR$(193) (the high-ASCII version of "A"),
but the literal character "A" is CHR$(65), and even the dumbest Apple knows
that CHR$(193) is not equal to CHR$(65).
Fortunately the cure is simple:
IF PEEK (49152) > 127 THEN K$ = CHR$ ( PEEK (49152) - 128): POKE 49168,0
(I like to use 49152 instead of -16384, and 49168 instead of -16368,
because it saves a byte of memory each time, and probably executes slightly
faster because there's one less token to interpret. An even better way
would be
KB = 49152:CK = 49168
and then
IF PEEK (KB) > 127 THEN K$ = CHR$ ( PEEK (KB) - 128): POKE CK,0
.)
- Neil Parker
--
Neil Parker, nparker@inferno.uoregon.edu, nparker@axis.llx.com,
http://www.llx.com/~nparker/ (Note new addresses and home page!)
Unsolicited commerical e-mail is not welcome, and will be discarded unread.