mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-10 22:49:00 +01:00
- Made GenRandomCode's 'size' parameter unsigned. Doesn't make sense to have the capability of being able to be negative.
- Made CodesToHeader's 'numCodes' unsigned for the same reason. - Removed some type-casts from other functions.
This commit is contained in:
parent
d9aecd80b1
commit
7d11f8cedd
@ -104,10 +104,10 @@ bool Compare(const std::vector<u16> &code1, const std::vector<u16> &code2)
|
|||||||
return code1.size() == code2.size() && code1.size() == count_equal;
|
return code1.size() == code2.size() && code1.size() == count_equal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenRandomCode(int size, std::vector<u16> &code)
|
void GenRandomCode(u32 size, std::vector<u16> &code)
|
||||||
{
|
{
|
||||||
code.resize(size);
|
code.resize(size);
|
||||||
for (int i = 0; i < size; i++)
|
for (u32 i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
code[i] = rand() ^ (rand() << 8);
|
code[i] = rand() ^ (rand() << 8);
|
||||||
}
|
}
|
||||||
@ -144,28 +144,28 @@ void CodeToHeader(const std::vector<u16> &code, std::string _filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CodesToHeader(const std::vector<u16> *codes, const std::vector<std::string>* filenames,
|
void CodesToHeader(const std::vector<u16> *codes, const std::vector<std::string>* filenames,
|
||||||
int numCodes, const char *name, std::string &header)
|
u32 numCodes, const char *name, std::string &header)
|
||||||
{
|
{
|
||||||
std::vector<std::vector<u16> > codes_padded;
|
std::vector<std::vector<u16> > codes_padded;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
int reserveSize = 0;
|
u32 reserveSize = 0;
|
||||||
for(int i = 0; i < numCodes; i++)
|
for(u32 i = 0; i < numCodes; i++)
|
||||||
{
|
{
|
||||||
codes_padded.push_back(codes[i]);
|
codes_padded.push_back(codes[i]);
|
||||||
// Pad with nops to 32byte boundary
|
// Pad with nops to 32byte boundary
|
||||||
while (codes_padded.at(i).size() & 0x7f)
|
while (codes_padded.at(i).size() & 0x7f)
|
||||||
codes_padded.at(i).push_back(0);
|
codes_padded.at(i).push_back(0);
|
||||||
|
|
||||||
reserveSize += (int)codes_padded.at(i).size();
|
reserveSize += (u32)codes_padded.at(i).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
header.clear();
|
header.clear();
|
||||||
header.reserve(reserveSize * 4);
|
header.reserve(reserveSize * 4);
|
||||||
sprintf(buffer, "#define NUM_UCODES %d\n\n", numCodes);
|
sprintf(buffer, "#define NUM_UCODES %u\n\n", numCodes);
|
||||||
header.append(buffer);
|
header.append(buffer);
|
||||||
header.append("const char* UCODE_NAMES[NUM_UCODES] = {\n");
|
header.append("const char* UCODE_NAMES[NUM_UCODES] = {\n");
|
||||||
for (int i = 0; i < numCodes; i++)
|
for (u32 i = 0; i < numCodes; i++)
|
||||||
{
|
{
|
||||||
std::string filename;
|
std::string filename;
|
||||||
if (! SplitPath(filenames->at(i), NULL, &filename, NULL))
|
if (! SplitPath(filenames->at(i), NULL, &filename, NULL))
|
||||||
@ -176,7 +176,7 @@ void CodesToHeader(const std::vector<u16> *codes, const std::vector<std::string>
|
|||||||
header.append("};\n\n");
|
header.append("};\n\n");
|
||||||
header.append("const unsigned short dsp_code[NUM_UCODES][0x1000] = {\n");
|
header.append("const unsigned short dsp_code[NUM_UCODES][0x1000] = {\n");
|
||||||
|
|
||||||
for(int i = 0; i < numCodes; i++)
|
for(u32 i = 0; i < numCodes; i++)
|
||||||
{
|
{
|
||||||
if(codes[i].size() == 0)
|
if(codes[i].size() == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -197,7 +197,7 @@ void CodesToHeader(const std::vector<u16> *codes, const std::vector<std::string>
|
|||||||
void CodeToBinaryStringBE(const std::vector<u16> &code, std::string &str)
|
void CodeToBinaryStringBE(const std::vector<u16> &code, std::string &str)
|
||||||
{
|
{
|
||||||
str.resize(code.size() * 2);
|
str.resize(code.size() * 2);
|
||||||
for (int i = 0; i < (int)code.size(); i++)
|
for (size_t i = 0; i < code.size(); i++)
|
||||||
{
|
{
|
||||||
str[i * 2 + 0] = code[i] >> 8;
|
str[i * 2 + 0] = code[i] >> 8;
|
||||||
str[i * 2 + 1] = code[i] & 0xff;
|
str[i * 2 + 1] = code[i] & 0xff;
|
||||||
@ -207,7 +207,7 @@ void CodeToBinaryStringBE(const std::vector<u16> &code, std::string &str)
|
|||||||
void BinaryStringBEToCode(const std::string &str, std::vector<u16> &code)
|
void BinaryStringBEToCode(const std::string &str, std::vector<u16> &code)
|
||||||
{
|
{
|
||||||
code.resize(str.size() / 2);
|
code.resize(str.size() / 2);
|
||||||
for (int i = 0; i < (int)code.size(); i++)
|
for (size_t i = 0; i < code.size(); i++)
|
||||||
{
|
{
|
||||||
code[i] = ((u16)(u8)str[i * 2 + 0] << 8) | ((u16)(u8)str[i * 2 + 1]);
|
code[i] = ((u16)(u8)str[i * 2 + 0] << 8) | ((u16)(u8)str[i * 2 + 1]);
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,11 @@
|
|||||||
bool Assemble(const char *text, std::vector<u16> &code, bool force = false);
|
bool Assemble(const char *text, std::vector<u16> &code, bool force = false);
|
||||||
bool Disassemble(const std::vector<u16> &code, bool line_numbers, std::string &text);
|
bool Disassemble(const std::vector<u16> &code, bool line_numbers, std::string &text);
|
||||||
bool Compare(const std::vector<u16> &code1, const std::vector<u16> &code2);
|
bool Compare(const std::vector<u16> &code1, const std::vector<u16> &code2);
|
||||||
void GenRandomCode(int size, std::vector<u16> &code);
|
void GenRandomCode(u32 size, std::vector<u16> &code);
|
||||||
void CodeToHeader(const std::vector<u16> &code, std::string _filename,
|
void CodeToHeader(const std::vector<u16> &code, std::string _filename,
|
||||||
const char *name, std::string &header);
|
const char *name, std::string &header);
|
||||||
void CodesToHeader(const std::vector<u16> *codes, const std::vector<std::string> *filenames,
|
void CodesToHeader(const std::vector<u16> *codes, const std::vector<std::string> *filenames,
|
||||||
int numCodes, const char *name, std::string &header);
|
u32 numCodes, const char *name, std::string &header);
|
||||||
|
|
||||||
// Big-endian, for writing straight to file using File::WriteStringToFile.
|
// Big-endian, for writing straight to file using File::WriteStringToFile.
|
||||||
void CodeToBinaryStringBE(const std::vector<u16> &code, std::string &str);
|
void CodeToBinaryStringBE(const std::vector<u16> &code, std::string &str);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user