Package mars.tools

Class KeyboardAndDisplaySimulator

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants, Memory.Listener, MarsTool

public class KeyboardAndDisplaySimulator extends AbstractMarsTool
Keyboard and Display Simulator. It can be run either as a stand-alone Java application having access to the mars package, or through MARS as an item in its Tools menu. It makes maximum use of methods inherited from its abstract superclass AbstractMarsToolAndApplication.

Version 1.0, 24 July 2008.

Version 1.1, 24 November 2008 corrects two omissions: (1) the tool failed to register as an observer of kernel text memory when counting instruction executions for transmitter ready bit reset delay, and (2) the tool failed to test the Status register's Exception Level bit before raising the exception that results in the interrupt (if the Exception Level bit is 1, that means an interrupt is being processed, so disable further interrupts).

Version 1.2, August 2009, soft-codes the MMIO register locations for new memory configuration feature of MARS 3.7. Previously memory segment addresses were fixed and final. Now they can be modified dynamically so the tool has to get its values dynamically as well.

Version 1.3, August 2011, corrects bug to enable Display window to scroll when needed.

Version 1.4, August 2014, adds two features: (1) ASCII control character 12 (form feed) when transmitted will clear the Display window. (2) ASCII control character 7 (bell) when transmitted with properly coded (X,Y) values will reposition the cursor to the specified position of a virtual text-based terminal. X represents column, Y represents row.

Author:
Pete Sanderson
See Also:
  • Field Details

    • PREFERRED_TEXT_AREA_DIMENSION

      public static final Dimension PREFERRED_TEXT_AREA_DIMENSION
    • receiverControl

      public static int receiverControl
    • receiverData

      public static int receiverData
    • transmitterControl

      public static int transmitterControl
    • transmitterData

      public static int transmitterData
  • Constructor Details

    • KeyboardAndDisplaySimulator

      public KeyboardAndDisplaySimulator()
      Construct an instance of this tool. This will be used by the ToolManager.
  • Method Details

    • getName

      public String getName()
      Required MarsTool method to return Tool name.
      Specified by:
      getName in interface MarsTool
      Specified by:
      getName in class AbstractMarsTool
      Returns:
      Tool name. MARS will display this in menu item.
    • initializePreGUI

      protected void initializePreGUI()
      Set the MMIO addresses. Prior to MARS 3.7 these were final because MIPS address space was final as well. Now we will get MMIO base address each time to reflect possible change in memory configuration. DPS 6-Aug-09
      Overrides:
      initializePreGUI in class AbstractMarsTool
    • startObserving

      protected void startObserving()
      Override the inherited method, which registers us as an Observer over the static data segment (starting address 0x10010000) only.

      When user enters keystroke, set RECEIVER_CONTROL and RECEIVER_DATA using the action listener. When user loads word (lw) from RECEIVER_DATA (we are notified of the read), then clear RECEIVER_CONTROL. When user stores word (sw) to TRANSMITTER_DATA (we are notified of the write), then clear TRANSMITTER_CONTROL, read TRANSMITTER_DATA, echo the character to display, wait for delay period, then set TRANSMITTER_CONTROL.

      If you use the inherited GUI buttons, this method is invoked when you click "Connect" button on MarsTool or the "Assemble and Run" button on a Mars-based app.

      Overrides:
      startObserving in class AbstractMarsTool
      See Also:
    • stopObserving

      protected void stopObserving()
      Description copied from class: AbstractMarsTool
      Unregister this tool as a listener of memory and/or registers, if applicable. This method is called when the tool is closed by the user. Does nothing by default.
      Overrides:
      stopObserving in class AbstractMarsTool
      See Also:
    • memoryRead

      public void memoryRead(int address, int length, int value, int wordAddress, int wordValue)
      Update display when connected MIPS program reads an instruction from the text or kernel text segments.
      Parameters:
      address - The address which was read from.
      length - The number of bytes read. Will always be 1 (single byte), Memory.BYTES_PER_HALFWORD, or Memory.BYTES_PER_WORD.
      value - The value which was read.
      wordAddress - The address of the word affected by the operation.
      wordValue - The full value of the word.
    • buildMainDisplayArea

      protected JComponent buildMainDisplayArea()
      Method that constructs the main display area. It is organized vertically into two major components: the display and the keyboard. The display itself is a JTextArea and it echoes characters placed into the low order byte of the Transmitter Data location, 0xffff000c. They keyboard is also a JTextArea places each typed character into the Receive Data location 0xffff0004.
      Specified by:
      buildMainDisplayArea in class AbstractMarsTool
      Returns:
      the GUI component containing these two areas
    • initializePostGUI

      protected void initializePostGUI()
      Initialization code to be executed after the GUI is configured. Overrides inherited default.
      Overrides:
      initializePostGUI in class AbstractMarsTool
    • reset

      protected void reset()
      Method to reset counters and display when the Reset button selected. Overrides inherited method that does nothing.
      Overrides:
      reset in class AbstractMarsTool
    • getHelpComponent

      protected JComponent getHelpComponent()
      Overrides default method, to provide a Help button for this tool/app.
      Overrides:
      getHelpComponent in class AbstractMarsTool