mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-23 14:25:37 +00:00
CDSubChannelReplacement: Use subq union directly
This commit is contained in:
parent
93528db388
commit
03c3b10054
|
@ -108,7 +108,7 @@ bool CDImageBin::Open(const char* filename)
|
||||||
|
|
||||||
bool CDImageBin::ReadSubChannelQ(SubChannelQ* subq)
|
bool CDImageBin::ReadSubChannelQ(SubChannelQ* subq)
|
||||||
{
|
{
|
||||||
if (m_sbi.GetReplacementSubChannelQ(m_position_on_disc, subq->data))
|
if (m_sbi.GetReplacementSubChannelQ(m_position_on_disc, subq))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return CDImage::ReadSubChannelQ(subq);
|
return CDImage::ReadSubChannelQ(subq);
|
||||||
|
|
|
@ -231,7 +231,7 @@ bool CDImageCHD::Open(const char* filename)
|
||||||
|
|
||||||
bool CDImageCHD::ReadSubChannelQ(SubChannelQ* subq)
|
bool CDImageCHD::ReadSubChannelQ(SubChannelQ* subq)
|
||||||
{
|
{
|
||||||
if (m_sbi.GetReplacementSubChannelQ(m_position_on_disc, subq->data))
|
if (m_sbi.GetReplacementSubChannelQ(m_position_on_disc, subq))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// TODO: Read subchannel data from CHD
|
// TODO: Read subchannel data from CHD
|
||||||
|
|
|
@ -219,7 +219,7 @@ bool CDImageCueSheet::OpenAndParse(const char* filename)
|
||||||
|
|
||||||
bool CDImageCueSheet::ReadSubChannelQ(SubChannelQ* subq)
|
bool CDImageCueSheet::ReadSubChannelQ(SubChannelQ* subq)
|
||||||
{
|
{
|
||||||
if (m_sbi.GetReplacementSubChannelQ(m_position_on_disc, subq->data))
|
if (m_sbi.GetReplacementSubChannelQ(m_position_on_disc, subq))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return CDImage::ReadSubChannelQ(subq);
|
return CDImage::ReadSubChannelQ(subq);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "cd_subchannel_replacement.h"
|
#include "cd_subchannel_replacement.h"
|
||||||
#include "log.h"
|
|
||||||
#include "file_system.h"
|
#include "file_system.h"
|
||||||
|
#include "log.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
Log_SetChannel(CDSubChannelReplacement);
|
Log_SetChannel(CDSubChannelReplacement);
|
||||||
|
@ -68,33 +68,42 @@ bool CDSubChannelReplacement::LoadSBI(const char* path)
|
||||||
|
|
||||||
const u32 lba = MSFToLBA(entry.minute_bcd, entry.second_bcd, entry.frame_bcd);
|
const u32 lba = MSFToLBA(entry.minute_bcd, entry.second_bcd, entry.frame_bcd);
|
||||||
|
|
||||||
ReplacementData subq_data;
|
CDImage::SubChannelQ subq;
|
||||||
std::copy_n(entry.data, countof(entry.data), subq_data.data());
|
std::copy_n(entry.data, countof(entry.data), subq.data.data());
|
||||||
|
|
||||||
// generate an invalid crc by flipping all bits from the valid crc (will never collide)
|
// generate an invalid crc by flipping all bits from the valid crc (will never collide)
|
||||||
const u16 crc = CDImage::SubChannelQ::ComputeCRC(subq_data) ^ 0xFFFF;
|
const u16 crc = subq.ComputeCRC(subq.data) ^ 0xFFFF;
|
||||||
subq_data[10] = Truncate8(crc);
|
subq.data[10] = Truncate8(crc);
|
||||||
subq_data[11] = Truncate8(crc >> 8);
|
subq.data[11] = Truncate8(crc >> 8);
|
||||||
|
|
||||||
m_replacement_subq.emplace(lba, subq_data);
|
m_replacement_subq.emplace(lba, subq);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log_InfoPrintf("Loaded %zu replacement sectors from '%s'", m_replacement_subq.size(), path);
|
Log_InfoPrintf("Loaded %zu replacement sectors from '%s'", m_replacement_subq.size(), path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd,
|
void CDSubChannelReplacement::AddReplacementSubChannelQ(u32 lba, const CDImage::SubChannelQ& subq)
|
||||||
ReplacementData& subq_data) const
|
|
||||||
{
|
{
|
||||||
return GetReplacementSubChannelQ(MSFToLBA(minute_bcd, second_bcd, frame_bcd), subq_data);
|
auto iter = m_replacement_subq.find(lba);
|
||||||
|
if (iter != m_replacement_subq.end())
|
||||||
|
iter->second.data = subq.data;
|
||||||
|
else
|
||||||
|
m_replacement_subq.emplace(lba, subq);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u32 lba, ReplacementData& subq_data) const
|
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd,
|
||||||
|
CDImage::SubChannelQ* subq) const
|
||||||
|
{
|
||||||
|
return GetReplacementSubChannelQ(MSFToLBA(minute_bcd, second_bcd, frame_bcd), subq);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u32 lba, CDImage::SubChannelQ* subq) const
|
||||||
{
|
{
|
||||||
const auto iter = m_replacement_subq.find(lba);
|
const auto iter = m_replacement_subq.find(lba);
|
||||||
if (iter == m_replacement_subq.cend())
|
if (iter == m_replacement_subq.cend())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
subq_data = iter->second;
|
*subq = iter->second;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,6 @@
|
||||||
class CDSubChannelReplacement
|
class CDSubChannelReplacement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum : u32
|
|
||||||
{
|
|
||||||
SUBCHANNEL_Q_SIZE = 12,
|
|
||||||
};
|
|
||||||
|
|
||||||
using ReplacementData = std::array<u8, SUBCHANNEL_Q_SIZE>;
|
|
||||||
|
|
||||||
CDSubChannelReplacement();
|
CDSubChannelReplacement();
|
||||||
~CDSubChannelReplacement();
|
~CDSubChannelReplacement();
|
||||||
|
|
||||||
|
@ -22,14 +15,17 @@ public:
|
||||||
|
|
||||||
bool LoadSBI(const char* path);
|
bool LoadSBI(const char* path);
|
||||||
|
|
||||||
|
/// Adds a sector to the replacement map.
|
||||||
|
void AddReplacementSubChannelQ(u32 lba, const CDImage::SubChannelQ& subq);
|
||||||
|
|
||||||
/// Returns the replacement subchannel data for the specified position (in BCD).
|
/// Returns the replacement subchannel data for the specified position (in BCD).
|
||||||
bool GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd, ReplacementData& subq_data) const;
|
bool GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd, CDImage::SubChannelQ* subq) const;
|
||||||
|
|
||||||
/// Returns the replacement subchannel data for the specified sector.
|
/// Returns the replacement subchannel data for the specified sector.
|
||||||
bool GetReplacementSubChannelQ(u32 lba, ReplacementData& subq_data) const;
|
bool GetReplacementSubChannelQ(u32 lba, CDImage::SubChannelQ* subq) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using ReplacementMap = std::unordered_map<u32, ReplacementData>;
|
using ReplacementMap = std::unordered_map<u32, CDImage::SubChannelQ>;
|
||||||
|
|
||||||
ReplacementMap m_replacement_subq;
|
ReplacementMap m_replacement_subq;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue