mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 22:05:38 +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
|
||||
cdrom.cpp
|
||||
cdrom.h
|
||||
controller.cpp
|
||||
controller.h
|
||||
cpu_code_cache.cpp
|
||||
cpu_code_cache.h
|
||||
cpu_core.cpp
|
||||
|
@ -48,8 +50,6 @@ add_library(core
|
|||
memory_card.h
|
||||
pad.cpp
|
||||
pad.h
|
||||
pad_device.cpp
|
||||
pad_device.h
|
||||
save_state_version.h
|
||||
settings.cpp
|
||||
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 PadDevice
|
||||
class Controller
|
||||
{
|
||||
public:
|
||||
PadDevice();
|
||||
virtual ~PadDevice();
|
||||
Controller();
|
||||
virtual ~Controller();
|
||||
|
||||
virtual void Reset();
|
||||
virtual bool DoState(StateWrapper& sw);
|
||||
|
@ -21,7 +21,7 @@ public:
|
|||
virtual bool Transfer(const u8 data_in, u8* data_out);
|
||||
|
||||
/// 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.
|
||||
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="memory_card.cpp" />
|
||||
<ClCompile Include="pad.cpp" />
|
||||
<ClCompile Include="pad_device.cpp" />
|
||||
<ClCompile Include="controller.cpp" />
|
||||
<ClCompile Include="settings.cpp" />
|
||||
<ClCompile Include="sio.cpp" />
|
||||
<ClCompile Include="spu.cpp" />
|
||||
|
@ -111,7 +111,7 @@
|
|||
<ClInclude Include="mdec.h" />
|
||||
<ClInclude Include="memory_card.h" />
|
||||
<ClInclude Include="pad.h" />
|
||||
<ClInclude Include="pad_device.h" />
|
||||
<ClInclude Include="controller.h" />
|
||||
<ClInclude Include="save_state_version.h" />
|
||||
<ClInclude Include="settings.h" />
|
||||
<ClInclude Include="sio.h" />
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
<ClCompile Include="cdrom.cpp" />
|
||||
<ClCompile Include="gte.cpp" />
|
||||
<ClCompile Include="pad.cpp" />
|
||||
<ClCompile Include="pad_device.cpp" />
|
||||
<ClCompile Include="digital_controller.cpp" />
|
||||
<ClCompile Include="timers.cpp" />
|
||||
<ClCompile Include="spu.cpp" />
|
||||
|
@ -37,6 +36,7 @@
|
|||
<ClCompile Include="cpu_recompiler_code_generator_aarch64.cpp" />
|
||||
<ClCompile Include="gpu_hw_opengl_es.cpp" />
|
||||
<ClCompile Include="sio.cpp" />
|
||||
<ClCompile Include="controller.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="types.h" />
|
||||
|
@ -56,7 +56,6 @@
|
|||
<ClInclude Include="gte.h" />
|
||||
<ClInclude Include="gte_types.h" />
|
||||
<ClInclude Include="pad.h" />
|
||||
<ClInclude Include="pad_device.h" />
|
||||
<ClInclude Include="digital_controller.h" />
|
||||
<ClInclude Include="timers.h" />
|
||||
<ClInclude Include="spu.h" />
|
||||
|
@ -76,6 +75,7 @@
|
|||
<ClInclude Include="game_list.h" />
|
||||
<ClInclude Include="gpu_hw_opengl_es.h" />
|
||||
<ClInclude Include="sio.h" />
|
||||
<ClInclude Include="controller.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpu_core.inl" />
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
#include "pad_device.h"
|
||||
#include "controller.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
class DigitalController final : public PadDevice
|
||||
class DigitalController final : public Controller
|
||||
{
|
||||
public:
|
||||
enum class Button : u8
|
||||
|
|
|
@ -245,7 +245,7 @@ std::shared_ptr<MemoryCard> MemoryCard::Open(System* system, std::string_view fi
|
|||
{
|
||||
SmallString message;
|
||||
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.");
|
||||
Log_ErrorPrint(message);
|
||||
mc->Format();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include "common/bitfield.h"
|
||||
#include "pad_device.h"
|
||||
#include "controller.h"
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
@ -8,7 +8,7 @@
|
|||
|
||||
class System;
|
||||
|
||||
class MemoryCard final : public PadDevice
|
||||
class MemoryCard final
|
||||
{
|
||||
public:
|
||||
enum : u32
|
||||
|
@ -19,16 +19,16 @@ public:
|
|||
};
|
||||
|
||||
MemoryCard(System* system);
|
||||
~MemoryCard() override;
|
||||
~MemoryCard();
|
||||
|
||||
static std::shared_ptr<MemoryCard> Create(System* system);
|
||||
static std::shared_ptr<MemoryCard> Open(System* system, std::string_view filename);
|
||||
|
||||
void Reset() override;
|
||||
bool DoState(StateWrapper& sw) override;
|
||||
void Reset();
|
||||
bool DoState(StateWrapper& sw);
|
||||
|
||||
void ResetTransferState() override;
|
||||
bool Transfer(const u8 data_in, u8* data_out) override;
|
||||
void ResetTransferState();
|
||||
bool Transfer(const u8 data_in, u8* data_out);
|
||||
|
||||
void Format();
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "host_interface.h"
|
||||
#include "interrupt_controller.h"
|
||||
#include "memory_card.h"
|
||||
#include "pad_device.h"
|
||||
#include "controller.h"
|
||||
#include "system.h"
|
||||
Log_SetChannel(Pad);
|
||||
|
||||
|
@ -289,8 +289,8 @@ void Pad::DoTransfer()
|
|||
{
|
||||
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<PadDevice>& memory_card = m_memory_cards[m_JOY_CTRL.SLOT];
|
||||
const std::shared_ptr<Controller>& controller = m_controllers[m_JOY_CTRL.SLOT];
|
||||
const std::shared_ptr<MemoryCard>& memory_card = m_memory_cards[m_JOY_CTRL.SLOT];
|
||||
|
||||
// set rx?
|
||||
m_JOY_CTRL.RXEN = true;
|
||||
|
|
|
@ -9,7 +9,7 @@ class StateWrapper;
|
|||
|
||||
class System;
|
||||
class InterruptController;
|
||||
class PadDevice;
|
||||
class Controller;
|
||||
class MemoryCard;
|
||||
|
||||
class Pad
|
||||
|
@ -22,8 +22,8 @@ public:
|
|||
void Reset();
|
||||
bool DoState(StateWrapper& sw);
|
||||
|
||||
PadDevice* GetController(u32 slot) { return m_controllers[slot].get(); }
|
||||
void SetController(u32 slot, std::shared_ptr<PadDevice> dev) { m_controllers[slot] = dev; }
|
||||
Controller* GetController(u32 slot) { return m_controllers[slot].get(); }
|
||||
void SetController(u32 slot, std::shared_ptr<Controller> dev) { m_controllers[slot] = dev; }
|
||||
|
||||
MemoryCard* GetMemoryCard(u32 slot) { return m_memory_cards[slot].get(); }
|
||||
void SetMemoryCard(u32 slot, std::shared_ptr<MemoryCard> dev) { m_memory_cards[slot] = dev; }
|
||||
|
@ -106,7 +106,7 @@ private:
|
|||
System* m_system = 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;
|
||||
|
||||
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 "interrupt_controller.h"
|
||||
#include "memory_card.h"
|
||||
#include "pad_device.h"
|
||||
#include "controller.h"
|
||||
#include "system.h"
|
||||
Log_SetChannel(SIO);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class StateWrapper;
|
|||
|
||||
class System;
|
||||
class InterruptController;
|
||||
class PadDevice;
|
||||
class Controller;
|
||||
class MemoryCard;
|
||||
|
||||
class SIO
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "bus.h"
|
||||
#include "cdrom.h"
|
||||
#include "common/state_wrapper.h"
|
||||
#include "controller.h"
|
||||
#include "cpu_code_cache.h"
|
||||
#include "cpu_core.h"
|
||||
#include "dma.h"
|
||||
|
@ -16,7 +17,6 @@
|
|||
#include "mdec.h"
|
||||
#include "memory_card.h"
|
||||
#include "pad.h"
|
||||
#include "pad_device.h"
|
||||
#include "sio.h"
|
||||
#include "spu.h"
|
||||
#include "timers.h"
|
||||
|
@ -448,7 +448,7 @@ void System::StallCPU(TickCount 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));
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class InterruptController;
|
|||
class GPU;
|
||||
class CDROM;
|
||||
class Pad;
|
||||
class PadDevice;
|
||||
class Controller;
|
||||
class Timers;
|
||||
class SPU;
|
||||
class MDEC;
|
||||
|
@ -79,7 +79,7 @@ public:
|
|||
// Adds ticks to the global tick counter, simulating the CPU being stalled.
|
||||
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 UpdateCPUExecutionMode();
|
||||
|
||||
|
|
Loading…
Reference in a new issue