diff options
Diffstat (limited to 'ZAPD/ZSkeleton.cpp')
| -rw-r--r-- | ZAPD/ZSkeleton.cpp | 98 |
1 files changed, 30 insertions, 68 deletions
diff --git a/ZAPD/ZSkeleton.cpp b/ZAPD/ZSkeleton.cpp index 5de5626..6eb06d9 100644 --- a/ZAPD/ZSkeleton.cpp +++ b/ZAPD/ZSkeleton.cpp @@ -1,6 +1,8 @@ #include "ZSkeleton.h" #include <cassert> + +#include "Globals.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" @@ -13,15 +15,6 @@ ZSkeleton::ZSkeleton(ZFile* nParent) : ZResource(nParent), limbsTable(nParent) RegisterRequiredAttribute("LimbType"); } -void ZSkeleton::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) -{ - ZResource::ExtractFromXML(reader, nRawDataIndex); - - Declaration* decl = parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, - GetRawDataSize(), GetSourceTypeName(), name, ""); - decl->staticConf = staticConf; -} - void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) { ZResource::ParseXML(reader); @@ -46,12 +39,9 @@ void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) limbType = ZLimb::GetTypeByAttributeName(limbTypeXml); if (limbType == ZLimbType::Invalid) { - fprintf(stderr, - "ZSkeleton::ParseXML: Warning in '%s'.\n" - "\t Invalid LimbType found: '%s'.\n" - "\t Defaulting to 'Standard'.\n", - name.c_str(), limbTypeXml.c_str()); - limbType = ZLimbType::Standard; + throw std::runtime_error(StringHelper::Sprintf("ZSkeleton::ParseXML: Error in '%s'.\n" + "\t Invalid LimbType found: '%s'.\n", + name.c_str(), limbTypeXml.c_str())); } } @@ -77,6 +67,8 @@ void ZSkeleton::DeclareReferences(const std::string& prefix) if (defaultPrefix == "") defaultPrefix = prefix; + ZResource::DeclareReferences(defaultPrefix); + if (limbsArrayAddress != 0 && GETSEGNUM(limbsArrayAddress) == parent->segment) { uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress); @@ -122,26 +114,6 @@ size_t ZSkeleton::GetRawDataSize() const } } -std::string ZSkeleton::GetSourceOutputCode([[maybe_unused]] const std::string& prefix) -{ - std::string headerStr = GetBodySourceCode(); - - Declaration* decl = parent->GetDeclaration(GetAddress()); - - if (decl == nullptr) - { - decl = parent->AddDeclaration(GetAddress(), DeclarationAlignment::Align16, GetRawDataSize(), - GetSourceTypeName(), name, headerStr); - } - else - { - decl->text = headerStr; - } - decl->staticConf = staticConf; - - return ""; -} - std::string ZSkeleton::GetSourceTypeName() const { switch (type) @@ -162,9 +134,9 @@ ZResourceType ZSkeleton::GetResourceType() const return ZResourceType::Skeleton; } -segptr_t ZSkeleton::GetAddress() +DeclarationAlignment ZSkeleton::GetDeclarationAlignment() const { - return rawDataIndex; + return DeclarationAlignment::Align16; } uint8_t ZSkeleton::GetLimbCount() @@ -180,16 +152,6 @@ ZLimbTable::ZLimbTable(ZFile* nParent) : ZResource(nParent) RegisterRequiredAttribute("Count"); } -void ZLimbTable::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) -{ - ZResource::ExtractFromXML(reader, nRawDataIndex); - - Declaration* decl = - parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(), - GetSourceTypeName(), name, limbsAddresses.size(), ""); - decl->staticConf = staticConf; -} - void ZLimbTable::ExtractFromBinary(uint32_t nRawDataIndex, ZLimbType nLimbType, size_t nCount) { rawDataIndex = nRawDataIndex; @@ -233,9 +195,9 @@ void ZLimbTable::ParseRawData() void ZLimbTable::DeclareReferences(const std::string& prefix) { - std::string varPrefix = prefix; - if (name != "") - varPrefix = name; + std::string varPrefix = name; + if (varPrefix == "") + varPrefix = prefix; ZResource::DeclareReferences(varPrefix); @@ -248,15 +210,31 @@ void ZLimbTable::DeclareReferences(const std::string& prefix) uint32_t limbOffset = Seg2Filespace(limbAddress, parent->baseAddress); if (!parent->HasDeclaration(limbOffset)) { - ZLimb* limb = new ZLimb(limbType, varPrefix, limbOffset, parent); + ZLimb* limb = new ZLimb(parent); + limb->ExtractFromBinary(limbOffset, limbType); + limb->SetName(limb->GetDefaultName(varPrefix)); + limb->DeclareVar(varPrefix, ""); limb->DeclareReferences(varPrefix); - limb->GetSourceOutputCode(varPrefix); parent->AddResource(limb); } } } } +Declaration* ZLimbTable::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + + if (name == "") + auxName = GetDefaultName(prefix); + + Declaration* decl = + parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(), + GetSourceTypeName(), auxName, limbsAddresses.size(), bodyStr); + decl->staticConf = staticConf; + return decl; +} + std::string ZLimbTable::GetBodySourceCode() const { std::string body = ""; @@ -273,22 +251,6 @@ std::string ZLimbTable::GetBodySourceCode() const return body; } -std::string ZLimbTable::GetSourceOutputCode([[maybe_unused]] const std::string& prefix) -{ - std::string body = GetBodySourceCode(); - - Declaration* decl = parent->GetDeclaration(rawDataIndex); - if (decl == nullptr || decl->isPlaceholder) - decl = parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, - GetRawDataSize(), GetSourceTypeName(), name, - limbsAddresses.size(), body); - else - decl->text = body; - decl->staticConf = staticConf; - - return ""; -} - std::string ZLimbTable::GetSourceTypeName() const { switch (limbType) |
