📄 memory.java
字号:
}
else if(arg.equals("Address D800h - DFFFh (55296 - 57343)"))
{
top=55296;
bottom=57344;
repaint();
return true;
}
else if(arg.equals("Address E000h - E7FFh (57344 - 59391)"))
{
top=57344;
bottom=59392;
repaint();
return true;
}
else if(arg.equals("Address E800h - EFFFh (59392 - 61439)"))
{
top=59392;
bottom=61440;
repaint();
return true;
}
else if(arg.equals("Address F000h - F7FFh (61440 - 63487)"))
{
top=61440;
bottom=63488;
repaint();
return true;
}
else if(arg.equals("Address F800h - FFFFh (63488 - 65535)"))
{
top=63488;
bottom=65536;
repaint();
return true;
}
*/
if(arg.equals("Close Window"))
{
setVisible( false );
return true;
}
else if(arg.equals("View memory in HEX"))
{
showType = 1;
repaint();
return true;
}
else if(arg.equals("View memory in BINARY"))
{
showType = 0;
repaint();
return true;
}
else return false;
}
public void actionPerformed( ActionEvent e )
{
Object eventSource = e.getSource();
if ( eventSource == editMemoryMenuItem )
{
editMemory = new EditMemoryDialog( this, "Edit Memory", true );
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension editMemoryDialogSize = editMemory.getSize();
Point editMemoryDialogLocation = new Point( ( screenSize.width -
editMemoryDialogSize.width ) / 2, ( screenSize.height -
editMemoryDialogSize.height ) / 2 );
editMemory.setLocation( editMemoryDialogLocation );
editMemory.setVisible( true );
}
else if ( eventSource == fillMemoryMenuItem )
{
fillMemory = new FillMemoryDialog( this, "Fill Memory", true );
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension fillMemoryDialogSize = fillMemory.getSize();
Point fillMemoryDialogLocation = new Point( ( screenSize.width -
fillMemoryDialogSize.width ) / 2, ( screenSize.height -
fillMemoryDialogSize.height ) / 2 );
fillMemory.setLocation( fillMemoryDialogLocation );
fillMemory.setVisible( true );
}
else if ( eventSource == clearMemoryMenuItem )
{
clear();
repaint();
}
}
public void paint( Graphics g )
{
Font boldFont = new Font( "SansSerif", Font.BOLD, 11 );
Font plainFont = new Font( "SansSerif", Font.PLAIN, 11 );
boolean binaryViewMode = ( showType == 0 );
for ( int contentsIndex = top; contentsIndex < bottom; contentsIndex
+= 4 )
{
int yPosition = ( 5 * contentsIndex ) - scrollvalue + 65 - ( 5 *
top );
int nybbleStringBase = ( binaryViewMode ? 2 : 16 );
int nybbleStringLength = ( binaryViewMode ? 4 : 1 );
g.setFont( boldFont );
g.drawString( contentsIndex + ":", 5, yPosition );
for ( int columnCounter = 0; columnCounter < 4;
columnCounter++ )
{
long upperNybble = ( contents[ contentsIndex + columnCounter ]
& 0xf0 ) >> 4;
long lowerNybble = contents[ contentsIndex + columnCounter ] &
0xf;
if ( ( contentsIndex + columnCounter ) == CPUBox.
simulationStartNumber )
{
g.setFont( boldFont );
}
else
{
g.setFont( plainFont );
}
g.drawString( AssemblyInstruction.toNumberString( upperNybble,
nybbleStringBase, nybbleStringLength ).toUpperCase() + " "
+ AssemblyInstruction.toNumberString( lowerNybble,
nybbleStringBase, nybbleStringLength ).toUpperCase(), 47 + (
62 * columnCounter ), yPosition );
}
}
}
public void clear()
{
for ( int index = 0; index < MEMORY_SIZE; index++ )
{
contents[ index ] = 0;
}
}
public void dispose()
{
//editMemory.dispose();
//fillMemory.dispose();
super.dispose();
}
public short read( int address )
{
//System.out.println( "DEBUG ==> Memory size="+MEMORY_SIZE+" <--> Read address: " + address);
if ( ( address < 0 ) || ( address >= MEMORY_SIZE ) )
{
return ( -1 );
}
else
{
return ( contents[ address ] );
}
}
public boolean write( int address, short data )
{
if ( ( address < 0 ) || ( address >= MEMORY_SIZE ) || ( data < 0 ) ||
( data > 0xff ) )
{
return ( false );
}
else
{
contents[ address ] = data;
return ( true );
}
}
public String[] readBinaryNybbleStringArray( int address )
{
return ( toBinaryNybbleStringArray( read( address ) ) );
}
public boolean writeBinaryNybbleStringArray( int address, String[]
dataStringArray )
{
short data = fromBinaryNybbleStringArray( dataStringArray );
return ( write( address, data ) );
}
public static short fromBinaryNybbleStringArray( String[] nybbleString )
{
if ( ( nybbleString != null ) && ( nybbleString.length == 2 ) )
{
try
{
int upperNybble = Integer.valueOf( nybbleString[ 0 ], 2 ).
intValue();
int lowerNybble = Integer.valueOf( nybbleString[ 1 ], 2 ).
intValue();
return ( ( short ) ( ( upperNybble * 0x10 ) + lowerNybble ) );
}
catch ( NumberFormatException e )
{
return ( -1 );
}
}
else
{
return ( -1 );
}
}
public static String[] toBinaryNybbleStringArray( short byteShort )
{
if ( ( byteShort >= 0 ) && ( byteShort <= 0xff ) )
{
String upperNybble = AssemblyInstruction.toNumberString( byteShort
/ 0x10, 2, 4 );
String lowerNybble = AssemblyInstruction.toNumberString( byteShort
% 0x10, 2, 4 );
String[] binaryNybble = { upperNybble, lowerNybble };
return ( binaryNybble );
}
else
{
return ( null );
}
}
public void disableComponents()
{
if ( editMemory != null )
{
editMemory.dispose();
}
if ( fillMemory != null )
{
fillMemory.dispose();
}
editMenu.setEnabled( false );
editMemoryMenuItem.setEnabled( false );
fillMemoryMenuItem.setEnabled( false );
clearMemoryMenuItem.setEnabled( false );
}
public void enableComponents()
{
editMenu.setEnabled( true );
editMemoryMenuItem.setEnabled( true );
fillMemoryMenuItem.setEnabled( true );
clearMemoryMenuItem.setEnabled( true );
}
private int scrollvalue = 0;
private int showType = 0;
private int top;
private int bottom;
private Scrollbar vert;
private Menu editMenu;
private MenuItem editMemoryMenuItem;
private MenuItem fillMemoryMenuItem;
private MenuItem clearMemoryMenuItem;
private CPU CPUBox;
private EditMemoryDialog editMemory;
private FillMemoryDialog fillMemory;
private short[] contents = new short[ MEMORY_SIZE ];
public static final int MEMORY_SIZE = 64;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -