As mentioned in https://github.com/libretro/reicast-emulator/commit/55b25a4208c453bb5b28cdce634d464c25fb646f, naomi controls are only partially working.
I think i got the general idea of what is wrong.
This is how we handle naomi inputs in reicast :
https://github.com/libretro/reicast-emulator/blob/master/core/hw/maple/maple_devs.cpp#L1136-L1161
This is extremely similar to how mame is handling dreamcast controls :
https://github.com/mamedev/mame/blob/master/src/mame/drivers/dccons.cpp#L428-L459
But mame is actually handling naomi controls differently, see this :
https://github.com/mamedev/mame/blob/master/src/mame/drivers/naomi.cpp#L2038-L2064
My guess is that the naomi controls in reicast are based on how the dreamcast controls work, but we actually need to figure out how to port the lines from naomi.cpp in the link above to reicast.
Ok, i did a few interesting discoveries :
ADDFEAT(1, 2, 12, 0); //Feat 1=Digital Inputs. 2 Players. 10 bits
ADDFEAT(2, 2, 0, 0); //Feat 2=Coin inputs. 2 Inputs
ADDFEAT(3, 2, 0, 0); //Feat 3=Analog. 2 Chans
ADDFEAT(0, 0, 0, 0); //End of list
by
ADDFEAT(1, 2, 13, 0); //Feat 1=Digital Inputs. 2 Players. 10 bits
ADDFEAT(2, 2, 0, 0); //Feat 2=Coin inputs. 2 Inputs
ADDFEAT(3, 8, 16, 0); //Feat 3=Analog. 2 Chans
ADDFEAT(12, 6, 0, 0); //End of list
Source :
https://github.com/mamedev/mame/blob/927623bb1811e029ff8666d8db447f2d9dbed6ae/src/mame/machine/jvs13551.cpp#L105-L118
This is probably necessary to get working analogs, and perhaps fix other input issues
~kcode[1] doesn't contain a valid content when running GG XX Accent Core, Akatsuki, ... It is supposed to be filed by the libretro frontend, so i guess the issue with P2 not working in some games could be related to a frontend issue. Add the following code if (keycode2&NAOMI_START_KEY) printf("TEST !!!!!!!!!!!!!!!!!!!!!!\n");
after
https://github.com/libretro/reicast-emulator/blob/9170ed26130ad16bf83667c7d3e0300c50f70998/core/hw/maple/maple_devs.cpp#L1018-L1020
And you'll understand what i mean.
AFAIK the following code is never called for P2 controls with those games :
https://github.com/libretro/reicast-emulator/blob/85553efec4c34dfdc4ab76c48cff6c068350494d/core/hw/maple/maple_devs.cpp#L1014
So inputs aren't polled for P2 controls in libretro.cpp, and ~kcode[1] is left empty.
Could be related to the following code being wrong for those games :
https://github.com/libretro/reicast-emulator/blob/85553efec4c34dfdc4ab76c48cff6c068350494d/core/hw/maple/maple_cfg.cpp#L96
The 2nd player issue should be fixed with https://github.com/libretro/reicast-emulator/pull/121. I still need to implement analogs.
Also, i'm 99% sure analogs go in there :
https://github.com/libretro/reicast-emulator/blob/85553efec4c34dfdc4ab76c48cff6c068350494d/core/hw/maple/maple_devs.cpp#L1221-L1228
Not exactly sure "how" though, and the changes to the ADD_FEAT calls i mentioned above are most likely necessary too (those calls are some kind of setup for the jamma I/O board if i understood well).
@twinaphex This is just crazy how bad i'm with bitwise arythmetics and type conversion, tell me how i can convert a signed char ( -127 to 128) to an unsigned short (0 to 65536) properly, and analog controls will be fixed 5 minutes later.
Would that work? -127 -> 0 and 128 -> 65280
char c;
u16 u = (c + 127) << 8;
@flyinghead i opened a PR, controls finaly working in monkey ball, feel free to rewrite the lines i mention in the PR properly (i did it "the way i understand").
u16 u = (c + 127) << 8;
@flyinghead Nope, that's one of the things i tried, it doesn't work properly (extreme left analog would move right).
Then you could try:
char c;
u16 u = (127 - c) << 8;
converts: -128 to 65280, 0 to 32512 and 127 to 0
Or:
u16 u = 32767 − (c * 256);
converts: -128 to 65535, 0 to 32767 and 127 to 255
@flyinghead u16 u = 32767 − (c * 256); is basically what i did, so i guess it's fine.
It's all good then.
For future reference about 4P mode : https://www.solvalou.com/arcade_naomicapcom.php
Basically, the second Jamma I/O board will be useless for most (all ?) games, we need to emulate a Capcom Naomi I/O board for this, and AFAIK, there is no emulator who knows how to do that (didn't find anything in MAME).