// Create Console View as child of Main Window void CreateConsoleView(HWND hwndParent, int x, int y, int width, int height) { ASSERT(hwndParent != NULL); g_hwndConsole = CreateWindow( CLASSNAME_TOOLWINDOW, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, x, y, width, height, hwndParent, NULL, g_hInst, NULL); SetWindowText(g_hwndConsole, _T("Debug Console")); // ToolWindow subclassing m_wndprocConsoleToolWindow = (WNDPROC) LongToPtr( SetWindowLongPtr( g_hwndConsole, GWLP_WNDPROC, PtrToLong(ConsoleViewWndProc)) ); RECT rcConsole; GetClientRect(g_hwndConsole, &rcConsole); m_hwndConsoleEdit = CreateWindowEx( WS_EX_CLIENTEDGE, _T("EDIT"), NULL, WS_CHILD | WS_VISIBLE, 90, rcConsole.bottom - 20, rcConsole.right - 90, 20, g_hwndConsole, NULL, g_hInst, NULL); m_hwndConsoleLog = CreateWindowEx( WS_EX_CLIENTEDGE, _T("EDIT"), NULL, WS_CHILD | WS_VSCROLL | WS_VISIBLE | ES_READONLY | ES_MULTILINE, 0, 0, rcConsole.right, rcConsole.bottom - 20, g_hwndConsole, NULL, g_hInst, NULL); m_hwndConsolePrompt = CreateWindowEx( 0, _T("STATIC"), NULL, WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE | SS_CENTER | SS_NOPREFIX, 0, rcConsole.bottom - 20, 90, 20, g_hwndConsole, NULL, g_hInst, NULL); m_hfontConsole = CreateMonospacedFont(); SendMessage(m_hwndConsolePrompt, WM_SETFONT, (WPARAM) m_hfontConsole, 0); SendMessage(m_hwndConsoleEdit, WM_SETFONT, (WPARAM) m_hfontConsole, 0); SendMessage(m_hwndConsoleLog, WM_SETFONT, (WPARAM) m_hfontConsole, 0); // Edit box subclassing m_wndprocConsoleEdit = (WNDPROC) LongToPtr( SetWindowLongPtr( m_hwndConsoleEdit, GWLP_WNDPROC, PtrToLong(ConsoleEditWndProc)) ); ShowWindow(g_hwndConsole, SW_SHOW); UpdateWindow(g_hwndConsole); ConsoleView_Print(_T("Use 'h' command to show help.\r\n\r\n")); PrintConsolePrompt(); SetFocus(m_hwndConsoleEdit); }
void DoConsoleCommand() { // Get command text TCHAR command[32]; GetWindowText(m_hwndConsoleEdit, command, 32); SendMessage(m_hwndConsoleEdit, WM_SETTEXT, 0, (LPARAM) _T("")); // Clear command if (command[0] == 0) return; // Nothing to do // Echo command to the log TCHAR buffer[36]; ::GetWindowText(m_hwndConsolePrompt, buffer, 14); ConsoleView_Print(buffer); wsprintf(buffer, _T(" %s\r\n"), command); ConsoleView_Print(buffer); BOOL okUpdateAllViews = FALSE; // Flag - need to update all debug views CProcessor* pProc = ConsoleView_GetCurrentProcessor(); // Execute the command switch (command[0]) { case _T('h'): ConsoleView_ShowHelp(); break; case _T('c'): // Clear log ClearConsole(); break; case _T('r'): // Register operations if (command[1] == 0) // Print all registers { for (int r = 0; r < 8; r++) { LPCTSTR name = REGISTER_NAME[r]; WORD value = pProc->GetReg(r); PrintRegister(name, value); } PrintRegister(_T("PS"), pProc->GetPSW()); } else if (command[1] >= _T('0') && command[1] <= _T('7')) // "r0".."r7" { int r = command[1] - _T('0'); LPCTSTR name = REGISTER_NAME[r]; if (command[2] == 0) // "rN" - show register N { WORD value = pProc->GetReg(r); PrintRegister(name, value); } else if (command[2] == _T('=') || command[2] == _T(' ')) // "rN=XXXXXX" - set register N to value XXXXXX { WORD value; if (! ParseOctalValue(command + 3, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { pProc->SetReg(r, value); PrintRegister(name, value); okUpdateAllViews = TRUE; } } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); } else if (command[1] == _T('p') && command[2] == _T('s')) // "rps" { if (command[3] == 0) // "rps" - show PSW { WORD value = pProc->GetPSW(); PrintRegister(_T("PS"), value); } else if (command[3] == _T('=') || command[3] == _T(' ')) // "rps=XXXXXX" - set PSW to value XXXXXX { WORD value; if (! ParseOctalValue(command + 4, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { pProc->SetPSW(value); PrintRegister(_T("PS"), value); okUpdateAllViews = TRUE; } } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); break; case _T('s'): // Step if (command[1] == 0) // "s" - Step Into, execute one instruction { PrintDisassemble(pProc, pProc->GetPC(), TRUE, FALSE); //pProc->Execute(); g_pBoard->DebugTicks(); okUpdateAllViews = TRUE; } else if (command[1] == _T('o')) // "so" - Step Over { int instrLength = PrintDisassemble(pProc, pProc->GetPC(), TRUE, FALSE); WORD bpaddress = (WORD)(pProc->GetPC() + instrLength * 2); Emulator_SetCPUBreakpoint(bpaddress); Emulator_Start(); } break; case _T('d'): // Disassemble case _T('D'): // Disassemble, short format { BOOL okShort = (command[0] == _T('D')); if (command[1] == 0) // "d" - disassemble at current address PrintDisassemble(pProc, pProc->GetPC(), FALSE, okShort); else if (command[1] >= _T('0') && command[1] <= _T('7')) // "dXXXXXX" - disassemble at address XXXXXX { WORD value; if (! ParseOctalValue(command + 1, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { PrintDisassemble(pProc, value, FALSE, okShort); } } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); } break; case _T('u'): SaveMemoryDump(pProc); break; case _T('m'): if (command[1] == 0) // "m" - dump memory at current address { PrintMemoryDump(pProc, pProc->GetPC(), 8); } else if (command[1] >= _T('0') && command[1] <= _T('7')) // "mXXXXXX" - dump memory at address XXXXXX { WORD value; if (! ParseOctalValue(command + 1, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { PrintMemoryDump(pProc, value, 8); } } else if (command[1] == _T('r') && command[2] >= _T('0') && command[2] <= _T('7')) // "mrN" - dump memory at address from register N { int r = command[2] - _T('0'); WORD address = pProc->GetReg(r); PrintMemoryDump(pProc, address, 8); } else if (command[1] == _T('o')) { ConsoleView_GotoMonitor(); } else ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); break; //TODO: "mXXXXXX YYYYYY" - set memory cell at XXXXXX to value YYYYYY //TODO: "mrN YYYYYY" - set memory cell at address from rN to value YYYYYY case _T('g'): if (command[1] == 0) { Emulator_Start(); } else { WORD value; if (! ParseOctalValue(command + 1, &value)) ConsoleView_Print(MESSAGE_WRONG_VALUE); else { Emulator_SetCPUBreakpoint(value); Emulator_Start(); } } break; #if !defined(PRODUCT) case _T('t'): { BOOL okTrace = !g_pBoard->GetTrace(); g_pBoard->SetTrace(okTrace); if (okTrace) ConsoleView_Print(_T(" Trace is ON.\r\n")); else { ConsoleView_Print(_T(" Trace is OFF.\r\n")); DebugLogCloseFile(); } } break; #endif default: ConsoleView_Print(MESSAGE_UNKNOWN_COMMAND); break; } PrintConsolePrompt(); if (okUpdateAllViews) { MainWindow_UpdateAllViews(); } }