diff --git a/tools/ZAPD/.clang-format b/tools/ZAPD/.clang-format new file mode 100644 index 0000000000..784e734e97 --- /dev/null +++ b/tools/ZAPD/.clang-format @@ -0,0 +1,84 @@ +--- +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: false +ColumnLimit: 100 +CommentPragmas: '^ (IWYU pragma:|NOLINT)' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ForEachMacros: [ ] +IncludeCategories: + - Regex: '^<[Ww]indows\.h>$' + Priority: 1 + - Regex: '^<' + Priority: 2 + - Regex: '^"' + Priority: 3 +IndentCaseLabels: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Latest +TabWidth: 4 +UseTab: AlignWithSpaces +... + diff --git a/tools/ZAPD/.gitignore b/tools/ZAPD/.gitignore index 136ffb1b28..4a9671810a 100644 --- a/tools/ZAPD/.gitignore +++ b/tools/ZAPD/.gitignore @@ -332,5 +332,6 @@ ASALocalRun/ *.out *.o *.d +lib/libgfxd/libgfxd.a .vscode/ ZAPD/BuildInfo.h \ No newline at end of file diff --git a/tools/ZAPD/.gitrepo b/tools/ZAPD/.gitrepo index 511240f54b..0fcc361bdb 100644 --- a/tools/ZAPD/.gitrepo +++ b/tools/ZAPD/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/zeldaret/ZAPD.git branch = master - commit = 4bf6600a3b67223d5e28d6a1fccfeb54e37d7a77 - parent = 8e0fa07a7e03730951ba98a377cf7738e8f26295 + commit = 4751db5c9ee0a25a26379ca5b44efad72215d256 + parent = 77ec4d491610620338e592a0f853b7c59af7fba5 method = merge cmdver = 0.4.3 diff --git a/tools/ZAPD/Jenkinsfile b/tools/ZAPD/Jenkinsfile index 0240b8ed92..d7ea29396f 100644 --- a/tools/ZAPD/Jenkinsfile +++ b/tools/ZAPD/Jenkinsfile @@ -1,5 +1,7 @@ pipeline { - agent any + agent { + label "ZAPD" + } stages { stage('Build ZAPD') { diff --git a/tools/ZAPD/Makefile b/tools/ZAPD/Makefile index cd4cd2826a..0502cb5d10 100644 --- a/tools/ZAPD/Makefile +++ b/tools/ZAPD/Makefile @@ -1,11 +1,5 @@ CC := g++ - -ifneq (, $(shell which ccache)) -CC := ccache $(CC) -endif - CFLAGS := -g -std=c++17 -I ZAPD -I lib/assimp/include -I lib/elfio -I lib/json/include -I lib/stb -I lib/tinygltf -I lib/libgfxd -I lib/tinyxml2 -O2 -rdynamic - UNAME := $(shell uname) FS_INC = @@ -19,18 +13,22 @@ CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp)) CPP_FILES += lib/tinyxml2/tinyxml2.cpp O_FILES := $(CPP_FILES:.cpp=.o) -all: genbuildinfo ZAPD.out +all: ZAPD.out genbuildinfo: python3 ZAPD/genbuildinfo.py clean: rm -f $(O_FILES) ZAPD.out + $(MAKE) -C lib/libgfxd clean rebuild: clean all -%.o: %.cpp +%.o: %.cpp genbuildinfo $(CC) $(CFLAGS) -c $< -o $@ -ZAPD.out: $(O_FILES) +lib/libgfxd/libgfxd.a: + $(MAKE) -C lib/libgfxd -j + +ZAPD.out: $(O_FILES) lib/libgfxd/libgfxd.a $(CC) $(CFLAGS) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC) diff --git a/tools/ZAPD/ZAPD/BitConverter.h b/tools/ZAPD/ZAPD/BitConverter.h index dfc3c84407..9d209f055b 100644 --- a/tools/ZAPD/ZAPD/BitConverter.h +++ b/tools/ZAPD/ZAPD/BitConverter.h @@ -49,48 +49,66 @@ public: static inline int32_t ToInt32BE(const uint8_t* data, int offset) { - return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; } static inline int32_t ToInt32BE(const std::vector& data, int offset) { - return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; } static inline uint32_t ToUInt32BE(const uint8_t* data, int offset) { - return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; } static inline uint32_t ToUInt32BE(const std::vector& data, int offset) { - return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; } static inline int64_t ToInt64BE(const uint8_t* data, int offset) { - return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); } static inline int64_t ToInt64BE(const std::vector& data, int offset) { - return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); } static inline uint64_t ToUInt64BE(const uint8_t* data, int offset) { - return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); } static inline uint64_t ToUInt64BE(const std::vector& data, int offset) { - return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); } static inline float ToFloatBE(const uint8_t* data, int offset) { float value; - uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + + ((uint32_t)data[offset + 1] << 16) + + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; static_assert(sizeof(uint32_t) == sizeof(float)); std::memcpy(&value, &floatData, sizeof(value)); return value; @@ -99,7 +117,9 @@ public: static inline float ToFloatBE(const std::vector& data, int offset) { float value; - uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + + ((uint32_t)data[offset + 1] << 16) + + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; static_assert(sizeof(uint32_t) == sizeof(float)); std::memcpy(&value, &floatData, sizeof(value)); return value; @@ -108,9 +128,14 @@ public: static inline double ToDoubleBE(const uint8_t* data, int offset) { double value; - uint64_t floatData = ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + uint64_t floatData = + ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); static_assert(sizeof(uint64_t) == sizeof(double)); - // Checks if the float format on the platform the ZAPD binary is running on supports the same float format as the object file. + // Checks if the float format on the platform the ZAPD binary is running on supports the + // same float format as the object file. static_assert(std::numeric_limits::is_iec559); std::memcpy(&value, &floatData, sizeof(value)); return value; @@ -119,9 +144,14 @@ public: static inline double ToDoubleBE(const std::vector& data, int offset) { double value; - uint64_t floatData = ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + uint64_t floatData = + ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); static_assert(sizeof(uint64_t) == sizeof(double)); - // Checks if the float format on the platform the ZAPD binary is running on supports the same float format as the object file. + // Checks if the float format on the platform the ZAPD binary is running on supports the + // same float format as the object file. static_assert(std::numeric_limits::is_iec559); std::memcpy(&value, &floatData, sizeof(value)); return value; diff --git a/tools/ZAPD/ZAPD/Directory.h b/tools/ZAPD/ZAPD/Directory.h index bddec9d466..74bb14ed6c 100644 --- a/tools/ZAPD/ZAPD/Directory.h +++ b/tools/ZAPD/ZAPD/Directory.h @@ -1,7 +1,8 @@ #pragma once -#include #include +#include +#include #if __has_include() #include @@ -11,18 +12,14 @@ namespace fs = std::filesystem; namespace fs = std::experimental::filesystem; #endif +#include "StringHelper.h" + class Directory { public: - static std::string GetCurrentDirectory() - { - return fs::current_path().u8string(); - } + static std::string GetCurrentDirectory() { return fs::current_path().u8string(); } - static bool Exists(const std::string& path) - { - return fs::exists(fs::path(path)); - } + static bool Exists(const std::string& path) { return fs::exists(fs::path(path)); } static void CreateDirectory(const std::string& path) { @@ -37,6 +34,6 @@ public: fs::create_directory(curPath); } - //fs::create_directory(path); + // fs::create_directory(path); } }; diff --git a/tools/ZAPD/ZAPD/File.h b/tools/ZAPD/ZAPD/File.h index fe2e1fa3d7..5db466ad9b 100644 --- a/tools/ZAPD/ZAPD/File.h +++ b/tools/ZAPD/ZAPD/File.h @@ -1,11 +1,11 @@ #pragma once -#include #include -#include #include #include #include +#include +#include #include "StringHelper.h" class File @@ -25,7 +25,7 @@ public: char* data = new char[fileSize]; file.read(data, fileSize); std::vector result = std::vector(data, data + fileSize); - delete data; + delete[] data; return result; }; @@ -35,11 +35,11 @@ public: std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate); int fileSize = (int)file.tellg(); file.seekg(0); - char* data = new char[fileSize+1]; + char* data = new char[fileSize + 1]; memset(data, 0, fileSize + 1); file.read(data, fileSize); std::string str = std::string((const char*)data); - delete data; + delete[] data; return str; }; diff --git a/tools/ZAPD/ZAPD/Globals.cpp b/tools/ZAPD/ZAPD/Globals.cpp index 572ce2ef76..e6f2458dba 100644 --- a/tools/ZAPD/ZAPD/Globals.cpp +++ b/tools/ZAPD/ZAPD/Globals.cpp @@ -1,7 +1,7 @@ #include "Globals.h" +#include #include "File.h" #include "tinyxml2.h" -#include using namespace tinyxml2; using namespace std; @@ -14,7 +14,7 @@ Globals::Globals() files = std::vector(); segments = std::vector(); - symbolMap = std::map (); + symbolMap = std::map(); segmentRefs = map(); segmentRefFiles = map(); game = ZGame::OOT_RETAIL; @@ -45,9 +45,10 @@ string Globals::FindSymbolSegRef(int segNumber, uint32_t symbolAddress) if (root == nullptr) return "ERROR"; - //vector files = vector(); + // vector files = vector(); - for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = root->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { if (string(child->Name()) == "File") { @@ -78,7 +79,8 @@ void Globals::ReadConfigFile(const std::string& configFilePath) if (root == nullptr) return; - for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = root->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { if (string(child->Name()) == "SymbolMap") { diff --git a/tools/ZAPD/ZAPD/Globals.h b/tools/ZAPD/ZAPD/Globals.h index 7b034de135..6b7075f492 100644 --- a/tools/ZAPD/ZAPD/Globals.h +++ b/tools/ZAPD/ZAPD/Globals.h @@ -4,10 +4,11 @@ #include #include #include "ZFile.h" -#include "ZTexture.h" #include "ZRoom/ZRoom.h" +#include "ZTexture.h" -typedef enum VerbosityLevel { +typedef enum VerbosityLevel +{ VERBOSITY_SILENT, VERBOSITY_INFO, VERBOSITY_DEBUG @@ -20,12 +21,12 @@ class Globals public: static Globals* Instance; - bool genSourceFile; // Used for extraction + bool genSourceFile; // Used for extraction bool useExternalResources; - bool testMode; // Enables certain experimental features - bool profile; // Measure performance of certain operations - bool includeFilePrefix; // Include the file prefix in symbols - VerbosityLevel verbosity; // ZAPD outputs additional information + bool testMode; // Enables certain experimental features + bool profile; // Measure performance of certain operations + bool includeFilePrefix; // Include the file prefix in symbols + VerbosityLevel verbosity; // ZAPD outputs additional information ZFileMode fileMode; std::string baseRomPath, inputPath, outputPath, cfgPath; TextureType texType; @@ -58,11 +59,11 @@ public: GameConfig(); private: - }; /* - * Note: In being able to track references across files, there are a few major files that make use of segments... + * Note: In being able to track references across files, there are a few major files that make use + * of segments... * Segment 1: nintendo_rogo_static/title_static * Segment 2: parameter_static * Segment 4: gameplay_keep diff --git a/tools/ZAPD/ZAPD/HighLevel/HLAnimation.h b/tools/ZAPD/ZAPD/HighLevel/HLAnimation.h index dfc4532462..52d6847a66 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLAnimation.h +++ b/tools/ZAPD/ZAPD/HighLevel/HLAnimation.h @@ -9,5 +9,4 @@ class HLAnimation { public: - }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp index 1b64af1357..7d879c9470 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp +++ b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp @@ -14,7 +14,6 @@ HLAnimationIntermediette::HLAnimationIntermediette() HLAnimationIntermediette::~HLAnimationIntermediette() { - } HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath) @@ -30,11 +29,13 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath) anim->limbCount = root->IntAttribute("LimbCount"); anim->frameCount = root->IntAttribute("FrameCount"); - for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = root->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { if (string(child->Name()) == "RotationValues") { - for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL; child2 = child2->NextSiblingElement()) + for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL; + child2 = child2->NextSiblingElement()) { string value = child2->GetText(); anim->rotationValues.push_back(atoi(value.c_str())); @@ -42,8 +43,11 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath) } else if (string(child->Name()) == "RotationIndices") { - for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL; child2 = child2->NextSiblingElement()) - anim->rotationIndices.push_back(RotationIndex(child2->IntAttribute("X"), child2->IntAttribute("Y"), child2->IntAttribute("Z"))); + for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL; + child2 = child2->NextSiblingElement()) + anim->rotationIndices.push_back(RotationIndex(child2->IntAttribute("X"), + child2->IntAttribute("Y"), + child2->IntAttribute("Z"))); } } @@ -56,12 +60,12 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromZAnimation(ZAnimation* z /*anim->limit = zAnim->limit; anim->frameCount = zAnim->frameCount; - + for (uint16_t item : zAnim->rotationValues) - anim->rotationValues.push_back(item); + anim->rotationValues.push_back(item); for (RotationIndex item : zAnim->rotationIndices) - anim->rotationIndices.push_back(item);*/ + anim->rotationIndices.push_back(item);*/ return anim; } @@ -74,10 +78,10 @@ ZAnimation* HLAnimationIntermediette::ToZAnimation() zAnim->frameCount = frameCount; for (uint16_t item : rotationValues) - zAnim->rotationValues.push_back(item); + zAnim->rotationValues.push_back(item); for (RotationIndex item : rotationIndices) - zAnim->rotationIndices.push_back(item);*/ + zAnim->rotationIndices.push_back(item);*/ return zAnim; } @@ -95,19 +99,19 @@ string HLAnimationIntermediette::OutputXML() doc.InsertFirstChild(root); XMLElement* rotValues = doc.NewElement("RotationValues"); - - for (int i = 0; i < rotationValues.size(); i++) + + for (size_t i = 0; i < rotationValues.size(); i++) { XMLElement* rotValue = doc.NewElement("Value"); rotValue->SetText(rotationValues[i]); rotValues->InsertEndChild(rotValue); } - + root->InsertEndChild(rotValues); XMLElement* rotIndices = doc.NewElement("RotationIndices"); - for (int i = 0; i < rotationIndices.size(); i++) + for (size_t i = 0; i < rotationIndices.size(); i++) { XMLElement* rotIndex = doc.NewElement("Value"); rotIndex->SetAttribute("X", rotationIndices[i].x); diff --git a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.h b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.h index 42ba9bbde8..0f5c00b04f 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.h +++ b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.h @@ -1,8 +1,8 @@ #pragma once #include -#include "../ZAnimation.h" #include +#include "../ZAnimation.h" #include "HLFileIntermediette.h" /* @@ -23,7 +23,7 @@ public: HLAnimationIntermediette(); ~HLAnimationIntermediette(); - + std::string OutputXML(); ZAnimation* ToZAnimation(); diff --git a/tools/ZAPD/ZAPD/HighLevel/HLFileIntermediette.h b/tools/ZAPD/ZAPD/HighLevel/HLFileIntermediette.h index bd18f1e146..ef16bb8fd9 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLFileIntermediette.h +++ b/tools/ZAPD/ZAPD/HighLevel/HLFileIntermediette.h @@ -2,5 +2,4 @@ class HLFileIntermediette { - }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp index bd8ec784ee..25355378f4 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp +++ b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp @@ -1,15 +1,15 @@ #include "HLModelIntermediette.h" -#include "../ZDisplayList.h" -#include "../StringHelper.h" +#include "../File.h" #include "../Globals.h" #include "../Path.h" -#include "../File.h" +#include "../StringHelper.h" +#include "../ZDisplayList.h" #ifdef USE_ASSIMP -#include #include -#include +#include #include +#include #endif using namespace std; @@ -31,7 +31,8 @@ HLModelIntermediette* HLModelIntermediette::FromXML(tinyxml2::XMLElement* root) { HLModelIntermediette* model = new HLModelIntermediette(); - for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = root->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { string childName = child->Name(); HLIntermediette* block = nullptr; @@ -60,18 +61,18 @@ HLModelIntermediette* HLModelIntermediette::FromXML(tinyxml2::XMLElement* root) void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDisplayList* zDisplayList) { - //HLModelIntermediette* model = new HLModelIntermediette(); + // HLModelIntermediette* model = new HLModelIntermediette(); HLLimbIntermediette* limb = new HLLimbIntermediette(); limb->name = zDisplayList->GetName(); // Go through verts vector finalVerts = vector(); - uint32_t vStart = -1; + int32_t vStart = -1; - for (pair> pair : zDisplayList->vertices) + for (pair> pair : zDisplayList->vertices) { - if (vStart == -1) // TODO: Find a better way to do this + if (vStart == -1) // TODO: Find a better way to do this vStart = pair.first; for (Vertex v : pair.second) @@ -97,7 +98,7 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla HLDisplayListIntermediette* dList = new HLDisplayListIntermediette(); dList->address = zDisplayList->GetRawDataIndex(); int startIndex = 0; - + // Go through the display lists and setup commands int meshCnt = 0; @@ -112,7 +113,7 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla startIndex = 0; - for (int i = startIndex; i < zDisplayList->instructions.size(); i++) + for (size_t i = startIndex; i < zDisplayList->instructions.size(); i++) { uint64_t data = zDisplayList->instructions[i]; F3DZEXOpcode opcode = (F3DZEXOpcode)(data >> 56); @@ -121,15 +122,14 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla { int ss = (data & 0x0000FF0000000000) >> 40; int nn = (data & 0x000000FF00000000) >> 32; - int dd = (data & 0xFFFFFFFF); + // int dd = (data & 0xFFFFFFFF); int sft = 32 - (nn + 1) - ss; if (sft == 3) { - int mode1 = (dd & 0xCCCC0000) >> 0; - int mode2 = (dd & 0x33330000) >> 0; - + // int mode1 = (dd & 0xCCCC0000) >> 0; + // int mode2 = (dd & 0x33330000) >> 0; } } else if (opcode == F3DZEXOpcode::G_SETPRIMCOLOR) @@ -155,20 +155,30 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla lastMat->clrL = ff; lastMat->clrM = mm; } - else if (opcode == F3DZEXOpcode::G_SETTILE && (F3DZEXOpcode)(zDisplayList->instructions[i - 1] >> 56) != F3DZEXOpcode::G_RDPPIPESYNC) + else if (opcode == F3DZEXOpcode::G_SETTILE && + (F3DZEXOpcode)(zDisplayList->instructions[i - 1] >> 56) != + F3DZEXOpcode::G_RDPPIPESYNC) { - int fff = (data & 0b0000000011100000000000000000000000000000000000000000000000000000) >> 53; - int ii = (data & 0b0000000000011000000000000000000000000000000000000000000000000000) >> 51; - int nnnnnnnnn = (data & 0b0000000000000011111111100000000000000000000000000000000000000000) >> 41; - int mmmmmmmmm = (data & 0b0000000000000000000000011111111100000000000000000000000000000000) >> 32; - int ttt = (data & 0b0000000000000000000000000000000000000111000000000000000000000000) >> 24; - int pppp = (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >> 20; - int cc = (data & 0b0000000000000000000000000000000000000000000011000000000000000000) >> 18; - int aaaa = (data & 0b0000000000000000000000000000000000000000000000111100000000000000) >> 14; - int ssss = (data & 0b0000000000000000000000000000000000000000000000000011110000000000) >> 10; - int dd = (data & 0b0000000000000000000000000000000000000000000000000000001100000000) >> 8; - int bbbb = (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; - int uuuu = (data & 0b0000000000000000000000000000000000000000000000000000000000001111); + // int fff = (data & 0b0000000011100000000000000000000000000000000000000000000000000000) + // >> 53; int ii = (data & + // 0b0000000000011000000000000000000000000000000000000000000000000000) >> 51; int + // nnnnnnnnn = (data & + // 0b0000000000000011111111100000000000000000000000000000000000000000) >> 41; int + // mmmmmmmmm = (data & + // 0b0000000000000000000000011111111100000000000000000000000000000000) >> 32; int ttt = + // (data & 0b0000000000000000000000000000000000000111000000000000000000000000) >> 24; int + // pppp = (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >> + // 20; + int cc = + (data & 0b0000000000000000000000000000000000000000000011000000000000000000) >> 18; + // int aaaa = (data & + // 0b0000000000000000000000000000000000000000000000111100000000000000) >> 14; int ssss = + // (data & 0b0000000000000000000000000000000000000000000000000011110000000000) >> 10; + int dd = + (data & 0b0000000000000000000000000000000000000000000000000000001100000000) >> 8; + // int bbbb = (data & + // 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; int uuuu = + // (data & 0b0000000000000000000000000000000000000000000000000000000000001111); lastMat->cmtH = (HLMaterialCmt)cc; lastMat->cmtV = (HLMaterialCmt)dd; @@ -188,7 +198,7 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla lastMat->clrA = lastClrA; lastMat->clrL = lastClrL; lastMat->clrM = lastClrM; - + // Bit of a hack here... int32_t lastData = (int32_t)(zDisplayList->instructions[i - 1]); string texName = zDisplayList->textures[lastData & 0x00FFFFFF]->GetName(); @@ -200,7 +210,8 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla meshCnt++; mesh = new HLMeshIntermediette(); - mesh->name = StringHelper::Sprintf("%s_%i", zDisplayList->GetName().c_str(), meshCnt); + mesh->name = + StringHelper::Sprintf("%s_%i", zDisplayList->GetName().c_str(), meshCnt); } } else if (opcode == F3DZEXOpcode::G_SETTIMG) @@ -242,7 +253,7 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla mesh->commands.push_back(new HLMeshCmdTriangle2(aa, bb, cc, 0, dd, ee, ff, 0)); } - int bp = 0; + // int bp = 0; } limb->commands.push_back(new HLLimbCommand(mesh->name, lastMat->name)); @@ -250,18 +261,18 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla model->blocks.push_back(mesh); model->blocks.push_back(limb); - //return model; + // return model; } void HLModelIntermediette::FromZSkeleton(HLModelIntermediette* model, ZSkeleton* zSkeleton) { model->hasSkeleton = true; - for (int i = 0; i < zSkeleton->limbs.size(); i++) + for (size_t i = 0; i < zSkeleton->limbs.size(); i++) { - ZLimb* limb = zSkeleton->limbs[i]; + // ZLimb* limb = zSkeleton->limbs[i]; - for (int j = 0; j < model->blocks.size(); j++) + for (size_t j = 0; j < model->blocks.size(); j++) { } } @@ -332,7 +343,7 @@ string HLModelIntermediette::OutputCode() for (HLIntermediette* block : blocks) { string code = block->OutputCode(); - + output += code; if (code != "") @@ -360,8 +371,7 @@ std::string HLModelIntermediette::OutputXML() return printer.CStr(); } - -template +template inline T* HLModelIntermediette::FindByName(string name) { for (HLIntermediette* block : blocks) @@ -376,7 +386,7 @@ inline T* HLModelIntermediette::FindByName(string name) return nullptr; } -template +template inline T* HLModelIntermediette::FindByType() { for (HLIntermediette* block : blocks) @@ -415,17 +425,14 @@ string HLIntermediette::OutputOBJ() void HLIntermediette::OutputAssimp(aiScene* scene, std::vector* verts) { - } void HLIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root) { - } void HLMeshCommand::InitFromXML(XMLElement* xmlElement) { - } string HLMeshCommand::OutputCode(HLModelIntermediette* parent) @@ -446,7 +453,6 @@ void HLMeshCommand::OutputXML(tinyxml2::XMLElement* parent) { } - HLVerticesIntermediette::HLVerticesIntermediette() : HLIntermediette() { vertices = vector(); @@ -456,10 +462,13 @@ void HLVerticesIntermediette::InitFromXML(XMLElement* verticesElement) { name = verticesElement->Attribute("Name"); - for (XMLElement* child = verticesElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) - vertices.push_back(Vertex(child->IntAttribute("X"), child->IntAttribute("Y"), child->IntAttribute("Z"), child->IntAttribute("Flags"), - child->IntAttribute("S"), child->IntAttribute("T"), - child->IntAttribute("R"), child->IntAttribute("G"), child->IntAttribute("B"), child->IntAttribute("A"))); + for (XMLElement* child = verticesElement->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) + vertices.push_back(Vertex(child->IntAttribute("X"), child->IntAttribute("Y"), + child->IntAttribute("Z"), child->IntAttribute("Flags"), + child->IntAttribute("S"), child->IntAttribute("T"), + child->IntAttribute("R"), child->IntAttribute("G"), + child->IntAttribute("B"), child->IntAttribute("A"))); } void HLVerticesIntermediette::InitFromVertices(vector dispListVertices) @@ -476,8 +485,8 @@ string HLVerticesIntermediette::OutputCode(HLModelIntermediette* parent) for (Vertex v : vertices) { - output += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", - v.x, v.y, v.z, v.flag, v.s, v.t, v.r, v.g, v.b, v.a); + output += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", v.x, v.y, + v.z, v.flag, v.s, v.t, v.r, v.g, v.b, v.a); } output += StringHelper::Sprintf("};\n"); @@ -491,32 +500,34 @@ std::string HLVerticesIntermediette::OutputOBJ() for (Vertex v : vertices) { - output += StringHelper::Sprintf("v %f %f %f %i %i %i %i\n", (float)v.x * 0.1f, (float)v.y * 0.1f, (float)v.z * 0.1f, v.r, v.g, v.b, v.a); - //output += StringHelper::Sprintf("v %f %f %f\n", (float)v.x * 0.1f, (float)v.y * 0.1f, (float)v.z * 0.1f); + output += StringHelper::Sprintf("v %f %f %f %i %i %i %i\n", (float)v.x * 0.1f, + (float)v.y * 0.1f, (float)v.z * 0.1f, v.r, v.g, v.b, v.a); + // output += StringHelper::Sprintf("v %f %f %f\n", (float)v.x * 0.1f, (float)v.y * 0.1f, + // (float)v.z * 0.1f); } - //for (Vertex v : vertices) - //output += StringHelper::Sprintf("vt %i %i\n", v.s, v.t); + // for (Vertex v : vertices) + // output += StringHelper::Sprintf("vt %i %i\n", v.s, v.t); return output; } void HLVerticesIntermediette::OutputAssimp(aiScene* scene, std::vector* verts) { - //aiVector3D* verts = new aiVector3D[vertices.size()]; - //aiVector3D* normals = new aiVector3D[vertices.size()]; + // aiVector3D* verts = new aiVector3D[vertices.size()]; + // aiVector3D* normals = new aiVector3D[vertices.size()]; verts->clear(); - for (int i = 0; i < vertices.size(); i++) + for (size_t i = 0; i < vertices.size(); i++) { verts->push_back(aiVector3D(vertices[i].x, vertices[i].y, vertices[i].z)); - //normals[i] = aiVector3D(vertices[i].x, vertices[i].y, vertices[i].z); + // normals[i] = aiVector3D(vertices[i].x, vertices[i].y, vertices[i].z); } - //mesh->mVertices = verts; - //mesh->mNormals = normals; - //mesh->mNumVertices += vertices.size(); + // mesh->mVertices = verts; + // mesh->mNormals = normals; + // mesh->mNumVertices += vertices.size(); } void HLVerticesIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root) @@ -562,8 +573,9 @@ string HLMeshCmdGeoSettings::OutputCode(HLModelIntermediette* parent) string output = ""; if (off != "") - output += StringHelper::Sprintf("gsSPClearGeometryMode(G_TEXTURE_ENABLE | %s),\n", off.c_str()); - + output += + StringHelper::Sprintf("gsSPClearGeometryMode(G_TEXTURE_ENABLE | %s),\n", off.c_str()); + if (on != "") output += StringHelper::Sprintf("gsSPSetGeometryMode(G_TEXTURE_ENABLE | %s),", on.c_str()); @@ -635,7 +647,8 @@ HLMeshCmdTriangle2::HLMeshCmdTriangle2() flag1 = 0; } -HLMeshCmdTriangle2::HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0, int32_t nV10, int32_t nV11, int32_t nV12, int32_t nFlag1) +HLMeshCmdTriangle2::HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0, + int32_t nV10, int32_t nV11, int32_t nV12, int32_t nFlag1) { v0 = nV0; v1 = nV1; @@ -654,25 +667,28 @@ void HLMeshCmdTriangle2::InitFromXML(tinyxml2::XMLElement* xmlElement) v2 = xmlElement->IntAttribute("V2"); flag0 = xmlElement->IntAttribute("Flag0"); v10 = xmlElement->IntAttribute("V10"); - v11 = xmlElement->IntAttribute("V11"); + v11 = xmlElement->IntAttribute("V11"); v12 = xmlElement->IntAttribute("V12"); flag1 = xmlElement->IntAttribute("Flag1"); } string HLMeshCmdTriangle2::OutputCode(HLModelIntermediette* parent) { - return StringHelper::Sprintf("gsSP2Triangles(%i, %i, %i, %i, %i, %i, %i, %i),", v0, v1, v2, flag0, v10, v11, v12, flag1); + return StringHelper::Sprintf("gsSP2Triangles(%i, %i, %i, %i, %i, %i, %i, %i),", v0, v1, v2, + flag0, v10, v11, v12, flag1); } std::string HLMeshCmdTriangle2::OutputOBJ(HLModelIntermediette* parent) { - HLVerticesIntermediette* verts = parent->FindByName(""); + // HLVerticesIntermediette* verts = parent->FindByName(""); string output = ""; int startIndex = parent->startIndex; - output += StringHelper::Sprintf("f %i %i %i\n", startIndex+v0+1, startIndex + v1+1, startIndex + v2+1); - output += StringHelper::Sprintf("f %i %i %i\n", startIndex + v10+1, startIndex + v11+1, startIndex + v12+1); + output += StringHelper::Sprintf("f %i %i %i\n", startIndex + v0 + 1, startIndex + v1 + 1, + startIndex + v2 + 1); + output += StringHelper::Sprintf("f %i %i %i\n", startIndex + v10 + 1, startIndex + v11 + 1, + startIndex + v12 + 1); return output; } @@ -714,7 +730,7 @@ void HLMeshCmdTriangle2::OutputXML(tinyxml2::XMLElement* parent) elem->SetAttribute("V11", v11); elem->SetAttribute("V12", v12); elem->SetAttribute("Flag1", flag1); - + parent->InsertEndChild(elem); } @@ -736,7 +752,7 @@ void HLMeshCmdLoadVertices::OutputXML(tinyxml2::XMLElement* parent) elem->SetAttribute("StartIndex", startIndex); elem->SetAttribute("NumVerts", numVerts); - + parent->InsertEndChild(elem); } @@ -760,24 +776,25 @@ void HLMeshCmdLoadVertices::OutputAssimp(HLModelIntermediette* parent, aiScene* string HLMeshCmdLoadVertices::OutputCode(HLModelIntermediette* parent) { HLVerticesIntermediette* verts = parent->FindByType(); - return StringHelper::Sprintf("gsSPVertex(&%s[%i], %i, %i),", verts->name.c_str(), startIndex, numVerts, 0); + return StringHelper::Sprintf("gsSPVertex(&%s[%i], %i, %i),", verts->name.c_str(), startIndex, + numVerts, 0); } HLMaterialIntermediette::HLMaterialIntermediette() { textureName = ""; - //repeatH = false; - //repeatV = false; + // repeatH = false; + // repeatV = false; clrR = 0; clrG = 0; clrB = 0; clrA = 0; clrM = 0; clrL = 0; - //clampH = false; - //clampV = false; - //mirrorH = false; - //mirrorV = false; + // clampH = false; + // clampV = false; + // mirrorH = false; + // mirrorV = false; cmtH = HLMaterialCmt::Wrap; cmtV = HLMaterialCmt::Wrap; } @@ -786,12 +803,12 @@ void HLMaterialIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement) { name = xmlElement->Attribute("Name"); textureName = xmlElement->Attribute("TextureName"); - //repeatH = xmlElement->BoolAttribute("RepeatH"); - //repeatV = xmlElement->BoolAttribute("RepeatV"); - //clampH = xmlElement->BoolAttribute("ClampH"); - //clampV = xmlElement->BoolAttribute("ClampV"); - //mirrorH = xmlElement->BoolAttribute("MirrorH"); - //mirrorV = xmlElement->BoolAttribute("MirrorV"); + // repeatH = xmlElement->BoolAttribute("RepeatH"); + // repeatV = xmlElement->BoolAttribute("RepeatV"); + // clampH = xmlElement->BoolAttribute("ClampH"); + // clampV = xmlElement->BoolAttribute("ClampV"); + // mirrorH = xmlElement->BoolAttribute("MirrorH"); + // mirrorV = xmlElement->BoolAttribute("MirrorV"); clrR = xmlElement->IntAttribute("ClrR"); clrG = xmlElement->IntAttribute("ClrG"); clrB = xmlElement->IntAttribute("ClrB"); @@ -835,7 +852,8 @@ string HLDisplayListIntermediette::OutputCode() void HLDisplayListIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement) { - for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { string name = child->Name(); @@ -867,7 +885,6 @@ void HLDisplayListCmdDrawMesh::InitFromXML(tinyxml2::XMLElement* xmlElement) { meshName = xmlElement->Attribute("Mesh"); materialName = xmlElement->Attribute("Material"); - } std::string HLDisplayListCmdDrawMesh::OutputCode() @@ -885,16 +902,19 @@ void HLTextureIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement) name = xmlElement->Attribute("Name"); fileName = xmlElement->Attribute("TextureName"); - //string format = xmlElement->Attribute("Format"); - string format = "rgb5a1"; // TEST + // string format = xmlElement->Attribute("Format"); + string format = "rgb5a1"; // TEST - //tex = HLTexture::FromPNG(fileName, (HLTextureType)ZTexture::GetTextureTypeFromString(format)); - tex = ZTexture::FromPNG(Path::GetDirectoryName(Globals::Instance->inputPath) + "/" + fileName, ZTexture::GetTextureTypeFromString(format)); + // tex = HLTexture::FromPNG(fileName, + // (HLTextureType)ZTexture::GetTextureTypeFromString(format)); + tex = ZTexture::FromPNG(Path::GetDirectoryName(Globals::Instance->inputPath) + "/" + fileName, + ZTexture::GetTextureTypeFromString(format)); } std::string HLTextureIntermediette::OutputCode() { - return StringHelper::Sprintf("#include <../%s/%s.inc.c>", Globals::Instance->outputPath.c_str(), name.c_str()); + return StringHelper::Sprintf("#include <../%s/%s.inc.c>", Globals::Instance->outputPath.c_str(), + name.c_str()); } void HLTextureIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root) @@ -902,7 +922,8 @@ void HLTextureIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XML XMLElement* element = doc->NewElement("Texture"); element->SetAttribute("Name", name.c_str()); - element->SetAttribute("TextureName", (name + "." + tex->GetExternalExtension() + ".png").c_str()); + element->SetAttribute("TextureName", + (name + "." + tex->GetExternalExtension() + ".png").c_str()); tex->Save(Globals::Instance->outputPath); root->InsertEndChild(element); @@ -943,7 +964,8 @@ void HLMeshIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement) { name = xmlElement->Attribute("Name"); - for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { string name = child->Name(); @@ -976,13 +998,15 @@ string HLMeshIntermediette::OutputCode(string materialName) HLTextureIntermediette* tex = parent->FindByName(mat->textureName); output += StringHelper::Sprintf("\tgsDPPipeSync(),\n"); - output += StringHelper::Sprintf("\tgsDPSetPrimColor(%i, %i, %i, %i, %i, %i),\n", mat->clrL, mat->clrM, mat->clrR, mat->clrG, mat->clrB, mat->clrA); + output += StringHelper::Sprintf("\tgsDPSetPrimColor(%i, %i, %i, %i, %i, %i),\n", mat->clrL, + mat->clrM, mat->clrR, mat->clrG, mat->clrB, mat->clrA); output += StringHelper::Sprintf("\tgsDPPipeSync(),\n"); output += StringHelper::Sprintf("\tgsSPTexture(65535, 65535, 0, 0, G_ON),\n"); - output += StringHelper::Sprintf("\tgsDPLoadMultiBlock(%s, 0, 0, %s, %s, %i, %i, 0, 0, 0, 5, 5, 0, 0),\n", mat->textureName.c_str(), - tex->tex->GetIMFmtFromType().c_str(), tex->tex->GetIMSizFromType().c_str(), tex->tex->GetWidth(), tex->tex->GetHeight()); - + output += StringHelper::Sprintf( + "\tgsDPLoadMultiBlock(%s, 0, 0, %s, %s, %i, %i, 0, 0, 0, 5, 5, 0, 0),\n", + mat->textureName.c_str(), tex->tex->GetIMFmtFromType().c_str(), + tex->tex->GetIMSizFromType().c_str(), tex->tex->GetWidth(), tex->tex->GetHeight()); for (HLMeshCommand* cmd : commands) output += "\t" + cmd->OutputCode(parent) + "\n"; @@ -1005,7 +1029,8 @@ string HLMeshIntermediette::OutputOBJ() void HLMeshIntermediette::OutputAssimp(aiScene* scene, std::vector* verts) { aiMesh* mesh = new aiMesh(); - mesh->mVertices = new aiVector3D[8192]; // TODO: Replace these hardcoded counts with the actual count + mesh->mVertices = + new aiVector3D[8192]; // TODO: Replace these hardcoded counts with the actual count mesh->mNormals = new aiVector3D[8192]; mesh->mFaces = new aiFace[8192]; mesh->mPrimitiveTypes = 8; @@ -1024,12 +1049,12 @@ void HLMeshIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLEle XMLElement* element = doc->NewElement("Mesh"); element->SetAttribute("Name", name.c_str()); - + for (HLMeshCommand* cmd : commands) { cmd->OutputXML(element); } - + root->InsertEndChild(element); } @@ -1042,7 +1067,8 @@ void HLLimbIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement) { name = xmlElement->Attribute("Name"); - for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { string name = child->Name(); @@ -1120,8 +1146,8 @@ std::string HLLimbCommand::OutputCode(HLModelIntermediette* parent) // Time to generate the display list... HLMeshIntermediette* mesh = parent->FindByName(meshName); - HLMaterialIntermediette* mat = parent->FindByName(materialName); - HLTextureIntermediette* tex = parent->FindByName(mat->textureName); + // HLMaterialIntermediette* mat = parent->FindByName(materialName); + // HLTextureIntermediette* tex = parent->FindByName(mat->textureName); output += mesh->OutputCode(materialName); @@ -1138,11 +1164,11 @@ HLTerminator::~HLTerminator() void HLTerminator::OutputAssimp(aiScene* scene, std::vector* verts) { - for (int i = parent->meshStartIndex; i < scene->mNumMeshes; i++) + for (uint32_t i = parent->meshStartIndex; i < scene->mNumMeshes; i++) { scene->mMeshes[i]->mNumVertices = verts->size(); - for (int j = 0; j < verts->size(); j++) + for (uint32_t j = 0; j < verts->size(); j++) scene->mMeshes[i]->mVertices[j] = verts[0][j]; parent->meshStartIndex++; diff --git a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h index c64653ef5d..b879974600 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h +++ b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h @@ -1,14 +1,14 @@ #pragma once +#include #include -#include #include -#include "HLTexture.h" -#include "HLFileIntermediette.h" +#include +#include #include "../ZDisplayList.h" #include "../ZSkeleton.h" -#include -#include +#include "HLFileIntermediette.h" +#include "HLTexture.h" /* * An intermediette format for models. Goes from FBX<-->Intermediette<-->Display List C Code. @@ -43,8 +43,8 @@ public: bool startsWithClearGeometryMode; bool lerpBeforeTextureBlock; - int startIndex; - int meshStartIndex; + uint32_t startIndex; + uint32_t meshStartIndex; HLModelIntermediette(); ~HLModelIntermediette(); @@ -98,10 +98,10 @@ class HLMaterialIntermediette : public HLIntermediette { public: std::string textureName; - //int32_t repeatH, repeatV; + // int32_t repeatH, repeatV; uint8_t clrR, clrG, clrB, clrA, clrM, clrL; - //bool clampH, clampV; - //bool mirrorH, mirrorV; + // bool clampH, clampV; + // bool mirrorH, mirrorV; HLMaterialCmt cmtH, cmtV; // TODO: Remember to add lerp params here... @@ -130,7 +130,7 @@ public: std::vector vertices; HLVerticesIntermediette(); - + virtual void InitFromXML(tinyxml2::XMLElement* verticesElement); void InitFromVertices(std::vector dispListVertices); virtual std::string OutputCode(HLModelIntermediette* parent); @@ -159,7 +159,8 @@ public: int32_t v0, v1, v2, flag0, v10, v11, v12, flag1; HLMeshCmdTriangle2(); - HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0, int32_t nV10, int32_t nV11, int32_t nV12, int32_t nFlag1); + HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0, int32_t nV10, + int32_t nV11, int32_t nV12, int32_t nFlag1); virtual void InitFromXML(tinyxml2::XMLElement* xmlElement); virtual std::string OutputCode(HLModelIntermediette* parent); diff --git a/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp b/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp index 192c50e22f..f9b362cfdc 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp +++ b/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp @@ -1,6 +1,6 @@ #include "HLTexture.h" -#include "../StringHelper.h" #include +#include "../StringHelper.h" using namespace std; @@ -9,7 +9,8 @@ HLTexture* HLTexture::FromPNG(std::string pngFilePath, HLTextureType texType) int comp; HLTexture* tex = new HLTexture(); tex->type = texType; - tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int*)&tex->width, (int*)&tex->height, &comp, STBI_rgb_alpha); - + tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int*)&tex->width, (int*)&tex->height, + &comp, STBI_rgb_alpha); + return tex; } diff --git a/tools/ZAPD/ZAPD/HighLevel/HLTexture.h b/tools/ZAPD/ZAPD/HighLevel/HLTexture.h index c8c187b80a..53f1cadee6 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLTexture.h +++ b/tools/ZAPD/ZAPD/HighLevel/HLTexture.h @@ -1,10 +1,11 @@ #pragma once #include -#include #include +#include -// TODO: This was duplicated from ZTexture. It's probably going to be modified to differentiate from ZTexture but if not, we're going to need to have the two share an enum. +// TODO: This was duplicated from ZTexture. It's probably going to be modified to differentiate from +// ZTexture but if not, we're going to need to have the two share an enum. enum class HLTextureType { RGBA32bpp, @@ -19,7 +20,6 @@ enum class HLTextureType Error }; - class HLTexture { public: diff --git a/tools/ZAPD/ZAPD/Main.cpp b/tools/ZAPD/ZAPD/Main.cpp index 9e0195c508..d771e7a357 100644 --- a/tools/ZAPD/ZAPD/Main.cpp +++ b/tools/ZAPD/ZAPD/Main.cpp @@ -1,20 +1,20 @@ -#include "ZFile.h" -#include "ZTexture.h" -#include "ZBlob.h" -#include "ZAnimation.h" -#include "HighLevel/HLModelIntermediette.h" +#include "BuildInfo.h" +#include "Directory.h" +#include "File.h" +#include "Globals.h" #include "HighLevel/HLAnimationIntermediette.h" +#include "HighLevel/HLModelIntermediette.h" #include "Overlays/ZOverlay.h" #include "Path.h" -#include "File.h" -#include "Directory.h" -#include "Globals.h" -#include "BuildInfo.h" +#include "ZAnimation.h" +#include "ZBlob.h" +#include "ZFile.h" +#include "ZTexture.h" #if !defined(_MSC_VER) && !defined(__CYGWIN__) #include -#include #include +#include #endif #include @@ -23,9 +23,11 @@ using namespace tinyxml2; using namespace std; -bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, ZFileMode fileMode); +bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, + ZFileMode fileMode); -void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, const std::string& outPath); +void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, + const std::string& outPath); void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath); void BuildAssetModelIntermediette(const std::string& mdlPath, const std::string& outPath); void BuildAssetAnimationIntermediette(const std::string& animPath, const std::string& outPath); @@ -41,13 +43,13 @@ void ErrorHandler(int sig) size = backtrace(array, 4096); symbols = backtrace_symbols(array, 4096); - for (int i = 1; i < size; i++) + for (size_t i = 1; i < size; i++) { - size_t len = strlen(symbols[i]); + // size_t len = strlen(symbols[i]); cout << symbols[i] << "\n"; } - //cout << "Error: signal " << sig << ":\n"; + // cout << "Error: signal " << sig << ":\n"; backtrace_symbols_fd(array, size, STDERR_FILENO); exit(1); } @@ -101,82 +103,83 @@ int NewMain(int argc, char* argv[]) { string arg = argv[i]; - if (arg == "-o" || arg == "--outputpath") // Set output path + if (arg == "-o" || arg == "--outputpath") // Set output path { Globals::Instance->outputPath = argv[i + 1]; i++; } - else if (arg == "-i" || arg == "--inputpath") // Set input path + else if (arg == "-i" || arg == "--inputpath") // Set input path { Globals::Instance->inputPath = argv[i + 1]; i++; } - else if (arg == "-b" || arg == "--baserompath") // Set baserom path + else if (arg == "-b" || arg == "--baserompath") // Set baserom path { Globals::Instance->baseRomPath = argv[i + 1]; i++; } - else if (arg == "-gsf") // Generate source file during extraction + else if (arg == "-gsf") // Generate source file during extraction { Globals::Instance->genSourceFile = string(argv[i + 1]) == "1"; i++; } - else if (arg == "-ifp") // Include file prefix in generated symbols + else if (arg == "-ifp") // Include file prefix in generated symbols { Globals::Instance->includeFilePrefix = string(argv[i + 1]) == "1"; i++; } - else if (arg == "-tm") // Test Mode + else if (arg == "-tm") // Test Mode { Globals::Instance->testMode = string(argv[i + 1]) == "1"; i++; } - else if (arg == "-profile") // Profile + else if (arg == "-profile") // Profile { Globals::Instance->profile = string(argv[i + 1]) == "1"; i++; } - else if (arg == "-uer") // Split resources into their individual components (enabled by default) + else if (arg == + "-uer") // Split resources into their individual components (enabled by default) { Globals::Instance->useExternalResources = string(argv[i + 1]) == "1"; i++; } - else if (arg == "-tt") // Set texture type + else if (arg == "-tt") // Set texture type { Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[i + 1]); i++; } - else if (arg == "-cfg") // Set cfg path + else if (arg == "-cfg") // Set cfg path { Globals::Instance->cfgPath = argv[i + 1]; i++; } - else if (arg == "-sm") // Set symbol map path + else if (arg == "-sm") // Set symbol map path { Globals::Instance->GenSymbolMap(argv[i + 1]); i++; } - else if (arg == "-rconf") // Read Config File + else if (arg == "-rconf") // Read Config File { Globals::Instance->ReadConfigFile(argv[i + 1]); i++; } - else if (arg == "-al") // Set actor list + else if (arg == "-al") // Set actor list { i++; } - else if (arg == "-ol") // Set object list + else if (arg == "-ol") // Set object list { i++; } - else if (arg == "-eh") // Enable Error Handler + else if (arg == "-eh") // Enable Error Handler { #if !defined(_MSC_VER) && !defined(__CYGWIN__) signal(SIGSEGV, ErrorHandler); signal(SIGABRT, ErrorHandler); #endif } - else if (arg == "-v") // Verbose + else if (arg == "-v") // Verbose { Globals::Instance->verbosity = (VerbosityLevel)strtol(argv[++i], NULL, 16); } @@ -185,9 +188,15 @@ int NewMain(int argc, char* argv[]) if (Globals::Instance->verbosity >= VERBOSITY_INFO) printf("ZAPD: Zelda Asset Processor For Decomp: %s\n", gBuildHash); - if (fileMode == ZFileMode::Build || fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile) + if (fileMode == ZFileMode::Build || fileMode == ZFileMode::Extract || + fileMode == ZFileMode::BuildSourceFile) { - Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath, Globals::Instance->outputPath, fileMode); + bool parseSuccessful = Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath, + Globals::Instance->outputPath, fileMode); + if (!parseSuccessful) + { + return 1; + } } else if (fileMode == ZFileMode::BuildTexture) { @@ -210,11 +219,14 @@ int NewMain(int argc, char* argv[]) } else if (fileMode == ZFileMode::BuildAnimationIntermediette) { - BuildAssetAnimationIntermediette(Globals::Instance->inputPath, Globals::Instance->outputPath); + BuildAssetAnimationIntermediette(Globals::Instance->inputPath, + Globals::Instance->outputPath); } else if (fileMode == ZFileMode::BuildOverlay) { - ZOverlay* overlay = ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath), Path::GetDirectoryName(Globals::Instance->cfgPath)); + ZOverlay* overlay = + ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath), + Path::GetDirectoryName(Globals::Instance->cfgPath)); if (overlay) File::WriteAllText(Globals::Instance->outputPath, overlay->GetSourceOutputCode("")); @@ -223,20 +235,28 @@ int NewMain(int argc, char* argv[]) return 0; } -bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, ZFileMode fileMode) +bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, + ZFileMode fileMode) { XMLDocument doc; XMLError eResult = doc.LoadFile(xmlFilePath.c_str()); if (eResult != tinyxml2::XML_SUCCESS) + { + fprintf(stderr, "Invalid xml file: '%s'\n", xmlFilePath.c_str()); return false; + } XMLNode* root = doc.FirstChild(); if (root == nullptr) + { + fprintf(stderr, "Missing Root tag in xml file: '%s'\n", xmlFilePath.c_str()); return false; + } - for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = root->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { if (string(child->Name()) == "File") { @@ -264,7 +284,8 @@ bool Parse(const std::string& xmlFilePath, const std::string& basePath, const st return true; } -void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, const std::string& outPath) +void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, + const std::string& outPath) { vector split = StringHelper::Split(outPath, "/"); string name = StringHelper::Split(split[split.size() - 1], ".")[0]; @@ -274,7 +295,8 @@ void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, cons if (File::Exists(cfgPath)) name = File::ReadAllText(cfgPath); - //string src = StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str()) + tex->GetSourceOutputCode(name) + "};\n"; + // string src = StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str()) + + // tex->GetSourceOutputCode(name) + "};\n"; string src = tex->GetSourceOutputCode(name); File::WriteAllText(outPath, src); @@ -288,7 +310,8 @@ void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath) ZBlob* blob = ZBlob::FromFile(blobFilePath); string name = StringHelper::Split(split[split.size() - 1], ".")[0]; - //string src = StringHelper::Sprintf("u8 %s[] = \n{\n", name.c_str()) + blob->GetSourceOutputCode(name) + "};\n"; + // string src = StringHelper::Sprintf("u8 %s[] = \n{\n", name.c_str()) + + // blob->GetSourceOutputCode(name) + "};\n"; string src = blob->GetSourceOutputCode(name); File::WriteAllText(outPath, src); @@ -299,7 +322,7 @@ void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath) void BuildAssetModelIntermediette(const std::string& mdlPath, const std::string& outPath) { XMLDocument doc; - XMLError eResult = doc.LoadFile(mdlPath.c_str()); + // XMLError eResult = doc.LoadFile(mdlPath.c_str()); vector split = StringHelper::Split(outPath, "/"); HLModelIntermediette* mdl = HLModelIntermediette::FromXML(doc.RootElement()); @@ -318,8 +341,8 @@ void BuildAssetAnimationIntermediette(const std::string& animPath, const std::st ZAnimation* zAnim = anim->ToZAnimation(); zAnim->SetName(Path::GetFileNameWithoutExtension(split[split.size() - 1])); zAnim->parent = file; - //zAnim->rotationIndicesSeg = 1; - //zAnim->rotationValuesSeg = 2; + // zAnim->rotationIndicesSeg = 1; + // zAnim->rotationValuesSeg = 2; zAnim->GetSourceOutputCode(split[split.size() - 2]); string output = ""; diff --git a/tools/ZAPD/ZAPD/OutputFormatter.cpp b/tools/ZAPD/ZAPD/OutputFormatter.cpp index 5e7c35ccd4..3a7fbd63d6 100644 --- a/tools/ZAPD/ZAPD/OutputFormatter.cpp +++ b/tools/ZAPD/ZAPD/OutputFormatter.cpp @@ -1,6 +1,6 @@ #include "OutputFormatter.h" -int OutputFormatter::write(const char *buf, int count) +int OutputFormatter::write(const char* buf, int count) { for (int i = 0; i < count; i++) { @@ -65,29 +65,20 @@ int OutputFormatter::write(const char *buf, int count) OutputFormatter* OutputFormatter::static_instance; -int OutputFormatter::write_static(const char *buf, int count) +int OutputFormatter::write_static(const char* buf, int count) { return static_instance->write(buf, count); } -int (*OutputFormatter::static_writer())(const char *buf, int count) +int (*OutputFormatter::static_writer())(const char* buf, int count) { static_instance = this; return &write_static; } -OutputFormatter::OutputFormatter(int tab_size , int default_indent, - int line_limit) - : - tab_size{tab_size}, - default_indent{default_indent}, - line_limit{line_limit}, - col{0}, - nest{0}, - nest_indent{default_indent}, - current_indent{default_indent}, - word_p{word}, - space_p{space} +OutputFormatter::OutputFormatter(int tab_size, int default_indent, int line_limit) + : tab_size{tab_size}, default_indent{default_indent}, line_limit{line_limit}, col{0}, nest{0}, + nest_indent{default_indent}, current_indent{default_indent}, word_p{word}, space_p{space} { } diff --git a/tools/ZAPD/ZAPD/OutputFormatter.h b/tools/ZAPD/ZAPD/OutputFormatter.h index d1cdc68f6e..97edcdd37f 100644 --- a/tools/ZAPD/ZAPD/OutputFormatter.h +++ b/tools/ZAPD/ZAPD/OutputFormatter.h @@ -1,8 +1,8 @@ #pragma once -#include #include #include +#include class OutputFormatter { @@ -18,21 +18,20 @@ private: char word[128]; char space[128]; - char *word_p; - char *space_p; + char* word_p; + char* space_p; std::string str; - int write(const char *buf, int count); + int write(const char* buf, int count); - static OutputFormatter *static_instance; - static int write_static(const char *buf, int count); + static OutputFormatter* static_instance; + static int write_static(const char* buf, int count); public: - OutputFormatter(int tab_size = 4, int default_indent = 4, - int line_limit = 120); + OutputFormatter(int tab_size = 4, int default_indent = 4, int line_limit = 120); - int (*static_writer())(const char *buf, int count); + int (*static_writer())(const char* buf, int count); std::string get_output(); }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp b/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp index 006aa84395..1179b508f7 100644 --- a/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp +++ b/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp @@ -1,7 +1,7 @@ #include "ZOverlay.h" +#include "../Directory.h" #include "../File.h" #include "../Path.h" -#include "../Directory.h" #include "../StringHelper.h" using namespace std; @@ -20,7 +20,7 @@ ZOverlay::ZOverlay(string nName) : ZOverlay() ZOverlay::~ZOverlay() { - for (auto entry: entries) + for (auto entry : entries) if (entry) delete entry; entries.clear(); @@ -33,26 +33,25 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) ZOverlay* ovl = new ZOverlay(StringHelper::Strip(cfgLines[0], "\r")); - vector relSections = {".rel.text", ".rel.data" , ".rel.rodata"}; - vector sections = {".text", ".data" , ".rodata"}; + vector relSections = {".rel.text", ".rel.data", ".rel.rodata"}; + vector sections = {".text", ".data", ".rodata"}; int sectionOffs[5] = {0}; vector textRelocs; vector dataRelocs; vector rodataRelocs; - // get the elf files vector readers; - for (int i = 1; i < cfgLines.size(); i++) + for (size_t i = 1; i < cfgLines.size(); i++) { - string elfPath = buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size()-2) + ".o"; + string elfPath = buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o"; elfio* reader = new elfio(); if (!reader->load(elfPath)) { // not all files were compiled - for (auto r: readers) + for (auto r : readers) delete r; readers.clear(); @@ -66,11 +65,12 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) for (auto curReader : readers) { Elf_Half sec_num = curReader->sections.size(); - for(int i = 0; i < sec_num; i++) + for (int i = 0; i < sec_num; i++) { section* pSec = curReader->sections[i]; - if (pSec->get_type() == SHT_REL && std::find(relSections.begin(), relSections.end(), pSec->get_name()) != relSections.end()) + if (pSec->get_type() == SHT_REL && std::find(relSections.begin(), relSections.end(), + pSec->get_name()) != relSections.end()) { SectionType sectionType = GetSectionTypeFromStr(pSec->get_name()); @@ -91,16 +91,17 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) string curSymName; Elf_Half curSymShndx = SHN_UNDEF; { - symbol_section_accessor symbols(*curReader, curReader->sections[(Elf_Half)pSec->get_link()]); + symbol_section_accessor symbols( + *curReader, curReader->sections[(Elf_Half)pSec->get_link()]); Elf64_Addr value; Elf_Xword size; unsigned char bind; unsigned char type; unsigned char other; - symbols.get_symbol(symbol, curSymName, value, size, bind, type, curSymShndx, other); + symbols.get_symbol(symbol, curSymName, value, size, bind, type, curSymShndx, + other); } - // check symbols outside the elf but within the overlay if (curSymShndx == SHN_UNDEF) { @@ -129,7 +130,8 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) unsigned char type; unsigned char other; - symbols.get_symbol(symIdx, name, value, size, bind, type, shndx, other); + symbols.get_symbol(symIdx, name, value, size, bind, type, shndx, + other); if (name == curSymName) { @@ -145,7 +147,8 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) RelocationType typeConverted = (RelocationType)type; offset += sectionOffs[sectionType]; - RelocationEntry* reloc = new RelocationEntry(sectionType, typeConverted, offset); + RelocationEntry* reloc = + new RelocationEntry(sectionType, typeConverted, offset); // this is to keep the correct reloc entry order if (sectionType == SectionType::Text) @@ -163,7 +166,8 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) for (int i = 0; i < sec_num; i++) { section* pSec = curReader->sections[i]; - if (pSec->get_type() == SHT_PROGBITS && std::find(sections.begin(), sections.end(), pSec->get_name()) != sections.end()) + if (pSec->get_type() == SHT_PROGBITS && + std::find(sections.begin(), sections.end(), pSec->get_name()) != sections.end()) { SectionType sectionType = GetSectionTypeFromStr(pSec->get_name()); sectionOffs[sectionType] += pSec->get_size(); @@ -178,7 +182,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) for (auto reloc : rodataRelocs) ovl->entries.push_back(reloc); - for (auto r: readers) + for (auto r : readers) delete r; readers.clear(); @@ -198,7 +202,7 @@ string ZOverlay::GetSourceOutputCode(const std::string& prefix) output += StringHelper::Sprintf(".word %i\n", entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { RelocationEntry* reloc = entries[i]; output += StringHelper::Sprintf(".word 0x%08X\n", reloc->CalcRelocationWord()); @@ -227,7 +231,8 @@ SectionType ZOverlay::GetSectionTypeFromStr(string sectionName) return SectionType::Text; else if (sectionName == ".rel.data" || sectionName == ".data") return SectionType::Data; - else if (sectionName == ".rel.rodata" || sectionName == ".rodata" || sectionName == ".rodata.str1.4" || sectionName == ".rodata.cst4") + else if (sectionName == ".rel.rodata" || sectionName == ".rodata" || + sectionName == ".rodata.str1.4" || sectionName == ".rodata.cst4") return SectionType::RoData; else if (sectionName == ".rel.bss" || sectionName == ".bss") return SectionType::Bss; diff --git a/tools/ZAPD/ZAPD/Overlays/ZOverlay.h b/tools/ZAPD/ZAPD/Overlays/ZOverlay.h index 03dba43c36..dddae6a747 100644 --- a/tools/ZAPD/ZAPD/Overlays/ZOverlay.h +++ b/tools/ZAPD/ZAPD/Overlays/ZOverlay.h @@ -1,8 +1,8 @@ #pragma once -#include "../ZResource.h" -#include #include +#include +#include "../ZResource.h" enum SectionType { @@ -64,5 +64,5 @@ private: ZOverlay(); static SectionType GetSectionTypeFromStr(std::string sectionName); - //static std::string GetOverlayNameFromElf(ELFIO::elfio& reader); + // static std::string GetOverlayNameFromElf(ELFIO::elfio& reader); }; diff --git a/tools/ZAPD/ZAPD/Path.h b/tools/ZAPD/ZAPD/Path.h index 6bfde45a45..3e45281f6c 100644 --- a/tools/ZAPD/ZAPD/Path.h +++ b/tools/ZAPD/ZAPD/Path.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include "StringHelper.h" #if __has_include() diff --git a/tools/ZAPD/ZAPD/StringHelper.h b/tools/ZAPD/ZAPD/StringHelper.h index 07ae37f7e0..b7771fbca4 100644 --- a/tools/ZAPD/ZAPD/StringHelper.h +++ b/tools/ZAPD/ZAPD/StringHelper.h @@ -1,10 +1,10 @@ #pragma once -#include -#include #include #include #include +#include +#include class StringHelper { @@ -62,7 +62,7 @@ public: static std::string Sprintf(const char* format, ...) { char buffer[32768]; - //char buffer[2048]; + // char buffer[2048]; std::string output = ""; va_list va; @@ -77,9 +77,8 @@ public: static std::string Implode(std::vector& elements, const char* const separator) { return std::accumulate(std::begin(elements), std::end(elements), std::string(), - [separator](std::string& ss, std::string& s) - { - return ss.empty() ? s : ss + separator + s; - }); + [separator](std::string& ss, std::string& s) { + return ss.empty() ? s : ss + separator + s; + }); } }; diff --git a/tools/ZAPD/ZAPD/Vec3s.h b/tools/ZAPD/ZAPD/Vec3s.h index 589b660b05..8df39c034d 100644 --- a/tools/ZAPD/ZAPD/Vec3s.h +++ b/tools/ZAPD/ZAPD/Vec3s.h @@ -6,5 +6,10 @@ struct Vec3s { int16_t x, y, z; - Vec3s(int16_t nX, int16_t nY, int16_t nZ) { x = nX; y = nY; z = nZ; }; + Vec3s(int16_t nX, int16_t nY, int16_t nZ) + { + x = nX; + y = nY; + z = nZ; + }; }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZAnimation.cpp b/tools/ZAPD/ZAPD/ZAnimation.cpp index 21fdf3ffd9..4ae07e1e53 100644 --- a/tools/ZAPD/ZAPD/ZAnimation.cpp +++ b/tools/ZAPD/ZAPD/ZAnimation.cpp @@ -1,11 +1,11 @@ #include "ZAnimation.h" #include -#include "ZFile.h" #include "BitConverter.h" -#include "StringHelper.h" #include "File.h" -#include "HighLevel/HLAnimationIntermediette.h" #include "Globals.h" +#include "HighLevel/HLAnimationIntermediette.h" +#include "StringHelper.h" +#include "ZFile.h" using namespace std; @@ -61,18 +61,20 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix) if (parent != nullptr) { string defaultPrefix = name.c_str(); - defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables + defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables - string headerStr = StringHelper::Sprintf("{ %i }, %sFrameData, %sJointIndices, %i", - frameCount, defaultPrefix.c_str(), defaultPrefix.c_str(), limit); - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "AnimationHeader", StringHelper::Sprintf("%s", name.c_str()), headerStr); + string headerStr = + StringHelper::Sprintf("{ %i }, %sFrameData, %sJointIndices, %i", frameCount, + defaultPrefix.c_str(), defaultPrefix.c_str(), limit); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "AnimationHeader", + StringHelper::Sprintf("%s", name.c_str()), headerStr); string indicesStr = ""; string valuesStr = " "; const int lineLength = 14; const int offset = 0; - for (int i = 0; i < rotationValues.size(); i++) + for (size_t i = 0; i < rotationValues.size(); i++) { valuesStr += StringHelper::Sprintf("0x%04X, ", rotationValues[i]); @@ -80,19 +82,25 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix) valuesStr += "\n "; } - for (int i = 0; i < rotationIndices.size(); i++) + for (size_t i = 0; i < rotationIndices.size(); i++) { - indicesStr += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x, rotationIndices[i].y, rotationIndices[i].z); + indicesStr += + StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x, + rotationIndices[i].y, rotationIndices[i].z); if (i != (rotationIndices.size() - 1)) indicesStr += "\n"; } - parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16, (int)rotationValues.size() * 2, "static s16", - StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()), rotationValues.size(), valuesStr); + parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16, + (int)rotationValues.size() * 2, "static s16", + StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()), + rotationValues.size(), valuesStr); - parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16, (int)rotationIndices.size() * 6, "static JointIndex", - StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()), rotationIndices.size(), indicesStr); + parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16, + (int)rotationIndices.size() * 6, "static JointIndex", + StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()), + rotationIndices.size(), indicesStr); } return ""; @@ -103,7 +111,9 @@ int ZNormalAnimation::GetRawDataSize() return 16; } -ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, const std::string& nRelPath) +ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, + std::vector nRawData, int rawDataIndex, + const std::string& nRelPath) { ZNormalAnimation* anim = new ZNormalAnimation(); anim->rawData = std::move(nRawData); @@ -127,7 +137,7 @@ void ZNormalAnimation::ParseRawData() uint32_t currentPtr = rotationValuesSeg; // Read the Rotation Values - for (int i = 0; i < ((rotationIndicesSeg - rotationValuesSeg) / 2); i++) + for (uint32_t i = 0; i < ((rotationIndicesSeg - rotationValuesSeg) / 2); i++) { rotationValues.push_back(BitConverter::ToInt16BE(data, currentPtr)); currentPtr += 2; @@ -136,9 +146,11 @@ void ZNormalAnimation::ParseRawData() currentPtr = rotationIndicesSeg; // Read the Rotation Indices - for (int i = 0; i < ((rawDataIndex - rotationIndicesSeg) / 6); i++) + for (uint32_t i = 0; i < ((rawDataIndex - rotationIndicesSeg) / 6); i++) { - rotationIndices.push_back(RotationIndex(BitConverter::ToInt16BE(data, currentPtr), BitConverter::ToInt16BE(data, currentPtr + 2), BitConverter::ToInt16BE(data, currentPtr + 4))); + rotationIndices.push_back(RotationIndex(BitConverter::ToInt16BE(data, currentPtr), + BitConverter::ToInt16BE(data, currentPtr + 2), + BitConverter::ToInt16BE(data, currentPtr + 4))); currentPtr += 6; } } @@ -152,10 +164,14 @@ std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix) { if (parent != nullptr) { - string segSymbol = segmentAddress == 0 ? "NULL" : parent->GetDeclarationName(segmentAddress, StringHelper::Sprintf("%sSeg%06X", name.c_str(), segmentAddress)); - string headerStr = StringHelper::Sprintf("{ %i }, 0x%08X", - frameCount, segmentAddress); - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "LinkAnimationHeader", StringHelper::Sprintf("%s", name.c_str()), headerStr); + string segSymbol = segmentAddress == 0 ? + "NULL" : + parent->GetDeclarationName( + segmentAddress, StringHelper::Sprintf("%sSeg%06X", name.c_str(), + segmentAddress)); + string headerStr = StringHelper::Sprintf("{ %i }, 0x%08X", frameCount, segmentAddress); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "LinkAnimationHeader", + StringHelper::Sprintf("%s", name.c_str()), headerStr); } return ""; @@ -166,7 +182,9 @@ int ZLinkAnimation::GetRawDataSize() return 8; } -ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, const std::string& nRelPath) +ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, + std::vector nRawData, int rawDataIndex, + const std::string& nRelPath) { ZLinkAnimation* anim = new ZLinkAnimation(); anim->rawData = std::move(nRawData); @@ -183,6 +201,318 @@ void ZLinkAnimation::ParseRawData() const uint8_t* data = rawData.data(); - //segmentAddress = GETSEGOFFSET(BitConverter::ToInt32BE(data, rawDataIndex + 4)); + // segmentAddress = GETSEGOFFSET(BitConverter::ToInt32BE(data, rawDataIndex + 4)); segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4)); } + +/* ZCurveAnimation */ + +TransformData::TransformData(ZFile* parent, const std::vector& rawData, + uint32_t fileOffset) + : parent(parent) +{ + unk_00 = BitConverter::ToUInt16BE(rawData, fileOffset + 0); + unk_02 = BitConverter::ToUInt16BE(rawData, fileOffset + 2); + unk_04 = BitConverter::ToInt16BE(rawData, fileOffset + 4); + unk_06 = BitConverter::ToInt16BE(rawData, fileOffset + 6); + unk_08 = BitConverter::ToFloatBE(rawData, fileOffset + 8); +} + +TransformData::TransformData(ZFile* parent, const std::vector& rawData, + uint32_t fileOffset, size_t index) + : TransformData(parent, rawData, fileOffset + index * GetRawDataSize()) +{ +} + +std::string TransformData::GetBody(const std::string& prefix) const +{ + return StringHelper::Sprintf("0x%04X, 0x%04X, %i, %i, %ff", unk_00, unk_02, unk_04, unk_06, + unk_08); +} + +size_t TransformData::GetRawDataSize() +{ + return 0x0C; +} + +std::string TransformData::GetSourceTypeName() +{ + return "TransformData"; +} + +ZCurveAnimation::ZCurveAnimation(tinyxml2::XMLElement* reader, const std::vector& nRawData, + int nRawDataIndex, ZFile* nParent) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + parent = nParent; + + ParseXML(reader); + ParseRawData(); + + skel = new ZSkeleton(ZSkeletonType::Curve, ZLimbType::Curve, "CurveAnim", nRawData, + Seg2Filespace(skelOffset, parent->baseAddress), nParent); + + size_t transformDataSize = 0; + size_t copyValuesSize = 0; + if (refIndex != 0) + { + uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress); + for (size_t i = 0; i < 3 * 3 * skel->GetLimbCount(); i++) + { + uint8_t ref = BitConverter::ToUInt8BE(nRawData, refIndexOffset + i); + if (ref == 0) + { + copyValuesSize++; + } + else + { + transformDataSize += ref; + } + refIndexArr.emplace_back(ref); + } + } + + if (transformData != 0) + { + uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress); + for (size_t i = 0; i < transformDataSize; i++) + { + transformDataArr.emplace_back(parent, nRawData, transformDataOffset, i); + } + } + + if (copyValues != 0) + { + uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress); + for (size_t i = 0; i < copyValuesSize; i++) + { + copyValuesArr.emplace_back(BitConverter::ToInt16BE(nRawData, copyValuesOffset + i * 2)); + } + } +} + +ZCurveAnimation::~ZCurveAnimation() +{ + delete skel; +} + +void ZCurveAnimation::ParseXML(tinyxml2::XMLElement* reader) +{ + ZAnimation::ParseXML(reader); + + const char* skelOffsetXml = reader->Attribute("SkelOffset"); + if (skelOffsetXml == nullptr) + { + throw std::runtime_error( + "ZCurveAnimation::ParseXML: Fatal error in '%s'. Missing 'SkelOffset' attribute in " + "xml. You need to provide the offset of the curve skeleton."); + } + skelOffset = std::strtoul(skelOffsetXml, nullptr, 0); +} + +void ZCurveAnimation::ParseRawData() +{ + ZAnimation::ParseRawData(); + + refIndex = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); + transformData = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4); + copyValues = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); + unk_0C = BitConverter::ToInt16BE(rawData, rawDataIndex + 12); + unk_10 = BitConverter::ToInt16BE(rawData, rawDataIndex + 14); +} + +ZCurveAnimation* ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, + int nRawDataIndex, std::string nRelPath, + ZFile* nParent) +{ + ZCurveAnimation* curve = new ZCurveAnimation(reader, nRawData, nRawDataIndex, nParent); + curve->relativePath = std::move(nRelPath); + + curve->parent->AddDeclaration(curve->rawDataIndex, DeclarationAlignment::Align16, + curve->GetRawDataSize(), curve->GetSourceTypeName(), curve->name, + ""); + + return curve; +} + +void ZCurveAnimation::PreGenValues(const std::string& prefix) +{ + Declaration* decl = parent->GetDeclaration(skelOffset); + if (decl == nullptr) + { + skel->GetSourceOutputCode(prefix); + } + + if (refIndex != 0) + { + uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress); + string refIndexStr = + StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", refIndexOffset); + + string entryStr = " "; + uint16_t arrayItemCnt = refIndexArr.size(); + + size_t i = 0; + for (auto& child : refIndexArr) + { + entryStr += StringHelper::Sprintf("0x%02X, %s", child, (i++ % 8 == 7) ? "\n " : ""); + } + + Declaration* decl = parent->GetDeclaration(refIndexOffset); + if (decl == nullptr) + { + parent->AddDeclarationArray(refIndexOffset, DeclarationAlignment::None, + arrayItemCnt * 1, "u8", refIndexStr, arrayItemCnt, + entryStr); + } + else + { + decl->text = entryStr; + } + } + + if (transformData != 0) + { + uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress); + string transformDataStr = + StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), + TransformData::GetSourceTypeName().c_str(), transformDataOffset); + + string entryStr = ""; + uint16_t arrayItemCnt = transformDataArr.size(); + + size_t i = 0; + for (auto& child : transformDataArr) + { + entryStr += StringHelper::Sprintf(" { %s },%s", child.GetBody(prefix).c_str(), + (++i < arrayItemCnt) ? "\n" : ""); + } + + Declaration* decl = parent->GetDeclaration(transformDataOffset); + if (decl == nullptr) + { + parent->AddDeclarationArray(transformDataOffset, DeclarationAlignment::None, + arrayItemCnt * TransformData::GetRawDataSize(), + TransformData::GetSourceTypeName(), transformDataStr, + arrayItemCnt, entryStr); + } + else + { + decl->text = entryStr; + } + } + + if (copyValues != 0) + { + uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress); + string copyValuesStr = + StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", copyValuesOffset); + + string entryStr = " "; + uint16_t arrayItemCnt = copyValuesArr.size(); + + size_t i = 0; + for (auto& child : copyValuesArr) + { + entryStr += StringHelper::Sprintf("% 6i, %s", child, (i++ % 8 == 7) ? "\n " : ""); + } + + Declaration* decl = parent->GetDeclaration(copyValuesOffset); + if (decl == nullptr) + { + parent->AddDeclarationArray(copyValuesOffset, DeclarationAlignment::None, + arrayItemCnt * 2, "s16", copyValuesStr, arrayItemCnt, + entryStr); + } + else + { + decl->text = entryStr; + } + } +} + +int ZCurveAnimation::GetRawDataSize() +{ + return 0x10; +} + +std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix) +{ + string bodyStr = ""; + uint32_t address = Seg2Filespace(rawDataIndex, parent->baseAddress); + + PreGenValues(prefix); + + string refIndexStr = "NULL"; + if (refIndex != 0) + { + uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(refIndexOffset); + if (decl == nullptr) + { + refIndexStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", + refIndexOffset); + } + else + { + refIndexStr = decl->varName; + } + } + + string transformDataStr = "NULL"; + if (transformData != 0) + { + uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(transformDataOffset); + if (decl == nullptr) + { + transformDataStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), + TransformData::GetSourceTypeName().c_str(), + transformDataOffset); + } + else + { + transformDataStr = decl->varName; + } + } + + string copyValuesStr = "NULL"; + if (copyValues != 0) + { + uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(copyValuesOffset); + if (decl == nullptr) + { + copyValuesStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", + copyValuesOffset); + } + else + { + copyValuesStr = decl->varName; + } + } + + bodyStr = + StringHelper::Sprintf("\n %s,\n %s,\n %s,\n %i, %i\n", refIndexStr.c_str(), + transformDataStr.c_str(), copyValuesStr.c_str(), unk_0C, unk_10); + + Declaration* decl = parent->GetDeclaration(address); + if (decl == nullptr) + { + parent->AddDeclaration(address, DeclarationAlignment::None, GetRawDataSize(), + GetSourceTypeName(), name, bodyStr); + } + else + { + decl->text = bodyStr; + } + + return ""; +} + +std::string ZCurveAnimation::GetSourceTypeName() +{ + return "TransformUpdateIndex"; +} diff --git a/tools/ZAPD/ZAPD/ZAnimation.h b/tools/ZAPD/ZAPD/ZAnimation.h index 25c066a072..71fbf2d109 100644 --- a/tools/ZAPD/ZAPD/ZAnimation.h +++ b/tools/ZAPD/ZAPD/ZAnimation.h @@ -1,35 +1,40 @@ #pragma once -#include -#include #include -#include "ZResource.h" +#include +#include #include "Vec3s.h" +#include "ZResource.h" +#include "ZSkeleton.h" #include "tinyxml2.h" struct RotationIndex { - //uint16_t transX, transY, transZ; + // uint16_t transX, transY, transZ; uint16_t x, y, z; - RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) { x = nX; y = nY; z = nZ; }; + RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) + { + x = nX; + y = nY; + z = nZ; + }; }; class ZAnimation : public ZResource { public: - int16_t frameCount; ZAnimation(); std::string GetSourceOutputCode(const std::string& prefix) override; ZResourceType GetResourceType() override; -protected: - virtual void ParseRawData(); - void Save(const std::string& outFolder); - void ParseXML(tinyxml2::XMLElement* reader); +protected: + virtual void ParseRawData() override; + void Save(const std::string& outFolder) override; + void ParseXML(tinyxml2::XMLElement* reader) override; }; class ZNormalAnimation : public ZAnimation @@ -43,13 +48,15 @@ public: ZNormalAnimation(); - std::string GetSourceOutputCode(const std::string& prefix); + std::string GetSourceOutputCode(const std::string& prefix) override; int GetRawDataSize() override; - static ZNormalAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, const std::string& nRelPath); + static ZNormalAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, + std::vector nRawData, int rawDataIndex, + const std::string& nRelPath); protected: - virtual void ParseRawData(); + virtual void ParseRawData() override; }; class ZLinkAnimation : public ZAnimation @@ -59,11 +66,82 @@ public: ZLinkAnimation(); - std::string GetSourceOutputCode(const std::string& prefix); + std::string GetSourceOutputCode(const std::string& prefix) override; int GetRawDataSize() override; - static ZLinkAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, const std::string& nRelPath); + static ZLinkAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, + std::vector nRawData, int rawDataIndex, + const std::string& nRelPath); protected: - virtual void ParseRawData(); + virtual void ParseRawData() override; }; + +class TransformData +{ +protected: + ZFile* parent; + + ///* 0x0000 */ u16 unk_00; // appears to be flags + uint16_t unk_00; + ///* 0x0002 */ s16 unk_02; + int16_t unk_02; + ///* 0x0004 */ s16 unk_04; + int16_t unk_04; + ///* 0x0006 */ s16 unk_06; + int16_t unk_06; + ///* 0x0008 */ f32 unk_08; + float unk_08; + +public: + TransformData() = default; + TransformData(ZFile* parent, const std::vector& rawData, uint32_t fileOffset); + TransformData(ZFile* parent, const std::vector& rawData, uint32_t fileOffset, + size_t index); + + [[nodiscard]] std::string GetBody(const std::string& prefix) const; + + static size_t GetRawDataSize(); + static std::string GetSourceTypeName(); +}; + +class ZCurveAnimation : public ZAnimation +{ +protected: + segptr_t skelOffset = 0; + + ///* 0x0000 */ u8* refIndex; + segptr_t refIndex = 0; + ///* 0x0004 */ TransformData* transformData; + segptr_t transformData = 0; + ///* 0x0008 */ s16* copyValues; + segptr_t copyValues = 0; + ///* 0x000C */ s16 unk_0C; + int16_t unk_0C; + ///* 0x000E */ s16 unk_10; + int16_t unk_10; + + ZSkeleton* skel; + + std::vector refIndexArr; + std::vector transformDataArr; + std::vector copyValuesArr; + +public: + ZCurveAnimation() = default; + ZCurveAnimation(tinyxml2::XMLElement* reader, const std::vector& nRawData, + int nRawDataIndex, ZFile* nParent); + ~ZCurveAnimation(); + void ParseXML(tinyxml2::XMLElement* reader) override; + void ParseRawData() override; + static ZCurveAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, int nRawDataIndex, + std::string nRelPath, ZFile* nParent); + + void PreGenValues(const std::string& prefix); + int GetRawDataSize() override; + std::string GetSourceOutputCode(const std::string& prefix) override; + + std::string GetSourceTypeName() override; +}; +// TransformUpdateIndex diff --git a/tools/ZAPD/ZAPD/ZArray.cpp b/tools/ZAPD/ZAPD/ZArray.cpp index 622aef5a5d..74fa9c5af7 100644 --- a/tools/ZAPD/ZAPD/ZArray.cpp +++ b/tools/ZAPD/ZAPD/ZArray.cpp @@ -1,11 +1,10 @@ #include "ZArray.h" -#include "ZFile.h" #include "Globals.h" #include "StringHelper.h" +#include "ZFile.h" ZArray::ZArray() { - } void ZArray::ParseXML(tinyxml2::XMLElement* reader) @@ -13,7 +12,8 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader) ZResource::ParseXML(reader); arrayCnt = reader->IntAttribute("Count", 0); - testFile = new ZFile(ZFileMode::Extract, reader, Globals::Instance->baseRomPath, "", parent->GetName(), true); + testFile = new ZFile(ZFileMode::Extract, reader, Globals::Instance->baseRomPath, "", + parent->GetName(), true); } // TODO: This is a bit hacky, but until we refactor how ZFile parses the XML, it'll have to do. @@ -31,7 +31,9 @@ std::string ZArray::GetSourceOutputCode(const std::string& prefix) if (!res->DoesSupportArray()) { - throw StringHelper::Sprintf("Error! Resource %s does not support being wrapped in an array!\n", res->GetName().c_str()); + throw std::runtime_error(StringHelper::Sprintf( + "Error! Resource %s does not support being wrapped in an array!\n", + res->GetName().c_str())); } for (int i = 0; i < arrayCnt; i++) @@ -40,34 +42,34 @@ std::string ZArray::GetSourceOutputCode(const std::string& prefix) res->SetRawDataIndex(childIndex); res->ParseRawData(); std::string test = res->GetSourceOutputCode(""); - //output += " { " + testFile->declarations[childIndex]->text + " }"; + // output += " { " + testFile->declarations[childIndex]->text + " }"; output += testFile->declarations[childIndex]->text; - + if (i < arrayCnt - 1) output += ",\n"; - - int bp = 0; } if (parent != nullptr) - parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), res->GetSourceTypeName(), name, arrayCnt, output); + parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), + res->GetSourceTypeName(), name, arrayCnt, output); return ""; } int ZArray::GetRawDataSize() { - return arrayCnt * testFile->resources[0]->GetRawDataSize(); + return arrayCnt * testFile->resources[0]->GetRawDataSize(); } -ZArray* ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath, ZFile* nParent) +ZArray* ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const int rawDataIndex, const std::string& nRelPath, ZFile* nParent) { ZArray* arr = new ZArray(); arr->rawData = nRawData; arr->rawDataIndex = rawDataIndex; arr->parent = nParent; arr->ParseXML(reader); - //arr->ParseRawData(); + // arr->ParseRawData(); return arr; } diff --git a/tools/ZAPD/ZAPD/ZArray.h b/tools/ZAPD/ZAPD/ZArray.h index 8fd2565055..8e0092325c 100644 --- a/tools/ZAPD/ZAPD/ZArray.h +++ b/tools/ZAPD/ZAPD/ZArray.h @@ -1,8 +1,8 @@ #pragma once -#include -#include #include +#include +#include #include "ZResource.h" #include "tinyxml2.h" @@ -15,11 +15,13 @@ public: std::string GetSourceOutputCode(const std::string& prefix) override; int GetRawDataSize() override; - static ZArray* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath, ZFile* nParent); + static ZArray* ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, const int rawDataIndex, + const std::string& nRelPath, ZFile* nParent); protected: int arrayCnt; ZFile* testFile; - //void ParseRawData(const std::vector& data, const int offset); + // void ParseRawData(const std::vector& data, const int offset); }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZBlob.cpp b/tools/ZAPD/ZAPD/ZBlob.cpp index edb0e34c9c..fb39bd373a 100644 --- a/tools/ZAPD/ZAPD/ZBlob.cpp +++ b/tools/ZAPD/ZAPD/ZBlob.cpp @@ -1,26 +1,28 @@ #include "ZBlob.h" -#include "File.h" -#include "ZFile.h" #include "BitConverter.h" +#include "File.h" #include "Path.h" #include "StringHelper.h" +#include "ZFile.h" using namespace tinyxml2; using namespace std; ZBlob::ZBlob() : ZResource() { - } -ZBlob::ZBlob(const std::vector& nRawData, int nRawDataIndex, int size, std::string nName) : ZBlob() +ZBlob::ZBlob(const std::vector& nRawData, int nRawDataIndex, int size, std::string nName) + : ZBlob() { rawDataIndex = nRawDataIndex; - rawData = vector(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size); + rawData = + vector(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size); name = std::move(nName); } -ZBlob* ZBlob::ExtractFromXML(XMLElement* reader, const vector& nRawData, int nRawDataIndex, string nRelPath) +ZBlob* ZBlob::ExtractFromXML(XMLElement* reader, const vector& nRawData, int nRawDataIndex, + string nRelPath) { ZBlob* blob = new ZBlob(); @@ -28,7 +30,8 @@ ZBlob* ZBlob::ExtractFromXML(XMLElement* reader, const vector& nRawData blob->ParseXML(reader); int size = strtol(reader->Attribute("Size"), NULL, 16); - blob->rawData = vector(nRawData.data() + blob->rawDataIndex, nRawData.data() + blob->rawDataIndex + size); + blob->rawData = vector(nRawData.data() + blob->rawDataIndex, + nRawData.data() + blob->rawDataIndex + size); blob->relativePath = std::move(nRelPath); return blob; @@ -48,7 +51,6 @@ ZBlob* ZBlob::BuildFromXML(XMLElement* reader, const std::string& inFolder, bool ZBlob* ZBlob::FromFile(const std::string& filePath) { - int comp; ZBlob* blob = new ZBlob(); blob->name = StringHelper::Split(Path::GetFileNameWithoutExtension(filePath), ".")[0]; blob->rawData = File::ReadAllBytes(filePath); @@ -59,9 +61,9 @@ ZBlob* ZBlob::FromFile(const std::string& filePath) string ZBlob::GetSourceOutputCode(const std::string& prefix) { sourceOutput = ""; - //sourceOutput += StringHelper::Sprintf("u8 %s_%s[] = \n{\n", prefix.c_str(), name.c_str()); + // sourceOutput += StringHelper::Sprintf("u8 %s_%s[] = \n{\n", prefix.c_str(), name.c_str()); - for (int i = 0; i < rawData.size(); i += 1) + for (uint32_t i = 0; i < rawData.size(); i += 1) { if (i % 16 == 0) sourceOutput += "\t"; @@ -72,7 +74,10 @@ string ZBlob::GetSourceOutputCode(const std::string& prefix) sourceOutput += "\n"; } - //sourceOutput += "};\n"; + // Ensure there's always a trailing line feed to prevent dumb warnings. + sourceOutput += "\n"; + + // sourceOutput += "};\n"; return sourceOutput; } @@ -84,7 +89,7 @@ string ZBlob::GetSourceOutputHeader(const std::string& prefix) void ZBlob::Save(const std::string& outFolder) { - //printf("NAME = %s\n", name.c_str()); + // printf("NAME = %s\n", name.c_str()); File::WriteAllBytes(outFolder + "/" + name + ".bin", rawData); } diff --git a/tools/ZAPD/ZAPD/ZBlob.h b/tools/ZAPD/ZAPD/ZBlob.h index bb51bb1ff5..6b5508846f 100644 --- a/tools/ZAPD/ZAPD/ZBlob.h +++ b/tools/ZAPD/ZAPD/ZBlob.h @@ -8,8 +8,10 @@ class ZBlob : public ZResource public: ZBlob(const std::vector& nRawData, int rawDataIndex, int size, std::string nName); - static ZBlob* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, int rawDataIndex, std::string nRelPath); - static ZBlob* BuildFromXML(tinyxml2::XMLElement* reader, const std::string& inFolder, bool readFile); + static ZBlob* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + int rawDataIndex, std::string nRelPath); + static ZBlob* BuildFromXML(tinyxml2::XMLElement* reader, const std::string& inFolder, + bool readFile); static ZBlob* FromFile(const std::string& filePath); std::string GetSourceOutputCode(const std::string& prefix) override; std::string GetSourceOutputHeader(const std::string& prefix) override; diff --git a/tools/ZAPD/ZAPD/ZCollision.cpp b/tools/ZAPD/ZAPD/ZCollision.cpp index 35ecbca57c..bb3144a94a 100644 --- a/tools/ZAPD/ZAPD/ZCollision.cpp +++ b/tools/ZAPD/ZAPD/ZCollision.cpp @@ -1,18 +1,18 @@ #include "ZCollision.h" -#include "BitConverter.h" -#include "StringHelper.h" -#include "Globals.h" #include #include +#include "BitConverter.h" +#include "Globals.h" +#include "StringHelper.h" using namespace std; ZCollisionHeader::ZCollisionHeader() { - } -ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, const std::vector& rawData, int rawDataIndex) +ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, + const std::vector& rawData, int rawDataIndex) { const uint8_t* data = rawData.data(); @@ -42,14 +42,14 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con uint32_t waterBoxSegmentOffset = Seg2Filespace(waterBoxAddress, parent->baseAddress); // HOTSPOT - for (int i = 0; i < numVerts; i++) + for (uint16_t i = 0; i < numVerts; i++) vertices.push_back(new VertexEntry(rawData, vtxSegmentOffset + (i * 6))); // HOTSPOT - for (int i = 0; i < numPolygons; i++) + for (uint16_t i = 0; i < numPolygons; i++) polygons.push_back(new PolygonEntry(rawData, polySegmentOffset + (i * 16))); - int highestPolyType = 0; + uint16_t highestPolyType = 0; for (PolygonEntry* poly : polygons) { @@ -57,70 +57,89 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con highestPolyType = poly->type; } - //if (highestPolyType > 0) + // if (highestPolyType > 0) { - for (int i = 0; i < highestPolyType + 1; i++) - polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8))); + for (uint16_t i = 0; i < highestPolyType + 1; i++) + polygonTypes.push_back( + BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8))); } - //else + // else //{ - //int polyTypesSize = abs(polyTypeDefSegmentOffset - camDataSegmentOffset) / 8; + // int polyTypesSize = abs(polyTypeDefSegmentOffset - camDataSegmentOffset) / 8; - //for (int i = 0; i < polyTypesSize; i++) - //polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8))); + // for (int i = 0; i < polyTypesSize; i++) + // polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8))); //} if (camDataAddress != 0) - camData = new CameraDataList(parent, prefix, rawData, camDataSegmentOffset, polyTypeDefSegmentOffset, polygonTypes.size()); + camData = new CameraDataList(parent, prefix, rawData, camDataSegmentOffset, + polyTypeDefSegmentOffset, polygonTypes.size()); for (int i = 0; i < numWaterBoxes; i++) - waterBoxes.push_back(new WaterBoxHeader(rawData, waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16)))); + waterBoxes.push_back(new WaterBoxHeader( + rawData, + waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16)))); string declaration = ""; char line[2048]; if (waterBoxes.size() > 0) { - for (int i = 0; i < waterBoxes.size(); i++) + for (size_t i = 0; i < waterBoxes.size(); i++) { - sprintf(line, " { %i, %i, %i, %i, %i, 0x%08X },\n", waterBoxes[i]->xMin, waterBoxes[i]->ySurface, waterBoxes[i]->zMin, waterBoxes[i]->xLength, waterBoxes[i]->zLength, waterBoxes[i]->properties); + sprintf(line, " { %i, %i, %i, %i, %i, 0x%08X },\n", waterBoxes[i]->xMin, + waterBoxes[i]->ySurface, waterBoxes[i]->zMin, waterBoxes[i]->xLength, + waterBoxes[i]->zLength, waterBoxes[i]->properties); declaration += line; } } if (waterBoxAddress != 0) - parent->AddDeclarationArray(waterBoxSegmentOffset, DeclarationAlignment::None, 16 * waterBoxes.size(), "WaterBox", - StringHelper::Sprintf("%s_waterBoxes_%08X", prefix.c_str(), waterBoxSegmentOffset), 0, declaration); + parent->AddDeclarationArray( + waterBoxSegmentOffset, DeclarationAlignment::None, 16 * waterBoxes.size(), "WaterBox", + StringHelper::Sprintf("%s_waterBoxes_%08X", prefix.c_str(), waterBoxSegmentOffset), 0, + declaration); if (polygons.size() > 0) { declaration = ""; - for (int i = 0; i < polygons.size(); i++) + for (size_t i = 0; i < polygons.size(); i++) { - sprintf(line, " { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },\n", - (uint16_t)polygons[i]->type, (uint16_t)polygons[i]->vtxA, (uint16_t)polygons[i]->vtxB, (uint16_t)polygons[i]->vtxC, - (uint16_t)polygons[i]->a, (uint16_t)polygons[i]->b, (uint16_t)polygons[i]->c, (uint16_t)polygons[i]->d); + sprintf( + line, " { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },\n", + (uint16_t)polygons[i]->type, (uint16_t)polygons[i]->vtxA, + (uint16_t)polygons[i]->vtxB, (uint16_t)polygons[i]->vtxC, (uint16_t)polygons[i]->a, + (uint16_t)polygons[i]->b, (uint16_t)polygons[i]->c, (uint16_t)polygons[i]->d); declaration += line; } - if (polyAddress != 0) { - parent->AddDeclarationArray(polySegmentOffset, DeclarationAlignment::None, polygons.size() * 16, "CollisionPoly", StringHelper::Sprintf("%s_polygons_%08X", prefix.c_str(), polySegmentOffset), 0, declaration); + if (polyAddress != 0) + { + parent->AddDeclarationArray( + polySegmentOffset, DeclarationAlignment::None, polygons.size() * 16, + "CollisionPoly", + StringHelper::Sprintf("%s_polygons_%08X", prefix.c_str(), polySegmentOffset), 0, + declaration); } } declaration = ""; - for (int i = 0; i < polygonTypes.size(); i++) + for (size_t i = 0; i < polygonTypes.size(); i++) { - declaration += StringHelper::Sprintf(" { 0x%08lX, 0x%08lX },", polygonTypes[i] >> 32, polygonTypes[i] & 0xFFFFFFFF); + declaration += StringHelper::Sprintf(" { 0x%08lX, 0x%08lX },", polygonTypes[i] >> 32, + polygonTypes[i] & 0xFFFFFFFF); if (i < polygonTypes.size() - 1) declaration += "\n"; } if (polyTypeDefAddress != 0) - parent->AddDeclarationArray(polyTypeDefSegmentOffset, DeclarationAlignment::None, polygonTypes.size() * 8, - "SurfaceType", StringHelper::Sprintf("%s_surfaceType_%08X", prefix.c_str(), polyTypeDefSegmentOffset), 0, declaration); + parent->AddDeclarationArray( + polyTypeDefSegmentOffset, DeclarationAlignment::None, polygonTypes.size() * 8, + "SurfaceType", + StringHelper::Sprintf("%s_surfaceType_%08X", prefix.c_str(), polyTypeDefSegmentOffset), + 0, declaration); declaration = ""; @@ -128,17 +147,20 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con { declaration = ""; - for (int i = 0; i < vertices.size(); i++) + for (size_t i = 0; i < vertices.size(); i++) { - declaration += StringHelper::Sprintf(" { %i, %i, %i },", vertices[i]->x, vertices[i]->y, vertices[i]->z); + declaration += StringHelper::Sprintf(" { %i, %i, %i },", vertices[i]->x, + vertices[i]->y, vertices[i]->z); if (i < vertices.size() - 1) declaration += "\n"; } if (vtxAddress != 0) - parent->AddDeclarationArray(vtxSegmentOffset, DeclarationAlignment::None, vertices.size() * 6, - "Vec3s", StringHelper::Sprintf("%s_vtx_%08X", prefix.c_str(), vtxSegmentOffset), 0, declaration); + parent->AddDeclarationArray( + vtxSegmentOffset, DeclarationAlignment::None, vertices.size() * 6, "Vec3s", + StringHelper::Sprintf("%s_vtx_%08X", prefix.c_str(), vtxSegmentOffset), 0, + declaration); declaration = ""; } @@ -153,17 +175,19 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con declaration += "\n"; - declaration += StringHelper::Sprintf(" { %i, %i, %i },\n { %i, %i, %i },\n", - absMinX, absMinY, absMinZ, - absMaxX, absMaxY, absMaxZ); + declaration += StringHelper::Sprintf(" { %i, %i, %i },\n { %i, %i, %i },\n", absMinX, + absMinY, absMinZ, absMaxX, absMaxY, absMaxZ); - declaration += StringHelper::Sprintf(" %i,\n %s_vtx_%08X,\n %i,\n %s_polygons_%08X,\n %s_surfaceType_%08X,\n &%s_camDataList_%08X,\n %i,\n %s\n", - numVerts, prefix.c_str(), vtxSegmentOffset, numPolygons, - prefix.c_str(), polySegmentOffset, prefix.c_str(), polyTypeDefSegmentOffset, - prefix.c_str(), camDataSegmentOffset, numWaterBoxes, waterBoxStr); + declaration += StringHelper::Sprintf( + " %i,\n %s_vtx_%08X,\n %i,\n %s_polygons_%08X,\n %s_surfaceType_%08X,\n " + "%s_camDataList_%08X,\n %i,\n %s\n", + numVerts, prefix.c_str(), vtxSegmentOffset, numPolygons, prefix.c_str(), polySegmentOffset, + prefix.c_str(), polyTypeDefSegmentOffset, prefix.c_str(), camDataSegmentOffset, + numWaterBoxes, waterBoxStr); - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, DeclarationPadding::Pad16, 44, "CollisionHeader", - StringHelper::Sprintf("%s", prefix.c_str(), rawDataIndex), declaration); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, DeclarationPadding::Pad16, 44, + "CollisionHeader", + StringHelper::Sprintf("%s", prefix.c_str(), rawDataIndex), declaration); } ZCollisionHeader::~ZCollisionHeader() @@ -183,12 +207,11 @@ ZResourceType ZCollisionHeader::GetResourceType() return ZResourceType::CollisionHeader; } -ZCollisionHeader* ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader, vector nRawData, int rawDataIndex) +ZCollisionHeader* ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader, + vector nRawData, int rawDataIndex) { ZCollisionHeader* col = new ZCollisionHeader(); - - return col; } @@ -234,21 +257,25 @@ WaterBoxHeader::WaterBoxHeader(const std::vector& rawData, int rawDataI } } -CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const std::vector& rawData, int rawDataIndex, int polyTypeDefSegmentOffset, int polygonTypesCnt) +CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, + const std::vector& rawData, int rawDataIndex, + int polyTypeDefSegmentOffset, int polygonTypesCnt) { string declaration = ""; // Parse CameraDataEntries int numElements = abs(polyTypeDefSegmentOffset - (rawDataIndex)) / 8; - //int numElements = polygonTypesCnt; + // int numElements = polygonTypesCnt; uint32_t cameraPosDataSeg = rawDataIndex; for (int i = 0; i < numElements; i++) { CameraDataEntry* entry = new CameraDataEntry(); - entry->cameraSType = BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 0); + entry->cameraSType = + BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 0); entry->numData = BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 2); - entry->cameraPosDataSeg = BitConverter::ToInt32BE(rawData, rawDataIndex + (entries.size() * 8) + 4); + entry->cameraPosDataSeg = + BitConverter::ToInt32BE(rawData, rawDataIndex + (entries.size() * 8) + 4); if (entry->cameraPosDataSeg != 0 && GETSEGNUM(entry->cameraPosDataSeg) != 2) { @@ -262,27 +289,33 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const s entries.push_back(entry); } - //setting cameraPosDataAddr to rawDataIndex give a pos list length of 0 + // setting cameraPosDataAddr to rawDataIndex give a pos list length of 0 uint32_t cameraPosDataOffset = cameraPosDataSeg & 0xFFFFFF; - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { char camSegLine[2048]; if (entries[i]->cameraPosDataSeg != 0) { int index = ((entries[i]->cameraPosDataSeg & 0x00FFFFFF) - cameraPosDataOffset) / 0x6; - sprintf(camSegLine, "&%s_camPosData_%08X[%i]", prefix.c_str(), cameraPosDataOffset, index); + sprintf(camSegLine, "&%s_camPosData_%08X[%i]", prefix.c_str(), cameraPosDataOffset, + index); } else sprintf(camSegLine, "0x%08X", entries[i]->cameraPosDataSeg); - declaration += StringHelper::Sprintf(" { 0x%04X, %i, %s },", entries[i]->cameraSType, entries[i]->numData, camSegLine, rawDataIndex + (i * 8)); + declaration += + StringHelper::Sprintf(" { 0x%04X, %i, %s },", entries[i]->cameraSType, + entries[i]->numData, camSegLine, rawDataIndex + (i * 8)); if (i < entries.size() - 1) declaration += "\n"; } - parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, entries.size() * 8, "CamData", StringHelper::Sprintf("%s_camDataList_%08X", prefix.c_str(), rawDataIndex), entries.size(), declaration); + parent->AddDeclarationArray( + rawDataIndex, DeclarationAlignment::None, entries.size() * 8, "CamData", + StringHelper::Sprintf("%s_camDataList_%08X", prefix.c_str(), rawDataIndex), entries.size(), + declaration); int numDataTotal = abs(rawDataIndex - (int)cameraPosDataOffset) / 0x6; @@ -291,15 +324,20 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const s declaration = ""; for (int i = 0; i < numDataTotal; i++) { - CameraPositionData* data = new CameraPositionData(rawData, cameraPosDataOffset + (i * 6)); + CameraPositionData* data = + new CameraPositionData(rawData, cameraPosDataOffset + (i * 6)); cameraPositionData.push_back(data); - declaration += StringHelper::Sprintf(" { %6i, %6i, %6i },\n", data->x, data->y, data->z); + declaration += + StringHelper::Sprintf(" { %6i, %6i, %6i },\n", data->x, data->y, data->z); } int cameraPosDataIndex = cameraPosDataSeg & 0x00FFFFFF; int entrySize = numDataTotal * 0x6; - parent->AddDeclarationArray(cameraPosDataIndex, DeclarationAlignment::None, entrySize, "Vec3s", StringHelper::Sprintf("%s_camPosData_%08X", prefix.c_str(), cameraPosDataIndex), numDataTotal, declaration); + parent->AddDeclarationArray( + cameraPosDataIndex, DeclarationAlignment::None, entrySize, "Vec3s", + StringHelper::Sprintf("%s_camPosData_%08X", prefix.c_str(), cameraPosDataIndex), + numDataTotal, declaration); } } diff --git a/tools/ZAPD/ZAPD/ZCollision.h b/tools/ZAPD/ZAPD/ZCollision.h index 7f7b7150a9..1f95e57645 100644 --- a/tools/ZAPD/ZAPD/ZCollision.h +++ b/tools/ZAPD/ZAPD/ZCollision.h @@ -1,7 +1,7 @@ #pragma once -#include "ZResource.h" #include "ZFile.h" +#include "ZResource.h" #include "ZRoom/ZRoom.h" class PolygonEntry @@ -58,7 +58,8 @@ public: std::vector entries; std::vector cameraPositionData; - CameraDataList(ZFile* parent, const std::string& prefix, const std::vector& rawData, int rawDataIndex, int polyTypeDefSegmentOffset, int polygonTypesCnt); + CameraDataList(ZFile* parent, const std::string& prefix, const std::vector& rawData, + int rawDataIndex, int polyTypeDefSegmentOffset, int polygonTypesCnt); }; class ZCollisionHeader : public ZResource @@ -66,9 +67,9 @@ class ZCollisionHeader : public ZResource public: int16_t absMinX, absMinY, absMinZ; int16_t absMaxX, absMaxY, absMaxZ; - int16_t numVerts; + uint16_t numVerts; segptr_t vtxAddress; - int16_t numPolygons; + uint16_t numPolygons; segptr_t polyAddress; segptr_t polyTypeDefAddress; segptr_t camDataAddress; @@ -83,11 +84,13 @@ public: CameraDataList* camData; ZCollisionHeader(); - //ZCollisionHeader(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); - ZCollisionHeader(ZFile* parent, const std::string& prefix, const std::vector& rawData, int rawDataIndex); + // ZCollisionHeader(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + ZCollisionHeader(ZFile* parent, const std::string& prefix, const std::vector& rawData, + int rawDataIndex); ~ZCollisionHeader(); ZResourceType GetResourceType() override; - static ZCollisionHeader* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex); + static ZCollisionHeader* ExtractFromXML(tinyxml2::XMLElement* reader, + std::vector nRawData, int rawDataIndex); }; diff --git a/tools/ZAPD/ZAPD/ZCutscene.cpp b/tools/ZAPD/ZAPD/ZCutscene.cpp index d2ef633930..f84be295d3 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.cpp +++ b/tools/ZAPD/ZAPD/ZCutscene.cpp @@ -27,10 +27,12 @@ ZCutscene::ZCutscene(std::vector nRawData, int rawDataIndex, int rawDat int numEntries = 1; - /*if (cmdID != CutsceneCommands::SetCameraPos && cmdID != CutsceneCommands::SetCameraFocus && cmdID != CutsceneCommands::SetCameraFocusLink && cmdID != CutsceneCommands::SetCameraPosLink) + /*if (cmdID != CutsceneCommands::SetCameraPos && cmdID != CutsceneCommands::SetCameraFocus + && cmdID != CutsceneCommands::SetCameraFocusLink && cmdID != + CutsceneCommands::SetCameraPosLink) { - numEntries = BitConverter::ToInt32BE(rawData, currentPtr); - currentPtr += 4; + numEntries = BitConverter::ToInt32BE(rawData, currentPtr); + currentPtr += 4; }*/ for (int j = 0; j < numEntries; j++) @@ -39,15 +41,39 @@ ZCutscene::ZCutscene(std::vector nRawData, int rawDataIndex, int rawDat switch (cmdID) { - case CutsceneCommands::SetCameraPos: cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); break; - case CutsceneCommands::SetCameraFocus: cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); break; - case CutsceneCommands::SpecialAction: cmd = new CutsceneCommandSpecialAction(rawData, currentPtr); break; - case CutsceneCommands::SetLighting: cmd = new CutsceneCommandEnvLighting(rawData, currentPtr); break; - case CutsceneCommands::SetCameraPosLink: cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); break; - case CutsceneCommands::SetCameraFocusLink: cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); break; - case CutsceneCommands::Textbox: cmd = new CutsceneCommandTextbox(rawData, currentPtr); break; - case CutsceneCommands::Cmd09: cmd = new CutsceneCommandUnknown9(rawData, currentPtr); break; - case CutsceneCommands::Unknown: cmd = new CutsceneCommandUnknown(rawData, currentPtr); break; + case CutsceneCommands::Cmd00: + break; + case CutsceneCommands::SetCameraPos: + cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); + break; + case CutsceneCommands::SetCameraFocus: + cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); + break; + case CutsceneCommands::SpecialAction: + cmd = new CutsceneCommandSpecialAction(rawData, currentPtr); + break; + case CutsceneCommands::SetLighting: + cmd = new CutsceneCommandEnvLighting(rawData, currentPtr); + break; + case CutsceneCommands::SetCameraPosLink: + cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); + break; + case CutsceneCommands::SetCameraFocusLink: + cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); + break; + case CutsceneCommands::Cmd07: + break; + case CutsceneCommands::Cmd08: + break; + case CutsceneCommands::Cmd09: + cmd = new CutsceneCommandUnknown9(rawData, currentPtr); + break; + case CutsceneCommands::Textbox: + cmd = new CutsceneCommandTextbox(rawData, currentPtr); + break; + case CutsceneCommands::Unknown: + cmd = new CutsceneCommandUnknown(rawData, currentPtr); + break; case CutsceneCommands::SetActorAction0: case CutsceneCommands::SetActorAction1: case CutsceneCommands::SetActorAction2: @@ -58,15 +84,37 @@ ZCutscene::ZCutscene(std::vector nRawData, int rawDataIndex, int rawDat case CutsceneCommands::SetActorAction7: case CutsceneCommands::SetActorAction8: case CutsceneCommands::SetActorAction9: - case CutsceneCommands::SetActorAction10: cmd = new CutsceneCommandActorAction(rawData, currentPtr); break; - case CutsceneCommands::SetSceneTransFX: cmd = new CutsceneCommandSceneTransFX(rawData, currentPtr); break; - case CutsceneCommands::Nop: cmd = new CutsceneCommandNop(rawData, currentPtr); break; - case CutsceneCommands::PlayBGM: cmd = new CutsceneCommandPlayBGM(rawData, currentPtr); break; - case CutsceneCommands::StopBGM: cmd = new CutsceneCommandStopBGM(rawData, currentPtr); break; - case CutsceneCommands::FadeBGM: cmd = new CutsceneCommandFadeBGM(rawData, currentPtr); break; - case CutsceneCommands::SetTime: cmd = new CutsceneCommandDayTime(rawData, currentPtr); break; - case CutsceneCommands::Terminator: cmd = new CutsceneCommandTerminator(rawData, currentPtr); break; - case CutsceneCommands::End: cmd = new CutsceneCommandEnd(rawData, currentPtr); break; + case CutsceneCommands::SetActorAction10: + cmd = new CutsceneCommandActorAction(rawData, currentPtr); + break; + case CutsceneCommands::SetSceneTransFX: + cmd = new CutsceneCommandSceneTransFX(rawData, currentPtr); + break; + case CutsceneCommands::Nop: + cmd = new CutsceneCommandNop(rawData, currentPtr); + break; + case CutsceneCommands::PlayBGM: + cmd = new CutsceneCommandPlayBGM(rawData, currentPtr); + break; + case CutsceneCommands::StopBGM: + cmd = new CutsceneCommandStopBGM(rawData, currentPtr); + break; + case CutsceneCommands::FadeBGM: + cmd = new CutsceneCommandFadeBGM(rawData, currentPtr); + break; + case CutsceneCommands::SetTime: + cmd = new CutsceneCommandDayTime(rawData, currentPtr); + break; + case CutsceneCommands::Terminator: + cmd = new CutsceneCommandTerminator(rawData, currentPtr); + break; + case CutsceneCommands::End: + cmd = new CutsceneCommandEnd(rawData, currentPtr); + break; + case CutsceneCommands::Error: + fprintf(stderr, "Cutscene command error %d %s %d\n", (int)cmdID, __FILE__, + __LINE__); + break; } cmd->commandIndex = i; @@ -87,18 +135,18 @@ ZCutscene::~ZCutscene() string ZCutscene::GetSourceOutputCode(const std::string& prefix) { string output = ""; - int size = 0; + size_t size = 0; int32_t curPtr = 0; - //output += StringHelper::Sprintf("// SIZE = 0x%04X\n", GetRawDataSize()); + // output += StringHelper::Sprintf("// SIZE = 0x%04X\n", GetRawDataSize()); output += StringHelper::Sprintf("\tCS_BEGIN_CUTSCENE(%i, %i),\n", commands.size(), endFrame); - for (int i = 0; i < commands.size(); i++) + for (size_t i = 0; i < commands.size(); i++) { CutsceneCommand* cmd = commands[i]; output += "\t" + cmd->GenerateSourceCode(prefix, curPtr); curPtr += (uint32_t)cmd->GetCommandSize(); - size += (int)cmd->GetCommandSize(); + size += cmd->GetCommandSize(); } output += StringHelper::Sprintf("\tCS_END(),\n", commands.size(), endFrame); @@ -113,7 +161,7 @@ int ZCutscene::GetRawDataSize() // Beginning size += 8; - for (int i = 0; i < commands.size(); i++) + for (size_t i = 0; i < commands.size(); i++) { CutsceneCommand* cmd = commands[i]; size += (int)cmd->GetCommandSize(); @@ -126,7 +174,9 @@ int ZCutscene::GetRawDataSize() return size; } -ZCutscene* ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath) +ZCutscene* ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, const int rawDataIndex, + const std::string& nRelPath) { ZCutscene* cs = new ZCutscene(nRawData, rawDataIndex, 9999); cs->rawData = nRawData; @@ -145,35 +195,165 @@ CutsceneCommands ZCutscene::GetCommandFromID(int id) { switch (id) { - case 0x0003: return CutsceneCommands::SpecialAction; - case 0x0004: return CutsceneCommands::SetLighting; - case 0x0056: return CutsceneCommands::PlayBGM; - case 0x0057: return CutsceneCommands::StopBGM; - case 0x007C: return CutsceneCommands::FadeBGM; - case 0x0009: return CutsceneCommands::Cmd09; - case 0x0013: return CutsceneCommands::Textbox; - case 0x008C: return CutsceneCommands::SetTime; - case 0x0001: return CutsceneCommands::SetCameraPos; - case 0x0002: return CutsceneCommands::SetCameraFocus; - case 0x0005: return CutsceneCommands::SetCameraPosLink; - case 0x0006: return CutsceneCommands::SetCameraFocusLink; - case 0x0007: return CutsceneCommands::Cmd07; - case 0x0008: return CutsceneCommands::Cmd08; - case 0x03E8: return CutsceneCommands::Terminator; - case 0xFFFF: return CutsceneCommands::End; - case 0x002D: return CutsceneCommands::SetSceneTransFX; - case 10: return CutsceneCommands::SetActorAction0; - case 15: case 17: case 18: case 23: case 34: case 39: case 46: case 76: case 85: case 93: case 105: case 107: case 110: case 119: case 123: case 138: case 139: case 144: return CutsceneCommands::SetActorAction1; - case 14: case 16: case 24: case 35: case 40: case 48: case 64: case 68: case 70: case 78: case 80: case 94: case 116: case 118: case 120: case 125: case 131: case 141: return CutsceneCommands::SetActorAction2; - case 25: case 36: case 41: case 50: case 67: case 69: case 72: case 81: case 106: case 117: case 121: case 126: case 132: return CutsceneCommands::SetActorAction3; - case 29: case 37: case 42: case 51: case 53: case 63: case 65: case 66: case 75: case 82: case 108: case 127: case 133: return CutsceneCommands::SetActorAction4; - case 30: case 38: case 43: case 47: case 54: case 79: case 83: case 128: case 135: return CutsceneCommands::SetActorAction5; - case 44: case 55: case 77: case 84: case 90: case 129: case 136: return CutsceneCommands::SetActorAction6; - case 31: case 52: case 57: case 58: case 88: case 115: case 130: case 137: return CutsceneCommands::SetActorAction7; - case 49: case 60: case 89: case 111: case 114: case 134: case 142: return CutsceneCommands::SetActorAction8; - case 62: return CutsceneCommands::SetActorAction9; - case 143: return CutsceneCommands::SetActorAction10; - case 0x0B: case 0x0D: case 0x1A: case 0x1B: case 0x1C: case 0x20: case 0x21: case 0x3B: case 0x3D: case 0x47: case 0x49: case 0x6D: case 0x15: case 0x16: case 0x70: case 0x71: case 0x4A: return CutsceneCommands::Unknown; + case 0x0003: + return CutsceneCommands::SpecialAction; + case 0x0004: + return CutsceneCommands::SetLighting; + case 0x0056: + return CutsceneCommands::PlayBGM; + case 0x0057: + return CutsceneCommands::StopBGM; + case 0x007C: + return CutsceneCommands::FadeBGM; + case 0x0009: + return CutsceneCommands::Cmd09; + case 0x0013: + return CutsceneCommands::Textbox; + case 0x008C: + return CutsceneCommands::SetTime; + case 0x0001: + return CutsceneCommands::SetCameraPos; + case 0x0002: + return CutsceneCommands::SetCameraFocus; + case 0x0005: + return CutsceneCommands::SetCameraPosLink; + case 0x0006: + return CutsceneCommands::SetCameraFocusLink; + case 0x0007: + return CutsceneCommands::Cmd07; + case 0x0008: + return CutsceneCommands::Cmd08; + case 0x03E8: + return CutsceneCommands::Terminator; + case 0xFFFF: + return CutsceneCommands::End; + case 0x002D: + return CutsceneCommands::SetSceneTransFX; + case 10: + return CutsceneCommands::SetActorAction0; + case 15: + case 17: + case 18: + case 23: + case 34: + case 39: + case 46: + case 76: + case 85: + case 93: + case 105: + case 107: + case 110: + case 119: + case 123: + case 138: + case 139: + case 144: + return CutsceneCommands::SetActorAction1; + case 14: + case 16: + case 24: + case 35: + case 40: + case 48: + case 64: + case 68: + case 70: + case 78: + case 80: + case 94: + case 116: + case 118: + case 120: + case 125: + case 131: + case 141: + return CutsceneCommands::SetActorAction2; + case 25: + case 36: + case 41: + case 50: + case 67: + case 69: + case 72: + case 81: + case 106: + case 117: + case 121: + case 126: + case 132: + return CutsceneCommands::SetActorAction3; + case 29: + case 37: + case 42: + case 51: + case 53: + case 63: + case 65: + case 66: + case 75: + case 82: + case 108: + case 127: + case 133: + return CutsceneCommands::SetActorAction4; + case 30: + case 38: + case 43: + case 47: + case 54: + case 79: + case 83: + case 128: + case 135: + return CutsceneCommands::SetActorAction5; + case 44: + case 55: + case 77: + case 84: + case 90: + case 129: + case 136: + return CutsceneCommands::SetActorAction6; + case 31: + case 52: + case 57: + case 58: + case 88: + case 115: + case 130: + case 137: + return CutsceneCommands::SetActorAction7; + case 49: + case 60: + case 89: + case 111: + case 114: + case 134: + case 142: + return CutsceneCommands::SetActorAction8; + case 62: + return CutsceneCommands::SetActorAction9; + case 143: + return CutsceneCommands::SetActorAction10; + case 0x0B: + case 0x0D: + case 0x1A: + case 0x1B: + case 0x1C: + case 0x20: + case 0x21: + case 0x3B: + case 0x3D: + case 0x47: + case 0x49: + case 0x6D: + case 0x15: + case 0x16: + case 0x70: + case 0x71: + case 0x4A: + return CutsceneCommands::Unknown; } printf("WARNING: Could not identify cutscene command ID 0x%04X\n", id); @@ -188,7 +368,6 @@ ZResourceType ZCutscene::GetResourceType() CutsceneCommand::CutsceneCommand(const vector& rawData, int rawDataIndex) { - } string CutsceneCommand::GetCName(const std::string& prefix) @@ -198,7 +377,9 @@ string CutsceneCommand::GetCName(const std::string& prefix) string CutsceneCommand::GenerateSourceCode(const std::string& roomName, int baseAddress) { - return StringHelper::Sprintf("%s %sCutsceneData%04XCmd%02X = { 0x%02X,", GetCName(roomName).c_str(), roomName.c_str(), baseAddress, commandIndex, commandID); + return StringHelper::Sprintf("%s %sCutsceneData%04XCmd%02X = { 0x%02X,", + GetCName(roomName).c_str(), roomName.c_str(), baseAddress, + commandIndex, commandID); } size_t CutsceneCommand::GetCommandSize() @@ -222,7 +403,9 @@ CutsceneCameraPoint::CutsceneCameraPoint(const vector& rawData, int raw unused = BitConverter::ToInt16BE(data, rawDataIndex + 14); } -CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector& rawData, + int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { const uint8_t* data = rawData.data(); @@ -285,10 +468,13 @@ string CutsceneCommandSetCameraPos::GenerateSourceCode(const std::string& roomNa result += StringHelper::Sprintf("%s(%i, %i),\n", listStr.c_str(), startFrame, endFrame); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("\t\t%s(%i, %i, %i, 0x%06X, %i, %i, %i, %i),\n", posStr.c_str(), entries[i]->continueFlag, entries[i]->cameraRoll, entries[i]->nextPointFrame, - *(uint32_t*)&entries[i]->viewAngle, entries[i]->posX, entries[i]->posY, entries[i]->posZ, entries[i]->unused); + result += StringHelper::Sprintf("\t\t%s(%i, %i, %i, 0x%06X, %i, %i, %i, %i),\n", + posStr.c_str(), entries[i]->continueFlag, + entries[i]->cameraRoll, entries[i]->nextPointFrame, + *(uint32_t*)&entries[i]->viewAngle, entries[i]->posX, + entries[i]->posY, entries[i]->posZ, entries[i]->unused); } return result; @@ -312,12 +498,16 @@ MusicFadeEntry::MusicFadeEntry(const vector& rawData, int rawDataIndex) unknown5 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 24); unknown6 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 28); unknown7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32); - unknown8 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 36); - unknown9 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 40); - unknown10 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 44); + unknown8 = (uint32_t)BitConverter::ToInt32BE(rawData, + rawDataIndex + 36); // Macro hardcodes it as zero + unknown9 = (uint32_t)BitConverter::ToInt32BE(rawData, + rawDataIndex + 40); // Macro hardcodes it as zero + unknown10 = (uint32_t)BitConverter::ToInt32BE(rawData, + rawDataIndex + 44); // Macro hardcodes it as zero } -CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector& rawData, int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); @@ -341,11 +531,13 @@ string CutsceneCommandFadeBGM::GenerateSourceCode(const std::string& roomName, i result += StringHelper::Sprintf("CS_FADE_BGM_LIST(%i),\n", entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("\t\tCS_FADE_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, - entries[i]->unknown0, entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7, - entries[i]->unknown8, entries[i]->unknown9, entries[i]->unknown10); + result += StringHelper::Sprintf( + "\t\tCS_FADE_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, + entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0, + entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, + entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7); } return result; @@ -353,7 +545,7 @@ string CutsceneCommandFadeBGM::GenerateSourceCode(const std::string& roomName, i size_t CutsceneCommandFadeBGM::GetCommandSize() { - return CutsceneCommand::GetCommandSize() + 0x30; + return CutsceneCommand::GetCommandSize() + 0x30 * entries.size(); } MusicChangeEntry::MusicChangeEntry(const vector& rawData, int rawDataIndex) @@ -371,7 +563,8 @@ MusicChangeEntry::MusicChangeEntry(const vector& rawData, int rawDataIn unknown7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32); } -CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector& rawData, int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); @@ -390,11 +583,13 @@ string CutsceneCommandPlayBGM::GenerateSourceCode(const std::string& roomName, i result += StringHelper::Sprintf("CS_PLAY_BGM_LIST(%i),\n", entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("\t\tCS_PLAY_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->sequence, entries[i]->startFrame, - entries[i]->endFrame, entries[i]->unknown0, entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, entries[i]->unknown5, - entries[i]->unknown6, entries[i]->unknown7); + result += StringHelper::Sprintf( + "\t\tCS_PLAY_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->sequence, + entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0, + entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, + entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7); } return result; @@ -410,7 +605,8 @@ size_t CutsceneCommandPlayBGM::GetCommandSize() return CutsceneCommand::GetCommandSize() + 0x30; } -CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector& rawData, int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); @@ -429,11 +625,13 @@ string CutsceneCommandStopBGM::GenerateSourceCode(const std::string& roomName, i result += StringHelper::Sprintf("CS_STOP_BGM_LIST(%i),\n", entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("CS_STOP_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->sequence, entries[i]->startFrame, - entries[i]->endFrame, entries[i]->unknown0, entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, entries[i]->unknown5, - entries[i]->unknown6, entries[i]->unknown7); + result += StringHelper::Sprintf( + "\t\tCS_STOP_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->sequence, + entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0, + entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, + entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7); } return result; @@ -464,7 +662,9 @@ EnvLightingEntry::EnvLightingEntry(const vector& rawData, int rawDataIn unused7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32); } -CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector& rawData, + int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); @@ -483,10 +683,12 @@ string CutsceneCommandEnvLighting::GenerateSourceCode(const std::string& roomNam result += StringHelper::Sprintf("CS_LIGHTING_LIST(%i),\n", entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("CS_LIGHTING(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->setting, entries[i]->startFrame, - entries[i]->endFrame, entries[i]->unused0, entries[i]->unused1, entries[i]->unused2, entries[i]->unused3, entries[i]->unused4, entries[i]->unused5, + result += StringHelper::Sprintf( + "\t\tCS_LIGHTING(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->setting, + entries[i]->startFrame, entries[i]->endFrame, entries[i]->unused0, entries[i]->unused1, + entries[i]->unused2, entries[i]->unused3, entries[i]->unused4, entries[i]->unused5, entries[i]->unused6, entries[i]->unused7); } @@ -512,10 +714,12 @@ Unknown9Entry::Unknown9Entry(const vector& rawData, int rawDataIndex) unk3 = rawData[rawDataIndex + 7]; unk4 = rawData[rawDataIndex + 8]; unused0 = rawData[rawDataIndex + 10]; - unused1 = rawData[rawDataIndex + 11];; + unused1 = rawData[rawDataIndex + 11]; + ; } -CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector& rawData, int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); @@ -534,10 +738,12 @@ string CutsceneCommandUnknown9::GenerateSourceCode(const std::string& roomName, result += StringHelper::Sprintf("CS_CMD_09_LIST(%i),\n", entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("CS_CMD_09(%i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->unk2, - entries[i]->unk3, entries[i]->unk4, entries[i]->unused0, entries[i]->unused1); + result += StringHelper::Sprintf("\t\tCS_CMD_09(%i, %i, %i, %i, %i, %i, %i, %i),\n", + entries[i]->base, entries[i]->startFrame, + entries[i]->endFrame, entries[i]->unk2, entries[i]->unk3, + entries[i]->unk4, entries[i]->unused0, entries[i]->unused1); } return result; @@ -569,7 +775,8 @@ UnkEntry::UnkEntry(const vector& rawData, int rawDataIndex) unused11 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 44); } -CutsceneCommandUnknown::CutsceneCommandUnknown(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandUnknown::CutsceneCommandUnknown(const vector& rawData, int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); @@ -588,11 +795,13 @@ string CutsceneCommandUnknown::GenerateSourceCode(const std::string& roomName, i result += StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%02X, %i),\n", commandID, entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("\tCS_UNK_DATA(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->unused0, entries[i]->unused1, entries[i]->unused2, - entries[i]->unused3, entries[i]->unused4, entries[i]->unused5, entries[i]->unused6, - entries[i]->unused7, entries[i]->unused8, entries[i]->unused9, entries[i]->unused10, entries[i]->unused11); + result += StringHelper::Sprintf( + "\t\tCS_UNK_DATA(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", + entries[i]->unused0, entries[i]->unused1, entries[i]->unused2, entries[i]->unused3, + entries[i]->unused4, entries[i]->unused5, entries[i]->unused6, entries[i]->unused7, + entries[i]->unused8, entries[i]->unused9, entries[i]->unused10, entries[i]->unused11); } return result; @@ -618,7 +827,8 @@ DayTimeEntry::DayTimeEntry(const vector& rawData, int rawDataIndex) unused = rawData[rawDataIndex + 8]; } -CutsceneCommandDayTime::CutsceneCommandDayTime(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandDayTime::CutsceneCommandDayTime(const vector& rawData, int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); @@ -642,10 +852,11 @@ string CutsceneCommandDayTime::GenerateSourceCode(const std::string& roomName, i result += StringHelper::Sprintf("CS_TIME_LIST(%i),\n", entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("\t\tCS_TIME(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, - entries[i]->hour, entries[i]->minute, entries[i]->unused); + result += StringHelper::Sprintf("\t\tCS_TIME(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, + entries[i]->startFrame, entries[i]->endFrame, + entries[i]->hour, entries[i]->minute, entries[i]->unused); } return result; @@ -666,7 +877,8 @@ TextboxEntry::TextboxEntry(const vector& rawData, int rawDataIndex) textID2 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 10); } -CutsceneCommandTextbox::CutsceneCommandTextbox(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandTextbox::CutsceneCommandTextbox(const vector& rawData, int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); @@ -690,16 +902,19 @@ string CutsceneCommandTextbox::GenerateSourceCode(const std::string& roomName, i result += StringHelper::Sprintf("CS_TEXT_LIST(%i),\n", entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { if (entries[i]->base == 0xFFFF) { - result += StringHelper::Sprintf("\t\tCS_TEXT_NONE(%i, %i),\n", entries[i]->startFrame, entries[i]->endFrame); + result += StringHelper::Sprintf("\t\tCS_TEXT_NONE(%i, %i),\n", entries[i]->startFrame, + entries[i]->endFrame); } else { - result += StringHelper::Sprintf("\t\tCS_TEXT_DISPLAY_TEXTBOX(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->type, - entries[i]->textID1, entries[i]->textID2); + result += StringHelper::Sprintf( + "\t\tCS_TEXT_DISPLAY_TEXTBOX(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, + entries[i]->startFrame, entries[i]->endFrame, entries[i]->type, entries[i]->textID1, + entries[i]->textID2); } } @@ -732,7 +947,9 @@ ActorAction::ActorAction(const vector& rawData, int rawDataIndex) normalZ = BitConverter::ToInt32BE(data, rawDataIndex + 44); } -CutsceneCommandActorAction::CutsceneCommandActorAction(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandActorAction::CutsceneCommandActorAction(const vector& rawData, + int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); @@ -748,14 +965,28 @@ CutsceneCommandActorAction::CutsceneCommandActorAction(const vector& ra string CutsceneCommandActorAction::GenerateSourceCode(const std::string& roomName, int baseAddress) { string result = ""; + string subCommand = ""; - result += StringHelper::Sprintf("CS_NPC_ACTION_LIST(%i, %i),\n", commandID, entries.size()); - - for (int i = 0; i < entries.size(); i++) + if (commandID == 10) { - result += StringHelper::Sprintf("\tCS_NPC_ACTION(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->action, entries[i]->startFrame, entries[i]->endFrame, - entries[i]->rotX, entries[i]->rotY, entries[i]->rotZ, entries[i]->startPosX, entries[i]->startPosY, entries[i]->startPosZ, entries[i]->endPosX, entries[i]->endPosY, entries[i]->endPosZ, - *(int32_t*)&entries[i]->normalX, *(int32_t*)&entries[i]->normalY, *(int32_t*)&entries[i]->normalZ); + result += StringHelper::Sprintf("CS_PLAYER_ACTION_LIST(%i),\n", entries.size()); + subCommand = "CS_PLAYER_ACTION"; + } + else + { + result += StringHelper::Sprintf("CS_NPC_ACTION_LIST(%i, %i),\n", commandID, entries.size()); + subCommand = "CS_NPC_ACTION"; + } + + for (size_t i = 0; i < entries.size(); i++) + { + result += StringHelper::Sprintf( + "\t\t%s(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", + subCommand.c_str(), entries[i]->action, entries[i]->startFrame, entries[i]->endFrame, + entries[i]->rotX, entries[i]->rotY, entries[i]->rotZ, entries[i]->startPosX, + entries[i]->startPosY, entries[i]->startPosZ, entries[i]->endPosX, entries[i]->endPosY, + entries[i]->endPosZ, *(int32_t*)&entries[i]->normalX, *(int32_t*)&entries[i]->normalY, + *(int32_t*)&entries[i]->normalZ); } return result; @@ -771,14 +1002,16 @@ size_t CutsceneCommandActorAction::GetCommandSize() return CutsceneCommand::GetCommandSize() + (entries.size() * 0x30); } -CutsceneCommandTerminator::CutsceneCommandTerminator(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandTerminator::CutsceneCommandTerminator(const vector& rawData, + int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4); - unknown = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); + unknown = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); // endFrame duplicate } string CutsceneCommandTerminator::GetCName(const std::string& prefix) @@ -790,7 +1023,7 @@ string CutsceneCommandTerminator::GenerateSourceCode(const std::string& roomName { string result = ""; - result += StringHelper::Sprintf("CS_TERMINATOR(0x%04X, %i, %i, 0x%04X),\n", base, startFrame, endFrame, unknown); + result += StringHelper::Sprintf("CS_TERMINATOR(0x%04X, %i, %i),\n", base, startFrame, endFrame); return result; } @@ -800,7 +1033,8 @@ size_t CutsceneCommandTerminator::GetCommandSize() return CutsceneCommand::GetCommandSize() + 8; } -CutsceneCommandEnd::CutsceneCommandEnd(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandEnd::CutsceneCommandEnd(const vector& rawData, int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); @@ -846,7 +1080,9 @@ SpecialActionEntry::SpecialActionEntry(const vector& rawData, int rawDa unused10 = BitConverter::ToUInt32BE(data, rawDataIndex + 44); } -CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector& rawData, + int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); @@ -859,17 +1095,22 @@ CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector } } -string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomName, + int baseAddress) { string result = ""; result += StringHelper::Sprintf("CS_MISC_LIST(%i),\n", entries.size()); - for (int i = 0; i < entries.size(); i++) + for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("\t\tCS_MISC(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, - entries[i]->unused0, entries[i]->unused1, entries[i]->unused2, entries[i]->unused3, entries[i]->unused4, entries[i]->unused5, entries[i]->unused6, - entries[i]->unused7, entries[i]->unused8, entries[i]->unused9, entries[i]->unused10); + result += StringHelper::Sprintf( + "\t\tCS_MISC(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, " + "%i),\n", + entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->unused0, + entries[i]->unused1, entries[i]->unused2, entries[i]->unused3, entries[i]->unused4, + entries[i]->unused5, entries[i]->unused6, entries[i]->unused7, entries[i]->unused8, + entries[i]->unused9, entries[i]->unused10); } return result; @@ -885,7 +1126,8 @@ size_t CutsceneCommandSpecialAction::GetCommandSize() return CutsceneCommand::GetCommandSize() + (0x30 * entries.size()); } -CutsceneCommandNop::CutsceneCommandNop(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandNop::CutsceneCommandNop(const vector& rawData, int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); @@ -902,7 +1144,9 @@ size_t CutsceneCommandNop::GetCommandSize() return CutsceneCommand::GetCommandSize() + 6; } -CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) +CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector& rawData, + int rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; diff --git a/tools/ZAPD/ZAPD/ZCutscene.h b/tools/ZAPD/ZAPD/ZCutscene.h index bf26b90280..6c97db98e1 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.h +++ b/tools/ZAPD/ZAPD/ZCutscene.h @@ -1,8 +1,8 @@ #pragma once -#include -#include #include +#include +#include #include "ZResource.h" #include "tinyxml2.h" @@ -141,7 +141,7 @@ class CutsceneCommandFadeBGM : public CutsceneCommand public: std::vector entries; - CutsceneCommandFadeBGM( const std::vector& rawData, int rawDataIndex); + CutsceneCommandFadeBGM(const std::vector& rawData, int rawDataIndex); std::string GetCName(const std::string& prefix); std::string GenerateSourceCode(const std::string& roomName, int baseAddress); size_t GetCommandSize(); @@ -411,11 +411,14 @@ public: ZResourceType GetResourceType() override; - static ZCutscene* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath); + static ZCutscene* ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, const int rawDataIndex, + const std::string& nRelPath); + protected: int numCommands; int endFrame; std::vector commands; - void ParseRawData(); + void ParseRawData() override; }; diff --git a/tools/ZAPD/ZAPD/ZDisplayList.cpp b/tools/ZAPD/ZAPD/ZDisplayList.cpp index 02e43d52fc..c5fd660496 100644 --- a/tools/ZAPD/ZAPD/ZDisplayList.cpp +++ b/tools/ZAPD/ZAPD/ZDisplayList.cpp @@ -1,15 +1,15 @@ #include "ZDisplayList.h" -#include "BitConverter.h" -#include "StringHelper.h" -#include "OutputFormatter.h" -#include "HighLevel/HLModelIntermediette.h" -#include "Globals.h" -#include "gfxd.h" -#include -#include #include #include +#include +#include #include +#include "BitConverter.h" +#include "Globals.h" +#include "HighLevel/HLModelIntermediette.h" +#include "OutputFormatter.h" +#include "StringHelper.h" +#include "gfxd.h" using namespace std; using namespace tinyxml2; @@ -40,19 +40,21 @@ ZDisplayList::ZDisplayList() : ZResource() } // EXTRACT MODE -ZDisplayList* ZDisplayList::ExtractFromXML(XMLElement* reader, vector nRawData, int nRawDataIndex, int rawDataSize, string nRelPath) +ZDisplayList* ZDisplayList::ExtractFromXML(XMLElement* reader, vector nRawData, + int nRawDataIndex, int rawDataSize, string nRelPath) { ZDisplayList* dList = new ZDisplayList(); dList->ParseXML(reader); - //dList->name = reader->Attribute("Name"); + // dList->name = reader->Attribute("Name"); dList->rawData = nRawData; dList->rawDataIndex = nRawDataIndex; dList->fileData = dList->rawData; dList->relativePath = nRelPath; - dList->rawData = vector(dList->rawData.data() + dList->rawDataIndex, dList->rawData.data() + dList->rawDataIndex + rawDataSize); + dList->rawData = vector(dList->rawData.data() + dList->rawDataIndex, + dList->rawData.data() + dList->rawDataIndex + rawDataSize); dList->ParseRawData(); return dList; @@ -66,12 +68,14 @@ ZDisplayList* ZDisplayList::BuildFromXML(XMLElement* reader, string inFolder, bo return dList; } -ZDisplayList::ZDisplayList(vector nRawData, int nRawDataIndex, int rawDataSize) : ZDisplayList() +ZDisplayList::ZDisplayList(vector nRawData, int nRawDataIndex, int rawDataSize) + : ZDisplayList() { fileData = nRawData; rawDataIndex = nRawDataIndex; name = StringHelper::Sprintf("DL_%06X", rawDataIndex); - rawData = vector(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + rawDataSize); + rawData = vector(nRawData.data() + rawDataIndex, + nRawData.data() + rawDataIndex + rawDataSize); ParseRawData(); } @@ -86,7 +90,8 @@ void ZDisplayList::ParseRawData() instructions.push_back(BitConverter::ToUInt64BE(rawDataArr, (i * 8))); } -void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::string prefix, + char* line) { switch (opcode) { @@ -95,13 +100,13 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s break; case F3DZEXOpcode::G_DL: Opcode_G_DL(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_MODIFYVTX: Opcode_G_MODIFYVTX(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_CULLDL: Opcode_G_CULLDL(data, i, prefix, line); - break; + break; /*case F3DZEXOpcode::G_BRANCH_Z: { int aaa = (data & 0x00FFF00000000000) >> 44; @@ -113,10 +118,10 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s break;*/ case F3DZEXOpcode::G_TRI1: Opcode_G_TRI1(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_TRI2: Opcode_G_TRI2(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_QUAD: { int aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; @@ -131,7 +136,7 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s Opcode_G_VTX(data, i, prefix, line); } break; - case F3DZEXOpcode::G_SETTIMG: // HOTSPOT + case F3DZEXOpcode::G_SETTIMG: // HOTSPOT { Opcode_G_SETTIMG(data, i, prefix, line); } @@ -187,30 +192,30 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s else sprintf(line, "gsSPClearGeometryMode(%s),", geoModeStr.c_str()); - //sprintf(line, "gsSPGeometryMode(0x%08X, 0x%08X),", ~cccccc, ssssssss); + // sprintf(line, "gsSPGeometryMode(0x%08X, 0x%08X),", ~cccccc, ssssssss); } break; case F3DZEXOpcode::G_SETPRIMCOLOR: Opcode_G_SETPRIMCOLOR(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_SETOTHERMODE_L: Opcode_G_SETOTHERMODE_L(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_SETOTHERMODE_H: Opcode_G_SETOTHERMODE_H(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_SETTILE: Opcode_G_SETTILE(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_SETTILESIZE: Opcode_G_SETTILESIZE(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_LOADBLOCK: Opcode_G_LOADBLOCK(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_TEXTURE: Opcode_G_TEXTURE(data, i, prefix, line); - break; + break; case F3DZEXOpcode::G_RDPSETOTHERMODE: { int hhhhhh = (data & 0x00FFFFFF00000000) >> 32; @@ -269,10 +274,12 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s uint32_t b = (data2 & 0x00000FFF00000000) >> 32; uint32_t z = (data2 & 0x00000000FFFFFFFF) >> 0; - //sprintf(line, "gsDPWord(%i, 0),", h); - sprintf(line, "gsSPBranchLessZraw(%sDlist0x%06X, 0x%02X, 0x%02X),", prefix.c_str(), h & 0x00FFFFFF, (a / 5) | (b / 2), z); + // sprintf(line, "gsDPWord(%i, 0),", h); + sprintf(line, "gsSPBranchLessZraw(%sDlist0x%06X, 0x%02X, 0x%02X),", prefix.c_str(), + h & 0x00FFFFFF, (a / 5) | (b / 2), z); - ZDisplayList* nList = new ZDisplayList(fileData, h & 0x00FFFFFF, GetDListLength(fileData, h & 0x00FFFFFF, dListType)); + ZDisplayList* nList = new ZDisplayList( + fileData, h & 0x00FFFFFF, GetDListLength(fileData, h & 0x00FFFFFF, dListType)); nList->scene = scene; nList->parent = parent; otherDLists.push_back(nList); @@ -290,14 +297,15 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s break;*/ case F3DZEXOpcode::G_MTX: Opcode_G_MTX(data, i, prefix, line); - break; + break; default: sprintf(line, "// Opcode 0x%02X unimplemented!", (uint32_t)opcode); break; } } -void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, int i, std::string prefix, + char* line) { switch (opcode) { @@ -452,7 +460,7 @@ bool ZDisplayList::SequenceCheck(vector sequence, int startIndex) { bool success = true; - for (int j = 0; j < sequence.size(); j++) + for (size_t j = 0; j < sequence.size(); j++) { F3DZEXOpcode opcode = (F3DZEXOpcode)(instructions[startIndex + j] >> 56); @@ -488,18 +496,23 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out return -1; } - std::vector sequence = { F3DZEXOpcode::G_SETTIMG, F3DZEXOpcode::G_SETTILE, F3DZEXOpcode::G_RDPLOADSYNC, F3DZEXOpcode::G_LOADBLOCK, F3DZEXOpcode::G_RDPPIPESYNC, F3DZEXOpcode::G_SETTILE, F3DZEXOpcode::G_SETTILESIZE }; + std::vector sequence = {F3DZEXOpcode::G_SETTIMG, F3DZEXOpcode::G_SETTILE, + F3DZEXOpcode::G_RDPLOADSYNC, F3DZEXOpcode::G_LOADBLOCK, + F3DZEXOpcode::G_RDPPIPESYNC, F3DZEXOpcode::G_SETTILE, + F3DZEXOpcode::G_SETTILESIZE}; bool seqRes = SequenceCheck(sequence, startIndex); if (seqRes) { - // gsDPLoadTextureBlock(texAddr, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) - // gsDPLoadMultiBlock(texAddr, tmem, rtile, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) - // gsDPLoadTextureBlock_4b(texAddr, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) - // gsDPLoadMultiBlock_4b(texAddr, tmem, rtile, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) + // gsDPLoadTextureBlock(texAddr, fmt, siz, width, height, pal, cms, cmt, masks, maskt, + // shifts, shiftt) gsDPLoadMultiBlock(texAddr, tmem, rtile, fmt, siz, width, height, pal, + // cms, cmt, masks, maskt, shifts, shiftt) gsDPLoadTextureBlock_4b(texAddr, fmt, width, + // height, pal, cms, cmt, masks, maskt, shifts, shiftt) gsDPLoadMultiBlock_4b(texAddr, tmem, + // rtile, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) - uint32_t texAddr, tmem, rtile, fmt, siz, sizB, width, height, width2, height2, pal, cms, cmt, masks, maskt, shifts, shiftt; + uint32_t texAddr, tmem, rtile, fmt, siz, sizB, width, height, width2, height2, pal, cms, + cmt, masks, maskt, shifts, shiftt; string texStr = ""; // gsDPSetTextureImage @@ -507,7 +520,7 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out uint64_t data = instructions[startIndex + 0]; int __ = (data & 0x00FF000000000000) >> 48; - int www = (data & 0x00000FFF00000000) >> 32; + // int www = (data & 0x00000FFF00000000) >> 32; fmt = (__ & 0xE0) >> 5; siz = (__ & 0x18) >> 3; @@ -518,7 +531,9 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out Declaration* texDecl = nullptr; - if (parent != nullptr && segmentNumber != 2) // HACK: Until we have declarations use segment addresses, we'll exclude scene references... + if (parent != nullptr && + segmentNumber != 2) // HACK: Until we have declarations use segment addresses, + // we'll exclude scene references... { texDecl = parent->GetDeclaration(texAddr); @@ -532,7 +547,8 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out texStr = StringHelper::Sprintf("%s", texDecl->varName.c_str()); else if (segmentNumber == 2) texStr = StringHelper::Sprintf("%sTex_%06X", scene->GetName().c_str(), texAddr); - else if (!Globals::Instance->HasSegment(segmentNumber)) // Probably an external asset we are unable to track + else if (!Globals::Instance->HasSegment( + segmentNumber)) // Probably an external asset we are unable to track texStr = StringHelper::Sprintf("0x%06X", data); else texStr = StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), texAddr); @@ -547,17 +563,22 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out { uint64_t data = instructions[startIndex + 1]; - tmem = (data & 0b0000000000000000111111111111111100000000000000000000000000000000) >> 32; + tmem = + (data & 0b0000000000000000111111111111111100000000000000000000000000000000) >> 32; cmt = (data & 0b0000000000000000000000000000000000000000000011000000000000000000) >> 18; - maskt = (data & 0b0000000000000000000000000000000000000000000000111100000000000000) >> 14; - shiftt = (data & 0b0000000000000000000000000000000000000000000000000011110000000000) >> 10; + maskt = + (data & 0b0000000000000000000000000000000000000000000000111100000000000000) >> 14; + shiftt = + (data & 0b0000000000000000000000000000000000000000000000000011110000000000) >> 10; cms = (data & 0b0000000000000000000000000000000000000000000000000000001100000000) >> 8; - masks = (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; + masks = + (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; shifts = (data & 0b0000000000000000000000000000000000000000000000000000000000001111); - //sprintf(line, "gsDPSetTile(%s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),", fmtTbl[fff].c_str(), sizTbl[ii].c_str(), nnnnnnnnn, mmmmmmmmm, ttt, pppp, cc, aaaa, ssss, dd, bbbb, uuuu); - + // sprintf(line, "gsDPSetTile(%s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),", + // fmtTbl[fff].c_str(), sizTbl[ii].c_str(), nnnnnnnnn, mmmmmmmmm, ttt, pppp, cc, aaaa, + // ssss, dd, bbbb, uuuu); } // gsDPLoadSync @@ -571,8 +592,9 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out uint64_t data = instructions[startIndex + 5]; int __ = (data & 0x00FF000000000000) >> 48; pal = (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >> 20; - //siz = (__ & 0x18) >> 3; - rtile = (data & 0b0000000000000000000000000000000011111111000000000000000000000000) >> 24; + // siz = (__ & 0x18) >> 3; + rtile = + (data & 0b0000000000000000000000000000000011111111000000000000000000000000) >> 24; sizB = (__ & 0x18) >> 3; } @@ -585,13 +607,15 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out int shiftAmtW = 2; int shiftAmtH = 2; - if (sizB == (int)F3DZEXTexSizes::G_IM_SIZ_8b && fmt == (int)F3DZEXTexFormats::G_IM_FMT_IA) + if (sizB == (int)F3DZEXTexSizes::G_IM_SIZ_8b && + fmt == (int)F3DZEXTexFormats::G_IM_FMT_IA) shiftAmtW = 3; if (sizB == (int)F3DZEXTexSizes::G_IM_SIZ_4b) shiftAmtW = 3; - if (sizB == (int)F3DZEXTexSizes::G_IM_SIZ_4b && fmt == (int)F3DZEXTexFormats::G_IM_FMT_IA) + if (sizB == (int)F3DZEXTexSizes::G_IM_SIZ_4b && + fmt == (int)F3DZEXTexFormats::G_IM_FMT_IA) shiftAmtH = 3; width = (uuu >> shiftAmtW) + 1; @@ -601,29 +625,39 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out height2 = (vvv >> 2) + 1; } - string fmtTbl[] = { "G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", "G_IM_FMT_I" }; - string sizTbl[] = { "G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b" }; + string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", + "G_IM_FMT_I"}; + string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"}; - //output += StringHelper::Sprintf("gsDPLoadTextureBlock(%s, %s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", - //texStr.c_str(), fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), width, height, pal, cms, cmt, masks, maskt, shifts, shiftt); + // output += StringHelper::Sprintf("gsDPLoadTextureBlock(%s, %s, %s, %i, %i, %i, %i, %i, %i, + // %i, %i, %i),", texStr.c_str(), fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), width, height, + // pal, cms, cmt, masks, maskt, shifts, shiftt); if (siz == 2 && sizB == 0) { if (tmem != 0) - output += StringHelper::Sprintf("gsDPLoadMultiBlock_4b(%s, %i, %i, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", - texStr.c_str(), tmem, rtile, fmtTbl[fmt].c_str(), width2, height2, pal, cms, cmt, masks, maskt, shifts, shiftt); + output += StringHelper::Sprintf( + "gsDPLoadMultiBlock_4b(%s, %i, %i, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", + texStr.c_str(), tmem, rtile, fmtTbl[fmt].c_str(), width2, height2, pal, cms, + cmt, masks, maskt, shifts, shiftt); else - output += StringHelper::Sprintf("gsDPLoadTextureBlock_4b(%s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", - texStr.c_str(), fmtTbl[fmt].c_str(), width2, height2, pal, cms, cmt, masks, maskt, shifts, shiftt); + output += StringHelper::Sprintf( + "gsDPLoadTextureBlock_4b(%s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", + texStr.c_str(), fmtTbl[fmt].c_str(), width2, height2, pal, cms, cmt, masks, + maskt, shifts, shiftt); } else if (siz == 2 && sizB != 0) { if (tmem != 0) - output += StringHelper::Sprintf("gsDPLoadMultiBlock(%s, %i, %i, %s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", - texStr.c_str(), tmem, rtile, fmtTbl[fmt].c_str(), sizTbl[sizB].c_str(), width2, height2, pal, cms, cmt, masks, maskt, shifts, shiftt); + output += StringHelper::Sprintf( + "gsDPLoadMultiBlock(%s, %i, %i, %s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", + texStr.c_str(), tmem, rtile, fmtTbl[fmt].c_str(), sizTbl[sizB].c_str(), width2, + height2, pal, cms, cmt, masks, maskt, shifts, shiftt); else - output += StringHelper::Sprintf("gsDPLoadTextureBlock(%s, %s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", - texStr.c_str(), fmtTbl[fmt].c_str(), sizTbl[sizB].c_str(), width2, height2, pal, cms, cmt, masks, maskt, shifts, shiftt); + output += StringHelper::Sprintf( + "gsDPLoadTextureBlock(%s, %s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", + texStr.c_str(), fmtTbl[fmt].c_str(), sizTbl[sizB].c_str(), width2, height2, pal, + cms, cmt, masks, maskt, shifts, shiftt); } else { @@ -641,8 +675,10 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out return -1; } - output += StringHelper::Sprintf("gsDPLoadMultiBlock(%s, %i, %i, %s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", - texStr.c_str(), tmem, rtile, fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), width, height, pal, cms, cmt, masks, maskt, shifts, shiftt); + output += StringHelper::Sprintf( + "gsDPLoadMultiBlock(%s, %i, %i, %s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i),", + texStr.c_str(), tmem, rtile, fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), width, + height, pal, cms, cmt, masks, maskt, shifts, shiftt); } lastTexAddr = texAddr; @@ -689,10 +725,12 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, int i, std::string prefix, char* l sprintf(line, "gsSPDisplayList(%sDlist0x%06lX),", prefix.c_str(), GETSEGOFFSET(data)); } - // TODO: This is the same as `segNum`. Consider resuing that variable instead of making a new one. + // TODO: This is the same as `segNum`. Consider resuing that variable instead of making a new + // one. int segmentNumber = GETSEGNUM(data); - if (segmentNumber == 8 || segmentNumber == 9 || segmentNumber == 10 || segmentNumber == 11 || segmentNumber == 12 || segmentNumber == 13) // Used for runtime-generated display lists + if (segmentNumber == 8 || segmentNumber == 9 || segmentNumber == 10 || segmentNumber == 11 || + segmentNumber == 12 || segmentNumber == 13) // Used for runtime-generated display lists { if (pp != 0) sprintf(line, "gsSPBranchList(0x%08lX),", data & 0xFFFFFFFF); @@ -701,7 +739,8 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, int i, std::string prefix, char* l } else { - ZDisplayList* nList = new ZDisplayList(fileData, data & 0x00FFFFFF, GetDListLength(fileData, data & 0x00FFFFFF, dListType)); + ZDisplayList* nList = new ZDisplayList( + fileData, data & 0x00FFFFFF, GetDListLength(fileData, data & 0x00FFFFFF, dListType)); nList->scene = scene; nList->parent = parent; otherDLists.push_back(nList); @@ -778,17 +817,16 @@ void ZDisplayList::Opcode_G_MTX(uint64_t data, int i, std::string prefix, char* if (pp & 0x01) push = true; - + if (pp & 0x02) load = true; - + if (pp & 0x04) projection = true; sprintf(line, "gsSPMatrix(%s, %s | %s | %s),", matrixRef.c_str(), - projection ? "G_MTX_PROJECTION" : "G_MTX_MODELVIEW", - push ? "G_MTX_PUSH" : "G_MTX_NOPUSH", - load ? "G_MTX_LOAD" : "G_MTX_MUL"); + projection ? "G_MTX_PROJECTION" : "G_MTX_MODELVIEW", + push ? "G_MTX_PUSH" : "G_MTX_NOPUSH", load ? "G_MTX_LOAD" : "G_MTX_MUL"); } void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* line) @@ -804,8 +842,7 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* { uint32_t hi = data >> 32; -#define _SHIFTR( v, s, w ) \ - (((uint32_t)v >> s) & ((0x01 << w) - 1)) +#define _SHIFTR(v, s, w) (((uint32_t)v >> s) & ((0x01 << w) - 1)) nn = _SHIFTR(hi, 10, 6); @@ -813,10 +850,12 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* } // Hack: Don't extract vertices from a unknown segment. - if (!Globals::Instance->HasSegment(GETSEGNUM(data))) { + if (!Globals::Instance->HasSegment(GETSEGNUM(data))) + { segptr_t segmented = data & 0xFFFFFFFF; references.push_back(segmented); - parent->AddDeclaration(segmented, DeclarationAlignment::Align16, 16, "Vtx", StringHelper::Sprintf("0x%08X", segmented), ""); + parent->AddDeclaration(segmented, DeclarationAlignment::Align16, 16, "Vtx", + StringHelper::Sprintf("0x%08X", segmented), ""); return; } references.push_back(vtxAddr); @@ -828,7 +867,7 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* // TODO: These two could probably be condenced to one... if (parent->GetDeclarationRanged(vtxAddr + (nn * 16)) != nullptr) { - Declaration* decl = parent->GetDeclarationRanged(vtxAddr + (nn * 16)); + // Declaration* decl = parent->GetDeclarationRanged(vtxAddr + (nn * 16)); uint32_t addr = parent->GetDeclarationRangedAddress(vtxAddr + (nn * 16)); int diff = addr - vtxAddr; if (diff > 0) @@ -839,7 +878,7 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* if (parent->GetDeclarationRanged(vtxAddr) != nullptr) { - Declaration* decl = parent->GetDeclarationRanged(vtxAddr); + // Declaration* decl = parent->GetDeclarationRanged(vtxAddr); uint32_t addr = parent->GetDeclarationRangedAddress(vtxAddr); int diff = addr - vtxAddr; if (diff > 0) @@ -880,15 +919,16 @@ void ZDisplayList::Opcode_G_TEXTURE(uint64_t data, int i, std::string prefix, ch else nnnnnnn = (____ & 0xFE) >> 1; - sprintf(line, "gsSPTexture(%i, %i, %i, %i, %s),", ssss, tttt, lll, ddd, nnnnnnn == 1 ? "G_ON" : "G_OFF"); + sprintf(line, "gsSPTexture(%i, %i, %i, %i, %s),", ssss, tttt, lll, ddd, + nnnnnnn == 1 ? "G_ON" : "G_OFF"); } void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, int i, std::string prefix, char* line) { int __ = (data & 0x00FF000000000000) >> 48; int www = (data & 0x00000FFF00000000) >> 32; - string fmtTbl[] = { "G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", "G_IM_FMT_I" }; - string sizTbl[] = { "G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b" }; + string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", "G_IM_FMT_I"}; + string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"}; uint32_t fmt = (__ & 0xE0) >> 5; uint32_t siz = (__ & 0x18) >> 3; @@ -896,7 +936,7 @@ void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, int i, std::string prefix, ch if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) printf("TextureGenCheck G_SETTIMG\n"); - TextureGenCheck(prefix); // HOTSPOT + TextureGenCheck(prefix); // HOTSPOT lastTexFmt = (F3DZEXTexFormats)fmt; lastTexSiz = (F3DZEXTexSizes)siz; @@ -926,24 +966,27 @@ void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, int i, std::string prefix, ch else { // TEST: CHECK OTHER FILES FOR REF - //if (segmentNumber == 4) + // if (segmentNumber == 4) //{ - //Globals::Instance->FindSymbolSegRef(segmentNumber, texAddress); + // Globals::Instance->FindSymbolSegRef(segmentNumber, texAddress); //} - //else + // else { sprintf(texStr, "0x%08lX", data & 0xFFFFFFFF); } } - sprintf(line, "gsDPSetTextureImage(%s, %s, %i, %s),", fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), www + 1, texStr); - //sprintf(line, "gsDPSetTextureImage(%s, %s, %i, @r),", fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), www + 1); - //references.push_back(data & 0x00FFFFFF); + sprintf(line, "gsDPSetTextureImage(%s, %s, %i, %s),", fmtTbl[fmt].c_str(), + sizTbl[siz].c_str(), www + 1, texStr); + // sprintf(line, "gsDPSetTextureImage(%s, %s, %i, @r),", fmtTbl[fmt].c_str(), + // sizTbl[siz].c_str(), www + 1); references.push_back(data & 0x00FFFFFF); } else { - //sprintf(line, "gsDPSetTextureImage(%s, %s, %i, 0x%08X),", fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), www + 1, data & 0xFFFFFFFF); - sprintf(line, "gsDPSetTextureImage(%s, %s, %i, %sTex_%06lX),", fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), www + 1, scene->GetName().c_str(), GETSEGOFFSET(data)); + // sprintf(line, "gsDPSetTextureImage(%s, %s, %i, 0x%08X),", fmtTbl[fmt].c_str(), + // sizTbl[siz].c_str(), www + 1, data & 0xFFFFFFFF); + sprintf(line, "gsDPSetTextureImage(%s, %s, %i, %sTex_%06lX),", fmtTbl[fmt].c_str(), + sizTbl[siz].c_str(), www + 1, scene->GetName().c_str(), GETSEGOFFSET(data)); } } @@ -951,8 +994,10 @@ void ZDisplayList::Opcode_G_SETTILE(uint64_t data, int i, std::string prefix, ch { int fff = (data & 0b0000000011100000000000000000000000000000000000000000000000000000) >> 53; int ii = (data & 0b0000000000011000000000000000000000000000000000000000000000000000) >> 51; - int nnnnnnnnn = (data & 0b0000000000000011111111100000000000000000000000000000000000000000) >> 41; - int mmmmmmmmm = (data & 0b0000000000000000000000011111111100000000000000000000000000000000) >> 32; + int nnnnnnnnn = + (data & 0b0000000000000011111111100000000000000000000000000000000000000000) >> 41; + int mmmmmmmmm = + (data & 0b0000000000000000000000011111111100000000000000000000000000000000) >> 32; int ttt = (data & 0b0000000000000000000000000000000000000111000000000000000000000000) >> 24; int pppp = (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >> 20; int cc = (data & 0b0000000000000000000000000000000000000000000011000000000000000000) >> 18; @@ -962,15 +1007,17 @@ void ZDisplayList::Opcode_G_SETTILE(uint64_t data, int i, std::string prefix, ch int bbbb = (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; int uuuu = (data & 0b0000000000000000000000000000000000000000000000000000000000001111); - string fmtTbl[] = { "G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", "G_IM_FMT_I" }; - string sizTbl[] = { "G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b" }; + string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", "G_IM_FMT_I"}; + string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"}; if (fff == (int)F3DZEXTexFormats::G_IM_FMT_CI) lastCISiz = (F3DZEXTexSizes)ii; lastTexSizTest = (F3DZEXTexSizes)ii; - sprintf(line, "gsDPSetTile(%s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),", fmtTbl[fff].c_str(), sizTbl[ii].c_str(), nnnnnnnnn, mmmmmmmmm, ttt, pppp, cc, aaaa, ssss, dd, bbbb, uuuu); + sprintf(line, "gsDPSetTile(%s, %s, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),", + fmtTbl[fff].c_str(), sizTbl[ii].c_str(), nnnnnnnnn, mmmmmmmmm, ttt, pppp, cc, aaaa, + ssss, dd, bbbb, uuuu); } void ZDisplayList::Opcode_G_SETTILESIZE(uint64_t data, int index, std::string prefix, char* line) @@ -984,22 +1031,25 @@ void ZDisplayList::Opcode_G_SETTILESIZE(uint64_t data, int index, std::string pr int shiftAmtW = 2; int shiftAmtH = 2; - if (lastTexSizTest == F3DZEXTexSizes::G_IM_SIZ_8b && lastTexFmt == F3DZEXTexFormats::G_IM_FMT_IA) + if (lastTexSizTest == F3DZEXTexSizes::G_IM_SIZ_8b && + lastTexFmt == F3DZEXTexFormats::G_IM_FMT_IA) shiftAmtW = 3; - //if (lastTexFmt == F3DZEXTexFormats::G_IM_FMT_I || lastTexFmt == F3DZEXTexFormats::G_IM_FMT_CI) + // if (lastTexFmt == F3DZEXTexFormats::G_IM_FMT_I || lastTexFmt == + // F3DZEXTexFormats::G_IM_FMT_CI) if (lastTexSizTest == F3DZEXTexSizes::G_IM_SIZ_4b) shiftAmtW = 3; - if (lastTexSizTest == F3DZEXTexSizes::G_IM_SIZ_4b && lastTexFmt == F3DZEXTexFormats::G_IM_FMT_IA) + if (lastTexSizTest == F3DZEXTexSizes::G_IM_SIZ_4b && + lastTexFmt == F3DZEXTexFormats::G_IM_FMT_IA) shiftAmtH = 3; - lastTexWidth = (uuu >> shiftAmtW) + 1; lastTexHeight = (vvv >> shiftAmtH) + 1; if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) - printf("lastTexWidth: %i lastTexHeight: %i, lastTexSizTest: 0x%x, lastTexFmt: 0x%x\n", lastTexWidth, lastTexHeight, (uint32_t)lastTexSizTest, (uint32_t)lastTexFmt); + printf("lastTexWidth: %i lastTexHeight: %i, lastTexSizTest: 0x%x, lastTexFmt: 0x%x\n", + lastTexWidth, lastTexHeight, (uint32_t)lastTexSizTest, (uint32_t)lastTexFmt); if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) printf("TextureGenCheck G_SETTILESIZE\n"); @@ -1017,11 +1067,11 @@ void ZDisplayList::Opcode_G_LOADBLOCK(uint64_t data, int index, std::string pref int xxx = (data & 0x0000000000FFF000) >> 12; int ddd = (data & 0x0000000000000FFF); - //lastTexHeight = (ddd + 1) / 16; + // lastTexHeight = (ddd + 1) / 16; lastTexLoaded = true; - //TextureGenCheck(prefix); + // TextureGenCheck(prefix); sprintf(line, "gsDPLoadBlock(%i, %i, %i, %i, %i),", i, sss, ttt, xxx, ddd); } @@ -1045,24 +1095,59 @@ void ZDisplayList::Opcode_G_SETCOMBINE(uint64_t data, int i, std::string prefix, int ab1 = (data & 0b00000000000000000000000000000000000000000000000000000000111000) >> 3; int ad1 = (data & 0b00000000000000000000000000000000000000000000000000000000000111) >> 0; - string modesA[] = { "COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT", "1", "NOISE", - "0", "9", "10", "11", "12", "13", "14", "0"}; - string modesB[] = { "COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT", "CENTER", "K4", - "8", "9", "10", "11", "12", "13", "14", "0"}; - string modesC[] = { "COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT", "1", "COMBINED_ALPHA", - "TEXEL0_ALPHA", "TEXEL1_ALPHA", "PRIMITIVE_ALPHA", "SHADE_ALPHA", "ENV_ALPHA", "LOD_FRACTION", "PRIM_LOD_FRAC", "K5", - "16", "17", "18", "19", "20", "21", "22", "23", - "24", "25", "26", "27", "28", "29", "30", "0" }; - string modesD[] = { "COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT", "1", "0"}; + string modesA[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT", + "1", "NOISE", "0", "9", "10", "11", + "12", "13", "14", "0"}; + string modesB[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT", + "CENTER", "K4", "8", "9", "10", "11", + "12", "13", "14", "0"}; + string modesC[] = {"COMBINED", + "TEXEL0", + "TEXEL1", + "PRIMITIVE", + "SHADE", + "ENVIRONMENT", + "1", + "COMBINED_ALPHA", + "TEXEL0_ALPHA", + "TEXEL1_ALPHA", + "PRIMITIVE_ALPHA", + "SHADE_ALPHA", + "ENV_ALPHA", + "LOD_FRACTION", + "PRIM_LOD_FRAC", + "K5", + "16", + "17", + "18", + "19", + "20", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + "29", + "30", + "0"}; + string modesD[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", + "SHADE", "ENVIRONMENT", "1", "0"}; - string modes2[] = { "COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT", "1", "0" }; - string modes2C[] = { "LOD_FRACTION", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT", "PRIM_LOD_FRAC", "0" }; + string modes2[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", + "SHADE", "ENVIRONMENT", "1", "0"}; + string modes2C[] = {"LOD_FRACTION", "TEXEL0", "TEXEL1", "PRIMITIVE", + "SHADE", "ENVIRONMENT", "PRIM_LOD_FRAC", "0"}; - sprintf(line, "gsDPSetCombineLERP(%s, %s, %s, %s, %s, %s, %s, %s,\n %s, %s, %s, %s, %s, %s, %s, %s),", - modesA[a0].c_str(), modesB[b0].c_str(), modesC[c0].c_str(), modesD[d0].c_str(), - modes2[aa0].c_str(), modes2[ab0].c_str(), modes2C[ac0].c_str(), modes2[ad0].c_str(), - modesA[a1].c_str(), modesB[b1].c_str(), modesC[c1].c_str(), modesD[d1].c_str(), - modes2[aa1].c_str(), modes2[ab1].c_str(), modes2C[ac1].c_str(), modes2[ad1].c_str()); + sprintf(line, + "gsDPSetCombineLERP(%s, %s, %s, %s, %s, %s, %s, %s,\n %s, %s, " + "%s, %s, %s, %s, %s, %s),", + modesA[a0].c_str(), modesB[b0].c_str(), modesC[c0].c_str(), modesD[d0].c_str(), + modes2[aa0].c_str(), modes2[ab0].c_str(), modes2C[ac0].c_str(), modes2[ad0].c_str(), + modesA[a1].c_str(), modesB[b1].c_str(), modesC[c1].c_str(), modesD[d1].c_str(), + modes2[aa1].c_str(), modes2[ab1].c_str(), modes2C[ac1].c_str(), modes2[ad1].c_str()); } void ZDisplayList::Opcode_G_SETPRIMCOLOR(uint64_t data, int i, std::string prefix, char* line) @@ -1076,7 +1161,8 @@ void ZDisplayList::Opcode_G_SETPRIMCOLOR(uint64_t data, int i, std::string prefi sprintf(line, "gsDPSetPrimColor(%i, %i, %i, %i, %i, %i),", mm, ff, rr, gg, bb, aa); } -void ZDisplayList::Opcode_F3DEX_G_SETOTHERMODE_L(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_F3DEX_G_SETOTHERMODE_L(uint64_t data, int i, std::string prefix, + char* line) { int sft = (data & 0x0000FF0000000000) >> 40; int len = (data & 0x000000FF00000000) >> 32; @@ -1102,154 +1188,210 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string pre { int ss = (data & 0x0000FF0000000000) >> 40; len = ((data & 0x000000FF00000000) >> 32) + 1; - sft = 32 - (len) - ss; + sft = 32 - (len)-ss; } if (sft == G_MDSFT_RENDERMODE) { - int mode1 = (dd & 0xCCCC0000) >> 0; - int mode2 = (dd & 0x3333FFFF); + uint32_t mode1 = (dd & 0xCCCC0000) >> 0; + uint32_t mode2 = (dd & 0x3333FFFF); // TODO: Jesus Christ This is Messy - uint32_t tblA[] = - { - G_RM_FOG_SHADE_A, G_RM_FOG_PRIM_A, G_RM_PASS, G_RM_AA_ZB_OPA_SURF, - G_RM_AA_ZB_XLU_SURF, G_RM_AA_ZB_OPA_DECAL, G_RM_AA_ZB_XLU_DECAL, - G_RM_AA_ZB_OPA_INTER, G_RM_AA_ZB_XLU_INTER, G_RM_AA_ZB_XLU_LINE, - G_RM_AA_ZB_DEC_LINE, G_RM_AA_ZB_TEX_EDGE, G_RM_AA_ZB_TEX_INTER, - G_RM_AA_ZB_SUB_SURF, G_RM_AA_ZB_PCL_SURF, G_RM_AA_ZB_OPA_TERR, - G_RM_AA_ZB_TEX_TERR, G_RM_AA_ZB_SUB_TERR, G_RM_RA_ZB_OPA_SURF, - G_RM_RA_ZB_OPA_DECAL, G_RM_RA_ZB_OPA_INTER, G_RM_AA_OPA_SURF, - G_RM_AA_XLU_SURF, G_RM_AA_XLU_LINE, G_RM_AA_DEC_LINE, - G_RM_AA_TEX_EDGE, G_RM_AA_SUB_SURF, G_RM_AA_PCL_SURF, - G_RM_AA_OPA_TERR, G_RM_AA_TEX_TERR, G_RM_AA_SUB_TERR, - G_RM_RA_OPA_SURF, G_RM_ZB_OPA_SURF, G_RM_ZB_XLU_SURF, - G_RM_ZB_OPA_DECAL, G_RM_ZB_XLU_DECAL, G_RM_ZB_CLD_SURF, - G_RM_ZB_OVL_SURF, G_RM_ZB_PCL_SURF, G_RM_OPA_SURF, - G_RM_XLU_SURF, G_RM_CLD_SURF, G_RM_TEX_EDGE, G_RM_PCL_SURF, - G_RM_ADD, G_RM_NOOP, G_RM_VISCVG, G_RM_OPA_CI + uint32_t tblA[] = {G_RM_FOG_SHADE_A, + G_RM_FOG_PRIM_A, + G_RM_PASS, + G_RM_AA_ZB_OPA_SURF, + G_RM_AA_ZB_XLU_SURF, + G_RM_AA_ZB_OPA_DECAL, + G_RM_AA_ZB_XLU_DECAL, + G_RM_AA_ZB_OPA_INTER, + G_RM_AA_ZB_XLU_INTER, + G_RM_AA_ZB_XLU_LINE, + G_RM_AA_ZB_DEC_LINE, + G_RM_AA_ZB_TEX_EDGE, + G_RM_AA_ZB_TEX_INTER, + G_RM_AA_ZB_SUB_SURF, + G_RM_AA_ZB_PCL_SURF, + G_RM_AA_ZB_OPA_TERR, + G_RM_AA_ZB_TEX_TERR, + G_RM_AA_ZB_SUB_TERR, + G_RM_RA_ZB_OPA_SURF, + G_RM_RA_ZB_OPA_DECAL, + G_RM_RA_ZB_OPA_INTER, + G_RM_AA_OPA_SURF, + G_RM_AA_XLU_SURF, + G_RM_AA_XLU_LINE, + G_RM_AA_DEC_LINE, + G_RM_AA_TEX_EDGE, + G_RM_AA_SUB_SURF, + G_RM_AA_PCL_SURF, + G_RM_AA_OPA_TERR, + G_RM_AA_TEX_TERR, + G_RM_AA_SUB_TERR, + G_RM_RA_OPA_SURF, + G_RM_ZB_OPA_SURF, + G_RM_ZB_XLU_SURF, + G_RM_ZB_OPA_DECAL, + G_RM_ZB_XLU_DECAL, + G_RM_ZB_CLD_SURF, + G_RM_ZB_OVL_SURF, + G_RM_ZB_PCL_SURF, + G_RM_OPA_SURF, + G_RM_XLU_SURF, + G_RM_CLD_SURF, + G_RM_TEX_EDGE, + G_RM_PCL_SURF, + G_RM_ADD, + G_RM_NOOP, + G_RM_VISCVG, + G_RM_OPA_CI}; + + uint32_t tblB[] = {G_RM_AA_ZB_OPA_SURF2, + G_RM_AA_ZB_XLU_SURF2, + G_RM_AA_ZB_OPA_DECAL2, + G_RM_AA_ZB_XLU_DECAL2, + G_RM_AA_ZB_OPA_INTER2, + G_RM_AA_ZB_XLU_INTER2, + G_RM_AA_ZB_XLU_LINE2, + G_RM_AA_ZB_DEC_LINE2, + G_RM_AA_ZB_TEX_EDGE2, + G_RM_AA_ZB_TEX_INTER2, + G_RM_AA_ZB_SUB_SURF2, + G_RM_AA_ZB_PCL_SURF2, + G_RM_AA_ZB_OPA_TERR2, + G_RM_AA_ZB_TEX_TERR2, + G_RM_AA_ZB_SUB_TERR2, + G_RM_RA_ZB_OPA_SURF2, + G_RM_RA_ZB_OPA_DECAL2, + G_RM_RA_ZB_OPA_INTER2, + G_RM_AA_OPA_SURF2, + G_RM_AA_XLU_SURF2, + G_RM_AA_XLU_LINE2, + G_RM_AA_DEC_LINE2, + G_RM_AA_TEX_EDGE2, + G_RM_AA_SUB_SURF2, + G_RM_AA_PCL_SURF2, + G_RM_AA_OPA_TERR2, + G_RM_AA_TEX_TERR2, + G_RM_AA_SUB_TERR2, + G_RM_RA_OPA_SURF2, + G_RM_ZB_OPA_SURF2, + G_RM_ZB_XLU_SURF2, + G_RM_ZB_OPA_DECAL2, + G_RM_ZB_XLU_DECAL2, + G_RM_ZB_CLD_SURF2, + G_RM_ZB_OVL_SURF2, + G_RM_ZB_PCL_SURF2, + G_RM_OPA_SURF2, + G_RM_XLU_SURF2, + G_RM_CLD_SURF2, + G_RM_TEX_EDGE2, + G_RM_PCL_SURF2, + G_RM_ADD2, + G_RM_NOOP2, + G_RM_VISCVG2, + G_RM_OPA_CI2}; + + map str = { + {G_RM_FOG_SHADE_A, "G_RM_FOG_SHADE_A"}, + {G_RM_FOG_PRIM_A, "G_RM_FOG_PRIM_A"}, + {G_RM_PASS, "G_RM_PASS"}, + {G_RM_AA_ZB_OPA_SURF, "G_RM_AA_ZB_OPA_SURF"}, + {G_RM_AA_ZB_OPA_SURF2, "G_RM_AA_ZB_OPA_SURF2"}, + {G_RM_AA_ZB_XLU_SURF, "G_RM_AA_ZB_XLU_SURF"}, + {G_RM_AA_ZB_XLU_SURF2, "G_RM_AA_ZB_XLU_SURF2"}, + {G_RM_AA_ZB_OPA_DECAL, "G_RM_AA_ZB_OPA_DECAL"}, + {G_RM_AA_ZB_OPA_DECAL2, "G_RM_AA_ZB_OPA_DECAL2"}, + {G_RM_AA_ZB_XLU_DECAL, "G_RM_AA_ZB_XLU_DECAL"}, + {G_RM_AA_ZB_XLU_DECAL2, "G_RM_AA_ZB_XLU_DECAL2"}, + {G_RM_AA_ZB_OPA_INTER, "G_RM_AA_ZB_OPA_INTER"}, + {G_RM_AA_ZB_OPA_INTER2, "G_RM_AA_ZB_OPA_INTER2"}, + {G_RM_AA_ZB_XLU_INTER, "G_RM_AA_ZB_XLU_INTER"}, + {G_RM_AA_ZB_XLU_INTER2, "G_RM_AA_ZB_XLU_INTER2"}, + {G_RM_AA_ZB_XLU_LINE, "G_RM_AA_ZB_XLU_LINE"}, + {G_RM_AA_ZB_XLU_LINE2, "G_RM_AA_ZB_XLU_LINE2"}, + {G_RM_AA_ZB_DEC_LINE, "G_RM_AA_ZB_DEC_LINE"}, + {G_RM_AA_ZB_DEC_LINE2, "G_RM_AA_ZB_DEC_LINE2"}, + {G_RM_AA_ZB_TEX_EDGE, "G_RM_AA_ZB_TEX_EDGE"}, + {G_RM_AA_ZB_TEX_EDGE2, "G_RM_AA_ZB_TEX_EDGE2"}, + {G_RM_AA_ZB_TEX_INTER, "G_RM_AA_ZB_TEX_INTER"}, + {G_RM_AA_ZB_TEX_INTER2, "G_RM_AA_ZB_TEX_INTER2"}, + {G_RM_AA_ZB_SUB_SURF, "G_RM_AA_ZB_SUB_SURF"}, + {G_RM_AA_ZB_SUB_SURF2, "G_RM_AA_ZB_SUB_SURF2"}, + {G_RM_AA_ZB_PCL_SURF, "G_RM_AA_ZB_PCL_SURF"}, + {G_RM_AA_ZB_PCL_SURF2, "G_RM_AA_ZB_PCL_SURF2"}, + {G_RM_AA_ZB_OPA_TERR, "G_RM_AA_ZB_OPA_TERR"}, + {G_RM_AA_ZB_OPA_TERR2, "G_RM_AA_ZB_OPA_TERR2"}, + {G_RM_AA_ZB_TEX_TERR, "G_RM_AA_ZB_TEX_TERR"}, + {G_RM_AA_ZB_TEX_TERR2, "G_RM_AA_ZB_TEX_TERR2"}, + {G_RM_AA_ZB_SUB_TERR, "G_RM_AA_ZB_SUB_TERR"}, + {G_RM_AA_ZB_SUB_TERR2, "G_RM_AA_ZB_SUB_TERR2"}, + {G_RM_RA_ZB_OPA_SURF, "G_RM_RA_ZB_OPA_SURF"}, + {G_RM_RA_ZB_OPA_SURF2, "G_RM_RA_ZB_OPA_SURF2"}, + {G_RM_RA_ZB_OPA_DECAL, "G_RM_RA_ZB_OPA_DECAL"}, + {G_RM_RA_ZB_OPA_DECAL2, "G_RM_RA_ZB_OPA_DECAL2"}, + {G_RM_RA_ZB_OPA_INTER, "G_RM_RA_ZB_OPA_INTER"}, + {G_RM_RA_ZB_OPA_INTER2, "G_RM_RA_ZB_OPA_INTER2"}, + {G_RM_AA_OPA_SURF, "G_RM_AA_OPA_SURF"}, + {G_RM_AA_OPA_SURF2, "G_RM_AA_OPA_SURF2"}, + {G_RM_AA_XLU_SURF, "G_RM_AA_XLU_SURF"}, + {G_RM_AA_XLU_SURF2, "G_RM_AA_XLU_SURF2"}, + {G_RM_AA_XLU_LINE, "G_RM_AA_XLU_LINE"}, + {G_RM_AA_XLU_LINE2, "G_RM_AA_XLU_LINE2"}, + {G_RM_AA_DEC_LINE, "G_RM_AA_DEC_LINE"}, + {G_RM_AA_DEC_LINE2, "G_RM_AA_DEC_LINE2"}, + {G_RM_AA_TEX_EDGE, "G_RM_AA_TEX_EDGE"}, + {G_RM_AA_TEX_EDGE2, "G_RM_AA_TEX_EDGE2"}, + {G_RM_AA_SUB_SURF, "G_RM_AA_SUB_SURF"}, + {G_RM_AA_SUB_SURF2, "G_RM_AA_SUB_SURF2"}, + {G_RM_AA_PCL_SURF, "G_RM_AA_PCL_SURF"}, + {G_RM_AA_PCL_SURF2, "G_RM_AA_PCL_SURF2"}, + {G_RM_AA_OPA_TERR, "G_RM_AA_OPA_TERR"}, + {G_RM_AA_OPA_TERR2, "G_RM_AA_OPA_TERR2"}, + {G_RM_AA_TEX_TERR, "G_RM_AA_TEX_TERR"}, + {G_RM_AA_TEX_TERR2, "G_RM_AA_TEX_TERR2"}, + {G_RM_AA_TEX_TERR, "G_RM_AA_TEX_TERR"}, + {G_RM_AA_TEX_TERR2, "G_RM_AA_TEX_TERR2"}, + {G_RM_AA_SUB_TERR, "G_RM_AA_SUB_TERR"}, + {G_RM_AA_SUB_TERR2, "G_RM_AA_SUB_TERR2"}, + {G_RM_RA_OPA_SURF, "G_RM_RA_OPA_SURF"}, + {G_RM_RA_OPA_SURF2, "G_RM_RA_OPA_SURF2"}, + {G_RM_ZB_OPA_SURF, "G_RM_ZB_OPA_SURF"}, + {G_RM_ZB_OPA_SURF2, "G_RM_ZB_OPA_SURF2"}, + {G_RM_ZB_XLU_SURF, "G_RM_ZB_XLU_SURF"}, + {G_RM_ZB_XLU_SURF2, "G_RM_ZB_XLU_SURF2"}, + {G_RM_ZB_OPA_DECAL, "G_RM_ZB_OPA_DECAL"}, + {G_RM_ZB_OPA_DECAL2, "G_RM_ZB_OPA_DECAL2"}, + {G_RM_ZB_XLU_DECAL, "G_RM_ZB_XLU_DECAL"}, + {G_RM_ZB_XLU_DECAL2, "G_RM_ZB_XLU_DECAL2"}, + {G_RM_ZB_CLD_SURF, "G_RM_ZB_CLD_SURF"}, + {G_RM_ZB_CLD_SURF2, "G_RM_ZB_CLD_SURF2"}, + {G_RM_ZB_OVL_SURF, "G_RM_ZB_OVL_SURF"}, + {G_RM_ZB_OVL_SURF2, "G_RM_ZB_OVL_SURF2"}, + {G_RM_ZB_PCL_SURF, "G_RM_ZB_PCL_SURF"}, + {G_RM_ZB_PCL_SURF2, "G_RM_ZB_PCL_SURF2"}, + {G_RM_OPA_SURF, "G_RM_OPA_SURF"}, + {G_RM_OPA_SURF2, "G_RM_OPA_SURF2"}, + {G_RM_XLU_SURF, "G_RM_XLU_SURF"}, + {G_RM_XLU_SURF2, "G_RM_XLU_SURF2"}, + {G_RM_CLD_SURF, "G_RM_CLD_SURF"}, + {G_RM_CLD_SURF2, "G_RM_CLD_SURF2"}, + {G_RM_TEX_EDGE, "G_RM_TEX_EDGE"}, + {G_RM_TEX_EDGE2, "G_RM_TEX_EDGE2"}, + {G_RM_PCL_SURF, "G_RM_PCL_SURF"}, + {G_RM_PCL_SURF2, "G_RM_PCL_SURF2"}, + {G_RM_ADD, "G_RM_ADD"}, + {G_RM_ADD2, "G_RM_ADD2"}, + {G_RM_NOOP, "G_RM_NOOP"}, + {G_RM_NOOP2, "G_RM_NOOP2"}, + {G_RM_VISCVG, "G_RM_VISCVG"}, + {G_RM_VISCVG2, "G_RM_VISCVG2"}, + {G_RM_OPA_CI, "G_RM_OPA_CI"}, + {G_RM_OPA_CI2, "G_RM_OPA_CI2"}, }; - uint32_t tblB[] = - { - G_RM_AA_ZB_OPA_SURF2, - G_RM_AA_ZB_XLU_SURF2, G_RM_AA_ZB_OPA_DECAL2, G_RM_AA_ZB_XLU_DECAL2, - G_RM_AA_ZB_OPA_INTER2, G_RM_AA_ZB_XLU_INTER2, G_RM_AA_ZB_XLU_LINE2, - G_RM_AA_ZB_DEC_LINE2, G_RM_AA_ZB_TEX_EDGE2, G_RM_AA_ZB_TEX_INTER2, - G_RM_AA_ZB_SUB_SURF2, G_RM_AA_ZB_PCL_SURF2, G_RM_AA_ZB_OPA_TERR2, - G_RM_AA_ZB_TEX_TERR2, G_RM_AA_ZB_SUB_TERR2, G_RM_RA_ZB_OPA_SURF2, - G_RM_RA_ZB_OPA_DECAL2, G_RM_RA_ZB_OPA_INTER2, G_RM_AA_OPA_SURF2, - G_RM_AA_XLU_SURF2, G_RM_AA_XLU_LINE2, G_RM_AA_DEC_LINE2, - G_RM_AA_TEX_EDGE2, G_RM_AA_SUB_SURF2, G_RM_AA_PCL_SURF2, - G_RM_AA_OPA_TERR2, G_RM_AA_TEX_TERR2, G_RM_AA_SUB_TERR2, - G_RM_RA_OPA_SURF2, G_RM_ZB_OPA_SURF2, G_RM_ZB_XLU_SURF2, - G_RM_ZB_OPA_DECAL2, G_RM_ZB_XLU_DECAL2, G_RM_ZB_CLD_SURF2, - G_RM_ZB_OVL_SURF2, G_RM_ZB_PCL_SURF2, G_RM_OPA_SURF2, - G_RM_XLU_SURF2, G_RM_CLD_SURF2, G_RM_TEX_EDGE2, G_RM_PCL_SURF2, - G_RM_ADD2, G_RM_NOOP2,G_RM_VISCVG2, G_RM_OPA_CI2 - }; - - map str = - { - { G_RM_FOG_SHADE_A, "G_RM_FOG_SHADE_A" }, - { G_RM_FOG_PRIM_A, "G_RM_FOG_PRIM_A" }, - { G_RM_PASS, "G_RM_PASS" }, - { G_RM_AA_ZB_OPA_SURF, "G_RM_AA_ZB_OPA_SURF" }, - { G_RM_AA_ZB_OPA_SURF2, "G_RM_AA_ZB_OPA_SURF2" }, - { G_RM_AA_ZB_XLU_SURF, "G_RM_AA_ZB_XLU_SURF" }, - { G_RM_AA_ZB_XLU_SURF2, "G_RM_AA_ZB_XLU_SURF2" }, - { G_RM_AA_ZB_OPA_DECAL, "G_RM_AA_ZB_OPA_DECAL" }, - { G_RM_AA_ZB_OPA_DECAL2, "G_RM_AA_ZB_OPA_DECAL2" }, - { G_RM_AA_ZB_XLU_DECAL, "G_RM_AA_ZB_XLU_DECAL" }, - { G_RM_AA_ZB_XLU_DECAL2, "G_RM_AA_ZB_XLU_DECAL2" }, - { G_RM_AA_ZB_OPA_INTER, "G_RM_AA_ZB_OPA_INTER" }, - { G_RM_AA_ZB_OPA_INTER2, "G_RM_AA_ZB_OPA_INTER2" }, - { G_RM_AA_ZB_XLU_INTER, "G_RM_AA_ZB_XLU_INTER" }, - { G_RM_AA_ZB_XLU_INTER2, "G_RM_AA_ZB_XLU_INTER2" }, - { G_RM_AA_ZB_XLU_LINE, "G_RM_AA_ZB_XLU_LINE" }, - { G_RM_AA_ZB_XLU_LINE2, "G_RM_AA_ZB_XLU_LINE2" }, - { G_RM_AA_ZB_DEC_LINE, "G_RM_AA_ZB_DEC_LINE" }, - { G_RM_AA_ZB_DEC_LINE2, "G_RM_AA_ZB_DEC_LINE2" }, - { G_RM_AA_ZB_TEX_EDGE, "G_RM_AA_ZB_TEX_EDGE" }, - { G_RM_AA_ZB_TEX_EDGE2, "G_RM_AA_ZB_TEX_EDGE2" }, - { G_RM_AA_ZB_TEX_INTER, "G_RM_AA_ZB_TEX_INTER" }, - { G_RM_AA_ZB_TEX_INTER2, "G_RM_AA_ZB_TEX_INTER2" }, - { G_RM_AA_ZB_SUB_SURF, "G_RM_AA_ZB_SUB_SURF" }, - { G_RM_AA_ZB_SUB_SURF2, "G_RM_AA_ZB_SUB_SURF2" }, - { G_RM_AA_ZB_PCL_SURF, "G_RM_AA_ZB_PCL_SURF" }, - { G_RM_AA_ZB_PCL_SURF2, "G_RM_AA_ZB_PCL_SURF2" }, - { G_RM_AA_ZB_OPA_TERR, "G_RM_AA_ZB_OPA_TERR" }, - { G_RM_AA_ZB_OPA_TERR2, "G_RM_AA_ZB_OPA_TERR2" }, - { G_RM_AA_ZB_TEX_TERR, "G_RM_AA_ZB_TEX_TERR" }, - { G_RM_AA_ZB_TEX_TERR2, "G_RM_AA_ZB_TEX_TERR2" }, - { G_RM_AA_ZB_SUB_TERR, "G_RM_AA_ZB_SUB_TERR" }, - { G_RM_AA_ZB_SUB_TERR2, "G_RM_AA_ZB_SUB_TERR2" }, - { G_RM_RA_ZB_OPA_SURF, "G_RM_RA_ZB_OPA_SURF" }, - { G_RM_RA_ZB_OPA_SURF2, "G_RM_RA_ZB_OPA_SURF2" }, - { G_RM_RA_ZB_OPA_DECAL, "G_RM_RA_ZB_OPA_DECAL" }, - { G_RM_RA_ZB_OPA_DECAL2, "G_RM_RA_ZB_OPA_DECAL2" }, - { G_RM_RA_ZB_OPA_INTER, "G_RM_RA_ZB_OPA_INTER" }, - { G_RM_RA_ZB_OPA_INTER2, "G_RM_RA_ZB_OPA_INTER2" }, - { G_RM_AA_OPA_SURF, "G_RM_AA_OPA_SURF" }, - { G_RM_AA_OPA_SURF2, "G_RM_AA_OPA_SURF2" }, - { G_RM_AA_XLU_SURF, "G_RM_AA_XLU_SURF" }, - { G_RM_AA_XLU_SURF2, "G_RM_AA_XLU_SURF2" }, - { G_RM_AA_XLU_LINE, "G_RM_AA_XLU_LINE" }, - { G_RM_AA_XLU_LINE2, "G_RM_AA_XLU_LINE2" }, - { G_RM_AA_DEC_LINE, "G_RM_AA_DEC_LINE" }, - { G_RM_AA_DEC_LINE2, "G_RM_AA_DEC_LINE2" }, - { G_RM_AA_TEX_EDGE, "G_RM_AA_TEX_EDGE" }, - { G_RM_AA_TEX_EDGE2, "G_RM_AA_TEX_EDGE2" }, - { G_RM_AA_SUB_SURF, "G_RM_AA_SUB_SURF" }, - { G_RM_AA_SUB_SURF2, "G_RM_AA_SUB_SURF2" }, - { G_RM_AA_PCL_SURF, "G_RM_AA_PCL_SURF" }, - { G_RM_AA_PCL_SURF2, "G_RM_AA_PCL_SURF2" }, - { G_RM_AA_OPA_TERR, "G_RM_AA_OPA_TERR" }, - { G_RM_AA_OPA_TERR2, "G_RM_AA_OPA_TERR2" }, - { G_RM_AA_TEX_TERR, "G_RM_AA_TEX_TERR" }, - { G_RM_AA_TEX_TERR2, "G_RM_AA_TEX_TERR2" }, - { G_RM_AA_TEX_TERR, "G_RM_AA_TEX_TERR" }, - { G_RM_AA_TEX_TERR2, "G_RM_AA_TEX_TERR2" }, - { G_RM_AA_SUB_TERR, "G_RM_AA_SUB_TERR" }, - { G_RM_AA_SUB_TERR2, "G_RM_AA_SUB_TERR2" }, - { G_RM_RA_OPA_SURF, "G_RM_RA_OPA_SURF" }, - { G_RM_RA_OPA_SURF2, "G_RM_RA_OPA_SURF2" }, - { G_RM_ZB_OPA_SURF, "G_RM_ZB_OPA_SURF" }, - { G_RM_ZB_OPA_SURF2, "G_RM_ZB_OPA_SURF2" }, - { G_RM_ZB_XLU_SURF, "G_RM_ZB_XLU_SURF" }, - { G_RM_ZB_XLU_SURF2, "G_RM_ZB_XLU_SURF2" }, - { G_RM_ZB_OPA_DECAL, "G_RM_ZB_OPA_DECAL" }, - { G_RM_ZB_OPA_DECAL2, "G_RM_ZB_OPA_DECAL2" }, - { G_RM_ZB_XLU_DECAL, "G_RM_ZB_XLU_DECAL" }, - { G_RM_ZB_XLU_DECAL2, "G_RM_ZB_XLU_DECAL2" }, - { G_RM_ZB_CLD_SURF, "G_RM_ZB_CLD_SURF" }, - { G_RM_ZB_CLD_SURF2, "G_RM_ZB_CLD_SURF2" }, - { G_RM_ZB_OVL_SURF, "G_RM_ZB_OVL_SURF" }, - { G_RM_ZB_OVL_SURF2, "G_RM_ZB_OVL_SURF2" }, - { G_RM_ZB_PCL_SURF, "G_RM_ZB_PCL_SURF" }, - { G_RM_ZB_PCL_SURF2, "G_RM_ZB_PCL_SURF2" }, - { G_RM_OPA_SURF, "G_RM_OPA_SURF" }, - { G_RM_OPA_SURF2, "G_RM_OPA_SURF2" }, - { G_RM_XLU_SURF, "G_RM_XLU_SURF" }, - { G_RM_XLU_SURF2, "G_RM_XLU_SURF2" }, - { G_RM_CLD_SURF, "G_RM_CLD_SURF" }, - { G_RM_CLD_SURF2, "G_RM_CLD_SURF2" }, - { G_RM_TEX_EDGE, "G_RM_TEX_EDGE" }, - { G_RM_TEX_EDGE2, "G_RM_TEX_EDGE2" }, - { G_RM_PCL_SURF, "G_RM_PCL_SURF" }, - { G_RM_PCL_SURF2, "G_RM_PCL_SURF2" }, - { G_RM_ADD, "G_RM_ADD" }, - { G_RM_ADD2, "G_RM_ADD2" }, - { G_RM_NOOP, "G_RM_NOOP" }, - { G_RM_NOOP2, "G_RM_NOOP2" }, - { G_RM_VISCVG, "G_RM_VISCVG" }, - { G_RM_VISCVG2, "G_RM_VISCVG2" }, - { G_RM_OPA_CI, "G_RM_OPA_CI" }, - { G_RM_OPA_CI2, "G_RM_OPA_CI2" }, - }; - - for (int k = 0; k < sizeof(tblA) / 4; k++) + for (uint32_t k = 0; k < sizeof(tblA) / 4; k++) { if ((dd & tblA[k]) == tblA[k]) { @@ -1258,7 +1400,7 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string pre } } - for (int k = 0; k < sizeof(tblB) / 4; k++) + for (uint32_t k = 0; k < sizeof(tblB) / 4; k++) { if ((dd & tblB[k]) == tblB[k]) { @@ -1375,7 +1517,7 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string pre int bb = (mode2 >> 16) & 0b11; mode2Str += StringHelper::Sprintf("GBL_c2(%i, %i, %i, %i)", bp, ba, bm, bb); - //mode2Str = StringHelper::Sprintf("0x%08X", mode2); + // mode2Str = StringHelper::Sprintf("0x%08X", mode2); } sprintf(line, "gsDPSetRenderMode(%s, %s),", mode1Str.c_str(), mode2Str.c_str()); @@ -1394,9 +1536,9 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_H(uint64_t data, int i, std::string pre int sft = 32 - (nn + 1) - ss; - if (sft == 14) // G_MDSFT_TEXTLUT + if (sft == 14) // G_MDSFT_TEXTLUT { - string types[] = { "G_TT_NONE", "G_TT_NONE", "G_TT_RGBA16", "G_TT_IA16" }; + string types[] = {"G_TT_NONE", "G_TT_NONE", "G_TT_RGBA16", "G_TT_IA16"}; sprintf(line, "gsDPSetTextureLUT(%s),", types[dd >> 14].c_str()); } else @@ -1443,10 +1585,11 @@ static int GfxdCallback_FormatSingleEntry(void) gfxd_macro_dflt(); gfxd_puts(","); - // dont print a new line after the last command - if (gfxd_macro_id() != gfxd_SPEndDisplayList) { - gfxd_puts("\n"); - } + // dont print a new line after the last command + if (gfxd_macro_id() != gfxd_SPEndDisplayList) + { + gfxd_puts("\n"); + } return 0; } @@ -1457,7 +1600,8 @@ static int GfxdCallback_Vtx(uint32_t seg, int32_t count) uint32_t vtxOffset = Seg2Filespace(seg, instance->parent->baseAddress); string vtxName = ""; - if (!Globals::Instance->HasSegment(GETSEGNUM(seg))) // Probably an external asset we are unable to track + if (!Globals::Instance->HasSegment( + GETSEGNUM(seg))) // Probably an external asset we are unable to track { vtxName = StringHelper::Sprintf("0x%08X", seg); } @@ -1469,7 +1613,7 @@ static int GfxdCallback_Vtx(uint32_t seg, int32_t count) // TODO: These two could probably be condenced to one... if (instance->parent->GetDeclarationRanged(vtxOffset + (count * 16)) != nullptr) { - Declaration* decl = instance->parent->GetDeclarationRanged(vtxOffset + (count * 16)); + // Declaration* decl = instance->parent->GetDeclarationRanged(vtxOffset + (count * 16)); uint32_t addr = instance->parent->GetDeclarationRangedAddress(vtxOffset + (count * 16)); int diff = addr - vtxOffset; @@ -1481,7 +1625,7 @@ static int GfxdCallback_Vtx(uint32_t seg, int32_t count) if (instance->parent->GetDeclarationRanged(vtxOffset) != nullptr) { - Declaration* decl = instance->parent->GetDeclarationRanged(vtxOffset); + // Declaration* decl = instance->parent->GetDeclarationRanged(vtxOffset); uint32_t addr = instance->parent->GetDeclarationRangedAddress(vtxOffset); int diff = addr - vtxOffset; @@ -1505,7 +1649,7 @@ static int GfxdCallback_Vtx(uint32_t seg, int32_t count) } instance->vertices[vtxOffset] = vtxList; } - + vtxName = "@r"; } @@ -1514,7 +1658,8 @@ static int GfxdCallback_Vtx(uint32_t seg, int32_t count) return 1; } -static int GfxdCallback_Texture(uint32_t seg, int32_t fmt, int32_t siz, int32_t width, int32_t height, int32_t pal) +static int GfxdCallback_Texture(uint32_t seg, int32_t fmt, int32_t siz, int32_t width, + int32_t height, int32_t pal) { ZDisplayList* instance = ZDisplayList::static_instance; uint32_t texOffset = Seg2Filespace(seg, instance->parent->baseAddress); @@ -1522,7 +1667,9 @@ static int GfxdCallback_Texture(uint32_t seg, int32_t fmt, int32_t siz, int32_t Declaration* texDecl = nullptr; string texName = ""; - if (instance->parent != nullptr && texSegNum != 2) // HACK: Until we have declarations use segment addresses, we'll exclude scene references... + if (instance->parent != nullptr && + texSegNum != 2) // HACK: Until we have declarations use segment addresses, we'll exclude + // scene references... { texDecl = instance->parent->GetDeclaration(texOffset); @@ -1530,12 +1677,14 @@ static int GfxdCallback_Texture(uint32_t seg, int32_t fmt, int32_t siz, int32_t texDecl = instance->parent->GetDeclaration(seg); } - if (!Globals::Instance->HasSegment(texSegNum)) // Probably an external asset we are unable to track + if (!Globals::Instance->HasSegment( + texSegNum)) // Probably an external asset we are unable to track texName = StringHelper::Sprintf("0x%08X", seg); else if (texDecl != nullptr) texName = StringHelper::Sprintf("%s", texDecl->varName.c_str()); else if (texSegNum == 2) - texName = StringHelper::Sprintf("%sTex_%06X", instance->scene->GetName().c_str(), texOffset); + texName = + StringHelper::Sprintf("%sTex_%06X", instance->scene->GetName().c_str(), texOffset); else texName = StringHelper::Sprintf("%sTex_%06X", instance->curPrefix.c_str(), texOffset); @@ -1562,7 +1711,9 @@ static int GfxdCallback_Palette(uint32_t seg, int32_t idx, int32_t count) Declaration* palDecl = nullptr; string palName = ""; - if (instance->parent != nullptr && palSegNum != 2) // HACK: Until we have declarations use segment addresses, we'll exclude scene references... + if (instance->parent != nullptr && + palSegNum != 2) // HACK: Until we have declarations use segment addresses, we'll exclude + // scene references... { palDecl = instance->parent->GetDeclaration(palOffset); @@ -1570,12 +1721,14 @@ static int GfxdCallback_Palette(uint32_t seg, int32_t idx, int32_t count) palDecl = instance->parent->GetDeclaration(seg); } - if (!Globals::Instance->HasSegment(palSegNum)) // Probably an external asset we are unable to track + if (!Globals::Instance->HasSegment( + palSegNum)) // Probably an external asset we are unable to track palName = StringHelper::Sprintf("0x%08X", seg); else if (palDecl != nullptr) palName = StringHelper::Sprintf("%s", palDecl->varName.c_str()); else if (palSegNum == 2) - palName = StringHelper::Sprintf("%sTex_%06X", instance->scene->GetName().c_str(), palOffset); + palName = + StringHelper::Sprintf("%sTex_%06X", instance->scene->GetName().c_str(), palOffset); else palName = StringHelper::Sprintf("%sTex_%06X", instance->curPrefix.c_str(), palOffset); @@ -1594,7 +1747,7 @@ static int GfxdCallback_Palette(uint32_t seg, int32_t idx, int32_t count) return 1; } -static int GfxdCallback_DisplayList(uint32_t seg) +static int GfxdCallback_DisplayList(uint32_t seg) { ZDisplayList* instance = ZDisplayList::static_instance; uint32_t dListOffset = GETSEGOFFSET(seg); @@ -1605,7 +1758,8 @@ static int GfxdCallback_DisplayList(uint32_t seg) if (instance->parent != nullptr) dListDecl = instance->parent->GetDeclaration(dListOffset); - if (!Globals::Instance->HasSegment(dListSegNum)) // Probably an external asset we are unable to track + if (!Globals::Instance->HasSegment( + dListSegNum)) // Probably an external asset we are unable to track dListName = StringHelper::Sprintf("0x%08X", seg); else if (dListDecl != nullptr) dListName = StringHelper::Sprintf("%s", dListDecl->varName.c_str()); @@ -1614,7 +1768,9 @@ static int GfxdCallback_DisplayList(uint32_t seg) if (dListSegNum <= 6) { - ZDisplayList* newDList = new ZDisplayList(instance->fileData, dListOffset, instance->GetDListLength(instance->fileData, dListOffset, instance->dListType)); + ZDisplayList* newDList = new ZDisplayList( + instance->fileData, dListOffset, + instance->GetDListLength(instance->fileData, dListOffset, instance->dListType)); newDList->scene = instance->scene; newDList->parent = instance->parent; instance->otherDLists.push_back(newDList); @@ -1625,7 +1781,7 @@ static int GfxdCallback_DisplayList(uint32_t seg) return 1; } -static int GfxdCallback_Matrix(uint32_t seg) +static int GfxdCallback_Matrix(uint32_t seg) { string mtxName = ""; @@ -1645,61 +1801,66 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) { OutputFormatter outputformatter; string sourceOutput = ""; - int dListSize = instructions.size() * sizeof(instructions[0]); + size_t dListSize = instructions.size() * sizeof(instructions[0]); gfxd_input_buffer(instructions.data(), dListSize); - gfxd_endian(gfxd_endian_little, sizeof(uint64_t)); // tell gfxdis what format the data is + gfxd_endian(gfxd_endian_little, sizeof(uint64_t)); // tell gfxdis what format the data is - gfxd_macro_fn(GfxdCallback_FormatSingleEntry); // format for each command entry - gfxd_vtx_callback(GfxdCallback_Vtx); // handle vertices - gfxd_timg_callback(GfxdCallback_Texture); // handle textures - gfxd_tlut_callback(GfxdCallback_Palette); // handle palettes - gfxd_dl_callback(GfxdCallback_DisplayList); // handle child display lists - gfxd_mtx_callback(GfxdCallback_Matrix); // handle matrices - gfxd_output_callback(outputformatter.static_writer()); // convert tabs to 4 spaces and enforce 120 line limit + gfxd_macro_fn(GfxdCallback_FormatSingleEntry); // format for each command entry + gfxd_vtx_callback(GfxdCallback_Vtx); // handle vertices + gfxd_timg_callback(GfxdCallback_Texture); // handle textures + gfxd_tlut_callback(GfxdCallback_Palette); // handle palettes + gfxd_dl_callback(GfxdCallback_DisplayList); // handle child display lists + gfxd_mtx_callback(GfxdCallback_Matrix); // handle matrices + gfxd_output_callback( + outputformatter.static_writer()); // convert tabs to 4 spaces and enforce 120 line limit - gfxd_enable(gfxd_emit_dec_color); // use decimal for colors + gfxd_enable(gfxd_emit_dec_color); // use decimal for colors // set microcode. see gfxd.h for more options. - if (dListType == DListType::F3DZEX) { + if (dListType == DListType::F3DZEX) + { gfxd_target(gfxd_f3dex2); - } else { + } + else + { gfxd_target(gfxd_f3dex); } this->curPrefix = prefix; static_instance = this; - gfxd_execute(); // generate display list - sourceOutput += outputformatter.get_output(); // write formatted display list + gfxd_execute(); // generate display list + sourceOutput += outputformatter.get_output(); // write formatted display list // Iterate through our vertex lists, connect intersecting lists. if (vertices.size() > 0) { vector>> verticesSorted(vertices.begin(), vertices.end()); - sort(verticesSorted.begin(), verticesSorted.end(), [](const auto& lhs, const auto& rhs) - { - return lhs.first < rhs.first; - }); + sort(verticesSorted.begin(), verticesSorted.end(), + [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); - for (int i = 0; i < verticesSorted.size() - 1; i++) + for (size_t i = 0; i < verticesSorted.size() - 1; i++) { - //int vtxSize = verticesSorted[i].second.size() * 16; - int vtxSize = (int)vertices[verticesSorted[i].first].size() * 16; + // int vtxSize = verticesSorted[i].second.size() * 16; + size_t vtxSize = vertices[verticesSorted[i].first].size() * 16; - if ((verticesSorted[i].first + vtxSize) > verticesSorted[i + 1].first) + if ((verticesSorted[i].first + (int)vtxSize) > verticesSorted[i + 1].first) { - int intersectAmt = (verticesSorted[i].first + vtxSize) - verticesSorted[i + 1].first; + int intersectAmt = + (verticesSorted[i].first + vtxSize) - verticesSorted[i + 1].first; int intersectIndex = intersectAmt / 16; - for (int j = intersectIndex; j < verticesSorted[i + 1].second.size(); j++) + for (size_t j = intersectIndex; j < verticesSorted[i + 1].second.size(); j++) { vertices[verticesSorted[i].first].push_back(verticesSorted[i + 1].second[j]); } - //defines += StringHelper::Sprintf("#define %sVtx_%06X ((u32)%sVtx_%06X + 0x%06X)\n", prefix.c_str(), verticesSorted[i + 1].first, prefix.c_str(), verticesSorted[i].first, verticesSorted[i + 1].first - verticesSorted[i].first); + // defines += StringHelper::Sprintf("#define %sVtx_%06X ((u32)%sVtx_%06X + + // 0x%06X)\n", prefix.c_str(), verticesSorted[i + 1].first, prefix.c_str(), + // verticesSorted[i].first, verticesSorted[i + 1].first - verticesSorted[i].first); - int nSize = (int)vertices[verticesSorted[i].first].size(); + // int nSize = (int)vertices[verticesSorted[i].first].size(); vertices.erase(verticesSorted[i + 1].first); verticesSorted.erase(verticesSorted.begin() + i + 1); @@ -1708,7 +1869,7 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) } } - if (scene == nullptr) // TODO: Bit of a hack but it works for now... + if (scene == nullptr) // TODO: Bit of a hack but it works for now... parent->defines += defines; // Generate Vertex Declarations @@ -1723,8 +1884,9 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) if (curAddr != item.first) declaration += "\n"; - declaration += StringHelper::Sprintf(" VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i),", - vtx.x, vtx.y, vtx.z, vtx.s, vtx.t, vtx.r, vtx.g, vtx.b, vtx.a); + declaration += + StringHelper::Sprintf(" VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i),", vtx.x, + vtx.y, vtx.z, vtx.s, vtx.t, vtx.r, vtx.g, vtx.b, vtx.a); curAddr += 16; } @@ -1733,8 +1895,11 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) if (parent != nullptr) { - parent->AddDeclarationArray(item.first, DeclarationAlignment::None, item.second.size() * 16, "static Vtx", - StringHelper::Sprintf("%sVtx_%06X", prefix.c_str(), item.first, item.second.size()), item.second.size(), declaration); + parent->AddDeclarationArray(item.first, DeclarationAlignment::None, + item.second.size() * 16, "static Vtx", + StringHelper::Sprintf("%sVtx_%06X", prefix.c_str(), + item.first, item.second.size()), + item.second.size(), declaration); } } } @@ -1743,23 +1908,26 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) { if (scene != nullptr && scene->textures.size() != 0) { - vector> texturesSorted(scene->textures.begin(), scene->textures.end()); + vector> texturesSorted(scene->textures.begin(), + scene->textures.end()); - sort(texturesSorted.begin(), texturesSorted.end(), [](const auto& lhs, const auto& rhs) - { - return lhs.first < rhs.first; - }); + sort(texturesSorted.begin(), texturesSorted.end(), + [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); - for (int i = 0; i < texturesSorted.size() - 1; i++) + for (size_t i = 0; i < texturesSorted.size() - 1; i++) { int texSize = scene->textures[texturesSorted[i].first]->GetRawDataSize(); if ((texturesSorted[i].first + texSize) > texturesSorted[i + 1].first) { - int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + 1].first; + // int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + + // 1].first; - defines += StringHelper::Sprintf("#define %sTex_%06X ((u32)%sTex_%06X + 0x%06X)\n", scene->GetName().c_str(), texturesSorted[i + 1].first, scene->GetName().c_str(), - texturesSorted[i].first, texturesSorted[i + 1].first - texturesSorted[i].first); + defines += StringHelper::Sprintf( + "#define %sTex_%06X ((u32)%sTex_%06X + 0x%06X)\n", scene->GetName().c_str(), + texturesSorted[i + 1].first, scene->GetName().c_str(), + texturesSorted[i].first, + texturesSorted[i + 1].first - texturesSorted[i].first); scene->parent->declarations.erase(texturesSorted[i + 1].first); scene->textures.erase(texturesSorted[i + 1].first); @@ -1775,32 +1943,34 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) { vector> texturesSorted(textures.begin(), textures.end()); - sort(texturesSorted.begin(), texturesSorted.end(), [](const auto& lhs, const auto& rhs) - { - return lhs.first < rhs.first; - }); + sort(texturesSorted.begin(), texturesSorted.end(), + [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); - for (int i = 0; i < texturesSorted.size() - 1; i++) + for (size_t i = 0; i < texturesSorted.size() - 1; i++) { - if (texturesSorted.size() == 0) // ????? + if (texturesSorted.size() == 0) // ????? break; int texSize = textures[texturesSorted[i].first]->GetRawDataSize(); if ((texturesSorted[i].first + texSize) > texturesSorted[i + 1].first) { - int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + 1].first; + // int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + + // 1].first; // If we're working with a palette, resize it to its "real" dimensions if (texturesSorted[i].second->isPalette) { - texturesSorted[i].second->SetWidth((texturesSorted[i + 1].first - texturesSorted[i].first) / 2); + texturesSorted[i].second->SetWidth( + (texturesSorted[i + 1].first - texturesSorted[i].first) / 2); texturesSorted[i].second->SetHeight(1); } else { - defines += StringHelper::Sprintf("#define %sTex_%06X ((u32)%sTex_%06X + 0x%06X)\n", prefix.c_str(), texturesSorted[i + 1].first, prefix.c_str(), - texturesSorted[i].first, texturesSorted[i + 1].first - texturesSorted[i].first); + defines += StringHelper::Sprintf( + "#define %sTex_%06X ((u32)%sTex_%06X + 0x%06X)\n", prefix.c_str(), + texturesSorted[i + 1].first, prefix.c_str(), texturesSorted[i].first, + texturesSorted[i + 1].first - texturesSorted[i].first); textures.erase(texturesSorted[i + 1].first); texturesSorted.erase(texturesSorted.begin() + i + 1); @@ -1828,19 +1998,24 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) item.second->Save(Globals::Instance->outputPath); - parent->AddDeclarationIncludeArray(item.first, StringHelper::Sprintf("%s/%s.%s.inc.c", - Globals::Instance->outputPath.c_str(), Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(), - item.second->GetExternalExtension().c_str()), item.second->GetRawDataSize(), - "u64", StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first), 0); + parent->AddDeclarationIncludeArray( + item.first, + StringHelper::Sprintf( + "%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(), + Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(), + item.second->GetExternalExtension().c_str()), + item.second->GetRawDataSize(), "u64", + StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first), 0); } } } - } if (parent != nullptr) { - Declaration* decl = parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), "Gfx", StringHelper::Sprintf("%s", name.c_str()), 0, sourceOutput); + Declaration* decl = parent->AddDeclarationArray( + rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), "Gfx", + StringHelper::Sprintf("%s", name.c_str()), 0, sourceOutput); decl->references = references; return ""; } @@ -1851,7 +2026,9 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) // HOTSPOT void ZDisplayList::TextureGenCheck(string prefix) { - if (TextureGenCheck(fileData, textures, scene, parent, prefix, lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg, lastTexFmt, lastTexSiz, lastTexLoaded, lastTexIsPalette)) + if (TextureGenCheck(fileData, textures, scene, parent, prefix, lastTexWidth, lastTexHeight, + lastTexAddr, lastTexSeg, lastTexFmt, lastTexSiz, lastTexLoaded, + lastTexIsPalette)) { lastTexAddr = 0; lastTexLoaded = false; @@ -1860,18 +2037,26 @@ void ZDisplayList::TextureGenCheck(string prefix) } // HOTSPOT -bool ZDisplayList::TextureGenCheck(vector fileData, map& textures, ZRoom* scene, ZFile* parent, string prefix, uint32_t texWidth, uint32_t texHeight, uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette) +bool ZDisplayList::TextureGenCheck(vector fileData, map& textures, + ZRoom* scene, ZFile* parent, string prefix, uint32_t texWidth, + uint32_t texHeight, uint32_t texAddr, uint32_t texSeg, + F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded, + bool texIsPalette) { int segmentNumber = GETSEGNUM(texSeg); if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) - printf("TextureGenCheck seg=%i width=%i height=%i ispal=%i addr=0x%06X\n", segmentNumber, texWidth, texHeight, texIsPalette, texAddr); + printf("TextureGenCheck seg=%i width=%i height=%i ispal=%i addr=0x%06X\n", segmentNumber, + texWidth, texHeight, texIsPalette, texAddr); - if ((texSeg != 0 || texAddr != 0) && texWidth != 0 && texHeight != 0 && texLoaded && Globals::Instance->HasSegment(segmentNumber)) + if ((texSeg != 0 || texAddr != 0) && texWidth != 0 && texHeight != 0 && texLoaded && + Globals::Instance->HasSegment(segmentNumber)) { - if (segmentNumber != 2) // Not from a scene file + if (segmentNumber != 2) // Not from a scene file { - ZTexture* tex = ZTexture::FromBinary(TexFormatToTexType(texFmt, texSiz), fileData, texAddr, StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), texAddr), texWidth, texHeight); + ZTexture* tex = ZTexture::FromBinary( + TexFormatToTexType(texFmt, texSiz), fileData, texAddr, + StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), texAddr), texWidth, texHeight); tex->isPalette = texIsPalette; textures[texAddr] = tex; @@ -1879,15 +2064,24 @@ bool ZDisplayList::TextureGenCheck(vector fileData, mapGetRawData(), texAddr, - StringHelper::Sprintf("%sTex_%06X", Globals::Instance->lastScene->GetName().c_str(), texAddr), texWidth, texHeight); + ZTexture* tex = ZTexture::FromBinary( + TexFormatToTexType(texFmt, texSiz), scene->GetRawData(), texAddr, + StringHelper::Sprintf("%sTex_%06X", Globals::Instance->lastScene->GetName().c_str(), + texAddr), + texWidth, texHeight); if (scene != nullptr) { scene->textures[texAddr] = tex; - scene->parent->AddDeclarationIncludeArray(texAddr, StringHelper::Sprintf("%s/%s.%s.inc.c", - Globals::Instance->outputPath.c_str(), Path::GetFileNameWithoutExtension(tex->GetName()).c_str(), tex->GetExternalExtension().c_str()), tex->GetRawDataSize(), - "u64", StringHelper::Sprintf("%sTex_%06X", Globals::Instance->lastScene->GetName().c_str(), texAddr), 0); + scene->parent->AddDeclarationIncludeArray( + texAddr, + StringHelper::Sprintf("%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(), + Path::GetFileNameWithoutExtension(tex->GetName()).c_str(), + tex->GetExternalExtension().c_str()), + tex->GetRawDataSize(), "u64", + StringHelper::Sprintf("%sTex_%06X", + Globals::Instance->lastScene->GetName().c_str(), texAddr), + 0); } return true; @@ -1906,13 +2100,13 @@ TextureType ZDisplayList::TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSize else if (siz == F3DZEXTexSizes::G_IM_SIZ_32b) return TextureType::RGBA32bpp; } - else if (fmt == F3DZEXTexFormats::G_IM_FMT_CI) - { - if (siz == F3DZEXTexSizes::G_IM_SIZ_4b) - return TextureType::Palette4bpp; + else if (fmt == F3DZEXTexFormats::G_IM_FMT_CI) + { + if (siz == F3DZEXTexSizes::G_IM_SIZ_4b) + return TextureType::Palette4bpp; else if (siz == F3DZEXTexSizes::G_IM_SIZ_8b) - return TextureType::Palette8bpp; - } + return TextureType::Palette8bpp; + } else if (fmt == F3DZEXTexFormats::G_IM_FMT_IA) { if (siz == F3DZEXTexSizes::G_IM_SIZ_4b) @@ -1930,7 +2124,6 @@ TextureType ZDisplayList::TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSize return TextureType::Grayscale8bpp; else if (siz == F3DZEXTexSizes::G_IM_SIZ_16b) return TextureType::Grayscale8bpp; - } return TextureType::RGBA16bpp; @@ -1938,18 +2131,18 @@ TextureType ZDisplayList::TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSize void ZDisplayList::Save(const std::string& outFolder) { - //HLModelIntermediette* mdl = HLModelIntermediette::FromZDisplayList(this); + // HLModelIntermediette* mdl = HLModelIntermediette::FromZDisplayList(this); // For testing purposes only at the moment... - //if (Globals::Instance->testMode) + // if (Globals::Instance->testMode) //{ - //string xml = mdl->OutputXML(); - //string obj = mdl->ToOBJFile(); - //string fbx = mdl->ToFBXFile(); + // string xml = mdl->OutputXML(); + // string obj = mdl->ToOBJFile(); + // string fbx = mdl->ToFBXFile(); - //File::WriteAllText(outFolder + "/" + name + ".mdli", xml); - //File::WriteAllText(outFolder + "/" + name + ".obj", obj); - //File::WriteAllText(outFolder + "/" + name + ".fbx", fbx); + // File::WriteAllText(outFolder + "/" + name + ".mdli", xml); + // File::WriteAllText(outFolder + "/" + name + ".obj", obj); + // File::WriteAllText(outFolder + "/" + name + ".fbx", fbx); //} } @@ -1989,7 +2182,8 @@ Vertex::Vertex() a = 0; } -Vertex::Vertex(int16_t nX, int16_t nY, int16_t nZ, uint16_t nFlag, int16_t nS, int16_t nT, uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA) +Vertex::Vertex(int16_t nX, int16_t nY, int16_t nZ, uint16_t nFlag, int16_t nS, int16_t nT, + uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA) { x = nX; y = nY; diff --git a/tools/ZAPD/ZAPD/ZDisplayList.h b/tools/ZAPD/ZAPD/ZDisplayList.h index 66f2f4e2b5..c3f3f8b1c4 100644 --- a/tools/ZAPD/ZAPD/ZDisplayList.h +++ b/tools/ZAPD/ZAPD/ZDisplayList.h @@ -1,13 +1,13 @@ #pragma once #include "ZResource.h" -#include "ZTexture.h" #include "ZRoom/ZRoom.h" +#include "ZTexture.h" #include "tinyxml2.h" -#include #include #include +#include enum class F3DEXOpcode { @@ -164,10 +164,10 @@ enum class OoTSegments FrameBuffer = 16, }; -#define G_MDSFT_ALPHACOMPARE 0 -#define G_MDSFT_ZSRCSEL 2 -#define G_MDSFT_RENDERMODE 3 -#define G_MDSFT_BLENDER 16 +#define G_MDSFT_ALPHACOMPARE 0 +#define G_MDSFT_ZSRCSEL 2 +#define G_MDSFT_RENDERMODE 3 +#define G_MDSFT_BLENDER 16 #define G_RM_FOG_SHADE_A 0xC8000000 #define G_RM_FOG_PRIM_A 0xC4000000 @@ -263,23 +263,23 @@ enum class OoTSegments #define G_RM_OPA_CI 0x0C080000 #define G_RM_OPA_CI2 0x03020000 -#define AA_EN 0x8 -#define Z_CMP 0x10 -#define Z_UPD 0x20 -#define IM_RD 0x40 -#define CLR_ON_CVG 0x80 -#define CVG_DST_CLAMP 0 -#define CVG_DST_WRAP 0x100 -#define CVG_DST_FULL 0x200 -#define CVG_DST_SAVE 0x300 -#define ZMODE_OPA 0 -#define ZMODE_INTER 0x400 -#define ZMODE_XLU 0x800 -#define ZMODE_DEC 0xc00 -#define CVG_X_ALPHA 0x1000 -#define ALPHA_CVG_SEL 0x2000 -#define FORCE_BL 0x4000 -#define TEX_EDGE 0x0000 +#define AA_EN 0x8 +#define Z_CMP 0x10 +#define Z_UPD 0x20 +#define IM_RD 0x40 +#define CLR_ON_CVG 0x80 +#define CVG_DST_CLAMP 0 +#define CVG_DST_WRAP 0x100 +#define CVG_DST_FULL 0x200 +#define CVG_DST_SAVE 0x300 +#define ZMODE_OPA 0 +#define ZMODE_INTER 0x400 +#define ZMODE_XLU 0x800 +#define ZMODE_DEC 0xc00 +#define CVG_X_ALPHA 0x1000 +#define ALPHA_CVG_SEL 0x2000 +#define FORCE_BL 0x4000 +#define TEX_EDGE 0x0000 class Vertex { @@ -290,7 +290,8 @@ public: uint8_t r, g, b, a; Vertex(); - Vertex(int16_t nX, int16_t nY, int16_t nZ, uint16_t nFlag, int16_t nS, int16_t nT, uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA); + Vertex(int16_t nX, int16_t nY, int16_t nZ, uint16_t nFlag, int16_t nS, int16_t nT, uint8_t nR, + uint8_t nG, uint8_t nB, uint8_t nA); Vertex(std::vector rawData, int rawDataIndex); }; @@ -298,7 +299,7 @@ class ZDisplayList : public ZResource { protected: static TextureType TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSizes siz); - void ParseRawData(); + void ParseRawData() override; void ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::string prefix, char* line); void ParseF3DEX(F3DEXOpcode opcode, uint64_t data, int i, std::string prefix, char* line); @@ -331,6 +332,7 @@ protected: void Opcode_G_SETOTHERMODE_H(uint64_t data, int i, std::string prefix, char* line); void Opcode_G_LOADTLUT(uint64_t data, int i, std::string prefix, char* line); void Opcode_G_ENDDL(uint64_t data, int i, std::string prefix, char* line); + public: std::string sceneSegName; ZRoom* scene; @@ -345,7 +347,7 @@ public: DListType dListType; - //int dListAddress; + // int dListAddress; std::map> vertices; std::map vtxDeclarations; @@ -356,21 +358,28 @@ public: std::vector references; - std::string defines; // Hack for special cases where vertex arrays intersect... + std::string defines; // Hack for special cases where vertex arrays intersect... std::vector fileData; ZDisplayList(); ZDisplayList(std::vector nRawData, int rawDataIndex, int rawDataSize); static ZDisplayList* static_instance; - static ZDisplayList* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, int rawDataSize, std::string nRelPath); - static ZDisplayList* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, bool readFile); + static ZDisplayList* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, + int rawDataIndex, int rawDataSize, std::string nRelPath); + static ZDisplayList* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, + bool readFile); void TextureGenCheck(std::string prefix); - static bool TextureGenCheck(std::vector fileData, std::map& textures, ZRoom* scene, ZFile* parent, std::string prefix, uint32_t texWidth, uint32_t texHeight, uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette); + static bool TextureGenCheck(std::vector fileData, + std::map& textures, ZRoom* scene, + ZFile* parent, std::string prefix, uint32_t texWidth, + uint32_t texHeight, uint32_t texAddr, uint32_t texSeg, + F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded, + bool texIsPalette); static int GetDListLength(std::vector rawData, int rawDataIndex, DListType dListType); - std::vector GetRawData(); + std::vector GetRawData() override; int GetRawDataSize() override; std::string GetSourceOutputHeader(const std::string& prefix) override; std::string GetSourceOutputCode(const std::string& prefix) override; diff --git a/tools/ZAPD/ZAPD/ZFile.cpp b/tools/ZAPD/ZAPD/ZFile.cpp index 5046ed1cbb..75eb9bc1a3 100644 --- a/tools/ZAPD/ZAPD/ZFile.cpp +++ b/tools/ZAPD/ZAPD/ZFile.cpp @@ -1,24 +1,25 @@ #include "ZFile.h" -#include "ZBlob.h" -#include "ZDisplayList.h" -#include "ZRoom/ZRoom.h" -#include "ZTexture.h" -#include "ZAnimation.h" -#include "ZLimb.h" -#include "ZSkeleton.h" -#include "ZCollision.h" -#include "ZScalar.h" -#include "ZVector.h" -#include "ZVtx.h" -#include "ZCutscene.h" -#include "ZArray.h" -#include "Path.h" -#include "File.h" -#include "Directory.h" -#include "Globals.h" -#include "HighLevel/HLModelIntermediette.h" #include #include +#include "Directory.h" +#include "File.h" +#include "Globals.h" +#include "HighLevel/HLModelIntermediette.h" +#include "Path.h" +#include "ZAnimation.h" +#include "ZArray.h" +#include "ZBlob.h" +#include "ZCollision.h" +#include "ZCutscene.h" +#include "ZDisplayList.h" +#include "ZLimb.h" +#include "ZRoom/ZRoom.h" +#include "ZScalar.h" +#include "ZSkeleton.h" +#include "ZSymbol.h" +#include "ZTexture.h" +#include "ZVector.h" +#include "ZVtx.h" using namespace tinyxml2; using namespace std; @@ -28,7 +29,7 @@ ZFile::ZFile() resources = vector(); basePath = ""; outputPath = Directory::GetCurrentDirectory(); - declarations = map(); + declarations = map(); defines = ""; baseAddress = 0; rangeStart = 0x000000000; @@ -41,7 +42,9 @@ ZFile::ZFile(string nOutPath, string nName) : ZFile() name = nName; } -ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPath, std::string filename, bool placeholderMode) : ZFile() +ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPath, + std::string filename, bool placeholderMode) + : ZFile() { if (nBasePath == "") basePath = Directory::GetCurrentDirectory(); @@ -71,7 +74,8 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b int segment = -1; - // TODO: This should be a variable on the ZFile, but it is a large change in order to force all ZResource types to have a parent ZFile. + // TODO: This should be a variable on the ZFile, but it is a large change in order to force all + // ZResource types to have a parent ZFile. const char* gameStr = reader->Attribute("Game"); if (reader->Attribute("Game") != nullptr) { @@ -90,39 +94,45 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b } if (reader->Attribute("BaseAddress") != NULL) - baseAddress = (uint32_t)strtoul(StringHelper::Split(reader->Attribute("BaseAddress"), "0x")[1].c_str(), NULL, 16); + baseAddress = (uint32_t)strtoul( + StringHelper::Split(reader->Attribute("BaseAddress"), "0x")[1].c_str(), NULL, 16); if (reader->Attribute("RangeStart") != NULL) - rangeStart = (uint32_t)strtoul(StringHelper::Split(reader->Attribute("RangeStart"), "0x")[1].c_str(), NULL, 16); + rangeStart = (uint32_t)strtoul( + StringHelper::Split(reader->Attribute("RangeStart"), "0x")[1].c_str(), NULL, 16); if (reader->Attribute("RangeEnd") != NULL) - rangeEnd = (uint32_t)strtoul(StringHelper::Split(reader->Attribute("RangeEnd"), "0x")[1].c_str(), NULL, 16); + rangeEnd = (uint32_t)strtoul( + StringHelper::Split(reader->Attribute("RangeEnd"), "0x")[1].c_str(), NULL, 16); if (reader->Attribute("Segment") != NULL) segment = strtol(reader->Attribute("Segment"), NULL, 10); if (segment != -1) { - //printf("Adding Segment %i\n", segment); + // printf("Adding Segment %i\n", segment); Globals::Instance->AddSegment(segment); } string folderName = basePath + "/" + Path::GetFileNameWithoutExtension(name); - + if (mode == ZFileMode::Extract) { if (!File::Exists(basePath + "/" + name)) - throw StringHelper::Sprintf("Error! File %s does not exist.", (basePath + "/" + name).c_str()); + throw StringHelper::Sprintf("Error! File %s does not exist.", + (basePath + "/" + name).c_str()); rawData = File::ReadAllBytes(basePath + "/" + name); } int rawDataIndex = 0; - for (XMLElement* child = reader->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = reader->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { if (child->Attribute("Offset") != NULL) - rawDataIndex = strtol(StringHelper::Split(child->Attribute("Offset"), "0x")[1].c_str(), NULL, 16); + rawDataIndex = + strtol(StringHelper::Split(child->Attribute("Offset"), "0x")[1].c_str(), NULL, 16); if (Globals::Instance->verbosity >= VERBOSITY_INFO) printf("%s: 0x%06X\n", child->Attribute("Name"), rawDataIndex); @@ -163,9 +173,15 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b ZResource* dList = nullptr; if (mode == ZFileMode::Extract) - dList = ZDisplayList::ExtractFromXML(child, rawData, rawDataIndex, ZDisplayList::GetDListLength(rawData, rawDataIndex, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX), folderName); - //else - //dList = ZDisplayList::BuildFromXML(child, folderName, mode == ZFileMode::Build); + dList = ZDisplayList::ExtractFromXML( + child, rawData, rawDataIndex, + ZDisplayList::GetDListLength(rawData, rawDataIndex, + Globals::Instance->game == ZGame::OOT_SW97 ? + DListType::F3DEX : + DListType::F3DZEX), + folderName); + // else + // dList = ZDisplayList::BuildFromXML(child, folderName, mode == ZFileMode::Build); else dList = ZBlob::BuildFromXML(child, folderName, mode == ZFileMode::Build); @@ -180,7 +196,8 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b ZRoom* room = nullptr; if (mode == ZFileMode::Extract) - room = ZRoom::ExtractFromXML(child, rawData, rawDataIndex, folderName, this, Globals::Instance->lastScene); + room = ZRoom::ExtractFromXML(child, rawData, rawDataIndex, folderName, this, + Globals::Instance->lastScene); if (string(child->Name()) == "Scene") { @@ -226,6 +243,23 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b rawDataIndex += anim->GetRawDataSize(); } + else if (string(child->Name()) == "CurveAnimation") + { + ZCurveAnimation* anim = nullptr; + + if (mode == ZFileMode::Extract) + { + anim = + ZCurveAnimation::ExtractFromXML(child, rawData, rawDataIndex, folderName, this); + } + + if (anim == nullptr) + { + throw std::runtime_error("Couldn't create ZCurveAnimation."); + } + resources.push_back(anim); + rawDataIndex += anim->GetRawDataSize(); + } else if (string(child->Name()) == "Skeleton") { ZSkeleton* skeleton = nullptr; @@ -233,6 +267,10 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b if (mode == ZFileMode::Extract) skeleton = ZSkeleton::FromXML(child, rawData, rawDataIndex, folderName, this); + if (skeleton == nullptr) + { + throw std::runtime_error("Couldn't create ZSkeleton."); + } resources.push_back(skeleton); rawDataIndex += skeleton->GetRawDataSize(); } @@ -243,23 +281,27 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b if (mode == ZFileMode::Extract) limb = ZLimb::FromXML(child, rawData, rawDataIndex, folderName, this); + if (limb == nullptr) + { + throw std::runtime_error("Couldn't create ZLimb."); + } resources.push_back(limb); - rawDataIndex += limb->GetRawDataSize(); } else if (string(child->Name()) == "Symbol") { - ZResource* res = nullptr; + ZSymbol* symbol = nullptr; if (mode == ZFileMode::Extract) { - res = new ZResource(); - res->SetName(child->Attribute("Name")); - res->SetRawDataIndex(rawDataIndex); - res->outputDeclaration = false; + symbol = ZSymbol::ExtractFromXML(child, rawData, rawDataIndex, this); } - resources.push_back(res); + if (symbol == nullptr) + { + throw std::runtime_error("Couldn't create ZSymbol."); + } + resources.push_back(symbol); } else if (string(child->Name()) == "Collision") { @@ -364,7 +406,8 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b else { std::cerr << "ERROR bad type\n"; - printf("Encountered unknown resource type: %s on line: %d\n", child->Name(), child->GetLineNum()); + printf("Encountered unknown resource type: %s on line: %d\n", child->Name(), + child->GetLineNum()); std::exit(EXIT_FAILURE); } } @@ -388,9 +431,9 @@ void ZFile::BuildResources() for (ZResource* res : resources) { - //Console.WriteLine("Building resource " + res.GetName()); + // Console.WriteLine("Building resource " + res.GetName()); memcpy(file.data() + fileIndex, res->GetRawData().data(), res->GetRawData().size()); - //Array.Copy(res.GetRawData(), 0, file, fileIndex, res.GetRawData().Length); + // Array.Copy(res.GetRawData(), 0, file, fileIndex, res.GetRawData().Length); fileIndex += res->GetRawData().size(); } @@ -427,8 +470,8 @@ void ZFile::ExtractResources(string outputDir) { string folderName = Path::GetFileNameWithoutExtension(outputPath); - //printf("DIR CHECK: %s\n", folderName.c_str()); - //printf("OUT CHECK: %s\n", outputDir.c_str()); + // printf("DIR CHECK: %s\n", folderName.c_str()); + // printf("OUT CHECK: %s\n", outputDir.c_str()); if (!Directory::Exists(outputPath)) Directory::CreateDirectory(outputPath); @@ -443,8 +486,8 @@ void ZFile::ExtractResources(string outputDir) { if (Globals::Instance->verbosity >= VERBOSITY_INFO) printf("Saving resource %s\n", res->GetName().c_str()); - - res->CalcHash(); // TEST + + res->CalcHash(); // TEST res->Save(outputPath); } @@ -457,7 +500,8 @@ void ZFile::AddResource(ZResource* res) resources.push_back(res); } -Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size, std::string varType, std::string varName, std::string body) +Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size, + std::string varType, std::string varName, std::string body) { #if _DEBUG if (declarations.find(address) != declarations.end()) @@ -473,7 +517,9 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm return decl; } -Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, DeclarationPadding padding, uint32_t size, string varType, string varName, std::string body) +Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, + DeclarationPadding padding, uint32_t size, string varType, + string varName, std::string body) { #if _DEBUG if (declarations.find(address) != declarations.end()) @@ -484,11 +530,14 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm AddDeclarationDebugChecks(address); - declarations[address] = new Declaration(alignment, padding, size, varType, varName, false, body); + declarations[address] = + new Declaration(alignment, padding, size, varType, varName, false, body); return declarations[address]; } -Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, uint32_t size, std::string varType, std::string varName, int arrayItemCnt, std::string body) +Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, + uint32_t size, std::string varType, std::string varName, + int arrayItemCnt, std::string body) { #if _DEBUG if (declarations.find(address) != declarations.end()) @@ -499,12 +548,14 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a AddDeclarationDebugChecks(address); - declarations[address] = new Declaration(alignment, size, varType, varName, true, arrayItemCnt, body); + declarations[address] = + new Declaration(alignment, size, varType, varName, true, arrayItemCnt, body); return declarations[address]; } - -Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, DeclarationPadding padding, uint32_t size, string varType, string varName, int arrayItemCnt, std::string body) +Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, + DeclarationPadding padding, uint32_t size, string varType, + string varName, int arrayItemCnt, std::string body) { #if _DEBUG if (declarations.find(address) != declarations.end()) @@ -515,11 +566,11 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a AddDeclarationDebugChecks(address); - declarations[address] = new Declaration(alignment, padding, size, varType, varName, true, arrayItemCnt, body); + declarations[address] = + new Declaration(alignment, padding, size, varType, varName, true, arrayItemCnt, body); return declarations[address]; } - Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address) { AddDeclarationDebugChecks(address); @@ -535,12 +586,14 @@ Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, string varName) AddDeclarationDebugChecks(address); if (declarations.find(address) == declarations.end()) - declarations[address] = new Declaration(DeclarationAlignment::None, 0, "", varName, false, ""); + declarations[address] = + new Declaration(DeclarationAlignment::None, 0, "", varName, false, ""); return declarations[address]; } -Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, uint32_t size, string varType, string varName) +Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, uint32_t size, + string varType, string varName) { AddDeclarationDebugChecks(address); @@ -550,7 +603,9 @@ Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, return declarations[address]; } -Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string includePath, uint32_t size, std::string varType, std::string varName, int arrayItemCnt) +Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string includePath, + uint32_t size, std::string varType, + std::string varName, int arrayItemCnt) { #if _DEBUG if (declarations.find(address) != declarations.end()) @@ -582,7 +637,9 @@ void ZFile::AddDeclarationDebugChecks(uint32_t address) std::string ZFile::GetDeclarationName(uint32_t address) { - return GetDeclarationName(address, "ERROR_COULD_NOT_FIND_DECLARATION"); // Note: For now that default message is just for testing + return GetDeclarationName(address, + "ERROR_COULD_NOT_FIND_DECLARATION"); // Note: For now that default + // message is just for testing } std::string ZFile::GetDeclarationName(uint32_t address, std::string defaultResult) @@ -646,7 +703,7 @@ void ZFile::GenerateSourceFiles(string outputDir) if (res->IsExternalResource()) { - //cout << "EXTERN\n"; + // cout << "EXTERN\n"; string path = Path::GetFileNameWithoutExtension(res->GetName()).c_str(); while (StringHelper::EndsWith(outputDir, "/")) @@ -658,16 +715,19 @@ void ZFile::GenerateSourceFiles(string outputDir) if (res->GetResourceType() != ZResourceType::Texture) declType = "u8"; - AddDeclarationIncludeArray(res->GetRawDataIndex(), StringHelper::Sprintf("%s/%s.%s.inc.c", - outputDir.c_str(), Path::GetFileNameWithoutExtension(res->GetOutName()).c_str(), res->GetExternalExtension().c_str()), res->GetRawDataSize(), - declType, res->GetName(), 0); - - - //File::WriteAllText("build/" + outputDir + "/" + Path::GetFileNameWithoutExtension(res->GetName()) + ".inc.c", resSrc); + AddDeclarationIncludeArray( + res->GetRawDataIndex(), + StringHelper::Sprintf("%s/%s.%s.inc.c", outputDir.c_str(), + Path::GetFileNameWithoutExtension(res->GetOutName()).c_str(), + res->GetExternalExtension().c_str()), + res->GetRawDataSize(), declType, res->GetName(), 0); + + // File::WriteAllText("build/" + outputDir + "/" + + // Path::GetFileNameWithoutExtension(res->GetName()) + ".inc.c", resSrc); } else { - //cout << "NOT EXTERN\n"; + // cout << "NOT EXTERN\n"; sourceOutput += resSrc; } @@ -680,18 +740,18 @@ void ZFile::GenerateSourceFiles(string outputDir) while (StringHelper::EndsWith(outputDir, "/")) outputDir = outputDir.substr(0, outputDir.length() - 1); - //string buildPath = "build/" + outputDir + "/" + "basefile.txt"; + // string buildPath = "build/" + outputDir + "/" + "basefile.txt"; string outPath = outputDir + "/" + Path::GetFileNameWithoutExtension(name) + ".c"; - //printf("WRITING %s\n", buildPath.c_str()); + // printf("WRITING %s\n", buildPath.c_str()); - //if (!Directory::Exists(Path::GetPath(outPath))) - //Directory::CreateDirectory(Path::GetPath(outPath)); + // if (!Directory::Exists(Path::GetPath(outPath))) + // Directory::CreateDirectory(Path::GetPath(outPath)); - //if (!Directory::Exists(Path::GetPath(buildPath))) - //Directory::CreateDirectory(Path::GetPath(buildPath)); + // if (!Directory::Exists(Path::GetPath(buildPath))) + // Directory::CreateDirectory(Path::GetPath(buildPath)); File::WriteAllText(outPath, sourceOutput); - //File::WriteAllText(buildPath, outPath); + // File::WriteAllText(buildPath, outPath); // Generate Header sourceOutput = ""; @@ -707,7 +767,8 @@ void ZFile::GenerateSourceFiles(string outputDir) sourceOutput += ProcessExterns(); - File::WriteAllText(outputDir + "/" + Path::GetFileNameWithoutExtension(name) + ".h", sourceOutput); + File::WriteAllText(outputDir + "/" + Path::GetFileNameWithoutExtension(name) + ".h", + sourceOutput); } void ZFile::GenerateHLIntermediette() @@ -727,7 +788,8 @@ void ZFile::GenerateHLIntermediette() std::string ZFile::GetHeaderInclude() { - return StringHelper::Sprintf("#include \"%s\"\n\n", (Path::GetFileNameWithoutExtension(name) + ".h").c_str()); + return StringHelper::Sprintf("#include \"%s\"\n\n", + (Path::GetFileNameWithoutExtension(name) + ".h").c_str()); } void ZFile::GeneratePlaceholderDeclarations() @@ -747,22 +809,16 @@ string ZFile::ProcessDeclarations() if (declarations.size() == 0) return output; - auto declarationKeysSorted = vector>(declarations.begin(), declarations.end()); - sort(declarationKeysSorted.begin(), declarationKeysSorted.end(), [](const auto& lhs, const auto& rhs) - { - return lhs.first < rhs.first; - }); - // Account for padding/alignment - int lastAddr = 0; - int lastSize = 0; + uint32_t lastAddr = 0; + uint32_t lastSize = 0; - //printf("RANGE START: 0x%06X - RANGE END: 0x%06X\n", rangeStart, rangeEnd); + // 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... - //pair lastItem = declarationKeysSorted[0]; + // pair lastItem = declarationKeysSorted[0]; - //for (int i = 1; i < declarationKeysSorted.size(); i++) + // for (int i = 1; i < declarationKeysSorted.size(); i++) //{ // pair curItem = declarationKeysSorted[i]; @@ -789,41 +845,41 @@ string ZFile::ProcessDeclarations() // lastItem = curItem; //} - for (pair item : declarations) + for (pair item : declarations) { ProcessDeclarationText(item.second); } - for (pair item : declarationKeysSorted) + for (pair item : declarations) { - while (declarations[item.first]->size % 4 != 0) + while (item.second->size % 4 != 0) { - declarations[item.first]->size++; + item.second->size++; } if (lastAddr != 0) { if (item.second->alignment == DeclarationAlignment::Align16) { - int lastAddrSizeTest = declarations[lastAddr]->size; + // int lastAddrSizeTest = declarations[lastAddr]->size; int curPtr = lastAddr + declarations[lastAddr]->size; while (curPtr % 4 != 0) { declarations[lastAddr]->size++; - //declarations[item.first]->size++; + // item.second->size++; curPtr++; } /*while (curPtr % 16 != 0) { - char buffer[2048]; + char buffer[2048]; - sprintf(buffer, "static u32 align%02X = 0;\n", curPtr); - declarations[item.first]->text = buffer + declarations[item.first]->text; + sprintf(buffer, "static u32 align%02X = 0;\n", curPtr); + item.second->text = buffer + item.second->text; - declarations[lastAddr]->size += 4; - curPtr += 4; + declarations[lastAddr]->size += 4; + curPtr += 4; }*/ } else if (item.second->alignment == DeclarationAlignment::Align8) @@ -833,8 +889,7 @@ string ZFile::ProcessDeclarations() while (curPtr % 4 != 0) { declarations[lastAddr]->size++; - //item.second->size++; - //declarations[item.first]->size++; + // item.second->size++; curPtr++; } @@ -843,11 +898,10 @@ string ZFile::ProcessDeclarations() char buffer[2048]; sprintf(buffer, "static u32 align%02X = 0;\n", curPtr); - declarations[item.first]->preText = buffer + declarations[item.first]->preText; + item.second->preText = buffer + item.second->preText; declarations[lastAddr]->size += 4; - //item.second->size += 4; - //declarations[item.first]->size += 4; + // item.second->size += 4; curPtr += 4; } } @@ -865,7 +919,7 @@ string ZFile::ProcessDeclarations() while (curPtr % 16 != 0) { - declarations[item.first]->postText += StringHelper::Sprintf("static u32 pad%02X = 0;\n", curPtr); + item.second->postText += StringHelper::Sprintf("static u32 pad%02X = 0;\n", curPtr); item.second->size += 4; curPtr += 4; @@ -878,27 +932,31 @@ string ZFile::ProcessDeclarations() // Handle unaccounted data lastAddr = 0; lastSize = 0; - for (pair item : declarationKeysSorted) + for (pair item : declarations) { if (item.first >= rangeStart && item.first < rangeEnd) { - if (lastAddr != 0 && declarations.find(lastAddr) != declarations.end() && lastAddr + declarations[lastAddr]->size > item.first) + if (lastAddr != 0 && declarations.find(lastAddr) != declarations.end() && + lastAddr + declarations[lastAddr]->size > item.first) { - printf("WARNING: Intersection detected from 0x%06X:0x%06X, conflicts with 0x%06X\n", lastAddr, lastAddr + declarations[lastAddr]->size, item.first); + printf("WARNING: Intersection detected from 0x%06X:0x%06X, conflicts with 0x%06X\n", + lastAddr, lastAddr + declarations[lastAddr]->size, item.first); } uint8_t* rawDataArr = rawData.data(); - if (lastAddr + lastSize != item.first && lastAddr >= rangeStart && lastAddr + lastSize < rangeEnd) + if (lastAddr + lastSize != item.first && lastAddr >= rangeStart && + lastAddr + lastSize < rangeEnd) { - //int diff = item.first - (lastAddr + declarations[lastAddr]->size); + // int diff = item.first - (lastAddr + declarations[lastAddr]->size); int diff = item.first - (lastAddr + lastSize); string src = " "; for (int i = 0; i < diff; i++) { - //src += StringHelper::Sprintf("0x%02X, ", rawDataArr[lastAddr + declarations[lastAddr]->size + i]); + // src += StringHelper::Sprintf("0x%02X, ", rawDataArr[lastAddr + + // declarations[lastAddr]->size + i]); src += StringHelper::Sprintf("0x%02X, ", rawDataArr[lastAddr + lastSize + i]); if ((i % 16 == 15) && (i != (diff - 1))) @@ -909,8 +967,14 @@ string ZFile::ProcessDeclarations() { if (diff > 0) { - //AddDeclarationArray(lastAddr + declarations[lastAddr]->size, DeclarationAlignment::None, diff, "static u8", StringHelper::Sprintf("unaccounted_%06X", lastAddr + declarations[lastAddr]->size), diff, src); - AddDeclarationArray(lastAddr + lastSize, DeclarationAlignment::None, diff, "static u8", StringHelper::Sprintf("unaccounted_%06X", lastAddr + lastSize), diff, src); + // AddDeclarationArray(lastAddr + declarations[lastAddr]->size, + // DeclarationAlignment::None, diff, "static u8", + // StringHelper::Sprintf("unaccounted_%06X", lastAddr + + // declarations[lastAddr]->size), diff, src); + AddDeclarationArray( + lastAddr + lastSize, DeclarationAlignment::None, diff, "static u8", + StringHelper::Sprintf("unaccounted_%06X", lastAddr + lastSize), diff, + src); } } } @@ -921,7 +985,9 @@ string ZFile::ProcessDeclarations() } // TODO: THIS CONTAINS REDUNDANCIES. CLEAN THIS UP! - if (lastAddr + declarations[lastAddr]->size < rawData.size() && lastAddr + declarations[lastAddr]->size >= rangeStart && lastAddr + declarations[lastAddr]->size < rangeEnd) + if (lastAddr + declarations[lastAddr]->size < rawData.size() && + lastAddr + declarations[lastAddr]->size >= rangeStart && + lastAddr + declarations[lastAddr]->size < rangeEnd) { int diff = (int)(rawData.size() - (lastAddr + declarations[lastAddr]->size)); @@ -929,7 +995,8 @@ string ZFile::ProcessDeclarations() for (int i = 0; i < diff; i++) { - src += StringHelper::Sprintf("0x%02X, ", rawData[lastAddr + declarations[lastAddr]->size + i]); + src += StringHelper::Sprintf("0x%02X, ", + rawData[lastAddr + declarations[lastAddr]->size + i]); if (i % 16 == 15) src += "\n "; @@ -939,34 +1006,37 @@ string ZFile::ProcessDeclarations() { if (diff > 0) { - AddDeclarationArray(lastAddr + declarations[lastAddr]->size, DeclarationAlignment::None, diff, "static u8", StringHelper::Sprintf("unaccounted_%06X", lastAddr + declarations[lastAddr]->size), - diff, src); + AddDeclarationArray(lastAddr + declarations[lastAddr]->size, + DeclarationAlignment::None, diff, "static u8", + StringHelper::Sprintf("unaccounted_%06X", + lastAddr + declarations[lastAddr]->size), + diff, src); } } } // Go through include declarations - declarationKeysSorted = vector>(declarations.begin(), declarations.end()); - sort(declarationKeysSorted.begin(), declarationKeysSorted.end(), [](const auto& lhs, const auto& rhs) - { - return lhs.first < rhs.first; - }); - // First, handle the prototypes (static only for now) int protoCnt = 0; - for (pair item : declarationKeysSorted) + for (pair item : declarations) { - if (item.second->includePath == "" && StringHelper::StartsWith(item.second->varType, "static ") && !StringHelper::StartsWith(item.second->varName, "unaccounted_")) + if (item.second->includePath == "" && + StringHelper::StartsWith(item.second->varType, "static ") && + !StringHelper::StartsWith(item.second->varName, "unaccounted_")) { if (item.second->isArray) { if (item.second->arrayItemCnt == 0) - output += StringHelper::Sprintf("%s %s[];\n", item.second->varType.c_str(), item.second->varName.c_str()); + output += StringHelper::Sprintf("%s %s[];\n", item.second->varType.c_str(), + item.second->varName.c_str()); else - output += StringHelper::Sprintf("%s %s[%i];\n", item.second->varType.c_str(), item.second->varName.c_str(), item.second->arrayItemCnt); + output += StringHelper::Sprintf("%s %s[%i];\n", item.second->varType.c_str(), + item.second->varName.c_str(), + item.second->arrayItemCnt); } else - output += StringHelper::Sprintf("%s %s;\n", item.second->varType.c_str(), item.second->varName.c_str()); + output += StringHelper::Sprintf("%s %s;\n", item.second->varType.c_str(), + item.second->varName.c_str()); protoCnt++; } @@ -976,16 +1046,20 @@ string ZFile::ProcessDeclarations() output += "\n"; // Next, output the actual declarations - for (pair item : declarationKeysSorted) + for (pair item : declarations) { - if (item.first < rangeStart || item.first >= rangeEnd) { + if (item.first < rangeStart || item.first >= rangeEnd) + { continue; } if (item.second->includePath != "") { - //output += StringHelper::Sprintf("#include \"%s\"\n", item.second->includePath.c_str()); - output += StringHelper::Sprintf("%s %s[] = {\n#include \"%s\"\n};\n\n", item.second->varType.c_str(), item.second->varName.c_str(), item.second->includePath.c_str()); + // output += StringHelper::Sprintf("#include \"%s\"\n", + // item.second->includePath.c_str()); + output += StringHelper::Sprintf( + "%s %s[] = {\n#include \"%s\"\n};\n\n", item.second->varType.c_str(), + item.second->varName.c_str(), item.second->includePath.c_str()); } else if (item.second->varType != "") { @@ -995,15 +1069,19 @@ string ZFile::ProcessDeclarations() if (item.second->isArray) { if (item.second->arrayItemCnt == 0) - output += StringHelper::Sprintf("%s %s[] = {\n", item.second->varType.c_str(), item.second->varName.c_str()); + output += StringHelper::Sprintf("%s %s[] = {\n", item.second->varType.c_str(), + item.second->varName.c_str()); else - output += StringHelper::Sprintf("%s %s[%i] = {\n", item.second->varType.c_str(), item.second->varName.c_str(), item.second->arrayItemCnt); + output += StringHelper::Sprintf("%s %s[%i] = {\n", item.second->varType.c_str(), + item.second->varName.c_str(), + item.second->arrayItemCnt); output += item.second->text + "\n"; } else { - output += StringHelper::Sprintf("%s %s = { ", item.second->varType.c_str(), item.second->varName.c_str()); + output += StringHelper::Sprintf("%s %s = { ", item.second->varType.c_str(), + item.second->varName.c_str()); output += item.second->text; } @@ -1013,7 +1091,7 @@ string ZFile::ProcessDeclarations() output += " };"; output += " " + item.second->rightText + "\n\n"; - + if (item.second->postText != "") output += item.second->postText + "\n"; } @@ -1026,11 +1104,11 @@ string ZFile::ProcessDeclarations() void ZFile::ProcessDeclarationText(Declaration* decl) { - int refIndex = 0; + size_t refIndex = 0; if (decl->references.size() > 0) { - for (int i = 0; i < decl->text.size() - 1; i++) + for (size_t i = 0; i < decl->text.size() - 1; i++) { char c = decl->text[i]; char c2 = decl->text[i + 1]; @@ -1052,11 +1130,14 @@ void ZFile::ProcessDeclarationText(Declaration* decl) int itemSize = refDecl->size / refDecl->arrayItemCnt; int itemIndex = (decl->references[refIndex] - refDeclAddr) / itemSize; - decl->text.replace(i, 2, StringHelper::Sprintf("&%s[%i]", refDecl->varName.c_str(), itemIndex)); + decl->text.replace(i, 2, + StringHelper::Sprintf( + "&%s[%i]", refDecl->varName.c_str(), itemIndex)); } else { - decl->text.replace(i, 2, StringHelper::Sprintf("ERROR ARRAYITEMCNT = 0")); + decl->text.replace(i, 2, + StringHelper::Sprintf("ERROR ARRAYITEMCNT = 0")); } } else @@ -1077,29 +1158,30 @@ string ZFile::ProcessExterns() { string output = ""; - auto declarationKeysSorted = vector>(declarations.begin(), declarations.end()); - sort(declarationKeysSorted.begin(), declarationKeysSorted.end(), [](const auto& lhs, const auto& rhs) + for (pair item : declarations) { - return lhs.first < rhs.first; - }); - - for (pair item : declarationKeysSorted) - { - if (item.first < rangeStart || item.first >= rangeEnd) { + if (item.first < rangeStart || item.first >= rangeEnd) + { continue; } - if (!StringHelper::StartsWith(item.second->varType, "static ") && item.second->varType != "")// && item.second->includePath == "") + if (!StringHelper::StartsWith(item.second->varType, "static ") && + item.second->varType != "") // && item.second->includePath == "") { if (item.second->isArray) { if (item.second->arrayItemCnt == 0) - output += StringHelper::Sprintf("extern %s %s[];\n", item.second->varType.c_str(), item.second->varName.c_str()); + output += + StringHelper::Sprintf("extern %s %s[];\n", item.second->varType.c_str(), + item.second->varName.c_str()); else - output += StringHelper::Sprintf("extern %s %s[%i];\n", item.second->varType.c_str(), item.second->varName.c_str(), item.second->arrayItemCnt); + output += StringHelper::Sprintf( + "extern %s %s[%i];\n", item.second->varType.c_str(), + item.second->varName.c_str(), item.second->arrayItemCnt); } else - output += StringHelper::Sprintf("extern %s %s;\n", item.second->varType.c_str(), item.second->varName.c_str()); + output += StringHelper::Sprintf("extern %s %s;\n", item.second->varType.c_str(), + item.second->varName.c_str()); } } diff --git a/tools/ZAPD/ZAPD/ZFile.h b/tools/ZAPD/ZAPD/ZFile.h index ca1c0cad97..668d9c6ea0 100644 --- a/tools/ZAPD/ZAPD/ZFile.h +++ b/tools/ZAPD/ZAPD/ZFile.h @@ -1,9 +1,9 @@ #pragma once -#include #include -#include "tinyxml2.h" +#include #include "ZResource.h" +#include "tinyxml2.h" enum class ZFileMode { @@ -28,13 +28,14 @@ enum class ZGame class ZFile { public: - std::map declarations; + std::map declarations; std::string defines; std::vector resources; uint32_t baseAddress, rangeStart, rangeEnd; ZFile(std::string nOutPath, std::string nName); - ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, std::string nBasePath, std::string nOutPath, std::string filename, bool placeholderMode); + ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, std::string nBasePath, std::string nOutPath, + std::string filename, bool placeholderMode); ~ZFile(); std::string GetVarName(int address); @@ -44,14 +45,24 @@ public: void BuildSourceFile(std::string outputDir); void AddResource(ZResource* res); - Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size, std::string varType, std::string varName, std::string body); - Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, DeclarationPadding padding, uint32_t size, std::string varType, std::string varName, std::string body); - Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, uint32_t size, std::string varType, std::string varName, int arrayItemCnt, std::string body); - Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, DeclarationPadding padding, uint32_t size, std::string varType, std::string varName, int arrayItemCnt, std::string body); + Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size, + std::string varType, std::string varName, std::string body); + Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, + DeclarationPadding padding, uint32_t size, std::string varType, + std::string varName, std::string body); + Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, + uint32_t size, std::string varType, std::string varName, + int arrayItemCnt, std::string body); + Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, + DeclarationPadding padding, uint32_t size, std::string varType, + std::string varName, int arrayItemCnt, std::string body); Declaration* AddDeclarationPlaceholder(uint32_t address); Declaration* AddDeclarationPlaceholder(uint32_t address, std::string varName); - Declaration* AddDeclarationInclude(uint32_t address, std::string includePath, uint32_t size, std::string varType, std::string varName); - Declaration* AddDeclarationIncludeArray(uint32_t address, std::string includePath, uint32_t size, std::string varType, std::string varName, int arrayItemCnt); + Declaration* AddDeclarationInclude(uint32_t address, std::string includePath, uint32_t size, + std::string varType, std::string varName); + Declaration* AddDeclarationIncludeArray(uint32_t address, std::string includePath, + uint32_t size, std::string varType, std::string varName, + int arrayItemCnt); std::string GetDeclarationName(uint32_t address); std::string GetDeclarationName(uint32_t address, std::string defaultResult); Declaration* GetDeclaration(uint32_t address); @@ -69,7 +80,8 @@ protected: std::string sourceOutput; ZFile(); - void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename, bool placeholderMode); + void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename, + bool placeholderMode); void GenerateSourceFiles(std::string outputDir); void GenerateHLIntermediette(); void AddDeclarationDebugChecks(uint32_t address); diff --git a/tools/ZAPD/ZAPD/ZLimb.cpp b/tools/ZAPD/ZAPD/ZLimb.cpp index b7e63988cd..087d496458 100644 --- a/tools/ZAPD/ZAPD/ZLimb.cpp +++ b/tools/ZAPD/ZAPD/ZLimb.cpp @@ -1,12 +1,11 @@ #include "ZLimb.h" -#include "BitConverter.h" -#include "StringHelper.h" -#include "Globals.h" #include +#include "BitConverter.h" +#include "Globals.h" +#include "StringHelper.h" using namespace std; - Struct_800A57C0::Struct_800A57C0(const std::vector& rawData, uint32_t fileOffset) { unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00); @@ -17,15 +16,16 @@ Struct_800A57C0::Struct_800A57C0(const std::vector& rawData, uint32_t f unk_8 = BitConverter::ToInt8BE(rawData, fileOffset + 0x08); unk_9 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x09); } -Struct_800A57C0::Struct_800A57C0(const std::vector& rawData, uint32_t fileOffset, size_t index) +Struct_800A57C0::Struct_800A57C0(const std::vector& rawData, uint32_t fileOffset, + size_t index) : Struct_800A57C0(rawData, fileOffset + index * GetRawDataSize()) { } std::string Struct_800A57C0::GetSourceOutputCode() const { - return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X", - unk_0, unk_2, unk_4, unk_6, unk_7, unk_8, unk_9); + return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X", unk_0, unk_2, unk_4, unk_6, + unk_7, unk_8, unk_9); } size_t Struct_800A57C0::GetRawDataSize() @@ -38,7 +38,6 @@ std::string Struct_800A57C0::GetSourceTypeName() return "Struct_800A57C0"; } - Struct_800A598C_2::Struct_800A598C_2(const std::vector& rawData, uint32_t fileOffset) { unk_0 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x00); @@ -47,15 +46,15 @@ Struct_800A598C_2::Struct_800A598C_2(const std::vector& rawData, uint32 z = BitConverter::ToInt16BE(rawData, fileOffset + 0x06); unk_8 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x08); } -Struct_800A598C_2::Struct_800A598C_2(const std::vector& rawData, uint32_t fileOffset, size_t index) +Struct_800A598C_2::Struct_800A598C_2(const std::vector& rawData, uint32_t fileOffset, + size_t index) : Struct_800A598C_2(rawData, fileOffset + index * GetRawDataSize()) { } std::string Struct_800A598C_2::GetSourceOutputCode() const { - return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", - unk_0, x, y, z, unk_8); + return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", unk_0, x, y, z, unk_8); } size_t Struct_800A598C_2::GetRawDataSize() @@ -68,8 +67,8 @@ std::string Struct_800A598C_2::GetSourceTypeName() return "Struct_800A598C_2"; } - -Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector& rawData, uint32_t fileOffset) +Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector& rawData, + uint32_t fileOffset) : parent(parent) { unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00); @@ -78,21 +77,26 @@ Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector& rawD unk_8 = BitConverter::ToUInt32BE(rawData, fileOffset + 0x08); unk_C = BitConverter::ToUInt32BE(rawData, fileOffset + 0x0C); - if (unk_8 != 0) { + if (unk_8 != 0) + { uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - for (size_t i = 0; i < unk_0; i++) { + for (size_t i = 0; i < unk_0; i++) + { unk_8_arr.emplace_back(rawData, unk_8_Offset, i); } } - if (unk_C != 0) { + if (unk_C != 0) + { uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress); - for (size_t i = 0; i < unk_2; i++) { + for (size_t i = 0; i < unk_2; i++) + { unk_C_arr.emplace_back(rawData, unk_C_Offset, i); } } } -Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector& rawData, uint32_t fileOffset, size_t index) +Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector& rawData, + uint32_t fileOffset, size_t index) : Struct_800A598C(parent, rawData, fileOffset + index * GetRawDataSize()) { } @@ -101,52 +105,62 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix) { string entryStr; - if (unk_8 != 0) { + if (unk_8 != 0) + { uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - string unk_8_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset); + string unk_8_Str = + StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), + Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset); size_t arrayItemCnt = unk_8_arr.size(); entryStr = ""; size_t i = 0; - for (auto& child: unk_8_arr) { - entryStr += StringHelper::Sprintf(" { %s },%s", - child.GetSourceOutputCode().c_str(), - (++i < arrayItemCnt) ? "\n" : ""); + for (auto& child : unk_8_arr) + { + entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(), + (++i < arrayItemCnt) ? "\n" : ""); } Declaration* decl = parent->GetDeclaration(unk_8_Offset); - if (decl == nullptr) { - parent->AddDeclarationArray( - unk_8_Offset, DeclarationAlignment::None, - arrayItemCnt * Struct_800A57C0::GetRawDataSize(), Struct_800A57C0::GetSourceTypeName(), - unk_8_Str, arrayItemCnt, entryStr); + if (decl == nullptr) + { + parent->AddDeclarationArray(unk_8_Offset, DeclarationAlignment::None, + arrayItemCnt * Struct_800A57C0::GetRawDataSize(), + Struct_800A57C0::GetSourceTypeName(), unk_8_Str, + arrayItemCnt, entryStr); } - else { + else + { decl->text = entryStr; } } - if (unk_C != 0) { + if (unk_C != 0) + { uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress); - string unk_C_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset); + string unk_C_Str = + StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), + Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset); size_t arrayItemCnt = unk_C_arr.size(); entryStr = ""; size_t i = 0; - for (auto& child: unk_C_arr) { - entryStr += StringHelper::Sprintf(" { %s },%s", - child.GetSourceOutputCode().c_str(), - (++i < arrayItemCnt) ? "\n" : ""); + for (auto& child : unk_C_arr) + { + entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(), + (++i < arrayItemCnt) ? "\n" : ""); } Declaration* decl = parent->GetDeclaration(unk_C_Offset); - if (decl == nullptr) { - parent->AddDeclarationArray( - unk_C_Offset, DeclarationAlignment::None, - arrayItemCnt * Struct_800A598C_2::GetRawDataSize(), Struct_800A598C_2::GetSourceTypeName(), - unk_C_Str, arrayItemCnt, entryStr); + if (decl == nullptr) + { + parent->AddDeclarationArray(unk_C_Offset, DeclarationAlignment::None, + arrayItemCnt * Struct_800A598C_2::GetRawDataSize(), + Struct_800A598C_2::GetSourceTypeName(), unk_C_Str, + arrayItemCnt, entryStr); } - else { + else + { decl->text = entryStr; } } @@ -157,21 +171,27 @@ std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) cons string entryStr; string unk_8_Str = "NULL"; - if (unk_8 != 0) { + if (unk_8 != 0) + { uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - unk_8_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset); + unk_8_Str = + StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), + Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset); } string unk_C_Str = "NULL"; - if (unk_C != 0) { + if (unk_C != 0) + { uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress); - unk_C_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset); + unk_C_Str = + StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), + Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset); } entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n", - unk_8_Str.c_str(), unk_C_Str.c_str()); - entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, - unk_8_Str.c_str(), unk_C_Str.c_str()); + unk_8_Str.c_str(), unk_C_Str.c_str()); + entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(), + unk_C_Str.c_str()); return entryStr; } @@ -186,8 +206,8 @@ std::string Struct_800A598C::GetSourceTypeName() return "Struct_800A598C"; } - -Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector& nRawData, uint32_t fileOffset) +Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector& nRawData, + uint32_t fileOffset) : parent(parent), rawData(nRawData) { unk_0 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x00); @@ -195,14 +215,17 @@ Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector& nRaw unk_4 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x04); unk_8 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x08); - if (unk_4 != 0) { + if (unk_4 != 0) + { uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); - for (size_t i = 0; i < unk_2; i++) { + for (size_t i = 0; i < unk_2; i++) + { unk_4_arr.emplace_back(parent, nRawData, unk_4_Offset, i); } } } -Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector& rawData, uint32_t fileOffset, size_t index) +Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector& rawData, + uint32_t fileOffset, size_t index) : Struct_800A5E28(parent, rawData, fileOffset + index * GetRawDataSize()) { } @@ -214,38 +237,47 @@ Struct_800A5E28::~Struct_800A5E28() void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix) { - if (unk_4 != 0) { + if (unk_4 != 0) + { uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); - string unk_4_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset); + string unk_4_Str = + StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), + Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset); string entryStr = ""; uint16_t arrayItemCnt = unk_4_arr.size(); size_t i = 0; - for (auto& child: unk_4_arr) { + for (auto& child : unk_4_arr) + { child.PreGenSourceFiles(prefix); - entryStr += StringHelper::Sprintf(" { %s },%s", - child.GetSourceOutputCode(prefix).c_str(), - (++i < arrayItemCnt) ? "\n" : ""); + entryStr += + StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode(prefix).c_str(), + (++i < arrayItemCnt) ? "\n" : ""); } Declaration* decl = parent->GetDeclaration(unk_4_Offset); - if (decl == nullptr) { - parent->AddDeclarationArray( - unk_4_Offset, DeclarationAlignment::None, - arrayItemCnt * Struct_800A598C::GetRawDataSize(), Struct_800A598C::GetSourceTypeName(), - unk_4_Str, arrayItemCnt, entryStr); + if (decl == nullptr) + { + parent->AddDeclarationArray(unk_4_Offset, DeclarationAlignment::None, + arrayItemCnt * Struct_800A598C::GetRawDataSize(), + Struct_800A598C::GetSourceTypeName(), unk_4_Str, + arrayItemCnt, entryStr); } - else { + else + { decl->text = entryStr; } } - if (unk_8 != 0) { + if (unk_8 != 0) + { uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - int dlistLength = ZDisplayList::GetDListLength(rawData, unk_8_Offset, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); + int dlistLength = ZDisplayList::GetDListLength( + rawData, unk_8_Offset, + Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength); unk_8_dlist->parent = parent; @@ -260,33 +292,40 @@ std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) cons string entryStr = ""; string unk_4_Str = "NULL"; - if (unk_4 != 0) { + if (unk_4 != 0) + { uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); Declaration* decl = parent->GetDeclaration(unk_4_Offset); - if (decl == nullptr) { - unk_4_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset); + if (decl == nullptr) + { + unk_4_Str = + StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), + Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset); } - else { + else + { unk_4_Str = decl->varName; } } string unk_8_Str = "NULL"; - if (unk_8 != 0) { + if (unk_8 != 0) + { uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); Declaration* decl = parent->GetDeclaration(unk_8_Offset); - if (decl == nullptr) { + if (decl == nullptr) + { // Something went wrong... unk_8_Str = StringHelper::Sprintf("0x%08X", unk_8); } - else { + else + { unk_8_Str = decl->varName; } } - return StringHelper::Sprintf("\n %i, ARRAY_COUNTU(%s),\n %s, %s\n", - unk_0, unk_4_Str.c_str(), - unk_4_Str.c_str(), unk_8_Str.c_str()); + return StringHelper::Sprintf("\n %i, ARRAY_COUNTU(%s),\n %s, %s\n", unk_0, + unk_4_Str.c_str(), unk_4_Str.c_str(), unk_8_Str.c_str()); } size_t Struct_800A5E28::GetRawDataSize() @@ -299,8 +338,8 @@ std::string Struct_800A5E28::GetSourceTypeName() return "Struct_800A5E28"; } - -ZLimb::ZLimb(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, ZFile* nParent) +ZLimb::ZLimb(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, + ZFile* nParent) { rawData.assign(nRawData.begin(), nRawData.end()); rawDataIndex = nRawDataIndex; @@ -311,15 +350,18 @@ ZLimb::ZLimb(tinyxml2::XMLElement* reader, const std::vector& nRawData, ParseXML(reader); ParseRawData(); - if (type == ZLimbType::Skin) { - if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0) { + if (type == ZLimbType::Skin) + { + if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0) + { uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress); segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset); } } } -ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector& nRawData, int nRawDataIndex, ZFile* nParent) +ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector& nRawData, + int nRawDataIndex, ZFile* nParent) { rawData.assign(nRawData.begin(), nRawData.end()); rawDataIndex = nRawDataIndex; @@ -338,28 +380,45 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader) // Reading from a const char* limbType = reader->Attribute("LimbType"); - if (limbType == nullptr) { + if (limbType == nullptr) + { // Reading from a limbType = reader->Attribute("Type"); } - if (limbType == nullptr) { - fprintf(stderr, "ZLimb::ParseXML: Warning in '%s'.\n\t Missing 'LimbType' attribute in xml. Defaulting to 'Standard'.\n", name.c_str()); + if (limbType == nullptr) + { + fprintf(stderr, + "ZLimb::ParseXML: Warning in '%s'.\n\t Missing 'LimbType' attribute in xml. " + "Defaulting to 'Standard'.\n", + name.c_str()); type = ZLimbType::Standard; } - else { + else + { string limbTypeStr(limbType); - if (limbTypeStr == "Standard") { + if (limbTypeStr == "Standard") + { type = ZLimbType::Standard; } - else if(limbTypeStr == "LOD") { + else if (limbTypeStr == "LOD") + { type = ZLimbType::LOD; } - else if(limbTypeStr == "Skin") { + else if (limbTypeStr == "Skin") + { type = ZLimbType::Skin; } - else { - fprintf(stderr, "ZLimb::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. Defaulting to 'Standard'.\n", name.c_str(), limbType); + else if (limbTypeStr == "Curve") + { + type = ZLimbType::Curve; + } + else + { + fprintf(stderr, + "ZLimb::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. " + "Defaulting to 'Standard'.\n", + name.c_str(), limbType); type = ZLimbType::Standard; } } @@ -367,6 +426,16 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader) void ZLimb::ParseRawData() { + if (type == ZLimbType::Curve) + { + childIndex = rawData.at(rawDataIndex + 0); + siblingIndex = rawData.at(rawDataIndex + 1); + + dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4); + dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); + return; + } + transX = BitConverter::ToInt16BE(rawData, rawDataIndex + 0); transY = BitConverter::ToInt16BE(rawData, rawDataIndex + 2); transZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 4); @@ -374,36 +443,39 @@ void ZLimb::ParseRawData() childIndex = rawData.at(rawDataIndex + 6); siblingIndex = rawData.at(rawDataIndex + 7); - switch (type) { + switch (type) + { case ZLimbType::LOD: - farDListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12); + dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12); case ZLimbType::Standard: dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); break; case ZLimbType::Skin: - skinSegmentType = static_cast(BitConverter::ToInt32BE(rawData, rawDataIndex + 8)); + skinSegmentType = + static_cast(BitConverter::ToInt32BE(rawData, rawDataIndex + 8)); skinSegment = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12); break; } } -ZLimb* ZLimb::FromXML(tinyxml2::XMLElement* reader, vector nRawData, int rawDataIndex, string nRelPath, ZFile* parent) +ZLimb* ZLimb::FromXML(tinyxml2::XMLElement* reader, vector nRawData, int rawDataIndex, + string nRelPath, ZFile* parent) { ZLimb* limb = new ZLimb(reader, nRawData, rawDataIndex, parent); limb->relativePath = std::move(nRelPath); - limb->parent->AddDeclaration( - limb->GetFileAddress(), DeclarationAlignment::None, limb->GetRawDataSize(), - limb->GetSourceTypeName(), limb->name, ""); + limb->parent->AddDeclaration(limb->GetFileAddress(), DeclarationAlignment::None, + limb->GetRawDataSize(), limb->GetSourceTypeName(), limb->name, ""); return limb; } - int ZLimb::GetRawDataSize() { - switch (type) { + switch (type) + { case ZLimbType::Standard: + case ZLimbType::Curve: return 0x0C; case ZLimbType::LOD: case ZLimbType::Skin: @@ -417,23 +489,33 @@ string ZLimb::GetSourceOutputCode(const std::string& prefix) string dListStr = "NULL"; string dListStr2 = "NULL"; - if (dListPtr != 0) { - dListStr = GetLimbDListSourceOutputCode(prefix, "", dListPtr); + if (dListPtr != 0) + { + string limbPrefix = type == ZLimbType::Curve ? "Curve" : ""; + dListStr = GetLimbDListSourceOutputCode(prefix, limbPrefix, dListPtr); } - if (farDListPtr != 0) { - dListStr2 = GetLimbDListSourceOutputCode(prefix, "Far", farDListPtr); + if (dList2Ptr != 0) + { + string limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far"; + dListStr2 = GetLimbDListSourceOutputCode(prefix, limbPrefix, dList2Ptr); } - string entryStr = StringHelper::Sprintf("\n { %i, %i, %i },\n 0x%02X, 0x%02X,\n", - transX, transY, transZ, childIndex, siblingIndex); + string entryStr = ""; + if (type != ZLimbType::Curve) + { + entryStr += StringHelper::Sprintf("\n { %i, %i, %i },", transX, transY, transZ); + } - switch (type) { + entryStr += StringHelper::Sprintf("\n 0x%02X, 0x%02X,\n", childIndex, siblingIndex); + + switch (type) + { case ZLimbType::Standard: entryStr += StringHelper::Sprintf(" %s\n", dListStr.c_str()); break; case ZLimbType::LOD: - entryStr += StringHelper::Sprintf(" { %s, %s }\n", - dListStr.c_str(), dListStr2.c_str()); + case ZLimbType::Curve: + entryStr += StringHelper::Sprintf(" { %s, %s }\n", dListStr.c_str(), dListStr2.c_str()); break; case ZLimbType::Skin: entryStr += GetSourceOutputCodeSkin(prefix); @@ -441,10 +523,13 @@ string ZLimb::GetSourceOutputCode(const std::string& prefix) } Declaration* decl = parent->GetDeclaration(GetFileAddress()); - if (decl == nullptr) { - parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(), GetSourceTypeName(), name, entryStr); + if (decl == nullptr) + { + parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(), + GetSourceTypeName(), name, entryStr); } - else { + else + { decl->text = entryStr; } @@ -468,13 +553,16 @@ ZLimbType ZLimb::GetLimbType() const char* ZLimb::GetSourceTypeName(ZLimbType limbType) { - switch (limbType) { + switch (limbType) + { case ZLimbType::Standard: return "StandardLimb"; case ZLimbType::LOD: return "LodLimb"; case ZLimbType::Skin: return "SkinLimb"; + case ZLimbType::Curve: + return "SkelCurveLimb"; } return "StandardLimb"; } @@ -484,9 +572,11 @@ uint32_t ZLimb::GetFileAddress() return Seg2Filespace(segAddress, parent->baseAddress); } -std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix, const std::string& limbPrefix, segptr_t dListPtr) +std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix, + const std::string& limbPrefix, segptr_t dListPtr) { - if (dListPtr == 0) { + if (dListPtr == 0) + { return "NULL"; } @@ -494,16 +584,21 @@ std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix, const string dListStr; Declaration* decl = parent->GetDeclaration(dListOffset); - if (decl == nullptr) { - dListStr = StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), dListOffset); + if (decl == nullptr) + { + dListStr = StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), + dListOffset); - int dlistLength = ZDisplayList::GetDListLength(rawData, dListOffset, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); + int dlistLength = ZDisplayList::GetDListLength( + rawData, dListOffset, + Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); auto& dList = dLists.emplace_back(rawData, dListOffset, dlistLength); dList.parent = parent; dList.SetName(dListStr); dList.GetSourceOutputCode(prefix); } - else { + else + { dListStr = decl->varName; } @@ -515,7 +610,8 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix) assert(type == ZLimbType::Skin); assert(skinSegmentType == ZLimbSkinType::SkinType_4); - if (skinSegment == 0) { + if (skinSegment == 0) + { return "NULL"; } @@ -523,18 +619,21 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix) string struct_800A5E28_Str; Declaration* decl = parent->GetDeclaration(skinSegmentOffset); - if (decl == nullptr) { - struct_800A5E28_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset); + if (decl == nullptr) + { + struct_800A5E28_Str = + StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), + Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset); segmentStruct.PreGenSourceFiles(prefix); string entryStr = segmentStruct.GetSourceOutputCode(prefix); - parent->AddDeclaration( - skinSegmentOffset, DeclarationAlignment::None, - Struct_800A5E28::GetRawDataSize(), Struct_800A5E28::GetSourceTypeName(), - struct_800A5E28_Str, entryStr); + parent->AddDeclaration(skinSegmentOffset, DeclarationAlignment::None, + Struct_800A5E28::GetRawDataSize(), + Struct_800A5E28::GetSourceTypeName(), struct_800A5E28_Str, entryStr); } - else { + else + { struct_800A5E28_Str = decl->varName; } @@ -547,8 +646,10 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix) string skinSegmentStr = "NULL"; - if (skinSegment != 0) { - switch (skinSegmentType) { + if (skinSegment != 0) + { + switch (skinSegmentType) + { case ZLimbSkinType::SkinType_4: skinSegmentStr = "&" + GetSourceOutputCodeSkin_Type_4(prefix); break; @@ -556,17 +657,23 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix) skinSegmentStr = GetLimbDListSourceOutputCode(prefix, "Skin", skinSegment); break; default: - fprintf(stderr, "ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Unknown segment type for SkinLimb: '%i'. \n\tPlease report this.\n", name.c_str(), static_cast(skinSegmentType)); + fprintf(stderr, + "ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Unknown segment type " + "for SkinLimb: '%i'. \n\tPlease report this.\n", + name.c_str(), static_cast(skinSegmentType)); case ZLimbSkinType::SkinType_0: case ZLimbSkinType::SkinType_5: - fprintf(stderr, "ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Segment type for SkinLimb not implemented: '%i'.\n", name.c_str(), static_cast(skinSegmentType)); + fprintf(stderr, + "ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Segment type for " + "SkinLimb not implemented: '%i'.\n", + name.c_str(), static_cast(skinSegmentType)); skinSegmentStr = StringHelper::Sprintf("0x%08X", skinSegment); break; } } - string entryStr = StringHelper::Sprintf(" 0x%02X, %s\n", - skinSegmentType, skinSegmentStr.c_str()); + string entryStr = + StringHelper::Sprintf(" 0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str()); return entryStr; } diff --git a/tools/ZAPD/ZAPD/ZLimb.h b/tools/ZAPD/ZAPD/ZLimb.h index cc5e9065d8..edff33542d 100644 --- a/tools/ZAPD/ZAPD/ZLimb.h +++ b/tools/ZAPD/ZAPD/ZLimb.h @@ -1,29 +1,28 @@ #pragma once -#include -#include #include -#include "ZFile.h" +#include +#include #include "ZDisplayList.h" - +#include "ZFile.h" enum class ZLimbType { Standard, LOD, - Skin + Skin, + Curve, }; // TODO: check if more types exists enum class ZLimbSkinType { - SkinType_0, // Segment = 0 - SkinType_4 = 4, // Segment = segmented address // Struct_800A5E28 - SkinType_5 = 5, // Segment = 0 - SkinType_DList = 11, // Segment = DList address + SkinType_0, // Segment = 0 + SkinType_4 = 4, // Segment = segmented address // Struct_800A5E28 + SkinType_5 = 5, // Segment = 0 + SkinType_DList = 11, // Segment = DList address }; - class Struct_800A57C0 { protected: @@ -39,14 +38,12 @@ public: Struct_800A57C0(const std::vector& rawData, uint32_t fileOffset); Struct_800A57C0(const std::vector& rawData, uint32_t fileOffset, size_t index); - [[nodiscard]] - std::string GetSourceOutputCode() const; + [[nodiscard]] std::string GetSourceOutputCode() const; static size_t GetRawDataSize(); static std::string GetSourceTypeName(); }; - class Struct_800A598C_2 { protected: @@ -60,51 +57,48 @@ public: Struct_800A598C_2(const std::vector& rawData, uint32_t fileOffset); Struct_800A598C_2(const std::vector& rawData, uint32_t fileOffset, size_t index); - [[nodiscard]] - std::string GetSourceOutputCode() const; + [[nodiscard]] std::string GetSourceOutputCode() const; static size_t GetRawDataSize(); static std::string GetSourceTypeName(); }; - class Struct_800A598C { protected: ZFile* parent; - uint16_t unk_0; // Length of unk_8 - uint16_t unk_2; // Length of unk_C - uint16_t unk_4; // 0 or 1 // Used as an index for unk_C - segptr_t unk_8; // Struct_800A57C0* - segptr_t unk_C; // Struct_800A598C_2* + uint16_t unk_0; // Length of unk_8 + uint16_t unk_2; // Length of unk_C + uint16_t unk_4; // 0 or 1 // Used as an index for unk_C + segptr_t unk_8; // Struct_800A57C0* + segptr_t unk_C; // Struct_800A598C_2* std::vector unk_8_arr; std::vector unk_C_arr; public: Struct_800A598C(ZFile* parent, const std::vector& rawData, uint32_t fileOffset); - Struct_800A598C(ZFile* parent, const std::vector& rawData, uint32_t fileOffset, size_t index); + Struct_800A598C(ZFile* parent, const std::vector& rawData, uint32_t fileOffset, + size_t index); void PreGenSourceFiles(const std::string& prefix); - [[nodiscard]] - std::string GetSourceOutputCode(const std::string& prefix) const; + [[nodiscard]] std::string GetSourceOutputCode(const std::string& prefix) const; static size_t GetRawDataSize(); static std::string GetSourceTypeName(); }; - class Struct_800A5E28 { protected: ZFile* parent; std::vector rawData; - uint16_t unk_0; // Vtx count - uint16_t unk_2; // Length of unk_4 - segptr_t unk_4; // Struct_800A598C* - segptr_t unk_8; // Gfx* + uint16_t unk_0; // Vtx count + uint16_t unk_2; // Length of unk_4 + segptr_t unk_4; // Struct_800A598C* + segptr_t unk_8; // Gfx* std::vector unk_4_arr; ZDisplayList* unk_8_dlist = nullptr; @@ -112,18 +106,17 @@ protected: public: Struct_800A5E28() = default; Struct_800A5E28(ZFile* parent, const std::vector& rawData, uint32_t fileOffset); - Struct_800A5E28(ZFile* parent, const std::vector& rawData, uint32_t fileOffset, size_t index); + Struct_800A5E28(ZFile* parent, const std::vector& rawData, uint32_t fileOffset, + size_t index); ~Struct_800A5E28(); void PreGenSourceFiles(const std::string& prefix); - [[nodiscard]] - std::string GetSourceOutputCode(const std::string& prefix) const; + [[nodiscard]] std::string GetSourceOutputCode(const std::string& prefix) const; static size_t GetRawDataSize(); static std::string GetSourceTypeName(); }; - class ZLimb : public ZResource { protected: @@ -136,24 +129,28 @@ protected: std::vector dLists; - segptr_t farDListPtr = 0; // LOD only + segptr_t dList2Ptr = 0; // LOD and Curve only - ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only - segptr_t skinSegment = 0; // Skin only - Struct_800A5E28 segmentStruct; // Skin only + ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only + segptr_t skinSegment = 0; // Skin only + Struct_800A5E28 segmentStruct; // Skin only - std::string GetLimbDListSourceOutputCode(const std::string& prefix, const std::string& limbPrefix, segptr_t dListPtr); + std::string GetLimbDListSourceOutputCode(const std::string& prefix, + const std::string& limbPrefix, segptr_t dListPtr); std::string GetSourceOutputCodeSkin(const std::string& prefix); std::string GetSourceOutputCodeSkin_Type_4(const std::string& prefix); public: - ZLimb(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, ZFile* nParent); - ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector& nRawData, int nRawDataIndex, ZFile* nParent); + ZLimb(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, + ZFile* nParent); + ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector& nRawData, + int nRawDataIndex, ZFile* nParent); void ParseXML(tinyxml2::XMLElement* reader) override; void ParseRawData() override; - static ZLimb* FromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, std::string nRelPath, ZFile* parent); + static ZLimb* FromXML(tinyxml2::XMLElement* reader, std::vector nRawData, + int rawDataIndex, std::string nRelPath, ZFile* parent); int GetRawDataSize() override; std::string GetSourceOutputCode(const std::string& prefix) override; std::string GetSourceTypeName() override; diff --git a/tools/ZAPD/ZAPD/ZResource.cpp b/tools/ZAPD/ZAPD/ZResource.cpp index f906c7a794..7a8acb417a 100644 --- a/tools/ZAPD/ZAPD/ZResource.cpp +++ b/tools/ZAPD/ZAPD/ZResource.cpp @@ -29,7 +29,6 @@ void ZResource::ParseXML(tinyxml2::XMLElement* reader) void ZResource::Save(const std::string& outFolder) { - } void ZResource::PreGenSourceFiles() @@ -107,7 +106,6 @@ void ZResource::ParseRawData() void ZResource::GenerateHLIntermediette(HLFileIntermediette& hlFile) { - } std::string ZResource::GetSourceTypeName() @@ -125,12 +123,11 @@ void ZResource::CalcHash() hash = 0; } - uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress) { uint32_t currentPtr = GETSEGOFFSET(segmentedAddress); - if (GETSEGNUM(segmentedAddress) == 0x80) // Is defined in code? + if (GETSEGNUM(segmentedAddress) == 0x80) // Is defined in code? currentPtr -= GETSEGOFFSET(parentBaseAddress); return currentPtr; diff --git a/tools/ZAPD/ZAPD/ZResource.h b/tools/ZAPD/ZAPD/ZResource.h index b34ccdcd22..78f69a6c82 100644 --- a/tools/ZAPD/ZAPD/ZResource.h +++ b/tools/ZAPD/ZAPD/ZResource.h @@ -1,9 +1,10 @@ #pragma once #include +#include +#include #include #include -#include #include "tinyxml2.h" #define SEGMENT_SCENE 2 @@ -39,7 +40,8 @@ enum class ZResourceType Scalar, Vector, Vertex, - CollisionHeader + CollisionHeader, + Symbol, }; class ZResource @@ -58,7 +60,7 @@ public: std::string GetRelativePath(); virtual std::vector GetRawData(); virtual bool IsExternalResource(); - virtual bool DoesSupportArray(); // Can this type be wrapped in an node? + virtual bool DoesSupportArray(); // Can this type be wrapped in an node? virtual std::string GetExternalExtension(); virtual int GetRawDataIndex(); virtual int GetRawDataSize(); @@ -116,15 +118,21 @@ public: int arrayItemCnt; std::vector references; - Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, std::string nText); - Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, std::string nText); - Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, int nArrayItemCnt, std::string nText); - Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, int nArrayItemCnt, std::string nText); - Declaration(std::string nIncludePath, uint32_t nSize, std::string nVarType, std::string nVarName); + Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType, + std::string nVarName, bool nIsArray, std::string nText); + Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, + std::string nVarType, std::string nVarName, bool nIsArray, std::string nText); + Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType, + std::string nVarName, bool nIsArray, int nArrayItemCnt, std::string nText); + Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, + std::string nVarType, std::string nVarName, bool nIsArray, int nArrayItemCnt, + std::string nText); + Declaration(std::string nIncludePath, uint32_t nSize, std::string nVarType, + std::string nVarName); protected: - Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, std::string nText); + Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, + std::string nText); }; - uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress); diff --git a/tools/ZAPD/ZAPD/ZRoom/ActorList.h b/tools/ZAPD/ZAPD/ZRoom/ActorList.h index 742adc858d..24ba26efa3 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ActorList.h +++ b/tools/ZAPD/ZAPD/ZRoom/ActorList.h @@ -2,478 +2,477 @@ #include -static const std::string ActorList[] = -{ - /* 0x0000 */ "ACTOR_PLAYER", - /* 0x0001 */ "ACTOR_UNSET_1", - /* 0x0002 */ "ACTOR_EN_TEST", - /* 0x0003 */ "ACTOR_UNSET_3", - /* 0x0004 */ "ACTOR_EN_GIRLA", - /* 0x0005 */ "ACTOR_UNSET_5", - /* 0x0006 */ "ACTOR_UNSET_6", - /* 0x0007 */ "ACTOR_EN_PART", - /* 0x0008 */ "ACTOR_EN_LIGHT", - /* 0x0009 */ "ACTOR_EN_DOOR", - /* 0x000A */ "ACTOR_EN_BOX", // Treasure Chest - /* 0x000B */ "ACTOR_BG_DY_YOSEIZO", - /* 0x000C */ "ACTOR_BG_HIDAN_FIREWALL", - /* 0x000D */ "ACTOR_EN_POH", - /* 0x000E */ "ACTOR_EN_OKUTA", - /* 0x000F */ "ACTOR_BG_YDAN_SP", - /* 0x0010 */ "ACTOR_EN_BOM", - /* 0x0011 */ "ACTOR_EN_WALLMAS", - /* 0x0012 */ "ACTOR_EN_DODONGO", - /* 0x0013 */ "ACTOR_EN_FIREFLY", - /* 0x0014 */ "ACTOR_EN_HORSE", - /* 0x0015 */ "ACTOR_EN_ITEM00", - /* 0x0016 */ "ACTOR_EN_ARROW", - /* 0x0017 */ "ACTOR_UNSET_17", - /* 0x0018 */ "ACTOR_EN_ELF", - /* 0x0019 */ "ACTOR_EN_NIW", - /* 0x001A */ "ACTOR_UNSET_1A", - /* 0x001B */ "ACTOR_EN_TITE", - /* 0x001C */ "ACTOR_EN_REEBA", - /* 0x001D */ "ACTOR_EN_PEEHAT", - /* 0x001E */ "ACTOR_EN_BUTTE", - /* 0x001F */ "ACTOR_UNSET_1F", - /* 0x0020 */ "ACTOR_EN_INSECT", - /* 0x0021 */ "ACTOR_EN_FISH", - /* 0x0022 */ "ACTOR_UNSET_22", - /* 0x0023 */ "ACTOR_EN_HOLL", - /* 0x0024 */ "ACTOR_EN_SCENE_CHANGE", - /* 0x0025 */ "ACTOR_EN_ZF", - /* 0x0026 */ "ACTOR_EN_HATA", - /* 0x0027 */ "ACTOR_BOSS_DODONGO", - /* 0x0028 */ "ACTOR_BOSS_GOMA", - /* 0x0029 */ "ACTOR_EN_ZL1", - /* 0x002A */ "ACTOR_EN_VIEWER", - /* 0x002B */ "ACTOR_EN_GOMA", - /* 0x002C */ "ACTOR_BG_PUSHBOX", - /* 0x002D */ "ACTOR_EN_BUBBLE", - /* 0x002E */ "ACTOR_DOOR_SHUTTER", - /* 0x002F */ "ACTOR_EN_DODOJR", - /* 0x0030 */ "ACTOR_EN_BDFIRE", - /* 0x0031 */ "ACTOR_UNSET_31", - /* 0x0032 */ "ACTOR_EN_BOOM", - /* 0x0033 */ "ACTOR_EN_TORCH2", - /* 0x0034 */ "ACTOR_EN_BILI", - /* 0x0035 */ "ACTOR_EN_TP", - /* 0x0036 */ "ACTOR_UNSET_36", - /* 0x0037 */ "ACTOR_EN_ST", - /* 0x0038 */ "ACTOR_EN_BW", - /* 0x0039 */ "ACTOR_EN_A_OBJ", - /* 0x003A */ "ACTOR_EN_EIYER", - /* 0x003B */ "ACTOR_EN_RIVER_SOUND", - /* 0x003C */ "ACTOR_EN_HORSE_NORMAL", - /* 0x003D */ "ACTOR_EN_OSSAN", - /* 0x003E */ "ACTOR_BG_TREEMOUTH", - /* 0x003F */ "ACTOR_BG_DODOAGO", - /* 0x0040 */ "ACTOR_BG_HIDAN_DALM", - /* 0x0041 */ "ACTOR_BG_HIDAN_HROCK", - /* 0x0042 */ "ACTOR_EN_HORSE_GANON", - /* 0x0043 */ "ACTOR_BG_HIDAN_ROCK", - /* 0x0044 */ "ACTOR_BG_HIDAN_RSEKIZOU", - /* 0x0045 */ "ACTOR_BG_HIDAN_SEKIZOU", - /* 0x0046 */ "ACTOR_BG_HIDAN_SIMA", - /* 0x0047 */ "ACTOR_BG_HIDAN_SYOKU", - /* 0x0048 */ "ACTOR_EN_XC", - /* 0x0049 */ "ACTOR_BG_HIDAN_CURTAIN", - /* 0x004A */ "ACTOR_BG_SPOT00_HANEBASI", - /* 0x004B */ "ACTOR_EN_MB", - /* 0x004C */ "ACTOR_EN_BOMBF", - /* 0x004D */ "ACTOR_EN_ZL2", - /* 0x004E */ "ACTOR_BG_HIDAN_FSLIFT", - /* 0x004F */ "ACTOR_EN_OE2", - /* 0x0050 */ "ACTOR_BG_YDAN_HASI", - /* 0x0051 */ "ACTOR_BG_YDAN_MARUTA", - /* 0x0052 */ "ACTOR_BOSS_GANONDROF", - /* 0x0053 */ "ACTOR_UNSET_53", - /* 0x0054 */ "ACTOR_EN_AM", - /* 0x0055 */ "ACTOR_EN_DEKUBABA", - /* 0x0056 */ "ACTOR_EN_M_FIRE1", - /* 0x0057 */ "ACTOR_EN_M_THUNDER", - /* 0x0058 */ "ACTOR_BG_DDAN_JD", - /* 0x0059 */ "ACTOR_BG_BREAKWALL", - /* 0x005A */ "ACTOR_EN_JJ", - /* 0x005B */ "ACTOR_EN_HORSE_ZELDA", - /* 0x005C */ "ACTOR_BG_DDAN_KD", - /* 0x005D */ "ACTOR_DOOR_WARP1", - /* 0x005E */ "ACTOR_OBJ_SYOKUDAI", - /* 0x005F */ "ACTOR_ITEM_B_HEART", - /* 0x0060 */ "ACTOR_EN_DEKUNUTS", - /* 0x0061 */ "ACTOR_BG_MENKURI_KAITEN", - /* 0x0062 */ "ACTOR_BG_MENKURI_EYE", - /* 0x0063 */ "ACTOR_EN_VALI", - /* 0x0064 */ "ACTOR_BG_MIZU_MOVEBG", - /* 0x0065 */ "ACTOR_BG_MIZU_WATER", - /* 0x0066 */ "ACTOR_ARMS_HOOK", - /* 0x0067 */ "ACTOR_EN_FHG", - /* 0x0068 */ "ACTOR_BG_MORI_HINERI", - /* 0x0069 */ "ACTOR_EN_BB", - /* 0x006A */ "ACTOR_BG_TOKI_HIKARI", - /* 0x006B */ "ACTOR_EN_YUKABYUN", - /* 0x006C */ "ACTOR_BG_TOKI_SWD", - /* 0x006D */ "ACTOR_EN_FHG_FIRE", - /* 0x006E */ "ACTOR_BG_MJIN", - /* 0x006F */ "ACTOR_BG_HIDAN_KOUSI", - /* 0x0070 */ "ACTOR_DOOR_TOKI", - /* 0x0071 */ "ACTOR_BG_HIDAN_HAMSTEP", - /* 0x0072 */ "ACTOR_EN_BIRD", - /* 0x0073 */ "ACTOR_UNSET_73", - /* 0x0074 */ "ACTOR_UNSET_74", - /* 0x0075 */ "ACTOR_UNSET_75", - /* 0x0076 */ "ACTOR_UNSET_76", - /* 0x0077 */ "ACTOR_EN_WOOD02", - /* 0x0078 */ "ACTOR_UNSET_78", - /* 0x0079 */ "ACTOR_UNSET_79", - /* 0x007A */ "ACTOR_UNSET_7A", - /* 0x007B */ "ACTOR_UNSET_7B", - /* 0x007C */ "ACTOR_EN_LIGHTBOX", - /* 0x007D */ "ACTOR_EN_PU_BOX", - /* 0x007E */ "ACTOR_UNSET_7E", - /* 0x007F */ "ACTOR_UNSET_7F", - /* 0x0080 */ "ACTOR_EN_TRAP", - /* 0x0081 */ "ACTOR_EN_AROW_TRAP", - /* 0x0082 */ "ACTOR_EN_VASE", - /* 0x0083 */ "ACTOR_UNSET_83", - /* 0x0084 */ "ACTOR_EN_TA", - /* 0x0085 */ "ACTOR_EN_TK", - /* 0x0086 */ "ACTOR_BG_MORI_BIGST", - /* 0x0087 */ "ACTOR_BG_MORI_ELEVATOR", - /* 0x0088 */ "ACTOR_BG_MORI_KAITENKABE", - /* 0x0089 */ "ACTOR_BG_MORI_RAKKATENJO", - /* 0x008A */ "ACTOR_EN_VM", - /* 0x008B */ "ACTOR_DEMO_EFFECT", - /* 0x008C */ "ACTOR_DEMO_KANKYO", - /* 0x008D */ "ACTOR_BG_HIDAN_FWBIG", - /* 0x008E */ "ACTOR_EN_FLOORMAS", - /* 0x008F */ "ACTOR_EN_HEISHI1", - /* 0x0090 */ "ACTOR_EN_RD", - /* 0x0091 */ "ACTOR_EN_PO_SISTERS", - /* 0x0092 */ "ACTOR_BG_HEAVY_BLOCK", - /* 0x0093 */ "ACTOR_BG_PO_EVENT", - /* 0x0094 */ "ACTOR_OBJ_MURE", - /* 0x0095 */ "ACTOR_EN_SW", - /* 0x0096 */ "ACTOR_BOSS_FD", - /* 0x0097 */ "ACTOR_OBJECT_KANKYO", - /* 0x0098 */ "ACTOR_EN_DU", - /* 0x0099 */ "ACTOR_EN_FD", - /* 0x009A */ "ACTOR_EN_HORSE_LINK_CHILD", - /* 0x009B */ "ACTOR_DOOR_ANA", - /* 0x009C */ "ACTOR_BG_SPOT02_OBJECTS", - /* 0x009D */ "ACTOR_BG_HAKA", - /* 0x009E */ "ACTOR_MAGIC_WIND", - /* 0x009F */ "ACTOR_MAGIC_FIRE", - /* 0x00A0 */ "ACTOR_UNSET_A0", - /* 0x00A1 */ "ACTOR_EN_RU1", - /* 0x00A2 */ "ACTOR_BOSS_FD2", - /* 0x00A3 */ "ACTOR_EN_FD_FIRE", - /* 0x00A4 */ "ACTOR_EN_DH", - /* 0x00A5 */ "ACTOR_EN_DHA", - /* 0x00A6 */ "ACTOR_EN_RL", - /* 0x00A7 */ "ACTOR_EN_ENCOUNT1", - /* 0x00A8 */ "ACTOR_DEMO_DU", - /* 0x00A9 */ "ACTOR_DEMO_IM", - /* 0x00AA */ "ACTOR_DEMO_TRE_LGT", - /* 0x00AB */ "ACTOR_EN_FW", - /* 0x00AC */ "ACTOR_BG_VB_SIMA", - /* 0x00AD */ "ACTOR_EN_VB_BALL", - /* 0x00AE */ "ACTOR_BG_HAKA_MEGANE", - /* 0x00AF */ "ACTOR_BG_HAKA_MEGANEBG", - /* 0x00B0 */ "ACTOR_BG_HAKA_SHIP", - /* 0x00B1 */ "ACTOR_BG_HAKA_SGAMI", - /* 0x00B2 */ "ACTOR_UNSET_B2", - /* 0x00B3 */ "ACTOR_EN_HEISHI2", - /* 0x00B4 */ "ACTOR_EN_ENCOUNT2", - /* 0x00B5 */ "ACTOR_EN_FIRE_ROCK", - /* 0x00B6 */ "ACTOR_EN_BROB", - /* 0x00B7 */ "ACTOR_MIR_RAY", - /* 0x00B8 */ "ACTOR_BG_SPOT09_OBJ", - /* 0x00B9 */ "ACTOR_BG_SPOT18_OBJ", - /* 0x00BA */ "ACTOR_BOSS_VA", - /* 0x00BB */ "ACTOR_BG_HAKA_TUBO", - /* 0x00BC */ "ACTOR_BG_HAKA_TRAP", - /* 0x00BD */ "ACTOR_BG_HAKA_HUTA", - /* 0x00BE */ "ACTOR_BG_HAKA_ZOU", - /* 0x00BF */ "ACTOR_BG_SPOT17_FUNEN", - /* 0x00C0 */ "ACTOR_EN_SYATEKI_ITM", - /* 0x00C1 */ "ACTOR_EN_SYATEKI_MAN", - /* 0x00C2 */ "ACTOR_EN_TANA", - /* 0x00C3 */ "ACTOR_EN_NB", - /* 0x00C4 */ "ACTOR_BOSS_MO", - /* 0x00C5 */ "ACTOR_EN_SB", - /* 0x00C6 */ "ACTOR_EN_BIGOKUTA", - /* 0x00C7 */ "ACTOR_EN_KAREBABA", - /* 0x00C8 */ "ACTOR_BG_BDAN_OBJECTS", - /* 0x00C9 */ "ACTOR_DEMO_SA", - /* 0x00CA */ "ACTOR_DEMO_GO", - /* 0x00CB */ "ACTOR_EN_IN", - /* 0x00CC */ "ACTOR_EN_TR", - /* 0x00CD */ "ACTOR_BG_SPOT16_BOMBSTONE", - /* 0x00CE */ "ACTOR_UNSET_CE", - /* 0x00CF */ "ACTOR_BG_HIDAN_KOWARERUKABE", - /* 0x00D0 */ "ACTOR_BG_BOMBWALL", - /* 0x00D1 */ "ACTOR_BG_SPOT08_ICEBLOCK", - /* 0x00D2 */ "ACTOR_EN_RU2", - /* 0x00D3 */ "ACTOR_OBJ_DEKUJR", - /* 0x00D4 */ "ACTOR_BG_MIZU_UZU", - /* 0x00D5 */ "ACTOR_BG_SPOT06_OBJECTS", - /* 0x00D6 */ "ACTOR_BG_ICE_OBJECTS", - /* 0x00D7 */ "ACTOR_BG_HAKA_WATER", - /* 0x00D8 */ "ACTOR_UNSET_D8", - /* 0x00D9 */ "ACTOR_EN_MA2", - /* 0x00DA */ "ACTOR_EN_BOM_CHU", - /* 0x00DB */ "ACTOR_EN_HORSE_GAME_CHECK", - /* 0x00DC */ "ACTOR_BOSS_TW", - /* 0x00DD */ "ACTOR_EN_RR", - /* 0x00DE */ "ACTOR_EN_BA", - /* 0x00DF */ "ACTOR_EN_BX", - /* 0x00E0 */ "ACTOR_EN_ANUBICE", - /* 0x00E1 */ "ACTOR_EN_ANUBICE_FIRE", - /* 0x00E2 */ "ACTOR_BG_MORI_HASHIGO", - /* 0x00E3 */ "ACTOR_BG_MORI_HASHIRA4", - /* 0x00E4 */ "ACTOR_BG_MORI_IDOMIZU", - /* 0x00E5 */ "ACTOR_BG_SPOT16_DOUGHNUT", - /* 0x00E6 */ "ACTOR_BG_BDAN_SWITCH", - /* 0x00E7 */ "ACTOR_EN_MA1", - /* 0x00E8 */ "ACTOR_BOSS_GANON", - /* 0x00E9 */ "ACTOR_BOSS_SST", - /* 0x00EA */ "ACTOR_UNSET_EA", - /* 0x00EB */ "ACTOR_UNSET_EB", - /* 0x00EC */ "ACTOR_EN_NY", - /* 0x00ED */ "ACTOR_EN_FR", - /* 0x00EE */ "ACTOR_ITEM_SHIELD", - /* 0x00EF */ "ACTOR_BG_ICE_SHELTER", - /* 0x00F0 */ "ACTOR_EN_ICE_HONO", - /* 0x00F1 */ "ACTOR_ITEM_OCARINA", - /* 0x00F2 */ "ACTOR_UNSET_F2", - /* 0x00F3 */ "ACTOR_UNSET_F3", - /* 0x00F4 */ "ACTOR_MAGIC_DARK", - /* 0x00F5 */ "ACTOR_DEMO_6K", - /* 0x00F6 */ "ACTOR_EN_ANUBICE_TAG", - /* 0x00F7 */ "ACTOR_BG_HAKA_GATE", - /* 0x00F8 */ "ACTOR_BG_SPOT15_SAKU", - /* 0x00F9 */ "ACTOR_BG_JYA_GOROIWA", - /* 0x00FA */ "ACTOR_BG_JYA_ZURERUKABE", - /* 0x00FB */ "ACTOR_UNSET_FB", - /* 0x00FC */ "ACTOR_BG_JYA_COBRA", - /* 0x00FD */ "ACTOR_BG_JYA_KANAAMI", - /* 0x00FE */ "ACTOR_FISHING", - /* 0x00FF */ "ACTOR_OBJ_OSHIHIKI", - /* 0x0100 */ "ACTOR_BG_GATE_SHUTTER", - /* 0x0101 */ "ACTOR_EFF_DUST", - /* 0x0102 */ "ACTOR_BG_SPOT01_FUSYA", - /* 0x0103 */ "ACTOR_BG_SPOT01_IDOHASHIRA", - /* 0x0104 */ "ACTOR_BG_SPOT01_IDOMIZU", - /* 0x0105 */ "ACTOR_BG_PO_SYOKUDAI", - /* 0x0106 */ "ACTOR_BG_GANON_OTYUKA", - /* 0x0107 */ "ACTOR_BG_SPOT15_RRBOX", - /* 0x0108 */ "ACTOR_BG_UMAJUMP", - /* 0x0109 */ "ACTOR_UNSET_109", - /* 0x010A */ "ACTOR_ARROW_FIRE", - /* 0x010B */ "ACTOR_ARROW_ICE", - /* 0x010C */ "ACTOR_ARROW_LIGHT", - /* 0x010D */ "ACTOR_UNSET_10D", - /* 0x010E */ "ACTOR_UNSET_10E", - /* 0x010F */ "ACTOR_ITEM_ETCETERA", - /* 0x0110 */ "ACTOR_OBJ_KIBAKO", - /* 0x0111 */ "ACTOR_OBJ_TSUBO", - /* 0x0112 */ "ACTOR_EN_WONDER_ITEM", - /* 0x0113 */ "ACTOR_EN_IK", - /* 0x0114 */ "ACTOR_DEMO_IK", - /* 0x0115 */ "ACTOR_EN_SKJ", - /* 0x0116 */ "ACTOR_EN_SKJNEEDLE", - /* 0x0117 */ "ACTOR_EN_G_SWITCH", - /* 0x0118 */ "ACTOR_DEMO_EXT", - /* 0x0119 */ "ACTOR_DEMO_SHD", - /* 0x011A */ "ACTOR_EN_DNS", - /* 0x011B */ "ACTOR_ELF_MSG", - /* 0x011C */ "ACTOR_EN_HONOTRAP", - /* 0x011D */ "ACTOR_EN_TUBO_TRAP", - /* 0x011E */ "ACTOR_OBJ_ICE_POLY", - /* 0x011F */ "ACTOR_BG_SPOT03_TAKI", - /* 0x0120 */ "ACTOR_BG_SPOT07_TAKI", - /* 0x0121 */ "ACTOR_EN_FZ", - /* 0x0122 */ "ACTOR_EN_PO_RELAY", - /* 0x0123 */ "ACTOR_BG_RELAY_OBJECTS", - /* 0x0124 */ "ACTOR_EN_DIVING_GAME", - /* 0x0125 */ "ACTOR_EN_KUSA", - /* 0x0126 */ "ACTOR_OBJ_BEAN", - /* 0x0127 */ "ACTOR_OBJ_BOMBIWA", - /* 0x0128 */ "ACTOR_UNSET_128", - /* 0x0129 */ "ACTOR_UNSET_129", - /* 0x012A */ "ACTOR_OBJ_SWITCH", - /* 0x012B */ "ACTOR_OBJ_ELEVATOR", - /* 0x012C */ "ACTOR_OBJ_LIFT", - /* 0x012D */ "ACTOR_OBJ_HSBLOCK", - /* 0x012E */ "ACTOR_EN_OKARINA_TAG", - /* 0x012F */ "ACTOR_EN_YABUSAME_MARK", - /* 0x0130 */ "ACTOR_EN_GOROIWA", - /* 0x0131 */ "ACTOR_EN_EX_RUPPY", - /* 0x0132 */ "ACTOR_EN_TORYO", - /* 0x0133 */ "ACTOR_EN_DAIKU", - /* 0x0134 */ "ACTOR_UNSET_134", - /* 0x0135 */ "ACTOR_EN_NWC", - /* 0x0136 */ "ACTOR_EN_BLKOBJ", - /* 0x0137 */ "ACTOR_ITEM_INBOX", - /* 0x0138 */ "ACTOR_EN_GE1", - /* 0x0139 */ "ACTOR_OBJ_BLOCKSTOP", - /* 0x013A */ "ACTOR_EN_SDA", - /* 0x013B */ "ACTOR_EN_CLEAR_TAG", - /* 0x013C */ "ACTOR_EN_NIW_LADY", - /* 0x013D */ "ACTOR_EN_GM", - /* 0x013E */ "ACTOR_EN_MS", - /* 0x013F */ "ACTOR_EN_HS", - /* 0x0140 */ "ACTOR_BG_INGATE", - /* 0x0141 */ "ACTOR_EN_KANBAN", - /* 0x0142 */ "ACTOR_EN_HEISHI3", - /* 0x0143 */ "ACTOR_EN_SYATEKI_NIW", - /* 0x0144 */ "ACTOR_EN_ATTACK_NIW", - /* 0x0145 */ "ACTOR_BG_SPOT01_IDOSOKO", - /* 0x0146 */ "ACTOR_EN_SA", - /* 0x0147 */ "ACTOR_EN_WONDER_TALK", - /* 0x0148 */ "ACTOR_BG_GJYO_BRIDGE", - /* 0x0149 */ "ACTOR_EN_DS", - /* 0x014A */ "ACTOR_EN_MK", - /* 0x014B */ "ACTOR_EN_BOM_BOWL_MAN", - /* 0x014C */ "ACTOR_EN_BOM_BOWL_PIT", - /* 0x014D */ "ACTOR_EN_OWL", - /* 0x014E */ "ACTOR_EN_ISHI", - /* 0x014F */ "ACTOR_OBJ_HANA", - /* 0x0150 */ "ACTOR_OBJ_LIGHTSWITCH", - /* 0x0151 */ "ACTOR_OBJ_MURE2", - /* 0x0152 */ "ACTOR_EN_GO", - /* 0x0153 */ "ACTOR_EN_FU", - /* 0x0154 */ "ACTOR_UNSET_154", - /* 0x0155 */ "ACTOR_EN_CHANGER", - /* 0x0156 */ "ACTOR_BG_JYA_MEGAMI", - /* 0x0157 */ "ACTOR_BG_JYA_LIFT", - /* 0x0158 */ "ACTOR_BG_JYA_BIGMIRROR", - /* 0x0159 */ "ACTOR_BG_JYA_BOMBCHUIWA", - /* 0x015A */ "ACTOR_BG_JYA_AMISHUTTER", - /* 0x015B */ "ACTOR_BG_JYA_BOMBIWA", - /* 0x015C */ "ACTOR_BG_SPOT18_BASKET", - /* 0x015D */ "ACTOR_UNSET_15D", - /* 0x015E */ "ACTOR_EN_GANON_ORGAN", - /* 0x015F */ "ACTOR_EN_SIOFUKI", - /* 0x0160 */ "ACTOR_EN_STREAM", - /* 0x0161 */ "ACTOR_UNSET_161", - /* 0x0162 */ "ACTOR_EN_MM", - /* 0x0163 */ "ACTOR_EN_KO", - /* 0x0164 */ "ACTOR_EN_KZ", - /* 0x0165 */ "ACTOR_EN_WEATHER_TAG", - /* 0x0166 */ "ACTOR_BG_SST_FLOOR", - /* 0x0167 */ "ACTOR_EN_ANI", - /* 0x0168 */ "ACTOR_EN_EX_ITEM", - /* 0x0169 */ "ACTOR_BG_JYA_IRONOBJ", - /* 0x016A */ "ACTOR_EN_JS", - /* 0x016B */ "ACTOR_EN_JSJUTAN", - /* 0x016C */ "ACTOR_EN_CS", - /* 0x016D */ "ACTOR_EN_MD", - /* 0x016E */ "ACTOR_EN_HY", - /* 0x016F */ "ACTOR_EN_GANON_MANT", - /* 0x0170 */ "ACTOR_EN_OKARINA_EFFECT", - /* 0x0171 */ "ACTOR_EN_MAG", - /* 0x0172 */ "ACTOR_DOOR_GERUDO", - /* 0x0173 */ "ACTOR_ELF_MSG2", - /* 0x0174 */ "ACTOR_DEMO_GT", - /* 0x0175 */ "ACTOR_EN_PO_FIELD", - /* 0x0176 */ "ACTOR_EFC_ERUPC", - /* 0x0177 */ "ACTOR_BG_ZG", - /* 0x0178 */ "ACTOR_EN_HEISHI4", - /* 0x0179 */ "ACTOR_EN_ZL3", - /* 0x017A */ "ACTOR_BOSS_GANON2", - /* 0x017B */ "ACTOR_EN_KAKASI", - /* 0x017C */ "ACTOR_EN_TAKARA_MAN", - /* 0x017D */ "ACTOR_OBJ_MAKEOSHIHIKI", - /* 0x017E */ "ACTOR_OCEFF_SPOT", - /* 0x017F */ "ACTOR_END_TITLE", - /* 0x0180 */ "ACTOR_UNSET_180", - /* 0x0181 */ "ACTOR_EN_TORCH", - /* 0x0182 */ "ACTOR_DEMO_EC", - /* 0x0183 */ "ACTOR_SHOT_SUN", - /* 0x0184 */ "ACTOR_EN_DY_EXTRA", - /* 0x0185 */ "ACTOR_EN_WONDER_TALK2", - /* 0x0186 */ "ACTOR_EN_GE2", - /* 0x0187 */ "ACTOR_OBJ_ROOMTIMER", - /* 0x0188 */ "ACTOR_EN_SSH", - /* 0x0189 */ "ACTOR_EN_STH", - /* 0x018A */ "ACTOR_OCEFF_WIPE", - /* 0x018B */ "ACTOR_OCEFF_STORM", - /* 0x018C */ "ACTOR_EN_WEIYER", - /* 0x018D */ "ACTOR_BG_SPOT05_SOKO", - /* 0x018E */ "ACTOR_BG_JYA_1FLIFT", - /* 0x018F */ "ACTOR_BG_JYA_HAHENIRON", - /* 0x0190 */ "ACTOR_BG_SPOT12_GATE", - /* 0x0191 */ "ACTOR_BG_SPOT12_SAKU", - /* 0x0192 */ "ACTOR_EN_HINTNUTS", - /* 0x0193 */ "ACTOR_EN_NUTSBALL", - /* 0x0194 */ "ACTOR_BG_SPOT00_BREAK", - /* 0x0195 */ "ACTOR_EN_SHOPNUTS", - /* 0x0196 */ "ACTOR_EN_IT", - /* 0x0197 */ "ACTOR_EN_GELDB", - /* 0x0198 */ "ACTOR_OCEFF_WIPE2", - /* 0x0199 */ "ACTOR_OCEFF_WIPE3", - /* 0x019A */ "ACTOR_EN_NIW_GIRL", - /* 0x019B */ "ACTOR_EN_DOG", - /* 0x019C */ "ACTOR_EN_SI", - /* 0x019D */ "ACTOR_BG_SPOT01_OBJECTS2", - /* 0x019E */ "ACTOR_OBJ_COMB", - /* 0x019F */ "ACTOR_BG_SPOT11_BAKUDANKABE", - /* 0x01A0 */ "ACTOR_OBJ_KIBAKO2", - /* 0x01A1 */ "ACTOR_EN_DNT_DEMO", - /* 0x01A2 */ "ACTOR_EN_DNT_JIJI", - /* 0x01A3 */ "ACTOR_EN_DNT_NOMAL", - /* 0x01A4 */ "ACTOR_EN_GUEST", - /* 0x01A5 */ "ACTOR_BG_BOM_GUARD", - /* 0x01A6 */ "ACTOR_EN_HS2", - /* 0x01A7 */ "ACTOR_DEMO_KEKKAI", - /* 0x01A8 */ "ACTOR_BG_SPOT08_BAKUDANKABE", - /* 0x01A9 */ "ACTOR_BG_SPOT17_BAKUDANKABE", - /* 0x01AA */ "ACTOR_UNSET_1AA", - /* 0x01AB */ "ACTOR_OBJ_MURE3", - /* 0x01AC */ "ACTOR_EN_TG", - /* 0x01AD */ "ACTOR_EN_MU", - /* 0x01AE */ "ACTOR_EN_GO2", - /* 0x01AF */ "ACTOR_EN_WF", - /* 0x01B0 */ "ACTOR_EN_SKB", - /* 0x01B1 */ "ACTOR_DEMO_GJ", - /* 0x01B2 */ "ACTOR_DEMO_GEFF", - /* 0x01B3 */ "ACTOR_BG_GND_FIREMEIRO", - /* 0x01B4 */ "ACTOR_BG_GND_DARKMEIRO", - /* 0x01B5 */ "ACTOR_BG_GND_SOULMEIRO", - /* 0x01B6 */ "ACTOR_BG_GND_NISEKABE", - /* 0x01B7 */ "ACTOR_BG_GND_ICEBLOCK", - /* 0x01B8 */ "ACTOR_EN_GB", - /* 0x01B9 */ "ACTOR_EN_GS", - /* 0x01BA */ "ACTOR_BG_MIZU_BWALL", - /* 0x01BB */ "ACTOR_BG_MIZU_SHUTTER", - /* 0x01BC */ "ACTOR_EN_DAIKU_KAKARIKO", - /* 0x01BD */ "ACTOR_BG_BOWL_WALL", - /* 0x01BE */ "ACTOR_EN_WALL_TUBO", - /* 0x01BF */ "ACTOR_EN_PO_DESERT", - /* 0x01C0 */ "ACTOR_EN_CROW", - /* 0x01C1 */ "ACTOR_DOOR_KILLER", - /* 0x01C2 */ "ACTOR_BG_SPOT11_OASIS", - /* 0x01C3 */ "ACTOR_BG_SPOT18_FUTA", - /* 0x01C4 */ "ACTOR_BG_SPOT18_SHUTTER", - /* 0x01C5 */ "ACTOR_EN_MA3", - /* 0x01C6 */ "ACTOR_EN_COW", - /* 0x01C7 */ "ACTOR_BG_ICE_TURARA", - /* 0x01C8 */ "ACTOR_BG_ICE_SHUTTER", - /* 0x01C9 */ "ACTOR_EN_KAKASI2", - /* 0x01CA */ "ACTOR_EN_KAKASI3", - /* 0x01CB */ "ACTOR_OCEFF_WIPE4", - /* 0x01CC */ "ACTOR_EN_EG", - /* 0x01CD */ "ACTOR_BG_MENKURI_NISEKABE", - /* 0x01CE */ "ACTOR_EN_ZO", - /* 0x01CF */ "ACTOR_OBJ_MAKEKINSUTA", - /* 0x01D0 */ "ACTOR_EN_GE3", - /* 0x01D1 */ "ACTOR_OBJ_TIMEBLOCK", - /* 0x01D2 */ "ACTOR_OBJ_HAMISHI", - /* 0x01D3 */ "ACTOR_EN_ZL4", - /* 0x01D4 */ "ACTOR_EN_MM2", - /* 0x01D5 */ "ACTOR_BG_JYA_BLOCK", - /* 0x01D6 */ "ACTOR_OBJ_WARP2BLOCK", - /* 0x01D7 */ "ACTOR_ID_MAX" // originally "ACTOR_DLF_MAX" +static const std::string ActorList[] = { + /* 0x0000 */ "ACTOR_PLAYER", + /* 0x0001 */ "ACTOR_UNSET_1", + /* 0x0002 */ "ACTOR_EN_TEST", + /* 0x0003 */ "ACTOR_UNSET_3", + /* 0x0004 */ "ACTOR_EN_GIRLA", + /* 0x0005 */ "ACTOR_UNSET_5", + /* 0x0006 */ "ACTOR_UNSET_6", + /* 0x0007 */ "ACTOR_EN_PART", + /* 0x0008 */ "ACTOR_EN_LIGHT", + /* 0x0009 */ "ACTOR_EN_DOOR", + /* 0x000A */ "ACTOR_EN_BOX", // Treasure Chest + /* 0x000B */ "ACTOR_BG_DY_YOSEIZO", + /* 0x000C */ "ACTOR_BG_HIDAN_FIREWALL", + /* 0x000D */ "ACTOR_EN_POH", + /* 0x000E */ "ACTOR_EN_OKUTA", + /* 0x000F */ "ACTOR_BG_YDAN_SP", + /* 0x0010 */ "ACTOR_EN_BOM", + /* 0x0011 */ "ACTOR_EN_WALLMAS", + /* 0x0012 */ "ACTOR_EN_DODONGO", + /* 0x0013 */ "ACTOR_EN_FIREFLY", + /* 0x0014 */ "ACTOR_EN_HORSE", + /* 0x0015 */ "ACTOR_EN_ITEM00", + /* 0x0016 */ "ACTOR_EN_ARROW", + /* 0x0017 */ "ACTOR_UNSET_17", + /* 0x0018 */ "ACTOR_EN_ELF", + /* 0x0019 */ "ACTOR_EN_NIW", + /* 0x001A */ "ACTOR_UNSET_1A", + /* 0x001B */ "ACTOR_EN_TITE", + /* 0x001C */ "ACTOR_EN_REEBA", + /* 0x001D */ "ACTOR_EN_PEEHAT", + /* 0x001E */ "ACTOR_EN_BUTTE", + /* 0x001F */ "ACTOR_UNSET_1F", + /* 0x0020 */ "ACTOR_EN_INSECT", + /* 0x0021 */ "ACTOR_EN_FISH", + /* 0x0022 */ "ACTOR_UNSET_22", + /* 0x0023 */ "ACTOR_EN_HOLL", + /* 0x0024 */ "ACTOR_EN_SCENE_CHANGE", + /* 0x0025 */ "ACTOR_EN_ZF", + /* 0x0026 */ "ACTOR_EN_HATA", + /* 0x0027 */ "ACTOR_BOSS_DODONGO", + /* 0x0028 */ "ACTOR_BOSS_GOMA", + /* 0x0029 */ "ACTOR_EN_ZL1", + /* 0x002A */ "ACTOR_EN_VIEWER", + /* 0x002B */ "ACTOR_EN_GOMA", + /* 0x002C */ "ACTOR_BG_PUSHBOX", + /* 0x002D */ "ACTOR_EN_BUBBLE", + /* 0x002E */ "ACTOR_DOOR_SHUTTER", + /* 0x002F */ "ACTOR_EN_DODOJR", + /* 0x0030 */ "ACTOR_EN_BDFIRE", + /* 0x0031 */ "ACTOR_UNSET_31", + /* 0x0032 */ "ACTOR_EN_BOOM", + /* 0x0033 */ "ACTOR_EN_TORCH2", + /* 0x0034 */ "ACTOR_EN_BILI", + /* 0x0035 */ "ACTOR_EN_TP", + /* 0x0036 */ "ACTOR_UNSET_36", + /* 0x0037 */ "ACTOR_EN_ST", + /* 0x0038 */ "ACTOR_EN_BW", + /* 0x0039 */ "ACTOR_EN_A_OBJ", + /* 0x003A */ "ACTOR_EN_EIYER", + /* 0x003B */ "ACTOR_EN_RIVER_SOUND", + /* 0x003C */ "ACTOR_EN_HORSE_NORMAL", + /* 0x003D */ "ACTOR_EN_OSSAN", + /* 0x003E */ "ACTOR_BG_TREEMOUTH", + /* 0x003F */ "ACTOR_BG_DODOAGO", + /* 0x0040 */ "ACTOR_BG_HIDAN_DALM", + /* 0x0041 */ "ACTOR_BG_HIDAN_HROCK", + /* 0x0042 */ "ACTOR_EN_HORSE_GANON", + /* 0x0043 */ "ACTOR_BG_HIDAN_ROCK", + /* 0x0044 */ "ACTOR_BG_HIDAN_RSEKIZOU", + /* 0x0045 */ "ACTOR_BG_HIDAN_SEKIZOU", + /* 0x0046 */ "ACTOR_BG_HIDAN_SIMA", + /* 0x0047 */ "ACTOR_BG_HIDAN_SYOKU", + /* 0x0048 */ "ACTOR_EN_XC", + /* 0x0049 */ "ACTOR_BG_HIDAN_CURTAIN", + /* 0x004A */ "ACTOR_BG_SPOT00_HANEBASI", + /* 0x004B */ "ACTOR_EN_MB", + /* 0x004C */ "ACTOR_EN_BOMBF", + /* 0x004D */ "ACTOR_EN_ZL2", + /* 0x004E */ "ACTOR_BG_HIDAN_FSLIFT", + /* 0x004F */ "ACTOR_EN_OE2", + /* 0x0050 */ "ACTOR_BG_YDAN_HASI", + /* 0x0051 */ "ACTOR_BG_YDAN_MARUTA", + /* 0x0052 */ "ACTOR_BOSS_GANONDROF", + /* 0x0053 */ "ACTOR_UNSET_53", + /* 0x0054 */ "ACTOR_EN_AM", + /* 0x0055 */ "ACTOR_EN_DEKUBABA", + /* 0x0056 */ "ACTOR_EN_M_FIRE1", + /* 0x0057 */ "ACTOR_EN_M_THUNDER", + /* 0x0058 */ "ACTOR_BG_DDAN_JD", + /* 0x0059 */ "ACTOR_BG_BREAKWALL", + /* 0x005A */ "ACTOR_EN_JJ", + /* 0x005B */ "ACTOR_EN_HORSE_ZELDA", + /* 0x005C */ "ACTOR_BG_DDAN_KD", + /* 0x005D */ "ACTOR_DOOR_WARP1", + /* 0x005E */ "ACTOR_OBJ_SYOKUDAI", + /* 0x005F */ "ACTOR_ITEM_B_HEART", + /* 0x0060 */ "ACTOR_EN_DEKUNUTS", + /* 0x0061 */ "ACTOR_BG_MENKURI_KAITEN", + /* 0x0062 */ "ACTOR_BG_MENKURI_EYE", + /* 0x0063 */ "ACTOR_EN_VALI", + /* 0x0064 */ "ACTOR_BG_MIZU_MOVEBG", + /* 0x0065 */ "ACTOR_BG_MIZU_WATER", + /* 0x0066 */ "ACTOR_ARMS_HOOK", + /* 0x0067 */ "ACTOR_EN_FHG", + /* 0x0068 */ "ACTOR_BG_MORI_HINERI", + /* 0x0069 */ "ACTOR_EN_BB", + /* 0x006A */ "ACTOR_BG_TOKI_HIKARI", + /* 0x006B */ "ACTOR_EN_YUKABYUN", + /* 0x006C */ "ACTOR_BG_TOKI_SWD", + /* 0x006D */ "ACTOR_EN_FHG_FIRE", + /* 0x006E */ "ACTOR_BG_MJIN", + /* 0x006F */ "ACTOR_BG_HIDAN_KOUSI", + /* 0x0070 */ "ACTOR_DOOR_TOKI", + /* 0x0071 */ "ACTOR_BG_HIDAN_HAMSTEP", + /* 0x0072 */ "ACTOR_EN_BIRD", + /* 0x0073 */ "ACTOR_UNSET_73", + /* 0x0074 */ "ACTOR_UNSET_74", + /* 0x0075 */ "ACTOR_UNSET_75", + /* 0x0076 */ "ACTOR_UNSET_76", + /* 0x0077 */ "ACTOR_EN_WOOD02", + /* 0x0078 */ "ACTOR_UNSET_78", + /* 0x0079 */ "ACTOR_UNSET_79", + /* 0x007A */ "ACTOR_UNSET_7A", + /* 0x007B */ "ACTOR_UNSET_7B", + /* 0x007C */ "ACTOR_EN_LIGHTBOX", + /* 0x007D */ "ACTOR_EN_PU_BOX", + /* 0x007E */ "ACTOR_UNSET_7E", + /* 0x007F */ "ACTOR_UNSET_7F", + /* 0x0080 */ "ACTOR_EN_TRAP", + /* 0x0081 */ "ACTOR_EN_AROW_TRAP", + /* 0x0082 */ "ACTOR_EN_VASE", + /* 0x0083 */ "ACTOR_UNSET_83", + /* 0x0084 */ "ACTOR_EN_TA", + /* 0x0085 */ "ACTOR_EN_TK", + /* 0x0086 */ "ACTOR_BG_MORI_BIGST", + /* 0x0087 */ "ACTOR_BG_MORI_ELEVATOR", + /* 0x0088 */ "ACTOR_BG_MORI_KAITENKABE", + /* 0x0089 */ "ACTOR_BG_MORI_RAKKATENJO", + /* 0x008A */ "ACTOR_EN_VM", + /* 0x008B */ "ACTOR_DEMO_EFFECT", + /* 0x008C */ "ACTOR_DEMO_KANKYO", + /* 0x008D */ "ACTOR_BG_HIDAN_FWBIG", + /* 0x008E */ "ACTOR_EN_FLOORMAS", + /* 0x008F */ "ACTOR_EN_HEISHI1", + /* 0x0090 */ "ACTOR_EN_RD", + /* 0x0091 */ "ACTOR_EN_PO_SISTERS", + /* 0x0092 */ "ACTOR_BG_HEAVY_BLOCK", + /* 0x0093 */ "ACTOR_BG_PO_EVENT", + /* 0x0094 */ "ACTOR_OBJ_MURE", + /* 0x0095 */ "ACTOR_EN_SW", + /* 0x0096 */ "ACTOR_BOSS_FD", + /* 0x0097 */ "ACTOR_OBJECT_KANKYO", + /* 0x0098 */ "ACTOR_EN_DU", + /* 0x0099 */ "ACTOR_EN_FD", + /* 0x009A */ "ACTOR_EN_HORSE_LINK_CHILD", + /* 0x009B */ "ACTOR_DOOR_ANA", + /* 0x009C */ "ACTOR_BG_SPOT02_OBJECTS", + /* 0x009D */ "ACTOR_BG_HAKA", + /* 0x009E */ "ACTOR_MAGIC_WIND", + /* 0x009F */ "ACTOR_MAGIC_FIRE", + /* 0x00A0 */ "ACTOR_UNSET_A0", + /* 0x00A1 */ "ACTOR_EN_RU1", + /* 0x00A2 */ "ACTOR_BOSS_FD2", + /* 0x00A3 */ "ACTOR_EN_FD_FIRE", + /* 0x00A4 */ "ACTOR_EN_DH", + /* 0x00A5 */ "ACTOR_EN_DHA", + /* 0x00A6 */ "ACTOR_EN_RL", + /* 0x00A7 */ "ACTOR_EN_ENCOUNT1", + /* 0x00A8 */ "ACTOR_DEMO_DU", + /* 0x00A9 */ "ACTOR_DEMO_IM", + /* 0x00AA */ "ACTOR_DEMO_TRE_LGT", + /* 0x00AB */ "ACTOR_EN_FW", + /* 0x00AC */ "ACTOR_BG_VB_SIMA", + /* 0x00AD */ "ACTOR_EN_VB_BALL", + /* 0x00AE */ "ACTOR_BG_HAKA_MEGANE", + /* 0x00AF */ "ACTOR_BG_HAKA_MEGANEBG", + /* 0x00B0 */ "ACTOR_BG_HAKA_SHIP", + /* 0x00B1 */ "ACTOR_BG_HAKA_SGAMI", + /* 0x00B2 */ "ACTOR_UNSET_B2", + /* 0x00B3 */ "ACTOR_EN_HEISHI2", + /* 0x00B4 */ "ACTOR_EN_ENCOUNT2", + /* 0x00B5 */ "ACTOR_EN_FIRE_ROCK", + /* 0x00B6 */ "ACTOR_EN_BROB", + /* 0x00B7 */ "ACTOR_MIR_RAY", + /* 0x00B8 */ "ACTOR_BG_SPOT09_OBJ", + /* 0x00B9 */ "ACTOR_BG_SPOT18_OBJ", + /* 0x00BA */ "ACTOR_BOSS_VA", + /* 0x00BB */ "ACTOR_BG_HAKA_TUBO", + /* 0x00BC */ "ACTOR_BG_HAKA_TRAP", + /* 0x00BD */ "ACTOR_BG_HAKA_HUTA", + /* 0x00BE */ "ACTOR_BG_HAKA_ZOU", + /* 0x00BF */ "ACTOR_BG_SPOT17_FUNEN", + /* 0x00C0 */ "ACTOR_EN_SYATEKI_ITM", + /* 0x00C1 */ "ACTOR_EN_SYATEKI_MAN", + /* 0x00C2 */ "ACTOR_EN_TANA", + /* 0x00C3 */ "ACTOR_EN_NB", + /* 0x00C4 */ "ACTOR_BOSS_MO", + /* 0x00C5 */ "ACTOR_EN_SB", + /* 0x00C6 */ "ACTOR_EN_BIGOKUTA", + /* 0x00C7 */ "ACTOR_EN_KAREBABA", + /* 0x00C8 */ "ACTOR_BG_BDAN_OBJECTS", + /* 0x00C9 */ "ACTOR_DEMO_SA", + /* 0x00CA */ "ACTOR_DEMO_GO", + /* 0x00CB */ "ACTOR_EN_IN", + /* 0x00CC */ "ACTOR_EN_TR", + /* 0x00CD */ "ACTOR_BG_SPOT16_BOMBSTONE", + /* 0x00CE */ "ACTOR_UNSET_CE", + /* 0x00CF */ "ACTOR_BG_HIDAN_KOWARERUKABE", + /* 0x00D0 */ "ACTOR_BG_BOMBWALL", + /* 0x00D1 */ "ACTOR_BG_SPOT08_ICEBLOCK", + /* 0x00D2 */ "ACTOR_EN_RU2", + /* 0x00D3 */ "ACTOR_OBJ_DEKUJR", + /* 0x00D4 */ "ACTOR_BG_MIZU_UZU", + /* 0x00D5 */ "ACTOR_BG_SPOT06_OBJECTS", + /* 0x00D6 */ "ACTOR_BG_ICE_OBJECTS", + /* 0x00D7 */ "ACTOR_BG_HAKA_WATER", + /* 0x00D8 */ "ACTOR_UNSET_D8", + /* 0x00D9 */ "ACTOR_EN_MA2", + /* 0x00DA */ "ACTOR_EN_BOM_CHU", + /* 0x00DB */ "ACTOR_EN_HORSE_GAME_CHECK", + /* 0x00DC */ "ACTOR_BOSS_TW", + /* 0x00DD */ "ACTOR_EN_RR", + /* 0x00DE */ "ACTOR_EN_BA", + /* 0x00DF */ "ACTOR_EN_BX", + /* 0x00E0 */ "ACTOR_EN_ANUBICE", + /* 0x00E1 */ "ACTOR_EN_ANUBICE_FIRE", + /* 0x00E2 */ "ACTOR_BG_MORI_HASHIGO", + /* 0x00E3 */ "ACTOR_BG_MORI_HASHIRA4", + /* 0x00E4 */ "ACTOR_BG_MORI_IDOMIZU", + /* 0x00E5 */ "ACTOR_BG_SPOT16_DOUGHNUT", + /* 0x00E6 */ "ACTOR_BG_BDAN_SWITCH", + /* 0x00E7 */ "ACTOR_EN_MA1", + /* 0x00E8 */ "ACTOR_BOSS_GANON", + /* 0x00E9 */ "ACTOR_BOSS_SST", + /* 0x00EA */ "ACTOR_UNSET_EA", + /* 0x00EB */ "ACTOR_UNSET_EB", + /* 0x00EC */ "ACTOR_EN_NY", + /* 0x00ED */ "ACTOR_EN_FR", + /* 0x00EE */ "ACTOR_ITEM_SHIELD", + /* 0x00EF */ "ACTOR_BG_ICE_SHELTER", + /* 0x00F0 */ "ACTOR_EN_ICE_HONO", + /* 0x00F1 */ "ACTOR_ITEM_OCARINA", + /* 0x00F2 */ "ACTOR_UNSET_F2", + /* 0x00F3 */ "ACTOR_UNSET_F3", + /* 0x00F4 */ "ACTOR_MAGIC_DARK", + /* 0x00F5 */ "ACTOR_DEMO_6K", + /* 0x00F6 */ "ACTOR_EN_ANUBICE_TAG", + /* 0x00F7 */ "ACTOR_BG_HAKA_GATE", + /* 0x00F8 */ "ACTOR_BG_SPOT15_SAKU", + /* 0x00F9 */ "ACTOR_BG_JYA_GOROIWA", + /* 0x00FA */ "ACTOR_BG_JYA_ZURERUKABE", + /* 0x00FB */ "ACTOR_UNSET_FB", + /* 0x00FC */ "ACTOR_BG_JYA_COBRA", + /* 0x00FD */ "ACTOR_BG_JYA_KANAAMI", + /* 0x00FE */ "ACTOR_FISHING", + /* 0x00FF */ "ACTOR_OBJ_OSHIHIKI", + /* 0x0100 */ "ACTOR_BG_GATE_SHUTTER", + /* 0x0101 */ "ACTOR_EFF_DUST", + /* 0x0102 */ "ACTOR_BG_SPOT01_FUSYA", + /* 0x0103 */ "ACTOR_BG_SPOT01_IDOHASHIRA", + /* 0x0104 */ "ACTOR_BG_SPOT01_IDOMIZU", + /* 0x0105 */ "ACTOR_BG_PO_SYOKUDAI", + /* 0x0106 */ "ACTOR_BG_GANON_OTYUKA", + /* 0x0107 */ "ACTOR_BG_SPOT15_RRBOX", + /* 0x0108 */ "ACTOR_BG_UMAJUMP", + /* 0x0109 */ "ACTOR_UNSET_109", + /* 0x010A */ "ACTOR_ARROW_FIRE", + /* 0x010B */ "ACTOR_ARROW_ICE", + /* 0x010C */ "ACTOR_ARROW_LIGHT", + /* 0x010D */ "ACTOR_UNSET_10D", + /* 0x010E */ "ACTOR_UNSET_10E", + /* 0x010F */ "ACTOR_ITEM_ETCETERA", + /* 0x0110 */ "ACTOR_OBJ_KIBAKO", + /* 0x0111 */ "ACTOR_OBJ_TSUBO", + /* 0x0112 */ "ACTOR_EN_WONDER_ITEM", + /* 0x0113 */ "ACTOR_EN_IK", + /* 0x0114 */ "ACTOR_DEMO_IK", + /* 0x0115 */ "ACTOR_EN_SKJ", + /* 0x0116 */ "ACTOR_EN_SKJNEEDLE", + /* 0x0117 */ "ACTOR_EN_G_SWITCH", + /* 0x0118 */ "ACTOR_DEMO_EXT", + /* 0x0119 */ "ACTOR_DEMO_SHD", + /* 0x011A */ "ACTOR_EN_DNS", + /* 0x011B */ "ACTOR_ELF_MSG", + /* 0x011C */ "ACTOR_EN_HONOTRAP", + /* 0x011D */ "ACTOR_EN_TUBO_TRAP", + /* 0x011E */ "ACTOR_OBJ_ICE_POLY", + /* 0x011F */ "ACTOR_BG_SPOT03_TAKI", + /* 0x0120 */ "ACTOR_BG_SPOT07_TAKI", + /* 0x0121 */ "ACTOR_EN_FZ", + /* 0x0122 */ "ACTOR_EN_PO_RELAY", + /* 0x0123 */ "ACTOR_BG_RELAY_OBJECTS", + /* 0x0124 */ "ACTOR_EN_DIVING_GAME", + /* 0x0125 */ "ACTOR_EN_KUSA", + /* 0x0126 */ "ACTOR_OBJ_BEAN", + /* 0x0127 */ "ACTOR_OBJ_BOMBIWA", + /* 0x0128 */ "ACTOR_UNSET_128", + /* 0x0129 */ "ACTOR_UNSET_129", + /* 0x012A */ "ACTOR_OBJ_SWITCH", + /* 0x012B */ "ACTOR_OBJ_ELEVATOR", + /* 0x012C */ "ACTOR_OBJ_LIFT", + /* 0x012D */ "ACTOR_OBJ_HSBLOCK", + /* 0x012E */ "ACTOR_EN_OKARINA_TAG", + /* 0x012F */ "ACTOR_EN_YABUSAME_MARK", + /* 0x0130 */ "ACTOR_EN_GOROIWA", + /* 0x0131 */ "ACTOR_EN_EX_RUPPY", + /* 0x0132 */ "ACTOR_EN_TORYO", + /* 0x0133 */ "ACTOR_EN_DAIKU", + /* 0x0134 */ "ACTOR_UNSET_134", + /* 0x0135 */ "ACTOR_EN_NWC", + /* 0x0136 */ "ACTOR_EN_BLKOBJ", + /* 0x0137 */ "ACTOR_ITEM_INBOX", + /* 0x0138 */ "ACTOR_EN_GE1", + /* 0x0139 */ "ACTOR_OBJ_BLOCKSTOP", + /* 0x013A */ "ACTOR_EN_SDA", + /* 0x013B */ "ACTOR_EN_CLEAR_TAG", + /* 0x013C */ "ACTOR_EN_NIW_LADY", + /* 0x013D */ "ACTOR_EN_GM", + /* 0x013E */ "ACTOR_EN_MS", + /* 0x013F */ "ACTOR_EN_HS", + /* 0x0140 */ "ACTOR_BG_INGATE", + /* 0x0141 */ "ACTOR_EN_KANBAN", + /* 0x0142 */ "ACTOR_EN_HEISHI3", + /* 0x0143 */ "ACTOR_EN_SYATEKI_NIW", + /* 0x0144 */ "ACTOR_EN_ATTACK_NIW", + /* 0x0145 */ "ACTOR_BG_SPOT01_IDOSOKO", + /* 0x0146 */ "ACTOR_EN_SA", + /* 0x0147 */ "ACTOR_EN_WONDER_TALK", + /* 0x0148 */ "ACTOR_BG_GJYO_BRIDGE", + /* 0x0149 */ "ACTOR_EN_DS", + /* 0x014A */ "ACTOR_EN_MK", + /* 0x014B */ "ACTOR_EN_BOM_BOWL_MAN", + /* 0x014C */ "ACTOR_EN_BOM_BOWL_PIT", + /* 0x014D */ "ACTOR_EN_OWL", + /* 0x014E */ "ACTOR_EN_ISHI", + /* 0x014F */ "ACTOR_OBJ_HANA", + /* 0x0150 */ "ACTOR_OBJ_LIGHTSWITCH", + /* 0x0151 */ "ACTOR_OBJ_MURE2", + /* 0x0152 */ "ACTOR_EN_GO", + /* 0x0153 */ "ACTOR_EN_FU", + /* 0x0154 */ "ACTOR_UNSET_154", + /* 0x0155 */ "ACTOR_EN_CHANGER", + /* 0x0156 */ "ACTOR_BG_JYA_MEGAMI", + /* 0x0157 */ "ACTOR_BG_JYA_LIFT", + /* 0x0158 */ "ACTOR_BG_JYA_BIGMIRROR", + /* 0x0159 */ "ACTOR_BG_JYA_BOMBCHUIWA", + /* 0x015A */ "ACTOR_BG_JYA_AMISHUTTER", + /* 0x015B */ "ACTOR_BG_JYA_BOMBIWA", + /* 0x015C */ "ACTOR_BG_SPOT18_BASKET", + /* 0x015D */ "ACTOR_UNSET_15D", + /* 0x015E */ "ACTOR_EN_GANON_ORGAN", + /* 0x015F */ "ACTOR_EN_SIOFUKI", + /* 0x0160 */ "ACTOR_EN_STREAM", + /* 0x0161 */ "ACTOR_UNSET_161", + /* 0x0162 */ "ACTOR_EN_MM", + /* 0x0163 */ "ACTOR_EN_KO", + /* 0x0164 */ "ACTOR_EN_KZ", + /* 0x0165 */ "ACTOR_EN_WEATHER_TAG", + /* 0x0166 */ "ACTOR_BG_SST_FLOOR", + /* 0x0167 */ "ACTOR_EN_ANI", + /* 0x0168 */ "ACTOR_EN_EX_ITEM", + /* 0x0169 */ "ACTOR_BG_JYA_IRONOBJ", + /* 0x016A */ "ACTOR_EN_JS", + /* 0x016B */ "ACTOR_EN_JSJUTAN", + /* 0x016C */ "ACTOR_EN_CS", + /* 0x016D */ "ACTOR_EN_MD", + /* 0x016E */ "ACTOR_EN_HY", + /* 0x016F */ "ACTOR_EN_GANON_MANT", + /* 0x0170 */ "ACTOR_EN_OKARINA_EFFECT", + /* 0x0171 */ "ACTOR_EN_MAG", + /* 0x0172 */ "ACTOR_DOOR_GERUDO", + /* 0x0173 */ "ACTOR_ELF_MSG2", + /* 0x0174 */ "ACTOR_DEMO_GT", + /* 0x0175 */ "ACTOR_EN_PO_FIELD", + /* 0x0176 */ "ACTOR_EFC_ERUPC", + /* 0x0177 */ "ACTOR_BG_ZG", + /* 0x0178 */ "ACTOR_EN_HEISHI4", + /* 0x0179 */ "ACTOR_EN_ZL3", + /* 0x017A */ "ACTOR_BOSS_GANON2", + /* 0x017B */ "ACTOR_EN_KAKASI", + /* 0x017C */ "ACTOR_EN_TAKARA_MAN", + /* 0x017D */ "ACTOR_OBJ_MAKEOSHIHIKI", + /* 0x017E */ "ACTOR_OCEFF_SPOT", + /* 0x017F */ "ACTOR_END_TITLE", + /* 0x0180 */ "ACTOR_UNSET_180", + /* 0x0181 */ "ACTOR_EN_TORCH", + /* 0x0182 */ "ACTOR_DEMO_EC", + /* 0x0183 */ "ACTOR_SHOT_SUN", + /* 0x0184 */ "ACTOR_EN_DY_EXTRA", + /* 0x0185 */ "ACTOR_EN_WONDER_TALK2", + /* 0x0186 */ "ACTOR_EN_GE2", + /* 0x0187 */ "ACTOR_OBJ_ROOMTIMER", + /* 0x0188 */ "ACTOR_EN_SSH", + /* 0x0189 */ "ACTOR_EN_STH", + /* 0x018A */ "ACTOR_OCEFF_WIPE", + /* 0x018B */ "ACTOR_OCEFF_STORM", + /* 0x018C */ "ACTOR_EN_WEIYER", + /* 0x018D */ "ACTOR_BG_SPOT05_SOKO", + /* 0x018E */ "ACTOR_BG_JYA_1FLIFT", + /* 0x018F */ "ACTOR_BG_JYA_HAHENIRON", + /* 0x0190 */ "ACTOR_BG_SPOT12_GATE", + /* 0x0191 */ "ACTOR_BG_SPOT12_SAKU", + /* 0x0192 */ "ACTOR_EN_HINTNUTS", + /* 0x0193 */ "ACTOR_EN_NUTSBALL", + /* 0x0194 */ "ACTOR_BG_SPOT00_BREAK", + /* 0x0195 */ "ACTOR_EN_SHOPNUTS", + /* 0x0196 */ "ACTOR_EN_IT", + /* 0x0197 */ "ACTOR_EN_GELDB", + /* 0x0198 */ "ACTOR_OCEFF_WIPE2", + /* 0x0199 */ "ACTOR_OCEFF_WIPE3", + /* 0x019A */ "ACTOR_EN_NIW_GIRL", + /* 0x019B */ "ACTOR_EN_DOG", + /* 0x019C */ "ACTOR_EN_SI", + /* 0x019D */ "ACTOR_BG_SPOT01_OBJECTS2", + /* 0x019E */ "ACTOR_OBJ_COMB", + /* 0x019F */ "ACTOR_BG_SPOT11_BAKUDANKABE", + /* 0x01A0 */ "ACTOR_OBJ_KIBAKO2", + /* 0x01A1 */ "ACTOR_EN_DNT_DEMO", + /* 0x01A2 */ "ACTOR_EN_DNT_JIJI", + /* 0x01A3 */ "ACTOR_EN_DNT_NOMAL", + /* 0x01A4 */ "ACTOR_EN_GUEST", + /* 0x01A5 */ "ACTOR_BG_BOM_GUARD", + /* 0x01A6 */ "ACTOR_EN_HS2", + /* 0x01A7 */ "ACTOR_DEMO_KEKKAI", + /* 0x01A8 */ "ACTOR_BG_SPOT08_BAKUDANKABE", + /* 0x01A9 */ "ACTOR_BG_SPOT17_BAKUDANKABE", + /* 0x01AA */ "ACTOR_UNSET_1AA", + /* 0x01AB */ "ACTOR_OBJ_MURE3", + /* 0x01AC */ "ACTOR_EN_TG", + /* 0x01AD */ "ACTOR_EN_MU", + /* 0x01AE */ "ACTOR_EN_GO2", + /* 0x01AF */ "ACTOR_EN_WF", + /* 0x01B0 */ "ACTOR_EN_SKB", + /* 0x01B1 */ "ACTOR_DEMO_GJ", + /* 0x01B2 */ "ACTOR_DEMO_GEFF", + /* 0x01B3 */ "ACTOR_BG_GND_FIREMEIRO", + /* 0x01B4 */ "ACTOR_BG_GND_DARKMEIRO", + /* 0x01B5 */ "ACTOR_BG_GND_SOULMEIRO", + /* 0x01B6 */ "ACTOR_BG_GND_NISEKABE", + /* 0x01B7 */ "ACTOR_BG_GND_ICEBLOCK", + /* 0x01B8 */ "ACTOR_EN_GB", + /* 0x01B9 */ "ACTOR_EN_GS", + /* 0x01BA */ "ACTOR_BG_MIZU_BWALL", + /* 0x01BB */ "ACTOR_BG_MIZU_SHUTTER", + /* 0x01BC */ "ACTOR_EN_DAIKU_KAKARIKO", + /* 0x01BD */ "ACTOR_BG_BOWL_WALL", + /* 0x01BE */ "ACTOR_EN_WALL_TUBO", + /* 0x01BF */ "ACTOR_EN_PO_DESERT", + /* 0x01C0 */ "ACTOR_EN_CROW", + /* 0x01C1 */ "ACTOR_DOOR_KILLER", + /* 0x01C2 */ "ACTOR_BG_SPOT11_OASIS", + /* 0x01C3 */ "ACTOR_BG_SPOT18_FUTA", + /* 0x01C4 */ "ACTOR_BG_SPOT18_SHUTTER", + /* 0x01C5 */ "ACTOR_EN_MA3", + /* 0x01C6 */ "ACTOR_EN_COW", + /* 0x01C7 */ "ACTOR_BG_ICE_TURARA", + /* 0x01C8 */ "ACTOR_BG_ICE_SHUTTER", + /* 0x01C9 */ "ACTOR_EN_KAKASI2", + /* 0x01CA */ "ACTOR_EN_KAKASI3", + /* 0x01CB */ "ACTOR_OCEFF_WIPE4", + /* 0x01CC */ "ACTOR_EN_EG", + /* 0x01CD */ "ACTOR_BG_MENKURI_NISEKABE", + /* 0x01CE */ "ACTOR_EN_ZO", + /* 0x01CF */ "ACTOR_OBJ_MAKEKINSUTA", + /* 0x01D0 */ "ACTOR_EN_GE3", + /* 0x01D1 */ "ACTOR_OBJ_TIMEBLOCK", + /* 0x01D2 */ "ACTOR_OBJ_HAMISHI", + /* 0x01D3 */ "ACTOR_EN_ZL4", + /* 0x01D4 */ "ACTOR_EN_MM2", + /* 0x01D5 */ "ACTOR_BG_JYA_BLOCK", + /* 0x01D6 */ "ACTOR_OBJ_WARP2BLOCK", + /* 0x01D7 */ "ACTOR_ID_MAX" // originally "ACTOR_DLF_MAX" }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.cpp index a077ce9744..81320a99c4 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.cpp @@ -3,13 +3,15 @@ using namespace std; -EndMarker::EndMarker(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +EndMarker::EndMarker(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { } string EndMarker::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str()); + return StringHelper::Sprintf( + "%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str()); } string EndMarker::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.cpp index 30ed52e072..762105106e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.cpp @@ -1,14 +1,15 @@ #include "SetActorList.h" -#include "../../ZFile.h" -#include "../ZRoom.h" -#include "../ActorList.h" #include "../../BitConverter.h" -#include "../../StringHelper.h" #include "../../Globals.h" +#include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ActorList.h" +#include "../ZRoom.h" using namespace std; -SetActorList::SetActorList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetActorList::SetActorList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { numActors = rawData[rawDataIndex + 1]; segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); @@ -38,15 +39,14 @@ string SetActorList::GenerateSourceCodePass1(string roomName, int baseAddress) return ""; } - string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress) { string sourceOutput = ""; - int numActorsReal = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 16; + size_t numActorsReal = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 16; actors = vector(); uint32_t currentPtr = segmentOffset; - for (int i = 0; i < numActorsReal; i++) + for (size_t i = 0; i < numActorsReal; i++) { ActorSpawnEntry* entry = new ActorSpawnEntry(_rawData, currentPtr); actors.push_back(entry); @@ -54,32 +54,47 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress) currentPtr += 16; } - sourceOutput += StringHelper::Sprintf("%s 0x%02X, (u32)%sActorList0x%06X };", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), numActors, roomName.c_str(), segmentOffset); + sourceOutput += + StringHelper::Sprintf("%s 0x%02X, (u32)%sActorList0x%06X };", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + numActors, roomName.c_str(), segmentOffset); - //zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, GetRawDataSize(), - //"SCmdActorList", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress), sourceOutput); + // zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, + // DeclarationPadding::None, GetRawDataSize(), "SCmdActorList", + //ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress), sourceOutput); string declaration = ""; - int index = 0; + size_t index = 0; for (ActorSpawnEntry* entry : actors) { uint16_t actorNum = entry->actorNum; // SW97 Actor 0x22 was removed, so we want to not output a working actor. if (actorNum == 0x22 && Globals::Instance->game == ZGame::OOT_SW97) - declaration += StringHelper::Sprintf("\t//{ %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", /*StringHelper::Sprintf("SW_REMOVED_0x%04X", actorNum).c_str()*/ "ACTOR_DUNGEON_KEEP", entry->posX, entry->posY, entry->posZ, entry->rotX, entry->rotY, entry->rotZ, (uint16_t)entry->initVar, segmentOffset + (index * 16)); + declaration += StringHelper::Sprintf( + "\t//{ %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", + /*StringHelper::Sprintf("SW_REMOVED_0x%04X", actorNum).c_str()*/ + "ACTOR_DUNGEON_KEEP", entry->posX, entry->posY, entry->posZ, entry->rotX, + entry->rotY, entry->rotZ, (uint16_t)entry->initVar, segmentOffset + (index * 16)); else { - // SW97 Actor 0x23 and above are shifted up by one because 0x22 was removed between SW97 and retail. - // We need to shift down by one + // SW97 Actor 0x23 and above are shifted up by one because 0x22 was removed between SW97 + // and retail. We need to shift down by one if (Globals::Instance->game == ZGame::OOT_SW97 && actorNum >= 0x23) actorNum--; if (actorNum < sizeof(ActorList) / sizeof(ActorList[0])) - declaration += StringHelper::Sprintf("\t{ %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", ActorList[actorNum].c_str(), entry->posX, entry->posY, entry->posZ, entry->rotX, entry->rotY, entry->rotZ, (uint16_t)entry->initVar, segmentOffset + (index * 16)); + declaration += + StringHelper::Sprintf("\t{ %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", + ActorList[actorNum].c_str(), entry->posX, entry->posY, + entry->posZ, entry->rotX, entry->rotY, entry->rotZ, + (uint16_t)entry->initVar, segmentOffset + (index * 16)); else - declaration += StringHelper::Sprintf("\t{ 0x%04X, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", actorNum, entry->posX, entry->posY, entry->posZ, entry->rotX, entry->rotY, entry->rotZ, (uint16_t)entry->initVar, segmentOffset + (index * 16)); + declaration += StringHelper::Sprintf( + "\t{ 0x%04X, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", actorNum, entry->posX, + entry->posY, entry->posZ, entry->rotX, entry->rotY, entry->rotZ, + (uint16_t)entry->initVar, segmentOffset + (index * 16)); if (index < actors.size() - 1) declaration += "\n"; @@ -88,8 +103,10 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress) index++; } - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, actors.size() * 16, - "ActorEntry", StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset), GetActorListArraySize(), declaration); + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, actors.size() * 16, + "ActorEntry", StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset), + GetActorListArraySize(), declaration); return sourceOutput; } @@ -99,12 +116,13 @@ int32_t SetActorList::GetRawDataSize() return ZRoomCommand::GetRawDataSize() + ((int)actors.size() * 16); } -int SetActorList::GetActorListArraySize() +size_t SetActorList::GetActorListArraySize() { - int actorCount = 0; + size_t actorCount = 0; // Doing an else-if here so we only do the loop when the game is SW97. - // Actor 0x22 is removed from SW97, so we need to ensure that we don't increment the actor count for it. + // Actor 0x22 is removed from SW97, so we need to ensure that we don't increment the actor count + // for it. if (Globals::Instance->game == ZGame::OOT_SW97) { actorCount = 0; @@ -115,7 +133,7 @@ int SetActorList::GetActorListArraySize() } else { - actorCount = (int)actors.size(); + actorCount = actors.size(); } return actorCount; @@ -123,7 +141,8 @@ int SetActorList::GetActorListArraySize() string SetActorList::GenerateExterns() { - return StringHelper::Sprintf("extern ActorEntry %sActorList0x%06X[%i];\n", zRoom->GetName().c_str(), segmentOffset, GetActorListArraySize()); + return StringHelper::Sprintf("extern ActorEntry %sActorList0x%06X[%i];\n", + zRoom->GetName().c_str(), segmentOffset, GetActorListArraySize()); } string SetActorList::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.h index 3f59494c97..d18d6ba06b 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.h @@ -32,7 +32,7 @@ public: virtual std::string GenerateExterns(); private: - int GetActorListArraySize(); + size_t GetActorListArraySize(); int numActors; std::vector actors; uint32_t segmentOffset; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp index 894a37c760..914d2d7da0 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp @@ -1,17 +1,19 @@ #include "SetAlternateHeaders.h" -#include "../../ZFile.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" using namespace std; -SetAlternateHeaders::SetAlternateHeaders(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetAlternateHeaders::SetAlternateHeaders(ZRoom* nZRoom, std::vector rawData, + int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); if (segmentOffset != 0) zRoom->parent->AddDeclarationPlaceholder(segmentOffset); - + _rawData = rawData; _rawDataIndex = rawDataIndex; } @@ -30,22 +32,28 @@ string SetAlternateHeaders::GenerateSourceCodePass1(string roomName, int baseAdd zRoom->commandSets.push_back(CommandSet(address)); } - sourceOutput += StringHelper::Sprintf("%s 0, (u32)&%sAlternateHeaders0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), roomName.c_str(), segmentOffset); + sourceOutput += + StringHelper::Sprintf("%s 0, (u32)&%sAlternateHeaders0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + roomName.c_str(), segmentOffset); string declaration = ""; for (int i = 0; i < numHeaders; i++) { - //sprintf(line, "\t0x%06X,\n", headers[i]); + // sprintf(line, "\t0x%06X,\n", headers[i]); if (headers[i] == 0) declaration += StringHelper::Sprintf("\t0,\n"); else - declaration += StringHelper::Sprintf("\t(u32)&%sSet%04XCmd00,\n", roomName.c_str(), headers[i] & 0x00FFFFFF); + declaration += StringHelper::Sprintf("\t(u32)&%sSet%04XCmd00,\n", roomName.c_str(), + headers[i] & 0x00FFFFFF); } - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, headers.size() * 4, - "u32", StringHelper::Sprintf("%sAlternateHeaders0x%06X", roomName.c_str(), segmentOffset), 0, declaration); + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, headers.size() * 4, "u32", + StringHelper::Sprintf("%sAlternateHeaders0x%06X", roomName.c_str(), segmentOffset), 0, + declaration); return sourceOutput; } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.h index d1dca33ca4..15a054312e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.h @@ -1,7 +1,7 @@ #pragma once -#include "../ZRoomCommand.h" #include "../ZRoom.h" +#include "../ZRoomCommand.h" class SetAlternateHeaders : public ZRoomCommand { diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp index 830aacc439..57f0dd71e8 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp @@ -4,7 +4,8 @@ using namespace std; -SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { cameraMovement = rawData[rawDataIndex + 0x01]; mapHighlight = BitConverter::ToInt32BE(rawData, rawDataIndex + 4); @@ -12,7 +13,9 @@ SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector rawData string SetCameraSettings::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), cameraMovement, mapHighlight); + return StringHelper::Sprintf( + "%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + cameraMovement, mapHighlight); } string SetCameraSettings::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp index 7f037086f3..90b0c595ff 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp @@ -1,20 +1,28 @@ #include "SetCollisionHeader.h" -#include "../ZRoom.h" -#include "../../ZFile.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" using namespace std; -SetCollisionHeader::SetCollisionHeader(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetCollisionHeader::SetCollisionHeader(ZRoom* nZRoom, std::vector rawData, + int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); - collisionHeader = ZCollisionHeader(nZRoom->parent, StringHelper::Sprintf("%sCollisionHeader0x%06X", nZRoom->GetName().c_str(), segmentOffset), rawData, segmentOffset); + collisionHeader = ZCollisionHeader( + nZRoom->parent, + StringHelper::Sprintf("%sCollisionHeader0x%06X", nZRoom->GetName().c_str(), segmentOffset), + rawData, segmentOffset); } string SetCollisionHeader::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x00, (u32)&%sCollisionHeader0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf( + "%s 0x00, (u32)&%sCollisionHeader0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + zRoom->GetName().c_str(), segmentOffset); } string SetCollisionHeader::GenerateSourceCodePass2(string roomName, int baseAddress) diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.h index d9ba188eb0..f2b12644af 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.h @@ -1,7 +1,7 @@ #pragma once -#include "../ZRoomCommand.h" #include "../../ZCollision.h" +#include "../ZRoomCommand.h" class SetCollisionHeader : public ZRoomCommand { diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp index 20c77c79a0..a253270f17 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp @@ -1,16 +1,16 @@ #include "SetCutscenes.h" -#include "../ZRoom.h" -#include "../../ZFile.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" using namespace std; -SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; - - uint32_t curPtr = segmentOffset; + string output = ""; cutscene = new ZCutscene(rawData, segmentOffset, 9999); @@ -18,8 +18,22 @@ SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector rawData, int rawD output += cutscene->GetSourceOutputCode(zRoom->GetName()); if (segmentOffset != 0) - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, cutscene->GetRawDataSize(), "s32", - StringHelper::Sprintf("%sCutsceneData0x%06X", zRoom->GetName().c_str(), segmentOffset), 0, output); + { + Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); + if (decl == nullptr) + { + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, + cutscene->GetRawDataSize(), "s32", + StringHelper::Sprintf("%sCutsceneData0x%06X", zRoom->GetName().c_str(), + segmentOffset), + 0, output); + } + else if (decl->text == "") + { + decl->text = output; + } + } } SetCutscenes::~SetCutscenes() @@ -33,7 +47,14 @@ SetCutscenes::~SetCutscenes() string SetCutscenes::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0, (u32)%sCutsceneData0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), zRoom->GetName().c_str(), segmentOffset); + string pass1 = ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress); + Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); + if (decl != nullptr) + { + return StringHelper::Sprintf("%s 0, (u32)%s", pass1.c_str(), decl->varName.c_str()); + } + return StringHelper::Sprintf("%s 0, (u32)%sCutsceneData0x%06X", pass1.c_str(), + zRoom->GetName().c_str(), segmentOffset); } int32_t SetCutscenes::GetRawDataSize() @@ -43,7 +64,13 @@ int32_t SetCutscenes::GetRawDataSize() string SetCutscenes::GenerateExterns() { - return StringHelper::Sprintf("extern s32 %sCutsceneData0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset); + Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); + if (decl != nullptr && decl->varName != "") + { + return StringHelper::Sprintf("extern s32 %s[];\n", decl->varName.c_str()); + } + return StringHelper::Sprintf("extern s32 %sCutsceneData0x%06X[];\n", zRoom->GetName().c_str(), + segmentOffset); } string SetCutscenes::GetCommandCName() @@ -59,4 +86,4 @@ RoomCommand SetCutscenes::GetRoomCommand() string SetCutscenes::GetSourceOutputCode(std::string prefix) { return ""; -} \ No newline at end of file +} diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h index 2234bf6eb7..5e7e6985a3 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h @@ -1,7 +1,7 @@ #pragma once -#include "../ZRoomCommand.h" #include "../../ZCutscene.h" +#include "../ZRoomCommand.h" class SetCutscenes : public ZRoomCommand { diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.cpp index 1d4c9826b2..40a11cfd3c 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.cpp @@ -3,14 +3,17 @@ using namespace std; -SetEchoSettings::SetEchoSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetEchoSettings::SetEchoSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { echo = rawData[rawDataIndex + 0x07]; } string SetEchoSettings::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0, { 0 }, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), echo); + return StringHelper::Sprintf( + "%s 0, { 0 }, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + echo); } string SetEchoSettings::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp index f9b48cd7d6..6e81552450 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp @@ -1,13 +1,14 @@ #include "SetEntranceList.h" -#include "SetStartPositionList.h" -#include "../../ZFile.h" -#include "../ZRoom.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" +#include "SetStartPositionList.h" using namespace std; -SetEntranceList::SetEntranceList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetEntranceList::SetEntranceList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; entrances = vector(); @@ -24,10 +25,13 @@ SetEntranceList::~SetEntranceList() string SetEntranceList::GenerateSourceCodePass1(string roomName, int baseAddress) { - string sourceOutput = StringHelper::Sprintf("%s 0x00, (u32)&%sEntranceList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), zRoom->GetName().c_str(), segmentOffset); + string sourceOutput = + StringHelper::Sprintf("%s 0x00, (u32)&%sEntranceList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + zRoom->GetName().c_str(), segmentOffset); // Parse Entrances and Generate Declaration - zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined + zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; uint32_t currentPtr = segmentOffset; @@ -45,19 +49,24 @@ string SetEntranceList::GenerateSourceCodePass1(string roomName, int baseAddress for (EntranceEntry* entry : entrances) { - declaration += StringHelper::Sprintf("\t{ 0x%02X, 0x%02X }, //0x%06X \n", entry->startPositionIndex, entry->roomToLoad, segmentOffset + (index * 2)); + declaration += + StringHelper::Sprintf("\t{ 0x%02X, 0x%02X }, //0x%06X \n", entry->startPositionIndex, + entry->roomToLoad, segmentOffset + (index * 2)); index++; } - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, entrances.size() * 2, "EntranceEntry", - StringHelper::Sprintf("%sEntranceList0x%06X", zRoom->GetName().c_str(), segmentOffset), entrances.size(), declaration); + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, entrances.size() * 2, "EntranceEntry", + StringHelper::Sprintf("%sEntranceList0x%06X", zRoom->GetName().c_str(), segmentOffset), + entrances.size(), declaration); return sourceOutput; } string SetEntranceList::GenerateExterns() { - return StringHelper::Sprintf("extern EntranceEntry %sEntranceList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf("extern EntranceEntry %sEntranceList0x%06X[];\n", + zRoom->GetName().c_str(), segmentOffset); } string SetEntranceList::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp index 89c7ddb08f..23b89e2290 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp @@ -1,12 +1,13 @@ #include "SetExitList.h" -#include "../ZRoom.h" -#include "../../ZFile.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" using namespace std; -SetExitList::SetExitList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetExitList::SetExitList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); exits = vector(); @@ -20,10 +21,13 @@ SetExitList::SetExitList(ZRoom* nZRoom, std::vector rawData, int rawDat string SetExitList::GenerateSourceCodePass1(string roomName, int baseAddress) { - string sourceOutput = StringHelper::Sprintf("%s 0x00, (u32)&%sExitList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), zRoom->GetName().c_str(), segmentOffset); + string sourceOutput = + StringHelper::Sprintf("%s 0x00, (u32)&%sExitList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + zRoom->GetName().c_str(), segmentOffset); // Parse Entrances and Generate Declaration - zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined + zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; uint32_t currentPtr = segmentOffset; @@ -38,9 +42,12 @@ string SetExitList::GenerateSourceCodePass1(string roomName, int baseAddress) string declaration = ""; for (uint16_t exit : exits) - declaration += StringHelper::Sprintf("\t0x%04X,\n", exit);; + declaration += StringHelper::Sprintf("\t0x%04X,\n", exit); + ; - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, exits.size() * 2, "u16", StringHelper::Sprintf("%sExitList0x%06X", zRoom->GetName().c_str(), segmentOffset), + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, exits.size() * 2, "u16", + StringHelper::Sprintf("%sExitList0x%06X", zRoom->GetName().c_str(), segmentOffset), exits.size(), declaration); return sourceOutput; @@ -48,7 +55,9 @@ string SetExitList::GenerateSourceCodePass1(string roomName, int baseAddress) string SetExitList::GenerateExterns() { - return StringHelper::Sprintf("extern u16 %sExitList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);; + return StringHelper::Sprintf("extern u16 %sExitList0x%06X[];\n", zRoom->GetName().c_str(), + segmentOffset); + ; } string SetExitList::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.cpp index 57b5430664..2018c2e5a6 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.cpp @@ -4,13 +4,15 @@ using namespace std; -SetLightList::SetLightList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetLightList::SetLightList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { this->ptrRoom = nZRoom; this->numLights = rawData[rawDataIndex + 1]; this->segment = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; - //std::string declarations = StringHelper::Sprintf("LightInfo %sLightInfo0x%06X[] =\n{\n", this->ptrRoom->GetName().c_str(), this->segment); + // std::string declarations = StringHelper::Sprintf("LightInfo %sLightInfo0x%06X[] =\n{\n", + // this->ptrRoom->GetName().c_str(), this->segment); string declarations = ""; for (int i = 0; i < this->numLights; i++) @@ -20,21 +22,29 @@ SetLightList::SetLightList(ZRoom* nZRoom, std::vector rawData, int rawD for (int y = 0; y < 6; y++) { - params.push_back(BitConverter::ToInt16BE(rawData, this->segment + ((0xE * i) + 2 + (y * 2)))); + params.push_back( + BitConverter::ToInt16BE(rawData, this->segment + ((0xE * i) + 2 + (y * 2)))); } - declarations += StringHelper::Sprintf("\t{ 0x%02X, { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X } },\n", type, params[0], params[1], params[2], params[3], params[4], params[5]); + declarations += StringHelper::Sprintf( + "\t{ 0x%02X, { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X } },\n", type, params[0], + params[1], params[2], params[3], params[4], params[5]); } declarations += "};\n"; - this->ptrRoom->parent->AddDeclarationArray(this->segment, DeclarationAlignment::None, this->numLights * 0xE, "LightInfo", - StringHelper::Sprintf("%sLightInfo0x%06X", this->ptrRoom->GetName().c_str(), this->segment), this->numLights, declarations); + this->ptrRoom->parent->AddDeclarationArray( + this->segment, DeclarationAlignment::None, this->numLights * 0xE, "LightInfo", + StringHelper::Sprintf("%sLightInfo0x%06X", this->ptrRoom->GetName().c_str(), this->segment), + this->numLights, declarations); } string SetLightList::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s %i, &%sLightInfo0x%06X};", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), this->numLights, this->ptrRoom->GetName().c_str(), this->segment); + return StringHelper::Sprintf( + "%s %i, &%sLightInfo0x%06X};", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), this->numLights, + this->ptrRoom->GetName().c_str(), this->segment); } string SetLightList::GetCommandCName() @@ -44,7 +54,8 @@ string SetLightList::GetCommandCName() string SetLightList::GenerateExterns() { - return StringHelper::Sprintf("extern LightInfo %sLightInfo0x%06X[];\n", this->ptrRoom->GetName().c_str(), this->segment); + return StringHelper::Sprintf("extern LightInfo %sLightInfo0x%06X[];\n", + this->ptrRoom->GetName().c_str(), this->segment); } RoomCommand SetLightList::GetRoomCommand() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.h index 625d3b8e9d..b3383aa5ce 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.h @@ -2,9 +2,9 @@ #include -#include "ZFile.h" #include "../ZRoom.h" #include "../ZRoomCommand.h" +#include "ZFile.h" class SetLightList : public ZRoomCommand { diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp index 5f8d4d4145..8436feeb53 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp @@ -1,12 +1,14 @@ #include "SetLightingSettings.h" -#include "../ZRoom.h" -#include "../../ZFile.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" using namespace std; -SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector rawData, + int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { uint8_t numLights = rawData[rawDataIndex + 1]; segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); @@ -20,18 +22,24 @@ SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector raw for (int i = 0; i < numLights; i++) { - declaration += StringHelper::Sprintf("\t{ 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%04X, 0x%04X }, // 0x%06X \n", + declaration += StringHelper::Sprintf( + "\t{ 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, " + "0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%04X, " + "0x%04X }, // 0x%06X \n", settings[i]->ambientClrR, settings[i]->ambientClrG, settings[i]->ambientClrB, settings[i]->diffuseClrA_R, settings[i]->diffuseClrA_G, settings[i]->diffuseClrA_B, settings[i]->diffuseDirA_X, settings[i]->diffuseDirA_Y, settings[i]->diffuseDirA_Z, settings[i]->diffuseClrB_R, settings[i]->diffuseClrB_G, settings[i]->diffuseClrB_B, settings[i]->diffuseDirB_X, settings[i]->diffuseDirB_Y, settings[i]->diffuseDirB_Z, - settings[i]->fogClrR, settings[i]->fogClrG, settings[i]->fogClrB, - settings[i]->unk, settings[i]->drawDistance, segmentOffset + (i * 22)); + settings[i]->fogClrR, settings[i]->fogClrG, settings[i]->fogClrB, settings[i]->unk, + settings[i]->drawDistance, segmentOffset + (i * 22)); } - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, numLights * 22, "LightSettings", - StringHelper::Sprintf("%sLightSettings0x%06X", zRoom->GetName().c_str(), segmentOffset), numLights, declaration); + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, numLights * 22, + "LightSettings", + StringHelper::Sprintf("%sLightSettings0x%06X", zRoom->GetName().c_str(), segmentOffset), + numLights, declaration); } } @@ -43,7 +51,10 @@ SetLightingSettings::~SetLightingSettings() string SetLightingSettings::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s %i, (u32)&%sLightSettings0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), settings.size(), zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf( + "%s %i, (u32)&%sLightSettings0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), settings.size(), + zRoom->GetName().c_str(), segmentOffset); } string SetLightingSettings::GenerateSourceCodePass2(string roomName, int baseAddress) @@ -58,7 +69,8 @@ string SetLightingSettings::GetCommandCName() string SetLightingSettings::GenerateExterns() { - return StringHelper::Sprintf("extern LightSettings %sLightSettings0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf("extern LightSettings %sLightSettings0x%06X[];\n", + zRoom->GetName().c_str(), segmentOffset); } RoomCommand SetLightingSettings::GetRoomCommand() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp index 50baed3d72..4884e3e50c 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp @@ -1,14 +1,16 @@ #include "SetMesh.h" -#include "../../ZFile.h" -#include "../ZRoom.h" +#include +#include #include "../../BitConverter.h" #include "../../StringHelper.h" -#include -#include +#include "../../ZFile.h" +#include "../ZRoom.h" using namespace std; -SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, int segAddressOffset) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, + int segAddressOffset) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { data = rawData[rawDataIndex + 1]; segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); @@ -39,11 +41,17 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, { MeshEntry0* entry = new MeshEntry0(); entry->opaqueDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 0)); - entry->translucentDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 4)); + entry->translucentDListAddr = + GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 4)); if (entry->opaqueDListAddr != 0) { - entry->opaqueDList = new ZDisplayList(rawData, entry->opaqueDListAddr, ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX)); + entry->opaqueDList = new ZDisplayList( + rawData, entry->opaqueDListAddr, + ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr, + Globals::Instance->game == ZGame::OOT_SW97 ? + DListType::F3DEX : + DListType::F3DZEX)); entry->opaqueDList->scene = zRoom->scene; entry->opaqueDList->parent = zRoom->parent; GenDListDeclarations(rawData, entry->opaqueDList); @@ -51,7 +59,12 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, if (entry->translucentDListAddr != 0) { - entry->translucentDList = new ZDisplayList(rawData, entry->translucentDListAddr, ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX)); + entry->translucentDList = new ZDisplayList( + rawData, entry->translucentDListAddr, + ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr, + Globals::Instance->game == ZGame::OOT_SW97 ? + DListType::F3DEX : + DListType::F3DZEX)); entry->translucentDList->scene = zRoom->scene; entry->translucentDList->parent = zRoom->parent; GenDListDeclarations(rawData, entry->translucentDList); @@ -65,56 +78,74 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, declaration += StringHelper::Sprintf("{ 0 }, 0x%02X, ", meshHeader0->entries.size()); if (meshHeader0->dListStart != 0) - declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ", zRoom->GetName().c_str(), meshHeader0->dListStart); + declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ", + zRoom->GetName().c_str(), meshHeader0->dListStart); else declaration += "0, "; if (meshHeader0->dListEnd != 0) - declaration += StringHelper::Sprintf("(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)", zRoom->GetName().c_str(), meshHeader0->dListStart, zRoom->GetName().c_str(), meshHeader0->dListStart); + declaration += StringHelper::Sprintf( + "(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)", + zRoom->GetName().c_str(), meshHeader0->dListStart, zRoom->GetName().c_str(), + meshHeader0->dListStart); else declaration += "0"; - zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::Align16, 12, "MeshHeader0", StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), + zRoom->parent->AddDeclaration( + segmentOffset, DeclarationAlignment::Align16, 12, "MeshHeader0", + StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), declaration); declaration = ""; - for (int i = 0; i < meshHeader0->entries.size(); i++) + for (size_t i = 0; i < meshHeader0->entries.size(); i++) { if (meshHeader0->entries[i]->opaqueDListAddr != 0) - declaration += StringHelper::Sprintf("\t{ (u32)%sDL_%06X, ", zRoom->GetName().c_str(), meshHeader0->entries[i]->opaqueDListAddr); + declaration += + StringHelper::Sprintf("\t{ (u32)%sDL_%06X, ", zRoom->GetName().c_str(), + meshHeader0->entries[i]->opaqueDListAddr); else declaration += "\t{ 0, "; if (meshHeader0->entries[i]->translucentDListAddr != 0) - declaration += StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(), meshHeader0->entries[i]->translucentDListAddr); + declaration += + StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(), + meshHeader0->entries[i]->translucentDListAddr); else declaration += "0 },\n"; } - zRoom->parent->AddDeclarationArray(meshHeader0->dListStart, DeclarationAlignment::None, DeclarationPadding::None, (meshHeader0->entries.size() * 8) + 0, "MeshEntry0", - StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(), meshHeader0->dListStart), meshHeader0->entries.size(), declaration); + zRoom->parent->AddDeclarationArray( + meshHeader0->dListStart, DeclarationAlignment::None, DeclarationPadding::None, + (meshHeader0->entries.size() * 8) + 0, "MeshEntry0", + StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(), + meshHeader0->dListStart), + meshHeader0->entries.size(), declaration); - zRoom->parent->AddDeclaration(meshHeader0->dListStart + (meshHeader0->entries.size() * 8) + 0, DeclarationAlignment::None, DeclarationPadding::Pad16, 4, "static s32", - "terminatorMaybe", " 0x01000000 "); + zRoom->parent->AddDeclaration(meshHeader0->dListStart + (meshHeader0->entries.size() * 8) + + 0, + DeclarationAlignment::None, DeclarationPadding::Pad16, 4, + "static s32", "terminatorMaybe", " 0x01000000 "); meshHeader = meshHeader0; } else if (meshHeaderType == 1) { MeshHeader1Base* meshHeader1 = nullptr; - + uint8_t fmt = rawData[segmentOffset + 1]; - if (fmt == 1) // Single Format + if (fmt == 1) // Single Format { MeshHeader1Single* headerSingle = new MeshHeader1Single(); headerSingle->headerType = 1; headerSingle->format = fmt; - headerSingle->entryRecord = BitConverter::ToInt32BE(rawData, segmentOffset + 4);// &0x00FFFFFF; + headerSingle->entryRecord = + BitConverter::ToInt32BE(rawData, segmentOffset + 4); // &0x00FFFFFF; - headerSingle->imagePtr = BitConverter::ToInt32BE(rawData, segmentOffset + 8);// &0x00FFFFFF; + headerSingle->imagePtr = + BitConverter::ToInt32BE(rawData, segmentOffset + 8); // &0x00FFFFFF; headerSingle->unknown = BitConverter::ToInt32BE(rawData, segmentOffset + 12); headerSingle->unknown2 = BitConverter::ToInt32BE(rawData, segmentOffset + 16); headerSingle->bgWidth = BitConverter::ToInt16BE(rawData, segmentOffset + 20); @@ -124,37 +155,50 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, headerSingle->imagePal = BitConverter::ToInt16BE(rawData, segmentOffset + 26); headerSingle->imageFlip = BitConverter::ToInt16BE(rawData, segmentOffset + 28); - declaration += StringHelper::Sprintf("{ { 1 }, 1, 0x%06X }, 0x%06X, ", - headerSingle->entryRecord, headerSingle->imagePtr); + declaration += StringHelper::Sprintf("{ { 1 }, 1, 0x%06X }, 0x%06X, ", + headerSingle->entryRecord, headerSingle->imagePtr); declaration += StringHelper::Sprintf("0x%06X, 0x%06X, %i, %i, %i, %i, %i, %i\n", - headerSingle->unknown, headerSingle->unknown2, headerSingle->bgWidth, headerSingle->bgHeight, headerSingle->imageFormat, headerSingle->imageSize, headerSingle->imagePal, headerSingle->imageFlip); + headerSingle->unknown, headerSingle->unknown2, + headerSingle->bgWidth, headerSingle->bgHeight, + headerSingle->imageFormat, headerSingle->imageSize, + headerSingle->imagePal, headerSingle->imageFlip); - zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, 0x1E, "MeshHeader1Single", - StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), declaration); + zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, + DeclarationPadding::Pad16, 0x1E, "MeshHeader1Single", + StringHelper::Sprintf("%sMeshHeader0x%06X", + zRoom->GetName().c_str(), + segmentOffset), + declaration); meshHeader1 = headerSingle; } - else if (fmt == 2) // Multi-Format + else if (fmt == 2) // Multi-Format { MeshHeader1Multi* headerMulti = new MeshHeader1Multi(); headerMulti->headerType = 1; headerMulti->format = fmt; - headerMulti->entryRecord = BitConverter::ToInt32BE(rawData, segmentOffset + 4);// &0x00FFFFFF; + headerMulti->entryRecord = + BitConverter::ToInt32BE(rawData, segmentOffset + 4); // &0x00FFFFFF; headerMulti->bgCnt = rawData[segmentOffset + 8]; headerMulti->bgRecordPtr = BitConverter::ToInt32BE(rawData, segmentOffset + 12); declaration += StringHelper::Sprintf("{ { 1 }, 2, 0x%06X }, 0x%06X, 0x%06X", - headerMulti->entryRecord, headerMulti->bgCnt, headerMulti->bgRecordPtr); + headerMulti->entryRecord, headerMulti->bgCnt, + headerMulti->bgRecordPtr); - zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, 16, "MeshHeader1Multi", - StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), declaration); + zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, + DeclarationPadding::Pad16, 16, "MeshHeader1Multi", + StringHelper::Sprintf("%sMeshHeader0x%06X", + zRoom->GetName().c_str(), + segmentOffset), + declaration); meshHeader1 = headerMulti; } - else // UH OH + else // UH OH { if (Globals::Instance->verbosity >= VERBOSITY_INFO) printf("WARNING: MeshHeader FMT %i not implemented!\n", fmt); @@ -164,14 +208,13 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, meshHeader1->format = fmt; meshHeader1->entryRecord = BitConverter::ToInt32BE(rawData, segmentOffset + 4) & 0x00FFFFFF; - meshHeader = meshHeader1; } else if (meshHeaderType == 2) { MeshHeader2* meshHeader2 = new MeshHeader2(); meshHeader2->headerType = 2; - + meshHeader2->entries = vector(); meshHeader2->dListStart = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 4)); meshHeader2->dListEnd = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 8)); @@ -189,22 +232,33 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, entry->playerZMin = BitConverter::ToInt16BE(rawData, currentPtr + 6); entry->opaqueDListAddr = BitConverter::ToInt32BE(rawData, currentPtr + 8) & 0x00FFFFFF; - entry->translucentDListAddr = BitConverter::ToInt32BE(rawData, currentPtr + 12) & 0x00FFFFFF; + entry->translucentDListAddr = + BitConverter::ToInt32BE(rawData, currentPtr + 12) & 0x00FFFFFF; if (entry->opaqueDListAddr != 0) { - entry->opaqueDList = new ZDisplayList(rawData, entry->opaqueDListAddr, ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX)); + entry->opaqueDList = new ZDisplayList( + rawData, entry->opaqueDListAddr, + ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr, + Globals::Instance->game == ZGame::OOT_SW97 ? + DListType::F3DEX : + DListType::F3DZEX)); entry->opaqueDList->scene = zRoom->scene; entry->opaqueDList->parent = zRoom->parent; - GenDListDeclarations(rawData, entry->opaqueDList); // HOTSPOT + GenDListDeclarations(rawData, entry->opaqueDList); // HOTSPOT } if (entry->translucentDListAddr != 0) { - entry->translucentDList = new ZDisplayList(rawData, entry->translucentDListAddr, ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX)); + entry->translucentDList = new ZDisplayList( + rawData, entry->translucentDListAddr, + ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr, + Globals::Instance->game == ZGame::OOT_SW97 ? + DListType::F3DEX : + DListType::F3DZEX)); entry->translucentDList->scene = zRoom->scene; entry->translucentDList->parent = zRoom->parent; - GenDListDeclarations(rawData, entry->translucentDList); // HOTSPOT + GenDListDeclarations(rawData, entry->translucentDList); // HOTSPOT } meshHeader2->entries.push_back(entry); @@ -215,40 +269,57 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, declaration += StringHelper::Sprintf("{ 2 }, 0x%02lX, ", meshHeader2->entries.size()); if (meshHeader2->dListStart != 0) - declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ", zRoom->GetName().c_str(), meshHeader2->dListStart); + declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ", + zRoom->GetName().c_str(), meshHeader2->dListStart); else declaration += "0, "; if (meshHeader2->dListEnd != 0) - declaration += StringHelper::Sprintf("(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)", zRoom->GetName().c_str(), meshHeader2->dListStart, zRoom->GetName().c_str(), meshHeader2->dListStart); + declaration += StringHelper::Sprintf( + "(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)", + zRoom->GetName().c_str(), meshHeader2->dListStart, zRoom->GetName().c_str(), + meshHeader2->dListStart); else declaration += "0"; - zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, 12, "MeshHeader2", - StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), declaration); + zRoom->parent->AddDeclaration( + segmentOffset, DeclarationAlignment::None, 12, "MeshHeader2", + StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), + declaration); declaration = ""; - for (int i = 0; i < meshHeader2->entries.size(); i++) + for (size_t i = 0; i < meshHeader2->entries.size(); i++) { - declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, ", meshHeader2->entries[i]->playerXMax, meshHeader2->entries[i]->playerZMax, meshHeader2->entries[i]->playerXMin, meshHeader2->entries[i]->playerZMin); + declaration += StringHelper::Sprintf( + "\t{ %i, %i, %i, %i, ", meshHeader2->entries[i]->playerXMax, + meshHeader2->entries[i]->playerZMax, meshHeader2->entries[i]->playerXMin, + meshHeader2->entries[i]->playerZMin); if (meshHeader2->entries[i]->opaqueDListAddr != 0) - declaration += StringHelper::Sprintf("(u32)%sDL_%06X, ", zRoom->GetName().c_str(), meshHeader2->entries[i]->opaqueDListAddr); + declaration += StringHelper::Sprintf("(u32)%sDL_%06X, ", zRoom->GetName().c_str(), + meshHeader2->entries[i]->opaqueDListAddr); else declaration += "0, "; if (meshHeader2->entries[i]->translucentDListAddr != 0) - declaration += StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(), meshHeader2->entries[i]->translucentDListAddr); + declaration += + StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(), + meshHeader2->entries[i]->translucentDListAddr); else declaration += "0 },\n"; } - zRoom->parent->AddDeclarationArray(meshHeader2->dListStart, DeclarationAlignment::None, DeclarationPadding::None, (meshHeader2->entries.size() * 16) + 0, - "MeshEntry2", StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(), meshHeader2->dListStart, meshHeader2->entries.size()), meshHeader2->entries.size(), declaration); + zRoom->parent->AddDeclarationArray( + meshHeader2->dListStart, DeclarationAlignment::None, DeclarationPadding::None, + (meshHeader2->entries.size() * 16) + 0, "MeshEntry2", + StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(), + meshHeader2->dListStart, meshHeader2->entries.size()), + meshHeader2->entries.size(), declaration); - zRoom->parent->AddDeclaration(meshHeader2->dListStart + (meshHeader2->entries.size() * 16), DeclarationAlignment::None, DeclarationPadding::Pad16, 4, "static s32", - "terminatorMaybe", "0x01000000"); + zRoom->parent->AddDeclaration(meshHeader2->dListStart + (meshHeader2->entries.size() * 16), + DeclarationAlignment::None, DeclarationPadding::Pad16, 4, + "static s32", "terminatorMaybe", "0x01000000"); meshHeader = meshHeader2; } @@ -267,23 +338,27 @@ void SetMesh::GenDListDeclarations(std::vector rawData, ZDisplayList* d { string srcVarName = ""; - //if (Globals::Instance->includeFilePrefix) - srcVarName = StringHelper::Sprintf("%s%s", zRoom->GetName().c_str(), dList->GetName().c_str()); - //else - //srcVarName = StringHelper::Sprintf("%s", dList->GetName().c_str()); + // if (Globals::Instance->includeFilePrefix) + srcVarName = StringHelper::Sprintf("%s%s", zRoom->GetName().c_str(), dList->GetName().c_str()); + // else + // srcVarName = StringHelper::Sprintf("%s", dList->GetName().c_str()); dList->SetName(srcVarName); - string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName()); // HOTSPOT + string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName()); // HOTSPOT - //zRoom->parent->AddDeclarationArray(dList->GetRawDataIndex(), DeclarationAlignment::None, dList->GetRawDataSize(), "static Gfx", srcVarName, dList->GetRawDataSize() / 8, sourceOutput); + // zRoom->parent->AddDeclarationArray(dList->GetRawDataIndex(), DeclarationAlignment::None, + // dList->GetRawDataSize(), "static Gfx", srcVarName, dList->GetRawDataSize() / 8, sourceOutput); for (ZDisplayList* otherDList : dList->otherDLists) GenDListDeclarations(rawData, otherDList); for (pair vtxEntry : dList->vtxDeclarations) { - zRoom->parent->AddDeclarationArray(vtxEntry.first, DeclarationAlignment::Align8, dList->vertices[vtxEntry.first].size() * 16, "static Vtx", - StringHelper::Sprintf("%sVtx_%06X", zRoom->GetName().c_str(), vtxEntry.first), dList->vertices[vtxEntry.first].size(), vtxEntry.second); + zRoom->parent->AddDeclarationArray( + vtxEntry.first, DeclarationAlignment::Align8, + dList->vertices[vtxEntry.first].size() * 16, "static Vtx", + StringHelper::Sprintf("%sVtx_%06X", zRoom->GetName().c_str(), vtxEntry.first), + dList->vertices[vtxEntry.first].size(), vtxEntry.second); } for (pair texEntry : dList->texDeclarations) @@ -292,21 +367,30 @@ void SetMesh::GenDListDeclarations(std::vector rawData, ZDisplayList* d if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) printf("SAVING IMAGE TO %s\n", Globals::Instance->outputPath.c_str()); - + zRoom->textures[texEntry.first]->Save(Globals::Instance->outputPath); - zRoom->parent->AddDeclarationIncludeArray(texEntry.first, StringHelper::Sprintf("%s/%s.%s.inc.c", - Globals::Instance->outputPath.c_str(), Path::GetFileNameWithoutExtension(zRoom->textures[texEntry.first]->GetName()).c_str(), zRoom->textures[texEntry.first]->GetExternalExtension().c_str()), - zRoom->textures[texEntry.first]->GetRawDataSize(), "u64", StringHelper::Sprintf("%s", zRoom->textures[texEntry.first]->GetName().c_str(), texEntry.first), 0); + zRoom->parent->AddDeclarationIncludeArray( + texEntry.first, + StringHelper::Sprintf( + "%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(), + Path::GetFileNameWithoutExtension(zRoom->textures[texEntry.first]->GetName()) + .c_str(), + zRoom->textures[texEntry.first]->GetExternalExtension().c_str()), + zRoom->textures[texEntry.first]->GetRawDataSize(), "u64", + StringHelper::Sprintf("%s", zRoom->textures[texEntry.first]->GetName().c_str(), + texEntry.first), + 0); } } std::string SetMesh::GenDListExterns(ZDisplayList* dList) { string sourceOutput = ""; - + if (Globals::Instance->includeFilePrefix) - sourceOutput += StringHelper::Sprintf("extern Gfx %sDL_%06X[];\n", zRoom->GetName().c_str(), dList->GetRawDataIndex()); + sourceOutput += StringHelper::Sprintf("extern Gfx %sDL_%06X[];\n", zRoom->GetName().c_str(), + dList->GetRawDataIndex()); else sourceOutput += StringHelper::Sprintf("extern Gfx DL_%06X[];\n", dList->GetRawDataIndex()); @@ -314,7 +398,8 @@ std::string SetMesh::GenDListExterns(ZDisplayList* dList) sourceOutput += GenDListExterns(otherDList); for (pair texEntry : dList->texDeclarations) - sourceOutput += StringHelper::Sprintf("extern u64 %sTex_%06X[];\n", zRoom->GetName().c_str(), texEntry.first); + sourceOutput += StringHelper::Sprintf("extern u64 %sTex_%06X[];\n", + zRoom->GetName().c_str(), texEntry.first); sourceOutput += dList->defines; @@ -324,17 +409,20 @@ std::string SetMesh::GenDListExterns(ZDisplayList* dList) string SetMesh::GenerateSourceCodePass1(string roomName, int baseAddress) { string sourceOutput = ""; - - sourceOutput += StringHelper::Sprintf("%s %i, (u32)&%sMeshHeader0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), data, zRoom->GetName().c_str(), segmentOffset); + + sourceOutput += + StringHelper::Sprintf("%s %i, (u32)&%sMeshHeader0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + data, zRoom->GetName().c_str(), segmentOffset); /*if (meshHeader->headerType == 0) { - MeshHeader0* meshHeader0 = (MeshHeader0*)meshHeader; + MeshHeader0* meshHeader0 = (MeshHeader0*)meshHeader; } else { - sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n"; + sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n"; } */ return sourceOutput; @@ -348,9 +436,12 @@ string SetMesh::GenerateExterns() { MeshHeader0* meshHeader0 = (MeshHeader0*)meshHeader; - sourceOutput += StringHelper::Sprintf("extern MeshHeader0 %sMeshHeader0x%06X;\n", zRoom->GetName().c_str(), segmentOffset); - sourceOutput += StringHelper::Sprintf("extern MeshEntry0 %sMeshDListEntry0x%06X[%i];\n", zRoom->GetName().c_str(), meshHeader0->dListStart, meshHeader0->entries.size()); - + sourceOutput += StringHelper::Sprintf("extern MeshHeader0 %sMeshHeader0x%06X;\n", + zRoom->GetName().c_str(), segmentOffset); + sourceOutput += StringHelper::Sprintf("extern MeshEntry0 %sMeshDListEntry0x%06X[%i];\n", + zRoom->GetName().c_str(), meshHeader0->dListStart, + meshHeader0->entries.size()); + for (MeshEntry0* entry : meshHeader0->entries) { if (entry->opaqueDList != nullptr) @@ -365,16 +456,21 @@ string SetMesh::GenerateExterns() MeshHeader1Base* meshHeader1 = (MeshHeader1Base*)meshHeader; if (meshHeader1->format == 1) - sourceOutput += StringHelper::Sprintf("extern MeshHeader1Single %sMeshHeader0x%06X;\n", zRoom->GetName().c_str(), segmentOffset); + sourceOutput += StringHelper::Sprintf("extern MeshHeader1Single %sMeshHeader0x%06X;\n", + zRoom->GetName().c_str(), segmentOffset); else if (meshHeader1->format == 2) - sourceOutput += StringHelper::Sprintf("extern MeshHeader1Multi %sMeshHeader0x%06X;\n", zRoom->GetName().c_str(), segmentOffset); + sourceOutput += StringHelper::Sprintf("extern MeshHeader1Multi %sMeshHeader0x%06X;\n", + zRoom->GetName().c_str(), segmentOffset); } else if (meshHeader->headerType == 2) { MeshHeader2* meshHeader2 = (MeshHeader2*)meshHeader; - sourceOutput += StringHelper::Sprintf("extern MeshHeader2 %sMeshHeader0x%06X;\n", zRoom->GetName().c_str(), segmentOffset); - sourceOutput += StringHelper::Sprintf("extern MeshEntry2 %sMeshDListEntry0x%06X[%i];\n", zRoom->GetName().c_str(), meshHeader2->dListStart, meshHeader2->entries.size()); + sourceOutput += StringHelper::Sprintf("extern MeshHeader2 %sMeshHeader0x%06X;\n", + zRoom->GetName().c_str(), segmentOffset); + sourceOutput += StringHelper::Sprintf("extern MeshEntry2 %sMeshDListEntry0x%06X[%i];\n", + zRoom->GetName().c_str(), meshHeader2->dListStart, + meshHeader2->entries.size()); for (MeshEntry2* entry : meshHeader2->entries) { @@ -387,7 +483,7 @@ string SetMesh::GenerateExterns() } else { - //sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n"; + // sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n"; } return sourceOutput; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h index cf102885c3..1105e0b59e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h @@ -1,12 +1,12 @@ #pragma once -#include "../ZRoomCommand.h" #include "../../ZDisplayList.h" +#include "../ZRoomCommand.h" class MeshHeaderBase { public: - int8_t headerType; // 0x00 + int8_t headerType; // 0x00 }; class MeshEntry0 @@ -30,51 +30,51 @@ public: class MeshHeader1Base : public MeshHeaderBase { public: - int8_t format; // 0x01 - uint32_t entryRecord; // 0x04 + int8_t format; // 0x01 + uint32_t entryRecord; // 0x04 }; class MeshHeader1Single : public MeshHeader1Base { public: - uint32_t imagePtr; // 0x08 + uint32_t imagePtr; // 0x08 - uint32_t unknown; // 0x0C - uint32_t unknown2; // 0x10 + uint32_t unknown; // 0x0C + uint32_t unknown2; // 0x10 - uint16_t bgWidth; // 0x14 - uint16_t bgHeight; // 0x16 - - uint8_t imageFormat; // 0x18 - uint8_t imageSize; // 0x19 - uint16_t imagePal; // 0x1A - uint16_t imageFlip; // 0x1C + uint16_t bgWidth; // 0x14 + uint16_t bgHeight; // 0x16 + + uint8_t imageFormat; // 0x18 + uint8_t imageSize; // 0x19 + uint16_t imagePal; // 0x1A + uint16_t imageFlip; // 0x1C }; class MeshHeader1Multi : public MeshHeader1Base { public: - uint8_t bgCnt; // 0x08 - uint32_t bgRecordPtr; // 0x0C + uint8_t bgCnt; // 0x08 + uint32_t bgRecordPtr; // 0x0C }; class BackgroundRecord { public: - uint16_t unknown; // 0x00 - int8_t bgID; // 0x02 + uint16_t unknown; // 0x00 + int8_t bgID; // 0x02 - uint32_t imagePtr; // 0x04 - uint32_t unknown2; // 0x08 - uint32_t unknown3; // 0x0C + uint32_t imagePtr; // 0x04 + uint32_t unknown2; // 0x08 + uint32_t unknown3; // 0x0C - uint16_t bgWidth; // 0x10 - uint16_t bgHeight; // 0x12 + uint16_t bgWidth; // 0x10 + uint16_t bgHeight; // 0x12 - uint8_t imageFmt; // 0x14 - uint8_t imageSize; // 0x15 - uint16_t imagePal; // 0x16 - uint16_t imageFlip; // 0x18 + uint8_t imageFmt; // 0x14 + uint8_t imageSize; // 0x15 + uint16_t imagePal; // 0x16 + uint16_t imageFlip; // 0x18 }; class MeshEntry2 @@ -105,8 +105,8 @@ public: ~SetMesh(); virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - //virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - //virtual std::string GenerateSourceCodePass3(std::string roomName); + // virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); + // virtual std::string GenerateSourceCodePass3(std::string roomName); virtual std::string GenerateExterns(); virtual std::string GetCommandCName(); virtual RoomCommand GetRoomCommand(); diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.cpp index e91b0e98e1..f8d00a101e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.cpp @@ -1,20 +1,21 @@ #include "SetObjectList.h" -#include "../ZRoom.h" -#include "../ObjectList.h" -#include "../../ZFile.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ObjectList.h" +#include "../ZRoom.h" using namespace std; -SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { objects = vector(); uint8_t objectCnt = rawData[rawDataIndex + 1]; segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); uint32_t currentPtr = segmentOffset; - for (int i = 0; i < objectCnt; i++) + for (uint8_t i = 0; i < objectCnt; i++) { uint16_t objectIndex = BitConverter::ToInt16BE(rawData, currentPtr); objects.push_back(objectIndex); @@ -27,18 +28,22 @@ SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector rawData, int ra string SetObjectList::GenerateExterns() { - return StringHelper::Sprintf("s16 %sObjectList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf("s16 %sObjectList0x%06X[];\n", zRoom->GetName().c_str(), + segmentOffset); } string SetObjectList::GenerateSourceCodePass1(string roomName, int baseAddress) { string sourceOutput = ""; - sourceOutput += StringHelper::Sprintf("%s 0x%02X, (u32)%sObjectList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), objects.size(), zRoom->GetName().c_str(), segmentOffset); + sourceOutput += + StringHelper::Sprintf("%s 0x%02X, (u32)%sObjectList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + objects.size(), zRoom->GetName().c_str(), segmentOffset); string declaration = ""; - for (int i = 0; i < objects.size(); i++) + for (size_t i = 0; i < objects.size(); i++) { uint16_t objectIndex = objects[i]; declaration += StringHelper::Sprintf("\t%s,", ObjectList[objectIndex].c_str()); @@ -47,8 +52,10 @@ string SetObjectList::GenerateSourceCodePass1(string roomName, int baseAddress) declaration += "\n"; } - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, objects.size() * 2, "s16", - StringHelper::Sprintf("%sObjectList0x%06X", zRoom->GetName().c_str(), segmentOffset), objects.size(), declaration); + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, objects.size() * 2, "s16", + StringHelper::Sprintf("%sObjectList0x%06X", zRoom->GetName().c_str(), segmentOffset), + objects.size(), declaration); return sourceOutput; } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp index 6795d99e92..9d70e273cf 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp @@ -1,12 +1,13 @@ #include "SetPathways.h" -#include "../ZRoom.h" -#include "../../ZFile.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" using namespace std; -SetPathways::SetPathways(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetPathways::SetPathways(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { _rawData = rawData; _rawDataIndex = rawDataIndex; @@ -16,8 +17,6 @@ SetPathways::SetPathways(ZRoom* nZRoom, std::vector rawData, int rawDat InitList(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))); - uint32_t currentPtr = listSegmentOffset; - if (segmentOffset != 0) zRoom->parent->AddDeclarationPlaceholder(segmentOffset); } @@ -42,7 +41,7 @@ string SetPathways::GetSourceOutputCode(std::string prefix) string SetPathways::GenerateSourceCodePass1(string roomName, int baseAddress) { - //int numPathsReal = zRoom->GetDeclarationSizeFromNeighbor(listSegmentOffset) / 6; + // int numPathsReal = zRoom->GetDeclarationSizeFromNeighbor(listSegmentOffset) / 6; uint32_t currentPtr = listSegmentOffset; uint8_t* data = _rawData.data(); @@ -59,7 +58,7 @@ string SetPathways::GenerateSourceCodePass1(string roomName, int baseAddress) currentPtr += 6; } - if (numPoints == 0) // Hack for SharpOcarina + if (numPoints == 0) // Hack for SharpOcarina { for (int i = 0; i < 3; i++) { @@ -71,36 +70,44 @@ string SetPathways::GenerateSourceCodePass1(string roomName, int baseAddress) return ""; } - string SetPathways::GenerateSourceCodePass2(string roomName, int baseAddress) { string sourceOutput = ""; - sourceOutput += StringHelper::Sprintf("%s 0, (u32)&%sPathway0x%06X };", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), roomName.c_str(), segmentOffset); + sourceOutput += + StringHelper::Sprintf("%s 0, (u32)&%sPathway0x%06X };", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + roomName.c_str(), segmentOffset); { - string declaration = StringHelper::Sprintf("%i, (u32)%sPathwayList0x%06X", numPoints, roomName.c_str(), listSegmentOffset); - - zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, 8, "Path", + string declaration = StringHelper::Sprintf("%i, (u32)%sPathwayList0x%06X", numPoints, + roomName.c_str(), listSegmentOffset); + + zRoom->parent->AddDeclaration( + segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, 8, "Path", StringHelper::Sprintf("%sPathway0x%06X", roomName.c_str(), segmentOffset), declaration); } { string declaration = ""; - int index = 0; + size_t index = 0; for (PathwayEntry* entry : pathways) { - declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", entry->x, entry->y, entry->z, listSegmentOffset + (index * 6)); + declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", entry->x, entry->y, + entry->z, listSegmentOffset + (index * 6)); if (index < pathways.size() - 1) declaration += "\n"; - + index++; } - zRoom->parent->AddDeclarationArray(listSegmentOffset, DeclarationAlignment::None, DeclarationPadding::None, pathways.size() * 6, - "Vec3s", StringHelper::Sprintf("%sPathwayList0x%06X", roomName.c_str(), listSegmentOffset), pathways.size(), declaration); + zRoom->parent->AddDeclarationArray( + listSegmentOffset, DeclarationAlignment::None, DeclarationPadding::None, + pathways.size() * 6, "Vec3s", + StringHelper::Sprintf("%sPathwayList0x%06X", roomName.c_str(), listSegmentOffset), + pathways.size(), declaration); } return sourceOutput; @@ -113,7 +120,8 @@ int32_t SetPathways::GetRawDataSize() string SetPathways::GenerateExterns() { - return StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n", zRoom->GetName().c_str(), + segmentOffset); } string SetPathways::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.h index 67d0322d8e..7c085fbf2c 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.h @@ -1,7 +1,7 @@ #pragma once -#include "../ZRoomCommand.h" #include "../../Vec3s.h" +#include "../ZRoomCommand.h" class PathwayEntry { diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.cpp index b73335ca6c..1ae7ae5652 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.cpp @@ -4,7 +4,8 @@ using namespace std; -SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { gameplayFlags = rawData[rawDataIndex + 0x01]; gameplayFlags2 = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x04); @@ -12,7 +13,10 @@ SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector rawData, in string SetRoomBehavior::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), gameplayFlags, gameplayFlags2);; + return StringHelper::Sprintf( + "%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + gameplayFlags, gameplayFlags2); + ; } string SetRoomBehavior::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp index e6c1889a30..823ca9a408 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp @@ -1,13 +1,14 @@ #include "SetRoomList.h" -#include "../ZRoom.h" -#include "../../ZFile.h" -#include "../../Globals.h" #include "../../BitConverter.h" +#include "../../Globals.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" using namespace std; -SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { int numRooms = rawData[rawDataIndex + 1]; segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; @@ -33,7 +34,10 @@ SetRoomList::~SetRoomList() string SetRoomList::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x%02X, (u32)&%sRoomList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), rooms.size(), zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf( + "%s 0x%02X, (u32)&%sRoomList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), rooms.size(), + zRoom->GetName().c_str(), segmentOffset); } string SetRoomList::GenerateSourceCodePass2(string roomName, int baseAddress) @@ -43,7 +47,8 @@ string SetRoomList::GenerateSourceCodePass2(string roomName, int baseAddress) string SetRoomList::GenerateExterns() { - return StringHelper::Sprintf("extern RomFile %sRoomList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf("extern RomFile %sRoomList0x%06X[];\n", zRoom->GetName().c_str(), + segmentOffset); } string SetRoomList::GetCommandCName() @@ -67,13 +72,17 @@ std::string SetRoomList::PreGenSourceFiles() if (res->GetResourceType() == ZResourceType::Room && res != zRoom) { string roomName = res->GetName(); - declaration += StringHelper::Sprintf("\t{ (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n", roomName.c_str(), roomName.c_str()); + declaration += + StringHelper::Sprintf("\t{ (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n", + roomName.c_str(), roomName.c_str()); } } } - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, rooms.size() * 8, - "RomFile", StringHelper::Sprintf("%sRoomList0x%06X", zRoom->GetName().c_str(), segmentOffset), 0, declaration); + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, rooms.size() * 8, "RomFile", + StringHelper::Sprintf("%sRoomList0x%06X", zRoom->GetName().c_str(), segmentOffset), 0, + declaration); return std::string(); } @@ -89,6 +98,8 @@ RoomEntry::RoomEntry(int32_t nVAS, int32_t nVAE) virtualAddressEnd = nVAE; } -RoomEntry::RoomEntry(std::vector rawData, int rawDataIndex) : RoomEntry(BitConverter::ToInt32BE(rawData, rawDataIndex + 0), BitConverter::ToInt32BE(rawData, rawDataIndex + 4)) +RoomEntry::RoomEntry(std::vector rawData, int rawDataIndex) + : RoomEntry(BitConverter::ToInt32BE(rawData, rawDataIndex + 0), + BitConverter::ToInt32BE(rawData, rawDataIndex + 4)) { } \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.cpp index 08f50c1844..a0d03c3155 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.cpp @@ -3,7 +3,8 @@ using namespace std; -SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { disableSky = rawData[rawDataIndex + 0x04]; disableSunMoon = rawData[rawDataIndex + 0x05]; @@ -11,7 +12,11 @@ SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector rawData string SetSkyboxModifier::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0, 0, 0, 0x%02X, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), disableSky, disableSunMoon);; + return StringHelper::Sprintf( + "%s 0, 0, 0, 0x%02X, 0x%02X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), disableSky, + disableSunMoon); + ; } string SetSkyboxModifier::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp index 18c16365b0..f5c05e682d 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp @@ -3,7 +3,8 @@ using namespace std; -SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { skyboxNumber = rawData[rawDataIndex + 0x04]; cloudsType = rawData[rawDataIndex + 0x05]; @@ -12,8 +13,10 @@ SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector rawData string SetSkyboxSettings::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), skyboxNumber, cloudsType, lightingSettingsControl); + return StringHelper::Sprintf( + "%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), skyboxNumber, + cloudsType, lightingSettingsControl); } string SetSkyboxSettings::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.cpp index 3fc1985d95..4668060f90 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.cpp @@ -3,7 +3,8 @@ using namespace std; -SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { reverb = rawData[rawDataIndex + 0x01]; nightTimeSFX = rawData[rawDataIndex + 0x06]; @@ -12,7 +13,10 @@ SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector rawData, string SetSoundSettings::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x%02X, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), reverb, nightTimeSFX, musicSequence); + return StringHelper::Sprintf( + "%s 0x%02X, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), reverb, nightTimeSFX, + musicSequence); } string SetSoundSettings::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp index e22f6179e3..fccd1bacab 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp @@ -4,7 +4,8 @@ using namespace std; -SetSpecialObjects::SetSpecialObjects(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetSpecialObjects::SetSpecialObjects(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { elfMessage = rawData[rawDataIndex + 0x01]; globalObject = BitConverter::ToInt16BE(rawData, rawDataIndex + 6); @@ -12,7 +13,9 @@ SetSpecialObjects::SetSpecialObjects(ZRoom* nZRoom, std::vector rawData string SetSpecialObjects::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x%02X, 0x%04X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), elfMessage, globalObject); + return StringHelper::Sprintf( + "%s 0x%02X, 0x%04X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + elfMessage, globalObject); } string SetSpecialObjects::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.cpp index e16373f546..be9bb8219a 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.cpp @@ -1,17 +1,19 @@ #include "SetStartPositionList.h" -#include "../ZRoom.h" -#include "../ActorList.h" -#include "../../ZFile.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ActorList.h" +#include "../ZRoom.h" using namespace std; -SetStartPositionList::SetStartPositionList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetStartPositionList::SetStartPositionList(ZRoom* nZRoom, std::vector rawData, + int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { - int numActors = rawData[rawDataIndex + 1]; + uint8_t numActors = rawData[rawDataIndex + 1]; segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); - + if (segmentOffset != 0) zRoom->parent->AddDeclarationPlaceholder(segmentOffset); @@ -35,20 +37,26 @@ SetStartPositionList::~SetStartPositionList() string SetStartPositionList::GenerateSourceCodePass1(string roomName, int baseAddress) { string sourceOutput = ""; - char line[2048]; - sourceOutput += StringHelper::Sprintf("%s 0x%02X, (u32)&%sStartPositionList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), actors.size(), zRoom->GetName().c_str(), segmentOffset); + sourceOutput += + StringHelper::Sprintf("%s 0x%02X, (u32)&%sStartPositionList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + actors.size(), zRoom->GetName().c_str(), segmentOffset); string declaration = ""; for (ActorSpawnEntry* entry : actors) { - declaration += StringHelper::Sprintf("\t{ %s, %i, %i, %i, %i, %i, %i, 0x%04X },\n", ActorList[entry->actorNum].c_str(), entry->posX, entry->posY, entry->posZ, - entry->rotX, entry->rotY, entry->rotZ, entry->initVar); + declaration += StringHelper::Sprintf("\t{ %s, %i, %i, %i, %i, %i, %i, 0x%04X },\n", + ActorList[entry->actorNum].c_str(), entry->posX, + entry->posY, entry->posZ, entry->rotX, entry->rotY, + entry->rotZ, entry->initVar); } - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, actors.size() * 16, "ActorEntry", - StringHelper::Sprintf("%sStartPositionList0x%06X", zRoom->GetName().c_str(), segmentOffset), 0, declaration); + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, actors.size() * 16, "ActorEntry", + StringHelper::Sprintf("%sStartPositionList0x%06X", zRoom->GetName().c_str(), segmentOffset), + 0, declaration); return sourceOutput; } @@ -60,7 +68,8 @@ string SetStartPositionList::GenerateSourceCodePass2(string roomName, int baseAd string SetStartPositionList::GenerateExterns() { - return StringHelper::Sprintf("extern ActorEntry %sStartPositionList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf("extern ActorEntry %sStartPositionList0x%06X[];\n", + zRoom->GetName().c_str(), segmentOffset); } string SetStartPositionList::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.h index 90316d4e89..9452ca3db2 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.h @@ -3,7 +3,6 @@ #include "../ZRoomCommand.h" #include "SetActorList.h" - class SetStartPositionList : public ZRoomCommand { public: @@ -17,7 +16,7 @@ public: virtual std::string GetCommandCName(); virtual std::string GenerateExterns(); virtual RoomCommand GetRoomCommand(); + private: - uint32_t segmentOffset; }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.cpp index 97e752a973..6e3272d71d 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.cpp @@ -4,7 +4,8 @@ using namespace std; -SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { hour = rawData[rawDataIndex + 4]; min = rawData[rawDataIndex + 5]; @@ -13,7 +14,9 @@ SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector rawData, in string SetTimeSettings::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), hour, min, unk); + return StringHelper::Sprintf( + "%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), hour, min, unk); } string SetTimeSettings::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.h index fbdfc23335..de5c3bcee5 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.h @@ -12,8 +12,8 @@ public: virtual RoomCommand GetRoomCommand(); private: - //uint16_t time; - //int8_t speed; + // uint16_t time; + // int8_t speed; uint8_t hour; uint8_t min; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp index fb0c299165..f73664050b 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp @@ -1,13 +1,15 @@ #include "SetTransitionActorList.h" -#include "../ZRoom.h" -#include "../ActorList.h" -#include "../../ZFile.h" #include "../../BitConverter.h" #include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ActorList.h" +#include "../ZRoom.h" using namespace std; -SetTransitionActorList::SetTransitionActorList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetTransitionActorList::SetTransitionActorList(ZRoom* nZRoom, std::vector rawData, + int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { int numActors = rawData[rawDataIndex + 1]; segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; @@ -38,7 +40,10 @@ string SetTransitionActorList::GetSourceOutputCode(std::string prefix) string SetTransitionActorList::GenerateSourceCodePass1(string roomName, int baseAddress) { - string sourceOutput = StringHelper::Sprintf("%s 0x%02X, (u32)%sTransitionActorList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), transitionActors.size(), roomName.c_str(), segmentOffset); + string sourceOutput = + StringHelper::Sprintf("%s 0x%02X, (u32)%sTransitionActorList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + transitionActors.size(), roomName.c_str(), segmentOffset); string declaration = ""; for (TransitionActorEntry* entry : transitionActors) @@ -50,16 +55,22 @@ string SetTransitionActorList::GenerateSourceCodePass1(string roomName, int base else actorStr = StringHelper::Sprintf("0x%04X", entry->actorNum); - declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %s, %i, %i, %i, %i, 0x%04X }, \n", entry->frontObjectRoom, entry->frontTransitionReaction, entry->backObjectRoom, entry->backTransitionReaction, actorStr.c_str(), entry->posX, entry->posY, entry->posZ, entry->rotY, (uint16_t)entry->initVar); + declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %s, %i, %i, %i, %i, 0x%04X }, \n", + entry->frontObjectRoom, entry->frontTransitionReaction, + entry->backObjectRoom, entry->backTransitionReaction, + actorStr.c_str(), entry->posX, entry->posY, + entry->posZ, entry->rotY, (uint16_t)entry->initVar); } - zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, transitionActors.size() * 16, "TransitionActorEntry", - StringHelper::Sprintf("%sTransitionActorList0x%06X", roomName.c_str(), segmentOffset), 0, declaration); + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, transitionActors.size() * 16, + "TransitionActorEntry", + StringHelper::Sprintf("%sTransitionActorList0x%06X", roomName.c_str(), segmentOffset), 0, + declaration); return sourceOutput; } - string SetTransitionActorList::GenerateSourceCodePass2(string roomName, int baseAddress) { return ""; @@ -72,7 +83,8 @@ int32_t SetTransitionActorList::GetRawDataSize() string SetTransitionActorList::GenerateExterns() { - return StringHelper::Sprintf("extern TransitionActorEntry %sTransitionActorList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf("extern TransitionActorEntry %sTransitionActorList0x%06X[];\n", + zRoom->GetName().c_str(), segmentOffset); } string SetTransitionActorList::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.cpp index 88f12667da..8efbbbc83f 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.cpp @@ -3,7 +3,8 @@ using namespace std; -SetWind::SetWind(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +SetWind::SetWind(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { windWest = rawData[rawDataIndex + 0x04]; windVertical = rawData[rawDataIndex + 0x05]; @@ -13,7 +14,10 @@ SetWind::SetWind(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) string SetWind::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), windWest, windVertical, windSouth, clothFlappingStrength); + return StringHelper::Sprintf( + "%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X, 0x%02X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), windWest, + windVertical, windSouth, clothFlappingStrength); } string SetWind::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.cpp index d8b5a45fa9..9dc014d4cf 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.cpp @@ -3,13 +3,15 @@ using namespace std; -Unused09::Unused09(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +Unused09::Unused09(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { } string Unused09::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str()); + return StringHelper::Sprintf( + "%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str()); } string Unused09::GetCommandCName() diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.cpp index c536169654..c256b26ed6 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.cpp @@ -1,10 +1,11 @@ #include "ZRoomCommandUnk.h" -#include "BitConverter.h" #include "../../StringHelper.h" +#include "BitConverter.h" using namespace std; -ZRoomCommandUnk::ZRoomCommandUnk(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) +ZRoomCommandUnk::ZRoomCommandUnk(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) { cmdID = (RoomCommand)rawData[rawDataIndex]; cmdAddress = rawDataIndex; @@ -16,7 +17,10 @@ ZRoomCommandUnk::ZRoomCommandUnk(ZRoom* nZRoom, std::vector rawData, in string ZRoomCommandUnk::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s %sSet%04XCmd%02X = { 0x%02X, 0x%02X, 0x%06X }; /* WARNING: UNIMPLEMENTED ROOM COMMAND */", GetCommandCName().c_str(), roomName.c_str(), baseAddress, data2, cmdID, data1, data2); + return StringHelper::Sprintf("%s %sSet%04XCmd%02X = { 0x%02X, 0x%02X, 0x%06X }; /* WARNING: " + "UNIMPLEMENTED ROOM COMMAND */", + GetCommandCName().c_str(), roomName.c_str(), baseAddress, data2, + cmdID, data1, data2); } string ZRoomCommandUnk::GenerateSourceCodePass2(string roomName, int baseAddress) diff --git a/tools/ZAPD/ZAPD/ZRoom/ObjectList.h b/tools/ZAPD/ZAPD/ZRoom/ObjectList.h index 57d908de34..5b40cada52 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ObjectList.h +++ b/tools/ZAPD/ZAPD/ZRoom/ObjectList.h @@ -2,408 +2,407 @@ #include -static const std::string ObjectList[] = -{ - /* 0x0000 */ "OBJECT_UNSET_0", - /* 0x0001 */ "OBJECT_GAMEPLAY_KEEP", - /* 0x0002 */ "OBJECT_GAMEPLAY_FIELD_KEEP", - /* 0x0003 */ "OBJECT_GAMEPLAY_DANGEON_KEEP", - /* 0x0004 */ "OBJECT_UNSET_4", - /* 0x0005 */ "OBJECT_UNSET_5", - /* 0x0006 */ "OBJECT_HUMAN", - /* 0x0007 */ "OBJECT_OKUTA", - /* 0x0008 */ "OBJECT_CROW", - /* 0x0009 */ "OBJECT_POH", - /* 0x000A */ "OBJECT_DY_OBJ", - /* 0x000B */ "OBJECT_WALLMASTER", - /* 0x000C */ "OBJECT_DODONGO", - /* 0x000D */ "OBJECT_FIREFLY", - /* 0x000E */ "OBJECT_BOX", - /* 0x000F */ "OBJECT_FIRE", - /* 0x0010 */ "OBJECT_UNSET_10", - /* 0x0011 */ "OBJECT_UNSET_11", - /* 0x0012 */ "OBJECT_BUBBLE", - /* 0x0013 */ "OBJECT_NIW", - /* 0x0014 */ "OBJECT_LINK_BOY", - /* 0x0015 */ "OBJECT_LINK_CHILD", - /* 0x0016 */ "OBJECT_TITE", - /* 0x0017 */ "OBJECT_REEBA", - /* 0x0018 */ "OBJECT_PEEHAT", - /* 0x0019 */ "OBJECT_KINGDODONGO", - /* 0x001A */ "OBJECT_HORSE", - /* 0x001B */ "OBJECT_ZF", - /* 0x001C */ "OBJECT_GOMA", - /* 0x001D */ "OBJECT_ZL1", - /* 0x001E */ "OBJECT_GOL", - /* 0x001F */ "OBJECT_DODOJR", - /* 0x0020 */ "OBJECT_TORCH2", - /* 0x0021 */ "OBJECT_BL", - /* 0x0022 */ "OBJECT_TP", - /* 0x0023 */ "OBJECT_OA1", - /* 0x0024 */ "OBJECT_ST", - /* 0x0025 */ "OBJECT_BW", - /* 0x0026 */ "OBJECT_EI", - /* 0x0027 */ "OBJECT_HORSE_NORMAL", - /* 0x0028 */ "OBJECT_OB1", - /* 0x0029 */ "OBJECT_O_ANIME", - /* 0x002A */ "OBJECT_SPOT04_OBJECTS", - /* 0x002B */ "OBJECT_DDAN_OBJECTS", - /* 0x002C */ "OBJECT_HIDAN_OBJECTS", - /* 0x002D */ "OBJECT_HORSE_GANON", - /* 0x002E */ "OBJECT_OA2", - /* 0x002F */ "OBJECT_SPOT00_OBJECTS", - /* 0x0030 */ "OBJECT_MB", - /* 0x0031 */ "OBJECT_BOMBF", - /* 0x0032 */ "OBJECT_SK2", - /* 0x0033 */ "OBJECT_OE1", - /* 0x0034 */ "OBJECT_OE_ANIME", - /* 0x0035 */ "OBJECT_OE2", - /* 0x0036 */ "OBJECT_YDAN_OBJECTS", - /* 0x0037 */ "OBJECT_GND", - /* 0x0038 */ "OBJECT_AM", - /* 0x0039 */ "OBJECT_DEKUBABA", - /* 0x003A */ "OBJECT_UNSET_3A", - /* 0x003B */ "OBJECT_OA3", - /* 0x003C */ "OBJECT_OA4", - /* 0x003D */ "OBJECT_OA5", - /* 0x003E */ "OBJECT_OA6", - /* 0x003F */ "OBJECT_OA7", - /* 0x0040 */ "OBJECT_JJ", - /* 0x0041 */ "OBJECT_OA8", - /* 0x0042 */ "OBJECT_OA9", - /* 0x0043 */ "OBJECT_OB2", - /* 0x0044 */ "OBJECT_OB3", - /* 0x0045 */ "OBJECT_OB4", - /* 0x0046 */ "OBJECT_HORSE_ZELDA", - /* 0x0047 */ "OBJECT_OPENING_DEMO1", - /* 0x0048 */ "OBJECT_WARP1", - /* 0x0049 */ "OBJECT_B_HEART", - /* 0x004A */ "OBJECT_DEKUNUTS", - /* 0x004B */ "OBJECT_OE3", - /* 0x004C */ "OBJECT_OE4", - /* 0x004D */ "OBJECT_MENKURI_OBJECTS", - /* 0x004E */ "OBJECT_OE5", - /* 0x004F */ "OBJECT_OE6", - /* 0x0050 */ "OBJECT_OE7", - /* 0x0051 */ "OBJECT_OE8", - /* 0x0052 */ "OBJECT_OE9", - /* 0x0053 */ "OBJECT_OE10", - /* 0x0054 */ "OBJECT_OE11", - /* 0x0055 */ "OBJECT_OE12", - /* 0x0056 */ "OBJECT_VALI", - /* 0x0057 */ "OBJECT_OA10", - /* 0x0058 */ "OBJECT_OA11", - /* 0x0059 */ "OBJECT_MIZU_OBJECTS", - /* 0x005A */ "OBJECT_FHG", - /* 0x005B */ "OBJECT_OSSAN", - /* 0x005C */ "OBJECT_MORI_HINERI1", - /* 0x005D */ "OBJECT_BB", - /* 0x005E */ "OBJECT_TOKI_OBJECTS", - /* 0x005F */ "OBJECT_YUKABYUN", - /* 0x0060 */ "OBJECT_ZL2", - /* 0x0061 */ "OBJECT_MJIN", - /* 0x0062 */ "OBJECT_MJIN_FLASH", - /* 0x0063 */ "OBJECT_MJIN_DARK", - /* 0x0064 */ "OBJECT_MJIN_FLAME", - /* 0x0065 */ "OBJECT_MJIN_ICE", - /* 0x0066 */ "OBJECT_MJIN_SOUL", - /* 0x0067 */ "OBJECT_MJIN_WIND", - /* 0x0068 */ "OBJECT_MJIN_OKA", - /* 0x0069 */ "OBJECT_HAKA_OBJECTS", - /* 0x006A */ "OBJECT_SPOT06_OBJECTS", - /* 0x006B */ "OBJECT_ICE_OBJECTS", - /* 0x006C */ "OBJECT_RELAY_OBJECTS", - /* 0x006D */ "OBJECT_PO_FIELD", - /* 0x006E */ "OBJECT_PO_COMPOSER", - /* 0x006F */ "OBJECT_MORI_HINERI1A", - /* 0x0070 */ "OBJECT_MORI_HINERI2", - /* 0x0071 */ "OBJECT_MORI_HINERI2A", - /* 0x0072 */ "OBJECT_MORI_OBJECTS", - /* 0x0073 */ "OBJECT_MORI_TEX", - /* 0x0074 */ "OBJECT_SPOT08_OBJ", - /* 0x0075 */ "OBJECT_WARP2", - /* 0x0076 */ "OBJECT_HATA", - /* 0x0077 */ "OBJECT_BIRD", - /* 0x0078 */ "OBJECT_UNSET_78", - /* 0x0079 */ "OBJECT_UNSET_79", - /* 0x007A */ "OBJECT_UNSET_7A", - /* 0x007B */ "OBJECT_UNSET_7B", - /* 0x007C */ "OBJECT_WOOD02", - /* 0x007D */ "OBJECT_UNSET_7D", - /* 0x007E */ "OBJECT_UNSET_7E", - /* 0x007F */ "OBJECT_UNSET_7F", - /* 0x0080 */ "OBJECT_UNSET_80", - /* 0x0081 */ "OBJECT_LIGHTBOX", - /* 0x0082 */ "OBJECT_PU_BOX", - /* 0x0083 */ "OBJECT_UNSET_83", - /* 0x0084 */ "OBJECT_UNSET_84", - /* 0x0085 */ "OBJECT_TRAP", - /* 0x0086 */ "OBJECT_VASE", - /* 0x0087 */ "OBJECT_IM", - /* 0x0088 */ "OBJECT_TA", - /* 0x0089 */ "OBJECT_TK", - /* 0x008A */ "OBJECT_XC", - /* 0x008B */ "OBJECT_VM", - /* 0x008C */ "OBJECT_BV", - /* 0x008D */ "OBJECT_HAKACH_OBJECTS", - /* 0x008E */ "OBJECT_EFC_CRYSTAL_LIGHT", - /* 0x008F */ "OBJECT_EFC_FIRE_BALL", - /* 0x0090 */ "OBJECT_EFC_FLASH", - /* 0x0091 */ "OBJECT_EFC_LGT_SHOWER", - /* 0x0092 */ "OBJECT_EFC_STAR_FIELD", - /* 0x0093 */ "OBJECT_GOD_LGT", - /* 0x0094 */ "OBJECT_LIGHT_RING", - /* 0x0095 */ "OBJECT_TRIFORCE_SPOT", - /* 0x0096 */ "OBJECT_BDAN_OBJECTS", - /* 0x0097 */ "OBJECT_SD", - /* 0x0098 */ "OBJECT_RD", - /* 0x0099 */ "OBJECT_PO_SISTERS", - /* 0x009A */ "OBJECT_HEAVY_OBJECT", - /* 0x009B */ "OBJECT_GNDD", - /* 0x009C */ "OBJECT_FD", - /* 0x009D */ "OBJECT_DU", - /* 0x009E */ "OBJECT_FW", - /* 0x009F */ "OBJECT_MEDAL", - /* 0x00A0 */ "OBJECT_HORSE_LINK_CHILD", - /* 0x00A1 */ "OBJECT_SPOT02_OBJECTS", - /* 0x00A2 */ "OBJECT_HAKA", - /* 0x00A3 */ "OBJECT_RU1", - /* 0x00A4 */ "OBJECT_SYOKUDAI", - /* 0x00A5 */ "OBJECT_FD2", - /* 0x00A6 */ "OBJECT_DH", - /* 0x00A7 */ "OBJECT_RL", - /* 0x00A8 */ "OBJECT_EFC_TW", - /* 0x00A9 */ "OBJECT_DEMO_TRE_LGT", - /* 0x00AA */ "OBJECT_GI_KEY", - /* 0x00AB */ "OBJECT_MIR_RAY", - /* 0x00AC */ "OBJECT_BROB", - /* 0x00AD */ "OBJECT_GI_JEWEL", - /* 0x00AE */ "OBJECT_SPOT09_OBJ", - /* 0x00AF */ "OBJECT_SPOT18_OBJ", - /* 0x00B0 */ "OBJECT_BDOOR", - /* 0x00B1 */ "OBJECT_SPOT17_OBJ", - /* 0x00B2 */ "OBJECT_SHOP_DUNGEN", - /* 0x00B3 */ "OBJECT_NB", - /* 0x00B4 */ "OBJECT_MO", - /* 0x00B5 */ "OBJECT_SB", - /* 0x00B6 */ "OBJECT_GI_MELODY", - /* 0x00B7 */ "OBJECT_GI_HEART", - /* 0x00B8 */ "OBJECT_GI_COMPASS", - /* 0x00B9 */ "OBJECT_GI_BOSSKEY", - /* 0x00BA */ "OBJECT_GI_MEDAL", - /* 0x00BB */ "OBJECT_GI_NUTS", - /* 0x00BC */ "OBJECT_SA", - /* 0x00BD */ "OBJECT_GI_HEARTS", - /* 0x00BE */ "OBJECT_GI_ARROWCASE", - /* 0x00BF */ "OBJECT_GI_BOMBPOUCH", - /* 0x00C0 */ "OBJECT_IN", - /* 0x00C1 */ "OBJECT_TR", - /* 0x00C2 */ "OBJECT_SPOT16_OBJ", - /* 0x00C3 */ "OBJECT_OE1S", - /* 0x00C4 */ "OBJECT_OE4S", - /* 0x00C5 */ "OBJECT_OS_ANIME", - /* 0x00C6 */ "OBJECT_GI_BOTTLE", - /* 0x00C7 */ "OBJECT_GI_STICK", - /* 0x00C8 */ "OBJECT_GI_MAP", - /* 0x00C9 */ "OBJECT_OF1D_MAP", - /* 0x00CA */ "OBJECT_RU2", - /* 0x00CB */ "OBJECT_GI_SHIELD_1", - /* 0x00CC */ "OBJECT_DEKUJR", - /* 0x00CD */ "OBJECT_GI_MAGICPOT", - /* 0x00CE */ "OBJECT_GI_BOMB_1", - /* 0x00CF */ "OBJECT_OF1S", - /* 0x00D0 */ "OBJECT_MA2", - /* 0x00D1 */ "OBJECT_GI_PURSE", - /* 0x00D2 */ "OBJECT_HNI", - /* 0x00D3 */ "OBJECT_TW", - /* 0x00D4 */ "OBJECT_RR", - /* 0x00D5 */ "OBJECT_BXA", - /* 0x00D6 */ "OBJECT_ANUBICE", - /* 0x00D7 */ "OBJECT_GI_GERUDO", - /* 0x00D8 */ "OBJECT_GI_ARROW", - /* 0x00D9 */ "OBJECT_GI_BOMB_2", - /* 0x00DA */ "OBJECT_GI_EGG", - /* 0x00DB */ "OBJECT_GI_SCALE", - /* 0x00DC */ "OBJECT_GI_SHIELD_2", - /* 0x00DD */ "OBJECT_GI_HOOKSHOT", - /* 0x00DE */ "OBJECT_GI_OCARINA", - /* 0x00DF */ "OBJECT_GI_MILK", - /* 0x00E0 */ "OBJECT_MA1", - /* 0x00E1 */ "OBJECT_GANON", - /* 0x00E2 */ "OBJECT_SST", - /* 0x00E3 */ "OBJECT_NY_UNUSED", - /* 0x00E4 */ "OBJECT_UNSET_E4", - /* 0x00E5 */ "OBJECT_NY", - /* 0x00E6 */ "OBJECT_FR", - /* 0x00E7 */ "OBJECT_GI_PACHINKO", - /* 0x00E8 */ "OBJECT_GI_BOOMERANG", - /* 0x00E9 */ "OBJECT_GI_BOW", - /* 0x00EA */ "OBJECT_GI_GLASSES", - /* 0x00EB */ "OBJECT_GI_LIQUID", - /* 0x00EC */ "OBJECT_ANI", - /* 0x00ED */ "OBJECT_DEMO_6K", - /* 0x00EE */ "OBJECT_GI_SHIELD_3", - /* 0x00EF */ "OBJECT_GI_LETTER", - /* 0x00F0 */ "OBJECT_SPOT15_OBJ", - /* 0x00F1 */ "OBJECT_JYA_OBJ", - /* 0x00F2 */ "OBJECT_GI_CLOTHES", - /* 0x00F3 */ "OBJECT_GI_BEAN", - /* 0x00F4 */ "OBJECT_GI_FISH", - /* 0x00F5 */ "OBJECT_GI_SAW", - /* 0x00F6 */ "OBJECT_GI_HAMMER", - /* 0x00F7 */ "OBJECT_GI_GRASS", - /* 0x00F8 */ "OBJECT_GI_LONGSWORD", - /* 0x00F9 */ "OBJECT_SPOT01_OBJECTS", - /* 0x00FA */ "OBJECT_MD_UNUSED", - /* 0x00FB */ "OBJECT_MD", - /* 0x00FC */ "OBJECT_KM1", - /* 0x00FD */ "OBJECT_KW1", - /* 0x00FE */ "OBJECT_ZO", - /* 0x00FF */ "OBJECT_KZ", - /* 0x0100 */ "OBJECT_UMAJUMP", - /* 0x0101 */ "OBJECT_MASTERKOKIRI", - /* 0x0102 */ "OBJECT_MASTERKOKIRIHEAD", - /* 0x0103 */ "OBJECT_MASTERGOLON", - /* 0x0104 */ "OBJECT_MASTERZOORA", - /* 0x0105 */ "OBJECT_AOB", - /* 0x0106 */ "OBJECT_IK", - /* 0x0107 */ "OBJECT_AHG", - /* 0x0108 */ "OBJECT_CNE", - /* 0x0109 */ "OBJECT_GI_NIWATORI", - /* 0x010A */ "OBJECT_SKJ", - /* 0x010B */ "OBJECT_GI_BOTTLE_LETTER", - /* 0x010C */ "OBJECT_BJI", - /* 0x010D */ "OBJECT_BBA", - /* 0x010E */ "OBJECT_GI_OCARINA_0", - /* 0x010F */ "OBJECT_DS", - /* 0x0110 */ "OBJECT_ANE", - /* 0x0111 */ "OBJECT_BOJ", - /* 0x0112 */ "OBJECT_SPOT03_OBJECT", - /* 0x0113 */ "OBJECT_SPOT07_OBJECT", - /* 0x0114 */ "OBJECT_FZ", - /* 0x0115 */ "OBJECT_BOB", - /* 0x0116 */ "OBJECT_GE1", - /* 0x0117 */ "OBJECT_YABUSAME_POINT", - /* 0x0118 */ "OBJECT_GI_BOOTS_2", - /* 0x0119 */ "OBJECT_GI_SEED", - /* 0x011A */ "OBJECT_GND_MAGIC", - /* 0x011B */ "OBJECT_D_ELEVATOR", - /* 0x011C */ "OBJECT_D_HSBLOCK", - /* 0x011D */ "OBJECT_D_LIFT", - /* 0x011E */ "OBJECT_MAMENOKI", - /* 0x011F */ "OBJECT_GOROIWA", - /* 0x0120 */ "OBJECT_UNSET_120", - /* 0x0121 */ "OBJECT_TORYO", - /* 0x0122 */ "OBJECT_DAIKU", - /* 0x0123 */ "OBJECT_UNSET_123", - /* 0x0124 */ "OBJECT_NWC", - /* 0x0125 */ "OBJECT_BLKOBJ", - /* 0x0126 */ "OBJECT_GM", - /* 0x0127 */ "OBJECT_MS", - /* 0x0128 */ "OBJECT_HS", - /* 0x0129 */ "OBJECT_INGATE", - /* 0x012A */ "OBJECT_LIGHTSWITCH", - /* 0x012B */ "OBJECT_KUSA", - /* 0x012C */ "OBJECT_TSUBO", - /* 0x012D */ "OBJECT_GI_GLOVES", - /* 0x012E */ "OBJECT_GI_COIN", - /* 0x012F */ "OBJECT_KANBAN", - /* 0x0130 */ "OBJECT_GJYO_OBJECTS", - /* 0x0131 */ "OBJECT_OWL", - /* 0x0132 */ "OBJECT_MK", - /* 0x0133 */ "OBJECT_FU", - /* 0x0134 */ "OBJECT_GI_KI_TAN_MASK", - /* 0x0135 */ "OBJECT_GI_REDEAD_MASK", - /* 0x0136 */ "OBJECT_GI_SKJ_MASK", - /* 0x0137 */ "OBJECT_GI_RABIT_MASK", - /* 0x0138 */ "OBJECT_GI_TRUTH_MASK", - /* 0x0139 */ "OBJECT_GANON_OBJECTS", - /* 0x013A */ "OBJECT_SIOFUKI", - /* 0x013B */ "OBJECT_STREAM", - /* 0x013C */ "OBJECT_MM", - /* 0x013D */ "OBJECT_FA", - /* 0x013E */ "OBJECT_OS", - /* 0x013F */ "OBJECT_GI_EYE_LOTION", - /* 0x0140 */ "OBJECT_GI_POWDER", - /* 0x0141 */ "OBJECT_GI_MUSHROOM", - /* 0x0142 */ "OBJECT_GI_TICKETSTONE", - /* 0x0143 */ "OBJECT_GI_BROKENSWORD", - /* 0x0144 */ "OBJECT_JS", - /* 0x0145 */ "OBJECT_CS", - /* 0x0146 */ "OBJECT_GI_PRESCRIPTION", - /* 0x0147 */ "OBJECT_GI_BRACELET", - /* 0x0148 */ "OBJECT_GI_SOLDOUT", - /* 0x0149 */ "OBJECT_GI_FROG", - /* 0x014A */ "OBJECT_MAG", - /* 0x014B */ "OBJECT_DOOR_GERUDO", - /* 0x014C */ "OBJECT_GT", - /* 0x014D */ "OBJECT_EFC_ERUPC", - /* 0x014E */ "OBJECT_ZL2_ANIME1", - /* 0x014F */ "OBJECT_ZL2_ANIME2", - /* 0x0150 */ "OBJECT_GI_GOLONMASK", - /* 0x0151 */ "OBJECT_GI_ZORAMASK", - /* 0x0152 */ "OBJECT_GI_GERUDOMASK", - /* 0x0153 */ "OBJECT_GANON2", - /* 0x0154 */ "OBJECT_KA", - /* 0x0155 */ "OBJECT_TS", - /* 0x0156 */ "OBJECT_ZG", - /* 0x0157 */ "OBJECT_GI_HOVERBOOTS", - /* 0x0158 */ "OBJECT_GI_M_ARROW", - /* 0x0159 */ "OBJECT_DS2", - /* 0x015A */ "OBJECT_EC", - /* 0x015B */ "OBJECT_FISH", - /* 0x015C */ "OBJECT_GI_SUTARU", - /* 0x015D */ "OBJECT_GI_GODDESS", - /* 0x015E */ "OBJECT_SSH", - /* 0x015F */ "OBJECT_BIGOKUTA", - /* 0x0160 */ "OBJECT_BG", - /* 0x0161 */ "OBJECT_SPOT05_OBJECTS", - /* 0x0162 */ "OBJECT_SPOT12_OBJ", - /* 0x0163 */ "OBJECT_BOMBIWA", - /* 0x0164 */ "OBJECT_HINTNUTS", - /* 0x0165 */ "OBJECT_RS", - /* 0x0166 */ "OBJECT_SPOT00_BREAK", - /* 0x0167 */ "OBJECT_GLA", - /* 0x0168 */ "OBJECT_SHOPNUTS", - /* 0x0169 */ "OBJECT_GELDB", - /* 0x016A */ "OBJECT_GR", - /* 0x016B */ "OBJECT_DOG", - /* 0x016C */ "OBJECT_JYA_IRON", - /* 0x016D */ "OBJECT_JYA_DOOR", - /* 0x016E */ "OBJECT_UNSET_16E", - /* 0x016F */ "OBJECT_SPOT11_OBJ", - /* 0x0170 */ "OBJECT_KIBAKO2", - /* 0x0171 */ "OBJECT_DNS", - /* 0x0172 */ "OBJECT_DNK", - /* 0x0173 */ "OBJECT_GI_FIRE", - /* 0x0174 */ "OBJECT_GI_INSECT", - /* 0x0175 */ "OBJECT_GI_BUTTERFLY", - /* 0x0176 */ "OBJECT_GI_GHOST", - /* 0x0177 */ "OBJECT_GI_SOUL", - /* 0x0178 */ "OBJECT_BOWL", - /* 0x0179 */ "OBJECT_DEMO_KEKKAI", - /* 0x017A */ "OBJECT_EFC_DOUGHNUT", - /* 0x017B */ "OBJECT_GI_DEKUPOUCH", - /* 0x017C */ "OBJECT_GANON_ANIME1", - /* 0x017D */ "OBJECT_GANON_ANIME2", - /* 0x017E */ "OBJECT_GANON_ANIME3", - /* 0x017F */ "OBJECT_GI_RUPY", - /* 0x0180 */ "OBJECT_SPOT01_MATOYA", - /* 0x0181 */ "OBJECT_SPOT01_MATOYAB", - /* 0x0182 */ "OBJECT_MU", - /* 0x0183 */ "OBJECT_WF", - /* 0x0184 */ "OBJECT_SKB", - /* 0x0185 */ "OBJECT_GJ", - /* 0x0186 */ "OBJECT_GEFF", - /* 0x0187 */ "OBJECT_HAKA_DOOR", - /* 0x0188 */ "OBJECT_GS", - /* 0x0189 */ "OBJECT_PS", - /* 0x018A */ "OBJECT_BWALL", - /* 0x018B */ "OBJECT_COW", - /* 0x018C */ "OBJECT_COB", - /* 0x018D */ "OBJECT_GI_SWORD_1", - /* 0x018E */ "OBJECT_DOOR_KILLER", - /* 0x018F */ "OBJECT_OUKE_HAKA", - /* 0x0190 */ "OBJECT_TIMEBLOCK", - /* 0x0191 */ "OBJECT_ZL4", +static const std::string ObjectList[] = { + /* 0x0000 */ "OBJECT_UNSET_0", + /* 0x0001 */ "OBJECT_GAMEPLAY_KEEP", + /* 0x0002 */ "OBJECT_GAMEPLAY_FIELD_KEEP", + /* 0x0003 */ "OBJECT_GAMEPLAY_DANGEON_KEEP", + /* 0x0004 */ "OBJECT_UNSET_4", + /* 0x0005 */ "OBJECT_UNSET_5", + /* 0x0006 */ "OBJECT_HUMAN", + /* 0x0007 */ "OBJECT_OKUTA", + /* 0x0008 */ "OBJECT_CROW", + /* 0x0009 */ "OBJECT_POH", + /* 0x000A */ "OBJECT_DY_OBJ", + /* 0x000B */ "OBJECT_WALLMASTER", + /* 0x000C */ "OBJECT_DODONGO", + /* 0x000D */ "OBJECT_FIREFLY", + /* 0x000E */ "OBJECT_BOX", + /* 0x000F */ "OBJECT_FIRE", + /* 0x0010 */ "OBJECT_UNSET_10", + /* 0x0011 */ "OBJECT_UNSET_11", + /* 0x0012 */ "OBJECT_BUBBLE", + /* 0x0013 */ "OBJECT_NIW", + /* 0x0014 */ "OBJECT_LINK_BOY", + /* 0x0015 */ "OBJECT_LINK_CHILD", + /* 0x0016 */ "OBJECT_TITE", + /* 0x0017 */ "OBJECT_REEBA", + /* 0x0018 */ "OBJECT_PEEHAT", + /* 0x0019 */ "OBJECT_KINGDODONGO", + /* 0x001A */ "OBJECT_HORSE", + /* 0x001B */ "OBJECT_ZF", + /* 0x001C */ "OBJECT_GOMA", + /* 0x001D */ "OBJECT_ZL1", + /* 0x001E */ "OBJECT_GOL", + /* 0x001F */ "OBJECT_DODOJR", + /* 0x0020 */ "OBJECT_TORCH2", + /* 0x0021 */ "OBJECT_BL", + /* 0x0022 */ "OBJECT_TP", + /* 0x0023 */ "OBJECT_OA1", + /* 0x0024 */ "OBJECT_ST", + /* 0x0025 */ "OBJECT_BW", + /* 0x0026 */ "OBJECT_EI", + /* 0x0027 */ "OBJECT_HORSE_NORMAL", + /* 0x0028 */ "OBJECT_OB1", + /* 0x0029 */ "OBJECT_O_ANIME", + /* 0x002A */ "OBJECT_SPOT04_OBJECTS", + /* 0x002B */ "OBJECT_DDAN_OBJECTS", + /* 0x002C */ "OBJECT_HIDAN_OBJECTS", + /* 0x002D */ "OBJECT_HORSE_GANON", + /* 0x002E */ "OBJECT_OA2", + /* 0x002F */ "OBJECT_SPOT00_OBJECTS", + /* 0x0030 */ "OBJECT_MB", + /* 0x0031 */ "OBJECT_BOMBF", + /* 0x0032 */ "OBJECT_SK2", + /* 0x0033 */ "OBJECT_OE1", + /* 0x0034 */ "OBJECT_OE_ANIME", + /* 0x0035 */ "OBJECT_OE2", + /* 0x0036 */ "OBJECT_YDAN_OBJECTS", + /* 0x0037 */ "OBJECT_GND", + /* 0x0038 */ "OBJECT_AM", + /* 0x0039 */ "OBJECT_DEKUBABA", + /* 0x003A */ "OBJECT_UNSET_3A", + /* 0x003B */ "OBJECT_OA3", + /* 0x003C */ "OBJECT_OA4", + /* 0x003D */ "OBJECT_OA5", + /* 0x003E */ "OBJECT_OA6", + /* 0x003F */ "OBJECT_OA7", + /* 0x0040 */ "OBJECT_JJ", + /* 0x0041 */ "OBJECT_OA8", + /* 0x0042 */ "OBJECT_OA9", + /* 0x0043 */ "OBJECT_OB2", + /* 0x0044 */ "OBJECT_OB3", + /* 0x0045 */ "OBJECT_OB4", + /* 0x0046 */ "OBJECT_HORSE_ZELDA", + /* 0x0047 */ "OBJECT_OPENING_DEMO1", + /* 0x0048 */ "OBJECT_WARP1", + /* 0x0049 */ "OBJECT_B_HEART", + /* 0x004A */ "OBJECT_DEKUNUTS", + /* 0x004B */ "OBJECT_OE3", + /* 0x004C */ "OBJECT_OE4", + /* 0x004D */ "OBJECT_MENKURI_OBJECTS", + /* 0x004E */ "OBJECT_OE5", + /* 0x004F */ "OBJECT_OE6", + /* 0x0050 */ "OBJECT_OE7", + /* 0x0051 */ "OBJECT_OE8", + /* 0x0052 */ "OBJECT_OE9", + /* 0x0053 */ "OBJECT_OE10", + /* 0x0054 */ "OBJECT_OE11", + /* 0x0055 */ "OBJECT_OE12", + /* 0x0056 */ "OBJECT_VALI", + /* 0x0057 */ "OBJECT_OA10", + /* 0x0058 */ "OBJECT_OA11", + /* 0x0059 */ "OBJECT_MIZU_OBJECTS", + /* 0x005A */ "OBJECT_FHG", + /* 0x005B */ "OBJECT_OSSAN", + /* 0x005C */ "OBJECT_MORI_HINERI1", + /* 0x005D */ "OBJECT_BB", + /* 0x005E */ "OBJECT_TOKI_OBJECTS", + /* 0x005F */ "OBJECT_YUKABYUN", + /* 0x0060 */ "OBJECT_ZL2", + /* 0x0061 */ "OBJECT_MJIN", + /* 0x0062 */ "OBJECT_MJIN_FLASH", + /* 0x0063 */ "OBJECT_MJIN_DARK", + /* 0x0064 */ "OBJECT_MJIN_FLAME", + /* 0x0065 */ "OBJECT_MJIN_ICE", + /* 0x0066 */ "OBJECT_MJIN_SOUL", + /* 0x0067 */ "OBJECT_MJIN_WIND", + /* 0x0068 */ "OBJECT_MJIN_OKA", + /* 0x0069 */ "OBJECT_HAKA_OBJECTS", + /* 0x006A */ "OBJECT_SPOT06_OBJECTS", + /* 0x006B */ "OBJECT_ICE_OBJECTS", + /* 0x006C */ "OBJECT_RELAY_OBJECTS", + /* 0x006D */ "OBJECT_PO_FIELD", + /* 0x006E */ "OBJECT_PO_COMPOSER", + /* 0x006F */ "OBJECT_MORI_HINERI1A", + /* 0x0070 */ "OBJECT_MORI_HINERI2", + /* 0x0071 */ "OBJECT_MORI_HINERI2A", + /* 0x0072 */ "OBJECT_MORI_OBJECTS", + /* 0x0073 */ "OBJECT_MORI_TEX", + /* 0x0074 */ "OBJECT_SPOT08_OBJ", + /* 0x0075 */ "OBJECT_WARP2", + /* 0x0076 */ "OBJECT_HATA", + /* 0x0077 */ "OBJECT_BIRD", + /* 0x0078 */ "OBJECT_UNSET_78", + /* 0x0079 */ "OBJECT_UNSET_79", + /* 0x007A */ "OBJECT_UNSET_7A", + /* 0x007B */ "OBJECT_UNSET_7B", + /* 0x007C */ "OBJECT_WOOD02", + /* 0x007D */ "OBJECT_UNSET_7D", + /* 0x007E */ "OBJECT_UNSET_7E", + /* 0x007F */ "OBJECT_UNSET_7F", + /* 0x0080 */ "OBJECT_UNSET_80", + /* 0x0081 */ "OBJECT_LIGHTBOX", + /* 0x0082 */ "OBJECT_PU_BOX", + /* 0x0083 */ "OBJECT_UNSET_83", + /* 0x0084 */ "OBJECT_UNSET_84", + /* 0x0085 */ "OBJECT_TRAP", + /* 0x0086 */ "OBJECT_VASE", + /* 0x0087 */ "OBJECT_IM", + /* 0x0088 */ "OBJECT_TA", + /* 0x0089 */ "OBJECT_TK", + /* 0x008A */ "OBJECT_XC", + /* 0x008B */ "OBJECT_VM", + /* 0x008C */ "OBJECT_BV", + /* 0x008D */ "OBJECT_HAKACH_OBJECTS", + /* 0x008E */ "OBJECT_EFC_CRYSTAL_LIGHT", + /* 0x008F */ "OBJECT_EFC_FIRE_BALL", + /* 0x0090 */ "OBJECT_EFC_FLASH", + /* 0x0091 */ "OBJECT_EFC_LGT_SHOWER", + /* 0x0092 */ "OBJECT_EFC_STAR_FIELD", + /* 0x0093 */ "OBJECT_GOD_LGT", + /* 0x0094 */ "OBJECT_LIGHT_RING", + /* 0x0095 */ "OBJECT_TRIFORCE_SPOT", + /* 0x0096 */ "OBJECT_BDAN_OBJECTS", + /* 0x0097 */ "OBJECT_SD", + /* 0x0098 */ "OBJECT_RD", + /* 0x0099 */ "OBJECT_PO_SISTERS", + /* 0x009A */ "OBJECT_HEAVY_OBJECT", + /* 0x009B */ "OBJECT_GNDD", + /* 0x009C */ "OBJECT_FD", + /* 0x009D */ "OBJECT_DU", + /* 0x009E */ "OBJECT_FW", + /* 0x009F */ "OBJECT_MEDAL", + /* 0x00A0 */ "OBJECT_HORSE_LINK_CHILD", + /* 0x00A1 */ "OBJECT_SPOT02_OBJECTS", + /* 0x00A2 */ "OBJECT_HAKA", + /* 0x00A3 */ "OBJECT_RU1", + /* 0x00A4 */ "OBJECT_SYOKUDAI", + /* 0x00A5 */ "OBJECT_FD2", + /* 0x00A6 */ "OBJECT_DH", + /* 0x00A7 */ "OBJECT_RL", + /* 0x00A8 */ "OBJECT_EFC_TW", + /* 0x00A9 */ "OBJECT_DEMO_TRE_LGT", + /* 0x00AA */ "OBJECT_GI_KEY", + /* 0x00AB */ "OBJECT_MIR_RAY", + /* 0x00AC */ "OBJECT_BROB", + /* 0x00AD */ "OBJECT_GI_JEWEL", + /* 0x00AE */ "OBJECT_SPOT09_OBJ", + /* 0x00AF */ "OBJECT_SPOT18_OBJ", + /* 0x00B0 */ "OBJECT_BDOOR", + /* 0x00B1 */ "OBJECT_SPOT17_OBJ", + /* 0x00B2 */ "OBJECT_SHOP_DUNGEN", + /* 0x00B3 */ "OBJECT_NB", + /* 0x00B4 */ "OBJECT_MO", + /* 0x00B5 */ "OBJECT_SB", + /* 0x00B6 */ "OBJECT_GI_MELODY", + /* 0x00B7 */ "OBJECT_GI_HEART", + /* 0x00B8 */ "OBJECT_GI_COMPASS", + /* 0x00B9 */ "OBJECT_GI_BOSSKEY", + /* 0x00BA */ "OBJECT_GI_MEDAL", + /* 0x00BB */ "OBJECT_GI_NUTS", + /* 0x00BC */ "OBJECT_SA", + /* 0x00BD */ "OBJECT_GI_HEARTS", + /* 0x00BE */ "OBJECT_GI_ARROWCASE", + /* 0x00BF */ "OBJECT_GI_BOMBPOUCH", + /* 0x00C0 */ "OBJECT_IN", + /* 0x00C1 */ "OBJECT_TR", + /* 0x00C2 */ "OBJECT_SPOT16_OBJ", + /* 0x00C3 */ "OBJECT_OE1S", + /* 0x00C4 */ "OBJECT_OE4S", + /* 0x00C5 */ "OBJECT_OS_ANIME", + /* 0x00C6 */ "OBJECT_GI_BOTTLE", + /* 0x00C7 */ "OBJECT_GI_STICK", + /* 0x00C8 */ "OBJECT_GI_MAP", + /* 0x00C9 */ "OBJECT_OF1D_MAP", + /* 0x00CA */ "OBJECT_RU2", + /* 0x00CB */ "OBJECT_GI_SHIELD_1", + /* 0x00CC */ "OBJECT_DEKUJR", + /* 0x00CD */ "OBJECT_GI_MAGICPOT", + /* 0x00CE */ "OBJECT_GI_BOMB_1", + /* 0x00CF */ "OBJECT_OF1S", + /* 0x00D0 */ "OBJECT_MA2", + /* 0x00D1 */ "OBJECT_GI_PURSE", + /* 0x00D2 */ "OBJECT_HNI", + /* 0x00D3 */ "OBJECT_TW", + /* 0x00D4 */ "OBJECT_RR", + /* 0x00D5 */ "OBJECT_BXA", + /* 0x00D6 */ "OBJECT_ANUBICE", + /* 0x00D7 */ "OBJECT_GI_GERUDO", + /* 0x00D8 */ "OBJECT_GI_ARROW", + /* 0x00D9 */ "OBJECT_GI_BOMB_2", + /* 0x00DA */ "OBJECT_GI_EGG", + /* 0x00DB */ "OBJECT_GI_SCALE", + /* 0x00DC */ "OBJECT_GI_SHIELD_2", + /* 0x00DD */ "OBJECT_GI_HOOKSHOT", + /* 0x00DE */ "OBJECT_GI_OCARINA", + /* 0x00DF */ "OBJECT_GI_MILK", + /* 0x00E0 */ "OBJECT_MA1", + /* 0x00E1 */ "OBJECT_GANON", + /* 0x00E2 */ "OBJECT_SST", + /* 0x00E3 */ "OBJECT_NY_UNUSED", + /* 0x00E4 */ "OBJECT_UNSET_E4", + /* 0x00E5 */ "OBJECT_NY", + /* 0x00E6 */ "OBJECT_FR", + /* 0x00E7 */ "OBJECT_GI_PACHINKO", + /* 0x00E8 */ "OBJECT_GI_BOOMERANG", + /* 0x00E9 */ "OBJECT_GI_BOW", + /* 0x00EA */ "OBJECT_GI_GLASSES", + /* 0x00EB */ "OBJECT_GI_LIQUID", + /* 0x00EC */ "OBJECT_ANI", + /* 0x00ED */ "OBJECT_DEMO_6K", + /* 0x00EE */ "OBJECT_GI_SHIELD_3", + /* 0x00EF */ "OBJECT_GI_LETTER", + /* 0x00F0 */ "OBJECT_SPOT15_OBJ", + /* 0x00F1 */ "OBJECT_JYA_OBJ", + /* 0x00F2 */ "OBJECT_GI_CLOTHES", + /* 0x00F3 */ "OBJECT_GI_BEAN", + /* 0x00F4 */ "OBJECT_GI_FISH", + /* 0x00F5 */ "OBJECT_GI_SAW", + /* 0x00F6 */ "OBJECT_GI_HAMMER", + /* 0x00F7 */ "OBJECT_GI_GRASS", + /* 0x00F8 */ "OBJECT_GI_LONGSWORD", + /* 0x00F9 */ "OBJECT_SPOT01_OBJECTS", + /* 0x00FA */ "OBJECT_MD_UNUSED", + /* 0x00FB */ "OBJECT_MD", + /* 0x00FC */ "OBJECT_KM1", + /* 0x00FD */ "OBJECT_KW1", + /* 0x00FE */ "OBJECT_ZO", + /* 0x00FF */ "OBJECT_KZ", + /* 0x0100 */ "OBJECT_UMAJUMP", + /* 0x0101 */ "OBJECT_MASTERKOKIRI", + /* 0x0102 */ "OBJECT_MASTERKOKIRIHEAD", + /* 0x0103 */ "OBJECT_MASTERGOLON", + /* 0x0104 */ "OBJECT_MASTERZOORA", + /* 0x0105 */ "OBJECT_AOB", + /* 0x0106 */ "OBJECT_IK", + /* 0x0107 */ "OBJECT_AHG", + /* 0x0108 */ "OBJECT_CNE", + /* 0x0109 */ "OBJECT_GI_NIWATORI", + /* 0x010A */ "OBJECT_SKJ", + /* 0x010B */ "OBJECT_GI_BOTTLE_LETTER", + /* 0x010C */ "OBJECT_BJI", + /* 0x010D */ "OBJECT_BBA", + /* 0x010E */ "OBJECT_GI_OCARINA_0", + /* 0x010F */ "OBJECT_DS", + /* 0x0110 */ "OBJECT_ANE", + /* 0x0111 */ "OBJECT_BOJ", + /* 0x0112 */ "OBJECT_SPOT03_OBJECT", + /* 0x0113 */ "OBJECT_SPOT07_OBJECT", + /* 0x0114 */ "OBJECT_FZ", + /* 0x0115 */ "OBJECT_BOB", + /* 0x0116 */ "OBJECT_GE1", + /* 0x0117 */ "OBJECT_YABUSAME_POINT", + /* 0x0118 */ "OBJECT_GI_BOOTS_2", + /* 0x0119 */ "OBJECT_GI_SEED", + /* 0x011A */ "OBJECT_GND_MAGIC", + /* 0x011B */ "OBJECT_D_ELEVATOR", + /* 0x011C */ "OBJECT_D_HSBLOCK", + /* 0x011D */ "OBJECT_D_LIFT", + /* 0x011E */ "OBJECT_MAMENOKI", + /* 0x011F */ "OBJECT_GOROIWA", + /* 0x0120 */ "OBJECT_UNSET_120", + /* 0x0121 */ "OBJECT_TORYO", + /* 0x0122 */ "OBJECT_DAIKU", + /* 0x0123 */ "OBJECT_UNSET_123", + /* 0x0124 */ "OBJECT_NWC", + /* 0x0125 */ "OBJECT_BLKOBJ", + /* 0x0126 */ "OBJECT_GM", + /* 0x0127 */ "OBJECT_MS", + /* 0x0128 */ "OBJECT_HS", + /* 0x0129 */ "OBJECT_INGATE", + /* 0x012A */ "OBJECT_LIGHTSWITCH", + /* 0x012B */ "OBJECT_KUSA", + /* 0x012C */ "OBJECT_TSUBO", + /* 0x012D */ "OBJECT_GI_GLOVES", + /* 0x012E */ "OBJECT_GI_COIN", + /* 0x012F */ "OBJECT_KANBAN", + /* 0x0130 */ "OBJECT_GJYO_OBJECTS", + /* 0x0131 */ "OBJECT_OWL", + /* 0x0132 */ "OBJECT_MK", + /* 0x0133 */ "OBJECT_FU", + /* 0x0134 */ "OBJECT_GI_KI_TAN_MASK", + /* 0x0135 */ "OBJECT_GI_REDEAD_MASK", + /* 0x0136 */ "OBJECT_GI_SKJ_MASK", + /* 0x0137 */ "OBJECT_GI_RABIT_MASK", + /* 0x0138 */ "OBJECT_GI_TRUTH_MASK", + /* 0x0139 */ "OBJECT_GANON_OBJECTS", + /* 0x013A */ "OBJECT_SIOFUKI", + /* 0x013B */ "OBJECT_STREAM", + /* 0x013C */ "OBJECT_MM", + /* 0x013D */ "OBJECT_FA", + /* 0x013E */ "OBJECT_OS", + /* 0x013F */ "OBJECT_GI_EYE_LOTION", + /* 0x0140 */ "OBJECT_GI_POWDER", + /* 0x0141 */ "OBJECT_GI_MUSHROOM", + /* 0x0142 */ "OBJECT_GI_TICKETSTONE", + /* 0x0143 */ "OBJECT_GI_BROKENSWORD", + /* 0x0144 */ "OBJECT_JS", + /* 0x0145 */ "OBJECT_CS", + /* 0x0146 */ "OBJECT_GI_PRESCRIPTION", + /* 0x0147 */ "OBJECT_GI_BRACELET", + /* 0x0148 */ "OBJECT_GI_SOLDOUT", + /* 0x0149 */ "OBJECT_GI_FROG", + /* 0x014A */ "OBJECT_MAG", + /* 0x014B */ "OBJECT_DOOR_GERUDO", + /* 0x014C */ "OBJECT_GT", + /* 0x014D */ "OBJECT_EFC_ERUPC", + /* 0x014E */ "OBJECT_ZL2_ANIME1", + /* 0x014F */ "OBJECT_ZL2_ANIME2", + /* 0x0150 */ "OBJECT_GI_GOLONMASK", + /* 0x0151 */ "OBJECT_GI_ZORAMASK", + /* 0x0152 */ "OBJECT_GI_GERUDOMASK", + /* 0x0153 */ "OBJECT_GANON2", + /* 0x0154 */ "OBJECT_KA", + /* 0x0155 */ "OBJECT_TS", + /* 0x0156 */ "OBJECT_ZG", + /* 0x0157 */ "OBJECT_GI_HOVERBOOTS", + /* 0x0158 */ "OBJECT_GI_M_ARROW", + /* 0x0159 */ "OBJECT_DS2", + /* 0x015A */ "OBJECT_EC", + /* 0x015B */ "OBJECT_FISH", + /* 0x015C */ "OBJECT_GI_SUTARU", + /* 0x015D */ "OBJECT_GI_GODDESS", + /* 0x015E */ "OBJECT_SSH", + /* 0x015F */ "OBJECT_BIGOKUTA", + /* 0x0160 */ "OBJECT_BG", + /* 0x0161 */ "OBJECT_SPOT05_OBJECTS", + /* 0x0162 */ "OBJECT_SPOT12_OBJ", + /* 0x0163 */ "OBJECT_BOMBIWA", + /* 0x0164 */ "OBJECT_HINTNUTS", + /* 0x0165 */ "OBJECT_RS", + /* 0x0166 */ "OBJECT_SPOT00_BREAK", + /* 0x0167 */ "OBJECT_GLA", + /* 0x0168 */ "OBJECT_SHOPNUTS", + /* 0x0169 */ "OBJECT_GELDB", + /* 0x016A */ "OBJECT_GR", + /* 0x016B */ "OBJECT_DOG", + /* 0x016C */ "OBJECT_JYA_IRON", + /* 0x016D */ "OBJECT_JYA_DOOR", + /* 0x016E */ "OBJECT_UNSET_16E", + /* 0x016F */ "OBJECT_SPOT11_OBJ", + /* 0x0170 */ "OBJECT_KIBAKO2", + /* 0x0171 */ "OBJECT_DNS", + /* 0x0172 */ "OBJECT_DNK", + /* 0x0173 */ "OBJECT_GI_FIRE", + /* 0x0174 */ "OBJECT_GI_INSECT", + /* 0x0175 */ "OBJECT_GI_BUTTERFLY", + /* 0x0176 */ "OBJECT_GI_GHOST", + /* 0x0177 */ "OBJECT_GI_SOUL", + /* 0x0178 */ "OBJECT_BOWL", + /* 0x0179 */ "OBJECT_DEMO_KEKKAI", + /* 0x017A */ "OBJECT_EFC_DOUGHNUT", + /* 0x017B */ "OBJECT_GI_DEKUPOUCH", + /* 0x017C */ "OBJECT_GANON_ANIME1", + /* 0x017D */ "OBJECT_GANON_ANIME2", + /* 0x017E */ "OBJECT_GANON_ANIME3", + /* 0x017F */ "OBJECT_GI_RUPY", + /* 0x0180 */ "OBJECT_SPOT01_MATOYA", + /* 0x0181 */ "OBJECT_SPOT01_MATOYAB", + /* 0x0182 */ "OBJECT_MU", + /* 0x0183 */ "OBJECT_WF", + /* 0x0184 */ "OBJECT_SKB", + /* 0x0185 */ "OBJECT_GJ", + /* 0x0186 */ "OBJECT_GEFF", + /* 0x0187 */ "OBJECT_HAKA_DOOR", + /* 0x0188 */ "OBJECT_GS", + /* 0x0189 */ "OBJECT_PS", + /* 0x018A */ "OBJECT_BWALL", + /* 0x018B */ "OBJECT_COW", + /* 0x018C */ "OBJECT_COB", + /* 0x018D */ "OBJECT_GI_SWORD_1", + /* 0x018E */ "OBJECT_DOOR_KILLER", + /* 0x018F */ "OBJECT_OUKE_HAKA", + /* 0x0190 */ "OBJECT_TIMEBLOCK", + /* 0x0191 */ "OBJECT_ZL4", }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp b/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp index b8ea40b029..9d8528c870 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp @@ -1,40 +1,40 @@ +#include "ZRoom.h" +#include #include #include -#include "ZRoom.h" -#include "ZFile.h" -#include "ZCutscene.h" -#include "../ZBlob.h" -#include "ObjectList.h" #include "../File.h" -#include "../StringHelper.h" #include "../Globals.h" -#include "Commands/SetRoomList.h" -#include "Commands/SetEchoSettings.h" -#include "Commands/SetSoundSettings.h" -#include "Commands/SetWind.h" -#include "Commands/SetTimeSettings.h" -#include "Commands/SetSpecialObjects.h" -#include "Commands/SetSkyboxSettings.h" -#include "Commands/SetSkyboxModifier.h" -#include "Commands/SetRoomBehavior.h" -#include "Commands/SetCameraSettings.h" -#include "Commands/SetStartPositionList.h" +#include "../StringHelper.h" +#include "../ZBlob.h" +#include "Commands/EndMarker.h" #include "Commands/SetActorList.h" -#include "Commands/SetTransitionActorList.h" +#include "Commands/SetAlternateHeaders.h" +#include "Commands/SetCameraSettings.h" +#include "Commands/SetCollisionHeader.h" +#include "Commands/SetCutscenes.h" +#include "Commands/SetEchoSettings.h" #include "Commands/SetEntranceList.h" #include "Commands/SetExitList.h" -#include "Commands/SetAlternateHeaders.h" -#include "Commands/SetCollisionHeader.h" -#include "Commands/SetObjectList.h" -#include "Commands/SetMesh.h" -#include "Commands/SetLightingSettings.h" -#include "Commands/SetPathways.h" -#include "Commands/Unused09.h" -#include "Commands/SetCutscenes.h" -#include "Commands/EndMarker.h" #include "Commands/SetLightList.h" +#include "Commands/SetLightingSettings.h" +#include "Commands/SetMesh.h" +#include "Commands/SetObjectList.h" +#include "Commands/SetPathways.h" +#include "Commands/SetRoomBehavior.h" +#include "Commands/SetRoomList.h" +#include "Commands/SetSkyboxModifier.h" +#include "Commands/SetSkyboxSettings.h" +#include "Commands/SetSoundSettings.h" +#include "Commands/SetSpecialObjects.h" +#include "Commands/SetStartPositionList.h" +#include "Commands/SetTimeSettings.h" +#include "Commands/SetTransitionActorList.h" +#include "Commands/SetWind.h" +#include "Commands/Unused09.h" #include "Commands/ZRoomCommandUnk.h" -#include +#include "ObjectList.h" +#include "ZCutscene.h" +#include "ZFile.h" using namespace std; using namespace tinyxml2; @@ -54,7 +54,8 @@ ZRoom::~ZRoom() delete cmd; } -ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int rawDataIndex, string nRelPath, ZFile* nParent, ZRoom* nScene) +ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int rawDataIndex, + string nRelPath, ZFile* nParent, ZRoom* nScene) { ZRoom* room = new ZRoom(); @@ -62,7 +63,7 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int r room->rawData = nRawData; room->name = reader->Attribute("Name"); - //printf("ZRoom: %s\n", name.c_str()); + // printf("ZRoom: %s\n", name.c_str()); room->scene = nScene; @@ -75,7 +76,7 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int r Globals::Instance->AddSegment(SEGMENT_ROOM); Globals::Instance->AddSegment(SEGMENT_SCENE); - //GenDefinitions(); + // GenDefinitions(); int cmdCount = 999999; @@ -85,7 +86,8 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int r cmdCount = 0; } - for (XMLElement* child = reader->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) + for (XMLElement* child = reader->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) { // TODO: Bunch of repeated code between all of these that needs to be combined. if (string(child->Name()) == "DListHint") @@ -99,7 +101,12 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int r string addressStr = child->Attribute("Offset"); int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); - ZDisplayList* dList = new ZDisplayList(room->rawData, address, ZDisplayList::GetDListLength(room->rawData, address, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX)); + ZDisplayList* dList = new ZDisplayList( + room->rawData, address, + ZDisplayList::GetDListLength(room->rawData, address, + Globals::Instance->game == ZGame::OOT_SW97 ? + DListType::F3DEX : + DListType::F3DZEX)); if (child->Attribute("Name") != NULL) name = string(child->Attribute("Name")); @@ -123,14 +130,18 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int r string sizeStr = child->Attribute("Size"); int size = strtol(StringHelper::Split(sizeStr, "0x")[1].c_str(), NULL, 16); - ZBlob* blob = new ZBlob(room->rawData, address, size, StringHelper::Sprintf("%sBlob0x%06X", room->name.c_str(), address)); - + ZBlob* blob = + new ZBlob(room->rawData, address, size, + StringHelper::Sprintf("%sBlob0x%06X", room->name.c_str(), address)); + if (child->Attribute("Name") != NULL) name = string(child->Attribute("Name")); else name = StringHelper::Sprintf("%s_%s", room->name.c_str(), blob->GetName().c_str()); - - room->parent->AddDeclarationArray(address, DeclarationAlignment::None, blob->GetRawDataSize(), "u8", name, 0, blob->GetSourceOutputCode(room->name)); + + room->parent->AddDeclarationArray(address, DeclarationAlignment::None, + blob->GetRawDataSize(), "u8", name, 0, + blob->GetSourceOutputCode(room->name)); delete blob; } else if (string(child->Name()) == "CutsceneHint") @@ -149,10 +160,13 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int r if (child->Attribute("Name") != NULL) name = string(child->Attribute("Name")); else - name = StringHelper::Sprintf("%sCutsceneData0x%06X", room->name.c_str(), cutscene->segmentOffset); + name = StringHelper::Sprintf("%sCutsceneData0x%06X", room->name.c_str(), + cutscene->segmentOffset); - room->parent->AddDeclarationArray(address, DeclarationAlignment::None, DeclarationPadding::Pad16, cutscene->GetRawDataSize(), "s32", - name, 0, cutscene->GetSourceOutputCode(room->name)); + room->parent->AddDeclarationArray(address, DeclarationAlignment::None, + DeclarationPadding::Pad16, cutscene->GetRawDataSize(), + "s32", name, 0, + cutscene->GetSourceOutputCode(room->name)); delete cutscene; } else if (string(child->Name()) == "AltHeaderHint") @@ -207,14 +221,18 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int r int width = strtol(string(child->Attribute("Width")).c_str(), NULL, 10); int height = strtol(string(child->Attribute("Height")).c_str(), NULL, 10); - ZTexture* tex = ZTexture::FromBinary(ZTexture::GetTextureTypeFromString(typeStr), room->rawData, address, StringHelper::Sprintf("%sTex_%06X", room->name.c_str(), address), width, height); - room->parent->AddDeclarationArray(address, DeclarationAlignment::None, tex->GetRawDataSize(), "u64", StringHelper::Sprintf("%s", tex->GetName().c_str()), 0, - tex->GetSourceOutputCode(room->name)); + ZTexture* tex = ZTexture::FromBinary( + ZTexture::GetTextureTypeFromString(typeStr), room->rawData, address, + StringHelper::Sprintf("%sTex_%06X", room->name.c_str(), address), width, height); + room->parent->AddDeclarationArray(address, DeclarationAlignment::None, + tex->GetRawDataSize(), "u64", + StringHelper::Sprintf("%s", tex->GetName().c_str()), + 0, tex->GetSourceOutputCode(room->name)); delete tex; } } - //ParseCommands(rawDataIndex); + // ParseCommands(rawDataIndex); room->commandSets.push_back(CommandSet(rawDataIndex, cmdCount)); room->ProcessCommandSets(); @@ -242,32 +260,83 @@ void ZRoom::ParseCommands(std::vector& commandList, CommandSet co switch (opcode) { - case RoomCommand::SetStartPositionList: cmd = new SetStartPositionList(this, rawData, rawDataIndex); break; // 0x00 - case RoomCommand::SetActorList: cmd = new SetActorList(this, rawData, rawDataIndex); break; // 0x01 - case RoomCommand::SetCollisionHeader: cmd = new SetCollisionHeader(this, rawData, rawDataIndex); break; // 0x03 - case RoomCommand::SetRoomList: cmd = new SetRoomList(this, rawData, rawDataIndex); break; // 0x04 - case RoomCommand::SetWind: cmd = new SetWind(this, rawData, rawDataIndex); break; // 0x05 - case RoomCommand::SetEntranceList: cmd = new SetEntranceList(this, rawData, rawDataIndex); break; // 0x06 - case RoomCommand::SetSpecialObjects: cmd = new SetSpecialObjects(this, rawData, rawDataIndex); break; // 0x07 - case RoomCommand::SetRoomBehavior: cmd = new SetRoomBehavior(this, rawData, rawDataIndex); break; // 0x08 - case RoomCommand::Unused09: cmd = new Unused09(this, rawData, rawDataIndex); break; // 0x09 - case RoomCommand::SetMesh: cmd = new SetMesh(this, rawData, rawDataIndex, 0); break; // 0x0A - case RoomCommand::SetObjectList: cmd = new SetObjectList(this, rawData, rawDataIndex); break; // 0x0B - case RoomCommand::SetLightList: cmd = new SetLightList(this, rawData, rawDataIndex); break; // 0x0C (MM-ONLY) - case RoomCommand::SetPathways: cmd = new SetPathways(this, rawData, rawDataIndex); break; // 0x0D - case RoomCommand::SetTransitionActorList: cmd = new SetTransitionActorList(this, rawData, rawDataIndex); break; // 0x0E - case RoomCommand::SetLightingSettings: cmd = new SetLightingSettings(this, rawData, rawDataIndex); break; // 0x0F - case RoomCommand::SetTimeSettings: cmd = new SetTimeSettings(this, rawData, rawDataIndex); break; // 0x10 - case RoomCommand::SetSkyboxSettings: cmd = new SetSkyboxSettings(this, rawData, rawDataIndex); break; // 0x11 - case RoomCommand::SetSkyboxModifier: cmd = new SetSkyboxModifier(this, rawData, rawDataIndex); break; // 0x12 - case RoomCommand::SetExitList: cmd = new SetExitList(this, rawData, rawDataIndex); break; // 0x13 - case RoomCommand::EndMarker: cmd = new EndMarker(this, rawData, rawDataIndex); break; // 0x14 - case RoomCommand::SetSoundSettings: cmd = new SetSoundSettings(this, rawData, rawDataIndex); break; // 0x15 - case RoomCommand::SetEchoSettings: cmd = new SetEchoSettings(this, rawData, rawDataIndex); break; // 0x16 - case RoomCommand::SetCutscenes: cmd = new SetCutscenes(this, rawData, rawDataIndex); break; // 0x17 - case RoomCommand::SetAlternateHeaders: cmd = new SetAlternateHeaders(this, rawData, rawDataIndex); break; // 0x18 - case RoomCommand::SetCameraSettings: cmd = new SetCameraSettings(this, rawData, rawDataIndex); break; // 0x19 - default: cmd = new ZRoomCommandUnk(this, rawData, rawDataIndex); + case RoomCommand::SetStartPositionList: + cmd = new SetStartPositionList(this, rawData, rawDataIndex); + break; // 0x00 + case RoomCommand::SetActorList: + cmd = new SetActorList(this, rawData, rawDataIndex); + break; // 0x01 + case RoomCommand::SetCollisionHeader: + cmd = new SetCollisionHeader(this, rawData, rawDataIndex); + break; // 0x03 + case RoomCommand::SetRoomList: + cmd = new SetRoomList(this, rawData, rawDataIndex); + break; // 0x04 + case RoomCommand::SetWind: + cmd = new SetWind(this, rawData, rawDataIndex); + break; // 0x05 + case RoomCommand::SetEntranceList: + cmd = new SetEntranceList(this, rawData, rawDataIndex); + break; // 0x06 + case RoomCommand::SetSpecialObjects: + cmd = new SetSpecialObjects(this, rawData, rawDataIndex); + break; // 0x07 + case RoomCommand::SetRoomBehavior: + cmd = new SetRoomBehavior(this, rawData, rawDataIndex); + break; // 0x08 + case RoomCommand::Unused09: + cmd = new Unused09(this, rawData, rawDataIndex); + break; // 0x09 + case RoomCommand::SetMesh: + cmd = new SetMesh(this, rawData, rawDataIndex, 0); + break; // 0x0A + case RoomCommand::SetObjectList: + cmd = new SetObjectList(this, rawData, rawDataIndex); + break; // 0x0B + case RoomCommand::SetLightList: + cmd = new SetLightList(this, rawData, rawDataIndex); + break; // 0x0C (MM-ONLY) + case RoomCommand::SetPathways: + cmd = new SetPathways(this, rawData, rawDataIndex); + break; // 0x0D + case RoomCommand::SetTransitionActorList: + cmd = new SetTransitionActorList(this, rawData, rawDataIndex); + break; // 0x0E + case RoomCommand::SetLightingSettings: + cmd = new SetLightingSettings(this, rawData, rawDataIndex); + break; // 0x0F + case RoomCommand::SetTimeSettings: + cmd = new SetTimeSettings(this, rawData, rawDataIndex); + break; // 0x10 + case RoomCommand::SetSkyboxSettings: + cmd = new SetSkyboxSettings(this, rawData, rawDataIndex); + break; // 0x11 + case RoomCommand::SetSkyboxModifier: + cmd = new SetSkyboxModifier(this, rawData, rawDataIndex); + break; // 0x12 + case RoomCommand::SetExitList: + cmd = new SetExitList(this, rawData, rawDataIndex); + break; // 0x13 + case RoomCommand::EndMarker: + cmd = new EndMarker(this, rawData, rawDataIndex); + break; // 0x14 + case RoomCommand::SetSoundSettings: + cmd = new SetSoundSettings(this, rawData, rawDataIndex); + break; // 0x15 + case RoomCommand::SetEchoSettings: + cmd = new SetEchoSettings(this, rawData, rawDataIndex); + break; // 0x16 + case RoomCommand::SetCutscenes: + cmd = new SetCutscenes(this, rawData, rawDataIndex); + break; // 0x17 + case RoomCommand::SetAlternateHeaders: + cmd = new SetAlternateHeaders(this, rawData, rawDataIndex); + break; // 0x18 + case RoomCommand::SetCameraSettings: + cmd = new SetCameraSettings(this, rawData, rawDataIndex); + break; // 0x19 + default: + cmd = new ZRoomCommandUnk(this, rawData, rawDataIndex); } auto end = chrono::steady_clock::now(); @@ -279,7 +348,7 @@ void ZRoom::ParseCommands(std::vector& commandList, CommandSet co printf("OP: %s, TIME: %lims\n", cmd->GetCommandCName().c_str(), diff); } - //printf("OP: %s\n", cmd->GetCommandCName().c_str()); + // printf("OP: %s\n", cmd->GetCommandCName().c_str()); cmd->cmdIndex = currentIndex; cmd->cmdSet = rawDataIndex; @@ -306,14 +375,18 @@ void ZRoom::ProcessCommandSets() ParseCommands(setCommands, commandSets[0]); commandSets.erase(commandSets.begin()); - for (int i = 0; i < setCommands.size(); i++) + for (size_t i = 0; i < setCommands.size(); i++) { ZRoomCommand* cmd = setCommands[i]; cmd->commandSet = commandSet & 0x00FFFFFF; string pass1 = cmd->GenerateSourceCodePass1(name, cmd->commandSet); - Declaration* decl = parent->AddDeclaration(cmd->cmdAddress, i == 0 ? DeclarationAlignment::Align16 : DeclarationAlignment::None, 8, StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()), - StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), commandSet & 0x00FFFFFF, cmd->cmdIndex, cmd->cmdID), + Declaration* decl = parent->AddDeclaration( + cmd->cmdAddress, + i == 0 ? DeclarationAlignment::Align16 : DeclarationAlignment::None, 8, + StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()), + StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), commandSet & 0x00FFFFFF, + cmd->cmdIndex, cmd->cmdID), StringHelper::Sprintf("%s", pass1.c_str())); decl->rightText = StringHelper::Sprintf("// 0x%04X", cmd->cmdAddress); @@ -330,27 +403,30 @@ void ZRoom::ProcessCommandSets() string pass2 = cmd->GenerateSourceCodePass2(name, cmd->commandSet); if (pass2 != "") - parent->AddDeclaration(cmd->cmdAddress, DeclarationAlignment::None, 8, StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()), StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), cmd->commandSet & 0x00FFFFFF, cmd->cmdIndex, cmd->cmdID), StringHelper::Sprintf("%s // 0x%04X", pass2.c_str(), cmd->cmdAddress)); + parent->AddDeclaration( + cmd->cmdAddress, DeclarationAlignment::None, 8, + StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()), + StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), + cmd->commandSet & 0x00FFFFFF, cmd->cmdIndex, cmd->cmdID), + StringHelper::Sprintf("%s // 0x%04X", pass2.c_str(), cmd->cmdAddress)); } } /* - * There is one room in Ocarina of Time that lacks a header. Room 120, "Syotes", dates back to very early in the game's development. - * Since this room is a special case, this hack adds back a header so that the room can be processed properly. + * There is one room in Ocarina of Time that lacks a header. Room 120, "Syotes", dates back to very + * early in the game's development. Since this room is a special case, this hack adds back a header + * so that the room can be processed properly. */ void ZRoom::SyotesRoomHack() { - char headerData[] = - { - 0x0A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08 - }; + char headerData[] = {0x0A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08}; - for (int i = 0; i < sizeof(headerData); i++) + for (size_t i = 0; i < sizeof(headerData); i++) rawData.insert(rawData.begin() + i, headerData[i]); SetMesh* cmdSetMesh = new SetMesh(this, rawData, 0, -8); - for (int i = 0; i < sizeof(headerData); i++) + for (size_t i = 0; i < sizeof(headerData); i++) rawData.erase(rawData.begin()); cmdSetMesh->cmdIndex = 0; @@ -361,7 +437,7 @@ void ZRoom::SyotesRoomHack() ZRoomCommand* ZRoom::FindCommandOfType(RoomCommand cmdType) { - for (int i = 0; i < commands.size(); i++) + for (size_t i = 0; i < commands.size(); i++) { if (commands[i]->cmdID == cmdType) return commands[i]; @@ -372,15 +448,17 @@ ZRoomCommand* ZRoom::FindCommandOfType(RoomCommand cmdType) size_t ZRoom::GetDeclarationSizeFromNeighbor(int declarationAddress) { - int declarationIndex = -1; + size_t declarationIndex = -1; // Copy it into a vector. - vector> declarationKeysSorted(parent->declarations.begin(), parent->declarations.end()); + vector> declarationKeysSorted(parent->declarations.begin(), + parent->declarations.end()); // Sort the vector according to the word count in descending order. - sort(declarationKeysSorted.begin(), declarationKeysSorted.end(), [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); + sort(declarationKeysSorted.begin(), declarationKeysSorted.end(), + [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); - for (int i = 0; i < declarationKeysSorted.size(); i++) + for (size_t i = 0; i < declarationKeysSorted.size(); i++) { if (declarationKeysSorted[i].first == declarationAddress) { @@ -389,10 +467,11 @@ size_t ZRoom::GetDeclarationSizeFromNeighbor(int declarationAddress) } } - if (declarationIndex != -1) + if ((int)declarationIndex != -1) { if (declarationIndex + 1 < declarationKeysSorted.size()) - return declarationKeysSorted[declarationIndex + 1].first - declarationKeysSorted[declarationIndex].first; + return declarationKeysSorted[declarationIndex + 1].first - + declarationKeysSorted[declarationIndex].first; else return rawData.size() - declarationKeysSorted[declarationIndex].first; } @@ -402,9 +481,9 @@ size_t ZRoom::GetDeclarationSizeFromNeighbor(int declarationAddress) size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd) { - int cmdIndex = -1; + size_t cmdIndex = -1; - for (int i = 0; i < commands.size(); i++) + for (size_t i = 0; i < commands.size(); i++) { if (commands[i] == cmd) { @@ -413,7 +492,7 @@ size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd) } } - if (cmdIndex != -1) + if ((int)cmdIndex != -1) { if (cmdIndex + 1 < commands.size()) return commands[cmdIndex + 1]->cmdAddress - commands[cmdIndex]->cmdAddress; @@ -443,7 +522,7 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix) { sourceOutput = ""; - //sourceOutput += "#include \n"; + // sourceOutput += "#include \n"; sourceOutput += "#include \"segment_symbols.h\"\n"; sourceOutput += "#include \"command_macros_base.h\"\n"; sourceOutput += "#include \"z64cutscene_commands.h\"\n"; @@ -452,7 +531,7 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix) if (scene != nullptr) sourceOutput += scene->parent->GetHeaderInclude(); - //sourceOutput += "\n"; + // sourceOutput += "\n"; ProcessCommandSets(); @@ -463,21 +542,22 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix) { vector> texturesSorted(textures.begin(), textures.end()); - sort(texturesSorted.begin(), texturesSorted.end(), [](const auto& lhs, const auto& rhs) - { - return lhs.first < rhs.first; - }); + sort(texturesSorted.begin(), texturesSorted.end(), + [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); - for (int i = 0; i < texturesSorted.size() - 1; i++) + for (size_t i = 0; i < texturesSorted.size() - 1; i++) { int texSize = textures[texturesSorted[i].first]->GetRawDataSize(); if ((texturesSorted[i].first + texSize) > texturesSorted[i + 1].first) { - int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + 1].first; + // int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + + // 1].first; - defines += StringHelper::Sprintf("#define %sTex_%06X ((u32)%sTex_%06X + 0x%06X)\n", prefix.c_str(), texturesSorted[i + 1].first, prefix.c_str(), - texturesSorted[i].first, texturesSorted[i + 1].first - texturesSorted[i].first); + defines += StringHelper::Sprintf( + "#define %sTex_%06X ((u32)%sTex_%06X + 0x%06X)\n", prefix.c_str(), + texturesSorted[i + 1].first, prefix.c_str(), texturesSorted[i].first, + texturesSorted[i + 1].first - texturesSorted[i].first); parent->declarations.erase(texturesSorted[i + 1].first); textures.erase(texturesSorted[i + 1].first); @@ -489,7 +569,7 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix) } parent->defines += defines; - //parent->externs[0xFFFFFFFF] = defines; + // parent->externs[0xFFFFFFFF] = defines; } for (pair item : textures) @@ -503,12 +583,16 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix) item.second->Save(Globals::Instance->outputPath); - parent->AddDeclarationIncludeArray(item.first, StringHelper::Sprintf("%s/%s.%s.inc.c", - Globals::Instance->outputPath.c_str(), Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(), item.second->GetExternalExtension().c_str()), item.second->GetRawDataSize(), - "u64", StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first), 0); + parent->AddDeclarationIncludeArray( + item.first, + StringHelper::Sprintf("%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(), + Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(), + item.second->GetExternalExtension().c_str()), + item.second->GetRawDataSize(), "u64", + StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first), 0); } - //sourceOutput += "\n"; + // sourceOutput += "\n"; return sourceOutput; } @@ -545,7 +629,8 @@ void ZRoom::PreGenSourceFiles() cmd->PreGenSourceFiles(); } -Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, string nText) +Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, + uint32_t nSize, string nText) { alignment = nAlignment; padding = nPadding; @@ -564,21 +649,28 @@ Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPa references = vector(); } -Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType, string nVarName, bool nIsArray, string nText) : Declaration(nAlignment, DeclarationPadding::None, nSize, nText) +Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType, + string nVarName, bool nIsArray, string nText) + : Declaration(nAlignment, DeclarationPadding::None, nSize, nText) { varType = nVarType; varName = nVarName; isArray = nIsArray; } -Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, string nVarType, string nVarName, bool nIsArray, string nText) : Declaration(nAlignment, nPadding, nSize, nText) +Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, + uint32_t nSize, string nVarType, string nVarName, bool nIsArray, + string nText) + : Declaration(nAlignment, nPadding, nSize, nText) { varType = nVarType; varName = nVarName; isArray = nIsArray; } -Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType, string nVarName, bool nIsArray, int nArrayItemCnt, string nText) : Declaration(nAlignment, DeclarationPadding::None, nSize, nText) +Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType, + string nVarName, bool nIsArray, int nArrayItemCnt, string nText) + : Declaration(nAlignment, DeclarationPadding::None, nSize, nText) { varType = nVarType; varName = nVarName; @@ -586,7 +678,10 @@ Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string arrayItemCnt = nArrayItemCnt; } -Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, string nVarType, string nVarName, bool nIsArray, int nArrayItemCnt, string nText) : Declaration(nAlignment, nPadding, nSize, nText) +Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, + uint32_t nSize, string nVarType, string nVarName, bool nIsArray, + int nArrayItemCnt, string nText) + : Declaration(nAlignment, nPadding, nSize, nText) { varType = nVarType; varName = nVarName; @@ -594,7 +689,8 @@ Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPa arrayItemCnt = nArrayItemCnt; } -Declaration::Declaration(std::string nIncludePath, uint32_t nSize, string nVarType, string nVarName) : Declaration(DeclarationAlignment::None, DeclarationPadding::None, nSize, "") +Declaration::Declaration(std::string nIncludePath, uint32_t nSize, string nVarType, string nVarName) + : Declaration(DeclarationAlignment::None, DeclarationPadding::None, nSize, "") { includePath = nIncludePath; varType = nVarType; diff --git a/tools/ZAPD/ZAPD/ZRoom/ZRoom.h b/tools/ZAPD/ZAPD/ZRoom/ZRoom.h index 7324248e2d..b0b4a503e3 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoom.h +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoom.h @@ -1,13 +1,13 @@ #pragma once +#include #include "../ZResource.h" #include "ZRoomCommand.h" #include "ZTexture.h" -#include -#include #include #include +#include class ZRoom : public ZResource { @@ -29,7 +29,9 @@ public: std::string extDefines; - static ZRoom* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, std::string nRelPath, ZFile* nParent, ZRoom* nScene); + static ZRoom* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, + int rawDataIndex, std::string nRelPath, ZFile* nParent, + ZRoom* nScene); void ParseCommands(std::vector& commandList, CommandSet commandSet); size_t GetDeclarationSizeFromNeighbor(int declarationAddress); size_t GetCommandSizeFromNeighbor(ZRoomCommand* cmd); @@ -44,7 +46,7 @@ public: struct CommandSet { int32_t address; - int32_t commandCount; // Only used if explicitly specified in the XML + int32_t commandCount; // Only used if explicitly specified in the XML CommandSet(int32_t nAddress); CommandSet(int32_t nAddress, int32_t nCommandCount); diff --git a/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.cpp b/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.cpp index 6b42adec94..8d3baeb728 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.cpp @@ -13,7 +13,8 @@ string ZRoomCommand::GenerateSourceCodePass1(string roomName, int baseAddress) { char line[2048]; - //sprintf(line, "%s _%s_set%04X_cmd%02X = { 0x%02X,", GetCommandCName().c_str(), roomName.c_str(), baseAddress, cmdIndex, cmdID); + // sprintf(line, "%s _%s_set%04X_cmd%02X = { 0x%02X,", GetCommandCName().c_str(), + // roomName.c_str(), baseAddress, cmdIndex, cmdID); sprintf(line, " 0x%02X,", (uint8_t)cmdID); return string(line); diff --git a/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.h b/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.h index c7020ca1ab..3389d9e121 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.h +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.h @@ -2,8 +2,8 @@ #include -#include #include +#include class ZRoom; diff --git a/tools/ZAPD/ZAPD/ZScalar.cpp b/tools/ZAPD/ZAPD/ZScalar.cpp index 10866f1ef4..e523562ee9 100644 --- a/tools/ZAPD/ZAPD/ZScalar.cpp +++ b/tools/ZAPD/ZAPD/ZScalar.cpp @@ -1,11 +1,12 @@ #include "ZScalar.h" -#include "ZFile.h" #include "BitConverter.h" -#include "StringHelper.h" #include "File.h" #include "Globals.h" +#include "StringHelper.h" +#include "ZFile.h" -ZScalar* ZScalar::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath) +ZScalar* ZScalar::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const int rawDataIndex, const std::string& nRelPath) { ZScalar* scalar = new ZScalar(); scalar->rawData = nRawData; @@ -35,7 +36,7 @@ void ZScalar::ParseXML(tinyxml2::XMLElement* reader) scalarType = ZScalar::MapOutputTypeToScalarType(type); } -ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type) +ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type) { if (type == "s8") { @@ -83,7 +84,8 @@ ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type) std::string ZScalar::MapScalarTypeToOutputType(const ZScalarType scalarType) { - switch (scalarType) { + switch (scalarType) + { case ZSCALAR_S8: return "s8"; case ZSCALAR_U8: @@ -111,7 +113,8 @@ std::string ZScalar::MapScalarTypeToOutputType(const ZScalarType scalarType) int ZScalar::MapTypeToSize(const ZScalarType scalarType) { - switch (scalarType) { + switch (scalarType) + { case ZSCALAR_S8: return sizeof(scalarData.s8); case ZSCALAR_U8: @@ -149,7 +152,8 @@ void ZScalar::ParseRawData() void ZScalar::ParseRawData(const std::vector& data, const int offset) { - switch (scalarType) { + switch (scalarType) + { case ZSCALAR_S8: scalarData.s8 = BitConverter::ToInt8BE(data, offset); break; @@ -180,6 +184,10 @@ void ZScalar::ParseRawData(const std::vector& data, const int offset) case ZSCALAR_F64: scalarData.f64 = BitConverter::ToDoubleBE(data, offset); break; + case ZSCALAR_NONE: + fprintf(stderr, "Warning in ZScalar: Invalid type. %d %s %d\n", (int)scalarType, __FILE__, + __LINE__); + break; } } @@ -190,7 +198,8 @@ std::string ZScalar::GetSourceTypeName() std::string ZScalar::GetSourceValue() { - switch (scalarType) { + switch (scalarType) + { case ZSCALAR_S8: return StringHelper::Sprintf("%hhd", scalarData.s8); case ZSCALAR_U8: @@ -219,7 +228,8 @@ std::string ZScalar::GetSourceValue() std::string ZScalar::GetSourceOutputCode(const std::string& prefix) { if (parent != nullptr) - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), GetSourceTypeName(), GetName(), GetSourceValue()); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), + GetSourceTypeName(), GetName(), GetSourceValue()); return ""; } diff --git a/tools/ZAPD/ZAPD/ZScalar.h b/tools/ZAPD/ZAPD/ZScalar.h index 26e6a9d8dc..e5109ca16e 100644 --- a/tools/ZAPD/ZAPD/ZScalar.h +++ b/tools/ZAPD/ZAPD/ZScalar.h @@ -1,12 +1,13 @@ #pragma once -#include -#include #include +#include +#include #include "ZResource.h" #include "tinyxml2.h" -typedef enum ZScalarType { +typedef enum ZScalarType +{ ZSCALAR_NONE, ZSCALAR_S8, ZSCALAR_U8, @@ -20,7 +21,8 @@ typedef enum ZScalarType { ZSCALAR_F64 } ZScalarType; -typedef union ZScalarData { +typedef union ZScalarData +{ uint8_t u8; int8_t s8; uint16_t u16; @@ -35,7 +37,8 @@ typedef union ZScalarData { class ZScalar : public ZResource { -friend class ZVector; + friend class ZVector; + public: ZScalarData scalarData; ZScalarType scalarType; @@ -52,7 +55,9 @@ public: bool DoesSupportArray() override; void ParseRawData() override; - static ZScalar* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath); + static ZScalar* ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, const int rawDataIndex, + const std::string& nRelPath); static int MapTypeToSize(const ZScalarType scalarType); static ZScalarType MapOutputTypeToScalarType(const std::string& type); static std::string MapScalarTypeToOutputType(const ZScalarType scalarType); diff --git a/tools/ZAPD/ZAPD/ZSkeleton.cpp b/tools/ZAPD/ZAPD/ZSkeleton.cpp index 37d9f46ff1..e100e2333a 100644 --- a/tools/ZAPD/ZAPD/ZSkeleton.cpp +++ b/tools/ZAPD/ZAPD/ZSkeleton.cpp @@ -1,12 +1,12 @@ #include "ZSkeleton.h" #include "BitConverter.h" -#include "StringHelper.h" #include "HighLevel/HLModelIntermediette.h" +#include "StringHelper.h" using namespace std; - -ZSkeleton::ZSkeleton(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, ZFile* nParent) +ZSkeleton::ZSkeleton(tinyxml2::XMLElement* reader, const std::vector& nRawData, + int nRawDataIndex, ZFile* nParent) { rawData.assign(nRawData.begin(), nRawData.end()); rawDataIndex = nRawDataIndex; @@ -16,14 +16,44 @@ ZSkeleton::ZSkeleton(tinyxml2::XMLElement* reader, const std::vector& n ParseRawData(); string defaultPrefix = name; - defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables + defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress); - for (size_t i = 0; i < limbCount; i++) { + for (size_t i = 0; i < limbCount; i++) + { uint32_t ptr2 = Seg2Filespace(BitConverter::ToUInt32BE(rawData, ptr), parent->baseAddress); ZLimb* limb = new ZLimb(reader, rawData, ptr2, parent); - limb->SetName(StringHelper::Sprintf("%sLimb_%06X", defaultPrefix.c_str(), limb->GetFileAddress())); + limb->SetName( + StringHelper::Sprintf("%sLimb_%06X", defaultPrefix.c_str(), limb->GetFileAddress())); + limbs.push_back(limb); + + ptr += 4; + } +} + +ZSkeleton::ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix, + const std::vector& nRawData, int nRawDataIndex, ZFile* nParent) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + parent = nParent; + + name = StringHelper::Sprintf("%sSkel_%06X", prefix.c_str(), rawDataIndex); + type = nType; + limbType = nLimbType; + + ParseRawData(); + + string defaultPrefix = name; + defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables + uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress); + + for (size_t i = 0; i < limbCount; i++) + { + uint32_t ptr2 = Seg2Filespace(BitConverter::ToUInt32BE(rawData, ptr), parent->baseAddress); + + ZLimb* limb = new ZLimb(limbType, prefix, rawData, ptr2, parent); limbs.push_back(limb); ptr += 4; @@ -32,7 +62,8 @@ ZSkeleton::ZSkeleton(tinyxml2::XMLElement* reader, const std::vector& n ZSkeleton::~ZSkeleton() { - for (auto& limb: limbs) { + for (auto& limb : limbs) + { delete limb; } } @@ -42,39 +73,69 @@ void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) ZResource::ParseXML(reader); const char* skelTypeXml = reader->Attribute("Type"); - if (skelTypeXml == nullptr) { - fprintf(stderr, "ZSkeleton::ParseXML: Warning in '%s'.\n\t Type not found found. Defaulting to 'Normal'.\n", name.c_str()); + if (skelTypeXml == nullptr) + { + fprintf(stderr, + "ZSkeleton::ParseXML: Warning in '%s'.\n\t Type not found found. Defaulting to " + "'Normal'.\n", + name.c_str()); type = ZSkeletonType::Normal; } - else { + else + { string skelTypeStr(skelTypeXml); - if (skelTypeStr == "Flex") { + if (skelTypeStr == "Flex") + { type = ZSkeletonType::Flex; } - else if (skelTypeStr != "Normal") { - fprintf(stderr, "ZSkeleton::ParseXML: Warning in '%s'.\n\t Invalid Type found: '%s'. Defaulting to 'Normal'.\n", name.c_str(), skelTypeXml); + else if (skelTypeStr == "Curve") + { + type = ZSkeletonType::Curve; + } + else if (skelTypeStr != "Normal" && skelTypeStr != "Standard") + { + fprintf(stderr, + "ZSkeleton::ParseXML: Warning in '%s'.\n\t Invalid Type found: '%s'. " + "Defaulting to 'Normal'.\n", + name.c_str(), skelTypeXml); type = ZSkeletonType::Normal; } } const char* limbTypeXml = reader->Attribute("LimbType"); - if (limbTypeXml == nullptr) { - fprintf(stderr, "ZSkeleton::ParseXML: Warning in '%s'.\n\t LimbType not found found. Defaulting to 'Standard'.\n", name.c_str()); + if (limbTypeXml == nullptr) + { + fprintf(stderr, + "ZSkeleton::ParseXML: Warning in '%s'.\n\t LimbType not found found. Defaulting to " + "'Standard'.\n", + name.c_str()); limbType = ZLimbType::Standard; } - else { + else + { string limbTypeStr(limbTypeXml); - if (limbTypeStr == "Standard") { + if (limbTypeStr == "Standard") + { limbType = ZLimbType::Standard; } - else if (limbTypeStr == "LOD") { + else if (limbTypeStr == "LOD") + { limbType = ZLimbType::LOD; } - else if (limbTypeStr == "Skin") { + else if (limbTypeStr == "Skin") + { limbType = ZLimbType::Skin; } - else { - fprintf(stderr, "ZSkeleton::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. Defaulting to 'Standard'.\n", name.c_str(), limbTypeXml); + else if (limbTypeStr == "Curve") + { + limbType = ZLimbType::Curve; + } + else + { + fprintf(stderr, + "ZSkeleton::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. " + "Defaulting to 'Standard'.\n", + name.c_str(), limbTypeXml); limbType = ZLimbType::Standard; } } @@ -89,14 +150,15 @@ void ZSkeleton::ParseRawData() dListCount = BitConverter::ToUInt8BE(rawData, rawDataIndex + 8); } -ZSkeleton* ZSkeleton::FromXML(tinyxml2::XMLElement* reader, vector nRawData, int rawDataIndex, string nRelPath, ZFile* nParent) +ZSkeleton* ZSkeleton::FromXML(tinyxml2::XMLElement* reader, vector nRawData, + int rawDataIndex, string nRelPath, ZFile* nParent) { ZSkeleton* skeleton = new ZSkeleton(reader, nRawData, rawDataIndex, nParent); skeleton->relativePath = std::move(nRelPath); - skeleton->parent->AddDeclaration( - skeleton->rawDataIndex, DeclarationAlignment::Align16, skeleton->GetRawDataSize(), - skeleton->GetSourceTypeName(), skeleton->name, ""); + skeleton->parent->AddDeclaration(skeleton->rawDataIndex, DeclarationAlignment::Align16, + skeleton->GetRawDataSize(), skeleton->GetSourceTypeName(), + skeleton->name, ""); return skeleton; } @@ -109,16 +171,17 @@ void ZSkeleton::GenerateHLIntermediette(HLFileIntermediette& hlFile) { HLModelIntermediette* mdl = (HLModelIntermediette*)&hlFile; HLModelIntermediette::FromZSkeleton(mdl, this); - //mdl->blocks.push_back(new HLTerminator()); + // mdl->blocks.push_back(new HLTerminator()); } int ZSkeleton::GetRawDataSize() { - switch (type) { - case ZSkeletonType::Normal: - return 0x8; + switch (type) + { case ZSkeletonType::Flex: return 0xC; + case ZSkeletonType::Normal: + case ZSkeletonType::Curve: default: return 0x8; } @@ -126,14 +189,16 @@ int ZSkeleton::GetRawDataSize() std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix) { - if (parent == nullptr) { + if (parent == nullptr) + { return ""; } string defaultPrefix = name.c_str(); - defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables + defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables - for (auto& limb: limbs) { + for (auto& limb : limbs) + { limb->GetSourceOutputCode(defaultPrefix); } @@ -147,35 +212,42 @@ std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix) { ZLimb* limb = limbs.at(i); - string decl = StringHelper::Sprintf(" &%s,", parent->GetDeclarationName(limb->GetFileAddress()).c_str()); - if (i != (limbs.size() - 1)) { + string decl = StringHelper::Sprintf( + " &%s,", parent->GetDeclarationName(limb->GetFileAddress()).c_str()); + if (i != (limbs.size() - 1)) + { decl += "\n"; } tblStr += decl; } - parent->AddDeclarationArray(ptr, DeclarationAlignment::None, 4 * limbCount, - StringHelper::Sprintf("static %s*", ZLimb::GetSourceTypeName(limbType)), - StringHelper::Sprintf("%sLimbs", defaultPrefix.c_str()), limbCount, tblStr); + parent->AddDeclarationArray(ptr, DeclarationAlignment::None, 4 * limbCount, "static void*", + StringHelper::Sprintf("%sLimbs", defaultPrefix.c_str()), + limbCount, tblStr); } string headerStr; - switch (type) { + switch (type) + { case ZSkeletonType::Normal: + case ZSkeletonType::Curve: headerStr = StringHelper::Sprintf("%sLimbs, %i", defaultPrefix.c_str(), limbCount); break; case ZSkeletonType::Flex: - headerStr = StringHelper::Sprintf("%sLimbs, %i, %i", defaultPrefix.c_str(), limbCount, dListCount); + headerStr = + StringHelper::Sprintf("%sLimbs, %i, %i", defaultPrefix.c_str(), limbCount, dListCount); break; } Declaration* decl = parent->GetDeclaration(GetAddress()); - if (decl == nullptr) { - parent->AddDeclaration(GetAddress(), DeclarationAlignment::Align16, - GetRawDataSize(), GetSourceTypeName(), name, headerStr); + if (decl == nullptr) + { + parent->AddDeclaration(GetAddress(), DeclarationAlignment::Align16, GetRawDataSize(), + GetSourceTypeName(), name, headerStr); } - else { + else + { decl->text = headerStr; } @@ -184,11 +256,14 @@ std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix) std::string ZSkeleton::GetSourceTypeName() { - switch (type) { + switch (type) + { case ZSkeletonType::Normal: return "SkeletonHeader"; case ZSkeletonType::Flex: return "FlexSkeletonHeader"; + case ZSkeletonType::Curve: + return "SkelCurveLimbList"; } return "SkeletonHeader"; } @@ -202,3 +277,8 @@ segptr_t ZSkeleton::GetAddress() { return rawDataIndex; } + +uint8_t ZSkeleton::GetLimbCount() +{ + return limbCount; +} diff --git a/tools/ZAPD/ZAPD/ZSkeleton.h b/tools/ZAPD/ZAPD/ZSkeleton.h index 2cafd56ceb..06ad628412 100644 --- a/tools/ZAPD/ZAPD/ZSkeleton.h +++ b/tools/ZAPD/ZAPD/ZSkeleton.h @@ -1,16 +1,17 @@ #pragma once -#include -#include #include -#include "ZFile.h" +#include +#include #include "ZDisplayList.h" +#include "ZFile.h" #include "ZLimb.h" enum ZSkeletonType { Normal, - Flex + Flex, + Curve, }; class ZSkeleton : public ZResource @@ -21,13 +22,18 @@ public: std::vector limbs; segptr_t limbsArrayAddress; uint8_t limbCount; - uint8_t dListCount; // FLEX SKELETON ONLY + uint8_t dListCount; // FLEX SKELETON ONLY - ZSkeleton(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, ZFile* nParent); + ZSkeleton() = default; + ZSkeleton(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, + ZFile* nParent); + ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix, + const std::vector& nRawData, int nRawDataIndex, ZFile* nParent); ~ZSkeleton(); void ParseXML(tinyxml2::XMLElement* reader) override; void ParseRawData() override; - static ZSkeleton* FromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, std::string nRelPath, ZFile* nParent); + static ZSkeleton* FromXML(tinyxml2::XMLElement* reader, std::vector nRawData, + int rawDataIndex, std::string nRelPath, ZFile* nParent); void Save(const std::string& outFolder) override; void GenerateHLIntermediette(HLFileIntermediette& hlFile) override; @@ -38,4 +44,5 @@ public: ZResourceType GetResourceType() override; segptr_t GetAddress(); + uint8_t GetLimbCount(); }; diff --git a/tools/ZAPD/ZAPD/ZSymbol.cpp b/tools/ZAPD/ZAPD/ZSymbol.cpp new file mode 100644 index 0000000000..44613c545a --- /dev/null +++ b/tools/ZAPD/ZAPD/ZSymbol.cpp @@ -0,0 +1,105 @@ +#include "ZSymbol.h" +#include "StringHelper.h" + +ZSymbol::ZSymbol(const std::string& nName, int nRawDataIndex, const std::string& nType, + uint32_t nTypeSize, bool nIsArray, uint32_t nCount) + : type(nType), typeSize(nTypeSize), isArray(nIsArray), count(nCount) +{ + name = nName; + rawDataIndex = nRawDataIndex; +} + +ZSymbol::ZSymbol(tinyxml2::XMLElement* reader, const std::vector& nRawData, + int nRawDataIndex, ZFile* nParent) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + parent = nParent; + + ParseXML(reader); +} + +ZSymbol* ZSymbol::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + int nRawDataIndex, ZFile* parent) +{ + ZSymbol* symbol = new ZSymbol(reader, nRawData, nRawDataIndex, parent); + + return symbol; +} + +void ZSymbol::ParseXML(tinyxml2::XMLElement* reader) +{ + ZResource::ParseXML(reader); + + const char* typeXml = reader->Attribute("Type"); + if (typeXml == nullptr) + { + fprintf(stderr, + "ZSymbol::ParseXML: Warning in '%s'.\n\t Missing 'Type' attribute in xml. " + "Defaulting to 'void*'.\n", + name.c_str()); + type = "void*"; + } + else + { + type = std::string(typeXml); + } + + const char* typeSizeXml = reader->Attribute("TypeSize"); + if (typeSizeXml == nullptr) + { + fprintf(stderr, + "ZSymbol::ParseXML: Warning in '%s'.\n\t Missing 'TypeSize' attribute in xml. " + "Defaulting to '4'.\n", + name.c_str()); + typeSize = 4; // Size of a word. + } + else + { + typeSize = std::strtoul(typeSizeXml, nullptr, 0); + } + + const char* countXml = reader->Attribute("Count"); + if (countXml != nullptr) + { + isArray = true; + if (!std::string(countXml).empty()) + { + count = std::strtoul(countXml, nullptr, 0); + } + } +} + +int ZSymbol::GetRawDataSize() +{ + if (isArray) + { + return count * typeSize; + } + return typeSize; +} + +std::string ZSymbol::GetSourceOutputHeader(const std::string& prefix) +{ + if (isArray) + { + if (count == 0) + { + return StringHelper::Sprintf("extern %s %s%s[];\n", type.c_str(), prefix.c_str(), + name.c_str()); + } + return StringHelper::Sprintf("extern %s %s%s[%i];\n", type.c_str(), prefix.c_str(), + name.c_str(), count); + } + return StringHelper::Sprintf("extern %s %s%s;\n", type.c_str(), prefix.c_str(), name.c_str()); +} + +std::string ZSymbol::GetSourceTypeName() +{ + return type; +} + +ZResourceType ZSymbol::GetResourceType() +{ + return ZResourceType::Symbol; +} diff --git a/tools/ZAPD/ZAPD/ZSymbol.h b/tools/ZAPD/ZAPD/ZSymbol.h new file mode 100644 index 0000000000..4513f8ff30 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZSymbol.h @@ -0,0 +1,33 @@ +#pragma once + +#include "ZResource.h" +#include "tinyxml2.h" + +class ZSymbol : public ZResource +{ +protected: + std::string type; + uint32_t typeSize; + bool isArray = false; + uint32_t count = 0; + +public: + ZSymbol() = default; + ZSymbol(const std::string& nName, int nRawDataIndex, const std::string& nType, + uint32_t nTypeSize, bool nIsArray, uint32_t nCount); + ZSymbol(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, + ZFile* nParent); + + static ZSymbol* ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, int nRawDataIndex, + ZFile* parent); + + void ParseXML(tinyxml2::XMLElement* reader) override; + + int GetRawDataSize() override; + + std::string GetSourceOutputHeader(const std::string& prefix) override; + + std::string GetSourceTypeName() override; + ZResourceType GetResourceType() override; +}; diff --git a/tools/ZAPD/ZAPD/ZTexture.cpp b/tools/ZAPD/ZAPD/ZTexture.cpp index 21d01df79a..ab2ee55461 100644 --- a/tools/ZAPD/ZAPD/ZTexture.cpp +++ b/tools/ZAPD/ZAPD/ZTexture.cpp @@ -3,10 +3,10 @@ #define TINYGLTF_IMPLEMENTATION #include "ZTexture.h" -#include "StringHelper.h" #include "BitConverter.h" -#include "Path.h" #include "File.h" +#include "Path.h" +#include "StringHelper.h" #include "stb_image.h" #include "stb_image_write.h" @@ -44,13 +44,15 @@ ZTexture::~ZTexture() } // EXTRACT MODE -ZTexture* ZTexture::ExtractFromXML(XMLElement* reader, vector nRawData, int nRawDataIndex, string nRelPath) +ZTexture* ZTexture::ExtractFromXML(XMLElement* reader, vector nRawData, int nRawDataIndex, + string nRelPath) { ZTexture* tex = new ZTexture(); tex->ParseXML(reader); tex->rawDataIndex = nRawDataIndex; - tex->rawData = vector(nRawData.data() + tex->rawDataIndex, nRawData.data() + tex->rawDataIndex + tex->GetRawDataSize()); + tex->rawData = vector(nRawData.data() + tex->rawDataIndex, + nRawData.data() + tex->rawDataIndex + tex->GetRawDataSize()); tex->relativePath = nRelPath; @@ -60,7 +62,8 @@ ZTexture* ZTexture::ExtractFromXML(XMLElement* reader, vector nRawData, return tex; } -ZTexture* ZTexture::FromBinary(TextureType nType, std::vector nRawData, int nRawDataIndex, std::string nName, int nWidth, int nHeight) +ZTexture* ZTexture::FromBinary(TextureType nType, std::vector nRawData, int nRawDataIndex, + std::string nName, int nWidth, int nHeight) { ZTexture* tex = new ZTexture(); @@ -99,23 +102,44 @@ ZTexture* ZTexture::FromPNG(string pngFilePath, TextureType texType) ZTexture* tex = new ZTexture(); tex->type = texType; tex->name = StringHelper::Split(Path::GetFileNameWithoutExtension(pngFilePath), ".")[0]; - - tex->bmpRgb = (uint8_t*)stbi_load((pngFilePath).c_str(), &tex->width, &tex->height, &comp, STBI_rgb); + + tex->bmpRgb = + (uint8_t*)stbi_load((pngFilePath).c_str(), &tex->width, &tex->height, &comp, STBI_rgb); stbi_image_free(tex->bmpRgb); tex->bmpRgb = nullptr; tex->rawData = vector(tex->GetRawDataSize()); switch (texType) { - case TextureType::RGBA16bpp: tex->PrepareRawDataRGBA16(pngFilePath); break; - case TextureType::RGBA32bpp: tex->PrepareRawDataRGBA32(pngFilePath); break; - case TextureType::Grayscale4bpp: tex->PrepareRawDataGrayscale4(pngFilePath); break; - case TextureType::Grayscale8bpp: tex->PrepareRawDataGrayscale8(pngFilePath); break; - case TextureType::GrayscaleAlpha4bpp: tex->PrepareRawDataGrayscaleAlpha4(pngFilePath); break; - case TextureType::GrayscaleAlpha8bpp: tex->PrepareRawDataGrayscaleAlpha8(pngFilePath); break; - case TextureType::GrayscaleAlpha16bpp: tex->PrepareRawDataGrayscaleAlpha16(pngFilePath); break; - case TextureType::Palette4bpp: tex->PrepareRawDataPalette4(pngFilePath); break; - case TextureType::Palette8bpp: tex->PrepareRawDataPalette8(pngFilePath); break; + case TextureType::RGBA16bpp: + tex->PrepareRawDataRGBA16(pngFilePath); + break; + case TextureType::RGBA32bpp: + tex->PrepareRawDataRGBA32(pngFilePath); + break; + case TextureType::Grayscale4bpp: + tex->PrepareRawDataGrayscale4(pngFilePath); + break; + case TextureType::Grayscale8bpp: + tex->PrepareRawDataGrayscale8(pngFilePath); + break; + case TextureType::GrayscaleAlpha4bpp: + tex->PrepareRawDataGrayscaleAlpha4(pngFilePath); + break; + case TextureType::GrayscaleAlpha8bpp: + tex->PrepareRawDataGrayscaleAlpha8(pngFilePath); + break; + case TextureType::GrayscaleAlpha16bpp: + tex->PrepareRawDataGrayscaleAlpha16(pngFilePath); + break; + case TextureType::Palette4bpp: + tex->PrepareRawDataPalette4(pngFilePath); + break; + case TextureType::Palette8bpp: + tex->PrepareRawDataPalette8(pngFilePath); + break; + default: + throw std::runtime_error("Format is not supported!"); } tex->FixRawData(); @@ -149,23 +173,23 @@ void ZTexture::ParseXML(XMLElement* reader) type = GetTextureTypeFromString(formatStr); if (type == TextureType::Error) - throw "Format " + formatStr + " is not supported!"; + throw std::runtime_error("Format " + formatStr + " is not supported!"); } void ZTexture::FixRawData() { if (type == TextureType::RGBA32bpp) { - for (int i = 0; i < rawData.size(); i += 4) + for (size_t i = 0; i < rawData.size(); i += 4) { uint8_t tmp = rawData[i]; rawData[i] = rawData[i + 2]; rawData[i + 2] = tmp; } } - else if (type == TextureType::RGBA16bpp)// || type == TextureType::GrayscaleAlpha16bpp) + else if (type == TextureType::RGBA16bpp) // || type == TextureType::GrayscaleAlpha16bpp) { - for (int i = 0; i < rawData.size(); i += 2) + for (size_t i = 0; i < rawData.size(); i += 2) { uint8_t tmp = rawData[i]; rawData[i] = rawData[i + 1]; @@ -181,15 +205,35 @@ void ZTexture::PrepareBitmap() switch (type) { - case TextureType::RGBA16bpp: PrepareBitmapRGBA16(); break; - case TextureType::RGBA32bpp: PrepareBitmapRGBA32(); break; - case TextureType::Grayscale4bpp: PrepareBitmapGrayscale4(); break; - case TextureType::Grayscale8bpp: PrepareBitmapGrayscale8(); break; - case TextureType::GrayscaleAlpha4bpp: PrepareBitmapGrayscaleAlpha4(); break; - case TextureType::GrayscaleAlpha8bpp: PrepareBitmapGrayscaleAlpha8(); break; - case TextureType::GrayscaleAlpha16bpp: PrepareBitmapGrayscaleAlpha16(); break; - case TextureType::Palette4bpp: PrepareBitmapPalette4(); break; - case TextureType::Palette8bpp: PrepareBitmapPalette8(); break; + case TextureType::RGBA16bpp: + PrepareBitmapRGBA16(); + break; + case TextureType::RGBA32bpp: + PrepareBitmapRGBA32(); + break; + case TextureType::Grayscale4bpp: + PrepareBitmapGrayscale4(); + break; + case TextureType::Grayscale8bpp: + PrepareBitmapGrayscale8(); + break; + case TextureType::GrayscaleAlpha4bpp: + PrepareBitmapGrayscaleAlpha4(); + break; + case TextureType::GrayscaleAlpha8bpp: + PrepareBitmapGrayscaleAlpha8(); + break; + case TextureType::GrayscaleAlpha16bpp: + PrepareBitmapGrayscaleAlpha16(); + break; + case TextureType::Palette4bpp: + PrepareBitmapPalette4(); + break; + case TextureType::Palette8bpp: + PrepareBitmapPalette8(); + break; + default: + throw std::runtime_error("Format is not supported!"); } } @@ -378,17 +422,35 @@ void ZTexture::PrepareRawData(string inFolder) switch (type) { - case TextureType::RGBA16bpp: PrepareRawDataRGBA16(inFolder + "/" + outName + ".rgba5a1.png"); break; - case TextureType::RGBA32bpp: PrepareRawDataRGBA32(inFolder + "/" + outName + ".rgba32.png"); break; - case TextureType::Grayscale4bpp: PrepareRawDataGrayscale4(inFolder + "/" + outName + ".i4.png"); break; - case TextureType::Grayscale8bpp: PrepareRawDataGrayscale8(inFolder + "/" + outName + ".i8.png"); break; - case TextureType::GrayscaleAlpha4bpp: PrepareRawDataGrayscaleAlpha4(inFolder + "/" + outName + ".ia4.png"); break; - case TextureType::GrayscaleAlpha8bpp: PrepareRawDataGrayscaleAlpha8(inFolder + "/" + outName + ".ia8.png"); break; - case TextureType::GrayscaleAlpha16bpp: PrepareRawDataGrayscaleAlpha16(inFolder + "/" + outName + ".ia16.png"); break; - case TextureType::Palette4bpp: PrepareRawDataPalette4(inFolder + "/" + outName + ".ci4.png"); break; - case TextureType::Palette8bpp: PrepareRawDataPalette8(inFolder + "/" + outName + ".ci8.png"); break; + case TextureType::RGBA16bpp: + PrepareRawDataRGBA16(inFolder + "/" + outName + ".rgba5a1.png"); + break; + case TextureType::RGBA32bpp: + PrepareRawDataRGBA32(inFolder + "/" + outName + ".rgba32.png"); + break; + case TextureType::Grayscale4bpp: + PrepareRawDataGrayscale4(inFolder + "/" + outName + ".i4.png"); + break; + case TextureType::Grayscale8bpp: + PrepareRawDataGrayscale8(inFolder + "/" + outName + ".i8.png"); + break; + case TextureType::GrayscaleAlpha4bpp: + PrepareRawDataGrayscaleAlpha4(inFolder + "/" + outName + ".ia4.png"); + break; + case TextureType::GrayscaleAlpha8bpp: + PrepareRawDataGrayscaleAlpha8(inFolder + "/" + outName + ".ia8.png"); + break; + case TextureType::GrayscaleAlpha16bpp: + PrepareRawDataGrayscaleAlpha16(inFolder + "/" + outName + ".ia16.png"); + break; + case TextureType::Palette4bpp: + PrepareRawDataPalette4(inFolder + "/" + outName + ".ci4.png"); + break; + case TextureType::Palette8bpp: + PrepareRawDataPalette8(inFolder + "/" + outName + ".ci8.png"); + break; default: - throw "Build Mode: Format is not supported!"; + throw std::runtime_error("Build Mode: Format is not supported!"); } } @@ -603,13 +665,22 @@ float ZTexture::GetPixelMultiplyer() { switch (type) { - case TextureType::Grayscale4bpp: case TextureType::GrayscaleAlpha4bpp: case TextureType::Palette4bpp: return 0.5f; - case TextureType::Grayscale8bpp: case TextureType::GrayscaleAlpha8bpp: case TextureType::Palette8bpp: return 1; - case TextureType::GrayscaleAlpha16bpp: case TextureType::RGBA16bpp: return 2; - case TextureType::RGBA32bpp: return 4; + case TextureType::Grayscale4bpp: + case TextureType::GrayscaleAlpha4bpp: + case TextureType::Palette4bpp: + return 0.5f; + case TextureType::Grayscale8bpp: + case TextureType::GrayscaleAlpha8bpp: + case TextureType::Palette8bpp: + return 1; + case TextureType::GrayscaleAlpha16bpp: + case TextureType::RGBA16bpp: + return 2; + case TextureType::RGBA32bpp: + return 4; + default: + return -1; } - - return -1; } vector ZTexture::GetRawData() @@ -626,26 +697,43 @@ std::string ZTexture::GetIMFmtFromType() { switch (type) { - case TextureType::RGBA32bpp: case TextureType::RGBA16bpp: return "G_IM_FMT_RGBA"; - case TextureType::Grayscale4bpp: case TextureType::Grayscale8bpp: return "G_IM_FMT_I"; - case TextureType::Palette4bpp: case TextureType::Palette8bpp: return "G_IM_FMT_CI"; - case TextureType::GrayscaleAlpha4bpp: case TextureType::GrayscaleAlpha8bpp: case TextureType::GrayscaleAlpha16bpp: return "G_IM_FMT_IA"; + case TextureType::RGBA32bpp: + case TextureType::RGBA16bpp: + return "G_IM_FMT_RGBA"; + case TextureType::Grayscale4bpp: + case TextureType::Grayscale8bpp: + return "G_IM_FMT_I"; + case TextureType::Palette4bpp: + case TextureType::Palette8bpp: + return "G_IM_FMT_CI"; + case TextureType::GrayscaleAlpha4bpp: + case TextureType::GrayscaleAlpha8bpp: + case TextureType::GrayscaleAlpha16bpp: + return "G_IM_FMT_IA"; + default: + return "ERROR"; } - - return "ERROR"; } std::string ZTexture::GetIMSizFromType() { switch (type) { - case TextureType::Grayscale4bpp: case TextureType::Palette4bpp: case TextureType::GrayscaleAlpha4bpp: return "G_IM_SIZ_4b"; - case TextureType::Palette8bpp: case TextureType::Grayscale8bpp: return "G_IM_SIZ_8b"; - case TextureType::GrayscaleAlpha16bpp: case TextureType::RGBA16bpp: return "G_IM_SIZ_16b"; - case TextureType::RGBA32bpp: return "G_IM_SIZ_32b"; + case TextureType::Grayscale4bpp: + case TextureType::Palette4bpp: + case TextureType::GrayscaleAlpha4bpp: + return "G_IM_SIZ_4b"; + case TextureType::Palette8bpp: + case TextureType::Grayscale8bpp: + return "G_IM_SIZ_8b"; + case TextureType::GrayscaleAlpha16bpp: + case TextureType::RGBA16bpp: + return "G_IM_SIZ_16b"; + case TextureType::RGBA32bpp: + return "G_IM_SIZ_32b"; + default: + return "ERROR"; } - - return "ERROR"; } int ZTexture::GetWidth() @@ -676,26 +764,35 @@ TextureType ZTexture::GetTextureType() void ZTexture::Save(const std::string& outFolder) { if (type == TextureType::RGBA32bpp) - stbi_write_png((outFolder + "/" + outName + ".rgba32.png").c_str(), width, height, 4, bmpRgba, width * 4); + stbi_write_png((outFolder + "/" + outName + ".rgba32.png").c_str(), width, height, 4, + bmpRgba, width * 4); else if (type == TextureType::RGBA16bpp) - stbi_write_png((outFolder + "/" + outName + ".rgb5a1.png").c_str(), width, height, 4, bmpRgba, width * 4); + stbi_write_png((outFolder + "/" + outName + ".rgb5a1.png").c_str(), width, height, 4, + bmpRgba, width * 4); else if (type == TextureType::Grayscale8bpp) - stbi_write_png((outFolder + "/" + outName + ".i8.png").c_str(), width, height, 3, bmpRgb, width * 3); + stbi_write_png((outFolder + "/" + outName + ".i8.png").c_str(), width, height, 3, bmpRgb, + width * 3); else if (type == TextureType::Grayscale4bpp) - stbi_write_png((outFolder + "/" + outName + ".i4.png").c_str(), width, height, 3, bmpRgb, width * 3); + stbi_write_png((outFolder + "/" + outName + ".i4.png").c_str(), width, height, 3, bmpRgb, + width * 3); else if (type == TextureType::GrayscaleAlpha16bpp) - stbi_write_png((outFolder + "/" + outName + ".ia16.png").c_str(), width, height, 4, bmpRgba, width * 4); + stbi_write_png((outFolder + "/" + outName + ".ia16.png").c_str(), width, height, 4, bmpRgba, + width * 4); else if (type == TextureType::GrayscaleAlpha8bpp) - stbi_write_png((outFolder + "/" + outName + ".ia8.png").c_str(), width, height, 4, bmpRgba, width * 4); + stbi_write_png((outFolder + "/" + outName + ".ia8.png").c_str(), width, height, 4, bmpRgba, + width * 4); else if (type == TextureType::GrayscaleAlpha4bpp) - stbi_write_png((outFolder + "/" + outName + ".ia4.png").c_str(), width, height, 4, bmpRgba, width * 4); + stbi_write_png((outFolder + "/" + outName + ".ia4.png").c_str(), width, height, 4, bmpRgba, + width * 4); else if (type == TextureType::Palette4bpp) - stbi_write_png((outFolder + "/" + outName + ".ci4.png").c_str(), width, height, 3, bmpRgb, width * 3); + stbi_write_png((outFolder + "/" + outName + ".ci4.png").c_str(), width, height, 3, bmpRgb, + width * 3); else if (type == TextureType::Palette8bpp) - stbi_write_png((outFolder + "/" + outName + ".ci8.png").c_str(), width, height, 3, bmpRgb, width * 3); + stbi_write_png((outFolder + "/" + outName + ".ci8.png").c_str(), width, height, 3, bmpRgb, + width * 3); - //if (outName != name && outName != "") - //File::WriteAllText(outFolder + "/" + outName + ".cfg", name.c_str()); + // if (outName != name && outName != "") + // File::WriteAllText(outFolder + "/" + outName + ".cfg", name.c_str()); } // HOTSPOT @@ -703,29 +800,33 @@ string ZTexture::GetSourceOutputCode(const std::string& prefix) { sourceOutput = ""; - //sprintf(line, "%s:\n", name.c_str()); - //sourceOutput += line; + // sprintf(line, "%s:\n", name.c_str()); + // sourceOutput += line; // TODO: TEMP relativePath = "build/assets/" + relativePath; FixRawData(); - //sourceOutput += StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str()); + // sourceOutput += StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str()); uint8_t* rawDataArr = rawData.data(); - for (int i = 0; i < rawData.size(); i += 8) + for (size_t i = 0; i < rawData.size(); i += 8) { if (i % 32 == 0) sourceOutput += "\t"; - sourceOutput += StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(rawDataArr, i)); + sourceOutput += + StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(rawDataArr, i)); if (i % 32 == 24) sourceOutput += StringHelper::Sprintf(" // 0x%06X \n", rawDataIndex + ((i / 32) * 32)); } - //sourceOutput += "};\n"; + // Ensure there's always a trailing line feed to prevent dumb warnings. + sourceOutput += "\n"; + + // sourceOutput += "};\n"; return sourceOutput; } @@ -749,24 +850,32 @@ std::string ZTexture::GetExternalExtension() { switch (type) { - case TextureType::RGBA32bpp: return "rgba32"; - case TextureType::RGBA16bpp: return "rgb5a1"; - case TextureType::Grayscale4bpp: return "i4"; - case TextureType::Grayscale8bpp: return "i8"; - case TextureType::GrayscaleAlpha4bpp: return "ia4"; - case TextureType::GrayscaleAlpha8bpp: return "ia8"; - case TextureType::GrayscaleAlpha16bpp: return "ia16"; - case TextureType::Palette4bpp: return "ci4"; - case TextureType::Palette8bpp: return "ci8"; + case TextureType::RGBA32bpp: + return "rgba32"; + case TextureType::RGBA16bpp: + return "rgb5a1"; + case TextureType::Grayscale4bpp: + return "i4"; + case TextureType::Grayscale8bpp: + return "i8"; + case TextureType::GrayscaleAlpha4bpp: + return "ia4"; + case TextureType::GrayscaleAlpha8bpp: + return "ia8"; + case TextureType::GrayscaleAlpha16bpp: + return "ia16"; + case TextureType::Palette4bpp: + return "ci4"; + case TextureType::Palette8bpp: + return "ci8"; + default: + return "ERROR"; } - - return ""; } - string ZTexture::GetSourceOutputHeader(const std::string& prefix) { - //return StringHelper::Sprintf("extern u64 %s[];\n", name.c_str()); + // return StringHelper::Sprintf("extern u64 %s[];\n", name.c_str()); return ""; } @@ -792,7 +901,7 @@ TextureType ZTexture::GetTextureTypeFromString(string str) texType = TextureType::Palette4bpp; else if (str == "ci8") texType = TextureType::Palette8bpp; - else - printf("Encountered Unknown Texture Type %s \n",str.c_str()); + else + fprintf(stderr, "Encountered Unknown Texture Type %s \n", str.c_str()); return texType; } diff --git a/tools/ZAPD/ZAPD/ZTexture.h b/tools/ZAPD/ZAPD/ZTexture.h index faf7d68fdc..3b66d083be 100644 --- a/tools/ZAPD/ZAPD/ZTexture.h +++ b/tools/ZAPD/ZAPD/ZTexture.h @@ -1,7 +1,7 @@ #pragma once -#include "ZResource.h" #include "HighLevel/HLTexture.h" +#include "ZResource.h" #include "tinyxml2.h" #include @@ -62,9 +62,12 @@ public: bool isPalette; - static ZTexture* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, bool readFile); - static ZTexture* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, std::string nRelPath); - static ZTexture* FromBinary(TextureType nType, std::vector nRawData, int rawDataIndex, std::string nName, int nWidth, int nHeight); + static ZTexture* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, + bool readFile); + static ZTexture* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, + int rawDataIndex, std::string nRelPath); + static ZTexture* FromBinary(TextureType nType, std::vector nRawData, int rawDataIndex, + std::string nName, int nWidth, int nHeight); static ZTexture* FromPNG(std::string pngFilePath, TextureType texType); static ZTexture* FromHLTexture(HLTexture* hlTex); static TextureType GetTextureTypeFromString(std::string str); diff --git a/tools/ZAPD/ZAPD/ZVector.cpp b/tools/ZAPD/ZAPD/ZVector.cpp index 23de24fc39..68f3739e73 100644 --- a/tools/ZAPD/ZAPD/ZVector.cpp +++ b/tools/ZAPD/ZAPD/ZVector.cpp @@ -1,10 +1,10 @@ #include "ZVector.h" -#include "ZFile.h" +#include #include "BitConverter.h" -#include "StringHelper.h" #include "File.h" #include "Globals.h" -#include +#include "StringHelper.h" +#include "ZFile.h" ZVector::ZVector() : ZResource() { @@ -13,7 +13,8 @@ ZVector::ZVector() : ZResource() this->dimensions = 0; } -ZVector* ZVector::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath) +ZVector* ZVector::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const int rawDataIndex, const std::string& nRelPath) { ZVector* vector = new ZVector(); vector->rawData = nRawData; @@ -41,7 +42,7 @@ void ZVector::ParseRawData() scalars.clear(); - for (int i = 0; i < this->dimensions; i++) + for (uint32_t i = 0; i < this->dimensions; i++) { ZScalar* scalar = new ZScalar(this->scalarType); scalar->rawDataIndex = currentRawDataIndex; @@ -59,7 +60,7 @@ void ZVector::ParseRawData() int ZVector::GetRawDataSize() { int size = 0; - for (int i = 0; i < this->scalars.size(); i++) + for (size_t i = 0; i < this->scalars.size(); i++) size += this->scalars[i]->GetRawDataSize(); return size; } @@ -85,7 +86,9 @@ std::string ZVector::GetSourceTypeName() } else { - std::string output = StringHelper::Sprintf("Encountered unsupported vector type: %d dimensions, %s type", dimensions, ZScalar::MapScalarTypeToOutputType(scalarType).c_str()); + std::string output = StringHelper::Sprintf( + "Encountered unsupported vector type: %d dimensions, %s type", dimensions, + ZScalar::MapScalarTypeToOutputType(scalarType).c_str()); if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) printf("%s\n", output.c_str()); @@ -97,7 +100,7 @@ std::string ZVector::GetSourceTypeName() std::string ZVector::GetSourceValue() { std::vector strings = std::vector(); - for (int i = 0; i < this->scalars.size(); i++) + for (size_t i = 0; i < this->scalars.size(); i++) strings.push_back(scalars[i]->GetSourceValue()); return "{ " + StringHelper::Implode(strings, ", ") + " }"; } @@ -105,7 +108,8 @@ std::string ZVector::GetSourceValue() std::string ZVector::GetSourceOutputCode(const std::string& prefix) { if (parent != nullptr) - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), GetSourceTypeName(), GetName(), GetSourceValue()); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), + GetSourceTypeName(), GetName(), GetSourceValue()); return ""; } diff --git a/tools/ZAPD/ZAPD/ZVector.h b/tools/ZAPD/ZAPD/ZVector.h index 0d6ea06eb3..a12ee47a5b 100644 --- a/tools/ZAPD/ZAPD/ZVector.h +++ b/tools/ZAPD/ZAPD/ZVector.h @@ -1,8 +1,8 @@ #pragma once -#include -#include #include +#include +#include #include "ZResource.h" #include "ZScalar.h" #include "tinyxml2.h" @@ -16,16 +16,18 @@ public: ZVector(); - void ParseXML(tinyxml2::XMLElement* reader); + void ParseXML(tinyxml2::XMLElement* reader) override; std::string GetSourceTypeName() override; std::string GetSourceValue(); - std::string GetSourceOutputCode(const std::string& prefix); + std::string GetSourceOutputCode(const std::string& prefix) override; void ParseRawData() override; - int GetRawDataSize(); + int GetRawDataSize() override; bool DoesSupportArray() override; - ZResourceType GetResourceType(); + ZResourceType GetResourceType() override; - static ZVector* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath); + static ZVector* ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, const int rawDataIndex, + const std::string& nRelPath); protected: }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZVtx.cpp b/tools/ZAPD/ZAPD/ZVtx.cpp index b951310429..c551e0d573 100644 --- a/tools/ZAPD/ZAPD/ZVtx.cpp +++ b/tools/ZAPD/ZAPD/ZVtx.cpp @@ -1,7 +1,7 @@ #include "ZVtx.h" -#include "ZFile.h" -#include "StringHelper.h" #include "BitConverter.h" +#include "StringHelper.h" +#include "ZFile.h" ZVtx::ZVtx() { @@ -28,12 +28,14 @@ std::string ZVtx::GetSourceTypeName() std::string ZVtx::GetSourceOutputCode(const std::string& prefix) { - std::string output = StringHelper::Sprintf("VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i)", x, y, z, s, t, r, g, b, a); + std::string output = + StringHelper::Sprintf("VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i)", x, y, z, s, t, r, g, b, a); if (parent != nullptr) - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(), GetSourceTypeName(), name, output); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(), + GetSourceTypeName(), name, output); - return ""; + return ""; } void ZVtx::ParseRawData() @@ -54,25 +56,26 @@ void ZVtx::ParseRawData() int ZVtx::GetRawDataSize() { - return 16; + return 16; } bool ZVtx::DoesSupportArray() { - return true; + return true; } ZResourceType ZVtx::GetResourceType() { - return ZResourceType::Vertex; + return ZResourceType::Vertex; } -ZVtx* ZVtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath) +ZVtx* ZVtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const int rawDataIndex, const std::string& nRelPath) { - ZVtx* vtx = new ZVtx(); + ZVtx* vtx = new ZVtx(); vtx->rawData = nRawData; vtx->rawDataIndex = rawDataIndex; - vtx->ParseRawData(); + vtx->ParseRawData(); - return vtx; + return vtx; } diff --git a/tools/ZAPD/ZAPD/ZVtx.h b/tools/ZAPD/ZAPD/ZVtx.h index 83eb734d73..bd40b07e93 100644 --- a/tools/ZAPD/ZAPD/ZVtx.h +++ b/tools/ZAPD/ZAPD/ZVtx.h @@ -1,8 +1,8 @@ #pragma once -#include -#include #include +#include +#include #include "ZResource.h" #include "ZScalar.h" #include "tinyxml2.h" @@ -17,15 +17,16 @@ public: ZVtx(); - void ParseXML(tinyxml2::XMLElement* reader); + void ParseXML(tinyxml2::XMLElement* reader) override; std::string GetSourceTypeName() override; - std::string GetSourceOutputCode(const std::string& prefix); + std::string GetSourceOutputCode(const std::string& prefix) override; void ParseRawData() override; - int GetRawDataSize(); + int GetRawDataSize() override; bool DoesSupportArray() override; - ZResourceType GetResourceType(); + ZResourceType GetResourceType() override; - static ZVtx* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath); + static ZVtx* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const int rawDataIndex, const std::string& nRelPath); protected: }; \ No newline at end of file diff --git a/tools/ZAPD/lib/libgfxd/LICENSE b/tools/ZAPD/lib/libgfxd/LICENSE new file mode 100644 index 0000000000..a7655f829d --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016-2021 glank (glankk@github.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/tools/ZAPD/lib/libgfxd/Makefile b/tools/ZAPD/lib/libgfxd/Makefile new file mode 100644 index 0000000000..b340ff5c0a --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/Makefile @@ -0,0 +1,25 @@ +CFLAGS = -Wall -O2 -g +UC_OBJ = uc_f3d.o uc_f3db.o uc_f3dex.o uc_f3dexb.o uc_f3dex2.o +OBJ = gfxd.o $(UC_OBJ) +LIB = libgfxd.a + +CPPFLAGS-$(MT) += -DCONFIG_MT +CPPFLAGS += $(CPPFLAGS-y) + +.PHONY: all +all: $(LIB) + +.PHONY: clean +clean: + rm -f $(OBJ) $(LIB) + +.INTERMEDIATE: $(OBJ) + +$(OBJ): gbi.h gfxd.h priv.h +$(UC_OBJ): uc.c uc_argfn.c uc_argtbl.c uc_macrofn.c uc_macrotbl.c + +$(LIB): $(OBJ) + $(AR) rcs $@ $^ + +%.o: %.c + $(COMPILE.c) $(OUTPUT_OPTION) $< diff --git a/tools/ZAPD/lib/libgfxd/README.md b/tools/ZAPD/lib/libgfxd/README.md new file mode 100644 index 0000000000..2e82589439 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/README.md @@ -0,0 +1,478 @@ +## Installing +Run `make` for a single-threaded build, or `make MT=y` for a multi-threaded +build. Copy `libgfxd.a` to your lib directory, and `gfxd.h` to your include +directory. + +## Example usage +Example source code: +``` +#include +#include + +static int macro_fn(void) +{ + /* Print a tab before each macro, and a comma and newline after each + macro */ + gfxd_puts("\t"); + gfxd_macro_dflt(); /* Execute the default macro handler */ + gfxd_puts(",\n"); + + return 0; +} + +int main() +{ + /* Read from stdin and write to stdout */ + gfxd_input_fd(fileno(stdin)); + gfxd_output_fd(fileno(stdout)); + + /* Override the default macro handler to make the output prettier */ + gfxd_macro_fn(macro_fn); + + /* Select F3DEX as the target microcode */ + gfxd_target(gfxd_f3dex); + + /* Set the input endianness to big endian, and the word size to 4 */ + gfxd_endian(gfxd_endian_big, 4); + + /* Print an opening brace */ + gfxd_puts("{\n"); + + /* Execute until the end of input, or until encountering an invalid + command */ + gfxd_execute(); + + /* Print a closing brace */ + gfxd_puts("}\n"); +} +``` + +Example input (binary): +``` +0xe7000000, 0x00000000, +0xfc127e03, 0xfffffdf8, +0xb900031d, 0xc8112078, +0xb6000000, 0x000e0000, +0xb7000000, 0x00012000, +0xfa000000, 0xffffffff, +0x040030bf, 0x000002e0, +0xb1000204, 0x00020604, +0xb1080a0c, 0x000a0e0c, +0xb10a1012, 0x000a120e, +0xb1140200, 0x00140016, +0xb8000000, 0x00000000, +``` + +Example output: +``` +{ + gsDPPipeSync(), + gsDPSetCombineLERP(TEXEL0, 0, SHADE, 0, 0, 0, 0, 1, COMBINED, 0, PRIMITIVE, 0, 0, 0, 0, COMBINED), + gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2), + gsSPClearGeometryMode(G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR), + gsSPSetGeometryMode(G_CULL_BACK | G_FOG), + gsDPSetPrimColor(0, 0, 0xFF, 0xFF, 0xFF, 0xFF), + gsSPVertex(0x000002E0, 12, 0), + gsSP2Triangles(0, 1, 2, 0, 1, 3, 2, 0), + gsSP2Triangles(4, 5, 6, 0, 5, 7, 6, 0), + gsSP1Quadrangle(5, 8, 9, 7, 0), + gsSP1Quadrangle(10, 1, 0, 11, 0), + gsSPEndDisplayList(), +} +``` + +## Input/output methods +The input consists of any number of `Gfx` packets, and the output is the +decompiled macros in plain-text. The endianness and microcode type of the input +can be set using `gfxd_endian` and `gfxd_target`. + +Several methods of doing I/O are available. No method is selected by default, +meaning there will be no input, and any output will be discarded. + +--- + +##### `void gfxd_input_buffer(const void *buf, int size)` +##### `void gfxd_output_buffer(char *buf, int size)` +Use the buffer pointed to by `buf`, of `size` bytes. + +--- + +##### `void gfxd_input_fd(int fd)` +##### `void gfxd_output_fd(int fd)` +Use `read()` / `write()` with the provided file descriptor, `fd`. + +--- + +##### `typedef int gfxd_input_fn_t(void *buf, int count)` +##### `typedef int gfxd_output_fn_t(const char *buf, int count)` +##### `void gfxd_input_callback(gfxd_input_fn_t *fn)` +##### `void gfxd_output_callback(gfxd_output_fn_t *fn)` +Use the provided callback function, `fn`. `fn` should copy at most `count` +bytes to/from `buf`, and return the number of bytes actually copied. The input +callback should return 0 to signal end of input. + +## Handlers +The macro handler function is responsible for writing the output of each +decompiled macro. The default macro handler is `gfxd_macro_dflt`, but this can +be changed with `gfxd_macro_fn`. The new handler can extend the default +function by calling `gfxd_macro_dflt` within it, or it can override it +completely. + +--- + +##### `int gfxd_macro_dflt()` +The default macro handler. Outputs the macro name, dynamic display list pointer +if one has been specified, and then each argument in order using the function +registered using `gfxd_arg_fn` (`gfxd_arg_dflt` by default), and returns zero. +Because it is designed to be extended, it only outputs the macro text, without +any whitespace or punctuation before or after. When this function is used as +the sole macro handler, it will output the entire display list on one line +without any separation between macros, which is probably not what you want. + +--- + +##### `void gfxd_macro_fn(gfxd_macro_fn_t *fn)` +Set `fn` to be the macro handler function. `fn` can be null, in which case the +handler is reset to the default. + +--- + +##### `void gfxd_arg_dflt(int arg_num)` +The default argument handler for `gfxd_macro_dflt`. For the argument with index +`arg_num`, calls `gfxd_arg_callbacks`, and prints the argument value if the +callback returns zero, or if there is no callback for the given argument. + +--- + +##### `void gfxd_arg_fn(gfxd_arg_fn_t *fn)` +Set `fn` to be the argument handler function, called by `gfxd_macro_dflt`, +for each argument in the current macro, not counting the dynamic display list +pointer if one has been specified. `fn` can be null, in which case the handler +is reset to the default. This only affects the output of `gfxd_macro_dflt`, and +has no observable effect if `gfxd_macro_dflt` is overridden (not extended). + +## Argument callbacks +Callbacks can be registered that will be executed when an argument of a certain +type is encountered. The default argument handler `gfxd_arg_dflt` will execute +callbacks as needed using `gfxd_arg_callbacks`. If a callback returns non-zero, +`gfxd_arg_dflt` will not output anything. This is to allow callbacks to +override the default argument output. Otherwise, `gfxd_arg_dflt` will output +the argument value after the callback function's output. + +--- + +##### `int gfxd_arg_callbacks(int arg_num)` +Examines the argument with index `arg_num` and executes the callback function +for that argument type, if such a callback is supported and has been +registered. This function returns the value that was returned by the callback +function. If no callback function has been registered for the argument type, +zero is returned. + +Most argument callbacks have some extra parameters containing information that +might be relevant to the argument that triggered the callback. The extra +information is extracted only from the current macro, as gfxd does not retain +any context information from previous or subsequent macros. If any of the extra +parameter values is not available in the current macro, the value for that +parameter is substituted with `-1` for signed parameters, and zero for unsigned +parameters. + +--- + +##### `typedef int gfxd_tlut_fn_t(uint32_t tlut, int32_t idx, int32_t count)` +##### `void gfxd_tlut_callback(gfxd_tlut_fn_t *fn)` +Set the callback function for palette arguments. The argument type is +`gfxd_Tlut`. The palette index is in `idx` and the number of colors in `count`. + +--- + +##### `typedef int gfxd_timg_fn_t(uint32_t timg, int32_t fmt, int32_t siz, int32_t width, int32_t height, int32_t pal)` +##### `void gfxd_timg_callback(gfxd_timg_fn_t *fn)` +Set the callback function for texture arguments. The argument type is +`gfxd_Timg`. The image format is in `fmt` and `siz`, the dimensions in `width` +and `height`, and the palette index in `pal`. + +--- + +##### `typedef int gfxd_cimg_fn_t(uint32_t cimg, int32_t fmt, int32_t siz, int32_t width)` +##### `void gfxd_cimg_callback(gfxd_cimg_fn_t *fn)` +Set the callback function for frame buffer arguments. The argument type is +`gfxd_Cimg`. The image format is in `fmt` and `siz`, and the horizontal +resolution in `width`. + +--- + +##### `typedef int gfxd_zimg_fn_t(uint32_t zimg)` +##### `void gfxd_zimg_callback(gfxd_zimg_fn_t *fn)` +Set the callback function for depth buffer arguments. The argument type is +`gfxd_Zimg`. + +--- + +##### `typedef int gfxd_dl_fn_t(uint32_t dl)` +##### `void gfxd_dl_callback(gfxd_dl_fn_t *fn)` +Set the callback function for display list arguments. The argument type is +`gfxd_Dl`. + +--- + +##### `typedef int gfxd_mtx_fn_t(uint32_t mtx)` +##### `void gfxd_mtx_callback(gfxd_mtx_fn_t *fn)` +Set the callback function for matrix arguments. The argument type is +`gfxd_Mtxptr`. + +--- + +##### `typedef int gfxd_lookat_fn_t(uint32_t lookat, int32_t count)` +##### `void gfxd_lookat_callback(gfxd_lookat_fn_t *fn)` +Set the callback function for lookat array arguments. The argument type is +`gfxd_Lookatptr`. The number of lookat structures (1 or 2) is in `count`. + +--- + +##### `typedef int gfxd_light_fn_t(uint32_t light, int32_t count)` +##### `void gfxd_light_callback(gfxd_light_fn_t *fn)` +Set the callback function for light array arguments. The argument type is +`gfxd_Lightptr`. The number of light structures is in `count`. + +--- + +##### `typedef int gfxd_seg_fn_t(uint32_t seg, int32_t num)` +##### `void gfxd_seg_callback(gfxd_seg_fn_t *fn)` +Set the callback function for segment base arguments. The argument type is +`gfxd_Segptr`. The segment number is in `num`. + +--- + +##### `typedef int gfxd_vtx_fn_t(uint32_t vtx, int32_t num)` +##### `void gfxd_vtx_callback(gfxd_vtx_fn_t *fn)` +Set the callback function for vertex array arguments. The argument type is +`gfxd_Vtxptr`. The number of vertex structures is in `num`. + +--- + +##### `typedef int gfxd_vp_fn_t(uint32_t vp)` +##### `void gfxd_vp_callback(gfxd_vp_fn_t *fn)` +Set the callback function for viewport arguments. The argument type is +`gfxd_Vp`. + +--- + +##### `typedef int gfxd_uctext_fn_t(uint32_t text, uint32_t size)` +##### `void gfxd_uctext_callback(gfxd_uctext_fn_t *fn)` +Set the callback function for microcode text arguments. The argument type is +`gfxd_Uctext`. The size of the text segment is in `size`. + +--- + +##### `typedef int gfxd_ucdata_fn_t(uint32_t data, uint32_t size)` +##### `void gfxd_ucdata_callback(gfxd_ucdata_fn_t *fn)` +Set the callback function for microcode data arguments. The argument type is +`gfxd_Ucdata`. The size of the data segment is in `size`. + +--- + +##### `typedef int gfxd_dram_fn_t(uint32_t dram, uint32_t size)` +##### `void gfxd_dram_callback(gfxd_dram_fn_t *fn)` +Set the callback function for generic pointer arguments. The argument type is +`gfxd_Dram`. The size of the data is in `size`. + +## General settings +These functions control general input and output settings. + +--- + +##### `void gfxd_target(gfxd_ucode_t ucode)` +Select `ucode` as the target microcode. `ucode` can be `gfxd_f3d`, `gfxd_f3db`, +`gfxd_f3dex`, `gfxd_f3dexb`, or `gfxd_f3dex2`. The microcode must be selected +before `gfxd_execute`, as no microcode is selected by default. + +--- + +##### `void gfxd_endian(int endian, int wordsize)` +Select `endian` as the endianness of the input, and `wordsize` as the size of +each word in number of bytes. `endian` can be `gfxd_endian_big`, +`gfxd_endian_little`, or `gfxd_endian_host` (the endianness of the host +machine). `wordsize` can be 1, 2, 4, or 8. Big endian is selected by default, +with a word size of 4. + +--- + +##### `void gfxd_dynamic(const char *arg)` +Enable or disable the use of dynamic `g` macros instead of static `gs` macros, +and select the dynamic display list pointer argument to be used. `arg` will be +used by `gfxd_macro_dflt` as the first argument to dynamic macros. If `arg` is +null, dynamic macros are disabled, and `gs` macros are used. Also affects the +result of `gfxd_macro_name`, as it will return either the dynamic or static +version of the macro name as selected by this setting. + +--- + +##### `void gfxd_enable(int cap)` +##### `void gfxd_disable(int cap)` +Enable or disable the feature specified by `cap`. Can be one of the following; +- `gfxd_stop_on_invalid`: Stop execution when encountering an invalid macro. +Enabled by default. +- `gfxd_stop_on_end`: Stop execution when encountering a `SPBranchList` or +`SPEndDisplayList`. Enabled by default. +- `gfxd_emit_dec_color`: Print color components as decimal instead of +hexadecimal. Disabled by default. +- `gfxd_emit_q_macro`: Print fixed-point conversion `q` macros for fixed-point +values. Disabled by default. +- `gfxd_emit_ext_macro`: Emit non-standard macros. Some commands are valid +(though possibly meaningless), but have no macros associated with them, such as +a standalone `G_RDPHALF_1`. When this feature is enabled, such a command will +produce a non-standard `gsDPHalf1` macro instead of a raw hexadecimal command. +Also enables some non-standard multi-packet texture loading macros. Disabled by +default. + +--- + +##### `void gfxd_udata_set(void *ptr)` +##### `void *gfxd_udata_get(void)` +Set or get a generic pointer that can be used to pass user-defined data in and +out of callback functions. + +## Execution +Decompilation is started using the `gfxd_execute` function. When gfxd is +executing (i.e. after `gfxd_execute` has been entered, and before it returns), +the general settings and the I/O settings should not be changed. + +--- + +##### `int gfxd_execute()` +Start executing gfxd with the current settings. For each macro, the macro +handler registered with `gfxd_macro_fn` is called. Execution ends when the +input ends, the macro handler returns non-zero, when an invalid macro is +encountered and `gfxd_stop_on_invalid` is enabled, or when `SPBranchList` or +`SPEndDisplayList` is encountered and `gfxd_stop_on_end` is enabled. If +execution ends due to an invalid macro, `-1` is returned. If execution ends +because the macro handler returns non-zero, the return value from the macro +handler is returned. Otherwise zero is returned. + +## Macro information +The following functions can be used to obtain information about the current +macro and its arguments. They should only be used in custom handlers and +callbacks from within `gfxd_execute`. If used elsewhere, their behavior is +undefined. + +--- + +##### `int gfxd_macro_offset()` +Returns the offset in the input data of the current macro. The offset starts +at zero when `gfxd_execute` is called. + +--- + +##### `int gfxd_macro_packets()` +Returns the number of `Gfx` packets within the current macro. + +--- + +##### `const void *gfxd_macro_data()` +Returns a pointer to the input data for the current macro. The data is not +byte-swapped. The data has a length of `sizeof(Gfx) * gfxd_macro_packets()`. + +--- + +##### `int gfxd_macro_id()` +Returns a number that uniquely identifies the current macro. The number will +be one of the constants in `gfxd.h`. + +--- + +##### `const char *gfxd_macro_name()` +Returns the name of the current macro. If the macro does not have a name (i.e. +it's invalid), null is returned. If a dynamic display list pointer has been +specified, the dynamic `g` version is returned. Otherwise the static `gs` +version is returned. The returned pointer is invalidated by a subsequent call +to `gfxd_macro_name`. + +--- + +##### `int gfxd_arg_count()` +Returns the number of arguments to the current macro, not including a dynamic +display list pointer if one has been specified. + +--- + +##### `int gfxd_arg_type(int arg_num)` +Returns a number that identifies the type of the argument with index `arg_num`. +The number will be one of the constants in `gfxd.h`. + +--- + +##### `const char *gfxd_arg_name(int arg_num)` +Returns the name of the argument with index `arg_num`. Argument names are not +canonical, nor are they needed for macro disassembly, but they can be useful +for informational and diagnostic purposes. + +--- + +##### `int gfxd_arg_fmt(int arg_num)` +Returns the data format of the argument with index `arg_num`. The return value +will be `gfxd_argfmt_i` for `int32_t`, `gfxd_argfmt_u` for `uint32_t`, or +`gfxd_argfmt_f` for `float`. When accessing the value of the argument with +`gfxd_arg_value`, the member with the corresponding type should be used. + +--- + +##### `const gfxd_value_t *gfxd_arg_value(int arg_num)` +Returns a pointer to the value of the argument with index `arg_num`. The value +is a union of type `gfxd_value_t` with the following layout; +``` +typedef union +{ + int32_t i; + uint32_t u; + float f; +} gfxd_value_t +``` + +--- + +##### `const gfxd_value_t *gfxd_value_by_type(int type, int idx)` +Returns a pointer to the value of the argument that is of `type`, and has order +`idx` in all arguments of that type. An `idx` of zero returns the first +argument that has the specified type. If there is no argument with the given +type and order, null is returned. + +--- + +##### `int gfxd_arg_valid(int arg_num)` +Returns non-zero if the argument with index `arg_num` is "valid", for some +definition of valid. An invalid argument generally means that the disassembler +found inconsistencies in the input data, or that the data can not be reproduced +by the current macro type. The argument still has a value that can be printed, +though the value is not guaranteed to make any sense. + +## Custom output +When the default handlers are overridden or extended, the custom handler +functions will want to do some output of their own. The following methods are +available for inserting custom text into the gfxd output. + +--- + +##### `int gfxd_write(const void *buf, int count)` +Insert `count` bytes from the buffer at `buf` into the output. The number of +characters written is returned. + +--- + +##### `int gfxd_puts(const char *str)` +Insert the null-terminated string at `str` into the output. The number of +characters written is returned. + +--- + +##### `int gfxd_printf(const char *fmt, ...)` +Insert the printf-formatted string described by `fmt` and additional arguments +into the output. Limited to 255 characters. The number of characters written is +returned. + +--- + +##### `int gfxd_print_value(int type, const gfxd_value_t *value)` +Insert the type-formatted value into the output. The type should be one of the +constants in `gfxd.h`. The number of characters written is returned. The +macro argument with index `n` can be printed with +`gfxd_print_value(gfxd_arg_type(n), gfxd_arg_value(n))`. diff --git a/tools/ZAPD/lib/libgfxd/gbi.h b/tools/ZAPD/lib/libgfxd/gbi.h new file mode 100644 index 0000000000..e502ee9508 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/gbi.h @@ -0,0 +1,3808 @@ +/** + * gbi.h version 0.3.3 + * n64 graphics microcode interface library + * compatible with fast3d, f3dex, f3dex2, s2dex, and s2dex2 + * + * select a microcode with one of these preprocessor definitions; + * #define F3D_GBI + * for fast3d (selected automatically by default), or + * #define F3DEX_GBI + * for f3dex/s2dex, or + * #define F3DEX_GBI_2 + * for f3dex2/s2dex2 + * + * for early versions of fast3d and f3dex, also define the following; + * #define F3D_BETA + * + * ido incompatibilities; + * - use of c99 variadic macros + * - use of c99 fixed-width integer types + * - use of c99 designated initializers + * - use of c99 compound literals + * - use of c11 _Alignas + * - use of gnu c compound expressions + * - use of gnu c __typeof__ + * + * libultra incompatibilities; + * - many private, undocumented, or obsolete macros not commonly used by + * programmers are missing + * - many different implementation details that will produce matching gbi, + * but not matching code +**/ + +#ifndef N64_GBI_H +#define N64_GBI_H + +#include + +/* use fast3d by default */ +#if !defined(F3D_GBI) && !defined(F3DEX_GBI) && !defined(F3DEX_GBI_2) +# define F3D_GBI +#endif + +/* commands for fast3d and f3dex */ +#if defined(F3D_GBI) || defined(F3DEX_GBI) +# define G_SPNOOP 0x00 +# define G_MTX 0x01 +# define G_MOVEMEM 0x03 +# define G_VTX 0x04 +# define G_DL 0x06 +# if defined(F3D_BETA) +# define G_RDPHALF_2 0xB2 +# define G_RDPHALF_1 0xB3 +# define G_PERSPNORM 0xB4 +# else +# define G_RDPHALF_2 0xB3 +# define G_RDPHALF_1 0xB4 +# endif +# define G_LINE3D 0xB5 +# define G_CLEARGEOMETRYMODE 0xB6 +# define G_SETGEOMETRYMODE 0xB7 +# define G_ENDDL 0xB8 +# define G_SETOTHERMODE_L 0xB9 +# define G_SETOTHERMODE_H 0xBA +# define G_TEXTURE 0xBB +# define G_MOVEWORD 0xBC +# define G_POPMTX 0xBD +# define G_CULLDL 0xBE +# define G_TRI1 0xBF +# define G_NOOP 0xC0 +#endif + +/* commands for f3dex */ +#if defined(F3DEX_GBI) +# define G_LOAD_UCODE 0xAF +# define G_BRANCH_Z 0xB0 +# define G_TRI2 0xB1 +# if !defined(F3D_BETA) +# define G_MODIFYVTX 0xB2 +# endif +#endif + +/* commands for f3dex2 */ +#if defined(F3DEX_GBI_2) +# define G_NOOP 0x00 +# define G_VTX 0x01 +# define G_MODIFYVTX 0x02 +# define G_CULLDL 0x03 +# define G_BRANCH_Z 0x04 +# define G_TRI1 0x05 +# define G_TRI2 0x06 +# define G_QUAD 0x07 +# define G_LINE3D 0x08 +# define G_SPECIAL_3 0xD3 +# define G_SPECIAL_2 0xD4 +# define G_SPECIAL_1 0xD5 +# define G_DMA_IO 0xD6 +# define G_TEXTURE 0xD7 +# define G_POPMTX 0xD8 +# define G_GEOMETRYMODE 0xD9 +# define G_MTX 0xDA +# define G_MOVEWORD 0xDB +# define G_MOVEMEM 0xDC +# define G_LOAD_UCODE 0xDD +# define G_DL 0xDE +# define G_ENDDL 0xDF +# define G_SPNOOP 0xE0 +# define G_RDPHALF_1 0xE1 +# define G_SETOTHERMODE_L 0xE2 +# define G_SETOTHERMODE_H 0xE3 +# define G_RDPHALF_2 0xF1 +#endif + +/* rdp commands */ +#define G_TEXRECT 0xE4 +#define G_TEXRECTFLIP 0xE5 +#define G_RDPLOADSYNC 0xE6 +#define G_RDPPIPESYNC 0xE7 +#define G_RDPTILESYNC 0xE8 +#define G_RDPFULLSYNC 0xE9 +#define G_SETKEYGB 0xEA +#define G_SETKEYR 0xEB +#define G_SETCONVERT 0xEC +#define G_SETSCISSOR 0xED +#define G_SETPRIMDEPTH 0xEE +#define G_RDPSETOTHERMODE 0xEF +#define G_LOADTLUT 0xF0 +#define G_SETTILESIZE 0xF2 +#define G_LOADBLOCK 0xF3 +#define G_LOADTILE 0xF4 +#define G_SETTILE 0xF5 +#define G_FILLRECT 0xF6 +#define G_SETFILLCOLOR 0xF7 +#define G_SETFOGCOLOR 0xF8 +#define G_SETBLENDCOLOR 0xF9 +#define G_SETPRIMCOLOR 0xFA +#define G_SETENVCOLOR 0xFB +#define G_SETCOMBINE 0xFC +#define G_SETTIMG 0xFD +#define G_SETZIMG 0xFE +#define G_SETCIMG 0xFF + +/* commands for s2dex */ +#if defined(F3DEX_GBI) +# define G_BG_1CYC 0x01 +# define G_BG_COPY 0x02 +# define G_OBJ_RECTANGLE 0x03 +# define G_OBJ_SPRITE 0x04 +# define G_OBJ_MOVEMEM 0x05 +# define G_SELECT_DL 0xB0 +# define G_OBJ_RENDERMODE 0xB1 +# define G_OBJ_RECTANGLE_R 0xB2 +# define G_OBJ_LOADTXTR 0xC1 +# define G_OBJ_LDTX_SPRITE 0xC2 +# define G_OBJ_LDTX_RECT 0xC3 +# define G_OBJ_LDTX_RECT_R 0xC4 +#endif + +/* commands for s2dex2 */ +#if defined(F3DEX_GBI_2) +# define G_OBJ_RECTANGLE 0x01 +# define G_OBJ_SPRITE 0x02 +# define G_SELECT_DL 0x04 +# define G_OBJ_LOADTXTR 0x05 +# define G_OBJ_LDTX_SPRITE 0x06 +# define G_OBJ_LDTX_RECT 0x07 +# define G_OBJ_LDTX_RECT_R 0x08 +# define G_BG_1CYC 0x09 +# define G_BG_COPY 0x0A +# define G_OBJ_RENDERMODE 0x0B +# define G_OBJ_RECTANGLE_R 0xDA +# define G_OBJ_MOVEMEM 0xDC +#endif + +/* commands for s2dex and s2dex2 */ +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +# define G_RDPHALF_0 0xE4 +#endif + +/* image formats */ +#define G_IM_FMT_RGBA 0 +#define G_IM_FMT_YUV 1 +#define G_IM_FMT_CI 2 +#define G_IM_FMT_IA 3 +#define G_IM_FMT_I 4 +#define G_IM_SIZ_4b 0 +#define G_IM_SIZ_8b 1 +#define G_IM_SIZ_16b 2 +#define G_IM_SIZ_32b 3 + +/* texture settings */ +#define G_TX_NOMIRROR (gI_(0b0) << 0) +#define G_TX_MIRROR (gI_(0b1) << 0) +#define G_TX_WRAP (gI_(0b0) << 1) +#define G_TX_CLAMP (gI_(0b1) << 1) +#define G_TX_NOMASK gI_(0) +#define G_TX_NOLOD gI_(0) +#define G_OFF gI_(0) +#define G_ON gI_(1) + +/* tile indices */ +#define G_TX_LOADTILE 7 +#define G_TX_RENDERTILE 0 + +/* geometry mode */ +#define G_ZBUFFER (gI_(0b1) << 0) +#define G_SHADE (gI_(0b1) << 2) +#define G_CULL_BOTH (G_CULL_FRONT | G_CULL_BACK) +#define G_FOG (gI_(0b1) << 16) +#define G_LIGHTING (gI_(0b1) << 17) +#define G_TEXTURE_GEN (gI_(0b1) << 18) +#define G_TEXTURE_GEN_LINEAR (gI_(0b1) << 19) +#define G_LOD (gI_(0b1) << 20) + +/* geometry mode for fast3d */ +#if defined(F3D_GBI) +# define G_CLIPPING (gI_(0b0) << 0) +#endif + +/* geometry mode for fast3d and f3dex */ +#if defined(F3D_GBI) || defined(F3DEX_GBI) +# define G_TEXTURE_ENABLE (gI_(0b1) << 1) +# define G_SHADING_SMOOTH (gI_(0b1) << 9) +# define G_CULL_FRONT (gI_(0b1) << 12) +# define G_CULL_BACK (gI_(0b1) << 13) +#endif + +/* geometry mode for f3dex and f3dex2 */ +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +# define G_CLIPPING (gI_(0b1) << 23) +#endif + +/* geometry mode for f3dex2 */ +#if defined(F3DEX_GBI_2) +# define G_TEXTURE_ENABLE (gI_(0b0) << 0) +# define G_CULL_FRONT (gI_(0b1) << 9) +# define G_CULL_BACK (gI_(0b1) << 10) +# define G_SHADING_SMOOTH (gI_(0b1) << 21) +#endif + +/* othermode lo */ +#define G_MDSFT_ALPHACOMPARE 0 +#define G_MDSFT_ZSRCSEL 2 +#define G_MDSFT_RENDERMODE 3 +#define G_MDSFT_BLENDER 16 +#define G_MDSIZ_ALPHACOMPARE 2 +#define G_MDSIZ_ZSRCSEL 1 +#define G_MDSIZ_RENDERMODE 29 +#define G_MDSIZ_BLENDER 13 + +#define G_AC_NONE (gI_(0b00) << G_MDSFT_ALPHACOMPARE) +#define G_AC_THRESHOLD (gI_(0b01) << G_MDSFT_ALPHACOMPARE) +#define G_AC_DITHER (gI_(0b11) << G_MDSFT_ALPHACOMPARE) +#define G_ZS_PIXEL (gI_(0b0) << G_MDSFT_ZSRCSEL) +#define G_ZS_PRIM (gI_(0b1) << G_MDSFT_ZSRCSEL) +#define AA_EN (gI_(0b1) << (G_MDSFT_RENDERMODE + 0)) +#define Z_CMP (gI_(0b1) << (G_MDSFT_RENDERMODE + 1)) +#define Z_UPD (gI_(0b1) << (G_MDSFT_RENDERMODE + 2)) +#define IM_RD (gI_(0b1) << (G_MDSFT_RENDERMODE + 3)) +#define CLR_ON_CVG (gI_(0b1) << (G_MDSFT_RENDERMODE + 4)) +#define CVG_DST_CLAMP (gI_(0b00) << (G_MDSFT_RENDERMODE + 5)) +#define CVG_DST_WRAP (gI_(0b01) << (G_MDSFT_RENDERMODE + 5)) +#define CVG_DST_FULL (gI_(0b10) << (G_MDSFT_RENDERMODE + 5)) +#define CVG_DST_SAVE (gI_(0b11) << (G_MDSFT_RENDERMODE + 5)) +#define ZMODE_OPA (gI_(0b00) << (G_MDSFT_RENDERMODE + 7)) +#define ZMODE_INTER (gI_(0b01) << (G_MDSFT_RENDERMODE + 7)) +#define ZMODE_XLU (gI_(0b10) << (G_MDSFT_RENDERMODE + 7)) +#define ZMODE_DEC (gI_(0b11) << (G_MDSFT_RENDERMODE + 7)) +#define CVG_X_ALPHA (gI_(0b1) << (G_MDSFT_RENDERMODE + 9)) +#define ALPHA_CVG_SEL (gI_(0b1) << (G_MDSFT_RENDERMODE + 10)) +#define FORCE_BL (gI_(0b1) << (G_MDSFT_RENDERMODE + 11)) + +#define G_BL_1MA gI_(0b00) +#define G_BL_1 gI_(0b10) +#define G_BL_0 gI_(0b11) +#define G_BL_CLR_IN gI_(0b00) +#define G_BL_CLR_MEM gI_(0b01) +#define G_BL_CLR_BL gI_(0b10) +#define G_BL_CLR_FOG gI_(0b11) +#define G_BL_A_IN gI_(0b00) +#define G_BL_A_FOG gI_(0b01) +#define G_BL_A_MEM gI_(0b01) +#define G_BL_A_SHADE gI_(0b10) + +#define GBL_c1(p, a, m, b) \ + ( \ + gF_(p, 2, 30) | \ + gF_(a, 2, 26) | \ + gF_(m, 2, 22) | \ + gF_(b, 2, 18) \ + ) +#define GBL_c2(p, a, m, b) \ + ( \ + gF_(p, 2, 28) | \ + gF_(a, 2, 24) | \ + gF_(m, 2, 20) | \ + gF_(b, 2, 16) \ + ) + +/* render modes */ +#define G_RM_OPA_SURF \ + ( \ + CVG_DST_CLAMP | ZMODE_OPA | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) +#define G_RM_OPA_SURF2 \ + ( \ + CVG_DST_CLAMP | ZMODE_OPA | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) +#define G_RM_AA_OPA_SURF \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_OPA_SURF2 \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_RA_OPA_SURF \ + ( \ + AA_EN | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_RA_OPA_SURF2 \ + ( \ + AA_EN | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_ZB_OPA_SURF \ + ( \ + Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_ZB_OPA_SURF2 \ + ( \ + Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_OPA_SURF \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_OPA_SURF2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_RA_ZB_OPA_SURF \ + ( \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_RA_ZB_OPA_SURF2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) + +#define G_RM_XLU_SURF \ + ( \ + IM_RD | CVG_DST_FULL | ZMODE_OPA | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_XLU_SURF2 \ + ( \ + IM_RD | CVG_DST_FULL | ZMODE_OPA | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_XLU_SURF \ + ( \ + AA_EN | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | ZMODE_OPA | \ + FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_XLU_SURF2 \ + ( \ + AA_EN | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | ZMODE_OPA | \ + FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_ZB_XLU_SURF \ + ( \ + Z_CMP | IM_RD | CVG_DST_FULL | ZMODE_XLU | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_ZB_XLU_SURF2 \ + ( \ + Z_CMP | IM_RD | CVG_DST_FULL | ZMODE_XLU | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_XLU_SURF \ + ( \ + AA_EN | Z_CMP | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | \ + ZMODE_XLU | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_XLU_SURF2 \ + ( \ + AA_EN | Z_CMP | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | \ + ZMODE_XLU | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_ZB_OPA_DECAL \ + ( \ + Z_CMP | CVG_DST_FULL | ZMODE_DEC | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_ZB_OPA_DECAL2 \ + ( \ + Z_CMP | CVG_DST_FULL | ZMODE_DEC | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_OPA_DECAL \ + ( \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | ZMODE_DEC | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_OPA_DECAL2 \ + ( \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | ZMODE_DEC | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_RA_ZB_OPA_DECAL \ + ( \ + AA_EN | Z_CMP | CVG_DST_WRAP | ZMODE_DEC | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_RA_ZB_OPA_DECAL2 \ + ( \ + AA_EN | Z_CMP | CVG_DST_WRAP | ZMODE_DEC | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) + +#define G_RM_ZB_XLU_DECAL \ + ( \ + Z_CMP | IM_RD | CVG_DST_FULL | ZMODE_DEC | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_ZB_XLU_DECAL2 \ + ( \ + Z_CMP | IM_RD | CVG_DST_FULL | ZMODE_DEC | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_XLU_DECAL \ + ( \ + AA_EN | Z_CMP | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | \ + ZMODE_DEC | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_XLU_DECAL2 \ + ( \ + AA_EN | Z_CMP | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | \ + ZMODE_DEC | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_AA_ZB_OPA_INTER \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_INTER | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_OPA_INTER2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_INTER | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_RA_ZB_OPA_INTER \ + ( \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | ZMODE_INTER | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_RA_ZB_OPA_INTER2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | ZMODE_INTER | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) + +#define G_RM_AA_ZB_XLU_INTER \ + ( \ + AA_EN | Z_CMP | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | \ + ZMODE_INTER | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_XLU_INTER2 \ + ( \ + AA_EN | Z_CMP | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | \ + ZMODE_INTER | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_AA_XLU_LINE \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_XLU_LINE2 \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_XLU_LINE \ + ( \ + AA_EN | Z_CMP | IM_RD | CVG_DST_CLAMP | ZMODE_XLU | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_XLU_LINE2 \ + ( \ + AA_EN | Z_CMP | IM_RD | CVG_DST_CLAMP | ZMODE_XLU | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_AA_DEC_LINE \ + ( \ + AA_EN | IM_RD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_DEC_LINE2 \ + ( \ + AA_EN | IM_RD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_DEC_LINE \ + ( \ + AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_DEC | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_DEC_LINE2 \ + ( \ + AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_DEC | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + + +#define G_RM_TEX_EDGE \ + ( \ + AA_EN | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) +#define G_RM_TEX_EDGE2 \ + ( \ + AA_EN | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) +#define G_RM_AA_TEX_EDGE \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_TEX_EDGE2 \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_TEX_EDGE \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_TEX_EDGE2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) + +#define G_RM_AA_ZB_TEX_INTER \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_INTER | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_TEX_INTER2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_INTER | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) + +#define G_RM_AA_SUB_SURF \ + ( \ + AA_EN | IM_RD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_SUB_SURF2 \ + ( \ + AA_EN | IM_RD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_SUB_SURF \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) +#define G_RM_AA_ZB_SUB_SURF2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) \ + ) + +#define G_RM_PCL_SURF \ + ( \ + G_AC_DITHER | CVG_DST_FULL | ZMODE_OPA | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) +#define G_RM_PCL_SURF2 \ + ( \ + G_AC_DITHER | CVG_DST_FULL | ZMODE_OPA | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) +#define G_RM_AA_PCL_SURF \ + ( \ + G_AC_DITHER | AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_PCL_SURF2 \ + ( \ + G_AC_DITHER | AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_ZB_PCL_SURF \ + ( \ + G_AC_DITHER | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | \ + GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) +#define G_RM_ZB_PCL_SURF2 \ + ( \ + G_AC_DITHER | Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | \ + GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) +#define G_RM_AA_ZB_PCL_SURF \ + ( \ + G_AC_DITHER | AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_PCL_SURF2 \ + ( \ + G_AC_DITHER | AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_AA_OPA_TERR \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_OPA_TERR2 \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_OPA_TERR \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_OPA_TERR2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_AA_TEX_TERR \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_TEX_TERR2 \ + ( \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_TEX_TERR \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_TEX_TERR2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_AA_SUB_TERR \ + ( \ + AA_EN | IM_RD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_SUB_TERR2 \ + ( \ + AA_EN | IM_RD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_SUB_TERR \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_ZB_SUB_TERR2 \ + ( \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | ZMODE_OPA | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_CLD_SURF \ + ( \ + IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_CLD_SURF2 \ + ( \ + IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_ZB_CLD_SURF \ + ( \ + Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_XLU | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_ZB_CLD_SURF2 \ + ( \ + Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_XLU | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_ZB_OVL_SURF \ + ( \ + Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_DEC | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_ZB_OVL_SURF2 \ + ( \ + Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_DEC | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) + +#define G_RM_ADD \ + ( \ + IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_1) \ + ) +#define G_RM_ADD2 \ + ( \ + IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_1) \ + ) + +#define G_RM_FOG_SHADE_A \ + GBL_c1(G_BL_CLR_FOG, G_BL_A_SHADE, G_BL_CLR_IN, G_BL_1MA) + +#define G_RM_FOG_PRIM_A \ + GBL_c1(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_IN, G_BL_1MA) + +#define G_RM_PASS \ + GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + +#define G_RM_VISCVG \ + ( \ + IM_RD | FORCE_BL | \ + GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_BL, G_BL_A_MEM) \ + ) +#define G_RM_VISCVG2 \ + ( \ + IM_RD | FORCE_BL | \ + GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_BL, G_BL_A_MEM) \ + ) + +#define G_RM_OPA_CI \ + ( \ + CVG_DST_CLAMP | ZMODE_OPA | \ + GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) +#define G_RM_OPA_CI2 \ + ( \ + CVG_DST_CLAMP | ZMODE_OPA | \ + GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) \ + ) + +#define G_RM_NOOP GBL_c1(0, 0, 0, 0) +#define G_RM_NOOP2 GBL_c2(0, 0, 0, 0) + +#define G_RM_SPRITE G_RM_OPA_SURF +#define G_RM_SPRITE2 G_RM_OPA_SURF2 +#define G_RM_RA_SPRITE \ + ( \ + AA_EN | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | \ + GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_RA_SPRITE2 \ + ( \ + AA_EN | CVG_DST_CLAMP | ZMODE_OPA | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | \ + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) \ + ) +#define G_RM_AA_SPRITE G_RM_AA_TEX_TERR +#define G_RM_AA_SPRITE2 G_RM_AA_TEX_TERR2 +#define G_RM_XLU_SPRITE G_RM_XLU_SURF +#define G_RM_XLU_SPRITE2 G_RM_XLU_SURF2 +#define G_RM_AA_XLU_SPRITE G_RM_AA_XLU_SURF +#define G_RM_AA_XLU_SPRITE2 G_RM_AA_XLU_SURF2 + +#define G_OBJRM_NOTXCLAMP (gI_(0b1) << 0) +#define G_OBJRM_XLU (gI_(0b1) << 1) +#define G_OBJRM_ANTIALIAS (gI_(0b1) << 2) +#define G_OBJRM_BILERP (gI_(0b1) << 3) +#define G_OBJRM_SHRINKSIZE_1 (gI_(0b1) << 4) +#define G_OBJRM_SHRINKSIZE_2 (gI_(0b1) << 5) +#define G_OBJRM_WIDEN (gI_(0b1) << 6) + +/* othermode hi */ +#define G_MDSFT_ALPHADITHER 4 +#define G_MDSFT_RGBDITHER 6 +#define G_MDSFT_COMBKEY 8 +#define G_MDSFT_TEXTCONV 9 +#define G_MDSFT_TEXTFILT 12 +#define G_MDSFT_TEXTLUT 14 +#define G_MDSFT_TEXTLOD 16 +#define G_MDSFT_TEXTDETAIL 17 +#define G_MDSFT_TEXTPERSP 19 +#define G_MDSFT_CYCLETYPE 20 +#define G_MDSFT_PIPELINE 23 +#define G_MDSIZ_ALPHADITHER 2 +#define G_MDSIZ_RGBDITHER 2 +#define G_MDSIZ_COMBKEY 1 +#define G_MDSIZ_TEXTCONV 3 +#define G_MDSIZ_TEXTFILT 2 +#define G_MDSIZ_TEXTLUT 2 +#define G_MDSIZ_TEXTLOD 1 +#define G_MDSIZ_TEXTDETAIL 2 +#define G_MDSIZ_TEXTPERSP 1 +#define G_MDSIZ_CYCLETYPE 2 +#define G_MDSIZ_PIPELINE 1 + +#define G_AD_PATTERN (gI_(0b00) << G_MDSFT_ALPHADITHER) +#define G_AD_NOTPATTERN (gI_(0b01) << G_MDSFT_ALPHADITHER) +#define G_AD_NOISE (gI_(0b10) << G_MDSFT_ALPHADITHER) +#define G_AD_DISABLE (gI_(0b11) << G_MDSFT_ALPHADITHER) +#define G_CD_MAGICSQ (gI_(0b00) << G_MDSFT_RGBDITHER) +#define G_CD_BAYER (gI_(0b01) << G_MDSFT_RGBDITHER) +#define G_CD_NOISE (gI_(0b10) << G_MDSFT_RGBDITHER) +#define G_CD_DISABLE (gI_(0b11) << G_MDSFT_RGBDITHER) +#define G_CD_ENABLE (gI_(0b10) << G_MDSFT_RGBDITHER) +#define G_CK_NONE (gI_(0b0) << G_MDSFT_COMBKEY) +#define G_CK_KEY (gI_(0b1) << G_MDSFT_COMBKEY) +#define G_TC_CONV (gI_(0b000) << G_MDSFT_TEXTCONV) +#define G_TC_FILTCONV (gI_(0b101) << G_MDSFT_TEXTCONV) +#define G_TC_FILT (gI_(0b110) << G_MDSFT_TEXTCONV) +#define G_TF_POINT (gI_(0b00) << G_MDSFT_TEXTFILT) +#define G_TF_BILERP (gI_(0b10) << G_MDSFT_TEXTFILT) +#define G_TF_AVERAGE (gI_(0b11) << G_MDSFT_TEXTFILT) +#define G_TT_NONE (gI_(0b00) << G_MDSFT_TEXTLUT) +#define G_TT_RGBA16 (gI_(0b10) << G_MDSFT_TEXTLUT) +#define G_TT_IA16 (gI_(0b11) << G_MDSFT_TEXTLUT) +#define G_TL_TILE (gI_(0b0) << G_MDSFT_TEXTLOD) +#define G_TL_LOD (gI_(0b1) << G_MDSFT_TEXTLOD) +#define G_TD_CLAMP (gI_(0b00) << G_MDSFT_TEXTDETAIL) +#define G_TD_SHARPEN (gI_(0b01) << G_MDSFT_TEXTDETAIL) +#define G_TD_DETAIL (gI_(0b10) << G_MDSFT_TEXTDETAIL) +#define G_TP_NONE (gI_(0b0) << G_MDSFT_TEXTPERSP) +#define G_TP_PERSP (gI_(0b1) << G_MDSFT_TEXTPERSP) +#define G_CYC_1CYCLE (gI_(0b00) << G_MDSFT_CYCLETYPE) +#define G_CYC_2CYCLE (gI_(0b01) << G_MDSFT_CYCLETYPE) +#define G_CYC_COPY (gI_(0b10) << G_MDSFT_CYCLETYPE) +#define G_CYC_FILL (gI_(0b11) << G_MDSFT_CYCLETYPE) +#define G_PM_NPRIMITIVE (gI_(0b0) << G_MDSFT_PIPELINE) +#define G_PM_1PRIMITIVE (gI_(0b1) << G_MDSFT_PIPELINE) + +/* color conversion constants */ +#define G_CV_K0 (175) +#define G_CV_K1 (-43) +#define G_CV_K2 (-89) +#define G_CV_K3 (222) +#define G_CV_K4 (114) +#define G_CV_K5 (42) + +/* color combiner */ +#define G_CCMUX_COMBINED 0 +#define G_CCMUX_TEXEL0 1 +#define G_CCMUX_TEXEL1 2 +#define G_CCMUX_PRIMITIVE 3 +#define G_CCMUX_SHADE 4 +#define G_CCMUX_ENVIRONMENT 5 +#define G_CCMUX_1 6 +#define G_CCMUX_NOISE 7 +#define G_CCMUX_0 31 +#define G_CCMUX_CENTER 6 +#define G_CCMUX_K4 7 +#define G_CCMUX_SCALE 6 +#define G_CCMUX_COMBINED_ALPHA 7 +#define G_CCMUX_TEXEL0_ALPHA 8 +#define G_CCMUX_TEXEL1_ALPHA 9 +#define G_CCMUX_PRIMITIVE_ALPHA 10 +#define G_CCMUX_SHADE_ALPHA 11 +#define G_CCMUX_ENV_ALPHA 12 +#define G_CCMUX_LOD_FRACTION 13 +#define G_CCMUX_PRIM_LOD_FRAC 14 +#define G_CCMUX_K5 15 +#define G_ACMUX_COMBINED 0 +#define G_ACMUX_TEXEL0 1 +#define G_ACMUX_TEXEL1 2 +#define G_ACMUX_PRIMITIVE 3 +#define G_ACMUX_SHADE 4 +#define G_ACMUX_ENVIRONMENT 5 +#define G_ACMUX_1 6 +#define G_ACMUX_0 7 +#define G_ACMUX_LOD_FRACTION 0 +#define G_ACMUX_PRIM_LOD_FRAC 6 + +/* + * combine modes + * ( A - B ) * C + D +*/ +#define G_CC_MODULATEI \ + TEXEL0, 0, SHADE, 0, \ + 0, 0, 0, SHADE +#define G_CC_MODULATEIA \ + TEXEL0, 0, SHADE, 0, \ + TEXEL0, 0, SHADE, 0 +#define G_CC_MODULATEIDECALA \ + TEXEL0, 0, SHADE, 0, \ + 0, 0, 0, TEXEL0 +#define G_CC_MODULATERGB \ + G_CC_MODULATEI +#define G_CC_MODULATERGBA \ + G_CC_MODULATEIA +#define G_CC_MODULATERGBDECALA \ + G_CC_MODULATEIDECALA +#define G_CC_MODULATEI_PRIM \ + TEXEL0, 0, PRIMITIVE, 0, \ + 0, 0, 0, PRIMITIVE +#define G_CC_MODULATEIA_PRIM \ + TEXEL0, 0, PRIMITIVE, 0, \ + TEXEL0, 0, PRIMITIVE, 0 +#define G_CC_MODULATEIDECALA_PRIM \ + TEXEL0, 0, PRIMITIVE, 0, \ + 0, 0, 0, TEXEL0 +#define G_CC_MODULATERGB_PRIM \ + G_CC_MODULATEI_PRIM +#define G_CC_MODULATERGBA_PRIM \ + G_CC_MODULATEIA_PRIM +#define G_CC_MODULATERGBDECALA_PRIM \ + G_CC_MODULATEIDECALA_PRIM +#define G_CC_DECALRGB \ + 0, 0, 0, TEXEL0, \ + 0, 0, 0, SHADE +#define G_CC_DECALRGBA \ + 0, 0, 0, TEXEL0, \ + 0, 0, 0, TEXEL0 +#define G_CC_BLENDI \ + ENVIRONMENT, SHADE, TEXEL0, SHADE, \ + 0, 0, 0, SHADE +#define G_CC_BLENDIA \ + ENVIRONMENT, SHADE, TEXEL0, SHADE, \ + TEXEL0, 0, SHADE, 0 +#define G_CC_BLENDIDECALA \ + ENVIRONMENT, SHADE, TEXEL0, SHADE, \ + 0, 0, 0, TEXEL0 +#define G_CC_BLENDRGBA \ + TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, \ + 0, 0, 0, SHADE +#define G_CC_BLENDRGBDECALA \ + TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, \ + 0, 0, 0, TEXEL0 +#define G_CC_REFLECTRGB \ + ENVIRONMENT, 0, TEXEL0, SHADE, \ + 0, 0, 0, SHADE +#define G_CC_REFLECTRGBDECALA \ + ENVIRONMENT, 0, TEXEL0, SHADE, \ + 0, 0, 0, TEXEL0 +#define G_CC_HILITERGB \ + PRIMITIVE, SHADE, TEXEL0, SHADE, \ + 0, 0, 0, SHADE +#define G_CC_HILITERGBA \ + PRIMITIVE, SHADE, TEXEL0, SHADE, \ + PRIMITIVE, SHADE, TEXEL0, SHADE +#define G_CC_HILITERGBDECALA \ + PRIMITIVE, SHADE, TEXEL0, SHADE, \ + 0, 0, 0, TEXEL0 +#define G_CC_1CYUV2RGB \ + TEXEL0, K4, K5, TEXEL0, \ + 0, 0, 0, SHADE +#define G_CC_PRIMITIVE \ + 0, 0, 0, PRIMITIVE, \ + 0, 0, 0, PRIMITIVE +#define G_CC_SHADE \ + 0, 0, 0, SHADE, \ + 0, 0, 0, SHADE +#define G_CC_ADDRGB \ + 1, 0, TEXEL0, SHADE, \ + 0, 0, 0, SHADE +#define G_CC_ADDRGBDECALA \ + 1, 0, TEXEL0, SHADE, \ + 0, 0, 0, TEXEL0 +#define G_CC_SHADEDECALA \ + 0, 0, 0, SHADE, \ + 0, 0, 0, TEXEL0 +#define G_CC_BLENDPE \ + PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, \ + TEXEL0, 0, SHADE, 0 +#define G_CC_BLENDPEDECALA \ + PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, \ + 0, 0, 0, TEXEL0 +#define G_CC_TRILERP \ + TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0, \ + TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0 +#define G_CC_TEMPLERP \ + TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, \ + TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0 +#define G_CC_INTERFERENCE \ + TEXEL0, 0, TEXEL1, 0, \ + TEXEL0, 0, TEXEL1, 0 +#define _G_CC_BLENDPE \ + ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, \ + TEXEL0, 0, SHADE, 0 +#define _G_CC_BLENDPEDECALA \ + ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, \ + 0, 0, 0, TEXEL0 +#define _G_CC_SPARSEST \ + PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0, \ + PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0 +#define _G_CC_TWOCOLORTEX \ + PRIMITIVE, SHADE, TEXEL0, SHADE, \ + 0, 0, 0, SHADE +#define G_CC_MODULATEI2 \ + COMBINED, 0, SHADE, 0, \ + 0, 0, 0, SHADE +#define G_CC_MODULATEIA2 \ + COMBINED, 0, SHADE, 0, \ + COMBINED, 0, SHADE, 0 +#define G_CC_MODULATERGB2 \ + G_CC_MODULATEI2 +#define G_CC_MODULATERGBA2 \ + G_CC_MODULATEIA2 +#define G_CC_MODULATEI_PRIM2 \ + COMBINED, 0, PRIMITIVE, 0, \ + 0, 0, 0, PRIMITIVE +#define G_CC_MODULATEIA_PRIM2 \ + COMBINED, 0, PRIMITIVE, 0, \ + COMBINED, 0, PRIMITIVE, 0 +#define G_CC_MODULATERGB_PRIM2 \ + G_CC_MODULATEI_PRIM2 +#define G_CC_MODULATERGBA_PRIM2 \ + G_CC_MODULATEIA_PRIM2 +#define G_CC_DECALRGB2 \ + 0, 0, 0, COMBINED, \ + 0, 0, 0, SHADE +#define G_CC_BLENDI2 \ + ENVIRONMENT, SHADE, COMBINED, SHADE, \ + 0, 0, 0, SHADE +#define G_CC_BLENDIA2 \ + ENVIRONMENT, SHADE, COMBINED, SHADE, \ + COMBINED, 0, SHADE, 0 +#define G_CC_HILITERGB2 \ + ENVIRONMENT, COMBINED, TEXEL0, COMBINED, \ + 0, 0, 0, SHADE +#define G_CC_HILITERGBA2 \ + ENVIRONMENT, COMBINED, TEXEL0, COMBINED, \ + ENVIRONMENT, COMBINED, TEXEL0, COMBINED +#define G_CC_HILITERGBDECALA2 \ + ENVIRONMENT, COMBINED, TEXEL0, COMBINED, \ + 0, 0, 0, TEXEL0 +#define G_CC_HILITERGBPASSA2 \ + ENVIRONMENT, COMBINED, TEXEL0, COMBINED, \ + 0, 0, 0, COMBINED +#define G_CC_CHROMA_KEY2 \ + TEXEL0, CENTER, SCALE, 0, \ + 0, 0, 0, 0 +#define G_CC_YUV2RGB \ + TEXEL1, K4, K5, TEXEL1, \ + 0, 0, 0, 0 +#define G_CC_PASS2 \ + 0, 0, 0, COMBINED, \ + 0, 0, 0, COMBINED +#define G_CC_LERP(a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ + a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ + ( \ + gFL_(G_CCMUX_##a0, 4, 52) | \ + gFL_(G_CCMUX_##c0, 5, 47) | \ + gFL_(G_ACMUX_##Aa0, 3, 44) | \ + gFL_(G_ACMUX_##Ac0, 3, 41) | \ + gFL_(G_CCMUX_##a1, 4, 37) | \ + gFL_(G_CCMUX_##c1, 5, 32) | \ + gFL_(G_CCMUX_##b0, 4, 28) | \ + gFL_(G_CCMUX_##b1, 4, 24) | \ + gFL_(G_ACMUX_##Aa1, 3, 21) | \ + gFL_(G_ACMUX_##Ac1, 3, 18) | \ + gFL_(G_CCMUX_##d0, 3, 15) | \ + gFL_(G_ACMUX_##Ab0, 3, 12) | \ + gFL_(G_ACMUX_##Ad0, 3, 9) | \ + gFL_(G_CCMUX_##d1, 3, 6) | \ + gFL_(G_ACMUX_##Ab1, 3, 3) | \ + gFL_(G_ACMUX_##Ad1, 3, 0) \ + ) +#define G_CC_MODE(mode1, mode2) G_CC_LERP(mode1, mode2) + +/* scissor modes */ +#define G_SC_NON_INTERLACE gI_(0b00) +#define G_SC_EVEN_INTERLACE gI_(0b10) +#define G_SC_ODD_INTERLACE gI_(0b11) + +/* display list branch flags */ +#define G_DL_PUSH gI_(0b0) +#define G_DL_NOPUSH gI_(0b1) + +/* conditional branching flags (f3dex and f3dex2) */ +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +# define G_BZ_PERSP 0 +# define G_BZ_ORTHO 1 +#endif + +/* matrix params */ +#define G_MTX_MUL (gI_(0b0) << 1) +#define G_MTX_LOAD (gI_(0b1) << 1) + +/* matrix params for fast3d and f3dex */ +#if defined(F3D_GBI) || defined(F3DEX_GBI) +# define G_MTX_MODELVIEW (gI_(0b0) << 0) +# define G_MTX_PROJECTION (gI_(0b1) << 0) +# define G_MTX_NOPUSH (gI_(0b0) << 2) +# define G_MTX_PUSH (gI_(0b1) << 2) +#endif + +/* matrix params for f3dex2 */ +#if defined(F3DEX_GBI_2) +# define G_MTX_NOPUSH (gI_(0b0) << 0) +# define G_MTX_PUSH (gI_(0b1) << 0) +# define G_MTX_MODELVIEW (gI_(0b0) << 2) +# define G_MTX_PROJECTION (gI_(0b1) << 2) +#endif + +/* moveword indices */ +#define G_MW_MATRIX 0 +#define G_MW_NUMLIGHT 2 +#define G_MW_CLIP 4 +#define G_MW_SEGMENT 6 +#define G_MW_FOG 8 +#define G_MW_GENSTAT 8 +#define G_MW_LIGHTCOL 10 +#define G_MW_PERSPNORM 14 + +/* moveword indices for fast3d and f3dex */ +#if defined(F3D_GBI) || defined(F3DEX_GBI) +# define G_MW_POINTS 12 +#endif + +/* moveword indices for f3dex2 */ +#if defined(F3DEX_GBI_2) +# define G_MW_FORCEMTX 12 +#endif + +/* moveword offsets */ +#define G_MWO_NUMLIGHT gI_(0x00) +#define G_MWO_CLIP_RNX gI_(0x04) +#define G_MWO_CLIP_RNY gI_(0x0C) +#define G_MWO_CLIP_RPX gI_(0x14) +#define G_MWO_CLIP_RPY gI_(0x1C) +#define G_MWO_SEGMENT_0 gI_(0x00) +#define G_MWO_SEGMENT_1 gI_(0x04) +#define G_MWO_SEGMENT_2 gI_(0x08) +#define G_MWO_SEGMENT_3 gI_(0x0C) +#define G_MWO_SEGMENT_4 gI_(0x10) +#define G_MWO_SEGMENT_5 gI_(0x14) +#define G_MWO_SEGMENT_6 gI_(0x18) +#define G_MWO_SEGMENT_7 gI_(0x1C) +#define G_MWO_SEGMENT_8 gI_(0x20) +#define G_MWO_SEGMENT_9 gI_(0x24) +#define G_MWO_SEGMENT_A gI_(0x28) +#define G_MWO_SEGMENT_B gI_(0x2C) +#define G_MWO_SEGMENT_C gI_(0x30) +#define G_MWO_SEGMENT_D gI_(0x34) +#define G_MWO_SEGMENT_E gI_(0x38) +#define G_MWO_SEGMENT_F gI_(0x3C) +#define G_MWO_FOG gI_(0x00) +#define G_MWO_aLIGHT_1 gI_(0x00) +#define G_MWO_bLIGHT_1 gI_(0x04) +#define G_MWO_MATRIX_XX_XY_I gI_(0x00) +#define G_MWO_MATRIX_XZ_XW_I gI_(0x04) +#define G_MWO_MATRIX_YX_YY_I gI_(0x08) +#define G_MWO_MATRIX_YZ_YW_I gI_(0x0C) +#define G_MWO_MATRIX_ZX_ZY_I gI_(0x10) +#define G_MWO_MATRIX_ZZ_ZW_I gI_(0x14) +#define G_MWO_MATRIX_WX_WY_I gI_(0x18) +#define G_MWO_MATRIX_WZ_WW_I gI_(0x1C) +#define G_MWO_MATRIX_XX_XY_F gI_(0x20) +#define G_MWO_MATRIX_XZ_XW_F gI_(0x24) +#define G_MWO_MATRIX_YX_YY_F gI_(0x28) +#define G_MWO_MATRIX_YZ_YW_F gI_(0x2C) +#define G_MWO_MATRIX_ZX_ZY_F gI_(0x30) +#define G_MWO_MATRIX_ZZ_ZW_F gI_(0x34) +#define G_MWO_MATRIX_WX_WY_F gI_(0x38) +#define G_MWO_MATRIX_WZ_WW_F gI_(0x3C) +#define G_MWO_POINT_RGBA gI_(0x10) +#define G_MWO_POINT_ST gI_(0x14) +#define G_MWO_POINT_XYSCREEN gI_(0x18) +#define G_MWO_POINT_ZSCREEN gI_(0x1C) + +/* moveword offsets for fast3d and f3dex */ +#if defined(F3D_GBI) || defined(F3DEX_GBI) +# define G_MWO_aLIGHT_2 gI_(0x20) +# define G_MWO_bLIGHT_2 gI_(0x24) +# define G_MWO_aLIGHT_3 gI_(0x40) +# define G_MWO_bLIGHT_3 gI_(0x44) +# define G_MWO_aLIGHT_4 gI_(0x60) +# define G_MWO_bLIGHT_4 gI_(0x64) +# define G_MWO_aLIGHT_5 gI_(0x80) +# define G_MWO_bLIGHT_5 gI_(0x84) +# define G_MWO_aLIGHT_6 gI_(0xA0) +# define G_MWO_bLIGHT_6 gI_(0xA4) +# define G_MWO_aLIGHT_7 gI_(0xC0) +# define G_MWO_bLIGHT_7 gI_(0xC4) +# define G_MWO_aLIGHT_8 gI_(0xE0) +# define G_MWO_bLIGHT_8 gI_(0xE4) +#endif + +/* moveword offsets for f3dex2 */ +#if defined(F3DEX_GBI_2) +# define G_MWO_aLIGHT_2 gI_(0x18) +# define G_MWO_bLIGHT_2 gI_(0x1C) +# define G_MWO_aLIGHT_3 gI_(0x30) +# define G_MWO_bLIGHT_3 gI_(0x34) +# define G_MWO_aLIGHT_4 gI_(0x48) +# define G_MWO_bLIGHT_4 gI_(0x4C) +# define G_MWO_aLIGHT_5 gI_(0x60) +# define G_MWO_bLIGHT_5 gI_(0x64) +# define G_MWO_aLIGHT_6 gI_(0x78) +# define G_MWO_bLIGHT_6 gI_(0x7C) +# define G_MWO_aLIGHT_7 gI_(0x90) +# define G_MWO_bLIGHT_7 gI_(0x94) +# define G_MWO_aLIGHT_8 gI_(0xA8) +# define G_MWO_bLIGHT_8 gI_(0xAC) +#endif + +/* movemem params for fast3d and f3dex */ +#if defined(F3D_GBI) || defined(F3DEX_GBI) +# define G_MV_VIEWPORT 128 +# define G_MV_LOOKATY 130 +# define G_MV_LOOKATX 132 +# define G_MV_L0 134 +# define G_MV_L1 136 +# define G_MV_L2 138 +# define G_MV_L3 140 +# define G_MV_L4 142 +# define G_MV_L5 144 +# define G_MV_L6 146 +# define G_MV_L7 148 +# define G_MV_TXTATT 150 +# define G_MV_MATRIX_2 152 +# define G_MV_MATRIX_3 154 +# define G_MV_MATRIX_4 156 +# define G_MV_MATRIX_1 158 +#endif + +/* movemem params for f3dex2 */ +#if defined(F3DEX_GBI_2) +# define G_MV_MMTX 2 +# define G_MV_PMTX 6 +# define G_MV_VIEWPORT 8 +# define G_MV_LIGHT 10 +# define G_MV_POINT 12 +# define G_MV_MATRIX 14 +# define G_MVO_LOOKATX gI_(0 * 0x18) +# define G_MVO_LOOKATY gI_(1 * 0x18) +# define G_MVO_L0 gI_(2 * 0x18) +# define G_MVO_L1 gI_(3 * 0x18) +# define G_MVO_L2 gI_(4 * 0x18) +# define G_MVO_L3 gI_(5 * 0x18) +# define G_MVO_L4 gI_(6 * 0x18) +# define G_MVO_L5 gI_(7 * 0x18) +# define G_MVO_L6 gI_(8 * 0x18) +# define G_MVO_L7 gI_(9 * 0x18) +#endif + +/* frustum ratios */ +#define FRUSTRATIO_1 gI_(1) +#define FRUSTRATIO_2 gI_(2) +#define FRUSTRATIO_3 gI_(3) +#define FRUSTRATIO_4 gI_(4) +#define FRUSTRATIO_5 gI_(5) +#define FRUSTRATIO_6 gI_(6) + +/* light params */ +#define NUMLIGHTS_0 1 +#define NUMLIGHTS_1 1 +#define NUMLIGHTS_2 2 +#define NUMLIGHTS_3 3 +#define NUMLIGHTS_4 4 +#define NUMLIGHTS_5 5 +#define NUMLIGHTS_6 6 +#define NUMLIGHTS_7 7 +#define LIGHT_1 1 +#define LIGHT_2 2 +#define LIGHT_3 3 +#define LIGHT_4 4 +#define LIGHT_5 5 +#define LIGHT_6 6 +#define LIGHT_7 7 +#define LIGHT_8 8 + +/* light params for fast3d and f3dex */ +#if defined(F3D_GBI) || defined(F3DEX_GBI) +# define NUML(n) (((n) + 1) * 32 + 0x80000000) +#endif + +/* light params for f3dex2 */ +#if defined(F3DEX_GBI_2) +# define NUML(n) ((n) * 0x18) +#endif + +/* background load types */ +#define G_BGLT_LOADBLOCK gI_(0x0033) +#define G_BGLT_LOADTILE gI_(0xFFF4) + +/* background flags */ +#define G_BG_FLAG_FLIPS (gI_(0b1) << 0) +#define G_BG_FLAG_FLIPT (gI_(0b1) << 1) + +/* object load types */ +#define G_OBJLT_TXTRBLOCK gI_(0x00001033) +#define G_OBJLT_TXTRTILE gI_(0x00FC1034) +#define G_OBJLT_TLUT gI_(0x00000030) + +/* object flags */ +#define G_OBJ_FLAG_FLIPS (gI_(0b1) << 0) +#define G_OBJ_FLAG_FLIPT (gI_(0b1) << 4) + +/* color macros */ +#define G_MAXZ 0x03FF +#define G_MAXFBZ 0x3FFF +#define GPACK_RGBA5551(r, g, b, a) \ + ( \ + gF_(r, 5, 11) | \ + gF_(g, 5, 6) | \ + gF_(b, 5, 1) | \ + gF_(a, 1, 0) \ + ) +#define GPACK_RGBA8888(r, g, b, a) \ + ( \ + gF_(r, 8, 24) | \ + gF_(g, 8, 16) | \ + gF_(b, 8, 8) | \ + gF_(a, 8, 0) \ + ) +#define GPACK_RGB24A8(rgb, a) (gF_(rgb, 24, 8) | gF_(a, 8, 0)) +#define GPACK_ZDZ(z, dz) (gF_(z, 14, 2) | gF_(dz, 2, 0)) + +/* structure definition macros */ +#define gdSPDefMtx(xx, xy, xz, xw, \ + yx, yy, yz, yw, \ + zx, zy, zz, zw, \ + wx, wy, wz, ww) \ + ( \ + (Mtx) \ + { \ + .i = \ + { \ + (qs1616(xx) >> 16) & 0xFFFF, \ + (qs1616(xy) >> 16) & 0xFFFF, \ + (qs1616(xz) >> 16) & 0xFFFF, \ + (qs1616(xw) >> 16) & 0xFFFF, \ + (qs1616(yx) >> 16) & 0xFFFF, \ + (qs1616(yy) >> 16) & 0xFFFF, \ + (qs1616(yz) >> 16) & 0xFFFF, \ + (qs1616(yw) >> 16) & 0xFFFF, \ + (qs1616(zx) >> 16) & 0xFFFF, \ + (qs1616(zy) >> 16) & 0xFFFF, \ + (qs1616(zz) >> 16) & 0xFFFF, \ + (qs1616(zw) >> 16) & 0xFFFF, \ + (qs1616(wx) >> 16) & 0xFFFF, \ + (qs1616(wy) >> 16) & 0xFFFF, \ + (qs1616(wz) >> 16) & 0xFFFF, \ + (qs1616(ww) >> 16) & 0xFFFF, \ + }, \ + .f = \ + { \ + qs1616(xx) & 0xFFFF, \ + qs1616(xy) & 0xFFFF, \ + qs1616(xz) & 0xFFFF, \ + qs1616(xw) & 0xFFFF, \ + qs1616(yx) & 0xFFFF, \ + qs1616(yy) & 0xFFFF, \ + qs1616(yz) & 0xFFFF, \ + qs1616(yw) & 0xFFFF, \ + qs1616(zx) & 0xFFFF, \ + qs1616(zy) & 0xFFFF, \ + qs1616(zz) & 0xFFFF, \ + qs1616(zw) & 0xFFFF, \ + qs1616(wx) & 0xFFFF, \ + qs1616(wy) & 0xFFFF, \ + qs1616(wz) & 0xFFFF, \ + qs1616(ww) & 0xFFFF, \ + } \ + } \ + ) +#define gdSPDefLookAt(rx, ry, rz, ux, uy, uz) \ + ( \ + (LookAt) \ + { \ + .l[0].l = \ + { \ + .col = {0, 0, 0}, \ + .colc = {0, 0, 0}, \ + .dir = {rx, ry, rz}, \ + }, \ + .l[1].l = \ + { \ + .col = {0, 0x80, 0}, \ + .colc = {0, 0x80, 0}, \ + .dir = {ux, uy, uz}, \ + }, \ + } \ + ) +#define gdSPDefLights0(ar, ag, ab) \ + ( \ + (Lights0) \ + { \ + .a.l = \ + { \ + .col = {ar, ag, ab}, \ + .colc = {ar, ag, ab}, \ + }, \ + .l[0].l = \ + { \ + } \ + } \ + ) +#define gdSPDefLights1(ar, ag, ab, \ + r1, g1, b1, x1, y1, z1) \ + ( \ + (Lights1) \ + { \ + .a.l = \ + { \ + .col = {ar, ag, ab}, \ + .colc = {ar, ag, ab}, \ + }, \ + .l[0].l = \ + { \ + .col = {r1, g1, b1}, \ + .colc = {r1, g1, b1}, \ + .dir = {x1, y1, z1}, \ + } \ + } \ + ) +#define gdSPDefLights2(ar, ag, ab, \ + r1, g1, b1, x1, y1, z1, \ + r2, g2, b2, x2, y2, z2) \ + ( \ + (Lights2) \ + { \ + .a.l = \ + { \ + .col = {ar, ag, ab}, \ + .colc = {ar, ag, ab}, \ + }, \ + .l[0].l = \ + { \ + .col = {r1, g1, b1}, \ + .colc = {r1, g1, b1}, \ + .dir = {x1, y1, z1}, \ + } \ + .l[1].l = \ + { \ + .col = {r2, g2, b2}, \ + .colc = {r2, g2, b2}, \ + .dir = {x2, y2, z2}, \ + } \ + } \ + ) +#define gdSPDefLights3(ar, ag, ab, \ + r1, g1, b1, x1, y1, z1, \ + r2, g2, b2, x2, y2, z2, \ + r3, g3, b3, x3, y3, z3) \ + ( \ + (Lights3) \ + { \ + .a.l = \ + { \ + .col = {ar, ag, ab}, \ + .colc = {ar, ag, ab}, \ + }, \ + .l[0].l = \ + { \ + .col = {r1, g1, b1}, \ + .colc = {r1, g1, b1}, \ + .dir = {x1, y1, z1}, \ + } \ + .l[1].l = \ + { \ + .col = {r2, g2, b2}, \ + .colc = {r2, g2, b2}, \ + .dir = {x2, y2, z2}, \ + } \ + .l[2].l = \ + { \ + .col = {r3, g3, b3}, \ + .colc = {r3, g3, b3}, \ + .dir = {x3, y3, z3}, \ + } \ + } \ + ) +#define gdSPDefLights4(ar, ag, ab, \ + r1, g1, b1, x1, y1, z1, \ + r2, g2, b2, x2, y2, z2, \ + r3, g3, b3, x3, y3, z3, \ + r4, g4, b4, x4, y4, z4) \ + ( \ + (Lights4) \ + { \ + .a.l = \ + { \ + .col = {ar, ag, ab}, \ + .colc = {ar, ag, ab}, \ + }, \ + .l[0].l = \ + { \ + .col = {r1, g1, b1}, \ + .colc = {r1, g1, b1}, \ + .dir = {x1, y1, z1}, \ + } \ + .l[1].l = \ + { \ + .col = {r2, g2, b2}, \ + .colc = {r2, g2, b2}, \ + .dir = {x2, y2, z2}, \ + } \ + .l[2].l = \ + { \ + .col = {r3, g3, b3}, \ + .colc = {r3, g3, b3}, \ + .dir = {x3, y3, z3}, \ + } \ + .l[3].l = \ + { \ + .col = {r4, g4, b4}, \ + .colc = {r4, g4, b4}, \ + .dir = {x4, y4, z4}, \ + } \ + } \ + ) +#define gdSPDefLights5(ar, ag, ab, \ + r1, g1, b1, x1, y1, z1, \ + r2, g2, b2, x2, y2, z2, \ + r3, g3, b3, x3, y3, z3, \ + r4, g4, b4, x4, y4, z4, \ + r5, g5, b5, x5, y5, z5) \ + ( \ + (Lights5) \ + { \ + .a.l = \ + { \ + .col = {ar, ag, ab}, \ + .colc = {ar, ag, ab}, \ + }, \ + .l[0].l = \ + { \ + .col = {r1, g1, b1}, \ + .colc = {r1, g1, b1}, \ + .dir = {x1, y1, z1}, \ + } \ + .l[1].l = \ + { \ + .col = {r2, g2, b2}, \ + .colc = {r2, g2, b2}, \ + .dir = {x2, y2, z2}, \ + } \ + .l[2].l = \ + { \ + .col = {r3, g3, b3}, \ + .colc = {r3, g3, b3}, \ + .dir = {x3, y3, z3}, \ + } \ + .l[3].l = \ + { \ + .col = {r4, g4, b4}, \ + .colc = {r4, g4, b4}, \ + .dir = {x4, y4, z4}, \ + } \ + .l[4].l = \ + { \ + .col = {r5, g5, b5}, \ + .colc = {r5, g5, b5}, \ + .dir = {x5, y5, z5}, \ + } \ + } \ + ) +#define gdSPDefLights6(ar, ag, ab, \ + r1, g1, b1, x1, y1, z1, \ + r2, g2, b2, x2, y2, z2, \ + r3, g3, b3, x3, y3, z3, \ + r4, g4, b4, x4, y4, z4, \ + r5, g5, b5, x5, y5, z5, \ + r6, g6, b6, x6, y6, z6)\ + ( \ + (Lights6) \ + { \ + .a.l = \ + { \ + .col = {ar, ag, ab}, \ + .colc = {ar, ag, ab}, \ + }, \ + .l[0].l = \ + { \ + .col = {r1, g1, b1}, \ + .colc = {r1, g1, b1}, \ + .dir = {x1, y1, z1}, \ + } \ + .l[1].l = \ + { \ + .col = {r2, g2, b2}, \ + .colc = {r2, g2, b2}, \ + .dir = {x2, y2, z2}, \ + } \ + .l[2].l = \ + { \ + .col = {r3, g3, b3}, \ + .colc = {r3, g3, b3}, \ + .dir = {x3, y3, z3}, \ + } \ + .l[3].l = \ + { \ + .col = {r4, g4, b4}, \ + .colc = {r4, g4, b4}, \ + .dir = {x4, y4, z4}, \ + } \ + .l[4].l = \ + { \ + .col = {r5, g5, b5}, \ + .colc = {r5, g5, b5}, \ + .dir = {x5, y5, z5}, \ + } \ + .l[5].l = \ + { \ + .col = {r6, g6, b6}, \ + .colc = {r6, g6, b6}, \ + .dir = {x6, y6, z6}, \ + } \ + } \ + ) +#define gdSPDefLights7(ar, ag, ab, \ + r1, g1, b1, x1, y1, z1, \ + r2, g2, b2, x2, y2, z2, \ + r3, g3, b3, x3, y3, z3, \ + r4, g4, b4, x4, y4, z4, \ + r5, g5, b5, x5, y5, z5, \ + r6, g6, b6, x6, y6, z6, \ + r7, g7, b7, x7, y7, z7) \ + ( \ + (Lights7) \ + { \ + .a.l = \ + { \ + .col = {ar, ag, ab}, \ + .colc = {ar, ag, ab}, \ + }, \ + .l[0].l = \ + { \ + .col = {r1, g1, b1}, \ + .colc = {r1, g1, b1}, \ + .dir = {x1, y1, z1}, \ + } \ + .l[1].l = \ + { \ + .col = {r2, g2, b2}, \ + .colc = {r2, g2, b2}, \ + .dir = {x2, y2, z2}, \ + } \ + .l[2].l = \ + { \ + .col = {r3, g3, b3}, \ + .colc = {r3, g3, b3}, \ + .dir = {x3, y3, z3}, \ + } \ + .l[3].l = \ + { \ + .col = {r4, g4, b4}, \ + .colc = {r4, g4, b4}, \ + .dir = {x4, y4, z4}, \ + } \ + .l[4].l = \ + { \ + .col = {r5, g5, b5}, \ + .colc = {r5, g5, b5}, \ + .dir = {x5, y5, z5}, \ + } \ + .l[5].l = \ + { \ + .col = {r6, g6, b6}, \ + .colc = {r6, g6, b6}, \ + .dir = {x6, y6, z6}, \ + } \ + .l[6].l = \ + { \ + .col = {r7, g7, b7}, \ + .colc = {r7, g7, b7}, \ + .dir = {x7, y7, z7}, \ + } \ + } \ + ) +#define gdSPDefVtx(x, y, z, s, t) \ + ( \ + (Vtx) \ + { \ + .v = \ + { \ + .ob = {x, y, z}, \ + .tc = {qs105(s), qs105(t)}, \ + } \ + } \ + ) +#define gdSPDefVtxC(x, y, z, s, t, cr, cg, cb, ca) \ + ( \ + (Vtx) \ + { \ + .v = \ + { \ + .ob = {x, y, z}, \ + .tc = {qs105(s), qs105(t)}, \ + .cn = {cr, cg, cb, ca}, \ + } \ + } \ + ) +#define gdSPDefVtxN(x, y, z, s, t, nx, ny, nz, ca) \ + ( \ + (Vtx) \ + { \ + .n = \ + { \ + .ob = {x, y, z}, \ + .tc = {qs105(s), qs105(t)}, \ + .n = {nx, ny, nz}, \ + .a = ca \ + } \ + } \ + ) + +/* instruction macros */ + +#define gsDPFillRectangle(ulx, uly, lrx, lry) \ + gO_( \ + G_FILLRECT, \ + gF_(lrx, 10, 14) | \ + gF_(lry, 10, 2), \ + gF_(ulx, 10, 14) | \ + gF_(uly, 10, 2)) + +#define gsDPScisFillRectangle(ulx, uly, lrx, lry) \ + gsDPFillRectangle(gScC_(ulx), gScC_(uly), gScC_(lrx), gScC_(lry)) + +#define gsDPFullSync() \ + gO_(G_RDPFULLSYNC, 0, 0) + +#define gsDPLoadSync() \ + gO_(G_RDPLOADSYNC, 0, 0) + +#define gsDPTileSync() \ + gO_(G_RDPTILESYNC, 0, 0) + +#define gsDPPipeSync() \ + gO_(G_RDPPIPESYNC, 0, 0) + +#define gsDPLoadTLUT_pal16(pal, dram) \ + gsDPLoadTLUT(16, 256 + (gI_(pal) & 0xF) * 16, dram) + +#define gsDPLoadTLUT_pal256(dram) \ + gsDPLoadTLUT(256, 256, dram) + +#define gLTB_(timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + dxt, tmem, rt, line) \ + gsDPSetTextureImage(fmt, G_SIZ_LDSIZ(siz), 1, timg), \ + gsDPSetTile( \ + fmt, G_SIZ_LDSIZ(siz), 0, tmem, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock( \ + G_TX_LOADTILE, 0, 0, \ + (((width) * (height) + 1) * G_SIZ_BITS(siz) - 1) / \ + G_SIZ_BITS(G_SIZ_LDSIZ(siz)) - 1, \ + dxt), \ + gsDPPipeSync(), \ + gsDPSetTile( \ + fmt, siz, line, tmem, rt, pal, \ + cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPSetTileSize(rt, 0, 0, qu102((width) - 1), qu102((height) - 1)) + +#define gsDPLoadTextureBlock(timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + G_DXT(siz, width), 0x0, G_TX_RENDERTILE, \ + ((width) * G_SIZ_LDBITS(siz) + 63) / 64) + +#define gsDPLoadTextureBlockS(timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0, 0x0, G_TX_RENDERTILE, \ + ((width) * G_SIZ_LDBITS(siz) + 63) / 64) + +#define gsDPLoadTextureBlock_4b(timg, fmt, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, G_IM_SIZ_4b, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + G_DXT(G_IM_SIZ_4b, width), 0x0, G_TX_RENDERTILE, \ + ((width) * 4 + 63) / 64) + +#define gsDPLoadTextureBlock_4bS(timg, fmt, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, G_IM_SIZ_4b, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0, 0x0, G_TX_RENDERTILE, \ + ((width) * 4 + 63) / 64) + +#define gsDPLoadTextureBlockYuv(timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + G_DXT(siz, width), 0x0, G_TX_RENDERTILE, \ + ((width) + 7) / 8) + +#define gsDPLoadTextureBlockYuvS(timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0, 0x0, G_TX_RENDERTILE, \ + ((width) + 7) / 8) + +#define _gsDPLoadTextureBlock(timg, tmem, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + G_DXT(siz, width), tmem, G_TX_RENDERTILE, \ + ((width) * G_SIZ_LDBITS(siz) + 63) / 64) + +#define _gsDPLoadTextureBlockS(timg, tmem, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0, tmem, G_TX_RENDERTILE, \ + ((width) * G_SIZ_LDBITS(siz) + 63) / 64) + +#define _gsDPLoadTextureBlock_4b(timg, tmem, fmt, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, G_IM_SIZ_4b, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + G_DXT(G_IM_SIZ_4b, width), tmem, G_TX_RENDERTILE, \ + ((width) * 4 + 63) / 64) + +#define _gsDPLoadTextureBlock_4bS(timg, tmem, fmt, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, G_IM_SIZ_4b, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0, tmem, G_TX_RENDERTILE, \ + ((width) * 4 + 63) / 64) + +#define _gsDPLoadTextureBlockYuv(timg, tmem, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + G_DXT(siz, width), tmem, G_TX_RENDERTILE, \ + ((width) + 7) / 8) + +#define _gsDPLoadTextureBlockYuvS(timg, tmem, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0, tmem, G_TX_RENDERTILE, \ + ((width) + 7) / 8) + +#define gsDPLoadMultiBlock(timg, tmem, rt, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + G_DXT(siz, width), tmem, rt, \ + ((width) * G_SIZ_LDBITS(siz) + 63) / 64) + +#define gsDPLoadMultiBlockS(timg, tmem, rt, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0, tmem, rt, \ + ((width) * G_SIZ_LDBITS(siz) + 63) / 64) + +#define gsDPLoadMultiBlock_4b(timg, tmem, rt, fmt, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, G_IM_SIZ_4b, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + G_DXT(G_IM_SIZ_4b, width), tmem, rt, \ + ((width) * 4 + 63) / 64) + +#define gsDPLoadMultiBlock_4bS(timg, tmem, rt, fmt, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, G_IM_SIZ_4b, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0, tmem, rt, \ + ((width) * 4 + 63) / 64) + +#define gsDPLoadMultiBlockYuv(timg, tmem, rt, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + G_DXT(siz, width), tmem, rt, \ + ((width) + 7) / 8) + +#define gsDPLoadMultiBlockYuvS(timg, tmem, rt, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTB_( \ + timg, fmt, siz, width, height, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0, tmem, rt, \ + ((width) + 7) / 8) + +#define gLTT_(timg, fmt, siz, width, height, uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + tmem, rt, line) \ + gsDPSetTextureImage(fmt, siz, width, timg), \ + gsDPSetTile( \ + fmt, siz, line, tmem, \ + G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( \ + G_TX_LOADTILE, \ + qu102(uls), qu102(ult), \ + qu102(lrs), qu102(lrt)), \ + gsDPPipeSync(), \ + gsDPSetTile( \ + fmt, siz, line, \ + tmem, rt, pal, \ + cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPSetTileSize( \ + rt, \ + qu102(uls), qu102(ult), \ + qu102(lrs), qu102(lrt)) + +#define gLTT4_(timg, fmt, width, height, uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + tmem, rt) \ + gsDPSetTextureImage(fmt, G_IM_SIZ_8b, (width) / 2, timg), \ + gsDPSetTile( \ + fmt, G_IM_SIZ_8b, \ + (((lrs) - (uls) + 1) / 2 + 7) / 8, \ + tmem, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( \ + G_TX_LOADTILE, \ + qu102(uls) / 2, qu102(ult), \ + qu102(lrs) / 2, qu102(lrt)), \ + gsDPPipeSync(), \ + gsDPSetTile( \ + fmt, G_IM_SIZ_4b, \ + (((lrs) - (uls) + 1) / 2 + 7) / 8, \ + tmem, rt, pal, \ + cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPSetTileSize( \ + rt, \ + qu102(uls), qu102(ult), \ + qu102(lrs), qu102(lrt)) + +#define gsDPLoadTextureTile(timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTT_( \ + timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0x0, G_TX_RENDERTILE, \ + (((lrs) - (uls) + 1) * G_SIZ_LDBITS(siz) + 63) / 64) + +#define gsDPLoadTextureTile_4b(timg, fmt, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTT4_( \ + timg, fmt, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0x0, G_TX_RENDERTILE) + +#define gsDPLoadTextureTileYuv(timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTT_( \ + timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + 0x0, G_TX_RENDERTILE, \ + (((lrs) - (uls) + 1) + 7) / 8) + +#define _gsDPLoadTextureTile(timg, tmem, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTT_( \ + timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + tmem, G_TX_RENDERTILE, \ + (((lrs) - (uls) + 1) * G_SIZ_LDBITS(siz) + 63) / 64) + +#define _gsDPLoadTextureTile_4b(timg, tmem, fmt, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTT4_( \ + timg, fmt, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + tmem, G_TX_RENDERTILE) + +#define _gsDPLoadTextureTileYuv(timg, tmem, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, cms, cmt, \ + masks, maskt, shifts, shiftt) \ + gLTT_( \ + timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + tmem, G_TX_RENDERTILE, \ + (((lrs) - (uls) + 1) + 7) / 8) + +#define gsDPLoadMultiTile(timg, tmem, rt, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTT_( \ + timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + tmem, rt, \ + (((lrs) - (uls) + 1) * G_SIZ_LDBITS(siz) + 63) / 64) + +#define gsDPLoadMultiTile_4b(timg, tmem, rt, fmt, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTT4_( \ + timg, fmt, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + tmem, rt) + +#define gsDPLoadMultiTileYuv(timg, tmem, rt, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ + gLTT_( \ + timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt, \ + tmem, rt, \ + (((lrs) - (uls) + 1) + 7) / 8) + +#define gsDPLoadBlock(tile, uls, ult, lrs, dxt) \ + gO_( \ + G_LOADBLOCK, \ + gF_(uls, 12, 12) | \ + gF_(ult, 12, 0), \ + gF_(tile, 3, 24) | \ + gF_(lrs, 12, 12) | \ + gF_(dxt, 12, 0)) + +#define gsDPNoOp() \ + gsDPNoOpTag(0) + +#define gsDPNoOpTag(tag) \ + gO_(G_NOOP, 0, tag) + +#define gsDPPipelineMode(mode) \ + gsSPSetOtherModeHi(G_MDSFT_PIPELINE, G_MDSIZ_PIPELINE, mode) + +#define gsDPSetBlendColor(r, g, b, a) \ + gO_( \ + G_SETBLENDCOLOR, \ + 0, \ + gF_(r, 8, 24) | \ + gF_(g, 8, 16) | \ + gF_(b, 8, 8) | \ + gF_(a, 8, 0)) + +#define gsDPSetEnvColor(r, g, b, a) \ + gO_( \ + G_SETENVCOLOR, \ + 0, \ + gF_(r, 8, 24) | \ + gF_(g, 8, 16) | \ + gF_(b, 8, 8) | \ + gF_(a, 8, 0)) + +#define gsDPSetFillColor(c) \ + gO_(G_SETFILLCOLOR, 0, c) + +#define gsDPSetFogColor(r, g, b, a) \ + gO_( \ + G_SETFOGCOLOR, 0, \ + gF_(r, 8, 24) | \ + gF_(g, 8, 16) | \ + gF_(b, 8, 8) | \ + gF_(a, 8, 0)) + +#define gsDPSetPrimColor(m, l, r, g, b, a) \ + gO_( \ + G_SETPRIMCOLOR, \ + gF_(m, 8, 8) | \ + gF_(l, 8, 0), \ + gF_(r, 8, 24) | \ + gF_(g, 8, 16) | \ + gF_(b, 8, 8) | \ + gF_(a, 8, 0)) + +#define gsDPSetColorImage(fmt, siz, width, img) \ + gO_( \ + G_SETCIMG, \ + gF_(fmt, 3, 21) | \ + gF_(siz, 2, 19) | \ + gF_((width) - 1, 12, 0), \ + img) + +#define gsDPSetDepthImage(img) \ + gO_(G_SETZIMG, 0, img) + +#define gsDPSetTextureImage(fmt, siz, width, img) \ + gO_( \ + G_SETTIMG, \ + gF_(fmt, 3, 21) | \ + gF_(siz, 2, 19) | \ + gF_((width) - 1, 12, 0), \ + img) + +#define gsDPSetHilite1Tile(tile, hilite, width, height) \ + gsDPSetTileSize( \ + tile, \ + ((Hilite *)(hilite))->h.x1 & 0xFFF, \ + ((Hilite *)(hilite))->h.y1 & 0xFFF, \ + (((width) - 1) * 4 + ((Hilite *)(hilite))->h.x1) & 0xFFF, \ + (((height) - 1) * 4 + ((Hilite *)(hilite))->h.y1) & 0xFFF) + +#define gsDPSetHilite2Tile(tile, hilite, width, height) \ + gsDPSetTileSize( \ + tile, \ + ((Hilite *)(hilite))->h.x2 & 0xFFF, \ + ((Hilite *)(hilite))->h.y2 & 0xFFF, \ + (((width) - 1) * 4 + ((Hilite *)(hilite))->h.x2) & 0xFFF, \ + (((height) - 1) * 4 + ((Hilite *)(hilite))->h.y2) & 0xFFF) + +#define gsDPSetAlphaCompare(mode) \ + gsSPSetOtherModeLo(G_MDSFT_ALPHACOMPARE, G_MDSIZ_ALPHACOMPARE, mode) + +#define gsDPSetAlphaDither(type) \ + gsSPSetOtherModeHi(G_MDSFT_ALPHADITHER, G_MDSIZ_ALPHADITHER, type) + +#define gsDPSetColorDither(type) \ + gsSPSetOtherModeHi(G_MDSFT_RGBDITHER, G_MDSIZ_RGBDITHER, type) + +#define gsDPSetCombineMode(mode1, mode2) \ + gsDPSetCombineLERP(mode1, mode2) + +#define gsDPSetCombineLERP(a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ + a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ + gO_( \ + G_SETCOMBINE, \ + gF_(G_CCMUX_##a0, 4, 20) | \ + gF_(G_CCMUX_##c0, 5, 15) | \ + gF_(G_ACMUX_##Aa0, 3, 12) | \ + gF_(G_ACMUX_##Ac0, 3, 9) | \ + gF_(G_CCMUX_##a1, 4, 5) | \ + gF_(G_CCMUX_##c1, 5, 0), \ + gF_(G_CCMUX_##b0, 4, 28) | \ + gF_(G_CCMUX_##b1, 4, 24) | \ + gF_(G_ACMUX_##Aa1, 3, 21) | \ + gF_(G_ACMUX_##Ac1, 3, 18) | \ + gF_(G_CCMUX_##d0, 3, 15) | \ + gF_(G_ACMUX_##Ab0, 3, 12) | \ + gF_(G_ACMUX_##Ad0, 3, 9) | \ + gF_(G_CCMUX_##d1, 3, 6) | \ + gF_(G_ACMUX_##Ab1, 3, 3) | \ + gF_(G_ACMUX_##Ad1, 3, 0)) + +#define gsDPSetConvert(k0, k1, k2, k3, k4, k5) \ + gO_( \ + G_SETCONVERT, \ + gF_(k0, 9, 13) | \ + gF_(k1, 9, 4) | \ + gF_(gI_(k2) >> 5, 4, 0), \ + gF_(k2, 5, 27) | \ + gF_(k3, 9, 18) | \ + gF_(k4, 9, 9) | \ + gF_(k5, 9, 0)) + +#define gsDPSetTextureConvert(type) \ + gsSPSetOtherModeHi(G_MDSFT_TEXTCONV, G_MDSIZ_TEXTCONV, type) + +#define gsDPSetCycleType(type) \ + gsSPSetOtherModeHi(G_MDSFT_CYCLETYPE, G_MDSIZ_CYCLETYPE, type) + +#define gsDPSetDepthSource(source) \ + gsSPSetOtherModeLo(G_MDSFT_ZSRCSEL, G_MDSIZ_ZSRCSEL, source) + +#define gsDPSetCombineKey(type) \ + gsSPSetOtherModeHi(G_MDSFT_COMBKEY, G_MDSIZ_COMBKEY, type) + +#define gsDPSetKeyGB(cG, sG, wG, cB, sB, wB) \ + gO_( \ + G_SETKEYGB, \ + gF_(wG, 12, 12) | \ + gF_(wB, 12, 0), \ + gF_(cG, 8, 24) | \ + gF_(sG, 8, 16) | \ + gF_(cB, 8, 8) | \ + gF_(sB, 8, 0)) + +#define gsDPSetKeyR(cR, sR, wR) \ + gO_( \ + G_SETKEYR, 0, \ + gF_(wR, 12, 16) | \ + gF_(cR, 8, 8) | \ + gF_(sR, 8, 0)) + +#define gsDPSetPrimDepth(z, dz) \ + gO_( \ + G_SETPRIMDEPTH, \ + 0, \ + gF_(z, 16, 16) | \ + gF_(dz, 16, 0)) + +#define gsDPSetRenderMode(mode1, mode2) \ + gsSPSetOtherModeLo( \ + G_MDSFT_RENDERMODE, \ + G_MDSIZ_RENDERMODE, \ + gI_(mode1) | \ + gI_(mode2)) + +#define gsDPSetScissor(mode, ulx, uly, lrx, lry) \ + gsDPSetScissorFrac( \ + mode, \ + qu102(gI_(ulx)), \ + qu102(gI_(uly)), \ + qu102(gI_(lrx)), \ + qu102(gI_(lry))) + +#define gsDPSetScissorFrac(mode, ulx, uly, lrx, lry) \ + gO_( \ + G_SETSCISSOR, \ + gF_(ulx, 12, 12) | \ + gF_(uly, 12, 0), \ + gF_(mode, 2, 24) | \ + gF_(lrx, 12, 12) | \ + gF_(lry, 12, 0)) + +#define gsDPSetTextureDetail(type) \ + gsSPSetOtherModeHi(G_MDSFT_TEXTDETAIL, G_MDSIZ_TEXTDETAIL, type) + +#define gsDPSetTextureFilter(mode) \ + gsSPSetOtherModeHi(G_MDSFT_TEXTFILT, G_MDSIZ_TEXTFILT, mode) + +#define gsDPSetTextureLOD(mode) \ + gsSPSetOtherModeHi(G_MDSFT_TEXTLOD, G_MDSIZ_TEXTLOD, mode) + +#define gsDPSetTextureLUT(mode) \ + gsSPSetOtherModeHi(G_MDSFT_TEXTLUT, G_MDSIZ_TEXTLUT, mode) + +#define gsDPSetTexturePersp(enable) \ + gsSPSetOtherModeHi(G_MDSFT_TEXTPERSP, G_MDSIZ_TEXTPERSP, enable) + +#define gsDPSetTile(fmt, siz, line, tmem, tile, palette, \ + cmt, maskt, shiftt, cms, masks, shifts) \ + gO_( \ + G_SETTILE, \ + gF_(fmt, 3, 21) | \ + gF_(siz, 2, 19) | \ + gF_(line, 9, 9) | \ + gF_(tmem, 9, 0), \ + gF_(tile, 3, 24) | \ + gF_(palette, 4, 20) | \ + gF_(cmt, 2, 18) | \ + gF_(maskt, 4, 14) | \ + gF_(shiftt, 4, 10) | \ + gF_(cms, 2, 8) | \ + gF_(masks, 4, 4) | \ + gF_(shifts, 4, 0)) + +#define gsDPSetTileSize(tile, uls, ult, lrs, lrt) \ + gO_( \ + G_SETTILESIZE, \ + gF_(uls, 12, 12) | \ + gF_(ult, 12, 0), \ + gF_(tile, 3, 24) | \ + gF_(lrs, 12, 12) | \ + gF_(lrt, 12, 0)) + +#define gsSPBranchList(dl) \ + gsDisplayList(dl, 1) + +#define gsSPClipRatio(r) \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNX, (uint16_t)(r)), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNY, (uint16_t)(r)), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPX, (uint16_t)-(r)), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPY, (uint16_t)-(r)) + +#define gsSPDisplayList(dl) \ + gsDisplayList(dl, 0) + +#define gsSPEndDisplayList() \ + gO_(G_ENDDL, 0, 0) + +#define gsSPFogFactor(fm, fo) \ + gsMoveWd( \ + G_MW_FOG, \ + G_MWO_FOG, \ + gF_(fm, 16, 16) | \ + gF_(fo, 16, 0)) + +#define gsSPFogPosition(min, max) \ + gsSPFogFactor( \ + (500 * 0x100) / ((max) - (min)), \ + (500 - (min)) * 0x100 / ((max) - (min))) + +#define gsSPLine3D(v0, v1, flag) \ + gsSPLineW3D(v0, v1, 0, flag) + +#define gsSPLookAt(l) \ + gsSPLookAtX(l), \ + gsSPLookAtY(gI_(l) + 0x10) + +#define gsSPSegment(seg, base) \ + gsMoveWd(G_MW_SEGMENT, (seg) * 4, base) + +#define gsSPSetLights0(lites) \ + gsSPNumLights(NUMLIGHTS_0), \ + gsSPLight(&(lites).l[0], 1), \ + gsSPLight(&(lites).a, 2) + +#define gsSPSetLights1(lites) \ + gsSPNumLights(NUMLIGHTS_1), \ + gsSPLight(&(lites).l[0], 1), \ + gsSPLight(&(lites).a, 2) + +#define gsSPSetLights2(lites) \ + gsSPNumLights(NUMLIGHTS_2), \ + gsSPLight(&(lites).l[0], 1), \ + gsSPLight(&(lites).l[1], 2), \ + gsSPLight(&(lites).a, 3) + +#define gsSPSetLights3(lites) \ + gsSPNumLights(NUMLIGHTS_3), \ + gsSPLight(&(lites).l[0], 1), \ + gsSPLight(&(lites).l[1], 2), \ + gsSPLight(&(lites).l[2], 3), \ + gsSPLight(&(lites).a, 4) + +#define gsSPSetLights4(lites) \ + gsSPNumLights(NUMLIGHTS_4), \ + gsSPLight(&(lites).l[0], 1), \ + gsSPLight(&(lites).l[1], 2), \ + gsSPLight(&(lites).l[2], 3), \ + gsSPLight(&(lites).l[3], 4), \ + gsSPLight(&(lites).a, 5) + +#define gsSPSetLights5(lites) \ + gsSPNumLights(NUMLIGHTS_5), \ + gsSPLight(&(lites).l[0], 1), \ + gsSPLight(&(lites).l[1], 2), \ + gsSPLight(&(lites).l[2], 3), \ + gsSPLight(&(lites).l[3], 4), \ + gsSPLight(&(lites).l[4], 5), \ + gsSPLight(&(lites).a, 6) + +#define gsSPSetLights6(lites) \ + gsSPNumLights(NUMLIGHTS_6), \ + gsSPLight(&(lites).l[0], 1), \ + gsSPLight(&(lites).l[1], 2), \ + gsSPLight(&(lites).l[2], 3), \ + gsSPLight(&(lites).l[3], 4), \ + gsSPLight(&(lites).l[4], 5), \ + gsSPLight(&(lites).l[5], 6), \ + gsSPLight(&(lites).a, 7) + +#define gsSPSetLights7(lites) \ + gsSPNumLights(NUMLIGHTS_7), \ + gsSPLight(&(lites).l[0], 1), \ + gsSPLight(&(lites).l[1], 2), \ + gsSPLight(&(lites).l[2], 3), \ + gsSPLight(&(lites).l[3], 4), \ + gsSPLight(&(lites).l[4], 5), \ + gsSPLight(&(lites).l[5], 6), \ + gsSPLight(&(lites).l[6], 7), \ + gsSPLight(&(lites).a, 8) + +#define gsSPSetStatus(sid, val) \ + gsMoveWd(G_MW_GENSTAT, sid, val) + +#define gsSPNumLights(n) \ + gsMoveWd(G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) + +#define gsSPLightColor(Lightnum, packedcolor) \ + gsMoveWd(G_MW_LIGHTCOL, G_MWO_a##Lightnum, packedcolor), \ + gsMoveWd(G_MW_LIGHTCOL, G_MWO_b##Lightnum, packedcolor) + +#define gsSPTextureRectangle(ulx, uly, lrx, lry, tile, s, t, dsdx, dtdy) \ + gsTexRect(ulx, uly, lrx, lry, tile), \ + gsDPHalf1(gF_(s, 16, 16) | gF_(t, 16, 0)), \ + gsDPHalf2(gF_(dsdx, 16, 16) | gF_(dtdy, 16, 0)) + +#define gsSPScisTextureRectangle(ulx, uly, lrx, lry, tile, s, t, dsdx, dtdy) \ + gsTexRect(gScC_(ulx), gScC_(uly), gScC_(lrx), gScC_(lry), tile), \ + gsDPHalf1( \ + gF_(gScD_(s, ulx, dsdx), 16, 16) | \ + gF_(gScD_(t, uly, dtdy), 16, 0)), \ + gsDPHalf2(gF_(dsdx, 16, 16) | gF_(dtdy, 16, 0)) + +#define gsSPTextureRectangleFlip(ulx, uly, lrx, lry, tile, s, t, dsdx, dtdy) \ + gsTexRectFlip(ulx, uly, lrx, lry, tile), \ + gsDPHalf1(gF_(s, 16, 16) | gF_(t, 16, 0)), \ + gsDPHalf2(gF_(dsdx, 16, 16) | gF_(dtdy, 16, 0)) + +#define gsSPScisTextureRectangleFlip( \ + ulx, uly, lrx, lry, tile, s, t, dsdx, dtdy) \ + gsTexRectFlip(gScC_(ulx), gScC_(uly), gScC_(lrx), gScC_(lry), tile), \ + gsDPHalf1( \ + gF_(gScD_(s, ulx, dsdx), 16, 16) | \ + gF_(gScD_(t, uly, dtdy), 16, 0)), \ + gsDPHalf2(gF_(dsdx, 16, 16) | gF_(dtdy, 16, 0)) + +#define gsSPBgRectCopy(bg) \ + gO_(G_BG_COPY, 0, bg) + +#define gsSPBgRect1Cyc(bg) \ + gO_(G_BG_1CYC, 0, bg) + +#define gsSPObjRectangle(sp) \ + gO_(G_OBJ_RECTANGLE, 0, sp) + +#define gsSPObjRectangleR(sp) \ + gO_(G_OBJ_RECTANGLE_R, 0, sp) + +#define gsSPObjSprite(sp) \ + gO_(G_OBJ_SPRITE, 0, sp) + +#define gsSPObjMatrix(mtx) \ + gO_( \ + G_OBJ_MOVEMEM, \ + gF_(sizeof(uObjMtx) - 1, 8, 16), \ + mtx) + +#define gsSPObjSubMatrix(mtx) \ + gO_( \ + G_OBJ_MOVEMEM, \ + gF_(sizeof(uObjSubMtx) - 1, 8, 16) | \ + gF_(2, 16, 0), \ + mtx) + +#define gsSPObjRenderMode(mode) \ + gO_(G_OBJ_RENDERMODE, 0, mode) + +#define gsSPObjLoadTxtr(tx) \ + gO_(G_OBJ_LOADTXTR, 23, tx) + +#define gsSPObjLoadTxRect(txsp) \ + gO_(G_OBJ_LDTX_RECT, 47, txsp) + +#define gsSPObjLoadTxRectR(txsp) \ + gO_(G_OBJ_LDTX_RECT_R, 47, txsp) + +#define gsSPObjLoadTxSprite(txsp) \ + gO_(G_OBJ_LDTX_SPRITE, 47, txsp) + +#define gsSPSelectDL(ldl, sid, flag, mask) \ + gO_( \ + G_RDPHALF_0, \ + gF_(sid, 8, 16) | \ + gF_(ldl, 16, 0), \ + flag), \ + gO_( \ + G_SELECT_DL, \ + gF_(0x00, 8, 16) | \ + gF_(gI_(ldl) >> 16, 16, 0), \ + mask) + +#define gsSPSelectBranchDL(bdl, sid, flag, mask) \ + gO_( \ + G_RDPHALF_0, \ + gF_(sid, 8, 16) | \ + gF_(bdl, 16, 0), \ + flag), \ + gO_( \ + G_SELECT_DL, \ + gF_(0x01, 8, 16) | \ + gF_(gI_(bdl) >> 16, 16, 0), \ + mask) + +/* unlisted instructions */ + +#define gsDPLoadTLUTCmd(tile, count) \ + gO_( \ + G_LOADTLUT, \ + 0, \ + gF_(tile, 3, 24) | \ + gF_(count, 10, 14)) + +#define gsDPLoadTLUT(count, tmem, dram) \ + gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram), \ + gsDPTileSync(), \ + gsDPSetTile(0, 0, 0, tmem, G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0), \ + gsDPLoadSync(), \ + gsDPLoadTLUTCmd(G_TX_LOADTILE, (count) - 1), \ + gsDPPipeSync() + +#define gsDisplayList(dl, branch) \ + gO_(G_DL, gF_(branch, 8, 16), dl) + +#define gsDPLoadTile(tile, uls, ult, lrs, lrt) \ + gO_( \ + G_LOADTILE, \ + gF_(uls, 12, 12) | \ + gF_(ult, 12, 0), \ + gF_(tile, 3, 24) | \ + gF_(lrs, 12, 12) | \ + gF_(lrt, 12, 0)) + +#define gsDPSetCombine(c) \ + gO_( \ + G_SETCOMBINE, \ + (gL_(c) >> 32) & 0xFFFFFFFF, \ + (gL_(c) >> 0) & 0xFFFFFFFF) + +#define gsSPSetOtherModeLo(shift, length, data) \ + gsSPSetOtherMode(G_SETOTHERMODE_L, shift, length, data) + +#define gsSPSetOtherModeHi(shift, length, data) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, shift, length, data) + +#define gsDPSetOtherMode(mode0, mode1) \ + gO_(G_RDPSETOTHERMODE, gF_(mode0, 24, 0), mode1) + +#define gsTexRect(ulx, uly, lrx, lry, tile) \ + gO_( \ + G_TEXRECT, \ + gF_(lrx, 12, 12) | \ + gF_(lry, 12, 0), \ + gF_(tile, 3, 24) | \ + gF_(ulx, 12, 12) | \ + gF_(uly, 12, 0)) + +#define gsTexRectFlip(ulx, uly, lrx, lry, tile) \ + gO_( \ + G_TEXRECTFLIP, \ + gF_(lrx, 12, 12) | \ + gF_(lry, 12, 0), \ + gF_(tile, 3, 24) | \ + gF_(ulx, 12, 12) | \ + gF_(uly, 12, 0)) + +#define gsSPNoOp() \ + gO_(G_SPNOOP, 0, 0) + +#define gsDPHalf1(wordhi) \ + gO_(G_RDPHALF_1, 0, wordhi) + +#define gsDPHalf2(wordlo) \ + gO_(G_RDPHALF_2, 0, wordlo) + +#define gsDPWord(wordhi, wordlo) \ + gsDPHalf1(wordhi), \ + gsDPHalf2(wordlo) + +/* instruction macros for fast3d */ + +#if defined(F3D_GBI) + +# define gsSP1Triangle(v0, v1, v2, flag) \ + gO_( \ + G_TRI1, \ + 0, \ + gF_(flag, 8, 24) | \ + gF_(gI_(v0) * 10, 8, 16) | \ + gF_(gI_(v1) * 10, 8, 8) | \ + gF_(gI_(v2) * 10, 8, 0)) + +# define gsSPCullDisplayList(v0, vn) \ + gO_( \ + G_CULLDL, \ + (gI_(v0) & 0xF) * 40, \ + gI_((vn) + 1) & 0xF) * 40) + +# define gsSPLineW3D(v0, v1, wd, flag) \ + gO_( \ + G_LINE3D, \ + 0, \ + gF_(flag, 8, 24) | \ + gF_(gI_(v0) * 10, 8, 16) | \ + gF_(gI_(v1) * 10, 8, 8) | \ + gF_(wd, 8, 0)) + +# define gsSPVertex(v, n, v0) \ + gO_( \ + G_VTX, \ + gF_((n) - 1, 4, 20) | \ + gF_(v0, 4, 16) | \ + gF_(sizeof(Vtx) * (n), 16, 0), \ + v) + +#endif + +/* instruction macros for fast3d and beta f3dex */ +#if defined(F3D_GBI) || (defined(F3D_BETA) && defined(F3DEX_GBI)) + +# define gsSPModifyVertex(vtx, where, val) \ + gsMoveWd(G_MW_POINTS, (vtx) * 40 + (where), val) + +#endif + +/* instruction macros for fast3d and f3dex */ + +#if defined(F3D_GBI) || defined(F3DEX_GBI) + +# define gsSPForceMatrix(mptr) \ + gsMoveMem(16, G_MV_MATRIX_1, (char *)(mptr)), \ + gsMoveMem(16, G_MV_MATRIX_2, (char *)(mptr) + 16), \ + gsMoveMem(16, G_MV_MATRIX_3, (char *)(mptr) + 32), \ + gsMoveMem(16, G_MV_MATRIX_4, (char *)(mptr) + 48) + +# define gsSPSetGeometryMode(mode) \ + gO_(G_SETGEOMETRYMODE, 0, gI_(mode)) + +# define gsSPClearGeometryMode(mode) \ + gO_(G_CLEARGEOMETRYMODE, 0, gI_(mode)) + +# define gsSPLoadGeometryMode(mode) \ + gsSPClearGeometryMode(~gI_(0)), \ + gsSPSetGeometryMode(mode) + +# define gsSPInsertMatrix(where, num) \ + gsMoveWd(G_MW_MATRIX, where, num) + +# define gsSPLookAtX(l) \ + gsMoveMem(sizeof(Light), G_MV_LOOKATX, l) + +# define gsSPLookAtY(l) \ + gsMoveMem(sizeof(Light), G_MV_LOOKATY, l) + +# define gsSPMatrix(matrix, param) \ + gO_( \ + G_MTX, \ + gF_(param, 8, 16) | \ + gF_(sizeof(Mtx), 16, 0), \ + matrix) + +# define gsSPPopMatrix(param) \ + gO_(G_POPMTX, 0, param) + +# define gsSPLight(l, n) \ + gsMoveMem(sizeof(Light), G_MV_L0 + ((n) - 1) * 2, l) + +# define gsSPTexture(sc, tc, level, tile, on) \ + gO_( \ + G_TEXTURE, \ + gF_(level, 3, 11) | \ + gF_(tile, 3, 8) | \ + gF_(on, 8, 0), \ + gF_(sc, 16, 16) | \ + gF_(tc, 16, 0)) + +# define gsSPViewport(v) \ + gsMoveMem(sizeof(Vp), G_MV_VIEWPORT, v) + +# define gsSPSetOtherMode(opc, shift, length, data) \ + gO_( \ + opc, \ + gF_(shift, 8, 8) | \ + gF_(length, 8, 0), \ + data) + +# define gsMoveWd(index, offset, data) \ + gO_( \ + G_MOVEWORD, \ + gF_(offset, 16, 8) | \ + gF_(index, 8, 0), \ + data) + +# define gsMoveMem(size, index, address) \ + gO_( \ + G_MOVEMEM, \ + gF_(index, 8, 16) | \ + gF_(size, 16, 0), \ + address) + +#endif + +/* instruction macros for f3dex */ + +#if defined(F3DEX_GBI) + +# define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ + gO_( \ + G_TRI2, \ + gF_(gV4_(v0, v1, v2, v3, flag) * 2, 8, 16) | \ + gF_(gV4_(v1, v2, v3, v0, flag) * 2, 8, 8) | \ + gF_(gV4_(v2, v3, v0, v1, flag) * 2, 8, 0), \ + gF_(gV4_(v0, v1, v2, v3, flag) * 2, 8, 16) | \ + gF_(gV4_(v2, v3, v0, v1, flag) * 2, 8, 8) | \ + gF_(gV4_(v3, v0, v1, v2, flag) * 2, 8, 0)) + +# define gsSPVertex(v, n, v0) \ + gO_( \ + G_VTX, \ + gF_((v0) * 2, 8, 16) | \ + gF_(n, 6, 10) | \ + gF_(sizeof(Vtx) * (n) - 1, 10, 0), \ + v) + +#endif + +/* instruction macros for f3dex and f3dex2 */ + +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) + +# define gsSP1Triangle(v0, v1, v2, flag) \ + gO_( \ + G_TRI1, \ + gF_(gV3_(v0, v1, v2, flag) * 2, 8, 16) | \ + gF_(gV3_(v1, v2, v0, flag) * 2, 8, 8) | \ + gF_(gV3_(v2, v0, v1, flag) * 2, 8, 0), \ + 0) + +# define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ + gO_( \ + G_TRI2, \ + gF_(gV3_(v00, v01, v02, flag0) * 2, 8, 16) | \ + gF_(gV3_(v01, v02, v00, flag0) * 2, 8, 8) | \ + gF_(gV3_(v02, v00, v01, flag0) * 2, 8, 0), \ + gF_(gV3_(v10, v11, v12, flag1) * 2, 8, 16) | \ + gF_(gV3_(v11, v12, v10, flag1) * 2, 8, 8) | \ + gF_(gV3_(v12, v10, v11, flag1) * 2, 8, 0)) + +# define gsSPBranchLessZ(branchdl, vtx, zval, near, far, flag) \ + gsSPBranchLessZrg(branchdl, vtx, zval, near, far, flag, 0, G_MAXZ) + +# define gsSPBranchLessZrg(branchdl, vtx, zval, near, far, flag, zmin, zmax) \ + gsSPBranchLessZraw(branchdl, vtx, \ + G_DEPTOZSrg(zval, near, far, flag, zmin, zmax)) + +# define gsSPBranchLessZraw(branchdl, vtx, zval) \ + gsDPHalf1(branchdl), \ + gsBranchZ(vtx, zval) + +# define gsSPCullDisplayList(v0, vn) \ + gO_( \ + G_CULLDL, \ + gF_((v0) * 2, 16, 0), \ + gF_((vn) * 2, 16, 0)) + +# define gsSPLineW3D(v0, v1, wd, flag) \ + gO_( \ + G_LINE3D, \ + gF_(gV2_(v0, v1, flag) * 2, 8, 16) | \ + gF_(gV2_(v1, v0, flag) * 2, 8, 8) | \ + gF_(wd, 8, 0), \ + 0) + +# define gsSPLoadUcode(uc_start, uc_dstart) \ + gsSPLoadUcodeEx(uc_start, uc_dstart, 0x800) + +# define gsSPLoadUcodeL(ucode) \ + gsSPLoadUcode( \ + gI_(&ucode##TextStart) & 0x1FFFFFFF, \ + gI_(&ucode##DataStart) & 0x1FFFFFFF) + +# if !(defined(F3D_BETA) && defined(F3DEX_GBI)) +# define gsSPModifyVertex(vtx, where, val) \ + gO_( \ + G_MODIFYVTX, \ + gF_(where, 8, 16) | \ + gF_((vtx) * 2, 16, 0), \ + val) +# endif + +# define gsBranchZ(vtx, zval) \ + gO_( \ + G_BRANCH_Z, \ + gF_((vtx) * 5, 12, 12) | \ + gF_((vtx) * 2, 12, 0), \ + zval) + +# define gsLoadUcode(uc_start, uc_dsize) \ + gO_( \ + G_LOAD_UCODE, \ + gF_((uc_dsize) - 1, 16, 0), \ + uc_start) + +# define gsSPLoadUcodeEx(uc_start, uc_dstart, uc_dsize) \ + gsDPHalf1(uc_dstart), \ + gsLoadUcode(uc_start, uc_dsize) + +#endif + +/* instruction macros for f3dex2 */ + +#if defined(F3DEX_GBI_2) + +# define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ + gO_( \ + G_QUAD, \ + gF_(gV4_(v0, v1, v2, v3, flag) * 2, 8, 16) | \ + gF_(gV4_(v1, v2, v3, v0, flag) * 2, 8, 8) | \ + gF_(gV4_(v2, v3, v0, v1, flag) * 2, 8, 0), \ + gF_(gV4_(v0, v1, v2, v3, flag) * 2, 8, 16) | \ + gF_(gV4_(v2, v3, v0, v1, flag) * 2, 8, 8) | \ + gF_(gV4_(v3, v0, v1, v2, flag) * 2, 8, 0)) + +# define gsSPForceMatrix(mptr) \ + gsMoveMem(sizeof(Mtx), G_MV_MATRIX, 0, mptr), \ + gsMoveWd(G_MW_FORCEMTX, 0, 0x10000) + +# define gsSPSetGeometryMode(mode) \ + gsSPGeometryMode(0, mode) + +# define gsSPClearGeometryMode(mode) \ + gsSPGeometryMode(mode, 0) + +# define gsSPLoadGeometryMode(mode) \ + gsSPGeometryMode(~gI_(0), mode) + +# define gsSPLookAtX(l) \ + gsMoveMem(sizeof(Light), G_MV_LIGHT, G_MVO_LOOKATX, l) + +# define gsSPLookAtY(l) \ + gsMoveMem(sizeof(Light), G_MV_LIGHT, G_MVO_LOOKATY, l) + +# define gsSPMatrix(matrix, param) \ + gO_( \ + G_MTX, \ + gF_((sizeof(Mtx) - 1) / 8, 5, 19) | \ + gF_(gI_(param) ^ G_MTX_PUSH, 8, 0), \ + matrix) + +# define gsSPPopMatrix(param) \ + gsSPPopMatrixN(param, 1) + +# define gsSPPopMatrixN(param, n) \ + gO_( \ + G_POPMTX, \ + gF_((sizeof(Mtx) - 1) / 8, 5, 19) | \ + gF_(2, 8, 0), \ + sizeof(Mtx) * (n)) + +# define gsSPLight(l, n) \ + gsMoveMem(sizeof(Light), G_MV_LIGHT, ((n) + 1) * 0x18, l) + +# define gsSPTexture(sc, tc, level, tile, on) \ + gO_( \ + G_TEXTURE, \ + gF_(level, 3, 11) | \ + gF_(tile, 3, 8) | \ + gF_(on, 7, 1), \ + gF_(sc, 16, 16) | \ + gF_(tc, 16, 0)) + +# define gsSPVertex(v, n, v0) \ + gO_( \ + G_VTX, \ + gF_(n, 8, 12) | \ + gF_((v0) + (n), 7, 1), \ + v) + +# define gsSPViewport(v) \ + gsMoveMem(sizeof(Vp), G_MV_VIEWPORT, 0, v) + +# define gsSPGeometryMode(clearbits, setbits) \ + gO_( \ + G_GEOMETRYMODE, \ + gF_(~gI_(clearbits), 24, 0), \ + setbits) + +# define gsSPSetOtherMode(opc, shift, length, data) \ + gO_( \ + opc, \ + gF_(32 - (shift) - (length), 8, 8) | \ + gF_((length) - 1, 8, 0), \ + data) + +# define gsMoveWd(index, offset, data) \ + gO_( \ + G_MOVEWORD, \ + gF_(index, 8, 16) | \ + gF_(offset, 16, 0), \ + data) + +# define gsMoveMem(size, index, offset, address) \ + gO_( \ + G_MOVEMEM, \ + gF_((size - 1) / 8, 5, 19) | \ + gF_((offset) / 8, 8, 8) | \ + gF_(index, 8, 0), \ + address) + +# define gsSPDma_io(flag, dmem, dram, size) \ + gO_( \ + G_DMA_IO, \ + gF_(flag, 1, 23) | \ + gF_((dmem) / 8, 10, 13) | \ + gF_((size) - 1, 12, 0), \ + dram) + +# define gsSPDmaRead(dmem, dram, size) \ + gsSPDma_io(0, dmem, dram, size) + +# define gsSPDmaWrite(dmem, dram, size) \ + gsSPDma_io(1, dmem, dram, size) + +# define gsSpecial3(hi, lo) \ + gO_(G_SPECIAL_3, hi, lo) + +# define gsSpecial2(hi, lo) \ + gO_(G_SPECIAL_2, hi, lo) + +# define gsSpecial1(hi, lo) \ + gO_(G_SPECIAL_1, hi, lo) + +#endif + +/* instruction macros for beta fast3d and f3dex */ + +#if defined(F3D_BETA) && (defined(F3D_GBI) || defined(F3DEX_GBI)) + +# define gsSPPerspNormalize(scale) \ + gO_(G_PERSPNORM, 0, scale) + +#else + +# define gsSPPerspNormalize(scale) \ + gsMoveWd(G_MW_PERSPNORM, 0, scale) + +#endif + +/* dynamic instruction macros */ + +#define gDisplayListPut(gdl, ...) \ + ({ \ + Gfx Gd_[] = {__VA_ARGS__}; \ + for(size_t Gi_ = 0; Gi_ < sizeof(Gd_) / sizeof(Gfx); Gi_++) \ + { \ + *(Gfx *)(gdl) = Gd_[Gi_]; \ + } \ + (void)0; \ + }) +#define gDisplayListAppend(pgdl, ...) \ + ({ \ + Gfx Gd_[] = {__VA_ARGS__}; \ + for(size_t Gi_ = 0; Gi_ < sizeof(Gd_) / sizeof(Gfx); Gi_++) \ + { \ + *(*(Gfx **)(pgdl))++ = Gd_[Gi_]; \ + } \ + (void)0; \ + }) +#define gDisplayListData(pgdl, d) \ + ({ \ + Gfx **Gp_ = (void *)(pgdl); \ + struct \ + { \ + __typeof__(d) v; \ + } *Gd_, *Gs_; \ + *Gp_ -= (sizeof(*Gd_) + sizeof(Gfx) - 1) / sizeof(Gfx); \ + Gd_ = (void *)*Gp_; \ + Gs_ = (void *)&(d); \ + *Gd_ = *Gs_; \ + &Gd_->v; \ + }) +#define gDisplayListAlloc(pgdl, s) \ + ({ \ + Gfx **Gp_ = (void *)(pgdl); \ + *Gp_ -= ((s) + sizeof(Gfx) - 1) / sizeof(Gfx); \ + (void *)*Gp_; \ + }) + +#define gDPFillRectangle(gdl, ...) \ + gD_(gdl, gsDPFillRectangle, __VA_ARGS__) +#define gDPScisFillRectangle(gdl, ...) \ + gD_(gdl, gsDPScisFillRectangle, __VA_ARGS__) +#define gDPFullSync(gdl) \ + gDisplayListPut(gdl, gsDPFullSync()) +#define gDPLoadSync(gdl) \ + gDisplayListPut(gdl, gsDPLoadSync()) +#define gDPTileSync(gdl) \ + gDisplayListPut(gdl, gsDPTileSync()) +#define gDPPipeSync(gdl) \ + gDisplayListPut(gdl, gsDPPipeSync()) +#define gDPLoadTLUT_pal16(gdl, ...) \ + gD_(gdl, gsDPLoadTLUT_pal16, __VA_ARGS__) +#define gDPLoadTLUT_pal256(gdl, ...) \ + gD_(gdl, gsDPLoadTLUT_pal256, __VA_ARGS__) +#define gDPLoadTextureBlock(gdl, ...) \ + gD_(gdl, gsDPLoadTextureBlock, __VA_ARGS__) +#define gDPLoadTextureBlockS(gdl, ...) \ + gD_(gdl, gsDPLoadTextureBlockS, __VA_ARGS__) +#define gDPLoadTextureBlock_4b(gdl, ...) \ + gD_(gdl, gsDPLoadTextureBlock_4b, __VA_ARGS__) +#define gDPLoadTextureBlock_4bS(gdl, ...) \ + gD_(gdl, gsDPLoadTextureBlock_4bS, __VA_ARGS__) +#define gDPLoadTextureBlockYuv(gdl, ...) \ + gD_(gdl, gsDPLoadTextureBlockYuv, __VA_ARGS__) +#define gDPLoadTextureBlockYuvS(gdl, ...) \ + gD_(gdl, gsDPLoadTextureBlockYuvS, __VA_ARGS__) +#define _gDPLoadTextureBlock(gdl, ...) \ + gD_(gdl, _gsDPLoadTextureBlock, __VA_ARGS__) +#define _gDPLoadTextureBlockS(gdl, ...) \ + gD_(gdl, _gsDPLoadTextureBlockS, __VA_ARGS__) +#define _gDPLoadTextureBlock_4b(gdl, ...) \ + gD_(gdl, _gsDPLoadTextureBlock_4b, __VA_ARGS__) +#define _gDPLoadTextureBlock_4bS(gdl, ...) \ + gD_(gdl, _gsDPLoadTextureBlock_4bS, __VA_ARGS__) +#define _gDPLoadTextureBlockYuv(gdl, ...) \ + gD_(gdl, _gsDPLoadTextureBlockYuv, __VA_ARGS__) +#define _gDPLoadTextureBlockYuvS(gdl, ...) \ + gD_(gdl, _gsDPLoadTextureBlockYuvS, __VA_ARGS__) +#define gDPLoadMultiBlock(gdl, ...) \ + gD_(gdl, gsDPLoadMultiBlock, __VA_ARGS__) +#define gDPLoadMultiBlockS(gdl, ...) \ + gD_(gdl, gsDPLoadMultiBlockS, __VA_ARGS__) +#define gDPLoadMultiBlock_4b(gdl, ...) \ + gD_(gdl, gsDPLoadMultiBlock_4b, __VA_ARGS__) +#define gDPLoadMultiBlock_4bS(gdl, ...) \ + gD_(gdl, gsDPLoadMultiBlock_4bS, __VA_ARGS__) +#define gDPLoadMultiBlockYuv(gdl, ...) \ + gD_(gdl, gsDPLoadMultiBlockYuv, __VA_ARGS__) +#define gDPLoadMultiBlockYuvS(gdl, ...) \ + gD_(gdl, gsDPLoadMultiBlockYuvS, __VA_ARGS__) +#define gDPLoadTextureTile(gdl, ...) \ + gD_(gdl, gsDPLoadTextureTile, __VA_ARGS__) +#define gDPLoadTextureTile_4b(gdl, ...) \ + gD_(gdl, gsDPLoadTextureTile_4b, __VA_ARGS__) +#define gDPLoadTextureTileYuv(gdl, ...) \ + gD_(gdl, gsDPLoadTextureTileYuv, __VA_ARGS__) +#define _gDPLoadTextureTile(gdl, ...) \ + gD_(gdl, _gsDPLoadTextureTile, __VA_ARGS__) +#define _gDPLoadTextureTile_4b(gdl, ...) \ + gD_(gdl, _gsDPLoadTextureTile_4b, __VA_ARGS__) +#define _gDPLoadTextureTileYuv(gdl, ...) \ + gD_(gdl, _gsDPLoadTextureTileYuv, __VA_ARGS__) +#define gDPLoadMultiTile(gdl, ...) \ + gD_(gdl, gsDPLoadMultiTile, __VA_ARGS__) +#define gDPLoadMultiTile_4b(gdl, ...) \ + gD_(gdl, gsDPLoadMultiTile_4b, __VA_ARGS__) +#define gDPLoadMultiTileYuv(gdl, ...) \ + gD_(gdl, gsDPLoadMultiTileYuv, __VA_ARGS__) +#define gDPLoadBlock(gdl, ...) \ + gD_(gdl, gsDPLoadBlock, __VA_ARGS__) +#define gDPNoOp(gdl) \ + gDisplayListPut(gdl, gsDPNoOp()) +#define gDPNoOpTag(gdl, ...) \ + gD_(gdl, gsDPNoOpTag, __VA_ARGS__) +#define gDPPipelineMode(gdl, ...) \ + gD_(gdl, gsDPPipelineMode, __VA_ARGS__) +#define gDPSetBlendColor(gdl, ...) \ + gD_(gdl, gsDPSetBlendColor, __VA_ARGS__) +#define gDPSetEnvColor(gdl, ...) \ + gD_(gdl, gsDPSetEnvColor, __VA_ARGS__) +#define gDPSetFillColor(gdl, ...) \ + gD_(gdl, gsDPSetFillColor, __VA_ARGS__) +#define gDPSetFogColor(gdl, ...) \ + gD_(gdl, gsDPSetFogColor, __VA_ARGS__) +#define gDPSetPrimColor(gdl, ...) \ + gD_(gdl, gsDPSetPrimColor, __VA_ARGS__) +#define gDPSetColorImage(gdl, ...) \ + gD_(gdl, gsDPSetColorImage, __VA_ARGS__) +#define gDPSetDepthImage(gdl, ...) \ + gD_(gdl, gsDPSetDepthImage, __VA_ARGS__) +#define gDPSetTextureImage(gdl, ...) \ + gD_(gdl, gsDPSetTextureImage, __VA_ARGS__) +#define gDPSetHilite1Tile(gdl, ...) \ + gD_(gdl, gsDPSetHilite1Tile, __VA_ARGS__) +#define gDPSetHilite2Tile(gdl, ...) \ + gD_(gdl, gsDPSetHilite2Tile, __VA_ARGS__) +#define gDPSetAlphaCompare(gdl, ...) \ + gD_(gdl, gsDPSetAlphaCompare, __VA_ARGS__) +#define gDPSetAlphaDither(gdl, ...) \ + gD_(gdl, gsDPSetAlphaDither, __VA_ARGS__) +#define gDPSetColorDither(gdl, ...) \ + gD_(gdl, gsDPSetColorDither, __VA_ARGS__) +#define gDPSetCombineMode(gdl, ...) \ + gD_(gdl, gsDPSetCombineLERP, __VA_ARGS__) +#define gDPSetCombineLERP(gdl, ...) \ + gD_(gdl, gsDPSetCombineLERP, __VA_ARGS__) +#define gDPSetConvert(gdl, ...) \ + gD_(gdl, gsDPSetConvert, __VA_ARGS__) +#define gDPSetTextureConvert(gdl, ...) \ + gD_(gdl, gsDPSetTextureConvert, __VA_ARGS__) +#define gDPSetCycleType(gdl, ...) \ + gD_(gdl, gsDPSetCycleType, __VA_ARGS__) +#define gDPSetDepthSource(gdl, ...) \ + gD_(gdl, gsDPSetDepthSource, __VA_ARGS__) +#define gDPSetCombineKey(gdl, ...) \ + gD_(gdl, gsDPSetCombineKey, __VA_ARGS__) +#define gDPSetKeyGB(gdl, ...) \ + gD_(gdl, gsDPSetKeyGB, __VA_ARGS__) +#define gDPSetKeyR(gdl, ...) \ + gD_(gdl, gsDPSetKeyR, __VA_ARGS__) +#define gDPSetPrimDepth(gdl, ...) \ + gD_(gdl, gsDPSetPrimDepth, __VA_ARGS__) +#define gDPSetRenderMode(gdl, ...) \ + gD_(gdl, gsDPSetRenderMode, __VA_ARGS__) +#define gDPSetScissor(gdl, ...) \ + gD_(gdl, gsDPSetScissor, __VA_ARGS__) +#define gDPSetScissorFrac(gdl, ...) \ + gD_(gdl, gsDPSetScissorFrac, __VA_ARGS__) +#define gDPSetTextureDetail(gdl, ...) \ + gD_(gdl, gsDPSetTextureDetail, __VA_ARGS__) +#define gDPSetTextureFilter(gdl, ...) \ + gD_(gdl, gsDPSetTextureFilter, __VA_ARGS__) +#define gDPSetTextureLOD(gdl, ...) \ + gD_(gdl, gsDPSetTextureLOD, __VA_ARGS__) +#define gDPSetTextureLUT(gdl, ...) \ + gD_(gdl, gsDPSetTextureLUT, __VA_ARGS__) +#define gDPSetTexturePersp(gdl, ...) \ + gD_(gdl, gsDPSetTexturePersp, __VA_ARGS__) +#define gDPSetTile(gdl, ...) \ + gD_(gdl, gsDPSetTile, __VA_ARGS__) +#define gDPSetTileSize(gdl, ...) \ + gD_(gdl, gsDPSetTileSize, __VA_ARGS__) +#define gSP1Triangle(gdl, ...) \ + gD_(gdl, gsSP1Triangle, __VA_ARGS__) +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +# define gSP2Triangles(gdl, ...) \ + gD_(gdl, gsSP2Triangles, __VA_ARGS__) +# define gSP1Quadrangle(gdl, ...) \ + gD_(gdl, gsSP1Quadrangle, __VA_ARGS__) +# define gSPBranchLessZ(gdl, ...) \ + gD_(gdl, gsSPBranchLessZ, __VA_ARGS__) +# define gSPBranchLessZrg(gdl, ...) \ + gD_(gdl, gsSPBranchLessZrg, __VA_ARGS__) +# define gSPBranchLessZraw(gdl, ...) \ + gD_(gdl, gsSPBranchLessZraw, __VA_ARGS__) +#endif +#define gSPBranchList(gdl, ...) \ + gD_(gdl, gsSPBranchList, __VA_ARGS__) +#define gSPClipRatio(gdl, ...) \ + gD_(gdl, gsSPClipRatio, __VA_ARGS__) +#define gSPCullDisplayList(gdl, ...) \ + gD_(gdl, gsSPCullDisplayList, __VA_ARGS__) +#define gSPDisplayList(gdl, ...) \ + gD_(gdl, gsSPDisplayList, __VA_ARGS__) +#define gSPEndDisplayList(gdl) \ + gDisplayListPut(gdl, gsSPEndDisplayList()) +#define gSPFogFactor(gdl, ...) \ + gD_(gdl, gsSPFogFactor, __VA_ARGS__) +#define gSPFogPosition(gdl, ...) \ + gD_(gdl, gsSPFogPosition, __VA_ARGS__) +#define gSPForceMatrix(gdl, ...) \ + gD_(gdl, gsSPForceMatrix, __VA_ARGS__) +#define gSPSetGeometryMode(gdl, ...) \ + gD_(gdl, gsSPSetGeometryMode, __VA_ARGS__) +#define gSPClearGeometryMode(gdl, ...) \ + gD_(gdl, gsSPClearGeometryMode, __VA_ARGS__) +#define gSPLoadGeometryMode(gdl, ...) \ + gD_(gdl, gsSPLoadGeometryMode, __VA_ARGS__) +#if defined(F3D_GBI) || defined(F3DEX_GBI) +# define gSPInsertMatrix(gdl, ...) \ + gD_(gdl, gsSPInsertMatrix, __VA_ARGS__) +#endif +#define gSPLine3D(gdl, ...) \ + gD_(gdl, gsSPLine3D, __VA_ARGS__) +#define gSPLineW3D(gdl, ...) \ + gD_(gdl, gsSPLineW3D, __VA_ARGS__) +#define gSPLoadUcode(gdl, ...) \ + gD_(gdl, gsSPLoadUcode, __VA_ARGS__) +#define gSPLoadUcodeL(gdl, ...) \ + gD_(gdl, gsSPLoadUcodeL, __VA_ARGS__) +#define gSPLookAtX(gdl, ...) \ + gD_(gdl, gsSPLookAtX, __VA_ARGS__) +#define gSPLookAtY(gdl, ...) \ + gD_(gdl, gsSPLookAtY, __VA_ARGS__) +#define gSPLookAt(gdl, ...) \ + gD_(gdl, gsSPLookAt, __VA_ARGS__) +#define gSPMatrix(gdl, ...) \ + gD_(gdl, gsSPMatrix, __VA_ARGS__) +#define gSPModifyVertex(gdl, ...) \ + gD_(gdl, gsSPModifyVertex, __VA_ARGS__) +#define gSPPerspNormalize(gdl, ...) \ + gD_(gdl, gsSPPerspNormalize, __VA_ARGS__) +#define gSPPopMatrix(gdl, ...) \ + gD_(gdl, gsSPPopMatrix, __VA_ARGS__) +#if defined(F3DEX_GBI_2) +# define gSPPopMatrixN(gdl, ...) \ + gD_(gdl, gsSPPopMatrixN, __VA_ARGS__) +#endif +#define gSPSegment(gdl, ...) \ + gD_(gdl, gsSPSegment, __VA_ARGS__) +#define gSPSetLights0(gdl, ...) \ + gD_(gdl, gsSPSetLights0, __VA_ARGS__) +#define gSPSetLights1(gdl, ...) \ + gD_(gdl, gsSPSetLights1, __VA_ARGS__) +#define gSPSetLights2(gdl, ...) \ + gD_(gdl, gsSPSetLights2, __VA_ARGS__) +#define gSPSetLights3(gdl, ...) \ + gD_(gdl, gsSPSetLights3, __VA_ARGS__) +#define gSPSetLights4(gdl, ...) \ + gD_(gdl, gsSPSetLights4, __VA_ARGS__) +#define gSPSetLights5(gdl, ...) \ + gD_(gdl, gsSPSetLights5, __VA_ARGS__) +#define gSPSetLights6(gdl, ...) \ + gD_(gdl, gsSPSetLights6, __VA_ARGS__) +#define gSPSetLights7(gdl, ...) \ + gD_(gdl, gsSPSetLights7, __VA_ARGS__) +#define gSPSetStatus(gdl, ...) \ + gD_(gdl, gsSPSetStatus, __VA_ARGS__) +#define gSPNumLights(gdl, ...) \ + gD_(gdl, gsSPNumLights, __VA_ARGS__) +#define gSPLight(gdl, ...) \ + gD_(gdl, gsSPLight, __VA_ARGS__) +#define gSPLightColor(gdl, ...) \ + gD_(gdl, gsSPLightColor, __VA_ARGS__) +#define gSPTexture(gdl, ...) \ + gD_(gdl, gsSPTexture, __VA_ARGS__) +#define gSPTextureRectangle(gdl, ...) \ + gD_(gdl, gsSPTextureRectangle, __VA_ARGS__) +#define gSPScisTextureRectangle(gdl, ...) \ + gD_(gdl, gsSPScisTextureRectangle, __VA_ARGS__) +#define gSPTextureRectangleFlip(gdl, ...) \ + gD_(gdl, gsSPTextureRectangleFlip, __VA_ARGS__) +#define gSPScisTextureRectangleFlip(gdl, ...) \ + gD_(gdl, gsSPScisTextureRectangleFlip, __VA_ARGS__) +#define gSPVertex(gdl, ...) \ + gD_(gdl, gsSPVertex, __VA_ARGS__) +#define gSPViewport(gdl, ...) \ + gD_(gdl, gsSPViewport, __VA_ARGS__) +#define gSPBgRectCopy(gdl, ...) \ + gD_(gdl, gsSPBgRectCopy, __VA_ARGS__) +#define gSPBgRect1Cyc(gdl, ...) \ + gD_(gdl, gsSPBgRect1Cyc, __VA_ARGS__) +#define gSPObjRectangle(gdl, ...) \ + gD_(gdl, gsSPObjRectangle, __VA_ARGS__) +#define gSPObjRectangleR(gdl, ...) \ + gD_(gdl, gsSPObjRectangleR, __VA_ARGS__) +#define gSPObjSprite(gdl, ...) \ + gD_(gdl, gsSPObjSprite, __VA_ARGS__) +#define gSPObjMatrix(gdl, ...) \ + gD_(gdl, gsSPObjMatrix, __VA_ARGS__) +#define gSPObjSubMatrix(gdl, ...) \ + gD_(gdl, gsSPObjSubMatrix, __VA_ARGS__) +#define gSPObjRenderMode(gdl, ...) \ + gD_(gdl, gsSPObjRenderMode, __VA_ARGS__) +#define gSPObjLoadTxtr(gdl, ...) \ + gD_(gdl, gsSPObjLoadTxtr, __VA_ARGS__) +#define gSPObjLoadTxRect(gdl, ...) \ + gD_(gdl, gsSPObjLoadTxRect, __VA_ARGS__) +#define gSPObjLoadTxRectR(gdl, ...) \ + gD_(gdl, gsSPObjLoadTxRectR, __VA_ARGS__) +#define gSPObjLoadTxSprite(gdl, ...) \ + gD_(gdl, gsSPObjLoadTxSprite, __VA_ARGS__) +#define gSPSelectDL(gdl, ...) \ + gD_(gdl, gsSPSelectDL, __VA_ARGS__) +#define gSPSelectBranchDL(gdl, ...) \ + gD_(gdl, gsSPSelectBranchDL, __VA_ARGS__) +#define gDPLoadTLUTCmd(gdl, ...) \ + gD_(gdl, gsDPLoadTLUTCmd, __VA_ARGS__) +#define gDPLoadTLUT(gdl, ...) \ + gD_(gdl, gsDPLoadTLUT, __VA_ARGS__) +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +# define gBranchZ(gdl, ...) \ + gD_(gdl, gsBranchZ, __VA_ARGS__) +#endif +#define gDisplayList(gdl, ...) \ + gD_(gdl, gsDisplayList, __VA_ARGS__) +#define gDPHalf1(gdl, ...) \ + gD_(gdl, gsDPHalf1, __VA_ARGS__) +#define gDPHalf2(gdl, ...) \ + gD_(gdl, gsDPHalf2, __VA_ARGS__) +#define gDPLoadTile(gdl, ...) \ + gD_(gdl, gsDPLoadTile, __VA_ARGS__) +#define gDPSetCombine(gdl, ...) \ + gD_(gdl, gsDPSetCombine, __VA_ARGS__) +#if defined(F3DEX_GBI_2) +# define gSPGeometryMode(gdl, ...) \ + gD_(gdl, gsSPGeometryMode, __VA_ARGS__) +#endif +#define gSPSetOtherMode(gdl, ...) \ + gD_(gdl, gsSPSetOtherMode, __VA_ARGS__) +#define gSPSetOtherModeLo(gdl, ...) \ + gD_(gdl, gsSPSetOtherModeLo, __VA_ARGS__) +#define gSPSetOtherModeHi(gdl, ...) \ + gD_(gdl, gsSPSetOtherModeHi, __VA_ARGS__) +#define gDPSetOtherMode(gdl, ...) \ + gD_(gdl, gsDPSetOtherMode, __VA_ARGS__) +#define gMoveWd(gdl, ...) \ + gD_(gdl, gsMoveWd, __VA_ARGS__) +#define gMoveMem(gdl, ...) \ + gD_(gdl, gsMoveMem, __VA_ARGS__) +#if defined(F3DEX_GBI_2) +# define gSPDma_io(gdl, ...) \ + gD_(gdl, gsSPDma_io, __VA_ARGS__) +# define gSPDmaRead(gdl, ...) \ + gD_(gdl, gsSPDmaRead, __VA_ARGS__) +# define gSPDmaWrite(gdl, ...) \ + gD_(gdl, gsSPDmaWrite, __VA_ARGS__) +#endif +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +# define gLoadUcode(gdl, ...) \ + gD_(gdl, gsLoadUcode, __VA_ARGS__) +# define gSPLoadUcodeEx(gdl, ...) \ + gD_(gdl, gsSPLoadUcodeEx, __VA_ARGS__) +#endif +#define gTexRect(gdl, ...) \ + gD_(gdl, gsTexRect, __VA_ARGS__) +#define gTexRectFlip(gdl, ...) \ + gD_(gdl, gsTexRectFlip, __VA_ARGS__) +#define gSPNoOp(gdl) \ + gDisplayListPut(gdl, gsSPNoOp()) +#define gDPWord(gdl, ...) \ + gD_(gdl, gsDPWord, __VA_ARGS__) +#if defined(F3DEX_GBI_2) +# define gSpecial3(gdl, ...) \ + gD_(gdl, gsSpecial3, __VA_ARGS__) +# define gSpecial2(gdl, ...) \ + gD_(gdl, gsSpecial2, __VA_ARGS__) +# define gSpecial1(gdl, ...) \ + gD_(gdl, gsSpecial1, __VA_ARGS__) +#endif + +/* data types and structures */ +typedef uint8_t qu08_t; +typedef uint16_t qu016_t; +typedef int16_t qs48_t; +typedef int16_t qs510_t; +typedef uint16_t qu510_t; +typedef int16_t qs102_t; +typedef uint16_t qu102_t; +typedef int16_t qs105_t; +typedef uint16_t qu105_t; +typedef int16_t qs132_t; +typedef int16_t qs142_t; +typedef int32_t qs1516_t; +typedef int32_t qs1616_t; +typedef int32_t qs205_t; + +typedef uint16_t g_bglt_t; +typedef uint8_t g_ifmt_t; +typedef uint8_t g_isiz_t; +typedef uint16_t g_bgf_t; +typedef uint8_t g_objf_t; +typedef uint32_t g_objlt_t; + +typedef struct +{ + _Alignas(8) + uint32_t hi; + uint32_t lo; +} Gfx; + +typedef struct +{ + int32_t x1; + int32_t y1; + int32_t x2; + int32_t y2; +} Hilite_t; + +typedef union +{ + _Alignas(8) + Hilite_t h; +} Hilite; + +typedef int32_t Mtx_t[4][4]; + +typedef union +{ + _Alignas(8) + Mtx_t m; + int32_t l[16]; + struct + { + int16_t i[16]; + uint16_t f[16]; + }; +} Mtx; + +typedef struct +{ + uint8_t col[3]; + char pad1; + uint8_t colc[3]; + char pad2; + int8_t dir[3]; + char pad3; +} Light_t; + +typedef union +{ + _Alignas(8) + Light_t l; +} Light; + +typedef struct +{ + Light l[2]; +} LookAt; + +typedef struct +{ + uint8_t col[3]; + char pad1; + uint8_t colc[3]; + char pad2; +} Ambient_t; + +typedef union +{ + _Alignas(8) + Ambient_t l; +} Ambient; + +typedef struct +{ + Ambient a; + Light l[1]; +} Lights0, Lights1; + +typedef struct +{ + Ambient a; + Light l[2]; +} Lights2; + +typedef struct +{ + Ambient a; + Light l[3]; +} Lights3; + +typedef struct +{ + Ambient a; + Light l[4]; +} Lights4; + +typedef struct +{ + Ambient a; + Light l[5]; +} Lights5; + +typedef struct +{ + Ambient a; + Light l[6]; +} Lights6; + +typedef struct +{ + Ambient a; + Light l[7]; +} Lightsn, Lights7; + +typedef struct +{ + int16_t ob[3]; + uint16_t flag; + qs105_t tc[2]; + uint8_t cn[4]; +} Vtx_t; + +typedef struct +{ + int16_t ob[3]; + uint16_t flag; + qs105_t tc[2]; + int8_t n[3]; + uint8_t a; +} Vtx_tn; + +typedef union +{ + _Alignas(8) + Vtx_t v; + Vtx_tn n; +} Vtx; + +typedef struct +{ + qs142_t vscale[4]; + qs142_t vtrans[4]; +} Vp_t; + +typedef union +{ + _Alignas(8) + Vp_t vp; +} Vp; + +typedef struct +{ + qs1516_t A; + qs1516_t B; + qs1516_t C; + qs1516_t D; + qs102_t X; + qs102_t Y; + qu510_t BaseScaleX; + qu510_t BaseScaleY; +} uObjMtx_t; + +typedef union +{ + _Alignas(8) + uObjMtx_t m; +} uObjMtx; + +typedef struct +{ + qs102_t X; + qs102_t Y; + qu510_t BaseScaleX; + qu510_t BaseScaleY; +} uObjSubMtx_t; + +typedef union +{ + _Alignas(8) + uObjSubMtx_t m; +} uObjSubMtx; + +typedef struct +{ + qu105_t imageX; + qu102_t imageW; + qs102_t frameX; + qu102_t frameW; + qu105_t imageY; + qu102_t imageH; + qs102_t frameY; + qu102_t frameH; + uint64_t * imagePtr; + g_bglt_t imageLoad; + g_ifmt_t imageFmt; + g_isiz_t imageSiz; + uint16_t imagePal; + g_bgf_t imageFlip; + uint16_t tmemW; + qs132_t tmemH; + uint16_t tmemLoadSH; + uint16_t tmemLoadTH; + uint16_t tmemSizeW; + uint16_t tmemSize; +} uObjBg_t; + +typedef struct +{ + qu105_t imageX; + qu102_t imageW; + qs102_t frameX; + qu102_t frameW; + qu105_t imageY; + qu102_t imageH; + qs102_t frameY; + qu102_t frameH; + uint64_t * imagePtr; + g_bglt_t imageLoad; + g_ifmt_t imageFmt; + g_isiz_t imageSiz; + uint16_t imagePal; + g_bgf_t imageFlip; + qu510_t scaleW; + qu510_t scaleH; + qs205_t imageYorig; + char padding[4]; +} uObjScaleBg_t; + +typedef union +{ + _Alignas(8) + uObjBg_t b; + uObjScaleBg_t s; +} uObjBg; + +typedef struct +{ + qs102_t objX; + qu510_t scaleW; + qu105_t imageW; + uint16_t paddingX; + qs102_t objY; + qu510_t scaleH; + qu105_t imageH; + uint16_t paddingY; + uint16_t imageStride; + uint16_t imageAdrs; + g_ifmt_t imageFmt; + g_isiz_t imageSiz; + uint16_t imagePal; + g_objf_t imageFlags; +} uObjSprite_t; + +typedef union +{ + _Alignas(8) + uObjSprite_t s; +} uObjSprite; + +typedef struct +{ + g_objlt_t type; + uint64_t * image; + uint16_t tmem; + uint16_t tsize; + uint16_t tline; + uint16_t sid; + uint32_t flag; + uint32_t mask; +} uObjTxtrBlock_t; + +typedef struct +{ + g_objlt_t type; + uint64_t * image; + uint16_t tmem; + uint16_t twidth; + uint16_t theight; + uint16_t sid; + uint32_t flag; + uint32_t mask; +} uObjTxtrTile_t; + +typedef struct +{ + g_objlt_t type; + uint64_t * image; + uint16_t phead; + uint16_t pnum; + uint16_t zero; + uint16_t sid; + uint32_t flag; + uint32_t mask; +} uObjTxtrTLUT_t; + +typedef union +{ + _Alignas(8) + uObjTxtrBlock_t block; + uObjTxtrTile_t tile; + uObjTxtrTLUT_t tlut; +} uObjTxtr; + +typedef struct +{ + uObjTxtr txtr; + uObjSprite sprite; +} uObjTxSprite; + +/* rectangle scissoring macros */ +#define gScC_(c) ((c) < 0 ? 0 : (c)) +#define gScD_(t, c, d) \ + ( \ + (c) < 0 ? \ + ( \ + (d) < 0 ? \ + (t) + (c) * (d) / 0x80 : \ + (t) - (c) * (d) / 0x80 \ + ) : \ + (t) \ + ) + +/* texture loading helper macros */ +#define G_SIZ_LDSIZ(siz) ((siz) < G_IM_SIZ_16b ? G_IM_SIZ_16b : (siz)) +#define G_SIZ_BITS(siz) (4 << gI_(siz)) +#define G_SIZ_LDBITS(siz) ((siz) < G_IM_SIZ_16b ? G_SIZ_BITS(siz) : 16) +#define G_DXT(siz, width) \ + ( \ + (width) * G_SIZ_BITS(siz) <= 64 ? \ + (1 << 11) : \ + ((1 << 11) + (width) * G_SIZ_BITS(siz) / 64 - 1) / \ + ((width) * G_SIZ_BITS(siz) / 64) \ + ) + +/* depth value macros */ +#define gZp_(zval, near, far) \ + ( \ + (1.f - (float)(near) / (float)(zval)) / \ + (1.f - (float)(near) / (float)(far)) \ + ) +#define gZo_(zval, near, far) \ + ( \ + ((float)(zval) - (float)(near)) / \ + ((float)(far) - (float)(near)) \ + ) +#define gZf_(zval, near, far, flag) \ + qs1616 \ + ( \ + (flag) == G_BZ_PERSP ? \ + gZp_(zval, near, far) : \ + gZo_(zval, near, far) \ + ) +#define G_DEPTOZSrg(zval, near, far, flag, zmin, zmax) \ + ( \ + gZf_(zval, near, far, flag) * \ + ((int32_t)((zmax) - (zmin)) & ~(int32_t)1) + \ + qs1616(zmin) \ + ) +#define G_DEPTOZS(zval, near, far, flag) \ + G_DEPTOZSrg(zval, near, far, flag, 0, G_MAXZ) + +/* vertex ordering macros */ +#define gV2_(v0, v1, flag) \ + ( \ + (flag) == 0 ? gI_(v0) : \ + gI_(v1) \ + ) +#define gV3_(v0, v1, v2, flag) \ + ( \ + (flag) == 0 ? gI_(v0) : \ + (flag) == 1 ? gI_(v1) : \ + gI_(v2) \ + ) +#define gV4_(v0, v1, v2, v3, flag) \ + ( \ + (flag) == 0 ? gI_(v0) : \ + (flag) == 1 ? gI_(v1) : \ + (flag) == 2 ? gI_(v2) : \ + gI_(v3) \ + ) + +/* sprite texture parameter macros */ +#define GS_PIX2TMEM(pix, siz) ((pix) * G_SIZ_BITS(siz) / 64) +#define GS_TB_TSIZE(pix, siz) (GS_PIX2TMEM(pix, siz) - 1) +#define GS_TB_TLINE(pix, siz) (((1 << 11) - 1) / GS_PIX2TMEM(pix, siz) + 1) +#define GS_TT_TWIDTH(pix, siz) (GS_PIX2TMEM(pix, siz) * 4 - 1) +#define GS_TT_THEIGHT(pix, siz) ((pix) * 4 - 1) +#define GS_PAL_HEAD(head) ((head) + 256) +#define GS_PAL_NUM(num) ((num) - 1) + +/* fixed-point conversion macros */ +#define qu08(n) ((qu08_t)((n) * 0x100)) +#define qu016(n) ((qu016_t)((n) * 0x10000)) +#define qs48(n) ((qs48_t)((n) * 0x0100)) +#define qs510(n) ((qs510_t)((n) * 0x0400)) +#define qu510(n) ((qu510_t)((n) * 0x0400)) +#define qs102(n) ((qs102_t)((n) * 0x0004)) +#define qu102(n) ((qu102_t)((n) * 0x0004)) +#define qs105(n) ((qs105_t)((n) * 0x0020)) +#define qu105(n) ((qu105_t)((n) * 0x0020)) +#define qs132(n) ((qs132_t)((n) * 0x0004)) +#define qs142(n) ((qs142_t)((n) * 0x0004)) +#define qs1516(n) ((qs1516_t)((n) * 0x00010000)) +#define qs1616(n) ((qs1616_t)((n) * 0x00010000)) +#define qs205(n) ((qs205_t)((n) * 0x00000020)) + +/* private helper macros */ +#define gI_(i) ((uint32_t)(i)) +#define gL_(l) ((uint64_t)(l)) +#define gF_(i, n, s) ((gI_(i) & ((gI_(1) << (n)) - 1)) << (s)) +#define gFL_(l, n, s) ((gL_(l) & ((gL_(1) << (n)) - 1)) << (s)) +#define gO_(opc, hi, lo) ((Gfx){gF_(opc, 8, 24) | gI_(hi), gI_(lo)}) +#define gD_(gdl, m, ...) gDisplayListPut(gdl, m(__VA_ARGS__)) + +#endif diff --git a/tools/ZAPD/lib/libgfxd/gfxd.c b/tools/ZAPD/lib/libgfxd/gfxd.c new file mode 100644 index 0000000000..76d7ded8a7 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/gfxd.c @@ -0,0 +1,863 @@ +#include +#include +#include +#include +#include +#ifdef _WIN32 +# include +# define read _read +# define write _write +#else +# include +#endif +#include "gbi.h" +#include "gfxd.h" +#include "priv.h" + +static TLOCAL struct gfxd_state state; + +static int buffer_input_fn(void *buf, int count) +{ + if (count > config.input_buf_size) + count = config.input_buf_size; + memcpy(buf, config.input_buf, count); + config.input_buf += count; + config.input_buf_size -= count; + return count; +} + +static int buffer_output_fn(const char *buf, int count) +{ + if (count > config.output_buf_size) + count = config.output_buf_size; + memcpy(config.output_buf, buf, count); + config.output_buf += count; + config.output_buf_size -= count; + return count; +} + +static int fd_input_fn(void *buf, int count) +{ + return read(config.input_fd, buf, count); +} + +static int fd_output_fn(const char *buf, int count) +{ + return write(config.output_fd, buf, count); +} + +static void swap_words(Gfx *gfx) +{ + uint8_t b[8]; + uint8_t *pw = (void *) gfx; + uint8_t *pb = b; + + int endian = config.endian; + int wordsize = config.wordsize; + + for (int i = 0; i < 8 / wordsize; i++) + { + if (endian == gfxd_endian_host) + { + switch (wordsize) + { + case 1: + { + uint8_t w = *(uint8_t *) pw; + *pb++ = w >> 0; + break; + } + case 2: + { + uint16_t w = *(uint16_t *) pw; + *pb++ = w >> 8; + *pb++ = w >> 0; + break; + } + case 4: + { + uint32_t w = *(uint32_t *) pw; + *pb++ = w >> 24; + *pb++ = w >> 16; + *pb++ = w >> 8; + *pb++ = w >> 0; + break; + } + case 8: + { + uint64_t w = *(uint64_t *) pw; + *pb++ = w >> 56; + *pb++ = w >> 48; + *pb++ = w >> 40; + *pb++ = w >> 32; + *pb++ = w >> 24; + *pb++ = w >> 16; + *pb++ = w >> 8; + *pb++ = w >> 0; + break; + } + } + } + else + { + for (int j = 0; j < wordsize; j++) + { + if (endian == gfxd_endian_little) + *pb++ = pw[wordsize - 1 - j]; + else + *pb++ = pw[j]; + } + } + pw += wordsize; + } + + gfx->hi = ((uint32_t) b[0] << 24) + | ((uint32_t) b[1] << 16) + | ((uint32_t) b[2] << 8) + | ((uint32_t) b[3] << 0); + gfx->lo = ((uint32_t) b[4] << 24) + | ((uint32_t) b[5] << 16) + | ((uint32_t) b[6] << 8) + | ((uint32_t) b[7] << 0); +} + +static void get_more_input(void) +{ + if (state.end_input != 0) + return; + + char *recv_buf = (void *) &state.gfx[0]; + + while (state.n_gfx < sizeof(state.gfx) / sizeof(state.gfx[0])) + { + int n_read = sizeof(state.gfx) - state.n_byte; + n_read = config.input_fn(&recv_buf[state.n_byte], n_read); + if (n_read == 0) + return; + state.n_byte += n_read; + + while (state.n_gfx < state.n_byte / sizeof(Gfx)) + { + Gfx gfx = state.gfx[state.n_gfx]; + gfxd_macro_t *m = &state.macro[state.n_gfx]; + + swap_words(&gfx); + + int ret = config.ucode->disas_fn(m, gfx.hi, gfx.lo); + if (ret != 0 && config.stop_on_invalid != 0) + { + state.end_input = 1; + state.ret = ret; + return; + } + + state.n_gfx++; + } + } +} + +static int32_t typed_arg_i(int type, int idx) +{ + const gfxd_value_t *v = gfxd_value_by_type(type, idx); + if (v != NULL) + return v->i; + else + return -1; +} + +static uint32_t typed_arg_u(int type, int idx) +{ + const gfxd_value_t *v = gfxd_value_by_type(type, idx); + if (v != NULL) + return v->u; + else + return 0; +} + + +TLOCAL struct gfxd_config config = +{ + .ucode = NULL, + .endian = gfxd_endian_big, + .wordsize = 4, + .arg = NULL, + + .stop_on_invalid = 1, + .stop_on_end = 1, + .emit_dec_color = 0, + .emit_q_macro = 0, + .emit_ext_macro = 0, + + .input_buf = NULL, + .input_buf_size = 0, + .input_fn = &buffer_input_fn, + + .output_buf = NULL, + .output_buf_size = 0, + .output_fn = &buffer_output_fn, + + .macro_fn = &gfxd_macro_dflt, + .arg_fn = &gfxd_arg_dflt, + + .tlut_fn = NULL, + .timg_fn = NULL, + .cimg_fn = NULL, + .zimg_fn = NULL, + .dl_fn = NULL, + .mtx_fn = NULL, + .lookat_fn = NULL, + .light_fn = NULL, + .seg_fn = NULL, + .vtx_fn = NULL, + .vp_fn = NULL, + .uctext_fn = NULL, + .ucdata_fn = NULL, + .dram_fn = NULL, +}; + +void gfxd_input_buffer(const void *buf, int size) +{ + config.input_buf = buf; + config.input_buf_size = size; + config.input_fn = &buffer_input_fn; +} + +void gfxd_output_buffer(char *buf, int size) +{ + config.output_buf = buf; + config.output_buf_size = size; + config.output_fn = &buffer_output_fn; +} + +void gfxd_input_fd(int fd) +{ + config.input_fd = fd; + config.input_fn = &fd_input_fn; +} + +void gfxd_output_fd(int fd) +{ + config.output_fd = fd; + config.output_fn = &fd_output_fn; +} + +void gfxd_input_callback(gfxd_input_fn_t *fn) +{ + if (fn != NULL) + config.input_fn = fn; + else + gfxd_input_buffer(NULL, 0); +} + +void gfxd_output_callback(gfxd_output_fn_t *fn) +{ + if (fn != NULL) + config.output_fn = fn; + else + gfxd_output_buffer(NULL, 0); +} + +void gfxd_macro_fn(gfxd_macro_fn_t *fn) +{ + if (fn != NULL) + config.macro_fn = fn; + else + config.macro_fn = gfxd_macro_dflt; +} + +void gfxd_arg_fn(gfxd_arg_fn_t *fn) +{ + if (fn != NULL) + config.arg_fn = fn; + else + config.arg_fn = gfxd_arg_dflt; +} + +int gfxd_write(const void *buf, int count) +{ + return config.output_fn(buf, count); +} + +int gfxd_puts(const char *str) +{ + return gfxd_write(str, strlen(str)); +} + +int gfxd_printf(const char *fmt, ...) +{ + char s[256]; + + va_list arg; + va_start(arg, fmt); + int n = vsnprintf(s, sizeof(s), fmt, arg); + va_end(arg); + + if (n > sizeof(s) - 1) + n = sizeof(s) - 1; + + return gfxd_write(s, n); +} + +int gfxd_print_value(int type, const gfxd_value_t *value) +{ + return config.ucode->arg_tbl[type].fn(value); +} + +int gfxd_macro_dflt(void) +{ + gfxd_macro_t *m = &state.macro[0]; + const gfxd_macro_type_t *t = &config.ucode->macro_tbl[m->id]; + + const char *name = gfxd_macro_name(); + if (name == NULL) + { + if (config.arg != NULL) + { + gfxd_puts(config.arg); + gfxd_puts(" = "); + } + + gfxd_puts("(Gfx){"); + } + else + { + gfxd_puts(name); + gfxd_puts("("); + + if (config.arg != NULL) + { + gfxd_puts(config.arg); + if (t->n_arg != 0) + gfxd_puts(", "); + } + } + + for (int i = 0; i < t->n_arg; i++) + { + if (i != 0) + gfxd_puts(", "); + + config.arg_fn(i); + } + + if (name == NULL) + gfxd_puts("}"); + else + gfxd_puts(")"); + + return 0; +} + +int gfxd_arg_callbacks(int arg_num) +{ + int id = gfxd_macro_id(); + + switch (gfxd_arg_type(arg_num)) + { + case gfxd_Tlut: + { + if (config.tlut_fn != NULL) + { + int32_t num; + if (id == gfxd_DPLoadTLUT_pal16) + num = 16; + else if (id == gfxd_DPLoadTLUT_pal256) + num = 256; + else + num = typed_arg_i(gfxd_Num, 0); + return config.tlut_fn( + typed_arg_u(gfxd_Tlut, 0), + typed_arg_i(gfxd_Pal, 0), + num); + } + break; + } + case gfxd_Timg: + { + if (config.timg_fn != NULL) + { + int32_t siz = typed_arg_i(gfxd_Siz, 0); + if (siz == -1) + siz = G_IM_SIZ_4b; + return config.timg_fn( + typed_arg_u(gfxd_Timg, 0), + typed_arg_i(gfxd_Fmt, 0), + siz, + typed_arg_i(gfxd_Dim, 0), + typed_arg_i(gfxd_Dim, 1), + typed_arg_i(gfxd_Pal, 0)); + } + break; + } + case gfxd_Cimg: + { + if (config.cimg_fn != NULL) + { + return config.cimg_fn( + typed_arg_u(gfxd_Cimg, 0), + typed_arg_i(gfxd_Fmt, 0), + typed_arg_i(gfxd_Siz, 0), + typed_arg_i(gfxd_Dim, 0)); + } + break; + } + case gfxd_Zimg: + { + if (config.zimg_fn != NULL) + { + return config.zimg_fn( + typed_arg_u(gfxd_Zimg, 0)); + } + break; + } + case gfxd_Dl: + { + if (config.dl_fn != NULL) + { + return config.dl_fn( + typed_arg_u(gfxd_Dl, 0)); + } + break; + } + case gfxd_Mtxptr: + { + if (config.mtx_fn != NULL) + { + return config.mtx_fn( + typed_arg_u(gfxd_Mtxptr, 0)); + } + break; + } + case gfxd_Lookatptr: + { + if (config.lookat_fn != NULL) + { + int32_t num; + if (id == gfxd_SPLookAt) + num = 2; + else + num = 1; + return config.lookat_fn( + typed_arg_u(gfxd_Lookatptr, 0), + num); + } + break; + } + case gfxd_Lightptr: + { + if (config.light_fn != NULL) + { + int32_t num; + if (id == gfxd_SPSetLights1) + num = 1; + else if (id == gfxd_SPSetLights2) + num = 2; + else if (id == gfxd_SPSetLights3) + num = 3; + else if (id == gfxd_SPSetLights4) + num = 4; + else if (id == gfxd_SPSetLights5) + num = 5; + else if (id == gfxd_SPSetLights6) + num = 6; + else if (id == gfxd_SPSetLights7) + num = 7; + else + num = 1; + return config.light_fn( + typed_arg_u(gfxd_Lightptr, 0), + num); + } + break; + + } + case gfxd_Segptr: + { + if (config.seg_fn != NULL) + { + return config.seg_fn( + typed_arg_u(gfxd_Segptr, 0), + typed_arg_i(gfxd_Seg, 0)); + } + break; + } + case gfxd_Vtxptr: + { + if (config.vtx_fn != NULL) + { + return config.vtx_fn( + typed_arg_u(gfxd_Vtxptr, 0), + typed_arg_i(gfxd_Num, 0)); + } + break; + } + case gfxd_Vpptr: + { + if (config.vp_fn != NULL) + { + return config.vp_fn( + typed_arg_u(gfxd_Vpptr, 0)); + } + break; + } + case gfxd_Uctext: + { + if (config.uctext_fn != NULL) + { + return config.uctext_fn( + typed_arg_u(gfxd_Uctext, 0), + 0x1000); + } + break; + } + case gfxd_Ucdata: + { + if (config.ucdata_fn != NULL) + { + uint32_t size; + if (id == gfxd_SPLoadUcodeEx) + size = typed_arg_u(gfxd_Size, 0); + else + size = 0x800; + return config.ucdata_fn( + typed_arg_u(gfxd_Ucdata, 0), + size); + } + break; + } + case gfxd_Dram: + { + if (config.dram_fn != NULL) + { + return config.dram_fn( + typed_arg_u(gfxd_Dram, 0), + typed_arg_u(gfxd_Size, 0)); + } + break; + } + } + + return 0; +} + +void gfxd_arg_dflt(int arg_num) +{ + if (gfxd_arg_callbacks(arg_num) == 0) + { + gfxd_arg_t *a = &state.macro[0].arg[arg_num]; + + gfxd_print_value(a->type, &a->value); + } +} + +void gfxd_tlut_callback(gfxd_tlut_fn_t *fn) +{ + config.tlut_fn = fn; +} + +void gfxd_timg_callback(gfxd_timg_fn_t *fn) +{ + config.timg_fn = fn; +} + +void gfxd_cimg_callback(gfxd_cimg_fn_t *fn) +{ + config.cimg_fn = fn; +} + +void gfxd_zimg_callback(gfxd_zimg_fn_t *fn) +{ + config.zimg_fn = fn; +} + +void gfxd_dl_callback(gfxd_dl_fn_t *fn) +{ + config.dl_fn = fn; +} + +void gfxd_mtx_callback(gfxd_mtx_fn_t *fn) +{ + config.mtx_fn = fn; +} + +void gfxd_lookat_callback(gfxd_lookat_fn_t *fn) +{ + config.lookat_fn = fn; +} + +void gfxd_light_callback(gfxd_light_fn_t *fn) +{ + config.light_fn = fn; +} + +void gfxd_seg_callback(gfxd_seg_fn_t *fn) +{ + config.seg_fn = fn; +} + +void gfxd_vtx_callback(gfxd_vtx_fn_t *fn) +{ + config.vtx_fn = fn; +} + +void gfxd_vp_callback(gfxd_vp_fn_t *fn) +{ + config.vp_fn = fn; +} + +void gfxd_uctext_callback(gfxd_uctext_fn_t *fn) +{ + config.uctext_fn = fn; +} + +void gfxd_ucdata_callback(gfxd_ucdata_fn_t *fn) +{ + config.ucdata_fn = fn; +} + +void gfxd_dram_callback(gfxd_dram_fn_t *fn) +{ + config.dram_fn = fn; +} + +void gfxd_target(gfxd_ucode_t ucode) +{ + config.ucode = ucode; +} + +void gfxd_endian(int endian, int wordsize) +{ + config.endian = endian; + config.wordsize = wordsize; +} + +void gfxd_dynamic(const char *arg) +{ + config.arg = arg; +} + +void gfxd_enable(int cap) +{ + switch (cap) + { + case gfxd_stop_on_invalid: + config.stop_on_invalid = 1; + break; + + case gfxd_stop_on_end: + config.stop_on_end = 1; + break; + + case gfxd_emit_dec_color: + config.emit_dec_color = 1; + break; + + case gfxd_emit_q_macro: + config.emit_q_macro = 1; + break; + + case gfxd_emit_ext_macro: + config.emit_ext_macro = 1; + break; + } +} + +void gfxd_disable(int cap) +{ + switch (cap) + { + case gfxd_stop_on_invalid: + config.stop_on_invalid = 0; + return; + + case gfxd_stop_on_end: + config.stop_on_end = 0; + return; + + case gfxd_emit_dec_color: + config.emit_dec_color = 0; + break; + + case gfxd_emit_q_macro: + config.emit_q_macro = 0; + break; + + case gfxd_emit_ext_macro: + config.emit_ext_macro = 0; + break; + } +} + +void gfxd_udata_set(void *ptr) +{ + config.udata = ptr; +} + +void *gfxd_udata_get(void) +{ + return config.udata; +} + +int gfxd_execute(void) +{ + state.macro_offset = 0; + state.n_byte = 0; + state.n_gfx = 0; + state.end_input = 0; + state.ret = 0; + + for (;;) + { + get_more_input(); + if (state.n_gfx == 0) + break; + + gfxd_macro_t *m = &state.macro[0]; + config.ucode->combine_fn(m, state.n_gfx); + + const gfxd_macro_type_t *t = &config.ucode->macro_tbl[m->id]; + if (t->ext != 0 && config.emit_ext_macro == 0) + { + Gfx gfx = state.gfx[0]; + swap_words(&gfx); + + t = &config.ucode->macro_tbl[gfxd_Invalid]; + t->disas_fn(m, gfx.hi, gfx.lo); + } + + int ret = config.macro_fn(); + if (ret != 0) + { + state.ret = ret; + break; + } + + if (config.stop_on_end != 0 + && (m->id == gfxd_SPBranchList + || m->id == gfxd_SPEndDisplayList)) + { + break; + } + + int n_pop = config.ucode->macro_tbl[m->id].n_gfx; + int n_rem = state.n_gfx - n_pop; + { + int n_byte = n_rem * sizeof(gfxd_macro_t); + memmove(&state.macro[0], &state.macro[n_pop], n_byte); + state.n_gfx = n_rem; + } + { + int n_byte = n_rem * sizeof(Gfx); + memmove(&state.gfx[0], &state.gfx[n_pop], n_byte); + state.n_byte = n_byte; + } + state.macro_offset += n_pop * sizeof(Gfx); + } + + return state.ret; +} + +int gfxd_macro_offset(void) +{ + return state.macro_offset; +} + +int gfxd_macro_packets(void) +{ + return config.ucode->macro_tbl[state.macro[0].id].n_gfx; +} + +const void *gfxd_macro_data(void) +{ + return state.gfx; +} + +int gfxd_macro_id(void) +{ + return state.macro[0].id; +} + +const char *gfxd_macro_name(void) +{ + int id = state.macro[0].id; + const gfxd_macro_type_t *t = &config.ucode->macro_tbl[id]; + + if (t->prefix == NULL && t->suffix == NULL) + { + return NULL; + } + else + { + static TLOCAL char buf[32]; + + char *p = buf; + if (t->prefix != NULL) + { + const char *s = t->prefix; + while (*s != '\0') + *p++ = *s++; + } + *p++ = 'g'; + if (config.arg == NULL) + *p++ = 's'; + if (t->suffix != NULL) + { + const char *s = t->suffix; + while (*s != '\0') + *p++ = *s++; + } + *p++ = '\0'; + + return buf; + } +} + +int gfxd_arg_count(void) +{ + return config.ucode->macro_tbl[state.macro[0].id].n_arg; +} + +int gfxd_arg_type(int arg_num) +{ + return state.macro[0].arg[arg_num].type; +} + +const char *gfxd_arg_name(int arg_num) +{ + return state.macro[0].arg[arg_num].name; +} + +int gfxd_arg_fmt(int arg_num) +{ + return config.ucode->arg_tbl[state.macro[0].arg[arg_num].type].fmt; +} + +const gfxd_value_t *gfxd_arg_value(int arg_num) +{ + return &state.macro[0].arg[arg_num].value; +} + +const gfxd_value_t *gfxd_value_by_type(int type, int idx) +{ + gfxd_macro_t *m = &state.macro[0]; + const gfxd_macro_type_t *t = &config.ucode->macro_tbl[m->id]; + + for (int i = 0; i < t->n_arg; i++) + { + gfxd_arg_t *a = &m->arg[i]; + if (a->type == type) + { + if (idx == 0) + return &a->value; + else + idx--; + } + } + + return NULL; +} + +int gfxd_arg_valid(int arg_num) +{ + return state.macro[0].arg[arg_num].bad == 0; +} diff --git a/tools/ZAPD/lib/libgfxd/gfxd.h b/tools/ZAPD/lib/libgfxd/gfxd.h index ee0fc64c9e..268bbfa10f 100644 --- a/tools/ZAPD/lib/libgfxd/gfxd.h +++ b/tools/ZAPD/lib/libgfxd/gfxd.h @@ -10,6 +10,7 @@ extern "C" enum { gfxd_Word, /* generic word */ + gfxd_Opcode, /* command opcode (G_*) */ gfxd_Coordi, /* integer coordinate */ gfxd_Coordq, /* fractional (q10.2) coordinate */ gfxd_Pal, /* palette index */ @@ -65,7 +66,8 @@ enum gfxd_Dlflag, /* display list flag */ gfxd_Cr, /* clip ratio */ gfxd_Num, /* element count */ - gfxd_Fogz, /* fog depth (0 - 1000) */ + gfxd_Fogz, /* fog factor */ + gfxd_Fogp, /* fog position (0 - 1000) */ gfxd_Mtxptr, /* matrix pointer */ gfxd_Gm, /* geometry mode */ gfxd_Mwo_matrix, /* matrix moveword offset */ @@ -186,6 +188,7 @@ enum gfxd_SPCullDisplayList, gfxd_SPDisplayList, gfxd_SPEndDisplayList, + gfxd_SPFogFactor, gfxd_SPFogPosition, gfxd_SPForceMatrix, gfxd_SPSetGeometryMode, @@ -225,8 +228,10 @@ enum gfxd_DisplayList, gfxd_DPHalf1, gfxd_DPHalf2, + gfxd_DPWord, gfxd_DPLoadTile, gfxd_SPGeometryMode, + gfxd_SPSetOtherMode, gfxd_SPSetOtherModeLo, gfxd_SPSetOtherModeHi, gfxd_DPSetOtherMode, @@ -251,12 +256,14 @@ enum gfxd_stop_on_end, gfxd_emit_dec_color, gfxd_emit_q_macro, + gfxd_emit_ext_macro, }; enum { gfxd_endian_big, gfxd_endian_little, + gfxd_endian_host, }; enum @@ -347,6 +354,8 @@ void gfxd_endian(int endian, int wordsize); void gfxd_dynamic(const char *arg); void gfxd_enable(int cap); void gfxd_disable(int cap); +void gfxd_udata_set(void *ptr); +void *gfxd_udata_get(void); int gfxd_execute(void); diff --git a/tools/ZAPD/lib/libgfxd/libgfxd.a b/tools/ZAPD/lib/libgfxd/libgfxd.a deleted file mode 100644 index 1f8c0e2736..0000000000 Binary files a/tools/ZAPD/lib/libgfxd/libgfxd.a and /dev/null differ diff --git a/tools/ZAPD/lib/libgfxd/priv.h b/tools/ZAPD/lib/libgfxd/priv.h new file mode 100644 index 0000000000..37cb66b683 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/priv.h @@ -0,0 +1,123 @@ +#ifndef GFXD_PRIV_H +#define GFXD_PRIV_H +#include "gfxd.h" + +#ifdef CONFIG_MT +# ifdef _MSC_VER +# define TLOCAL __declspec(thread) +# else +# define TLOCAL _Thread_local +# endif +#else +# define TLOCAL +#endif + +#define UCFUNC static inline + +#define config gfxd_config__ + +typedef int gfxd_argfn_t(const gfxd_value_t *v); + +typedef struct +{ + int fmt; + gfxd_argfn_t * fn; +} gfxd_arg_type_t; + +typedef struct +{ + int type; + const char * name; + gfxd_value_t value; + int bad; +} gfxd_arg_t; + +typedef struct +{ + int id; + gfxd_arg_t arg[18]; +} gfxd_macro_t; + +typedef int gfxd_disas_fn_t(gfxd_macro_t *macro, uint32_t hi, uint32_t lo); +typedef int gfxd_combine_fn_t(gfxd_macro_t *macro, int n_macro); + +typedef struct +{ + const char * prefix; + const char * suffix; + int opcode; + int n_arg; + int n_gfx; + gfxd_disas_fn_t * disas_fn; + gfxd_combine_fn_t * combine_fn; + int alias; + int ext; +} gfxd_macro_type_t; + +struct gfxd_ucode +{ + gfxd_disas_fn_t * disas_fn; + gfxd_combine_fn_t * combine_fn; + const gfxd_arg_type_t * arg_tbl; + const gfxd_macro_type_t * macro_tbl; +}; + +struct gfxd_state +{ + int macro_offset; + + Gfx gfx[9]; + int n_byte; + int n_gfx; + gfxd_macro_t macro[9]; + + int end_input; + int ret; +}; + +struct gfxd_config +{ + gfxd_ucode_t ucode; + int endian; + int wordsize; + const char * arg; + void * udata; + + int stop_on_invalid; + int stop_on_end; + int emit_dec_color; + int emit_q_macro; + int emit_ext_macro; + + const char * input_buf; + int input_buf_size; + int input_fd; + gfxd_input_fn_t * input_fn; + + char * output_buf; + int output_buf_size; + int output_fd; + gfxd_output_fn_t * output_fn; + + gfxd_macro_fn_t * macro_fn; + gfxd_arg_fn_t * arg_fn; + + gfxd_tlut_fn_t * tlut_fn; + gfxd_timg_fn_t * timg_fn; + gfxd_cimg_fn_t * cimg_fn; + gfxd_zimg_fn_t * zimg_fn; + gfxd_dl_fn_t * dl_fn; + gfxd_mtx_fn_t * mtx_fn; + gfxd_lookat_fn_t * lookat_fn; + gfxd_light_fn_t * light_fn; + gfxd_seg_fn_t * seg_fn; + gfxd_vtx_fn_t * vtx_fn; + gfxd_vp_fn_t * vp_fn; + gfxd_uctext_fn_t * uctext_fn; + gfxd_ucdata_fn_t * ucdata_fn; + gfxd_dram_fn_t * dram_fn; +}; + +extern TLOCAL struct gfxd_config gfxd_config__; + +#endif diff --git a/tools/ZAPD/lib/libgfxd/uc.c b/tools/ZAPD/lib/libgfxd/uc.c new file mode 100644 index 0000000000..7efb091052 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include "gbi.h" +#include "gfxd.h" +#include "priv.h" + +#include "uc_argfn.c" +#include "uc_argtbl.c" +#include "uc_macrofn.c" +#include "uc_macrotbl.c" + +UCFUNC int disas(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int opcode = (hi >> 24) & 0xFF; + + for (int i = 0; i < sizeof(macro_tbl) / sizeof(macro_tbl[0]); i++) + { + const gfxd_macro_type_t *t = ¯o_tbl[i]; + if (t->disas_fn != NULL && t->opcode == opcode) + return t->disas_fn(m, hi, lo); + } + + return d_Invalid(m, hi, lo); +} + +UCFUNC int combine(gfxd_macro_t *m, int num) +{ + int opcode = macro_tbl[m->id].opcode; + + for (int i = 0; i < sizeof(macro_tbl) / sizeof(macro_tbl[0]); i++) + { + const gfxd_macro_type_t *t = ¯o_tbl[i]; + if (t->combine_fn != NULL + && t->opcode == opcode + && (t->ext == 0 || config.emit_ext_macro != 0)) + { + if (t->combine_fn(m, num) == 0) + return 0; + } + } + + return -1; +} + +static const struct gfxd_ucode uc = +{ + .disas_fn = disas, + .combine_fn = combine, + .arg_tbl = arg_tbl, + .macro_tbl = macro_tbl, +}; + +const gfxd_ucode_t uc_name = &uc; diff --git a/tools/ZAPD/lib/libgfxd/uc_argfn.c b/tools/ZAPD/lib/libgfxd/uc_argfn.c new file mode 100644 index 0000000000..f65feb60f7 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc_argfn.c @@ -0,0 +1,1814 @@ +#define MDMASK(md) ((((uint32_t)1 << G_MDSIZ_##md) - 1) << G_MDSFT_##md) +#define MDMASK_RM_C1 ((uint32_t)0xCCCC0000) +#define MDMASK_RM_C2 ((uint32_t)0x33330000) +#define MDMASK_RM_LO ((uint32_t)0x0000FFF8) + +UCFUNC int argfn_i(const gfxd_value_t *v) +{ + return gfxd_printf("%" PRIi32, v->i); +} + +UCFUNC int argfn_u(const gfxd_value_t *v) +{ + return gfxd_printf("%" PRIu32, v->u); +} + +UCFUNC int argfn_x8(const gfxd_value_t *v) +{ + return gfxd_printf("0x%02" PRIX32, v->u); +} + +UCFUNC int argfn_x16(const gfxd_value_t *v) +{ + return gfxd_printf("0x%04" PRIX32, v->u); +} + +UCFUNC int argfn_x32(const gfxd_value_t *v) +{ + return gfxd_printf("0x%08" PRIX32, v->u); +} + +UCFUNC int argfn_color(const gfxd_value_t *v) +{ + if (config.emit_dec_color) + return gfxd_printf("%" PRIu32, v->u); + else + return gfxd_printf("0x%02" PRIX32, v->u); +} + +UCFUNC int argfn_qu08(const gfxd_value_t *v) +{ + if (v->u == 0) + return gfxd_puts("0"); + else if (config.emit_q_macro) + return gfxd_printf("qu08(%.16g)", v->u / 256.f); + else + return gfxd_printf("0x%02" PRIX32, v->u); +} + +UCFUNC int argfn_qu016(const gfxd_value_t *v) +{ + if (v->u == 0) + return gfxd_puts("0"); + else if (config.emit_q_macro) + return gfxd_printf("qu016(%.16g)", v->u / 65536.f); + else + return gfxd_printf("0x%04" PRIX32, v->u); +} + +UCFUNC int argfn_qs48(const gfxd_value_t *v) +{ + if (v->i == 0) + return gfxd_puts("0"); + else if (config.emit_q_macro) + return gfxd_printf("qs48(%.16g)", v->i / 256.f); + else + { + if (v->i < 0) + return gfxd_printf("-0x%04" PRIX32, (uint32_t)-v->i); + else + return gfxd_printf("0x%04" PRIX32, (uint32_t)v->i); + } +} + +UCFUNC int argfn_qs510(const gfxd_value_t *v) +{ + if (v->i == 0) + return gfxd_puts("0"); + else if (config.emit_q_macro) + return gfxd_printf("qs510(%.16g)", v->i / 1024.f); + else + { + if (v->i < 0) + return gfxd_printf("-0x%04" PRIX32, (uint32_t)-v->i); + else + return gfxd_printf("0x%04" PRIX32, (uint32_t)v->i); + } +} + +UCFUNC int argfn_qu102(const gfxd_value_t *v) +{ + if (v->u == 0) + return gfxd_puts("0"); + else if (config.emit_q_macro) + return gfxd_printf("qu102(%.16g)", v->u / 4.f); + else + return gfxd_printf("0x%04" PRIX32, v->u); +} + +UCFUNC int argfn_qs105(const gfxd_value_t *v) +{ + if (v->i == 0) + return gfxd_puts("0"); + else if (config.emit_q_macro) + return gfxd_printf("qs105(%.16g)", v->i / 32.f); + else + { + if (v->i < 0) + return gfxd_printf("-0x%04" PRIX32, (uint32_t)-v->i); + else + return gfxd_printf("0x%04" PRIX32, (uint32_t)v->i); + } +} + +UCFUNC int argfn_qs1616(const gfxd_value_t *v) +{ + if (v->i == 0) + return gfxd_puts("0"); + else if (config.emit_q_macro) + return gfxd_printf("qs1616(%.16g)", v->i / 65536.f); + else + { + if (v->i < 0) + return gfxd_printf("-0x%08" PRIX32, (uint32_t)-v->i); + else + return gfxd_printf("0x%08" PRIX32, (uint32_t)v->i); + } +} + +UCFUNC int argfn_opc(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_SPNOOP: + return gfxd_puts("G_SPNOOP"); + case G_MTX: + return gfxd_puts("G_MTX"); + case G_MOVEMEM: + return gfxd_puts("G_MOVEMEM"); + case G_VTX: + return gfxd_puts("G_VTX"); + case G_DL: + return gfxd_puts("G_DL"); + case G_RDPHALF_2: + return gfxd_puts("G_RDPHALF_2"); + case G_RDPHALF_1: + return gfxd_puts("G_RDPHALF_1"); +#if defined(F3D_BETA) && (defined(F3D_GBI) || defined(F3DEX_GBI)) + case G_PERSPNORM: + return gfxd_puts("G_PERSPNORM"); +#endif + case G_LINE3D: + return gfxd_puts("G_LINE3D"); +#if defined(F3D_GBI) || defined(F3DEX_GBI) + case G_CLEARGEOMETRYMODE: + return gfxd_puts("G_CLEARGEOMETRYMODE"); + case G_SETGEOMETRYMODE: + return gfxd_puts("G_SETGEOMETRYMODE"); +#endif + case G_ENDDL: + return gfxd_puts("G_ENDDL"); + case G_SETOTHERMODE_L: + return gfxd_puts("G_SETOTHERMODE_L"); + case G_SETOTHERMODE_H: + return gfxd_puts("G_SETOTHERMODE_H"); + case G_TEXTURE: + return gfxd_puts("G_TEXTURE"); + case G_MOVEWORD: + return gfxd_puts("G_MOVEWORD"); + case G_POPMTX: + return gfxd_puts("G_POPMTX"); + case G_CULLDL: + return gfxd_puts("G_CULLDL"); + case G_TRI1: + return gfxd_puts("G_TRI1"); + case G_NOOP: + return gfxd_puts("G_NOOP"); +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) + case G_LOAD_UCODE: + return gfxd_puts("G_LOAD_UCODE"); + case G_BRANCH_Z: + return gfxd_puts("G_BRANCH_Z"); + case G_TRI2: + return gfxd_puts("G_TRI2"); +# if !(defined(F3D_BETA) && defined(F3DEX_GBI)) + case G_MODIFYVTX: + return gfxd_puts("G_MODIFYVTX"); +# endif +#endif +#if defined(F3DEX_GBI_2) + case G_QUAD: + return gfxd_puts("G_QUAD"); + case G_SPECIAL_3: + return gfxd_puts("G_SPECIAL_3"); + case G_SPECIAL_2: + return gfxd_puts("G_SPECIAL_2"); + case G_SPECIAL_1: + return gfxd_puts("G_SPECIAL_1"); + case G_DMA_IO: + return gfxd_puts("G_DMA_IO"); + case G_GEOMETRYMODE: + return gfxd_puts("G_GEOMETRYMODE"); +#endif + case G_TEXRECT: + return gfxd_puts("G_TEXRECT"); + case G_TEXRECTFLIP: + return gfxd_puts("G_TEXRECTFLIP"); + case G_RDPLOADSYNC: + return gfxd_puts("G_RDPLOADSYNC"); + case G_RDPPIPESYNC: + return gfxd_puts("G_RDPPIPESYNC"); + case G_RDPTILESYNC: + return gfxd_puts("G_RDPTILESYNC"); + case G_RDPFULLSYNC: + return gfxd_puts("G_RDPFULLSYNC"); + case G_SETKEYGB: + return gfxd_puts("G_SETKEYGB"); + case G_SETKEYR: + return gfxd_puts("G_SETKEYR"); + case G_SETCONVERT: + return gfxd_puts("G_SETCONVERT"); + case G_SETSCISSOR: + return gfxd_puts("G_SETSCISSOR"); + case G_SETPRIMDEPTH: + return gfxd_puts("G_SETPRIMDEPTH"); + case G_RDPSETOTHERMODE: + return gfxd_puts("G_RDPSETOTHERMODE"); + case G_LOADTLUT: + return gfxd_puts("G_LOADTLUT"); + case G_SETTILESIZE: + return gfxd_puts("G_SETTILESIZE"); + case G_LOADBLOCK: + return gfxd_puts("G_LOADBLOCK"); + case G_LOADTILE: + return gfxd_puts("G_LOADTILE"); + case G_SETTILE: + return gfxd_puts("G_SETTILE"); + case G_FILLRECT: + return gfxd_puts("G_FILLRECT"); + case G_SETFILLCOLOR: + return gfxd_puts("G_SETFILLCOLOR"); + case G_SETFOGCOLOR: + return gfxd_puts("G_SETFOGCOLOR"); + case G_SETBLENDCOLOR: + return gfxd_puts("G_SETBLENDCOLOR"); + case G_SETPRIMCOLOR: + return gfxd_puts("G_SETPRIMCOLOR"); + case G_SETENVCOLOR: + return gfxd_puts("G_SETENVCOLOR"); + case G_SETCOMBINE: + return gfxd_puts("G_SETCOMBINE"); + case G_SETTIMG: + return gfxd_puts("G_SETTIMG"); + case G_SETZIMG: + return gfxd_puts("G_SETZIMG"); + case G_SETCIMG: + return gfxd_puts("G_SETCIMG"); + default: + return gfxd_printf("0x%02" PRIX32, (uint32_t)v->i); + } +} + +UCFUNC int argfn_fmt(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_IM_FMT_RGBA: + return gfxd_puts("G_IM_FMT_RGBA"); + case G_IM_FMT_YUV: + return gfxd_puts("G_IM_FMT_YUV"); + case G_IM_FMT_CI: + return gfxd_puts("G_IM_FMT_CI"); + case G_IM_FMT_IA: + return gfxd_puts("G_IM_FMT_IA"); + case G_IM_FMT_I: + return gfxd_puts("G_IM_FMT_I"); + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +UCFUNC int argfn_siz(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_IM_SIZ_4b: + return gfxd_puts("G_IM_SIZ_4b"); + case G_IM_SIZ_8b: + return gfxd_puts("G_IM_SIZ_8b"); + case G_IM_SIZ_16b: + return gfxd_puts("G_IM_SIZ_16b"); + case G_IM_SIZ_32b: + return gfxd_puts("G_IM_SIZ_32b"); + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +UCFUNC int argfn_cm(const gfxd_value_t *v) +{ + int n = 0; + if (v->u & G_TX_MIRROR) + n += gfxd_puts("G_TX_MIRROR"); + else + n += gfxd_puts("G_TX_NOMIRROR"); + if (v->u & G_TX_CLAMP) + n += gfxd_puts(" | G_TX_CLAMP"); + else + n += gfxd_puts(" | G_TX_WRAP"); + return n; +} + +UCFUNC int argfn_tm(const gfxd_value_t *v) +{ + if (v->i == 0) + return gfxd_puts("G_TX_NOMASK"); + else + return gfxd_printf("%" PRIi32, v->i); +} + +UCFUNC int argfn_ts(const gfxd_value_t *v) +{ + if (v->i == 0) + return gfxd_puts("G_TX_NOLOD"); + else + return gfxd_printf("%" PRIi32, v->i); +} + +UCFUNC int argfn_switch(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_ON: + return gfxd_puts("G_ON"); + case G_OFF: + return gfxd_puts("G_OFF"); + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +UCFUNC int argfn_tile(const gfxd_value_t *v) +{ + if (v->i == G_TX_LOADTILE) + return gfxd_puts("G_TX_LOADTILE"); + else if (v->i == G_TX_RENDERTILE) + return gfxd_puts("G_TX_RENDERTILE"); + else + return gfxd_printf("%" PRIi32, v->i); +} + +UCFUNC int argfn_gm(const gfxd_value_t *v) +{ + int n = 0; + uint32_t arg = v->u; + if (arg & G_ZBUFFER) + n += gfxd_puts("G_ZBUFFER"); + if (arg & G_TEXTURE_ENABLE) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_TEXTURE_ENABLE"); + } + if (arg & G_SHADE) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_SHADE"); + } + if ((arg & G_CULL_BOTH) == G_CULL_BOTH) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_CULL_BOTH"); + } + else + { + if (arg & G_CULL_FRONT) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_CULL_FRONT"); + } + if (arg & G_CULL_BACK) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_CULL_BACK"); + } + } + if (arg & G_FOG) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_FOG"); + } + if (arg & G_LIGHTING) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_LIGHTING"); + } + if (arg & G_TEXTURE_GEN) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_TEXTURE_GEN"); + } + if (arg & G_TEXTURE_GEN_LINEAR) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_TEXTURE_GEN_LINEAR"); + } + if (arg & G_LOD) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_LOD"); + } + if (arg & G_SHADING_SMOOTH) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_SHADING_SMOOTH"); + } + if (arg & G_CLIPPING) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("G_CLIPPING"); + } + arg = arg & ~(G_ZBUFFER | G_TEXTURE_ENABLE | G_SHADE | G_CULL_BOTH | + G_FOG | G_LIGHTING | G_TEXTURE_GEN | + G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH | + G_CLIPPING); + if (arg) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_printf("0x%08" PRIX32, arg); + } + return n; +} + +UCFUNC int argfn_sftlo(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_MDSFT_ALPHACOMPARE: + return gfxd_puts("G_MDSFT_ALPHACOMPARE"); + case G_MDSFT_ZSRCSEL: + return gfxd_puts("G_MDSFT_ZSRCSEL"); + case G_MDSFT_RENDERMODE: + return gfxd_puts("G_MDSFT_RENDERMODE"); + case G_MDSFT_BLENDER: + return gfxd_puts("G_MDSFT_BLENDER"); + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +UCFUNC int rm_mode_str(uint32_t arg) +{ + int n = 0; + if (arg & AA_EN) + n += gfxd_puts("AA_EN"); + if (arg & Z_CMP) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("Z_CMP"); + } + if (arg & Z_UPD) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("Z_UPD"); + } + if (arg & IM_RD) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("IM_RD"); + } + if (arg & CLR_ON_CVG) + { + if (n > 0) + n += gfxd_puts(" | "); + n += gfxd_puts("CLR_ON_CVG"); + } + if (n > 0) + n += gfxd_puts(" | "); + int cvg = arg & 0x00000300; + switch (cvg) + { + case CVG_DST_CLAMP: + n += gfxd_puts("CVG_DST_CLAMP"); + break; + case CVG_DST_WRAP: + n += gfxd_puts("CVG_DST_WRAP"); + break; + case CVG_DST_FULL: + n += gfxd_puts("CVG_DST_FULL"); + break; + case CVG_DST_SAVE: + n += gfxd_puts("CVG_DST_SAVE"); + break; + } + int zmode = arg & 0x00000C00; + switch (zmode) + { + case ZMODE_OPA: + n += gfxd_puts(" | ZMODE_OPA"); + break; + case ZMODE_INTER: + n += gfxd_puts(" | ZMODE_INTER"); + break; + case ZMODE_XLU: + n += gfxd_puts(" | ZMODE_XLU"); + break; + case ZMODE_DEC: + n += gfxd_puts(" | ZMODE_DEC"); + break; + } + if (arg & CVG_X_ALPHA) + n += gfxd_puts(" | CVG_X_ALPHA"); + if (arg & ALPHA_CVG_SEL) + n += gfxd_puts(" | ALPHA_CVG_SEL"); + if (arg & FORCE_BL) + n += gfxd_puts(" | FORCE_BL"); + return n; +} + +UCFUNC int rm_cbl_str(uint32_t arg, int c) +{ + int n = 0; + if (c == 2) + arg <<= 2; + int bp = (arg >> 30) & 0b11; + switch (bp) + { + case G_BL_CLR_IN: + n += gfxd_printf("GBL_c%i(G_BL_CLR_IN", c); + break; + case G_BL_CLR_MEM: + n += gfxd_printf("GBL_c%i(G_BL_CLR_MEM", c); + break; + case G_BL_CLR_BL: + n += gfxd_printf("GBL_c%i(G_BL_CLR_BL", c); + break; + case G_BL_CLR_FOG: + n += gfxd_printf("GBL_c%i(G_BL_CLR_FOG", c); + break; + } + int ba = (arg >> 26) & 0b11; + switch (ba) + { + case G_BL_A_IN: + n += gfxd_puts(", G_BL_A_IN"); + break; + case G_BL_A_FOG: + n += gfxd_puts(", G_BL_A_FOG"); + break; + case G_BL_A_SHADE: + n += gfxd_puts(", G_BL_A_SHADE"); + break; + case G_BL_0: + n += gfxd_puts(", G_BL_0"); + break; + } + int bm = (arg >> 22) & 0b11; + switch (bm) + { + case G_BL_CLR_IN: + n += gfxd_puts(", G_BL_CLR_IN"); + break; + case G_BL_CLR_MEM: + n += gfxd_puts(", G_BL_CLR_MEM"); + break; + case G_BL_CLR_BL: + n += gfxd_puts(", G_BL_CLR_BL"); + break; + case G_BL_CLR_FOG: + n += gfxd_puts(", G_BL_CLR_FOG"); + break; + } + int bb = (arg >> 18) & 0b11; + switch (bb) + { + case G_BL_1MA: + n += gfxd_puts(", G_BL_1MA)"); + break; + case G_BL_A_MEM: + n += gfxd_puts(", G_BL_A_MEM)"); + break; + case G_BL_1: + n += gfxd_puts(", G_BL_1)"); + break; + case G_BL_0: + n += gfxd_puts(", G_BL_0)"); + break; + } + return n; +} + +struct rm_preset +{ + uint32_t rm; + const char * name; +}; + +static const struct rm_preset rm_presets[] = +{ + {G_RM_OPA_SURF, "G_RM_OPA_SURF"}, + {G_RM_OPA_SURF2, "G_RM_OPA_SURF2"}, + {G_RM_AA_OPA_SURF, "G_RM_AA_OPA_SURF"}, + {G_RM_AA_OPA_SURF2, "G_RM_AA_OPA_SURF2"}, + {G_RM_RA_OPA_SURF, "G_RM_RA_OPA_SURF"}, + {G_RM_RA_OPA_SURF2, "G_RM_RA_OPA_SURF2"}, + {G_RM_ZB_OPA_SURF, "G_RM_ZB_OPA_SURF"}, + {G_RM_ZB_OPA_SURF2, "G_RM_ZB_OPA_SURF2"}, + {G_RM_AA_ZB_OPA_SURF, "G_RM_AA_ZB_OPA_SURF"}, + {G_RM_AA_ZB_OPA_SURF2, "G_RM_AA_ZB_OPA_SURF2"}, + {G_RM_RA_ZB_OPA_SURF, "G_RM_RA_ZB_OPA_SURF"}, + {G_RM_RA_ZB_OPA_SURF2, "G_RM_RA_ZB_OPA_SURF2"}, + {G_RM_XLU_SURF, "G_RM_XLU_SURF"}, + {G_RM_XLU_SURF2, "G_RM_XLU_SURF2"}, + {G_RM_AA_XLU_SURF, "G_RM_AA_XLU_SURF"}, + {G_RM_AA_XLU_SURF2, "G_RM_AA_XLU_SURF2"}, + {G_RM_ZB_XLU_SURF, "G_RM_ZB_XLU_SURF"}, + {G_RM_ZB_XLU_SURF2, "G_RM_ZB_XLU_SURF2"}, + {G_RM_AA_ZB_XLU_SURF, "G_RM_AA_ZB_XLU_SURF"}, + {G_RM_AA_ZB_XLU_SURF2, "G_RM_AA_ZB_XLU_SURF2"}, + {G_RM_ZB_OPA_DECAL, "G_RM_ZB_OPA_DECAL"}, + {G_RM_ZB_OPA_DECAL2, "G_RM_ZB_OPA_DECAL2"}, + {G_RM_AA_ZB_OPA_DECAL, "G_RM_AA_ZB_OPA_DECAL"}, + {G_RM_AA_ZB_OPA_DECAL2, "G_RM_AA_ZB_OPA_DECAL2"}, + {G_RM_RA_ZB_OPA_DECAL, "G_RM_RA_ZB_OPA_DECAL"}, + {G_RM_RA_ZB_OPA_DECAL2, "G_RM_RA_ZB_OPA_DECAL2"}, + {G_RM_ZB_XLU_DECAL, "G_RM_ZB_XLU_DECAL"}, + {G_RM_ZB_XLU_DECAL2, "G_RM_ZB_XLU_DECAL2"}, + {G_RM_AA_ZB_XLU_DECAL, "G_RM_AA_ZB_XLU_DECAL"}, + {G_RM_AA_ZB_XLU_DECAL2, "G_RM_AA_ZB_XLU_DECAL2"}, + {G_RM_AA_ZB_OPA_INTER, "G_RM_AA_ZB_OPA_INTER"}, + {G_RM_AA_ZB_OPA_INTER2, "G_RM_AA_ZB_OPA_INTER2"}, + {G_RM_RA_ZB_OPA_INTER, "G_RM_RA_ZB_OPA_INTER"}, + {G_RM_RA_ZB_OPA_INTER2, "G_RM_RA_ZB_OPA_INTER2"}, + {G_RM_AA_ZB_XLU_INTER, "G_RM_AA_ZB_XLU_INTER"}, + {G_RM_AA_ZB_XLU_INTER2, "G_RM_AA_ZB_XLU_INTER2"}, + {G_RM_AA_XLU_LINE, "G_RM_AA_XLU_LINE"}, + {G_RM_AA_XLU_LINE2, "G_RM_AA_XLU_LINE2"}, + {G_RM_AA_ZB_XLU_LINE, "G_RM_AA_ZB_XLU_LINE"}, + {G_RM_AA_ZB_XLU_LINE2, "G_RM_AA_ZB_XLU_LINE2"}, + {G_RM_AA_DEC_LINE, "G_RM_AA_DEC_LINE"}, + {G_RM_AA_DEC_LINE2, "G_RM_AA_DEC_LINE2"}, + {G_RM_AA_ZB_DEC_LINE, "G_RM_AA_ZB_DEC_LINE"}, + {G_RM_AA_ZB_DEC_LINE2, "G_RM_AA_ZB_DEC_LINE2"}, + {G_RM_TEX_EDGE, "G_RM_TEX_EDGE"}, + {G_RM_TEX_EDGE2, "G_RM_TEX_EDGE2"}, + {G_RM_AA_TEX_EDGE, "G_RM_AA_TEX_EDGE"}, + {G_RM_AA_TEX_EDGE2, "G_RM_AA_TEX_EDGE2"}, + {G_RM_AA_ZB_TEX_EDGE, "G_RM_AA_ZB_TEX_EDGE"}, + {G_RM_AA_ZB_TEX_EDGE2, "G_RM_AA_ZB_TEX_EDGE2"}, + {G_RM_AA_ZB_TEX_INTER, "G_RM_AA_ZB_TEX_INTER"}, + {G_RM_AA_ZB_TEX_INTER2, "G_RM_AA_ZB_TEX_INTER2"}, + {G_RM_AA_SUB_SURF, "G_RM_AA_SUB_SURF"}, + {G_RM_AA_SUB_SURF2, "G_RM_AA_SUB_SURF2"}, + {G_RM_AA_ZB_SUB_SURF, "G_RM_AA_ZB_SUB_SURF"}, + {G_RM_AA_ZB_SUB_SURF2, "G_RM_AA_ZB_SUB_SURF2"}, + {G_RM_PCL_SURF, "G_RM_PCL_SURF"}, + {G_RM_PCL_SURF2, "G_RM_PCL_SURF2"}, + {G_RM_AA_PCL_SURF, "G_RM_AA_PCL_SURF"}, + {G_RM_AA_PCL_SURF2, "G_RM_AA_PCL_SURF2"}, + {G_RM_ZB_PCL_SURF, "G_RM_ZB_PCL_SURF"}, + {G_RM_ZB_PCL_SURF2, "G_RM_ZB_PCL_SURF2"}, + {G_RM_AA_ZB_PCL_SURF, "G_RM_AA_ZB_PCL_SURF"}, + {G_RM_AA_ZB_PCL_SURF2, "G_RM_AA_ZB_PCL_SURF2"}, + {G_RM_AA_OPA_TERR, "G_RM_AA_OPA_TERR"}, + {G_RM_AA_OPA_TERR2, "G_RM_AA_OPA_TERR2"}, + {G_RM_AA_ZB_OPA_TERR, "G_RM_AA_ZB_OPA_TERR"}, + {G_RM_AA_ZB_OPA_TERR2, "G_RM_AA_ZB_OPA_TERR2"}, + {G_RM_AA_TEX_TERR, "G_RM_AA_TEX_TERR"}, + {G_RM_AA_TEX_TERR2, "G_RM_AA_TEX_TERR2"}, + {G_RM_AA_ZB_TEX_TERR, "G_RM_AA_ZB_TEX_TERR"}, + {G_RM_AA_ZB_TEX_TERR2, "G_RM_AA_ZB_TEX_TERR2"}, + {G_RM_AA_SUB_TERR, "G_RM_AA_SUB_TERR"}, + {G_RM_AA_SUB_TERR2, "G_RM_AA_SUB_TERR2"}, + {G_RM_AA_ZB_SUB_TERR, "G_RM_AA_ZB_SUB_TERR"}, + {G_RM_AA_ZB_SUB_TERR2, "G_RM_AA_ZB_SUB_TERR2"}, + {G_RM_CLD_SURF, "G_RM_CLD_SURF"}, + {G_RM_CLD_SURF2, "G_RM_CLD_SURF2"}, + {G_RM_ZB_CLD_SURF, "G_RM_ZB_CLD_SURF"}, + {G_RM_ZB_CLD_SURF2, "G_RM_ZB_CLD_SURF2"}, + {G_RM_ZB_OVL_SURF, "G_RM_ZB_OVL_SURF"}, + {G_RM_ZB_OVL_SURF2, "G_RM_ZB_OVL_SURF2"}, + {G_RM_ADD, "G_RM_ADD"}, + {G_RM_ADD2, "G_RM_ADD2"}, + {G_RM_VISCVG, "G_RM_VISCVG"}, + {G_RM_VISCVG2, "G_RM_VISCVG2"}, + {G_RM_OPA_CI, "G_RM_OPA_CI"}, + {G_RM_OPA_CI2, "G_RM_OPA_CI2"}, + {G_RM_RA_SPRITE, "G_RM_RA_SPRITE"}, + {G_RM_RA_SPRITE2, "G_RM_RA_SPRITE2"}, +}; + +static const struct rm_preset bl1_presets[] = +{ + {G_RM_FOG_SHADE_A, "G_RM_FOG_SHADE_A"}, + {G_RM_FOG_PRIM_A, "G_RM_FOG_PRIM_A"}, + {G_RM_PASS, "G_RM_PASS"}, + {G_RM_NOOP, "G_RM_NOOP"}, +}; + +static const struct rm_preset bl2_presets[] = +{ + {G_RM_NOOP2, "G_RM_NOOP2"}, +}; + +UCFUNC int othermodelo_str(uint32_t arg, uint32_t which) +{ + int n = 0; + uint32_t rm_c1_mask = MDMASK_RM_C1; + uint32_t rm_c2_mask = MDMASK_RM_C2; + uint32_t rm_mode_lo = MDMASK_RM_LO; + uint32_t rm_mask = rm_c1_mask | rm_c2_mask | rm_mode_lo; + const struct rm_preset *pre_c1 = NULL; + const struct rm_preset *pre_c2 = NULL; + int n_rm_presets = sizeof(rm_presets) / sizeof(*rm_presets); + for (int i = 0; i < n_rm_presets; i++) + { + const struct rm_preset *pre = &rm_presets[i]; + uint32_t pre_extra = pre->rm & ~rm_mask; + uint32_t rm_c1 = arg & (rm_c1_mask | rm_mode_lo | pre_extra); + if (!pre_c1 && rm_c1 == pre->rm) + pre_c1 = pre; + uint32_t rm_c2 = arg & (rm_c2_mask | rm_mode_lo | pre_extra); + if (!pre_c2 && rm_c2 == pre->rm) + pre_c2 = pre; + } + if (!pre_c1 || !pre_c2 || pre_c1 + 1 != pre_c2) + { + int n_bl1_presets = sizeof(bl1_presets) / sizeof(*bl1_presets); + for (int i = 0; i < n_bl1_presets; i++) + { + const struct rm_preset *pre = &bl1_presets[i]; + uint32_t pre_extra = pre->rm & ~rm_mask; + uint32_t rm_c1 = arg & (rm_c1_mask | pre_extra); + if (rm_c1 == pre->rm) + { + pre_c1 = pre; + break; + } + } + int n_bl2_presets = sizeof(bl2_presets) / sizeof(*bl2_presets); + for (int i = 0; i < n_bl2_presets; i++) + { + const struct rm_preset *pre = &bl2_presets[i]; + uint32_t pre_extra = pre->rm & ~rm_mask; + uint32_t rm_c2 = arg & (rm_c2_mask | pre_extra); + if (rm_c2 == pre->rm) + { + pre_c2 = pre; + break; + } + } + } + uint32_t pre_rm = 0; + if (pre_c1) + pre_rm |= pre_c1->rm; + if (pre_c2) + pre_rm |= pre_c2->rm; + uint32_t ac_mask = MDMASK(ALPHACOMPARE); + if (((arg & ~pre_rm) | which) & ac_mask) + { + uint32_t ac = arg & ac_mask; + switch (ac) + { + case G_AC_NONE: + n += gfxd_puts("G_AC_NONE"); + break; + case G_AC_THRESHOLD: + n += gfxd_puts("G_AC_THRESHOLD"); + break; + case G_AC_DITHER: + n += gfxd_puts("G_AC_DITHER"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, ac); + break; + } + } + uint32_t zs_mask = MDMASK(ZSRCSEL); + if (((arg & ~pre_rm) | which) & zs_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t zs = arg & zs_mask; + switch (zs) + { + case G_ZS_PIXEL: + n += gfxd_puts("G_ZS_PIXEL"); + break; + case G_ZS_PRIM: + n += gfxd_puts("G_ZS_PRIM"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, zs); + break; + } + } + uint32_t rm = arg & (rm_mask | pre_rm); + if (((arg & ~pre_rm) | which) & rm_mode_lo) + { + if (n > 0) + n += gfxd_puts(" | "); + n += rm_mode_str(rm); + } + int c = 0; + if (which & rm_c1_mask) + c |= 1; + if (which & rm_c2_mask) + c |= 2; + if (c & 1 || (c == 0 && arg & rm_c1_mask)) + { + if (n > 0) + n += gfxd_puts(" | "); + if (pre_c1) + n += gfxd_printf("%s", pre_c1->name); + else + n += rm_cbl_str(rm, 1); + } + if (c & 2 || (c == 0 && arg & rm_c2_mask)) + { + if (n > 0) + n += gfxd_puts(" | "); + if (pre_c2) + n += gfxd_printf("%s", pre_c2->name); + else + n += rm_cbl_str(rm, 2); + } + uint32_t unk_mask = ~(rm_mask | ac_mask | zs_mask); + if (arg & unk_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t unk = arg & unk_mask; + n += gfxd_printf("0x%08" PRIX32, unk); + } + return n; +} + +UCFUNC int argfn_ac(const gfxd_value_t *v) +{ + return othermodelo_str(v->u, MDMASK(ALPHACOMPARE)); +} + +UCFUNC int argfn_zs(const gfxd_value_t *v) +{ + return othermodelo_str(v->u, MDMASK(ZSRCSEL)); +} + +UCFUNC int argfn_rm1(const gfxd_value_t *v) +{ + return othermodelo_str(v->u, MDMASK_RM_C1); +} + +UCFUNC int argfn_rm2(const gfxd_value_t *v) +{ + return othermodelo_str(v->u, MDMASK_RM_C2); +} + +UCFUNC int argfn_othermodelo(const gfxd_value_t *v) +{ + uint32_t mask = MDMASK(ALPHACOMPARE) | MDMASK(ZSRCSEL) | MDMASK_RM_C1 | + MDMASK_RM_C2; + return othermodelo_str(v->u, mask); +} + +UCFUNC int argfn_sfthi(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_MDSFT_ALPHADITHER: + return gfxd_puts("G_MDSFT_ALPHADITHER"); + case G_MDSFT_RGBDITHER: + return gfxd_puts("G_MDSFT_RGBDITHER"); + case G_MDSFT_COMBKEY: + return gfxd_puts("G_MDSFT_COMBKEY"); + case G_MDSFT_TEXTCONV: + return gfxd_puts("G_MDSFT_TEXTCONV"); + case G_MDSFT_TEXTFILT: + return gfxd_puts("G_MDSFT_TEXTFILT"); + case G_MDSFT_TEXTLUT: + return gfxd_puts("G_MDSFT_TEXTLUT"); + case G_MDSFT_TEXTLOD: + return gfxd_puts("G_MDSFT_TEXTLOD"); + case G_MDSFT_TEXTDETAIL: + return gfxd_puts("G_MDSFT_TEXTDETAIL"); + case G_MDSFT_TEXTPERSP: + return gfxd_puts("G_MDSFT_TEXTPERSP"); + case G_MDSFT_CYCLETYPE: + return gfxd_puts("G_MDSFT_CYCLETYPE"); + case G_MDSFT_PIPELINE: + return gfxd_puts("G_MDSFT_PIPELINE"); + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +UCFUNC int othermodehi_str(uint32_t arg, uint32_t which) +{ + int n = 0; + uint32_t ad_mask = MDMASK(ALPHADITHER); + if ((arg | which) & ad_mask) + { + uint32_t ad = arg & ad_mask; + switch (ad) + { + case G_AD_PATTERN: + n += gfxd_puts("G_AD_PATTERN"); + break; + case G_AD_NOTPATTERN: + n += gfxd_puts("G_AD_NOTPATTERN"); + break; + case G_AD_NOISE: + n += gfxd_puts("G_AD_NOISE"); + break; + case G_AD_DISABLE: + n += gfxd_puts("G_AD_DISABLE"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, ad); + break; + } + } + uint32_t cd_mask = MDMASK(RGBDITHER); + if ((arg | which) & cd_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t cd = arg & cd_mask; + switch (cd) + { + case G_CD_MAGICSQ: + n += gfxd_puts("G_CD_MAGICSQ"); + break; + case G_CD_BAYER: + n += gfxd_puts("G_CD_BAYER"); + break; + case G_CD_NOISE: + n += gfxd_puts("G_CD_NOISE"); + break; + case G_CD_DISABLE: + n += gfxd_puts("G_CD_DISABLE"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, cd); + break; + } + } + uint32_t ck_mask = MDMASK(COMBKEY); + if ((arg | which) & ck_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t ck = arg & ck_mask; + switch (ck) + { + case G_CK_NONE: + n += gfxd_puts("G_CK_NONE"); + break; + case G_CK_KEY: + n += gfxd_puts("G_CK_KEY"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, ck); + break; + } + } + uint32_t tc_mask = MDMASK(TEXTCONV); + if ((arg | which) & tc_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t tc = arg & tc_mask; + switch (tc) + { + case G_TC_CONV: + n += gfxd_puts("G_TC_CONV"); + break; + case G_TC_FILTCONV: + n += gfxd_puts("G_TC_FILTCONV"); + break; + case G_TC_FILT: + n += gfxd_puts("G_TC_FILT"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, tc); + break; + } + } + uint32_t tf_mask = MDMASK(TEXTFILT); + if ((arg | which) & tf_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t tf = arg & tf_mask; + switch (tf) + { + case G_TF_POINT: + n += gfxd_puts("G_TF_POINT"); + break; + case G_TF_BILERP: + n += gfxd_puts("G_TF_BILERP"); + break; + case G_TF_AVERAGE: + n += gfxd_puts("G_TF_AVERAGE"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, tf); + break; + } + } + uint32_t tt_mask = MDMASK(TEXTLUT); + if ((arg | which) & tt_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t tt = arg & tt_mask; + switch (tt) + { + case G_TT_NONE: + n += gfxd_puts("G_TT_NONE"); + break; + case G_TT_RGBA16: + n += gfxd_puts("G_TT_RGBA16"); + break; + case G_TT_IA16: + n += gfxd_puts("G_TT_IA16"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, tt); + break; + } + } + uint32_t tl_mask = MDMASK(TEXTLOD); + if ((arg | which) & tl_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t tl = arg & tl_mask; + switch (tl) + { + case G_TL_TILE: + n += gfxd_puts("G_TL_TILE"); + break; + case G_TL_LOD: + n += gfxd_puts("G_TL_LOD"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, tl); + break; + } + } + uint32_t td_mask = MDMASK(TEXTDETAIL); + if ((arg | which) & td_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t td = arg & td_mask; + switch (td) + { + case G_TD_CLAMP: + n += gfxd_puts("G_TD_CLAMP"); + break; + case G_TD_SHARPEN: + n += gfxd_puts("G_TD_SHARPEN"); + break; + case G_TD_DETAIL: + n += gfxd_puts("G_TD_DETAIL"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, td); + break; + } + } + uint32_t tp_mask = MDMASK(TEXTPERSP); + if ((arg | which) & tp_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t tp = arg & tp_mask; + switch (tp) + { + case G_TP_NONE: + n += gfxd_puts("G_TP_NONE"); + break; + case G_TP_PERSP: + n += gfxd_puts("G_TP_PERSP"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, tp); + break; + } + } + uint32_t cyc_mask = MDMASK(CYCLETYPE); + if ((arg | which) & cyc_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t cyc = arg & cyc_mask; + switch (cyc) + { + case G_CYC_1CYCLE: + n += gfxd_puts("G_CYC_1CYCLE"); + break; + case G_CYC_2CYCLE: + n += gfxd_puts("G_CYC_2CYCLE"); + break; + case G_CYC_COPY: + n += gfxd_puts("G_CYC_COPY"); + break; + case G_CYC_FILL: + n += gfxd_puts("G_CYC_FILL"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, cyc); + break; + } + } + uint32_t pm_mask = MDMASK(PIPELINE); + if ((arg | which) & pm_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t pm = arg & pm_mask; + switch (pm) + { + case G_PM_NPRIMITIVE: + n += gfxd_puts("G_PM_NPRIMITIVE"); + break; + case G_PM_1PRIMITIVE: + n += gfxd_puts("G_PM_1PRIMITIVE"); + break; + default: + n += gfxd_printf("0x%08" PRIX32, pm); + break; + } + } + uint32_t unk_mask = ~(ad_mask | cd_mask | ck_mask | tc_mask | tf_mask | + tt_mask | tl_mask | td_mask | tp_mask | + cyc_mask | pm_mask); + if (arg & unk_mask) + { + if (n > 0) + n += gfxd_puts(" | "); + uint32_t unk = arg & unk_mask; + n += gfxd_printf("0x%08" PRIX32, unk); + } + return n; +} + +UCFUNC int argfn_ad(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(ALPHADITHER)); +} + +UCFUNC int argfn_cd(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(RGBDITHER)); +} + +UCFUNC int argfn_ck(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(COMBKEY)); +} + +UCFUNC int argfn_tc(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(TEXTCONV)); +} + +UCFUNC int argfn_tf(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(TEXTFILT)); +} + +UCFUNC int argfn_tt(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(TEXTLUT)); +} + +UCFUNC int argfn_tl(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(TEXTLOD)); +} + +UCFUNC int argfn_td(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(TEXTDETAIL)); +} + +UCFUNC int argfn_tp(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(TEXTPERSP)); +} + +UCFUNC int argfn_cyc(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(CYCLETYPE)); +} + +UCFUNC int argfn_pm(const gfxd_value_t *v) +{ + return othermodehi_str(v->u, MDMASK(PIPELINE)); +} + +UCFUNC int argfn_othermodehi(const gfxd_value_t *v) +{ + uint32_t mask = MDMASK(ALPHADITHER) | + MDMASK(RGBDITHER) | + MDMASK(COMBKEY) | + MDMASK(TEXTCONV) | + MDMASK(TEXTFILT) | + MDMASK(TEXTLUT) | + MDMASK(TEXTLOD) | + MDMASK(TEXTDETAIL) | + MDMASK(TEXTPERSP) | + MDMASK(CYCLETYPE) | + MDMASK(PIPELINE); + return othermodehi_str(v->u, mask); +} + +UCFUNC int argfn_cv(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_CV_K0: + return gfxd_puts("G_CV_K0"); + case G_CV_K1: + return gfxd_puts("G_CV_K1"); + case G_CV_K2: + return gfxd_puts("G_CV_K2"); + case G_CV_K3: + return gfxd_puts("G_CV_K3"); + case G_CV_K4: + return gfxd_puts("G_CV_K4"); + case G_CV_K5: + return gfxd_puts("G_CV_K5"); + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +UCFUNC int argfn_ccmuxa(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_CCMUX_COMBINED: + return gfxd_puts("COMBINED"); + case G_CCMUX_TEXEL0: + return gfxd_puts("TEXEL0"); + case G_CCMUX_TEXEL1: + return gfxd_puts("TEXEL1"); + case G_CCMUX_PRIMITIVE: + return gfxd_puts("PRIMITIVE"); + case G_CCMUX_SHADE: + return gfxd_puts("SHADE"); + case G_CCMUX_ENVIRONMENT: + return gfxd_puts("ENVIRONMENT"); + case G_CCMUX_1: + return gfxd_puts("1"); + case G_CCMUX_NOISE: + return gfxd_puts("NOISE"); + default: + return gfxd_puts("0"); + } +} + +UCFUNC int argfn_ccmuxb(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_CCMUX_COMBINED: + return gfxd_puts("COMBINED"); + case G_CCMUX_TEXEL0: + return gfxd_puts("TEXEL0"); + case G_CCMUX_TEXEL1: + return gfxd_puts("TEXEL1"); + case G_CCMUX_PRIMITIVE: + return gfxd_puts("PRIMITIVE"); + case G_CCMUX_SHADE: + return gfxd_puts("SHADE"); + case G_CCMUX_ENVIRONMENT: + return gfxd_puts("ENVIRONMENT"); + case G_CCMUX_CENTER: + return gfxd_puts("CENTER"); + case G_CCMUX_K4: + return gfxd_puts("K4"); + default: + return gfxd_puts("0"); + } +} + +UCFUNC int argfn_ccmuxc(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_CCMUX_COMBINED: + return gfxd_puts("COMBINED"); + case G_CCMUX_TEXEL0: + return gfxd_puts("TEXEL0"); + case G_CCMUX_TEXEL1: + return gfxd_puts("TEXEL1"); + case G_CCMUX_PRIMITIVE: + return gfxd_puts("PRIMITIVE"); + case G_CCMUX_SHADE: + return gfxd_puts("SHADE"); + case G_CCMUX_ENVIRONMENT: + return gfxd_puts("ENVIRONMENT"); + case G_CCMUX_SCALE: + return gfxd_puts("SCALE"); + case G_CCMUX_COMBINED_ALPHA: + return gfxd_puts("COMBINED_ALPHA"); + case G_CCMUX_TEXEL0_ALPHA: + return gfxd_puts("TEXEL0_ALPHA"); + case G_CCMUX_TEXEL1_ALPHA: + return gfxd_puts("TEXEL1_ALPHA"); + case G_CCMUX_PRIMITIVE_ALPHA: + return gfxd_puts("PRIMITIVE_ALPHA"); + case G_CCMUX_SHADE_ALPHA: + return gfxd_puts("SHADE_ALPHA"); + case G_CCMUX_ENV_ALPHA: + return gfxd_puts("ENV_ALPHA"); + case G_CCMUX_LOD_FRACTION: + return gfxd_puts("LOD_FRACTION"); + case G_CCMUX_PRIM_LOD_FRAC: + return gfxd_puts("PRIM_LOD_FRAC"); + case G_CCMUX_K5: + return gfxd_puts("K5"); + default: + return gfxd_puts("0"); + } +} + +UCFUNC int argfn_ccmuxd(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_CCMUX_COMBINED: + return gfxd_puts("COMBINED"); + case G_CCMUX_TEXEL0: + return gfxd_puts("TEXEL0"); + case G_CCMUX_TEXEL1: + return gfxd_puts("TEXEL1"); + case G_CCMUX_PRIMITIVE: + return gfxd_puts("PRIMITIVE"); + case G_CCMUX_SHADE: + return gfxd_puts("SHADE"); + case G_CCMUX_ENVIRONMENT: + return gfxd_puts("ENVIRONMENT"); + case G_CCMUX_1: + return gfxd_puts("1"); + default: + return gfxd_puts("0"); + } +} + +UCFUNC int argfn_acmuxabd(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_ACMUX_COMBINED: + return gfxd_puts("COMBINED"); + case G_ACMUX_TEXEL0: + return gfxd_puts("TEXEL0"); + case G_ACMUX_TEXEL1: + return gfxd_puts("TEXEL1"); + case G_ACMUX_PRIMITIVE: + return gfxd_puts("PRIMITIVE"); + case G_ACMUX_SHADE: + return gfxd_puts("SHADE"); + case G_ACMUX_ENVIRONMENT: + return gfxd_puts("ENVIRONMENT"); + case G_ACMUX_1: + return gfxd_puts("1"); + default: + return gfxd_puts("0"); + } +} + +UCFUNC int argfn_acmuxc(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_ACMUX_LOD_FRACTION: + return gfxd_puts("LOD_FRACTION"); + case G_ACMUX_TEXEL0: + return gfxd_puts("TEXEL0"); + case G_ACMUX_TEXEL1: + return gfxd_puts("TEXEL1"); + case G_ACMUX_PRIMITIVE: + return gfxd_puts("PRIMITIVE"); + case G_ACMUX_SHADE: + return gfxd_puts("SHADE"); + case G_ACMUX_ENVIRONMENT: + return gfxd_puts("ENVIRONMENT"); + case G_ACMUX_PRIM_LOD_FRAC: + return gfxd_puts("PRIM_LOD_FRAC"); + default: + return gfxd_puts("0"); + } +} + +struct cc_mode +{ + int a; + int b; + int c; + int d; + int Aa; + int Ab; + int Ac; + int Ad; +}; + +struct cc_preset +{ + struct cc_mode mode; + const char * name; +}; + +#define CC_(a,b,c,d,Aa,Ab,Ac,Ad) \ + { \ + G_CCMUX_##a, G_CCMUX_##b, \ + G_CCMUX_##c, G_CCMUX_##d, \ + G_ACMUX_##Aa, G_ACMUX_##Ab, \ + G_ACMUX_##Ac, G_ACMUX_##Ad \ + } +#define CC(m) CC_(m) +static const struct cc_preset cc_presets[] = +{ + {CC(G_CC_MODULATEI), "G_CC_MODULATEI"}, + {CC(G_CC_MODULATEIA), "G_CC_MODULATEIA"}, + {CC(G_CC_MODULATEIDECALA), "G_CC_MODULATEIDECALA"}, + {CC(G_CC_MODULATERGB), "G_CC_MODULATERGB"}, + {CC(G_CC_MODULATERGBA), "G_CC_MODULATERGBA"}, + {CC(G_CC_MODULATERGBDECALA), "G_CC_MODULATERGBDECALA"}, + {CC(G_CC_MODULATEI_PRIM), "G_CC_MODULATEI_PRIM"}, + {CC(G_CC_MODULATEIA_PRIM), "G_CC_MODULATEIA_PRIM"}, + {CC(G_CC_MODULATEIDECALA_PRIM), "G_CC_MODULATEIDECALA_PRIM"}, + {CC(G_CC_MODULATERGB_PRIM), "G_CC_MODULATERGB_PRIM"}, + {CC(G_CC_MODULATERGBA_PRIM), "G_CC_MODULATERGBA_PRIM"}, + {CC(G_CC_MODULATERGBDECALA_PRIM), "G_CC_MODULATERGBDECALA_PRIM"}, + {CC(G_CC_DECALRGB), "G_CC_DECALRGB"}, + {CC(G_CC_DECALRGBA), "G_CC_DECALRGBA"}, + {CC(G_CC_BLENDI), "G_CC_BLENDI"}, + {CC(G_CC_BLENDIA), "G_CC_BLENDIA"}, + {CC(G_CC_BLENDIDECALA), "G_CC_BLENDIDECALA"}, + {CC(G_CC_BLENDRGBA), "G_CC_BLENDRGBA"}, + {CC(G_CC_BLENDRGBDECALA), "G_CC_BLENDRGBDECALA"}, + {CC(G_CC_REFLECTRGB), "G_CC_REFLECTRGB"}, + {CC(G_CC_REFLECTRGBDECALA), "G_CC_REFLECTRGBDECALA"}, + {CC(G_CC_HILITERGB), "G_CC_HILITERGB"}, + {CC(G_CC_HILITERGBA), "G_CC_HILITERGBA"}, + {CC(G_CC_HILITERGBDECALA), "G_CC_HILITERGBDECALA"}, + {CC(G_CC_1CYUV2RGB), "G_CC_1CYUV2RGB"}, + {CC(G_CC_PRIMITIVE), "G_CC_PRIMITIVE"}, + {CC(G_CC_SHADE), "G_CC_SHADE"}, + {CC(G_CC_ADDRGB), "G_CC_ADDRGB"}, + {CC(G_CC_ADDRGBDECALA), "G_CC_ADDRGBDECALA"}, + {CC(G_CC_SHADEDECALA), "G_CC_SHADEDECALA"}, + {CC(G_CC_BLENDPE), "G_CC_BLENDPE"}, + {CC(G_CC_BLENDPEDECALA), "G_CC_BLENDPEDECALA"}, + {CC(G_CC_TRILERP), "G_CC_TRILERP"}, + {CC(G_CC_TEMPLERP), "G_CC_TEMPLERP"}, + {CC(G_CC_INTERFERENCE), "G_CC_INTERFERENCE"}, + {CC(_G_CC_BLENDPE), "_G_CC_BLENDPE"}, + {CC(_G_CC_BLENDPEDECALA), "_G_CC_BLENDPEDECALA"}, + {CC(_G_CC_SPARSEST), "_G_CC_SPARSEST"}, + {CC(_G_CC_TWOCOLORTEX), "_G_CC_TWOCOLORTEX"}, + {CC(G_CC_MODULATEI2), "G_CC_MODULATEI2"}, + {CC(G_CC_MODULATEIA2), "G_CC_MODULATEIA2"}, + {CC(G_CC_MODULATERGB2), "G_CC_MODULATERGB2"}, + {CC(G_CC_MODULATERGBA2), "G_CC_MODULATERGBA2"}, + {CC(G_CC_MODULATEI_PRIM2), "G_CC_MODULATEI_PRIM2"}, + {CC(G_CC_MODULATEIA_PRIM2), "G_CC_MODULATEIA_PRIM2"}, + {CC(G_CC_MODULATERGB_PRIM2), "G_CC_MODULATERGB_PRIM2"}, + {CC(G_CC_MODULATERGBA_PRIM2), "G_CC_MODULATERGBA_PRIM2"}, + {CC(G_CC_DECALRGB2), "G_CC_DECALRGB2"}, + {CC(G_CC_BLENDI2), "G_CC_BLENDI2"}, + {CC(G_CC_BLENDIA2), "G_CC_BLENDIA2"}, + {CC(G_CC_HILITERGB2), "G_CC_HILITERGB2"}, + {CC(G_CC_HILITERGBA2), "G_CC_HILITERGBA2"}, + {CC(G_CC_HILITERGBDECALA2), "G_CC_HILITERGBDECALA2"}, + {CC(G_CC_HILITERGBPASSA2), "G_CC_HILITERGBPASSA2"}, + {CC(G_CC_CHROMA_KEY2), "G_CC_CHROMA_KEY2"}, + {CC(G_CC_YUV2RGB), "G_CC_YUV2RGB"}, + {CC(G_CC_PASS2), "G_CC_PASS2"}, +}; +#undef CC_ +#undef CC + +UCFUNC int argfn_ccpre(const gfxd_value_t *v) +{ + return gfxd_printf("%s", cc_presets[v->i].name); +} + +UCFUNC int argfn_sc(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_SC_NON_INTERLACE: + return gfxd_puts("G_SC_NON_INTERLACE"); + case G_SC_EVEN_INTERLACE: + return gfxd_puts("G_SC_EVEN_INTERLACE"); + case G_SC_ODD_INTERLACE: + return gfxd_puts("G_SC_ODD_INTERLACE"); + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +UCFUNC int argfn_bz(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_BZ_PERSP: + return gfxd_puts("G_BZ_PERSP"); + default: + return gfxd_puts("G_BZ_ORTHO"); + } +} +#endif + +UCFUNC int argfn_dlf(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_DL_PUSH: + return gfxd_puts("G_DL_PUSH"); + case G_DL_NOPUSH: + return gfxd_puts("G_DL_NOPUSH"); + default: + return gfxd_printf("%" PRIi32, v->i);; + } +} + +UCFUNC int argfn_mp(const gfxd_value_t *v) +{ + int n = 0; + if (v->u & G_MTX_PUSH) + n += gfxd_puts("G_MTX_PUSH"); + else + n += gfxd_puts("G_MTX_NOPUSH"); + if (v->u & G_MTX_LOAD) + n += gfxd_puts(" | G_MTX_LOAD"); + else + n += gfxd_puts(" | G_MTX_MUL"); + if (v->u & G_MTX_PROJECTION) + n += gfxd_puts(" | G_MTX_PROJECTION"); + else + n += gfxd_puts(" | G_MTX_MODELVIEW"); + for (int i = 3; i < 8; i++) + if (v->u & (1 << i)) + n += gfxd_printf(" | 0x%02x", 1 << i); + return n; +} + +UCFUNC int argfn_ms(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_MTX_MODELVIEW: + return gfxd_puts("G_MTX_MODELVIEW"); + case G_MTX_PROJECTION: + return gfxd_puts("G_MTX_PROJECTION"); + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +UCFUNC int argfn_mw(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_MW_MATRIX: + return gfxd_puts("G_MW_MATRIX"); + case G_MW_NUMLIGHT: + return gfxd_puts("G_MW_NUMLIGHT"); + case G_MW_CLIP: + return gfxd_puts("G_MW_CLIP"); + case G_MW_SEGMENT: + return gfxd_puts("G_MW_SEGMENT"); + case G_MW_FOG: + return gfxd_puts("G_MW_FOG"); + case G_MW_LIGHTCOL: + return gfxd_puts("G_MW_LIGHTCOL"); + case G_MW_PERSPNORM: + return gfxd_puts("G_MW_PERSPNORM"); +#if defined(F3D_GBI) || defined(F3DEX_GBI) + case G_MW_POINTS: + return gfxd_puts("G_MW_POINTS"); +#endif +#if defined(F3DEX_GBI_2) + case G_MW_FORCEMTX: + return gfxd_puts("G_MW_FORCEMTX"); +#endif + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +UCFUNC int argfn_mwo_clip(const gfxd_value_t *v) +{ + switch (v->u) + { + case G_MWO_CLIP_RNX: + return gfxd_puts("G_MWO_CLIP_RNX"); + case G_MWO_CLIP_RNY: + return gfxd_puts("G_MWO_CLIP_RNY"); + case G_MWO_CLIP_RPX: + return gfxd_puts("G_MWO_CLIP_RPX"); + case G_MWO_CLIP_RPY: + return gfxd_puts("G_MWO_CLIP_RPY"); + default: + return gfxd_printf("0x%04" PRIX32, v->u); + } +} + +UCFUNC int argfn_mwo_lightcol(const gfxd_value_t *v) +{ + switch (v->u) + { + case G_MWO_aLIGHT_1: + return gfxd_puts("G_MWO_aLIGHT_1"); + case G_MWO_bLIGHT_1: + return gfxd_puts("G_MWO_bLIGHT_1"); + case G_MWO_aLIGHT_2: + return gfxd_puts("G_MWO_aLIGHT_2"); + case G_MWO_bLIGHT_2: + return gfxd_puts("G_MWO_bLIGHT_2"); + case G_MWO_aLIGHT_3: + return gfxd_puts("G_MWO_aLIGHT_3"); + case G_MWO_bLIGHT_3: + return gfxd_puts("G_MWO_bLIGHT_3"); + case G_MWO_aLIGHT_4: + return gfxd_puts("G_MWO_aLIGHT_4"); + case G_MWO_bLIGHT_4: + return gfxd_puts("G_MWO_bLIGHT_4"); + case G_MWO_aLIGHT_5: + return gfxd_puts("G_MWO_aLIGHT_5"); + case G_MWO_bLIGHT_5: + return gfxd_puts("G_MWO_bLIGHT_5"); + case G_MWO_aLIGHT_6: + return gfxd_puts("G_MWO_aLIGHT_6"); + case G_MWO_bLIGHT_6: + return gfxd_puts("G_MWO_bLIGHT_6"); + case G_MWO_aLIGHT_7: + return gfxd_puts("G_MWO_aLIGHT_7"); + case G_MWO_bLIGHT_7: + return gfxd_puts("G_MWO_bLIGHT_7"); + case G_MWO_aLIGHT_8: + return gfxd_puts("G_MWO_aLIGHT_8"); + case G_MWO_bLIGHT_8: + return gfxd_puts("G_MWO_bLIGHT_8"); + default: + return gfxd_printf("0x%04" PRIX32, v->u); + } +} + +UCFUNC int argfn_lightnum(const gfxd_value_t *v) +{ + return gfxd_printf("LIGHT_%" PRIi32, v->i); +} + +UCFUNC int argfn_lightsn(const gfxd_value_t *v) +{ + return gfxd_printf("*(Lightsn *)0x%08" PRIX32, v->u); +} + +UCFUNC int argfn_mwo_matrix(const gfxd_value_t *v) +{ + switch (v->u) + { + case G_MWO_MATRIX_XX_XY_I: + return gfxd_puts("G_MWO_MATRIX_XX_XY_I"); + case G_MWO_MATRIX_XZ_XW_I: + return gfxd_puts("G_MWO_MATRIX_XZ_XW_I"); + case G_MWO_MATRIX_YX_YY_I: + return gfxd_puts("G_MWO_MATRIX_YX_YY_I"); + case G_MWO_MATRIX_YZ_YW_I: + return gfxd_puts("G_MWO_MATRIX_YZ_YW_I"); + case G_MWO_MATRIX_ZX_ZY_I: + return gfxd_puts("G_MWO_MATRIX_ZX_ZY_I"); + case G_MWO_MATRIX_ZZ_ZW_I: + return gfxd_puts("G_MWO_MATRIX_ZZ_ZW_I"); + case G_MWO_MATRIX_WX_WY_I: + return gfxd_puts("G_MWO_MATRIX_WX_WY_I"); + case G_MWO_MATRIX_WZ_WW_I: + return gfxd_puts("G_MWO_MATRIX_WZ_WW_I"); + case G_MWO_MATRIX_XX_XY_F: + return gfxd_puts("G_MWO_MATRIX_XX_XY_F"); + case G_MWO_MATRIX_XZ_XW_F: + return gfxd_puts("G_MWO_MATRIX_XZ_XW_F"); + case G_MWO_MATRIX_YX_YY_F: + return gfxd_puts("G_MWO_MATRIX_YX_YY_F"); + case G_MWO_MATRIX_YZ_YW_F: + return gfxd_puts("G_MWO_MATRIX_YZ_YW_F"); + case G_MWO_MATRIX_ZX_ZY_F: + return gfxd_puts("G_MWO_MATRIX_ZX_ZY_F"); + case G_MWO_MATRIX_ZZ_ZW_F: + return gfxd_puts("G_MWO_MATRIX_ZZ_ZW_F"); + case G_MWO_MATRIX_WX_WY_F: + return gfxd_puts("G_MWO_MATRIX_WX_WY_F"); + case G_MWO_MATRIX_WZ_WW_F: + return gfxd_puts("G_MWO_MATRIX_WZ_WW_F"); + default: + return gfxd_printf("0x%04" PRIX32, v->u); + } +} + +UCFUNC int argfn_mwo_point(const gfxd_value_t *v) +{ + switch (v->u) + { + case G_MWO_POINT_RGBA: + return gfxd_puts("G_MWO_POINT_RGBA"); + case G_MWO_POINT_ST: + return gfxd_puts("G_MWO_POINT_ST"); + case G_MWO_POINT_XYSCREEN: + return gfxd_puts("G_MWO_POINT_XYSCREEN"); + case G_MWO_POINT_ZSCREEN: + return gfxd_puts("G_MWO_POINT_ZSCREEN"); + default: + return gfxd_printf("0x%04" PRIX32, v->u); + } +} + +UCFUNC int argfn_mv(const gfxd_value_t *v) +{ + switch (v->i) + { + case G_MV_VIEWPORT: + return gfxd_puts("G_MV_VIEWPORT"); +#if defined(F3D_GBI) || defined(F3DEX_GBI) + case G_MV_LOOKATY: + return gfxd_puts("G_MV_LOOKATY"); + case G_MV_LOOKATX: + return gfxd_puts("G_MV_LOOKATX"); + case G_MV_L0: + return gfxd_puts("G_MV_L0"); + case G_MV_L1: + return gfxd_puts("G_MV_L1"); + case G_MV_L2: + return gfxd_puts("G_MV_L2"); + case G_MV_L3: + return gfxd_puts("G_MV_L3"); + case G_MV_L4: + return gfxd_puts("G_MV_L4"); + case G_MV_L5: + return gfxd_puts("G_MV_L5"); + case G_MV_L6: + return gfxd_puts("G_MV_L6"); + case G_MV_L7: + return gfxd_puts("G_MV_L7"); + case G_MV_TXTATT: + return gfxd_puts("G_MV_TXTATT"); + case G_MV_MATRIX_2: + return gfxd_puts("G_MV_MATRIX_2"); + case G_MV_MATRIX_3: + return gfxd_puts("G_MV_MATRIX_3"); + case G_MV_MATRIX_4: + return gfxd_puts("G_MV_MATRIX_4"); + case G_MV_MATRIX_1: + return gfxd_puts("G_MV_MATRIX_1"); +#elif defined(F3DEX_GBI_2) + case G_MV_MMTX: + return gfxd_puts("G_MV_MMTX"); + case G_MV_PMTX: + return gfxd_puts("G_MV_PMTX"); + case G_MV_LIGHT: + return gfxd_puts("G_MV_LIGHT"); + case G_MV_POINT: + return gfxd_puts("G_MV_POINT"); + case G_MV_MATRIX: + return gfxd_puts("G_MV_MATRIX"); +#endif + default: + return gfxd_printf("%" PRIi32, v->i); + } +} + +UCFUNC int argfn_cr(const gfxd_value_t *v) +{ + switch (v->u) + { + case FRUSTRATIO_1: + return gfxd_puts("FRUSTRATIO_1"); + case FRUSTRATIO_2: + return gfxd_puts("FRUSTRATIO_2"); + case FRUSTRATIO_3: + return gfxd_puts("FRUSTRATIO_3"); + case FRUSTRATIO_4: + return gfxd_puts("FRUSTRATIO_4"); + case FRUSTRATIO_5: + return gfxd_puts("FRUSTRATIO_5"); + case FRUSTRATIO_6: + return gfxd_puts("FRUSTRATIO_6"); + default: + return gfxd_printf("%" PRIu32, v->u); + } +} diff --git a/tools/ZAPD/lib/libgfxd/uc_argtbl.c b/tools/ZAPD/lib/libgfxd/uc_argtbl.c new file mode 100644 index 0000000000..09baa0abbb --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc_argtbl.c @@ -0,0 +1,490 @@ +static const gfxd_arg_type_t arg_tbl[] = +{ + [gfxd_Word] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Opcode] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_opc, + }, + [gfxd_Coordi] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_u, + }, + [gfxd_Coordq] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_qu102, + }, + [gfxd_Pal] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Tlut] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Timg] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Tmem] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x16, + }, + [gfxd_Tile] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_tile, + }, + [gfxd_Fmt] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_fmt, + }, + [gfxd_Siz] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_siz, + }, + [gfxd_Dim] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Cm] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_cm, + }, + [gfxd_Tm] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_tm, + }, + [gfxd_Ts] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_ts, + }, + [gfxd_Dxt] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_u, + }, + [gfxd_Tag] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Pm] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_pm, + }, + [gfxd_Colorpart] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_color, + }, + [gfxd_Color] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Lodfrac] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_qu08, + }, + [gfxd_Cimg] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Zimg] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Ac] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_ac, + }, + [gfxd_Ad] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_ad, + }, + [gfxd_Cd] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_cd, + }, + [gfxd_Ccpre] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_ccpre, + }, + [gfxd_Ccmuxa] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_ccmuxa, + }, + [gfxd_Ccmuxb] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_ccmuxb, + }, + [gfxd_Ccmuxc] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_ccmuxc, + }, + [gfxd_Ccmuxd] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_ccmuxd, + }, + [gfxd_Acmuxabd] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_acmuxabd, + }, + [gfxd_Acmuxc] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_acmuxc, + }, + [gfxd_Cv] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_cv, + }, + [gfxd_Tc] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_tc, + }, + [gfxd_Cyc] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_cyc, + }, + [gfxd_Zs] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_zs, + }, + [gfxd_Ck] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_ck, + }, + [gfxd_Keyscale] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_color, + }, + [gfxd_Keywidth] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_qs48, + }, + [gfxd_Zi] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Rm1] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_rm1, + }, + [gfxd_Rm2] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_rm2, + }, + [gfxd_Sc] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_sc, + }, + [gfxd_Td] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_td, + }, + [gfxd_Tf] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_tf, + }, + [gfxd_Tl] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_tl, + }, + [gfxd_Tt] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_tt, + }, + [gfxd_Tp] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_tp, + }, + [gfxd_Line] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Vtx] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Vtxflag] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Dl] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) + [gfxd_Zraw] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_qs1616, + }, +#endif + [gfxd_Dlflag] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_dlf, + }, + [gfxd_Cr] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_cr, + }, + [gfxd_Num] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Fogz] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Fogp] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Mtxptr] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Gm] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_gm, + }, + [gfxd_Mwo_matrix] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_mwo_matrix, + }, + [gfxd_Linewd] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Uctext] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Ucdata] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Size] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x16, + }, + [gfxd_Lookatptr] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Mtxparam] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_mp, + }, + [gfxd_Mtxstack] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_ms, + }, + [gfxd_Mwo_point] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_mwo_point, + }, + [gfxd_Wscale] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_qu016, + }, + [gfxd_Seg] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x8, + }, + [gfxd_Segptr] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Lightsn] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_lightsn, + }, + [gfxd_Numlights] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Lightnum] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_lightnum, + }, + [gfxd_Lightptr] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Tcscale] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_qu016, + }, + [gfxd_Switch] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_switch, + }, + [gfxd_St] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_qs105, + }, + [gfxd_Stdelta] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_qs510, + }, + [gfxd_Vtxptr] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Vpptr] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Dram] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x32, + }, + [gfxd_Dlflag] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, + [gfxd_Sftlo] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_sftlo, + }, + [gfxd_Othermodelo] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_othermodelo, + }, + [gfxd_Sfthi] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_sfthi, + }, + [gfxd_Othermodehi] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_othermodehi, + }, + [gfxd_Mw] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_mw, + }, + [gfxd_Mwo] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x16, + }, + [gfxd_Mwo_clip] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_mwo_clip, + }, + [gfxd_Mwo_lightcol] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_mwo_lightcol, + }, + [gfxd_Mv] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_mv, + }, + [gfxd_Mvo] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x16, + }, + [gfxd_Dmem] = + { + .fmt = gfxd_argfmt_u, + .fn = argfn_x16, + }, + [gfxd_Dmaflag] = + { + .fmt = gfxd_argfmt_i, + .fn = argfn_i, + }, +}; diff --git a/tools/ZAPD/lib/libgfxd/uc_f3d.c b/tools/ZAPD/lib/libgfxd/uc_f3d.c new file mode 100644 index 0000000000..9465515108 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc_f3d.c @@ -0,0 +1,4 @@ +#define uc_name gfxd_f3d +#define F3D_GBI + +#include "uc.c" diff --git a/tools/ZAPD/lib/libgfxd/uc_f3db.c b/tools/ZAPD/lib/libgfxd/uc_f3db.c new file mode 100644 index 0000000000..cd4990412d --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc_f3db.c @@ -0,0 +1,5 @@ +#define uc_name gfxd_f3db +#define F3D_GBI +#define F3D_BETA + +#include "uc.c" diff --git a/tools/ZAPD/lib/libgfxd/uc_f3dex.c b/tools/ZAPD/lib/libgfxd/uc_f3dex.c new file mode 100644 index 0000000000..2ec70d8aba --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc_f3dex.c @@ -0,0 +1,4 @@ +#define uc_name gfxd_f3dex +#define F3DEX_GBI + +#include "uc.c" diff --git a/tools/ZAPD/lib/libgfxd/uc_f3dex2.c b/tools/ZAPD/lib/libgfxd/uc_f3dex2.c new file mode 100644 index 0000000000..9a19c99038 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc_f3dex2.c @@ -0,0 +1,4 @@ +#define uc_name gfxd_f3dex2 +#define F3DEX_GBI_2 + +#include "uc.c" diff --git a/tools/ZAPD/lib/libgfxd/uc_f3dexb.c b/tools/ZAPD/lib/libgfxd/uc_f3dexb.c new file mode 100644 index 0000000000..2b5c30a4a6 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc_f3dexb.c @@ -0,0 +1,5 @@ +#define uc_name gfxd_f3dexb +#define F3DEX_GBI +#define F3D_BETA + +#include "uc.c" diff --git a/tools/ZAPD/lib/libgfxd/uc_macrofn.c b/tools/ZAPD/lib/libgfxd/uc_macrofn.c new file mode 100644 index 0000000000..707c0cbf5a --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc_macrofn.c @@ -0,0 +1,2453 @@ +static inline uint32_t getfield(uint32_t w, int n, int s) +{ + return (w >> s) & (((uint32_t)1 << n) - 1); +} + +static inline int32_t argvi(gfxd_macro_t *m, int idx) +{ + return m->arg[idx].value.i; +} + +static inline uint32_t argvu(gfxd_macro_t *m, int idx) +{ + return m->arg[idx].value.u; +} + +static inline float argvf(gfxd_macro_t *m, int idx) +{ + return m->arg[idx].value.f; +} + +static inline void argi(gfxd_macro_t *m, int idx, const char *name, + int32_t value, int type) +{ + m->arg[idx].type = type; + m->arg[idx].name = name; + m->arg[idx].value.i = value; + m->arg[idx].bad = 0; +} + +static inline void argu(gfxd_macro_t *m, int idx, const char *name, + uint32_t value, int type) +{ + m->arg[idx].type = type; + m->arg[idx].name = name; + m->arg[idx].value.u = value; + m->arg[idx].bad = 0; +} + +static inline void argf(gfxd_macro_t *m, int idx, const char *name, + float value, int type) +{ + m->arg[idx].type = type; + m->arg[idx].name = name; + m->arg[idx].value.f = value; + m->arg[idx].bad = 0; +} + +static inline void badarg(gfxd_macro_t *m, int idx) +{ + m->arg[idx].bad = 1; +} + +UCFUNC int32_t sx(uint32_t n, int bits) +{ + int32_t smin = (int32_t)1 << (bits - 1); + int32_t smax = (int32_t)1 << bits; + int32_t i = n; + if (i < smin) + return i; + else + return i - smax; +} + +UCFUNC int d_Invalid(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_Invalid; + argu(m, 0, "hi", hi, gfxd_Word); + argu(m, 1, "lo", lo, gfxd_Word); + return -1; +} + +UCFUNC int d_DPFillRectangle(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPFillRectangle; + argu(m, 0, "ulx", getfield(lo, 10, 14), gfxd_Coordi); + argu(m, 1, "uly", getfield(lo, 10, 2), gfxd_Coordi); + argu(m, 2, "lrx", getfield(hi, 10, 14), gfxd_Coordi); + argu(m, 3, "lry", getfield(hi, 10, 2), gfxd_Coordi); + return 0; +} + +UCFUNC int d_DPFullSync(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPFullSync; + return 0; +} + +UCFUNC int d_DPLoadSync(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPLoadSync; + return 0; +} + +UCFUNC int d_DPTileSync(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPTileSync; + return 0; +} + +UCFUNC int d_DPPipeSync(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPPipeSync; + return 0; +} + +UCFUNC int c_DPLoadTLUT_pal16(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 6) + return -1; + if (m[0].id != gfxd_DPSetTextureImage + || argvi(&m[0], 0) != G_IM_FMT_RGBA + || argvi(&m[0], 1) != G_IM_SIZ_16b + || argvi(&m[0], 2) != 1) + { + return -1; + } + uint32_t dram = argvu(&m[0], 3); + if (m[1].id != gfxd_DPTileSync) + return -1; + if (m[2].id != gfxd_DPSetTile + || argvi(&m[2], 0) != 0 + || argvi(&m[2], 1) != 0 + || argvi(&m[2], 2) != 0 + || argvu(&m[2], 3) < 0x100 + || argvu(&m[2], 3) % 0x10 != 0 + || argvi(&m[2], 4) != G_TX_LOADTILE + || argvi(&m[2], 5) != 0 + || argvu(&m[2], 6) != 0 + || argvi(&m[2], 7) != 0 + || argvi(&m[2], 8) != 0 + || argvu(&m[2], 9) != 0 + || argvi(&m[2], 10) != 0 + || argvi(&m[2], 11) != 0) + { + return -1; + } + int pal = (argvu(&m[2], 3) - 0x100) / 0x10; + if (m[3].id != gfxd_DPLoadSync) + return -1; + if (m[4].id != gfxd_DPLoadTLUTCmd + || argvi(&m[4], 0) != G_TX_LOADTILE + || argvi(&m[4], 1) != 15) + { + return -1; + } + if (m[5].id != gfxd_DPPipeSync) + return -1; + m->id = gfxd_DPLoadTLUT_pal16; + argi(m, 0, "pal", pal, gfxd_Pal); + argu(m, 1, "dram", dram, gfxd_Tlut); + return 0; +} + +UCFUNC int c_DPLoadTLUT_pal256(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 6) + return -1; + if (m[0].id != gfxd_DPSetTextureImage + || argvi(&m[0], 0) != G_IM_FMT_RGBA + || argvi(&m[0], 1) != G_IM_SIZ_16b + || argvi(&m[0], 2) != 1) + { + return -1; + } + uint32_t dram = argvu(&m[0], 3); + if (m[1].id != gfxd_DPTileSync) + return -1; + if (m[2].id != gfxd_DPSetTile + || argvi(&m[2], 0) != 0 + || argvi(&m[2], 1) != 0 + || argvi(&m[2], 2) != 0 + || argvu(&m[2], 3) != 0x100 + || argvi(&m[2], 4) != G_TX_LOADTILE + || argvi(&m[2], 5) != 0 + || argvu(&m[2], 6) != 0 + || argvi(&m[2], 7) != 0 + || argvi(&m[2], 8) != 0 + || argvu(&m[2], 9) != 0 + || argvi(&m[2], 10) != 0 + || argvi(&m[2], 11) != 0) + { + return -1; + } + if (m[3].id != gfxd_DPLoadSync) + return -1; + if (m[4].id != gfxd_DPLoadTLUTCmd + || argvi(&m[4], 0) != G_TX_LOADTILE + || argvi(&m[4], 1) != 255) + { + return -1; + } + if (m[5].id != gfxd_DPPipeSync) + return -1; + m->id = gfxd_DPLoadTLUT_pal256; + argu(m, 0, "dram", dram, gfxd_Tlut); + return 0; +} + +UCFUNC int c_ltb(gfxd_macro_t *m, int n_macro, int id, int mdxt, int mtmem, + int mrt, int myuv, int m4b) +{ + if (n_macro < 7) + return -1; + if (m[0].id != gfxd_DPSetTextureImage || argvi(&m[0], 2) != 1) + return -1; + g_ifmt_t fmt = argvi(&m[0], 0); + g_isiz_t ldsiz = argvi(&m[0], 1); + uint32_t timg = argvu(&m[0], 3); + if (myuv && fmt != G_IM_FMT_YUV) + return -1; + if (m[1].id != gfxd_DPSetTile + || argvi(&m[1], 0) != fmt + || argvi(&m[1], 1) != ldsiz + || argvi(&m[1], 2) != 0 + || argvi(&m[1], 4) != G_TX_LOADTILE + || argvi(&m[1], 5) != 0) + { + return -1; + } + uint32_t tmem = argvu(&m[1], 3); + unsigned cms = argvu(&m[1], 9); + unsigned cmt = argvu(&m[1], 6); + int masks = argvi(&m[1], 10); + int maskt = argvi(&m[1], 7); + int shifts = argvi(&m[1], 11); + int shiftt = argvi(&m[1], 8); + if (m[2].id != gfxd_DPLoadSync) + return -1; + if (m[3].id != gfxd_DPLoadBlock + || argvi(&m[3], 0) != G_TX_LOADTILE + || argvu(&m[3], 1) != 0 + || argvu(&m[3], 2) != 0) + { + return -1; + } + qu102_t ldlrs = argvu(&m[3], 3); + unsigned lddxt = argvu(&m[3], 4); + if (m[4].id != gfxd_DPPipeSync) + return -1; + if (m[5].id != gfxd_DPSetTile + || argvi(&m[5], 0) != fmt + || G_SIZ_LDSIZ(argvi(&m[5], 1)) != ldsiz + || argvu(&m[5], 3) != tmem + || argvu(&m[5], 6) != cmt + || argvi(&m[5], 7) != maskt + || argvi(&m[5], 8) != shiftt + || argvu(&m[5], 9) != cms + || argvi(&m[5], 10) != masks + || argvi(&m[5], 11) != shifts) + { + return -1; + } + int siz = argvi(&m[5], 1); + int rdline = argvi(&m[5], 2); + int rt = argvi(&m[5], 4); + int pal = argvi(&m[5], 5); + if (m4b && siz != G_IM_SIZ_4b) + return -1; + if (!(mrt && rt != G_TX_RENDERTILE && tmem == 0) + && (tmem != 0) != mtmem) + { + return -1; + } + if ((rt != G_TX_RENDERTILE) != mrt) + return -1; + if (m[6].id != gfxd_DPSetTileSize + || argvi(&m[6], 0) != rt + || argvu(&m[6], 1) != 0 + || argvu(&m[6], 2) != 0 + || (argvu(&m[6], 3) & 3) + || (argvu(&m[6], 4) & 3)) + { + return -1; + } + int width = (argvu(&m[6], 3) >> 2) + 1; + int height = (argvu(&m[6], 4) >> 2) + 1; + unsigned lrs = ((width * height + 1) * G_SIZ_BITS(siz) - 1) / + G_SIZ_BITS(G_SIZ_LDSIZ(siz)) - 1; + unsigned dxt = 0; + if (!mdxt) + { + dxt = (width * G_SIZ_BITS(siz) <= 64 ? (1 << 11) : + ((1 << 11) + width * G_SIZ_BITS(siz) / 64 - 1) / + (width * G_SIZ_BITS(siz) / 64)); + } + int line; + if (myuv) + line = (width + 7) / 8; + else + line = (width * G_SIZ_LDBITS(siz) + 63) / 64; + if (ldlrs != lrs || lddxt != dxt || rdline != line) + return -1; + m->id = id; + int i = 0; + argu(m, i++, "timg", timg, gfxd_Timg); + if (mtmem) + argu(m, i++, "tmem", tmem, gfxd_Tmem); + if (mrt) + argi(m, i++, "rtile", rt, gfxd_Tile); + argi(m, i++, "fmt", fmt, gfxd_Fmt); + if (!m4b) + argi(m, i++, "siz", siz, gfxd_Siz); + argi(m, i++, "width", width, gfxd_Dim); + argi(m, i++, "height", height, gfxd_Dim); + argi(m, i++, "pal", pal, gfxd_Pal); + argu(m, i++, "cms", cms, gfxd_Cm); + argu(m, i++, "cmt", cmt, gfxd_Cm); + argi(m, i++, "masks", masks, gfxd_Tm); + argi(m, i++, "maskt", maskt, gfxd_Tm); + argi(m, i++, "shifts", shifts, gfxd_Ts); + argi(m, i++, "shiftt", shiftt, gfxd_Ts); + return 0; +} + +UCFUNC int c_DPLoadMultiBlockYuvS(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadMultiBlockYuvS, 1, 1, 1, 1, 0); +} + +UCFUNC int c_DPLoadMultiBlockYuv(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadMultiBlockYuv, 0, 1, 1, 1, 0); +} + +UCFUNC int c_DPLoadMultiBlock_4bS(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadMultiBlock_4bS, 1, 1, 1, 0, 1); +} + +UCFUNC int c_DPLoadMultiBlock_4b(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadMultiBlock_4b, 0, 1, 1, 0, 1); +} + +UCFUNC int c_DPLoadMultiBlockS(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadMultiBlockS, 1, 1, 1, 0, 0); +} + +UCFUNC int c_DPLoadMultiBlock(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadMultiBlock, 0, 1, 1, 0, 0); +} + +UCFUNC int c__DPLoadTextureBlockYuvS(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd__DPLoadTextureBlockYuvS, 1, 1, 0, 1, 0); +} + +UCFUNC int c__DPLoadTextureBlockYuv(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd__DPLoadTextureBlockYuv, 0, 1, 0, 1, 0); +} + +UCFUNC int c__DPLoadTextureBlock_4bS(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd__DPLoadTextureBlock_4bS, 1, 1, 0, 0, 1); +} + +UCFUNC int c__DPLoadTextureBlock_4b(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd__DPLoadTextureBlock_4b, 0, 1, 0, 0, 1); +} + +UCFUNC int c__DPLoadTextureBlockS(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd__DPLoadTextureBlockS, 1, 1, 0, 0, 0); +} + +UCFUNC int c__DPLoadTextureBlock(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd__DPLoadTextureBlock, 0, 1, 0, 0, 0); +} + +UCFUNC int c_DPLoadTextureBlockYuvS(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadTextureBlockYuvS, 1, 0, 0, 1, 0); +} + +UCFUNC int c_DPLoadTextureBlockYuv(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadTextureBlockYuv, 0, 0, 0, 1, 0); +} + +UCFUNC int c_DPLoadTextureBlock_4bS(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadTextureBlock_4bS, 1, 0, 0, 0, 1); +} + +UCFUNC int c_DPLoadTextureBlock_4b(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadTextureBlock_4b, 0, 0, 0, 0, 1); +} + +UCFUNC int c_DPLoadTextureBlockS(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadTextureBlockS, 1, 0, 0, 0, 0); +} + +UCFUNC int c_DPLoadTextureBlock(gfxd_macro_t *m, int n_macro) +{ + return c_ltb(m, n_macro, gfxd_DPLoadTextureBlock, 0, 0, 0, 0, 0); +} + +UCFUNC int c_ltt(gfxd_macro_t *m, int n_macro, int id, int mtmem, int mrt, + int myuv, int m4b) +{ + if (n_macro < 7) + return -1; + if (m[0].id != gfxd_DPSetTextureImage) + return -1; + g_ifmt_t fmt = argvi(&m[0], 0); + g_isiz_t ldsiz = argvi(&m[0], 1); + int width = argvi(&m[0], 2); + if (m4b) + { + if (ldsiz != G_IM_SIZ_8b) + return -1; + width *= 2; + } + uint32_t timg = argvu(&m[0], 3); + if (myuv && fmt != G_IM_FMT_YUV) + return -1; + if (m[1].id != gfxd_DPSetTile + || argvi(&m[1], 0) != fmt + || argvi(&m[1], 1) != ldsiz + || argvi(&m[1], 4) != G_TX_LOADTILE + || argvi(&m[1], 5) != 0) + { + return -1; + } + int ldline = argvi(&m[1], 2); + uint32_t tmem = argvu(&m[1], 3); + unsigned cms = argvu(&m[1], 9); + unsigned cmt = argvu(&m[1], 6); + int masks = argvi(&m[1], 10); + int maskt = argvi(&m[1], 7); + int shifts = argvi(&m[1], 11); + int shiftt = argvi(&m[1], 8); + if (m[2].id != gfxd_DPLoadSync) + return -1; + if (m[3].id != gfxd_DPLoadTile + || argvi(&m[3], 0) != G_TX_LOADTILE + || (argvu(&m[3], 1) & 1) + || (argvu(&m[3], 2) & 3) + || (argvu(&m[3], 3) & 1) + || (argvu(&m[3], 4) & 3)) + { + return -1; + } + qu102_t lduls = argvu(&m[3], 1); + qu102_t ldult = argvu(&m[3], 2); + qu102_t ldlrs = argvu(&m[3], 3); + qu102_t ldlrt = argvu(&m[3], 4); + if (m[4].id != gfxd_DPPipeSync) + return -1; + if (m[5].id != gfxd_DPSetTile + || argvi(&m[5], 0) != fmt + || argvi(&m[5], 2) != ldline + || argvu(&m[5], 3) != tmem + || argvu(&m[5], 6) != cmt + || argvi(&m[5], 7) != maskt + || argvi(&m[5], 8) != shiftt + || argvu(&m[5], 9) != cms + || argvi(&m[5], 10) != masks + || argvi(&m[5], 11) != shifts) + { + return -1; + } + int siz = argvi(&m[5], 1); + int rt = argvi(&m[5], 4); + int pal = argvi(&m[5], 5); + if (m4b) + { + if (siz != G_IM_SIZ_4b) + return -1; + } + else if (siz != ldsiz) + return -1; + if (!(mrt && rt != G_TX_RENDERTILE && tmem == 0) + && (tmem != 0) != mtmem) + { + return -1; + } + if ((rt != G_TX_RENDERTILE) != mrt) + return -1; + if (m[6].id != gfxd_DPSetTileSize + || argvi(&m[6], 0) != rt + || (argvu(&m[6], 1) & 3) + || (argvu(&m[6], 2) & 3) + || (argvu(&m[6], 3) & 3) + || (argvu(&m[6], 4) & 3)) + { + return -1; + } + unsigned uls = argvu(&m[6], 1) >> 2; + unsigned ult = argvu(&m[6], 2) >> 2; + unsigned lrs = argvu(&m[6], 3) >> 2; + unsigned lrt = argvu(&m[6], 4) >> 2; + int line; + if (myuv) + line = ((lrs - uls + 1) + 7) / 8; + else if (m4b) + line = ((lrs - uls + 1) / 2 + 7) / 8; + else + line = ((lrs - uls + 1) * G_SIZ_LDBITS(siz) + 63) / 64; + if (m4b) + { + if (lduls != qu102(uls) / 2 || ldlrs != qu102(lrs) / 2) + return -1; + } + else if (lduls != qu102(uls) || ldlrs != qu102(lrs)) + return -1; + if (ldult != qu102(ult) || ldlrt != qu102(lrt) || ldline != line) + return -1; + m->id = id; + int i = 0; + argu(m, i++, "timg", timg, gfxd_Timg); + if (mtmem) + argu(m, i++, "tmem", tmem, gfxd_Tmem); + if (mrt) + argi(m, i++, "rtile", rt, gfxd_Tile); + argi(m, i++, "fmt", fmt, gfxd_Fmt); + if (!m4b) + argi(m, i++, "siz", siz, gfxd_Siz); + argi(m, i++, "width", width, gfxd_Dim); + argi(m, i++, "height", 0, gfxd_Dim); + argu(m, i++, "uls", uls, gfxd_Coordi); + argu(m, i++, "ult", ult, gfxd_Coordi); + argu(m, i++, "lrs", lrs, gfxd_Coordi); + argu(m, i++, "lrt", lrt, gfxd_Coordi); + argi(m, i++, "pal", pal, gfxd_Pal); + argu(m, i++, "cms", cms, gfxd_Cm); + argu(m, i++, "cmt", cmt, gfxd_Cm); + argi(m, i++, "masks", masks, gfxd_Tm); + argi(m, i++, "maskt", maskt, gfxd_Tm); + argi(m, i++, "shifts", shifts, gfxd_Ts); + argi(m, i++, "shiftt", shiftt, gfxd_Ts); + return 0; +} + +UCFUNC int c_DPLoadMultiTileYuv(gfxd_macro_t *m, int n_macro) +{ + return c_ltt(m, n_macro, gfxd_DPLoadMultiTileYuv, 1, 1, 1, 0); +} + +UCFUNC int c_DPLoadMultiTile_4b(gfxd_macro_t *m, int n_macro) +{ + return c_ltt(m, n_macro, gfxd_DPLoadMultiTile_4b, 1, 1, 0, 1); +} + +UCFUNC int c_DPLoadMultiTile(gfxd_macro_t *m, int n_macro) +{ + return c_ltt(m, n_macro, gfxd_DPLoadMultiTile, 1, 1, 0, 0); +} + +UCFUNC int c__DPLoadTextureTileYuv(gfxd_macro_t *m, int n_macro) +{ + return c_ltt(m, n_macro, gfxd__DPLoadTextureTileYuv, 1, 0, 1, 0); +} + +UCFUNC int c__DPLoadTextureTile_4b(gfxd_macro_t *m, int n_macro) +{ + return c_ltt(m, n_macro, gfxd__DPLoadTextureTile_4b, 1, 0, 0, 1); +} + +UCFUNC int c__DPLoadTextureTile(gfxd_macro_t *m, int n_macro) +{ + return c_ltt(m, n_macro, gfxd__DPLoadTextureTile, 1, 0, 0, 0); +} + +UCFUNC int c_DPLoadTextureTileYuv(gfxd_macro_t *m, int n_macro) +{ + return c_ltt(m, n_macro, gfxd_DPLoadTextureTileYuv, 0, 0, 1, 0); +} + +UCFUNC int c_DPLoadTextureTile_4b(gfxd_macro_t *m, int n_macro) +{ + return c_ltt(m, n_macro, gfxd_DPLoadTextureTile_4b, 0, 0, 0, 1); +} + +UCFUNC int c_DPLoadTextureTile(gfxd_macro_t *m, int n_macro) +{ + return c_ltt(m, n_macro, gfxd_DPLoadTextureTile, 0, 0, 0, 0); +} + +UCFUNC int d_DPLoadBlock(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPLoadBlock; + argi(m, 0, "tile", getfield(lo, 3, 24), gfxd_Tile); + argu(m, 1, "uls", getfield(hi, 12, 12), gfxd_Coordi); + argu(m, 2, "ult", getfield(hi, 12, 0), gfxd_Coordi); + argu(m, 3, "lrs", getfield(lo, 12, 12), gfxd_Coordi); + argu(m, 4, "dxt", getfield(lo, 12, 0), gfxd_Dxt); + return 0; +} + +UCFUNC int d_DPNoOp(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPNoOp; + return 0; +} + +UCFUNC int d_DPNoOpTag(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + if (lo == 0) + return d_DPNoOp(m, hi, lo); + else + { + m->id = gfxd_DPNoOpTag; + argu(m, 0, "tag", lo, gfxd_Tag); + return 0; + } +} + +UCFUNC int d_DPPipelineMode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPPipelineMode; + argu(m, 0, "mode", lo, gfxd_Pm); + return 0; +} + +UCFUNC int d_DPSetBlendColor(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetBlendColor; + argu(m, 0, "r", getfield(lo, 8, 24), gfxd_Colorpart); + argu(m, 1, "g", getfield(lo, 8, 16), gfxd_Colorpart); + argu(m, 2, "b", getfield(lo, 8, 8), gfxd_Colorpart); + argu(m, 3, "a", getfield(lo, 8, 0), gfxd_Colorpart); + return 0; +} + +UCFUNC int d_DPSetEnvColor(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetEnvColor; + argu(m, 0, "r", getfield(lo, 8, 24), gfxd_Colorpart); + argu(m, 1, "g", getfield(lo, 8, 16), gfxd_Colorpart); + argu(m, 2, "b", getfield(lo, 8, 8), gfxd_Colorpart); + argu(m, 3, "a", getfield(lo, 8, 0), gfxd_Colorpart); + return 0; +} + +UCFUNC int d_DPSetFillColor(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetFillColor; + argu(m, 0, "c", lo, gfxd_Color); + return 0; +} + +UCFUNC int d_DPSetFogColor(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetFogColor; + argu(m, 0, "r", getfield(lo, 8, 24), gfxd_Colorpart); + argu(m, 1, "g", getfield(lo, 8, 16), gfxd_Colorpart); + argu(m, 2, "b", getfield(lo, 8, 8), gfxd_Colorpart); + argu(m, 3, "a", getfield(lo, 8, 0), gfxd_Colorpart); + return 0; +} + +UCFUNC int d_DPSetPrimColor(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetPrimColor; + argu(m, 0, "m", getfield(hi, 8, 8), gfxd_Lodfrac); + argu(m, 1, "l", getfield(hi, 8, 0), gfxd_Lodfrac); + argu(m, 2, "r", getfield(lo, 8, 24), gfxd_Colorpart); + argu(m, 3, "g", getfield(lo, 8, 16), gfxd_Colorpart); + argu(m, 4, "b", getfield(lo, 8, 8), gfxd_Colorpart); + argu(m, 5, "a", getfield(lo, 8, 0), gfxd_Colorpart); + return 0; +} + +UCFUNC int d_DPSetColorImage(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetColorImage; + argi(m, 0, "fmt", getfield(hi, 3, 21), gfxd_Fmt); + argi(m, 1, "siz", getfield(hi, 2, 19), gfxd_Siz); + argi(m, 2, "width", getfield(hi, 12, 0) + 1, gfxd_Dim); + argu(m, 3, "cimg", lo, gfxd_Cimg); + return 0; +} + +UCFUNC int d_DPSetDepthImage(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetDepthImage; + argu(m, 0, "zimg", lo, gfxd_Zimg); + return 0; +} + +UCFUNC int d_DPSetTextureImage(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetTextureImage; + argi(m, 0, "fmt", getfield(hi, 3, 21), gfxd_Fmt); + argi(m, 1, "siz", getfield(hi, 2, 19), gfxd_Siz); + argi(m, 2, "width", getfield(hi, 12, 0) + 1, gfxd_Dim); + argu(m, 3, "timg", lo, gfxd_Timg); + return 0; +} + +UCFUNC int d_DPSetAlphaCompare(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetAlphaCompare; + argu(m, 0, "mode", lo, gfxd_Ac); + return 0; +} + +UCFUNC int d_DPSetAlphaDither(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetAlphaDither; + argu(m, 0, "mode", lo, gfxd_Ad); + return 0; +} + +UCFUNC int d_DPSetColorDither(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetColorDither; + argu(m, 0, "mode", lo, gfxd_Cd); + return 0; +} + +UCFUNC void cc_unpack(struct cc_mode *m0, struct cc_mode *m1, uint32_t hi, + uint32_t lo) +{ + m0->a = getfield(hi, 4, 20); + m0->b = getfield(lo, 4, 28); + m0->c = getfield(hi, 5, 15); + m0->d = getfield(lo, 3, 15); + m0->Aa = getfield(hi, 3, 12); + m0->Ab = getfield(lo, 3, 12); + m0->Ac = getfield(hi, 3, 9); + m0->Ad = getfield(lo, 3, 9); + m1->a = getfield(hi, 4, 5); + m1->b = getfield(lo, 4, 24); + m1->c = getfield(hi, 5, 0); + m1->d = getfield(lo, 3, 6); + m1->Aa = getfield(lo, 3, 21); + m1->Ab = getfield(lo, 3, 3); + m1->Ac = getfield(lo, 3, 18); + m1->Ad = getfield(lo, 3, 0); +} + +UCFUNC int cc_lookup(const struct cc_mode *m) +{ + struct cc_mode m_norm = *m; + if (m_norm.a > 0x7) m_norm.a = G_CCMUX_0; + if (m_norm.b > 0x7) m_norm.b = G_CCMUX_0; + if (m_norm.c > 0xF) m_norm.c = G_CCMUX_0; + if (m_norm.d > 0x6) m_norm.d = G_CCMUX_0; + m = &m_norm; + int n_presets = sizeof(cc_presets) / sizeof(*cc_presets); + for (int i = 0; i < n_presets; i++) + { + const struct cc_mode *p = &cc_presets[i].mode; + if (m->a == p->a + && m->b == p->b + && m->c == p->c + && m->d == p->d + && m->Aa == p->Aa + && m->Ab == p->Ab + && m->Ac == p->Ac + && m->Ad == p->Ad) + { + return i; + } + } + return -1; +} + +UCFUNC int d_DPSetCombineMode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetCombineMode; + struct cc_mode m0; + struct cc_mode m1; + cc_unpack(&m0, &m1, hi, lo); + int p0 = cc_lookup(&m0); + int p1 = cc_lookup(&m1); + argi(m, 0, "mode1", p0, gfxd_Ccpre); + argi(m, 1, "mode2", p1, gfxd_Ccpre); + int ret = 0; + if (p0 == -1) + { + badarg(m, 0); + ret = -1; + } + if (p1 == -1) + { + badarg(m, 1); + ret = -1; + } + return ret; +} + +UCFUNC int d_DPSetCombineLERP(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + struct cc_mode m0; + struct cc_mode m1; + cc_unpack(&m0, &m1, hi, lo); + int p0 = cc_lookup(&m0); + int p1 = cc_lookup(&m1); + if (p0 != -1 && p1 != -1) + return d_DPSetCombineMode(m, hi, lo); + else + { + m->id = gfxd_DPSetCombineLERP; + argi(m, 0, "a0", m0.a, gfxd_Ccmuxa); + argi(m, 1, "b0", m0.b, gfxd_Ccmuxb); + argi(m, 2, "c0", m0.c, gfxd_Ccmuxc); + argi(m, 3, "d0", m0.d, gfxd_Ccmuxd); + argi(m, 4, "Aa0", m0.Aa, gfxd_Acmuxabd); + argi(m, 5, "Ab0", m0.Ab, gfxd_Acmuxabd); + argi(m, 6, "Ac0", m0.Ac, gfxd_Acmuxc); + argi(m, 7, "Ad0", m0.Ad, gfxd_Acmuxabd); + argi(m, 8, "a1", m1.a, gfxd_Ccmuxa); + argi(m, 9, "b1", m1.b, gfxd_Ccmuxb); + argi(m, 10, "c1", m1.c, gfxd_Ccmuxc); + argi(m, 11, "d1", m1.d, gfxd_Ccmuxd); + argi(m, 12, "Aa1", m1.Aa, gfxd_Acmuxabd); + argi(m, 13, "Ab1", m1.Ab, gfxd_Acmuxabd); + argi(m, 14, "Ac1", m1.Ac, gfxd_Acmuxc); + argi(m, 15, "Ad1", m1.Ad, gfxd_Acmuxabd); + return 0; + } +} + +UCFUNC int d_DPSetConvert(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetConvert; + argi(m, 0, "k0", sx(getfield(hi, 9, 13), 9), gfxd_Cv); + argi(m, 1, "k1", sx(getfield(hi, 9, 4), 9), gfxd_Cv); + argi(m, 2, "k2", sx((getfield(hi, 4, 0) << 5) | getfield(lo, 5, 27), 9), + gfxd_Cv); + argi(m, 3, "k3", sx(getfield(lo, 9, 18), 9), gfxd_Cv); + argi(m, 4, "k4", sx(getfield(lo, 9, 9), 9), gfxd_Cv); + argi(m, 5, "k5", sx(getfield(lo, 9, 0), 9), gfxd_Cv); + return 0; +} + +UCFUNC int d_DPSetTextureConvert(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetTextureConvert; + argu(m, 0, "mode", lo, gfxd_Tc); + return 0; +} + +UCFUNC int d_DPSetCycleType(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetCycleType; + argu(m, 0, "mode", lo, gfxd_Cyc); + return 0; +} + +UCFUNC int d_DPSetDepthSource(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetDepthSource; + argu(m, 0, "mode", lo, gfxd_Zs); + return 0; +} + +UCFUNC int d_DPSetCombineKey(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetCombineKey; + argu(m, 0, "mode", lo, gfxd_Ck); + return 0; +} + +UCFUNC int d_DPSetKeyGB(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetKeyGB; + argu(m, 0, "cG", getfield(lo, 8, 24), gfxd_Color); + argu(m, 1, "sG", getfield(lo, 8, 16), gfxd_Keyscale); + argi(m, 2, "wG", sx(getfield(hi, 12, 12), 12), gfxd_Keywidth); + argu(m, 3, "cB", getfield(lo, 8, 8), gfxd_Color); + argu(m, 4, "sB", getfield(lo, 8, 0), gfxd_Keyscale); + argi(m, 5, "wB", sx(getfield(hi, 12, 0), 12), gfxd_Keywidth); + return 0; +} + +UCFUNC int d_DPSetKeyR(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetKeyR; + argu(m, 0, "cR", getfield(lo, 8, 8), gfxd_Color); + argu(m, 1, "sR", getfield(lo, 8, 0), gfxd_Keyscale); + argi(m, 2, "wR", sx(getfield(lo, 12, 16), 12), gfxd_Keywidth); + return 0; +} + +UCFUNC int d_DPSetPrimDepth(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetPrimDepth; + argi(m, 0, "z", sx(getfield(lo, 16, 16), 16), gfxd_Zi); + argi(m, 1, "dz", sx(getfield(lo, 16, 0), 16), gfxd_Zi); + return 0; +} + +UCFUNC int d_DPSetRenderMode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetRenderMode; + argu(m, 0, "mode1", lo, gfxd_Rm1); + argu(m, 1, "mode2", lo, gfxd_Rm2); + return 0; +} + +UCFUNC int d_DPSetScissor(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetScissor; + argi(m, 0, "mode", getfield(lo, 2, 24), gfxd_Sc); + argu(m, 1, "ulx", getfield(hi, 10, 14), gfxd_Coordi); + argu(m, 2, "uly", getfield(hi, 10, 2), gfxd_Coordi); + argu(m, 3, "lrx", getfield(lo, 10, 14), gfxd_Coordi); + argu(m, 4, "lry", getfield(lo, 10, 2), gfxd_Coordi); + return 0; +} + +UCFUNC int d_DPSetScissorFrac(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + qu102_t ulx = getfield(hi, 12, 12); + qu102_t uly = getfield(hi, 12, 0); + qu102_t lrx = getfield(lo, 12, 12); + qu102_t lry = getfield(lo, 12, 0); + if ((ulx & 3) || (uly & 3) || (lrx & 3) || (lry & 3)) + { + m->id = gfxd_DPSetScissorFrac; + argi(m, 0, "mode", getfield(lo, 2, 24), gfxd_Sc); + argu(m, 1, "ulx", ulx, gfxd_Coordq); + argu(m, 2, "uly", uly, gfxd_Coordq); + argu(m, 3, "lrx", lrx, gfxd_Coordq); + argu(m, 4, "lry", lry, gfxd_Coordq); + return 0; + } + else + return d_DPSetScissor(m, hi, lo); +} + +UCFUNC int d_DPSetTextureDetail(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetTextureDetail; + argu(m, 0, "mode", lo, gfxd_Td); + return 0; +} + +UCFUNC int d_DPSetTextureFilter(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetTextureFilter; + argu(m, 0, "mode", lo, gfxd_Tf); + return 0; +} + +UCFUNC int d_DPSetTextureLOD(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetTextureLOD; + argu(m, 0, "mode", lo, gfxd_Tl); + return 0; +} + +UCFUNC int d_DPSetTextureLUT(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetTextureLUT; + argu(m, 0, "mode", lo, gfxd_Tt); + return 0; +} + +UCFUNC int d_DPSetTexturePersp(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetTexturePersp; + argu(m, 0, "mode", lo, gfxd_Tp); + return 0; +} + +UCFUNC int d_DPSetTile(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetTile; + argi(m, 0, "fmt", getfield(hi, 3, 21), gfxd_Fmt); + argi(m, 1, "siz", getfield(hi, 2, 19), gfxd_Siz); + argi(m, 2, "line", getfield(hi, 9, 9), gfxd_Line); + argu(m, 3, "tmem", getfield(hi, 9, 0), gfxd_Tmem); + argi(m, 4, "tile", getfield(lo, 3, 24), gfxd_Tile); + argi(m, 5, "pal", getfield(lo, 4, 20), gfxd_Pal); + argu(m, 6, "cmt", getfield(lo, 2, 18), gfxd_Cm); + argi(m, 7, "maskt", getfield(lo, 4, 14), gfxd_Tm); + argi(m, 8, "shiftt", getfield(lo, 4, 10), gfxd_Ts); + argu(m, 9, "cms", getfield(lo, 2, 8), gfxd_Cm); + argi(m, 10, "masks", getfield(lo, 4, 4), gfxd_Tm); + argi(m, 11, "shifts", getfield(lo, 4, 0), gfxd_Ts); + return 0; +} + +UCFUNC int d_DPSetTileSize(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetTileSize; + argi(m, 0, "tile", getfield(lo, 3, 24), gfxd_Tile); + argu(m, 1, "uls", getfield(hi, 12, 12), gfxd_Coordq); + argu(m, 2, "ult", getfield(hi, 12, 0), gfxd_Coordq); + argu(m, 3, "lrs", getfield(lo, 12, 12), gfxd_Coordq); + argu(m, 4, "lrt", getfield(lo, 12, 0), gfxd_Coordq); + return 0; +} + +#if defined(F3D_GBI) +UCFUNC int d_SP1Triangle(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SP1Triangle; + int n0 = getfield(lo, 8, 16); + int n1 = getfield(lo, 8, 8); + int n2 = getfield(lo, 8, 0); + argi(m, 0, "v0", n0 / 10, gfxd_Vtx); + argi(m, 1, "v1", n1 / 10, gfxd_Vtx); + argi(m, 2, "v2", n2 / 10, gfxd_Vtx); + argi(m, 3, "flag", getfield(lo, 8, 24), gfxd_Vtxflag); + int ret = 0; + if (n0 % 10 != 0) + { + badarg(m, 0); + ret = -1; + } + if (n1 % 10 != 0) + { + badarg(m, 1); + ret = -1; + } + if (n2 % 10 != 0) + { + badarg(m, 2); + ret = -1; + } + return ret; +} +#elif defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +UCFUNC int d_SP1Triangle(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SP1Triangle; + int n0 = getfield(hi, 8, 16); + int n1 = getfield(hi, 8, 8); + int n2 = getfield(hi, 8, 0); + argi(m, 0, "v0", n0 / 2, gfxd_Vtx); + argi(m, 1, "v1", n1 / 2, gfxd_Vtx); + argi(m, 2, "v2", n2 / 2, gfxd_Vtx); + argi(m, 3, "flag", 0, gfxd_Vtxflag); + int ret = 0; + if (n0 % 2 != 0) + { + badarg(m, 0); + ret = -1; + } + if (n1 % 2 != 0) + { + badarg(m, 1); + ret = -1; + } + if (n2 % 2 != 0) + { + badarg(m, 2); + ret = -1; + } + return ret; +} + +UCFUNC int d_SP1Quadrangle(gfxd_macro_t *m, uint32_t hi, uint32_t lo); +UCFUNC int d_SP2Triangles(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int n00 = getfield(hi, 8, 16); + int n01 = getfield(hi, 8, 8); + int n02 = getfield(hi, 8, 0); + int n10 = getfield(lo, 8, 16); + int n11 = getfield(lo, 8, 8); + int n12 = getfield(lo, 8, 0); +#if defined(F3DEX_GBI) + if (n00 == n10 && n02 == n11) + return d_SP1Quadrangle(m, hi, lo); +#endif + m->id = gfxd_SP2Triangles; + argi(m, 0, "v00", n00 / 2, gfxd_Vtx); + argi(m, 1, "v01", n01 / 2, gfxd_Vtx); + argi(m, 2, "v02", n02 / 2, gfxd_Vtx); + argi(m, 3, "flag0", 0, gfxd_Vtxflag); + argi(m, 4, "v10", n10 / 2, gfxd_Vtx); + argi(m, 5, "v11", n11 / 2, gfxd_Vtx); + argi(m, 6, "v12", n12 / 2, gfxd_Vtx); + argi(m, 7, "flag1", 0, gfxd_Vtxflag); + int ret = 0; + if (n00 % 2 != 0) + { + badarg(m, 0); + ret = -1; + } + if (n01 % 2 != 0) + { + badarg(m, 1); + ret = -1; + } + if (n02 % 2 != 0) + { + badarg(m, 2); + ret = -1; + } + if (n10 % 2 != 0) + { + badarg(m, 4); + ret = -1; + } + if (n11 % 2 != 0) + { + badarg(m, 5); + ret = -1; + } + if (n12 % 2 != 0) + { + badarg(m, 6); + ret = -1; + } + return ret; +} + +UCFUNC int d_SP1Quadrangle(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SP1Quadrangle; + int n00 = getfield(hi, 8, 16); + int n01 = getfield(hi, 8, 8); + int n02 = getfield(hi, 8, 0); + int n10 = getfield(lo, 8, 16); + int n11 = getfield(lo, 8, 8); + int n12 = getfield(lo, 8, 0); + int v00 = n00 / 2; + int v01 = n01 / 2; + int v02 = n02 / 2; + int v10 = n10 / 2; + int v11 = n11 / 2; + int v12 = n12 / 2; + argi(m, 0, "v0", v00, gfxd_Vtx); + argi(m, 1, "v1", v01, gfxd_Vtx); + argi(m, 2, "v2", v11, gfxd_Vtx); + argi(m, 3, "v3", v12, gfxd_Vtx); + argi(m, 4, "flag", 0, gfxd_Vtxflag); + int ret = 0; + if (v00 != v10 || n00 % 2 != 0 || n10 % 2 != 0) + { + badarg(m, 0); + ret = -1; + } + if (n01 % 2 != 0) + { + badarg(m, 1); + ret = -1; + } + if (v02 != v11 || n02 % 2 != 0 || n11 % 2 != 0) + { + badarg(m, 2); + ret = -1; + } + if (n12 % 2 != 0) + { + badarg(m, 3); + ret = -1; + } + return ret; +} + +UCFUNC int c_SPBranchLessZraw(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 2) + return -1; + if (m[0].id != gfxd_DPHalf1) + return -1; + uint32_t branchdl = argvu(&m[0], 0); + if (m[1].id != gfxd_BranchZ) + return -1; + int32_t vtx = argvi(&m[1], 0); + int32_t zval = argvi(&m[1], 1); + m->id = gfxd_SPBranchLessZraw; + argu(m, 0, "dl", branchdl, gfxd_Dl); + argi(m, 1, "vtx", vtx, gfxd_Vtx); + argi(m, 2, "zval", zval, gfxd_Zraw); + return 0; +} +#endif + +UCFUNC int d_SPBranchList(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPBranchList; + argu(m, 0, "dl", lo, gfxd_Dl); + return 0; +} + +UCFUNC int c_SPClipRatio(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 4) + return -1; + if (m[0].id != gfxd_MoveWd + || argvi(&m[0], 0) != G_MW_CLIP + || argvu(&m[0], 1) != G_MWO_CLIP_RNX) + { + return -1; + } + uint32_t r = argvu(&m[0], 2); + if (m[1].id != gfxd_MoveWd + || argvi(&m[1], 0) != G_MW_CLIP + || argvu(&m[1], 1) != G_MWO_CLIP_RNY + || argvu(&m[1], 2) != r) + { + return -1; + } + if (m[2].id != gfxd_MoveWd + || argvi(&m[2], 0) != G_MW_CLIP + || argvu(&m[2], 1) != G_MWO_CLIP_RPX + || ((uint32_t)1 << 16) - argvu(&m[2], 2) != r) + { + return -1; + } + if (m[3].id != gfxd_MoveWd + || argvi(&m[3], 0) != G_MW_CLIP + || argvu(&m[3], 1) != G_MWO_CLIP_RPY + || ((uint32_t)1 << 16) - argvu(&m[3], 2) != r) + { + return -1; + } + m->id = gfxd_SPClipRatio; + argi(m, 0, "r", r, gfxd_Cr); + return 0; +} + +#if defined(F3D_GBI) +UCFUNC int d_SPCullDisplayList(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPCullDisplayList; + int n0 = getfield(hi, 24, 0); + int nn = getfield(lo, 16, 0); + argi(m, 0, "v0", n0 / 40, gfxd_Vtx); + argi(m, 1, "vn", nn / 40 - 1, gfxd_Num); + int ret = 0; + if (n0 % 40 != 0) + { + badarg(m, 0); + ret = -1; + } + if (nn % 40 != 0) + { + badarg(m, 1); + ret = -1; + } + return ret; +} +#elif defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +UCFUNC int d_SPCullDisplayList(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPCullDisplayList; + int n0 = getfield(hi, 16, 0); + int nn = getfield(lo, 16, 0); + argi(m, 0, "v0", n0 / 2, gfxd_Vtx); + argi(m, 1, "vn", nn / 2, gfxd_Num); + int ret = 0; + if (n0 % 2 != 0) + { + badarg(m, 0); + ret = -1; + } + if (nn % 2 != 0) + { + badarg(m, 1); + ret = -1; + } + return ret; +} +#endif + +UCFUNC int d_SPDisplayList(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPDisplayList; + argu(m, 0, "dl", lo, gfxd_Dl); + return 0; +} + +UCFUNC int d_SPEndDisplayList(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPEndDisplayList; + return 0; +} + +UCFUNC int d_SPFogFactor(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPFogFactor; + argi(m, 0, "fm", sx(getfield(lo, 16, 16), 16), gfxd_Fogz); + argi(m, 1, "fo", sx(getfield(lo, 16, 0), 16), gfxd_Fogz); + return 0; +} + +UCFUNC int d_SPFogPosition(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int x = sx(getfield(lo, 16, 16), 16); + int y = sx(getfield(lo, 16, 0), 16); + if (x == 0) + return d_SPFogFactor(m, hi, lo); + else + { + int d = 128000 / x; + int yd = y * d; + if (yd > 0) + yd += 255; + else if (yd < 0) + yd -= 255; + int min = 500 - yd / 256; + int max = d + min; + + if (min >= 0 && min <= 1000 && max >= 0 && max <= 1000) + { + m->id = gfxd_SPFogPosition; + argi(m, 0, "min", min, gfxd_Fogp); + argi(m, 1, "max", max, gfxd_Fogp); + return 0; + } + else + return d_SPFogFactor(m, hi, lo); + } +} + +#if defined(F3D_GBI) || defined(F3DEX_GBI) +UCFUNC int c_SPForceMatrix(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 4) + return -1; + for (int i = 0; i < 4; i++) + if (m[i].id != gfxd_MoveMem + || argvu(&m[i], 0) != 16 + || argvu(&m[i], 2) != argvu(&m[0], 2) + i * 16) + { + return -1; + } + if (argvi(&m[0], 1) != G_MV_MATRIX_1 + || argvi(&m[1], 1) != G_MV_MATRIX_2 + || argvi(&m[2], 1) != G_MV_MATRIX_3 + || argvi(&m[3], 1) != G_MV_MATRIX_4) + { + return -1; + } + uint32_t mptr = argvu(&m[0], 2); + m->id = gfxd_SPForceMatrix; + argu(m, 0, "mptr", mptr, gfxd_Mtxptr); + return 0; +} +#elif defined(F3DEX_GBI_2) +UCFUNC int c_SPForceMatrix(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 2) + return -1; + if (m[0].id != gfxd_MoveMem + || argvu(&m[0], 0) != sizeof(Mtx) + || argvi(&m[0], 1) != G_MV_MATRIX + || argvu(&m[0], 2) != 0) + { + return -1; + } + uint32_t mptr = argvu(&m[0], 3); + if (m[1].id != gfxd_MoveWd + || argvi(&m[1], 0) != G_MW_FORCEMTX + || argvu(&m[1], 1) != 0 + || argvu(&m[1], 2) != 0x10000) + { + return -1; + } + m->id = gfxd_SPForceMatrix; + argu(m, 0, "mptr", mptr, gfxd_Mtxptr); + return 0; +} +#endif + +UCFUNC int d_SPSetGeometryMode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPSetGeometryMode; + argu(m, 0, "mode", lo, gfxd_Gm); + return 0; +} + +UCFUNC int d_SPClearGeometryMode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPClearGeometryMode; +#if defined(F3D_GBI) || defined(F3DEX_GBI) + argu(m, 0, "mode", lo, gfxd_Gm); +#elif defined(F3DEX_GBI_2) + argu(m, 0, "mode", getfield(~hi, 24, 0), gfxd_Gm); +#endif + return 0; +} + +#if defined(F3D_GBI) || defined(F3DEX_GBI) +UCFUNC int c_SPLoadGeometryMode(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 2) + return -1; + if (m[0].id != gfxd_SPClearGeometryMode + || argvu(&m[0], 0) != 0xFFFFFFFF + || m[1].id != gfxd_SPSetGeometryMode) + { + return -1; + } + uint32_t mode = argvu(&m[1], 0); + m->id = gfxd_SPLoadGeometryMode; + argu(m, 0, "mode", mode, gfxd_Gm); + return 0; +} +#elif defined(F3DEX_GBI_2) +UCFUNC int d_SPLoadGeometryMode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPLoadGeometryMode; + argu(m, 0, "mode", lo, gfxd_Gm); + return 0; +} +#endif + +#if defined(F3D_GBI) || defined(F3DEX_GBI) +UCFUNC int d_SPInsertMatrix(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPInsertMatrix; + argu(m, 0, "where", getfield(hi, 16, 8), gfxd_Mwo_matrix); + argu(m, 1, "val", lo, gfxd_Word); + return 0; +} +#endif + +#if defined(F3D_GBI) +UCFUNC int d_SPLine3D(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPLine3D; + int n0 = getfield(lo, 8, 16); + int n1 = getfield(lo, 8, 8); + argi(m, 0, "v0", n0 / 10, gfxd_Vtx); + argi(m, 1, "v1", n1 / 10, gfxd_Vtx); + argi(m, 2, "flag", getfield(lo, 8, 24), gfxd_Vtxflag); + int ret = 0; + if (n0 % 10 != 0) + { + badarg(m, 0); + ret = -1; + } + if (n1 % 10 != 0) + { + badarg(m, 1); + ret = -1; + } + return ret; +} +#elif defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +UCFUNC int d_SPLine3D(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPLine3D; + int n0 = getfield(hi, 8, 16); + int n1 = getfield(hi, 8, 8); + argi(m, 0, "v0", n0 / 2, gfxd_Vtx); + argi(m, 1, "v1", n1 / 2, gfxd_Vtx); + argi(m, 2, "flag", 0, gfxd_Vtxflag); + int ret = 0; + if (n0 % 2 != 0) + { + badarg(m, 0); + ret = -1; + } + if (n1 % 2 != 0) + { + badarg(m, 1); + ret = -1; + } + return ret; +} +#endif + +#if defined(F3D_GBI) +UCFUNC int d_SPLineW3D(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int wd = getfield(lo, 8, 0); + if (wd == 0) + return d_SPLine3D(m, hi, lo); + else + { + m->id = gfxd_SPLineW3D; + int n0 = getfield(lo, 8, 16); + int n1 = getfield(lo, 8, 8); + argi(m, 0, "v0", n0 / 10, gfxd_Vtx); + argi(m, 1, "v1", n1 / 10, gfxd_Vtx); + argi(m, 2, "wd", wd, gfxd_Linewd); + argi(m, 3, "flag", getfield(lo, 8, 24), gfxd_Vtxflag); + int ret = 0; + if (n0 % 10 != 0) + { + badarg(m, 0); + ret = -1; + } + if (n1 % 10 != 0) + { + badarg(m, 1); + ret = -1; + } + return ret; + } +} +#elif defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +UCFUNC int d_SPLineW3D(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int wd = getfield(hi, 8, 0); + if (wd == 0) + return d_SPLine3D(m, hi, lo); + else + { + m->id = gfxd_SPLineW3D; + int n0 = getfield(hi, 8, 16); + int n1 = getfield(hi, 8, 8); + argi(m, 0, "v0", n0 / 2, gfxd_Vtx); + argi(m, 1, "v1", n1 / 2, gfxd_Vtx); + argi(m, 2, "wd", wd, gfxd_Linewd); + argi(m, 3, "flag", 0, gfxd_Vtxflag); + int ret = 0; + if (n0 % 2 != 0) + { + badarg(m, 0); + ret = -1; + } + if (n1 % 2 != 0) + { + badarg(m, 1); + ret = -1; + } + return ret; + } +} +#endif + +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +UCFUNC int c_SPLoadUcode(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 2) + return -1; + if (m[0].id != gfxd_DPHalf1) + return -1; + uint32_t uc_dstart = argvu(&m[0], 0); + if (m[1].id != gfxd_LoadUcode) + return -1; + uint32_t uc_start = argvu(&m[1], 0); + uint32_t uc_dsize = argvu(&m[1], 1); + if (uc_dsize != 0x800) + return -1; + m->id = gfxd_SPLoadUcode; + argu(m, 0, "uc_start", uc_start, gfxd_Uctext); + argu(m, 1, "uc_dstart", uc_dstart, gfxd_Ucdata); + return 0; +} +#endif + +UCFUNC int d_SPLookAtX(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPLookAtX; + argu(m, 0, "l", lo, gfxd_Lookatptr); + return 0; +} + +UCFUNC int d_SPLookAtY(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPLookAtY; + argu(m, 0, "l", lo, gfxd_Lookatptr); + return 0; +} + +UCFUNC int c_SPLookAt(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 2) + return -1; + if (m[0].id != gfxd_SPLookAtX) + return -1; + uint32_t l = argvu(&m[0], 0); + if (m[1].id != gfxd_SPLookAtY || argvu(&m[1], 0) != l + 0x10) + return -1; + m->id = gfxd_SPLookAt; + argu(m, 0, "l", l, gfxd_Lookatptr); + return 0; +} + +#if defined(F3D_GBI) || defined(F3DEX_GBI) +UCFUNC int d_SPMatrix(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPMatrix; + int x = getfield(hi, 16, 0); + argu(m, 0, "matrix", lo, gfxd_Mtxptr); + argi(m, 1, "param", getfield(hi, 8, 16), gfxd_Mtxparam); + if (x != sizeof(Mtx)) + return -1; + else + return 0; +} +#elif defined(F3DEX_GBI_2) +UCFUNC int d_SPMatrix(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPMatrix; + int x = getfield(hi, 5, 19); + argu(m, 0, "matrix", lo, gfxd_Mtxptr); + argi(m, 1, "param", getfield(hi, 8, 0) ^ G_MTX_PUSH, gfxd_Mtxparam); + if (x != (sizeof(Mtx) - 1) / 8) + return -1; + else + return 0; +} +#endif + +#if defined(F3D_GBI) || (defined(F3D_BETA) && defined(F3DEX_GBI)) +UCFUNC int d_SPModifyVertex(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPModifyVertex; + int offset = getfield(hi, 16, 8); + argi(m, 0, "vtx", offset / 40, gfxd_Vtx); + argu(m, 1, "where", offset % 40, gfxd_Mwo_point); + argu(m, 2, "val", lo, gfxd_Word); + return 0; +} +#elif defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +UCFUNC int d_SPModifyVertex(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPModifyVertex; + int vtx = getfield(hi, 16, 0); + argi(m, 0, "vtx", vtx / 2, gfxd_Vtx); + argu(m, 1, "where", getfield(hi, 8, 16), gfxd_Mwo_point); + argu(m, 2, "val", lo, gfxd_Word); + int ret = 0; + if (vtx % 2 != 0) + { + badarg(m, 0); + ret = -1; + } + return ret; +} +#endif + +UCFUNC int d_SPPerspNormalize(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPPerspNormalize; + argu(m, 0, "scale", getfield(lo, 16, 0), gfxd_Wscale); + return 0; +} + +UCFUNC int d_SPPopMatrix(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPPopMatrix; +#if defined(F3D_GBI) || defined(F3DEX_GBI) + argi(m, 0, "param", lo, gfxd_Mtxstack); +#elif defined(F3DEX_GBI_2) + argi(m, 0, "param", G_MTX_MODELVIEW, gfxd_Mtxstack); +#endif + return 0; +} + +#if defined(F3DEX_GBI_2) +UCFUNC int d_SPPopMatrixN(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int len = (getfield(hi, 5, 19) + 1) * 8; + int ofs = getfield(hi, 8, 8) * 8; + int idx = getfield(hi, 8, 0); + int n = lo / sizeof(Mtx); + if (lo % sizeof(Mtx) == 0 + && len == sizeof(Mtx) + && ofs == 0 + && idx == 2 + && n == 1) + { + return d_SPPopMatrix(m, hi, lo); + } + m->id = gfxd_SPPopMatrixN; + argi(m, 0, "param", G_MTX_MODELVIEW, gfxd_Mtxstack); + argi(m, 1, "num", n, gfxd_Num); + int ret = 0; + if (lo % sizeof(Mtx) != 0) + { + badarg(m, 1); + ret = -1; + } + if (len != sizeof(Mtx) || ofs != 0 || idx != 2) + ret = -1; + return ret; +} +#endif + +UCFUNC int d_SPSegment(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPSegment; +#if defined(F3D_GBI) || defined(F3DEX_GBI) + int offset = getfield(hi, 16, 8); +#elif defined(F3DEX_GBI_2) + int offset = getfield(hi, 16, 0); +#endif + argu(m, 0, "seg", offset / 4, gfxd_Seg); + argu(m, 1, "base", lo, gfxd_Segptr); + int ret = 0; + if (offset % 4 != 0) + { + badarg(m, 0); + ret = -1; + } + return ret; +} + +UCFUNC int c_SPSetLightsN(gfxd_macro_t *m, int n_macro, int id, int numlights) +{ + if (n_macro < 2 + numlights) + return -1; + if (m[0].id != gfxd_SPNumLights || argvi(&m[0], 0) != numlights) + return -1; + int a = 1 + numlights; + if (m[a].id != gfxd_SPLight || argvi(&m[a], 1) != a) + return -1; + uint32_t l = argvu(&m[a], 0); + for (int i = 1; i <= numlights; i++) + { + int offset = sizeof(Ambient) + sizeof(Light) * (i - 1); + if (m[i].id != gfxd_SPLight + || argvu(&m[i], 0) != l + offset + || argvi(&m[i], 1) != i) + { + return -1; + } + } + m->id = id; + argu(m, 0, "l", l, gfxd_Lightsn); + return 0; +} + +UCFUNC int c_SPSetLights1(gfxd_macro_t *m, int n_macro) +{ + return c_SPSetLightsN(m, n_macro, gfxd_SPSetLights1, NUMLIGHTS_1); +} + +UCFUNC int c_SPSetLights2(gfxd_macro_t *m, int n_macro) +{ + return c_SPSetLightsN(m, n_macro, gfxd_SPSetLights2, NUMLIGHTS_2); +} + +UCFUNC int c_SPSetLights3(gfxd_macro_t *m, int n_macro) +{ + return c_SPSetLightsN(m, n_macro, gfxd_SPSetLights3, NUMLIGHTS_3); +} + +UCFUNC int c_SPSetLights4(gfxd_macro_t *m, int n_macro) +{ + return c_SPSetLightsN(m, n_macro, gfxd_SPSetLights4, NUMLIGHTS_4); +} + +UCFUNC int c_SPSetLights5(gfxd_macro_t *m, int n_macro) +{ + return c_SPSetLightsN(m, n_macro, gfxd_SPSetLights5, NUMLIGHTS_5); +} + +UCFUNC int c_SPSetLights6(gfxd_macro_t *m, int n_macro) +{ + return c_SPSetLightsN(m, n_macro, gfxd_SPSetLights6, NUMLIGHTS_6); +} + +UCFUNC int c_SPSetLights7(gfxd_macro_t *m, int n_macro) +{ + return c_SPSetLightsN(m, n_macro, gfxd_SPSetLights7, NUMLIGHTS_7); +} + +#if defined(F3D_GBI) || defined(F3DEX_GBI) +UCFUNC int d_SPNumLights(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPNumLights; + argi(m, 0, "n", (lo - 0x80000000) / 32 - 1, gfxd_Numlights); + int ret = 0; + if (lo < 0x80000040 || lo % 32 != 0) + { + badarg(m, 0); + ret = -1; + } + return ret; +} +#elif defined(F3DEX_GBI_2) +UCFUNC int d_SPNumLights(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPNumLights; + argi(m, 0, "n", lo / 24, gfxd_Numlights); + int ret = 0; + if (lo < 24 || lo % 24 != 0) + { + badarg(m, 0); + ret = -1; + } + return ret; +} +#endif + +#if defined(F3D_GBI) || defined(F3DEX_GBI) +UCFUNC int d_SPLight(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int n = (getfield(hi, 8, 16) - G_MV_L0) / 2 + 1; + m->id = gfxd_SPLight; + argu(m, 0, "l", lo, gfxd_Lightptr); + argi(m, 1, "n", n, gfxd_Num); + return 0; +} +#elif defined(F3DEX_GBI_2) +UCFUNC int d_SPLight(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int n = (getfield(hi, 8, 8) * 8 / 24) - 1; + m->id = gfxd_SPLight; + argu(m, 0, "l", lo, gfxd_Lightptr); + argi(m, 1, "n", n, gfxd_Num); + return 0; +} +#endif + +UCFUNC int c_SPLightColor(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 2) + return -1; + if (m[0].id != gfxd_MoveWd + || argvi(&m[0], 0) != G_MW_LIGHTCOL + || argvu(&m[0], 1) % 0x18 != 0 + || argvu(&m[0], 1) > G_MWO_aLIGHT_8) + { + return -1; + } + uint32_t offset = argvu(&m[0], 1); + uint32_t packedcolor = argvu(&m[0], 2); + if (m[1].id != gfxd_MoveWd + || argvi(&m[1], 0) != G_MW_LIGHTCOL + || argvu(&m[1], 1) != offset + 4 + || argvu(&m[1], 2) != packedcolor) + { + return -1; + } + m->id = gfxd_SPLightColor; + argi(m, 0, "n", offset / 0x18 + 1, gfxd_Lightnum); + argu(m, 1, "c", packedcolor, gfxd_Color); + return 0; +} + +UCFUNC int d_SPTexture(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPTexture; + argu(m, 0, "sc", getfield(lo, 16, 16), gfxd_Tcscale); + argu(m, 1, "tc", getfield(lo, 16, 0), gfxd_Tcscale); + argi(m, 2, "level", getfield(hi, 3, 11), gfxd_Num); + argi(m, 3, "tile", getfield(hi, 3, 8), gfxd_Tile); +#if defined(F3D_GBI) || defined(F3DEX_GBI) + argi(m, 4, "on", getfield(hi, 8, 0), gfxd_Switch); +#elif defined(F3DEX_GBI_2) + argi(m, 4, "on", getfield(hi, 7, 1), gfxd_Switch); +#endif + return 0; +} + +UCFUNC int c_SPTextureRectangle(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 3) + return -1; + if (m[0].id != gfxd_TexRect) + return -1; + qu102_t ulx = argvu(&m[0], 0); + qu102_t uly = argvu(&m[0], 1); + qu102_t lrx = argvu(&m[0], 2); + qu102_t lry = argvu(&m[0], 3); + int tile = argvi(&m[0], 4); + if (m[1].id != gfxd_DPHalf1) + return -1; + qs105_t s = sx(getfield(argvu(&m[1], 0), 16, 16), 16); + qs105_t t = sx(getfield(argvu(&m[1], 0), 16, 0), 16); + if (m[2].id != gfxd_DPHalf2) + return -1; + qs510_t dsdx = sx(getfield(argvu(&m[2], 0), 16, 16), 16); + qs510_t dtdy = sx(getfield(argvu(&m[2], 0), 16, 0), 16); + m->id = gfxd_SPTextureRectangle; + argu(m, 0, "ulx", ulx, gfxd_Coordq); + argu(m, 1, "uly", uly, gfxd_Coordq); + argu(m, 2, "lrx", lrx, gfxd_Coordq); + argu(m, 3, "lry", lry, gfxd_Coordq); + argi(m, 4, "tile", tile, gfxd_Tile); + argi(m, 5, "s", s, gfxd_St); + argi(m, 6, "t", t, gfxd_St); + argi(m, 7, "dsdx", dsdx, gfxd_Stdelta); + argi(m, 8, "dtdy", dtdy, gfxd_Stdelta); + return 0; +} + +UCFUNC int c_SPTextureRectangleFlip(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 3) + return -1; + if (m[0].id != gfxd_TexRectFlip) + return -1; + qu102_t ulx = argvu(&m[0], 0); + qu102_t uly = argvu(&m[0], 1); + qu102_t lrx = argvu(&m[0], 2); + qu102_t lry = argvu(&m[0], 3); + int tile = argvi(&m[0], 4); + if (m[1].id != gfxd_DPHalf1) + return -1; + qs105_t s = sx(getfield(argvu(&m[1], 0), 16, 16), 16); + qs105_t t = sx(getfield(argvu(&m[1], 0), 16, 0), 16); + if (m[2].id != gfxd_DPHalf2) + return -1; + qs510_t dsdx = sx(getfield(argvu(&m[2], 0), 16, 16), 16); + qs510_t dtdy = sx(getfield(argvu(&m[2], 0), 16, 0), 16); + m->id = gfxd_SPTextureRectangleFlip; + argu(m, 0, "ulx", ulx, gfxd_Coordq); + argu(m, 1, "uly", uly, gfxd_Coordq); + argu(m, 2, "lrx", lrx, gfxd_Coordq); + argu(m, 3, "lry", lry, gfxd_Coordq); + argi(m, 4, "tile", tile, gfxd_Tile); + argi(m, 5, "s", s, gfxd_St); + argi(m, 6, "t", t, gfxd_St); + argi(m, 7, "dsdx", dsdx, gfxd_Stdelta); + argi(m, 8, "dtdy", dtdy, gfxd_Stdelta); + return 0; +} + +#if defined(F3D_GBI) +UCFUNC int d_SPVertex(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPVertex; + int n = getfield(hi, 4, 20) + 1; + int v0 = getfield(hi, 4, 16); + int size = getfield(hi, 16, 0); + argu(m, 0, "v", lo, gfxd_Vtxptr); + argi(m, 1, "n", n, gfxd_Num); + argi(m, 2, "v0", v0, gfxd_Vtx); + int ret = 0; + if (size != sizeof(Vtx) * n) + { + badarg(m, 1); + ret = -1; + } + return ret; +} +#elif defined(F3DEX_GBI) +UCFUNC int d_SPVertex(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPVertex; + int n = getfield(hi, 6, 10); + int v0 = getfield(hi, 8, 16); + int size = getfield(hi, 10, 0); + argu(m, 0, "v", lo, gfxd_Vtxptr); + argi(m, 1, "n", n, gfxd_Num); + argi(m, 2, "v0", v0 / 2, gfxd_Vtx); + int ret = 0; + if (size != sizeof(Vtx) * n - 1) + { + badarg(m, 1); + ret = -1; + } + if (v0 % 2 != 0) + { + badarg(m, 2); + ret = -1; + } + return ret; +} +#elif defined(F3DEX_GBI_2) +UCFUNC int d_SPVertex(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPVertex; + int n = getfield(hi, 8, 12); + int v0 = getfield(hi, 7, 1) - n; + argu(m, 0, "v", lo, gfxd_Vtxptr); + argi(m, 1, "n", n, gfxd_Num); + argi(m, 2, "v0", v0, gfxd_Vtx); + return 0; +} +#endif + +UCFUNC int d_SPViewport(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPViewport; + argu(m, 0, "v", lo, gfxd_Vpptr); + return 0; +} + +UCFUNC int d_DPLoadTLUTCmd(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPLoadTLUTCmd; + argi(m, 0, "tile", getfield(lo, 3, 24), gfxd_Tile); + argi(m, 1, "count", getfield(lo, 10, 14), gfxd_Num); + return 0; +} + +UCFUNC int c_DPLoadTLUT(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 6) + return -1; + if (m[0].id != gfxd_DPSetTextureImage + || argvi(&m[0], 0) != G_IM_FMT_RGBA + || argvi(&m[0], 1) != G_IM_SIZ_16b + || argvi(&m[0], 2) != 1) + { + return -1; + } + uint32_t dram = argvu(&m[0], 3); + if (m[1].id != gfxd_DPTileSync) + return -1; + if (m[2].id != gfxd_DPSetTile + || argvi(&m[2], 0) != 0 + || argvi(&m[2], 1) != 0 + || argvi(&m[2], 2) != 0 + || argvi(&m[2], 4) != G_TX_LOADTILE + || argvi(&m[2], 5) != 0 + || argvu(&m[2], 6) != 0 + || argvi(&m[2], 7) != 0 + || argvi(&m[2], 8) != 0 + || argvu(&m[2], 9) != 0 + || argvi(&m[2], 10) != 0 + || argvi(&m[2], 11) != 0) + { + return -1; + } + uint32_t tmem = argvu(&m[2], 3); + if (m[3].id != gfxd_DPLoadSync) + return -1; + if (m[4].id != gfxd_DPLoadTLUTCmd || argvi(&m[4], 0) != G_TX_LOADTILE) + return -1; + int count = argvi(&m[4], 1) + 1; + if (m[5].id != gfxd_DPPipeSync) + return -1; + m->id = gfxd_DPLoadTLUT; + argi(m, 0, "count", count, gfxd_Num); + argu(m, 1, "tmem", tmem, gfxd_Tmem); + argu(m, 2, "dram", dram, gfxd_Tlut); + return 0; +} + +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +UCFUNC int d_BranchZ(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_BranchZ; + int na = getfield(hi, 12, 12); + int nb = getfield(hi, 12, 0); + int32_t zval; + if (lo > 0x7FFFFFFF) + zval = -0x80000000 + (int32_t)(lo & 0x7FFFFFFF); + else + zval = lo; + argi(m, 0, "vtx", nb / 2, gfxd_Vtx); + argi(m, 1, "zval", zval, gfxd_Zraw); + int ret = 0; + if (nb % 2 != 0 || na / 5 != nb / 2 || na % 5 != 0) + { + badarg(m, 0); + ret = -1; + } + return ret; +} +#endif + +UCFUNC int d_DisplayList(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int flag = getfield(hi, 8, 16); + if (flag == 0) + return d_SPDisplayList(m, hi, lo); + else if (flag == 1) + return d_SPBranchList(m, hi, lo); + else + { + m->id = gfxd_DisplayList; + argu(m, 0, "dl", lo, gfxd_Dl); + argi(m, 1, "flag", flag, gfxd_Dlflag); + return 0; + } +} + +UCFUNC int d_DPHalf1(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPHalf1; + argu(m, 0, "hi", lo, gfxd_Word); + return 0; +} + +UCFUNC int d_DPHalf2(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPHalf2; + argu(m, 0, "lo", lo, gfxd_Word); + return 0; +} + +UCFUNC int c_DPWord(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 2) + return -1; + if (m[0].id != gfxd_DPHalf1 || m[1].id != gfxd_DPHalf2) + return -1; + uint32_t wordhi = argvu(&m[0], 0); + uint32_t wordlo = argvu(&m[1], 0); + m->id = gfxd_DPWord; + argu(m, 0, "wordhi", wordhi, gfxd_Word); + argu(m, 1, "wordlo", wordlo, gfxd_Word); + return 0; +} + +UCFUNC int d_DPLoadTile(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPLoadTile; + argi(m, 0, "tile", getfield(lo, 3, 24), gfxd_Tile); + argu(m, 1, "uls", getfield(hi, 12, 12), gfxd_Coordq); + argu(m, 2, "ult", getfield(hi, 12, 0), gfxd_Coordq); + argu(m, 3, "lrs", getfield(lo, 12, 12), gfxd_Coordq); + argu(m, 4, "lrt", getfield(lo, 12, 0), gfxd_Coordq); + return 0; +} + +#if defined(F3DEX_GBI_2) +UCFUNC int d_SPGeometryMode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + uint32_t clearbits = getfield(~hi, 24, 0); + uint32_t setbits = lo; + if (clearbits == 0 && setbits != 0) + return d_SPSetGeometryMode(m, hi, lo); + else if (clearbits != 0 && setbits == 0) + return d_SPClearGeometryMode(m, hi, lo); + else if (clearbits == 0x00FFFFFF) + return d_SPLoadGeometryMode(m, hi, lo); + else + { + m->id = gfxd_SPGeometryMode; + argu(m, 0, "c", clearbits, gfxd_Gm); + argu(m, 1, "s", setbits, gfxd_Gm); + return 0; + } +} +#endif + +UCFUNC int d_SPSetOtherMode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPSetOtherMode; + int opc = getfield(hi, 8, 24); +#if defined(F3D_GBI) || defined(F3DEX_GBI) + int length = getfield(hi, 8, 0); + int shift = getfield(hi, 8, 8); +#elif defined(F3DEX_GBI_2) + int length = getfield(hi, 8, 0) + 1; + int shift = 32 - (getfield(hi, 8, 8) + length); +#endif + argi(m, 0, "opc", opc, gfxd_Opcode); + argi(m, 1, "sft", shift, gfxd_Sftlo); + argi(m, 2, "len", length, gfxd_Num); + if (opc == G_SETOTHERMODE_H) + argu(m, 3, "mode", lo, gfxd_Othermodehi); + else if (opc == G_SETOTHERMODE_L) + argu(m, 3, "mode", lo, gfxd_Othermodelo); + else + argu(m, 3, "mode", lo, gfxd_Word); + return 0; +} + +UCFUNC int d_SPSetOtherModeLo(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ +#if defined(F3D_GBI) || defined(F3DEX_GBI) + int length = getfield(hi, 8, 0); + int shift = getfield(hi, 8, 8); +#elif defined(F3DEX_GBI_2) + int length = getfield(hi, 8, 0) + 1; + int shift = 32 - (getfield(hi, 8, 8) + length); +#endif + if (shift == G_MDSFT_ALPHACOMPARE && length == G_MDSIZ_ALPHACOMPARE) + return d_DPSetAlphaCompare(m, hi, lo); + else if (shift == G_MDSFT_ZSRCSEL && length == G_MDSIZ_ZSRCSEL) + return d_DPSetDepthSource(m, hi, lo); + else if (shift == G_MDSFT_RENDERMODE && length == G_MDSIZ_RENDERMODE) + return d_DPSetRenderMode(m, hi, lo); + else if (config.emit_ext_macro) + { + m->id = gfxd_SPSetOtherModeLo; + argi(m, 0, "sft", shift, gfxd_Sftlo); + argi(m, 1, "len", length, gfxd_Num); + argu(m, 2, "mode", lo, gfxd_Othermodelo); + return 0; + } + else + return d_SPSetOtherMode(m, hi, lo); +} + +UCFUNC int d_SPSetOtherModeHi(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ +#if defined(F3D_GBI) || defined(F3DEX_GBI) + int length = getfield(hi, 8, 0); + int shift = getfield(hi, 8, 8); +#elif defined(F3DEX_GBI_2) + int length = getfield(hi, 8, 0) + 1; + int shift = 32 - (getfield(hi, 8, 8) + length); +#endif + if (shift == G_MDSFT_ALPHADITHER && length == G_MDSIZ_ALPHADITHER) + return d_DPSetAlphaDither(m, hi, lo); + else if (shift == G_MDSFT_RGBDITHER && length == G_MDSIZ_RGBDITHER) + return d_DPSetColorDither(m, hi, lo); + else if (shift == G_MDSFT_COMBKEY && length == G_MDSIZ_COMBKEY) + return d_DPSetCombineKey(m, hi, lo); + else if (shift == G_MDSFT_TEXTCONV && length == G_MDSIZ_TEXTCONV) + return d_DPSetTextureConvert(m, hi, lo); + else if (shift == G_MDSFT_TEXTFILT && length == G_MDSIZ_TEXTFILT) + return d_DPSetTextureFilter(m, hi, lo); + else if (shift == G_MDSFT_TEXTLUT && length == G_MDSIZ_TEXTLUT) + return d_DPSetTextureLUT(m, hi, lo); + else if (shift == G_MDSFT_TEXTLOD && length == G_MDSIZ_TEXTLOD) + return d_DPSetTextureLOD(m, hi, lo); + else if (shift == G_MDSFT_TEXTDETAIL && length == G_MDSIZ_TEXTDETAIL) + return d_DPSetTextureDetail(m, hi, lo); + else if (shift == G_MDSFT_TEXTPERSP && length == G_MDSIZ_TEXTPERSP) + return d_DPSetTexturePersp(m, hi, lo); + else if (shift == G_MDSFT_CYCLETYPE && length == G_MDSIZ_CYCLETYPE) + return d_DPSetCycleType(m, hi, lo); + else if (shift == G_MDSFT_PIPELINE && length == G_MDSIZ_PIPELINE) + return d_DPPipelineMode(m, hi, lo); + else if (config.emit_ext_macro) + { + m->id = gfxd_SPSetOtherModeHi; + argi(m, 0, "sft", shift, gfxd_Sfthi); + argi(m, 1, "len", length, gfxd_Num); + argu(m, 2, "mode", lo, gfxd_Othermodehi); + return 0; + } + else + return d_SPSetOtherMode(m, hi, lo); +} + +UCFUNC int d_DPSetOtherMode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_DPSetOtherMode; + argu(m, 0, "hi", getfield(hi, 24, 0), gfxd_Othermodehi); + argu(m, 1, "lo", lo, gfxd_Othermodelo); + return 0; +} + +UCFUNC int d_MoveWd(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ +#if defined(F3D_GBI) || defined(F3DEX_GBI) + int index = getfield(hi, 8, 0); + int offset = getfield(hi, 16, 8); +#elif defined(F3DEX_GBI_2) + int index = getfield(hi, 8, 16); + int offset = getfield(hi, 16, 0); +#endif + if (index == G_MW_FOG && offset == G_MWO_FOG) + return d_SPFogPosition(m, hi, lo); +#if !(defined(F3D_BETA) && (defined(F3D_GBI) || defined(F3DEX_GBI))) + else if (index == G_MW_PERSPNORM && offset == 0) + return d_SPPerspNormalize(m, hi, lo); +#endif + else if (index == G_MW_SEGMENT) + return d_SPSegment(m, hi, lo); + else if (index == G_MW_NUMLIGHT && offset == G_MWO_NUMLIGHT) + return d_SPNumLights(m, hi, lo); +#if defined(F3D_GBI) || (defined(F3D_BETA) && defined(F3DEX_GBI)) + else if (index == G_MW_POINTS) + return d_SPModifyVertex(m, hi, lo); +#endif +#if defined(F3D_GBI) || defined(F3DEX_GBI) + else if (index == G_MW_MATRIX) + return d_SPInsertMatrix(m, hi, lo); +#endif + else + { + m->id = gfxd_MoveWd; + argi(m, 0, "index", index, gfxd_Mw); + if (index == G_MW_MATRIX) + argu(m, 1, "offset", offset, gfxd_Mwo_matrix); + else if (index == G_MW_CLIP) + argu(m, 1, "offset", offset, gfxd_Mwo_clip); + else if (index == G_MW_LIGHTCOL) + argu(m, 1, "offset", offset, gfxd_Mwo_lightcol); + else + argu(m, 1, "offset", offset, gfxd_Mwo); + argu(m, 2, "value", lo, gfxd_Word); + } + return 0; +} + +#if defined(F3D_GBI) || defined(F3DEX_GBI) +UCFUNC int d_MoveMem(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int size = getfield(hi, 16, 0); + int index = getfield(hi, 8, 16); + if (size == sizeof(Light) + && index >= G_MV_L0 + && index <= G_MV_L7 + && index % 2 == 0) + { + return d_SPLight(m, hi, lo); + } + else if (size == sizeof(Light) && index == G_MV_LOOKATX) + return d_SPLookAtX(m, hi, lo); + else if (size == sizeof(Light) && index == G_MV_LOOKATY) + return d_SPLookAtY(m, hi, lo); + else if (size == sizeof(Vp) && index == G_MV_VIEWPORT) + return d_SPViewport(m, hi, lo); + else + { + m->id = gfxd_MoveMem; + argu(m, 0, "size", size, gfxd_Size); + argi(m, 1, "index", index, gfxd_Mv); + argu(m, 2, "dram", lo, gfxd_Dram); + return 0; + } +} +#elif defined(F3DEX_GBI_2) +UCFUNC int d_MoveMem(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int size = (getfield(hi, 5, 19) + 1) * 8; + int index = getfield(hi, 8, 0); + int offset = getfield(hi, 8, 8) * 8; + if (size == sizeof(Light) + && index == G_MV_LIGHT + && offset >= G_MVO_L0 + && offset <= G_MVO_L7 + && offset % 0x18 == 0) + { + return d_SPLight(m, hi, lo); + } + else if (size == sizeof(Light) + && index == G_MV_LIGHT + && offset == G_MVO_LOOKATX) + { + return d_SPLookAtX(m, hi, lo); + } + else if (size == sizeof(Light) + && index == G_MV_LIGHT + && offset == G_MVO_LOOKATY) + { + return d_SPLookAtY(m, hi, lo); + } + else if (size == sizeof(Vp) + && index == G_MV_VIEWPORT + && offset == 0) + { + return d_SPViewport(m, hi, lo); + } + else + { + m->id = gfxd_MoveMem; + argu(m, 0, "size", size, gfxd_Size); + argi(m, 1, "index", index, gfxd_Mv); + argu(m, 2, "offset", offset, gfxd_Size); + argu(m, 3, "dram", lo, gfxd_Dram); + return 0; + } +} +#endif + +#if defined(F3DEX_GBI_2) +UCFUNC int d_SPDmaRead(gfxd_macro_t *m, uint32_t hi, uint32_t lo); +UCFUNC int d_SPDmaWrite(gfxd_macro_t *m, uint32_t hi, uint32_t lo); +UCFUNC int d_SPDma_io(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + int flag = getfield(hi, 1, 23); + if (flag == 0) + return d_SPDmaRead(m, hi, lo); + else if (flag == 1) + return d_SPDmaWrite(m, hi, lo); + else + { + m->id = gfxd_SPDma_io; + argi(m, 0, "flag", flag, gfxd_Dmaflag); + argu(m, 1, "dmem", getfield(hi, 10, 13) * 8, gfxd_Dmem); + argu(m, 2, "dram", lo, gfxd_Dram); + argu(m, 3, "size", getfield(hi, 12, 10) + 1, gfxd_Size); + return 0; + } +} + +UCFUNC int d_SPDmaRead(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPDmaRead; + argu(m, 0, "dmem", getfield(hi, 10, 13) * 8, gfxd_Dmem); + argu(m, 1, "dram", lo, gfxd_Dram); + argu(m, 2, "size", getfield(hi, 12, 10) + 1, gfxd_Size); + return 0; +} + +UCFUNC int d_SPDmaWrite(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPDmaWrite; + argu(m, 0, "dmem", getfield(hi, 10, 13) * 8, gfxd_Dmem); + argu(m, 1, "dram", lo, gfxd_Dram); + argu(m, 2, "size", getfield(hi, 12, 10) + 1, gfxd_Size); + return 0; +} +#endif + +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) +UCFUNC int d_LoadUcode(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_LoadUcode; + argu(m, 0, "uc_start", lo, gfxd_Uctext); + argu(m, 1, "uc_dsize", getfield(hi, 16, 0) + 1, gfxd_Size); + return 0; +} + +UCFUNC int c_SPLoadUcodeEx(gfxd_macro_t *m, int n_macro) +{ + if (n_macro < 2) + return -1; + if (m[0].id != gfxd_DPHalf1) + return -1; + uint32_t uc_dstart = argvu(&m[0], 0); + if (m[1].id != gfxd_LoadUcode) + return -1; + uint32_t uc_start = argvu(&m[1], 0); + uint32_t uc_dsize = argvu(&m[1], 1); + m->id = gfxd_SPLoadUcodeEx; + argu(m, 0, "uc_start", uc_start, gfxd_Uctext); + argu(m, 1, "uc_dstart", uc_dstart, gfxd_Ucdata); + argu(m, 2, "uc_dsize", uc_dsize, gfxd_Size); + return 0; +} +#endif + +UCFUNC int d_TexRect(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_TexRect; + argu(m, 0, "ulx", getfield(lo, 12, 12), gfxd_Coordq); + argu(m, 1, "uly", getfield(lo, 12, 0), gfxd_Coordq); + argu(m, 2, "lrx", getfield(hi, 12, 12), gfxd_Coordq); + argu(m, 3, "lry", getfield(hi, 12, 0), gfxd_Coordq); + argi(m, 4, "tile", getfield(lo, 3, 24), gfxd_Tile); + return 0; +} + +UCFUNC int d_TexRectFlip(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_TexRectFlip; + argu(m, 0, "ulx", getfield(lo, 12, 12), gfxd_Coordq); + argu(m, 1, "uly", getfield(lo, 12, 0), gfxd_Coordq); + argu(m, 2, "lrx", getfield(hi, 12, 12), gfxd_Coordq); + argu(m, 3, "lry", getfield(hi, 12, 0), gfxd_Coordq); + argi(m, 4, "tile", getfield(lo, 3, 24), gfxd_Tile); + return 0; +} + +UCFUNC int d_SPNoOp(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_SPNoOp; + return 0; +} + +#if defined(F3DEX_GBI_2) +UCFUNC int d_Special3(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_Special3; + argu(m, 0, "hi", getfield(hi, 24, 0), gfxd_Word); + argu(m, 1, "lo", lo, gfxd_Word); + return 0; +} + +UCFUNC int d_Special2(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_Special2; + argu(m, 0, "hi", getfield(hi, 24, 0), gfxd_Word); + argu(m, 1, "lo", lo, gfxd_Word); + return 0; +} + +UCFUNC int d_Special1(gfxd_macro_t *m, uint32_t hi, uint32_t lo) +{ + m->id = gfxd_Special1; + argu(m, 0, "hi", getfield(hi, 24, 0), gfxd_Word); + argu(m, 1, "lo", lo, gfxd_Word); + return 0; +} +#endif diff --git a/tools/ZAPD/lib/libgfxd/uc_macrotbl.c b/tools/ZAPD/lib/libgfxd/uc_macrotbl.c new file mode 100644 index 0000000000..a8939cede0 --- /dev/null +++ b/tools/ZAPD/lib/libgfxd/uc_macrotbl.c @@ -0,0 +1,1397 @@ +static const gfxd_macro_type_t macro_tbl[] = +{ + [gfxd_Invalid] = + { + .prefix = NULL, + .suffix = NULL, + .opcode = -1, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_Invalid, + }, + [gfxd_DPFillRectangle] = + { + .prefix = NULL, + .suffix = "DPFillRectangle", + .opcode = G_FILLRECT, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_DPFillRectangle, + }, + [gfxd_DPFullSync] = + { + .prefix = NULL, + .suffix = "DPFullSync", + .opcode = G_RDPFULLSYNC, + .n_gfx = 1, + .n_arg = 0, + .disas_fn = d_DPFullSync, + }, + [gfxd_DPLoadSync] = + { + .prefix = NULL, + .suffix = "DPLoadSync", + .opcode = G_RDPLOADSYNC, + .n_gfx = 1, + .n_arg = 0, + .disas_fn = d_DPLoadSync, + }, + [gfxd_DPTileSync] = + { + .prefix = NULL, + .suffix = "DPTileSync", + .opcode = G_RDPTILESYNC, + .n_gfx = 1, + .n_arg = 0, + .disas_fn = d_DPTileSync, + }, + [gfxd_DPPipeSync] = + { + .prefix = NULL, + .suffix = "DPPipeSync", + .opcode = G_RDPPIPESYNC, + .n_gfx = 1, + .n_arg = 0, + .disas_fn = d_DPPipeSync, + }, + [gfxd_DPLoadTLUT_pal16] = + { + .prefix = NULL, + .suffix = "DPLoadTLUT_pal16", + .opcode = G_SETTIMG, + .n_gfx = 6, + .n_arg = 2, + .combine_fn = c_DPLoadTLUT_pal16, + }, + [gfxd_DPLoadTLUT_pal256] = + { + .prefix = NULL, + .suffix = "DPLoadTLUT_pal256", + .opcode = G_SETTIMG, + .n_gfx = 6, + .n_arg = 1, + .combine_fn = c_DPLoadTLUT_pal256, + }, + [gfxd_DPLoadMultiBlockYuvS] = + { + .prefix = NULL, + .suffix = "DPLoadMultiBlockYuvS", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 14, + .combine_fn = c_DPLoadMultiBlockYuvS, + .ext = 1, + }, + [gfxd_DPLoadMultiBlockYuv] = + { + .prefix = NULL, + .suffix = "DPLoadMultiBlockYuv", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 14, + .combine_fn = c_DPLoadMultiBlockYuv, + .ext = 1, + }, + [gfxd_DPLoadMultiBlock_4bS] = + { + .prefix = NULL, + .suffix = "DPLoadMultiBlock_4bS", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 13, + .combine_fn = c_DPLoadMultiBlock_4bS, + }, + [gfxd_DPLoadMultiBlock_4b] = + { + .prefix = NULL, + .suffix = "DPLoadMultiBlock_4b", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 13, + .combine_fn = c_DPLoadMultiBlock_4b, + }, + [gfxd_DPLoadMultiBlockS] = + { + .prefix = NULL, + .suffix = "DPLoadMultiBlockS", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 14, + .combine_fn = c_DPLoadMultiBlockS, + }, + [gfxd_DPLoadMultiBlock] = + { + .prefix = NULL, + .suffix = "DPLoadMultiBlock", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 14, + .combine_fn = c_DPLoadMultiBlock, + }, + [gfxd__DPLoadTextureBlockYuvS] = + { + .prefix = "_", + .suffix = "DPLoadTextureBlockYuvS", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 13, + .combine_fn = c__DPLoadTextureBlockYuvS, + .ext = 1, + }, + [gfxd__DPLoadTextureBlockYuv] = + { + .prefix = "_", + .suffix = "DPLoadTextureBlockYuv", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 13, + .combine_fn = c__DPLoadTextureBlockYuv, + .ext = 1, + }, + [gfxd__DPLoadTextureBlock_4bS] = + { + .prefix = "_", + .suffix = "DPLoadTextureBlock_4bS", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 12, + .combine_fn = c__DPLoadTextureBlock_4bS, + .ext = 1, + }, + [gfxd__DPLoadTextureBlock_4b] = + { + .prefix = "_", + .suffix = "DPLoadTextureBlock_4b", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 12, + .combine_fn = c__DPLoadTextureBlock_4b, + }, + [gfxd__DPLoadTextureBlockS] = + { + .prefix = "_", + .suffix = "DPLoadTextureBlockS", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 13, + .combine_fn = c__DPLoadTextureBlockS, + .ext = 1, + }, + [gfxd__DPLoadTextureBlock] = + { + .prefix = "_", + .suffix = "DPLoadTextureBlock", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 13, + .combine_fn = c__DPLoadTextureBlock, + }, + [gfxd_DPLoadTextureBlockYuvS] = + { + .prefix = NULL, + .suffix = "DPLoadTextureBlockYuvS", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 12, + .combine_fn = c_DPLoadTextureBlockYuvS, + .ext = 1, + }, + [gfxd_DPLoadTextureBlockYuv] = + { + .prefix = NULL, + .suffix = "DPLoadTextureBlockYuv", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 12, + .combine_fn = c_DPLoadTextureBlockYuv, + .ext = 1, + }, + [gfxd_DPLoadTextureBlock_4bS] = + { + .prefix = NULL, + .suffix = "DPLoadTextureBlock_4bS", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 11, + .combine_fn = c_DPLoadTextureBlock_4bS, + }, + [gfxd_DPLoadTextureBlock_4b] = + { + .prefix = NULL, + .suffix = "DPLoadTextureBlock_4b", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 11, + .combine_fn = c_DPLoadTextureBlock_4b, + }, + [gfxd_DPLoadTextureBlockS] = + { + .prefix = NULL, + .suffix = "DPLoadTextureBlockS", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 12, + .combine_fn = c_DPLoadTextureBlockS, + }, + [gfxd_DPLoadTextureBlock] = + { + .prefix = NULL, + .suffix = "DPLoadTextureBlock", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 12, + .combine_fn = c_DPLoadTextureBlock, + }, + [gfxd_DPLoadMultiTileYuv] = + { + .prefix = NULL, + .suffix = "DPLoadMultiTileYuv", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 18, + .combine_fn = c_DPLoadMultiTileYuv, + .ext = 1, + }, + [gfxd_DPLoadMultiTile_4b] = + { + .prefix = NULL, + .suffix = "DPLoadMultiTile_4b", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 17, + .combine_fn = c_DPLoadMultiTile_4b, + }, + [gfxd_DPLoadMultiTile] = + { + .prefix = NULL, + .suffix = "DPLoadMultiTile", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 18, + .combine_fn = c_DPLoadMultiTile, + }, + [gfxd__DPLoadTextureTileYuv] = + { + .prefix = "_", + .suffix = "DPLoadTextureTileYuv", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 17, + .combine_fn = c__DPLoadTextureTileYuv, + .ext = 1, + }, + [gfxd__DPLoadTextureTile_4b] = + { + .prefix = "_", + .suffix = "DPLoadTextureTile_4b", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 16, + .combine_fn = c__DPLoadTextureTile_4b, + .ext = 1, + }, + [gfxd__DPLoadTextureTile] = + { + .prefix = "_", + .suffix = "DPLoadTextureTile", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 17, + .combine_fn = c__DPLoadTextureTile, + .ext = 1, + }, + [gfxd_DPLoadTextureTileYuv] = + { + .prefix = NULL, + .suffix = "DPLoadTextureTileYuv", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 16, + .combine_fn = c_DPLoadTextureTileYuv, + .ext = 1, + }, + [gfxd_DPLoadTextureTile_4b] = + { + .prefix = NULL, + .suffix = "DPLoadTextureTile_4b", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 15, + .combine_fn = c_DPLoadTextureTile_4b, + }, + [gfxd_DPLoadTextureTile] = + { + .prefix = NULL, + .suffix = "DPLoadTextureTile", + .opcode = G_SETTIMG, + .n_gfx = 7, + .n_arg = 16, + .combine_fn = c_DPLoadTextureTile, + }, + [gfxd_DPLoadBlock] = + { + .prefix = NULL, + .suffix = "DPLoadBlock", + .opcode = G_LOADBLOCK, + .n_gfx = 1, + .n_arg = 5, + .disas_fn = d_DPLoadBlock, + }, + [gfxd_DPNoOp] = + { + .prefix = NULL, + .suffix = "DPNoOp", + .opcode = G_NOOP, + .n_gfx = 1, + .n_arg = 0, + .alias = gfxd_DPNoOpTag, + }, + [gfxd_DPNoOpTag] = + { + .prefix = NULL, + .suffix = "DPNoOpTag", + .opcode = G_NOOP, + .n_gfx = 1, + .n_arg = 1, + .disas_fn = d_DPNoOpTag, + }, + [gfxd_DPPipelineMode] = + { + .prefix = NULL, + .suffix = "DPPipelineMode", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetBlendColor] = + { + .prefix = NULL, + .suffix = "DPSetBlendColor", + .opcode = G_SETBLENDCOLOR, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_DPSetBlendColor, + }, + [gfxd_DPSetEnvColor] = + { + .prefix = NULL, + .suffix = "DPSetEnvColor", + .opcode = G_SETENVCOLOR, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_DPSetEnvColor, + }, + [gfxd_DPSetFillColor] = + { + .prefix = NULL, + .suffix = "DPSetFillColor", + .opcode = G_SETFILLCOLOR, + .n_gfx = 1, + .n_arg = 1, + .disas_fn = d_DPSetFillColor, + }, + [gfxd_DPSetFogColor] = + { + .prefix = NULL, + .suffix = "DPSetFogColor", + .opcode = G_SETFOGCOLOR, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_DPSetFogColor, + }, + [gfxd_DPSetPrimColor] = + { + .prefix = NULL, + .suffix = "DPSetPrimColor", + .opcode = G_SETPRIMCOLOR, + .n_gfx = 1, + .n_arg = 6, + .disas_fn = d_DPSetPrimColor, + }, + [gfxd_DPSetColorImage] = + { + .prefix = NULL, + .suffix = "DPSetColorImage", + .opcode = G_SETCIMG, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_DPSetColorImage, + }, + [gfxd_DPSetDepthImage] = + { + .prefix = NULL, + .suffix = "DPSetDepthImage", + .opcode = G_SETZIMG, + .n_gfx = 1, + .n_arg = 1, + .disas_fn = d_DPSetDepthImage, + }, + [gfxd_DPSetTextureImage] = + { + .prefix = NULL, + .suffix = "DPSetTextureImage", + .opcode = G_SETTIMG, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_DPSetTextureImage, + }, + [gfxd_DPSetAlphaCompare] = + { + .prefix = NULL, + .suffix = "DPSetAlphaCompare", + .opcode = G_SETOTHERMODE_L, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeLo, + }, + [gfxd_DPSetAlphaDither] = + { + .prefix = NULL, + .suffix = "DPSetAlphaDither", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetColorDither] = + { + .prefix = NULL, + .suffix = "DPSetColorDither", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetCombineMode] = + { + .prefix = NULL, + .suffix = "DPSetCombineMode", + .opcode = G_SETCOMBINE, + .n_gfx = 1, + .n_arg = 2, + .alias = gfxd_DPSetCombineLERP, + }, + [gfxd_DPSetCombineLERP] = + { + .prefix = NULL, + .suffix = "DPSetCombineLERP", + .opcode = G_SETCOMBINE, + .n_gfx = 1, + .n_arg = 16, + .disas_fn = d_DPSetCombineLERP, + }, + [gfxd_DPSetConvert] = + { + .prefix = NULL, + .suffix = "DPSetConvert", + .opcode = G_SETCONVERT, + .n_gfx = 1, + .n_arg = 6, + .disas_fn = d_DPSetConvert, + }, + [gfxd_DPSetTextureConvert] = + { + .prefix = NULL, + .suffix = "DPSetTextureConvert", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetCycleType] = + { + .prefix = NULL, + .suffix = "DPSetCycleType", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetDepthSource] = + { + .prefix = NULL, + .suffix = "DPSetDepthSource", + .opcode = G_SETOTHERMODE_L, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeLo, + }, + [gfxd_DPSetCombineKey] = + { + .prefix = NULL, + .suffix = "DPSetCombineKey", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetKeyGB] = + { + .prefix = NULL, + .suffix = "DPSetKeyGB", + .opcode = G_SETKEYGB, + .n_gfx = 1, + .n_arg = 6, + .disas_fn = d_DPSetKeyGB, + }, + [gfxd_DPSetKeyR] = + { + .prefix = NULL, + .suffix = "DPSetKeyR", + .opcode = G_SETKEYR, + .n_gfx = 1, + .n_arg = 3, + .disas_fn = d_DPSetKeyR, + }, + [gfxd_DPSetPrimDepth] = + { + .prefix = NULL, + .suffix = "DPSetPrimDepth", + .opcode = G_SETPRIMDEPTH, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_DPSetPrimDepth, + }, + [gfxd_DPSetRenderMode] = + { + .prefix = NULL, + .suffix = "DPSetRenderMode", + .opcode = G_SETOTHERMODE_L, + .n_gfx = 1, + .n_arg = 2, + .alias = gfxd_SPSetOtherModeLo, + }, + [gfxd_DPSetScissor] = + { + .prefix = NULL, + .suffix = "DPSetScissor", + .opcode = G_SETSCISSOR, + .n_gfx = 1, + .n_arg = 5, + .alias = gfxd_DPSetScissorFrac, + }, + [gfxd_DPSetScissorFrac] = + { + .prefix = NULL, + .suffix = "DPSetScissorFrac", + .opcode = G_SETSCISSOR, + .n_gfx = 1, + .n_arg = 5, + .disas_fn = d_DPSetScissorFrac, + }, + [gfxd_DPSetTextureDetail] = + { + .prefix = NULL, + .suffix = "DPSetTextureDetail", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetTextureFilter] = + { + .prefix = NULL, + .suffix = "DPSetTextureFilter", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetTextureLOD] = + { + .prefix = NULL, + .suffix = "DPSetTextureLOD", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetTextureLUT] = + { + .prefix = NULL, + .suffix = "DPSetTextureLUT", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetTexturePersp] = + { + .prefix = NULL, + .suffix = "DPSetTexturePersp", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPSetOtherModeHi, + }, + [gfxd_DPSetTile] = + { + .prefix = NULL, + .suffix = "DPSetTile", + .opcode = G_SETTILE, + .n_gfx = 1, + .n_arg = 12, + .disas_fn = d_DPSetTile, + }, + [gfxd_DPSetTileSize] = + { + .prefix = NULL, + .suffix = "DPSetTileSize", + .opcode = G_SETTILESIZE, + .n_gfx = 1, + .n_arg = 5, + .disas_fn = d_DPSetTileSize, + }, + [gfxd_SP1Triangle] = + { + .prefix = NULL, + .suffix = "SP1Triangle", + .opcode = G_TRI1, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_SP1Triangle, + }, +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) + [gfxd_SP2Triangles] = + { + .prefix = NULL, + .suffix = "SP2Triangles", + .opcode = G_TRI2, + .n_gfx = 1, + .n_arg = 8, + .disas_fn = d_SP2Triangles, + }, +#endif +#if defined(F3DEX_GBI) + [gfxd_SP1Quadrangle] = + { + .prefix = NULL, + .suffix = "SP1Quadrangle", + .opcode = G_TRI2, + .n_gfx = 1, + .n_arg = 5, + .alias = gfxd_SP2Triangles, + }, +#elif defined(F3DEX_GBI_2) + [gfxd_SP1Quadrangle] = + { + .prefix = NULL, + .suffix = "SP1Quadrangle", + .opcode = G_QUAD, + .n_gfx = 1, + .n_arg = 5, + .disas_fn = d_SP1Quadrangle, + }, +#endif +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) + [gfxd_SPBranchLessZraw] = + { + .prefix = NULL, + .suffix = "SPBranchLessZraw", + .opcode = G_RDPHALF_1, + .n_gfx = 2, + .n_arg = 3, + .combine_fn = c_SPBranchLessZraw, + }, +#endif + [gfxd_SPBranchList] = + { + .prefix = NULL, + .suffix = "SPBranchList", + .opcode = G_DL, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_DisplayList, + }, + [gfxd_SPClipRatio] = + { + .prefix = NULL, + .suffix = "SPClipRatio", + .opcode = G_MOVEWORD, + .n_gfx = 4, + .n_arg = 1, + .combine_fn = c_SPClipRatio, + }, + [gfxd_SPCullDisplayList] = + { + .prefix = NULL, + .suffix = "SPCullDisplayList", + .opcode = G_CULLDL, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_SPCullDisplayList, + }, + [gfxd_SPDisplayList] = + { + .prefix = NULL, + .suffix = "SPDisplayList", + .opcode = G_DL, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_DisplayList, + }, + [gfxd_SPEndDisplayList] = + { + .prefix = NULL, + .suffix = "SPEndDisplayList", + .opcode = G_ENDDL, + .n_gfx = 1, + .n_arg = 0, + .disas_fn = d_SPEndDisplayList, + }, + [gfxd_SPFogFactor] = + { + .prefix = NULL, + .suffix = "SPFogFactor", + .opcode = G_MOVEWORD, + .n_gfx = 1, + .n_arg = 2, + .alias = gfxd_SPFogPosition, + }, + [gfxd_SPFogPosition] = + { + .prefix = NULL, + .suffix = "SPFogPosition", + .opcode = G_MOVEWORD, + .n_gfx = 1, + .n_arg = 2, + .alias = gfxd_MoveWd, + }, +#if defined(F3D_GBI) || defined(F3DEX_GBI) + [gfxd_SPForceMatrix] = + { + .prefix = NULL, + .suffix = "SPForceMatrix", + .opcode = G_MOVEMEM, + .n_gfx = 4, + .n_arg = 1, + .combine_fn = c_SPForceMatrix, + }, + [gfxd_SPSetGeometryMode] = + { + .prefix = NULL, + .suffix = "SPSetGeometryMode", + .opcode = G_SETGEOMETRYMODE, + .n_gfx = 1, + .n_arg = 1, + .disas_fn = d_SPSetGeometryMode, + }, + [gfxd_SPClearGeometryMode] = + { + .prefix = NULL, + .suffix = "SPClearGeometryMode", + .opcode = G_CLEARGEOMETRYMODE, + .n_gfx = 1, + .n_arg = 1, + .disas_fn = d_SPClearGeometryMode, + }, + [gfxd_SPLoadGeometryMode] = + { + .prefix = NULL, + .suffix = "SPLoadGeometryMode", + .opcode = G_CLEARGEOMETRYMODE, + .n_gfx = 2, + .n_arg = 1, + .combine_fn = c_SPLoadGeometryMode, + }, +#elif defined(F3DEX_GBI_2) + [gfxd_SPForceMatrix] = + { + .prefix = NULL, + .suffix = "SPForceMatrix", + .opcode = G_MOVEMEM, + .n_gfx = 2, + .n_arg = 1, + .combine_fn = c_SPForceMatrix, + }, + [gfxd_SPSetGeometryMode] = + { + .prefix = NULL, + .suffix = "SPSetGeometryMode", + .opcode = G_GEOMETRYMODE, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPGeometryMode, + }, + [gfxd_SPClearGeometryMode] = + { + .prefix = NULL, + .suffix = "SPClearGeometryMode", + .opcode = G_GEOMETRYMODE, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPGeometryMode, + }, + [gfxd_SPLoadGeometryMode] = + { + .prefix = NULL, + .suffix = "SPLoadGeometryMode", + .opcode = G_GEOMETRYMODE, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPGeometryMode, + }, +#endif +#if defined(F3D_GBI) || defined(F3DEX_GBI) + [gfxd_SPInsertMatrix] = + { + .prefix = NULL, + .suffix = "SPInsertMatrix", + .opcode = G_MOVEWORD, + .n_gfx = 1, + .n_arg = 2, + .alias = gfxd_MoveWd, + }, +#endif + [gfxd_SPLine3D] = + { + .prefix = NULL, + .suffix = "SPLine3D", + .opcode = G_LINE3D, + .n_gfx = 1, + .n_arg = 3, + .alias = gfxd_SPLineW3D, + }, + [gfxd_SPLineW3D] = + { + .prefix = NULL, + .suffix = "SPLineW3D", + .opcode = G_LINE3D, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_SPLineW3D, + }, +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) + [gfxd_SPLoadUcode] = + { + .prefix = NULL, + .suffix = "SPLoadUcode", + .opcode = G_RDPHALF_1, + .n_gfx = 2, + .n_arg = 2, + .combine_fn = c_SPLoadUcode, + }, +#endif + [gfxd_SPLookAtX] = + { + .prefix = NULL, + .suffix = "SPLookAtX", + .opcode = G_MOVEMEM, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_MoveMem, + }, + [gfxd_SPLookAtY] = + { + .prefix = NULL, + .suffix = "SPLookAtY", + .opcode = G_MOVEMEM, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_MoveMem, + }, + [gfxd_SPLookAt] = + { + .prefix = NULL, + .suffix = "SPLookAt", + .opcode = G_MOVEMEM, + .n_gfx = 2, + .n_arg = 1, + .combine_fn = c_SPLookAt, + }, + [gfxd_SPMatrix] = + { + .prefix = NULL, + .suffix = "SPMatrix", + .opcode = G_MTX, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_SPMatrix, + }, +#if defined(F3D_GBI) || (defined(F3D_BETA) && defined(F3DEX_GBI)) + [gfxd_SPModifyVertex] = + { + .prefix = NULL, + .suffix = "SPModifyVertex", + .opcode = G_MOVEWORD, + .n_gfx = 1, + .n_arg = 3, + .alias = gfxd_MoveWd, + }, +#elif defined(F3DEX_GBI) || defined(F3DEX_GBI_2) + [gfxd_SPModifyVertex] = + { + .prefix = NULL, + .suffix = "SPModifyVertex", + .opcode = G_MODIFYVTX, + .n_gfx = 1, + .n_arg = 3, + .disas_fn = d_SPModifyVertex, + }, +#endif +#if defined(F3D_BETA) && (defined(F3D_GBI) || defined(F3DEX_GBI)) + [gfxd_SPPerspNormalize] = + { + .prefix = NULL, + .suffix = "SPPerspNormalize", + .opcode = G_PERSPNORM, + .n_gfx = 1, + .n_arg = 1, + .disas_fn = d_SPPerspNormalize, + }, +#else + [gfxd_SPPerspNormalize] = + { + .prefix = NULL, + .suffix = "SPPerspNormalize", + .opcode = G_MOVEWORD, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_MoveWd, + }, +#endif +#if defined(F3D_GBI) || defined(F3DEX_GBI) + [gfxd_SPPopMatrix] = + { + .prefix = NULL, + .suffix = "SPPopMatrix", + .opcode = G_POPMTX, + .n_gfx = 1, + .n_arg = 1, + .disas_fn = d_SPPopMatrix, + }, +#elif defined(F3DEX_GBI_2) + [gfxd_SPPopMatrix] = + { + .prefix = NULL, + .suffix = "SPPopMatrix", + .opcode = G_POPMTX, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_SPPopMatrixN, + }, + [gfxd_SPPopMatrixN] = + { + .prefix = NULL, + .suffix = "SPPopMatrixN", + .opcode = G_POPMTX, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_SPPopMatrixN, + }, +#endif + [gfxd_SPSegment] = + { + .prefix = NULL, + .suffix = "SPSegment", + .opcode = G_MOVEWORD, + .n_gfx = 1, + .n_arg = 2, + .alias = gfxd_MoveWd, + }, + [gfxd_SPSetLights1] = + { + .prefix = NULL, + .suffix = "SPSetLights1", + .opcode = G_MOVEWORD, + .n_gfx = 3, + .n_arg = 1, + .combine_fn = c_SPSetLights1, + }, + [gfxd_SPSetLights2] = + { + .prefix = NULL, + .suffix = "SPSetLights2", + .opcode = G_MOVEWORD, + .n_gfx = 4, + .n_arg = 1, + .combine_fn = c_SPSetLights2, + }, + [gfxd_SPSetLights3] = + { + .prefix = NULL, + .suffix = "SPSetLights3", + .opcode = G_MOVEWORD, + .n_gfx = 5, + .n_arg = 1, + .combine_fn = c_SPSetLights3, + }, + [gfxd_SPSetLights4] = + { + .prefix = NULL, + .suffix = "SPSetLights4", + .opcode = G_MOVEWORD, + .n_gfx = 6, + .n_arg = 1, + .combine_fn = c_SPSetLights4, + }, + [gfxd_SPSetLights5] = + { + .prefix = NULL, + .suffix = "SPSetLights5", + .opcode = G_MOVEWORD, + .n_gfx = 7, + .n_arg = 1, + .combine_fn = c_SPSetLights5, + }, + [gfxd_SPSetLights6] = + { + .prefix = NULL, + .suffix = "SPSetLights6", + .opcode = G_MOVEWORD, + .n_gfx = 8, + .n_arg = 1, + .combine_fn = c_SPSetLights6, + }, + [gfxd_SPSetLights7] = + { + .prefix = NULL, + .suffix = "SPSetLights7", + .opcode = G_MOVEWORD, + .n_gfx = 9, + .n_arg = 1, + .combine_fn = c_SPSetLights7, + }, + [gfxd_SPNumLights] = + { + .prefix = NULL, + .suffix = "SPNumLights", + .opcode = G_MOVEWORD, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_MoveWd, + }, + [gfxd_SPLight] = + { + .prefix = NULL, + .suffix = "SPLight", + .opcode = G_MOVEMEM, + .n_gfx = 1, + .n_arg = 2, + .alias = gfxd_MoveMem, + }, + [gfxd_SPLightColor] = + { + .prefix = NULL, + .suffix = "SPLightColor", + .opcode = G_MOVEWORD, + .n_gfx = 2, + .n_arg = 2, + .combine_fn = c_SPLightColor, + }, + [gfxd_SPTexture] = + { + .prefix = NULL, + .suffix = "SPTexture", + .opcode = G_TEXTURE, + .n_gfx = 1, + .n_arg = 5, + .disas_fn = d_SPTexture, + }, + [gfxd_SPTextureRectangle] = + { + .prefix = NULL, + .suffix = "SPTextureRectangle", + .opcode = G_TEXRECT, + .n_gfx = 3, + .n_arg = 9, + .combine_fn = c_SPTextureRectangle, + }, + [gfxd_SPTextureRectangleFlip] = + { + .prefix = NULL, + .suffix = "SPTextureRectangleFlip", + .opcode = G_TEXRECTFLIP, + .n_gfx = 3, + .n_arg = 9, + .combine_fn = c_SPTextureRectangleFlip, + }, + [gfxd_SPVertex] = + { + .prefix = NULL, + .suffix = "SPVertex", + .opcode = G_VTX, + .n_gfx = 1, + .n_arg = 3, + .disas_fn = d_SPVertex, + }, + [gfxd_SPViewport] = + { + .prefix = NULL, + .suffix = "SPViewport", + .opcode = G_MOVEMEM, + .n_gfx = 1, + .n_arg = 1, + .alias = gfxd_MoveMem, + }, + [gfxd_DPLoadTLUTCmd] = + { + .prefix = NULL, + .suffix = "DPLoadTLUTCmd", + .opcode = G_LOADTLUT, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_DPLoadTLUTCmd, + }, + [gfxd_DPLoadTLUT] = + { + .prefix = NULL, + .suffix = "DPLoadTLUT", + .opcode = G_SETTIMG, + .n_gfx = 6, + .n_arg = 3, + .combine_fn = c_DPLoadTLUT, + }, +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) + [gfxd_BranchZ] = + { + .prefix = NULL, + .suffix = "BranchZ", + .opcode = G_BRANCH_Z, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_BranchZ, + .ext = 1, + }, +#endif + [gfxd_DisplayList] = + { + .prefix = NULL, + .suffix = "DisplayList", + .opcode = G_DL, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_DisplayList, + .ext = 1, + }, + [gfxd_DPHalf1] = + { + .prefix = NULL, + .suffix = "DPHalf1", + .opcode = G_RDPHALF_1, + .n_gfx = 1, + .n_arg = 1, + .disas_fn = d_DPHalf1, + .ext = 1, + }, + [gfxd_DPHalf2] = + { + .prefix = NULL, + .suffix = "DPHalf2", + .opcode = G_RDPHALF_2, + .n_gfx = 1, + .n_arg = 1, + .disas_fn = d_DPHalf2, + .ext = 1, + }, + [gfxd_DPWord] = + { + .prefix = NULL, + .suffix = "DPWord", + .opcode = G_RDPHALF_1, + .n_gfx = 2, + .n_arg = 2, + .combine_fn = c_DPWord, + }, + [gfxd_DPLoadTile] = + { + .prefix = NULL, + .suffix = "DPLoadTile", + .opcode = G_LOADTILE, + .n_gfx = 1, + .n_arg = 5, + .disas_fn = d_DPLoadTile, + }, +#if defined(F3DEX_GBI_2) + [gfxd_SPGeometryMode] = + { + .prefix = NULL, + .suffix = "SPGeometryMode", + .opcode = G_GEOMETRYMODE, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_SPGeometryMode, + }, +#endif + [gfxd_SPSetOtherMode] = + { + .prefix = NULL, + .suffix = "SPSetOtherMode", + .opcode = -1, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_SPSetOtherMode, + }, + [gfxd_SPSetOtherModeLo] = + { + .prefix = NULL, + .suffix = "SPSetOtherModeLo", + .opcode = G_SETOTHERMODE_L, + .n_gfx = 1, + .n_arg = 3, + .disas_fn = d_SPSetOtherModeLo, + .ext = 1, + }, + [gfxd_SPSetOtherModeHi] = + { + .prefix = NULL, + .suffix = "SPSetOtherModeHi", + .opcode = G_SETOTHERMODE_H, + .n_gfx = 1, + .n_arg = 3, + .disas_fn = d_SPSetOtherModeHi, + .ext = 1, + }, + [gfxd_DPSetOtherMode] = + { + .prefix = NULL, + .suffix = "DPSetOtherMode", + .opcode = G_RDPSETOTHERMODE, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_DPSetOtherMode, + }, + [gfxd_MoveWd] = + { + .prefix = NULL, + .suffix = "MoveWd", + .opcode = G_MOVEWORD, + .n_gfx = 1, + .n_arg = 3, + .disas_fn = d_MoveWd, + }, +#if defined(F3D_GBI) || defined(F3DEX_GBI) + [gfxd_MoveMem] = + { + .prefix = NULL, + .suffix = "MoveMem", + .opcode = G_MOVEMEM, + .n_gfx = 1, + .n_arg = 3, + .disas_fn = d_MoveMem, + .ext = 1, + }, +#elif defined(F3DEX_GBI_2) + [gfxd_MoveMem] = + { + .prefix = NULL, + .suffix = "MoveMem", + .opcode = G_MOVEMEM, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_MoveMem, + .ext = 1, + }, +#endif +#if defined(F3DEX_GBI_2) + [gfxd_SPDma_io] = + { + .prefix = NULL, + .suffix = "SPDma_io", + .opcode = G_DMA_IO, + .n_gfx = 1, + .n_arg = 4, + .disas_fn = d_SPDma_io, + }, + [gfxd_SPDmaRead] = + { + .prefix = NULL, + .suffix = "SPDmaRead", + .opcode = G_DMA_IO, + .n_gfx = 1, + .n_arg = 3, + .alias = gfxd_SPDma_io, + }, + [gfxd_SPDmaWrite] = + { + .prefix = NULL, + .suffix = "SPDmaWrite", + .opcode = G_DMA_IO, + .n_gfx = 1, + .n_arg = 3, + .alias = gfxd_SPDma_io, + }, +#endif +#if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) + [gfxd_LoadUcode] = + { + .prefix = NULL, + .suffix = "LoadUcode", + .opcode = G_LOAD_UCODE, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_LoadUcode, + }, + [gfxd_SPLoadUcodeEx] = + { + .prefix = NULL, + .suffix = "SPLoadUcodeEx", + .opcode = G_RDPHALF_1, + .n_gfx = 2, + .n_arg = 3, + .combine_fn = c_SPLoadUcodeEx, + }, +#endif + [gfxd_TexRect] = + { + .prefix = NULL, + .suffix = "TexRect", + .opcode = G_TEXRECT, + .n_gfx = 1, + .n_arg = 5, + .disas_fn = d_TexRect, + .ext = 1, + }, + [gfxd_TexRectFlip] = + { + .prefix = NULL, + .suffix = "TexRectFlip", + .opcode = G_TEXRECTFLIP, + .n_gfx = 1, + .n_arg = 5, + .disas_fn = d_TexRectFlip, + .ext = 1, + }, + [gfxd_SPNoOp] = + { + .prefix = NULL, + .suffix = "SPNoOp", + .opcode = G_SPNOOP, + .n_gfx = 1, + .n_arg = 0, + .disas_fn = d_SPNoOp, + }, +#if defined(F3DEX_GBI_2) + [gfxd_Special3] = + { + .prefix = NULL, + .suffix = "Special3", + .opcode = G_SPECIAL_3, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_Special3, + .ext = 1, + }, + [gfxd_Special2] = + { + .prefix = NULL, + .suffix = "Special2", + .opcode = G_SPECIAL_2, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_Special2, + .ext = 1, + }, + [gfxd_Special1] = + { + .prefix = NULL, + .suffix = "Special1", + .opcode = G_SPECIAL_1, + .n_gfx = 1, + .n_arg = 2, + .disas_fn = d_Special1, + .ext = 1, + }, +#endif +};