Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## mars.util
Class SystemIO

    java.lang.Object
      mars.util.SystemIO

    public class SystemIO

extends Object

Provides standard i/o services needed to simulate the MIPS syscall routines. These methods will detect whether the simulator is being run from the command line or through the GUI, then do I/O to System.in and System.out in the former situation, and interact with the GUI in the latter.

Author:
  Pete Sanderson and Ken Vollmar

Field Summary
`static String` | `fileErrorString` String used for description of file error
`static int` | `SYSCALL_BUFSIZE` Buffer size for syscalls for file I/O
`static int` | `SYSCALL_MAXFILES` Maximum number of files that can be open

Constructor Summary
`SystemIO()`

Method Summary
`static void` | `closeFile(int fd)` Close the file with specified file descriptor
`static String` | `getFileErrorMessage()` Retrieve file operation or error message
`static int` | `openFile(String filename, int flags)` Open a file for either reading or writing.
`static void` | `printString(String string)` Implements syscall having 4 in $v0, to print a string.
`static int` | `readChar(int serviceNumber)` Implements syscall having 12 in $v0, to read a char value.
`static double` | `readDouble(int serviceNumber)` Implements syscall to read a double value.
`static float` | `readFloat(int serviceNumber)` Implements syscall to read a float value.
`static int` | `readFromFile(int fd, byte[] myBuffer, int lengthRequested)` Read bytes from file.
`static int` | `readInteger(int serviceNumber)` Implements syscall to read an integer value.
`static String` | `readString(int serviceNumber, int maxLength)` Implements syscall to read a string.
`static void` | `resetFiles()` Reset all files -- clears out the file descriptor table.
`static int` | `writeToFile(int fd, byte[] myBuffer, int lengthRequested)` Write bytes to file.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### SYSCALL_BUFSIZE

    public static final int SYSCALL_BUFSIZE

  Buffer size for syscalls for file I/O

  See Also:
    Constant Field Values

### SYSCALL_MAXFILES

    public static final int SYSCALL_MAXFILES

  Maximum number of files that can be open

  See Also:
    Constant Field Values

### fileErrorString

    public static String fileErrorString

  String used for description of file error

Constructor Detail

### SystemIO

    public SystemIO()

Method Detail

### readInteger

    public static int readInteger(int serviceNumber)

  Implements syscall to read an integer value. Client is responsible for catching NumberFormatException.

  Parameters:
    `serviceNumber` - the number assigned to Read Int syscall (default 5)
  Returns:
    int value corresponding to user input

### readFloat

    public static float readFloat(int serviceNumber)

  Implements syscall to read a float value. Client is responsible for catching NumberFormatException.

  Parameters:
    `serviceNumber` - the number assigned to Read Float syscall (default 6)
  Returns:
    float value corresponding to user input Feb 14 2005 Ken Vollmar

### readDouble

    public static double readDouble(int serviceNumber)

  Implements syscall to read a double value. Client is responsible for catching NumberFormatException.

  Parameters:
    `serviceNumber` - the number assigned to Read Double syscall (default 7)
  Returns:
    double value corresponding to user input 1 Aug 2005 DPS, based on Ken Vollmar's readFloat

### printString

    public static void printString(String string)

  Implements syscall having 4 in $v0, to print a string.

### readString

    public static String readString(int serviceNumber,
                                    int maxLength)

  Implements syscall to read a string.

  Parameters:
    `serviceNumber` - the number assigned to Read String syscall (default 8)
    `maxLength` - the maximum string length
  Returns:
    the entered string, truncated to maximum length if necessary

### readChar

    public static int readChar(int serviceNumber)

  Implements syscall having 12 in $v0, to read a char value.

  Parameters:
    `serviceNumber` - the number assigned to Read Char syscall (default 12)
  Returns:
    int value with lowest byte corresponding to user input

### writeToFile

    public static int writeToFile(int fd,
                                  byte[] myBuffer,
                                  int lengthRequested)

  Write bytes to file.

  Parameters:
    `fd` - file descriptor
    `myBuffer` - byte array containing characters to write
    `lengthRequested` - number of bytes to write
  Returns:
    number of bytes written, or -1 on error

### readFromFile

    public static int readFromFile(int fd,
                                   byte[] myBuffer,
                                   int lengthRequested)

  Read bytes from file.

  Parameters:
    `fd` - file descriptor
    `myBuffer` - byte array to contain bytes read
    `lengthRequested` - number of bytes to read
  Returns:
    number of bytes read, 0 on EOF, or -1 on error

### openFile

    public static int openFile(String filename,
                               int flags)

  Open a file for either reading or writing. Note that read/write flag is NOT IMPLEMENTED. Also note that file permission modes are also NOT IMPLEMENTED.

  Parameters:
    `filename` - string containing filename
    `flag` - 0 for read, 1 for write
  Returns:
    file descriptor in the range 0 to SYSCALL_MAXFILES-1, or -1 if error

### closeFile

    public static void closeFile(int fd)

  Close the file with specified file descriptor

  Parameters:
    `fd` - the file descriptor of an open file

### resetFiles

    public static void resetFiles()

  Reset all files -- clears out the file descriptor table.

### getFileErrorMessage

    public static String getFileErrorMessage()

  Retrieve file operation or error message

  Returns:
    string containing message

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD