Misc: Make struct member functions file-local

This commit is contained in:
Stenzek
2023-11-18 16:21:51 +10:00
parent bee1f986a9
commit cce7be4723
39 changed files with 680 additions and 595 deletions

View File

@@ -32,6 +32,8 @@
Log_SetChannel(CDROM);
namespace CDROM {
namespace {
enum : u32
{
RAW_SECTOR_OUTPUT_SIZE = CDImage::RAW_SECTOR_SIZE - CDImage::SECTOR_SYNC_SIZE,
@@ -210,6 +212,8 @@ union RequestRegister
BitField<u8, bool, 7, 1> BFRD;
};
} // namespace
static void SoftReset(TickCount ticks_late);
static bool IsDriveIdle();

View File

@@ -29,6 +29,8 @@
Log_SetChannel(DMA);
namespace DMA {
namespace {
enum class SyncMode : u32
{
Manual = 0,
@@ -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;
@@ -110,8 +83,6 @@ struct ChannelState
bool request = false;
};
static std::array<ChannelState, NUM_CHANNELS> s_state;
union DPCR
{
u32 bits;
@@ -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
@@ -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

View File

@@ -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",

View File

@@ -36,6 +36,8 @@ Log_SetChannel(GameList);
#endif
namespace GameList {
namespace {
enum : u32
{
GAME_LIST_CACHE_SIGNATURE = 0x45434C47,
@@ -54,6 +56,8 @@ struct PlayedTimeEntry
std::time_t total_played_time;
};
} // namespace
using CacheMap = PreferUnorderedStringMap<Entry>;
using PlayedTimeMap = PreferUnorderedStringMap<PlayedTimeEntry>;

View File

@@ -162,24 +162,67 @@ ALWAYS_INLINE static u32 TruncateRGB(s32 value)
return static_cast<u32>(value);
}
void Initialize()
static void SetOTZ(s32 value);
static void PushSXY(s32 x, s32 y);
static void PushSZ(s32 value);
static void PushRGBFromMAC();
static u32 UNRDivide(u32 lhs, u32 rhs);
static void MulMatVec(const s16* M_, const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm);
static void MulMatVec(const s16* M_, const s32 T[3], const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm);
static void MulMatVecBuggy(const s16* M_, const s32 T[3], const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm);
static void InterpolateColor(s64 in_MAC1, s64 in_MAC2, s64 in_MAC3, u8 shift, bool lm);
static void RTPS(const s16 V[3], u8 shift, bool lm, bool last);
static void NCS(const s16 V[3], u8 shift, bool lm);
static void NCCS(const s16 V[3], u8 shift, bool lm);
static void NCDS(const s16 V[3], u8 shift, bool lm);
static void DPCS(const u8 color[3], u8 shift, bool lm);
static void Execute_MVMVA(Instruction inst);
static void Execute_SQR(Instruction inst);
static void Execute_OP(Instruction inst);
static void Execute_RTPS(Instruction inst);
static void Execute_RTPT(Instruction inst);
static void Execute_NCLIP(Instruction inst);
static void Execute_NCLIP_PGXP(Instruction inst);
static void Execute_AVSZ3(Instruction inst);
static void Execute_AVSZ4(Instruction inst);
static void Execute_NCS(Instruction inst);
static void Execute_NCT(Instruction inst);
static void Execute_NCCS(Instruction inst);
static void Execute_NCCT(Instruction inst);
static void Execute_NCDS(Instruction inst);
static void Execute_NCDT(Instruction inst);
static void Execute_CC(Instruction inst);
static void Execute_CDP(Instruction inst);
static void Execute_DPCS(Instruction inst);
static void Execute_DPCT(Instruction inst);
static void Execute_DCPL(Instruction inst);
static void Execute_INTPL(Instruction inst);
static void Execute_GPL(Instruction inst);
static void Execute_GPF(Instruction inst);
} // namespace GTE
void GTE::Initialize()
{
s_aspect_ratio = DisplayAspectRatio::R4_3;
Reset();
}
void Reset()
void GTE::Reset()
{
std::memset(&REGS, 0, sizeof(REGS));
}
bool DoState(StateWrapper& sw)
bool GTE::DoState(StateWrapper& sw)
{
sw.DoArray(REGS.r32, NUM_DATA_REGS + NUM_CONTROL_REGS);
return !sw.HasError();
}
void UpdateAspectRatio()
void GTE::UpdateAspectRatio()
{
if (!g_settings.gpu_widescreen_hack)
{
@@ -227,7 +270,7 @@ void UpdateAspectRatio()
s_custom_aspect_ratio_f = static_cast<float>((4.0 / 3.0) / (static_cast<double>(num) / static_cast<double>(denom)));
}
u32 ReadRegister(u32 index)
u32 GTE::ReadRegister(u32 index)
{
DebugAssert(index < countof(REGS.r32));
@@ -254,7 +297,7 @@ u32 ReadRegister(u32 index)
}
}
void WriteRegister(u32 index, u32 value)
void GTE::WriteRegister(u32 index, u32 value)
{
#if 0
if (index < 32)
@@ -349,12 +392,12 @@ void WriteRegister(u32 index, u32 value)
}
}
u32* GetRegisterPtr(u32 index)
u32* GTE::GetRegisterPtr(u32 index)
{
return &REGS.r32[index];
}
ALWAYS_INLINE static void SetOTZ(s32 value)
ALWAYS_INLINE void GTE::SetOTZ(s32 value)
{
if (value < 0)
{
@@ -370,7 +413,7 @@ ALWAYS_INLINE static void SetOTZ(s32 value)
REGS.dr32[7] = static_cast<u32>(value);
}
ALWAYS_INLINE static void PushSXY(s32 x, s32 y)
ALWAYS_INLINE void GTE::PushSXY(s32 x, s32 y)
{
if (x < -1024)
{
@@ -399,7 +442,7 @@ ALWAYS_INLINE static void PushSXY(s32 x, s32 y)
REGS.dr32[14] = (static_cast<u32>(x) & 0xFFFFu) | (static_cast<u32>(y) << 16);
}
ALWAYS_INLINE static void PushSZ(s32 value)
ALWAYS_INLINE void GTE::PushSZ(s32 value)
{
if (value < 0)
{
@@ -418,7 +461,7 @@ ALWAYS_INLINE static void PushSZ(s32 value)
REGS.dr32[19] = static_cast<u32>(value); // SZ3 <- value
}
static void PushRGBFromMAC()
ALWAYS_INLINE void GTE::PushRGBFromMAC()
{
// Note: SHR 4 used instead of /16 as the results are different.
const u32 r = TruncateRGB<0>(static_cast<u32>(REGS.MAC1 >> 4));
@@ -431,7 +474,7 @@ static void PushRGBFromMAC()
REGS.dr32[22] = r | (g << 8) | (b << 16) | (c << 24); // RGB2 <- Value
}
ALWAYS_INLINE static u32 UNRDivide(u32 lhs, u32 rhs)
ALWAYS_INLINE u32 GTE::UNRDivide(u32 lhs, u32 rhs)
{
if (rhs * 2 <= lhs)
{
@@ -475,7 +518,7 @@ ALWAYS_INLINE static u32 UNRDivide(u32 lhs, u32 rhs)
return std::min<u32>(0x1FFFF, result);
}
static void MulMatVec(const s16* M_, const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm)
void GTE::MulMatVec(const s16* M_, const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm)
{
#define M(i, j) M_[((i)*3) + (j)]
#define dot3(i) \
@@ -491,7 +534,7 @@ static void MulMatVec(const s16* M_, const s16 Vx, const s16 Vy, const s16 Vz, u
#undef M
}
static void MulMatVec(const s16* M_, const s32 T[3], const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm)
void GTE::MulMatVec(const s16* M_, const s32 T[3], const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm)
{
#define M(i, j) M_[((i)*3) + (j)]
#define dot3(i) \
@@ -509,7 +552,7 @@ static void MulMatVec(const s16* M_, const s32 T[3], const s16 Vx, const s16 Vy,
#undef M
}
static void MulMatVecBuggy(const s16* M_, const s32 T[3], const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm)
void GTE::MulMatVecBuggy(const s16* M_, const s32 T[3], const s16 Vx, const s16 Vy, const s16 Vz, u8 shift, bool lm)
{
#define M(i, j) M_[((i)*3) + (j)]
#define dot3(i) \
@@ -531,7 +574,7 @@ static void MulMatVecBuggy(const s16* M_, const s32 T[3], const s16 Vx, const s1
#undef M
}
static void Execute_MVMVA(Instruction inst)
void GTE::Execute_MVMVA(Instruction inst)
{
REGS.FLAG.Clear();
@@ -576,7 +619,7 @@ static void Execute_MVMVA(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_SQR(Instruction inst)
void GTE::Execute_SQR(Instruction inst)
{
REGS.FLAG.Clear();
@@ -594,7 +637,7 @@ static void Execute_SQR(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_OP(Instruction inst)
void GTE::Execute_OP(Instruction inst)
{
REGS.FLAG.Clear();
@@ -617,7 +660,7 @@ static void Execute_OP(Instruction inst)
REGS.FLAG.UpdateError();
}
static void RTPS(const s16 V[3], u8 shift, bool lm, bool last)
void GTE::RTPS(const s16 V[3], u8 shift, bool lm, bool last)
{
#define dot3(i) \
SignExtendMACResult<i + 1>(SignExtendMACResult<i + 1>((s64(REGS.TR[i]) << 12) + (s64(REGS.RT[i][0]) * s64(V[0]))) + \
@@ -763,14 +806,14 @@ static void RTPS(const s16 V[3], u8 shift, bool lm, bool last)
}
}
static void Execute_RTPS(Instruction inst)
void GTE::Execute_RTPS(Instruction inst)
{
REGS.FLAG.Clear();
RTPS(REGS.V0, inst.GetShift(), inst.lm, true);
REGS.FLAG.UpdateError();
}
static void Execute_RTPT(Instruction inst)
void GTE::Execute_RTPT(Instruction inst)
{
REGS.FLAG.Clear();
@@ -784,7 +827,7 @@ static void Execute_RTPT(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_NCLIP(Instruction inst)
void GTE::Execute_NCLIP(Instruction inst)
{
// MAC0 = SX0*SY1 + SX1*SY2 + SX2*SY0 - SX0*SY2 - SX1*SY0 - SX2*SY1
REGS.FLAG.Clear();
@@ -797,7 +840,7 @@ static void Execute_NCLIP(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_NCLIP_PGXP(Instruction inst)
void GTE::Execute_NCLIP_PGXP(Instruction inst)
{
if (PGXP::GTE_NCLIP_valid(REGS.dr32[12], REGS.dr32[13], REGS.dr32[14]))
{
@@ -810,7 +853,7 @@ static void Execute_NCLIP_PGXP(Instruction inst)
}
}
static void Execute_AVSZ3(Instruction inst)
void GTE::Execute_AVSZ3(Instruction inst)
{
REGS.FLAG.Clear();
@@ -821,7 +864,7 @@ static void Execute_AVSZ3(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_AVSZ4(Instruction inst)
void GTE::Execute_AVSZ4(Instruction inst)
{
REGS.FLAG.Clear();
@@ -832,7 +875,7 @@ static void Execute_AVSZ4(Instruction inst)
REGS.FLAG.UpdateError();
}
static ALWAYS_INLINE void InterpolateColor(s64 in_MAC1, s64 in_MAC2, s64 in_MAC3, u8 shift, bool lm)
ALWAYS_INLINE void GTE::InterpolateColor(s64 in_MAC1, s64 in_MAC2, s64 in_MAC3, u8 shift, bool lm)
{
// [MAC1,MAC2,MAC3] = MAC+(FC-MAC)*IR0
// [IR1,IR2,IR3] = (([RFC,GFC,BFC] SHL 12) - [MAC1,MAC2,MAC3]) SAR (sf*12)
@@ -847,7 +890,7 @@ static ALWAYS_INLINE void InterpolateColor(s64 in_MAC1, s64 in_MAC2, s64 in_MAC3
TruncateAndSetMACAndIR<3>(s64(s32(REGS.IR3) * s32(REGS.IR0)) + in_MAC3, shift, lm);
}
static void NCS(const s16 V[3], u8 shift, bool lm)
void GTE::NCS(const s16 V[3], u8 shift, bool lm)
{
// [IR1,IR2,IR3] = [MAC1,MAC2,MAC3] = (LLM*V0) SAR (sf*12)
MulMatVec(&REGS.LLM[0][0], V[0], V[1], V[2], shift, lm);
@@ -859,7 +902,7 @@ static void NCS(const s16 V[3], u8 shift, bool lm)
PushRGBFromMAC();
}
static void Execute_NCS(Instruction inst)
void GTE::Execute_NCS(Instruction inst)
{
REGS.FLAG.Clear();
@@ -868,7 +911,7 @@ static void Execute_NCS(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_NCT(Instruction inst)
void GTE::Execute_NCT(Instruction inst)
{
REGS.FLAG.Clear();
@@ -882,7 +925,7 @@ static void Execute_NCT(Instruction inst)
REGS.FLAG.UpdateError();
}
static void NCCS(const s16 V[3], u8 shift, bool lm)
void GTE::NCCS(const s16 V[3], u8 shift, bool lm)
{
// [IR1,IR2,IR3] = [MAC1,MAC2,MAC3] = (LLM*V0) SAR (sf*12)
MulMatVec(&REGS.LLM[0][0], V[0], V[1], V[2], shift, lm);
@@ -900,7 +943,7 @@ static void NCCS(const s16 V[3], u8 shift, bool lm)
PushRGBFromMAC();
}
static void Execute_NCCS(Instruction inst)
void GTE::Execute_NCCS(Instruction inst)
{
REGS.FLAG.Clear();
@@ -909,7 +952,7 @@ static void Execute_NCCS(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_NCCT(Instruction inst)
void GTE::Execute_NCCT(Instruction inst)
{
REGS.FLAG.Clear();
@@ -923,7 +966,7 @@ static void Execute_NCCT(Instruction inst)
REGS.FLAG.UpdateError();
}
static void NCDS(const s16 V[3], u8 shift, bool lm)
void GTE::NCDS(const s16 V[3], u8 shift, bool lm)
{
// [IR1,IR2,IR3] = [MAC1,MAC2,MAC3] = (LLM*V0) SAR (sf*12)
MulMatVec(&REGS.LLM[0][0], V[0], V[1], V[2], shift, lm);
@@ -944,7 +987,7 @@ static void NCDS(const s16 V[3], u8 shift, bool lm)
PushRGBFromMAC();
}
static void Execute_NCDS(Instruction inst)
void GTE::Execute_NCDS(Instruction inst)
{
REGS.FLAG.Clear();
@@ -953,7 +996,7 @@ static void Execute_NCDS(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_NCDT(Instruction inst)
void GTE::Execute_NCDT(Instruction inst)
{
REGS.FLAG.Clear();
@@ -967,7 +1010,7 @@ static void Execute_NCDT(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_CC(Instruction inst)
void GTE::Execute_CC(Instruction inst)
{
REGS.FLAG.Clear();
@@ -989,7 +1032,7 @@ static void Execute_CC(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_CDP(Instruction inst)
void GTE::Execute_CDP(Instruction inst)
{
REGS.FLAG.Clear();
@@ -1015,7 +1058,7 @@ static void Execute_CDP(Instruction inst)
REGS.FLAG.UpdateError();
}
static void DPCS(const u8 color[3], u8 shift, bool lm)
void GTE::DPCS(const u8 color[3], u8 shift, bool lm)
{
// In: [IR1,IR2,IR3]=Vector, FC=Far Color, IR0=Interpolation value, CODE=MSB of RGBC
// [MAC1,MAC2,MAC3] = [R,G,B] SHL 16 ;<--- for DPCS/DPCT
@@ -1030,7 +1073,7 @@ static void DPCS(const u8 color[3], u8 shift, bool lm)
PushRGBFromMAC();
}
static void Execute_DPCS(Instruction inst)
void GTE::Execute_DPCS(Instruction inst)
{
REGS.FLAG.Clear();
@@ -1039,7 +1082,7 @@ static void Execute_DPCS(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_DPCT(Instruction inst)
void GTE::Execute_DPCT(Instruction inst)
{
REGS.FLAG.Clear();
@@ -1052,7 +1095,7 @@ static void Execute_DPCT(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_DCPL(Instruction inst)
void GTE::Execute_DCPL(Instruction inst)
{
REGS.FLAG.Clear();
@@ -1074,7 +1117,7 @@ static void Execute_DCPL(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_INTPL(Instruction inst)
void GTE::Execute_INTPL(Instruction inst)
{
REGS.FLAG.Clear();
@@ -1092,7 +1135,7 @@ static void Execute_INTPL(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_GPL(Instruction inst)
void GTE::Execute_GPL(Instruction inst)
{
REGS.FLAG.Clear();
@@ -1111,7 +1154,7 @@ static void Execute_GPL(Instruction inst)
REGS.FLAG.UpdateError();
}
static void Execute_GPF(Instruction inst)
void GTE::Execute_GPF(Instruction inst)
{
REGS.FLAG.Clear();
@@ -1130,7 +1173,7 @@ static void Execute_GPF(Instruction inst)
REGS.FLAG.UpdateError();
}
void ExecuteInstruction(u32 inst_bits)
void GTE::ExecuteInstruction(u32 inst_bits)
{
const Instruction inst{inst_bits};
switch (inst.command)
@@ -1256,7 +1299,7 @@ void ExecuteInstruction(u32 inst_bits)
}
}
InstructionImpl GetInstructionImpl(u32 inst_bits, TickCount* ticks)
GTE::InstructionImpl GTE::GetInstructionImpl(u32 inst_bits, TickCount* ticks)
{
const Instruction inst{inst_bits};
switch (inst.command)
@@ -1358,5 +1401,3 @@ InstructionImpl GetInstructionImpl(u32 inst_bits, TickCount* ticks)
Panic("Missing handler");
}
}
} // namespace GTE

View File

@@ -23,6 +23,8 @@
Log_SetChannel(MDEC);
namespace MDEC {
namespace {
static constexpr u32 DATA_IN_FIFO_SIZE = 1024;
static constexpr u32 DATA_OUT_FIFO_SIZE = 768;
static constexpr u32 NUM_BLOCKS = 6;
@@ -89,6 +91,8 @@ union CommandWord
BitField<u32, u16, 0, 16> parameter_word_count;
};
} // namespace
static bool HasPendingBlockCopyOut();
static void SoftReset();

View File

@@ -2,6 +2,7 @@
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "memory_card_image.h"
#include "gpu_types.h"
#include "system.h"
#include "util/shiftjis.h"
@@ -21,6 +22,7 @@
Log_SetChannel(MemoryCard);
namespace MemoryCardImage {
namespace {
#pragma pack(push, 1)
@@ -57,6 +59,8 @@ static_assert(sizeof(TitleFrame) == FRAME_SIZE);
#pragma pack(pop)
} // namespace
static u8 GetChecksum(const u8* frame)
{
u8 checksum = frame[0];
@@ -82,24 +86,16 @@ const T* GetFramePtr(const DataArray& data, u32 block, u32 frame)
return reinterpret_cast<const T*>(&data[(block * BLOCK_SIZE) + (frame * FRAME_SIZE)]);
}
static constexpr u32 RGBA5551ToRGBA8888(u16 color)
{
u8 r = Truncate8(color & 31);
u8 g = Truncate8((color >> 5) & 31);
u8 b = Truncate8((color >> 10) & 31);
u8 a = Truncate8((color >> 15) & 1);
static std::optional<u32> GetNextFreeBlock(const DataArray& data);
static bool ImportCardMCD(DataArray* data, const char* filename, std::vector<u8> file_data);
static bool ImportCardGME(DataArray* data, const char* filename, std::vector<u8> file_data);
static bool ImportCardVGS(DataArray* data, const char* filename, std::vector<u8> file_data);
static bool ImportCardPSX(DataArray* data, const char* filename, std::vector<u8> file_data);
static bool ImportSaveWithDirectoryFrame(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd);
static bool ImportRawSave(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd);
} // namespace MemoryCardImage
// 00012345 -> 1234545
b = (b << 3) | (b & 0b111);
g = (g << 3) | (g & 0b111);
r = (r << 3) | (r & 0b111);
// a = a ? 255 : 0;
a = (color == 0) ? 0 : 255;
return ZeroExtend32(r) | (ZeroExtend32(g) << 8) | (ZeroExtend32(b) << 16) | (ZeroExtend32(a) << 24);
}
bool LoadFromFile(DataArray* data, const char* filename)
bool MemoryCardImage::LoadFromFile(DataArray* data, const char* filename)
{
FILESYSTEM_STAT_DATA sd;
if (!FileSystem::StatFile(filename, &sd) || sd.Size != DATA_SIZE)
@@ -120,7 +116,7 @@ bool LoadFromFile(DataArray* data, const char* filename)
return true;
}
bool SaveToFile(const DataArray& data, const char* filename)
bool MemoryCardImage::SaveToFile(const DataArray& data, const char* filename)
{
std::unique_ptr<ByteStream> stream =
ByteStream::OpenFile(filename, BYTESTREAM_OPEN_CREATE | BYTESTREAM_OPEN_TRUNCATE | BYTESTREAM_OPEN_WRITE |
@@ -142,14 +138,14 @@ bool SaveToFile(const DataArray& data, const char* filename)
return true;
}
bool IsValid(const DataArray& data)
bool MemoryCardImage::IsValid(const DataArray& data)
{
// TODO: Check checksum?
const u8* fptr = GetFramePtr<u8>(data, 0, 0);
return fptr[0] == 'M' && fptr[1] == 'C';
}
void Format(DataArray* data)
void MemoryCardImage::Format(DataArray* data)
{
// fill everything with FF
data->fill(u8(0xFF));
@@ -206,7 +202,7 @@ void Format(DataArray* data)
std::memcpy(GetFramePtr<u8>(data, 0, 63), GetFramePtr<u8>(data, 0, 0), FRAME_SIZE);
}
static std::optional<u32> GetNextFreeBlock(const DataArray& data)
std::optional<u32> MemoryCardImage::GetNextFreeBlock(const DataArray& data)
{
for (u32 dir_frame = 1; dir_frame < FRAMES_PER_BLOCK; dir_frame++)
{
@@ -218,7 +214,7 @@ static std::optional<u32> GetNextFreeBlock(const DataArray& data)
return std::nullopt;
}
u32 GetFreeBlockCount(const DataArray& data)
u32 MemoryCardImage::GetFreeBlockCount(const DataArray& data)
{
u32 count = 0;
for (u32 dir_frame = 1; dir_frame < FRAMES_PER_BLOCK; dir_frame++)
@@ -231,7 +227,7 @@ u32 GetFreeBlockCount(const DataArray& data)
return count;
}
std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted)
std::vector<MemoryCardImage::FileInfo> MemoryCardImage::EnumerateFiles(const DataArray& data, bool include_deleted)
{
std::vector<FileInfo> files;
@@ -299,8 +295,8 @@ std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted
u32* pixels_ptr = fi.icon_frames[icon_frame].pixels;
for (u32 i = 0; i < ICON_WIDTH * ICON_HEIGHT; i += 2)
{
*(pixels_ptr++) = RGBA5551ToRGBA8888(tf->icon_palette[*indices_ptr & 0xF]);
*(pixels_ptr++) = RGBA5551ToRGBA8888(tf->icon_palette[*indices_ptr >> 4]);
*(pixels_ptr++) = VRAMRGBA5551ToRGBA8888(tf->icon_palette[*indices_ptr & 0xF]);
*(pixels_ptr++) = VRAMRGBA5551ToRGBA8888(tf->icon_palette[*indices_ptr >> 4]);
indices_ptr++;
}
}
@@ -311,7 +307,7 @@ std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted
return files;
}
bool ReadFile(const DataArray& data, const FileInfo& fi, std::vector<u8>* buffer)
bool MemoryCardImage::ReadFile(const DataArray& data, const FileInfo& fi, std::vector<u8>* buffer)
{
buffer->resize(fi.num_blocks * BLOCK_SIZE);
@@ -328,7 +324,7 @@ bool ReadFile(const DataArray& data, const FileInfo& fi, std::vector<u8>* buffer
return true;
}
bool WriteFile(DataArray* data, const std::string_view& filename, const std::vector<u8>& buffer)
bool MemoryCardImage::WriteFile(DataArray* data, const std::string_view& filename, const std::vector<u8>& buffer)
{
if (buffer.empty())
{
@@ -386,7 +382,7 @@ bool WriteFile(DataArray* data, const std::string_view& filename, const std::vec
return true;
}
bool DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors)
bool MemoryCardImage::DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors)
{
Log_InfoFmt("Deleting '{}' from memory card ({} blocks)", fi.filename, fi.num_blocks);
@@ -417,7 +413,7 @@ bool DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors)
return true;
}
bool UndeleteFile(DataArray* data, const FileInfo& fi)
bool MemoryCardImage::UndeleteFile(DataArray* data, const FileInfo& fi)
{
if (!fi.deleted)
{
@@ -483,7 +479,7 @@ bool UndeleteFile(DataArray* data, const FileInfo& fi)
return true;
}
static bool ImportCardMCD(DataArray* data, const char* filename, std::vector<u8> file_data)
bool MemoryCardImage::ImportCardMCD(DataArray* data, const char* filename, std::vector<u8> file_data)
{
if (file_data.size() != DATA_SIZE)
{
@@ -495,7 +491,7 @@ static bool ImportCardMCD(DataArray* data, const char* filename, std::vector<u8>
return true;
}
static bool ImportCardGME(DataArray* data, const char* filename, std::vector<u8> file_data)
bool MemoryCardImage::ImportCardGME(DataArray* data, const char* filename, std::vector<u8> file_data)
{
#pragma pack(push, 1)
struct GMEHeader
@@ -522,7 +518,7 @@ static bool ImportCardGME(DataArray* data, const char* filename, std::vector<u8>
if (file_data.size() < expected_size)
{
Log_WarningFmt("GME memory card '{}' is too small (got {} expected {}), padding with zeroes", filename,
file_data.size(), expected_size);
file_data.size(), expected_size);
file_data.resize(expected_size);
}
@@ -531,7 +527,7 @@ static bool ImportCardGME(DataArray* data, const char* filename, std::vector<u8>
return true;
}
static bool ImportCardVGS(DataArray* data, const char* filename, std::vector<u8> file_data)
bool MemoryCardImage::ImportCardVGS(DataArray* data, const char* filename, std::vector<u8> file_data)
{
constexpr u32 HEADER_SIZE = 64;
@@ -552,7 +548,7 @@ static bool ImportCardVGS(DataArray* data, const char* filename, std::vector<u8>
return true;
}
static bool ImportCardPSX(DataArray* data, const char* filename, std::vector<u8> file_data)
bool MemoryCardImage::ImportCardPSX(DataArray* data, const char* filename, std::vector<u8> file_data)
{
constexpr u32 HEADER_SIZE = 256;
@@ -573,7 +569,7 @@ static bool ImportCardPSX(DataArray* data, const char* filename, std::vector<u8>
return true;
}
bool ImportCard(DataArray* data, const char* filename, std::vector<u8> file_data)
bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::vector<u8> file_data)
{
const char* extension = std::strrchr(filename, '.');
if (!extension)
@@ -608,7 +604,7 @@ bool ImportCard(DataArray* data, const char* filename, std::vector<u8> file_data
}
}
bool ImportCard(DataArray* data, const char* filename)
bool MemoryCardImage::ImportCard(DataArray* data, const char* filename)
{
std::optional<std::vector<u8>> file_data = FileSystem::ReadBinaryFile(filename);
if (!file_data.has_value())
@@ -617,7 +613,7 @@ bool ImportCard(DataArray* data, const char* filename)
return ImportCard(data, filename, std::move(file_data.value()));
}
bool ExportSave(DataArray* data, const FileInfo& fi, const char* filename)
bool MemoryCardImage::ExportSave(DataArray* data, const FileInfo& fi, const char* filename)
{
std::unique_ptr<ByteStream> stream =
ByteStream::OpenFile(filename, BYTESTREAM_OPEN_CREATE | BYTESTREAM_OPEN_TRUNCATE | BYTESTREAM_OPEN_WRITE |
@@ -650,7 +646,8 @@ bool ExportSave(DataArray* data, const FileInfo& fi, const char* filename)
return true;
}
static bool ImportSaveWithDirectoryFrame(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd)
bool MemoryCardImage::ImportSaveWithDirectoryFrame(DataArray* data, const char* filename,
const FILESYSTEM_STAT_DATA& sd)
{
// Make sure the size of the actual file is valid
if (sd.Size <= FRAME_SIZE || (sd.Size - FRAME_SIZE) % BLOCK_SIZE != 0u || (sd.Size - FRAME_SIZE) / BLOCK_SIZE > 15u)
@@ -713,7 +710,7 @@ static bool ImportSaveWithDirectoryFrame(DataArray* data, const char* filename,
return WriteFile(data, df.filename, blocks);
}
static bool ImportRawSave(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd)
bool MemoryCardImage::ImportRawSave(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd)
{
const std::string display_name(FileSystem::GetDisplayNameFromPath(filename));
std::string save_name(Path::GetFileTitle(filename));
@@ -759,7 +756,7 @@ static bool ImportRawSave(DataArray* data, const char* filename, const FILESYSTE
return WriteFile(data, save_name, blocks.value());
}
bool ImportSave(DataArray* data, const char* filename)
bool MemoryCardImage::ImportSave(DataArray* data, const char* filename)
{
FILESYSTEM_STAT_DATA sd;
if (!FileSystem::StatFile(filename, &sd))
@@ -789,5 +786,3 @@ bool ImportSave(DataArray* data, const char* filename)
return false;
}
}
} // namespace MemoryCardImage

View File

@@ -14,6 +14,7 @@
Log_SetChannel(PGXP);
namespace PGXP {
namespace {
enum : u32
{
@@ -71,8 +72,13 @@ typedef union
u32 d;
s32 sd;
} psx_value;
} // namespace
static void PGXP_CacheVertex(s16 sx, s16 sy, const PGXP_value& vertex);
static PGXP_value* PGXP_GetCachedVertex(short sx, short sy);
static float TruncateVertexPosition(float p);
static bool IsWithinTolerance(float precise_x, float precise_y, int int_x, int int_y);
static void MakeValid(PGXP_value* pV, u32 psxV);
static void Validate(PGXP_value* pV, u32 psxV);
@@ -85,6 +91,9 @@ static double f16Overflow(double in);
static PGXP_value* GetPtr(u32 addr);
static PGXP_value* ReadMem(u32 addr);
static void PGXP_MTC2_int(const PGXP_value& value, u32 reg);
static void CPU_BITWISE(u32 instr, u32 rdVal, u32 rsVal, u32 rtVal);
static const PGXP_value PGXP_value_invalid = {0.f, 0.f, 0.f, {0}, 0};
static const PGXP_value PGXP_value_zero = {0.f, 0.f, 0.f, {VALID_ALL}, 0};
@@ -254,7 +263,9 @@ ALWAYS_INLINE_RELEASE static void WriteMem16(const PGXP_value* src, u32 addr)
}
}
void Initialize()
} // namespace PGXP
void PGXP::Initialize()
{
std::memset(CPU_reg, 0, sizeof(CPU_reg));
std::memset(CP0_reg, 0, sizeof(CP0_reg));
@@ -285,7 +296,7 @@ void Initialize()
std::memset(vertexCache, 0, sizeof(PGXP_value) * VERTEX_CACHE_SIZE);
}
void Reset()
void PGXP::Reset()
{
std::memset(CPU_reg, 0, sizeof(CPU_reg));
std::memset(CP0_reg, 0, sizeof(CP0_reg));
@@ -299,7 +310,7 @@ void Reset()
std::memset(vertexCache, 0, sizeof(PGXP_value) * VERTEX_CACHE_SIZE);
}
void Shutdown()
void PGXP::Shutdown()
{
if (vertexCache)
{
@@ -340,7 +351,7 @@ void Shutdown()
#define SXY2 (GTE_regs[14])
#define SXYP (GTE_regs[15])
void GTE_PushSXYZ2f(float x, float y, float z, u32 v)
void PGXP::GTE_PushSXYZ2f(float x, float y, float z, u32 v)
{
// push values down FIFO
SXY0 = SXY1;
@@ -360,7 +371,7 @@ void GTE_PushSXYZ2f(float x, float y, float z, u32 v)
#define VY(n) (psxRegs.CP2D.p[n << 1].sw.h)
#define VZ(n) (psxRegs.CP2D.p[(n << 1) + 1].sw.l)
int GTE_NCLIP_valid(u32 sxy0, u32 sxy1, u32 sxy2)
int PGXP::GTE_NCLIP_valid(u32 sxy0, u32 sxy1, u32 sxy2)
{
Validate(&SXY0, sxy0);
Validate(&SXY1, sxy1);
@@ -370,7 +381,7 @@ int GTE_NCLIP_valid(u32 sxy0, u32 sxy1, u32 sxy2)
return 0;
}
float GTE_NCLIP()
float PGXP::GTE_NCLIP()
{
float nclip = ((SX0 * SY1) + (SX1 * SY2) + (SX2 * SY0) - (SX0 * SY2) - (SX1 * SY0) - (SX2 * SY1));
@@ -395,7 +406,7 @@ float GTE_NCLIP()
return nclip;
}
static void PGXP_MTC2_int(PGXP_value value, u32 reg)
ALWAYS_INLINE_RELEASE void PGXP::PGXP_MTC2_int(const PGXP_value& value, u32 reg)
{
switch (reg)
{
@@ -418,7 +429,7 @@ static void PGXP_MTC2_int(PGXP_value value, u32 reg)
// Data transfer tracking
////////////////////////////////////
void CPU_MFC2(u32 instr, u32 rdVal)
void PGXP::CPU_MFC2(u32 instr, u32 rdVal)
{
// CPU[Rt] = GTE_D[Rd]
const u32 idx = cop2idx(instr);
@@ -427,7 +438,7 @@ void CPU_MFC2(u32 instr, u32 rdVal)
CPU_reg[rt(instr)].value = rdVal;
}
void CPU_MTC2(u32 instr, u32 rtVal)
void PGXP::CPU_MTC2(u32 instr, u32 rtVal)
{
// GTE_D[Rd] = CPU[Rt]
const u32 idx = cop2idx(instr);
@@ -439,7 +450,7 @@ void CPU_MTC2(u32 instr, u32 rtVal)
////////////////////////////////////
// Memory Access
////////////////////////////////////
void CPU_LWC2(u32 instr, u32 addr, u32 rtVal)
void PGXP::CPU_LWC2(u32 instr, u32 addr, u32 rtVal)
{
// GTE_D[Rt] = Mem[addr]
PGXP_value val;
@@ -447,14 +458,14 @@ void CPU_LWC2(u32 instr, u32 addr, u32 rtVal)
PGXP_MTC2_int(val, rt(instr));
}
void CPU_SWC2(u32 instr, u32 addr, u32 rtVal)
void PGXP::CPU_SWC2(u32 instr, u32 addr, u32 rtVal)
{
// Mem[addr] = GTE_D[Rt]
Validate(&GTE_regs[rt(instr)], rtVal);
WriteMem(&GTE_regs[rt(instr)], addr);
}
ALWAYS_INLINE_RELEASE void PGXP_CacheVertex(s16 sx, s16 sy, const PGXP_value& vertex)
ALWAYS_INLINE_RELEASE void PGXP::PGXP_CacheVertex(s16 sx, s16 sy, const PGXP_value& vertex)
{
if (sx >= -0x800 && sx <= 0x7ff && sy >= -0x800 && sy <= 0x7ff)
{
@@ -463,7 +474,7 @@ ALWAYS_INLINE_RELEASE void PGXP_CacheVertex(s16 sx, s16 sy, const PGXP_value& ve
}
}
static ALWAYS_INLINE_RELEASE PGXP_value* PGXP_GetCachedVertex(short sx, short sy)
ALWAYS_INLINE_RELEASE PGXP::PGXP_value* PGXP::PGXP_GetCachedVertex(short sx, short sy)
{
if (sx >= -0x800 && sx <= 0x7ff && sy >= -0x800 && sy <= 0x7ff)
{
@@ -474,14 +485,14 @@ static ALWAYS_INLINE_RELEASE PGXP_value* PGXP_GetCachedVertex(short sx, short sy
return nullptr;
}
static ALWAYS_INLINE_RELEASE float TruncateVertexPosition(float p)
ALWAYS_INLINE_RELEASE float PGXP::TruncateVertexPosition(float p)
{
const s32 int_part = static_cast<s32>(p);
const float int_part_f = static_cast<float>(int_part);
return static_cast<float>(static_cast<s16>(int_part << 5) >> 5) + (p - int_part_f);
}
static ALWAYS_INLINE_RELEASE bool IsWithinTolerance(float precise_x, float precise_y, int int_x, int int_y)
ALWAYS_INLINE_RELEASE bool PGXP::IsWithinTolerance(float precise_x, float precise_y, int int_x, int int_y)
{
const float tolerance = g_settings.gpu_pgxp_tolerance;
if (tolerance < 0.0f)
@@ -491,7 +502,8 @@ static ALWAYS_INLINE_RELEASE bool IsWithinTolerance(float precise_x, float preci
std::abs(precise_y - static_cast<float>(int_y)) <= tolerance);
}
bool GetPreciseVertex(u32 addr, u32 value, int x, int y, int xOffs, int yOffs, float* out_x, float* out_y, float* out_w)
bool PGXP::GetPreciseVertex(u32 addr, u32 value, int x, int y, int xOffs, int yOffs, float* out_x, float* out_y,
float* out_w)
{
const PGXP_value* vert = ReadMem(addr);
if (vert && ((vert->flags & VALID_01) == VALID_01) && (vert->value == value))
@@ -544,35 +556,35 @@ bool GetPreciseVertex(u32 addr, u32 value, int x, int y, int xOffs, int yOffs, f
#define imm_sext(_instr) \
static_cast<s32>(static_cast<s16>(_instr & 0xFFFF)) // The immediate part of the instruction register
void CPU_LW(u32 instr, u32 addr, u32 rtVal)
void PGXP::CPU_LW(u32 instr, u32 addr, u32 rtVal)
{
// Rt = Mem[Rs + Im]
ValidateAndCopyMem(&CPU_reg[rt(instr)], addr, rtVal);
}
void CPU_LBx(u32 instr, u32 addr, u32 rtVal)
void PGXP::CPU_LBx(u32 instr, u32 addr, u32 rtVal)
{
CPU_reg[rt(instr)] = PGXP_value_invalid;
}
void CPU_LH(u32 instr, u32 addr, u32 rtVal)
void PGXP::CPU_LH(u32 instr, u32 addr, u32 rtVal)
{
// Rt = Mem[Rs + Im] (sign extended)
ValidateAndCopyMem16(&CPU_reg[rt(instr)], addr, rtVal, true);
}
void CPU_LHU(u32 instr, u32 addr, u32 rtVal)
void PGXP::CPU_LHU(u32 instr, u32 addr, u32 rtVal)
{
// Rt = Mem[Rs + Im] (zero extended)
ValidateAndCopyMem16(&CPU_reg[rt(instr)], addr, rtVal, false);
}
void CPU_SB(u32 instr, u32 addr, u32 rtVal)
void PGXP::CPU_SB(u32 instr, u32 addr, u32 rtVal)
{
WriteMem(&PGXP_value_invalid, addr);
}
void CPU_SH(u32 instr, u32 addr, u32 rtVal)
void PGXP::CPU_SH(u32 instr, u32 addr, u32 rtVal)
{
PGXP_value* val = &CPU_reg[rt(instr)];
@@ -581,7 +593,7 @@ void CPU_SH(u32 instr, u32 addr, u32 rtVal)
WriteMem16(val, addr);
}
void CPU_SW(u32 instr, u32 addr, u32 rtVal)
void PGXP::CPU_SW(u32 instr, u32 addr, u32 rtVal)
{
// Mem[Rs + Im] = Rt
PGXP_value* val = &CPU_reg[rt(instr)];
@@ -589,14 +601,14 @@ void CPU_SW(u32 instr, u32 addr, u32 rtVal)
WriteMem(val, addr);
}
void CPU_MOVE(u32 rd_and_rs, u32 rsVal)
void PGXP::CPU_MOVE(u32 rd_and_rs, u32 rsVal)
{
const u32 Rs = (rd_and_rs & 0xFFu);
Validate(&CPU_reg[Rs], rsVal);
CPU_reg[(rd_and_rs >> 8)] = CPU_reg[Rs];
}
void CPU_ADDI(u32 instr, u32 rsVal)
void PGXP::CPU_ADDI(u32 instr, u32 rsVal)
{
// Rt = Rs + Imm (signed)
Validate(&CPU_reg[rs(instr)], rsVal);
@@ -624,7 +636,7 @@ void CPU_ADDI(u32 instr, u32 rsVal)
CPU_reg[rt(instr)].value = rsVal + imm_sext(instr);
}
void CPU_ANDI(u32 instr, u32 rsVal)
void PGXP::CPU_ANDI(u32 instr, u32 rsVal)
{
// Rt = Rs & Imm
const u32 rtVal = rsVal & imm(instr);
@@ -659,7 +671,7 @@ void CPU_ANDI(u32 instr, u32 rsVal)
CPU_reg[rt(instr)].value = rtVal;
}
void CPU_ORI(u32 instr, u32 rsVal)
void PGXP::CPU_ORI(u32 instr, u32 rsVal)
{
// Rt = Rs | Imm
const u32 rtVal = rsVal | imm(instr);
@@ -686,7 +698,7 @@ void CPU_ORI(u32 instr, u32 rsVal)
CPU_reg[rt(instr)] = ret;
}
void CPU_XORI(u32 instr, u32 rsVal)
void PGXP::CPU_XORI(u32 instr, u32 rsVal)
{
// Rt = Rs ^ Imm
const u32 rtVal = rsVal ^ imm(instr);
@@ -713,7 +725,7 @@ void CPU_XORI(u32 instr, u32 rsVal)
CPU_reg[rt(instr)] = ret;
}
void CPU_SLTI(u32 instr, u32 rsVal)
void PGXP::CPU_SLTI(u32 instr, u32 rsVal)
{
// Rt = Rs < Imm (signed)
psx_value tempImm;
@@ -731,7 +743,7 @@ void CPU_SLTI(u32 instr, u32 rsVal)
CPU_reg[rt(instr)] = ret;
}
void CPU_SLTIU(u32 instr, u32 rsVal)
void PGXP::CPU_SLTIU(u32 instr, u32 rsVal)
{
// Rt = Rs < Imm (Unsigned)
psx_value tempImm;
@@ -752,7 +764,7 @@ void CPU_SLTIU(u32 instr, u32 rsVal)
////////////////////////////////////
// Load Upper
////////////////////////////////////
void CPU_LUI(u32 instr)
void PGXP::CPU_LUI(u32 instr)
{
// Rt = Imm << 16
CPU_reg[rt(instr)] = PGXP_value_zero;
@@ -765,7 +777,7 @@ void CPU_LUI(u32 instr)
// Register Arithmetic
////////////////////////////////////
void CPU_ADD(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_ADD(u32 instr, u32 rsVal, u32 rtVal)
{
// Rd = Rs + Rt (signed)
PGXP_value ret;
@@ -813,7 +825,7 @@ void CPU_ADD(u32 instr, u32 rsVal, u32 rtVal)
CPU_reg[rd(instr)] = ret;
}
void CPU_SUB(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_SUB(u32 instr, u32 rsVal, u32 rtVal)
{
// Rd = Rs - Rt (signed)
PGXP_value ret;
@@ -848,7 +860,7 @@ void CPU_SUB(u32 instr, u32 rsVal, u32 rtVal)
CPU_reg[rd(instr)] = ret;
}
static void CPU_BITWISE(u32 instr, u32 rdVal, u32 rsVal, u32 rtVal)
ALWAYS_INLINE_RELEASE void PGXP::CPU_BITWISE(u32 instr, u32 rdVal, u32 rsVal, u32 rtVal)
{
// Rd = Rs & Rt
psx_value vald, vals, valt;
@@ -937,35 +949,35 @@ static void CPU_BITWISE(u32 instr, u32 rdVal, u32 rsVal, u32 rtVal)
CPU_reg[rd(instr)] = ret;
}
void CPU_AND_(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_AND_(u32 instr, u32 rsVal, u32 rtVal)
{
// Rd = Rs & Rt
const u32 rdVal = rsVal & rtVal;
CPU_BITWISE(instr, rdVal, rsVal, rtVal);
}
void CPU_OR_(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_OR_(u32 instr, u32 rsVal, u32 rtVal)
{
// Rd = Rs | Rt
const u32 rdVal = rsVal | rtVal;
CPU_BITWISE(instr, rdVal, rsVal, rtVal);
}
void CPU_XOR_(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_XOR_(u32 instr, u32 rsVal, u32 rtVal)
{
// Rd = Rs ^ Rt
const u32 rdVal = rsVal ^ rtVal;
CPU_BITWISE(instr, rdVal, rsVal, rtVal);
}
void CPU_NOR(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_NOR(u32 instr, u32 rsVal, u32 rtVal)
{
// Rd = Rs NOR Rt
const u32 rdVal = ~(rsVal | rtVal);
CPU_BITWISE(instr, rdVal, rsVal, rtVal);
}
void CPU_SLT(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_SLT(u32 instr, u32 rsVal, u32 rtVal)
{
// Rd = Rs < Rt (signed)
PGXP_value ret;
@@ -991,7 +1003,7 @@ void CPU_SLT(u32 instr, u32 rsVal, u32 rtVal)
CPU_reg[rd(instr)] = ret;
}
void CPU_SLTU(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_SLTU(u32 instr, u32 rsVal, u32 rtVal)
{
// Rd = Rs < Rt (unsigned)
PGXP_value ret;
@@ -1021,7 +1033,7 @@ void CPU_SLTU(u32 instr, u32 rsVal, u32 rtVal)
// Register mult/div
////////////////////////////////////
void CPU_MULT(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_MULT(u32 instr, u32 rsVal, u32 rtVal)
{
// Hi/Lo = Rs * Rt (signed)
Validate(&CPU_reg[rs(instr)], rsVal);
@@ -1069,7 +1081,7 @@ void CPU_MULT(u32 instr, u32 rsVal, u32 rtVal)
CPU_Lo.value = Truncate32(result);
}
void CPU_MULTU(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_MULTU(u32 instr, u32 rsVal, u32 rtVal)
{
// Hi/Lo = Rs * Rt (unsigned)
Validate(&CPU_reg[rs(instr)], rsVal);
@@ -1117,7 +1129,7 @@ void CPU_MULTU(u32 instr, u32 rsVal, u32 rtVal)
CPU_Lo.value = Truncate32(result);
}
void CPU_DIV(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_DIV(u32 instr, u32 rsVal, u32 rtVal)
{
// Lo = Rs / Rt (signed)
// Hi = Rs % Rt (signed)
@@ -1166,7 +1178,7 @@ void CPU_DIV(u32 instr, u32 rsVal, u32 rtVal)
}
}
void CPU_DIVU(u32 instr, u32 rsVal, u32 rtVal)
void PGXP::CPU_DIVU(u32 instr, u32 rsVal, u32 rtVal)
{
// Lo = Rs / Rt (unsigned)
// Hi = Rs % Rt (unsigned)
@@ -1211,7 +1223,7 @@ void CPU_DIVU(u32 instr, u32 rsVal, u32 rtVal)
////////////////////////////////////
// Shift operations (sa)
////////////////////////////////////
void CPU_SLL(u32 instr, u32 rtVal)
void PGXP::CPU_SLL(u32 instr, u32 rtVal)
{
// Rd = Rt << Sa
const u32 rdVal = rtVal << sa(instr);
@@ -1256,7 +1268,7 @@ void CPU_SLL(u32 instr, u32 rtVal)
CPU_reg[rd(instr)] = ret;
}
void CPU_SRL(u32 instr, u32 rtVal)
void PGXP::CPU_SRL(u32 instr, u32 rtVal)
{
// Rd = Rt >> Sa
const u32 rdVal = rtVal >> sa(instr);
@@ -1320,7 +1332,7 @@ void CPU_SRL(u32 instr, u32 rtVal)
CPU_reg[rd(instr)] = ret;
}
void CPU_SRA(u32 instr, u32 rtVal)
void PGXP::CPU_SRA(u32 instr, u32 rtVal)
{
// Rd = Rt >> Sa
const u32 rdVal = static_cast<u32>(static_cast<s32>(rtVal) >> sa(instr));
@@ -1386,7 +1398,7 @@ void CPU_SRA(u32 instr, u32 rtVal)
////////////////////////////////////
// Shift operations variable
////////////////////////////////////
void CPU_SLLV(u32 instr, u32 rtVal, u32 rsVal)
void PGXP::CPU_SLLV(u32 instr, u32 rtVal, u32 rsVal)
{
// Rd = Rt << Rs
const u32 rdVal = rtVal << rsVal;
@@ -1431,7 +1443,7 @@ void CPU_SLLV(u32 instr, u32 rtVal, u32 rsVal)
CPU_reg[rd(instr)] = ret;
}
void CPU_SRLV(u32 instr, u32 rtVal, u32 rsVal)
void PGXP::CPU_SRLV(u32 instr, u32 rtVal, u32 rsVal)
{
// Rd = Rt >> Sa
const u32 rdVal = rtVal >> rsVal;
@@ -1496,7 +1508,7 @@ void CPU_SRLV(u32 instr, u32 rtVal, u32 rsVal)
CPU_reg[rd(instr)] = ret;
}
void CPU_SRAV(u32 instr, u32 rtVal, u32 rsVal)
void PGXP::CPU_SRAV(u32 instr, u32 rtVal, u32 rsVal)
{
// Rd = Rt >> Sa
const u32 rdVal = static_cast<u32>(static_cast<s32>(rtVal) >> rsVal);
@@ -1561,7 +1573,7 @@ void CPU_SRAV(u32 instr, u32 rtVal, u32 rsVal)
CPU_reg[rd(instr)] = ret;
}
void CPU_MFHI(u32 instr, u32 hiVal)
void PGXP::CPU_MFHI(u32 instr, u32 hiVal)
{
// Rd = Hi
Validate(&CPU_Hi, hiVal);
@@ -1569,7 +1581,7 @@ void CPU_MFHI(u32 instr, u32 hiVal)
CPU_reg[rd(instr)] = CPU_Hi;
}
void CPU_MTHI(u32 instr, u32 rsVal)
void PGXP::CPU_MTHI(u32 instr, u32 rsVal)
{
// Hi = Rd
Validate(&CPU_reg[rs(instr)], rsVal);
@@ -1577,7 +1589,7 @@ void CPU_MTHI(u32 instr, u32 rsVal)
CPU_Hi = CPU_reg[rd(instr)];
}
void CPU_MFLO(u32 instr, u32 loVal)
void PGXP::CPU_MFLO(u32 instr, u32 loVal)
{
// Rd = Lo
Validate(&CPU_Lo, loVal);
@@ -1585,7 +1597,7 @@ void CPU_MFLO(u32 instr, u32 loVal)
CPU_reg[rd(instr)] = CPU_Lo;
}
void CPU_MTLO(u32 instr, u32 rsVal)
void PGXP::CPU_MTLO(u32 instr, u32 rsVal)
{
// Lo = Rd
Validate(&CPU_reg[rs(instr)], rsVal);
@@ -1593,7 +1605,7 @@ void CPU_MTLO(u32 instr, u32 rsVal)
CPU_Lo = CPU_reg[rd(instr)];
}
void CPU_MFC0(u32 instr, u32 rdVal)
void PGXP::CPU_MFC0(u32 instr, u32 rdVal)
{
// CPU[Rt] = CP0[Rd]
Validate(&CP0_reg[rd(instr)], rdVal);
@@ -1601,12 +1613,10 @@ void CPU_MFC0(u32 instr, u32 rdVal)
CPU_reg[rt(instr)].value = rdVal;
}
void CPU_MTC0(u32 instr, u32 rdVal, u32 rtVal)
void PGXP::CPU_MTC0(u32 instr, u32 rdVal, u32 rtVal)
{
// CP0[Rd] = CPU[Rt]
Validate(&CPU_reg[rt(instr)], rtVal);
CP0_reg[rd(instr)] = CPU_reg[rt(instr)];
CP0_reg[rd(instr)].value = rdVal;
}
} // namespace PGXP

View File

@@ -19,6 +19,7 @@
Log_SetChannel(SIO);
namespace SIO {
namespace {
union SIO_CTRL
{
@@ -64,6 +65,7 @@ union SIO_MODE
BitField<u16, u8, 5, 1> parity_type;
BitField<u16, u8, 6, 2> stop_bit_length;
};
} // namespace
static void SoftReset();
@@ -79,7 +81,9 @@ void SIO::Initialize()
Reset();
}
void SIO::Shutdown() {}
void SIO::Shutdown()
{
}
void SIO::Reset()
{

View File

@@ -38,6 +38,8 @@ ALWAYS_INLINE static constexpr s32 ApplyVolume(s32 sample, s16 volume)
}
namespace SPU {
namespace {
enum : u32
{
SPU_BASE = 0x1F801C00,
@@ -307,6 +309,7 @@ struct ReverbRegisters
u16 rev[NUM_REVERB_REGS];
};
};
} // namespace
static ADSRPhase GetNextADSRPhase(ADSRPhase phase);
@@ -350,7 +353,7 @@ static void CreateOutputStream();
static std::unique_ptr<TimingEvent> s_tick_event;
static std::unique_ptr<TimingEvent> s_transfer_event;
static std::unique_ptr<Common::WAVWriter> s_dump_writer;
static std::unique_ptr<WAVWriter> s_dump_writer;
static std::unique_ptr<AudioStream> s_audio_stream;
static std::unique_ptr<AudioStream> s_null_audio_stream;
static bool s_audio_output_muted = false;
@@ -405,7 +408,7 @@ static std::array<u8, RAM_SIZE> s_ram{};
#ifdef SPU_DUMP_ALL_VOICES
// +1 for reverb output
static std::array<std::unique_ptr<Common::WAVWriter>, NUM_VOICES + 1> s_voice_dump_writers;
static std::array<std::unique_ptr<WAVWriter>, NUM_VOICES + 1> s_voice_dump_writers;
#endif
} // namespace SPU
@@ -1479,7 +1482,7 @@ bool SPU::IsDumpingAudio()
bool SPU::StartDumpingAudio(const char* filename)
{
s_dump_writer.reset();
s_dump_writer = std::make_unique<Common::WAVWriter>();
s_dump_writer = std::make_unique<WAVWriter>();
if (!s_dump_writer->Open(filename, SAMPLE_RATE, 2))
{
Log_ErrorPrintf("Failed to open '%s'", filename);
@@ -1491,13 +1494,13 @@ bool SPU::StartDumpingAudio(const char* filename)
for (size_t i = 0; i < s_voice_dump_writers.size(); i++)
{
s_voice_dump_writers[i].reset();
s_voice_dump_writers[i] = std::make_unique<Common::WAVWriter>();
s_voice_dump_writers[i] = std::make_unique<WAVWriter>();
TinyString new_suffix;
if (i == NUM_VOICES)
new_suffix.Assign("reverb.wav");
new_suffix.assign("reverb.wav");
else
new_suffix.Format("voice%u.wav", i);
new_suffix.fmt("voice{}.wav", i);
const std::string voice_filename = Path::ReplaceExtension(filename, new_suffix);
if (!s_voice_dump_writers[i]->Open(voice_filename.c_str(), SAMPLE_RATE, 2))

View File

@@ -21,6 +21,8 @@
Log_SetChannel(Timers);
namespace Timers {
namespace {
static constexpr u32 NUM_TIMERS = 3;
enum class SyncMode : u8
@@ -60,6 +62,8 @@ struct CounterState
bool irq_done;
};
} // namespace
static void UpdateCountingEnabled(CounterState& cs);
static void CheckForIRQ(u32 index, u32 old_counter);
static void UpdateIRQ(u32 index);