[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IRQs, ][+, //e, and an applesoft question



In article <carndtDE5t29.5wr@netcom.com> carndt@netcom.com (Chris Arndt) writes:
>[...IRQ questions skipped since I can't answer them.  But I can answer this
>one...]
>The same program uses a GET to wait for a carriage return from the modem 
>or a Q from the keyboard to start the routine. I'd like to modify it to 
>wait for a character from the keyboard or modem, or a switch closure on 
>a game port button input. I can handle the switch with a PEEK, but I need 
>a suggestion on how to loop and check for a character input without using 
>GET.

The most recent keypress can be found at memory location 49152.  If the
contents of 49152 are greater than 127, then a key has been pressed, and
PEEK(49152) returns the ASCII code of the keypress, with the high bit set.
If the contents of 49152 are less than 128, then no key has been pressed
since the last time the keyboard was pressed...in this case, PEEK(49152)
returns the ASCII code of the kepress from the previous keyboard check,
with the high bit clear.

After getting a keypress out of location 49152, you should POKE 49168,0.
This resets the keyboard so the next keypress can be detected.

For example:

     10  IF  PEEK (49152) > 127 THEN 50: REM Test keyboard
     20  PRINT "Sorry, no key pressed yet"
     30  FOR X = 1 TO 20: NEXT : REM Delay a little
     40  GOTO 10
     50 K$ = CHR$ ( PEEK (49152) - 128): POKE 49168,0: REM Get key into K$
     60  PRINT "You pressed ";K$
     70  GOTO 30

This method, however, will not automatically check the modem for input
(unlike GET, which will deliver either a keypress or a serial input
character, whichever comes first, provided the serial firmware supports such
a feature).

               - Neil Parker
-- 
Neil Parker, nparker@{cie-2,cie}.uoregon.edu, http://cie-2.uoregon.edu/~nparker

     "Evolution is vastly overrated."  -- Ambassador Delenn, _Babylon_5_