New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Naomi) Controls investigation #115

Closed
barbudreadmon opened this Issue Jul 3, 2018 · 12 comments

Comments

Projects
None yet
2 participants
@barbudreadmon

barbudreadmon commented Jul 3, 2018

As mentioned in 55b25a4, 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.

@barbudreadmon

This comment has been minimized.

Show comment
Hide comment
@barbudreadmon

barbudreadmon Jul 3, 2018

Ok, i did a few interesting discoveries :

  • i was wrong, i compared and our code is equivalent
  • i think we need to replace

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

  • For whatever reason ~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

u32 keycode = ~kcode[0];
u32 keycode2 = ~kcode[1];

And you'll understand what i mean.

barbudreadmon commented Jul 3, 2018

Ok, i did a few interesting discoveries :

  • i was wrong, i compared and our code is equivalent
  • i think we need to replace

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

  • For whatever reason ~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

u32 keycode = ~kcode[0];
u32 keycode2 = ~kcode[1];

And you'll understand what i mean.

@barbudreadmon

This comment has been minimized.

Show comment
Hide comment
@barbudreadmon

barbudreadmon Jul 4, 2018

AFAIK the following code is never called for P2 controls with those games :

config->GetInput(&pjs);

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 :
mcfg_Create(MDT_NaomiJamma, 1, 5);

barbudreadmon commented Jul 4, 2018

AFAIK the following code is never called for P2 controls with those games :

config->GetInput(&pjs);

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 :
mcfg_Create(MDT_NaomiJamma, 1, 5);

@barbudreadmon

This comment has been minimized.

Show comment
Hide comment
@barbudreadmon

barbudreadmon Jul 4, 2018

The 2nd player issue should be fixed with #121. I still need to implement analogs.

barbudreadmon commented Jul 4, 2018

The 2nd player issue should be fixed with #121. I still need to implement analogs.

@barbudreadmon

This comment has been minimized.

Show comment
Hide comment
@barbudreadmon

barbudreadmon Jul 4, 2018

Also, i'm 99% sure analogs go in there :

buffer_out_b[8 + 0x12 + 12] = 0x00;
buffer_out_b[8 + 0x12 + 13] = 0x00;
buffer_out_b[8 + 0x12 + 14] = 0x00;
buffer_out_b[8 + 0x12 + 15] = 0x00;
buffer_out_b[8 + 0x12 + 16] = 0x00;
buffer_out_b[8 + 0x12 + 17] = 0x00;
buffer_out_b[8 + 0x12 + 18] = 0x00;
buffer_out_b[8 + 0x12 + 19] = 0x00;

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).

barbudreadmon commented Jul 4, 2018

Also, i'm 99% sure analogs go in there :

buffer_out_b[8 + 0x12 + 12] = 0x00;
buffer_out_b[8 + 0x12 + 13] = 0x00;
buffer_out_b[8 + 0x12 + 14] = 0x00;
buffer_out_b[8 + 0x12 + 15] = 0x00;
buffer_out_b[8 + 0x12 + 16] = 0x00;
buffer_out_b[8 + 0x12 + 17] = 0x00;
buffer_out_b[8 + 0x12 + 18] = 0x00;
buffer_out_b[8 + 0x12 + 19] = 0x00;

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).

@barbudreadmon

This comment has been minimized.

Show comment
Hide comment
@barbudreadmon

barbudreadmon Jul 5, 2018

@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.

barbudreadmon commented Jul 5, 2018

@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.

@flyinghead

This comment has been minimized.

Show comment
Hide comment
@flyinghead

flyinghead Jul 5, 2018

Collaborator

Would that work? -127 -> 0 and 128 -> 65280

char c;
u16 u = (c + 127) << 8;
Collaborator

flyinghead commented Jul 5, 2018

Would that work? -127 -> 0 and 128 -> 65280

char c;
u16 u = (c + 127) << 8;
@barbudreadmon

This comment has been minimized.

Show comment
Hide comment
@barbudreadmon

barbudreadmon Jul 5, 2018

@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").

barbudreadmon commented Jul 5, 2018

@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").

@barbudreadmon

This comment has been minimized.

Show comment
Hide comment
@barbudreadmon

barbudreadmon Jul 5, 2018

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).

barbudreadmon commented Jul 5, 2018

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).

@flyinghead

This comment has been minimized.

Show comment
Hide comment
@flyinghead

flyinghead Jul 5, 2018

Collaborator

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

Collaborator

flyinghead commented Jul 5, 2018

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

@barbudreadmon

This comment has been minimized.

Show comment
Hide comment
@barbudreadmon

barbudreadmon Jul 5, 2018

@flyinghead u16 u = 32767 − (c * 256); is basically what i did, so i guess it's fine.

barbudreadmon commented Jul 5, 2018

@flyinghead u16 u = 32767 − (c * 256); is basically what i did, so i guess it's fine.

@flyinghead

This comment has been minimized.

Show comment
Hide comment
@flyinghead

flyinghead Jul 5, 2018

Collaborator

It's all good then.

Collaborator

flyinghead commented Jul 5, 2018

It's all good then.

@barbudreadmon

This comment has been minimized.

Show comment
Hide comment
@barbudreadmon

barbudreadmon Jul 5, 2018

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).

barbudreadmon commented Jul 5, 2018

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment