1
+ import java .util .Scanner ;
2
+
3
+ public class ACIA {
4
+ private byte dataRegister = 0 ;
5
+ private byte commandRegister = 0 ;
6
+ private byte statusRegister =0 ;
7
+ private byte controlRegister = 0 ;
8
+
9
+ private Scanner s ;
10
+
11
+ public ACIA () {
12
+ s = new Scanner (System .in );
13
+
14
+ }
15
+
16
+ /**
17
+ * @return theF dataRegister
18
+ */
19
+ public byte getDataRegister () {
20
+ return dataRegister ;
21
+ }
22
+
23
+ /**
24
+ * @return the commandRegister
25
+ */
26
+ public byte getCommandRegister () {
27
+ return commandRegister ;
28
+ }
29
+
30
+ /**
31
+ * @return the statusRegister
32
+ */
33
+ public byte getStatusRegister () {
34
+ return statusRegister ;
35
+ }
36
+
37
+ /**
38
+ * @return the controlRegister
39
+ */
40
+ public byte getControlRegister () {
41
+ return controlRegister ;
42
+ }
43
+
44
+ public byte read (short address ) {
45
+
46
+ switch (Short .toUnsignedInt (address ) - Bus .ACIA_ADDRESS ) {
47
+ case 0x00 :
48
+ try {
49
+ dataRegister = (byte ) System .in .read ();
50
+ if (dataRegister == 0xa ) dataRegister = 0xd ; //convert \n to \r
51
+
52
+ } catch (Exception e ) {
53
+ System .err .println ("Error reading from System.in" );
54
+ }
55
+ return dataRegister ; // Read Receiver Data Register
56
+ case 0x01 :
57
+ try {
58
+ if (System .in .available () >= 1 ) { // TODO: Remove this later when we go to a windowed interface
59
+ statusRegister = 1 << 3 ;
60
+ } else {
61
+ statusRegister = 0 << 3 ;
62
+ }
63
+ } catch (Exception e ) {
64
+ System .err .println ("Error reading from System.in" );
65
+ }
66
+ return statusRegister ; // Read Status Register
67
+ case 0x02 :
68
+ return commandRegister ; // Read Command Register
69
+
70
+ case 0x03 :
71
+ return controlRegister ; // Read Control Register
72
+ default :
73
+ System .err .printf ("Attempted to read from invalid ACIA register: %04x\n " , address );
74
+ return 0 ;
75
+
76
+ }
77
+ }
78
+
79
+ public void write (short address , byte data ) {
80
+ switch (Short .toUnsignedInt (address ) - Bus .ACIA_ADDRESS ) {
81
+ case 0x00 :
82
+ System .out .printf ("%c" , data ); // Write Transmitter Data Register
83
+ if (data == 0xd ) System .out .printf ("\n " ); // convert \r to \n
84
+
85
+ case 0x01 : // Programmed Reset
86
+ // Clear bits 4 through 0 in the Command Register and bit 2 in the Status
87
+ // Register
88
+ case 0x02 :
89
+ commandRegister = data ;
90
+ break ; // Write Command Register
91
+ case 0x03 :
92
+ controlRegister = data ;
93
+ break ; // Write Control Register
94
+ default :
95
+ System .err .printf ("Attempted to write to invalid ACIA register: %04x\n " , address );
96
+
97
+ }
98
+ }
99
+
100
+ }
0 commit comments