CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Windows/GEDebugger/TabDisplayLists.cpp
Views: 1401
#include "Windows/GEDebugger/TabDisplayLists.h"1#include "Windows/GEDebugger/GEDebugger.h"2#include "Windows/GEDebugger/CtrlDisplayListView.h"3#include "Windows/MainWindow.h"4#include "Windows/main.h"5#include "GPU/GPUInterface.h"6#include "GPU/Common/GPUDebugInterface.h"7#include "GPU/GPUState.h"8#include "Core/Config.h"9#include <windowsx.h>10#include <commctrl.h>1112enum { WM_GEDBG_LISTS_CHANGELIST = WM_USER+400, WM_GEDBG_LISTS_GOTOSTACKPC };1314//15// CtrlDisplayListStack16//1718enum { DLS_PC = 0, DLS_BASE, DLS_OFFSET, DLS_COLUMNCOUNT };1920const GenericListViewColumn displayListStackColumns[3] = {21{ L"PC", 0.34f },22{ L"Base", 0.33f },23{ L"Offset", 0.33f },24};2526GenericListViewDef displayListStackListDef = {27displayListStackColumns, ARRAY_SIZE(displayListStackColumns), NULL, false28};2930CtrlDisplayListStack::CtrlDisplayListStack(HWND hwnd): GenericListControl(hwnd,displayListStackListDef)31{32list.stackptr = 0;33Update();34}3536void CtrlDisplayListStack::GetColumnText(wchar_t* dest, int row, int col)37{38if (row < 0 || row >= (int)ARRAY_SIZE(list.stack)) {39return;40}41DisplayListStackEntry value = list.stack[row];4243switch (col)44{45case DLS_BASE:46wsprintf(dest,L"0x%08X",value.baseAddr);47break;48case DLS_OFFSET:49wsprintf(dest,L"0x%08X",value.offsetAddr);50break;51case DLS_PC:52wsprintf(dest,L"0x%08X",value.pc);53break;54}55}5657void CtrlDisplayListStack::OnDoubleClick(int itemIndex, int column)58{59SendMessage(GetParent(GetHandle()),WM_GEDBG_LISTS_GOTOSTACKPC,itemIndex,0);60}616263//64// CtrlDisplayListStack65//6667enum { ADL_STARTPC = 0, ADL_PC, ADL_STALL, ADL_STATE, APL_STARTED, APL_INTERRUPTED, ADL_COLUMNCOUNT };6869const GenericListViewColumn allDisplayListsColumns[ADL_COLUMNCOUNT] = {70{ L"Start PC", 0.18f },71{ L"PC", 0.18f },72{ L"Stall", 0.18f },73{ L"State", 0.16f },74{ L"Started", 0.15f },75{ L"Interrupted", 0.15f },76};7778GenericListViewDef allDisplayListsListDef = {79allDisplayListsColumns, ARRAY_SIZE(allDisplayListsColumns), NULL, false80};8182CtrlAllDisplayLists::CtrlAllDisplayLists(HWND hwnd): GenericListControl(hwnd,allDisplayListsListDef)83{84Update();85}8687void CtrlAllDisplayLists::GetColumnText(wchar_t* dest, int row, int col)88{89if (row < 0 || row >= (int)lists.size()) {90return;91}92DisplayList& list = lists[row];9394switch (col)95{96case ADL_STALL:97wsprintf(dest,L"0x%08X",list.stall);98break;99case ADL_PC:100wsprintf(dest,L"0x%08X",list.pc);101break;102case ADL_STARTPC:103wsprintf(dest,L"0x%08X",list.startpc);104break;105case ADL_STATE:106switch (list.state)107{108case PSP_GE_DL_STATE_NONE:109wcscpy(dest,L"None");110break;111case PSP_GE_DL_STATE_QUEUED:112wcscpy(dest,L"Queued");113break;114case PSP_GE_DL_STATE_RUNNING:115wcscpy(dest,L"Running");116break;117case PSP_GE_DL_STATE_COMPLETED:118wcscpy(dest,L"Completed");119break;120case PSP_GE_DL_STATE_PAUSED:121wcscpy(dest,L"Paused");122break;123}124break;125case APL_STARTED:126wcscpy(dest,list.started ? L"Yes" : L"No");127break;128case APL_INTERRUPTED:129wcscpy(dest,list.interrupted ? L"Yes" : L"No");130break;131}132}133134bool CtrlAllDisplayLists::WindowMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT& returnValue)135{136switch (msg)137{138case WM_KEYDOWN:139if (wParam == VK_RETURN)140{141int item = GetSelectedIndex();142SendMessage(GetParent(GetHandle()),WM_GEDBG_LISTS_CHANGELIST,item,0);143}144break;145case WM_GETDLGCODE:146if (lParam && ((MSG*)lParam)->message == WM_KEYDOWN)147{148if (wParam == VK_RETURN)149{150returnValue = DLGC_WANTMESSAGE;151return true;152}153}154}155156return false;157}158159void CtrlAllDisplayLists::OnDoubleClick(int itemIndex, int column)160{161SendMessage(GetParent(GetHandle()),WM_GEDBG_LISTS_CHANGELIST,itemIndex,0);162}163164165//166// TabDisplayLists167//168169TabDisplayLists::TabDisplayLists(HINSTANCE _hInstance, HWND _hParent)170: Dialog((LPCSTR)IDD_TABDISPLAYLISTS, _hInstance, _hParent)171{172displayList = CtrlDisplayListView::getFrom(GetDlgItem(m_hDlg,IDC_GEDBG_LISTS_SELECTEDLIST));173174stack = new CtrlDisplayListStack(GetDlgItem(m_hDlg,IDC_GEDBG_LISTS_STACK));175allLists = new CtrlAllDisplayLists(GetDlgItem(m_hDlg,IDC_GEDBG_LISTS_ALLLISTS));176177activeList = -1;178}179180TabDisplayLists::~TabDisplayLists()181{182delete stack;183delete allLists;184}185186void TabDisplayLists::UpdateSize(WORD width, WORD height)187{188struct Position189{190int x,y;191int w,h;192};193194Position positions[3];195int borderMargin = 5;196int betweenControlsMargin = 5;197198// All Lists199positions[0].x = borderMargin;200positions[0].y = borderMargin;201positions[0].w = width*2/3;202positions[0].h = std::min(height * 2 / 5, 200);203204// Stack205positions[1].x = positions[0].x+positions[0].w+betweenControlsMargin;206positions[1].y = borderMargin;207positions[1].w = width-positions[1].x-borderMargin;208positions[1].h = positions[0].h;209210// Current List211positions[2].x = borderMargin;212positions[2].y = positions[0].y+positions[0].h+betweenControlsMargin;213positions[2].w = width-2*borderMargin;214positions[2].h = height-positions[2].y-borderMargin;215216HWND handles[3] = {217GetDlgItem(m_hDlg,IDC_GEDBG_LISTS_ALLLISTS),218GetDlgItem(m_hDlg,IDC_GEDBG_LISTS_STACK),219GetDlgItem(m_hDlg,IDC_GEDBG_LISTS_SELECTEDLIST)220};221222for (int i = 0; i < 3; i++)223{224MoveWindow(handles[i],positions[i].x,positions[i].y,positions[i].w,positions[i].h,TRUE);225}226}227228void TabDisplayLists::Update(bool reload)229{230if (reload && gpuDebug != NULL)231{232lists = gpuDebug->ActiveDisplayLists();233}234235if (activeList != -1)236{237DisplayList currentList = lists[activeList];238239displayList->setDisplayList(currentList);240stack->setDisplayList(currentList);241}242243allLists->setDisplayLists(lists);244}245246BOOL TabDisplayLists::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {247switch (message) {248case WM_INITDIALOG:249return TRUE;250251case WM_SIZE:252UpdateSize(LOWORD(lParam), HIWORD(lParam));253return TRUE;254255case WM_NOTIFY:256switch (wParam)257{258case IDC_GEDBG_LISTS_STACK:259SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, stack->HandleNotify(lParam));260return TRUE;261case IDC_GEDBG_LISTS_ALLLISTS:262SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, allLists->HandleNotify(lParam));263return TRUE;264}265break;266267case WM_GEDBG_LISTS_CHANGELIST:268activeList = wParam;269Update();270break;271272case WM_GEDBG_LISTS_GOTOSTACKPC:273{274u32 pc = lists[activeList].stack[wParam].pc;275displayList->gotoAddr(pc);276}277break;278279case WM_GEDBG_TOGGLEPCBREAKPOINT:280SendMessage(GetParent(m_hDlg),message,wParam,lParam);281break;282283}284285return FALSE;286}287288289