Commit 160cde41 authored by thomas@cs.ru.nl's avatar thomas@cs.ru.nl
Browse files

Used static access for static constants

parent 4ab24bdb
This diff is collapsed.
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.Enumeration; public class MachineState extends Model{ protected int stackBottom ; protected int stackGrowthDir ; protected int code ; protected int instrPC ; protected Instruction instr ; protected int nInlineOpnds ; protected int inlineOpnds[] ; protected Memory memory ; protected Registers registers ; protected MemoryUser memoryUser ; public boolean isHalted ; public MachineState( int initMemCapacity, Messenger m ) { memory = new Memory( initMemCapacity, m ) ; registers = new Registers( memory, m ) ; stackGrowthDir = 1 ; reset() ; } protected void fireStateChange( MachineStateEvent ev ) { for( Enumeration e = getListeners() ; e.hasMoreElements() ; ) { MachineStateListener l = (MachineStateListener)e.nextElement() ; l.stateChanged( ev ) ; } } public void addMachineStateListener( MachineStateListener l ) { addListener( l ) ; } public void removeMachineStateListener( MachineStateListener l ) { removeListener( l ) ; } public void reset( ) { memory.reset() ; registers.reset() ; resetToInitialState() ; } public void resetToInitialState() { registers.setPC( 0 ) ; stackBottom = memory.getUsedForCode() + 16 ; registers.setSP( stackBottom - stackGrowthDir ) ; registers.setMP( registers.getSP() ) ; isHalted = false ; } public int dir( int v ) { return v * stackGrowthDir ; } public void setCurrentInstr( int pc, int code, Instruction instr ) { this.code = code ; instrPC = pc ; this.instr = instr ; nInlineOpnds = instr.getNrInlineOpnds() ; if ( nInlineOpnds > 0 ) inlineOpnds = new int[ nInlineOpnds ] ; } public Memory getMemory() { return memory ; } public int getStackBottom() { return stackBottom ; } public Registers getRegisters() { return registers ; } public boolean stackIsEmpty() { return stackBottom == registers.getSP() ; } public int stackTop() { return registers.getRegInd( registers.SP ) ; } public int getSR( ) { return stackIsEmpty() ? 0 : stackTop() ; } public String getSRAsString( ) { int sr = getSR() ; return "Z=" + ((sr & Instruction.ZZ) >> Instruction.SR_Z) + " C=" + ((sr & Instruction.CC) >> Instruction.SR_C) + " V=" + ((sr & Instruction.VV) >> Instruction.SR_V) + " N=" + ((sr & Instruction.NN) >> Instruction.SR_N) ; } class UndoStateModification implements Modification { private boolean wasHalted ; UndoStateModification( boolean h ) { wasHalted = h ; } public void modify() { isHalted = wasHalted ; } } public void setHalted() { isHalted = true ; fireStateChange( new MachineStateEvent( this, new UndoStateModification( false ) ) ) ; } public boolean isHalted() { return isHalted ; } public String toString() { return "state code=" + code + " instr-pc=" + instrPC + " n-inl=" + nInlineOpnds ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.Enumeration; public class MachineState extends Model{ protected int stackBottom ; protected int stackGrowthDir ; protected int code ; protected int instrPC ; protected Instruction instr ; protected int nInlineOpnds ; protected int inlineOpnds[] ; protected Memory memory ; protected Registers registers ; protected MemoryUser memoryUser ; public boolean isHalted ; public MachineState( int initMemCapacity, Messenger m ) { memory = new Memory( initMemCapacity, m ) ; registers = new Registers( memory, m ) ; stackGrowthDir = 1 ; reset() ; } protected void fireStateChange( MachineStateEvent ev ) { for( Enumeration e = getListeners() ; e.hasMoreElements() ; ) { MachineStateListener l = (MachineStateListener)e.nextElement() ; l.stateChanged( ev ) ; } } public void addMachineStateListener( MachineStateListener l ) { addListener( l ) ; } public void removeMachineStateListener( MachineStateListener l ) { removeListener( l ) ; } public void reset( ) { memory.reset() ; registers.reset() ; resetToInitialState() ; } public void resetToInitialState() { registers.setPC( 0 ) ; stackBottom = memory.getUsedForCode() + 16 ; registers.setSP( stackBottom - stackGrowthDir ) ; registers.setMP( registers.getSP() ) ; isHalted = false ; } public int dir( int v ) { return v * stackGrowthDir ; } public void setCurrentInstr( int pc, int code, Instruction instr ) { this.code = code ; instrPC = pc ; this.instr = instr ; nInlineOpnds = instr.getNrInlineOpnds() ; if ( nInlineOpnds > 0 ) inlineOpnds = new int[ nInlineOpnds ] ; } public Memory getMemory() { return memory ; } public int getStackBottom() { return stackBottom ; } public Registers getRegisters() { return registers ; } public boolean stackIsEmpty() { return stackBottom == registers.getSP() ; } public int stackTop() { return registers.getRegInd( Registers.SP ) ; } public int getSR( ) { return stackIsEmpty() ? 0 : stackTop() ; } public String getSRAsString( ) { int sr = getSR() ; return "Z=" + ((sr & Instruction.ZZ) >> Instruction.SR_Z) + " C=" + ((sr & Instruction.CC) >> Instruction.SR_C) + " V=" + ((sr & Instruction.VV) >> Instruction.SR_V) + " N=" + ((sr & Instruction.NN) >> Instruction.SR_N) ; } class UndoStateModification implements Modification { private boolean wasHalted ; UndoStateModification( boolean h ) { wasHalted = h ; } public void modify() { isHalted = wasHalted ; } } public void setHalted() { isHalted = true ; fireStateChange( new MachineStateEvent( this, new UndoStateModification( false ) ) ) ; } public boolean isHalted() { return isHalted ; } public String toString() { return "state code=" + code + " instr-pc=" + instrPC + " n-inl=" + nInlineOpnds ; } }
\ No newline at end of file
......
/* Runner.java Title: Simple Stack Machine Runner Author: atze Description: */ package nl.uu.cs.ssmui; import java.io.IOException;import java.io.Reader;import java.io.StreamTokenizer;import java.util.Vector; public class AssemblyParser { private StreamTokenizer tokens ; private int tok ; protected AssemblyParser( Reader input ) { tokens = new StreamTokenizer( input ) ; tokens.resetSyntax() ; tokens.wordChars( '0', '9' ) ; tokens.wordChars( 'a', 'z' ) ; tokens.wordChars( 'A', 'Z' ) ; tokens.wordChars( 0xA0, 0xF0 ) ; tokens.wordChars( '_', '_' ) ; tokens.wordChars( '-', '-' ) ; tokens.whitespaceChars( 0x00, 0x20 ) ; tokens.commentChar( ';' ) ; tokens.quoteChar( '"' ) ; tokens.eolIsSignificant( true ) ; tokens.slashSlashComments( true ) ; next() ; } private void next() { try { if ( ! isAtEOF() ) tok = tokens.nextToken() ; } catch ( IOException ex ) { tok = tokens.TT_EOF ; } } public boolean isAtEOF() { return tok == tokens.TT_EOF ; } private boolean isAtEOL() { return tok == tokens.TT_EOL || isAtEOF() ; } protected AssemblyParseResult parse1Line( AssemblyParseResult prevAPR ) { int lineNr = tokens.lineno() ; String label = null ; String msg = null ; Vector<String> instrNArgs = new Vector<String>() ; if ( ! isAtEOL() ) { if ( tok == tokens.TT_WORD ) { String s = tokens.sval ; next() ; if ( tok == ':' ) { label = s ; next() ; } else { instrNArgs.addElement( s ) ; } while( ! isAtEOL() ) { if ( tok == tokens.TT_WORD || tok == '"' ) { instrNArgs.addElement( tokens.sval ) ; } else if ( tok == tokens.TT_NUMBER ) { msg = "did not expect number " + tokens.nval ; } else { msg = "did not expect `" + (char)tok + "'" ; } next() ; } } else { msg = "expected label or instruction" ; } } next() ; if ( prevAPR == null ) return new AssemblyParseResult( lineNr, msg, label, instrNArgs ) ; else return prevAPR.addInfo( lineNr, msg, label, instrNArgs ) ; } }
\ No newline at end of file
/* Runner.java Title: Simple Stack Machine Runner Author: atze Description: */ package nl.uu.cs.ssmui; import java.io.IOException;import java.io.Reader;import java.io.StreamTokenizer;import java.util.Vector; public class AssemblyParser { private StreamTokenizer tokens ; private int tok ; protected AssemblyParser( Reader input ) { tokens = new StreamTokenizer( input ) ; tokens.resetSyntax() ; tokens.wordChars( '0', '9' ) ; tokens.wordChars( 'a', 'z' ) ; tokens.wordChars( 'A', 'Z' ) ; tokens.wordChars( 0xA0, 0xF0 ) ; tokens.wordChars( '_', '_' ) ; tokens.wordChars( '-', '-' ) ; tokens.whitespaceChars( 0x00, 0x20 ) ; tokens.commentChar( ';' ) ; tokens.quoteChar( '"' ) ; tokens.eolIsSignificant( true ) ; tokens.slashSlashComments( true ) ; next() ; } private void next() { try { if ( ! isAtEOF() ) tok = tokens.nextToken() ; } catch ( IOException ex ) { tok = StreamTokenizer.TT_EOF ; } } public boolean isAtEOF() { return tok == StreamTokenizer.TT_EOF ; } private boolean isAtEOL() { return tok == StreamTokenizer.TT_EOL || isAtEOF() ; } protected AssemblyParseResult parse1Line( AssemblyParseResult prevAPR ) { int lineNr = tokens.lineno() ; String label = null ; String msg = null ; Vector<String> instrNArgs = new Vector<String>() ; if ( ! isAtEOL() ) { if ( tok == StreamTokenizer.TT_WORD ) { String s = tokens.sval ; next() ; if ( tok == ':' ) { label = s ; next() ; } else { instrNArgs.addElement( s ) ; } while( ! isAtEOL() ) { if ( tok == StreamTokenizer.TT_WORD || tok == '"' ) { instrNArgs.addElement( tokens.sval ) ; } else if ( tok == StreamTokenizer.TT_NUMBER ) { msg = "did not expect number " + tokens.nval ; } else { msg = "did not expect `" + (char)tok + "'" ; } next() ; } } else { msg = "expected label or instruction" ; } } next() ; if ( prevAPR == null ) return new AssemblyParseResult( lineNr, msg, label, instrNArgs ) ; else return prevAPR.addInfo( lineNr, msg, label, instrNArgs ) ; } }
\ No newline at end of file
......
This diff is collapsed.
/* Runner.java Title: Simple Stack Machine Runner Author: atze Description: */ package nl.uu.cs.ssmui; import java.io.File; import javax.swing.UIManager; public class Runner extends Thread{ protected int delay = 50 ; SSMRunner ssmRunner ; public Runner( File initialFile ) { try { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } ssmRunner = new SSMRunner( this ); ssmRunner.initComponents(); ssmRunner.setVisible(true); //System.out.println( "Foc Trav=" + ssmRunner.isFocusTraversable() ) ; ssmRunner.requestFocus() ; if ( initialFile != null ) ssmRunner.loadFile( initialFile ) ; } catch (Exception e) { e.printStackTrace(); } } public void run() { while( true ) { int steppingState = ssmRunner.steppingState() ; if ( steppingState != ssmRunner.STEP_BY_STEP ) { if ( ssmRunner.hasBreakpointAtPC() ) ssmRunner.stopContinuouslyDoingSteps() ; else if ( steppingState == ssmRunner.STEP_CONT_FORWARD ) ssmRunner.doAStepForward() ; else if ( steppingState == ssmRunner.STEP_CONT_BACKWARD ) ssmRunner.doAStepBack() ; } try { sleep( delay ) ; } catch ( InterruptedException e ) {} } } // Main entry point static public void main(String[] args) { File initialFile = null ; if ( args.length > 0 ) { File f = new File( args[0] ) ; if ( f.exists() ) initialFile = f ; } new Runner( initialFile ) ; } }
\ No newline at end of file
/* Runner.java Title: Simple Stack Machine Runner Author: atze Description: */ package nl.uu.cs.ssmui; import java.io.File; import javax.swing.UIManager; public class Runner extends Thread{ protected int delay = 50 ; SSMRunner ssmRunner ; public Runner( File initialFile ) { try { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } ssmRunner = new SSMRunner( this ); ssmRunner.initComponents(); ssmRunner.setVisible(true); //System.out.println( "Foc Trav=" + ssmRunner.isFocusTraversable() ) ; ssmRunner.requestFocus() ; if ( initialFile != null ) ssmRunner.loadFile( initialFile ) ; } catch (Exception e) { e.printStackTrace(); } } public void run() { while( true ) { int steppingState = ssmRunner.steppingState() ; if ( steppingState != SSMRunner.STEP_BY_STEP ) { if ( ssmRunner.hasBreakpointAtPC() ) ssmRunner.stopContinuouslyDoingSteps() ; else if ( steppingState == SSMRunner.STEP_CONT_FORWARD ) ssmRunner.doAStepForward() ; else if ( steppingState == SSMRunner.STEP_CONT_BACKWARD ) ssmRunner.doAStepBack() ; } try { sleep( delay ) ; } catch ( InterruptedException e ) {} } } // Main entry point static public void main(String[] args) { File initialFile = null ; if ( args.length > 0 ) { File f = new File( args[0] ) ; if ( f.exists() ) initialFile = f ; } new Runner( initialFile ) ; } }
\ No newline at end of file
......
This diff is collapsed.
package nl.uu.cs.ssmui; import javax.swing.event.TableModelEvent;import javax.swing.table.AbstractTableModel; import nl.uu.cs.ssm.ColoredText;import nl.uu.cs.ssm.MachineState;import nl.uu.cs.ssm.Memory;import nl.uu.cs.ssm.MemoryAnnotation;import nl.uu.cs.ssm.MemoryCellEvent;import nl.uu.cs.ssm.MemoryCellListener;import nl.uu.cs.ssm.Registers;import nl.uu.cs.ssm.Utils; public class StackTableModel extends AbstractTableModel implements MemoryCellListener{ private static final long serialVersionUID = 1L ; private static final int C_ADDRESS = 0 ; private static final int C_VALUE = 1 ; protected static final int C_REGPTRS = 2 ; public static final int C_ANNOTE = 3 ; private static final String[] columnNames = { "Address", "Value", "RegPtrs", "Annote" } ; private MachineState machineState ; private Memory memory ; private Registers registers ; private int beforeMinAccessedSP ; private int maxAccessedSP ; private boolean isSPChanged = false ; public void beforeReset() { } public void reset() { if ( memory != null ) memory.removeMemoryCellListener( this ) ; if ( registers != null ) registers.removeMemoryCellListener( this ) ; memory = machineState.getMemory() ; registers = machineState.getRegisters() ; memory.addMemoryCellListener( this ) ; registers.addMemoryCellListener( this ) ; beforeMinAccessedSP = maxAccessedSP = registers.getReg( registers.SP ) ; fireTableChanged( new TableModelEvent( this ) ) ; //fireTableStructureChanged() ; } public StackTableModel( MachineState mst ) { machineState = mst ; reset() ; } protected boolean isSPChanged() { return isSPChanged ; } public int getColumnCount() { return columnNames.length ; } public int getRowCount() { return machineState.dir( maxAccessedSP - beforeMinAccessedSP ) ; //return memory.getCapacity() ; } private int rowToMemLoc( int row ) { return row + (beforeMinAccessedSP + 1) ; //return getRowCount() - row - 1 ; } protected int memLocToRow( int loc ) { return loc - (beforeMinAccessedSP + 1) ; //return rowToMemLoc( loc ) ; } public boolean isCellEditable( int row, int column ) { return column == C_VALUE ; } private boolean isMemLocWithinStackRange( int memLoc ) { return memLoc <= maxAccessedSP && memLoc > beforeMinAccessedSP ; } public Object getValueAt( int row, int column ) { Object res = "" ; int memLoc = rowToMemLoc( row ) ; switch( column ) { case C_ADDRESS : res = Utils.asHex( memLoc ) ; break ; case C_VALUE : res = Utils.asHex( memory.getAt( memLoc ) ) ; break ; case C_REGPTRS : { String pc, sp, mp ; pc = sp = mp = "" ; if ( memLoc == registers.getReg( registers.PC ) ) pc = " PC" ; if ( memLoc == registers.getReg( registers.SP ) ) sp = " SP" ; if ( memLoc == registers.getReg( registers.MP ) ) mp = " MP" ; res = pc + sp + mp ; } break ; case C_ANNOTE : MemoryAnnotation ann = memory.getAnnotationAt( memLoc ) ; //System.out.println( "annote stack at " + memLoc + "=" + ann ) ; res = ann == null ? ColoredText.blankDefault : ann ; break ; } return res ; } public void setValueAt( Object aValue, int row, int column ) { if ( column == C_VALUE ) { String strValue = null ; if ( aValue instanceof String ) strValue = (String)aValue ; else strValue = aValue.toString() ; memory.setAt( rowToMemLoc( row ), strValue ) ; } } public String getColumnName( int column ) { return columnNames[ column ] ; } public Class getColumnClass( int column ) { if ( column == C_ANNOTE ) return ColoredText.class ; else return SSMRunner.tableModelColumnClass ; } public void cellChanged( MemoryCellEvent e ) { Object src = e.getSource() ; int v ; if ( src == memory ) { int row = memLocToRow( e.cellIndex ) ; if ( isMemLocWithinStackRange( e.cellIndex ) ) fireTableRowsUpdated( row, row ) ; } else if ( src == registers && e.event == e.CELL ) { int loc = registers.getReg( e.cellIndex ) ; if ( e.cellIndex == registers.SP && maxAccessedSP < loc ) { int oldSPRow = rowToMemLoc( maxAccessedSP ) ; int newSPRow = rowToMemLoc( loc ) ; maxAccessedSP = loc ; isSPChanged = true ; fireTableRowsInserted( oldSPRow+1, newSPRow ) ; } else isSPChanged = false ; if ( isMemLocWithinStackRange( v = e.getOldCellValue() ) ) { int oldrow = memLocToRow( v ) ; fireTableCellUpdated( oldrow, C_REGPTRS ) ; } if ( isMemLocWithinStackRange( loc ) ) { int row = memLocToRow( loc ) ; fireTableCellUpdated( row, C_REGPTRS ) ; } } } }
\ No newline at end of file
package nl.uu.cs.ssmui; import javax.swing.event.TableModelEvent;import javax.swing.table.AbstractTableModel; import nl.uu.cs.ssm.ColoredText;import nl.uu.cs.ssm.MachineState;import nl.uu.cs.ssm.Memory;import nl.uu.cs.ssm.MemoryAnnotation;import nl.uu.cs.ssm.MemoryCellEvent;import nl.uu.cs.ssm.MemoryCellListener;import nl.uu.cs.ssm.Registers;import nl.uu.cs.ssm.Utils; public class StackTableModel extends AbstractTableModel implements MemoryCellListener{ private static final long serialVersionUID = 1L ; private static final int C_ADDRESS = 0 ; private static final int C_VALUE = 1 ; protected static final int C_REGPTRS = 2 ; public static final int C_ANNOTE = 3 ; private static final String[] columnNames = { "Address", "Value", "RegPtrs", "Annote" } ; private MachineState machineState ; private Memory memory ; private Registers registers ; private int beforeMinAccessedSP ; private int maxAccessedSP ; private boolean isSPChanged = false ; public void beforeReset() { } public void reset() { if ( memory != null ) memory.removeMemoryCellListener( this ) ; if ( registers != null ) registers.removeMemoryCellListener( this ) ; memory = machineState.getMemory() ; registers = machineState.getRegisters() ; memory.addMemoryCellListener( this ) ; registers.addMemoryCellListener( this ) ; beforeMinAccessedSP = maxAccessedSP = registers.getReg( Registers.SP ) ; fireTableChanged( new TableModelEvent( this ) ) ; //fireTableStructureChanged() ; } public StackTableModel( MachineState mst ) { machineState = mst ; reset() ; } protected boolean isSPChanged() { return isSPChanged ; } public int getColumnCount() { return columnNames.length ; } public int getRowCount() { return machineState.dir( maxAccessedSP - beforeMinAccessedSP ) ; //return memory.getCapacity() ; } private int rowToMemLoc( int row ) { return row + (beforeMinAccessedSP + 1) ; //return getRowCount() - row - 1 ; } protected int memLocToRow( int loc ) { return loc - (beforeMinAccessedSP + 1) ; //return rowToMemLoc( loc ) ; } public boolean isCellEditable( int row, int column ) { return column == C_VALUE ; } private boolean isMemLocWithinStackRange( int memLoc ) { return memLoc <= maxAccessedSP && memLoc > beforeMinAccessedSP ; } public Object getValueAt( int row, int column ) { Object res = "" ; int memLoc = rowToMemLoc( row ) ; switch( column ) { case C_ADDRESS : res = Utils.asHex( memLoc ) ; break ; case C_VALUE : res = Utils.asHex( memory.getAt( memLoc ) ) ; break ; case C_REGPTRS : { String pc, sp, mp ; pc = sp = mp = "" ; if ( memLoc == registers.getReg( Registers.PC ) ) pc = " PC" ; if ( memLoc == registers.getReg( Registers.SP ) ) sp = " SP" ; if ( memLoc == registers.getReg( Registers.MP ) ) mp = " MP" ; res = pc + sp + mp ; } break ; case C_ANNOTE : MemoryAnnotation ann = memory.getAnnotationAt( memLoc ) ; //System.out.println( "annote stack at " + memLoc + "=" + ann ) ; res = ann == null ? ColoredText.blankDefault : ann ; break ; } return res ; } public void setValueAt( Object aValue, int row, int column ) { if ( column == C_VALUE ) { String strValue = null ; if ( aValue instanceof String ) strValue = (String)aValue ; else strValue = aValue.toString() ; memory.setAt( rowToMemLoc( row ), strValue ) ; } } public String getColumnName( int column ) { return columnNames[ column ] ; } public Class getColumnClass( int column ) { if ( column == C_ANNOTE ) return ColoredText.class ; else return SSMRunner.tableModelColumnClass ; } public void cellChanged( MemoryCellEvent e ) { Object src = e.getSource() ; int v ; if ( src == memory ) { int row = memLocToRow( e.cellIndex ) ; if ( isMemLocWithinStackRange( e.cellIndex ) ) fireTableRowsUpdated( row, row ) ; } else if ( src == registers && e.event == MemoryCellEvent.CELL ) { int loc = registers.getReg( e.cellIndex ) ; if ( e.cellIndex == Registers.SP && maxAccessedSP < loc ) { int oldSPRow = rowToMemLoc( maxAccessedSP ) ; int newSPRow = rowToMemLoc( loc ) ; maxAccessedSP = loc ; isSPChanged = true ; fireTableRowsInserted( oldSPRow+1, newSPRow ) ; } else isSPChanged = false ; if ( isMemLocWithinStackRange( v = e.getOldCellValue() ) ) { int oldrow = memLocToRow( v ) ; fireTableCellUpdated( oldrow, C_REGPTRS ) ; } if ( isMemLocWithinStackRange( loc ) ) { int row = memLocToRow( loc ) ; fireTableCellUpdated( row, C_REGPTRS ) ; } } } }
\ No newline at end of file
......
package nl.uu.cs.ssmui; import javax.swing.event.TableModelEvent;import javax.swing.table.AbstractTableModel; import nl.uu.cs.ssm.MachineState;import nl.uu.cs.ssm.MemoryCellEvent;import nl.uu.cs.ssm.MemoryCellListener;import nl.uu.cs.ssm.Registers;import nl.uu.cs.ssm.Utils; public class StatusTableModel extends AbstractTableModel implements MemoryCellListener{ private static final long serialVersionUID = 1L ; private static final int C_PC = 0 ; private static final int C_SP = 1 ; private static final int C_MP = 2 ; private static final int C_R3 = 3 ; private static final int C_R4 = 4 ; private static final int C_R5 = 5 ; private static final int C_R6 = 6 ; private static final int C_R7 = 7 ; private static final int C_SR = 8 ; //private static final String[] columnNames = { "PC", "SP", "MP", "RR", "SR" } ; private MachineState machineState ; private Registers registers ; public void beforeReset() { } public void reset() { if ( registers != null ) registers.removeMemoryCellListener( this ) ; /* if ( memory != null ) memory.removeMemoryCellListener( this ) ; */ registers = machineState.getRegisters() ; registers.addMemoryCellListener( this ) ; /* memory = machineState.getMemory() ; memory.addMemoryCellListener( this ) ; */ fireTableChanged( new TableModelEvent( this ) ) ; //fireTableStructureChanged() ; } public StatusTableModel( MachineState mst ) { machineState = mst ; reset() ; } public int getColumnCount() { return registers.getNrRegs() + 1 ; } public int getRowCount() { return 1 ; } public boolean isCellEditable( int row, int column ) { return column != C_SR ; } public Object getValueAt( int row, int column ) { Object res ; if ( column == C_SR ) { res = machineState.getSRAsString() ; } else { int reg = column ; res = Utils.asHex( registers.getReg( reg ) ) ; } return res ; } public void setValueAt( Object aValue, int row, int column ) { String strValue ; if ( aValue instanceof String ) strValue = (String)aValue ; else strValue = aValue.toString() ; if ( column != C_SR ) { int reg = column ; registers.setReg( reg, Utils.fromHex( strValue ) ) ; } } public String getColumnName( int column ) { return column == C_SR ? "SR" : registers.getRegNAliasName( column ) ; } public Class getColumnClass( int column ) { return SSMRunner.tableModelColumnClass ; } public void cellChanged( MemoryCellEvent e ) { fireTableCellUpdated( 0, e.cellIndex ) ; } }
\ No newline at end of file
package nl.uu.cs.ssmui; import javax.swing.event.TableModelEvent;import javax.swing.table.AbstractTableModel; import nl.uu.cs.ssm.MachineState;import nl.uu.cs.ssm.MemoryCellEvent;import nl.uu.cs.ssm.MemoryCellListener;import nl.uu.cs.ssm.Registers;import nl.uu.cs.ssm.Utils; public class StatusTableModel extends AbstractTableModel implements MemoryCellListener{ private static final long serialVersionUID = 1L ; private static final int C_PC = 0 ; private static final int C_SP = 1 ; private static final int C_MP = 2 ; private static final int C_R3 = 3 ; private static final int C_R4 = 4 ; private static final int C_R5 = 5 ; private static final int C_R6 = 6 ; private static final int C_R7 = 7 ; private static final int C_SR = 8 ; //private static final String[] columnNames = { "PC", "SP", "MP", "RR", "SR" } ; private MachineState machineState ; private Registers registers ; public void beforeReset() { } public void reset() { if ( registers != null ) registers.removeMemoryCellListener( this ) ; /* if ( memory != null ) memory.removeMemoryCellListener( this ) ; */ registers = machineState.getRegisters() ; registers.addMemoryCellListener( this ) ; /* memory = machineState.getMemory() ; memory.addMemoryCellListener( this ) ; */ fireTableChanged( new TableModelEvent( this ) ) ; //fireTableStructureChanged() ; } public StatusTableModel( MachineState mst ) { machineState = mst ; reset() ; } public int getColumnCount() { return Registers.getNrRegs() + 1 ; } public int getRowCount() { return 1 ; } public boolean isCellEditable( int row, int column ) { return column != C_SR ; } public Object getValueAt( int row, int column ) { Object res ; if ( column == C_SR ) { res = machineState.getSRAsString() ; } else { int reg = column ; res = Utils.asHex( registers.getReg( reg ) ) ; } return res ; } public void setValueAt( Object aValue, int row, int column ) { String strValue ; if ( aValue instanceof String ) strValue = (String)aValue ; else strValue = aValue.toString() ; if ( column != C_SR ) { int reg = column ; registers.setReg( reg, Utils.fromHex( strValue ) ) ; } } public String getColumnName( int column ) { return column == C_SR ? "SR" : Registers.getRegNAliasName( column ) ; } public Class getColumnClass( int column ) { return SSMRunner.tableModelColumnClass ; } public void cellChanged( MemoryCellEvent e ) { fireTableCellUpdated( 0, e.cellIndex ) ; } }
\ No newline at end of file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment