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

📄 amview.cpp

📁 本软件实现了模拟cpu的基本工作原理和工作过程
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	// TODO: add cleanup after printing
}

void CAMView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CAMView diagnostics

#ifdef _DEBUG
void CAMView::AssertValid() const
{
	CFormView::AssertValid();
}

void CAMView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CAMDoc* CAMView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAMDoc)));
	return (CAMDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CAMView message handlers
void CAMView::OnPaint() 
{
	CPaintDC dc(this); 
	dc.SetBkMode(TRANSPARENT);
	dc.SetTextColor(TextColor);
	
	Draw(DataBus,BusBrush,dc);
	DrawAU(BusBrush,dc);
	DrawCU(BusBrush,dc);
	DrawMEM(BusBrush,dc);
	DrawIO(BusBrush,dc);
}

void CAMView::DrawIO(CBrush& BusBrush,CPaintDC& dc)
{
	OldBrush=dc.SelectObject(&SecBrush);
	dc.Rectangle(840,270,960,353);
	dc.SelectObject(OldBrush);
	//画器件
	Draw(io.INPUT,dc);
	Draw(io.OUTPUT,dc);
	//可闪布线
	Draw(io.WRITE[0],BusBrush);
	Draw(io.WRITE[1],BusBrush);
	Draw(io.DISPLACE[0],BusBrush);
	Draw(io.DISPLACE[1],BusBrush);
}

void CAMView::DrawMEM(CBrush& BusBrush,CPaintDC& dc)
{
	OldBrush=dc.SelectObject(&SecBrush);
	dc.Rectangle(840,46,960,260);
	dc.SelectObject(OldBrush);
	//画器件
	Draw(mem.AR,dc);
	Draw(mem.MEMERY,dc);
	//不可闪布线
	DrawBus(872,84,12,16,1,0,1,BusBrush);//μSP=>μSTACK
	//可闪布线
	Draw(mem.GAR,BusBrush);
	Draw(mem.WRITE,BusBrush);
	Draw(mem.READ,BusBrush);
}

void CAMView::DrawCU(CBrush& BusBrush,CPaintDC& dc)
{
	OldBrush=dc.SelectObject(&SecBrush);
	dc.Rectangle(400,46,820,353);
	dc.SelectObject(OldBrush);
	OldFont=dc.SelectObject(&Font);
	dc.TextOut(680,60,"至各部件的控制信号");
	dc.SelectObject(&BigFont);
	dc.TextOut(550,307,"控制器");
	dc.SelectObject(OldFont);
	
	//画器件
	Draw(cu.IR,dc);
	Draw(cu.MAPROM,dc);
	Draw(cu.CMDR,dc);
	Draw(cu.MUX,dc);
	Draw(cu.MPC,dc);
	//不可闪布线
	DrawBus(444,110,12,19,1,0,1,BusBrush);//μSP=>μSTACK
	DrawBus(574,110,12,19,1,0,1,BusBrush);//-1=>R/C
	DrawBus(444,173,12,63,1,0,1,BusBrush);//μSTACK=>MUX
	DrawBus(574,173,12,63,1,0,1,BusBrush);//R/C=>MUX
	DrawBus(473,145,23,12,0,1,0,BusBrush);	//μPC=>μSTACK
	int i;
	for(i=0;i<8;i++) DrawBus(680+i*17,79,9,51,1,1,0,BusBrush);//MAPROM=>D
	//可闪布线
	
	Draw(cu.IR_MAPROM,BusBrush);
	for(i=0;i<3;i++)Draw(cu.MUX_CM[i],BusBrush);
	for(i=0;i<5;i++)Draw(cu.MUX_MPC[i],BusBrush);
	Draw(cu.CM_CMDR,BusBrush);
	
	Draw(cu.GIR,BusBrush);
	Draw(cu.ITOIB,BusBrush);
	Draw(cu.INC_MPC,BusBrush);
	Draw(cu.MAPROM_D,BusBrush);
	Draw(cu.CMDR_D,BusBrush);
	Draw(cu.MPC_MUX,BusBrush);
	Draw(cu.D_MUX,BusBrush);
}

void CAMView::DrawAU(CBrush& BusBrush,CPaintDC& dc)
{
	OldBrush=dc.SelectObject(&SecBrush);
	dc.Rectangle(36,46,380,640);
	dc.SelectObject(OldBrush);
	OldFont=dc.SelectObject(&BigFont);
	dc.TextOut(220,580,"运算器");
	dc.SelectObject(OldFont);
	
	//画器件
	Draw(au.A_port,dc);
	Draw(au.B_port,dc);
	Draw(au.regs,dc);
	Draw(au.Q,dc);
	Draw(au.STA,dc);
	DrawALU(dc);
	//布线
	Draw(au.R_ALU,BusBrush);
	Draw(au.S_ALU,BusBrush);
	Draw(au.REG_A,BusBrush);
	Draw(au.REG_B,BusBrush);
	Draw(au.IBTOF,BusBrush);
	
	Draw(au.RTOIB,BusBrush);
	Draw(au.FTOIB,BusBrush);
	Draw(au.F_Y,BusBrush);
	Draw(au.A_R,BusBrush);
	Draw(au.B_S,BusBrush);
	Draw(au.REG_L,BusBrush);
	Draw(au.REG_N,BusBrush);
	Draw(au.REG_R,BusBrush);
	Draw(au.Q_L,BusBrush);
	Draw(au.Q_N,BusBrush);
	Draw(au.Q_R,BusBrush);
	int i;
	for(i=0;i<5;i++)Draw(au.A_Y[i],BusBrush);
	for(i=0;i<3;i++)Draw(au.A_S[i],BusBrush);
	for(i=0;i<3;i++)Draw(au.Q_S[i],BusBrush);
	for(i=0;i<3;i++)Draw(au.D_R[i],BusBrush);
	for(i=0;i<5;i++)Draw(au.F_REG[i],BusBrush);
	for(i=0;i<5;i++)Draw(au.F_Q[i],BusBrush);
	for(i=0;i<5;i++)Draw(au.Q_Q[i],BusBrush);
	
	OldFont=dc.SelectObject(&Font);
	dc.TextOut(82,382,"00-03");
	dc.TextOut(82,410,"04-07");
	dc.TextOut(82,438,"08-11");
	dc.TextOut(82,466,"12-15");
	dc.SelectObject(OldFont);
}

void CAMView::DrawALU(CPaintDC& dc)
{
	POINT ALU[7];
	ALU[0].x=140;
	ALU[0].y=140;
	ALU[1].x=80;
	ALU[1].y=200;
	ALU[2].x=158;
	ALU[2].y=200;
	ALU[3].x=169;
	ALU[3].y=190;
	ALU[4].x=180;
	ALU[4].y=200;
	ALU[5].x=255;
	ALU[5].y=200;
	ALU[6].x=195;
	ALU[6].y=140;
	
	CBrush AluBrush;
	AluBrush.CreateSolidBrush(dc.GetBkColor());


	OldBrush=dc.SelectObject(&AluBrush);
	dc.Polygon(ALU,7);
	dc.SelectObject(OldBrush);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void CAMView::Draw(BOX box,CPaintDC& dc)
{
	OldBrush=dc.SelectObject(&BoxBrush);
	dc.Rectangle(&box.pos);
	dc.SelectObject(OldBrush);
	
	OldFont=dc.SelectObject(&Font);
	
	CPoint position=box.pos.TopLeft();
	position.x+=2;
	position.y+=2;
	
	dc.TextOut(position.x,position.y,box.title);
	dc.SelectObject(OldFont);
}

void CAMView::DrawBus(int x,int y,int w,int h,int type,int arrow1,int arrow2,CBrush& brush)
{
	CClientDC dc(this);
	int x_scale=3;
	if(x_scale*2 >= w)x_scale=w/2-2;
	if(x_scale<0)x_scale=0;
	
	int y_scale=3;
	if(y_scale*2 >= h)y_scale=h/2-2;
	if(y_scale<0)y_scale=0;
	
	OldBrush=dc.SelectObject(&brush);
	
	POINT point[3];
	
	if(type==0){
		if(arrow1){
			point[0].x=x;
			point[0].y=y+h/2;
			point[1].x=x+h/2;
			point[1].y=y;
			point[2].x=x+h/2;
			point[2].y=y+h;
			dc.Polygon(point,3);
		}
		if(arrow2){
			point[0].x=x+w-1;
			point[0].y=y+h/2;
			point[1].x=x+w-h/2-1;
			point[1].y=y;
			point[2].x=x+w-h/2-1;
			point[2].y=y+h;
			dc.Polygon(point,3);
		}
		if(arrow1 && arrow2)		dc.Rectangle(x+h/2,y+y_scale,x+w-h/2,y+h-y_scale);
		else if(arrow1 && !arrow2)	dc.Rectangle(x+h/2,y+y_scale,    x+w,y+h-y_scale);
		else if(!arrow1 && arrow2)	dc.Rectangle(    x,y+y_scale,x+w-h/2,y+h-y_scale);
		else						dc.Rectangle(    x,y+y_scale,    x+w,y+h-y_scale);
	}
	else{
		if(arrow1){
			point[0].x=x+w/2;
			point[0].y=y;
			point[1].x=x;
			point[1].y=y+w/2;
			point[2].x=x+w;
			point[2].y=y+w/2;
			dc.Polygon(point,3);
		}
		if(arrow2){
			point[0].x=x+w/2;
			point[0].y=y+h-1;
			point[1].x=x;
			point[1].y=y+h-w/2-1;
			point[2].x=x+w;
			point[2].y=y+h-w/2-1;
			dc.Polygon(point,3);
		}
		if(arrow1 && arrow2)		dc.Rectangle(x+x_scale,y+w/2,x+w-x_scale,y+h-w/2);
		else if(arrow1 && !arrow2)	dc.Rectangle(x+x_scale,y+w/2,x+w-x_scale,    y+h);
		else if(!arrow1 && arrow2)	dc.Rectangle(x+x_scale,    y,x+w-x_scale,y+h-w/2);
		else						dc.Rectangle(x+x_scale,    y,x+w-x_scale,    y+h);
	}
	dc.SelectObject(OldBrush);
	
}
void CAMView::DrawBus(int x,int y,int w,int h,int type,int arrow1,int arrow2,CBrush& brush,CPaintDC& dc)
{
	int x_scale=3;
	if(x_scale*2 >= w)x_scale=w/2-2;
	if(x_scale<0)x_scale=0;
	
	int y_scale=3;
	if(y_scale*2 >= h)y_scale=h/2-2;
	if(y_scale<0)y_scale=0;
	
	OldBrush=dc.SelectObject(&brush);
	
	POINT point[3];
	
	if(type==0){
		if(arrow1){
			point[0].x=x;
			point[0].y=y+h/2;
			point[1].x=x+h/2;
			point[1].y=y;
			point[2].x=x+h/2;
			point[2].y=y+h;
			dc.Polygon(point,3);
		}
		if(arrow2){
			point[0].x=x+w-1;
			point[0].y=y+h/2;
			point[1].x=x+w-h/2-1;
			point[1].y=y;
			point[2].x=x+w-h/2-1;
			point[2].y=y+h;
			dc.Polygon(point,3);
		}
		if(arrow1 && arrow2)		dc.Rectangle(x+h/2,y+y_scale,x+w-h/2,y+h-y_scale);
		else if(arrow1 && !arrow2)	dc.Rectangle(x+h/2,y+y_scale,    x+w,y+h-y_scale);
		else if(!arrow1 && arrow2)	dc.Rectangle(    x,y+y_scale,x+w-h/2,y+h-y_scale);
		else						dc.Rectangle(    x,y+y_scale,    x+w,y+h-y_scale);
	}
	else{
		if(arrow1){
			point[0].x=x+w/2;
			point[0].y=y;
			point[1].x=x;
			point[1].y=y+w/2;
			point[2].x=x+w;
			point[2].y=y+w/2;
			dc.Polygon(point,3);
		}
		if(arrow2){
			point[0].x=x+w/2;
			point[0].y=y+h-1;
			point[1].x=x;
			point[1].y=y+h-w/2-1;
			point[2].x=x+w;
			point[2].y=y+h-w/2-1;
			dc.Polygon(point,3);
		}
		if(arrow1 && arrow2)		dc.Rectangle(x+x_scale,y+w/2,x+w-x_scale,y+h-w/2);
		else if(arrow1 && !arrow2)	dc.Rectangle(x+x_scale,y+w/2,x+w-x_scale,    y+h);
		else if(!arrow1 && arrow2)	dc.Rectangle(x+x_scale,    y,x+w-x_scale,y+h-w/2);
		else						dc.Rectangle(x+x_scale,    y,x+w-x_scale,    y+h);
	}
	dc.SelectObject(OldBrush);
	
}

void CAMView::Draw(LINE line,CBrush& brush)
{
	DrawBus(line.x,line.y,line.w,line.h,line.type,line.arrow1,line.arrow2,brush);
}
void CAMView::Draw(LINE line,CBrush& brush,CPaintDC& dc)
{
	DrawBus(line.x,line.y,line.w,line.h,line.type,line.arrow1,line.arrow2,brush,dc);
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void CAMView::OnButtonTime() 
{
	SetTimer(1,100,NULL);
	count=0;
	
	
	au.REG_A.shine=1;
	au.REG_B.shine=1;
	au.R_ALU.shine=1;
	au.S_ALU.shine=1;
	au.IBTOF.shine=1;
	
	au.RTOIB.shine=1;
	au.FTOIB.shine=1;
	au.IBTOF.shine=1;
	au.F_Y.shine=1;
	au.A_R.shine=1;
	au.B_S.shine=1;
	au.REG_L.shine=1;
	au.REG_N.shine=1;
	au.REG_R.shine=1;
	au.Q_L.shine=1;
	au.Q_N.shine=1;
	au.Q_R.shine=1;
	
	au.A_Y[0].shine=1;
	au.A_S[0].shine=1;
	au.Q_S[0].shine=1;
	au.D_R[0].shine=1;
	au.F_REG[0].shine=1;
	au.F_Q[0].shine=1;
	au.Q_Q[0].shine=1;
	
	cu.GIR.shine=1;
	cu.ITOIB.shine=1;
	cu.INC_MPC.shine=1;
	cu.MAPROM_D.shine=1;
	cu.CMDR_D.shine=1;
	cu.MPC_MUX.shine=1;
	cu.D_MUX.shine=1;
	
	cu.MAPROM_D.shine=1;
	cu.CMDR_D.shine=1;
	cu.MPC_MUX.shine=1;
	cu.D_MUX.shine=1;
	
	cu.IR_MAPROM.shine=1;
	cu.MUX_CM[0].shine=1;
	cu.MUX_MPC[0].shine=1;
	cu.CM_CMDR.shine=1;
	
	/////////////KLKJHGKJH
	
	mem.GAR.shine=1;
	mem.WRITE.shine=1;
	mem.READ.shine=1;
	
	io.WRITE[0].shine=1;
	io.DISPLACE[0].shine=1;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
void CAMView::OnButtonWrite() 
{
	cmpl=new CMPL;
	cmpl->DoModal();
	
	delete cmpl;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void CAMView::cvrt(int num,char* string)//把(16bit)整数转化为char[4]
{
	int temp;
	int low=4096;
	int hight=65536;
	int i=0;
	while(1){
		temp=(num%hight)/low;
		if(temp<=9)string[i]=temp+'0';
		else string[i]=temp-10+'A';
		if((++i)==4)break;
		hight=low;
		low/=16;
	}
	string[i]=0;
}
void CAMView::MemValueCvrt(unsigned short* num,CString& word)//把unsigned short[8]转化为分作8行存储的CString
{
	char temp[5];
	cvrt(num[0],temp);
	word=temp;
	for(int i=1;i<8;i++){
		cvrt(num[i],temp);
		word+="\r\n";
		word+=temp;
	}
}
void CAMView::sernum2cstr(int page,CString& word)
{
	int num=page*8;
	char temp[5];
	cvrt(num,temp);
	word=temp;
	for(int i=1;i<8;i++){
		word+="\r\n";
		cvrt(++num,temp);
		word+=temp;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void CAMView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	int m;
	switch(nSBCode){
		if(pScrollBar==&m_mem_scroll){
	case SB_THUMBTRACK:
		pScrollBar->SetScrollPos(nPos);	
		MemValueCvrt(memory+nPos*8,m_mem_data);
		sernum2cstr(nPos,m_mem_addr);
		UpdateData(false);
		break;
	case SB_LINEDOWN://单击滚动条右边的箭头
		m=m_mem_scroll.GetScrollPos();
		m=((m>=8191) ? 8191 : m+1);
		m_mem_scroll.SetScrollPos(m);
		sernum2cstr(m,m_mem_addr);
		MemValueCvrt(memory+m*8,m_mem_data);
		UpdateData(false);
		break;
	case SB_LINEUP://单击滚动条左边的箭头
		m=m_mem_scroll.GetScrollPos();
		m=((m<=0)?0:m-1);
		m_mem_scroll.SetScrollPos(m);
		sernum2cstr(m,m_mem_addr);
		MemValueCvrt(memory+m*8,m_mem_data);
		UpdateData(false);
		break;
	case SB_PAGEDOWN://单击滚动条右边的箭头与滑块之间的区域
		m=m_mem_scroll.GetScrollPos();
		m+=8;
		(m>8191)?m=8191:NULL;
		m_mem_scroll.SetScrollPos(m);
		sernum2cstr(m,m_mem_addr);
		MemValueCvrt(memory+m*8,m_mem_data);
		UpdateData(false);
		break;
	case SB_PAGEUP://单击滚动条左边的箭头与滑块之间的区域
		m=m_mem_scroll.GetScrollPos();
		m-=8;
		(m<=0)?m=0:NULL;
		sernum2cstr(m,m_mem_addr);
		m_mem_scroll.SetScrollPos(m);
		MemValueCvrt(memory+m*8,m_mem_data);

⌨️ 快捷键说明

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