Using Inkeys

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Re: Using Inkeys

Post by MrVertigo »

The root of my problem is that the window of opportunity for inputing a command rushes past too fast with INKEYS. I didn’t know until now that some computers other than the ZX81 need a number after their INKEYS command, to define how many milliseconds the computer waits for an INKEYS command before moving on.

It seems that the best way to achieve this on the ZX81 is to make the program loop around the INKEYS section briefly, using FOR/NEXT etc. I find input is much more responsive that way.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Using Inkeys

Post by XavSnap »

Hi MrVertigo ,

Thanks 1024MAK & dr beep for suggestions...

But, i presume MrVertigo can't explain its problem...

It's right?

I have 4 keys, north/east/south & west.
"Can i use "INKEY$" to go to Noth-East?"
Yes, if you use a loop on the command.
No, if you scan the Keyboard stat once.

"INKEY$" scan the last key stokes, but can't display a couple of key.
"A"+"P"= "P" if the scan is done on the "p" key.
In this case, you can't freeze the scan by using the LET K$= INKEY$ (Get the key at this moment!)
If both keys are pressed, only one key will be memorized.

Simultaneous pressed key can't be scanned in BASIC...
You had to use alternative keys to go to diagonals.

The BASIC valid any keys while its released.
If the fist key is active, the second key will be shadowed.

From the Mark's code:

Code: Select all

10 GOSUB 1000
20 FOR A=0 TO 0 STEP 0
30 LET OX=X
40 LET OY=Y
50 LET X=X+(INKEY$="P")-(INKEY$="O")
60 LET Y=Y+(INKEY$="Q")-(INKEY$="A")
70 IF NOT INKEY$ THEN GOTO 50
80 UNPLOT OX,OY
90 PLOT X,Y
100 REM OTHER CODE
110 NEXT A
1000 LET X=32
1020 LET Y=22
1030 RETURN
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
mrtinb
Posts: 1911
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Using Inkeys

Post by mrtinb »

Maybe reading LAST_K from Basic would be possible with PEEK. Then testing for multiple key presses would be possible.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
dr beep
Posts: 2080
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Using Inkeys

Post by dr beep »

XavSnap wrote: Tue Jul 25, 2023 1:28 am Hi MrVertigo ,

Thanks 1024MAK & dr beep for suggestions...

But, i presume MrVertigo can't explain its problem...

It's right?

I have 4 keys, north/east/south & west.
"Can i use "INKEY$" to go to Noth-East?"
Yes, if you use a loop on the command.
No, if you scan the Keyboard stat once.

"INKEY$" scan the last key stokes, but can't display a couple of key.
"A"+"P"= "P" if the scan is done on the "p" key.
In this case, you can't freeze the scan by using the LET K$= INKEY$ (Get the key at this moment!)
If both keys are pressed, only one key will be memorized.

Simultaneous pressed key can't be scanned in BASIC...
You had to use alternative keys to go to diagonals.

The BASIC valid any keys while its released.
If the fist key is active, the second key will be shadowed.

From the Mark's code:

Code: Select all

10 GOSUB 1000
20 FOR A=0 TO 0 STEP 0
30 LET OX=X
40 LET OY=Y
50 LET X=X+(INKEY$="P")-(INKEY$="O")
60 LET Y=Y+(INKEY$="Q")-(INKEY$="A")
70 IF NOT INKEY$ THEN GOTO 50
80 UNPLOT OX,OY
90 PLOT X,Y
100 REM OTHER CODE
110 NEXT A
1000 LET X=32
1020 LET Y=22
1030 RETURN
INKEY$ will return no key when multiple keys are pressed, for multiple keys on a ZX81 you will need IN in assembler.
LASTK also only returns 1 key.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Using Inkeys

Post by XavSnap »

We assume a shifted key is not a multiple keys process...

Code: Select all

1 REM KEYBOARD TEST
2 LET S$="@00@DA@DE@DF@00@00@00@00@00@E3*?@E4@E0@E5@E2@D8(-+=><)@00@C0@DB@E1@DD$/@D9;@DC:,@0C"
4 PRINT AT 0,0;"KEY:            ";AT 0,5;
5 LET K$=INKEY$
6 LET K=PEEK 16422
7 IF K$="" THEN GOTO 5
8 LET KB=CODE K$
10 LET S=NOT (INT (K-(INT(K/2)*2)))
15 GOSUB 100
20 PRINT ("SHIFTED " AND S);K$
25 PRINT KB
30 GOTO 4

100 IF KB>111 AND KB<120 THEN GOTO 150
105 FOR A=1 TO LEN S$
110 IF KB<>CODE S$(A) THEN NEXT A
120 IF A<=LEN S$ THEN IF CODE S$(A)<>0 THEN LET K$=CHR$ (28+A)
130 IF KB=11 THEN LET K$="P"
135 IF K$="," THEN LET K$="."
140 RETURN
150 LET K$=("5" AND KB=114)+("6" AND KB=113)+("7" AND KB=112)+("8" AND KB=115)+("1" AND KB=117)+("0" AND KB=119)+("9" AND KB=116)
160 RETURN
200 SAVE "SHIFT"
SHIFT.P
(1.5 KiB) Downloaded 108 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
dr beep
Posts: 2080
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Using Inkeys

Post by dr beep »

Shift simply creates a different lastk code
dr beep
Posts: 2080
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Using Inkeys

Post by dr beep »

On the Zx Spectrum IN was an extra function which could read multiple keypresses.....

but the keyboarddesign made it possible to have ghostkeys pressed.

Read Q to T and press Q and W, Read A to G and press A. You will also have S pressed.
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 »

The other problem is that, if you do want to go to a lower level, the code gets harder to do in BASIC. Even if there was an IN function on the ZX81, there are no bitwise operators to deal with the individual bits of the byte that is returned.

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 »

My new release (much faster & very less bugged) of the shifted keys decoder (for the GP100 printer for example)

Note:
Shifted space ("£") can"t be code, it's the BREAK command in BASIC.

shift2.jpg
shift2.jpg (22.42 KiB) Viewed 4255 times

Code: Select all

1 REM KEYBOARD TEST
2 LET S$="@77@75@DA@DE@DF@72@71@70@73@74@E3*?@E4@E0@E5@E2@D8(-+=><)@00@C0@DB@E1@DD$/@D9;@DC:"
4 PRINT AT 0,0;"KEY: @08           ";AT 0,5;
5 LET K$=INKEY$
6 LET K=PEEK 16422
7 IF K$="" THEN GOTO 5
8 LET KB=CODE K$
10 LET S=NOT (INT (K-(INT(K/2)*2)))
30 IF S THEN GOSUB 110
40 PRINT ("SHIFTED " AND S);CHR$(CODE K$+(128 AND S))
50 PRINT KB;"  "
60 GOTO 4

100 REM SHIFT DECODER
110 FOR A=1 TO 35
120 IF KB<>CODE S$(A) THEN NEXT A
130 IF CODE S$(A)<>0 THEN LET K$=CHR$ (27+A)
140 IF KB=11 THEN LET K$="P"
150 IF KB=26 THEN LET K$="."
160 RETURN
200 SAVE "SHIFT2"

SHIFT2.P
(1.36 KiB) Downloaded 98 times
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 »

I’m not trying to do diagonal movement, or have multiple key presses.

I think some confusion has occurred.

I am only moving left and right. But I have multiple enemies onscreen.

I didn’t find my left and right controls to be responsive enough, because INKEYS only works when the program is at that line, I think. Then the chance is gone.

I discovered BASIC on other micros let you set a number of microseconds to “hover” on the INKEYS line. To make the window of response time longer.

So I put INKEYS inside a For/Next loop, like:

10 For N=1TO 5
20 Let A$=INKEYS
30 IF A$<>”” THEN LET N= 5
40 Next N
50 IF A$=“8”.......etc

I found this made my left and right keys more responsive.

Does that make sense?
Post Reply