gruesome 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -2
- data/lib/gruesome/cli.rb +62 -62
- data/lib/gruesome/logo.rb +8 -8
- data/lib/gruesome/machine.rb +11 -11
- data/lib/gruesome/version.rb +1 -1
- data/lib/gruesome/z/abbreviation_table.rb +17 -17
- data/lib/gruesome/z/decoder.rb +273 -273
- data/lib/gruesome/z/dictionary.rb +144 -144
- data/lib/gruesome/z/header.rb +40 -40
- data/lib/gruesome/z/instruction.rb +42 -42
- data/lib/gruesome/z/machine.rb +51 -50
- data/lib/gruesome/z/memory.rb +301 -232
- data/lib/gruesome/z/object_table.rb +424 -424
- data/lib/gruesome/z/opcode.rb +489 -491
- data/lib/gruesome/z/opcode_class.rb +9 -9
- data/lib/gruesome/z/operand_type.rb +10 -10
- data/lib/gruesome/z/processor.rb +378 -361
- data/lib/gruesome/z/zscii.rb +307 -307
- data/lib/gruesome.rb +3 -3
- data/spec/z/memory_spec.rb +72 -72
- data/spec/z/processor_spec.rb +1883 -1883
- metadata +3 -3
data/lib/gruesome/z/opcode.rb
CHANGED
@@ -1,519 +1,517 @@
|
|
1
1
|
require_relative 'opcode_class'
|
2
2
|
|
3
3
|
module Gruesome
|
4
|
-
|
5
|
-
|
4
|
+
module Z
|
5
|
+
module Opcode
|
6
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
|
-
|
7
|
+
# 2OP
|
8
|
+
|
9
|
+
JE = (0x01 << 3) | OpcodeClass::OP2
|
10
|
+
JL = (0x02 << 3) | OpcodeClass::OP2
|
11
|
+
JG = (0x03 << 3) | OpcodeClass::OP2
|
12
|
+
DEC_CHK = (0x04 << 3) | OpcodeClass::OP2
|
13
|
+
INC_CHK = (0x05 << 3) | OpcodeClass::OP2
|
14
|
+
JIN = (0x06 << 3) | OpcodeClass::OP2
|
15
|
+
TEST = (0x07 << 3) | OpcodeClass::OP2
|
16
|
+
OR = (0x08 << 3) | OpcodeClass::OP2
|
17
|
+
AND = (0x09 << 3) | OpcodeClass::OP2
|
18
|
+
TEST_ATTR = (0x0a << 3) | OpcodeClass::OP2
|
19
|
+
SET_ATTR = (0x0b << 3) | OpcodeClass::OP2
|
20
|
+
CLEAR_ATTR = (0x0c << 3) | OpcodeClass::OP2
|
21
|
+
STORE = (0x0d << 3) | OpcodeClass::OP2
|
22
|
+
INSERT_OBJ = (0x0e << 3) | OpcodeClass::OP2
|
23
|
+
LOADW = (0x0f << 3) | OpcodeClass::OP2
|
24
|
+
LOADB = (0x10 << 3) | OpcodeClass::OP2
|
25
|
+
GET_PROP = (0x11 << 3) | OpcodeClass::OP2
|
26
|
+
GET_PROP_ADDR = (0x12 << 3) | OpcodeClass::OP2
|
27
|
+
GET_NPROP = (0x13 << 3) | OpcodeClass::OP2
|
28
|
+
ADD = (0x14 << 3) | OpcodeClass::OP2
|
29
|
+
SUB = (0x15 << 3) | OpcodeClass::OP2
|
30
|
+
MUL = (0x16 << 3) | OpcodeClass::OP2
|
31
|
+
DIV = (0x17 << 3) | OpcodeClass::OP2
|
32
|
+
MOD = (0x18 << 3) | OpcodeClass::OP2
|
33
|
+
CALL_2S = (0x19 << 3) | OpcodeClass::OP2
|
34
|
+
CALL_2N = (0x1a << 3) | OpcodeClass::OP2
|
35
|
+
SET_COLOUR = (0x1b << 3) | OpcodeClass::OP2
|
36
|
+
THROW = (0x1c << 3) | OpcodeClass::OP2
|
37
37
|
|
38
|
-
|
38
|
+
# 1OP
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
40
|
+
JZ = (0x00 << 3) | OpcodeClass::OP1
|
41
|
+
GET_SIBLING = (0x01 << 3) | OpcodeClass::OP1
|
42
|
+
GET_CHILD = (0x02 << 3) | OpcodeClass::OP1
|
43
|
+
GET_PARENT = (0x03 << 3) | OpcodeClass::OP1
|
44
|
+
GET_PROP_LEN = (0x04 << 3) | OpcodeClass::OP1
|
45
|
+
INC = (0x05 << 3) | OpcodeClass::OP1
|
46
|
+
DEC = (0x06 << 3) | OpcodeClass::OP1
|
47
|
+
PRINT_ADDR = (0x07 << 3) | OpcodeClass::OP1
|
48
|
+
CALL_1S = (0x08 << 3) | OpcodeClass::OP1
|
49
|
+
REMOVE_OBJ = (0x09 << 3) | OpcodeClass::OP1
|
50
|
+
PRINT_OBJ = (0x0a << 3) | OpcodeClass::OP1
|
51
|
+
RET = (0x0b << 3) | OpcodeClass::OP1
|
52
|
+
JUMP = (0x0c << 3) | OpcodeClass::OP1
|
53
|
+
PRINT_PADDR = (0x0d << 3) | OpcodeClass::OP1
|
54
|
+
LOAD = (0x0e << 3) | OpcodeClass::OP1
|
55
|
+
NOT_2 = (0x0f << 3) | OpcodeClass::OP1 # version 1-4
|
56
|
+
CALL_1N = (0x0f << 3) | OpcodeClass::OP1 # version 5
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
58
|
+
# 0OP
|
59
|
+
|
60
|
+
RTRUE = (0x00 << 3) | OpcodeClass::OP0
|
61
|
+
RFALSE = (0x01 << 3) | OpcodeClass::OP0
|
62
|
+
PRINT = (0x02 << 3) | OpcodeClass::OP0
|
63
|
+
PRINT_RET = (0x03 << 3) | OpcodeClass::OP0
|
64
|
+
NOP = (0x04 << 3) | OpcodeClass::OP0
|
65
|
+
SAVE = (0x05 << 3) | OpcodeClass::OP0
|
66
|
+
RESTORE = (0x06 << 3) | OpcodeClass::OP0
|
67
|
+
RESTART = (0x07 << 3) | OpcodeClass::OP0
|
68
|
+
RET_POPPED = (0x08 << 3) | OpcodeClass::OP0
|
69
|
+
POP = (0x09 << 3) | OpcodeClass::OP0 # version 1
|
70
|
+
CATCH = (0x09 << 3) | OpcodeClass::OP0 # version 5/6
|
71
|
+
QUIT = (0x0a << 3) | OpcodeClass::OP0
|
72
|
+
NEW_LINE = (0x0b << 3) | OpcodeClass::OP0
|
73
|
+
SHOW_STATUS = (0x0c << 3) | OpcodeClass::OP0 # version 3
|
74
|
+
VERIFY = (0x0d << 3) | OpcodeClass::OP0 # version 3
|
75
|
+
EXTENDED = (0x0e << 3) | OpcodeClass::OP0
|
76
|
+
PIRACY = (0x0f << 3) | OpcodeClass::OP0 # version 5/-
|
77
77
|
|
78
|
-
|
78
|
+
# VAR
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
80
|
+
CALL = (0x00 << 3) | OpcodeClass::VAR # version 1
|
81
|
+
CALL_VS = (0x00 << 3) | OpcodeClass::VAR # version 4
|
82
|
+
STOREW = (0x01 << 3) | OpcodeClass::VAR
|
83
|
+
STOREB = (0x02 << 3) | OpcodeClass::VAR
|
84
|
+
PUT_PROP = (0x03 << 3) | OpcodeClass::VAR
|
85
|
+
SREAD = (0x04 << 3) | OpcodeClass::VAR # version 1 (4 changes semantics)
|
86
|
+
AREAD = (0x04 << 3) | OpcodeClass::VAR # version 5
|
87
|
+
PRINT_CHAR = (0x05 << 3) | OpcodeClass::VAR
|
88
|
+
PRINT_NUM = (0x06 << 3) | OpcodeClass::VAR
|
89
|
+
RANDOM = (0x07 << 3) | OpcodeClass::VAR
|
90
|
+
PUSH = (0x08 << 3) | OpcodeClass::VAR
|
91
|
+
PULL = (0x09 << 3) | OpcodeClass::VAR
|
92
|
+
SPLIT_WINDOW = (0x0a << 3) | OpcodeClass::VAR
|
93
|
+
SET_WINDOW = (0x0b << 3) | OpcodeClass::VAR
|
94
|
+
CALL_VS2 = (0x0c << 3) | OpcodeClass::VAR
|
95
|
+
ERASE_WINDOW = (0x0d << 3) | OpcodeClass::VAR
|
96
|
+
ERASE_LINE = (0x0e << 3) | OpcodeClass::VAR
|
97
|
+
SET_CURSOR = (0x0f << 3) | OpcodeClass::VAR
|
98
|
+
GET_CURSOR = (0x10 << 3) | OpcodeClass::VAR
|
99
|
+
SET_TSTYLE = (0x11 << 3) | OpcodeClass::VAR
|
100
|
+
BUFFER_MODE = (0x12 << 3) | OpcodeClass::VAR
|
101
|
+
OUTPUT_STREAM = (0x13 << 3) | OpcodeClass::VAR
|
102
|
+
INPUT_STREAM = (0x14 << 3) | OpcodeClass::VAR
|
103
|
+
SOUND_EFFECT = (0x15 << 3) | OpcodeClass::VAR
|
104
|
+
READ_CHAR = (0x16 << 3) | OpcodeClass::VAR
|
105
|
+
SCAN_TABLE = (0x17 << 3) | OpcodeClass::VAR
|
106
|
+
NOT = (0x18 << 3) | OpcodeClass::VAR # version 5/6
|
107
|
+
CALL_VN = (0x19 << 3) | OpcodeClass::VAR
|
108
|
+
CALL_VN2 = (0x1a << 3) | OpcodeClass::VAR
|
109
|
+
TOKENIZE = (0x1b << 3) | OpcodeClass::VAR
|
110
|
+
ENCODE_TEXT = (0x1c << 3) | OpcodeClass::VAR
|
111
|
+
COPY_TABLE = (0x1d << 3) | OpcodeClass::VAR
|
112
|
+
PRINT_TABLE = (0x1e << 3) | OpcodeClass::VAR
|
113
|
+
CHECK_ARG_COUNT = (0x1f << 3) | OpcodeClass::VAR
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
115
|
+
SAVE_EXT = (0x00 << 3) | OpcodeClass::EXT
|
116
|
+
RESTORE_EXT = (0x01 << 3) | OpcodeClass::EXT
|
117
|
+
LOG_SHIFT = (0x02 << 3) | OpcodeClass::EXT
|
118
|
+
ART_SHIFT = (0x03 << 3) | OpcodeClass::EXT
|
119
|
+
SET_FONT = (0x04 << 3) | OpcodeClass::EXT
|
120
|
+
DRAW_PICTURE = (0x05 << 3) | OpcodeClass::EXT
|
121
|
+
PICTURE_DATA = (0x06 << 3) | OpcodeClass::EXT
|
122
|
+
ERASE_PICTURE = (0x07 << 3) | OpcodeClass::EXT
|
123
|
+
SET_MARGINS = (0x08 << 3) | OpcodeClass::EXT
|
124
|
+
SAVE_UNDO = (0x09 << 3) | OpcodeClass::EXT
|
125
|
+
RESTORE_UNDO = (0x0a << 3) | OpcodeClass::EXT
|
126
|
+
PRINT_UNICODE = (0x0b << 3) | OpcodeClass::EXT
|
127
|
+
CHECK_UNICODE = (0x0c << 3) | OpcodeClass::EXT
|
128
|
+
MOVE_WINDOW = (0x10 << 3) | OpcodeClass::EXT
|
129
|
+
WINDOW_SIZE = (0x11 << 3) | OpcodeClass::EXT
|
130
|
+
WINDOW_STYLE = (0x12 << 3) | OpcodeClass::EXT
|
131
|
+
GET_WIND_PROP = (0x13 << 3) | OpcodeClass::EXT
|
132
|
+
SCROLL_WINDOW = (0x14 << 3) | OpcodeClass::EXT
|
133
|
+
POP_STACK = (0x15 << 3) | OpcodeClass::EXT
|
134
|
+
READ_MOUSE = (0x16 << 3) | OpcodeClass::EXT
|
135
|
+
MOUSE_WINDOW = (0x17 << 3) | OpcodeClass::EXT
|
136
|
+
PUSH_STACK = (0x18 << 3) | OpcodeClass::EXT
|
137
|
+
PUT_WIND_PROP = (0x19 << 3) | OpcodeClass::EXT
|
138
|
+
PRINT_FORM = (0x1a << 3) | OpcodeClass::EXT
|
139
|
+
MAKE_MENU = (0x1b << 3) | OpcodeClass::EXT
|
140
|
+
PICTURE_TABLE = (0x1c << 3) | OpcodeClass::EXT
|
141
|
+
end
|
142
142
|
|
143
|
-
|
144
|
-
|
143
|
+
def Opcode.has_string?(opcode, version)
|
144
|
+
opcode_class = opcode & 7
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
146
|
+
result = false
|
147
|
+
if opcode_class == OpcodeClass::OP0
|
148
|
+
case opcode
|
149
|
+
when Opcode::PRINT, Opcode::PRINT_RET
|
150
|
+
result = true
|
151
|
+
end
|
152
|
+
end
|
153
153
|
|
154
|
-
|
155
|
-
|
154
|
+
result
|
155
|
+
end
|
156
156
|
|
157
|
-
|
158
|
-
|
157
|
+
def Opcode.is_store?(opcode, version)
|
158
|
+
opcode_class = opcode & 7
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
160
|
+
result = false
|
161
|
+
if opcode_class == OpcodeClass::OP2
|
162
|
+
case opcode
|
163
|
+
when Opcode::OR, Opcode::AND, Opcode::LOADB, Opcode::LOADW,
|
164
|
+
Opcode::GET_PROP, Opcode::GET_PROP_ADDR, Opcode::GET_NPROP,
|
165
|
+
Opcode::ADD, Opcode::SUB, Opcode::MUL, Opcode::DIV, Opcode::MOD,
|
166
|
+
Opcode::CALL_2S
|
167
|
+
result = true
|
168
|
+
end
|
169
|
+
elsif opcode_class == OpcodeClass::OP1
|
170
|
+
case opcode
|
171
|
+
when Opcode::GET_SIBLING, Opcode::GET_CHILD, Opcode::GET_PARENT,
|
172
|
+
Opcode::GET_PROP_LEN, Opcode::CALL_1S, Opcode::LOAD
|
173
|
+
result = true
|
174
|
+
end
|
175
175
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
176
|
+
if version < 5
|
177
|
+
case opcode
|
178
|
+
when Opcode::NOT
|
179
|
+
result = true
|
180
|
+
end
|
181
|
+
end
|
182
|
+
elsif opcode_class == OpcodeClass::OP0
|
183
|
+
case opcode
|
184
|
+
when Opcode::SAVE, Opcode::RESTORE
|
185
|
+
result = true if version >= 4
|
186
|
+
when Opcode::CATCH
|
187
|
+
result = true if version >= 5
|
188
|
+
end
|
189
|
+
elsif opcode_class == OpcodeClass::VAR
|
190
|
+
case opcode
|
191
|
+
when Opcode::CALL, Opcode::RANDOM, Opcode::CALL_VS2,
|
192
|
+
Opcode::READ_CHAR, Opcode::SCAN_TABLE, Opcode::NOT_2
|
193
|
+
result = true
|
194
|
+
end
|
193
195
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
196
|
+
if version >= 5
|
197
|
+
if opcode == Opcode::AREAD
|
198
|
+
result = true
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
200
202
|
|
201
|
-
|
202
|
-
|
203
|
+
result
|
204
|
+
end
|
203
205
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
206
|
+
def Opcode.is_variable_by_reference?(opcode, version)
|
207
|
+
case opcode
|
208
|
+
when Opcode::PULL, Opcode::STORE,
|
209
|
+
Opcode::INC, Opcode::DEC, Opcode::LOAD,
|
210
|
+
Opcode::DEC_CHK, Opcode::INC_CHK
|
211
|
+
return true
|
212
|
+
end
|
213
|
+
return false
|
214
|
+
end
|
213
215
|
|
214
|
-
|
215
|
-
|
216
|
+
def Opcode.is_valid?(opcode, version)
|
217
|
+
opcode_class = opcode & 7
|
216
218
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
result = false if version < 5
|
244
|
-
when Opcode::THROW
|
245
|
-
result = false if version < 5
|
246
|
-
end
|
219
|
+
result = true
|
220
|
+
if opcode_class == OpcodeClass::OP0
|
221
|
+
case opcode
|
222
|
+
when Opcode::SHOW_STATUS
|
223
|
+
result = false if version < 3
|
224
|
+
when Opcode::VERIFY
|
225
|
+
result = false if version < 3
|
226
|
+
when Opcode::PIRACY
|
227
|
+
result = false if version < 5
|
228
|
+
end
|
229
|
+
elsif opcode_class == OpcodeClass::OP1
|
230
|
+
case opcode
|
231
|
+
when Opcode::CALL_1S
|
232
|
+
result = false if version < 4
|
233
|
+
end
|
234
|
+
elsif opcode_class == OpcodeClass::OP2
|
235
|
+
case opcode
|
236
|
+
when Opcode::CALL_2S
|
237
|
+
result = false if version < 4
|
238
|
+
when Opcode::CALL_2N
|
239
|
+
result = false if version < 5
|
240
|
+
when Opcode::SET_COLOUR
|
241
|
+
result = false if version < 5
|
242
|
+
when Opcode::THROW
|
243
|
+
result = false if version < 5
|
244
|
+
end
|
247
245
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
246
|
+
if (opcode >> 3) > 0x1c or (opcode >> 3) == 0x00
|
247
|
+
result = false
|
248
|
+
end
|
249
|
+
elsif opcode_class == OpcodeClass::VAR
|
250
|
+
case opcode
|
251
|
+
when Opcode::SPLIT_WINDOW
|
252
|
+
result = false if version < 3
|
253
|
+
when Opcode::SET_WINDOW
|
254
|
+
result = false if version < 3
|
255
|
+
when Opcode::CALL_VS2
|
256
|
+
result = false if version < 4
|
257
|
+
when Opcode::ERASE_WINDOW
|
258
|
+
result = false if version < 4
|
259
|
+
when Opcode::ERASE_LINE
|
260
|
+
result = false if version < 4
|
261
|
+
when Opcode::SET_CURSOR
|
262
|
+
result = false if version < 4
|
263
|
+
when Opcode::GET_CURSOR
|
264
|
+
result = false if version < 4
|
265
|
+
when Opcode::SET_TSTYLE
|
266
|
+
result = false if version < 4
|
267
|
+
when Opcode::BUFFER_MODE
|
268
|
+
result = false if version < 4
|
269
|
+
when Opcode::OUTPUT_STREAM
|
270
|
+
result = false if version < 3
|
271
|
+
when Opcode::INPUT_STREAM
|
272
|
+
result = false if version < 3
|
273
|
+
when Opcode::SOUND_EFFECT
|
274
|
+
result = false if version < 5
|
275
|
+
when Opcode::READ_CHAR
|
276
|
+
result = false if version < 4
|
277
|
+
when Opcode::SCAN_TABLE
|
278
|
+
result = false if version < 4
|
279
|
+
when Opcode::NOT_2
|
280
|
+
result = false if version < 5
|
281
|
+
when Opcode::CALL_VN
|
282
|
+
result = false if version < 5
|
283
|
+
when Opcode::CALL_VN2
|
284
|
+
result = false if version < 5
|
285
|
+
when Opcode::TOKENIZE
|
286
|
+
result = false if version < 5
|
287
|
+
when Opcode::ENCODE_TEXT
|
288
|
+
result = false if version < 5
|
289
|
+
when Opcode::COPY_TABLE
|
290
|
+
result = false if version < 5
|
291
|
+
when Opcode::PRINT_TABLE
|
292
|
+
result = false if version < 5
|
293
|
+
when Opcode::CHECK_ARG_COUNT
|
294
|
+
result = false if version < 5
|
295
|
+
end
|
296
|
+
elsif opcode_class == OpcodeClass::EXT
|
297
|
+
result = false if version < 5
|
300
298
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
299
|
+
case opcode
|
300
|
+
when Opcode::SAVE_TABLE, EXT_RESTORE_TABLE, EXT_LOG_SHIFT,
|
301
|
+
ART_SHIFT, EXT_SET_FONT, EXT_SAVE_UNDO, EXT_RESTORE_UNDO,
|
302
|
+
PRINT_UNICODE, EXT_CHECK_UNICODE
|
303
|
+
else
|
304
|
+
result = false if version < 6
|
305
|
+
end
|
306
|
+
end
|
307
|
+
result
|
308
|
+
end
|
311
309
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
310
|
+
def Opcode.is_branch?(opcode, version)
|
311
|
+
opcode_class = opcode & 7
|
312
|
+
if not is_valid?(opcode, version)
|
313
|
+
return false
|
314
|
+
end
|
317
315
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
316
|
+
result = false
|
317
|
+
if opcode_class == OpcodeClass::OP0
|
318
|
+
case opcode
|
319
|
+
when Opcode::SAVE
|
320
|
+
if version < 4
|
321
|
+
result = true
|
322
|
+
end
|
323
|
+
when Opcode::RESTORE
|
324
|
+
if version < 4
|
325
|
+
result = true
|
326
|
+
end
|
327
|
+
when Opcode::VERIFY, Opcode::PIRACY
|
328
|
+
result = true
|
329
|
+
end
|
330
|
+
elsif opcode_class == OpcodeClass::OP1
|
331
|
+
case opcode
|
332
|
+
when Opcode::JZ, Opcode::GET_SIBLING, Opcode::GET_CHILD
|
333
|
+
result = true
|
334
|
+
end
|
335
|
+
elsif opcode_class == OpcodeClass::OP2
|
336
|
+
case opcode
|
337
|
+
when Opcode::JE, Opcode::JL, Opcode::JG,
|
338
|
+
Opcode::DEC_CHK, Opcode::INC_CHK, Opcode::JIN,
|
339
|
+
Opcode::TEST, Opcode::TEST_ATTR
|
340
|
+
result = true
|
341
|
+
end
|
342
|
+
elsif opcode_class == OpcodeClass::VAR
|
343
|
+
case opcode
|
344
|
+
when Opcode::SCAN_TABLE, Opcode::CHECK_ARG_COUNT
|
345
|
+
result = true
|
346
|
+
end
|
347
|
+
elsif opcode_class == OpcodeClass::EXT
|
348
|
+
case opcode
|
349
|
+
when Opcode::PICTURE_DATA,
|
350
|
+
Opcode::PUSH_STACK, Opcode::MAKE_MENU
|
351
|
+
result = true
|
352
|
+
end
|
353
|
+
end
|
356
354
|
|
357
|
-
|
358
|
-
|
355
|
+
result
|
356
|
+
end
|
359
357
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
358
|
+
def Opcode.name(opcode, version)
|
359
|
+
opcode_class = opcode & 7
|
360
|
+
if not is_valid?(opcode, version)
|
361
|
+
"invalid"
|
362
|
+
elsif opcode_class == OpcodeClass::OP0
|
363
|
+
case opcode
|
364
|
+
when Opcode::RTRUE then "rtrue"
|
365
|
+
when Opcode::RFALSE then "rfalse"
|
366
|
+
when Opcode::PRINT then "print"
|
367
|
+
when Opcode::PRINT_RET then "print_ret"
|
368
|
+
when Opcode::NOP then "nop"
|
369
|
+
when Opcode::SAVE then "save"
|
370
|
+
when Opcode::RESTORE then "restore"
|
371
|
+
when Opcode::RESTART then "restart"
|
372
|
+
when Opcode::RET_POPPED then "ret_popped"
|
373
|
+
when Opcode::POP, Opcode::CATCH
|
374
|
+
if version <= 4
|
375
|
+
"pop"
|
376
|
+
else
|
377
|
+
"catch"
|
378
|
+
end
|
379
|
+
when Opcode::QUIT then "quit"
|
380
|
+
when Opcode::NEW_LINE then "new_line"
|
381
|
+
when Opcode::SHOW_STATUS then "show_status"
|
382
|
+
when Opcode::VERIFY then "verify"
|
383
|
+
when Opcode::PIRACY then "piracy"
|
384
|
+
end
|
385
|
+
elsif opcode_class == OpcodeClass::OP1
|
386
|
+
case opcode
|
387
|
+
when Opcode::JZ then "jz"
|
388
|
+
when Opcode::GET_SIBLING then "get_sibling"
|
389
|
+
when Opcode::GET_CHILD then "get_child"
|
390
|
+
when Opcode::GET_PARENT then "get_parent"
|
391
|
+
when Opcode::GET_PROP_LEN then "get_prop_len"
|
392
|
+
when Opcode::INC then "inc"
|
393
|
+
when Opcode::DEC then "dec"
|
394
|
+
when Opcode::PRINT_ADDR then "print_addr"
|
395
|
+
when Opcode::CALL_1S then "call_1s"
|
396
|
+
when Opcode::REMOVE_OBJ then "remove_obj"
|
397
|
+
when Opcode::PRINT_OBJ then "print_obj"
|
398
|
+
when Opcode::RET then "ret"
|
399
|
+
when Opcode::JUMP then "jump"
|
400
|
+
when Opcode::PRINT_PADDR then "print_paddr"
|
401
|
+
when Opcode::LOAD then "load"
|
402
|
+
when Opcode::NOT, CALL_1N
|
403
|
+
if version <= 4
|
404
|
+
"not"
|
405
|
+
else
|
406
|
+
"call_1n"
|
407
|
+
end
|
408
|
+
end
|
409
|
+
elsif opcode_class == OpcodeClass::OP2
|
410
|
+
case opcode
|
411
|
+
when Opcode::JE then "je"
|
412
|
+
when Opcode::JL then "jl"
|
413
|
+
when Opcode::JG then "jg"
|
414
|
+
when Opcode::DEC_CHK then "dec_chk"
|
415
|
+
when Opcode::INC_CHK then "inc_chk"
|
416
|
+
when Opcode::JIN then "jin"
|
417
|
+
when Opcode::TEST then "test"
|
418
|
+
when Opcode::OR then "or"
|
419
|
+
when Opcode::AND then "and"
|
420
|
+
when Opcode::TEST_ATTR then "test_attr"
|
421
|
+
when Opcode::SET_ATTR then "set_attr"
|
422
|
+
when Opcode::CLEAR_ATTR then "clear_attr"
|
423
|
+
when Opcode::STORE then "store"
|
424
|
+
when Opcode::INSERT_OBJ then "insert_obj"
|
425
|
+
when Opcode::LOADW then "loadw"
|
426
|
+
when Opcode::LOADB then "loadb"
|
427
|
+
when Opcode::GET_PROP then "get_prop"
|
428
|
+
when Opcode::GET_PROP_ADDR then "get_prop_addr"
|
429
|
+
when Opcode::GET_NPROP then "get_next_prop"
|
430
|
+
when Opcode::ADD then "add"
|
431
|
+
when Opcode::SUB then "sub"
|
432
|
+
when Opcode::MUL then "mul"
|
433
|
+
when Opcode::DIV then "div"
|
434
|
+
when Opcode::MOD then "mod"
|
435
|
+
when Opcode::CALL_2S then "call_2s"
|
436
|
+
when Opcode::CALL_2N then "call_2n"
|
437
|
+
when Opcode::SET_COLOUR then "set_colour"
|
438
|
+
when Opcode::THROW then "throw"
|
439
|
+
end
|
440
|
+
elsif opcode_class == OpcodeClass::VAR
|
441
|
+
case opcode
|
442
|
+
when Opcode::CALL, Opcode::CALL_VS
|
443
|
+
if version < 4
|
444
|
+
"call"
|
445
|
+
else
|
446
|
+
"call_vs"
|
447
|
+
end
|
448
|
+
when Opcode::STOREW then "storew"
|
449
|
+
when Opcode::STOREB then "storeb"
|
450
|
+
when Opcode::PUT_PROP then "put_prop"
|
451
|
+
when Opcode::SREAD, Opcode::AREAD
|
452
|
+
if version < 5
|
453
|
+
"sread"
|
454
|
+
else
|
455
|
+
"aread"
|
456
|
+
end
|
457
|
+
when Opcode::PRINT_CHAR then "print_char"
|
458
|
+
when Opcode::PRINT_NUM then "print_num"
|
459
|
+
when Opcode::RANDOM then "random"
|
460
|
+
when Opcode::PUSH then "push"
|
461
|
+
when Opcode::PULL then "pull"
|
462
|
+
when Opcode::SPLIT_WINDOW then "split_window"
|
463
|
+
when Opcode::SET_WINDOW then "set_window"
|
464
|
+
when Opcode::CALL_VS2 then "call_vs2"
|
465
|
+
when Opcode::ERASE_WINDOW then "erase_window"
|
466
|
+
when Opcode::ERASE_LINE then "erase_line"
|
467
|
+
when Opcode::SET_CURSOR then "set_cursor"
|
468
|
+
when Opcode::GET_CURSOR then "get_cursor"
|
469
|
+
when Opcode::SET_TSTYLE then "set_text_style"
|
470
|
+
when Opcode::BUFFER_MODE then "buffer_mode"
|
471
|
+
when Opcode::OUTPUT_STREAM then "output_stream"
|
472
|
+
when Opcode::INPUT_STREAM then "input_stream"
|
473
|
+
when Opcode::SOUND_EFFECT then "sound_effect"
|
474
|
+
when Opcode::READ_CHAR then "read_char"
|
475
|
+
when Opcode::SCAN_TABLE then "scan_table"
|
476
|
+
when Opcode::NOT_2 then "not"
|
477
|
+
when Opcode::CALL_VN then "call_vn"
|
478
|
+
when Opcode::CALL_VN2 then "call_vn2"
|
479
|
+
when Opcode::TOKENIZE then "tokenize"
|
480
|
+
when Opcode::ENCODE_TEXT then "encode_text"
|
481
|
+
when Opcode::COPY_TABLE then "copy_table"
|
482
|
+
when Opcode::PRINT_TABLE then "print_table"
|
483
|
+
when Opcode::CHECK_ARG_COUNT then "check_arg_count"
|
484
|
+
end
|
485
|
+
elsif opcode_class == OpcodeClass::EXT
|
486
|
+
case opcode
|
487
|
+
when Opcode::SAVE_TABLE then "save_table"
|
488
|
+
when Opcode::RESTORE_TABLE then "restore_table"
|
489
|
+
when Opcode::LOG_SHIFT then "log_shift"
|
490
|
+
when Opcode::ART_SHIFT then "art_shift"
|
491
|
+
when Opcode::SET_FONT then "set_font"
|
492
|
+
when Opcode::DRAW_PICTURE then "draw_picture"
|
493
|
+
when Opcode::PICTURE_DATA then "picture_data"
|
494
|
+
when Opcode::ERASE_PICTURE then "erase_picture"
|
495
|
+
when Opcode::SET_MARGINS then "set_margins"
|
496
|
+
when Opcode::SAVE_UNDO then "save_undo"
|
497
|
+
when Opcode::RESTORE_UNDO then "restore_undo"
|
498
|
+
when Opcode::PRINT_UNICODE then "print_unicode"
|
499
|
+
when Opcode::CHECK_UNICODE then "check_unicode"
|
500
|
+
when Opcode::MOVE_WINDOW then "move_window"
|
501
|
+
when Opcode::WINDOW_SIZE then "window_size"
|
502
|
+
when Opcode::WINDOW_STYLE then "window_style"
|
503
|
+
when Opcode::GET_WIND_PROP then "get_wind_prop"
|
504
|
+
when Opcode::SCROLL_WINDOW then "scroll_window"
|
505
|
+
when Opcode::POP_STACK then "pop_stack"
|
506
|
+
when Opcode::READ_MOUSE then "read_mouse"
|
507
|
+
when Opcode::MOUSE_WINDOW then "mouse_window"
|
508
|
+
when Opcode::PUSH_STACK then "push_stack"
|
509
|
+
when Opcode::PUT_WIND_PROP then "put_wind_prop"
|
510
|
+
when Opcode::PRINT_FORM then "print_form"
|
511
|
+
when Opcode::MAKE_MENU then "make_menu"
|
512
|
+
when Opcode::PICTURE_TABLE then "picture_table"
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
516
|
+
end
|
519
517
|
end
|