48b85698315cfd63d1452f9e00976c0c78f09a9f
[Mograsim.git] /
1 package net.mograsim.logic.model.am2900.am2910;
2
3 import net.mograsim.logic.core.components.CoreBitDisplay;
4 import net.mograsim.logic.core.components.CoreManualSwitch;
5 import net.mograsim.logic.core.types.BitVector;
6 import net.mograsim.logic.model.am2900.util.TestEnvironmentHelper;
7 import net.mograsim.logic.model.am2900.util.TestEnvironmentHelper.DebugState;
8 import net.mograsim.logic.model.model.components.ModelComponent;
9
10 public class TestableAm2910Impl implements TestableAm2910
11 {
12
13         private ModelComponent am2901;
14         private CoreManualSwitch I;
15         private CoreManualSwitch C;
16         private CoreManualSwitch CI;
17         private CoreManualSwitch D;
18         private CoreManualSwitch _CC;
19         private CoreManualSwitch _CCEN;
20         private CoreManualSwitch _RLD;
21         private CoreManualSwitch _OE;
22         private CoreBitDisplay _FULL;
23         private CoreBitDisplay Y;
24         private CoreBitDisplay _PL, _MAP, _VECT;
25
26         private final TestEnvironmentHelper testHelper = new TestEnvironmentHelper(this, "Am2910");
27
28         @Override
29         public void setup()
30         {
31                 testHelper.setup(DebugState.NO_DEBUG);
32         }
33
34         @Override
35         public Result run()
36         {
37                 return testHelper.run();
38         }
39
40         @Override
41         public void clockOn(boolean isClockOn)
42         {
43                 if (isClockOn)
44                         C.switchFullOn();
45                 else
46                         C.switchFullOff();
47         }
48
49         @Override
50         public void setInstruction(Am2910_Inst inst)
51         {
52                 I.setState(BitVector.from(inst.ordinal(), 4));
53         }
54
55         @Override
56         public void set_CCEN(String val_1_bit)
57         {
58                 _CCEN.setState(BitVector.parse(val_1_bit));
59         }
60
61         @Override
62         public void setD(String val_12_bit)
63         {
64                 D.setState(BitVector.parse(val_12_bit));
65         }
66
67         @Override
68         public void set_CC(String val_1_bit)
69         {
70                 _CC.setState(BitVector.parse(val_1_bit));
71         }
72
73         @Override
74         public void setCI(String val_1_bit)
75         {
76                 CI.setState(BitVector.parse(val_1_bit));
77         }
78
79         @Override
80         public void set_RLD(String val_1_bit)
81         {
82                 _RLD.setState(BitVector.parse(val_1_bit));
83         }
84
85         @Override
86         public void set_OE(String val_1_bit)
87         {
88                 _OE.setState(BitVector.parse(val_1_bit));
89         }
90
91         @Override
92         public void setDirectly(Register r, String val_X_bit)
93         {
94                 am2901.setHighLevelState(regToStateID(r), BitVector.parse(val_X_bit));
95         }
96
97         @Override
98         public String getY()
99         {
100                 return Y.getDisplayedValue().toString();
101         }
102
103         @Override
104         public String get_FULL()
105         {
106                 return _FULL.getDisplayedValue().toString();
107         }
108
109         @Override
110         public String get_PL()
111         {
112                 return _PL.getDisplayedValue().toString();
113         }
114
115         @Override
116         public String get_MAP()
117         {
118                 return _MAP.getDisplayedValue().toString();
119         }
120
121         @Override
122         public String get_VECT()
123         {
124                 return _VECT.getDisplayedValue().toString();
125         }
126
127         @Override
128         public String getDirectly(Register r)
129         {
130                 return am2901.getHighLevelState(regToStateID(r)).toString();
131         }
132
133         private static String regToStateID(Register r)
134         {
135                 switch (r)
136                 {
137                 case S_0:
138                 case S_1:
139                 case S_2:
140                 case S_3:
141                 case S_4:
142                         return "stack.c" + BitVector.from(r.ordinal(), 3);
143                 case SP:
144                         return "sp.q";
145                 case PC:
146                         return "mupc.q";
147                 case REG_COUNT:
148                         return "r.q";
149                 default:
150                         throw new IllegalArgumentException("unknown: " + r);
151                 }
152         }
153
154         @Override
155         public TestEnvironmentHelper getTestEnvironmentHelper()
156         {
157                 return testHelper;
158         }
159 }