diff --git a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp index 48801920d..7b8f42b50 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp @@ -12,6 +12,7 @@ #include "stdafx.h" #include "DebuggerUI.h" #include "DMALog.h" +#include CDebugDMALogView::CDebugDMALogView(CDebuggerUI* debugger) : CDebugDialog(debugger) @@ -70,17 +71,21 @@ void CDebugDMALogView::RefreshList() int startIndex; int dmaLogSize = m_Debugger->DMALog()->GetNumEntries(); + HWND hWndExportBtn = GetDlgItem(IDC_EXPORT_BTN); + if (dmaLogSize == 0) { // Reset m_DMAList.DeleteAllItems(); startIndex = 0; m_bFilterChanged = false; + ::EnableWindow(hWndExportBtn, FALSE); } else { // Continue from last index startIndex = m_nLastStartIndex; + ::EnableWindow(hWndExportBtn, TRUE); } m_DMAList.SetRedraw(FALSE); @@ -130,6 +135,65 @@ void CDebugDMALogView::RefreshList() m_nLastStartIndex = dmaLogSize; } +void CDebugDMALogView::Export(void) +{ + OPENFILENAME openfilename; + TCHAR filePath[_MAX_PATH]; + + memset(&filePath, 0, sizeof(filePath)); + memset(&openfilename, 0, sizeof(openfilename)); + + wsprintf(filePath, L"*.csv"); + + const TCHAR* filters = ( + /*1*/ L"Comma separated values (*.csv)\0*.csv;\0" + /*2*/ L"Plain text (*.txt)\0*.txt;\0" + ); + + 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++) + { + DMALOGENTRY* entry = m_DMALog->GetEntryByIndex(nEntry); + + file << stdstr_f("0x%08X,0x%08X,0x%08X\r\n", + entry->romAddr, entry->ramAddr, entry->length); + } + + file.close(); + } +} + LRESULT CDebugDMALogView::OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { //RefreshList(); @@ -233,6 +297,9 @@ LRESULT CDebugDMALogView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& m_DMALog->ClearEntries(); RefreshList(); break; + case IDC_EXPORT_BTN: + Export(); + break; } return FALSE; } diff --git a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.h b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.h index d3a07a817..75ed95ed4 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.h @@ -32,6 +32,7 @@ private: }; void RefreshList(void); + void Export(void); CDMALog* m_DMALog; diff --git a/Source/Project64/UserInterface/UIResources.rc b/Source/Project64/UserInterface/UIResources.rc index 1f897e81d..fcb81066d 100644 --- a/Source/Project64/UserInterface/UIResources.rc +++ b/Source/Project64/UserInterface/UIResources.rc @@ -939,7 +939,7 @@ BEGIN CONTROL "",IDC_DMA_LIST,"SysListView32",LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_ALIGNLEFT | WS_TABSTOP,0,0,309,172 PUSHBUTTON "Clear",IDC_CLEAR_BTN,224,176,42,14 EDITTEXT IDC_DMA_RAM_EDIT,28,185,47,13,ES_AUTOHSCROLL - PUSHBUTTON "Export...",IDC_BUTTON1,266,176,41,14,WS_DISABLED + PUSHBUTTON "Export...",IDC_EXPORT_BTN,266,176,41,14,WS_DISABLED GROUPBOX "Trace",IDC_TRACE_STATIC,3,174,177,38,0,WS_EX_TRANSPARENT LTEXT "RAM",IDC_RAM_STATIC,9,187,15,9 LTEXT "ROM",IDC_ROM_STATIC,80,187,15,9 diff --git a/Source/Project64/UserInterface/resource.h b/Source/Project64/UserInterface/resource.h index bfae867f6..012b878c9 100644 --- a/Source/Project64/UserInterface/resource.h +++ b/Source/Project64/UserInterface/resource.h @@ -473,7 +473,7 @@ #define IDC_CLEAR_BTN 1302 #define IDC_DMA_RAM_EDIT 1303 #define IDC_COPY_BTN 1303 -#define IDC_BUTTON1 1305 +#define IDC_EXPORT_BTN 1305 #define IDC_DMA_ROM_EDIT 1306 #define IDC_TRACE_STATIC 1307 #define IDC_RAM_STATIC 1308