7ca3d38227f6c3406a857c8cdf7d9c934c9f85a1
[Mograsim.git] /
1 package net.mograsim.logic.model.am2900.machine.registers;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
6 import java.util.HashMap;
7 import java.util.HashSet;
8 import java.util.List;
9
10 import net.mograsim.machine.StandardRegister;
11
12 public class NumberedRegister extends StandardRegister
13 {
14         public static final List<NumberedRegister> instancesCorrectOrder;
15
16         static
17         {
18                 List<NumberedRegister> instancesCorrectOrderModifiable = new ArrayList<>();
19                 for (int i = 0; i < 16; i++)
20                         instancesCorrectOrderModifiable.add(new NumberedRegister(i));
21                 instancesCorrectOrder = Collections.unmodifiableList(instancesCorrectOrderModifiable);
22         }
23
24         private final int index;
25         private final String indexBitstring;
26
27         private NumberedRegister(int i)
28         {
29                 super("R" + i, new HashSet<>(Arrays.asList(new String[] { "R" + i, "Register #" + i, "Register " + i })), 16, new HashMap<>());
30                 this.index = i;
31
32                 StringBuilder sb = new StringBuilder();
33                 sb.append((index & 0b1000) != 0 ? '1' : '0');
34                 sb.append((index & 0b0100) != 0 ? '1' : '0');
35                 sb.append((index & 0b0010) != 0 ? '1' : '0');
36                 sb.append((index & 0b0001) != 0 ? '1' : '0');
37                 this.indexBitstring = sb.toString();
38         }
39
40         public int getIndex()
41         {
42                 return index;
43         }
44
45         public String getIndexAsBitstring()
46         {
47                 return indexBitstring;
48         }
49 }