Patch: Rename le{short,word,double} to be{short,word,double}

MIPS is little endian, not big endian. Having little endian commands
suggests to the reader that the "normal" format is big endian, which is
obviously incorrect.
This commit is contained in:
Stenzek 2023-05-25 19:56:56 +10:00 committed by refractionpcsx2
parent 680affd1fe
commit bfc3d2e1d4
3 changed files with 14 additions and 32 deletions

View File

@ -60,9 +60,9 @@ static const PatchTextTable dataType[] =
{3, "word", nullptr},
{4, "double", nullptr},
{5, "extended", nullptr},
{6, "leshort", nullptr},
{7, "leword", nullptr},
{8, "ledouble", nullptr},
{6, "beshort", nullptr},
{7, "beword", nullptr},
{8, "bedouble", nullptr},
{0, nullptr, nullptr} // Array Terminator
};

View File

@ -54,9 +54,9 @@ enum patch_data_type {
WORD_T,
DOUBLE_T,
EXTENDED_T,
SHORT_LE_T,
WORD_LE_T,
DOUBLE_LE_T
SHORT_BE_T,
WORD_BE_T,
DOUBLE_BE_T
};
// "place" is the first number at a pnach line (patch=<place>,...), e.g.:
@ -146,8 +146,3 @@ extern const IConsoleWriter *PatchesCon;
// regardless, they don't seem to have an implementation anywhere.
// extern int AddPatch(int Mode, int Place, int Address, int Size, u64 data);
// extern void ResetPatch(void);
// Swaps endianess of InputNum
// ex. 01020304 -> 04030201
// BitLength is length of InputNum in bits, ex. double,64 word,32 short,16
extern u64 SwapEndian(u64 InputNum, u8 BitLength);

View File

@ -15,6 +15,8 @@
#include "PrecompiledHeader.h"
#include "common/ByteSwap.h"
#define _PC_ // disables MIPS opcode macros.
#include "Common.h"
@ -542,20 +544,20 @@ void _ApplyPatch(IniPatch *p)
handle_extended_t(p);
break;
case SHORT_LE_T:
ledata = SwapEndian(p->data, 16);
case SHORT_BE_T:
ledata = ByteSwap(static_cast<u16>(p->data));
if (memRead16(p->addr) != (u16)ledata)
memWrite16(p->addr, (u16)ledata);
break;
case WORD_LE_T:
ledata = SwapEndian(p->data, 32);
case WORD_BE_T:
ledata = ByteSwap(static_cast<u32>(p->data));
if (memRead32(p->addr) != (u32)ledata)
memWrite32(p->addr, (u32)ledata);
break;
case DOUBLE_LE_T:
ledata = SwapEndian(p->data, 64);
case DOUBLE_BE_T:
ledata = ByteSwap(p->data);
if (memRead64(p->addr) != (u64)ledata)
memWrite64(p->addr, (u64)ledata);
break;
@ -605,18 +607,3 @@ void _ApplyDynaPatch(const DynamicPatch& patch, u32 address)
memWrite32(address + replacement.offset, replacement.value);
}
}
u64 SwapEndian(u64 InputNum, u8 BitLength)
{
if (BitLength == 64) // DOUBLE_LE_T
{
InputNum = (InputNum & 0x00000000FFFFFFFF) << 32 | (InputNum & 0xFFFFFFFF00000000) >> 32; //Swaps 4 bytes
}
if ((BitLength == 32)||(BitLength==64)) // WORD_LE_T
{
InputNum = (InputNum & 0x0000FFFF0000FFFF) << 16 | (InputNum & 0xFFFF0000FFFF0000) >> 16; // Swaps 2 bytes
}
InputNum = (InputNum & 0x00FF00FF00FF00FF) << 8 | (InputNum & 0xFF00FF00FF00FF00) >> 8; // Swaps 1 byte
return InputNum;
}