Vegz78 / McAirpos

MakeCode Arcade games in RetroPie, Recalbox 7/8 and Batocera, running natively as ELF executables on Raspberry Pi OS/Linux ARM with 1-2 gamepads
https://Vegz78.github.io/McAirpos
MIT License
80 stars 10 forks source link

[Picade] Button mapping(working with manual /sd/arcade.cfg edit and nomap option) #22

Closed rdmueller closed 2 years ago

rdmueller commented 2 years ago

thanx for this great tool! I try to get my games up and running on a picade and retroflag GPi case.

So far, I go with the picade, since I get the games at least up and running. I see the start screen with animations and hear sound.

But my input will not work. Not a single button.

What I've done so far:

used evtest to find out which scan codes I need:

evtest
No device specified, trying to scan all of /dev/input/event*
Not running as root, no devices may be available.
Available devices:
/dev/input/event0:      gpio_keys
Select the device event number [0-0]: 0
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio_keys"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 1 (KEY_ESC)
    Event code 23 (KEY_I)
    Event code 24 (KEY_O)
    Event code 28 (KEY_ENTER)
    Event code 29 (KEY_LEFTCTRL)
    Event code 42 (KEY_LEFTSHIFT)
    Event code 44 (KEY_Z)
    Event code 45 (KEY_X)
    Event code 56 (KEY_LEFTALT)

    Event code 57 (KEY_SPACE)

    Event code 103 (KEY_UP)

    Event code 105 (KEY_LEFT)
    Event code 106 (KEY_RIGHT)
    Event code 108 (KEY_DOWN)
    Event code 116 (KEY_POWER)

configures my /sd/arcade.cfg according to this map:

SCAN_CODES=/dev/input/event0
BTN_LEFT=105
BTN_RIGHT=106
BTN_UP=103
BTN_DOWN=108
BTN_A=29
BTN_B=56
BTN_LEFT2=0
BTN_RIGHT2=0
BTN_UP2=0
BTN_DOWN2=0
BTN_A2=0
BTN_B2=0
BTN_RESET=28
BTN_EXIT=1
BTN_MENU=23

use the nomap option to start the games. Still, nothing happends. Any Idea?

/home/pi/McAirpos/McAirpos/uinput-mapper/input-read -v -p /dev/input/event0
Input: 0 Type: EV_KEY
     KEY_ESC  → ([0, EV_KEY], KEY_ESC)
     KEY_UP  → ([0, EV_KEY], KEY_UP)
     KEY_LEFT  → ([0, EV_KEY], KEY_LEFT)
     KEY_LEFTSHIFT  → ([0, EV_KEY], KEY_LEFTSHIFT)

SCAN_CODES=/dev/input/event0
     KEY_Z  → ([0, EV_KEY], KEY_Z)

     KEY_X  → ([0, EV_KEY], KEY_X)
     KEY_LEFTALT  → ([0, EV_KEY], KEY_LEFTALT)
     KEY_POWER  → ([0, EV_KEY], KEY_POWER)
     KEY_RIGHT  → ([0, EV_KEY], KEY_RIGHT)
     KEY_DOWN  → ([0, EV_KEY], KEY_DOWN)
     KEY_I  → ([0, EV_KEY], KEY_I)
     KEY_O  → ([0, EV_KEY], KEY_O)
     KEY_SPACE  → ([0, EV_KEY], KEY_SPACE)
     KEY_ENTER  → ([0, EV_KEY], KEY_ENTER)
     KEY_LEFTCTRL  → ([0, EV_KEY], KEY_LEFTCTRL)

and here are the logs (/tmp/McAirpos.log):

nomap argument detected,
launCharc starting /home/pi/RetroPie/roms/makecode/arcade-Brick-Breaker2.elf with no automatic gamepad mappings...
[-1607608811] GC block 16376b @ 0x20000000
[       0] runtime starting, pid=31899...
[      17] FB: BCM2708 FB at 640x480 640x960 bpp=32
[      31] FB: BCM2708 FB at 640x480 640x960 bpp=32 2560
[      49] init keys
[      49] read config: /sd/arcade.cfg
[      97] SCAN_CODES=/dev/input/event0
[     113] BTN_LEFT=105
[     128] BTN_RIGHT=106
[     143] BTN_UP=103
[     158] BTN_DOWN=108
[     174] BTN_A=29
[     202] BTN_B=56
[     217] BTN_LEFT2=0
[     232] BTN_RIGHT2=0
[     248] BTN_UP2=0
[     263] BTN_DOWN2=0
[     278] BTN_A2=0
[     293] BTN_B2=0
[     309] BTN_RESET=28
[     324] BTN_EXIT=1
[     339] BTN_MENU=23
[     355] config done
[     370] sx=4 sy=4 ox=0 oy=0 32=1
[     385] fbuf=0x76235000 sz:1228800
[     403] loop
[     424] GC block 16376b @ 0x20004000
[    1316] PCM name: 'default'
[    1333] PCM state: PREPARED
Vegz78 commented 2 years ago

Hi @rdmueller,

Thank you for trying out McAirpos and I really appreciate your thorough troubleshooting and the documentation you provide with your initial issue here!

As a sidenote, I am also really happy to get the chance to figure out and test together with you what I hope will be a working solution for both the Picade and the RetroFlag GPi case, which I know are popular retro games devices, which I don't own myself and I have not yet been able to test, and for a while have been looking for help with: https://forum.makecode.com/t/gamepi20-joy-bonnet-picade-collaboration/9211

Sadly, I don't immideately see what the problem might be and I hope that we, with some patience, can methodically figure it out together. Please bear with me if my follow-up questions to come seem rather basic. ;-)

From what I can gather from the information you provided above, your picade controller interface is gpio on /dev/event0 and with only EV_KEY type inputs, which makes it seem to be the right approach to save processing power and run the games without uinput-mapper using the nomap option and by manual configuration of the /sd/arcade.cfg.

  1. Just to be absolutely sure, when running evtest /dev/input/event0, you also verified from inside evtest, that you got keypress confirmation on the screen(you are absolutely sure that the picade controller input is (always) on /dev/input/event0)?
  2. The Picade seems to only have one input. Could it be worth a try to delete the second set of buttons(BTN_LEFT2 etc.) from /sd/arcade.cfg instead of setting them to =0?
  3. Since I don't have any controll over eventual breaking changes from the MakeCode Arcade's RPi compiler side, could you please (trust me enough to)run an earlier compiled .elf(zipped) MCA button testing program which I have verified to work on my machine?(Don't remember where I got it, but it was compiled in January and I just tested it with McAirpos): arcade-RUN.zip
  4. What RPi version do you have and what OS(stretch, buster - uname -a), what RetroPie/Recalbox version?
  5. Could you please try running directly from the Linux console(no RetroPie/Recalbox or (console emulator in)X sessions running)?
  6. Are you absolutely sure that the MCA games folder and contents has the proper 755 permissions to allow the games' .data folders to be written?: https://github.com/Vegz78/McAirpos#Usage

Please also send me the (zipped) arcade-Brick-Breaker2.elf and link to its MCA source code, that I can try from my side, if possible.

Hope to hear back from you again soon!

rdmueller commented 2 years ago

...your picade controller interface is gpio on /dev/event0

/dev/input/event0

  1. yes, I get keypress events when I run evtest
  2. done. no change
  3. I think I already got the arcade-RUN.elf. It runs and shows a box "TEST1", but it does not react on keyboard events in my configuration
  4. Versions are quite old, but as I do understand, this shouldn't matter... :-) Pi 2 Model B v1.1, Emulationstation V2.9.3RP
    pi@retropie:~ $ uname -a
    Linux retropie 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux
  5. already did for tests, with and without sudo. Same results: I see the animated screen, but no keyboard events processed. but I get the following warnings:
    warn: ioctl KDSETMODE failed: Inappropriate ioctl for device
    warn: ioctl KDSETMODE failed: Inappropriate ioctl for device
  6. yes. .data gets written:
    pi@retropie:~/RetroPie/roms/makecode $ ls arcade-RUN.elf.data/
    _23run  _23scope

the brick-breaker source can be found here: https://github.com/rdmueller/brick-breaker nothing special. I guess we should stay with arcade-RUN for our tests.

I just had a little success: I plugged in my dongle for an external keyboard to check if the game will handle those events. I plugged it in while running and to my surprise, the joystick started to work (I guess /dev/input/event0 = joystick, /dev/input/event[1/2] = external keyboard)

I then rebooted the system. The external keyboard then gets mapped to /dev/input/event[0/1] and the joystick to /dev/input/event2. Now, the external keyboard is accepted as input and the joystick is dead again.

I started my experiments with a connected external keyboard, but noticed that the joystick will be mapped to event2 and the config always falls back to event0 (why?). So I removed the keyboard for further tests.

rdmueller commented 2 years ago

don't ask me what happened. It seems that it now runs quite well. Maybe step two (removal of second controller from cfg) was the right move. It also seems that the first key-event gets lost, but then everything is fine. I will test some more games

Vegz78 commented 2 years ago

don't ask me what happened. It seems that it now runs quite well.

Hehe, certainly don't ask me!... ;-) But I am glad to hear that it seems to work now and thanks for the feedback!

Maybe step two (removal of second controller from cfg) was the right move.

From what you wrote earlier, my suspects would be either:

  1. That the controller changes /dev/input/eventX number different from 0 which is hijacked by the keyboard every time you boot with a keyboard connected(That shouldn't be a problem normally, as I assume you don't use the keyboard much with the Picade, and I personally would recommend ssh'ing into the RetroPie devices, apart from when you need to test launCharc manually from the Linux console), or
  2. Maybe removing the unused buttons had an effect.

Sometimes, deleting a game's .data folder fixes different things for me, but that is on per game basis, not systemwide.

It also seems that the first key-event gets lost, but then everything is fine.

Hmm, I haven't noticed, but I will check it out. Hard to imagine that this is something I can fix in the source code, since the game more or less runs directly when running with the nomap option. Then again, I might have kludged with the two threads in my code. Have you tried running a game directly without launCharc(exit with some combinations of CTRL+\, CTRL+d and CTRL+c) and checked if you experience the same first button press delay?

I will test some more games

Great! Looking forward to hearing back from you with your results, and don't hesitate to get in touch again if something isn't working. I would also appreciate seeing a similar issue with a working solution shared for the Retroflag GPi.

Am I correct to assume that your working /sd/arcade.cfg for the Picade now looks like this?:

SCAN_CODES=/dev/input/event0
BTN_LEFT=105
BTN_RIGHT=106
BTN_UP=103
BTN_DOWN=108
BTN_A=29
BTN_B=56
BTN_RESET=28
BTN_EXIT=1
BTN_MENU=23
rdmueller commented 2 years ago

yes, this /sd/arcade.cfg is the one I currently use.

rdmueller commented 2 years ago

I will send a PR to document these settings in you readme - hope this is ok

rdmueller commented 2 years ago

I just checked the issue with the first keyboard event. Even if I launch games without your launcher, the first event will not be processed.

Over all, I am quite happy with this solution. I only found one game where the .lef file results in a segmentation fault, but this is due to the game and not the launcher.

I tried to document the knowledge from this issue in PR #23 . So I will close this issue now and try to setup my Retroflag GPi.

Vegz78 commented 2 years ago

I just checked the issue with the first keyboard event. Even if I launch games without your launcher, the first event will not be processed.

Thanks for checking and concluding that this is a MakeCode Arcade isssue.

Over all, I am quite happy with this solution.

👍

I only found one game where the .elf file results in a segmentation fault, but this is due to the game and not the launcher.

There exists a few incompatibilities in MakeCode Arcade between the web simulator and the variuos compilations to different hardware, e.g.: -https://github.com/Vegz78/McAirpos/issues/12 -https://github.com/Vegz78/McAirpos/issues/14 -https://forum.makecode.com/t/raspberry-pi-gpio-output/2492 -etc.

I tried to document the knowledge from this issue in PR #23 . So I will close this issue now and try to setup my Retroflag GPi.

Great summary, but for consistency I would prefer if you could add your summary here to the end of this issue, according to earlier practice, instead of adding more text to the main readme.md.

Looking forward to seeing how it worked with your Retroflag GPi!

rdmueller commented 2 years ago

Conclusion

Button mapping for Picade

The standard setup for Picade is RetroPie. So, if you follow the setup for RetroPie on your Picade, you will be able to launch the makecode games. To also play them, you still have to fix the button mapping: copy the following content to your /sd/arcade.cfg

SCAN_CODES=/dev/input/event0
BTN_LEFT=105
BTN_RIGHT=106
BTN_UP=103
BTN_DOWN=108
BTN_A=29
BTN_B=56
BTN_RESET=28
BTN_EXIT=1
BTN_MENU=23

This should work fine as long as no other keyboard is attached to the system. If an additional keyboard is attached, /dev/input/event0/ might change to another /dev/input/eventX. To activate this config, we have to tell the launcher not to use the uiinput-mapper and fall back to this config instead. Open /etc/emulationstation/es_systems.cfg and replace the line

    <command>/home/pi/McAirpos/McAirpos/launCharc/launCharc %ROM%</command>

with

    <command>/home/pi/McAirpos/McAirpos/launCharc/launCharc nomap %ROM%</command>

You are now able to run and play makecode games with McAirpos on your Retropie. Hint: for some reasons, the first keyboard event will not be processed.

Vegz78 commented 2 years ago

In adittion, I have added the arcade.cfg file for the Picade here: https://github.com/Vegz78/McAirpos/blob/master/McAirpos/MakeCode/sd/tested_ok/arcade.cfg_Picade

Vegz78 commented 2 years ago

Conclusion

... You are now able to run and play makecode games with McAirpos on your Retropie.

Thanks again, @rdmueller! image https://forum.makecode.com/t/gamepi20-joy-bonnet-picade-collaboration/9211/4