diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | ZAPD/OutputFormatter.cpp | 103 | ||||
| -rw-r--r-- | ZAPD/OutputFormatter.h | 38 | ||||
| -rw-r--r-- | ZAPD/ZCollision.cpp | 12 | ||||
| -rw-r--r-- | ZAPD/ZDisplayList.cpp | 267 | ||||
| -rw-r--r-- | ZAPD/ZDisplayList.h | 14 | ||||
| -rw-r--r-- | ZAPD/ZRoom/Commands/SetMesh.cpp | 12 | ||||
| -rw-r--r-- | ZAPD/ZSkeleton.cpp | 4 | ||||
| -rw-r--r-- | lib/libgfxd/gfxd.h | 378 | ||||
| -rw-r--r-- | lib/libgfxd/libgfxd.a | bin | 0 -> 3348354 bytes |
10 files changed, 776 insertions, 56 deletions
@@ -4,7 +4,7 @@ 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/tinyxml2 -O2 -rdynamic +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) @@ -33,4 +33,4 @@ rebuild: clean all $(CC) $(CFLAGS) -c $< -o $@ ZAPD.out: $(O_FILES) - $(CC) $(CFLAGS) $(O_FILES) -o $@ $(FS_INC) + $(CC) $(CFLAGS) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC) diff --git a/ZAPD/OutputFormatter.cpp b/ZAPD/OutputFormatter.cpp new file mode 100644 index 0000000..5e7c35c --- /dev/null +++ b/ZAPD/OutputFormatter.cpp @@ -0,0 +1,103 @@ +#include "OutputFormatter.h" + +int OutputFormatter::write(const char *buf, int count) +{ + for (int i = 0; i < count; i++) + { + char c = buf[i]; + + if (c == '\n') + { + col = 0; + current_indent = nest_indent[nest]; + } + else if (c == '\t') + { + int n = tab_size - (col % tab_size); + for (int j = 0; j < n - 1; j++) + *space_p++ = ' '; + c = ' '; + col += n; + } + else + { + col++; + } + + if (c == '(') + { + nest++; + nest_indent[nest] = col; + current_indent = col; + } + else if (c == ')') + { + nest--; + } + + if (c == ' ' || c == '\t' || c == '\n') + { + str.append(word, word_p - word); + word_p = word; + + *space_p++ = c; + } + else + { + if (col > line_limit) + { + str.append(1, '\n'); + str.append(current_indent, ' '); + col = current_indent + 1 + (word_p - word); + } + else + { + str.append(space, space_p - space); + } + space_p = space; + + *word_p++ = c; + } + } + + return count; +} + +OutputFormatter* OutputFormatter::static_instance; + +int OutputFormatter::write_static(const char *buf, int count) +{ + return static_instance->write(buf, 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} +{ +} + +std::string OutputFormatter::get_output() +{ + str.append(space, space_p - space); + space_p = space; + + str.append(word, word_p - word); + word_p = word; + + return std::move(str); +} diff --git a/ZAPD/OutputFormatter.h b/ZAPD/OutputFormatter.h new file mode 100644 index 0000000..d1cdc68 --- /dev/null +++ b/ZAPD/OutputFormatter.h @@ -0,0 +1,38 @@ +#pragma once + +#include <vector> +#include <map> +#include <string> + +class OutputFormatter +{ +private: + const int tab_size; + const int default_indent; + const int line_limit; + + int col; + int nest; + int nest_indent[8]; + int current_indent; + + char word[128]; + char space[128]; + char *word_p; + char *space_p; + + std::string str; + + int write(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); + + int (*static_writer())(const char *buf, int count); + + std::string get_output(); +};
\ No newline at end of file diff --git a/ZAPD/ZCollision.cpp b/ZAPD/ZCollision.cpp index d0b5fd9..ce10c0a 100644 --- a/ZAPD/ZCollision.cpp +++ b/ZAPD/ZCollision.cpp @@ -98,9 +98,9 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con for (int i = 0; i < polygons.size(); i++) { - sprintf(line, " { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X }, // 0x%08X\n", + 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, polySegmentOffset + (i * 16)); + (uint16_t)polygons[i]->a, (uint16_t)polygons[i]->b, (uint16_t)polygons[i]->c, (uint16_t)polygons[i]->d); declaration += line; } @@ -120,7 +120,7 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con if (polyTypeDefAddress != 0) parent->AddDeclarationArray(polyTypeDefSegmentOffset, DeclarationAlignment::None, polygonTypes.size() * 8, - "u32", StringHelper::Sprintf("%s_polygonTypes_%08X", prefix.c_str(), polyTypeDefSegmentOffset), 0, declaration); + "SurfaceType", StringHelper::Sprintf("%s_polygonTypes_%08X", prefix.c_str(), polyTypeDefSegmentOffset), 0, declaration); declaration = ""; @@ -130,7 +130,7 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con for (int i = 0; i < vertices.size(); i++) { - declaration += StringHelper::Sprintf(" { %i, %i, %i }, // 0x%08X", vertices[i]->x, vertices[i]->y, vertices[i]->z, vtxSegmentOffset + (i * 6)); + declaration += StringHelper::Sprintf(" { %i, %i, %i },", vertices[i]->x, vertices[i]->y, vertices[i]->z); if (i < vertices.size() - 1) declaration += "\n"; @@ -276,7 +276,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const s else sprintf(camSegLine, "0x%08X", entries[i]->cameraPosDataSeg); - declaration += StringHelper::Sprintf("\t{ 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"; @@ -294,7 +294,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const s CameraPositionData* data = new CameraPositionData(rawData, cameraPosDataOffset + (i * 6)); cameraPositionData.push_back(data); - declaration += StringHelper::Sprintf("\t{ %6i, %6i, %6i }, // 0x%08X\n", data->x, data->y, data->z, cameraPosDataSeg + (i * 0x6));; + declaration += StringHelper::Sprintf(" { %6i, %6i, %6i },\n", data->x, data->y, data->z); } int cameraPosDataIndex = cameraPosDataSeg & 0x00FFFFFF; diff --git a/ZAPD/ZDisplayList.cpp b/ZAPD/ZDisplayList.cpp index c69e1a8..4754c03 100644 --- a/ZAPD/ZDisplayList.cpp +++ b/ZAPD/ZDisplayList.cpp @@ -1,8 +1,10 @@ #include "ZDisplayList.h" #include "BitConverter.h" #include "StringHelper.h" +#include "OutputFormatter.h" #include "HighLevel/HLModelIntermediette.h" #include "Globals.h" +#include "gfxd.h" #include <chrono> #include <algorithm> #include <File.h> @@ -68,7 +70,7 @@ ZDisplayList::ZDisplayList(vector<uint8_t> nRawData, int nRawDataIndex, int rawD { fileData = nRawData; rawDataIndex = nRawDataIndex; - name = StringHelper::Sprintf("Dlist0x%06X", rawDataIndex); + name = StringHelper::Sprintf("DL_%06X", rawDataIndex); rawData = vector<uint8_t>(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + rawDataSize); ParseRawData(); } @@ -1428,48 +1430,241 @@ string ZDisplayList::GetSourceOutputHeader(const std::string& prefix) return ""; } -string ZDisplayList::GetSourceOutputCode(const std::string& prefix) +static int GfxdCallback_FormatSingleEntry(void) { - char line[4096]; - string sourceOutput = ""; + gfxd_puts("\t"); + gfxd_macro_dflt(); + gfxd_puts(","); - for (int i = 0; i < instructions.size(); i++) - { - uint8_t opcode = (uint8_t)(instructions[i] >> 56); - uint64_t data = instructions[i]; - sourceOutput += " "; + // dont print a new line after the last command + if (gfxd_macro_id() != gfxd_SPEndDisplayList) { + gfxd_puts("\n"); + } - auto start = chrono::steady_clock::now(); + return 0; +} - int optimizationResult = OptimizationChecks(i, sourceOutput, prefix); +static int GfxdCallback_Vtx(uint32_t seg, int32_t count) +{ + ZDisplayList* instance = ZDisplayList::static_instance; + uint32_t vtxOffset = Seg2Filespace(seg, instance->parent->baseAddress); + string vtxName = ""; - if (optimizationResult != -1) + if (!Globals::Instance->HasSegment(GETSEGNUM(seg))) // Probably an external asset we are unable to track + { + vtxName = StringHelper::Sprintf("0x%08X", seg); + } + else + { + instance->references.push_back(vtxOffset); + + // Check for vertex intersections from other display lists + // TODO: These two could probably be condenced to one... + if (instance->parent->GetDeclarationRanged(vtxOffset + (count * 16)) != nullptr) { - i += optimizationResult - 1; - line[0] = '\0'; + Declaration* decl = instance->parent->GetDeclarationRanged(vtxOffset + (count * 16)); + uint32_t addr = instance->parent->GetDeclarationRangedAddress(vtxOffset + (count * 16)); + int diff = addr - vtxOffset; + + if (diff > 0) + count = diff / 16; + else + count = 0; } - else + + if (instance->parent->GetDeclarationRanged(vtxOffset) != nullptr) { - if (dListType == DListType::F3DZEX) - ParseF3DZEX((F3DZEXOpcode)opcode, data, i, prefix, line); + Declaration* decl = instance->parent->GetDeclarationRanged(vtxOffset); + uint32_t addr = instance->parent->GetDeclarationRangedAddress(vtxOffset); + int diff = addr - vtxOffset; + + if (diff > 0) + count = diff / 16; else - ParseF3DEX((F3DEXOpcode)opcode, data, i, prefix, line); + count = 0; } - auto end = chrono::steady_clock::now(); - auto diff = chrono::duration_cast<chrono::milliseconds>(end - start).count(); + if (count > 0) + { + vector<Vertex> vtxList = vector<Vertex>(); + vtxList.reserve(count); + + uint32_t currentPtr = vtxOffset; + for (int i = 0; i < count; i++) + { + Vertex vtx = Vertex(instance->fileData, currentPtr); + vtxList.push_back(vtx); + currentPtr += 16; + } + instance->vertices[vtxOffset] = vtxList; + } + + vtxName = "@r"; + } + + gfxd_puts(vtxName.c_str()); + + return 1; +} + +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); + uint32_t texSegNum = GETSEGNUM(seg); + Declaration* texDecl = nullptr; + string texName = ""; + + if (instance->parent != nullptr && texSegNum != 2) // HACK: Until we have declarations use segment addresses, we'll exclude scene references... + { + texDecl = instance->parent->GetDeclaration(texOffset); + + if (texDecl == nullptr) + texDecl = instance->parent->GetDeclaration(seg); + } + + 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); + else + texName = StringHelper::Sprintf("%sTex_%06X", instance->curPrefix.c_str(), texOffset); + + instance->lastTexWidth = width; + instance->lastTexHeight = height; + instance->lastTexAddr = texOffset; + instance->lastTexSeg = seg; + instance->lastTexFmt = (F3DZEXTexFormats)fmt; + instance->lastTexSiz = (F3DZEXTexSizes)siz; + instance->lastTexLoaded = true; + instance->lastTexIsPalette = false; + + instance->TextureGenCheck(instance->curPrefix); + gfxd_puts(texName.c_str()); + + return 1; +} + +static int GfxdCallback_Palette(uint32_t seg, int32_t idx, int32_t count) +{ + ZDisplayList* instance = ZDisplayList::static_instance; + uint32_t palOffset = Seg2Filespace(seg, instance->parent->baseAddress); + uint32_t palSegNum = GETSEGNUM(seg); + Declaration* palDecl = nullptr; + string palName = ""; + + if (instance->parent != nullptr && palSegNum != 2) // HACK: Until we have declarations use segment addresses, we'll exclude scene references... + { + palDecl = instance->parent->GetDeclaration(palOffset); + + if (palDecl == nullptr) + palDecl = instance->parent->GetDeclaration(seg); + } + + 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); + else + palName = StringHelper::Sprintf("%sTex_%06X", instance->curPrefix.c_str(), palOffset); + + instance->lastTexWidth = sqrt(count); + instance->lastTexHeight = sqrt(count); + instance->lastTexAddr = palOffset; + instance->lastTexSeg = seg; + instance->lastTexSiz = F3DZEXTexSizes::G_IM_SIZ_16b; + instance->lastTexFmt = F3DZEXTexFormats::G_IM_FMT_RGBA; + instance->lastTexLoaded = true; + instance->lastTexIsPalette = true; + + instance->TextureGenCheck(instance->curPrefix); + gfxd_puts(palName.c_str()); + + return 1; +} + +static int GfxdCallback_DisplayList(uint32_t seg) +{ + ZDisplayList* instance = ZDisplayList::static_instance; + uint32_t dListOffset = GETSEGOFFSET(seg); + uint32_t dListSegNum = GETSEGNUM(seg); + Declaration* dListDecl = nullptr; + string dListName = ""; -#if _MSC_VER - //if (diff > 5) - //printf("F3DOP: 0x%02X, TIME: %ims\n", opcode, diff); -#endif + if (instance->parent != nullptr) + dListDecl = instance->parent->GetDeclaration(dListOffset); - sourceOutput += line; + 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()); + else + dListName = StringHelper::Sprintf("%sDL_%06X", instance->curPrefix.c_str(), dListOffset); - if (i < instructions.size() - 1) - sourceOutput += "\n"; + if (dListSegNum <= 6) + { + 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); } + gfxd_puts(dListName.c_str()); + + return 1; +} + +static int GfxdCallback_Matrix(uint32_t seg) +{ + string mtxName = ""; + + if (Globals::Instance->symbolMap.find(seg) != Globals::Instance->symbolMap.end()) + mtxName = StringHelper::Sprintf("&%s", Globals::Instance->symbolMap[seg].c_str()); + else + mtxName = StringHelper::Sprintf("0x%08X", seg); + + gfxd_puts(mtxName.c_str()); + + return 1; +} + +ZDisplayList* ZDisplayList::static_instance; + +string ZDisplayList::GetSourceOutputCode(const std::string& prefix) +{ + OutputFormatter outputformatter; + string sourceOutput = ""; + int 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_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 + + // set microcode. see gfxd.h for more options. + if (dListType == DListType::F3DZEX) { + gfxd_target(gfxd_f3dex2); + } else { + gfxd_target(gfxd_f3dex); + } + + this->curPrefix = prefix; + static_instance = this; + 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) { @@ -1704,17 +1899,21 @@ 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_8b) - return TextureType::Palette8bpp; - } + 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; + } else if (fmt == F3DZEXTexFormats::G_IM_FMT_IA) { - if (siz == F3DZEXTexSizes::G_IM_SIZ_16b) - return TextureType::GrayscaleAlpha16bpp; + if (siz == F3DZEXTexSizes::G_IM_SIZ_4b) + return TextureType::Grayscale4bpp; else if (siz == F3DZEXTexSizes::G_IM_SIZ_8b) return TextureType::GrayscaleAlpha8bpp; + else if (siz == F3DZEXTexSizes::G_IM_SIZ_16b) + return TextureType::GrayscaleAlpha16bpp; } else if (fmt == F3DZEXTexFormats::G_IM_FMT_I) { diff --git a/ZAPD/ZDisplayList.h b/ZAPD/ZDisplayList.h index c3f7fa2..66f2f4e 100644 --- a/ZAPD/ZDisplayList.h +++ b/ZAPD/ZDisplayList.h @@ -297,12 +297,6 @@ public: class ZDisplayList : public ZResource { protected: - uint32_t lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg; - F3DZEXTexFormats lastTexFmt; - F3DZEXTexSizes lastTexSiz, lastTexSizTest, lastCISiz; - bool lastTexLoaded; - bool lastTexIsPalette; - static TextureType TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSizes siz); void ParseRawData(); @@ -341,6 +335,13 @@ public: std::string sceneSegName; ZRoom* scene; std::vector<uint64_t> instructions; + std::string curPrefix; + + uint32_t lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg; + F3DZEXTexFormats lastTexFmt; + F3DZEXTexSizes lastTexSiz, lastTexSizTest, lastCISiz; + bool lastTexLoaded; + bool lastTexIsPalette; DListType dListType; @@ -361,6 +362,7 @@ public: ZDisplayList(); ZDisplayList(std::vector<uint8_t> nRawData, int rawDataIndex, int rawDataSize); + static ZDisplayList* static_instance; static ZDisplayList* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, int rawDataSize, std::string nRelPath); static ZDisplayList* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, bool readFile); diff --git a/ZAPD/ZRoom/Commands/SetMesh.cpp b/ZAPD/ZRoom/Commands/SetMesh.cpp index 3d60cfa..50baed3 100644 --- a/ZAPD/ZRoom/Commands/SetMesh.cpp +++ b/ZAPD/ZRoom/Commands/SetMesh.cpp @@ -82,12 +82,12 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, for (int i = 0; i < meshHeader0->entries.size(); i++) { if (meshHeader0->entries[i]->opaqueDListAddr != 0) - declaration += StringHelper::Sprintf("\t{ (u32)%sDlist0x%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)%sDlist0x%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"; } @@ -234,12 +234,12 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, 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)%sDlist0x%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)%sDlist0x%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"; } @@ -306,9 +306,9 @@ std::string SetMesh::GenDListExterns(ZDisplayList* dList) string sourceOutput = ""; if (Globals::Instance->includeFilePrefix) - sourceOutput += StringHelper::Sprintf("extern Gfx %sDlist0x%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 dlist0x%06X[];\n", dList->GetRawDataIndex()); + sourceOutput += StringHelper::Sprintf("extern Gfx DL_%06X[];\n", dList->GetRawDataIndex()); for (ZDisplayList* otherDList : dList->otherDLists) sourceOutput += GenDListExterns(otherDList); diff --git a/ZAPD/ZSkeleton.cpp b/ZAPD/ZSkeleton.cpp index 485c5a7..173570f 100644 --- a/ZAPD/ZSkeleton.cpp +++ b/ZAPD/ZSkeleton.cpp @@ -183,14 +183,14 @@ std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix) if (typeid(*limb) == typeid(ZLimbLOD)) { ZLimbLOD* limbLOD = (ZLimbLOD*)limbs[i]; - string defaultFarDLName = StringHelper::Sprintf("%sFarLimbDlist0x%06X", defaultPrefix.c_str(), limbLOD->farDListPtr); + string defaultFarDLName = StringHelper::Sprintf("%sFarLimbDL_%06X", defaultPrefix.c_str(), limbLOD->farDListPtr); string dListStr2 = limbLOD->farDListPtr == 0 ? "NULL" : StringHelper::Sprintf("%s", parent->GetDeclarationName(limbLOD->farDListPtr, defaultFarDLName).c_str()); if (limbLOD->farDListPtr != 0 && parent->GetDeclaration(limbLOD->farDListPtr) == nullptr) { ZDisplayList* dList = new ZDisplayList(rawData, limbLOD->farDListPtr, ZDisplayList::GetDListLength(rawData, limbLOD->farDListPtr, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX)); dList->parent = parent; - dList->SetName(StringHelper::Sprintf("%s_farLimbDlist_%06X", defaultPrefix.c_str(), limbLOD->farDListPtr)); + dList->SetName(StringHelper::Sprintf("%s_farLimbDL_%06X", defaultPrefix.c_str(), limbLOD->farDListPtr)); dList->GetSourceOutputCode(defaultPrefix); } diff --git a/lib/libgfxd/gfxd.h b/lib/libgfxd/gfxd.h new file mode 100644 index 0000000..ee0fc64 --- /dev/null +++ b/lib/libgfxd/gfxd.h @@ -0,0 +1,378 @@ +#ifndef GFXD_H +#define GFXD_H +#include <stdint.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +enum +{ + gfxd_Word, /* generic word */ + gfxd_Coordi, /* integer coordinate */ + gfxd_Coordq, /* fractional (q10.2) coordinate */ + gfxd_Pal, /* palette index */ + gfxd_Tlut, /* tlut pointer */ + gfxd_Timg, /* texture image pointer */ + gfxd_Tmem, /* tmem address */ + gfxd_Tile, /* tile index */ + gfxd_Fmt, /* texture format */ + gfxd_Siz, /* texture pixel size */ + gfxd_Dim, /* integer dimension (width / height) */ + gfxd_Cm, /* clamp and mirror flags */ + gfxd_Tm, /* tile mask */ + gfxd_Ts, /* tile shift */ + gfxd_Dxt, /* texture dxt */ + gfxd_Tag, /* generic tag */ + gfxd_Pm, /* pipeline mode */ + gfxd_Colorpart, /* color component */ + gfxd_Color, /* color */ + gfxd_Lodfrac, /* lod fraction (q0.8) */ + gfxd_Cimg, /* color image pointer */ + gfxd_Zimg, /* depth image pointer */ + gfxd_Ac, /* alpha compare mode */ + gfxd_Ad, /* alpha dither mode */ + gfxd_Cd, /* color dither mode */ + gfxd_Ccpre, /* color combiner preset index */ + gfxd_Ccmuxa, /* color mux operand (a) */ + gfxd_Ccmuxb, /* color mux operand (b) */ + gfxd_Ccmuxc, /* color mux operand (c) */ + gfxd_Ccmuxd, /* color mux operand (d) */ + gfxd_Acmuxabd, /* alpha mux operand (a, b, or d) */ + gfxd_Acmuxc, /* alpha mux operand (c) */ + gfxd_Cv, /* color convert operand */ + gfxd_Tc, /* texture convert mode */ + gfxd_Cyc, /* cycle type */ + gfxd_Zs, /* depth source mode */ + gfxd_Ck, /* combine key mode */ + gfxd_Keyscale, /* combine key scale */ + gfxd_Keywidth, /* combine key width */ + gfxd_Zi, /* integer depth */ + gfxd_Rm1, /* cycle 1 render mode */ + gfxd_Rm2, /* cycle 2 render mode */ + gfxd_Sc, /* scissor mode */ + gfxd_Td, /* texture detail mode */ + gfxd_Tf, /* texture filter mode */ + gfxd_Tl, /* texture LOD mode */ + gfxd_Tt, /* textuure LUT mode */ + gfxd_Tp, /* texture perspective mode */ + gfxd_Line, /* texture line size */ + gfxd_Vtx, /* vertex index */ + gfxd_Vtxflag, /* vertex flag */ + gfxd_Dl, /* display list pointer */ + gfxd_Zraw, /* raw depth value (q16.16) */ + gfxd_Dlflag, /* display list flag */ + gfxd_Cr, /* clip ratio */ + gfxd_Num, /* element count */ + gfxd_Fogz, /* fog depth (0 - 1000) */ + gfxd_Mtxptr, /* matrix pointer */ + gfxd_Gm, /* geometry mode */ + gfxd_Mwo_matrix, /* matrix moveword offset */ + gfxd_Linewd, /* line width (1.5 + q7.1) */ + gfxd_Uctext, /* microcode text pointer */ + gfxd_Ucdata, /* microcode data pointer */ + gfxd_Size, /* data size */ + gfxd_Lookatptr, /* lookat pointer */ + gfxd_Mtxparam, /* matrix param */ + gfxd_Mtxstack, /* matrix param (stack select only) */ + gfxd_Mwo_point, /* vertex moveword offset */ + gfxd_Wscale, /* w-component scale (perspnorm) */ + gfxd_Seg, /* segment number */ + gfxd_Segptr, /* segment pointer */ + gfxd_Lightsn, /* dereferenced Lighstn pointer */ + gfxd_Numlights, /* light count (NUMLIGHTS_*) */ + gfxd_Lightnum, /* light number (LIGHT_*) */ + gfxd_Lightptr, /* light pointer */ + gfxd_Tcscale, /* texture coordinate scale */ + gfxd_Switch, /* on-off value */ + gfxd_St, /* vertex coordinate (q10.5) */ + gfxd_Stdelta, /* vertex coordinate delta (q5.10) */ + gfxd_Vtxptr, /* vertex pointer */ + gfxd_Vpptr, /* viewport pointer */ + gfxd_Dram, /* generic dram address */ + gfxd_Sftlo, /* othermode lo shift */ + gfxd_Othermodelo, /* othermode lo value */ + gfxd_Sfthi, /* othermode hi shift */ + gfxd_Othermodehi, /* othermode hi value */ + gfxd_Mw, /* moveword index */ + gfxd_Mwo, /* moveword offset */ + gfxd_Mwo_clip, /* clip ratio moveword offset */ + gfxd_Mwo_lightcol, /* light color moveword offset */ + gfxd_Mv, /* movemem index */ + gfxd_Mvo, /* movemem offset */ + gfxd_Dmem, /* dmem address */ + gfxd_Dmaflag, /* dma io flag */ +}; + +enum +{ + gfxd_Invalid, + gfxd_DPFillRectangle, + gfxd_DPFullSync, + gfxd_DPLoadSync, + gfxd_DPTileSync, + gfxd_DPPipeSync, + gfxd_DPLoadTLUT_pal16, + gfxd_DPLoadTLUT_pal256, + gfxd_DPLoadMultiBlockYuvS, + gfxd_DPLoadMultiBlockYuv, + gfxd_DPLoadMultiBlock_4bS, + gfxd_DPLoadMultiBlock_4b, + gfxd_DPLoadMultiBlockS, + gfxd_DPLoadMultiBlock, + gfxd__DPLoadTextureBlockYuvS, + gfxd__DPLoadTextureBlockYuv, + gfxd__DPLoadTextureBlock_4bS, + gfxd__DPLoadTextureBlock_4b, + gfxd__DPLoadTextureBlockS, + gfxd__DPLoadTextureBlock, + gfxd_DPLoadTextureBlockYuvS, + gfxd_DPLoadTextureBlockYuv, + gfxd_DPLoadTextureBlock_4bS, + gfxd_DPLoadTextureBlock_4b, + gfxd_DPLoadTextureBlockS, + gfxd_DPLoadTextureBlock, + gfxd_DPLoadMultiTileYuv, + gfxd_DPLoadMultiTile_4b, + gfxd_DPLoadMultiTile, + gfxd__DPLoadTextureTileYuv, + gfxd__DPLoadTextureTile_4b, + gfxd__DPLoadTextureTile, + gfxd_DPLoadTextureTileYuv, + gfxd_DPLoadTextureTile_4b, + gfxd_DPLoadTextureTile, + gfxd_DPLoadBlock, + gfxd_DPNoOp, + gfxd_DPNoOpTag, + gfxd_DPPipelineMode, + gfxd_DPSetBlendColor, + gfxd_DPSetEnvColor, + gfxd_DPSetFillColor, + gfxd_DPSetFogColor, + gfxd_DPSetPrimColor, + gfxd_DPSetColorImage, + gfxd_DPSetDepthImage, + gfxd_DPSetTextureImage, + gfxd_DPSetAlphaCompare, + gfxd_DPSetAlphaDither, + gfxd_DPSetColorDither, + gfxd_DPSetCombineMode, + gfxd_DPSetCombineLERP, + gfxd_DPSetConvert, + gfxd_DPSetTextureConvert, + gfxd_DPSetCycleType, + gfxd_DPSetDepthSource, + gfxd_DPSetCombineKey, + gfxd_DPSetKeyGB, + gfxd_DPSetKeyR, + gfxd_DPSetPrimDepth, + gfxd_DPSetRenderMode, + gfxd_DPSetScissor, + gfxd_DPSetScissorFrac, + gfxd_DPSetTextureDetail, + gfxd_DPSetTextureFilter, + gfxd_DPSetTextureLOD, + gfxd_DPSetTextureLUT, + gfxd_DPSetTexturePersp, + gfxd_DPSetTile, + gfxd_DPSetTileSize, + gfxd_SP1Triangle, + gfxd_SP2Triangles, + gfxd_SP1Quadrangle, + gfxd_SPBranchLessZraw, + gfxd_SPBranchList, + gfxd_SPClipRatio, + gfxd_SPCullDisplayList, + gfxd_SPDisplayList, + gfxd_SPEndDisplayList, + gfxd_SPFogPosition, + gfxd_SPForceMatrix, + gfxd_SPSetGeometryMode, + gfxd_SPClearGeometryMode, + gfxd_SPLoadGeometryMode, + gfxd_SPInsertMatrix, + gfxd_SPLine3D, + gfxd_SPLineW3D, + gfxd_SPLoadUcode, + gfxd_SPLookAtX, + gfxd_SPLookAtY, + gfxd_SPLookAt, + gfxd_SPMatrix, + gfxd_SPModifyVertex, + gfxd_SPPerspNormalize, + gfxd_SPPopMatrix, + gfxd_SPPopMatrixN, + gfxd_SPSegment, + gfxd_SPSetLights1, + gfxd_SPSetLights2, + gfxd_SPSetLights3, + gfxd_SPSetLights4, + gfxd_SPSetLights5, + gfxd_SPSetLights6, + gfxd_SPSetLights7, + gfxd_SPNumLights, + gfxd_SPLight, + gfxd_SPLightColor, + gfxd_SPTexture, + gfxd_SPTextureRectangle, + gfxd_SPTextureRectangleFlip, + gfxd_SPVertex, + gfxd_SPViewport, + gfxd_DPLoadTLUTCmd, + gfxd_DPLoadTLUT, + gfxd_BranchZ, + gfxd_DisplayList, + gfxd_DPHalf1, + gfxd_DPHalf2, + gfxd_DPLoadTile, + gfxd_SPGeometryMode, + gfxd_SPSetOtherModeLo, + gfxd_SPSetOtherModeHi, + gfxd_DPSetOtherMode, + gfxd_MoveWd, + gfxd_MoveMem, + gfxd_SPDma_io, + gfxd_SPDmaRead, + gfxd_SPDmaWrite, + gfxd_LoadUcode, + gfxd_SPLoadUcodeEx, + gfxd_TexRect, + gfxd_TexRectFlip, + gfxd_SPNoOp, + gfxd_Special3, + gfxd_Special2, + gfxd_Special1, +}; + +enum +{ + gfxd_stop_on_invalid, + gfxd_stop_on_end, + gfxd_emit_dec_color, + gfxd_emit_q_macro, +}; + +enum +{ + gfxd_endian_big, + gfxd_endian_little, +}; + +enum +{ + gfxd_argfmt_i, + gfxd_argfmt_u, + gfxd_argfmt_f, +}; + +typedef union +{ + int32_t i; + uint32_t u; + float f; +} gfxd_value_t; + +typedef const struct gfxd_ucode *gfxd_ucode_t; + +typedef int gfxd_input_fn_t(void *buf, int count); +void gfxd_input_buffer(const void *buf, int size); +void gfxd_input_fd(int fd); +void gfxd_input_callback(gfxd_input_fn_t *fn); + +typedef int gfxd_output_fn_t(const char *buf, int count); +void gfxd_output_buffer(char *buf, int size); +void gfxd_output_fd(int fd); +void gfxd_output_callback(gfxd_output_fn_t *fn); + +typedef int gfxd_macro_fn_t(void); +void gfxd_macro_fn(gfxd_macro_fn_t *fn); +gfxd_macro_fn_t gfxd_macro_dflt; + +typedef void gfxd_arg_fn_t(int arg_num); +void gfxd_arg_fn(gfxd_arg_fn_t *fn); +gfxd_arg_fn_t gfxd_arg_dflt; + +typedef int gfxd_tlut_fn_t(uint32_t tlut, int32_t idx, int32_t count); +void gfxd_tlut_callback(gfxd_tlut_fn_t *fn); + +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); + +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); + +typedef int gfxd_zimg_fn_t(uint32_t zimg); +void gfxd_zimg_callback(gfxd_zimg_fn_t *fn); + +typedef int gfxd_dl_fn_t(uint32_t dl); +void gfxd_dl_callback(gfxd_dl_fn_t *fn); + +typedef int gfxd_mtx_fn_t(uint32_t mtx); +void gfxd_mtx_callback(gfxd_mtx_fn_t *fn); + +typedef int gfxd_lookat_fn_t(uint32_t lookat, int32_t count); +void gfxd_lookat_callback(gfxd_lookat_fn_t *fn); + +typedef int gfxd_light_fn_t(uint32_t light, int32_t count); +void gfxd_light_callback(gfxd_light_fn_t *fn); + +typedef int gfxd_seg_fn_t(uint32_t seg, int32_t num); +void gfxd_seg_callback(gfxd_seg_fn_t *fn); + +typedef int gfxd_vtx_fn_t(uint32_t vtx, int32_t num); +void gfxd_vtx_callback(gfxd_vtx_fn_t *fn); + +typedef int gfxd_vp_fn_t(uint32_t vp); +void gfxd_vp_callback(gfxd_vp_fn_t *fn); + +typedef int gfxd_uctext_fn_t(uint32_t text, uint32_t size); +void gfxd_uctext_callback(gfxd_uctext_fn_t *fn); + +typedef int gfxd_ucdata_fn_t(uint32_t data, uint32_t size); +void gfxd_ucdata_callback(gfxd_ucdata_fn_t *fn); + +typedef int gfxd_dram_fn_t(uint32_t dram, uint32_t size); +void gfxd_dram_callback(gfxd_dram_fn_t *fn); + +int gfxd_write(const void *buf, int count); +int gfxd_puts(const char *str); +int gfxd_printf(const char *fmt, ...); +int gfxd_print_value(int type, const gfxd_value_t *value); + +void gfxd_target(gfxd_ucode_t ucode); +void gfxd_endian(int endian, int wordsize); +void gfxd_dynamic(const char *arg); +void gfxd_enable(int cap); +void gfxd_disable(int cap); + +int gfxd_execute(void); + +int gfxd_macro_offset(void); +int gfxd_macro_packets(void); +const void *gfxd_macro_data(void); +int gfxd_macro_id(void); +const char *gfxd_macro_name(void); + +int gfxd_arg_count(void); +int gfxd_arg_type(int arg_num); +const char *gfxd_arg_name(int arg_num); +int gfxd_arg_fmt(int arg_num); +const gfxd_value_t *gfxd_arg_value(int arg_num); +const gfxd_value_t *gfxd_value_by_type(int type, int idx); +int gfxd_arg_valid(int arg_num); +int gfxd_arg_callbacks(int arg_num); + +extern const gfxd_ucode_t gfxd_f3d; +extern const gfxd_ucode_t gfxd_f3db; +extern const gfxd_ucode_t gfxd_f3dex; +extern const gfxd_ucode_t gfxd_f3dexb; +extern const gfxd_ucode_t gfxd_f3dex2; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/libgfxd/libgfxd.a b/lib/libgfxd/libgfxd.a Binary files differnew file mode 100644 index 0000000..1f8c0e2 --- /dev/null +++ b/lib/libgfxd/libgfxd.a |
