aboutsummaryrefslogtreecommitdiff
path: root/engines/agi/op_cmd.cpp
blob: fed07ea986f64da9b39441c73d63cb2fa0b92246 (plain)
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
243
244
245
246
247
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
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
356
357
358
359
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "base/version.h"

#include "agi/agi.h"
#include "agi/inv.h"
#include "agi/sprite.h"
#include "agi/text.h"
#include "agi/graphics.h"
#include "agi/opcodes.h"
#include "agi/menu.h"
#include "agi/systemui.h"
#include "agi/words.h"

#include "common/random.h"
#include "common/textconsole.h"

namespace Agi {

#define getFeatures() state->_vm->getFeatures()
#define getVersion() state->_vm->getVersion()
#define getLanguage() state->_vm->getLanguage()

void cmdIncrement(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	byte   varVal = vm->getVar(varNr);

	if (getVersion() < 0x2000) {
		if (varVal < 0xf0) {
			varVal++;
			vm->setVar(varNr, varVal);
		}
	} else {
		if (varVal != 0xff) {
			varVal++;
			vm->setVar(varNr, varVal);
		}
	}
}

void cmdDecrement(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	byte   varVal = vm->getVar(varNr);

	if (varVal != 0) {
		varVal--;
		vm->setVar(varNr, varVal);
	}
}

void cmdAssignN(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	uint16 value = parameter[1];

	vm->setVar(varNr, value);

	// WORKAROUND for a bug in fan game "Get outta SQ"
	// Total number of points is stored in variable 7, which
	// is then incorrectly assigned to 0. Thus, when the game
	// is restarted, "Points 0 of 0" is shown. We set the
	// variable to the correct value here
	// Fixes bug #1942476 - "AGI: Fan(Get Outta SQ) - Score
	// is lost on restart"
	if (vm->getGameID() == GID_GETOUTTASQ && varNr == 7)
		vm->setVar(varNr, 8);
}

void cmdAddN(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	uint16 value = parameter[1];
	byte   varVal = vm->getVar(varNr);

	vm->setVar(varNr, varVal + value);
}

void cmdSubN(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	uint16 value = parameter[1];
	byte   varVal = vm->getVar(varNr);

	vm->setVar(varNr, varVal - value);
}

void cmdAssignV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1  = parameter[0];
	uint16 varNr2  = parameter[1];
	byte   varVal2 = vm->getVar(varNr2);

	vm->setVar(varNr1, varVal2);
}

void cmdAddV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1 = parameter[0];
	uint16 varNr2 = parameter[1];
	byte   varVal1 = vm->getVar(varNr1);
	byte   varVal2 = vm->getVar(varNr2);

	vm->setVar(varNr1, varVal1 + varVal2);
}

void cmdSubV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1 = parameter[0];
	uint16 varNr2 = parameter[1];
	byte   varVal1 = vm->getVar(varNr1);
	byte   varVal2 = vm->getVar(varNr2);

	vm->setVar(varNr1, varVal1 - varVal2);
}

void cmdMulN(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	uint16 value = parameter[1];
	byte   varVal = vm->getVar(varNr);

	vm->setVar(varNr, varVal * value);
}

void cmdMulV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1 = parameter[0];
	uint16 varNr2 = parameter[1];
	byte   varVal1 = vm->getVar(varNr1);
	byte   varVal2 = vm->getVar(varNr2);

	vm->setVar(varNr1, varVal1 * varVal2);
}

void cmdDivN(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	uint16 value = parameter[1];
	byte   varVal = vm->getVar(varNr);

	vm->setVar(varNr, varVal / value);
}

void cmdDivV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1 = parameter[0];
	uint16 varNr2 = parameter[1];
	byte   varVal1 = vm->getVar(varNr1);
	byte   varVal2 = vm->getVar(varNr2);

	vm->setVar(varNr1, varVal1 / varVal2);
}

void cmdRandomV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];

	vm->setVar(varNr, vm->_rnd->getRandomNumber(250));
}

void cmdRandom(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 valueMin = parameter[0];
	uint16 valueMax = parameter[1];
	uint16 varNr = parameter[2];

	vm->setVar(varNr, vm->_rnd->getRandomNumber(valueMax - valueMin) + valueMin);
}

void cmdLindirectN(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	uint16 value = parameter[1];
	byte   varVal = vm->getVar(varNr);

	vm->setVar(varVal, value);
}

void cmdLindirectV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1 = parameter[0];
	uint16 varNr2 = parameter[1];
	byte   varVal1 = vm->getVar(varNr1);
	byte   varVal2 = vm->getVar(varNr2);

	vm->setVar(varVal1, varVal2);
}

void cmdRindirect(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1 = parameter[0];
	uint16 varNr2 = parameter[1];
	byte   varVal2 = vm->getVar(varNr2);
	byte   value   = vm->getVar(varVal2);

	vm->setVar(varNr1, value);
}

void cmdSet(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 flagNr = parameter[0];

	vm->setFlag(flagNr, true);
}

void cmdReset(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 flagNr = parameter[0];

	vm->setFlag(flagNr, false);
}

void cmdToggle(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 flagNr = parameter[0];
	bool curFlagState = vm->getFlag(flagNr);

	vm->setFlag(flagNr, !curFlagState);
}

void cmdSetV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 flagNr = parameter[0];

	if (getVersion() < 0x2000) {
		vm->setVar(flagNr, 1);
	} else {
		flagNr = vm->getVar(flagNr);

		vm->setFlag(flagNr, true);
	}
}

void cmdResetV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 flagNr = parameter[0];

	if (getVersion() < 0x2000) {
		vm->setVar(flagNr, 0);
	} else {
		flagNr = vm->getVar(flagNr);

		vm->setFlag(flagNr, false);
	}
}

void cmdToggleV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 flagNr = parameter[0];

	if (getVersion() < 0x2000) {
		byte value = vm->getVar(flagNr);
		vm->setVar(flagNr, value ^ 1);
	} else {
		flagNr = vm->getVar(flagNr);
		bool curFlagState = vm->getFlag(flagNr);

		vm->setFlag(flagNr, !curFlagState);
	}
}

void cmdNewRoom(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 newRoomNr = parameter[0];

	state->_vm->newRoom(newRoomNr);
}

void cmdNewRoomF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	byte   value = vm->getVar(varNr);

	state->_vm->newRoom(value);
}

void cmdLoadView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 resourceNr = parameter[0];

	state->_vm->agiLoadResource(RESOURCETYPE_VIEW, resourceNr);
}

void cmdLoadLogic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 resourceNr = parameter[0];

	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
}

void cmdLoadSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 resourceNr = parameter[0];

	state->_vm->agiLoadResource(RESOURCETYPE_SOUND, resourceNr);
}

void cmdLoadViewF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	byte   value = vm->getVar(varNr);

	vm->agiLoadResource(RESOURCETYPE_VIEW, value);
}

void cmdLoadLogicF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	byte   value = vm->getVar(varNr);

	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, value);
}

void cmdDiscardView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 resourceNr = parameter[0];

	state->_vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
}

void cmdObjectOnAnything(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags &= ~(fOnWater | fOnLand);
}

void cmdObjectOnLand(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fOnLand;
}

void cmdObjectOnWater(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fOnWater;
}

void cmdObserveHorizon(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags &= ~fIgnoreHorizon;
}

void cmdIgnoreHorizon(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fIgnoreHorizon;
}

void cmdObserveObjs(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags &= ~fIgnoreObjects;
}

void cmdIgnoreObjs(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fIgnoreObjects;
}

void cmdObserveBlocks(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags &= ~fIgnoreBlocks;
}

void cmdIgnoreBlocks(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fIgnoreBlocks;
}

void cmdSetHorizon(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 horizonValue = parameter[0];

	state->horizon = horizonValue;
}

void cmdGetPriority(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	vm->setVar(varNr, screenObj->priority);
}

void cmdSetPriority(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 priority = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fFixedPriority;
	screenObj->priority = priority;
}

void cmdSetPriorityF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fFixedPriority;
	screenObj->priority = vm->getVar(varNr);
}

void cmdReleasePriority(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags &= ~fFixedPriority;
}

void cmdSetUpperLeft(AgiGame *state, AgiEngine *vm, uint8 *parameter) {             // do nothing (AGI 2.917)
}

void cmdStartUpdate(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	state->_vm->startUpdate(screenObj);
}

void cmdStopUpdate(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	state->_vm->stopUpdate(screenObj);
}

void cmdCurrentView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	vm->setVar(varNr, screenObj->currentViewNr);
}

void cmdCurrentCel(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	vm->setVar(varNr, screenObj->currentCelNr);
	debugC(4, kDebugLevelScripts, "v%d=%d", varNr, screenObj->currentCelNr);
}

void cmdCurrentLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	vm->setVar(varNr, screenObj->currentLoopNr);
}

void cmdLastCel(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	vm->setVar(varNr, screenObj->loopData->celCount - 1);
}

void cmdSetCel(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 celNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	vm->setCel(screenObj, celNr);
	if (getVersion() >= 0x2000) {
		screenObj->flags &= ~fDontupdate;
	}
}

void cmdSetCelF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
	byte   value = vm->getVar(varNr);

	vm->setCel(screenObj, value);
	screenObj->flags &= ~fDontupdate;
}

void cmdSetView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 viewNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	state->_vm->setView(screenObj, viewNr);
}

void cmdSetViewF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
	byte   value = vm->getVar(varNr);

	state->_vm->setView(screenObj, value);
}

void cmdSetLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 loopNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	state->_vm->setLoop(screenObj, loopNr);
}

void cmdSetLoopF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
	byte   value = vm->getVar(varNr);

	state->_vm->setLoop(screenObj, value);
}

void cmdNumberOfLoops(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	vm->setVar(varNr, screenObj->loopCount);
}

void cmdFixLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fFixLoop;
}

void cmdReleaseLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags &= ~fFixLoop;
}

void cmdStepSize(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->stepSize = vm->getVar(varNr);
}

void cmdStepTime(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->stepTime = screenObj->stepTimeCount = vm->getVar(varNr);
}

void cmdCycleTime(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->cycleTime = screenObj->cycleTimeCount = vm->getVar(varNr);
}

void cmdStopCycling(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags &= ~fCycling;
}

void cmdStartCycling(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fCycling;
}

void cmdNormalCycle(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->cycle = kCycleNormal;
	screenObj->flags |= fCycling;
}

void cmdReverseCycle(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->cycle = kCycleReverse;
	screenObj->flags |= fCycling;
}

void cmdSetDir(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->direction = vm->getVar(varNr);
}

void cmdGetDir(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	vm->setVar(varNr, screenObj->direction);
}

void cmdGetRoomF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1 = parameter[0];
	uint16 varNr2 = parameter[1];
	byte   varVal1 = vm->getVar(varNr1);

	vm->setVar(varNr2, state->_vm->objectGetLocation(varVal1));
}

void cmdPut(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr = parameter[1];
	byte   varVal = vm->getVar(varNr);

	vm->objectSetLocation(objectNr, varVal);
}

void cmdPutF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1 = parameter[0];
	uint16 varNr2 = parameter[1];
	byte   varVal1 = vm->getVar(varNr1);
	byte   varVal2 = vm->getVar(varNr2);

	state->_vm->objectSetLocation(varVal1, varVal2);
}

void cmdDrop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];

	state->_vm->objectSetLocation(objectNr, 0);
}

void cmdGet(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];

	state->_vm->objectSetLocation(objectNr, EGO_OWNED);
}

void cmdGetV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];

	state->_vm->objectSetLocation(objectNr, EGO_OWNED_V1);
}

void cmdGetF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	byte   varVal = vm->getVar(varNr);

	state->_vm->objectSetLocation(varVal, EGO_OWNED);
}

void cmdWordToString(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 stringNr = parameter[0];
	uint16 wordNr = parameter[1];

	strcpy(state->strings[stringNr], state->_vm->_words->getEgoWord(wordNr));
}

void cmdOpenDialogue(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	vm->_text->dialogueOpen();
}

void cmdCloseDialogue(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	vm->_text->dialogueClose();
}

void cmdCloseWindow(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	vm->_text->closeWindow();
}

void cmdStatusLineOn(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *text = state->_vm->_text;

	text->statusEnable();
	text->statusDraw();
}

void cmdStatusLineOff(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *text = state->_vm->_text;

	text->statusDisable();
	state->_vm->_text->statusClear();
}

void cmdShowObj(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];

	state->_vm->_sprites->showObject(objectNr);
}

void cmdShowObjV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	byte   varVal = vm->getVar(varNr);

	state->_vm->_sprites->showObject(varVal);
}

void cmdSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 resourceNr = parameter[0];
	uint16 flagNr = parameter[1];

	state->_vm->_sound->startSound(resourceNr, flagNr);
}

void cmdStopSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	state->_vm->_sound->stopSound();
}

void cmdMenuInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if (vm->getFlag(VM_FLAG_MENUS_ACCESSIBLE)) {
		vm->_menu->delayedExecuteViaKeyboard();
	}
}

void cmdEnableItem(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 controlCode = parameter[0];

	state->_vm->_menu->itemEnable(controlCode);
}

void cmdDisableItem(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 controlCode = parameter[0];

	state->_vm->_menu->itemDisable(controlCode);
}

void cmdSubmitMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	state->_vm->_menu->submit();
}

void cmdSetScanStart(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	state->_curLogic->sIP = state->_curLogic->cIP;
}

void cmdResetScanStart(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	state->_curLogic->sIP = 2;
}

void cmdSaveGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	vm->inGameTimerPause();

	if (state->automaticSave) {
		if (vm->saveGameAutomatic()) {
			// automatic save succeded
			vm->inGameTimerResume();
			return;
		}
		// fall back to regular dialog otherwise
	}

	vm->saveGameDialog();

	vm->inGameTimerResume();
}

void cmdLoadGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	vm->inGameTimerPause();

	if (state->automaticSave) {
		if (vm->loadGameAutomatic()) {
			// automatic restore succeded
			vm->inGameTimerResume();
			return;
		}
		// fall back to regular dialog otherwise
	}

	vm->loadGameDialog();

	vm->inGameTimerResume();
}

void cmdInitDisk(AgiGame *state, AgiEngine *vm, uint8 *parameter) {             // do nothing
}

void cmdLog(AgiGame *state, AgiEngine *vm, uint8 *parameter) {              // do nothing
}

void cmdTraceOn(AgiGame *state, AgiEngine *vm, uint8 *parameter) {              // do nothing
}

void cmdTraceInfo(AgiGame *state, AgiEngine *vm, uint8 *parameter) {                // do nothing
}

void cmdShowMem(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	state->_vm->_text->messageBox("Enough memory");
}

void cmdInitJoy(AgiGame *state, AgiEngine *vm, uint8 *parameter) { // do nothing
}

void cmdScriptSize(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	debug(0, "script.size(%d)", parameter[0]);
}

// This implementation is based on observations of Amiga's Gold Rush.
// You can try this out (in the original and in ScummVM) by writing "bird man"
// to enter Gold Rush's debug mode and then writing "show position" or "sp".
// TODO: Make the cycle and motion status lines more like in Amiga's Gold Rush.
// TODO: Add control status line (After stepsize, before cycle status).
// Don't know what the control status means yet, possibly flags?
// Examples of the control-value (Taken in the first screen i.e. room 1):
// 4051 (When ego is stationary),
// 471 (When walking on the first screen's bridge),
// 71 (When walking around, using the mouse or the keyboard).
void cmdObjStatusF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[vm->getVar(varNr)];

	const char *cycleDesc;  // Object's cycle description line
	const char *motionDesc; // Object's motion description line
	char msg[256];          // The whole object status message

	// Generate cycle description line
	switch (screenObj->cycle) {
	case kCycleNormal:
		cycleDesc = "normal cycle";
		break;
	case kCycleEndOfLoop:
		cycleDesc = "end of loop";
		break;
	case kCycleRevLoop:
		cycleDesc = "reverse loop";
		break;
	case kCycleReverse:
		cycleDesc = "reverse cycle";
		break;
	default:
		cycleDesc = "unknown cycle type";
		break;
	}

	// Generate motion description line
	switch (screenObj->motionType) {
	case kMotionNormal:
		motionDesc = "normal motion";
		break;
	case kMotionWander:
		motionDesc = "wandering";
		break;
	case kMotionFollowEgo:
		motionDesc = "following ego";
		break;
	case kMotionMoveObj:
		// Amiga's Gold Rush! most probably uses "move to (x, y)"
		// here with real values for x and y. The same output
		// is used when moving the ego around using the mouse.
		motionDesc = "moving to a point";
		break;
	default:
		motionDesc = "unknown motion type";
		break;
	}

	sprintf(msg,
	        "Object %d:\n" \
	        "x: %d  xsize: %d\n" \
	        "y: %d  ysize: %d\n" \
	        "pri: %d\n" \
	        "stepsize: %d\n" \
	        "%s\n" \
	        "%s",
	        vm->getVar(varNr),
	        screenObj->xPos, screenObj->xSize,
	        screenObj->yPos, screenObj->ySize,
	        screenObj->priority,
	        screenObj->stepSize,
	        cycleDesc,
	        motionDesc);
	state->_vm->_text->messageBox(msg);
}

// unknown commands:
// unk_170: Force savegame name -- j5
// unk_171: script save -- j5
// unk_172: script restore -- j5
// unk_173: Activate keypressed control (ego only moves while key is pressed)
// unk_174: Change priority table (used in KQ4) -- j5
// unk_177: Disable menus completely -- j5
// unk_181: Deactivate keypressed control (default control of ego)
void cmdSetSimple(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if (!(getFeatures() & (GF_AGI256 | GF_AGI256_2))) {
		// set.simple is called by Larry 1 on Apple IIgs at the store, after answering the 555-6969 phone.
		// load.sound(16) is called right before it. Interpreter is 2.440-like.
		// it's called with parameter 16.
		// Original interpreter doesn't seem to play any sound.
		// TODO: Figure out what's going on. It can't be automatic saving of course.
		// Also getting called in KQ1, when planting beans - parameter 12.
		// And when killing the witch - parameter 40.
		if ((getVersion() < 0x2425) || (getVersion() == 0x2440)) {
			// was not available before 2.2425, but also not available in 2.440
			warning("set.simple called, although not available for current AGI version");
			return;
		}

		int16 stringNr = parameter[0];
		const char *textPtr = nullptr;

		state->automaticSave = false;

		// Try to get description for automatic saves
		textPtr = state->strings[stringNr];

		strncpy(state->automaticSaveDescription, textPtr, sizeof(state->automaticSaveDescription));
		state->automaticSaveDescription[sizeof(state->automaticSaveDescription) - 1] = 0;

		if (state->automaticSaveDescription[0]) {
			// We got it and it's set, so enable automatic saving
			state->automaticSave = true;
		}

	} else { // AGI256 and AGI256-2 use this unknown170 command to load 256 color pictures.
		// Load the picture. Similar to void cmdLoad_pic(AgiGame *state, AgiEngine *vm, uint8 *p).
		SpritesMgr *spritesMgr = state->_vm->_sprites;
		uint16 varNr = parameter[0];
		uint16 resourceNr = vm->getVar(varNr);

		spritesMgr->eraseSprites();
		vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr);

		// Draw the picture. Similar to void cmdDraw_pic(AgiGame *state, AgiEngine *vm, uint8 *p).
		vm->_picture->decodePicture(resourceNr, false, true);
		spritesMgr->drawAllSpriteLists();
		state->pictureShown = false;

		// Loading trigger
		vm->artificialDelayTrigger_DrawPicture(resourceNr);

		// Show the picture. Similar to void cmdShow_pic(AgiGame *state, AgiEngine *vm, uint8 *p).
		vm->setFlag(VM_FLAG_OUTPUT_MODE, false);
		vm->_text->closeWindow();
		vm->_picture->showPic();
		state->pictureShown = true;
	}
}

// push.script was not available until 2.425, and also not available in 2.440
void cmdPopScript(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if ((getVersion() < 0x2425) || (getVersion() == 0x2440)) {
		// was not available before 2.2425, but also not available in 2.440
		warning("pop.script called, although not available for current AGI version");
		return;
	}

	debug(0, "pop.script");
}

void cmdDiscardSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if (getVersion() >= 0x2936) {
		debug(0, "discard.sound");
	}
}

void cmdShowMouse(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if (state->mouseEnabled) {
		state->mouseHidden = false;

		g_system->showMouse(true);
	}
}

// Seems to have been added for AGI3, at least according to PC AGI
// Space Quest 2 on Apple IIgs (using AGI ) calls it during the spaceship cutscene in the intro
// but show.mouse is never called afterwards. Game running under emulator doesn't seem to hide the mouse cursor.
// TODO: figure out, what exactly happens. Probably some hacked-in command and not related to mouse cursor for that game?
void cmdHideMouse(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if (getVersion() < 0x3000) {
		// was not available before 3.086
		warning("hide.mouse, although not available for current AGI version");
		return;
	}

	if ((vm->getGameID() == GID_MH1) && (vm->getPlatform() == Common::kPlatformApple2GS)) {
		// Called right after beating arcade sequence on day 4 in the hospital Parameter is "1".
		// Right before cutscene. show.mouse isn't called. Probably different function.
		warning("hide.mouse called, disabled for MH1 Apple IIgs");
		return;
	}

	// WORKAROUND: Turns off current movement that's being caused with the mouse.
	// This fixes problems with too many popup boxes appearing in the Amiga
	// Gold Rush's copy protection failure scene (i.e. the hanging scene, logic.192).
	// Previously multiple popup boxes appeared one after another if you tried
	// to walk somewhere else than to the right using the mouse.
	// FIXME: Write a proper implementation using disassembly and
	//        apply it to other games as well if applicable.
	//state->screenObjTable[SCREENOBJECTS_EGO_ENTRY].flags &= ~fAdjEgoXY;
	if (state->mouseEnabled) {
		state->mouseHidden = true;

		g_system->showMouse(false);
	}
}

void cmdAllowMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if (getVersion() < 0x3098) {
		// was not available before 3.098
		warning("allow.menu called, although not available for current AGI version");
		return;
	}

	uint16 allowed = parameter[0];

	if (allowed) {
		state->_vm->_menu->accessAllow();
	} else {
		state->_vm->_menu->accessDeny();
	}
}

void cmdFenceMouse(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr1 = parameter[0];
	uint16 varNr2 = parameter[1];
	uint16 varNr3 = parameter[2];
	uint16 varNr4 = parameter[3];

	state->mouseFence.moveTo(varNr1, varNr2);
	state->mouseFence.setWidth(varNr3 - varNr1);
	state->mouseFence.setHeight(varNr4 - varNr1);
}

// HoldKey was added in 2.425
// There was no way to disable this mode until 3.098 though
void cmdHoldKey(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if ((getVersion() < 0x2425) || (getVersion() == 0x2440)) {
		// was not available before 2.425, but also not available in 2.440
		warning("hold.key called, although not available for current AGI version");
		return;
	}

	vm->_keyHoldMode = true;
}

void cmdReleaseKey(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if (getVersion() < 0x3098) {
		// was not available before 3.098
		warning("release.key called, although not available for current AGI version");
		return;
	}

	vm->_keyHoldMode = false;
}

void cmdAdjEgoMoveToXY(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int8 x, y;

	switch (logicNamesCmd[182].argumentsLength()) {
	// The 2 arguments version is used at least in Amiga Gold Rush!
	// (v2.05 1989-03-09, Amiga AGI 2.316) in logics 130 and 150
	// (Using arguments (0, 0), (0, 7), (0, 8), (9, 9) and (-9, 9)).
	case 2:
		// Both arguments are signed 8-bit (i.e. in range -128 to +127).
		x = (int8) parameter[0];
		y = (int8) parameter[1];

		// Turn off ego's current movement caused with the mouse if
		// adj.ego.move.to.x.y is called with other arguments than previously.
		// Fixes weird looping behavior when walking to a ladder in the mines
		// (Rooms 147-162) in Gold Rush using the mouse. Sometimes the ego didn't
		// stop when walking to a ladder using the mouse but kept moving on the
		// ladder in a horizontally looping manner i.e. from right to left, from
		// right to left etc. In the Amiga Gold Rush the ego stopped when getting
		// onto the ladder so this is more like it (Although that may be caused
		// by something else because this command doesn't do any flag manipulations
		// in the Amiga version - checked it with disassembly).
		if (x != state->adjMouseX || y != state->adjMouseY)
			state->screenObjTable[SCREENOBJECTS_EGO_ENTRY].flags &= ~fAdjEgoXY;

		state->adjMouseX = x;
		state->adjMouseY = y;

		debugC(4, kDebugLevelScripts, "adj.ego.move.to.x.y(%d, %d)", x, y);
		break;
	// TODO: Check where (if anywhere) the 0 arguments version is used
	case 0:
	default:
		state->screenObjTable[SCREENOBJECTS_EGO_ENTRY].flags |= fAdjEgoXY;
		break;
	}
}

void cmdParse(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *text = state->_vm->_text;
	uint16 stringNr = parameter[0];

	vm->setVar(VM_VAR_WORD_NOT_FOUND, 0);
	vm->setFlag(VM_FLAG_ENTERED_CLI, false);
	vm->setFlag(VM_FLAG_SAID_ACCEPTED_INPUT, false);

	vm->_words->parseUsingDictionary(text->stringPrintf(state->strings[stringNr]));
}

void cmdCall(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 logicNr = parameter[0];
	int oldCIP;
	int oldLognum;

	// CM: we don't save sIP because set.scan.start can be
	//     used in a called script (fixes xmas demo)
	oldCIP = state->_curLogic->cIP;
	oldLognum = state->curLogicNr;

	state->_vm->runLogic(logicNr);

	state->curLogicNr = oldLognum;
	state->_curLogic = &state->logics[state->curLogicNr];
	state->_curLogic->cIP = oldCIP;
}

void cmdCallF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	byte   logicNr = vm->getVar(varNr);

	cmdCall(state, vm, &logicNr);
}

void cmdDrawPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	uint16 resourceNr = vm->getVar(varNr);

	debugC(6, kDebugLevelScripts, "=== draw pic V1 %d ===", resourceNr);
	state->_vm->_picture->decodePicture(resourceNr, true);

	// TODO: check, if this was really done
	vm->_text->promptClear();

	// Loading trigger
	vm->artificialDelayTrigger_DrawPicture(resourceNr);
}

void cmdDrawPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	SpritesMgr *spritesMgr = state->_vm->_sprites;
	uint16 varNr = parameter[0];
	uint16 resourceNr = vm->getVar(varNr);

	debugC(6, kDebugLevelScripts, "=== draw pic %d ===", resourceNr);

	spritesMgr->eraseSprites();
	vm->_picture->decodePicture(resourceNr, true);

	spritesMgr->buildAllSpriteLists();
	spritesMgr->drawAllSpriteLists();
	state->pictureShown = false;
	debugC(6, kDebugLevelScripts, "--- end of draw pic %d ---", resourceNr);

	// WORKAROUND for a script bug which exists in SQ1, logic scripts
	// 20 and 110. Flag 103 is not reset correctly, which leads to erroneous
	// behavior from view 46 (the spider droid). View 46 is supposed to
	// follow ego and explode when it comes in contact with him. However, as
	// flag 103 is not reset correctly, when the player goes down the path
	// and back up, the spider is always at the base of the path (since it
	// can't go up) and kills the player when he goes down at ground level
	// (although the spider droid sprite itself seems to be correctly positioned).
	// With this workaround, when the player goes back to picture 20 (1 screen
	// above the ground), flag 103 is reset, thereby fixing this issue. Note
	// that this is a script bug and occurs in the original interpreter as well.
	// Fixes bug #3056: AGI: SQ1 (2.2 DOS ENG) bizzare exploding roger
	if (vm->getGameID() == GID_SQ1 && resourceNr == 20)
		vm->setFlag(103, false);

	// Loading trigger
	vm->artificialDelayTrigger_DrawPicture(resourceNr);
}

void cmdShowPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	debugC(6, kDebugLevelScripts, "=== show pic ===");

	vm->setFlag(VM_FLAG_OUTPUT_MODE, false);
	vm->_text->closeWindow();
	vm->_picture->showPicWithTransition();
	state->pictureShown = true;

	debugC(6, kDebugLevelScripts, "--- end of show pic ---");
}

void cmdLoadPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	SpritesMgr *spritesMgr = state->_vm->_sprites;
	uint16 varNr = parameter[0];
	uint16 resourceNr = vm->getVar(varNr);

	spritesMgr->eraseSprites();
	vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr);
	spritesMgr->buildAllSpriteLists();
	spritesMgr->drawAllSpriteLists();
}

void cmdLoadPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 varNr = parameter[0];
	uint16 resourceNr = vm->getVar(varNr);

	state->_vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr);
}

void cmdDiscardPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	debugC(6, kDebugLevelScripts, "--- discard pic ---");
	// do nothing
}

void cmdOverlayPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	SpritesMgr *spritesMgr = state->_vm->_sprites;
	uint16 varNr = parameter[0];
	uint16 resourceNr = vm->getVar(varNr);

	debugC(6, kDebugLevelScripts, "--- overlay pic ---");

	spritesMgr->eraseSprites();
	vm->_picture->decodePicture(resourceNr, false);
	spritesMgr->buildAllSpriteLists();
	spritesMgr->drawAllSpriteLists();
	spritesMgr->showAllSpriteLists();
	state->pictureShown = false;

	// Loading trigger
	vm->artificialDelayTrigger_DrawPicture(resourceNr);
}

void cmdShowPriScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	GfxMgr *gfx = state->_vm->_gfx;

	gfx->debugShowMap(1); // switch to priority map

	state->_vm->waitKey();

	gfx->debugShowMap(0); // switch back to visual map
}

void cmdAnimateObj(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	if (getVersion() < 0x2000) {
		if (screenObj->flags & fDidntMove)
			return;
	} else {
		if (screenObj->flags & fAnimated)
			return;
	}

	debugC(4, kDebugLevelScripts, "animate vt entry #%d", objectNr);
	screenObj->flags = fAnimated | fUpdate | fCycling;

	if (getVersion() < 0x2000) {
		screenObj->flags |= fDidntMove;
	}

	screenObj->motionType = kMotionNormal;
	screenObj->cycle = kCycleNormal;
	screenObj->direction = 0;
}

void cmdUnanimateAll(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int i;

	state->_vm->_sprites->eraseSprites();

	for (i = 0; i < SCREENOBJECTS_MAX; i++)
		state->screenObjTable[i].flags &= ~(fAnimated | fDrawn);
}

void cmdDraw(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	if (screenObj->flags & fDrawn)
		return;

//	if (vt.ySize <= 0 || vt.xSize <= 0)
//		return;

	debugC(4, kDebugLevelScripts, "draw entry %d", screenObj->objectNr);

	screenObj->flags |= fUpdate;
	if (getVersion() >= 0x3000) {
		state->_vm->setLoop(screenObj, screenObj->currentLoopNr);
		state->_vm->setCel(screenObj, screenObj->currentCelNr);
	}

	SpritesMgr *sprites = state->_vm->_sprites;

	state->_vm->fixPosition(objectNr);
	screenObj->xPos_prev = screenObj->xPos;
	screenObj->yPos_prev = screenObj->yPos;
	screenObj->xSize_prev = screenObj->xSize;
	screenObj->ySize_prev = screenObj->ySize;
	//screenObj->celData2 = screenObj->celData;
	sprites->eraseRegularSprites();
	screenObj->flags |= fDrawn;
	sprites->buildRegularSpriteList();
	sprites->drawRegularSpriteList();
	sprites->showSprite(screenObj);
	screenObj->flags &= ~fDontupdate;

	debugC(4, kDebugLevelScripts, "vt entry #%d flags = %02x", objectNr, screenObj->flags);
}

void cmdErase(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	SpritesMgr *sprites = state->_vm->_sprites;
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	bool noUpdateFlag = false;

	if (!(screenObj->flags & fDrawn))
		return;

	sprites->eraseRegularSprites();
	if ((screenObj->flags & fUpdate) == 0) {
		noUpdateFlag = true;
		sprites->eraseStaticSprites();
	}

	screenObj->flags &= ~fDrawn;

	if (noUpdateFlag) {
		sprites->buildStaticSpriteList();
		sprites->drawStaticSpriteList();
	}
	sprites->buildRegularSpriteList();
	sprites->drawRegularSpriteList();
	sprites->showSprite(screenObj);
}

void cmdPosition(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 xPos = parameter[1];
	uint16 yPos = parameter[2];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->xPos = screenObj->xPos_prev = xPos;
	screenObj->yPos = screenObj->yPos_prev = yPos;
}

void cmdPositionV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 xPos = parameter[1];
	uint16 yPos = parameter[2];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->xPos = xPos;
	screenObj->yPos = yPos;
}

void cmdPositionF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr1 = parameter[1];
	uint16 varNr2 = parameter[2];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->xPos = screenObj->xPos_prev = vm->getVar(varNr1);
	screenObj->yPos = screenObj->yPos_prev = vm->getVar(varNr2);
}

void cmdPositionFV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr1 = parameter[1];
	uint16 varNr2 = parameter[2];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->xPos = vm->getVar(varNr1);
	screenObj->yPos = vm->getVar(varNr2);
}

void cmdGetPosn(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr1 = parameter[1];
	uint16 varNr2 = parameter[2];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	vm->setVar(varNr1, (unsigned char)screenObj->xPos);
	vm->setVar(varNr2, (unsigned char)screenObj->yPos);
}

void cmdReposition(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr1 = parameter[1];
	uint16 varNr2 = parameter[2];
	int16 dx = (int8) vm->getVar(varNr1);
	int16 dy = (int8) vm->getVar(varNr2);
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	debugC(4, kDebugLevelScripts, "dx=%d, dy=%d", dx, dy);
	screenObj->flags |= fUpdatePos;

	if (dx < 0 && screenObj->xPos < -dx)
		screenObj->xPos = 0;
	else
		screenObj->xPos += dx;

	if (dy < 0 && screenObj->yPos < -dy)
		screenObj->yPos = 0;
	else
		screenObj->yPos += dy;

	state->_vm->fixPosition(objectNr);
}

void cmdRepositionV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 xPosPlus = parameter[1];
	uint16 yPosPlus = parameter[2];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->xPos_prev = screenObj->xPos;
	screenObj->yPos_prev = screenObj->yPos;
	screenObj->flags |= fUpdatePos;

	screenObj->xPos = (screenObj->xPos + xPosPlus) & 0xff;
	screenObj->yPos = (screenObj->yPos + yPosPlus) & 0xff;
}

void cmdRepositionTo(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 xPos = parameter[1];
	uint16 yPos = parameter[2];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->xPos = xPos;
	screenObj->yPos = yPos;
	screenObj->flags |= fUpdatePos;
	state->_vm->fixPosition(objectNr);
}

void cmdRepositionToF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 varNr1 = parameter[1];
	uint16 varNr2 = parameter[2];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->xPos = vm->getVar(varNr1);
	screenObj->yPos = vm->getVar(varNr2);
	screenObj->flags |= fUpdatePos;
	state->_vm->fixPosition(objectNr);
}

void cmdAddToPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 viewNr = parameter[0];
	uint16 loopNr = parameter[1];
	uint16 celNr = parameter[2];
	uint16 xPos = parameter[3];
	uint16 yPos = parameter[4];
	uint16 priority = parameter[5];
	uint16 border = parameter[6];

	state->_vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border);
}

void cmdAddToPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 viewNr = parameter[0];
	uint16 loopNr = parameter[1];
	uint16 celNr = parameter[2];
	uint16 xPos = parameter[3];
	uint16 yPos = parameter[4];
	uint16 priority = parameter[5];

	state->_vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, -1);
}

void cmdAddToPicF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 viewNr = vm->getVar(parameter[0]);
	uint16 loopNr = vm->getVar(parameter[1]);
	uint16 celNr = vm->getVar(parameter[2]);
	uint16 xPos = vm->getVar(parameter[3]);
	uint16 yPos = vm->getVar(parameter[4]);
	uint16 priority = vm->getVar(parameter[5]);
	uint16 border = vm->getVar(parameter[6]);

	state->_vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border);
}

void cmdForceUpdate(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	SpritesMgr *spritesMgr = state->_vm->_sprites;

	spritesMgr->eraseSprites();
	spritesMgr->buildAllSpriteLists();
	spritesMgr->drawAllSpriteLists();
	spritesMgr->showAllSpriteLists();
}

void cmdReverseLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 loopFlag = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	debugC(4, kDebugLevelScripts, "o%d, f%d", objectNr, loopFlag);
	screenObj->cycle = kCycleRevLoop;
	screenObj->flags |= (fDontupdate | fUpdate | fCycling);
	screenObj->loop_flag = loopFlag;
	state->_vm->setFlag(screenObj->loop_flag, false);

	vm->cyclerActivated(screenObj);
}

void cmdReverseLoopV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 loopFlag = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	debugC(4, kDebugLevelScripts, "o%d, f%d", objectNr, loopFlag);
	screenObj->cycle = kCycleRevLoop;
	state->_vm->setCel(screenObj, 0);
	screenObj->flags |= (fDontupdate | fUpdate | fCycling);
	screenObj->loop_flag = loopFlag;
	//screenObj->parm3 = 0;
}

void cmdEndOfLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 loopFlag = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	debugC(4, kDebugLevelScripts, "o%d, f%d", objectNr, loopFlag);
	screenObj->cycle = kCycleEndOfLoop;
	screenObj->flags |= (fDontupdate | fUpdate | fCycling);
	screenObj->loop_flag = loopFlag;
	vm->setFlag(screenObj->loop_flag, false);

	vm->cyclerActivated(screenObj);
}

void cmdEndOfLoopV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 loopFlag = parameter[1];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	debugC(4, kDebugLevelScripts, "o%d, f%d", objectNr, loopFlag);
	screenObj->cycle = kCycleEndOfLoop;
	state->_vm->setCel(screenObj, 0);
	screenObj->flags |= (fDontupdate | fUpdate | fCycling);
	screenObj->loop_flag = loopFlag;
	//screenObj->parm3 = 0;
}

void cmdBlock(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 x1 = parameter[0];
	uint16 y1 = parameter[1];
	uint16 x2 = parameter[2];
	uint16 y2 = parameter[3];

	debugC(4, kDebugLevelScripts, "x1=%d, y1=%d, x2=%d, y2=%d", x1, y1, x2, y2);
	state->block.active = true;
	state->block.x1 = x1;
	state->block.y1 = y1;
	state->block.x2 = x2;
	state->block.y2 = y2;
}

void cmdUnblock(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	state->block.active = false;
}

void cmdNormalMotion(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->motionType = kMotionNormal;
}

void cmdStopMotion(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->direction = 0;
	screenObj->motionType = kMotionNormal;
	if (objectNr == 0) {        // ego only
		state->_vm->setVar(VM_VAR_EGO_DIRECTION, 0);
		state->playerControl = false;
	}
}

void cmdStopMotionV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags &= ~fAnimated;
}

void cmdStartMotion(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->motionType = kMotionNormal;
	if (objectNr == 0) {        // ego only
		state->_vm->setVar(VM_VAR_EGO_DIRECTION, 0);
		state->playerControl = true;
	}
}

void cmdStartMotionV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->flags |= fAnimated;
}

void cmdPlayerControl(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	ScreenObjEntry *screenObjEgo = &state->screenObjTable[SCREENOBJECTS_EGO_ENTRY];

	state->playerControl = true;

	if (screenObjEgo->motionType != kMotionEgo)
		screenObjEgo->motionType = kMotionNormal;
}

void cmdProgramControl(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	state->playerControl = false;
}

void cmdFollowEgo(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 followStepSize = parameter[1];
	uint16 followFlag = parameter[2];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->motionType = kMotionFollowEgo;
	if (followStepSize <= screenObj->stepSize) {
		screenObj->follow_stepSize = screenObj->stepSize;
	} else {
		screenObj->follow_stepSize = followStepSize;
	}
	screenObj->follow_flag = followFlag;
	screenObj->follow_count = 255;

	if (getVersion() < 0x2000) {
		vm->setVar(screenObj->follow_flag, 0);
		screenObj->flags |= fUpdate | fAnimated;
	} else {
		vm->setFlag(screenObj->follow_flag, false);
		screenObj->flags |= fUpdate;
	}

	vm->motionActivated(screenObj);
}

void cmdMoveObj(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 moveX = parameter[1];
	uint16 moveY = parameter[2];
	uint16 stepSize = parameter[3];
	uint16 moveFlag = parameter[4];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];
	// _D (_D_WARN "o=%d, x=%d, y=%d, s=%d, f=%d", p0, p1, p2, p3, p4);

	screenObj->motionType = kMotionMoveObj;
	screenObj->move_x = moveX;
	screenObj->move_y = moveY;
	screenObj->move_stepSize = screenObj->stepSize;
	screenObj->move_flag = moveFlag;

	if (stepSize != 0)
		screenObj->stepSize = stepSize;

	if (getVersion() < 0x2000) {
		vm->setVar(moveFlag, 0);
		screenObj->flags |= fUpdate | fAnimated;
	} else {
		vm->setFlag(screenObj->move_flag, false);
		screenObj->flags |= fUpdate;
	}

	vm->motionActivated(screenObj);

	if (objectNr == 0)
		state->playerControl = false;

	// AGI 2.272 (ddp, xmas) doesn't call move_obj!
	if (getVersion() > 0x2272)
		vm->moveObj(screenObj);
}

void cmdMoveObjF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	uint16 moveX = vm->getVar(parameter[1]);
	uint16 moveY = vm->getVar(parameter[2]);
	uint16 stepSize = vm->getVar(parameter[3]);
	uint16 moveFlag = parameter[4];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	screenObj->motionType = kMotionMoveObj;
	screenObj->move_x = moveX;
	screenObj->move_y = moveY;
	screenObj->move_stepSize = screenObj->stepSize;
	screenObj->move_flag = moveFlag;

	if (stepSize != 0)
		screenObj->stepSize = stepSize;

	vm->setFlag(screenObj->move_flag, false);
	screenObj->flags |= fUpdate;

	vm->motionActivated(screenObj);

	if (objectNr == 0)
		state->playerControl = false;

	// AGI 2.272 (ddp, xmas) doesn't call move_obj!
	if (getVersion() > 0x2272)
		vm->moveObj(screenObj);
}

void cmdWander(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr = parameter[0];
	ScreenObjEntry *screenObj = &state->screenObjTable[objectNr];

	if (objectNr == 0)
		state->playerControl = false;

	screenObj->motionType = kMotionWander;
	if (getVersion() < 0x2000) {
		screenObj->flags |= fUpdate | fAnimated;
	} else {
		screenObj->flags |= fUpdate;
	}

	vm->motionActivated(screenObj);
}

void cmdSetGameID(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 textNr = parameter[0];

	if (state->_curLogic->texts && (textNr - 1) <= state->_curLogic->numTexts)
		Common::strlcpy(state->id, state->_curLogic->texts[textNr - 1], 8);
	else
		state->id[0] = 0;

	debug(0, "Game ID: \"%s\"", state->id);
}

void cmdPause(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	// Show pause message box
	vm->inGameTimerPause();

	state->_vm->_systemUI->pauseDialog();

	vm->inGameTimerResume();
}

void cmdSetMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 textNr = parameter[0];

	debugC(4, kDebugLevelScripts, "text %02x of %02x", textNr, state->_curLogic->numTexts);

	if (state->_curLogic->texts != NULL && (textNr - 1) <= state->_curLogic->numTexts) {
		const char *menuText = state->_curLogic->texts[textNr - 1];

		state->_vm->_menu->addMenu(menuText);
	}
}

void cmdSetMenuItem(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 textNr = parameter[0] - 1;
	uint16 controllerSlot = parameter[1];

	debugC(4, kDebugLevelScripts, "text %02x of %02x", textNr, state->_curLogic->numTexts);

	if (state->_curLogic->texts != NULL && textNr <= state->_curLogic->numTexts) {
		const char *menuItemText = state->_curLogic->texts[textNr];

		state->_vm->_menu->addMenuItem(menuItemText, controllerSlot);
	}
}

void cmdVersion(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	char ver2Msg[] =
	    "\n"
	    "                               \n\n"
	    "  ScummVM Sierra AGI v%x.%03x";
	char ver3Msg[] =
	    "\n"
	    "                             \n\n"
	    "ScummVM Sierra AGI v%x.002.%03x";

	Common::String verMsg = TITLE " v%s";

	int ver = getVersion();
	int maj = (ver >> 12) & 0xf;
	int min = ver & 0xfff;

	verMsg += (maj == 2 ? ver2Msg : ver3Msg);
	verMsg = Common::String::format(verMsg.c_str(), gScummVMVersion, maj, min);

	state->_vm->_text->messageBox(verMsg.c_str());
}

void cmdConfigureScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *textMgr = state->_vm->_text;
	uint16 lineMinPrint = parameter[0];
	uint16 promptRow = parameter[1];
	uint16 statusRow = parameter[2];

	textMgr->configureScreen(lineMinPrint);
	textMgr->statusRow_Set(statusRow);
	textMgr->promptRow_Set(promptRow);
}

void cmdTextScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	GfxMgr  *gfxMgr = state->_vm->_gfx;
	TextMgr *textMgr = state->_vm->_text;

	debugC(4, kDebugLevelScripts, "switching to text mode");

	state->gfxMode = false;
	gfxMgr->setPalette(false); // set text-mode palette
	textMgr->charAttrib_Set(textMgr->_textAttrib.foreground, textMgr->_textAttrib.background);
	gfxMgr->clearDisplay(0);
	textMgr->clearLines(0, 24, textMgr->_textAttrib.combinedBackground);
}

void cmdGraphics(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	debugC(4, kDebugLevelScripts, "switching to graphics mode");

	state->_vm->redrawScreen();
}

void cmdSetTextAttribute(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int16 foreground = parameter[0];
	int16 background = parameter[1];
	state->_vm->_text->charAttrib_Set(foreground, background);
}

void cmdStatus(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *textMgr = state->_vm->_text;
	InventoryMgr *inventoryMgr = state->_vm->_inventory;

	textMgr->inputEditOn();
	textMgr->charAttrib_Push();
	textMgr->charAttrib_Set(0, 15);

	cmdTextScreen(state, vm, parameter);

	inventoryMgr->show();

	//invent_state = 0;
	textMgr->charAttrib_Pop();
	state->_vm->redrawScreen();
}

void cmdQuit(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 withoutPrompt = parameter[0];
//	const char *buttons[] = { "Quit", "Continue", NULL };

	state->_vm->_sound->stopSound();
	if (withoutPrompt) {
		state->_vm->quitGame();
	} else {
		if (state->_vm->_systemUI->quitDialog()) {
			state->_vm->quitGame();
		}
	}
}

void cmdQuitV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	state->_vm->_sound->stopSound();
	state->_vm->quitGame();
}

void cmdRestartGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	bool doRestart = false;

	state->_vm->_sound->stopSound();

	if (vm->getFlag(VM_FLAG_AUTO_RESTART)) {
		doRestart = true;
	} else {
		doRestart = vm->_systemUI->restartDialog();
	}

	if (doRestart) {
		vm->_restartGame = true;
		vm->setFlag(VM_FLAG_RESTART_GAME, true);
		vm->_menu->itemEnableAll();
	}
}

void cmdDistance(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 objectNr1 = parameter[0];
	uint16 objectNr2 = parameter[1];
	uint16 destVarNr = parameter[2];
	int16 x1, y1, x2, y2, d;
	ScreenObjEntry *screenObj1 = &state->screenObjTable[objectNr1];
	ScreenObjEntry *screenObj2 = &state->screenObjTable[objectNr2];

	if (screenObj1->flags & fDrawn && screenObj2->flags & fDrawn) {
		x1 = screenObj1->xPos + screenObj1->xSize / 2;
		y1 = screenObj1->yPos;
		x2 = screenObj2->xPos + screenObj2->xSize / 2;
		y2 = screenObj2->yPos;
		d = ABS(x1 - x2) + ABS(y1 - y2);
		if (d > 0xfe)
			d = 0xfe;
	} else {
		d = 0xff;
	}

	// WORKAROUND: Fixes King's Quest IV's script bug #3067 (KQ4: Zombie bug).
	// This bug also happens in the original interpreter.
	// In the graveyard (Rooms 16 and 18) at night if you had the Obsidian Scarab (Item 4)
	// and you were very close to a spot where a zombie was going to rise up from the
	// ground you could reproduce the bug. Just standing there and letting the zombie
	// try to rise up the Obsidian Scarab would repel the zombie immediately and that
	// would make the script bug so that the zombie would still come up but it just
	// wouldn't chase Rosella around anymore. If it had worked correctly the zombie
	// wouldn't have come up at all or it would have come up and gone back down
	// immediately. The latter approach is the one implemented here.
	if (vm->getGameID() == GID_KQ4 && (vm->getVar(VM_VAR_CURRENT_ROOM) == 16 || vm->getVar(VM_VAR_CURRENT_ROOM) == 18) && destVarNr >= 221 && destVarNr <= 223) {
		// Rooms 16 and 18 are graveyards where three zombies come up at night. They use logics 16 and 18.
		// Variables 221-223 are used to save the distance between each zombie and Rosella.
		// Variables 155, 156 and 162 are used to save the state of each zombie in room 16.
		// Variables 155, 156 and 158 are used to save the state of each zombie in room 18.
		// Rosella gets turned to a zombie only if any of the zombies is under 10 units away
		// from her and she doesn't have the Obsidian Scarab (Item 4). Likewise Rosella makes
		// a zombie go back into the ground if the zombie comes under 15 units away from her
		// and she has the Obsidian Scarab. To ensure a zombie always first rises up before
		// checking for either of the aforementioned conditions (Rosella getting turned to
		// a zombie or the zombie getting turned away by the scarab) we make it appear the
		// zombie is far away from Rosella if the zombie is not already up and chasing her.
		enum zombieStates {ZOMBIE_SET_TO_RISE_UP, ZOMBIE_RISING_UP, ZOMBIE_CHASING_EGO};
		uint8 zombieStateVarNumList[] = {155, 156, (uint8)((vm->getVar(VM_VAR_CURRENT_ROOM) == 16) ? 162 : 158)};
		uint8 zombieNum         = destVarNr - 221;                         // Zombie's number (In range 0-2)
		uint8 zombieStateVarNum = zombieStateVarNumList[zombieNum]; // Number of the variable containing zombie's state
		uint8 zombieState       = vm->getVar(zombieStateVarNum);   // Zombie's state
		// If zombie is not chasing Rosella then set its distance from Rosella to the maximum
		if (zombieState != ZOMBIE_CHASING_EGO)
			d = 0xff;
	}

	vm->setVar(destVarNr, (unsigned char)d);
}

void cmdAcceptInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *textMgr = state->_vm->_text;

	debugC(4, kDebugLevelScripts | kDebugLevelInput, "input normal");

	textMgr->promptEnable();
	textMgr->promptRedraw();
}

void cmdPreventInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *textMgr = state->_vm->_text;

	debugC(4, kDebugLevelScripts | kDebugLevelInput, "no input");

	textMgr->promptDisable();

	textMgr->inputEditOn();
	textMgr->clearLine(textMgr->promptRow_Get(), 0);
}

void cmdCancelLine(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	state->_vm->_text->promptCancelLine();
}

void cmdEchoLine(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *textMgr = state->_vm->_text;

	if (textMgr->promptIsEnabled()) {
		textMgr->promptEchoLine();
	}
}

void cmdGetString(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *textMgr = state->_vm->_text;
	int16 stringDestNr = parameter[0];
	int16 leadInTextNr = parameter[1] - 1;
	int16 stringRow = parameter[2];
	int16 stringColumn = parameter[3];
	int16 stringMaxLen = parameter[4];
	bool previousEditState = false;
	const char *leadInTextPtr = nullptr;

	if (stringMaxLen > TEXT_STRING_MAX_SIZE)
		stringMaxLen = TEXT_STRING_MAX_SIZE;

	debugC(4, kDebugLevelScripts, "%d %d %d %d %d", stringDestNr, leadInTextNr, stringRow, stringColumn, stringMaxLen);

	previousEditState = textMgr->inputGetEditStatus();

	textMgr->charPos_Push();
	textMgr->inputEditOn();

	// Workaround for SQLC bug.
	// See Sarien bug #792125 for details
//	if (promptRow > 24)
//		promptRow = 24;
//	if (promptColumn > 39)
//		promptColumn = 39;

	if (stringRow < 25) {
		textMgr->charPos_Set(stringRow, stringColumn);
	}

	if (state->_curLogic->texts && state->_curLogic->numTexts >= leadInTextNr) {
		leadInTextPtr = state->_curLogic->texts[leadInTextNr];

		leadInTextPtr = textMgr->stringPrintf(leadInTextPtr);
		leadInTextPtr = textMgr->stringWordWrap(leadInTextPtr, 40); // ?? not absolutely sure

		textMgr->displayText(leadInTextPtr);
	}

	state->_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETSTRING);

	textMgr->stringSet("");
	textMgr->stringEdit(stringMaxLen);

	// copy string to destination
	// TODO: not sure if set all the time or only when ENTER is pressed
	strcpy(&state->_vm->_game.strings[stringDestNr][0], (char *)textMgr->_inputString);

	textMgr->charPos_Pop();

	if (!previousEditState) {
		textMgr->inputEditOff();
	}
}

void cmdGetNum(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *textMgr = state->_vm->_text;
	int16 leadInTextNr = parameter[0] - 1;
	int16 numberDestVarNr = parameter[1];
	const char *leadInTextPtr = nullptr;
	byte  number = 0;

	debugC(4, kDebugLevelScripts, "%d %d", leadInTextNr, numberDestVarNr);

	textMgr->inputEditOn();
	textMgr->charPos_Set(textMgr->promptRow_Get(), 0);

	if (state->_curLogic->texts && state->_curLogic->numTexts >= leadInTextNr) {
		leadInTextPtr = state->_curLogic->texts[leadInTextNr];

		leadInTextPtr = textMgr->stringPrintf(leadInTextPtr);
		leadInTextPtr = textMgr->stringWordWrap(leadInTextPtr, 40); // ?? not absolutely sure

		textMgr->displayText(leadInTextPtr);
	}

	textMgr->inputEditOff();

	state->_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETNUMBER);

	textMgr->stringSet("");
	textMgr->stringEdit(3);

	textMgr->promptRedraw();

	number = atoi((char *)textMgr->_inputString);
	vm->setVar(numberDestVarNr, number);

	debugC(4, kDebugLevelScripts, "[%s] -> %d", state->strings[MAX_STRINGS], number);
}

void cmdSetCursorChar(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	TextMgr *textMgr = state->_vm->_text;
	uint16 textNr = parameter[0] - 1;

	if (state->_curLogic->texts != NULL && textNr <= state->_curLogic->numTexts) {
		textMgr->inputSetCursorChar(*state->_curLogic->texts[textNr]);
	} else {
		// default
		textMgr->inputSetCursorChar('_');
	}
}

void cmdSetKey(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 key = parameter[0] + (parameter[1] << 8);
	uint16 controllerSlot = parameter[2];
	int16 keyMappingSlot = -1;

	for (int i = 0; i < MAX_CONTROLLER_KEYMAPPINGS; i++) {
		if (keyMappingSlot == -1 && !state->controllerKeyMapping[i].keycode)
			keyMappingSlot = i;

		if (state->controllerKeyMapping[i].keycode == key && state->controllerKeyMapping[i].controllerSlot == controllerSlot)
			return;
	}

	if (keyMappingSlot == -1) {
		warning("Number of set.keys exceeded %d", MAX_CONTROLLER_KEYMAPPINGS);
		return;
	}

	debugC(4, kDebugLevelScripts, "cmdSetKey: %d %d %d", parameter[0], parameter[1], controllerSlot);
	state->controllerKeyMapping[keyMappingSlot].keycode = key;
	state->controllerKeyMapping[keyMappingSlot].controllerSlot = controllerSlot;

	state->controllerOccured[controllerSlot] = false;
}

void cmdSetString(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 stringNr = parameter[0];
	uint16 textNr = parameter[1] - 1;
	// CM: to avoid crash in Groza (str = 150)
	if (stringNr > MAX_STRINGS)
		return;
	strcpy(state->strings[stringNr], state->_curLogic->texts[textNr]);
}

void cmdDisplay(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	// V1 has 4 args
	int16 textNr = (getVersion() >= 0x2000 ? parameter[2] : parameter[3]);
	int16 textRow = parameter[0];
	int16 textColumn = parameter[1];

	state->_vm->_text->display(textNr, textRow, textColumn);
}

void cmdDisplayF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int16 textRow = vm->getVar(parameter[0]);
	int16 textColumn = vm->getVar(parameter[1]);
	int16 textNr = vm->getVar(parameter[2]);

	state->_vm->_text->display(textNr, textRow, textColumn);
}

void cmdClearTextRect(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int16 textUpperRow = parameter[0];
	int16 textUpperColumn = parameter[1];
	int16 textLowerRow = parameter[2];
	int16 textLowerColumn = parameter[3];
	int16 color = state->_vm->_text->calculateTextBackground(parameter[4]);

	state->_vm->_text->clearBlock(textUpperRow, textUpperColumn, textLowerRow, textLowerColumn, color);
}

void cmdToggleMonitor(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	debug(0, "toggle.monitor");
}

void cmdClearLines(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int16 textRowUpper = parameter[0];
	int16 textRowLower = parameter[1];
	int16 color = state->_vm->_text->calculateTextBackground(parameter[2]);

	// Residence 44 calls clear.lines(24,0,0), see Sarien bug #558423
	// Agent06 incorrectly calls clear.lines(1,150,0), see ScummVM bugs
	// #1935838 and #1935842
	if (textRowUpper > textRowLower) {
		warning("cmdClearLines: RowUpper higher than RowLower");
		textRowLower = textRowUpper;
	}
	state->_vm->_text->clearLines(textRowUpper, textRowLower, color);
}

void cmdPrint(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int16 textNr = parameter[0];

	state->_vm->_text->print(textNr);
}

void cmdPrintF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int16 textNr = vm->getVar(parameter[0]);

	state->_vm->_text->print(textNr);
}

void cmdPrintAt(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int16 textNr = parameter[0];
	int16 textRow = parameter[1];
	int16 textColumn = parameter[2];
	int16 textWidth = parameter[3];

	debugC(4, kDebugLevelScripts, "%d %d %d %d", textNr, textRow, textColumn, textWidth);

	state->_vm->_text->printAt(textNr, textRow, textColumn, textWidth);
}

void cmdPrintAtV(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	int16 textNr = vm->getVar(parameter[0]);
	int16 textRow = parameter[1];
	int16 textColumn = parameter[2];
	int16 textWidth = parameter[3];

	debugC(4, kDebugLevelScripts, "%d %d %d %d", textNr, textRow, textColumn, textWidth);

	state->_vm->_text->printAt(textNr, textRow, textColumn, textWidth);
}

// push.script was not available until 2.425, and also not available in 2.440
void cmdPushScript(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	// We run AGIMOUSE always as a side effect
	//if (getFeatures() & GF_AGIMOUSE || true) {
	vm->setVar(VM_VAR_MOUSE_BUTTONSTATE, state->_vm->_mouse.button);
	vm->setVar(VM_VAR_MOUSE_X, vm->_mouse.pos.x / 2);
	vm->setVar(VM_VAR_MOUSE_Y, vm->_mouse.pos.y);
	/*} else {
	    if (getVersion() >= 0x2915) {
	        debug(0, "push.script");
	    }
	}*/
}

void cmdSetPriBase(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	if ((getVersion() != 0x2425) && (getVersion() < 0x2936)) {
		// was only available in the 2.425 interpreter and from 2.936 (last AGI2 version) onwards
		// Called during KQ3 (Apple IIgs):
		//  - picking up chicken (parameter = 50)
		//  - opening store/tavern door (parameter = 19)
		//  - when pirates say "Land Ho" (parameter = 16)
		//  - when killing the dragon (parameter = 4)
		// Also called by SQ2 (Apple IIgs):
		//  - in Vohaul's lair (SQ2 currently gets this call through, which breaks some priority)
		// TODO: Figure out what's going on
		warning("set.pri.base called, although not available for current AGI version");
		return;
	}

	uint16 priorityBase = parameter[0];

	debug(0, "Priority base set to %d", priorityBase);

	state->_vm->_gfx->setPriorityTable(priorityBase);
}

void cmdMousePosn(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 destVarNr1 = parameter[0];
	uint16 destVarNr2 = parameter[1];
	int16 mouseX = vm->_mouse.pos.x;
	int16 mouseY = vm->_mouse.pos.y;

	vm->_gfx->translateDisplayPosToGameScreen(mouseX, mouseY);

	vm->setVar(destVarNr1, mouseX);
	vm->setVar(destVarNr2, mouseY);
}

void cmdShakeScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 shakeCount = parameter[0];

	// AGIPAL uses shake.screen values between 100 and 109 to set the palette
	// (Checked the original AGIPAL-hack's shake.screen-routine's disassembly).
	if (shakeCount >= 100 && shakeCount < 110) {
		if (getFeatures() & GF_AGIPAL) {
			state->_vm->_gfx->setAGIPal(shakeCount);
			return;
		} else {
			warning("It looks like GF_AGIPAL flag is missing");
		}
	}

	state->_vm->_gfx->shakeScreen(shakeCount);
}

void cmdSetSpeed(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	// V1 command
	(void)state;
	(void)parameter;
	// speed = _v[p0];
}

void cmdSetItemView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	// V1 command
	(void)state;
	(void)parameter;
}

void cmdCallV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 resourceNr = parameter[0];

	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
	// FIXME: The following instruction looks incomplete.
	// Maybe something is meant to be assigned to, or read from,
	// the logic_list entry?
//	state->logic_list[++state->max_logics];
	// For now, just do the increment, to silence a clang warning
	++state->max_logics;
	vm->setVar(13, 1); // ???? maybe create another enum vor VM Vars
}

void cmdNewRoomV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 resourceNr = parameter[0];

	warning("cmdNewRoomV1()");
	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
	state->max_logics = 1;
	state->logic_list[1] = resourceNr;
	vm->setVar(13, 1);
}

void cmdNewRoomVV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	uint16 resourceNr = vm->getVar(parameter[0]);

	warning("cmdNewRoomVV1()");
	state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
	state->max_logics = 1;
	state->logic_list[1] = resourceNr;
	vm->setVar(13, 1);
}

void cmdUnknown(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
	warning("Skipping unknown opcode %2X", *(state->_curLogic->data + state->_curLogic->cIP - 1));
}

/**
 * Execute a logic script
 * @param n  Number of the logic resource to execute
 */
int AgiEngine::runLogic(int16 logicNr) {
	AgiGame *state = &_game;
	uint8 op = 0;
	uint8 p[CMD_BSIZE] = { 0 };
	int num = 0;
	ScriptPos sp;
	//int logic_index = 0;

	state->logic_list[0] = 0;
	state->max_logics = 0;

	debugC(2, kDebugLevelScripts, "=================");
	debugC(2, kDebugLevelScripts, "runLogic(%d)", logicNr);

	sp.script = logicNr;
	sp.curIP = 0;
	_game.execStack.push_back(sp);

	// If logic not loaded, load it
	if (~_game.dirLogic[logicNr].flags & RES_LOADED) {
		debugC(4, kDebugLevelScripts, "logic %d not loaded!", logicNr);
		agiLoadResource(RESOURCETYPE_LOGIC, logicNr);
	}

	_game.curLogicNr = logicNr;
	_game._curLogic = &_game.logics[_game.curLogicNr];

	_game._curLogic->cIP = _game._curLogic->sIP;

	while (state->_curLogic->cIP < _game.logics[logicNr].size && !(shouldQuit() || _restartGame)) {
		// TODO: old code, needs to be adjusted
#if 0
		if (_debug.enabled) {
			if (_debug.steps > 0) {
				if (_debug.logic0 || n) {
					debugConsole(n, lCOMMAND_MODE, NULL);
					_debug.steps--;
				}
			} else {
				_sprites->blitBoth();
				_sprites->commitBoth();
				do {
					mainCycle();
				} while (!_debug.steps && _debug.enabled);
				_sprites->eraseAllSprites();
			}
		}
#endif

		// Just a counter for every instruction, that got executed
		_instructionCounter++;

		_game.execStack.back().curIP = state->_curLogic->cIP;

		char st[101];
		int sz = MIN(_game.execStack.size(), 100u);
		memset(st, '.', sz);
		st[sz] = 0;

		switch (op = *(state->_curLogic->data + state->_curLogic->cIP++)) {
		case 0xff:  // if (open/close)
			testIfCode(logicNr);
			break;
		case 0xfe:  // goto
			// +2 covers goto size
			state->_curLogic->cIP += 2 + ((int16)READ_LE_UINT16(state->_curLogic->data + state->_curLogic->cIP));
			break;
		case 0x00:  // return
			debugC(2, kDebugLevelScripts, "%sreturn() // Logic %d", st, logicNr);
			debugC(2, kDebugLevelScripts, "=================");

//			if (getVersion() < 0x2000) {
//				if (logic_index < state->max_logics) {
//					n = state->logic_list[++logic_index];
//					state->_curLogic = &state->logics[n];
//					state->lognum = n;
//					ip = 2;
//					warning("running logic %d\n", n);
//					break;
//				}
//				_v[13]=0;
//			}

			_game.execStack.pop_back();
			return 1;
		default:
			num = logicNamesCmd[op].argumentsLength();
			memmove(p, state->_curLogic->data + state->_curLogic->cIP, num);
			memset(p + num, 0, CMD_BSIZE - num);

			debugC(2, kDebugLevelScripts, "%s%s(%d %d %d)", st, logicNamesCmd[op].name, p[0], p[1], p[2]);

			_agiCommands[op](&_game, this, p);
			state->_curLogic->cIP += num;
		}

//		if ((op == 0x0B || op == 0x3F || op == 0x40) && logic_index < state->max_logics) {
//			n = state->logic_list[++logic_index];
//			state->_curLogic = &state->logics[n];
//			state->lognum = n;
//			state->_curLogic_cIP = 2;
//			warning("running logic %d\n", n);
//		}

		if (_game.exitAllLogics)
			break;
	}

	_game.execStack.pop_back();

	return 0;       // after executing new.room()
}

void AgiEngine::executeAgiCommand(uint8 op, uint8 *p) {
	debugC(2, kDebugLevelScripts, "%s(%d %d %d)", logicNamesCmd[op].name, p[0], p[1], p[2]);

	_agiCommands[op](&_game, this, p);
}

} // End of namespace Agi