devkitSMS icon indicating copy to clipboard operation
devkitSMS copied to clipboard

SMS_readPaddle() never returns if the paddle is disconnected

Open raphnet opened this issue 4 years ago • 4 comments

When the paddle reading functions were reworked and replaced by assembly code, the return value changed from int to unsigned char. This exactly fits the range of values reported by a paddle, which is good, but then there is no longer a way to report a timeout which occurs if the user disconnects the paddle.

So I was wondering if a pull request changing the return type back to int and also implementing timeouts in the assembly code would be acceptable or not. Is it allowed (by the SMS user manual) to change controllers when the power is on anyway?

raphnet avatar Feb 11 '21 03:02 raphnet

I don't think we really need to check for this condition - I mean after all I think user is not supposed to disconnect a controller while a game is running. But I understand that SMSlib might even support that, so we could add that option under a conditional define. Let me know your opinion on that. Thanks!

sverx avatar Feb 11 '21 10:02 sverx

I thought about this again. Maybe it would be a good idea to check for timeouts after all, thus returning from the read position call even if the user disconnects the paddle... but I don't think it's worthy to report such a condition, so even just returning position as halfway for instance would be fine. What do you think about it?

sverx avatar Jan 10 '22 16:01 sverx

Yes, it would be much better! At least the music and animation won't stop. And if the return value is documented or defined, the game could optionally call SMS_detectPaddle to check if what was returned is the real position or a disconnected paddle. (I would recommend using 0x00 or 0xFF rather than halfway, since min/max seem less likely - but in the end it depends on the game of course)

In any case, once the check for timeout is added to the asm code, it will be easy to extend the code (under an ifdef) to more explicitly communicate the timeout condition by setting a bit in a global variable for instance.

raphnet avatar Jan 12 '22 10:01 raphnet

I suggested returning 'halfway' because for instance when you disconnect a pad you don't get neither left nor right pressed so you're kind of not going left nor right and I don't think disconnecting the paddle should result in an left or right end-of-range value. :thinking:

Best return value on a disconnected paddle would probably be the last value read when the pad was still connected - but this means to 'waste' one byte to cache it, which I'm unsure it's worth it.

I think for now we might simply use a define in SMSlib.h and set a specific value we like there and if someone prefers a different value they will just change it and recompile.

Some global variable for paddle status conditions could be nice, it's worth investigating about that possibility. The library already have one status byte where the TV detection routines will set bits if they detect 50 Hz or 60 Hz, but that detection is currently disabled by default (as you've probably seen). 6 bits are still unused there so we might pick one (two?) of them for paddle timeout flag(s).

sverx avatar Jan 12 '22 11:01 sverx

This has been solved by the recent update in the code. (PR #40)

sverx avatar Aug 22 '22 11:08 sverx