📄 pcspimview.cpp
字号:
NULL,
x,
y,
cx,
cy,
SWP_NOZORDER | SWP_NOACTIVATE);
x += cpixTitlebar;
y += cpixTitlebar;
}
pWnd = pWnd->GetNextWindow(GW_HWNDPREV);
}
EndDeferWindowPos(hdwp);
}
void CPCSpimView::OnWindowTile()
{
RECT r;
GetClientRect(&r);
TileWindows(r.right - r.left, r.bottom - r.top, r.bottom);
}
//
// Tile windows in a reasonable order:
// Register
// Text
// Data
// Messages
//
void CPCSpimView::TileWindows(long cx, long cy, long bottom)
{
long cTileWnds = 0;
if (!m_wndRegisters.IsIconic()) cTileWnds ++;
if (!m_wndTextSeg.IsIconic()) cTileWnds ++;
if (!m_wndDataSeg.IsIconic()) cTileWnds ++;
if (!m_wndMessages.IsIconic()) cTileWnds ++;
if (cTileWnds == 0)
return;
long y = 0;
cy = cy / cTileWnds;
HDWP hdwp = BeginDeferWindowPos(5);
if (!m_wndRegisters.IsIconic())
{
DeferWindowPos(hdwp, m_wndRegisters.m_hWnd, NULL, 0, y, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
y += cy;
if ((bottom - y) < (2 * cy))
cy = bottom - y;
}
if (!m_wndTextSeg.IsIconic())
{
DeferWindowPos(hdwp, m_wndTextSeg.m_hWnd, NULL, 0, y, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
y += cy;
if ((bottom - y) < (2 * cy))
cy = bottom - y;
}
if (!m_wndDataSeg.IsIconic())
{
DeferWindowPos(hdwp, m_wndDataSeg.m_hWnd, NULL, 0, y, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
y += cy;
if ((bottom - y) < (2 * cy))
cy = bottom - y;
}
if (!m_wndMessages.IsIconic())
{
DeferWindowPos(hdwp, m_wndMessages.m_hWnd, NULL, 0, y, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
y += cy;
if ((bottom - y) < (2 * cy))
cy = bottom - y;
}
EndDeferWindowPos(hdwp);
}
CConsoleWnd * CPCSpimView::GetConsole()
{
return &m_wndConsole;
}
void CPCSpimView::MakeConsoleVisible()
{
if (!m_fConsoleMinimized)
{
if (::IsWindow(m_hWnd))
{
m_wndConsole.ShowWindow(SW_NORMAL);
m_wndConsole.BringWindowToTop();
}
}
}
void CPCSpimView::BringConsoleToTop()
{
if (!m_fConsoleMinimized)
{
if (::IsWindow(m_hWnd))
{
MakeConsoleVisible();
m_wndConsole.SetFocus();
}
}
}
void CPCSpimView::OnWindowClearConsole()
{
m_wndConsole.Clear();
}
void CPCSpimView::OnWindowConsole()
{
MakeConsoleVisible();
}
void CPCSpimView::OnUpdateSimulatorSetvalue(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_fSimulatorInitialized);
}
void CPCSpimView::OnUpdateSimulatorBreakpoints(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_fSimulatorInitialized);
}
void CPCSpimView::OnUpdateSimulatorDisplaysymbols(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_fSimulatorInitialized);
}
void CPCSpimView::OnUpdateSimulatorClearRegisters(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_fSimulatorInitialized);
}
void CPCSpimView::OnUpdateSimulatorReinitialize(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_fSimulatorInitialized);
}
void CPCSpimView::OnWindowMessages()
{
m_wndMessages.ShowWindow(SW_NORMAL);
m_wndMessages.BringWindowToTop();
}
void CPCSpimView::OnWindowRegisters()
{
m_wndRegisters.ShowWindow(SW_NORMAL);
m_wndRegisters.BringWindowToTop();
}
void CPCSpimView::OnWindowTextseg()
{
m_wndTextSeg.ShowWindow(SW_NORMAL);
m_wndTextSeg.BringWindowToTop();
}
void CPCSpimView::OnWindowDataseg()
{
m_wndDataSeg.ShowWindow(SW_NORMAL);
m_wndDataSeg.BringWindowToTop();
}
#define WHITESPACE " \t\n\r"
void CPCSpimView::ProcessCommandLine()
{
LPTSTR argv[256];
int argc;
int i;
// Initialize argc & argv variables.
LPTSTR szCmdLine = GetCommandLine();
if (szCmdLine[0] == '"')
argv[0] = strtok(szCmdLine, "\"");
else
argv[0] = strtok(GetCommandLine(), WHITESPACE);
for (argc = 1; ; argc += 1)
{
LPTSTR szParam = strtok(NULL, WHITESPACE);
if (szParam == NULL)
break;
argv[argc] = szParam;
}
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '/')
argv[i][0] = '-'; /* Canonicalize commands */
if (streq (argv [i], "-asm")
|| streq (argv [i], "-a"))
{
bare_machine = 0;
delayed_branches = 0;
delayed_loads = 0;
}
else if (streq (argv [i], "-bare")
|| streq (argv [i], "-b"))
{
bare_machine = 1;
delayed_branches = 1;
delayed_loads = 1;
quiet = 1;
}
else if (streq (argv [i], "-delayed_branches")
|| streq (argv [i], "-db"))
{ delayed_branches = 1; }
else if (streq (argv [i], "-delayed_loads")
|| streq (argv [i], "-dl"))
{ delayed_loads = 1; }
else if (streq (argv [i], "-exception")
|| streq (argv [i], "-e"))
{ g_fLoadExceptionHandler = 1; }
else if (streq (argv [i], "-noexception")
|| streq (argv [i], "-ne"))
{ g_fLoadExceptionHandler = 0; }
else if (streq (argv [i], "-exception_file")
|| streq (argv [i], "-ef"))
{
exception_file_name = argv[++i];
g_fLoadExceptionHandler = 1;
}
else if (streq (argv [i], "-mapped_io")
|| streq (argv [i], "-mio"))
{ mapped_io = 1; }
else if (streq (argv [i], "-nomapped_io")
|| streq (argv [i], "-nmio"))
{ mapped_io = 0; }
else if (streq (argv [i], "-pseudo")
|| streq (argv [i], "-p"))
{ accept_pseudo_insts = 1; }
else if (streq (argv [i], "-nopseudo")
|| streq (argv [i], "-np"))
{ accept_pseudo_insts = 0; }
else if (streq (argv [i], "-quiet")
|| streq (argv [i], "-q"))
{ quiet = 1; }
else if (streq (argv [i], "-noquiet")
|| streq (argv [i], "-nq"))
{ quiet = 0; }
else if (streq (argv [i], "-stext")
|| streq (argv [i], "-st"))
{ initial_text_size = atoi (argv[++i]); }
else if (streq (argv [i], "-sdata")
|| streq (argv [i], "-sd"))
{ initial_data_size = atoi (argv[++i]); }
else if (streq (argv [i], "-ldata")
|| streq (argv [i], "-ld"))
{ initial_data_limit = atoi (argv[++i]); }
else if (streq (argv [i], "-sstack")
|| streq (argv [i], "-ss"))
{ initial_stack_size = atoi (argv[++i]); }
else if (streq (argv [i], "-lstack")
|| streq (argv [i], "-ls"))
{ initial_stack_limit = atoi (argv[++i]); }
else if (streq (argv [i], "-sktext")
|| streq (argv [i], "-skt"))
{ initial_k_text_size = atoi (argv[++i]); }
else if (streq (argv [i], "-skdata")
|| streq (argv [i], "-skd"))
{ initial_k_data_size = atoi (argv[++i]); }
else if (streq (argv [i], "-lkdata")
|| streq (argv [i], "-lkd"))
{ initial_k_data_limit = atoi (argv[++i]); }
else if ((streq (argv [i], "-file")
|| streq (argv [i], "-f"))
&& (i + 1 < argc))
{
m_strCurFilename = argv[++i];
g_strCmdLine = "";
for (int j = i; j < argc; j++)
{
g_strCmdLine += argv[j];
g_strCmdLine += " ";
}
g_strCmdLine.TrimRight();
break;
}
else if (argv [i][0] != '-')
{
/* Assume this is a file name and everything else are arguments
to program */
m_strCurFilename = argv[i];
g_strCmdLine = "";
for (int j = i + 1; j < argc; j++)
{
g_strCmdLine += argv[j];
g_strCmdLine += " ";
}
g_strCmdLine.TrimRight();
break;
}
else
goto l_ErrorMsg;
}
return;
l_ErrorMsg:
CString strMsg;
strMsg.Format("Error processing command line option #%d: \"%s\"\n"
"Usage: spim \n\
-bare Bare machine (no pseudo-ops, delayed branches and loads)\n\
-asm Extended machine (pseudo-ops, no delayed branches and loads) (default)\n\
-delayed_branches Execute delayed branches\n\
-delayed_loads Execute delayed loads\n\
-exception Load exception handler (default)\n\
-noexception Do not load exception handler\n\
-exception_file <file> Specify exception handler in place of default\n\
-quiet Do not print warnings\n\
-noquiet Print warnings (default)\n\
-mapped_io Enable memory-mapped IO\n\
-nomapped_io Do not enable memory-mapped IO (default)\n\
-file <file> <args> Assembly code file and arguments to program\n"
"Note that if -file is specified, it must be the last option.",
i,
argv[i],
argv[0]);
MessageBox(strMsg, "PCSpim -- Error processing command line.",
MB_OK | MB_ICONEXCLAMATION);
exit(-1);
}
void CPCSpimView::OnDestroy()
{
CPCSpimApp *pApp = (CPCSpimApp *)AfxGetApp();
WINDOWPLACEMENT wp;
if (g_fSaveWinPos)
{
// Save the main window's position
AfxGetMainWnd()->GetWindowPlacement(&wp);
pApp->WriteSetting(SPIM_REG_MAINWINPOS, &wp.rcNormalPosition);
// Save the child windows positions
m_wndConsole.GetWindowPlacement(&wp);
pApp->WriteSetting(SPIM_REG_CONSOLEPOS, &wp.rcNormalPosition);
m_wndDataSeg.GetWindowPlacement(&wp);
pApp->WriteSetting(SPIM_REG_DATASEGPOS, &wp.rcNormalPosition);
pApp->WriteSetting(SPIM_REG_DATASEGMINMAX, wp.showCmd);
m_wndMessages.GetWindowPlacement(&wp);
pApp->WriteSetting(SPIM_REG_MESSAGESPOS, &wp.rcNormalPosition);
pApp->WriteSetting(SPIM_REG_MESSAGESMINMAX, wp.showCmd);
m_wndRegisters.GetWindowPlacement(&wp);
pApp->WriteSetting(SPIM_REG_REGISTERSPOS, &wp.rcNormalPosition);
pApp->WriteSetting(SPIM_REG_REGISTERSMINMAX, wp.showCmd);
m_wndTextSeg.GetWindowPlacement(&wp);
pApp->WriteSetting(SPIM_REG_TEXTSEGPOS, &wp.rcNormalPosition);
pApp->WriteSetting(SPIM_REG_TEXTSEGMINMAX, wp.showCmd);
}
pApp->WriteSetting(SPIM_REG_CHECK_UNDEF, g_checkUndefinedSymbols);
CView::OnDestroy();
}
// NOTE: If this is called with a valid CDC, it will _not_
// output to the FILE*, even if it is valid.
void CPCSpimView::OutputLog(CString &strBuf)
{
CString strTemp;
strBuf.Empty();
#define LINE_SEPARATOR "\n=========================\n"
m_wndMessages.GetWindowText(strTemp);
strBuf += "Messages" LINE_SEPARATOR + strTemp + "\n\n";
m_wndRegisters.GetWindowText(strTemp);
strBuf += "Registers" LINE_SEPARATOR + strTemp + "\n\n";
m_wndConsole.GetWindowText(strTemp);
strBuf += "Console" LINE_SEPARATOR + strTemp + "\n\n";
m_wndTextSeg.GetWindowText(strTemp);
strBuf += "Text Segment" LINE_SEPARATOR + strTemp + "\n\n";
m_wndDataSeg.GetWindowText(strTemp);
strBuf += "Data Segment" LINE_SEPARATOR + strTemp + "\n\n";
}
void CPCSpimView::OnWindowArrangeicons()
{
ArrangeIconicWindows();
}
void CPCSpimView::OnFileSaveLog()
{
CString strBuf;
LPTSTR szBuf;
CFileDialog dlg(FALSE, NULL, "PCSpim.log");
dlg.m_ofn.lpstrFilter = "Log Files (*.log)\0*.log\0Text Files (*.txt)\0*.txt\0\0";
dlg.DoModal();
FILE *f = fopen(dlg.GetPathName(), "wb");
OutputLog(strBuf);
szBuf = strBuf.GetBuffer(0);
while (*szBuf != NULL)
{
if (*szBuf == '\n')
fputs("\r\n", f);
else if (*szBuf == '\t')
fputs(" ", f);
else if (*szBuf != '\r')
fputc(*szBuf, f);
++szBuf;
}
strBuf.ReleaseBuffer();
fclose(f);
}
CFont* CPCSpimView::GetSpimFont()
{
return m_wndTextSeg.GetFont();
}
void CPCSpimView::SetSpimFont(LOGFONT* lf)
{
CFont* font = new CFont;
VERIFY(font->CreateFontIndirect(lf)); // create the font
m_wndMessages.SetFont(font, TRUE);
m_wndRegisters.SetFont(font, TRUE);
m_wndConsole.SetFont(font, TRUE);
m_wndTextSeg.SetFont(font, TRUE);
m_wndDataSeg.SetFont(font, TRUE);
CPCSpimApp *pApp = (CPCSpimApp *)AfxGetApp();
pApp->WriteSetting(SPIM_REG_FONTFACE, lf->lfFaceName );
pApp->WriteSetting(SPIM_REG_FONTHEIGHT, lf->lfHeight);
pApp->WriteSetting(SPIM_REG_FONTWEIGHT, lf->lfWeight);
pApp->WriteSetting(SPIM_REG_FONTITALIC, lf->lfItalic);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -