Mercurial > vba-linux
view src/win32/Logging.cpp @ 2:3549bbe597ed
adding makefile.am
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:47 -0600 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 // Logging.cpp : implementation file2 //4 #include "stdafx.h"5 #include "resource.h"6 #include "Logging.h"7 #include "FileDlg.h"9 #include "../common/System.h"11 /////////////////////////////////////////////////////////////////////////////12 // Logging dialog14 Logging *Logging::instance = NULL;15 CString Logging:: text;17 Logging::Logging(CWnd*pParent /*=NULL*/)18 : ResizeDlg(Logging::IDD, pParent)19 {20 //{{AFX_DATA_INIT(Logging)21 m_swi = FALSE;22 m_unaligned_access = FALSE;23 m_illegal_write = FALSE;24 m_illegal_read = FALSE;25 m_dma0 = FALSE;26 m_dma1 = FALSE;27 m_dma2 = FALSE;28 m_dma3 = FALSE;29 m_agbprint = FALSE;30 m_undefined = FALSE;31 //}}AFX_DATA_INIT32 }34 void Logging::DoDataExchange(CDataExchange*pDX)35 {36 CDialog::DoDataExchange(pDX);37 //{{AFX_DATA_MAP(Logging)38 DDX_Control(pDX, IDC_LOG, m_log);39 DDX_Check(pDX, IDC_VERBOSE_SWI, m_swi);40 DDX_Check(pDX, IDC_VERBOSE_UNALIGNED_ACCESS, m_unaligned_access);41 DDX_Check(pDX, IDC_VERBOSE_ILLEGAL_WRITE, m_illegal_write);42 DDX_Check(pDX, IDC_VERBOSE_ILLEGAL_READ, m_illegal_read);43 DDX_Check(pDX, IDC_VERBOSE_DMA0, m_dma0);44 DDX_Check(pDX, IDC_VERBOSE_DMA1, m_dma1);45 DDX_Check(pDX, IDC_VERBOSE_DMA2, m_dma2);46 DDX_Check(pDX, IDC_VERBOSE_DMA3, m_dma3);47 DDX_Check(pDX, IDC_VERBOSE_AGBPRINT, m_agbprint);48 DDX_Check(pDX, IDC_VERBOSE_UNDEFINED, m_undefined);49 //}}AFX_DATA_MAP50 }52 BEGIN_MESSAGE_MAP(Logging, CDialog)53 //{{AFX_MSG_MAP(Logging)54 ON_BN_CLICKED(ID_OK, OnOk)55 ON_BN_CLICKED(IDC_CLEAR, OnClear)56 ON_BN_CLICKED(IDC_VERBOSE_AGBPRINT, OnVerboseAgbprint)57 ON_BN_CLICKED(IDC_VERBOSE_DMA0, OnVerboseDma0)58 ON_BN_CLICKED(IDC_VERBOSE_DMA1, OnVerboseDma1)59 ON_BN_CLICKED(IDC_VERBOSE_DMA2, OnVerboseDma2)60 ON_BN_CLICKED(IDC_VERBOSE_DMA3, OnVerboseDma3)61 ON_BN_CLICKED(IDC_VERBOSE_ILLEGAL_READ, OnVerboseIllegalRead)62 ON_BN_CLICKED(IDC_VERBOSE_ILLEGAL_WRITE, OnVerboseIllegalWrite)63 ON_BN_CLICKED(IDC_VERBOSE_SWI, OnVerboseSwi)64 ON_BN_CLICKED(IDC_VERBOSE_UNALIGNED_ACCESS, OnVerboseUnalignedAccess)65 ON_BN_CLICKED(IDC_VERBOSE_UNDEFINED, OnVerboseUndefined)66 ON_BN_CLICKED(IDC_SAVE, OnSave)67 ON_EN_ERRSPACE(IDC_LOG, OnErrspaceLog)68 ON_EN_MAXTEXT(IDC_LOG, OnMaxtextLog)69 ON_WM_CLOSE()70 //}}AFX_MSG_MAP71 END_MESSAGE_MAP()73 /////////////////////////////////////////////////////////////////////////////74 // Logging message handlers76 void Logging::OnOk()77 {78 EndDialog(TRUE);80 instance = NULL;81 }83 void Logging::OnClear()84 {85 text = "";86 m_log.SetWindowText("");87 }89 void Logging::OnVerboseAgbprint()90 {91 systemVerbose ^= 512;92 }94 void Logging::OnVerboseDma0()95 {96 systemVerbose ^= 16;97 }99 void Logging::OnVerboseDma1()100 {101 systemVerbose ^= 32;102 }104 void Logging::OnVerboseDma2()105 {106 systemVerbose ^= 64;107 }109 void Logging::OnVerboseDma3()110 {111 systemVerbose ^= 128;112 }114 void Logging::OnVerboseIllegalRead()115 {116 systemVerbose ^= 8;117 }119 void Logging::OnVerboseIllegalWrite()120 {121 systemVerbose ^= 4;122 }124 void Logging::OnVerboseSwi()125 {126 systemVerbose ^= 1;127 }129 void Logging::OnVerboseUnalignedAccess()130 {131 systemVerbose ^= 2;132 }134 void Logging::OnVerboseUndefined()135 {136 systemVerbose ^= 256;137 }139 void Logging::OnSave()140 {141 int len = m_log.GetWindowTextLength();143 char *mem = (char *)malloc(len);145 if (mem)146 {147 LPCTSTR exts[] = { ".txt", NULL };148 m_log.GetWindowText(mem, len);149 CString filter = "All Files|*.*||";150 FileDlg dlg(this, "", filter, 0,151 NULL, exts, NULL, "Save output", true);153 if (dlg.DoModal() == IDOK)154 {155 FILE *f = fopen(dlg.GetPathName(), "w");156 if (f)157 {158 fwrite(mem, 1, len, f);159 fclose(f);160 }161 }162 }164 free(mem);165 }167 void Logging::OnErrspaceLog()168 {169 systemMessage(0, "Error allocating space");170 }172 void Logging::OnMaxtextLog()173 {174 systemMessage(0, "Max text length reached %d", m_log.GetLimitText());175 }177 void Logging::PostNcDestroy()178 {179 delete this;180 }182 BOOL Logging::OnInitDialog()183 {184 CDialog::OnInitDialog();186 DIALOG_SIZER_START(sz)187 DIALOG_SIZER_ENTRY(IDC_LOG, DS_SizeY|DS_SizeX)188 DIALOG_SIZER_ENTRY(ID_OK, DS_MoveY)189 DIALOG_SIZER_ENTRY(IDC_CLEAR, DS_MoveY)190 DIALOG_SIZER_ENTRY(IDC_SAVE, DS_MoveY)191 DIALOG_SIZER_END()192 SetData(sz,193 TRUE,194 HKEY_CURRENT_USER,195 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\LogView",196 NULL);198 m_swi = (systemVerbose & 1) != 0;199 m_unaligned_access = (systemVerbose & 2) != 0;200 m_illegal_write = (systemVerbose & 4) != 0;201 m_illegal_read = (systemVerbose & 8) != 0;202 m_dma0 = (systemVerbose & 16) != 0;203 m_dma1 = (systemVerbose & 32) != 0;204 m_dma2 = (systemVerbose & 64) != 0;205 m_dma3 = (systemVerbose & 128) != 0;206 m_undefined = (systemVerbose & 256) != 0;207 m_agbprint = (systemVerbose & 256) != 0;208 UpdateData(FALSE);210 m_log.LimitText(-1);211 m_log.SetWindowText(text);213 return TRUE; // return TRUE unless you set the focus to a control214 // EXCEPTION: OCX Property Pages should return FALSE215 }217 void Logging::log(const char *s)218 {219 int size = ::SendMessage(m_log, WM_GETTEXTLENGTH, 0, 0);220 m_log.SetSel(size, size);221 m_log.ReplaceSel(s);222 }224 void Logging::OnClose()225 {226 EndDialog(FALSE);228 instance = NULL;230 CDialog::OnClose();231 }233 void toolsLogging()234 {235 if (Logging::instance == NULL)236 {237 Logging::instance = new Logging();238 Logging::instance->Create(IDD_LOGGING, AfxGetApp()->m_pMainWnd);239 Logging::instance->ShowWindow(SW_SHOW);240 }241 else242 {243 Logging::instance->SetForegroundWindow();244 }245 }247 void toolsLog(const char *s)248 {249 CString str;250 int state = 0;251 if (s)252 {253 char c = *s++;254 while (c)255 {256 if (c == '\n' && state == 0)257 str += '\r';258 else if (c == '\r')259 state = 1;260 else261 state = 0;262 str += c;263 c = *s++;264 }265 }267 Logging::text += str;268 if (Logging::instance != NULL)269 {270 Logging::instance->log(str);271 }272 }