mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-30 09:35:40 +00:00
cd_image: Make use of std::array where applicable
Simplifies array copies.
This commit is contained in:
parent
840a80670f
commit
0abe4c60b4
|
@ -308,7 +308,7 @@ void CDImage::AddLeadOutIndex()
|
||||||
m_indices.push_back(index);
|
m_indices.push_back(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 CDImage::SubChannelQ::ComputeCRC(const u8* data)
|
u16 CDImage::SubChannelQ::ComputeCRC(const Data& data)
|
||||||
{
|
{
|
||||||
static constexpr std::array<u16, 256> crc16_table = {
|
static constexpr std::array<u16, 256> crc16_table = {
|
||||||
{0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD,
|
{0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "bitfield.h"
|
#include "bitfield.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
@ -118,6 +119,8 @@ public:
|
||||||
|
|
||||||
union SubChannelQ
|
union SubChannelQ
|
||||||
{
|
{
|
||||||
|
using Data = std::array<u8, SUBCHANNEL_BYTES_PER_FRAME>;
|
||||||
|
|
||||||
union Control
|
union Control
|
||||||
{
|
{
|
||||||
u8 bits;
|
u8 bits;
|
||||||
|
@ -144,15 +147,15 @@ public:
|
||||||
u16 crc;
|
u16 crc;
|
||||||
};
|
};
|
||||||
|
|
||||||
u8 data[SUBCHANNEL_BYTES_PER_FRAME];
|
Data data;
|
||||||
|
|
||||||
static u16 ComputeCRC(const u8* data);
|
static u16 ComputeCRC(const Data& data);
|
||||||
|
|
||||||
bool IsCRCValid() const;
|
bool IsCRCValid() const;
|
||||||
|
|
||||||
SubChannelQ& operator=(const SubChannelQ& q)
|
SubChannelQ& operator=(const SubChannelQ& q)
|
||||||
{
|
{
|
||||||
std::copy(q.data, q.data + SUBCHANNEL_BYTES_PER_FRAME, data);
|
data = q.data;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,7 +72,7 @@ bool CDSubChannelReplacement::LoadSBI(const char* path)
|
||||||
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.data()) ^ 0xFFFF;
|
const u16 crc = CDImage::SubChannelQ::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);
|
||||||
|
|
||||||
|
@ -83,17 +83,18 @@ bool CDSubChannelReplacement::LoadSBI(const char* path)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd, u8* subq_data) const
|
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd,
|
||||||
|
ReplacementData& subq_data) const
|
||||||
{
|
{
|
||||||
return GetReplacementSubChannelQ(MSFToLBA(minute_bcd, second_bcd, frame_bcd), subq_data);
|
return GetReplacementSubChannelQ(MSFToLBA(minute_bcd, second_bcd, frame_bcd), subq_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u32 lba, u8* subq_data) const
|
bool CDSubChannelReplacement::GetReplacementSubChannelQ(u32 lba, ReplacementData& subq_data) const
|
||||||
{
|
{
|
||||||
ReplacementMap::const_iterator iter = m_replacement_subq.find(lba);
|
const auto iter = m_replacement_subq.find(lba);
|
||||||
if (iter == m_replacement_subq.end())
|
if (iter == m_replacement_subq.cend())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::copy(iter->second.begin(), iter->second.end(), subq_data);
|
subq_data = iter->second;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ public:
|
||||||
SUBCHANNEL_Q_SIZE = 12,
|
SUBCHANNEL_Q_SIZE = 12,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using ReplacementData = std::array<u8, SUBCHANNEL_Q_SIZE>;
|
||||||
|
|
||||||
CDSubChannelReplacement();
|
CDSubChannelReplacement();
|
||||||
~CDSubChannelReplacement();
|
~CDSubChannelReplacement();
|
||||||
|
|
||||||
|
@ -21,14 +23,13 @@ public:
|
||||||
bool LoadSBI(const char* path);
|
bool LoadSBI(const char* path);
|
||||||
|
|
||||||
/// 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, u8* subq_data) const;
|
bool GetReplacementSubChannelQ(u8 minute_bcd, u8 second_bcd, u8 frame_bcd, ReplacementData& subq_data) const;
|
||||||
|
|
||||||
/// Returns the replacement subchannel data for the specified sector.
|
/// Returns the replacement subchannel data for the specified sector.
|
||||||
bool GetReplacementSubChannelQ(u32 lba, u8* subq_data) const;
|
bool GetReplacementSubChannelQ(u32 lba, ReplacementData& subq_data) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using ReplacementData = std::array<u8, SUBCHANNEL_Q_SIZE>;
|
|
||||||
using ReplacementMap = std::unordered_map<u32, ReplacementData>;
|
using ReplacementMap = std::unordered_map<u32, ReplacementData>;
|
||||||
|
|
||||||
std::unordered_map<u32, ReplacementData> m_replacement_subq;
|
ReplacementMap m_replacement_subq;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue