Building on Macs (#513)

* Building on Macs

* Add Mac building documentation

* Review

* Update for new z64compress

* Review

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "155a463a5"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "155a463a5"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

* Fix some obvious warnings

* Rewrite docs

* -;

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "fd5a7f434"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "fd5a7f434"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

Co-authored-by: Anghelo Carvajal <angheloalf95@gmail.com>
This commit is contained in:
EllipticEllipsis
2021-12-28 01:07:41 +00:00
committed by GitHub
co-authored by Anghelo Carvajal
parent c291ebb232
commit 96eff2a4fd
30 changed files with 279 additions and 164 deletions
+2 -2
View File
@@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/zeldaret/ZAPD.git
branch = master
commit = 50242eca96a9c36fd84f438bab24548e73b42303
parent = 744955732b1fc9e8a835c62440aa97799cfe8940
commit = fd5a7f434171a33b1b3eb2a3e112fdcee6d9262d
parent = 844c24e39c96b7a3f3a40035058bda6c91ed4bbf
method = merge
cmdver = 0.4.3
+28 -28
View File
@@ -22,13 +22,13 @@ pipeline {
}
}
// stage('Checkout mm') {
// steps{
// dir('mm') {
// git url: 'https://github.com/zeldaret/mm.git'
// }
// }
// }
stage('Checkout mm') {
steps{
dir('mm') {
git url: 'https://github.com/zeldaret/mm.git'
}
}
}
}
}
@@ -51,20 +51,20 @@ pipeline {
}
}
// stage('Setup MM') {
// steps {
// dir('mm') {
// sh 'cp /usr/local/etc/roms/mm.us.rev1.z64 baserom.mm.us.rev1.z64'
stage('Setup MM') {
steps {
dir('mm') {
sh 'cp /usr/local/etc/roms/mm.us.rev1.z64 baserom.mm.us.rev1.z64'
// // Identical to `make setup` except for copying our newer ZAPD.out into mm
// sh 'make -C tools'
// sh 'cp ../ZAPD.out tools/ZAPD/'
// sh 'python3 tools/fixbaserom.py'
// sh 'python3 tools/extract_baserom.py'
// sh 'python3 extract_assets.py -t 4'
// }
// }
// }
// Identical to `make setup` except for copying our newer ZAPD.out into mm
sh 'make -C tools'
sh 'cp ../ZAPD.out tools/ZAPD/'
sh 'python3 tools/fixbaserom.py'
sh 'python3 tools/extract_baserom.py'
sh 'python3 extract_assets.py -t$(nproc)'
}
}
}
}
}
@@ -78,14 +78,14 @@ pipeline {
}
}
}
// stage('Build mm') {
// steps {
// dir('mm') {
// sh 'make -j disasm'
// sh 'make -j all'
// }
// }
// }
stage('Build mm') {
steps {
dir('mm') {
sh 'make -j disasm'
sh 'make -j all'
}
}
}
}
}
}
+1
View File
@@ -119,6 +119,7 @@ ZAPD also accepts the following list of extra parameters:
- `-tm MODE`: Test Mode (enables certain experimental features). To enable it, set `MODE` to `1`.
- `-se` / `--set-exporter` : Sets which exporter to use.
- `--gcc-compat` : Enables GCC compatibly mode. Slower.
- `-us` / `--unaccounted-static` : Mark unaccounted data as `static`
- `-s` / `--static` : Mark every asset as `static`.
- This behaviour can be overridden per asset using `Static=` in the respective XML node.
- `-W...`: warning flags, see below
+1 -2
View File
@@ -12,8 +12,7 @@ typedef uint32_t offset_t;
enum class DeclarationAlignment
{
Align4,
Align8,
Align16
Align8
};
enum class StaticConfig
+2 -2
View File
@@ -152,8 +152,8 @@ bool Globals::GetSegmentedPtrName(segptr_t segAddress, ZFile* currentFile,
}
}
const auto& symbolFromMap = Globals::Instance->symbolMap.find(segAddress);
if (symbolFromMap != Globals::Instance->symbolMap.end())
const auto& symbolFromMap = Globals::Instance->cfg.symbolMap.find(segAddress);
if (symbolFromMap != Globals::Instance->cfg.symbolMap.end())
{
declName = "&" + symbolFromMap->second;
return true;
+1 -1
View File
@@ -58,11 +58,11 @@ public:
bool verboseUnaccounted = false;
bool gccCompat = false;
bool forceStatic = false;
bool forceUnaccountedStatic = false;
std::vector<ZFile*> files;
std::vector<ZFile*> externalFiles;
std::vector<int32_t> segments;
std::map<uint32_t, std::string> symbolMap;
std::string currentExporter;
static std::map<std::string, ExporterSet*>& GetExporterMap();
+5 -1
View File
@@ -48,7 +48,7 @@ void ErrorHandler(int sig)
const char* crashEasterEgg[] = {
"\tYou've met with a terrible fate, haven't you?",
"\tSEA BEARS FOAM. SLEEP BEARS DREAMS. \n\tBOTH END IN THE SAME WAY: CRASSSH!",
"ZAPD has fallen and cannot get up."
"\tZAPD has fallen and cannot get up.",
};
srand(time(nullptr));
@@ -216,6 +216,10 @@ int main(int argc, char* argv[])
{
Globals::Instance->forceStatic = true;
}
else if (arg == "-us" || arg == "--unaccounted-static")
{
Globals::Instance->forceUnaccountedStatic = true;
}
}
// Parse File Mode
@@ -263,7 +263,7 @@ void Struct_800A5E28::DeclareReferences(const std::string& prefix)
ZResource::DeclareReferences(varPrefix);
if (unk_4 != 0 && GETSEGNUM(unk_4) == parent->segment)
if (unk_4 != SEGMENTED_NULL && GETSEGNUM(unk_4) == parent->segment)
{
const auto& res = unk_4_arr.at(0);
std::string unk_4_Str = res.GetDefaultName(varPrefix);
@@ -293,7 +293,7 @@ void Struct_800A5E28::DeclareReferences(const std::string& prefix)
decl->text = entryStr;
}
if (unk_8 != 0 && GETSEGNUM(unk_8) == parent->segment)
if (unk_8 != SEGMENTED_NULL && GETSEGNUM(unk_8) == parent->segment)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
@@ -306,6 +306,8 @@ void Struct_800A5E28::DeclareReferences(const std::string& prefix)
std::string dListStr =
StringHelper::Sprintf("%sSkinLimbDL_%06X", varPrefix.c_str(), unk_8_Offset);
unk_8_dlist->SetName(dListStr);
unk_8_dlist->DeclareVar(varPrefix, "");
unk_8_dlist->DeclareReferences(varPrefix);
parent->AddResource(unk_8_dlist);
}
}
+2 -1
View File
@@ -90,7 +90,8 @@ ZOverlay* ZOverlay::FromBuild(fs::path buildPath, fs::path cfgFolderPath)
std::vector<elfio*> readers;
for (size_t i = 1; i < cfgLines.size(); i++)
{
std::string elfPath = (buildPath / (cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o")).string();
std::string elfPath =
(buildPath / (cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o")).string();
elfio* reader = new elfio();
if (!reader->load(elfPath))
+3 -3
View File
@@ -104,7 +104,7 @@ void ZNormalAnimation::DeclareReferences(const std::string& prefix)
valuesStr += "\n ";
}
parent->AddDeclarationArray(rotationValuesOffset, DeclarationAlignment::Align16,
parent->AddDeclarationArray(rotationValuesOffset, DeclarationAlignment::Align4,
rotationValues.size() * 2, "s16",
StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()),
rotationValues.size(), valuesStr);
@@ -118,7 +118,7 @@ void ZNormalAnimation::DeclareReferences(const std::string& prefix)
indicesStr += "\n";
}
parent->AddDeclarationArray(rotationIndicesOffset, DeclarationAlignment::Align16,
parent->AddDeclarationArray(rotationIndicesOffset, DeclarationAlignment::Align4,
rotationIndices.size() * 6, "JointIndex",
StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()),
rotationIndices.size(), indicesStr);
@@ -385,7 +385,7 @@ size_t ZCurveAnimation::GetRawDataSize() const
DeclarationAlignment ZCurveAnimation::GetDeclarationAlignment() const
{
return DeclarationAlignment::Align16;
return DeclarationAlignment::Align4;
}
std::string ZCurveAnimation::GetSourceTypeName() const
+27 -9
View File
@@ -27,8 +27,8 @@ ZDisplayList::ZDisplayList(ZFile* nParent) : ZResource(nParent)
lastTexSizTest = F3DZEXTexSizes::G_IM_SIZ_16b;
lastTexLoaded = false;
lastTexIsPalette = false;
name = "";
dListType = Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX;
RegisterOptionalAttribute("Ucode");
}
ZDisplayList::~ZDisplayList()
@@ -44,13 +44,29 @@ void ZDisplayList::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDat
{
rawDataIndex = nRawDataIndex;
ParseXML(reader);
// TODO add error handling here
bool ucodeSet = registeredAttributes.at("Ucode").wasSet;
std::string ucodeValue = registeredAttributes.at("Ucode").value;
if ((Globals::Instance->game == ZGame::OOT_SW97) || (ucodeValue == "f3dex"))
{
dListType = DListType::F3DEX;
}
else if (!ucodeSet || ucodeValue == "f3dex2")
{
dListType = DListType::F3DZEX;
}
else
{
HANDLE_ERROR_RESOURCE(
WarningType::InvalidAttributeValue, parent, this, rawDataIndex,
StringHelper::Sprintf("Invalid ucode type in node: %s\n", reader->Name()), "");
}
// Don't parse raw data of external files
if (parent->GetMode() != ZFileMode::ExternalFile)
{
int32_t rawDataSize = ZDisplayList::GetDListLength(
parent->GetRawData(), rawDataIndex,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
int32_t rawDataSize =
ZDisplayList::GetDListLength(parent->GetRawData(), rawDataIndex, dListType);
numInstructions = rawDataSize / 8;
ParseRawData();
}
@@ -693,7 +709,8 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, const std::string& prefix, char* l
else if (dListDecl != nullptr)
sprintf(line, "gsSPBranchList(%s),", dListDecl->varName.c_str());
else
sprintf(line, "gsSPBranchList(%sDlist0x%06" PRIX64 "),", prefix.c_str(), GETSEGOFFSET(data));
sprintf(line, "gsSPBranchList(%sDlist0x%06" PRIX64 "),", prefix.c_str(),
GETSEGOFFSET(data));
}
else
{
@@ -702,7 +719,8 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, const std::string& prefix, char* l
else if (dListDecl != nullptr)
sprintf(line, "gsSPDisplayList(%s),", dListDecl->varName.c_str());
else
sprintf(line, "gsSPDisplayList(%sDlist0x%06" PRIX64 "),", prefix.c_str(), GETSEGOFFSET(data));
sprintf(line, "gsSPDisplayList(%sDlist0x%06" PRIX64 "),", prefix.c_str(),
GETSEGOFFSET(data));
}
// if (segNum == 8 || segNum == 9 || segNum == 10 || segNum == 11 || segNum == 12 || segNum ==
@@ -832,7 +850,7 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, char* line)
{
segptr_t segmented = data & 0xFFFFFFFF;
references.push_back(segmented);
parent->AddDeclaration(segmented, DeclarationAlignment::Align16, 16, "Vtx",
parent->AddDeclaration(segmented, DeclarationAlignment::Align8, 16, "Vtx",
StringHelper::Sprintf("0x%08X", segmented), "");
return;
}
@@ -1748,7 +1766,7 @@ void ZDisplayList::DeclareReferences(const std::string& prefix)
if (vertices.size() > 0)
{
std::vector<std::pair<uint32_t, std::vector<ZVtx>>> verticesSorted(vertices.begin(),
vertices.end());
vertices.end());
for (size_t i = 0; i < verticesSorted.size() - 1; i++)
{
@@ -1796,7 +1814,7 @@ void ZDisplayList::DeclareReferences(const std::string& prefix)
if (vertices.size() > 0)
{
std::vector<std::pair<uint32_t, std::vector<ZVtx>>> verticesSorted(vertices.begin(),
vertices.end());
vertices.end());
for (size_t i = 0; i < verticesSorted.size() - 1; i++)
{
+34 -46
View File
@@ -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"
@@ -192,7 +193,7 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename)
rawData = File::ReadAllBytes((basePath / name).string());
if (reader->Attribute("RangeEnd") == nullptr)
rangeEnd = rawData.size();
rangeEnd = rawData.size();
}
std::unordered_set<std::string> nameSet;
@@ -378,7 +379,7 @@ void ZFile::ExtractResources()
ZResourceExporter* exporter = Globals::Instance->GetExporter(res->GetResourceType());
if (exporter != nullptr)
{
//exporter->Save(res, Globals::Instance->outputPath.string(), &writerFile);
// exporter->Save(res, Globals::Instance->outputPath.string(), &writerFile);
exporter->Save(res, Globals::Instance->outputPath.string(), &writerRes);
}
@@ -391,7 +392,7 @@ void ZFile::ExtractResources()
File::WriteAllBytes(StringHelper::Sprintf("%s%s.bin",
Globals::Instance->outputPath.string().c_str(),
GetName().c_str()),
memStreamFile->ToVector());
memStreamFile->ToVector());
}
writerFile.Close();
@@ -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);
@@ -1320,7 +1305,10 @@ bool ZFile::HandleUnaccountedAddress(uint32_t currentAddress, uint32_t lastAddr,
StringHelper::Sprintf("%s_%s_%06X", name.c_str(), unaccountedPrefix.c_str(),
unaccountedAddress),
diff, src);
decl->isUnaccounted = true;
if (Globals::Instance->forceUnaccountedStatic)
decl->staticConf = StaticConfig::On;
if (nonZeroUnaccounted)
{
+1 -1
View File
@@ -133,5 +133,5 @@ protected:
std::string ProcessTextureIntersections(const std::string& prefix);
void HandleUnaccountedData();
bool HandleUnaccountedAddress(uint32_t currentAddress, uint32_t lastAddr, uint32_t& lastSize);
bool HandleUnaccountedAddress(offset_t currentAddress, offset_t lastAddr, uint32_t& lastSize);
};
+2 -2
View File
@@ -228,8 +228,8 @@ std::string ZLimb::GetBodySourceCode() const
{
std::string childName;
std::string siblingName;
Globals::Instance->GetSegmentedPtrName(childPtr, parent, "Gfx", childName);
Globals::Instance->GetSegmentedPtrName(siblingPtr, parent, "Gfx", siblingName);
Globals::Instance->GetSegmentedPtrName(childPtr, parent, "LegacyLimb", childName);
Globals::Instance->GetSegmentedPtrName(siblingPtr, parent, "LegacyLimb", siblingName);
entryStr += StringHelper::Sprintf("%s,\n", dListStr.c_str());
entryStr +=
@@ -152,7 +152,6 @@ void PolygonDlist::GetSourceOutputCode(const std::string& prefix)
DeclareVar(prefix, bodyStr);
else
decl->text = bodyStr;
}
std::string PolygonDlist::GetSourceTypeName() const
@@ -1,6 +1,8 @@
#include "SetSpecialObjects.h"
#include "Utils/BitConverter.h"
#include "Utils/StringHelper.h"
#include "ZRoom/ZNames.h"
SetSpecialObjects::SetSpecialObjects(ZFile* nParent) : ZRoomCommand(nParent)
{
@@ -15,8 +17,10 @@ void SetSpecialObjects::ParseRawData()
std::string SetSpecialObjects::GetBodySourceCode() const
{
return StringHelper::Sprintf("SCENE_CMD_SPECIAL_FILES(0x%02X, 0x%04X)", elfMessage,
globalObject);
std::string objectName = ZNames::GetObjectName(globalObject);
return StringHelper::Sprintf("SCENE_CMD_SPECIAL_FILES(0x%02X, %s)", elfMessage,
objectName.c_str());
}
std::string SetSpecialObjects::GetCommandCName() const
+2 -1
View File
@@ -261,7 +261,8 @@ void ZRoom::ParseRawData()
if (Globals::Instance->profile)
{
auto end = std::chrono::steady_clock::now();
int64_t diff = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
int64_t diff =
std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
if (diff > 50)
printf("OP: %s, TIME: %" PRIi64 "ms\n", cmd->GetCommandCName().c_str(), diff);
}
+1 -1
View File
@@ -139,7 +139,7 @@ ZResourceType ZSkeleton::GetResourceType() const
DeclarationAlignment ZSkeleton::GetDeclarationAlignment() const
{
return DeclarationAlignment::Align16;
return DeclarationAlignment::Align4;
}
uint8_t ZSkeleton::GetLimbCount()
+1 -1
View File
@@ -82,5 +82,5 @@ std::string ZVtx::GetExternalExtension() const
DeclarationAlignment ZVtx::GetDeclarationAlignment() const
{
return DeclarationAlignment::Align16;
return DeclarationAlignment::Align8;
}
+1 -1
View File
@@ -109,6 +109,6 @@ public:
static bool IEquals(const std::string& a, const std::string& b)
{
return std::equal(a.begin(), a.end(), b.begin(), b.end(),
[](char a, char b) { return tolower(a) == tolower(b); });
[](char a, char b) { return tolower(a) == tolower(b); });
}
};

Some files were not shown because too many files have changed in this diff Show More