Java Reference
In-Depth Information
[bus.command
#
ACK]
EXEC_FREAD
bus.command
#
HD_READ
EXEC_FREAD2
bus.command
#
RAM_WRITE
bus.address
#
arg( IR )
code (IR)
#
FREAD
[bus.command
#
ACK]
DECODE
FETCH
code (IR)
#
FOPEN
[bus.command
#
ACK]
EXEC_FOPEN
EXEC_FOPEN2
bus.command
#
HD_OPEN
bus.command
#
RAM_READ
bus.address
#
arg( IR )
EXEC_FCLOSE
bus.command
#
HD_CLOSE
code (IR)
#
FCLOSE
[bus.command
#
ACK]
Figure 5.11
FSA for file system instructions
Bus
, the constants must have package visibility and be accessible by all the
components.
class
Bus {
final static
String RAM_READ
#
"RAM_READ";
final static
String RAM_WRITE
#
"RAM_WRITE";
final static
String ACK
#
"ACK";
final static
String INPUT
#
"INPUT";
final static
String OUTPUT
#
"OUTPUT";
final static
String FOPEN
#
"FOPEN";
final static
String FREAD
#
"FREAD";
final static
String FCLOSE
#
"FCLOSE";
}
The new classes added in this prototype are the device classes
Keyboard
,
HardDisk
and
Display
. They are all components of the computer and interact
through the
Bus
, thus they have an attribute
bus
implementing this
association, which is initialized by the constructor.
The
Keyboard
class is based on a
BufferedReader
that is used to read line
by line from the default input. The
execute()
method checks whether the
command bus contains the
INPUT
command, then reads a line from the input
and puts the string on the data bus; finally it acknowledges the command.