Jump to content
  • 1
JimmyDansbo

Joystick strangeness

Question

I have created a very small program that reads the state of joystick 1 and prints it on the screen. I do NOT have any joysticks connected.

Quote

10 PRINT JOY(1)

20 GOTO 10

If you type in above program and run it, it behaves more or less as expected. It registers the ENTER key some times and then returns 0 as no keys are pressed.

When keys are pressed, the value changes accordingly.

Here comes the strange part. If you save above program and start the emulator like this: x16emu -prg joytest -run

The function returns 255 (all keys pressed) until a key is pressed, then it returns to normal functionality.

Can someone explain why there is this difference and more importantly, how do I work around this?

Thanks in advance.

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

This behavior has been present in the emulator since the beginning. It is a scenario that's impossible with the real hardware, where you're always booting to BASIC and the user will need to hit the Enter key at least once before running anything. This flushes the joystick interface and once the program is running, it will respond to the first Start/Enter press.

  • Like 2

Share this post


Link to post
Share on other sites
  • 0
20 hours ago, SlithyMatt said:

This behavior has been present in the emulator since the beginning.

I know it has, and it has been bothering me that it is the complete opposite of normal when the emulator is started with a program and the -run option.

At long last I have managed to write som code that is able to handle both scenarios in the same way.

  1. Program is started by adding the -prg and -run arguments when starting the emulator
  2. Program is started by typing RUN in BASIC

If anyone else have trouble with this, I have a code example here:

https://github.com/JimmyDansbo/cx16stuff/blob/master/wait_joy.asm

NOTE - the JOY basic command returns 0 when no buttons are pressed, but joystick_get returns $FF when no buttons are pressed.

Share this post


Link to post
Share on other sites
  • 0
On 10/9/2020 at 6:45 PM, SlithyMatt said:

It is a scenario that's impossible with the real hardware, where you're always booting to BASIC and the user will need to hit the Enter key at least once before running anything.

So there won't be any kind of autostart feature that loads a certain program from the sdcard directly on boot?
I thought there would be...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Please review our Terms of Use