-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.cs
72 lines (66 loc) · 2.07 KB
/
controller.cs
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
namespace sap1{
class Controller : register {
ProgramCounter pc;
Ram ram;
register A;
register B;
Alu alu;
OutputRegister or;
public Controller(ProgramCounter pcin, Ram ramin, register ain, register bin, Alu aluin, OutputRegister orin){
pc = pcin;
ram = ramin;
A = ain;
B = bin;
alu = aluin;
or = orin;
}
public void start(){
while (true){
fetch();
if (!(flipflops[0] || flipflops[1] || flipflops[2] || flipflops[3])){
this.output();
ram.input();
ram.output();
A.input();
}
else if (!(flipflops[0] || flipflops[1] || flipflops[2]) && flipflops[3]){
this.output();
ram.input();
ram.output();
B.input();
alu.outputWithSub(false);
A.input();
}
else if (!(flipflops[0] || flipflops[1] || flipflops[3]) && flipflops[2]){
this.output();
ram.input();
ram.output();
B.input();
alu.outputWithSub(true);
A.input();
}
else if (flipflops[0] && flipflops[1] && flipflops[2] && !(flipflops[3])){
A.output();
or.input();
or.output();
}
else if (flipflops[0] && flipflops[1] && flipflops[2] && flipflops[3]){
break;
}
}
}
private void fetch(){
pc.output();
ram.input();
pc.input();
ram.output();
this.input();
}
public override void output(){
bool[] chang = funcs.msb(flipflops);
for (int n = 4; n < 8; n++){
Bus.bus[n] = chang[n-4];
}
}
}
}