1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.zmpp.vm;
24
25 /***
26 * This is the definition of an instruction's operand. Each operand has
27 * an operand type, and a value which is to be interpreted according to
28 * the type.
29 *
30 * @author Wei-ju Wu
31 * @version 1.0
32 */
33 public class Operand {
34
35 /***
36 * Type number for a large constant.
37 */
38 public static final byte TYPENUM_LARGE_CONSTANT = 0x00;
39
40 /***
41 * Type number for a small constant.
42 */
43 public static final byte TYPENUM_SMALL_CONSTANT = 0x01;
44
45 /***
46 * Type number for a variable.
47 */
48 public static final byte TYPENUM_VARIABLE = 0x02;
49
50 /***
51 * Type number for omitted.
52 */
53 public static final byte TYPENUM_OMITTED = 0x03;
54
55 /***
56 * The available operand types.
57 */
58 public enum OperandType { SMALL_CONSTANT, LARGE_CONSTANT, VARIABLE, OMITTED }
59
60 /***
61 * This operand's type.
62 */
63 private OperandType type;
64
65 /***
66 * This operand's value.
67 */
68 private short value;
69
70 /***
71 * Constructor.
72 *
73 * @param typenum the type number, must be < 4
74 * @param value the operand value
75 */
76 public Operand(int typenum, short value) {
77
78 type = getOperandType(typenum);
79 this.value = value;
80 }
81
82 /***
83 * Determines the operand type from a two-bit value.
84 *
85 * @param typenum the type number
86 * @return the operand type
87 */
88 private static OperandType getOperandType(int typenum) {
89
90 switch (typenum) {
91
92 case 0x00:
93 return OperandType.LARGE_CONSTANT;
94 case 0x01:
95 return OperandType.SMALL_CONSTANT;
96 case 0x02:
97 return OperandType.VARIABLE;
98 default:
99 return OperandType.OMITTED;
100 }
101 }
102
103 /***
104 * Returns this operand's type.
105 *
106 * @return the operand type
107 */
108 public OperandType getType() { return type; }
109
110 /***
111 * The operand value.
112 *
113 * @return the value
114 */
115 public short getValue() { return value; }
116 }