Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #8067 from endrift/hsp
Preliminary HSP support
- Loading branch information
Showing
17 changed files
with
340 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ enum class LogType : int | |
| GDB_STUB, | ||
| GPFIFO, | ||
| HOST_GPU, | ||
| HSP, | ||
| IOS, | ||
| IOS_DI, | ||
| IOS_ES, | ||
|
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright 2022 Dolphin Emulator Project | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #include "Core/HW/HSP/HSP.h" | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "Common/ChunkFile.h" | ||
| #include "Core/Config/MainSettings.h" | ||
| #include "Core/HW/HSP/HSP_Device.h" | ||
|
|
||
| namespace HSP | ||
| { | ||
| static std::unique_ptr<IHSPDevice> s_device; | ||
|
|
||
| void Init() | ||
| { | ||
| AddDevice(Config::Get(Config::MAIN_HSP_DEVICE)); | ||
| } | ||
|
|
||
| void Shutdown() | ||
| { | ||
| RemoveDevice(); | ||
| } | ||
|
|
||
| u64 Read(u32 address) | ||
| { | ||
| DEBUG_LOG_FMT(HSP, "HSP read from 0x{:08x}", address); | ||
| if (s_device) | ||
| return s_device->Read(address); | ||
| return 0; | ||
| } | ||
|
|
||
| void Write(u32 address, u64 value) | ||
| { | ||
| DEBUG_LOG_FMT(HSP, "HSP write to 0x{:08x}: 0x{:016x}", address, value); | ||
| if (s_device) | ||
| s_device->Write(address, value); | ||
| } | ||
|
|
||
| void DoState(PointerWrap& p) | ||
| { | ||
| HSPDeviceType type = s_device->GetDeviceType(); | ||
| p.Do(type); | ||
|
|
||
| // If the type doesn't match, switch to the right device type | ||
| if (type != s_device->GetDeviceType()) | ||
| AddDevice(type); | ||
|
|
||
| s_device->DoState(p); | ||
| } | ||
|
|
||
| void AddDevice(std::unique_ptr<IHSPDevice> device) | ||
| { | ||
| // Set the new one | ||
| s_device = std::move(device); | ||
| } | ||
|
|
||
| void AddDevice(const HSPDeviceType device) | ||
| { | ||
| AddDevice(HSPDevice_Create(device)); | ||
| } | ||
|
|
||
| void RemoveDevice() | ||
| { | ||
| s_device.reset(); | ||
| } | ||
| } // namespace HSP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright 2022 Dolphin Emulator Project | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "Common/CommonTypes.h" | ||
|
|
||
| class PointerWrap; | ||
|
|
||
| namespace HSP | ||
| { | ||
| class IHSPDevice; | ||
| enum class HSPDeviceType : int; | ||
|
|
||
| void Init(); | ||
| void Shutdown(); | ||
|
|
||
| u64 Read(u32 address); | ||
| void Write(u32 address, u64 value); | ||
|
|
||
| void DoState(PointerWrap& p); | ||
|
|
||
| void RemoveDevice(); | ||
| void AddDevice(std::unique_ptr<IHSPDevice> device); | ||
| void AddDevice(HSPDeviceType device); | ||
| } // namespace HSP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright 2022 Dolphin Emulator Project | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #include "Core/HW/HSP/HSP_Device.h" | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "Core/HW/HSP/HSP_DeviceARAMExpansion.h" | ||
| #include "Core/HW/HSP/HSP_DeviceNull.h" | ||
|
|
||
| namespace HSP | ||
| { | ||
| IHSPDevice::IHSPDevice(HSPDeviceType device_type) : m_device_type(device_type) | ||
| { | ||
| } | ||
|
|
||
| HSPDeviceType IHSPDevice::GetDeviceType() const | ||
| { | ||
| return m_device_type; | ||
| } | ||
|
|
||
| void IHSPDevice::DoState(PointerWrap& p) | ||
| { | ||
| } | ||
|
|
||
| // F A C T O R Y | ||
| std::unique_ptr<IHSPDevice> HSPDevice_Create(const HSPDeviceType device) | ||
| { | ||
| switch (device) | ||
| { | ||
| case HSPDeviceType::ARAMExpansion: | ||
| return std::make_unique<CHSPDevice_ARAMExpansion>(device); | ||
| case HSPDeviceType::None: | ||
| default: | ||
| return std::make_unique<CHSPDevice_Null>(device); | ||
| } | ||
| } | ||
| } // namespace HSP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright 2022 Dolphin Emulator Project | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "Common/CommonTypes.h" | ||
|
|
||
| class PointerWrap; | ||
|
|
||
| namespace HSP | ||
| { | ||
| enum class HSPDeviceType : int | ||
| { | ||
| None, | ||
| ARAMExpansion, | ||
| }; | ||
|
|
||
| class IHSPDevice | ||
| { | ||
| public: | ||
| explicit IHSPDevice(HSPDeviceType device_type); | ||
| virtual ~IHSPDevice() = default; | ||
|
|
||
| HSPDeviceType GetDeviceType() const; | ||
|
|
||
| virtual void Write(u32 address, u64 value) = 0; | ||
| virtual u64 Read(u32 address) = 0; | ||
|
|
||
| // Savestate support | ||
| virtual void DoState(PointerWrap& p); | ||
|
|
||
| protected: | ||
| HSPDeviceType m_device_type; | ||
| }; | ||
|
|
||
| std::unique_ptr<IHSPDevice> HSPDevice_Create(HSPDeviceType device); | ||
|
|
||
| } // namespace HSP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright 2022 Dolphin Emulator Project | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #include "Core/HW/HSP/HSP_DeviceARAMExpansion.h" | ||
|
|
||
| #include <cstring> | ||
|
|
||
| #include "Common/ChunkFile.h" | ||
| #include "Common/MathUtil.h" | ||
| #include "Common/MemoryUtil.h" | ||
| #include "Common/Swap.h" | ||
|
|
||
| #include "Core/Config/MainSettings.h" | ||
|
|
||
| namespace HSP | ||
| { | ||
| CHSPDevice_ARAMExpansion::CHSPDevice_ARAMExpansion(HSPDeviceType device) : IHSPDevice(device) | ||
| { | ||
| m_size = MathUtil::NextPowerOf2(Config::Get(Config::MAIN_ARAM_EXPANSION_SIZE)); | ||
| m_mask = m_size - 1; | ||
| m_ptr = static_cast<u8*>(Common::AllocateMemoryPages(m_size)); | ||
| } | ||
|
|
||
| CHSPDevice_ARAMExpansion::~CHSPDevice_ARAMExpansion() | ||
| { | ||
| Common::FreeMemoryPages(m_ptr, m_size); | ||
| m_ptr = nullptr; | ||
| } | ||
|
|
||
| u64 CHSPDevice_ARAMExpansion::Read(u32 address) | ||
| { | ||
| u64 value; | ||
| std::memcpy(&value, &m_ptr[address & m_mask], sizeof(value)); | ||
| return Common::swap64(value); | ||
| } | ||
|
|
||
| void CHSPDevice_ARAMExpansion::Write(u32 address, u64 value) | ||
| { | ||
| value = Common::swap64(value); | ||
| std::memcpy(&value, &m_ptr[address & m_mask], sizeof(value)); | ||
| } | ||
|
|
||
| void CHSPDevice_ARAMExpansion::DoState(PointerWrap& p) | ||
| { | ||
| p.DoArray(m_ptr, m_size); | ||
| } | ||
|
|
||
| } // namespace HSP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright 2022 Dolphin Emulator Project | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "Core/HW/HSP/HSP_Device.h" | ||
|
|
||
| namespace HSP | ||
| { | ||
| class CHSPDevice_ARAMExpansion : public IHSPDevice | ||
| { | ||
| public: | ||
| explicit CHSPDevice_ARAMExpansion(HSPDeviceType device); | ||
| ~CHSPDevice_ARAMExpansion() override; | ||
|
|
||
| void Write(u32 address, u64 value) override; | ||
| u64 Read(u32 address) override; | ||
|
|
||
| void DoState(PointerWrap&) override; | ||
|
|
||
| private: | ||
| u32 m_size; | ||
| u32 m_mask; | ||
| u8* m_ptr = nullptr; | ||
| }; | ||
| } // namespace HSP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright 2022 Dolphin Emulator Project | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #include "Core/HW/HSP/HSP_DeviceNull.h" | ||
|
|
||
| #include <cstring> | ||
|
|
||
| #include "Core/HW/HSP/HSP.h" | ||
|
|
||
| namespace HSP | ||
| { | ||
| CHSPDevice_Null::CHSPDevice_Null(HSPDeviceType device) : IHSPDevice(device) | ||
| { | ||
| } | ||
|
|
||
| u64 CHSPDevice_Null::Read(u32 address) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| void CHSPDevice_Null::Write(u32 address, u64 value) | ||
| { | ||
| } | ||
|
|
||
| } // namespace HSP |
Oops, something went wrong.