HID system skeleton.

This commit is contained in:
Ben Vanik
2013-10-23 21:47:36 -07:00
parent 20bd15e7fe
commit 74803ae174
25 changed files with 684 additions and 5 deletions

View File

@@ -0,0 +1,19 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_HID_PRIVATE_H_
#define XENIA_HID_HID_PRIVATE_H_
#include <gflags/gflags.h>
DECLARE_string(hid);
#endif // XENIA_HID_HID_PRIVATE_H_

60
src/xenia/hid/hid.cc Normal file
View File

@@ -0,0 +1,60 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/hid/hid.h>
#include <xenia/hid/hid-private.h>
using namespace xe;
using namespace xe::hid;
DEFINE_string(hid, "any",
"Input system. Use: [any, nop, xinput]");
#include <xenia/hid/nop/nop_hid.h>
#if XE_PLATFORM(WIN32)
#include <xenia/hid/xinput/xinput_hid.h>
#endif // WIN32
InputSystem* xe::hid::Create(Emulator* emulator) {
//return xe::hid::nop::Create(emulator);
InputSystem* input_system = new InputSystem(emulator);
if (FLAGS_hid.compare("nop") == 0) {
input_system->AddDriver(xe::hid::nop::Create(input_system));
#if XE_PLATFORM(WIN32)
} else if (FLAGS_hid.compare("xinput") == 0) {
input_system->AddDriver(xe::hid::xinput::Create(input_system));
#endif // WIN32
} else {
// Create all available.
bool any_created = false;
// NOTE: in any mode we create as many as we can, falling back to nop.
#if XE_PLATFORM(WIN32)
InputDriver* xinput_driver = xe::hid::xinput::Create(input_system);
if (xinput_driver) {
input_system->AddDriver(xinput_driver);
any_created = true;
}
#endif // WIN32
// Fallback to nop if none created.
if (!any_created) {
input_system->AddDriver(xe::hid::nop::Create(input_system));
}
}
return input_system;
}

30
src/xenia/hid/hid.h Normal file
View File

@@ -0,0 +1,30 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_HID_H_
#define XENIA_HID_HID_H_
#include <xenia/hid/input_system.h>
XEDECLARECLASS1(xe, Emulator);
namespace xe {
namespace hid {
InputSystem* Create(Emulator* emulator);
} // namespace hid
} // namespace xe
#endif // XENIA_HID_HID_H_

View File

@@ -0,0 +1,22 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/hid/input_driver.h>
using namespace xe;
using namespace xe::hid;
InputDriver::InputDriver(InputSystem* input_system) :
input_system_(input_system) {
}
InputDriver::~InputDriver() {
}

View File

@@ -0,0 +1,40 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_INPUT_DRIVER_H_
#define XENIA_HID_INPUT_DRIVER_H_
#include <xenia/core.h>
#include <xenia/xbox.h>
namespace xe {
namespace hid {
class InputSystem;
class InputDriver {
public:
virtual ~InputDriver();
virtual X_STATUS Setup() = 0;
protected:
InputDriver(InputSystem* input_system);
InputSystem* input_system_;
};
} // namespace hid
} // namespace xe
#endif // XENIA_HID_INPUT_DRIVER_H_

View File

@@ -0,0 +1,43 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/hid/input_system.h>
#include <xenia/emulator.h>
#include <xenia/cpu/processor.h>
#include <xenia/hid/input_driver.h>
using namespace xe;
using namespace xe::hid;
InputSystem::InputSystem(Emulator* emulator) :
emulator_(emulator) {
memory_ = xe_memory_retain(emulator->memory());
}
InputSystem::~InputSystem() {
for (std::vector<InputDriver*>::iterator it = drivers_.begin();
it != drivers_.end(); ++it) {
InputDriver* driver = *it;
delete driver;
}
xe_memory_release(memory_);
}
X_STATUS InputSystem::Setup() {
processor_ = emulator_->processor();
return X_STATUS_SUCCESS;
}
void InputSystem::AddDriver(InputDriver* driver) {
drivers_.push_back(driver);
}

View File

@@ -0,0 +1,53 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_INPUT_SYSTEM_H_
#define XENIA_HID_INPUT_SYSTEM_H_
#include <xenia/core.h>
#include <xenia/xbox.h>
XEDECLARECLASS1(xe, Emulator);
XEDECLARECLASS2(xe, cpu, Processor);
namespace xe {
namespace hid {
class InputDriver;
class InputSystem {
public:
InputSystem(Emulator* emulator);
~InputSystem();
Emulator* emulator() const { return emulator_; }
xe_memory_ref memory() const { return memory_; }
cpu::Processor* processor() const { return processor_; }
X_STATUS Setup();
void AddDriver(InputDriver* driver);
private:
Emulator* emulator_;
xe_memory_ref memory_;
cpu::Processor* processor_;
std::vector<InputDriver*> drivers_;
};
} // namespace hid
} // namespace xe
#endif // XENIA_HID_INPUT_SYSTEM_H_

View File

@@ -0,0 +1,31 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_NOP_NOP_HID_PRIVATE_H_
#define XENIA_HID_NOP_NOP_HID_PRIVATE_H_
#include <xenia/core.h>
#include <xenia/hid/nop/nop_hid.h>
namespace xe {
namespace hid {
namespace nop {
} // namespace nop
} // namespace hid
} // namespace xe
#endif // XENIA_HID_NOP_NOP_HID_PRIVATE_H_

View File

@@ -0,0 +1,44 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/hid/nop/nop_hid.h>
#include <xenia/hid/nop/nop_input_driver.h>
using namespace xe;
using namespace xe::hid;
using namespace xe::hid::nop;
namespace {
void InitializeIfNeeded();
void CleanupOnShutdown();
void InitializeIfNeeded() {
static bool has_initialized = false;
if (has_initialized) {
return;
}
has_initialized = true;
//
atexit(CleanupOnShutdown);
}
void CleanupOnShutdown() {
}
}
InputDriver* xe::hid::nop::Create(InputSystem* input_system) {
InitializeIfNeeded();
return new NopInputDriver(input_system);
}

View File

@@ -0,0 +1,33 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_NOP_NOP_HID_H_
#define XENIA_HID_NOP_NOP_HID_H_
#include <xenia/core.h>
XEDECLARECLASS2(xe, hid, InputDriver);
XEDECLARECLASS2(xe, hid, InputSystem);
namespace xe {
namespace hid {
namespace nop {
InputDriver* Create(InputSystem* input_system);
} // namespace nop
} // namespace hid
} // namespace xe
#endif // XENIA_HID_NOP_NOP_HID_H_

View File

@@ -0,0 +1,29 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/hid/nop/nop_input_driver.h>
#include <xenia/hid/hid-private.h>
using namespace xe;
using namespace xe::hid;
using namespace xe::hid::nop;
NopInputDriver::NopInputDriver(InputSystem* input_system) :
InputDriver(input_system) {
}
NopInputDriver::~NopInputDriver() {
}
X_STATUS NopInputDriver::Setup() {
return X_STATUS_SUCCESS;
}

View File

@@ -0,0 +1,40 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_NOP_NOP_INPUT_DRIVER_H_
#define XENIA_HID_NOP_NOP_INPUT_DRIVER_H_
#include <xenia/core.h>
#include <xenia/hid/input_driver.h>
#include <xenia/hid/nop/nop_hid-private.h>
namespace xe {
namespace hid {
namespace nop {
class NopInputDriver : public InputDriver {
public:
NopInputDriver(InputSystem* input_system);
virtual ~NopInputDriver();
virtual X_STATUS Setup();
protected:
};
} // namespace nop
} // namespace hid
} // namespace xe
#endif // XENIA_HID_NOP_NOP_INPUT_DRIVER_H_

View File

@@ -0,0 +1,10 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'nop_hid-private.h',
'nop_hid.cc',
'nop_hid.h',
'nop_input_driver.cc',
'nop_input_driver.h',
],
}

View File

@@ -0,0 +1,24 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'hid-private.h',
'hid.cc',
'hid.h',
'input_driver.cc',
'input_driver.h',
'input_system.cc',
'input_system.h',
],
'includes': [
'nop/sources.gypi',
],
'conditions': [
['OS == "win"', {
'includes': [
'xinput/sources.gypi',
],
}],
],
}

View File

@@ -0,0 +1,10 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'xinput_hid-private.h',
'xinput_hid.cc',
'xinput_hid.h',
'xinput_input_driver.cc',
'xinput_input_driver.h',
],
}

View File

@@ -0,0 +1,31 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_XINPUT_XINPUT_HID_PRIVATE_H_
#define XENIA_HID_XINPUT_XINPUT_HID_PRIVATE_H_
#include <xenia/core.h>
#include <xenia/hid/xinput/xinput_hid.h>
namespace xe {
namespace hid {
namespace xinput {
} // namespace xinput
} // namespace hid
} // namespace xe
#endif // XENIA_HID_XINPUT_XINPUT_HID_PRIVATE_H_

View File

@@ -0,0 +1,44 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/hid/xinput/xinput_hid.h>
#include <xenia/hid/xinput/xinput_input_driver.h>
using namespace xe;
using namespace xe::hid;
using namespace xe::hid::xinput;
namespace {
void InitializeIfNeeded();
void CleanupOnShutdown();
void InitializeIfNeeded() {
static bool has_initialized = false;
if (has_initialized) {
return;
}
has_initialized = true;
//
atexit(CleanupOnShutdown);
}
void CleanupOnShutdown() {
}
}
InputDriver* xe::hid::xinput::Create(InputSystem* input_system) {
InitializeIfNeeded();
return new XInputInputDriver(input_system);
}

View File

@@ -0,0 +1,33 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_XINPUT_XINPUT_HID_H_
#define XENIA_HID_XINPUT_XINPUT_HID_H_
#include <xenia/core.h>
XEDECLARECLASS2(xe, hid, InputDriver);
XEDECLARECLASS2(xe, hid, InputSystem);
namespace xe {
namespace hid {
namespace xinput {
InputDriver* Create(InputSystem* input_system);
} // namespace xinput
} // namespace hid
} // namespace xe
#endif // XENIA_HID_XINPUT_XINPUT_HID_H_

View File

@@ -0,0 +1,29 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/hid/xinput/xinput_input_driver.h>
#include <xenia/hid/hid-private.h>
using namespace xe;
using namespace xe::hid;
using namespace xe::hid::xinput;
XInputInputDriver::XInputInputDriver(InputSystem* input_system) :
InputDriver(input_system) {
}
XInputInputDriver::~XInputInputDriver() {
}
X_STATUS XInputInputDriver::Setup() {
return X_STATUS_SUCCESS;
}

View File

@@ -0,0 +1,40 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_HID_XINPUT_XINPUT_DRIVER_H_
#define XENIA_HID_XINPUT_XINPUT_DRIVER_H_
#include <xenia/core.h>
#include <xenia/hid/input_driver.h>
#include <xenia/hid/nop/nop_hid-private.h>
namespace xe {
namespace hid {
namespace xinput {
class XInputInputDriver : public InputDriver {
public:
XInputInputDriver(InputSystem* input_system);
virtual ~XInputInputDriver();
virtual X_STATUS Setup();
protected:
};
} // namespace xinput
} // namespace hid
} // namespace xe
#endif // XENIA_HID_XINPUT_XINPUT_DRIVER_H_