Page 1 of 2

Eightyone emulator not recognizing cursor keys as joystick

Posted: Sun Mar 03, 2024 10:37 pm
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?

Re: Eightyone emulator not recognizing cursor keys as joystick

Posted: Sun Mar 03, 2024 11:28 pm
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

Re: Eightyone emulator not recognizing cursor keys as joystick

Posted: Mon Mar 04, 2024 2:28 am
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

Re: Eightyone emulator not recognizing cursor keys as joystick

Posted: Mon Mar 04, 2024 12:36 pm
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

Re: Eightyone emulator not recognizing cursor keys as joystick

Posted: Tue Mar 05, 2024 6:23 pm
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

Re: Eightyone emulator not recognizing cursor keys as joystick

Posted: Tue Mar 05, 2024 7:17 pm
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?

Re: Eightyone emulator not recognizing cursor keys as joystick

Posted: Tue Mar 05, 2024 7:41 pm
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

Re: Eightyone emulator not recognizing cursor keys as joystick

Posted: Tue Mar 05, 2024 8:02 pm
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

Re: Eightyone emulator not recognizing cursor keys as joystick

Posted: Tue Mar 05, 2024 9:09 pm
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

Re: Eightyone emulator not recognizing cursor keys as joystick

Posted: Tue Mar 05, 2024 9:22 pm
by Crayon21
what about collision with another object?