-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode.java
45 lines (38 loc) · 1007 Bytes
/
Code.java
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
package pippin;
public class Code {
public static final int CODE_MAX = 256;
private int nextCodeLocation;
private long[] code = new long[CODE_MAX];
public void setCode(int op, int arg){
long longOp = op;
long longArg = arg;
long longOpArg = longOp << 32;
longArg = longArg & 0x00000000FFFFFFFFL;
code[nextCodeLocation++] = longOpArg | longArg;
}
int getProgramSize(){
return nextCodeLocation;
}
public int getArg(int i){
return (int)code[i];
}
public int getOp(int i){
if(i < 0 || i >= nextCodeLocation) throw new CodeAccessException("Attempt to access code outside its bounds");
return (int)(code[i] >> 32);
}
public void clear(){
for(int i=0; i<code.length; i++){
code[i] =0;
}
nextCodeLocation = 0;
}
public String getText(int i){
StringBuilder builder = new StringBuilder();
if(i < nextCodeLocation){
builder.append(InstructionMap.mnemonics.get(getOp(i)));
builder.append(" ");
builder.append(getArg(i));
}
return builder.toString();
}
}