-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.java
More file actions
379 lines (322 loc) · 10.9 KB
/
Copy pathgui.java
File metadata and controls
379 lines (322 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
import javax.swing.*;
import java.awt.*;
class gui{
//Create textboxes
public static JTextField GPR0, GPR1, GPR2, GPR3, IXR1, IXR2, IXR3, PC, MAR, MBR, IR, MFR, PRIV, input, halt;
//Creates the gui, and starts the program
public static void start(){
//instantiate our variables
operational.PC = new boolean[12];
operational.MAR = new boolean[12];
operational.MBR = new word();
operational.IR = new word();
operational.MFR = new boolean[4];
operational.Priv = false;
operational.memory = new word[2048];
for(int i = 0; i<operational.memory.length; i++){
operational.memory[i] = new word();
}
gpr.R0 = new word();
gpr.R1 = new word();
gpr.R2 = new word();
gpr.R3 = new word();
index.X1 = new word();
index.X2 = new word();
index.X3 = new word();
//Create the JFrame window
JFrame frame = new JFrame("CISC");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200,700);
// Set JFrame layout manager
frame.setLayout(new GridLayout(8,3));
//4 GPRs (Labels, values, ld buttons)
JLabel GPR0L = new JLabel("GPR0");
frame.add(GPR0L);
GPR0 = new JTextField(gpr.R0.toString());
GPR0.setEditable(false);
frame.add(GPR0);
JButton GPR0B = new JButton("LD");
frame.add(GPR0B);
GPR0B.addActionListener(e -> GPR0BPressed());
JLabel GPR1L = new JLabel("GPR1");
frame.add(GPR1L);
GPR1 = new JTextField(gpr.R1.toString());
GPR1.setEditable(false);
frame.add(GPR1);
JButton GPR1B = new JButton("LD");
frame.add(GPR1B);
GPR1B.addActionListener(e -> GPR1BPressed());
JLabel GPR2L = new JLabel("GPR2");
frame.add(GPR2L);
GPR2 = new JTextField(gpr.R2.toString());
GPR2.setEditable(false);
frame.add(GPR2);
JButton GPR2B = new JButton("LD");
frame.add(GPR2B);
GPR2B.addActionListener(e -> GPR2BPressed());
JLabel GPR3L = new JLabel("GPR3");
frame.add(GPR3L);
GPR3 = new JTextField(gpr.R3.toString());
GPR3.setEditable(false);
frame.add(GPR3);
JButton GPR3B = new JButton("LD");
frame.add(GPR3B);
GPR3B.addActionListener(e -> GPR3BPressed());
//3 IXRs (Labels, values, ld buttons)
JLabel IXR1L = new JLabel("IXR1");
frame.add(IXR1L);
IXR1 = new JTextField(index.X1.toString());
IXR1.setEditable(false);
frame.add(IXR1);
JButton IXR1B = new JButton("LD");
frame.add(IXR1B);
IXR1B.addActionListener(e -> IXR1BPressed());
JLabel IXR2L = new JLabel("IXR2");
frame.add(IXR2L);
IXR2 = new JTextField(index.X2.toString());
IXR2.setEditable(false);
frame.add(IXR2);
JButton IXR2B = new JButton("LD");
frame.add(IXR2B);
IXR2B.addActionListener(e -> IXR2BPressed());
JLabel IXR3L = new JLabel("IXR3");
frame.add(IXR3L);
IXR3 = new JTextField(index.X3.toString());
IXR3.setEditable(false);
frame.add(IXR3);
JButton IXR3B = new JButton("LD");
frame.add(IXR3B);
IXR3B.addActionListener(e -> IXR3BPressed());
//PC (Label, value, ld button)
JLabel PCL = new JLabel("PC");
frame.add(PCL);
PC = new JTextField("000000000000");
PC.setEditable(false);
frame.add(PC);
JButton PCB = new JButton("LD");
frame.add(PCB);
PCB.addActionListener(e -> PCBPressed());
//MAR (Label, value, ld button)
JLabel MARL = new JLabel("MAR");
frame.add(MARL);
MAR = new JTextField("000000000000");
MAR.setEditable(false);
frame.add(MAR);
JButton MARB = new JButton("LD");
frame.add(MARB);
MARB.addActionListener(e -> MARBPressed());
//MBR (Label, value, ld button)
JLabel MBRL = new JLabel("MBR");
frame.add(MBRL);
MBR = new JTextField("0000000000000000");
MBR.setEditable(false);
frame.add(MBR);
JButton MBRB = new JButton("LD");
frame.add(MBRB);
MBRB.addActionListener(e -> MBRBPressed());
//IR (Label, value)
JLabel IRL = new JLabel("IR");
frame.add(IRL);
IR = new JTextField("0000000000000000");
IR.setEditable(false);
frame.add(IR);
//MFR (Label, value)
JLabel MFRL = new JLabel("MFR");
frame.add(MFRL);
MFR = new JTextField("0000");
MFR.setEditable(false);
frame.add(MFR);
//Privileged (Label, value)
JLabel PRIVL = new JLabel("Privileged");
frame.add(PRIVL);
PRIV = new JTextField("0");
PRIV.setEditable(false);
frame.add(PRIV);
//Input
JLabel inputL = new JLabel("Input");
frame.add(inputL);
input = new JTextField("0000000000000000", 16);
frame.add(input);
//Option Buttons
//Store
JButton StoreB = new JButton("Store");
frame.add(StoreB);
StoreB.addActionListener(e -> StoreBPressed());
//Store+
JButton StorePB = new JButton("St+");
frame.add(StorePB);
StorePB.addActionListener(e -> StorePBPressed());
//Load
JButton LoadB = new JButton("Load");
frame.add(LoadB);
LoadB.addActionListener(e -> LoadBPressed());
//Init
JButton InitB = new JButton("Init");
frame.add(InitB);
InitB.addActionListener(e -> InitBPressed());
//SS
JButton SSB = new JButton("SS");
frame.add(SSB);
SSB.addActionListener(e -> SSBPressed());
//Run
JButton RunB = new JButton("Run");
frame.add(RunB);
RunB.addActionListener(e -> RunBPressed());
JLabel haltL = new JLabel("Halt");
frame.add(haltL);
halt = new JTextField("0");
halt.setEditable(false);
frame.add(halt);
//Display Window
frame.setVisible(true);
}
//Validates that the string input is in the correct format
public static boolean validInputWord(String inText){
if(inText.length() != 16)
return false;
for(int x = 0; x<inText.length(); x++){
if(inText.charAt(x) != '0' && inText.charAt(x) != '1'){
System.out.println("Invalid input string");
return false;
}
}
return true;
}
/**
* NOW WE DEFINE METHODS FOR THE BUTTONS TO LOAD IN VALUES
*/
/**
* Until the next multi-line header, these methods define pressing 'LD' buttons next to the various registers
*/
public static void GPR0BPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
GPR0.setText(text);
gpr.R0 = new word(text);
}
public static void GPR1BPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
GPR1.setText(text);
gpr.R1 = new word(text);
}
public static void GPR2BPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
GPR2.setText(text);
gpr.R2 = new word(text);
}
public static void GPR3BPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
GPR3.setText(text);
gpr.R3 = new word(text);
}
public static void IXR1BPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
IXR1.setText(text);
index.X1 = new word(text);
}
public static void IXR2BPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
IXR2.setText(text);
index.X2 = new word(text);
}
public static void IXR3BPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
IXR3.setText(text);
index.X3 = new word(text);
}
public static void PCBPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
String b12 = text.substring(4);
PC.setText(b12);
operational.PC = operational.binaryStringToBinary(b12);
}
public static void MARBPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
String b12 = text.substring(4);
MAR.setText(b12);
operational.MAR = operational.binaryStringToBinary(b12);
}
public static void MBRBPressed(){
String text = input.getText();
if(!validInputWord(text)){
return;
}
MBR.setText(text);
operational.MBR = new word(text);
}
/*
* These operations define different operations the console can takes
*/
//Stores MBR into memory at MAR
public static void StoreBPressed(){
operational.Store();
update();
}
//Stores MBR into memory at MAR, and increments MAR
public static void StorePBPressed(){
operational.StorePlus();
update();
}
//Load in the MBR from memory
public static void LoadBPressed(){
operational.MBR = operational.memory[operational.binToDec(operational.MAR)];
gui.MBR.setText(operational.MBR.toString());
}
//Load program file
public static void InitBPressed(){
operational.Init();
update();
}
//Run a line of the program
public static void SSBPressed(){
operational.SS();
update();
}
//Runs entire program
public static void RunBPressed(){
operational.Run();
update();
}
//Updates the gui
public static void update(){
GPR0.setText(gpr.R0.toString());
GPR1.setText(gpr.R1.toString());
GPR2.setText(gpr.R2.toString());
GPR3.setText(gpr.R3.toString());
IXR1.setText(index.X1.toString());
IXR2.setText(index.X2.toString());
IXR3.setText(index.X3.toString());
PC.setText(operational.binaryToString(operational.PC));
MAR.setText(operational.binaryToString(operational.MAR));
MBR.setText(operational.MBR.toString());
IR.setText(operational.IR.toString());
MFR.setText(operational.binaryToString(operational.MFR));
PRIV.setText((operational.Priv ? "1" : "0"));
}
}