- 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:
lioncash 2013-01-15 17:50:50 -05:00
parent d9aecd80b1
commit 7d11f8cedd
2 changed files with 13 additions and 13 deletions

View file

@ -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);
}
@ -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))
@ -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;
@ -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;
@ -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]);
}

View file

@ -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);