project64/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp

408 lines
10 KiB
C++
Raw Normal View History

2017-08-18 05:08:22 +00:00
#include "stdafx.h"
2022-09-21 05:16:07 +00:00
2017-08-18 05:08:22 +00:00
#include "DMALog.h"
2022-09-21 05:16:07 +00:00
#include "DebuggerUI.h"
#include <fstream>
2017-08-18 05:08:22 +00:00
2022-09-21 05:16:07 +00:00
CDebugDMALogView::CDebugDMALogView(CDebuggerUI * debugger) :
CDebugDialog<CDebugDMALogView>(debugger)
2017-08-18 05:08:22 +00:00
{
2019-12-25 00:41:20 +00:00
m_DMALog = debugger->DMALog();
m_bFilterChanged = false;
m_bUniqueRomAddresses = true;
m_bCustomDrawClrNext = false;
2017-08-18 05:08:22 +00:00
}
CDebugDMALogView::~CDebugDMALogView()
{
}
/*
bool CDebugDMALogView::FilterEntry(int dmaLogIndex)
{
2019-12-25 00:41:20 +00:00
DMALogEntry entry = m_Debugger->DMALog()->at(dmaLogIndex);
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
for (int i = 0; i < dmaLogIndex; i++)
{
DMALogEntry testEntry = m_Debugger->DMALog()->at(i);
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
// Don't show if another entry has the same ROM address
if (entry.romAddr == testEntry.romAddr)
{
return false;
}
}
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
return true;
2017-08-18 05:08:22 +00:00
}
*/
2017-08-18 05:08:22 +00:00
void CDebugDMALogView::RefreshList()
{
2021-04-12 11:35:39 +00:00
if (g_Rom == nullptr)
2019-12-25 00:41:20 +00:00
{
return;
}
2022-09-21 05:16:07 +00:00
uint8_t * rom = g_Rom->GetRomAddress();
2019-12-25 00:41:20 +00:00
// Get scrollbar state
SCROLLINFO scroll;
scroll.cbSize = sizeof(SCROLLINFO);
scroll.fMask = SIF_ALL;
m_DMAList.GetScrollInfo(SB_VERT, &scroll);
bool bScrolledDown = false;
if ((scroll.nPage + scroll.nPos) - 1 == (uint32_t)scroll.nMax)
{
bScrolledDown = true;
}
int startIndex;
int dmaLogSize = m_Debugger->DMALog()->GetNumEntries();
2022-09-21 05:16:07 +00:00
HWND hWndExportBtn = GetDlgItem(IDC_EXPORT_BTN);
2019-12-25 00:41:20 +00:00
if (dmaLogSize == 0)
{
// Reset
m_DMAList.DeleteAllItems();
startIndex = 0;
m_bFilterChanged = false;
::EnableWindow(hWndExportBtn, FALSE);
2019-12-25 00:41:20 +00:00
}
else
{
// Continue from last index
startIndex = m_nLastStartIndex;
::EnableWindow(hWndExportBtn, TRUE);
2019-12-25 00:41:20 +00:00
}
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
m_DMAList.SetRedraw(FALSE);
int itemIndex = m_DMAList.GetItemCount();
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
for (int i = startIndex; i < dmaLogSize; i++)
{
2022-09-21 05:16:07 +00:00
DMALOGENTRY * lpEntry = m_DMALog->GetEntryByIndex(i);
2019-12-25 00:41:20 +00:00
//if (!FilterEntry(i))
//{
// continue;
//}
2022-09-21 05:16:07 +00:00
2020-05-12 12:19:05 +00:00
m_DMAList.AddItem(itemIndex, 0, stdstr_f("%08X", lpEntry->romAddr).ToUTF16().c_str());
m_DMAList.AddItem(itemIndex, 1, stdstr_f("%08X", lpEntry->ramAddr).ToUTF16().c_str());
m_DMAList.AddItem(itemIndex, 2, stdstr_f("%08X (%d)", lpEntry->length, lpEntry->length).ToUTF16().c_str());
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
union
{
uint32_t u32;
uint8_t sz[5];
2022-09-21 05:16:07 +00:00
} sig = {0};
2017-08-18 05:08:22 +00:00
2019-04-02 19:16:39 +00:00
if (lpEntry->romAddr < g_Rom->GetRomSize())
{
2022-09-21 05:16:07 +00:00
sig.u32 = _byteswap_ulong(*(uint32_t *)&rom[lpEntry->romAddr]);
2019-04-02 19:16:39 +00:00
}
2017-08-18 05:08:22 +00:00
// TODO: checkbox to display all in hex
2019-12-25 00:41:20 +00:00
if (isalnum(sig.sz[0]) && isalnum(sig.sz[1]) && isalnum(sig.sz[2]) && isalnum(sig.sz[3]))
{
2022-09-21 05:16:07 +00:00
m_DMAList.AddItem(itemIndex, 4, stdstr((char *)sig.sz).ToUTF16().c_str());
2019-12-25 00:41:20 +00:00
}
itemIndex++;
}
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
if (bScrolledDown)
{
m_DMAList.EnsureVisible(m_DMAList.GetItemCount() - 1, FALSE);
}
m_DMAList.SetRedraw(TRUE);
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
m_nLastStartIndex = dmaLogSize;
2017-08-18 05:08:22 +00:00
}
void CDebugDMALogView::Export(void)
{
OPENFILENAME openfilename;
TCHAR filePath[_MAX_PATH];
memset(&filePath, 0, sizeof(filePath));
memset(&openfilename, 0, sizeof(openfilename));
2022-09-21 05:16:07 +00:00
wsprintf(filePath, L"*.csv");
2022-09-26 02:31:54 +00:00
const TCHAR * filters = L"Comma separated values (*.csv)\0*.csv;\0Plain text (*.txt)\0*.txt;\0";
2022-09-21 05:16:07 +00:00
const char * extensions[] = {"", ".csv", ".txt"};
openfilename.lStructSize = sizeof(openfilename);
openfilename.hwndOwner = (HWND)m_hWnd;
openfilename.lpstrFilter = filters;
openfilename.lpstrFile = filePath;
openfilename.lpstrInitialDir = L".";
openfilename.nMaxFile = MAX_PATH;
openfilename.Flags = OFN_HIDEREADONLY;
if (GetSaveFileName(&openfilename))
{
stdstr path;
path.FromUTF16(filePath);
if (openfilename.nFileExtension == 0)
{
path += extensions[openfilename.nFilterIndex];
}
std::ofstream file;
file.open(path, std::ios::out | std::ios::binary);
if (!file.is_open())
{
return;
}
file << "ROM Address,RAM Address,Length\r\n";
size_t numEntries = m_DMALog->GetNumEntries();
for (size_t nEntry = 0; nEntry < numEntries; nEntry++)
{
2022-09-21 05:16:07 +00:00
DMALOGENTRY * entry = m_DMALog->GetEntryByIndex(nEntry);
file << stdstr_f("0x%08X,0x%08X,0x%08X\r\n",
2022-09-21 05:16:07 +00:00
entry->romAddr, entry->ramAddr, entry->length);
}
file.close();
}
}
2022-09-21 05:16:07 +00:00
LRESULT CDebugDMALogView::OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
2017-08-18 05:08:22 +00:00
{
2019-12-25 00:41:20 +00:00
//RefreshList();
return FALSE;
2017-08-18 05:08:22 +00:00
}
2022-09-21 05:16:07 +00:00
LRESULT CDebugDMALogView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
2017-08-18 05:08:22 +00:00
{
2019-12-25 00:41:20 +00:00
DlgResize_Init(false, true);
DlgSavePos_Init(DebuggerUI_DMALogPos);
2019-12-25 00:41:20 +00:00
m_bConvertingAddress = false;
m_nLastStartIndex = 0;
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
m_DMAList.Attach(GetDlgItem(IDC_DMA_LIST));
2019-04-02 19:16:39 +00:00
m_DMARamEdit.Attach(GetDlgItem(IDC_DMA_RAM_EDIT));
m_DMARomEdit.Attach(GetDlgItem(IDC_DMA_ROM_EDIT));
m_BlockInfo.Attach(GetDlgItem(IDC_BLOCK_INFO));
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
m_DMAList.ModifyStyle(LVS_OWNERDRAWFIXED, 0, 0);
2017-08-18 05:08:22 +00:00
2020-05-12 12:19:05 +00:00
m_DMAList.AddColumn(L"ROM", 0);
m_DMAList.AddColumn(L"RAM", 1);
m_DMAList.AddColumn(L"Length", 2);
m_DMAList.AddColumn(L"Symbol (RAM)", 3);
m_DMAList.AddColumn(L"Signature", 4);
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
m_DMAList.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
m_DMAList.SetColumnWidth(0, 65);
m_DMAList.SetColumnWidth(1, 65);
m_DMAList.SetColumnWidth(2, 120);
//m_DMAList.SetColumnWidth(3, 50);
//m_DMAList.SetColumnWidth(4, 50);
//m_DMAList.SetColumnWidth(5, 50);
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
m_DMARamEdit.SetLimitText(8);
m_DMARomEdit.SetLimitText(8);
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
RefreshList();
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
LoadWindowPos();
WindowCreated();
2017-08-18 05:08:22 +00:00
2019-12-25 00:41:20 +00:00
return TRUE;
2017-08-18 05:08:22 +00:00
}
2019-04-02 19:16:39 +00:00
void CDebugDMALogView::RefreshDMALogWindow(bool bReset)
2019-04-02 18:28:46 +00:00
{
2021-04-12 11:35:39 +00:00
if (m_hWnd == nullptr || m_DMAList.m_hWnd == nullptr)
2019-04-02 18:28:46 +00:00
{
2019-04-02 19:16:39 +00:00
if (bReset)
{
m_DMALog->ClearEntries();
}
2019-04-02 18:28:46 +00:00
return;
}
2019-04-02 19:16:39 +00:00
PostMessage(WM_REFRESH, bReset);
2019-04-02 18:28:46 +00:00
}
2022-09-21 05:16:07 +00:00
LRESULT CDebugDMALogView::OnRefresh(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
2019-04-02 18:28:46 +00:00
{
2020-01-22 06:34:27 +00:00
bool bReset = (wParam != 0);
2019-04-02 19:16:39 +00:00
if (bReset)
{
m_DMALog->ClearEntries();
}
2019-04-02 18:28:46 +00:00
RefreshList();
return TRUE;
}
void CDebugDMALogView::OnExitSizeMove(void)
{
SaveWindowPos(true);
}
2017-08-18 05:08:22 +00:00
LRESULT CDebugDMALogView::OnDestroy(void)
{
2019-04-02 19:16:39 +00:00
m_DMAList.Detach();
m_DMARamEdit.Detach();
m_DMARomEdit.Detach();
m_BlockInfo.Detach();
2019-12-25 00:41:20 +00:00
return 0;
2017-08-18 05:08:22 +00:00
}
2022-09-21 05:16:07 +00:00
LRESULT CDebugDMALogView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL & /*bHandled*/)
2017-08-18 05:08:22 +00:00
{
2019-12-25 00:41:20 +00:00
switch (wID)
{
case IDOK:
EndDialog(0);
break;
case IDCANCEL:
EndDialog(0);
break;
case IDC_CLEAR_BTN:
m_DMALog->ClearEntries();
RefreshList();
break;
case IDC_EXPORT_BTN:
Export();
break;
2019-12-25 00:41:20 +00:00
}
return FALSE;
2017-08-18 05:08:22 +00:00
}
2022-09-21 05:16:07 +00:00
LRESULT CDebugDMALogView::OnRamAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2017-08-18 05:08:22 +00:00
{
2019-12-25 00:41:20 +00:00
if (m_bConvertingAddress)
{
return FALSE;
}
stdstr szRomAddr;
uint32_t ramAddr = strtoul(GetCWindowText(m_DMARamEdit).c_str(), nullptr, 16);
2019-12-25 00:41:20 +00:00
uint32_t romAddr, offset;
DMALOGENTRY * lpEntry = m_DMALog->GetEntryByRamAddress(ramAddr, &romAddr, &offset);
2019-12-25 00:41:20 +00:00
2021-04-12 11:35:39 +00:00
if (lpEntry != nullptr)
2019-12-25 00:41:20 +00:00
{
szRomAddr.Format("%08X", romAddr);
2020-05-12 12:19:05 +00:00
stdstr_f blockInfo("Block: %08X -> %08X [%X] +%X", romAddr, ramAddr, lpEntry->length, offset);
m_BlockInfo.SetWindowText(blockInfo.ToUTF16().c_str());
2019-12-25 00:41:20 +00:00
}
else
{
szRomAddr = "????????";
2020-05-12 12:19:05 +00:00
m_BlockInfo.SetWindowText(L"Block: ?");
2019-12-25 00:41:20 +00:00
}
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
m_bConvertingAddress = true;
m_DMARomEdit.SetWindowText(szRomAddr.ToUTF16().c_str());
2019-12-25 00:41:20 +00:00
m_bConvertingAddress = false;
return FALSE;
2017-08-18 05:08:22 +00:00
}
2022-09-21 05:16:07 +00:00
LRESULT CDebugDMALogView::OnRomAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
2017-08-18 05:08:22 +00:00
{
2019-12-25 00:41:20 +00:00
if (m_bConvertingAddress)
{
return FALSE;
}
stdstr szRamAddr = GetCWindowText(m_DMARomEdit);
uint32_t romAddr = strtoul(szRamAddr.c_str(), nullptr, 16);
2019-12-25 00:41:20 +00:00
uint32_t ramAddr, offset;
2022-09-21 05:16:07 +00:00
DMALOGENTRY * lpEntry = m_DMALog->GetEntryByRomAddress(romAddr, &ramAddr, &offset);
2019-12-25 00:41:20 +00:00
2021-04-12 11:35:39 +00:00
if (lpEntry != nullptr)
2019-12-25 00:41:20 +00:00
{
szRamAddr.Format("%08X", ramAddr);
2019-12-25 00:41:20 +00:00
stdstr blockInfo = stdstr_f("Block: %08X -> %08X [%X] +%X", romAddr, ramAddr, lpEntry->length, offset);
2020-05-12 12:19:05 +00:00
m_BlockInfo.SetWindowText(blockInfo.ToUTF16().c_str());
2019-12-25 00:41:20 +00:00
}
else
{
szRamAddr = "????????";
2020-05-12 12:19:05 +00:00
m_BlockInfo.SetWindowText(L"Block: ?");
2019-12-25 00:41:20 +00:00
}
m_bConvertingAddress = true;
m_DMARamEdit.SetWindowText(szRamAddr.ToUTF16().c_str());
2019-12-25 00:41:20 +00:00
m_bConvertingAddress = false;
return FALSE;
2017-08-18 05:08:22 +00:00
}
2022-09-21 05:16:07 +00:00
LRESULT CDebugDMALogView::OnCustomDrawList(NMHDR * pNMHDR)
2017-08-18 05:08:22 +00:00
{
2022-09-21 05:16:07 +00:00
NMLVCUSTOMDRAW * pLVCD = reinterpret_cast<NMLVCUSTOMDRAW *>(pNMHDR);
2019-12-25 00:41:20 +00:00
DWORD drawStage = pLVCD->nmcd.dwDrawStage;
switch (drawStage)
{
case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW;
case CDDS_ITEMPREPAINT: return CDRF_NOTIFYSUBITEMDRAW;
case (CDDS_ITEMPREPAINT | CDDS_SUBITEM): break;
default: return CDRF_DODEFAULT;
}
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
DWORD nItem = pLVCD->nmcd.dwItemSpec;
DWORD nSubItem = pLVCD->iSubItem;
if (nSubItem != 0)
{
return CDRF_DODEFAULT;
}
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
size_t nEntries = m_DMALog->GetNumEntries();
if (nEntries == 0)
{
return CDRF_DODEFAULT;
}
2022-09-21 05:16:07 +00:00
DMALOGENTRY * lpEntry = m_DMALog->GetEntryByIndex(nItem);
if (nItem >= 1) // Continuation
2019-12-25 00:41:20 +00:00
{
2022-09-21 05:16:07 +00:00
DMALOGENTRY * lpPrevEntry = m_DMALog->GetEntryByIndex(nItem - 1);
2019-12-25 00:41:20 +00:00
if (lpEntry->romAddr == lpPrevEntry->romAddr + lpPrevEntry->length)
{
pLVCD->clrTextBk = RGB(0xFF, 0xFF, 0xCC);
return CDRF_DODEFAULT;
}
}
if (nEntries >= 2 && nItem <= nEntries - 2) // Head
2019-12-25 00:41:20 +00:00
{
2022-09-21 05:16:07 +00:00
DMALOGENTRY * lpNextEntry = m_DMALog->GetEntryByIndex(nItem + 1);
2019-12-25 00:41:20 +00:00
if (lpNextEntry->romAddr == lpEntry->romAddr + lpEntry->length)
{
pLVCD->clrTextBk = RGB(0xFF, 0xFF, 0x88);
return CDRF_DODEFAULT;
}
}
2022-09-21 05:16:07 +00:00
2019-12-25 00:41:20 +00:00
return CDRF_DODEFAULT;
}