diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index 1482b9656cc7..4e4a6c1c4aa7 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -34,6 +34,7 @@ // Subdirs in the User dir returned by GetUserPath(D_USER_IDX) #define GC_USER_DIR "GC" +#define TRI_USER_DIR "Triforce" #define GBA_USER_DIR "GBA" #define WII_USER_DIR "Wii" #define CONFIG_DIR "Config" diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index d84b725e70b9..194f1e587e8d 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -932,6 +932,7 @@ static void RebuildUserDirectories(unsigned int dir_index) { case D_USER_IDX: s_user_paths[D_GCUSER_IDX] = s_user_paths[D_USER_IDX] + GC_USER_DIR DIR_SEP; + s_user_paths[D_TRIUSER_IDX] = s_user_paths[D_USER_IDX] + TRI_USER_DIR DIR_SEP; s_user_paths[D_WIIROOT_IDX] = s_user_paths[D_USER_IDX] + WII_USER_DIR DIR_SEP; s_user_paths[D_CONFIG_IDX] = s_user_paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; s_user_paths[D_GAMESETTINGS_IDX] = s_user_paths[D_USER_IDX] + GAMESETTINGS_DIR DIR_SEP; diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index 0542cb3402fd..83a78e64e4f8 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -27,6 +27,7 @@ enum { D_USER_IDX, D_GCUSER_IDX, + D_TRIUSER_IDX, D_WIIROOT_IDX, // always points to User/Wii or global user-configured directory D_SESSION_WIIROOT_IDX, // may point to minimal temporary directory for determinism D_CONFIG_IDX, // global settings diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.cpp index 714698a5e29b..8ad163d0389d 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.cpp @@ -5,12 +5,34 @@ #include "Common/Assert.h" #include "Common/ChunkFile.h" +#include "Common/CommonPaths.h" #include "Common/CommonTypes.h" +#include "Common/FileUtil.h" +#include "Common/IOFile.h" #include "Common/Logging/Log.h" namespace ExpansionInterface { -CEXIBaseboard::CEXIBaseboard() = default; +CEXIBaseboard::CEXIBaseboard() +{ + m_position = 0; + m_have_irq = false; + EEPROM_filename = File::GetUserPath(D_TRIUSER_IDX) + "EEPROM.raw"; + if (File::Exists(EEPROM_filename)) + { + m_EEPROM = std::make_unique(EEPROM_filename, "rb+"); + } + else + { + m_EEPROM = std::make_unique(EEPROM_filename, "wb+"); + } +} + +CEXIBaseboard::~CEXIBaseboard() +{ + m_EEPROM->Close(); + File::Delete(EEPROM_filename); +} void CEXIBaseboard::SetCS(int cs) { @@ -37,12 +59,23 @@ void CEXIBaseboard::TransferByte(u8& byte) { static constexpr std::array ID = {0x06, 0x04, 0x10, 0x00}; byte = ID[(m_position - 2) & 3]; + INFO_LOG_FMT(EXPANSIONINTERFACE, "EXI BASEBOARD: ID Check {:#x} {:#x})", m_command, + m_position); break; } case 0x01: + m_offset = (m_subcommand[1] << 8 | (m_subcommand[2])); + m_EEPROM->Seek(m_offset, SEEK_SET); byte = 0x01; + WARN_LOG_FMT(EXPANSIONINTERFACE, "EXI BASEBOARD: Backup Offset {:#x} {:#x} (Offset: {:#x})", + m_command, m_position, m_offset); break; case 0x02: + m_EEPROM->WriteBytes(&m_subcommand[1], 1); + m_EEPROM->Flush(); + WARN_LOG_FMT(EXPANSIONINTERFACE, + "EXI BASEBOARD: Backup Write {:#x} {:#x} (Target: {:#x}-{:#x})", m_command, + m_position, m_offset, m_subcommand[1]); byte = 0x01; break; case 0x03: diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.h b/Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.h index 687ff110cc5a..2bc871c8199c 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.h +++ b/Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.h @@ -5,6 +5,8 @@ #include "Core/HW/EXI/EXI_Device.h" +#include "Common/IOFile.h" + class PointerWrap; namespace ExpansionInterface @@ -13,12 +15,16 @@ class CEXIBaseboard : public IEXIDevice { public: CEXIBaseboard(); + ~CEXIBaseboard(); void SetCS(int CS) override; bool IsPresent() const override; bool IsInterruptSet(); void DoState(PointerWrap& p) override; private: + std::string EEPROM_filename; + std::unique_ptr m_EEPROM; + // STATE_TO_SAVE bool m_have_irq; u32 m_position = 0; @@ -26,6 +32,7 @@ class CEXIBaseboard : public IEXIDevice u8* m_subcommand = (u8*)&m_command; u32 m_irq_timer; u32 m_irq_status; + int m_offset; void TransferByte(u8& byte) override; }; diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index a5f072125139..62f27ce41251 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -203,6 +203,7 @@ void CreateDirectories() File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX)); File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX) + ANAGLYPH_DIR DIR_SEP); File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX)); + File::CreateFullPath(File::GetUserPath(D_TRIUSER_IDX)); #ifndef ANDROID File::CreateFullPath(File::GetUserPath(D_THEMES_IDX)); File::CreateFullPath(File::GetUserPath(D_STYLES_IDX));