annotate src/win32/Logging.cpp @ 3:b05d00f19d80

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