Skip to content

Commit

Permalink
Misc: Make struct member functions file-local
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Nov 18, 2023
1 parent bee1f98 commit cce7be4
Show file tree
Hide file tree
Showing 39 changed files with 680 additions and 595 deletions.
42 changes: 22 additions & 20 deletions src/common/byte_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

Log_SetChannel(ByteStream);

namespace {
class FileByteStream : public ByteStream
{
public:
Expand Down Expand Up @@ -174,10 +175,7 @@ class FileByteStream : public ByteStream
return true;
}

u64 GetPosition() const override
{
return _ftelli64(m_pFile);
}
u64 GetPosition() const override { return _ftelli64(m_pFile); }

u64 GetSize() const override
{
Expand Down Expand Up @@ -232,10 +230,7 @@ class FileByteStream : public ByteStream
return true;
}

u64 GetPosition() const override
{
return static_cast<u64>(ftello(m_pFile));
}
u64 GetPosition() const override { return static_cast<u64>(ftello(m_pFile)); }

u64 GetSize() const override
{
Expand All @@ -262,15 +257,9 @@ class FileByteStream : public ByteStream
return true;
}

virtual bool Commit() override
{
return true;
}
virtual bool Commit() override { return true; }

virtual bool Discard() override
{
return false;
}
virtual bool Discard() override { return false; }

protected:
FILE* m_pFile;
Expand Down Expand Up @@ -364,10 +353,15 @@ class AtomicUpdatedFileByteStream final : public FileByteStream
std::string m_originalFileName;
std::string m_temporaryFileName;
};
} // namespace

NullByteStream::NullByteStream() {}
NullByteStream::NullByteStream()
{
}

NullByteStream::~NullByteStream() {}
NullByteStream::~NullByteStream()
{
}

bool NullByteStream::ReadByte(u8* pDestByte)
{
Expand Down Expand Up @@ -456,7 +450,9 @@ MemoryByteStream::MemoryByteStream(void* pMemory, u32 MemSize)
m_pMemory = (u8*)pMemory;
}

MemoryByteStream::~MemoryByteStream() {}
MemoryByteStream::~MemoryByteStream()
{
}

bool MemoryByteStream::ReadByte(u8* pDestByte)
{
Expand Down Expand Up @@ -586,7 +582,9 @@ ReadOnlyMemoryByteStream::ReadOnlyMemoryByteStream(const void* pMemory, u32 MemS
m_pMemory = reinterpret_cast<const u8*>(pMemory);
}

ReadOnlyMemoryByteStream::~ReadOnlyMemoryByteStream() {}
ReadOnlyMemoryByteStream::~ReadOnlyMemoryByteStream()
{
}

bool ReadOnlyMemoryByteStream::ReadByte(u8* pDestByte)
{
Expand Down Expand Up @@ -1346,6 +1344,7 @@ bool ByteStream::WriteBinaryToStream(ByteStream* stream, const void* data, size_
return stream->Write2(data, static_cast<u32>(data_length));
}

namespace {
class ZstdCompressStream final : public ByteStream
{
public:
Expand Down Expand Up @@ -1489,12 +1488,14 @@ class ZstdCompressStream final : public ByteStream
u8 m_input_buffer[INPUT_BUFFER_SIZE];
u8 m_output_buffer[OUTPUT_BUFFER_SIZE];
};
} // namespace

std::unique_ptr<ByteStream> ByteStream::CreateZstdCompressStream(ByteStream* src_stream, int compression_level)
{
return std::make_unique<ZstdCompressStream>(src_stream, compression_level);
}

namespace {
class ZstdDecompressStream final : public ByteStream
{
public:
Expand Down Expand Up @@ -1643,6 +1644,7 @@ class ZstdDecompressStream final : public ByteStream
u8 m_input_buffer[INPUT_BUFFER_SIZE];
u8 m_output_buffer[OUTPUT_BUFFER_SIZE];
};
} // namespace

std::unique_ptr<ByteStream> ByteStream::CreateZstdDecompressStream(ByteStream* src_stream, u32 compressed_size)
{
Expand Down
4 changes: 4 additions & 0 deletions src/common/crash_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "thirdparty/StackWalker.h"
#include <DbgHelp.h>

namespace {
class CrashHandlerStackWalker : public StackWalker
{
public:
Expand All @@ -26,6 +27,7 @@ class CrashHandlerStackWalker : public StackWalker
private:
HANDLE m_out_file;
};
} // namespace

CrashHandlerStackWalker::CrashHandlerStackWalker(HANDLE out_file)
: StackWalker(RetrieveVerbose, nullptr, GetCurrentProcessId(), GetCurrentProcess()), m_out_file(out_file)
Expand Down Expand Up @@ -213,12 +215,14 @@ void CrashHandler::Uninstall()
#include <unistd.h>

namespace CrashHandler {
namespace {
struct BacktraceBuffer
{
char* buffer;
size_t used;
size_t size;
};
} // namespace

static const char* GetSignalName(int signal_no);
static void AllocateBuffer(BacktraceBuffer* buf);
Expand Down
4 changes: 4 additions & 0 deletions src/core/cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
Log_SetChannel(CDROM);

namespace CDROM {
namespace {

enum : u32
{
RAW_SECTOR_OUTPUT_SIZE = CDImage::RAW_SECTOR_SIZE - CDImage::SECTOR_SYNC_SIZE,
Expand Down Expand Up @@ -210,6 +212,8 @@ union RequestRegister
BitField<u8, bool, 7, 1> BFRD;
};

} // namespace

static void SoftReset(TickCount ticks_late);

static bool IsDriveIdle();
Expand Down
81 changes: 41 additions & 40 deletions src/core/dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
Log_SetChannel(DMA);

namespace DMA {
namespace {

enum class SyncMode : u32
{
Manual = 0,
Expand All @@ -40,35 +42,6 @@ enum class SyncMode : u32
static constexpr PhysicalMemoryAddress BASE_ADDRESS_MASK = UINT32_C(0x00FFFFFF);
// static constexpr PhysicalMemoryAddress ADDRESS_MASK = UINT32_C(0x001FFFFC);

static u32 GetAddressMask();
static void ClearState();

// is everything enabled for a channel to operate?
static bool CanTransferChannel(Channel channel, bool ignore_halt);
static bool IsTransferHalted();
static void UpdateIRQ();

// returns false if the DMA should now be halted
static TickCount GetTransferSliceTicks();
static TickCount GetTransferHaltTicks();
static bool TransferChannel(Channel channel);
static void HaltTransfer(TickCount duration);
static void UnhaltTransfer(void*, TickCount ticks, TickCount ticks_late);

// from device -> memory
static TickCount TransferDeviceToMemory(Channel channel, u32 address, u32 increment, u32 word_count);

// from memory -> device
static TickCount TransferMemoryToDevice(Channel channel, u32 address, u32 increment, u32 word_count);

// configuration
static TickCount s_max_slice_ticks = 1000;
static TickCount s_halt_ticks = 100;

static std::vector<u32> s_transfer_buffer;
static std::unique_ptr<TimingEvent> s_unhalt_event;
static TickCount s_halt_ticks_remaining = 0;

struct ChannelState
{
u32 base_address = 0;
Expand Down Expand Up @@ -110,8 +83,6 @@ struct ChannelState
bool request = false;
};

static std::array<ChannelState, NUM_CHANNELS> s_state;

union DPCR
{
u32 bits;
Expand All @@ -133,15 +104,13 @@ union DPCR
BitField<u32, u8, 28, 3> priority_offset;
BitField<u32, bool, 31, 1> unused;

u8 GetPriority(Channel channel) const { return ((bits >> (static_cast<u8>(channel) * 4)) & u32(3)); }
bool GetMasterEnable(Channel channel) const
ALWAYS_INLINE u8 GetPriority(Channel channel) const { return ((bits >> (static_cast<u8>(channel) * 4)) & u32(3)); }
ALWAYS_INLINE bool GetMasterEnable(Channel channel) const
{
return ConvertToBoolUnchecked((bits >> (static_cast<u8>(channel) * 4 + 3)) & u32(1));
}
};

static DPCR s_DPCR = {};

static constexpr u32 DICR_WRITE_MASK = 0b00000000'11111111'10000000'00111111;
static constexpr u32 DICR_RESET_MASK = 0b01111111'00000000'00000000'00000000;
union DICR
Expand All @@ -166,25 +135,57 @@ union DICR
BitField<u32, bool, 30, 1> OTC_irq_flag;
BitField<u32, bool, 31, 1> master_flag;

bool IsIRQEnabled(Channel channel) const
ALWAYS_INLINE bool IsIRQEnabled(Channel channel) const
{
return ConvertToBoolUnchecked((bits >> (static_cast<u8>(channel) + 16)) & u32(1));
}

bool GetIRQFlag(Channel channel) const
ALWAYS_INLINE bool GetIRQFlag(Channel channel) const
{
return ConvertToBoolUnchecked((bits >> (static_cast<u8>(channel) + 24)) & u32(1));
}

void SetIRQFlag(Channel channel) { bits |= (u32(1) << (static_cast<u8>(channel) + 24)); }
void ClearIRQFlag(Channel channel) { bits &= ~(u32(1) << (static_cast<u8>(channel) + 24)); }
ALWAYS_INLINE void SetIRQFlag(Channel channel) { bits |= (u32(1) << (static_cast<u8>(channel) + 24)); }
ALWAYS_INLINE void ClearIRQFlag(Channel channel) { bits &= ~(u32(1) << (static_cast<u8>(channel) + 24)); }

void UpdateMasterFlag()
ALWAYS_INLINE void UpdateMasterFlag()
{
master_flag = master_enable && ((((bits >> 16) & u32(0b1111111)) & ((bits >> 24) & u32(0b1111111))) != 0);
}
};
} // namespace

static u32 GetAddressMask();
static void ClearState();

// is everything enabled for a channel to operate?
static bool CanTransferChannel(Channel channel, bool ignore_halt);
static bool IsTransferHalted();
static void UpdateIRQ();

// returns false if the DMA should now be halted
static TickCount GetTransferSliceTicks();
static TickCount GetTransferHaltTicks();
static bool TransferChannel(Channel channel);
static void HaltTransfer(TickCount duration);
static void UnhaltTransfer(void*, TickCount ticks, TickCount ticks_late);

// from device -> memory
static TickCount TransferDeviceToMemory(Channel channel, u32 address, u32 increment, u32 word_count);

// from memory -> device
static TickCount TransferMemoryToDevice(Channel channel, u32 address, u32 increment, u32 word_count);

// configuration
static TickCount s_max_slice_ticks = 1000;
static TickCount s_halt_ticks = 100;

static std::vector<u32> s_transfer_buffer;
static std::unique_ptr<TimingEvent> s_unhalt_event;
static TickCount s_halt_ticks_remaining = 0;

static std::array<ChannelState, NUM_CHANNELS> s_state;
static DPCR s_DPCR = {};
static DICR s_DICR = {};
}; // namespace DMA

Expand Down
2 changes: 1 addition & 1 deletion src/core/game_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static bool ParseJsonEntry(Entry* entry, const rapidjson::Value& value);
static bool ParseJsonCodes(u32 index, const rapidjson::Value& value);
static bool LoadTrackHashes();

std::array<const char*, static_cast<u32>(GameDatabase::Trait::Count)> s_trait_names = {{
static std::array<const char*, static_cast<u32>(GameDatabase::Trait::Count)> s_trait_names = {{
"ForceInterpreter",
"ForceSoftwareRenderer",
"ForceSoftwareRendererForReadbacks",
Expand Down
4 changes: 4 additions & 0 deletions src/core/game_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Log_SetChannel(GameList);
#endif

namespace GameList {
namespace {

enum : u32
{
GAME_LIST_CACHE_SIGNATURE = 0x45434C47,
Expand All @@ -54,6 +56,8 @@ struct PlayedTimeEntry
std::time_t total_played_time;
};

} // namespace

using CacheMap = PreferUnorderedStringMap<Entry>;
using PlayedTimeMap = PreferUnorderedStringMap<PlayedTimeEntry>;

Expand Down
Loading

0 comments on commit cce7be4

Please sign in to comment.