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 /***
27 * This class represents instructions of type SHORT, 0OP.
28 *
29 * @author Wei-ju Wu
30 * @version 1.0
31 */
32 public class Short0Instruction extends AbstractInstruction {
33
34
35 public static final int OP_RTRUE = 0x00;
36 public static final int OP_RFALSE = 0x01;
37 public static final int OP_NOP = 0x04;
38 public static final int OP_SAVE = 0x05;
39 public static final int OP_RESTORE = 0x06;
40 public static final int OP_RESTART = 0x07;
41 public static final int OP_RET_POPPED = 0x08;
42 public static final int OP_POP = 0x09;
43 public static final int OP_QUIT = 0x0a;
44 public static final int OP_NEW_LINE = 0x0b;
45 public static final int OP_SHOW_STATUS = 0x0c;
46 public static final int OP_VERIFY = 0x0d;
47
48 /***
49 * Constructor.
50 *
51 * @param machineState a reference to the MachineState object
52 * @param opcode the instruction's opcode
53 */
54 public Short0Instruction(Machine machineState, int opcode) {
55
56 super(machineState, opcode);
57 }
58
59 /***
60 * {@inheritDoc}
61 */
62 public void execute() {
63
64 switch (getOpcode()) {
65
66 case OP_RTRUE:
67 returnFromRoutine(TRUE);
68 break;
69 case OP_RFALSE:
70 returnFromRoutine(FALSE);
71 break;
72 case OP_NOP:
73 nextInstruction();
74 break;
75 case OP_SAVE:
76 branchOnTest(getMachine().save());
77 break;
78 case OP_RESTORE:
79 getMachine().restore();
80 break;
81 case OP_RESTART:
82 getMachine().restart();
83 break;
84 case OP_QUIT:
85 getMachine().quit();
86 break;
87 case OP_RET_POPPED:
88 returnFromRoutine(getMachine().getVariable(0));
89 break;
90 case OP_POP:
91 getMachine().getVariable(0);
92 nextInstruction();
93 break;
94 case OP_NEW_LINE:
95 getMachine().newline();
96 nextInstruction();
97 break;
98 case OP_SHOW_STATUS:
99 getMachine().updateStatusLine();
100 nextInstruction();
101 break;
102 case OP_VERIFY:
103 branchOnTest(getMachine().hasValidChecksum());
104 break;
105 default:
106 throwInvalidOpcode();
107 }
108 }
109
110 /***
111 * {@inheritDoc}
112 */
113 public InstructionForm getInstructionForm() { return InstructionForm.SHORT; }
114
115 /***
116 * {@inheritDoc}
117 */
118 public OperandCount getOperandCount() { return OperandCount.C0OP; }
119
120 /***
121 * {@inheritDoc}
122 */
123 public boolean isBranch() {
124
125 switch (getOpcode()) {
126
127 case OP_SAVE:
128 case OP_RESTORE:
129 case OP_VERIFY:
130 return true;
131 default:
132 return false;
133 }
134 }
135 }