nachos.machine
Class Console

java.lang.Object
  extended by nachos.machine.Console

public abstract class Console
extends java.lang.Object

This class defines a hardware console device. There are two kinds of console that have been implemented: A stream console, which takes its input from an InputStream (such as System.in) and writes its output to a PrintStream (such as System.out), and a GUI console, which takes interactive input from the keyboard and outputs to a display window. The GUI console is more realistic, in that interrupts occur immediately when a key is pressed, rather than waiting for the end of the line. Since the device is asynchronous, the interrupt handler "readAvail" is called when a character has arrived, ready to be read in. The interrupt handler "writeDone" is called when an output character has been "put", so that the next character can be written.


Method Summary
 char getChar()
          Read a character from the input buffer, assuming there is one.
static Console guiConsole()
          Factory method for creating a GUIConsole operating in PIO mode.
static Console guiConsole(InterruptHandler readAvail, InterruptHandler writeDone)
          Factory method for creating a GUIConsole.
 boolean isInputAvail()
          Poll the console to see if there is an input character available.
 boolean isOutputBusy()
          Poll the console to see if it is busy outputting a character.
 void putChar(char ch)
          Write a character to the simulated display and return.
 void stop()
          Stop the console, disabling interrupt handlers.
static Console streamConsole(java.lang.String rdFile, java.lang.String wrFile)
          Factory method for creating a StreamConsole operating in PIO mode.
static Console streamConsole(java.lang.String rdFile, java.lang.String wrFile, InterruptHandler readAvail, InterruptHandler writeDone)
          Factory method for creating a StreamConsole.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

streamConsole

public static Console streamConsole(java.lang.String rdFile,
                                    java.lang.String wrFile,
                                    InterruptHandler readAvail,
                                    InterruptHandler writeDone)
Factory method for creating a StreamConsole.

Parameters:
rdFile - Java stream simulating the keyboard (null -> use stdin)
wrFile - Java stream simulating the display (null -> use stdout)
readAvail - is the interrupt handler called when a character arrives from the keyboard (null -> PIO mode)
writeDone - is the interrupt handler called when a character has been output, so that it is ok to request the next char be output (null -> PIO mode)

streamConsole

public static Console streamConsole(java.lang.String rdFile,
                                    java.lang.String wrFile)
Factory method for creating a StreamConsole operating in PIO mode.

Parameters:
rdFile - Java stream simulating the keyboard (null -> use stdin)
wrFile - Java stream simulating the display (null -> use stdout)
Returns:
the newly created console.

guiConsole

public static Console guiConsole(InterruptHandler readAvail,
                                 InterruptHandler writeDone)
Factory method for creating a GUIConsole.

Parameters:
readAvail - is the interrupt handler called when a character arrives from the keyboard (null -> PIO mode)
writeDone - is the interrupt handler called when a character has been output, so that it is ok to request the next char be output (null -> PIO mode)
Returns:
the newly created console.

guiConsole

public static Console guiConsole()
Factory method for creating a GUIConsole operating in PIO mode.

Returns:
the newly created console.

stop

public void stop()
Stop the console, disabling interrupt handlers. This enables Nachos to shut down.


isInputAvail

public boolean isInputAvail()
Poll the console to see if there is an input character available.

Returns:
true if there is an input character available, otherwise false.

getChar

public char getChar()
Read a character from the input buffer, assuming there is one. This method should not be called unless it is known (by getting a read interrupt or getting a true return from isInputAvail()) that there is a character available.

Returns:
the character from the input buffer, if one exists.

isOutputBusy

public boolean isOutputBusy()
Poll the console to see if it is busy outputting a character.

Returns:
true if the console is busy outputting a character, otherwise false.

putChar

public void putChar(char ch)
Write a character to the simulated display and return. An interrupt will occur in the future when the writing is "finished". This method must not be called unless it is known (e.g. by getting an interrupt) that the console is finished with any previous printing operation.

Parameters:
ch - The character to be written.