diff --git a/src/common/cd_image.cpp b/src/common/cd_image.cpp
index 1b3d47878..28f5435e7 100644
--- a/src/common/cd_image.cpp
+++ b/src/common/cd_image.cpp
@@ -147,6 +147,30 @@ u32 CDImage::Read(ReadMode read_mode, u32 sector_count, void* buffer)
return sectors_read;
}
+bool CDImage::ReadRawSector(void* buffer)
+{
+ if (m_position_in_index == m_current_index->length)
+ {
+ if (!Seek(m_position_on_disc))
+ return false;
+ }
+
+ Assert(m_current_index->file);
+
+ // get raw sector
+ if (std::fread(buffer, RAW_SECTOR_SIZE, 1, m_current_index->file) != 1)
+ {
+ Log_ErrorPrintf("Read of LBA %u failed", m_position_on_disc);
+ Seek(m_position_on_disc);
+ return false;
+ }
+
+ m_position_on_disc++;
+ m_position_in_index++;
+ m_position_in_track++;
+ return true;
+}
+
const CDImage::Index* CDImage::GetIndexForDiscPosition(LBA pos)
{
for (const Index& index : m_indices)
diff --git a/src/common/cd_image.h b/src/common/cd_image.h
index ba85ea04e..e04645d11 100644
--- a/src/common/cd_image.h
+++ b/src/common/cd_image.h
@@ -123,6 +123,9 @@ public:
// Read from the current LBA. Returns the number of sectors read.
u32 Read(ReadMode read_mode, u32 sector_count, void* buffer);
+ // Read a single raw sector from the current LBA.
+ bool ReadRawSector(void* buffer);
+
protected:
struct Track
{
diff --git a/src/common/common.vcxproj b/src/common/common.vcxproj
index 11fdee829..5b647cf64 100644
--- a/src/common/common.vcxproj
+++ b/src/common/common.vcxproj
@@ -41,6 +41,7 @@
+
diff --git a/src/common/common.vcxproj.filters b/src/common/common.vcxproj.filters
index 393fb1f7f..a7bf0f289 100644
--- a/src/common/common.vcxproj.filters
+++ b/src/common/common.vcxproj.filters
@@ -11,6 +11,7 @@
+
@@ -26,4 +27,4 @@
-
+
\ No newline at end of file
diff --git a/src/common/heap_array.h b/src/common/heap_array.h
new file mode 100644
index 000000000..94ee4b4e0
--- /dev/null
+++ b/src/common/heap_array.h
@@ -0,0 +1,94 @@
+#pragma once
+#include
+#include
+
+template
+class HeapArray
+{
+public:
+ using value_type = T;
+ using size_type = std::size_t;
+ using difference_type = std::ptrdiff_t;
+ using reference = T&;
+ using const_reference = const T&;
+ using pointer = T*;
+ using const_pointer = const T*;
+ using this_type = typename HeapArray;
+
+ HeapArray() { m_data = new T[size]; }
+
+ HeapArray(const this_type& copy)
+ {
+ m_data = new T[size];
+ std::copy(copy.cbegin(), copy.cend(), begin());
+ }
+
+ HeapArray(const this_type&& move)
+ {
+ m_data = move.m_data;
+ move.m_data = nullptr;
+ }
+
+ ~HeapArray() { delete[] m_data; }
+
+ size_type size() const { return SIZE; }
+ size_type capacity() const { return SIZE; }
+ bool empty() const { return false; }
+
+ pointer begin() { return m_data; }
+ pointer end() { return m_data + SIZE; }
+
+ const_pointer data() const { return m_data; }
+ pointer data() { return m_data; }
+
+ const_pointer cbegin() const { return m_data; }
+ const_pointer cend() const { return m_data + SIZE; }
+
+ const_reference operator[](size_type index) const { return m_data[index]; }
+ reference operator[](size_type index) { return m_data[index]; }
+
+ const_reference front() const { return m_data[0]; }
+ const_reference back() const { return m_data[SIZE - 1]; }
+ reference front() { return m_data[0]; }
+ reference back() { return m_data[SIZE - 1]; }
+
+ void fill(const_reference value) { std::fill(begin(), end(), value); }
+
+ void swap(this_type& move) { std::swap(m_data, move.m_data); }
+
+ this_type& operator=(const this_type& rhs)
+ {
+ std::copy(begin(), end(), rhs.cbegin());
+ return *this;
+ }
+
+ this_type& operator=(const this_type&& move)
+ {
+ delete[] m_data;
+ m_data = move.m_data;
+ move.m_data = nullptr;
+ return *this;
+ }
+
+#define RELATIONAL_OPERATOR(op) \
+ bool operator##op(const this_type& rhs) const \
+ { \
+ for (size_type i = 0; i < SIZE; i++) \
+ { \
+ if (!(m_data[i] op rhs.m_data[i])) \
+ return false; \
+ } \
+ }
+
+ RELATIONAL_OPERATOR(==);
+ RELATIONAL_OPERATOR(!=);
+ RELATIONAL_OPERATOR(<);
+ RELATIONAL_OPERATOR(<=);
+ RELATIONAL_OPERATOR(>);
+ RELATIONAL_OPERATOR(>=);
+
+#undef RELATIONAL_OPERATOR
+
+private:
+ T* m_data;
+};
\ No newline at end of file
diff --git a/src/common/state_wrapper.h b/src/common/state_wrapper.h
index 073b40072..b4964e0cd 100644
--- a/src/common/state_wrapper.h
+++ b/src/common/state_wrapper.h
@@ -1,6 +1,7 @@
#pragma once
#include "YBaseLib/ByteStream.h"
#include "fifo_queue.h"
+#include "heap_array.h"
#include "types.h"
#include
#include
@@ -110,6 +111,12 @@ public:
DoArray(data->data(), data->size());
}
+ template
+ void Do(HeapArray* data)
+ {
+ DoArray(data->data(), data->size());
+ }
+
template
void Do(std::vector* data)
{