Show register updates before primitive updates

This also shows the register updates for object 0, which were previously not visible(!)
This commit is contained in:
Pokechu22 2021-03-03 17:13:33 -08:00
parent 83f7c41e31
commit 1dc3ff5879
1 changed files with 153 additions and 138 deletions

View File

@ -171,48 +171,33 @@ void FIFOAnalyzer::UpdateDetails()
if (!FifoPlayer::GetInstance().IsPlaying()) if (!FifoPlayer::GetInstance().IsPlaying())
return; return;
auto items = m_tree_widget->selectedItems(); const auto items = m_tree_widget->selectedItems();
if (items.isEmpty() || items[0]->data(0, OBJECT_ROLE).isNull()) if (items.isEmpty() || items[0]->data(0, OBJECT_ROLE).isNull())
return; return;
int frame_nr = items[0]->data(0, FRAME_ROLE).toInt(); const u32 frame_nr = items[0]->data(0, FRAME_ROLE).toUInt();
int object_nr = items[0]->data(0, OBJECT_ROLE).toInt(); const u32 object_nr = items[0]->data(0, OBJECT_ROLE).toUInt();
const auto& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr); const auto& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr);
const auto& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr); const auto& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr);
const u8* objectdata_start = &fifo_frame.fifoData[frame_info.objectStarts[object_nr]]; // Note that frame_info.objectStarts[object_nr] is the start of the primitive data,
const u8* objectdata_end = &fifo_frame.fifoData[frame_info.objectEnds[object_nr]]; // but we want to start with the register updates which happen before that.
const u8* objectdata = objectdata_start; const u32 object_start = (object_nr == 0 ? 0 : frame_info.objectEnds[object_nr - 1]);
const std::ptrdiff_t obj_offset = const u32 object_nonprim_size = frame_info.objectStarts[object_nr] - object_start;
objectdata_start - &fifo_frame.fifoData[frame_info.objectStarts[0]]; const u32 object_size = frame_info.objectEnds[object_nr] - object_start;
int cmd = *objectdata++; const u8* const object = &fifo_frame.fifoData[object_start];
int stream_size = Common::swap16(objectdata);
objectdata += 2;
QString new_label = QStringLiteral("%1: %2 %3 ")
.arg(obj_offset, 8, 16, QLatin1Char('0'))
.arg(cmd, 2, 16, QLatin1Char('0'))
.arg(stream_size, 4, 16, QLatin1Char('0'));
if (stream_size && ((objectdata_end - objectdata) % stream_size))
new_label += tr("NOTE: Stream size doesn't match actual data length\n");
while (objectdata < objectdata_end) u32 object_offset = 0;
new_label += QStringLiteral("%1").arg(*objectdata++, 2, 16, QLatin1Char('0')); while (object_offset < object_nonprim_size)
m_detail_list->addItem(new_label);
m_object_data_offsets.push_back(0);
// Between objectdata_end and next_objdata_start, there are register setting commands
if (object_nr + 1 < static_cast<int>(frame_info.objectStarts.size()))
{ {
const u8* next_objdata_start = &fifo_frame.fifoData[frame_info.objectStarts[object_nr + 1]]; QString new_label;
while (objectdata < next_objdata_start) const u32 start_offset = object_offset;
{ m_object_data_offsets.push_back(start_offset);
m_object_data_offsets.push_back(objectdata - objectdata_start);
int new_offset = objectdata - &fifo_frame.fifoData[frame_info.objectStarts[0]]; const u8 command = object[object_offset++];
int command = *objectdata++;
switch (command) switch (command)
{ {
case OpcodeDecoder::GX_NOP: case OpcodeDecoder::GX_NOP:
@ -229,9 +214,10 @@ void FIFOAnalyzer::UpdateDetails()
case OpcodeDecoder::GX_LOAD_CP_REG: case OpcodeDecoder::GX_LOAD_CP_REG:
{ {
u32 cmd2 = *objectdata++; const u8 cmd2 = object[object_offset++];
u32 value = Common::swap32(objectdata); const u32 value = Common::swap32(&object[object_offset]);
objectdata += 4; object_offset += 4;
const auto [name, desc] = GetCPRegInfo(cmd2, value); const auto [name, desc] = GetCPRegInfo(cmd2, value);
ASSERT(!name.empty()); ASSERT(!name.empty());
@ -244,23 +230,21 @@ void FIFOAnalyzer::UpdateDetails()
case OpcodeDecoder::GX_LOAD_XF_REG: case OpcodeDecoder::GX_LOAD_XF_REG:
{ {
const auto [name, desc] = GetXFTransferInfo(objectdata); const auto [name, desc] = GetXFTransferInfo(&object[object_offset]);
u32 cmd2 = Common::swap32(objectdata); const u32 cmd2 = Common::swap32(&object[object_offset]);
objectdata += 4; object_offset += 4;
ASSERT(!name.empty()); ASSERT(!name.empty());
u8 streamSize = ((cmd2 >> 16) & 15) + 1; const u8 stream_size = ((cmd2 >> 16) & 15) + 1;
const u8* stream_start = objectdata;
const u8* stream_end = stream_start + streamSize * 4;
new_label = QStringLiteral("XF %1 ").arg(cmd2, 8, 16, QLatin1Char('0')); new_label = QStringLiteral("XF %1 ").arg(cmd2, 8, 16, QLatin1Char('0'));
while (objectdata < stream_end)
{
new_label += QStringLiteral("%1").arg(*objectdata++, 2, 16, QLatin1Char('0'));
if (((objectdata - stream_start) % 4) == 0) for (u8 i = 0; i < stream_size; i++)
new_label += QLatin1Char(' '); {
const u32 value = Common::swap32(&object[object_offset]);
object_offset += 4;
new_label += QStringLiteral("%1 ").arg(value, 8, 16, QLatin1Char('0'));
} }
new_label += QStringLiteral(" ") + QString::fromStdString(name); new_label += QStringLiteral(" ") + QString::fromStdString(name);
@ -268,18 +252,20 @@ void FIFOAnalyzer::UpdateDetails()
break; break;
case OpcodeDecoder::GX_LOAD_INDX_A: case OpcodeDecoder::GX_LOAD_INDX_A:
new_label = QStringLiteral("LOAD INDX A");
object_offset += 4;
break;
case OpcodeDecoder::GX_LOAD_INDX_B: case OpcodeDecoder::GX_LOAD_INDX_B:
new_label = QStringLiteral("LOAD INDX B");
object_offset += 4;
break;
case OpcodeDecoder::GX_LOAD_INDX_C: case OpcodeDecoder::GX_LOAD_INDX_C:
new_label = QStringLiteral("LOAD INDX C");
object_offset += 4;
break;
case OpcodeDecoder::GX_LOAD_INDX_D: case OpcodeDecoder::GX_LOAD_INDX_D:
{ new_label = QStringLiteral("LOAD INDX D");
objectdata += 4; object_offset += 4;
new_label = (command == OpcodeDecoder::GX_LOAD_INDX_A) ?
QStringLiteral("LOAD INDX A") :
(command == OpcodeDecoder::GX_LOAD_INDX_B) ?
QStringLiteral("LOAD INDX B") :
(command == OpcodeDecoder::GX_LOAD_INDX_C) ? QStringLiteral("LOAD INDX C") :
QStringLiteral("LOAD INDX D");
}
break; break;
case OpcodeDecoder::GX_CMD_CALL_DL: case OpcodeDecoder::GX_CMD_CALL_DL:
@ -287,15 +273,15 @@ void FIFOAnalyzer::UpdateDetails()
// call to start them // call to start them
// That is done to make it easier to track where memory is updated // That is done to make it easier to track where memory is updated
ASSERT(false); ASSERT(false);
objectdata += 8; object_offset += 8;
new_label = QStringLiteral("CALL DL"); new_label = QStringLiteral("CALL DL");
break; break;
case OpcodeDecoder::GX_LOAD_BP_REG: case OpcodeDecoder::GX_LOAD_BP_REG:
{ {
const u8 cmd2 = *objectdata++; const u8 cmd2 = object[object_offset++];
const u32 cmddata = Common::swap24(objectdata); const u32 cmddata = Common::swap24(&object[object_offset]);
objectdata += 3; object_offset += 3;
const auto [name, desc] = GetBPRegInfo(cmd2, cmddata); const auto [name, desc] = GetBPRegInfo(cmd2, cmddata);
ASSERT(!name.empty()); ASSERT(!name.empty());
@ -309,13 +295,42 @@ void FIFOAnalyzer::UpdateDetails()
default: default:
new_label = tr("Unexpected 0x80 call? Aborting..."); new_label = tr("Unexpected 0x80 call? Aborting...");
objectdata = static_cast<const u8*>(next_objdata_start); object_offset = object_nonprim_size;
break; break;
} }
new_label = QStringLiteral("%1: ").arg(new_offset, 8, 16, QLatin1Char('0')) + new_label; new_label = QStringLiteral("%1: ").arg(object_start + start_offset, 8, 16, QLatin1Char('0')) +
new_label;
m_detail_list->addItem(new_label); m_detail_list->addItem(new_label);
} }
// Object primitive data
ASSERT(object_offset == object_nonprim_size);
m_object_data_offsets.push_back(object_offset);
const u8 cmd = object[object_offset++];
const u16 vertex_count = Common::swap16(&object[object_offset]);
object_offset += 2;
const u32 object_prim_size = object_size - object_offset;
QString new_label = QStringLiteral("%1: %2 %3 ")
.arg(object_start + object_offset, 8, 16, QLatin1Char('0'))
.arg(cmd, 2, 16, QLatin1Char('0'))
.arg(vertex_count, 4, 16, QLatin1Char('0'));
while (object_offset < object_size)
{
u32 byte = object[object_offset++];
new_label += QStringLiteral("%1").arg(byte, 2, 16, QLatin1Char('0'));
} }
if (vertex_count != 0 && (object_prim_size % vertex_count) != 0)
{
new_label += QLatin1Char{'\n'};
new_label += tr("NOTE: Stream size doesn't match actual data length");
}
m_detail_list->addItem(new_label);
} }
void FIFOAnalyzer::BeginSearch() void FIFOAnalyzer::BeginSearch()
@ -474,20 +489,20 @@ void FIFOAnalyzer::UpdateDescription()
if (!FifoPlayer::GetInstance().IsPlaying()) if (!FifoPlayer::GetInstance().IsPlaying())
return; return;
auto items = m_tree_widget->selectedItems(); const auto items = m_tree_widget->selectedItems();
if (items.isEmpty() || m_object_data_offsets.empty()) if (items.isEmpty() || m_object_data_offsets.empty())
return; return;
int frame_nr = items[0]->data(0, FRAME_ROLE).toInt(); const u32 frame_nr = items[0]->data(0, FRAME_ROLE).toUInt();
int object_nr = items[0]->data(0, OBJECT_ROLE).toInt(); const u32 object_nr = items[0]->data(0, OBJECT_ROLE).toUInt();
int entry_nr = m_detail_list->currentRow(); const u32 entry_nr = m_detail_list->currentRow();
const AnalyzedFrameInfo& frame = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr); const AnalyzedFrameInfo& frame_info = FifoPlayer::GetInstance().GetAnalyzedFrameInfo(frame_nr);
const FifoFrameInfo& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr); const FifoFrameInfo& fifo_frame = FifoPlayer::GetInstance().GetFile()->GetFrame(frame_nr);
const u8* cmddata = const u32 object_start = (object_nr == 0 ? 0 : frame_info.objectEnds[object_nr - 1]);
&fifo_frame.fifoData[frame.objectStarts[object_nr]] + m_object_data_offsets[entry_nr]; const u8* cmddata = &fifo_frame.fifoData[object_start + m_object_data_offsets[entry_nr]];
// TODO: Not sure whether we should bother translating the descriptions // TODO: Not sure whether we should bother translating the descriptions