Eightyone emulator not recognizing cursor keys as joystick

Emulator and emulator development specific topics
Crayon21
Posts: 354
Joined: Sun Nov 04, 2018 2:33 am

Eightyone emulator not recognizing cursor keys as joystick

Post by Crayon21 »

This is my code:
10 LET X=0: LET Y=0
15 LET J=0: LET K=10
20 LET K$=INKEY$
25 PRINT AT J,K; "*"
30 IF K$="" THEN GOTO 30
40 IF K$="8" (CURSOR RIGHT) THEN LET X=X+1 (for some reason X and Y are flipped)
41 if K$="5" (CURSOR LEFT) THEN LET X=X+1
72 GOTO 20
it just sits there and I can't move it at all. Is this a bug in the emulator or a problem with my code?
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
Exile
Posts: 44
Joined: Tue Jan 03, 2023 9:50 pm

Re: Eightyone emulator not recognizing cursor keys as joystick

Post by Exile »

At the moment I think it will not read the joystick again if it is not initially pressed?
Do you need to change line 30 to:

30 IF K$="" THEN GOTO 20

Also I presume one of line 40 or 41 should be X=X-1
Currently both are X=X+1
Crayon21
Posts: 354
Joined: Sun Nov 04, 2018 2:33 am

Re: Eightyone emulator not recognizing cursor keys as joystick

Post by Crayon21 »

It does not work with arrow keys. Tried twice. maybe someone can fix that in an update?

also, the spectrum maps the X coordinate and the Y coordinate as X=down, Y=across instead of Y down, X across which plays merry hell with any programs using these coordinates.

In other words, moving UP causes me to move down and left becomes right.
It's...irritating
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
Exile
Posts: 44
Joined: Tue Jan 03, 2023 9:50 pm

Re: Eightyone emulator not recognizing cursor keys as joystick

Post by Exile »

Here is some Basic code that uses the cursors keys to move a character around the screen. The code has been tested and works on both the ZX81 (sz81, picozx81 & EightyOne) and Spectrum (EightyOne and FUSE). There are checks to ensure that the character stays within the screen bounds. I used zmakebas to convert the code into a .p (ZX81) and .tap (Spectrum) file for testing.

Code: Select all

10 LET X=15
20 LET Y=10
30 PRINT AT Y,X;"O"
40 LET A$ = INKEY$
50 IF A$="" THEN GOTO 40
60 PRINT AT Y,X;" "
70 IF (A$="5") * (X>0) THEN LET X=X-1
80 IF (A$="6") * (Y<20) THEN LET Y=Y+1
90 IF (A$="7") * (Y>0) THEN LET Y=Y-1
100 IF (A$="8") * (X<30) THEN LET X=X+1
110 GOTO 30
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Eightyone emulator not recognizing cursor keys as joystick

Post by 1024MAK »

@Crayon21, in your original program, you are not actually using X to set the print position. You are using J and K. That's why the program appears to ignore the cursor keys.

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.
Crayon21
Posts: 354
Joined: Sun Nov 04, 2018 2:33 am

Re: Eightyone emulator not recognizing cursor keys as joystick

Post by Crayon21 »

1024MAK wrote: Tue Mar 05, 2024 6:23 pm @Crayon21, in your original program, you are not actually using X to set the print position. You are using J and K. That's why the program appears to ignore the cursor keys.

Mark
I'll give this a go, thanks

I can get left but it goes right when I hit the edge of the screen.
is there a corrected rom?
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
Crayon21
Posts: 354
Joined: Sun Nov 04, 2018 2:33 am

Re: Eightyone emulator not recognizing cursor keys as joystick

Post by Crayon21 »

Exile wrote: Mon Mar 04, 2024 12:36 pm Here is some Basic code that uses the cursors keys to move a character around the screen. The code has been tested and works on both the ZX81 (sz81, picozx81 & EightyOne) and Spectrum (EightyOne and FUSE). There are checks to ensure that the character stays within the screen bounds. I used zmakebas to convert the code into a .p (ZX81) and .tap (Spectrum) file for testing.

Code: Select all

10 LET X=15
20 LET Y=10
30 PRINT AT Y,X;"O"
40 LET A$ = INKEY$
50 IF A$="" THEN GOTO 40
60 PRINT AT Y,X;" "
70 IF (A$="5") * (X>0) THEN LET X=X-1
80 IF (A$="6") * (Y<20) THEN LET Y=Y+1
90 IF (A$="7") * (Y>0) THEN LET Y=Y-1
100 IF (A$="8") * (X<30) THEN LET X=X+1
110 GOTO 30

what are those secondary bracket checks for (x<30) and so on?
thank you for the help BTW
How do I check for collision? I've tried printing at the area and no luck. Screen$ and Attr likewise return no results
Last edited by Crayon21 on Tue Mar 05, 2024 8:18 pm, edited 1 time in total.
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Eightyone emulator not recognizing cursor keys as joystick

Post by 1024MAK »

Crayon21 wrote: Tue Mar 05, 2024 7:17 pm
1024MAK wrote: Tue Mar 05, 2024 6:23 pm @Crayon21, in your original program, you are not actually using X to set the print position. You are using J and K. That's why the program appears to ignore the cursor keys.

Mark
I'll give this a go, thanks

I can get left but it goes right when I hit the edge of the screen.
is there a corrected rom?
You also need to take into account what Exile wrote.

If there are no limits set to the value of the variable, then after zero (0) it will go negative. Hence the strange effect.

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.
Exile
Posts: 44
Joined: Tue Jan 03, 2023 9:50 pm

Re: Eightyone emulator not recognizing cursor keys as joystick

Post by Exile »

what are those secondary bracket checks for (x<30) and so on?
These checks ensure that x does not not go negative, or become larger than 30, and that y does not become negative, or larger than 20. That keeps the "O" within the boundary of the screen.

As an example,

70 IF (A$="5") * (X>0) THEN LET X=X-1 can be read as:

If left arrow pressed AND x is larger than 0 THEN x = x-1
Crayon21
Posts: 354
Joined: Sun Nov 04, 2018 2:33 am

Re: Eightyone emulator not recognizing cursor keys as joystick

Post by Crayon21 »

what about collision with another object?
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
Post Reply