Commit 408ac735 authored by Jack Andersen's avatar Jack Andersen

FileHandle refactor

parent b5f51048
This diff is collapsed.
......@@ -358,7 +358,6 @@ static inline int Stat(const SystemChar* path, Sstat* statOut)
* @param checksumInv
*/
void calculateChecksumBE(const uint16_t* data, size_t len, uint16_t* checksum, uint16_t* checksumInv);
void calculateChecksumLE(const uint16_t* data, size_t len, uint16_t* checksum, uint16_t* checksumInv);
}
#endif // __KABU_UTIL_HPP__
......@@ -16,14 +16,19 @@ void BlockAllocationTable::swapEndian()
void BlockAllocationTable::updateChecksum()
{
calculateChecksumLE(reinterpret_cast<uint16_t*>(__raw + 4), 0xFFE, &m_checksum, &m_checksumInv);
swapEndian();
calculateChecksumBE(reinterpret_cast<uint16_t*>(__raw + 4), 0xFFE, &m_checksum, &m_checksumInv);
swapEndian();
}
bool BlockAllocationTable::valid() const
{
uint16_t ckSum, ckSumInv;
calculateChecksumLE(reinterpret_cast<const uint16_t*>(__raw + 4), 0xFFE, &ckSum, &ckSumInv);
return (ckSum == m_checksum && ckSumInv == m_checksumInv);
const_cast<BlockAllocationTable&>(*this).swapEndian();
calculateChecksumBE(reinterpret_cast<const uint16_t*>(__raw + 4), 0xFFE, &ckSum, &ckSumInv);
bool res = (ckSum == m_checksum && ckSumInv == m_checksumInv);
const_cast<BlockAllocationTable&>(*this).swapEndian();
return res;
}
BlockAllocationTable::BlockAllocationTable(uint32_t blockCount)
......
This diff is collapsed.
......@@ -15,14 +15,19 @@ void Directory::swapEndian()
void Directory::updateChecksum()
{
calculateChecksumLE(reinterpret_cast<uint16_t*>(__raw), 0xFFE, &m_checksum, &m_checksumInv);
swapEndian();
calculateChecksumBE(reinterpret_cast<uint16_t*>(__raw), 0xFFE, &m_checksum, &m_checksumInv);
swapEndian();
}
bool Directory::valid() const
{
uint16_t ckSum, ckSumInv;
calculateChecksumLE(reinterpret_cast<const uint16_t*>(__raw), 0xFFE, &ckSum, &ckSumInv);
return (ckSum == m_checksum && ckSumInv == m_checksumInv);
const_cast<Directory&>(*this).swapEndian();
calculateChecksumBE(reinterpret_cast<const uint16_t*>(__raw), 0xFFE, &ckSum, &ckSumInv);
bool res = (ckSum == m_checksum && ckSumInv == m_checksumInv);
const_cast<Directory&>(*this).swapEndian();
return res;
}
Directory::Directory()
......@@ -36,7 +41,7 @@ Directory::Directory(uint8_t data[]) { memcpy(__raw, data, BlockSize); }
bool Directory::hasFreeFile() const
{
for (uint16_t i = 0; i < 127; i++)
for (uint16_t i = 1; i < 127; i++)
if (m_files[i].m_game[0] == 0xFF)
return true;
return false;
......@@ -45,7 +50,7 @@ bool Directory::hasFreeFile() const
int32_t Directory::numFreeFiles() const
{
int32_t ret = 0;
for (uint16_t i = 0; i < 127; i++)
for (uint16_t i = 1; i < 127; i++)
if (m_files[i].m_game[0] == 0xFF)
++ret;
return ret;
......@@ -53,7 +58,7 @@ int32_t Directory::numFreeFiles() const
File* Directory::getFirstFreeFile(const char* game, const char* maker, const char* filename)
{
for (uint16_t i = 0; i < 127; i++)
for (uint16_t i = 1; i < 127; i++)
{
if (m_files[i].m_game[0] == 0xFF)
{
......@@ -92,7 +97,7 @@ File* Directory::getFirstNonFreeFile(uint32_t start, const char* game, const cha
File* Directory::getFile(const char* game, const char* maker, const char* filename)
{
for (uint16_t i = 0; i < 127; i++)
for (uint16_t i = 1; i < 127; i++)
{
if (game && strlen(game) == 4 && memcmp(m_files[i].m_game, game, 4))
continue;
......
......@@ -42,19 +42,4 @@ void calculateChecksumBE(const uint16_t* data, size_t len, uint16_t* checksum, u
*checksumInv = 0;
}
void calculateChecksumLE(const uint16_t* data, size_t len, uint16_t* checksum, uint16_t* checksumInv)
{
*checksum = 0;
*checksumInv = 0;
for (size_t i = 0; i < len; ++i)
{
*checksum += data[i];
*checksumInv += uint16_t(data[i] ^ 0xFFFF);
}
if (*checksum == 0xFFFF)
*checksum = 0;
if (*checksumInv == 0xFFFF)
*checksumInv = 0;
}
}
......@@ -8,7 +8,7 @@ int main()
uint64_t a = 0;
mc.getSerial(a);
std::unique_ptr<kabufuda::IFileHandle> f;
kabufuda::FileHandle f;
mc.openFile("MetroidPrime A", f);
for (uint32_t i = 0; i < 127; i++)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment