Skip to content

Commit

Permalink
work on controller database, HID interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Dec 15, 2024
1 parent 8f77efa commit 022c8f4
Show file tree
Hide file tree
Showing 12 changed files with 20,269 additions and 1,693 deletions.
21,846 changes: 20,162 additions & 1,684 deletions Emulator/Peripherals/Joystick/GamePadDatabase.h

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions Emulator/Peripherals/Joystick/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ Joystick::eofHandler()
void
Joystick::configureHID(u16 vendorID, u16 productID, u16 version)
{
// Use the generic settings as fallback
traits = gamePads[0];
debug(PRT_DEBUG, "configureHID(%d, %d, %d)\n", vendorID, productID, version);

// Crawl through the database
for (const auto &gamePad : gamePads) {
Expand All @@ -328,7 +327,24 @@ Joystick::configureHID(u16 vendorID, u16 productID, u16 version)
if (gamePad.version != version) continue;

traits = gamePad;

debug(PRT_DEBUG, "Connected %s\n", traits.name);
debug(PRT_DEBUG, " vendorID = %d\n", traits.vendorID);
debug(PRT_DEBUG, " productID = %d\n", traits.productID);
debug(PRT_DEBUG, " version = %d\n", traits.version);

return;
}

// Fallback to the generic setting
traits = gamePads[0];
}

void
Joystick::trigger(isize page, isize usage, isize value, u16 vendorID, u16 productID, u16 version)
{
debug(PRT_DEBUG, "vendorID = %ld productID = %ld version = %ld\n", vendorID, productID, version);
debug(PRT_DEBUG, "usagePage = %ld usage = %ld value = %ld\n", page, usage, value);
}

void
Expand Down
1 change: 1 addition & 0 deletions Emulator/Peripherals/Joystick/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class Joystick final : public SubComponent, public Inspectable<JoystickInfo> {
void configureHID(u16 vendorID, u16 productID, u16 version);

// Processes a HID event
void trigger(isize page, isize usage, isize value, u16 vendorID, u16 productID, u16 version);
void trigger(isize page, isize usage, isize value);
};

Expand Down
23 changes: 20 additions & 3 deletions Emulator/Peripherals/Joystick/JoystickTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,50 @@ struct GamePadActionEnum : vamiga::util::Reflection<GamePadActionEnum, GamePadAc
enum_long(HID_ACTION)
{
HID_A0,
HID_A0_REV,
HID_A1,
HID_A1_REV,
HID_A12,
HID_A2,
HID_A2_REV,
HID_A20,
HID_A3,
HID_A3_REV,
HID_A31,
HID_A4,
HID_A5,
HID_A5_REV,
HID_A6,
HID_A6_REV,
HID_A7,
HID_A8,
HID_B0,
HID_B1,
HID_B10,
HID_B11,
HID_B12,
HID_B13,
HID_B14,
HID_B15,
HID_B16,
HID_B17,
HID_B19,
HID_B2,
HID_B20,
HID_B21,
HID_B22,
HID_B23,
HID_B24,
HID_B25,
HID_B26,
HID_B27,
HID_B3,
HID_B4,
HID_B5,
HID_B6,
HID_B7,
HID_B8,
HID_B9
};
typedef HID_ACTION HIDAction;

Expand Down Expand Up @@ -138,11 +155,11 @@ typedef struct {
int productID;
int version;

HID_ACTION button1;
HID_ACTION button2;
HID_ACTION leftx;
HID_ACTION lefty;
HID_ACTION rightx;
HID_ACTION lefty;
HID_ACTION righty;
HID_ACTION button1;
HID_ACTION button2;
}
GamePadTraits;
22 changes: 22 additions & 0 deletions Emulator/VAmiga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,28 @@ JoystickAPI::trigger(GamePadAction event)
emu->put(CMD_JOY_EVENT, GamePadCmd { .port = joystick->objid, .action = event });
}

void
JoystickAPI::configureHID(u16 vendorID, u16 productID, u16 version)
{
joystick->configureHID(vendorID, productID, version);
emu->isDirty = true;
}

void
JoystickAPI::trigger(isize page, isize usage, isize value, u16 vendorID, u16 productID, u16 version)
{
joystick->trigger(page, usage, value, vendorID, productID, version);
emu->isDirty = true;
}

void
JoystickAPI::trigger(isize page, isize usage, isize value)
{
// emu->put(CMD_HID_EVENT, GamePadCmd { .port = joystick->objid, ... });
joystick->trigger(page, usage, value);
emu->isDirty = true;
}


//
// Mouse
Expand Down
6 changes: 6 additions & 0 deletions Emulator/VAmiga.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,12 @@ struct JoystickAPI : public API {
/** @brief Triggers a joystick action.
*/
void trigger(GamePadAction event);

/** @brief HID API (experimental)
*/
void configureHID(u16 vendorID, u16 productID, u16 version);
void trigger(isize page, isize usage, isize value, u16 vendorID, u16 productID, u16 version);
void trigger(isize page, isize usage, isize value);
};


Expand Down
2 changes: 1 addition & 1 deletion Emulator/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ debugflag POSREG_DEBUG = 0;
debugflag JOYREG_DEBUG = 0;
debugflag POTREG_DEBUG = 0;
debugflag VID_DEBUG = 0;
debugflag PRT_DEBUG = 0;
debugflag PRT_DEBUG = 1;
debugflag SER_DEBUG = 0;
debugflag POT_DEBUG = 0;
debugflag HOLD_MOUSE_L = 0;
Expand Down
17 changes: 14 additions & 3 deletions GUI/Peripherals/GamePad.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ class GamePad {

// References to other objects
var manager: GamePadManager
var amiga: EmulatorProxy { return manager.parent.emu }
var prefs: Preferences { return manager.parent.pref }
var config: Configuration { return manager.parent.config }
var db: DeviceDatabase { return myAppDelegate.database }

// The Amiga port this device is connected to (1, 2, or nil)
var port: Int?

Expand All @@ -52,7 +53,8 @@ class GamePad {
var vendorID: String { return device?.vendorID ?? "" }
var productID: String { return device?.productID ?? "" }
var locationID: String { return device?.locationID ?? "" }

var version: String { return device?.versionNumberKey ?? "" }

// Type of the managed device (joystick or mouse)
var type: ControlPortDevice
var isMouse: Bool { return type == .MOUSE }
Expand Down Expand Up @@ -328,7 +330,16 @@ class GamePad {
let usage = Int(IOHIDElementGetUsage(element))

// track("usagePage = \(usagePage) usage = \(usage) value = \(intValue)")


// New code (uses experimental HID interface)
let cp = port == 1 ? amiga.controlPort1 : amiga.controlPort2
cp?.joystick.triggerPage(usagePage, usage: usage, value: intValue)


//
// Old code
//

var events: [GamePadAction]?

if usagePage == kHIDPage_Button {
Expand Down
6 changes: 6 additions & 0 deletions GUI/Peripherals/GamePadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ class GamePadManager {

// Bind the new device
gamePads[slot]?.port = port

let vendor = Int(gamePads[slot]?.vendorID ?? "", radix: 10) ?? 0
let product = Int(gamePads[slot]?.productID ?? "", radix: 10) ?? 0
let version = Int(gamePads[slot]?.version ?? "", radix: 10) ?? 0

parent.emu?.controlPort1.joystick.configureHID(vendor, productID: product, version: version)
}

func name(slot: Int) -> String {
Expand Down
1 change: 1 addition & 0 deletions GUI/Peripherals/HIDExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extension IOHIDDevice {
var vendorID: String { return property(key: kIOHIDVendorIDKey) ?? "" }
var productID: String { return property(key: kIOHIDProductIDKey) ?? "" }
var locationID: String { return property(key: kIOHIDLocationIDKey) ?? "" }
var versionNumberKey: String { return property(key: kIOHIDVersionNumberKey) ?? "" }
var manufacturerKey: String { return property(key: kIOHIDManufacturerKey) ?? "" }
var usageKey: String { return property(key: kIOHIDPrimaryUsageKey) ?? "" }
var builtInKey: String { return property(key: kIOHIDBuiltInKey) ?? "" }
Expand Down
3 changes: 3 additions & 0 deletions Proxy/EmulatorProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,10 @@

@interface JoystickProxy : CoreComponentProxy { }

- (void)configureHID:(NSInteger)vendorID productID:(NSInteger)productID version:(NSInteger)version;
- (void)trigger:(GamePadAction)event;
- (void)triggerPage:(NSInteger)page usage:(NSInteger)usage value:(NSInteger)value;
- (void)triggerPage:(NSInteger)page usage:(NSInteger)usage value:(NSInteger)value vendorID:(u16)vendorID productID:(u16)productID version:(u16)version;

@end

Expand Down
15 changes: 15 additions & 0 deletions Proxy/EmulatorProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,26 @@ - (JoystickAPI *)joystick
return (JoystickAPI *)obj;
}

- (void)configureHID:(NSInteger)vendorID productID:(NSInteger)productID version:(NSInteger)version
{
[self joystick]->configureHID(u16(vendorID), u16(productID), u16(version));
}

- (void)trigger:(GamePadAction)event
{
[self joystick]->trigger(event);
}

- (void)triggerPage:(NSInteger)page usage:(NSInteger)usage value:(NSInteger)value vendorID:(u16)vendorID productID:(u16)productID version:(u16)version
{
[self joystick]->trigger(page, usage, value, vendorID, productID, version);
}

- (void)triggerPage:(NSInteger)page usage:(NSInteger)usage value:(NSInteger)value
{
[self joystick]->trigger(page, usage, value);
}

@end


Expand Down

0 comments on commit 022c8f4

Please sign in to comment.