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
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001-2005 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$
*
*/
// Item script opcodes for Simon1/Simon2
#include <ctype.h>
#include "stdafx.h"
#include "simon/simon.h"
#include "simon/intern.h"
#include "common/system.h"
#ifdef _WIN32_WCE
extern bool isSmartphone(void);
#endif
namespace Simon {
int SimonEngine::runScript() {
byte opcode;
bool flag, condition;
do {
if (_continousMainScript)
dumpOpcode(_codePtr);
opcode = getByte();
if (opcode == 0xFF)
return 0;
if (_runScriptReturn1)
return 1;
/* Invert condition? */
flag = false;
if (opcode == 0) {
flag = true;
opcode = getByte();
if (opcode == 0xFF)
return 0;
}
condition = true;
switch (opcode) {
case 1:{ /* ptrA parent is */
condition = (getItem1Ptr()->parent == getNextItemID());
}
break;
case 2:{ /* ptrA parent is not */
condition = (getItem1Ptr()->parent != getNextItemID());
}
break;
case 5:{ /* parent is 1 */
condition = (getNextItemPtr()->parent == getItem1ID());
}
break;
case 6:{ /* parent isnot 1 */
condition = (getNextItemPtr()->parent != getItem1ID());
}
break;
case 7:{ /* parent is */
Item *item = getNextItemPtr();
condition = (item->parent == getNextItemID());
}
break;
case 11:{ /* is zero */
condition = (getNextVarContents() == 0);
}
break;
case 12:{ /* isnot zero */
condition = (getNextVarContents() != 0);
}
break;
case 13:{ /* equal */
uint tmp = getNextVarContents();
condition = (tmp == getVarOrWord());
}
break;
case 14:{ /* not equal */
uint tmp = getNextVarContents();
condition = (tmp != getVarOrWord());
}
break;
case 15:{ /* is greater */
uint tmp = getNextVarContents();
condition = (tmp > getVarOrWord());
}
break;
case 16:{ /* is less */
uint tmp = getNextVarContents();
condition = (tmp < getVarOrWord());
}
break;
case 17:{ /* is eq f */
uint tmp = getNextVarContents();
condition = (tmp == getNextVarContents());
}
break;
case 18:{ /* is not equal f */
uint tmp = getNextVarContents();
condition = (tmp != getNextVarContents());
}
break;
case 19:{ /* is greater f */
uint tmp = getNextVarContents();
condition = (tmp < getNextVarContents());
}
break;
case 20:{ /* is less f */
uint tmp = getNextVarContents();
condition = (tmp > getNextVarContents());
}
break;
case 23:{
condition = o_unk_23(getVarOrWord());
}
break;
case 25:{ /* has child of type 1 */
condition = hasChildOfType1(getNextItemPtr());
}
break;
case 26:{ /* has child of type 2 */
condition = hasChildOfType2(getNextItemPtr());
}
break;
case 27:{ /* item unk3 is */
Item *item = getNextItemPtr();
condition = ((uint) item->unk3 == getVarOrWord());
}
break;
case 28:{ /* item has prop */
Child2 *child = (Child2 *)findChildOfType(getNextItemPtr(), 2);
byte num = getVarOrByte();
condition = child != NULL && (child->avail_props & (1 << num)) != 0;
} break;
case 31:{ /* set no parent */
setItemParent(getNextItemPtr(), NULL);
}
break;
case 33:{ /* set item parent */
Item *item = getNextItemPtr();
setItemParent(item, getNextItemPtr());
}
break;
case 36:{ /* copy var */
uint value = getNextVarContents();
writeNextVarContents(value);
}
break;
case 41:{ /* zero var */
writeNextVarContents(0);
}
break;
case 42:{ /* set var */
uint var = getVarOrByte();
writeVariable(var, getVarOrWord());
}
break;
case 43:{ /* add */
uint var = getVarOrByte();
writeVariable(var, readVariable(var) + getVarOrWord());
}
break;
case 44:{ /* sub */
uint var = getVarOrByte();
writeVariable(var, readVariable(var) - getVarOrWord());
}
break;
case 45:{ /* add f */
uint var = getVarOrByte();
writeVariable(var, readVariable(var) + getNextVarContents());
}
break;
case 46:{ /* sub f */
uint var = getVarOrByte();
writeVariable(var, readVariable(var) - getNextVarContents());
}
break;
case 47:{ /* mul */
uint var = getVarOrByte();
writeVariable(var, readVariable(var) * getVarOrWord());
}
break;
case 48:{ /* div */
uint var = getVarOrByte();
int value = getVarOrWord();
if (value == 0)
error("Division by zero in div");
writeVariable(var, readVariable(var) / value);
}
break;
case 49:{ /* mul f */
uint var = getVarOrByte();
writeVariable(var, readVariable(var) * getNextVarContents());
}
break;
case 50:{ /* div f */
uint var = getVarOrByte();
int value = getNextVarContents();
if (value == 0)
error("Division by zero in div f");
writeVariable(var, readVariable(var) / value);
}
break;
case 51:{ /* mod */
uint var = getVarOrByte();
int value = getVarOrWord();
if (value == 0)
error("Division by zero in mod");
writeVariable(var, readVariable(var) % value);
}
break;
case 52:{ /* mod f */
uint var = getVarOrByte();
int value = getNextVarContents();
if (value == 0)
error("Division by zero in mod f");
writeVariable(var, readVariable(var) % value);
}
break;
case 53:{ /* random */
uint var = getVarOrByte();
uint value = (uint16)getVarOrWord();
// Disable random in simon1amiga for now
// Since copy protection screen is currently unreadable
if (_game == GAME_SIMON1AMIGA)
writeVariable(var, 4);
else
writeVariable(var, _rnd.getRandomNumber(value - 1));
}
break;
case 55:{ /* set itemA parent */
setItemParent(getItem1Ptr(), getNextItemPtr());
}
break;
case 56:{ /* set child2 fr bit */
Child2 *child = (Child2 *)findChildOfType(getNextItemPtr(), 2);
int value = getVarOrByte();
if (child != NULL && value >= 0x10)
child->avail_props |= 1 << value;
}
break;
case 57:{ /* clear child2 fr bit */
Child2 *child = (Child2 *)findChildOfType(getNextItemPtr(), 2);
int value = getVarOrByte();
if (child != NULL && value >= 0x10)
child->avail_props &= ~(1 << value);
}
break;
case 58:{ /* make siblings */
Item *item = getNextItemPtr();
setItemParent(item, derefItem(getNextItemPtr()->parent));
}
break;
case 59:{ /* item inc unk3 */
Item *item = getNextItemPtr();
if (item->unk3 <= 30000)
setItemUnk3(item, item->unk3 + 1);
}
break;
case 60:{ /* item dec unk3 */
Item *item = getNextItemPtr();
if (item->unk3 >= 0)
setItemUnk3(item, item->unk3 - 1);
}
break;
case 61:{ /* item set unk3 */
Item *item = getNextItemPtr();
int value = getVarOrWord();
if (value < 0)
value = 0;
if (value > 30000)
value = 30000;
setItemUnk3(item, value);
}
break;
case 62:{ /* show int */
showMessageFormat("%d", getNextVarContents());
}
break;
case 63:{ /* show string nl */
showMessageFormat("%s\n", getStringPtrByID(getNextStringID()));
}
break;
case 64:{ /* show string */
showMessageFormat("%s", getStringPtrByID(getNextStringID()));
}
break;
case 65:{ /* add hit area */
int id = getVarOrWord();
int x = getVarOrWord();
int y = getVarOrWord();
int w = getVarOrWord();
int h = getVarOrWord();
int number = getVarOrByte();
if (number < 20)
addNewHitArea(id, x, y, w, h, (number << 8) + 129, 0xD0, _dummyItem2);
}
break;
case 66:{ /* set item name */
uint var = getVarOrByte();
uint string_id = getNextStringID();
if (var < 20)
_stringIdArray2[var] = string_id;
}
break;
case 67:{ /* set item description */
uint var = getVarOrByte();
uint string_id = getNextStringID();
if (_game & GF_TALKIE) {
uint speech_id = getNextWord();
if (var < 20) {
_stringIdArray3[var] = string_id;
_speechIdArray4[var] = speech_id;
}
} else {
if (var < 20) {
_stringIdArray3[var] = string_id;
}
}
}
break;
case 68:{ /* exit interpreter */
shutdown();
}
break;
case 69:{ /* return 1 */
return 1;
}
case 70:{ /* show string from array */
const char *str = (const char *)getStringPtrByID(_stringIdArray3[getVarOrByte()]);
if (_game & GF_SIMON2) {
writeVariable(51, strlen(str) / 53 * 8 + 8);
}
showMessageFormat("%s\n", str);
}
break;
case 71:{ /* start subroutine */
Subroutine *sub = getSubroutineByID(getVarOrWord());
if (sub != NULL)
startSubroutine(sub);
}
break;
case 76:{ /* add timeout */
uint timeout = getVarOrWord();
addTimeEvent(timeout, getVarOrWord());
}
break;
case 77:{ /* has item minus 1 */
condition = _subjectItem != NULL;
}
break;
case 78:{ /* has item minus 3 */
condition = _objectItem != NULL;
}
break;
case 79:{ /* childstruct fr2 is */
Child2 *child = (Child2 *)findChildOfType(getNextItemPtr(), 2);
uint string_id = getNextStringID();
condition = (child != NULL) && child->string_id == string_id;
}
break;
case 80:{ /* item equal */
condition = getNextItemPtr() == getNextItemPtr();
}
break;
case 82:{ /* dummy opcode */
getVarOrByte();
}
break;
case 83:{ /* restart subroutine */
if (_game & GF_SIMON2)
o_83_helper();
return -10;
}
case 87:{ /* dummy opcode */
getNextStringID();
}
break;
case 88:{ /* or_lockWord */
_lockWord |= 0x10;
}
break;
case 89:{ /* and lock word */
_lockWord &= ~0x10;
}
break;
case 90:{ /* set minusitem to parent */
Item *item = derefItem(getNextItemPtr()->parent);
switch (getVarOrByte()) {
case 0:
_objectItem = item;
break;
case 1:
_subjectItem = item;
break;
default:
error("set minusitem to parent, invalid subcode");
}
}
break;
case 91:{ /* set minusitem to sibling */
Item *item = derefItem(getNextItemPtr()->sibling);
switch (getVarOrByte()) {
case 0:
_objectItem = item;
break;
case 1:
_subjectItem = item;
break;
default:
error("set minusitem to sibling, invalid subcode");
}
}
break;
case 92:{ /* set minusitem to child */
Item *item = derefItem(getNextItemPtr()->child);
switch (getVarOrByte()) {
case 0:
_objectItem = item;
break;
case 1:
_subjectItem = item;
break;
default:
error("set minusitem to child, invalid subcode");
}
}
break;
case 96:{
uint val = getVarOrWord();
o_set_video_mode(getVarOrByte(), val);
}
break;
case 97:{ /* load vga */
ensureVgaResLoadedC(getVarOrWord());
}
break;
case 98:{ /* start vga */
uint vga_res, vgaSpriteId, paletteMode, x, y, base_color;
if (_game & GF_SIMON2) {
vga_res = getVarOrWord();
vgaSpriteId = getVarOrWord();
} else {
vgaSpriteId = getVarOrWord();
vga_res = vgaSpriteId / 100;
}
paletteMode = getVarOrByte();
x = getVarOrWord();
y = getVarOrWord();
base_color = getVarOrWord();
loadSprite(paletteMode, vga_res, vgaSpriteId, x, y, base_color);
}
break;
case 99:{ /* kill sprite */
if (_game & GF_SIMON1) {
o_kill_sprite_simon1(getVarOrWord());
} else {
uint a = getVarOrWord();
uint b = getVarOrWord();
o_kill_sprite_simon2(a, b);
}
}
break;
case 100:{ /* vga reset */
o_vga_reset();
}
break;
case 101:{
uint a = getVarOrByte();
uint b = getVarOrWord();
uint c = getVarOrWord();
uint d = getVarOrWord();
uint e = getVarOrWord();
uint f = getVarOrWord();
uint g = getVarOrWord();
o_unk26_helper(a, b, c, d, e, f, g, 0);
}
break;
case 102:{
fcs_unk_2(getVarOrByte() & 7);
}
break;
case 103:{
o_unk_103();
}
break;
case 104:{
fcs_delete(getVarOrByte() & 7);
}
break;
case 107:{ /* add item hitarea */
uint flags = 0;
uint id = getVarOrWord();
uint params = id / 1000;
uint x, y, w, h, unk3;
Item *item;
id = id % 1000;
if (params & 1)
flags |= 8;
if (params & 2)
flags |= 4;
if (params & 4)
flags |= 0x80;
if (params & 8)
flags |= 1;
if (params & 16)
flags |= 0x10;
x = getVarOrWord();
y = getVarOrWord();
w = getVarOrWord();
h = getVarOrWord();
item = getNextItemPtrStrange();
unk3 = getVarOrWord();
if (x >= 1000) {
unk3 += 0x4000;
x -= 1000;
}
addNewHitArea(id, x, y, w, h, flags, unk3, item);
}
break;
case 108:{ /* delete hitarea */
delete_hitarea(getVarOrWord());
}
break;
case 109:{ /* clear hitarea bit 0x40 */
clear_hitarea_bit_0x40(getVarOrWord());
}
break;
case 110:{ /* set hitarea bit 0x40 */
set_hitarea_bit_0x40(getVarOrWord());
}
break;
case 111:{ /* set hitarea xy */
uint hitarea_id = getVarOrWord();
uint x = getVarOrWord();
uint y = getVarOrWord();
set_hitarea_x_y(hitarea_id, x, y);
}
break;
case 114:{
Item *item = getNextItemPtr();
uint fcs_index = getVarOrByte();
lock();
fcs_unk_proc_1(fcs_index, item, 0, 0);
unlock();
}
break;
case 115:{ /* item has flag */
Item *item = getNextItemPtr();
condition = (item->unk4 & (1 << getVarOrByte())) != 0;
}
break;
case 116:{ /* item set flag */
Item *item = getNextItemPtr();
item->unk4 |= (1 << getVarOrByte());
}
break;
case 117:{ /* item clear flag */
Item *item = getNextItemPtr();
item->unk4 &= ~(1 << getVarOrByte());
}
break;
case 119:{ /* wait vga */
uint var = getVarOrWord();
_scriptVar2 = (var == 200);
if (var != 200 || !_skipVgaWait)
o_wait_for_vga(var);
_skipVgaWait = false;
}
break;
case 120:{
o_unk_120(getVarOrWord());
}
break;
case 121:{ /* set vga item */
uint slot = getVarOrByte();
_vcItemArray[slot] = getNextItemPtr();
}
break;
case 125:{ /* item is sibling with item 1 */
Item *item = getNextItemPtr();
condition = (getItem1Ptr()->parent == item->parent);
}
break;
case 126:{
Item *item = getNextItemPtr();
uint fcs_index = getVarOrByte();
uint a = 1 << getVarOrByte();
lock();
fcs_unk_proc_1(fcs_index, item, 1, a);
unlock();
}
break;
case 127:{ /* deals with music */
o_play_music_resource();
}
break;
case 128:{ /* dummy instruction */
getVarOrWord();
}
break;
case 129:{ /* dummy instruction */
getVarOrWord();
condition = true;
}
break;
case 130:{ /* set script cond */
uint var = getVarOrByte();
getNextWord();
if (var == 1)
_scriptCondB = getNextWord();
else
_scriptCondC = getNextWord();
}
break;
case 132:{ /* save game */
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
o_save_game();
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
}
break;
case 133:{ /* load game */
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
o_load_game();
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
}
break;
case 134:{ /* dummy opcode? */
midi.stop();
_lastMusicPlayed = -1;
}
break;
case 135:{ /* quit if user presses y */
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
o_quit_if_user_presses_y();
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
}
break;
case 136:{ /* set var to item unk3 */
Item *item = getNextItemPtr();
writeNextVarContents(item->unk3);
}
break;
case 137:{
o_unk_137(getVarOrByte());
}
break;
case 138:{ /* vga pointer op 4 */
o_unk_138();
}
break;
case 139:{ /* set parent special */
Item *item = getNextItemPtr();
_noParentNotify = true;
setItemParent(item, getNextItemPtr());
_noParentNotify = false;
}
break;
case 140:{ /* del te and add one */
killAllTimers();
addTimeEvent(3, 0xA0);
}
break;
case 141:{ /* set m1 or m3 */
uint which = getVarOrByte();
Item *item = getNextItemPtr();
if (which == 1) {
_subjectItem = item;
} else {
_objectItem = item;
}
}
break;
case 142:{ /* is hitarea 0x40 clear */
condition = is_hitarea_0x40_clear(getVarOrWord());
}
break;
case 143:{ /* start item sub */
Child1 *child = (Child1 *)findChildOfType(getNextItemPtr(), 1);
if (child != NULL) {
Subroutine *sub = getSubroutineByID(child->subroutine_id);
if (sub)
startSubroutine(sub);
}
}
break;
case 151:{ /* set array6 to item */
uint var = getVarOrByte();
Item *item = getNextItemPtr();
_itemArray6[var] = item;
}
break;
case 152:{ /* set m1 or m3 to array6 */
Item *item = _itemArray6[getVarOrByte()];
uint var = getVarOrByte();
if (var == 1) {
_subjectItem = item;
} else {
_objectItem = item;
}
}
break;
case 153:{ /* set bit */
uint bit = getVarOrByte();
_bitArray[bit >> 4] |= 1 << (bit & 15);
break;
}
case 154:{ /* clear bit */
uint bit = getVarOrByte();
_bitArray[bit >> 4] &= ~(1 << (bit & 15));
break;
}
case 155:{ /* is bit clear? */
uint bit = getVarOrByte();
condition = (_bitArray[bit >> 4] & (1 << (bit & 15))) == 0;
}
break;
case 156:{ /* is bit set? */
uint bit = getVarOrByte();
condition = (_bitArray[bit >> 4] & (1 << (bit & 15))) != 0;
}
break;
case 157:{ /* get item int prop */
Item *item = getNextItemPtr();
Child2 *child = (Child2 *)findChildOfType(item, 2);
uint prop = getVarOrByte();
if (child != NULL && child->avail_props & (1 << prop) && prop < 16) {
uint offs = getOffsetOfChild2Param(child, 1 << prop);
writeNextVarContents(child->array[offs]);
} else {
writeNextVarContents(0);
}
}
break;
case 158:{ /* set item prop */
Item *item = getNextItemPtr();
Child2 *child = (Child2 *)findChildOfType(item, 2);
uint prop = getVarOrByte();
int value = getVarOrWord();
if (child != NULL && child->avail_props & (1 << prop) && prop < 16) {
uint offs = getOffsetOfChild2Param(child, 1 << prop);
child->array[offs] = value;
}
}
break;
case 160:{
o_unk_160(getVarOrByte());
}
break;
case 161:{ /* setup text */
TextLocation *tl = getTextLocation(getVarOrByte());
tl->x = getVarOrWord();
tl->y = getVarOrByte();
tl->width = getVarOrWord();
}
break;
case 162:{ /* print string */
o_print_str();
}
break;
case 163:{ /* play sound */
o_play_sound(getVarOrWord());
}
break;
case 164:{
_showPreposition = true;
o_setup_cond_c();
_showPreposition = false;
}
break;
case 165:{ /* item unk1 unk2 is */
Item *item = getNextItemPtr();
int16 a = getNextWord(), b = getNextWord();
condition = (item->unk2 == a && item->unk1 == b);
} break;
case 166:{ /* set bit2 */
uint bit = getVarOrByte();
_bitArray[(bit >> 4) + 16] |= 1 << (bit & 15);
}
break;
case 167:{ /* clear bit2 */
uint bit = getVarOrByte();
_bitArray[(bit >> 4) + 16] &= ~(1 << (bit & 15));
}
break;
case 168:{ /* is bit2 clear */
uint bit = getVarOrByte();
condition = (_bitArray[(bit >> 4) + 16] & (1 << (bit & 15))) == 0;
}
break;
case 169:{ /* is bit2 set */
uint bit = getVarOrByte();
condition = (_bitArray[(bit >> 4) + 16] & (1 << (bit & 15))) != 0;
}
break;
case 175:{ /* vga pointer op 1 */
o_unk_175();
}
break;
case 176:{ /* vga pointer op 2 */
o_unk_176();
}
break;
case 177:{ /* inventory descriptions */
o_inventory_descriptions();
}
break;
case 178:{ /* path find */
uint a = getVarOrWord();
uint b = getVarOrWord();
uint c = getVarOrByte();
uint d = getVarOrByte();
o_pathfind(a, b, c, d);
}
break;
case 179:{ /* conversation responses */
uint vgaSpriteId = getVarOrByte(); /* and room descriptions */
uint color = getVarOrByte();
uint string_id = getVarOrByte();
uint speech_id = 0;
const char *string_ptr = (const char *)getStringPtrByID(_stringIdArray3[string_id]);
TextLocation *tl = getTextLocation(vgaSpriteId);
if (_game & GF_TALKIE)
speech_id = _speechIdArray4[string_id];
if (_speech && speech_id != 0)
talk_with_speech(speech_id, vgaSpriteId);
if (string_ptr != NULL && _subtitles)
talk_with_text(vgaSpriteId, color, string_ptr, tl->x, tl->y, tl->width);
}
break;
case 180:{ /* force unlock */
o_force_unlock();
}
break;
case 181:{ /* force lock */
o_force_lock();
if (_game & GF_SIMON2) {
fcs_unk_2(1);
showMessageFormat("\xC");
}
}
break;
case 182:{ /* read vgares 328 */
if (_game & GF_SIMON2)
goto invalid_opcode;
o_read_vgares_328();
}
break;
case 183:{ /* read vgares 23 */
if (_game & GF_SIMON2)
goto invalid_opcode;
o_read_vgares_23();
}
break;
case 184:{ /* clear vgapointer entry */
o_clear_vgapointer_entry(getVarOrWord());
}
break;
case 185:{ /* midi sfx file number */
if (_game & GF_SIMON2)
goto invalid_opcode;
_soundFileId = getVarOrWord();
if (_game == GAME_SIMON1CD32) {
char buf[10];
sprintf(buf, "%d%s", _soundFileId, "Effects");
_sound->readSfxFile(buf);
sprintf(buf, "%d%s", _soundFileId, "simon");
_sound->readVoiceFile(buf);
}
}
break;
case 186:{ /* vga pointer op 3 */
o_unk_186();
}
break;
case 187:{ /* fade to black */
if (_game & GF_SIMON2)
goto invalid_opcode;
o_fade_to_black();
}
break;
case 188: /* string2 is */
if (_game & GF_SIMON1)
goto invalid_opcode;
{
uint i = getVarOrByte();
uint str = getNextStringID();
condition = (str < 20 && _stringIdArray2[i] == str);
}
break;
case 189:{ /* clear_op189_flag */
if (_game & GF_SIMON1)
goto invalid_opcode;
_op189Flags = 0;
}
break;
case 190:{
uint i;
if (_game & GF_SIMON1)
goto invalid_opcode;
i = getVarOrByte();
if (!(_op189Flags & (1 << i)))
o_190_helper(i);
}
break;
default:
invalid_opcode:;
error("Invalid opcode '%d'", opcode);
}
} while (condition != flag);
return 0;
}
int SimonEngine::startSubroutine(Subroutine *sub) {
int result = -1;
SubroutineLine *sl;
const byte *old_code_ptr;
if (_startMainScript)
dumpSubroutine(sub);
old_code_ptr = _codePtr;
if (++_recursionDepth > 40)
error("Recursion error");
sl = (SubroutineLine *)((byte *)sub + sub->first);
while ((byte *)sl != (byte *)sub) {
if (checkIfToRunSubroutineLine(sl, sub)) {
result = 0;
_codePtr = (byte *)sl;
if (sub->id)
_codePtr += 2;
else
_codePtr += 8;
if (_continousMainScript)
fprintf(_dumpFile, "; %d\n", sub->id);
result = runScript();
if (result != 0) {
/* result -10 means restart subroutine */
if (result == -10) {
delay(0); /* maybe leave control to the VGA */
sl = (SubroutineLine *)((byte *)sub + sub->first);
continue;
}
break;
}
}
sl = (SubroutineLine *)((byte *)sub + sl->next);
}
_codePtr = old_code_ptr;
_recursionDepth--;
return result;
}
int SimonEngine::startSubroutineEx(Subroutine *sub) {
return startSubroutine(sub);
}
bool SimonEngine::checkIfToRunSubroutineLine(SubroutineLine *sl, Subroutine *sub) {
if (sub->id)
return true;
if (sl->cond_a != -1 && sl->cond_a != _scriptCondA &&
(sl->cond_a != -2 || _scriptCondA != -1))
return false;
if (sl->cond_b != -1 && sl->cond_b != _scriptCondB &&
(sl->cond_b != -2 || _scriptCondB != -1))
return false;
if (sl->cond_c != -1 && sl->cond_c != _scriptCondC &&
(sl->cond_c != -2 || _scriptCondC != -1))
return false;
return true;
}
void SimonEngine::o_83_helper() {
if (_exitCutscene) {
if (vc_get_bit(9)) {
startSubroutine170();
}
} else {
processSpecialKeys();
}
}
void SimonEngine::o_190_helper(uint i) {
_exitCutscene = false;
while (!(_op189Flags & (1 << i))) {
if (_exitCutscene) {
if (vc_get_bit(9)) {
startSubroutine170();
break;
}
} else {
processSpecialKeys();
}
delay(10);
}
}
bool SimonEngine::o_unk_23(uint a) {
if (a == 0)
return 0;
if (a == 100)
return 1;
a += _scriptUnk1;
if (a <= 0) {
_scriptUnk1 = 0;
return 0;
}
if ((uint)_rnd.getRandomNumber(99) < a) {
if (_scriptUnk1 <= 0)
_scriptUnk1 -= 5;
else
_scriptUnk1 = 0;
return 1;
}
if (_scriptUnk1 >= 0)
_scriptUnk1 += 5;
else
_scriptUnk1 = 0;
return 0;
}
void SimonEngine::o_inventory_descriptions() {
uint vgaSpriteId = getVarOrByte();
uint color = getVarOrByte();
const char *string_ptr = NULL;
TextLocation *tl = NULL;
char buf[256];
Child2 *child = (Child2 *)findChildOfType(getNextItemPtr(), 2);
if (child != NULL && child->avail_props & 1) {
string_ptr = (const char *)getStringPtrByID(child->array[0]);
tl = getTextLocation(vgaSpriteId);
}
if ((_game & GF_SIMON2) && (_game & GF_TALKIE)) {
if (child != NULL && child->avail_props & 0x200) {
uint speech_id = child->array[getOffsetOfChild2Param(child, 0x200)];
if (child->avail_props & 0x100) {
uint speech_id_offs = child->array[getOffsetOfChild2Param(child, 0x100)];
if (speech_id == 116)
speech_id = speech_id_offs + 115;
if (speech_id == 92)
speech_id = speech_id_offs + 98;
if (speech_id == 99)
speech_id = 9;
if (speech_id == 97) {
switch (speech_id_offs) {
case 12:
speech_id = 109;
break;
case 14:
speech_id = 108;
break;
case 18:
speech_id = 107;
break;
case 20:
speech_id = 106;
break;
case 22:
speech_id = 105;
break;
case 28:
speech_id = 104;
break;
case 90:
speech_id = 103;
break;
case 92:
speech_id = 102;
break;
case 100:
speech_id = 51;
break;
default:
error("o_177: invalid case %d", speech_id_offs);
}
}
}
if (_speech)
talk_with_speech(speech_id, vgaSpriteId);
}
} else if (_game & GF_TALKIE) {
if (child != NULL && child->avail_props & 0x200) {
uint offs = getOffsetOfChild2Param(child, 0x200);
talk_with_speech(child->array[offs], vgaSpriteId);
} else if (child != NULL && child->avail_props & 0x100) {
uint offs = getOffsetOfChild2Param(child, 0x100);
talk_with_speech(child->array[offs] + 3550, vgaSpriteId);
}
}
if (child != NULL && (child->avail_props & 1) && _subtitles) {
if (child->avail_props & 0x100) {
sprintf(buf, "%d%s", child->array[getOffsetOfChild2Param(child, 0x100)], string_ptr);
string_ptr = buf;
}
if (string_ptr != NULL)
talk_with_text(vgaSpriteId, color, string_ptr, tl->x, tl->y, tl->width);
}
}
void SimonEngine::o_quit_if_user_presses_y() {
for (;;) {
delay(1);
#ifdef _WIN32_WCE
if (isSmartphone()) {
if (_keyPressed) {
if (_keyPressed == 13)
shutdown();
else
break;
}
}
#endif
if (_keyPressed == 'f' && _language == 20) // Hebrew
shutdown();
if (_keyPressed == 's' && _language == 5) // Spanish
shutdown();
if (_keyPressed == 's' && _language == 3) // Italian
shutdown();
if (_keyPressed == 'o' && _language == 2) // French
shutdown();
if (_keyPressed == 'j' && _language == 1) // German
shutdown();
if (_keyPressed == 'y' && _language == 0) // English
shutdown();
if (_keyPressed == 'n')
goto get_out;
}
get_out:;
}
void SimonEngine::o_unk_137(uint fcs_index) {
FillOrCopyStruct *fcs;
fcs = _fcsPtrArray3[fcs_index & 7];
if (fcs->fcs_data == NULL)
return;
fcs_unk_proc_1(fcs_index, fcs->fcs_data->item_ptr, fcs->fcs_data->unk1, fcs->fcs_data->unk2);
}
void SimonEngine::o_unk_138() {
_vgaBufStart = _vgaBufFreeStart;
_vgaFileBufOrg = _vgaBufFreeStart;
}
void SimonEngine::o_unk_186() {
_vgaBufFreeStart = _vgaFileBufOrg2;
_vgaBufStart = _vgaFileBufOrg2;
_vgaFileBufOrg = _vgaFileBufOrg2;
}
void SimonEngine::o_unk_175() {
_vgaBufStart = _vgaBufFreeStart;
}
void SimonEngine::o_unk_176() {
_vgaBufFreeStart = _vgaFileBufOrg;
_vgaBufStart = _vgaFileBufOrg;
}
int SimonEngine::o_unk_132_helper(bool *b, char *buf) {
HitArea *ha;
*b = true;
if (!_saveLoadFlag) {
strange_jump:;
_saveLoadFlag = false;
savegame_dialog(buf);
}
start_over:;
_keyPressed = 0;
if (_game == GAME_SIMON1CD32)
goto start_over_3;
start_over_2:;
_lastHitArea = _lastHitArea3 = 0;
do {
if (_keyPressed != 0) {
if (_saveLoadFlag) {
*b = false;
return _keyPressed;
}
goto start_over;
}
delay(100);
} while (_lastHitArea3 == 0);
ha = _lastHitArea;
if (ha == NULL || ha->id < 205)
goto start_over_2;
if (ha->id == 205)
return ha->id;
if (ha->id == 206) {
if (_saveLoadRowCurPos == 1)
goto start_over_2;
if (_saveLoadRowCurPos < 7)
_saveLoadRowCurPos = 1;
else
_saveLoadRowCurPos -= 6;
goto strange_jump;
}
if (ha->id == 207) {
if (!_saveDialogFlag)
goto start_over_2;
_saveLoadRowCurPos += 6;
if (_saveLoadRowCurPos >= _numSaveGameRows)
_saveLoadRowCurPos = _numSaveGameRows;
goto strange_jump;
}
if (ha->id >= 214)
goto start_over_2;
return ha->id - 208;
//FIXME Hack to allow load and save file selection in simon1cd32
// Uses the follow keys for moving around
// 1 - 6 to select slot to load/save
// Up Arrow to move up slots
// Down Arrow to move down slots
// X to exit
start_over_3:;
if (_saveLoadFlag) {
*b = false;
delay(1);
return _keyPressed;
}
if (_keyPressed == 17) {
if (_saveLoadRowCurPos == 1)
goto start_over_3;
if (_saveLoadRowCurPos < 7)
_saveLoadRowCurPos = 1;
else
_saveLoadRowCurPos -= 6;
goto strange_jump;
}
if (_keyPressed == 18) {
if (!_saveDialogFlag)
goto start_over_3;
_saveLoadRowCurPos += 6;
if (_saveLoadRowCurPos >= _numSaveGameRows)
_saveLoadRowCurPos = _numSaveGameRows;
goto strange_jump;
}
if (_keyPressed == 120)
return 205;
if (_keyPressed > 48 && _keyPressed < 55) {
return _keyPressed - 49;
}
delay(1);
goto start_over_3;
}
void SimonEngine::o_unk_132_helper_3() {
for (int i = 208; i != 208 + 6; i++)
set_hitarea_bit_0x40(i);
}
void SimonEngine::o_clear_character(FillOrCopyStruct *fcs, int x, byte b) {
byte old_text;
video_putchar(fcs, x, b);
old_text = fcs->text_color;
fcs->text_color = fcs->fill_color;
if (_language == 20) { //Hebrew
x = 128;
} else {
x += 120;
if (x != 128)
x = 129;
}
video_putchar(fcs, x);
fcs->text_color = old_text;
video_putchar(fcs, 8);
}
void SimonEngine::o_play_music_resource() {
int music = getVarOrWord();
int track = getVarOrWord();
// Jamieson630:
// This appears to be a "load or play music" command.
// The music resource is specified, and optionally
// a track as well. Normally we see two calls being
// made, one to load the resource and another to
// actually start a track (so the resource is
// effectively preloaded so there's no latency when
// starting playback).
if (_game & GF_SIMON2) {
int loop = getVarOrByte();
midi.setLoop (loop != 0);
if (_lastMusicPlayed != music)
_nextMusicToPlay = music;
else
midi.startTrack (track);
} else {
if (music != _lastMusicPlayed) {
_lastMusicPlayed = music;
loadMusic (music);
midi.startTrack (track);
}
}
}
void SimonEngine::o_unk_120(uint a) {
uint16 id = TO_BE_16(a);
if (_game & GF_SIMON2) {
_lockWord |= 0x8000;
_vcPtr = (byte *)&id;
vc15_wakeup_id();
_lockWord &= ~0x8000;
} else {
_lockWord |= 0x4000;
_vcPtr = (byte *)&id;
vc15_wakeup_id();
_lockWord &= ~0x4000;
}
}
void SimonEngine::o_play_sound(uint sound_id) {
if (_game == GAME_SIMON1DOS)
playSting(sound_id);
else
_sound->playEffects(sound_id);
}
void SimonEngine::o_unk_160(uint a) {
fcs_setTextColor(_fcsPtrArray3[_fcsUnk1], a);
}
void SimonEngine::o_unk_103() {
lock();
fcs_unk1(_fcsUnk1);
showMessageFormat("\x0C");
unlock();
}
void SimonEngine::o_kill_sprite_simon1(uint a) {
uint16 b = TO_BE_16(a);
_lockWord |= 0x4000;
_vcPtr = (byte *)&b;
vc60_killSprite();
_lockWord &= ~0x4000;
}
void SimonEngine::o_kill_sprite_simon2(uint a, uint b) {
uint16 items[2];
items[0] = TO_BE_16(a);
items[1] = TO_BE_16(b);
_lockWord |= 0x8000;
_vcPtr = (byte *)&items;
vc60_killSprite();
_lockWord &= ~0x8000;
}
/* OK */
void SimonEngine::o_unk26_helper(uint a, uint b, uint c, uint d, uint e, uint f, uint g, uint h) {
a &= 7;
if (_fcsPtrArray3[a])
fcs_delete(a);
_fcsPtrArray3[a] = fcs_alloc(b, c, d, e, f, g, h);
if (a == _fcsUnk1) {
_fcsPtr1 = _fcsPtrArray3[a];
showmessage_helper_3(_fcsPtr1->textLength, _fcsPtr1->textMaxLength);
}
}
} // End of namespace Simon
|