mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 23:55:40 +00:00
Split MemoryCard and PadDevice (now Controller)
This commit is contained in:
parent
c1710482df
commit
da14b10e72
|
@ -6,6 +6,8 @@ add_library(core
|
||||||
bus.inl
|
bus.inl
|
||||||
cdrom.cpp
|
cdrom.cpp
|
||||||
cdrom.h
|
cdrom.h
|
||||||
|
controller.cpp
|
||||||
|
controller.h
|
||||||
cpu_code_cache.cpp
|
cpu_code_cache.cpp
|
||||||
cpu_code_cache.h
|
cpu_code_cache.h
|
||||||
cpu_core.cpp
|
cpu_core.cpp
|
||||||
|
@ -48,8 +50,6 @@ add_library(core
|
||||||
memory_card.h
|
memory_card.h
|
||||||
pad.cpp
|
pad.cpp
|
||||||
pad.h
|
pad.h
|
||||||
pad_device.cpp
|
|
||||||
pad_device.h
|
|
||||||
save_state_version.h
|
save_state_version.h
|
||||||
settings.cpp
|
settings.cpp
|
||||||
settings.h
|
settings.h
|
||||||
|
|
38
src/core/controller.cpp
Normal file
38
src/core/controller.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include "controller.h"
|
||||||
|
#include "common/state_wrapper.h"
|
||||||
|
#include "digital_controller.h"
|
||||||
|
|
||||||
|
Controller::Controller() = default;
|
||||||
|
|
||||||
|
Controller::~Controller() = default;
|
||||||
|
|
||||||
|
void Controller::Reset() {}
|
||||||
|
|
||||||
|
bool Controller::DoState(StateWrapper& sw)
|
||||||
|
{
|
||||||
|
return !sw.HasError();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Controller::ResetTransferState() {}
|
||||||
|
|
||||||
|
bool Controller::Transfer(const u8 data_in, u8* data_out)
|
||||||
|
{
|
||||||
|
*data_out = 0xFF;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Controller> Controller::Create(std::string_view type_name)
|
||||||
|
{
|
||||||
|
if (type_name == "DigitalController")
|
||||||
|
return DigitalController::Create();
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<s32> Controller::GetButtonCodeByName(std::string_view type_name, std::string_view button_name)
|
||||||
|
{
|
||||||
|
if (type_name == "DigitalController")
|
||||||
|
return DigitalController::GetButtonCodeByName(button_name);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
|
@ -5,11 +5,11 @@
|
||||||
|
|
||||||
class StateWrapper;
|
class StateWrapper;
|
||||||
|
|
||||||
class PadDevice
|
class Controller
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PadDevice();
|
Controller();
|
||||||
virtual ~PadDevice();
|
virtual ~Controller();
|
||||||
|
|
||||||
virtual void Reset();
|
virtual void Reset();
|
||||||
virtual bool DoState(StateWrapper& sw);
|
virtual bool DoState(StateWrapper& sw);
|
||||||
|
@ -21,7 +21,7 @@ public:
|
||||||
virtual bool Transfer(const u8 data_in, u8* data_out);
|
virtual bool Transfer(const u8 data_in, u8* data_out);
|
||||||
|
|
||||||
/// Creates a new controller of the specified type.
|
/// Creates a new controller of the specified type.
|
||||||
static std::shared_ptr<PadDevice> Create(std::string_view type_name);
|
static std::shared_ptr<Controller> Create(std::string_view type_name);
|
||||||
|
|
||||||
/// Gets the integer code for a button in the specified controller type.
|
/// Gets the integer code for a button in the specified controller type.
|
||||||
static std::optional<s32> GetButtonCodeByName(std::string_view type_name, std::string_view button_name);
|
static std::optional<s32> GetButtonCodeByName(std::string_view type_name, std::string_view button_name);
|
|
@ -74,7 +74,7 @@
|
||||||
<ClCompile Include="mdec.cpp" />
|
<ClCompile Include="mdec.cpp" />
|
||||||
<ClCompile Include="memory_card.cpp" />
|
<ClCompile Include="memory_card.cpp" />
|
||||||
<ClCompile Include="pad.cpp" />
|
<ClCompile Include="pad.cpp" />
|
||||||
<ClCompile Include="pad_device.cpp" />
|
<ClCompile Include="controller.cpp" />
|
||||||
<ClCompile Include="settings.cpp" />
|
<ClCompile Include="settings.cpp" />
|
||||||
<ClCompile Include="sio.cpp" />
|
<ClCompile Include="sio.cpp" />
|
||||||
<ClCompile Include="spu.cpp" />
|
<ClCompile Include="spu.cpp" />
|
||||||
|
@ -111,7 +111,7 @@
|
||||||
<ClInclude Include="mdec.h" />
|
<ClInclude Include="mdec.h" />
|
||||||
<ClInclude Include="memory_card.h" />
|
<ClInclude Include="memory_card.h" />
|
||||||
<ClInclude Include="pad.h" />
|
<ClInclude Include="pad.h" />
|
||||||
<ClInclude Include="pad_device.h" />
|
<ClInclude Include="controller.h" />
|
||||||
<ClInclude Include="save_state_version.h" />
|
<ClInclude Include="save_state_version.h" />
|
||||||
<ClInclude Include="settings.h" />
|
<ClInclude Include="settings.h" />
|
||||||
<ClInclude Include="sio.h" />
|
<ClInclude Include="sio.h" />
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
<ClCompile Include="cdrom.cpp" />
|
<ClCompile Include="cdrom.cpp" />
|
||||||
<ClCompile Include="gte.cpp" />
|
<ClCompile Include="gte.cpp" />
|
||||||
<ClCompile Include="pad.cpp" />
|
<ClCompile Include="pad.cpp" />
|
||||||
<ClCompile Include="pad_device.cpp" />
|
|
||||||
<ClCompile Include="digital_controller.cpp" />
|
<ClCompile Include="digital_controller.cpp" />
|
||||||
<ClCompile Include="timers.cpp" />
|
<ClCompile Include="timers.cpp" />
|
||||||
<ClCompile Include="spu.cpp" />
|
<ClCompile Include="spu.cpp" />
|
||||||
|
@ -37,6 +36,7 @@
|
||||||
<ClCompile Include="cpu_recompiler_code_generator_aarch64.cpp" />
|
<ClCompile Include="cpu_recompiler_code_generator_aarch64.cpp" />
|
||||||
<ClCompile Include="gpu_hw_opengl_es.cpp" />
|
<ClCompile Include="gpu_hw_opengl_es.cpp" />
|
||||||
<ClCompile Include="sio.cpp" />
|
<ClCompile Include="sio.cpp" />
|
||||||
|
<ClCompile Include="controller.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="types.h" />
|
<ClInclude Include="types.h" />
|
||||||
|
@ -56,7 +56,6 @@
|
||||||
<ClInclude Include="gte.h" />
|
<ClInclude Include="gte.h" />
|
||||||
<ClInclude Include="gte_types.h" />
|
<ClInclude Include="gte_types.h" />
|
||||||
<ClInclude Include="pad.h" />
|
<ClInclude Include="pad.h" />
|
||||||
<ClInclude Include="pad_device.h" />
|
|
||||||
<ClInclude Include="digital_controller.h" />
|
<ClInclude Include="digital_controller.h" />
|
||||||
<ClInclude Include="timers.h" />
|
<ClInclude Include="timers.h" />
|
||||||
<ClInclude Include="spu.h" />
|
<ClInclude Include="spu.h" />
|
||||||
|
@ -76,6 +75,7 @@
|
||||||
<ClInclude Include="game_list.h" />
|
<ClInclude Include="game_list.h" />
|
||||||
<ClInclude Include="gpu_hw_opengl_es.h" />
|
<ClInclude Include="gpu_hw_opengl_es.h" />
|
||||||
<ClInclude Include="sio.h" />
|
<ClInclude Include="sio.h" />
|
||||||
|
<ClInclude Include="controller.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="cpu_core.inl" />
|
<None Include="cpu_core.inl" />
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "pad_device.h"
|
#include "controller.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
class DigitalController final : public PadDevice
|
class DigitalController final : public Controller
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Button : u8
|
enum class Button : u8
|
||||||
|
|
|
@ -245,7 +245,7 @@ std::shared_ptr<MemoryCard> MemoryCard::Open(System* system, std::string_view fi
|
||||||
{
|
{
|
||||||
SmallString message;
|
SmallString message;
|
||||||
message.AppendString("Memory card at '");
|
message.AppendString("Memory card at '");
|
||||||
message.AppendString(filename.data(), filename.length());
|
message.AppendString(filename.data(), static_cast<u32>(filename.length()));
|
||||||
message.AppendString("' could not be read, formatting.");
|
message.AppendString("' could not be read, formatting.");
|
||||||
Log_ErrorPrint(message);
|
Log_ErrorPrint(message);
|
||||||
mc->Format();
|
mc->Format();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "common/bitfield.h"
|
#include "common/bitfield.h"
|
||||||
#include "pad_device.h"
|
#include "controller.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
class System;
|
class System;
|
||||||
|
|
||||||
class MemoryCard final : public PadDevice
|
class MemoryCard final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum : u32
|
enum : u32
|
||||||
|
@ -19,16 +19,16 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
MemoryCard(System* system);
|
MemoryCard(System* system);
|
||||||
~MemoryCard() override;
|
~MemoryCard();
|
||||||
|
|
||||||
static std::shared_ptr<MemoryCard> Create(System* system);
|
static std::shared_ptr<MemoryCard> Create(System* system);
|
||||||
static std::shared_ptr<MemoryCard> Open(System* system, std::string_view filename);
|
static std::shared_ptr<MemoryCard> Open(System* system, std::string_view filename);
|
||||||
|
|
||||||
void Reset() override;
|
void Reset();
|
||||||
bool DoState(StateWrapper& sw) override;
|
bool DoState(StateWrapper& sw);
|
||||||
|
|
||||||
void ResetTransferState() override;
|
void ResetTransferState();
|
||||||
bool Transfer(const u8 data_in, u8* data_out) override;
|
bool Transfer(const u8 data_in, u8* data_out);
|
||||||
|
|
||||||
void Format();
|
void Format();
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "host_interface.h"
|
#include "host_interface.h"
|
||||||
#include "interrupt_controller.h"
|
#include "interrupt_controller.h"
|
||||||
#include "memory_card.h"
|
#include "memory_card.h"
|
||||||
#include "pad_device.h"
|
#include "controller.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
Log_SetChannel(Pad);
|
Log_SetChannel(Pad);
|
||||||
|
|
||||||
|
@ -289,8 +289,8 @@ void Pad::DoTransfer()
|
||||||
{
|
{
|
||||||
Log_DebugPrintf("Transferring slot %d", m_JOY_CTRL.SLOT.GetValue());
|
Log_DebugPrintf("Transferring slot %d", m_JOY_CTRL.SLOT.GetValue());
|
||||||
|
|
||||||
const std::shared_ptr<PadDevice>& controller = m_controllers[m_JOY_CTRL.SLOT];
|
const std::shared_ptr<Controller>& controller = m_controllers[m_JOY_CTRL.SLOT];
|
||||||
const std::shared_ptr<PadDevice>& memory_card = m_memory_cards[m_JOY_CTRL.SLOT];
|
const std::shared_ptr<MemoryCard>& memory_card = m_memory_cards[m_JOY_CTRL.SLOT];
|
||||||
|
|
||||||
// set rx?
|
// set rx?
|
||||||
m_JOY_CTRL.RXEN = true;
|
m_JOY_CTRL.RXEN = true;
|
||||||
|
|
|
@ -9,7 +9,7 @@ class StateWrapper;
|
||||||
|
|
||||||
class System;
|
class System;
|
||||||
class InterruptController;
|
class InterruptController;
|
||||||
class PadDevice;
|
class Controller;
|
||||||
class MemoryCard;
|
class MemoryCard;
|
||||||
|
|
||||||
class Pad
|
class Pad
|
||||||
|
@ -22,8 +22,8 @@ public:
|
||||||
void Reset();
|
void Reset();
|
||||||
bool DoState(StateWrapper& sw);
|
bool DoState(StateWrapper& sw);
|
||||||
|
|
||||||
PadDevice* GetController(u32 slot) { return m_controllers[slot].get(); }
|
Controller* GetController(u32 slot) { return m_controllers[slot].get(); }
|
||||||
void SetController(u32 slot, std::shared_ptr<PadDevice> dev) { m_controllers[slot] = dev; }
|
void SetController(u32 slot, std::shared_ptr<Controller> dev) { m_controllers[slot] = dev; }
|
||||||
|
|
||||||
MemoryCard* GetMemoryCard(u32 slot) { return m_memory_cards[slot].get(); }
|
MemoryCard* GetMemoryCard(u32 slot) { return m_memory_cards[slot].get(); }
|
||||||
void SetMemoryCard(u32 slot, std::shared_ptr<MemoryCard> dev) { m_memory_cards[slot] = dev; }
|
void SetMemoryCard(u32 slot, std::shared_ptr<MemoryCard> dev) { m_memory_cards[slot] = dev; }
|
||||||
|
@ -106,7 +106,7 @@ private:
|
||||||
System* m_system = nullptr;
|
System* m_system = nullptr;
|
||||||
InterruptController* m_interrupt_controller = nullptr;
|
InterruptController* m_interrupt_controller = nullptr;
|
||||||
|
|
||||||
std::array<std::shared_ptr<PadDevice>, NUM_SLOTS> m_controllers;
|
std::array<std::shared_ptr<Controller>, NUM_SLOTS> m_controllers;
|
||||||
std::array<std::shared_ptr<MemoryCard>, NUM_SLOTS> m_memory_cards;
|
std::array<std::shared_ptr<MemoryCard>, NUM_SLOTS> m_memory_cards;
|
||||||
|
|
||||||
State m_state = State::Idle;
|
State m_state = State::Idle;
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
#include "pad_device.h"
|
|
||||||
#include "common/state_wrapper.h"
|
|
||||||
#include "digital_controller.h"
|
|
||||||
|
|
||||||
PadDevice::PadDevice() = default;
|
|
||||||
|
|
||||||
PadDevice::~PadDevice() = default;
|
|
||||||
|
|
||||||
void PadDevice::Reset() {}
|
|
||||||
|
|
||||||
bool PadDevice::DoState(StateWrapper& sw)
|
|
||||||
{
|
|
||||||
return !sw.HasError();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PadDevice::ResetTransferState() {}
|
|
||||||
|
|
||||||
bool PadDevice::Transfer(const u8 data_in, u8* data_out)
|
|
||||||
{
|
|
||||||
*data_out = 0xFF;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<PadDevice> PadDevice::Create(std::string_view type_name)
|
|
||||||
{
|
|
||||||
if (type_name == "DigitalController")
|
|
||||||
return DigitalController::Create();
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<s32> PadDevice::GetButtonCodeByName(std::string_view type_name, std::string_view button_name)
|
|
||||||
{
|
|
||||||
if (type_name == "DigitalController")
|
|
||||||
return DigitalController::GetButtonCodeByName(button_name);
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "host_interface.h"
|
#include "host_interface.h"
|
||||||
#include "interrupt_controller.h"
|
#include "interrupt_controller.h"
|
||||||
#include "memory_card.h"
|
#include "memory_card.h"
|
||||||
#include "pad_device.h"
|
#include "controller.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
Log_SetChannel(SIO);
|
Log_SetChannel(SIO);
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ class StateWrapper;
|
||||||
|
|
||||||
class System;
|
class System;
|
||||||
class InterruptController;
|
class InterruptController;
|
||||||
class PadDevice;
|
class Controller;
|
||||||
class MemoryCard;
|
class MemoryCard;
|
||||||
|
|
||||||
class SIO
|
class SIO
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
#include "cdrom.h"
|
#include "cdrom.h"
|
||||||
#include "common/state_wrapper.h"
|
#include "common/state_wrapper.h"
|
||||||
|
#include "controller.h"
|
||||||
#include "cpu_code_cache.h"
|
#include "cpu_code_cache.h"
|
||||||
#include "cpu_core.h"
|
#include "cpu_core.h"
|
||||||
#include "dma.h"
|
#include "dma.h"
|
||||||
|
@ -16,7 +17,6 @@
|
||||||
#include "mdec.h"
|
#include "mdec.h"
|
||||||
#include "memory_card.h"
|
#include "memory_card.h"
|
||||||
#include "pad.h"
|
#include "pad.h"
|
||||||
#include "pad_device.h"
|
|
||||||
#include "sio.h"
|
#include "sio.h"
|
||||||
#include "spu.h"
|
#include "spu.h"
|
||||||
#include "timers.h"
|
#include "timers.h"
|
||||||
|
@ -448,7 +448,7 @@ void System::StallCPU(TickCount ticks)
|
||||||
m_cpu->AddPendingTicks(ticks);
|
m_cpu->AddPendingTicks(ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::SetController(u32 slot, std::shared_ptr<PadDevice> dev)
|
void System::SetController(u32 slot, std::shared_ptr<Controller> dev)
|
||||||
{
|
{
|
||||||
m_pad->SetController(slot, std::move(dev));
|
m_pad->SetController(slot, std::move(dev));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ class InterruptController;
|
||||||
class GPU;
|
class GPU;
|
||||||
class CDROM;
|
class CDROM;
|
||||||
class Pad;
|
class Pad;
|
||||||
class PadDevice;
|
class Controller;
|
||||||
class Timers;
|
class Timers;
|
||||||
class SPU;
|
class SPU;
|
||||||
class MDEC;
|
class MDEC;
|
||||||
|
@ -79,7 +79,7 @@ public:
|
||||||
// Adds ticks to the global tick counter, simulating the CPU being stalled.
|
// Adds ticks to the global tick counter, simulating the CPU being stalled.
|
||||||
void StallCPU(TickCount ticks);
|
void StallCPU(TickCount ticks);
|
||||||
|
|
||||||
void SetController(u32 slot, std::shared_ptr<PadDevice> dev);
|
void SetController(u32 slot, std::shared_ptr<Controller> dev);
|
||||||
void UpdateMemoryCards();
|
void UpdateMemoryCards();
|
||||||
void UpdateCPUExecutionMode();
|
void UpdateCPUExecutionMode();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue