📄 amview.cpp
字号:
UpdateData(false);
break;
}
}
CFormView::OnVScroll(nSBCode, nPos, pScrollBar);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void CAMView::short2CString(unsigned short num,CString& str)
{
char temp[5];
cvrt(num,temp);
str=temp;
}
unsigned short CAMView::CString2short(CString& str)
{
unsigned short num=0;
char temp[5];
strcpy(temp,str);
for(int i=0;i<4;i++){
num*=16;
if(temp[i]<='9')num+=temp[i]-'0';
else num+=temp[i]-'A'+10;
}
return num;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
unsigned short CAMView::RegGetValue(unsigned short RegSelect)
{
switch(RegSelect){
case 0:
return CString2short(m_r0);
case 1:
return CString2short(m_r1);
case 2:
return CString2short(m_r2);
case 3:
return CString2short(m_r3);
case 4:
return CString2short(m_r4);
case 5:
return CString2short(m_r5);
case 6:
return CString2short(m_r6);
case 7:
return CString2short(m_r7);
case 8:
return CString2short(m_r8);
case 9:
return CString2short(m_r9);
case 10:
return CString2short(m_r10);
case 11:
return CString2short(m_r11);
break;
case 12:
return CString2short(m_r12);
case 13:
return CString2short(m_r13);
case 14:
return CString2short(m_r14);
case 15:
return CString2short(m_r15);
default:
MessageBox("寄存器选择号出错!");
return 0;
}
}
void CAMView::RegWrite(unsigned short RegSelect,unsigned short value)
{
switch(RegSelect){
case 0:
short2CString(value,m_r0);
break;
case 1:
short2CString(value,m_r1);
break;
case 2:
short2CString(value,m_r2);
break;
case 3:
short2CString(value,m_r3);
break;
case 4:
short2CString(value,m_r4);
short2CString(value,m_sp);
break;
case 5:
short2CString(value,m_r5);
short2CString(value,m_pc);
break;
case 6:
short2CString(value,m_r6);
short2CString(value,m_ip);
break;
case 7:
short2CString(value,m_r7);
break;
case 8:
short2CString(value,m_r8);
break;
case 9:
short2CString(value,m_r9);
break;
case 10:
short2CString(value,m_r10);
break;
case 11:
short2CString(value,m_r11);
break;
case 12:
short2CString(value,m_r12);
break;
case 13:
short2CString(value,m_r13);
break;
case 14:
short2CString(value,m_r14);
break;
case 15:
short2CString(value,m_r15);
break;
default:
MessageBox("寄存器选择号出错!");
break;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void CAMView::Run()
{
int mode=GetCheckedRadioButton(IDC_MICROSTEP_RADIO,IDC_CONTINUE_RADIO);
if((mode==IDC_MACHINESTEP_RADIO)&&(m_mux=="0018"))SetTimer(2,2000,NULL);
//else if(mode==IDC_CONTINUE_RADIO) {
// if(!(m_mux=="00A4" && memory[CString2short(m_r5)]==0xFC00))OnRunButton();
// else KillTimer(2);
// }
//==========ALU结果写回==========
switch(MicroInst.m_i86){
case 0://F->Q
//if(au.Q_N.shine)
m_q=m_alu;
break;
case 1://NOP
break;
case 2://F->B
case 3://F->B
//if(au.REG_N.shine)
RegWrite(RB,CString2short(m_alu));
break;
//省略case 4:
case 5://F/2->B
//if(au.REG_R.shine)
{
unsigned short num;
num=CString2short(m_alu)/2;
//向右移位时最高位的补位MAM3
if(MicroInst.m_ssh==0 || (MicroInst.m_ssh==3 && m_sta_c==0))num=num & 32767;
else if(MicroInst.m_ssh==1 || (MicroInst.m_ssh==3 && m_sta_c==1))num=num | 32768;
else MessageBox("上一条指令的移位控制位SSH出错!");
RegWrite(RB,num);
}
break;
//省略case 6:
case 7://2*F->B
//if(au.REG_L.shine)
{
unsigned short num;
num=CString2short(m_alu)*2;
//向左移位时最低位的补位MAM0
if(MicroInst.m_ssh==0 || (MicroInst.m_ssh==3 && m_sta_c==0)) ;
else if(MicroInst.m_ssh==1 || (MicroInst.m_ssh==3 && m_sta_c==1))num=num | 1;
else MessageBox("上一条指令的移位控制位SSH出错!");
RegWrite(RB,num);
}
break;
}
//==========状态标志位写回==========
unsigned short BusNum=CString2short(m_bus);
switch(MicroInst.m_sst){
case 0:
break;
case 1:
m_sta_c=m_cy;
m_sta_z=m_zr;
m_sta_v=m_ov;
m_sta_s=m_f3;
break;
case 2://INNER BUS 7~4->STATE REGISTER
m_sta_c=((BusNum & 0x0080)? 1:0);
m_sta_z=((BusNum & 0x0040)? 1:0);
m_sta_c=((BusNum & 0x0020)? 1:0);
m_sta_c=((BusNum & 0x0010)? 1:0);
break;
case 3:
m_sta_c=0;
break;
case 4:
m_sta_c=1;
break;
case 5:
m_sta_c=((CString2short(m_alu) & 1) ? 1:0);
break;
case 6:
m_sta_c=((CString2short(m_alu) & 0x8000) ? 1:0);
//省略case 7:
default:
MessageBox("状态位的产生控制出错!");
}
//==========寄存器接收总线数据==========
if(MicroInst.m_dc2==0) ;
else if(MicroInst.m_dc2==1){
m_instruction=m_bus;
m_map=maprom[(CString2short(m_instruction))>>10];
}
else if(MicroInst.m_dc2==2)m_addr=m_bus;
else MessageBox("寄存器接收总线数据控制(DC2)出错!");
//==========搽除上一次的闪烁控制==========
au.REG_A.shine=0;
au.REG_B.shine=0;
au.R_ALU.shine=0;
au.S_ALU.shine=0;
au.IBTOF.shine=0;
au.RTOIB.shine=0;
au.FTOIB.shine=0;
au.F_Y.shine=0;
au.A_R.shine=0;
au.B_S.shine=0;
au.REG_L.shine=0;
au.REG_N.shine=0;
au.REG_R.shine=0;
au.Q_L.shine=0;
au.Q_N.shine=0;
au.Q_R.shine=0;
au.A_Y[0].shine=0;
au.A_S[0].shine=0;
au.Q_S[0].shine=0;
au.D_R[0].shine=0;
au.F_REG[0].shine=0;
au.F_Q[0].shine=0;
au.Q_Q[0].shine=0;
cu.GIR.shine=0;
cu.ITOIB.shine=0;
cu.INC_MPC.shine=0;
cu.MAPROM_D.shine=0;
cu.CMDR_D.shine=0;
cu.MPC_MUX.shine=0;
cu.D_MUX.shine=0;
mem.GAR.shine=0;
mem.WRITE.shine=0;
mem.READ.shine=0;
io.WRITE[0].shine=0;
io.DISPLACE[0].shine=0;
au.REG_A.shine=0;
au.REG_B.shine=0;
au.R_ALU.shine=0;
au.S_ALU.shine=0;
au.IBTOF.shine=0;
cu.IR_MAPROM.shine=0;
cu.MUX_CM[0].shine=0;
cu.MUX_MPC[0].shine=0;
cu.CM_CMDR.shine=0;
OnPaint();
//==========加载==========
if(m_mux=="00A4"){
UpdateData(true);
int mode=GetCheckedRadioButton(IDC_MICROSTEP_RADIO,IDC_CONTINUE_RADIO);
if(memory[CString2short(m_r5)]==0xFC00){
m_explain+="\r\n程序正常结束!";
MessageBox("程序正常结束!");
KillTimer(1);
KillTimer(2);
UpdateData(false);
GetDlgItem(IDC_STOP_BUTTON)->EnableWindow(FALSE);
GetDlgItem(IDC_RUN_BUTTON)->EnableWindow(FALSE);
GetDlgItem(IDC_START_BUTTON)->EnableWindow(TRUE);
GetDlgItem(IDC_MICROSTEP_RADIO)->EnableWindow(TRUE);
GetDlgItem(IDC_MACHINESTEP_RADIO)->EnableWindow(TRUE);
GetDlgItem(IDC_CONTINUE_RADIO)->EnableWindow(TRUE);
return;
}
else if(mode==IDC_MACHINESTEP_RADIO){
GetDlgItem(IDC_RUN_BUTTON)->EnableWindow(TRUE);
KillTimer(2);
}
m_mux="0018";
m_explain+="\r\n新机器指令:";
UpdateData(false);
}
MicroInst=mcode[CString2short(m_mux)];
m_explain+="\r\n";
m_explain+=info[CString2short(m_mux)].m_character;
m_cmdata="00";
m_cmdata+=(info[CString2short(m_mux)].m_number);
//==========INNER BUS 7~4->STATE REGISTER==========
if(MicroInst.m_sst==2)
au.IBTOF.shine=1;
//==========向IB总线发送数据控制==========
switch(MicroInst.m_dc1){
case 0://SWTOIB(Switch to InnerBus)
case 1://RTOIB(Result to InnerBus)
break;//留待ALU运算结果出来后处理
case 2://ITOIB(InstructionRegister to InnerBus)
m_bus=m_instruction;
cu.ITOIB.shine=1;
break;
case 3://FTOIB(Flags to InnerBus)
{
unsigned short num=0;
if(m_sta_c)num+=0x0080;
if(m_sta_z)num+=0x0040;
if(m_sta_v)num+=0x0020;
if(m_sta_s)num+=0x0010;
short2CString(num,m_bus);
au.FTOIB.shine=1;
}
break;
//4 ~ 7为关于中断的操作,这里不作处理
//case 4:
//case 5:
//case 6:
//case 7:
default:
MessageBox("向IB总线发送数据控制 DC1 出错!");
}
//==========寄存器选择==========
char tempchar[5];
unsigned short instruction=CString2short(m_instruction);
if(MicroInst.m_sa==0) RA=(int)MicroInst.m_a;
else RA=instruction%16;
itoa(RA,tempchar,10);
m_aport=tempchar;
m_aport+="号寄存器";
au.REG_A.shine=1;
if(MicroInst.m_sb==0) RB=(int)MicroInst.m_b;
else RB=(instruction/16)%16;
itoa(RB,tempchar,10);
m_bport=tempchar;
m_bport+="号寄存器";
au.REG_B.shine=1;
//==========A口B口选择==========
unsigned short r;
unsigned short s;
au.R_ALU.shine=1;
au.S_ALU.shine=1;
switch(MicroInst.m_i20){
case 0://R=A S=Q
r=RegGetValue(RA);
s=CString2short(m_q);
au.A_R.shine=1;
au.Q_S[0].shine=1;
break;
case 1://R=A S=B
r=RegGetValue(RA);
s=RegGetValue(RB);
au.A_R.shine=1;
au.B_S.shine=1;
break;
case 2://R=0 S=Q
r=0;
s=CString2short(m_q);
au.Q_S[0].shine=1;
break;
case 3://R=0 S=B
r=0;
s=RegGetValue(RB);
au.B_S.shine=1;
break;
case 4://R=0 S=A
r=0;
s=RegGetValue(RA);
au.A_S[0].shine=1;
break;
case 5://R=D S=A
r=CString2short(m_bus);
s=RegGetValue(RA);
au.D_R[0].shine=1;
au.A_S[0].shine=1;
break;
case 6://R=D S=Q
r=CString2short(m_bus);
s=CString2short(m_q);
au.D_R[0].shine=1;
au.Q_S[0].shine=1;
break;
case 7://R=D S=0
r=CString2short(m_bus);
s=0;
au.D_R[0].shine=1;
break;
default:
MessageBox("Am2901(ALU)指令I2-0出错!");
}
//==========ALU最低位进位选择(SCI)==========
unsigned short carry;
switch(MicroInst.m_sci){
case 0:
carry=0;
break;
case 1:
carry=1;
break;
case 2:
carry=m_sta_c;
break;
default:
MessageBox("ALU最低位进位选择(SCI)出错!");
}
//==========/MIO-REQ-/WE控制 1 ==========
if(MicroInst.m_mrw>=6)MessageBox("/MIO-REQ-/WE控制出错!");
else if(MicroInst.m_mrw==1){
short2CString(memory[CString2short(m_addr)],m_bus);
mem.READ.shine=1;
}
else if(MicroInst.m_mrw==3){
startdlg.m_title="输入设备送往总线的数据:";
startdlg.DoModal();
m_input=startdlg.m_startpoint;
m_bus=m_input;
io.WRITE[0].shine=1;
}
//==========ALU运算==========
m_cy=0;
m_ov=0;
unsigned short f;
switch(MicroInst.m_i53){
case 0://R+S
if((int)r+(int)s+(int)carry>=65536)m_cy=1;
else m_cy=0;
if((((r & 32767) + (s & 32767) + carry) & 32768) ^ m_cy) m_ov=1;
else m_ov=0;
m_operator="R+S=";
short2CString(f=r+s+carry,m_alu);
break;
case 1://S-R
r=~r+1;
if((int)r+(int)s+(int)carry>=65536)m_cy=1;
else m_cy=0;
if((((r & 32767) + (s & 32767) + carry) & 32768) ^ m_cy) m_ov=1;
else m_ov=0;
m_operator="S-R=";
short2CString(f=s+r+carry,m_alu);
r=~r+1;
break;
case 2://R-S
s=~s+1;
if((int)r+(int)s+(int)carry>=65536)m_cy=1;
else m_cy=0;
if((((r & 32767) + (s & 32767) + carry) & 32768) ^ m_cy) m_ov=1;
else m_ov=0;
m_operator="R-S=";
short2CString(f=r+s+carry,m_alu);
s=~s+1;
break;
case 3://R∨S
m_operator="R∨S=";
short2CString(f=r|s,m_alu);
break;
case 4://R∧S
m_operator="R∧S=";
short2CString(f=r&s,m_alu);
break;
case 5://~R∧S
m_operator="~R∧S=";
short2CString(f=(~r)&s,m_alu);
break;
case 6://R⊕S
m_operator="R⊕S=";
short2CString(f=r^s,m_alu);
break;
case 7://R⊙S
m_operator="R⊙S=";
short2CString(f=~(r^s),m_alu);
break;
default:
MessageBox("Am2901(ALU)指令I5-3出错!");
}
if(f==0)m_zr=1;
else m_zr=0;
if(f & 32768) m_f3=1;
else m_f3=0;
//==========ALU结果准备写回==========
switch(MicroInst.m_i86){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -