Skip to content

Commit

Permalink
Implement partial EXI backup support
Browse files Browse the repository at this point in the history
  • Loading branch information
Zopolis4 committed Feb 20, 2022
1 parent 0eaf6e8 commit 44bb7c5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions Source/Core/Common/CommonPaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/FileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<File::IOFile>(EEPROM_filename, "rb+");
}
else
{
m_EEPROM = std::make_unique<File::IOFile>(EEPROM_filename, "wb+");
}
}

CEXIBaseboard::~CEXIBaseboard()
{
m_EEPROM->Close();
File::Delete(EEPROM_filename);
}

void CEXIBaseboard::SetCS(int cs)
{
Expand All @@ -37,12 +59,23 @@ void CEXIBaseboard::TransferByte(u8& byte)
{
static constexpr std::array<u8, 4> 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:
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/HW/EXI/EXI_DeviceBaseboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "Core/HW/EXI/EXI_Device.h"

#include "Common/IOFile.h"

class PointerWrap;

namespace ExpansionInterface
Expand All @@ -13,19 +15,24 @@ 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<File::IOFile> m_EEPROM;

// STATE_TO_SAVE
bool m_have_irq;
u32 m_position = 0;
u32 m_command = 0;
u8* m_subcommand = (u8*)&m_command;
u32 m_irq_timer;
u32 m_irq_status;
int m_offset;

void TransferByte(u8& byte) override;
};
Expand Down
1 change: 1 addition & 0 deletions Source/Core/UICommon/UICommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 44bb7c5

Please sign in to comment.