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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
|
/* ScummVM - Kyrandia Interpreter
* Copyright (C) 2003-2004 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
#include "stdafx.h"
#include "kyra.h"
#include "script.h"
namespace Kyra {
// Command procs
void VMContext::c1_unknownCommand(void) {
debug("unknown command '0x%x'.", _currentCommand);
debug("\targument: '0x%x'", _argument);
_error = true;
}
void VMContext::c1_goToLine(void) {
_instructionPos = _argument << 1;
}
void VMContext::c1_setReturn(void) {
_returnValue = _argument;
}
void VMContext::c1_pushRetRec(void) {
if (!_argument) {
pushStack(_returnValue);
} else {
int32 rec = ((int16)_tempPos << 16) | ((_instructionPos >> 1) + 1);
pushStack(rec);
_tempPos = _instructionPos;
}
}
void VMContext::c1_push(void) {
pushStack(_argument);
}
void VMContext::c1_pushVar(void) {
pushStack(_registers[_argument]);
}
void VMContext::c1_pushFrameNeg(void) {
pushStack(_stack[_tempPos + _argument]);
}
void VMContext::c1_pushFramePos(void) {
pushStack(_stack[_tempPos - _argument]);
}
void VMContext::c1_popRetRec(void) {
if (!_argument) {
_returnValue = popStack();
} else {
if (_stackPos <= 0) {
_scriptState = kScriptStopped;
}
int32 rec = popStack();
_tempPos = (int16)((rec & 0xFFFF0000) >> 16);
_instructionPos = (rec & 0x0000FFFF) * 2;
}
}
void VMContext::c1_popVar(void) {
_registers[_argument] = popStack();
}
void VMContext::c1_popFrameNeg(void) {
_stack[_tempPos + _argument] = popStack();
}
void VMContext::c1_popFramePos(void) {
_stack[_tempPos - _argument] = popStack();
}
void VMContext::c1_addToSP(void) {
_stackPos -= _argument;
}
void VMContext::c1_subFromSP(void) {
_stackPos += _argument;
}
void VMContext::c1_execOpcode(void) {
if (_argument < _numOpcodes) {
OpcodeProc proc = _opcodes[_argument].proc;
(this->*proc)();
} else {
error("Invalid opcode 0x%X", _argument);
}
}
void VMContext::c1_ifNotGoTo(void) {
if (!popStack()) {
_instructionPos = _argument << 1;
}
}
void VMContext::c1_negate(void) {
switch(_argument) {
case 0:
topStack() = !topStack();
break;
case 1:
topStack() = -topStack();
break;
case 2:
topStack() = ~topStack();
break;
default:
debug("unkown negate instruction %d", _argument);
_error = true;
break;
};
}
void VMContext::c1_evaluate(void) {
int32 x, y;
int32 res = false;
x = popStack();
y = popStack();
switch(_argument) {
case 0:
res = x && y;
break;
case 1:
res = x || y;
break;
case 3:
res = x != y;
break;
case 4:
res = x < y;
break;
case 5:
res = x <= y;
break;
case 6:
res = x > y;
break;
case 7:
res = x >= y;
break;
case 8:
res = x + y;
break;
case 9:
res = x - y;
break;
case 10:
res = x * y;
break;
case 11:
res = x / y;
break;
case 12:
res = x >> y;
break;
case 13:
res = x << y;
break;
case 14:
res = x & y;
break;
case 15:
res = x | y;
break;
case 16:
res = x % y;
break;
case 17:
res = x ^ y;
break;
default:
debug("unknown evaluate command");
break;
};
pushStack(res);
}
// opcode procs
void VMContext::o1_unknownOpcode(void) {
_error = true;
debug("unknown opcode '0x%x'.", _argument);
debug("parameters:\n"
"Param0: %d\nParam1: %d\nParam2: %d\nParam3: %d\nParam4: %d\nParam5: %d\n"
"Param0 as a string: %s\nParam1 as a string: %s\nParam2 as a string: %s\n"
"Param3 as a string: %s\nParam4 as a string: %s\nParam5 as a string: %s\n",
param(0), param(1), param(2), param(3), param(5), param(5),
paramString(0), paramString(1), paramString(2), paramString(3),
paramString(4), paramString(5));
}
void VMContext::o1_0x68(void) {
debug("o1_0x68 was called with param0: '%d' and param1: '%d'", param(0), param(1));
}
} // end of namespace Kyra
|