Page 1 of 2
Joystick_get not working for me
Posted: Mon Jun 05, 2023 12:33 am
by ch4rl3sb
Is there something I need to do to get joysticks registering with the KERNAL functions?
I'm using a PS3 controller that uses an XBOX driver working with other programs on my laptop
and I use a joystick.h include and driver to get it working on X16 (in C)...
But, that only gives me 8bits of joystick keys. I would like to have the 12 keys that the KERNAL functions access, but calling
joystick_get, doesn't give me any data.
Re: Joystick_get not working for me
Posted: Mon Jun 05, 2023 3:06 am
by DragWx
This is CC65 C code, right? Try this:
Code: Select all
static unsigned char joy1Byte1, joy1Byte2;
void getJoyBytes() {
__asm__ ("lda #$01");
__asm__ ("jsr joystick_get");
__asm__ ("sta %v", joy1Byte1);
__asm__ ("stx %v", joy1Byte2);
}
That ought to put the first two bytes of joystick 1 into joy1Byte1 and joy1Byte2.
Re: Joystick_get not working for me
Posted: Mon Jun 05, 2023 3:31 am
by ch4rl3sb
That's effectively what I did. I'll double check but I don't think it's filling my variables or thinking my joystick is there. (Y register should be zero.)
Re: Joystick_get not working for me
Posted: Mon Jun 05, 2023 4:41 pm
by desertfish
are you sure you're using the correct command line arguments to the emulator?
-joy1 to -joy4
Note that box16 auto detects joysticks.
Re: Joystick_get not working for me
Posted: Mon Jun 05, 2023 8:08 pm
by DragWx
Well, just in case, the three gotchas I can think of are:
- Set A to the joystick number before calling joystick_get, remember that A=0 means the keyboard-keys "joystick" and NOT the physical port for joystick 1, which is A=1 instead.
- If CC65 overrides the kernal's IRQ handler (which I don't think it is, if joystick.h was working before), you'd need to call joystick_scan yourself, once per frame.
- Emulator might not be detecting your joystick (which seems odd if joystick.h was working before).
Re: Joystick_get not working for me
Posted: Mon Jun 05, 2023 9:26 pm
by ch4rl3sb
joystick.h has it's own joystick functions which I've been using. But they only access the first 8 buttons.
the 4 of the D pad, select, start, and 2 others, (B and Y?). But, I would like the full SNES controller working.
The emulator doesn't recognize my joysticks with joystick_get. I'm calling the default handler, so it should be running
joystick_scan, but I've tried calling it manually as well. Nothing is working yet. I started using another driver and handler because i couldn't get it working in the first place.
Re: Joystick_get not working for me
Posted: Mon Jun 05, 2023 10:48 pm
by ch4rl3sb
And, of course, R41 and R43 no longer recognize joystick 1.
But, joystick_get doesn't even recognize stick 0, the keyboard joystick.
Re: Joystick_get not working for me
Posted: Mon Jun 05, 2023 10:53 pm
by DragWx
Try calling joystick_get with A set to an invalid value, like 3F or something. That should return a state of all FF's for all three bytes. If it doesn't, then either joystick_get isn't getting called correctly, or the contents of A, X, and Y aren't correctly going where you're trying to put them.
Re: Joystick_get not working for me
Posted: Tue Jun 06, 2023 4:00 am
by ch4rl3sb
DragWx wrote: ↑Mon Jun 05, 2023 10:53 pm
Try calling joystick_get with A set to an invalid value, like 3F or something. That should return a state of all FF's for all three bytes. If it doesn't, then either joystick_get isn't getting called correctly, or the contents of A, X, and Y aren't correctly going where you're trying to put them.
Success! But through some of the ODDEST behavior I've experienced!!!
1. I can't check if Y register is = 0. I HAVE to check != 0xff.
2. it didn't matter which joystick I was polling, and with what value, it read joystick 2 and applied it to whichever player sprite was spawned first! Weird. (Turns out, the code [ __asm__ ("lda #$01"); ] wasn't working from C for me, and A had a default value.)
Then, joystick 1 is lda #02, and joystick 2 is lda #01! don't know why. But the lights on them show that, and the other driver picked them as 1 and 2 the same as the indicator lights on the joysticks.
I spent a lot of time trying to change the value of A (from C, which wasn't working) and kept finding one player would respond to joystick2, but not the same one, and it didn't matter what the values I tried for A, (because it wasn't changing.)
It was weird, but, I've got it working now. with an assembly function and the joysticks swapped.
Re: Joystick_get not working for me
Posted: Tue Jun 06, 2023 6:08 am
by DragWx
That makes me worried that it's not actually working still. The API for joystick_get is pretty simple and clearly defined; if it's acting confusingly, then something unexpected is happening.
If you do this exact thing:
Code: Select all
__asm__ ("lda #$01");
__asm__ ("jsr joystick_get");
__asm__ ("sta %v", byte1);
...without any other C code in between, then A
should be getting set to 1, joystick_get
should be getting immediately called without any other instructions in between (and most importantly, A still set to 1), and upon return, the new contents of A (byte 1 of joystick port 1)
should be getting stored to a C variable called "byte1" (as long as it's a global unsigned char).
If that exact code does not produce that exact result, then something invisible is happening, like CC65 optimizing something it shouldn't be, CC65's CX16 library having an incompatibility with the CX16's kernal, or I've completely misunderstood something about how mixing ASM and C is supposed to work in CC65.
Of course, there could also be another problem in the code somewhere else, and I'm just getting laser-focused on this part unnecessarily.
![Razz :P](./images/smilies/icon_razz.gif)