cebix / macemu

Basilisk II and SheepShaver Macintosh emulators
1.39k stars 289 forks source link

USB Joystick support? #142

Open Danfun64 opened 6 years ago

Danfun64 commented 6 years ago

I don't understand why, but Basilisk II and Sheepshaver have never supported USB Joysticks, or more importantly Analog Joysticks. I've been curious as to whether such support will be added in ever. Anybody have any info on that front?

rickyzhang82 commented 6 years ago

You know why. Because people who can program have no interest to implement this, while people who want this feature but have no expertise to do this (I'm not implying or referring you in either category)

In any case, you can think about how to implement this by reading networking in BII. It is a good learning path.

DMJC commented 4 years ago

How hard is it to implement an ADB device emulator? There were ADB joysticks back in the 1990s. Surely it'd be possible to map the values from say a linux /dev/js device to a virtual ADB device? Would it be easier to load the Thrustmaster drivers for macOS and then map the values from the host OS, or would you implement a driver from scratch as well as the Host OS Mapping?

MaddTheSane commented 4 years ago

Or USB pass-thru. Although that would be limited to Mac OS 8.1 or later and PowerPC.

lovrenco commented 2 years ago

This would be good option to have. For example, WinUAE (Amiga emulator) has this option. Strange that main Mac 060/PPC emulators do not have it.

DMJC commented 2 years ago

I found some developer documentation on ADB devices: https://developer.apple.com/library/archive/technotes/hw/hw_01.html#Extended Based on this I suspect that a joystick is either going to present itself as either a mouse, or a miscellaneous device. Based on models of joystick I've found, it's likely the quickest thing to implement would be a 4-5 button joystick with X/Y axis and 5 buttons (e.g a CH Mouse Stick II), that identifies itself to the OS as a mouse, but map joystick inputs to it. There is a three-axis joystick I've found called a Gravis Mac Blackhawk. It has 4 buttons and a scroll wheel in addition to X/Y axes. It also has custom drivers. I suspect it appears to the OS as 2 mice and then the drivers do some magic to make it a coherent device.

DMJC commented 2 years ago

I also found this super useful website (you will want to translate from French.) In it the author talks about multiple ADB devices. https://www-journaldulapin-com.translate.goog/2020/04/06/gravis-joystick-ii/?_x_tr_sl=fr&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp Most joysticks are just presented to the OS as Keyboard/Mouse devices. I suggest implementing a selection menu where you can select which device ID to present to the OS, have the Gravis Mouse stick 1 and 2 as options, as well as a gravis gamepad and Microsoft Sidewinder 3D Pro. These devices should all act as mouse/keyboard emulators and are simple to implement, simply add a system for binding joystick buttons and axes to keyboard buttons/mouse axes in Basilisk/Sheepshaver. He also has documentation on the Thrustmaster FCS system. I suspect this is a lot harder to implement as it has it's own protocol it talks in: https://www-journaldulapin-com.translate.goog/2020/03/19/joystick-adb/?_x_tr_sl=fr&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp

rickyzhang82 commented 2 years ago

First, forget about USB passthrough. It is not how BII works to handle HID.

Secondly, the way it works in BII is that you trigger an event in the host and then BII translate that event into the event in the guest OS. Take SDL2 as an example (see here), SDL2 intercept your joystick's event in your host OS and then translate into ADB event in the guest OS.

It should be an easy fix. For sure, you should read the mapping from the table storing form an external file just like the way the existing keyboard code does.

Hope this helps.

DMJC commented 2 years ago

It helped a lot, I've started to code up some support for it. I am also reaching out to people to try to get some Apple device ID's sadly lsadb on Linux hasn't got any id's other than keyboards/mice, but I've reached out to some people both online and irl who might be able to help me get some. I've already implemented most of the event handler code, luckily I've used libSDL for joystick handling before so it's been pretty straightforward. Once I have something useful I'll do a pull request.

DMJC commented 2 years ago

Quick update, I got this working, my joystick is pretending to be a mouse, but in Super Wing Commander it's working in joystick mode. Looks like ADB Joysticks are probably just Extended mouse devices. I haven't got multi-button working yet, but it'll happen soon.

rickyzhang82 commented 2 years ago

Sweet. Do show a demo in a screencast. Don't forget to send a PR. Have a good weekend!

DMJC commented 2 years ago

I've just been able to make my joystick code resolution independent. This means the joystick will behave correctly at 640x480, 1024x768 or any other resolution in between. This is an important part of the code. I am now moving on to focus on getting more buttons than the first Button working. I will update progress in this thread until I do the pull request itself. The code is quite simple and easy to debug. Currently I am just binding the first joystick automatically, however I have two USB joysticks here so I might tinker with having the used device be selectable via the GUI.

DMJC commented 2 years ago

My Gravis Mousestick II just arrived! I've got a friend loaning me a G3 Power Mac soon. I'm going to sniff the ADB id and see if I can make an identical device appear in Basilisk 2.

catdogmat commented 7 months ago

Hi @DMJC! I was just wondering if you ever finished this? I would love for it to be added so I can put sheepshaver on my arcade machine.

DMJC commented 7 months ago

I wasn't able to get more than one button to work on it, but I did get a joystick mapped with SDL and working like a mac joystick. Happy to provide code when I'm home a bit later.

On Fri, 1 Mar 2024, 2:28 pm Finn, @.***> wrote:

Hi @DMJC https://github.com/DMJC! I was just wondering if you ever finished this? I would love for it to be added so I can put sheepshaver on my arcade machine.

— Reply to this email directly, view it on GitHub https://github.com/cebix/macemu/issues/142#issuecomment-1972464249, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFS2Y6L4Z5TL6PWYM4R7B3YV74FZAVCNFSM4EDKHCV2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJXGI2DMNBSGQ4Q . You are receiving this because you were mentioned.Message ID: @.***>

catdogmat commented 7 months ago

Alright, that would be great! Thanks.