Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
lioncash committed Jan 15, 2013
1 parent d9aecd8 commit 7d11f8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions Source/Core/Core/Src/DSP/DSPCodeUtil.cpp
Expand Up @@ -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;
}

void GenRandomCode(int size, std::vector<u16> &code)
void GenRandomCode(u32 size, std::vector<u16> &code)
{
code.resize(size);
for (int i = 0; i < size; i++)
for (u32 i = 0; i < size; i++)
{
code[i] = rand() ^ (rand() << 8);
}
Expand Down Expand Up @@ -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,
int numCodes, const char *name, std::string &header)
u32 numCodes, const char *name, std::string &header)
{
std::vector<std::vector<u16> > codes_padded;
char buffer[1024];
int reserveSize = 0;
for(int i = 0; i < numCodes; i++)
u32 reserveSize = 0;
for(u32 i = 0; i < numCodes; i++)
{
codes_padded.push_back(codes[i]);
// Pad with nops to 32byte boundary
while (codes_padded.at(i).size() & 0x7f)
codes_padded.at(i).push_back(0);

reserveSize += (int)codes_padded.at(i).size();
reserveSize += (u32)codes_padded.at(i).size();
}


header.clear();
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("const char* UCODE_NAMES[NUM_UCODES] = {\n");
for (int i = 0; i < numCodes; i++)
for (u32 i = 0; i < numCodes; i++)
{
std::string filename;
if (! SplitPath(filenames->at(i), NULL, &filename, NULL))
Expand All @@ -176,7 +176,7 @@ void CodesToHeader(const std::vector<u16> *codes, const std::vector<std::string>
header.append("};\n\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)
continue;
Expand All @@ -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)
{
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 + 1] = code[i] & 0xff;
Expand All @@ -207,7 +207,7 @@ void CodeToBinaryStringBE(const std::vector<u16> &code, std::string &str)
void BinaryStringBEToCode(const std::string &str, std::vector<u16> &code)
{
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]);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/Src/DSP/DSPCodeUtil.h
Expand Up @@ -26,11 +26,11 @@
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 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,
const char *name, std::string &header);
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.
void CodeToBinaryStringBE(const std::vector<u16> &code, std::string &str);
Expand Down

0 comments on commit 7d11f8c

Please sign in to comment.