📄 mcodecontrolunit.java
字号:
import java.awt.*;
import java.awt.event.*;
public
class McodeControlUnit
extends Frame
implements ActionListener
{
private static final int COND_MASK = 0x60000;
private static final int OPER_MASK = 0x0fff0;
private static final int ARPC_MASK = 0x04000;
private static final int PCDR_MASK = 0x02000; // this was ARIN_MASK
private static final int ARDR_MASK = 0x01000; // this was ARDT_MASK
private static final int PCIN_MASK = 0x00800;
private static final int DRM_MASK = 0x00400;
private static final int IRDR_MASK = 0x00200;
private static final int PLUS_MASK = 0x00100;
private static final int ACIN_MASK = 0x00080;
private static final int AND_MASK = 0x00040;
// private static final int DRAC_MASK = 0x00200000;
// private static final int PCDT_MASK = 0x00800000;
// private static final int BT_MASK = 0x10000000;
// private static final int MINU_MASK = 0x00002000;
// private static final int ACZO_MASK = 0x00000800;
// private static final int RAC_MASK = 0x00080000;
// private static final int ZALU_MASK = 0x00040000;
// private static final int TRDR_MASK = 0x00020000;
// private static final int ACDR_MASK = 0x00010000;
// private static final int ACR_MASK = 0x00008000;
// private static final int OR_MASK = 0x00000200;
// private static final int XOR_MASK = 0x00000100;
// private static final int NOT_MASK = 0x00000080;
// private static final int MDR_MASK = 0x00000040;
private static final int ADDR_MASK = 0x0003f;
private static final int COND_1 = 0x00000;
private static final int COND_X = 0x20000;
// private static final int BT_JUMP = 0x00000000;
// private static final int BT_MAP = 0x10000000;
private static final int OPER_ARPC = 0x04000;
private static final int OPER_PCDR = 0x02000; // this was ARIN_MASK
private static final int OPER_ARDR = 0x01000; // this was ARDT_MASK
private static final int OPER_PCIN = 0x00800;
private static final int OPER_DRM = 0x00400;
private static final int OPER_IRDR = 0x00200;
private static final int OPER_PLUS = 0x00100;
private static final int OPER_ACIN = 0x00080;
private static final int OPER_AND = 0x00040;
// private static final int OPER_ARIN = 0x04000000;
// private static final int OPER_ARDT = 0x02000000;
// private static final int OPER_PCDT = 0x00800000;
// private static final int OPER_DRAC = 0x00200000;
// private static final int OPER_RAC = 0x00080000;
// private static final int OPER_ZALU = 0x00040000;
// private static final int OPER_TRDR = 0x00020000;
// private static final int OPER_ACDR = 0x00010000;
// private static final int OPER_ACR = 0x00008000;
// private static final int OPER_MINU = 0x00002000;
// private static final int OPER_ACZO = 0x00000800;
// private static final int OPER_OR = 0x00000200;
// private static final int OPER_XOR = 0x00000100;
// private static final int OPER_NOT = 0x00000080;
// private static final int OPER_MDR = 0x00000040;
private static final int ADDR_X = 0x0003f;
public McodeControlUnit( CPU parent, String title )
{
super( title );
cpu = parent;
active = false;
skipAnimation = false;
currentDotEnabled[ 0 ] = false;
currentDotEnabled[ 1 ] = false;
currentDotEnabled[ 2 ] = false;
currentDotEnabled[ 3 ] = false;
reset();
MenuBar mb = new MenuBar();
fileMenu = new Menu( "File" );
closeWindowMenuItem = new MenuItem( "Close Window" );
closeWindowMenuItem.addActionListener( this );
fileMenu.add( closeWindowMenuItem );
mb.add( fileMenu );
setMenuBar( mb );
// mcuCanvasScrollPane =
// new ScrollPane()
// {
// public Dimension getPreferredSize()
// {
// Dimension preferredSize = mcuCanvas.getPreferredSize();
// preferredSize.height += getHScrollbarHeight();
// preferredSize.width += getVScrollbarWidth();
// return ( preferredSize );
// }
// };
// mcuCanvasScrollPane.add( mcuCanvas );
// add( mcuCanvasScrollPane );
add( mcuCanvas );
addWindowListener(
new WindowAdapter()
{
public void windowClosing( WindowEvent evt )
{
setVisible( false );
}
}
);
pack();
setSize( 315, 500 );
}
public boolean getSkipAnimation()
{
return ( skipAnimation );
}
public void setSkipAnimation( boolean skip )
{
skipAnimation = skip;
}
public void reset()
{
clear();
addressRegister = 15; //was 0
updateCurrentAddress();
updateCurrentOperations();
updateCurrentSignals();
updateConditionMuxSelect();
// updateConditionMuxSignals();
// updateLogicBTInput();
updateLogicConditionInput();
updateLogicSelect();
updateIRMap();
updateAddressMuxSignals();
updateAddressMux();
justUpdatedCurrentAddress = false;
animationIndex = 0;
animUpdCurrAddrDone = false;
animUpdCurrOperDone = false;
// animUpdCurrLogSelBTDone = false;
animUpdCurrLogSelCondDone = false;
animUpdAddrMuxDone = false;
animUpdIRMapDone = false;
}
public void clear()
{
// hw1Enabled = false;
// zEnabled = false;
// notZEnabled = false;
clkEnabled = false;
irPathEnabled = false;
// currAddrP1Enabled = false;
nextAddrEnabled = false;
irMapEnabled = false;
currentARPC = false;
currentARDR = false;
currentPCIN = false;
currentPCDR = false;
currentDRM = false;
currentIRDR = false;
currentPLUS = false;
currentAND = false;
currentACIN = false;
// currentARIN = false;
// currentARDT = false;
// currentPCDT = false;
// currentDRAC = false;
// currentMINU = false;
// currentRAC = false;
// currentZALU = false;
// currentTRDR = false;
// currentACDR = false;
// currentACR = false;
// currentACZO = false;
// currentOR = false;
// currentXOR = false;
// currentNOT = false;
// currentMDR = false;
setDot( 0, false, null );
setDot( 1, false, null );
setDot( 2, false, null );
setDot( 3, false, null );
}
public void canvasRepaint()
{
mcuCanvas.repaint();
}
public void canvasRepaint( int tm )
{
mcuCanvas.repaint( tm );
}
public void executeCycle()
{
if ( skipAnimation || ( ! active ) || ( ! isShowing() ) )
{
animationIndex = 0;
clear();
cpu.setCurrentCLK( true );
clkEnabled = true;
if ( ! justUpdatedCurrentAddress )
{
updateAddressRegister();
updateCurrentAddress();
}
updateCurrentOperations();
updateCurrentSignals();
updateConditionMuxSelect();
// updateConditionMuxSignals();
// updateLogicBTInput();
updateLogicConditionInput();
updateLogicSelect();
updateAddressMuxSignals();
updateAddressMux();
animUpdCurrAddrDone = false;
animUpdCurrOperDone = false;
// animUpdCurrLogSelBTDone = false;
animUpdCurrLogSelCondDone = false;
animUpdAddrMuxDone = false;
justUpdatedCurrentAddress = false;
cpu.setStallAnimationCounter( false );
}
else
{
cpu.setStallAnimationCounter( ! executeAnimationCycle() );
canvasRepaint();
}
}
public byte updateIRMap()
{
if ( cpu.theBox.IRint == AssemblyInstruction.opcodeEND )
{
irMap = ( byte ) ( ( 0x0f ) );
}
else
{
irMap = ( byte ) ( ( cpu.theBox.IRint | 0x04 ) << 1);
}
return ( irMap );
}
public byte updateConditionMuxSelect()
{
int currentMC = microcode[ currentAddress ];
int currentCond = currentMC & COND_MASK;
if ( currentCond == COND_1 )
{
conditionMuxSelect = 0;
}
/* else if ( currentCond == COND_Z )
{
conditionMuxSelect = 1;
}
else if ( currentCond == COND_NOT_Z )
{
conditionMuxSelect = 2;
}
*/
else
{
conditionMuxSelect = 1;
}
return ( conditionMuxSelect );
}
/* public void updateConditionMuxSignals()
{
if ( conditionMuxSelect == 0 )
{
hw1Enabled = true;
zEnabled = false;
notZEnabled = false;
}
else if ( conditionMuxSelect == 1 )
{
hw1Enabled = false;
zEnabled = true;
notZEnabled = false;
}
else if ( conditionMuxSelect == 2 )
{
hw1Enabled = false;
zEnabled = false;
notZEnabled = true;
}
else
{
hw1Enabled = false;
zEnabled = false;
notZEnabled = false;
}
}
*/
/* public boolean updateLogicBTInput()
{
int currentMC = microcode[ currentAddress ];
int currentBT = currentMC & BT_MASK;
if ( currentBT == BT_JUMP )
{
logicBTInput = false;
}
else
{
logicBTInput = true;
}
return ( logicBTInput );
}
*/
public boolean updateLogicConditionInput()
{
if ( conditionMuxSelect == 0 )
{
// Hardwired 1
logicConditionInput = false;
}
/* else if ( conditionMuxSelect == 1 )
{
Calculate Z
if ( cpu.theBox.Zint == 0 )
{
logicConditionInput = false;
}
else
{
logicConditionInput = true;
}
}
else if ( conditionMuxSelect == 2 )
{
Calculate /Z
if ( cpu.theBox.Zint == 0 )
{
logicConditionInput = true;
}
else
{
logicConditionInput = false;
}
}
*/
else
{
logicConditionInput = true;
}
return ( logicConditionInput );
}
public byte updateLogicSelect()
{
if ( ! logicConditionInput )
{
logicSelect = 0;
}
else if ( logicConditionInput )
{
logicSelect = 1;
}
// else if ( logicBTInput )
// {
// logicSelect = 2;
// }
/* if ( ! logicConditionInput )
{
logicSelect = 0;
}
else if ( logicConditionInput )
{
logicSelect = 1;
}
*/
return ( logicSelect );
}
public void updateAddressMuxSignals()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -