📄 pcspimview.cpp
字号:
#include "RunDlg.h"
void CPCSpimView::OnSimulatorRun()
{
mem_addr addr;
CRunDlg dlg;
if (IDCANCEL == dlg.DoModal())
{
return;
}
InitStack(g_strCmdLine);
addr = strtoul(dlg.m_strAddress, NULL, 0);
if (addr == 0)
{
addr = starting_address ();
}
ExecuteProgram(addr, DEFAULT_RUN_STEPS, 0, 0);
}
void CPCSpimView::ExecuteProgram(mem_addr pc,
int steps,
int display,
int cont_bkpt)
{
if (pc != 0)
{
g_fRunning = TRUE;
ShowRunning();
while (1)
{
if (0 != run_program(pc, steps, display, cont_bkpt))
{
UpdateStatusDisplay();
HighlightCurrentInstruction();
// If we hit a breakpoint, and the user doesn't
// want to continue, then stop.
if (!AskContinue(FALSE))
{
break;
}
// Step over breakpoint
run_program(PC, 1, 0, 1);
pc = PC;
}
else
{
break;
}
}
if (::IsWindow(m_hWnd)) // We may have ended while running.
{
UpdateStatusDisplay();
HighlightCurrentInstruction();
g_fRunning = FALSE;
ShowRunning();
}
}
}
void CPCSpimView::UpdateStatusDisplay()
{
DisplayDataSegment();
DisplayTextSegment();
DisplayRegisters();
}
void CPCSpimView::DisplayRegisters()
{
static str_stream ss;
if (!m_fSimulatorInitialized)
{
return;
}
ss_clear (&ss);
format_registers (&ss, g_fGenRegHex, g_fFPRegHex);
char* buf2 = MakeCRLFValid(ss_to_string (&ss));
int top_line = m_wndRegisters.GetFirstVisibleLine(); // Remember window's top line
m_wndRegisters.SetWindowText(buf2);
m_wndRegisters.LineScroll(top_line, 0); // Put that line at top again
delete buf2;
}
void CPCSpimView::DisplayDataSegment()
{
static str_stream ss;
if (!m_fSimulatorInitialized)
return;
if (!data_modified)
return;
ss_clear (&ss);
format_data_segs (&ss);
data_modified = 0;
char* buf2 = MakeCRLFValid(ss_to_string (&ss));
int top_line = m_wndDataSeg.GetFirstVisibleLine(); // Remember window's top line
m_wndDataSeg.SetWindowText(buf2);
m_wndDataSeg.LineScroll(top_line, 0); // Put that line at top again
delete buf2;
}
void CPCSpimView::DisplayTextSegment()
{
static str_stream ss;
if (!m_fSimulatorInitialized)
return;
if (!text_modified)
return;
ss_clear (&ss);
format_insts (&ss, TEXT_BOT, text_top);
ss_printf (&ss, "\n\tKERNEL\n");
format_insts (&ss, K_TEXT_BOT, k_text_top);
text_modified = 0;
char* buf2 = MakeCRLFValid(ss_to_string (&ss));
int top_line = m_wndTextSeg.GetFirstVisibleLine(); // Remember window's top line
m_wndTextSeg.SetWindowText(buf2);
m_wndTextSeg.LineScroll(top_line, 0); // Put that line at top again
delete buf2;
}
void CPCSpimView::OnSimulatorBreakpoints()
{
m_dlgBP.ShowWindow(SW_NORMAL);
}
void CPCSpimView::SetMessageCapture(BOOL fOn)
{
if (!fOn)
m_strMsgCaptureBuf.Empty();
m_fCapture = fOn;
}
LPCTSTR CPCSpimView::GetMessageCaptureBuf()
{
return m_strMsgCaptureBuf;
}
void CPCSpimView::HighlightCurrentInstruction()
{
char pattern[100];
if (PC < TEXT_BOT || (PC > text_top && (PC < K_TEXT_BOT || PC > k_text_top)))
return;
sprintf (pattern, "[0x%08x]", PC);
CString text;
m_wndTextSeg.GetWindowText(text);
int start = text.Find(pattern);
if (start != -1)
{
int end = text.Find("\n", start + 1);
if (end != - 1)
{
// Reverse parameters so beginning of line is in window (!)
m_wndTextSeg.SetSel(end, start, FALSE);
}
}
}
#include "SetValueDlg.h"
void CPCSpimView::OnSimulatorSetvalue()
{
CSetValueDlg dlg;
dlg.DoModal();
UpdateStatusDisplay();
}
// Functions both as Break and Continue
void CPCSpimView::OnSimulatorBreak()
{
if (g_fRunning) // "Break" mode
{
UpdateStatusDisplay();
HighlightCurrentInstruction();
if (!AskContinue(TRUE))
force_break = 1;
}
else // "Continue" mode
{
ExecuteProgram(PC, DEFAULT_RUN_STEPS, 0, 0);
}
}
void CPCSpimView::OnUpdateSimulatorBreak(CCmdUI* pCmdUI)
{
if (!m_fSimulatorInitialized)
{
pCmdUI->Enable(FALSE);
return;
}
// NOTE: We might want a flag for this instead.
pCmdUI->Enable(PC != 0);
if (g_fRunning || (PC == 0))
pCmdUI->SetText("Break");
else
pCmdUI->SetText("Continue");
}
#include "SettingsDlg.h"
void CPCSpimView::OnSimulatorSettings()
{
CSettingsDlg dlg;
dlg.DoModal(); // It takes care of everything.
if (m_fSimulatorInitialized)
{
((CMainFrame*)AfxGetMainWnd())->GetActiveDocument()->UpdateAllViews(NULL);
}
}
void CPCSpimView::OnUpdateSimulatorReload(CCmdUI* pCmdUI)
{
pCmdUI->SetText("Re&load " + m_strCurFilename);
pCmdUI->Enable(!m_strCurFilename.IsEmpty() && m_fSimulatorInitialized);
}
void CPCSpimView::OnSimulatorReload()
{
LoadFile(m_strCurFilename);
}
extern "C" int parse_error_occurred; // Import from parser
void CPCSpimView::LoadFile(LPCTSTR strFilename)
{
int nLoaded;
CString strLoadMsg;
int result;
l_TryLoad:
if (m_strCurFilename.IsEmpty())
{
// Reset the simulator before loading first file
ReinitializeSimulator();
}
else if (IDYES == (result = MessageBox("Clear program and reinitialize simulator before loading?",
NULL, MB_YESNOCANCEL | MB_ICONQUESTION)))
{
// Reset the simulator if requested
ReinitializeSimulator();
}
else if (IDCANCEL == result)
{
// Quit before loading file
return;
}
g_pView->SetMessageCapture(TRUE);
nLoaded = read_assembly_file((char*)strFilename);
strLoadMsg = g_pView->GetMessageCaptureBuf();
g_pView->SetMessageCapture(FALSE);
// Trim the white space off the front and rear.
strLoadMsg.TrimLeft();
strLoadMsg.TrimRight();
if (nLoaded != 0)
{
strLoadMsg.Format("Could not open %s for reading.", (char*)strFilename);
MessageBox(strLoadMsg, NULL, MB_OK | MB_ICONEXCLAMATION);
}
else if (!strLoadMsg.IsEmpty())
{
CString strMsg;
if (parse_error_occurred)
{
strMsg.Format(
"An error occurred while loading the file.\n"
"The message are:\n"
"\n"
"%s\n"
"\n"
"Would you like to open the Settings dialog box to verify simulator settings?",
strLoadMsg);
if (IDYES == MessageBox(strMsg, NULL, MB_YESNO | MB_ICONEXCLAMATION))
{
SendMessage(WM_COMMAND, MAKEWPARAM(ID_SIMULATOR_SETTINGS, 0), NULL);
if (IDYES == MessageBox("Would you like to try to load the file again?",
NULL, MB_YESNO | MB_ICONQUESTION))
goto l_TryLoad;
}
// They didn't want to try to reload.
write_output(message_out,"Load terminated. Check code and simulator settings and try again.\n");
}
else
{
strMsg.Format(
"Loading the file produced warnings.\n"
"The messages are:\n"
"\n"
"%s\n"
"\n"
"Would you like to open the Settings dialog box to verify simulator settings?",
strLoadMsg);
if (IDYES == MessageBox(strMsg, NULL, MB_YESNO | MB_ICONEXCLAMATION))
{
SendMessage(WM_COMMAND, MAKEWPARAM(ID_SIMULATOR_SETTINGS, 0), NULL);
}
}
}
else // File loaded
{
m_strCurFilename = strFilename; // Save the filename
PC = find_symbol_address (DEFAULT_RUN_LOCATION);
write_output(message_out, "%s successfully loaded\n", (char*)strFilename);
}
UpdateStatusDisplay();
HighlightCurrentInstruction();
}
BOOL CPCSpimView::AskContinue(BOOL fBreak)
{
CString strMsg;
if (fBreak)
strMsg.Format("Execution paused by the user at 0x%08x.\n", PC);
else
strMsg.Format("Breakpoint encountered at 0x%08x.\n", PC);
strMsg += "\nContinue execution?";
return (IDYES == MessageBox(strMsg, NULL, MB_YESNO | MB_ICONQUESTION));
}
void CPCSpimView::ShowRunning()
{
CMainFrame *pWnd = (CMainFrame *)AfxGetMainWnd();
CString strTitle = pWnd->GetTitleBase();
if (g_fRunning)
strTitle += " [Running]";
pWnd->SetWindowText(strTitle);
}
void CPCSpimView::OnSimulatorStep()
{
ExecuteProgram(PC, 1, 1, 1);
}
#include "MultiStepDlg.h"
void CPCSpimView::OnSimulatorMultistep()
{
CMultiStepDlg dlg;
if (IDCANCEL == dlg.DoModal())
return;
ExecuteProgram(PC, dlg.m_cSteps, 1, 1);
}
void CPCSpimView::OnSimulatorDisplaysymbols()
{
print_symbols();
}
void CPCSpimView::OnWindowNext()
{
CWnd *pWndTop, *pWndNext;
pWndTop = GetTopWindow();
if (pWndTop == NULL)
return;
while (!pWndTop->IsWindowVisible())
{
pWndTop = pWndTop->GetNextWindow();
}
pWndNext = pWndTop->GetNextWindow();
if (pWndNext == NULL)
return;
while (!pWndNext->IsWindowVisible())
{
pWndNext = pWndNext->GetNextWindow();
}
pWndTop->SetWindowPos(&CWnd::wndBottom, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
pWndNext->BringWindowToTop();
pWndNext->SetFocus();
}
void CPCSpimView::OnWindowPrevious()
{
CWnd *pWndTop, *pWndBottom;
pWndTop = GetTopWindow();
if (pWndTop == NULL)
return;
pWndBottom = pWndTop->GetWindow(GW_HWNDLAST);
while (!pWndBottom->IsWindowVisible())
{
pWndBottom = pWndBottom->GetWindow(GW_HWNDPREV);
}
if (pWndBottom == pWndTop)
return;
pWndBottom->BringWindowToTop();
pWndBottom->SetFocus();
}
void CPCSpimView::OnWindowCascade()
{
CWnd *pWnd;
long x, y, cx, cy;
long cpixTitlebar = GetSystemMetrics(SM_CYCAPTION) +
GetSystemMetrics(SM_CYFRAME);
x = 0;
y = 0;
RECT r;
GetClientRect(&r);
cx = (r.right - r.left) - (10 * cpixTitlebar);
cy = (r.bottom - r.top) - (10 * cpixTitlebar);
HDWP hdwp = BeginDeferWindowPos(5); // Just a guess at the number
pWnd = GetTopWindow()->GetWindow(GW_HWNDLAST);
while (pWnd != NULL)
{
if (!pWnd->IsIconic())
{
DeferWindowPos(hdwp,
pWnd->m_hWnd,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -