Added HexToDec routine from hmagic

This commit is contained in:
Justin Scofield
2022-07-12 08:03:53 -04:00
parent 40fea79b0e
commit bb056ee4d3
2 changed files with 36 additions and 0 deletions

View File

@@ -18,6 +18,41 @@ int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) {
return (addr1 << 16) | (addr2 << 8) | addr3;
}
//hextodec has been imported from SNESDisasm to parse hex numbers
int HexToDec(char *input, int length)
{
int result = 0;
int value;
int ceiling = length - 1;
int power16 = 16;
int j = ceiling;
for( ; j >= 0; j--)
{
if(input[j] >= 'A' && input[j] <= 'F')
{
value = input[j] - 'F';
value += 15;
}
else
{
value = input[j] - '9';
value += 9;
}
if(j == ceiling)
{
result += value;
continue;
}
result += (value * power16);
power16 *= 16;
}
return result;
}
} // namespace core
} // namespace app

View File

@@ -9,6 +9,7 @@ namespace core {
unsigned int SnesToPc(unsigned int addr);
int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3);
int HexToDec(char *input, int length);
} // namespace core
} // namespace app