summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2025-01-25 14:03:07 -0600
committerKiritoDv <kiritodev01@gmail.com>2025-01-25 14:03:07 -0600
commit7bb9feddd8275fd5417d0ff0d2300ba688fa89b7 (patch)
tree60520889dd6017df4b357dec9ec1d46b44b2f52d /src
parent37258535fe2cde3e00149314778f135adf76d42b (diff)
Added support for dlist matrix opcode
Diffstat (limited to 'src')
-rw-r--r--src/factories/DisplayListFactory.cpp31
-rw-r--r--src/factories/DisplayListOverrides.cpp15
-rw-r--r--src/factories/DisplayListOverrides.h1
-rw-r--r--src/factories/MtxFactory.cpp7
4 files changed, 52 insertions, 2 deletions
diff --git a/src/factories/DisplayListFactory.cpp b/src/factories/DisplayListFactory.cpp
index c64fab8..86f311e 100644
--- a/src/factories/DisplayListFactory.cpp
+++ b/src/factories/DisplayListFactory.cpp
@@ -16,6 +16,7 @@
std::unordered_map<std::string, uint8_t> gF3DTable = {
{ "G_VTX", 0x04 },
{ "G_DL", 0x06 },
+ { "G_MTX", 0x1 },
{ "G_ENDDL", 0xB8 },
{ "G_SETTIMG", 0xFD },
{ "G_MOVEMEM", 0x03 },
@@ -29,6 +30,7 @@ std::unordered_map<std::string, uint8_t> gF3DTable = {
std::unordered_map<std::string, uint8_t> gF3DExTable = {
{ "G_VTX", 0x04 },
{ "G_DL", 0x06 },
+ { "G_MTX", 0x1 },
{ "G_ENDDL", 0xB8 },
{ "G_SETTIMG", 0xFD },
{ "G_MOVEMEM", 0x03 },
@@ -42,6 +44,7 @@ std::unordered_map<std::string, uint8_t> gF3DExTable = {
std::unordered_map<std::string, uint8_t> gF3DEx2Table = {
{ "G_VTX", 0x01 },
{ "G_DL", 0xDE },
+ { "G_MTX", 0xDA },
{ "G_ENDDL", 0xDF },
{ "G_SETTIMG", 0xFD },
{ "G_MOVEMEM", 0xDC },
@@ -143,6 +146,7 @@ ExportResult DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar
gfxd_lightsn_callback(GFXDOverride::Lights);
gfxd_light_callback(GFXDOverride::Light);
gfxd_vp_callback(GFXDOverride::Viewport);
+ gfxd_mtx_callback(GFXDOverride::Matrix);
GFXDSetGBIVersion();
if(searchTable.has_value()){
@@ -442,7 +446,6 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
N64Gfx value = gsDPSetTextureOTRImage(C0(21, 3), C0(19, 2), C0(0, 10), ptr);
w0 = value.words.w0;
w1 = value.words.w1;
-
writer.Write(w0);
writer.Write(w1);
@@ -463,6 +466,32 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
}
}
+ if(opcode == GBI(G_MTX)) {
+ auto ptr = w1;
+ auto dec = Companion::Instance->GetNodeByAddr(ptr);
+
+ w0 &= 0x00FFFFFF;
+ w0 += G_MTX_OTR << 24;
+ w1 = 0;
+
+ writer.Write(w0);
+ writer.Write(w1);
+
+ if(dec.has_value()){
+ uint64_t hash = CRC64(std::get<0>(dec.value()).c_str());
+
+ if(hash == 0){
+ throw std::runtime_error("Matrix hash is 0 for " + std::get<0>(dec.value()));
+ }
+
+ SPDLOG_INFO("Found matrix: 0x{:X} Hash: 0x{:X} Path: {}", ptr, hash, std::get<0>(dec.value()));
+ w0 = hash >> 32;
+ w1 = hash & 0xFFFFFFFF;
+ } else {
+ SPDLOG_WARN("Could not find matrix at 0x{:X}", ptr);
+ }
+ }
+
writer.Write(w0);
writer.Write(w1);
}
diff --git a/src/factories/DisplayListOverrides.cpp b/src/factories/DisplayListOverrides.cpp
index f684899..7284d29 100644
--- a/src/factories/DisplayListOverrides.cpp
+++ b/src/factories/DisplayListOverrides.cpp
@@ -184,6 +184,21 @@ int Viewport(uint32_t ptr) {
SPDLOG_TRACE("Could not find viewport to override at 0x{:X}", ptr);
return 0;
}
+
+int Matrix(uint32_t ptr) {
+ auto dec = Companion::Instance->GetNodeByAddr(ptr);
+
+ if(dec.has_value()){
+ auto node = std::get<1>(dec.value());
+ auto symbol = GetSafeNode<std::string>(node, "symbol");
+ SPDLOG_INFO("Found Matrix: 0x{:X} Symbol: {}", ptr, symbol);
+ gfxd_puts(("&" + symbol).c_str());
+ return 1;
+ }
+
+ SPDLOG_TRACE("Could not find viewport to override at 0x{:X}", ptr);
+ return 0;
+}
#endif
std::optional<std::tuple<std::string, YAML::Node>> GetVtxOverlap(uint32_t ptr){
diff --git a/src/factories/DisplayListOverrides.h b/src/factories/DisplayListOverrides.h
index e580f7c..dc568a2 100644
--- a/src/factories/DisplayListOverrides.h
+++ b/src/factories/DisplayListOverrides.h
@@ -47,6 +47,7 @@ int Lights(uint32_t lightsn, int32_t count);
int Light(uint32_t light);
int DisplayList(uint32_t dl);
int Viewport(uint32_t vp);
+int Matrix(uint32_t mtx);
#endif
void RegisterVTXOverlap(uint32_t ptr, std::tuple<std::string, YAML::Node>& vtx);
std::optional<std::tuple<std::string, YAML::Node>> GetVtxOverlap(uint32_t ptr);
diff --git a/src/factories/MtxFactory.cpp b/src/factories/MtxFactory.cpp
index ba5003f..9d84c56 100644
--- a/src/factories/MtxFactory.cpp
+++ b/src/factories/MtxFactory.cpp
@@ -105,12 +105,17 @@ ExportResult MtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParse
ExportResult MtxBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto mtx = std::static_pointer_cast<MtxData>(raw);
auto writer = LUS::BinaryWriter();
+ auto floats = GetSafeNode(node, "floats", false);
WriteHeader(writer, Torch::ResourceType::Matrix, 0);
for(size_t i = 0; i < 4; i++){
for(size_t j = 0; j < 4; j++){
- writer.Write((uint32_t) BSWAP32(mtx->mMtxs[0].mt.mint[i][j]));
+ if(floats){
+ writer.Write(mtx->mMtxs[0].mtx[i * 4 + j]);
+ } else {
+ writer.Write(mtx->mMtxs[0].mt.mint[i][j]);
+ }
}
}
writer.Finish(write);