randyrossi / bmc64

A bare metal Commodore 64 emulator for the Raspberry Pi with true 50hz/60hz smooth scrolling, low input latency and better audio/video sync.
GNU General Public License v3.0
473 stars 56 forks source link

[FR] GPIO Configuration for four Joysticks #190

Open asdfjkl opened 2 years ago

asdfjkl commented 2 years ago

First: BMC64 is awesome!

I would like to use it to play MULE with four players. VICE can emulate a four-player adapter. In order to reduce latency, I would like to wire four (old) C64 joysticks via the GPIO ports directly. Current default GPIO configs only wire two joysticks.

Is this even possible, i.e. assign two joysticks via GPIO ports to the normal joystick ports and two other joysticks via GPIO ports to the virtual four-player user port adapter? I am somewhat lost w.t.t. configuration... The 26 GPIO pins should be enough to write four joysticks plus rudimentary menu navigation (up, down, left, right + fire). Or just four joysticks + usb keyboard.

randyrossi commented 2 years ago

There is extra joystick support but it only works with USB right now. I suppose it would be possible to use another 10 GPIOs and route them to the extra joysticks but that's would take some code changes. I think the difference between GPIO and USB is only at most 1 frame anyway.

On Sun, Sep 5, 2021 at 3:43 PM Dominik Klein @.***> wrote:

First: BMC64 is awesome!

I would like to use it to play MULE with four players. VICE can emulate a four-player adapter. In order to reduce latency, I would like to wire four (old) C64 joysticks via the GPIO ports directly. Current default GPIO configs only wire two joysticks.

Is this even possible, i.e. assign two joysticks via GPIO ports to the normal joystick ports and two other joysticks via GPIO ports to the virtual four-player user port adapter? I am somewhat lost w.t.t. configuration...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/randyrossi/bmc64/issues/190, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI3HKGTPP5GQZME26D3GELUAPB4LANCNFSM5DPD5Z2A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Randy Rossi

asdfjkl commented 2 years ago

Do you have any hint where I might start to read/understand the code/what would need to be done? I might give it a try, not sure if I will succeed.

Thing is that delay adds up. 15ms for the controller, two frames (=40ms) by bmc (which is actually quite awesome, but still), then another 40ms by my TV in game mode... anything over 30ms is noticeable imho....

randyrossi commented 2 years ago

In menu_gpio.c, you would have to add more entries for all the directions + fire with ports 3 & 4 specified as the 2nd arg. NUM_GPIO_BINDINGS would have to increase by 5 to make room.

You would also need to add two more JOYDEV_ constants for JOYDEV_GPIO_2 & JOYDEV_GPIO_3 (appended to the end)

Then allow those to be selected in add_joyport_options (num_choices increases by 2)

Then in kernel.cpp, ReadCustomGPIO logic would have to change because now bank can be 2 or 3 as well as 0 or 1. So that code to find out which device the pin belongs to would get a bit more complicated. That code assumes there's only 2 possible gpio joysticks so it would need some refactoring to handle two more.

On Tue, Sep 28, 2021 at 10:43 AM Dominik Klein @.***> wrote:

Do you have any hint where I might start to read/understand the code/what would need to be done? I might give it a try, not sure if I will succeed.

Thing is that delay adds up. 15ms for the controller, two frames (=40ms) by bmc (which is actually quite awesome, but still), then another 40ms by my TV in game mode... anything over 30ms is noticeable imho....

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/randyrossi/bmc64/issues/190#issuecomment-929298027, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI3HKGHT2HG3DROA3DM6DTUEHH7XANCNFSM5DPD5Z2A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Randy Rossi

SDMatt2020 commented 2 years ago

@asdfjkl It would be game dependent, but what if you wired up a joystick into the GPIO header and matched the input of the keyboard matrix? For MULE, this would map the player 3 and 4 keyboard commands into the appropriate keyboard equivalents.