⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 integerdatapathctrl.cpp

📁 mips处理器指令仿真器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	oldBrush.FromHandle((HBRUSH)pOldBrush);

	CRect rect( 144, 75, 165, 320 );
	memDC.Rectangle( &rect );
	// text "IF/ID"
	rect.left = 140; rect.right = 170; rect.top = 60; rect.bottom = 74;
	memDC.DrawText( "IF/ID", &rect, DT_CENTER | DT_VCENTER );

	memDC.SelectObject( &oldBrush );
	memDC.SelectObject( pOldPen );
}

// ID
void CIntegerDatapathCtrl::IDCircuits()
{
	CPen pen;
	pen.CreatePen( m_penStyle, m_penWidth, m_penColor );
	CPen* pOldPen = (CPen*)memDC.SelectObject( &pen );

	CBrush brush1, oldBrush1;
	brush1.CreateSolidBrush( RGB(197, 197, 243) );
	CBrush* pOldBrush = (CBrush*)memDC.SelectObject( brush1 );
	oldBrush1.FromHandle((HBRUSH)pOldBrush);

	// Registers
	CRect rect( 232, 146, 284, 250 );
	memDC.Rectangle( &rect );
	// text "Registers"
	rect.top = 192; rect.bottom = 205;
	memDC.DrawText( "Registers", &rect, DT_CENTER | DT_VCENTER );

	memDC.SelectObject( &oldBrush1 );

	CBrush brush2, oldBrush2;
	brush2.CreateSolidBrush( m_bkColor );
	pOldBrush = (CBrush*)memDC.SelectObject( brush2 );
	oldBrush2.FromHandle((HBRUSH)pOldBrush);
	// Sign-extend
	rect.left = 210; rect.right = 250; rect.top = 255; rect.bottom = 305;
	memDC.Ellipse( &rect );
	// text "Sign-extend"
	rect.top = 265; rect.bottom = 290;
	memDC.DrawText( "Sign-\nextend", &rect, DT_CENTER | DT_VCENTER );

	// Zero?
	rect.left = 304; rect.right = 340; rect.top = 100; rect.bottom = 130;
	memDC.Rectangle( &rect );
	// rext "Zero?"
	rect.top = 108;
	memDC.DrawText( "Zero?", &rect, DT_CENTER | DT_VCENTER );

	// ADD
	CPoint poly[8];
	poly[0] = CPoint( 270, 80 ); poly[1] = CPoint( 270, 100 );
	poly[2] = CPoint( 303, 84 ); poly[3] = CPoint( 303, 56 );
	poly[4] = CPoint( 270, 40 );  poly[5] = CPoint( 270, 60 );
	poly[6] = CPoint( 278, 70 ); poly[7] = CPoint( 270, 80 );
	memDC.Polyline( poly, 8 );
	// text "ADD"
	rect.left = 278; rect.top = 65; rect.right = 300, rect.bottom = 80;
	memDC.DrawText( "ADD", &rect, DT_LEFT | DT_VCENTER );

	IDLines( m_penStyle, m_penWidth, m_penColor );

	memDC.SelectObject( &oldBrush2 );
	memDC.SelectObject( pOldPen );
}

void CIntegerDatapathCtrl::IDLines( int penStyle, int penWidth, COLORREF penColor, CString& str )
{
	m_IDPenStyle = penStyle;
	m_IDPenWidth = penWidth;
	m_IDPenColor = penColor;
	m_IDStr = str;

	l8.Draw( &memDC, penStyle, penWidth, penColor );
	l9.Draw( &memDC, penStyle, penWidth, penColor );
	l10.Draw( &memDC, penStyle, penWidth, penColor );
	l11.Draw( &memDC, penStyle, penWidth, penColor );
	l12.Draw( &memDC, penStyle, penWidth, penColor );
	l13.Draw( &memDC, penStyle, penWidth, penColor );
	l14.Draw( &memDC, penStyle, penWidth, penColor );
	l15.Draw( &memDC, penStyle, penWidth, penColor );
	l16.Draw( &memDC, penStyle, penWidth, penColor );
	l17.Draw( &memDC, penStyle, penWidth, penColor );
	l18.Draw( &memDC, penStyle, penWidth, penColor );
	l19.Draw( &memDC, penStyle, penWidth, penColor );

	// show current instructions
	CRect rect( 165, 0, 350, 20 );
	COLORREF clr = memDC.SetTextColor( penColor );
	memDC.DrawText( str, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK );
	memDC.SetTextColor( clr );
}

void CIntegerDatapathCtrl::RestoreIDLines( BOOL bCore )
{
	IDLines( m_IDPenStyle, m_IDPenWidth, m_bkColor, m_IDStr );
	m_IDStr = _T("");
	if( bCore ) IDLines( m_penStyle, m_penWidth, m_penColor );
}

// ID/EX
void CIntegerDatapathCtrl::IDEXRegs()
{
	CPen pen;
	pen.CreatePen( m_penStyle, m_penWidth, m_penColor );
	CPen* pOldPen = (CPen*)memDC.SelectObject( &pen );

	CBrush brush, oldBrush;
	brush.CreateSolidBrush( m_regColor );
	CBrush* pOldBrush = (CBrush*)memDC.SelectObject( brush );
	oldBrush.FromHandle((HBRUSH)pOldBrush);

	CRect rect( 350, 60, 371, 320 );
	memDC.Rectangle( &rect );
	// text "ID/EX"
	rect.left = 348; rect.right = 380; rect.top = 45; rect.bottom = 60;
	memDC.DrawText( "ID/EX", &rect, DT_LEFT | DT_VCENTER );

	memDC.SelectObject( &oldBrush );
	memDC.SelectObject( pOldPen );
}

// EX
void CIntegerDatapathCtrl::EXCircuits()
{
	CPen pen;
	pen.CreatePen( m_penStyle, m_penWidth, m_penColor );
	CPen* pOldPen = (CPen*)memDC.SelectObject( &pen );

	CBrush brush, oldBrush;
	brush.CreateSolidBrush( m_bkColor );
	CBrush* pOldBrush = (CBrush*)memDC.SelectObject( brush );
	oldBrush.FromHandle((HBRUSH)pOldBrush);

	CRect rect;

	// Mux
	rect.left = 400; rect.right = 417; rect.top = 205; rect.bottom = 245;
	memDC.RoundRect( &rect, CPoint(17, 17) );
	// text "Mux"
	memDC.DrawText( "M\nu\nx", &rect, DT_CENTER | DT_VCENTER );

	// ALU
	CPoint poly[8];
	poly[0] = CPoint( 430, 212 ); poly[1] = CPoint( 430, 238 );
	poly[2] = CPoint( 470, 215 ); poly[3] = CPoint( 470, 183 );
	poly[4] = CPoint( 430, 160 );  poly[5] = CPoint( 430, 186 );
	poly[6] = CPoint( 440, 199 ); poly[7] = CPoint( 430, 212 );
	memDC.Polyline( poly, 8 );
	// text "ADD"
	rect.left = 440; rect.top = 193; rect.right = 470, rect.bottom = 205;
	memDC.DrawText( "ALU", &rect, DT_CENTER | DT_VCENTER );

	EXLines( m_penStyle, m_penWidth, m_penColor );

	memDC.SelectObject( &oldBrush );
	memDC.SelectObject( pOldPen );
}

void CIntegerDatapathCtrl::EXLines( int penStyle, int penWidth, COLORREF penColor, CString& str )
{
	m_EXPenStyle = penStyle;
	m_EXPenWidth = penWidth;
	m_EXPenColor = penColor;
	m_EXStr = str;

	l20.Draw( &memDC, penStyle, penWidth, penColor );
	l21.Draw( &memDC, penStyle, penWidth, penColor );
	l22.Draw( &memDC, penStyle, penWidth, penColor );
	l23.Draw( &memDC, penStyle, penWidth, penColor );
	l24.Draw( &memDC, penStyle, penWidth, penColor );
	l25.Draw( &memDC, penStyle, penWidth, penColor );
	l26.Draw( &memDC, penStyle, penWidth, penColor );

	// show current instructions
	CRect rect( 350, 0, 480, 20 );
	COLORREF clr = memDC.SetTextColor( penColor );
	memDC.DrawText( str, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK );
	memDC.SetTextColor( clr );
}

void CIntegerDatapathCtrl::RestoreEXLines( BOOL bCore )
{
	EXLines( m_EXPenStyle, m_EXPenWidth, m_bkColor, m_EXStr );
	m_EXStr = _T("");
	if( bCore ) EXLines( m_penStyle, m_penWidth, m_penColor );
}

// EX/MEM]
void CIntegerDatapathCtrl::EXMEMRegs()
{
	CPen pen;
	pen.CreatePen( m_penStyle, m_penWidth, m_penColor );
	CPen* pOldPen = (CPen*)memDC.SelectObject( &pen );

	CBrush brush, oldBrush;
	brush.CreateSolidBrush( m_regColor );
	CBrush* pOldBrush = (CBrush*)memDC.SelectObject( brush );
	oldBrush.FromHandle((HBRUSH)pOldBrush);

	CRect rect( 480, 80, 501, 320 );
	memDC.Rectangle( &rect );
	// text "EX/MEM"
	rect.left = 460; rect.right = 521; rect.top = 65; rect.bottom = 80;
	memDC.DrawText( "EX/MEM", &rect, DT_CENTER | DT_VCENTER );

	memDC.SelectObject( &oldBrush );
	memDC.SelectObject( pOldPen );
}

// MEM
void CIntegerDatapathCtrl::MEMCircuits()
{
	CPen pen;
	pen.CreatePen( m_penStyle, m_penWidth, m_penColor );
	CPen* pOldPen = (CPen*)memDC.SelectObject( &pen );

	CBrush brush, oldBrush;
	brush.CreateSolidBrush( RGB(197, 197, 243) );
	CBrush* pOldBrush = (CBrush*)memDC.SelectObject( brush );
	oldBrush.FromHandle((HBRUSH)pOldBrush);

	// Data Memory
	CRect rect( 540, 190, 590, 260 );
	memDC.Rectangle( &rect );
	// text "Data memory"
	rect.top = 210;
	memDC.DrawText( "Data\nmemory", &rect, DT_CENTER | DT_VCENTER );

	MEMLines( PS_SOLID, 1, m_penColor );

	memDC.SelectObject( &oldBrush );
	memDC.SelectObject( pOldPen );
}

void CIntegerDatapathCtrl::MEMLines( int penStyle, int penWidth, COLORREF penColor, CString& str )
{
	m_MEMPenStyle = penStyle;
	m_MEMPenWidth = penWidth;
	m_MEMPenColor = penColor;
	m_MEMStr = str;

	l27.Draw( &memDC, penStyle, penWidth, penColor );
	l28.Draw( &memDC, penStyle, penWidth, penColor );
	l29.Draw( &memDC, penStyle, penWidth, penColor );
	l30.Draw( &memDC, penStyle, penWidth, penColor );
	l31.Draw( &memDC, penStyle, penWidth, penColor );

	// show current instructions
	CRect rect( 480, 0, 605, 20 );
	COLORREF clr = memDC.SetTextColor( penColor );
	memDC.DrawText( str, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK );
	memDC.SetTextColor( clr );
}

void CIntegerDatapathCtrl::RestoreMEMLines( BOOL bCore )
{
	MEMLines( m_MEMPenStyle, m_MEMPenWidth, m_bkColor, m_MEMStr );
	m_MEMStr = _T("");
	if( bCore ) MEMLines( m_penStyle, m_penWidth, m_penColor );
}

// MEM/WB
void CIntegerDatapathCtrl::MEMWBRegs()
{
	CPen pen;
	pen.CreatePen( m_penStyle, m_penWidth, m_penColor );
	CPen* pOldPen = (CPen*)memDC.SelectObject( &pen );

	CBrush brush, oldBrush;
	brush.CreateSolidBrush( m_regColor );
	CBrush* pOldBrush = (CBrush*)memDC.SelectObject( brush );
	oldBrush.FromHandle((HBRUSH)pOldBrush);

	CRect rect( 605, 80, 626, 320 );
	memDC.Rectangle( &rect );
	// text "MEM/WB"
	rect.left = 590; rect.right = 640; rect.top = 65; rect.bottom = 80;
	memDC.DrawText( "MEM/WB", &rect, DT_CENTER | DT_VCENTER );

	memDC.SelectObject( &oldBrush );
	memDC.SelectObject( pOldPen );
}

// WB
void CIntegerDatapathCtrl::WBCircuits()
{
	CPen pen;
	pen.CreatePen( m_penStyle, m_penWidth, m_penColor );
	CPen* pOldPen = (CPen*)memDC.SelectObject( &pen );

	CBrush brush, oldBrush;
	brush.CreateSolidBrush( m_bkColor );
	CBrush* pOldBrush = (CBrush*)memDC.SelectObject( brush );
	oldBrush.FromHandle((HBRUSH)pOldBrush);

	// Mux
	CRect rect( 650, 215, 668, 255 );
	memDC.RoundRect( &rect, CPoint(17, 17) );
	// text "Mux"
	memDC.DrawText( "M\nu\nx", &rect, DT_CENTER | DT_VCENTER );

	WBLines( m_penStyle, m_penWidth, m_penColor );

	memDC.SelectObject( &oldBrush );
	memDC.SelectObject( pOldPen );
}

void CIntegerDatapathCtrl::WBLines( int penStyle, int penWidth, COLORREF penColor, CString& str )
{
	m_WBPenStyle = penStyle;
	m_WBPenWidth = penWidth;
	m_WBPenColor = penColor;
	m_WBStr = str;

	l32.Draw( &memDC, penStyle, penWidth, penColor );
	l33.Draw( &memDC, penStyle, penWidth, penColor );
	l34.Draw( &memDC, penStyle, penWidth, penColor );
	l35.Draw( &memDC, penStyle, penWidth, penColor );

	// show current instructions
	CRect rect( 605, 0, 720, 20 );
	COLORREF clr = memDC.SetTextColor( penColor );
	memDC.DrawText( str, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK );
	memDC.SetTextColor( clr );
}

void CIntegerDatapathCtrl::RestoreWBLines( BOOL bCore )
{
	WBLines( m_WBPenStyle, m_WBPenWidth, m_bkColor, m_WBStr );
	m_WBStr = _T("");
	if( bCore ) WBLines( m_penStyle, m_penWidth, m_penColor );
}


void CIntegerDatapathCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	memDC.LPtoDP( &point );

	// Registers rectangle
	do {
		CRect rect1( 232, 146, 284, 250 );
		if( rect1.PtInRect( point ) ) {
			CRegDlg dlg;
			dlg.m_bEditable = FALSE;
			dlg.DoModal();
			break;
		}

		CRect rect2( 540, 190, 590, 260 );
		if( rect2.PtInRect( point ) ) {
			CMemDlg dlg;
			dlg.m_bEditable = FALSE;
			dlg.DoModal();
			break;
		}
	} while( 0 );
	
	CWnd::OnLButtonDown(nFlags, point);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -