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
479 stars 56 forks source link

[FR] Add Paddle Support (Pot[A,B]X, Pot[A,B]Y #148

Open aut0mat3d opened 3 years ago

aut0mat3d commented 3 years ago

I am building a Extension Board to provide 5 Buttons and 4 analogue Axis (Paddles) via USB HID. POC works, PCB Prototypes are in Production, so this is real!

Device can be recognized via Device Descriptor iManufacturer

Bus 001 Device 028: ID 2341:8036 Arduino SA Leonardo (CDC ACM, HID) Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x2341 Arduino SA idProduct 0x8036 Leonardo (CDC ACM, HID) bcdDevice 1.00 iManufacturer 1 BMC64_IO-BOARD iProduct 2 Arduino Leonardo iSerial 3 HIDAD

The Extension Board acts like a Gamepad and provides 4 Axis and 16 Buttons Vice in BMC64 shows raw Data (-127 to 127) and Buttons 0-15

Unfortuanally Paddles in BMC64 seems not to be configured or implemented. With the unique Device Descriptor it would be possible to implement Paddles without affecting the 4 built in USB Gamepads

randyrossi commented 3 years ago

If the device is being recognized and is reporting the raw data, then we would have to add some way for the user to specify that they want the 4 axis to be used as POTX and POTY inputs rather than being used a directional controls like they are now. I already have POTX and POTY handlers for 2nd joystick buttons so it shouldn't be too difficult to hook this in. Some UI work and a bit of logic to route the values into POTX/POTY. I can probably try out a prototype implementation. I'll update this bug if I run into any issues.

randyrossi commented 3 years ago

I implemented this today. Go to usb gamepad config and there is a new choice for USB Directions called 'Hat+POTX/Y Paddles' This old 'First Hat' choice was renamed to 'Hat+POTX/Y Buttons'. If you specify paddles, then the X/Y axes values will turn into POTX/Y values in registers 54297 and 54298. I didn't test with games but I ran a quick test with my gamepad and the values 0-255 were showing up for the x/y axes changes.

The UI does not prevent you from configuring more than one gamepad this way or configuring another game pad to use POTX/Y as buttons. So if something conflicts, the last one wins.

master kernel with this change is here: https://accentual.com/bmc64/downloads/master/

aut0mat3d commented 3 years ago

Thanks you Randy. Will give it a try the next days and give Feedback!

randyrossi notifications@github.com schrieb am Mo., 1. Feb. 2021, 20:44:

I implemented this today. Go to usb gamepad config and there is a new choice for USB Directions called 'Hat+POTX/Y Paddles' This old 'First Hat' choice was renamed to 'Hat+POTX/Y Buttons'. If you specify paddles, then the X/Y axes values will turn into POTX/Y values in registers 54297 and

  1. I didn't test with games but I ran a quick test with my gamepad and the values 0-255 were showing up for the x/y axes changes.

The UI does not prevent you from configuring more than one gamepad this way or configuring another game pad to use POTX/Y as buttons. So if something conflicts, the last one wins.

master kernel with this change is here: https://accentual.com/bmc64/downloads/master/

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/randyrossi/bmc64/issues/148#issuecomment-771109948, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDFHEU27C5OH7M5XK2O4RDS44AAXANCNFSM4UUR4HRQ .

aut0mat3d commented 3 years ago

Tested today with a (PS3 Clone) Gamepad: 4 Axis, all fine in raw (0-255), working when used as analogue Joystick Axis 0 and 1 choosen for Paddle

As you mentioned "first Catch first win" for other configured input Devices i tried to: disable Port1 and2 configure USB Gamepad 1 as Port 1 with no luck

Unfortuanally all Paddles (used joytester.crt from Forum64 User Zipcom) are recognized as turned ~25% left (no values, only visual). Arkanoid is not working too, Paddle also is steered to the left and not moveable.

I checked https://www.c64-wiki.com/wiki/Paddle and tried to read the Registers in Basic:

1 REM This program views the X/Y-values of the paddles. (Control-Port1) 10 POKE 56322, 224 :REM Keyboard deactivated 20 PRINT "Paddle port1 X-value =" ; PEEK(54297) :REM read value X 30 PRINT "Paddle port1 Y-value =" ; PEEK(54298) :REM read value Y 40 POKE 56322, 255 :REM Keyboard activated

Which also gives me static Data What makes me wonder is that no Paddle Value gets updated in Arkanoid/joytester.crt when movin Axes. I can only guess that Register 56320 needs some Handling due to Multiplexing in SID (we have 4 Axis in total), but that would not explain that no Data in Registers 54297 and 54298 is changed when peeked

randyrossi commented 3 years ago

I discovered some things.

  1. For some reason, the paddle values are not being updated unless you first configure the USB gamepad to 1351 MOUSE, then back to gamepad. I'm not sure why this is. It must be initializing something required for pot x/y input so I will find out why and fix it. So in the build you currently have, try doing this and your test program should start getting values. I must have done this by accident and that's why it worked for me. But this is a general bug I think in BMC64.

  2. For Arkanoid, after doing 1 above, you can move the paddle but for some reason, only while you hold the down direction on the hat. Down appears to be 'fire' from the C64's perspective. I'm not sure if this is the way it is supposed to be or something else is wrong with emulation. Was it the case that you had to hold down the paddle button during this game or your paddle would not move? Was that a 'feature' to control it better? And why is down = fire and not fire? I will try other paddle games and see if I get the same behaviour.

  3. VICE didn't have support for paddles so I had to add it myself. They don't seem to support the multiplexing from 56320 (at least not with joysticks). I'll try to get that to work but for now we may have to live with one paddle 'pair' emulation.

  4. I might add some sort of smoothing algorithm so the inputs aren't as jittery. Also, having some control over the range (like 135 degrees vs 90 degrees) in the options will be useful.

randyrossi commented 3 years ago

I just uploaded another master build to https://accentual.com/bmc64/downloads/master with some changes.

I tested this with a game called StarLords and was able to control 4 players with 'paddles'. So the multiplexing seems to work with my latest changes. Also tested Arkanoid and it worked without having to hold down any buttons.

I found that if you restore a snapshot image, the potx/poty polling gets turned off for some reason. So if you are loading a snapshot, you will have to use a workaround by temporarily setting the control port to MOUSE and then back to gamepad. I will try to find a solution but it appears to only be an issue with loading snapshots.

randyrossi commented 3 years ago

I think this is working in 3.7. Closing.