Using Inkeys

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Using Inkeys

Post by 1024MAK »

Yes, INKEY$(n) under ACORN BASIC works slightly differently compared to INKEY$ on the ZX81.

From the Acorn BBC User Guide:
BBC User Guide wrote:GET
GET$
INKEY
INKEY$
The GET and GET$ functions wait until a key is pressed whereas the INKEY and INKEY$ pair give up after a while if no key is pressed.
100 A$ = GET$
will wait (for ever) until a key is pressed whereas
100 A$ = INKEY$(200)
will wait for only 2 seconds (200 hundredths of a second). If no key is pressed within 2 seconds then the computer will move on to the next line of the program and A$ will be empty. If a key was pressed after say one second then the computer will immediately move on to the next line of the program and will put the “character typed” into A$.
The INKEY$ function on a ZX81 takes whatever key (if any) that was detected during the last scan (a scan of the keyboard takes place every time the computer redraws the video picture). It then immediately moves onto the next BASIC line to execute.

In the ZX81 manual it suggests:
10 PAUSE n
20 POKE 16437,255
30 PRINT INKEY$

Where n in line 10 is whatever time you want to wait for.

Line 20 is to overcome a ROM bug that is present in some ROM versions. If the program runs without it on your machine, you can leave it out.

Although, in a game, pausing wastes vital computing time. So it’s not practical to pause for any significant length of time.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Using Inkeys

Post by XavSnap »

Personaly i prefer to use a multi key test to avoid the pause...

Code: Select all

10 PRINT AT 0,0;"DISPLAY 1"
20 IF INKEY$<>"" THEN GOSUB 1000
30 PRINT AT 0,0;"DISPLAY 2"
40 IF INKEY$<>"" THEN GOSUB 1000
50 PRINT AT 0,0;"DISPLAY 3"
60 IF INKEY$<>"" THEN GOSUB 1000
70 GOTO 10

1000 LET A$=INKEY$
1010 IF A$="6" THEN ...
2000 RETURN
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Re: Using Inkeys

Post by MrVertigo »

Nice!

Another method I’ve seen is:
10 LET N=0
20 LET A$=INKEY$
30 IF A$ <> “” THEN GOTO 60
40 LET N=N+1
50 IF N<50 GOTO 20
60 IF A$=“8”...etc

In line 50 you set the length of pause you want.
User avatar
stefano
Posts: 568
Joined: Tue Dec 11, 2012 9:24 am
Contact:

Re: Using Inkeys

Post by stefano »

100 IF INKEY$ <> "" THEN GO TO 100
110 IF INKEY$ = "" THEN GO TO 110
120 LET A=CODE INKEY$ (or LET A$=INKEY$)

On the Spectrum I used to put:
100 PAUSE 0 (or PAUSE NOT PI) to reduce the code size and be quicker in typing

I neve knew of the ZX81 bug with PAUSE !
Post Reply