mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Added support for dlist matrix opcode
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user