summaryrefslogtreecommitdiff
path: root/ZAPD/ZFile.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-12-26 19:24:12 -0300
committerGitHub <noreply@github.com>2021-12-26 17:24:12 -0500
commit155a463a54a3bc9b9c86000ae6d819455875ec15 (patch)
tree22e9b3545e0051dac9162d901ae49cb87d1ba647 /ZAPD/ZFile.cpp
parent431c1bc46c64712a42a22893dc28e9503fe3934a (diff)
Fix padding generation for double word aligned variables (#223)
* Don't produce a symbol for 8byte aligned symbols * Change Vtx alignment to 8 * Remove Align16 * handle unaccounteds properly when stuff has Align8 alignment * format * Fix warning * typo
Diffstat (limited to 'ZAPD/ZFile.cpp')
-rw-r--r--ZAPD/ZFile.cpp71
1 files changed, 28 insertions, 43 deletions
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp
index f1d50a8..f7f3f69 100644
--- a/ZAPD/ZFile.cpp
+++ b/ZAPD/ZFile.cpp
@@ -8,6 +8,7 @@
#include "Globals.h"
#include "OutputFormatter.h"
#include "Utils/BinaryWriter.h"
+#include "Utils/BitConverter.h"
#include "Utils/Directory.h"
#include "Utils/File.h"
#include "Utils/MemoryStream.h"
@@ -949,9 +950,6 @@ std::string ZFile::ProcessDeclarations()
defines += ProcessTextureIntersections(name);
- // Account for padding/alignment
- uint32_t lastAddr = 0;
-
// printf("RANGE START: 0x%06X - RANGE END: 0x%06X\n", rangeStart, rangeEnd);
// Optimization: See if there are any arrays side by side that can be merged...
@@ -1002,43 +1000,6 @@ std::string ZFile::ProcessDeclarations()
{
while (item.second->size % 4 != 0)
item.second->size++;
-
- if (lastAddr != 0)
- {
- if (item.second->alignment == DeclarationAlignment::Align16)
- {
- int32_t curPtr = lastAddr + declarations[lastAddr]->size;
-
- while (curPtr % 4 != 0)
- {
- declarations[lastAddr]->size++;
- curPtr++;
- }
- }
- else if (item.second->alignment == DeclarationAlignment::Align8)
- {
- size_t curPtr = lastAddr + declarations[lastAddr]->size;
-
- while (curPtr % 4 != 0)
- {
- declarations[lastAddr]->size++;
- curPtr++;
- }
-
- while (curPtr % 8 != 0)
- {
- char buffer[2048];
-
- sprintf(buffer, "u32 %s_align%02zX = 0;\n", name.c_str(), curPtr);
- item.second->preText = buffer + item.second->preText;
-
- declarations[lastAddr]->size += 4;
- curPtr += 4;
- }
- }
- }
-
- lastAddr = item.first;
}
HandleUnaccountedData();
@@ -1199,14 +1160,15 @@ void ZFile::HandleUnaccountedData()
{
uint32_t lastAddr = 0;
uint32_t lastSize = 0;
- std::vector<uint32_t> declsAddresses;
+ std::vector<offset_t> declsAddresses;
+
for (const auto& item : declarations)
{
declsAddresses.push_back(item.first);
}
bool breakLoop = false;
- for (uint32_t currentAddress : declsAddresses)
+ for (offset_t currentAddress : declsAddresses)
{
if (currentAddress >= rangeEnd)
{
@@ -1235,7 +1197,7 @@ void ZFile::HandleUnaccountedData()
}
}
-bool ZFile::HandleUnaccountedAddress(uint32_t currentAddress, uint32_t lastAddr, uint32_t& lastSize)
+bool ZFile::HandleUnaccountedAddress(offset_t currentAddress, offset_t lastAddr, uint32_t& lastSize)
{
if (currentAddress != lastAddr && declarations.find(lastAddr) != declarations.end())
{
@@ -1275,6 +1237,29 @@ bool ZFile::HandleUnaccountedAddress(uint32_t currentAddress, uint32_t lastAddr,
xmlFilePath.c_str(), currentAddress, name.c_str(), rawData.size()));
}
+ // Handle Align8
+ if (currentAddress % 8 == 0 && diff % 8 != 0)
+ {
+ Declaration* currentDecl = GetDeclaration(currentAddress);
+
+ if (currentDecl != nullptr)
+ {
+ if (currentDecl->alignment == DeclarationAlignment::Align8)
+ {
+ // Check removed bytes are zeroes
+ if (BitConverter::ToUInt32BE(rawData, unaccountedAddress + diff - 4) == 0)
+ {
+ diff -= 4;
+ }
+ }
+
+ if (diff == 0)
+ {
+ return false;
+ }
+ }
+ }
+
for (int i = 0; i < diff; i++)
{
uint8_t val = rawData.at(unaccountedAddress + i);