1 #include "Vu1ProgramView.h"
2 #include "FrameDump.h"
3 #include "Ps2Const.h"
4
5 #include <QHBoxLayout>
6 #include <QVBoxLayout>
7 #include <QTabWidget>
8
CVu1ProgramView(QWidget * parent,CVu1Vm & virtualMachine)9 CVu1ProgramView::CVu1ProgramView(QWidget* parent, CVu1Vm& virtualMachine)
10 : QWidget(parent)
11 , m_virtualMachine(virtualMachine)
12 , m_vuMemPacketAddress(0)
13 {
14 m_OnMachineStateChangeConnection = virtualMachine.OnMachineStateChange.Connect(std::bind(&CVu1ProgramView::OnMachineStateChange, this));
15 m_OnRunningStateChangeConnection = virtualMachine.OnRunningStateChange.Connect(std::bind(&CVu1ProgramView::OnRunningStateChange, this));
16
17 auto v = new QVBoxLayout(this);
18 auto h = new QHBoxLayout();
19
20 m_disAsm = std::make_unique<CDisAsmWnd>(this, m_virtualMachine, m_virtualMachine.GetVu1Context(), "Vector Unit 1", CQtDisAsmTableModel::DISASM_VU);
21 h->addWidget(m_disAsm.get());
22
23 m_regView = std::make_unique<CRegViewVU>(this, m_virtualMachine.GetVu1Context());
24 h->addWidget(m_regView.get());
25 v->addLayout(h);
26
27 m_memoryView = std::make_unique<CMemoryViewTable>(this);
28 auto getByte = [ctx = m_virtualMachine.GetVu1Context()](uint32 address) {
29 return ctx->m_pMemoryMap->GetByte(address);
30 };
31
32 m_memoryView->Setup(&m_virtualMachine, m_virtualMachine.GetVu1Context(), true);
33 m_memoryView->SetData(getByte, PS2::VUMEM1SIZE);
34
35 auto tab = new QTabWidget(this);
36 v->addWidget(tab);
37
38 m_packetView = std::make_unique<CGifPacketView>(this);
39 tab->addTab(m_memoryView.get(), "VU Memory");
40 tab->addTab(m_packetView.get(), "Packet");
41
42 connect(this, &CVu1ProgramView::OnMachineStateChange, this, &CVu1ProgramView::OnMachineStateChangeMsg);
43 connect(this, &CVu1ProgramView::OnRunningStateChange, this, &CVu1ProgramView::OnRunningStateChangeMsg);
44 }
45
showEvent(QShowEvent * evt)46 void CVu1ProgramView::showEvent(QShowEvent* evt)
47 {
48 QWidget::showEvent(evt);
49 m_memoryView->ShowEvent();
50 }
51
resizeEvent(QResizeEvent * evt)52 void CVu1ProgramView::resizeEvent(QResizeEvent* evt)
53 {
54 QWidget::resizeEvent(evt);
55 m_memoryView->ResizeEvent();
56 }
57
UpdateState(CGSHandler * gs,CGsPacketMetadata * metadata,DRAWINGKICK_INFO *)58 void CVu1ProgramView::UpdateState(CGSHandler* gs, CGsPacketMetadata* metadata, DRAWINGKICK_INFO*)
59 {
60 #ifdef DEBUGGER_INCLUDED
61 memcpy(m_virtualMachine.GetMicroMem1(), metadata->microMem1, PS2::MICROMEM1SIZE);
62 memcpy(m_virtualMachine.GetVuMem1(), metadata->vuMem1, PS2::VUMEM1SIZE);
63 memcpy(&m_virtualMachine.GetVu1Context()->m_State, &metadata->vu1State, sizeof(MIPSSTATE));
64 m_virtualMachine.SetVpu1Top(metadata->vpu1Top);
65 m_virtualMachine.SetVpu1Itop(metadata->vpu1Itop);
66 m_vuMemPacketAddress = metadata->vuMemPacketAddress;
67 #endif
68 OnMachineStateChange();
69 }
70
StepVu1()71 void CVu1ProgramView::StepVu1()
72 {
73 m_virtualMachine.StepVu1();
74 }
75
OnMachineStateChangeMsg()76 void CVu1ProgramView::OnMachineStateChangeMsg()
77 {
78 // we're triggering PAUSED status to force the view to move to current location
79 auto newState = CVirtualMachine::STATUS::PAUSED;
80 m_disAsm->HandleRunningStateChange(newState);
81 m_memoryView->HandleRunningStateChange(newState);
82
83 m_packetView->SetPacket(m_virtualMachine.GetVuMem1(), m_vuMemPacketAddress, PS2::VUMEM1SIZE - m_vuMemPacketAddress);
84 m_regView->Update();
85 }
86
OnRunningStateChangeMsg()87 void CVu1ProgramView::OnRunningStateChangeMsg()
88 {
89 auto newState = CVirtualMachine::STATUS::PAUSED;
90 m_disAsm->HandleRunningStateChange(newState);
91 m_memoryView->HandleRunningStateChange(newState);
92 }
93