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
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
|
/* 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.
*
*/
/** \file
* Future Wars script interpreter file
*/
#include "common/endian.h"
#include "common/textconsole.h"
#include "cine/cine.h"
#include "cine/bg_list.h"
#include "cine/object.h"
#include "cine/sound.h"
#include "cine/various.h"
#include "cine/script.h"
#include "cine/console.h"
namespace Cine {
uint16 compareVars(int16 a, int16 b);
const Opcode *FWScript::_opcodeTable = 0;
unsigned int FWScript::_numOpcodes = 0;
void FWScript::setupTable() {
static const Opcode opcodeTable[] = {
/* 00 */
{ &FWScript::o1_modifyObjectParam, "bbw" },
{ &FWScript::o1_getObjectParam, "bbb" },
{ &FWScript::o1_addObjectParam, "bbw" },
{ &FWScript::o1_subObjectParam, "bbw" },
/* 04 */
{ &FWScript::o1_mulObjectParam, "bbw" },
{ &FWScript::o1_divObjectParam, "bbw" },
{ &FWScript::o1_compareObjectParam, "bbw" },
{ &FWScript::o1_setupObject, "bwwww" },
/* 08 */
{ &FWScript::o1_checkCollision, "bwwww" },
{ &FWScript::o1_loadVar, "bc" },
{ &FWScript::o1_addVar, "bc" },
{ &FWScript::o1_subVar, "bc" },
/* 0C */
{ &FWScript::o1_mulVar, "bc" },
{ &FWScript::o1_divVar, "bc" },
{ &FWScript::o1_compareVar, "bc" },
{ &FWScript::o1_modifyObjectParam2, "bbb" },
/* 10 */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ &FWScript::o1_loadMask0, "b" },
/* 14 */
{ &FWScript::o1_unloadMask0, "b" },
{ &FWScript::o1_addToBgList, "b" },
{ &FWScript::o1_loadMask1, "b" },
{ &FWScript::o1_unloadMask1, "b" },
/* 18 */
{ &FWScript::o1_loadMask4, "b" },
{ &FWScript::o1_unloadMask4, "b" },
{ &FWScript::o1_addSpriteFilledToBgList, "b" },
{ &FWScript::o1_op1B, "" },
/* 1C */
{ 0, 0 },
{ &FWScript::o1_label, "l" },
{ &FWScript::o1_goto, "b" },
{ &FWScript::o1_gotoIfSup, "b" },
/* 20 */
{ &FWScript::o1_gotoIfSupEqu, "b" },
{ &FWScript::o1_gotoIfInf, "b" },
{ &FWScript::o1_gotoIfInfEqu, "b" },
{ &FWScript::o1_gotoIfEqu, "b" },
/* 24 */
{ &FWScript::o1_gotoIfDiff, "b" },
{ &FWScript::o1_removeLabel, "b" },
{ &FWScript::o1_loop, "bb" },
{ 0, 0 },
/* 28 */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
/* 2C */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
/* 30 */
{ 0, 0 },
{ &FWScript::o1_startGlobalScript, "b" },
{ &FWScript::o1_endGlobalScript, "b" },
{ 0, 0 },
/* 34 */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
/* 38 */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ &FWScript::o1_loadAnim, "s" },
/* 3C */
{ &FWScript::o1_loadBg, "s" },
{ &FWScript::o1_loadCt, "s" },
{ 0, 0 },
{ &FWScript::o1_loadPart, "s" },
/* 40 */
{ &FWScript::o1_closePart, "" },
{ &FWScript::o1_loadNewPrcName, "bs" },
{ &FWScript::o1_requestCheckPendingDataLoad, "" },
{ 0, 0 },
/* 44 */
{ 0, 0 },
{ &FWScript::o1_blitAndFade, "" },
{ &FWScript::o1_fadeToBlack, "" },
{ &FWScript::o1_transformPaletteRange, "bbwww" },
/* 48 */
{ 0, 0 },
{ &FWScript::o1_setDefaultMenuBgColor, "b" },
{ &FWScript::o1_palRotate, "bbb" },
{ 0, 0 },
/* 4C */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ &FWScript::o1_break, "" },
/* 50 */
{ &FWScript::o1_endScript, "x" },
{ &FWScript::o1_message, "bwwww" },
{ &FWScript::o1_loadGlobalVar, "bc" },
{ &FWScript::o1_compareGlobalVar, "bc" },
/* 54 */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
/* 58 */
{ 0, 0 },
{ &FWScript::o1_declareFunctionName, "s" },
{ &FWScript::o1_freePartRange, "bb" },
{ &FWScript::o1_unloadAllMasks, "" },
/* 5C */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
/* 60 */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ &FWScript::o1_setScreenDimensions, "wwww" },
/* 64 */
{ &FWScript::o1_displayBackground, "" },
{ &FWScript::o1_initializeZoneData, "" },
{ &FWScript::o1_setZoneDataEntry, "bw" },
{ &FWScript::o1_getZoneDataEntry, "bb" },
/* 68 */
{ &FWScript::o1_setPlayerCommandPosY, "b" },
{ &FWScript::o1_allowPlayerInput, "" },
{ &FWScript::o1_disallowPlayerInput, "" },
{ &FWScript::o1_changeDataDisk, "b" },
/* 6C */
{ 0, 0 },
{ &FWScript::o1_loadMusic, "s" },
{ &FWScript::o1_playMusic, "" },
{ &FWScript::o1_fadeOutMusic, "" },
/* 70 */
{ &FWScript::o1_stopSample, "" },
{ &FWScript::o1_op71, "bw" },
{ &FWScript::o1_op72, "wbw" },
{ &FWScript::o1_op73, "wbw" },
/* 74 */
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ &FWScript::o1_playSample, "bbwbww" },
/* 78 */
{ &FWScript::o1_playSample, "bbwbww" },
{ &FWScript::o1_disableSystemMenu, "b" },
{ &FWScript::o1_loadMask5, "b" },
{ &FWScript::o1_unloadMask5, "b" }
};
FWScript::_opcodeTable = (const Opcode *)opcodeTable;
FWScript::_numOpcodes = ARRAYSIZE(opcodeTable);
}
FWScriptInfo *scriptInfo; ///< Script factory
/**
* @todo replace with script subsystem
*/
void setupOpcodes() {
static FWScriptInfo fw;
static OSScriptInfo os;
if (g_cine->getGameType() == Cine::GType_FW) {
FWScript::setupTable();
scriptInfo = &fw;
} else {
OSScript::setupTable();
scriptInfo = &os;
}
}
/**
* Allocate empty array
* @param len Size of array
*
* Explicit to prevent var=0 instead of var[i]=0 typos.
*/
ScriptVars::ScriptVars(unsigned int len) : _size(len), _vars(new int16[len]) {
assert(_vars);
reset();
}
/**
* Allocate array and read contents from savefile
* @param fHandle Savefile open for reading
* @param len Size of array
*/
ScriptVars::ScriptVars(Common::SeekableReadStream &fHandle, unsigned int len)
: _size(len), _vars(new int16[len]) {
assert(_vars);
load(fHandle);
}
void ScriptVars::reinit(unsigned int len) {
delete[] _vars;
_size = len;
_vars = new int16[len];
reset();
}
/**
* Copy constructor
*/
ScriptVars::ScriptVars(const ScriptVars &src) : _size(src._size), _vars(new int16[_size]) {
assert(_vars);
memcpy(_vars, src._vars, _size * sizeof(int16));
}
/**
* Destructor
*/
ScriptVars::~ScriptVars() {
delete[] _vars;
}
/**
* Assignment operator
*/
ScriptVars &ScriptVars::operator=(const ScriptVars &src) {
ScriptVars tmp(src);
int16 *tmpvars = _vars;
_vars = tmp._vars;
tmp._vars = tmpvars;
_size = src._size;
return *this;
}
/**
* Direct array item access.
* @param idx Item index
* @return Reference to item
*/
int16 &ScriptVars::operator[](unsigned int idx) {
debug(6, "assert(%d < %d)", idx, _size);
assert(idx < _size);
return _vars[idx];
}
/**
* Direct read-only array item access.
* @param idx Item index
* @return Copy of item
*/
int16 ScriptVars::operator[](unsigned int idx) const {
debug(6, "assert(%d < %d)", idx, _size);
assert(idx < _size);
return _vars[idx];
}
/**
* Savefile writer
* @param fHandle Savefile open for writing
*/
void ScriptVars::save(Common::OutSaveFile &fHandle) const {
save(fHandle, _size);
}
/**
* Savefile writer with data length limit
* @param fHandle Savefile open for writing
* @param len Length of data to be written (len <= _size)
*/
void ScriptVars::save(Common::OutSaveFile &fHandle, unsigned int len) const {
debug(6, "assert(%d <= %d)", len, _size);
assert(len <= _size);
for (unsigned int i = 0; i < len; i++) {
fHandle.writeUint16BE(_vars[i]);
}
}
/**
* Restore array from savefile
* @param fHandle Savefile open for reading
*/
void ScriptVars::load(Common::SeekableReadStream &fHandle) {
load(fHandle, _size);
}
/**
* Restore part of array from savefile
* @param fHandle Savefile open for reading
* @param len Length of data to be read
*/
void ScriptVars::load(Common::SeekableReadStream &fHandle, unsigned int len) {
debug(6, "assert(%d <= %d)", len, _size);
assert(len <= _size);
for (unsigned int i = 0; i < len; i++) {
_vars[i] = fHandle.readUint16BE();
}
}
/**
* Reset all values to 0
*/
void ScriptVars::reset() {
memset( _vars, 0, _size * sizeof(int16));
}
/**
* Constructor for partial loading
* @param s Size of bytecode which will be added later
*
* This constructor _MUST_ be followed by setdata() method call before the
* instance can be used. It leaves the instance in partially invalid state.
*/
RawScript::RawScript(uint16 s) : _size(s), _data(NULL),
_labels(SCRIPT_STACK_SIZE) { }
/**
* Complete constructor
* @param data Script bytecode
* @param s Bytecode length
*/
RawScript::RawScript(const FWScriptInfo &info, const byte *data, uint16 s) :
_size(s), _data(NULL), _labels(SCRIPT_STACK_SIZE) {
setData(info, data);
}
/**
* Copy constructor
*/
RawScript::RawScript(const RawScript &src) : _size(src._size),
_data(new byte[_size+1]), _labels(src._labels) {
assert(_data);
memcpy(_data, src._data, _size+1);
}
/**
* Destructor
*/
RawScript::~RawScript() {
delete[] _data;
}
/**
* Assignment operator
*/
RawScript &RawScript::operator=(const RawScript &src) {
assert(src._data);
byte *tmp = new byte[src._size+1];
assert(tmp);
_labels = src._labels;
_size = src._size;
delete[] _data;
_data = tmp;
memcpy(_data, src._data, _size);
_data[_size] = 0;
return *this;
}
/**
* Get the next label in bytecode
* @param info Script info instance
* @param offset Starting offset
* @return Index of the next label in bytecode or _size on end of bytecode
*
* computeScriptStackSub replacement
*/
int RawScript::getNextLabel(const FWScriptInfo &info, int offset) const {
assert(_data);
int pos = offset;
assert(pos >= 0);
while (pos < _size) {
uint8 opcode = _data[pos++];
const char *ptr = info.opcodeInfo(opcode);
if (!ptr) {
continue;
}
for (; *ptr; ++ptr) {
switch (*ptr) {
case 'b': // byte
pos++;
break;
case 'w': // word
pos += 2;
break;
case 'c': { // byte != 0 ? byte : word
uint8 test = _data[pos];
pos++;
if (test) {
pos++;
} else {
pos += 2;
}
}
break;
case 'l': // label
return pos;
case 's': // string
while (_data[pos++] != 0)
;
break;
case 'x': // exit script
return -pos-1;
}
}
}
return _size;
}
/**
* Calculate initial script labels
* @param info Script info instance
*
* computeScriptStack replacement
*/
void RawScript::computeLabels(const FWScriptInfo &info) {
assert(_data);
int pos = 0;
int i;
// reset labels
for (i = 0; i < SCRIPT_STACK_SIZE; i++) {
_labels[i] = -1;
}
// parse bytecode
while ((pos = getNextLabel(info, pos)) >= 0) {
i = _data[pos];
_labels[i] = ++pos;
}
}
/**
* find the next label from current position
* @param info Script info instance
* @param index Label index to look for
* @param offset Current position in script
* @return Position of next instruction following the label
*
* computeScriptStackFromScript replacement
*/
uint16 RawScript::getLabel(const FWScriptInfo &info, byte index, uint16 offset)
const {
assert(_data);
int pos = offset;
while ((pos = getNextLabel(info, pos)) >= 0) {
if (_data[pos++] == index) {
return pos;
}
}
return -pos - 1;
}
/**
* Copy bytecode and calculate labels
* @param data Bytecode to copy, must be _size long
*/
void RawScript::setData(const FWScriptInfo &info, const byte *data) {
assert(!_data); // this function should be called only once per instance
_data = new byte[_size+1];
assert(data && _data);
memcpy(_data, data, _size * sizeof(byte));
_data[_size] = 0;
computeLabels(info);
}
/**
* Initial script labels
* @return Precalculated script labels
*/
const ScriptVars &RawScript::labels() const {
assert(_data);
return _labels;
}
/**
* One byte of bytecode
* @param pos Index in bytecode
* @return Byte from bytecode
*/
byte RawScript::getByte(unsigned int pos) const {
assert(_data && pos < _size);
return _data[pos];
}
/**
* One word of bytecode
* @param pos Index of the first byte in bytecode
* @return Word of bytecode
*/
uint16 RawScript::getWord(unsigned int pos) const {
assert(_data && pos+1 < _size);
return READ_BE_UINT16(_data + pos);
}
/**
* String in bytecode
* @param pos Index of the first char in string
* @return Pointer to part of bytecode
*/
const char *RawScript::getString(unsigned int pos) const {
assert(_data && pos < _size);
return (const char*)(_data+pos);
}
/**
* Constructor for partial loading
* @param size Size of bytecode which will be added later
* @param p1 First object script parameter
* @param p2 Second object script parameter
* @param p3 Third object script parameter
*
* This constructor _MUST_ be followed by setdata() method call before the
* instance can be used. It leaves the instance in partially invalid state.
*/
RawObjectScript::RawObjectScript(uint16 s, uint16 p1, uint16 p2, uint16 p3)
: RawScript(s), _runCount(0), _param1(p1), _param2(p2), _param3(p3)
{ }
/**
* Complete constructor
* @param data Script bytecode
* @param s Bytecode length
* @param p1 First object script parameter
* @param p2 Second object script parameter
* @param p3 Third object script parameter
*/
RawObjectScript::RawObjectScript(const FWScriptInfo &info, const byte *data,
uint16 s, uint16 p1, uint16 p2, uint16 p3) : RawScript(info, data, s),
_runCount(0), _param1(p1), _param2(p2), _param3(p3) { }
/**
* Contructor for global scripts
* @param script Script bytecode reference
* @param idx Script bytecode index
*/
FWScript::FWScript(const RawScript &script, int16 idx) : _script(script),
_pos(0), _line(0), _compare(0), _index(idx),
_labels(script.labels()), _localVars(LOCAL_VARS_SIZE),
_globalVars(g_cine->_globalVars), _info(new FWScriptInfo) { }
/**
* Copy constructor
*/
FWScript::FWScript(const FWScript &src) : _script(src._script), _pos(src._pos),
_line(src._line), _compare(src._compare), _index(src._index),
_labels(src._labels), _localVars(src._localVars),
_globalVars(src._globalVars), _info(new FWScriptInfo) { }
/**
* Contructor for global scripts in derived classes
* @param script Script bytecode reference
* @param idx Script bytecode index
*/
FWScript::FWScript(const RawScript &script, int16 idx, FWScriptInfo *info) :
_script(script), _pos(0), _line(0), _compare(0), _index(idx),
_labels(script.labels()), _localVars(LOCAL_VARS_SIZE),
_globalVars(g_cine->_globalVars), _info(info) { }
/**
* Constructor for object scripts in derived classes
* @param script Script bytecode reference
* @param idx Script bytecode index
*/
FWScript::FWScript(RawObjectScript &script, int16 idx, FWScriptInfo *info) :
_script(script), _pos(0), _line(0), _compare(0), _index(idx),
_labels(script.labels()), _localVars(LOCAL_VARS_SIZE),
_globalVars(g_cine->_globalVars), _info(info) {
_localVars[0] = script.run();
}
/**
* Copy constructor for derived classes
*/
FWScript::FWScript(const FWScript &src, FWScriptInfo *info) :
_script(src._script), _pos(src._pos), _line(src._line),
_compare(src._compare), _index(src._index), _labels(src._labels),
_localVars(src._localVars), _globalVars(src._globalVars), _info(info) { }
FWScript::~FWScript() {
delete _info;
}
/**
* Read next byte from bytecode
* @return Byte from bytecode
*/
byte FWScript::getNextByte() {
byte val = _script.getByte(_pos);
_pos++;
return val;
}
/**
* Read next word from bytecode
* @return Word from bytecode
*/
uint16 FWScript::getNextWord() {
uint16 val = _script.getWord(_pos);
_pos += 2;
return val;
}
/**
* Read next string from bytecode
* @return Pointer to string
*/
const char *FWScript::getNextString() {
const char *val = _script.getString(_pos);
_pos += strlen(val) + 1;
return val;
}
/**
* Restore script state from savefile
* @param labels Restored script labels
* @param local Restored local script variables
* @param compare Restored last comparison result
* @param pos Restored script position
*/
void FWScript::load(const ScriptVars &labels, const ScriptVars &local, uint16 compare, uint16 pos) {
assert(pos < _script._size);
_labels = labels;
_localVars = local;
_compare = compare;
_pos = _line = pos;
}
/**
* Execute script
* @return <0 on script termination, >0 on script pause
*
* executeScript replacement.
* Instruction handler must return 0 if the script should continue or
* nonzero with the same meaning as return value of this function
*/
int FWScript::execute() {
int ret = 0;
while (!ret) {
_line = _pos;
byte opcode = getNextByte();
OpFunc handler = _info->opcodeHandler(opcode);
if (handler) {
ret = (this->*handler)();
}
}
return ret;
}
/**
* Save script to savefile
* @param fHandle Savefile handle
*/
void FWScript::save(Common::OutSaveFile &fHandle) const {
_labels.save(fHandle);
_localVars.save(fHandle);
fHandle.writeUint16BE(_compare);
fHandle.writeUint16BE(_pos);
// data order sucks...
fHandle.writeUint16BE(_index);
}
/**
* Get opcode info string
* @param opcode Opcode to look for in opcode table
*/
const char *FWScriptInfo::opcodeInfo(byte opcode) const {
if (opcode == 0 || opcode > FWScript::_numOpcodes) {
return NULL;
}
if (!FWScript::_opcodeTable[opcode - 1].args) {
warning("Undefined opcode 0x%02X in FWScriptInfo::opcodeInfo", opcode - 1);
return NULL;
}
return FWScript::_opcodeTable[opcode - 1].args;
}
/**
* Get opcode handler pointer
* @param opcode Opcode to look for in opcode table
*/
OpFunc FWScriptInfo::opcodeHandler(byte opcode) const {
if (opcode == 0 || opcode > FWScript::_numOpcodes) {
return NULL;
}
if (!FWScript::_opcodeTable[opcode - 1].proc) {
warning("Undefined opcode 0x%02X in FWScriptInfo::opcodeHandler", opcode - 1);
return NULL;
}
return FWScript::_opcodeTable[opcode - 1].proc;
}
/**
* Create new FWScript instance
* @param script Script bytecode
* @param index Bytecode index
*/
FWScript *FWScriptInfo::create(const RawScript &script, int16 index) const {
return new FWScript(script, index);
}
/**
* Create new FWScript instance
* @param script Object script bytecode
* @param index Bytecode index
*/
FWScript *FWScriptInfo::create(const RawObjectScript &script, int16 index) const {
return new FWScript(script, index);
}
/**
* Load saved FWScript instance
* @param script Script bytecode
* @param index Bytecode index
* @param local Local variables
* @param labels Script labels
* @param compare Last compare result
* @param pos Position in script
*/
FWScript *FWScriptInfo::create(const RawScript &script, int16 index, const ScriptVars &labels, const ScriptVars &local, uint16 compare, uint16 pos) const {
FWScript *tmp = new FWScript(script, index);
assert(tmp);
tmp->load(labels, local, compare, pos);
return tmp;
}
/**
* Load saved FWScript instance
* @param script Object script bytecode
* @param index Bytecode index
* @param local Local variables
* @param labels Script labels
* @param compare Last compare result
* @param pos Position in script
*/
FWScript *FWScriptInfo::create(const RawObjectScript &script, int16 index, const ScriptVars &labels, const ScriptVars &local, uint16 compare, uint16 pos) const {
FWScript *tmp = new FWScript(script, index);
assert(tmp);
tmp->load(labels, local, compare, pos);
return tmp;
}
// ------------------------------------------------------------------------
// FUTURE WARS opcodes
// ------------------------------------------------------------------------
int FWScript::o1_modifyObjectParam() {
byte objIdx = getNextByte();
byte paramIdx = getNextByte();
int16 newValue = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: modifyObjectParam(objIdx:%d,paramIdx:%d,newValue:%d)", _line, objIdx, paramIdx, newValue);
modifyObjectParam(objIdx, paramIdx, newValue);
return 0;
}
int FWScript::o1_getObjectParam() {
byte objIdx = getNextByte();
byte paramIdx = getNextByte();
byte newValue = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: getObjectParam(objIdx:%d,paramIdx:%d,var:%d)", _line, objIdx, paramIdx, newValue);
_localVars[newValue] = getObjectParam(objIdx, paramIdx);
return 0;
}
int FWScript::o1_addObjectParam() {
byte objIdx = getNextByte();
byte paramIdx = getNextByte();
int16 newValue = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: addObjectParam(objIdx:%d,paramIdx:%d,newValue:%d)", _line, objIdx, paramIdx, newValue);
addObjectParam(objIdx, paramIdx, newValue);
return 0;
}
int FWScript::o1_subObjectParam() {
byte objIdx = getNextByte();
byte paramIdx = getNextByte();
int16 newValue = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: subObjectParam(objIdx:%d,paramIdx:%d,newValue:%d)", _line, objIdx, paramIdx, newValue);
subObjectParam(objIdx, paramIdx, newValue);
return 0;
}
int FWScript::o1_mulObjectParam() {
byte objIdx = getNextByte();
byte paramIdx = getNextByte();
int16 newValue = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: mulObjectParam(objIdx:%d,paramIdx:%d,newValue:%d)", _line, objIdx, paramIdx, newValue);
// FIXME? In PC versions of Future Wars and Operation Stealth the multiplication is done unsigned.
// (16b x 16b -> 32b, taking only 16 LSBs). The question is, does it really matter?
int16 currentValue = getObjectParam(objIdx, paramIdx);
modifyObjectParam(objIdx, paramIdx, currentValue * newValue);
return 0;
}
int FWScript::o1_divObjectParam() {
byte objIdx = getNextByte();
byte paramIdx = getNextByte();
int16 newValue = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: divObjectParam(objIdx:%d,paramIdx:%d,newValue:%d)", _line, objIdx, paramIdx, newValue);
// In PC versions of Future Wars and Operation Stealth the division is done signed.
// Dividend is first sign extended from 16 bits to 32 bits and then divided by the
// 16 bit divider using signed division. Only 16 LSBs of the quotient are saved.
int16 currentValue = getObjectParam(objIdx, paramIdx);
modifyObjectParam(objIdx, paramIdx, currentValue / newValue);
return 0;
}
int FWScript::o1_compareObjectParam() {
byte objIdx = getNextByte();
byte param1 = getNextByte();
int16 param2 = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: compareObjectParam(objIdx:%d,type:%d,value:%d)", _line, objIdx, param1, param2);
_compare = compareObjectParam(objIdx, param1, param2);
return 0;
}
int FWScript::o1_setupObject() {
byte objIdx = getNextByte();
int16 param1 = getNextWord();
int16 param2 = getNextWord();
int16 param3 = getNextWord();
int16 param4 = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: setupObject(objIdx:%d,%d,%d,%d,%d)", _line, objIdx, param1, param2, param3, param4);
setupObject(objIdx, param1, param2, param3, param4);
return 0;
}
int FWScript::o1_checkCollision() {
byte objIdx = getNextByte();
int16 param1 = getNextWord();
int16 param2 = getNextWord();
int16 param3 = getNextWord();
int16 param4 = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: checkCollision(objIdx:%d,%d,%d,%d,%d)", _line, objIdx, param1, param2, param3, param4);
_compare = checkCollision(objIdx, param1, param2, param3, param4);
return 0;
}
int FWScript::o1_loadVar() {
byte varIdx = getNextByte();
byte varType = getNextByte();
if (varType) {
byte dataIdx = getNextByte();
int16 var;
switch (varType) {
case 1:
debugC(5, kCineDebugScript, "Line: %d: var[%d] = var[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] = _localVars[dataIdx];
break;
case 2:
debugC(5, kCineDebugScript, "Line: %d: var[%d] = globalVars[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] = _globalVars[dataIdx];
break;
case 3:
debugC(5, kCineDebugScript, "Line: %d: var[%d] = mouseX", _line, varIdx);
getMouseData(mouseUpdateStatus, &dummyU16, (uint16 *)&var, &dummyU16);
_localVars[varIdx] = var;
break;
case 4:
debugC(5, kCineDebugScript, "Line: %d: var[%d] = mouseY", _line, varIdx);
getMouseData(mouseUpdateStatus, &dummyU16, &dummyU16, (uint16 *)&var);
_localVars[varIdx] = var;
break;
case 5:
debugC(5, kCineDebugScript, "Line: %d: var[%d] = rand mod %d", _line, varIdx, dataIdx);
_localVars[varIdx] = g_cine->_rnd.getRandomNumber(dataIdx - 1);
break;
case 8:
debugC(5, kCineDebugScript, "Line: %d: var[%d] = file[%d].packedSize", _line, varIdx, dataIdx);
_localVars[varIdx] = g_cine->_partBuffer[dataIdx].packedSize;
break;
case 9:
debugC(5, kCineDebugScript, "Line: %d: var[%d] = file[%d].unpackedSize", _line, varIdx, dataIdx);
_localVars[varIdx] = g_cine->_partBuffer[dataIdx].unpackedSize;
break;
default:
error("executeScript: o1_loadVar: Unknown variable type %d", varType);
}
} else {
int16 value = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: var[%d] = %d", _line, varIdx, value);
_localVars[varIdx] = value;
}
return 0;
}
int FWScript::o1_addVar() {
byte varIdx = getNextByte();
byte varType = getNextByte();
if (varType) {
byte dataIdx = getNextByte();
if (varType == 1) {
debugC(5, kCineDebugScript, "Line: %d: var[%d] += var[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] += _localVars[dataIdx];
} else if (varType == 2) {
debugC(5, kCineDebugScript, "Line: %d: var[%d] += globalVar[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] += _globalVars[dataIdx];
}
} else {
int16 value = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: var[%d] += %d", _line, varIdx, value);
_localVars[varIdx] += value;
}
return 0;
}
int FWScript::o1_subVar() {
byte varIdx = getNextByte();
byte varType = getNextByte();
if (varType) {
byte dataIdx = getNextByte();
if (varType == 1) {
debugC(5, kCineDebugScript, "Line: %d: var[%d] -= var[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] -= _localVars[dataIdx];
} else if (varType == 2) {
debugC(5, kCineDebugScript, "Line: %d: var[%d] -= globalVar[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] -= _globalVars[dataIdx];
}
} else {
int16 value = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: var[%d] -= %d", _line, varIdx, value);
_localVars[varIdx] -= value;
}
return 0;
}
int FWScript::o1_mulVar() {
byte varIdx = getNextByte();
byte varType = getNextByte();
if (varType) {
byte dataIdx = getNextByte();
if (varType == 1) {
debugC(5, kCineDebugScript, "Line: %d: var[%d] *= var[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] *= _localVars[dataIdx];
} else if (varType == 2) {
debugC(5, kCineDebugScript, "Line: %d: var[%d] *= globalVar[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] *= _globalVars[dataIdx];
}
} else {
int16 value = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: var[%d] *= %d", _line, varIdx, value);
_localVars[varIdx] *= value;
}
return 0;
}
int FWScript::o1_divVar() {
byte varIdx = getNextByte();
byte varType = getNextByte();
if (varType) {
byte dataIdx = getNextByte();
if (varType == 1) {
debugC(5, kCineDebugScript, "Line: %d: var[%d] /= var[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] /= _localVars[dataIdx];
} else if (varType == 2) {
debugC(5, kCineDebugScript, "Line: %d: var[%d] /= globalVar[%d]", _line, varIdx, dataIdx);
_localVars[varIdx] /= _globalVars[dataIdx];
}
} else {
int16 value = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: var[%d] /= %d", _line, varIdx, value);
_localVars[varIdx] /= value;
}
return 0;
}
int FWScript::o1_compareVar() {
// WORKAROUND: A workaround for a script bug in script file CODE2.PRC
// in at least some of the Amiga and Atari ST versions of Future Wars.
// Fixes bug #2016647 (FW: crash with italian amiga version). A local
// variable 251 is compared against value 0 although it's quite apparent
// from the context in the script that instead global variable 251 should
// be compared against value 0. So looks like someone made a typo when
// making the scripts. Therefore we change that particular comparison
// from using the local variable 251 to using the global variable 251.
if (g_cine->getGameType() == Cine::GType_FW && scumm_stricmp(currentPrcName, "CODE2.PRC") == 0 &&
(g_cine->getPlatform() == Common::kPlatformAmiga || g_cine->getPlatform() == Common::kPlatformAtariST) &&
_script.getByte(_pos) == 251 && _script.getByte(_pos + 1) == 0 && _script.getWord(_pos + 2) == 0) {
return o1_compareGlobalVar();
}
byte varIdx = getNextByte();
byte varType = getNextByte();
if (varType) {
byte dataIdx = getNextByte();
if (varType == 1) {
debugC(5, kCineDebugScript, "Line: %d: compare var[%d] and var[%d]", _line, varIdx, dataIdx);
_compare = compareVars(_localVars[varIdx], _localVars[dataIdx]);
} else if (varType == 2) {
debugC(5, kCineDebugScript, "Line: %d: compare var[%d] and globalVar[%d]", _line, varIdx, dataIdx);
_compare = compareVars(_localVars[varIdx], _globalVars[dataIdx]);
}
} else {
int16 value = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: compare var[%d] and %d", _line, varIdx, value);
_compare = compareVars(_localVars[varIdx], value);
}
return 0;
}
int FWScript::o1_modifyObjectParam2() {
byte objIdx = getNextByte();
byte paramIdx = getNextByte();
byte newValue = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: modifyObjectParam2(objIdx:%d,paramIdx:%d,var[%d])", _line, objIdx, paramIdx, newValue);
modifyObjectParam(objIdx, paramIdx, _localVars[newValue]);
return 0;
}
int FWScript::o1_loadMask0() {
// OP_loadV7Element
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: addSpriteOverlay(%d)", _line, param);
addOverlay(param, 0);
return 0;
}
int FWScript::o1_unloadMask0() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: removeSpriteOverlay(%d)", _line, param);
removeOverlay(param, 0);
return 0;
}
int FWScript::o1_addToBgList() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: addToBGList(%d)", _line, param);
addToBGList(param);
return 0;
}
int FWScript::o1_loadMask1() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: addOverlay1(%d)", _line, param);
addOverlay(param, 1);
return 0;
}
int FWScript::o1_unloadMask1() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: removeOverlay1(%d)", _line, param);
removeOverlay(param, 1);
return 0;
}
int FWScript::o1_loadMask4() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: addOverlayType4(%d)", _line, param);
addOverlay(param, 4);
return 0;
}
int FWScript::o1_unloadMask4() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: removeSpriteOverlay4(%d)", _line, param);
removeOverlay(param, 4);
return 0;
}
int FWScript::o1_addSpriteFilledToBgList() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: op1A(%d) -> TODO !", _line, param);
addSpriteFilledToBGList(param);
return 0;
}
int FWScript::o1_op1B() {
debugC(5, kCineDebugScript, "Line: %d: freeBgIncrustList", _line);
g_cine->_bgIncrustList.clear();
return 0;
}
int FWScript::o1_label() {
byte labelIdx = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: label(%d)", _line, labelIdx);
_labels[labelIdx] = _pos;
return 0;
}
int FWScript::o1_goto() {
byte labelIdx = getNextByte();
assert(_labels[labelIdx] != -1);
debugC(5, kCineDebugScript, "Line: %d: goto label(%d)", _line, labelIdx);
_pos = _labels[labelIdx];
return 0;
}
int FWScript::o1_gotoIfSup() {
byte labelIdx = getNextByte();
if (_compare == kCmpGT) {
assert(_labels[labelIdx] != -1);
debugC(5, kCineDebugScript, "Line: %d: if(>) goto %d (true)", _line, labelIdx);
_pos = _labels[labelIdx];
} else {
debugC(5, kCineDebugScript, "Line: %d: if(>) goto %d (false)", _line, labelIdx);
}
return 0;
}
int FWScript::o1_gotoIfSupEqu() {
byte labelIdx = getNextByte();
if (_compare & (kCmpGT | kCmpEQ)) {
assert(_labels[labelIdx] != -1);
debugC(5, kCineDebugScript, "Line: %d: if(>=) goto %d (true)", _line, labelIdx);
_pos = _labels[labelIdx];
} else {
debugC(5, kCineDebugScript, "Line: %d: if(>=) goto %d (false)", _line, labelIdx);
}
return 0;
}
int FWScript::o1_gotoIfInf() {
byte labelIdx = getNextByte();
if (_compare == kCmpLT) {
assert(_labels[labelIdx] != -1);
debugC(5, kCineDebugScript, "Line: %d: if(<) goto %d (true)", _line, labelIdx);
_pos = _labels[labelIdx];
} else {
debugC(5, kCineDebugScript, "Line: %d: if(<) goto %d (false)", _line, labelIdx);
}
return 0;
}
int FWScript::o1_gotoIfInfEqu() {
byte labelIdx = getNextByte();
if (_compare & (kCmpLT | kCmpEQ)) {
assert(_labels[labelIdx] != -1);
debugC(5, kCineDebugScript, "Line: %d: if(<=) goto %d (true)", _line, labelIdx);
_pos = _labels[labelIdx];
} else {
debugC(5, kCineDebugScript, "Line: %d: if(<=) goto %d (false)", _line, labelIdx);
}
return 0;
}
int FWScript::o1_gotoIfEqu() {
byte labelIdx = getNextByte();
if (_compare == kCmpEQ) {
assert(_labels[labelIdx] != -1);
debugC(5, kCineDebugScript, "Line: %d: if(==) goto %d (true)", _line, labelIdx);
_pos = _labels[labelIdx];
} else {
debugC(5, kCineDebugScript, "Line: %d: if(==) goto %d (false)", _line, labelIdx);
}
return 0;
}
int FWScript::o1_gotoIfDiff() {
byte labelIdx = getNextByte();
if (_compare != kCmpEQ) {
assert(_labels[labelIdx] != -1);
debugC(5, kCineDebugScript, "Line: %d: if(!=) goto %d (true)", _line, labelIdx);
_pos = _labels[labelIdx];
} else {
debugC(5, kCineDebugScript, "Line: %d: if(!=) goto %d (false)", _line, labelIdx);
}
return 0;
}
int FWScript::o1_removeLabel() {
byte labelIdx = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: removeLabel(%d)", _line, labelIdx);
_labels[labelIdx] = -1;
return 0;
}
int FWScript::o1_loop() {
byte varIdx = getNextByte();
byte labelIdx = getNextByte();
_localVars[varIdx]--;
if (_localVars[varIdx] >= 0) {
assert(_labels[labelIdx] != -1);
debugC(5, kCineDebugScript, "Line: %d: loop(var[%d]) goto %d (continue)", _line, varIdx, labelIdx);
_pos = _labels[labelIdx];
} else {
debugC(5, kCineDebugScript, "Line: %d: loop(var[%d]) goto %d (stop)", _line, varIdx, labelIdx);
}
return 0;
}
int FWScript::o1_startGlobalScript() {
// OP_startScript
byte param = getNextByte();
assert(param < NUM_MAX_SCRIPT);
debugC(5, kCineDebugScript, "Line: %d: startScript(%d)", _line, param);
// Cheat for Scene 6 Guards Labyrinth Arcade Game to disable John's Death (to aid playtesting)
if (g_cine->getGameType() == Cine::GType_OS && labyrinthCheat && scumm_stricmp(currentPrcName, "LABY.PRC") == 0 && param == 46) {
warning("LABY.PRC startScript(46) Disabled. CHEAT!");
return 0;
}
// Cheat for Scene 8 Rats Labyrinth Arcade Game to disable John's Death (to aid playtesting)
if (g_cine->getGameType() == Cine::GType_OS && labyrinthCheat && scumm_stricmp(currentPrcName, "EGOU.PRC") == 0 && param == 46) {
warning("EGOU.PRC startScript(46) Disabled. CHEAT!");
return 0;
}
addScriptToGlobalScripts(param);
return 0;
}
int FWScript::o1_endGlobalScript() {
byte scriptIdx = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: stopGlobalScript(%d)", _line, scriptIdx);
ScriptList::iterator it = g_cine->_globalScripts.begin();
for (; it != g_cine->_globalScripts.end(); ++it) {
if ((*it)->_index == scriptIdx) {
(*it)->_index = -1;
}
}
return 0;
}
int FWScript::o1_loadAnim() {
// OP_loadResource
const char *param = getNextString();
debugC(5, kCineDebugScript, "Line: %d: loadResource(\"%s\")", _line, param);
loadResource(param);
return 0;
}
int FWScript::o1_loadBg() {
const char *param = getNextString();
debugC(5, kCineDebugScript, "Line: %d: loadBg(\"%s\")", _line, param);
loadBg(param);
g_cine->_bgIncrustList.clear();
bgVar0 = 0;
return 0;
}
/** Load collision table data */
int FWScript::o1_loadCt() {
const char *param = getNextString();
debugC(5, kCineDebugScript, "Line: %d: loadCt(\"%s\")", _line, param);
loadCtFW(param);
return 0;
}
int FWScript::o1_loadPart() {
const char *param = getNextString();
debugC(5, kCineDebugScript, "Line: %d: loadPart(\"%s\")", _line, param);
loadPart(param);
return 0;
}
int FWScript::o1_closePart() {
debugC(5, kCineDebugScript, "Line: %d: closePart", _line);
closePart();
return 0;
}
int FWScript::o1_loadNewPrcName() {
// OP_loadData
byte param1 = getNextByte();
const char *param2 = getNextString();
assert(param1 <= 3);
switch (param1) {
case 0:
debugC(5, kCineDebugScript, "Line: %d: loadPrc(\"%s\")", _line, param2);
strcpy(newPrcName, param2);
break;
case 1:
debugC(5, kCineDebugScript, "Line: %d: loadRel(\"%s\")", _line, param2);
strcpy(newRelName, param2);
break;
case 2:
debugC(5, kCineDebugScript, "Line: %d: loadObject(\"%s\")", _line, param2);
strcpy(newObjectName, param2);
break;
case 3:
debugC(5, kCineDebugScript, "Line: %d: loadMsg(\"%s\")", _line, param2);
strcpy(newMsgName, param2);
break;
}
return 0;
}
int FWScript::o1_requestCheckPendingDataLoad() {
debugC(5, kCineDebugScript, "Line: %d: request data load", _line);
checkForPendingDataLoadSwitch = 1;
return 0;
}
int FWScript::o1_blitAndFade() {
debugC(5, kCineDebugScript, "Line: %d: request fadein", _line);
// TODO: use real code
// fadeFromBlack();
renderer->reloadPalette();
return 0;
}
int FWScript::o1_fadeToBlack() {
debugC(5, kCineDebugScript, "Line: %d: request fadeout", _line);
renderer->fadeToBlack();
return 0;
}
int FWScript::o1_transformPaletteRange() {
byte startColor = getNextByte();
byte endColor = getNextByte();
int16 r = getNextWord();
int16 g = getNextWord();
int16 b = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: transformPaletteRange(from:%d,to:%d,r:%d,g:%d,b:%d)", _line, startColor, endColor, r, g, b);
renderer->transformPalette(startColor, endColor, r, g, b);
return 0;
}
/** Set the default background color used for message boxes. */
int FWScript::o1_setDefaultMenuBgColor() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: setDefaultMenuBgColor(%d)", _line, param);
renderer->_messageBg = param;
return 0;
}
int FWScript::o1_palRotate() {
byte a = getNextByte();
byte b = getNextByte();
byte c = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: palRotate(%d,%d,%d)", _line, a, b, c);
renderer->rotatePalette(a, b, c);
return 0;
}
/**
* Pause script.
* @todo Make sure it works
*/
int FWScript::o1_break() {
debugC(5, kCineDebugScript, "Line: %d: break", _line);
// WORKAROUND for bug #2669415 ("FW: half walking speed in a screen").
// The problem was that in Amiga/Atari ST versions of Future Wars the
// walking speed has halved in a forest scene where a monk's robe hangs
// on a tree branch (Up and to the left from the medieval castle's front).
//
// Initialization script for the scene is PART02.PRC's 26th script (011_INIT)
// and the background used in the scene is L11.PI1. The difference between
// the PC version and the Amiga/Atari ST version of the script is that the
// PC version calls scripts 37 and 36 for handling movement of the character
// when Amiga/Atari ST version calls scripts 22 and 21 for the same purpose
// (Scripts 37 and 22 handle vertical movement, 36 and 21 the horizontal).
//
// The called scripts only differ functionally so that all BREAK opcodes have been
// doubled in the Amiga/Atari ST versions (i.e. one BREAK has become two BREAKs)
// and in script 21 after LABEL_25 there's an extra opcode that isn't in script 36:
// SET globalvars[251], 0.
//
// As a BREAK opcode stops the execution of a script it causes a pause and
// with the BREAKs doubled the pause is twice as long in the Amiga/Atari ST versions.
// Thus the longer pause is eliminated by running only one BREAK when several
// are designated (i.e. ignoring a BREAK if there's another BREAK after it).
//
// TODO: Check whether the speed is halved in any other scenes in Amiga/Atari ST versions under ScummVM
// TODO: Check whether the speed is halved when running the original executable under an emulator
if (g_cine->getGameType() == Cine::GType_FW &&
(g_cine->getPlatform() == Common::kPlatformAmiga || g_cine->getPlatform() == Common::kPlatformAtariST) &&
_pos < _script._size && _script.getByte(_pos) == (0x4F + 1) && // Is the next opcode a BREAK too?
scumm_stricmp(currentPrcName, "PART02.PRC") == 0 &&
scumm_stricmp(renderer->getBgName(), "L11.PI1") == 0) {
return 0;
}
return 1;
}
/**
* Terminate script
* @todo Make sure it works
*/
int FWScript::o1_endScript() {
debugC(5, kCineDebugScript, "Line: %d: endScript", _line);
return -1;
}
int FWScript::o1_message() {
byte param1 = getNextByte();
uint16 param2 = getNextWord();
uint16 param3 = getNextWord();
uint16 param4 = getNextWord();
uint16 param5 = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: message(%d,%d,%d,%d,%d)", _line, param1, param2, param3, param4, param5);
addMessage(param1, param2, param3, param4, param5);
return 0;
}
int FWScript::o1_loadGlobalVar() {
byte varIdx = getNextByte();
byte varType = getNextByte();
if (varType) {
byte dataIdx = getNextByte();
if (varType == 1) {
debugC(5, kCineDebugScript, "Line: %d: globalVars[%d] = var[%d]", _line, varIdx, dataIdx);
_globalVars[varIdx] = _localVars[dataIdx];
} else {
debugC(5, kCineDebugScript, "Line: %d: globalVars[%d] = globalVars[%d]", _line, varIdx, dataIdx);
_globalVars[varIdx] = _globalVars[dataIdx];
}
} else {
uint16 value = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: globalVars[%d] = %d", _line, varIdx, value);
_globalVars[varIdx] = value;
}
return 0;
}
int FWScript::o1_compareGlobalVar() {
byte varIdx = getNextByte();
byte varType = getNextByte();
if (varType) {
byte value = getNextByte();
if (varType == 1) {
debugC(5, kCineDebugScript, "Line: %d: compare globalVars[%d] and var[%d]", _line, varIdx, value);
_compare = compareVars(_globalVars[varIdx], _localVars[value]);
} else {
debugC(5, kCineDebugScript, "Line: %d: compare globalVars[%d] and globalVars[%d]", _line, varIdx, value);
_compare = compareVars(_globalVars[varIdx], _globalVars[value]);
}
} else {
uint16 value = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: compare globalVars[%d] and %d", _line, varIdx, value);
// WORKAROUND for bug #2054882. Without this, the monks will always
// kill you as an impostor, even if you enter the monastery in disguise.
//
// TODO: Check whether this might be worked around in some other way
// like setting global variable 255 to 143 in Future Wars (This is
// supposedly what Future Wars checks for from time to time during
// gameplay to verify that copy protection was successfully passed).
if (varIdx == 255 && (g_cine->getGameType() == Cine::GType_FW)) {
_compare = kCmpEQ;
} else {
_compare = compareVars(_globalVars[varIdx], value);
}
}
return 0;
}
int FWScript::o1_declareFunctionName() {
const char *param = getNextString();
debugC(5, kCineDebugScript, "Line: %d: comment(%s)", _line, param);
return 0;
}
int FWScript::o1_freePartRange() {
byte startIdx = getNextByte();
byte numIdx = getNextByte();
assert(startIdx + numIdx <= NUM_MAX_ANIMDATA);
debugC(5, kCineDebugScript, "Line: %d: freePartRange(%d,%d)", _line, startIdx, numIdx);
freeAnimDataRange(startIdx, numIdx);
return 0;
}
int FWScript::o1_unloadAllMasks() {
debugC(5, kCineDebugScript, "Line: %d: unloadAllMasks()", _line);
g_cine->_overlayList.clear();
return 0;
}
/**
* @todo Implement this instruction
*/
int FWScript::o1_setScreenDimensions() {
uint16 a = getNextWord();
uint16 b = getNextWord();
uint16 c = getNextWord();
uint16 d = getNextWord();
warning("STUB: o1_setScreenDimensions(%x, %x, %x, %x)", a, b, c, d);
// setupScreenParam
return 0;
}
/**
* @todo Implement this instruction
*/
int FWScript::o1_displayBackground() {
warning("STUB: o1_displayBackground()");
return 0;
}
int FWScript::o1_initializeZoneData() {
debugC(5, kCineDebugScript, "Line: %d: initializeZoneData()", _line);
for (int i = 0; i < NUM_MAX_ZONE; i++) {
g_cine->_zoneData[i] = i;
}
return 0;
}
int FWScript::o1_setZoneDataEntry() {
byte zoneIdx = getNextByte();
uint16 var = getNextWord();
debugC(5, kCineDebugScript, "Line: %d: setZone[%d] = %d", _line, zoneIdx, var);
g_cine->_zoneData[zoneIdx] = var;
return 0;
}
int FWScript::o1_getZoneDataEntry() {
byte zoneIdx = getNextByte();
byte var = getNextByte();
_localVars[var] = g_cine->_zoneData[zoneIdx];
return 0;
}
/** Set the player command string's vertical position on-screen. */
int FWScript::o1_setPlayerCommandPosY() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: setPlayerCommandPosY(%d)", _line, param);
renderer->_cmdY = param;
return 0;
}
int FWScript::o1_allowPlayerInput() {
debugC(5, kCineDebugScript, "Line: %d: allowPlayerInput()", _line);
allowPlayerInput = 1;
return 0;
}
int FWScript::o1_disallowPlayerInput() {
debugC(5, kCineDebugScript, "Line: %d: dissallowPlayerInput()", _line);
allowPlayerInput = 0;
return 0;
}
int FWScript::o1_changeDataDisk() {
byte newDisk = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: changeDataDisk(%d)", _line, newDisk);
checkDataDisk(newDisk);
return 0;
}
int FWScript::o1_loadMusic() {
const char *param = getNextString();
debugC(5, kCineDebugScript, "Line: %d: loadMusic(%s)", _line, param);
g_sound->loadMusic(param);
strncpy(currentDatName, param, 30);
musicIsPlaying = 0;
return 0;
}
int FWScript::o1_playMusic() {
debugC(5, kCineDebugScript, "Line: %d: playMusic()", _line);
g_sound->playMusic();
musicIsPlaying = 1;
return 0;
}
int FWScript::o1_fadeOutMusic() {
debugC(5, kCineDebugScript, "Line: %d: fadeOutMusic()", _line);
g_sound->fadeOutMusic();
musicIsPlaying = 0;
return 0;
}
int FWScript::o1_stopSample() {
debugC(5, kCineDebugScript, "Line: %d: stopSample()", _line);
g_sound->stopMusic();
musicIsPlaying = 0;
return 0;
}
/**
* @todo Implement this instruction's Amiga part (PC part already done)
* In PC versions of Future Wars and Operation Stealth this instruction does nothing else but read the parameters.
*/
int FWScript::o1_op71() {
byte a = getNextByte();
uint16 b = getNextWord();
warning("STUB: o1_op71(%x, %x)", a, b);
return 0;
}
/**
* @todo Implement this instruction's Amiga part (PC part already done)
* In PC versions of Future Wars and Operation Stealth this instruction does nothing else but read the parameters.
*/
int FWScript::o1_op72() {
uint16 a = getNextWord();
byte b = getNextByte();
uint16 c = getNextWord();
warning("STUB: o1_op72(%x, %x, %x)", a, b, c);
return 0;
}
/**
* @todo Implement this instruction's Amiga part (PC part already done)
* In PC versions of Future Wars and Operation Stealth this instruction does nothing else but read the parameters.
*/
int FWScript::o1_op73() {
// I believe this opcode is identical to o1_op72(). In fact, Operation
// Stealth doesn't even have it. It uses o1_op72() instead.
uint16 a = getNextWord();
byte b = getNextByte();
uint16 c = getNextWord();
warning("STUB: o1_op73(%x, %x, %x)", a, b, c);
return 0;
}
int FWScript::o1_playSample() {
debugC(5, kCineDebugScript, "Line: %d: playSample()", _line);
byte anim = getNextByte();
byte channel = getNextByte();
uint16 freq = getNextWord();
byte repeat = getNextByte();
int16 volume = getNextWord();
uint16 size = getNextWord();
const byte *data = g_cine->_animDataTable[anim].data();
if (!data) {
return 0;
}
if (g_cine->getPlatform() == Common::kPlatformAmiga || g_cine->getPlatform() == Common::kPlatformAtariST) {
if (size == 0xFFFF) {
size = g_cine->_animDataTable[anim]._width * g_cine->_animDataTable[anim]._height;
}
if (channel < 10) { // || _currentOpcode == 0x78
int channel1, channel2;
if (channel == 0) {
channel1 = 0;
channel2 = 1;
} else {
channel1 = 2;
channel2 = 3;
}
g_sound->playSound(channel1, freq, data, size, -1, volume, 63, repeat);
g_sound->playSound(channel2, freq, data, size, 1, volume, 0, repeat);
} else {
channel -= 10;
if (volume > 63) {
volume = 63;
}
g_sound->playSound(channel, freq, data, size, 0, 0, volume, repeat);
}
} else {
if (volume > 63 || volume < 0) {
volume = 63;
}
if (channel >= 10) {
channel -= 10;
}
if (volume < 50) {
volume = 50;
}
if (g_cine->getGameType() == Cine::GType_OS && size == 0) {
return 0;
}
g_sound->stopMusic();
if (size == 0xFFFF) {
g_sound->playSound(channel, 0, data, 0, 0, 0, volume, 0);
} else {
g_sound->stopSound(channel);
}
}
return 0;
}
int FWScript::o1_disableSystemMenu() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: disableSystemMenu(%d)", _line, param);
disableSystemMenu = (param != 0);
return 0;
}
int FWScript::o1_loadMask5() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: addOverlay5(%d)", _line, param);
addOverlay(param, 5);
return 0;
}
int FWScript::o1_unloadMask5() {
byte param = getNextByte();
debugC(5, kCineDebugScript, "Line: %d: freeOverlay5(%d)", _line, param);
removeOverlay(param, 5);
return 0;
}
//-----------------------------------------------------------------------
void addScriptToGlobalScripts(uint16 idx) {
ScriptPtr tmp(scriptInfo->create(*g_cine->_scriptTable[idx], idx));
assert(tmp);
g_cine->_globalScripts.push_back(tmp);
}
int16 getZoneFromPosition(byte *page, int16 x, int16 y, int16 width) {
byte *ptr = page + (y * width) + x / 2;
byte zoneVar;
if (!(x % 2)) {
zoneVar = (*(ptr) >> 4) & 0xF;
} else {
zoneVar = (*(ptr)) & 0xF;
}
return zoneVar;
}
int16 getZoneFromPositionRaw(byte *page, int16 x, int16 y, int16 width) {
// WORKAROUND for bug #2848940 ("ScummVM crashes with Future wars"):
// Vertical positions outside the 320x200 screen (e.g. in range 200-232)
// are accessed after teleporting Lo'Ann to the future using the pendant
// and walking down the slope and out of the screen (This causes a crash
// at least on Mac OS X). The original PC version of Future Wars doesn't
// clip its coordinates in this function or in checkCollision-function
// according to reverse engineering but instead just happily reads outside
// the 320x200 buffer. Not really knowing how to properly fix this I simply
// hope that the area outside the 320x200 part is full of zero and not of
// some random values and thus I return zero here and hope nothing breaks.
if (g_cine->getGameType() == Cine::GType_FW && !Common::Rect(320, 200).contains(x, y)) {
return 0;
}
byte *ptr = page + (y * width) + x;
byte zoneVar;
zoneVar = (*(ptr)) & 0xF;
return zoneVar;
}
int16 checkCollision(int16 objIdx, int16 x, int16 y, int16 numZones, int16 zoneIdx) {
debugC(1, kCineDebugCollision, "checkCollision(objIdx: %d x: %d y:%d numZones:%d zoneIdx: %d)", objIdx, x, y, numZones, zoneIdx);
int16 lx = g_cine->_objectTable[objIdx].x + x;
int16 ly = g_cine->_objectTable[objIdx].y + y;
int16 idx;
int16 result = 0;
for (int16 i = 0; i < numZones; i++) {
// Don't try to read data in Operation Stealth if position isn't in 320x200 screen bounds.
if (g_cine->getGameType() == Cine::GType_OS) {
if ((lx + i) < 0 || (lx + i) > 319 || ly < 0 || ly > 199) {
continue;
}
}
idx = getZoneFromPositionRaw(collisionPage, lx + i, ly, 320);
assert(idx >= 0 && idx < NUM_MAX_ZONE);
// The zoneQuery table is updated here only in Operation Stealth
if (g_cine->getGameType() == Cine::GType_OS) {
if (g_cine->_zoneData[idx] < NUM_MAX_ZONE) {
g_cine->_zoneQuery[g_cine->_zoneData[idx]]++;
}
}
if (g_cine->_zoneData[idx] == zoneIdx) {
result = 1;
// Future Wars breaks out early on the first match, but
// Operation Stealth doesn't because it needs to update
// the zoneQuery table for the whole loop's period.
if (g_cine->getGameType() == Cine::GType_FW) {
break;
}
}
}
return result;
}
uint16 compareVars(int16 a, int16 b) {
uint16 flag = 0;
if (a == b) {
flag |= kCmpEQ;
} else if (a > b) {
flag |= kCmpGT;
} else if (a < b) {
flag |= kCmpLT;
}
return flag;
}
void executeObjectScripts() {
ScriptList::iterator it = g_cine->_objectScripts.begin();
for (; it != g_cine->_objectScripts.end();) {
debugC(5, kCineDebugScript, "executeObjectScripts() Executing Object Index: %d", (*it)->_index);
if ((*it)->_index < 0 || (*it)->execute() < 0) {
it = g_cine->_objectScripts.erase(it);
} else {
++it;
}
}
}
void executeGlobalScripts() {
ScriptList::iterator it = g_cine->_globalScripts.begin();
for (; it != g_cine->_globalScripts.end();) {
debugC(5, kCineDebugScript, "executeGlobalScripts() Executing Object Index: %d", (*it)->_index);
if ((*it)->_index < 0 || (*it)->execute() < 0) {
it = g_cine->_globalScripts.erase(it);
} else {
++it;
}
}
}
/**
* @todo Remove object scripts with script index of -1 (Not script position, but script index!).
* This would seem to be valid for both Future Wars and Operation Stealth.
*/
void purgeObjectScripts() {
}
/**
* @todo Remove global scripts with script index of -1 (Not script position, but script index!).
* This would seem to be valid for both Future Wars and Operation Stealth.
*/
void purgeGlobalScripts() {
}
////////////////////////////////////
// SCRIPT DECOMPILER
#ifdef DUMP_SCRIPTS
char decompileBuffer[10000][1000];
uint16 decompileBufferPosition = 0;
char bufferDec[256];
char compareString1[256];
char compareString2[256];
const char *getObjPramName(byte paramIdx) {
switch (paramIdx) {
case 1:
return ".X";
case 2:
return ".Y";
case 3:
return ".mask";
case 4:
return ".frame";
case 5:
return ".status";
case 6:
return ".costume";
default:
sprintf(bufferDec, ".param%d", paramIdx);
return bufferDec;
}
}
void decompileScript(const byte *scriptPtr, uint16 scriptSize, uint16 scriptIdx) {
char lineBuffer[256];
const byte *localScriptPtr = scriptPtr;
uint16 exitScript;
uint32 position = 0;
assert(scriptPtr);
exitScript = 0;
sprintf(decompileBuffer[decompileBufferPosition++], "--------- SCRIPT %d ---------\n", scriptIdx);
do {
uint16 opcode = *(localScriptPtr + position);
position++;
if (position == scriptSize) {
opcode = 0;
}
strcpy(lineBuffer, "");
switch (opcode - 1) {
case -1:
{
break;
}
case 0x0:
{
byte param1;
byte param2;
int16 param3;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
sprintf(lineBuffer, "obj[%d]%s = %d\n", param1, getObjPramName(param2), param3);
break;
}
case 0x1:
{
byte param1;
byte param2;
byte param3;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
param3 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "var[%d]=obj[%d]%s\n", param3, param1, getObjPramName(param2));
break;
}
case 0x2:
case 0x3:
case 0x4:
case 0x5:
case 0x6:
{
byte param1;
byte param2;
int16 param3;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
if (opcode - 1 == 0x2) {
sprintf(lineBuffer, "obj[%d]%s+=%d\n", param1, getObjPramName(param2), param3);
} else if (opcode - 1 == 0x3) {
sprintf(lineBuffer, "obj[%d]%s-=%d\n", param1, getObjPramName(param2), param3);
} else if (opcode - 1 == 0x4) {
sprintf(lineBuffer, "obj[%d]%s+=obj[%d]%s\n", param1, getObjPramName(param2), param3, getObjPramName(param2));
} else if (opcode - 1 == 0x5) {
sprintf(lineBuffer, "obj[%d]%s-=obj[%d]%s\n", param1, getObjPramName(param2), param3, getObjPramName(param2));
} else if (opcode - 1 == 0x6) {
sprintf(compareString1, "obj[%d]%s", param1, getObjPramName(param2));
sprintf(compareString2, "%d", param3);
}
break;
}
case 0x7:
case 0x8:
{
byte param1;
int16 param2;
int16 param3;
int16 param4;
int16 param5;
param1 = *(localScriptPtr + position);
position++;
param2 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param4 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param5 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
if (opcode - 1 == 0x7) {
sprintf(lineBuffer, "setupObject(Idx:%d,X:%d,Y:%d,mask:%d,frame:%d)\n", param1, param2, param3, param4, param5);
} else if (opcode - 1 == 0x8) {
sprintf(lineBuffer, "checkCollision(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5);
}
break;
}
case 0x9:
{
byte param1;
int16 param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
if (param2) {
byte param3;
param3 = *(localScriptPtr + position);
position++;
if (param2 == 1) {
sprintf(lineBuffer, "var[%d]=var[%d]\n", param1, param3);
} else if (param2 == 2) {
sprintf(lineBuffer, "var[%d]=globalVar[%d]\n", param1, param3);
} else if (param2 == 3) {
sprintf(lineBuffer, "var[%d]=mouse.X\n", param1);
} else if (param2 == 4) {
sprintf(lineBuffer, "var[%d]=mouse.Y\n", param1);
} else if (param2 == 5) {
sprintf(lineBuffer, "var[%d]=rand() mod %d\n", param1, param3);
} else if (param2 == 8) {
sprintf(lineBuffer, "var[%d]=file[%d].packedSize\n", param1, param3);
} else if (param2 == 9) {
sprintf(lineBuffer, "var[%d]=file[%d].unpackedSize\n", param1, param3);
} else {
error("decompileScript: 0x09: param2 = %d", param2);
}
} else {
int16 param3;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
sprintf(lineBuffer, "var[%d]=%d\n", param1, param3);
}
break;
}
case 0xA:
case 0xB:
case 0xC:
case 0xD:
{
byte param1;
byte param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
if (param2) {
byte param3;
param3 = *(localScriptPtr + position);
position++;
if (opcode - 1 == 0xA) {
sprintf(lineBuffer, "var[%d]+=var[%d]\n", param1, param3);
} else if (opcode - 1 == 0xB) {
sprintf(lineBuffer, "var[%d]-=var[%d]\n", param1, param3);
} else if (opcode - 1 == 0xC) {
sprintf(lineBuffer, "var[%d]*=var[%d]\n", param1, param3);
} else if (opcode - 1 == 0xD) {
sprintf(lineBuffer, "var[%d]/=var[%d]\n", param1, param3);
}
} else {
int16 param3;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
if (opcode - 1 == 0xA) {
sprintf(lineBuffer, "var[%d]+=%d\n", param1, param3);
} else if (opcode - 1 == 0xB) {
sprintf(lineBuffer, "var[%d]-=%d\n", param1, param3);
} else if (opcode - 1 == 0xC) {
sprintf(lineBuffer, "var[%d]*=%d\n", param1, param3);
} else if (opcode - 1 == 0xD) {
sprintf(lineBuffer, "var[%d]/=%d\n", param1, param3);
}
}
break;
}
case 0xE:
{
byte param1;
byte param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
if (param2) {
byte param3;
param3 = *(localScriptPtr + position);
position++;
if (param2 == 1) {
sprintf(compareString1, "var[%d]", param1);
sprintf(compareString2, "var[%d]", param3);
} else if (param2 == 2) {
sprintf(compareString1, "var[%d]", param1);
sprintf(compareString2, "globalVar[%d]", param3);
} else {
error("decompileScript: 0x0E: param2 = %d", param2);
}
} else {
int16 param3;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
sprintf(compareString1, "var[%d]", param1);
sprintf(compareString2, "%d", param3);
}
break;
}
case 0xF:
{
byte param1;
byte param2;
byte param3;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
param3 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "obj[%d]%s=var[%d]\n", param1, getObjPramName(param2), param3);
break;
}
case 0x13:
case 0x14:
case 0x15:
case 0x16:
case 0x17:
case 0x18:
case 0x19:
{
byte param;
param = *(localScriptPtr + position);
position++;
if (opcode - 1 == 0x13) {
sprintf(lineBuffer, "loadMask0(%d)\n", param);
} else if (opcode - 1 == 0x14) {
sprintf(lineBuffer, "unloadMask0(%d)\n", param);
} else if (opcode - 1 == 0x15) {
sprintf(lineBuffer, "OP_15(%d)\n", param);
} else if (opcode - 1 == 0x16) {
sprintf(lineBuffer, "loadMask1(%d)\n", param);
} else if (opcode - 1 == 0x17) {
sprintf(lineBuffer, "unloadMask0(%d)\n", param);
} else if (opcode - 1 == 0x18) {
sprintf(lineBuffer, "loadMask4(%d)\n", param);
} else if (opcode - 1 == 0x19) {
sprintf(lineBuffer, "unloadMask4(%d)\n", param);
}
break;
}
case 0x1A:
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_1A(%d)\n", param);
break;
}
case 0x1B:
{
sprintf(lineBuffer, "bgIncrustList.clear()\n");
break;
}
case 0x1D:
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "label(%d)\n", param);
break;
}
case 0x1E:
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "goto(%d)\n", param);
break;
}
// If cases
case 0x1F:
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24:
{
byte param;
param = *(localScriptPtr + position);
position++;
if (opcode - 1 == 0x1F) {
sprintf(lineBuffer, "if(%s>%s) goto(%d)\n", compareString1, compareString2, param);
} else if (opcode - 1 == 0x20) {
sprintf(lineBuffer, "if(%s>=%s) goto(%d)\n", compareString1, compareString2, param);
} else if (opcode - 1 == 0x21) {
sprintf(lineBuffer, "if(%s<%s) goto(%d)\n", compareString1, compareString2, param);
} else if (opcode - 1 == 0x22) {
sprintf(lineBuffer, "if(%s<=%s) goto(%d)\n", compareString1, compareString2, param);
} else if (opcode - 1 == 0x23) {
sprintf(lineBuffer, "if(%s==%s) goto(%d)\n", compareString1, compareString2, param);
} else if (opcode - 1 == 0x24) {
sprintf(lineBuffer, "if(%s!=%s) goto(%d)\n", compareString1, compareString2, param);
}
break;
}
case 0x25:
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "removeLabel(%d)\n", param);
break;
}
case 0x26:
{
byte param1;
byte param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "loop(--var[%d]) -> label(%d)\n", param1, param2);
break;
}
case 0x31:
case 0x32:
{
byte param;
param = *(localScriptPtr + position);
position++;
if (opcode - 1 == 0x31) {
sprintf(lineBuffer, "startGlobalScript(%d)\n", param);
} else if (opcode - 1 == 0x32) {
sprintf(lineBuffer, "endGlobalScript(%d)\n", param);
}
break;
}
case 0x3B:
case 0x3C:
case 0x3D:
case OP_loadPart:
{
if (opcode - 1 == 0x3B) {
sprintf(lineBuffer, "loadResource(%s)\n", localScriptPtr + position);
} else if (opcode - 1 == 0x3C) {
sprintf(lineBuffer, "loadBg(%s)\n", localScriptPtr + position);
} else if (opcode - 1 == 0x3D) {
sprintf(lineBuffer, "loadCt(%s)\n", localScriptPtr + position);
} else if (opcode - 1 == OP_loadPart) {
sprintf(lineBuffer, "loadPart(%s)\n", localScriptPtr + position);
}
position += strlen((const char *)localScriptPtr + position) + 1;
break;
}
case 0x40:
{
sprintf(lineBuffer, "closePart()\n");
break;
}
case OP_loadNewPrcName:
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "loadPrc(%d,%s)\n", param, localScriptPtr + position);
position += strlen((const char *)localScriptPtr + position) + 1;
break;
}
case OP_requestCheckPendingDataLoad: // nop
{
sprintf(lineBuffer, "requestCheckPendingDataLoad()\n");
break;
}
case 0x45:
{
sprintf(lineBuffer, "blitAndFade()\n");
break;
}
case 0x46:
{
sprintf(lineBuffer, "fadeToBlack()\n");
break;
}
case 0x47:
{
byte param1;
byte param2;
int16 param3;
int16 param4;
int16 param5;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param4 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param5 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
sprintf(lineBuffer, "transformPaletteRange(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5);
break;
}
case 0x49:
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "setDefaultMenuBgColor(%d)\n", param);
break;
}
case 0x4F:
{
sprintf(lineBuffer, "break()\n");
exitScript = 1;
break;
}
case 0x50:
{
sprintf(lineBuffer, "endScript()\n\n");
break;
}
case 0x51:
{
byte param1;
int16 param2;
int16 param3;
int16 param4;
int16 param5;
param1 = *(localScriptPtr + position);
position++;
param2 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param4 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param5 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
sprintf(lineBuffer, "message(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5);
break;
}
case 0x52:
case 0x53:
{
byte param1;
byte param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
if (param2) {
byte param3;
param3 = *(localScriptPtr + position);
position++;
if (param2 == 1) {
if (opcode - 1 == 0x52) {
sprintf(lineBuffer, "globalVar[%d] = var[%d]\n", param1, param3);
} else if (opcode - 1 == 0x53) {
sprintf(compareString1, "globalVar[%d]", param1);
sprintf(compareString2, "var[%d]", param3);
}
} else if (param2 == 2) {
if (opcode - 1 == 0x52) {
sprintf(lineBuffer, "globalVar[%d] = globalVar[%d]\n", param1, param3);
} else if (opcode - 1 == 0x53) {
sprintf(compareString1, "globalVar[%d]", param1);
sprintf(compareString2, "globalVar[%d]", param3);
}
} else {
if (opcode - 1 == 0x52) {
error("decompileScript: 0x52: param2 = %d", param2);
} else if (opcode - 1 == 0x53) {
error("decompileScript: 0x53: param2 = %d", param2);
}
}
} else {
int16 param3;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
if (opcode - 1 == 0x52) {
sprintf(lineBuffer, "globalVar[%d] = %d\n", param1, param3);
} else if (opcode - 1 == 0x53) {
sprintf(compareString1, "globalVar[%d]", param1);
sprintf(compareString2, "%d", param3);
}
}
break;
}
case 0x59:
{
sprintf(lineBuffer, "comment: %s\n", localScriptPtr + position);
position += strlen((const char *)localScriptPtr + position);
break;
}
case 0x5A:
{
byte param1;
byte param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "freePartRang(%d,%d)\n", param1, param2);
break;
}
case 0x5B:
{
sprintf(lineBuffer, "unloadAllMasks()\n");
break;
}
case 0x65:
{
sprintf(lineBuffer, "setupTableUnk1()\n");
break;
}
case 0x66:
{
byte param1;
int16 param2;
param1 = *(localScriptPtr + position);
position++;
param2 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
sprintf(lineBuffer, "tableUnk1[%d] = %d\n", param1, param2);
break;
}
case 0x68:
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "setPlayerCommandPosY(%d)\n", param);
break;
}
case 0x69:
{
sprintf(lineBuffer, "allowPlayerInput()\n");
break;
}
case 0x6A:
{
sprintf(lineBuffer, "disallowPlayerInput()\n");
break;
}
case 0x6B:
{
byte newDisk;
newDisk = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "changeDataDisk(%d)\n", newDisk);
break;
}
case 0x6D:
{
sprintf(lineBuffer, "loadDat(%s)\n", localScriptPtr + position);
position += strlen((const char *)localScriptPtr + position) + 1;
break;
}
case 0x6E: // nop
{
sprintf(lineBuffer, "updateDat()\n");
break;
}
case 0x6F:
{
sprintf(lineBuffer, "OP_6F() -> dat related\n");
break;
}
case 0x70:
{
sprintf(lineBuffer, "stopSample()\n");
break;
}
case 0x79:
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "disableSystemMenu(%d)\n", param);
break;
}
case 0x77:
case 0x78:
{
byte param1;
byte param2;
int16 param3;
byte param4;
int16 param5;
int16 param6;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param4 = *(localScriptPtr + position);
position++;
param5 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param6 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
if (opcode - 1 == 0x77) {
sprintf(lineBuffer, "playSample(%d,%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5, param6);
} else if (opcode - 1 == 0x78) {
sprintf(lineBuffer, "OP_78(%d,%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5, param6);
}
break;
}
case 0x7A:
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_7A(%d)\n", param);
break;
}
case 0x7B: // OS only
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_7B(%d)\n", param);
break;
}
case 0x7F: // OS only
{
byte param1;
byte param2;
byte param3;
byte param4;
int16 param5;
int16 param6;
int16 param7;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
param3 = *(localScriptPtr + position);
position++;
param4 = *(localScriptPtr + position);
position++;
param5 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param6 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param7 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
sprintf(lineBuffer, "OP_7F(%d,%d,%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5, param6, param7);
break;
}
case 0x80: // OS only
{
byte param1;
byte param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_80(%d,%d)\n", param1, param2);
break;
}
case 0x82: // OS only
{
byte param1;
byte param2;
uint16 param3;
uint16 param4;
byte param5;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param4 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param5 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_82(%d,%d,%d,%d,%d)\n", param1, param2, param3, param4, param5);
break;
}
case 0x83: // OS only
{
byte param1;
byte param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_83(%d,%d)\n", param1, param2);
break;
}
case 0x89: // OS only
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "if(%s!=%s) goto next label(%d)\n", compareString1, compareString2, param);
break;
}
case 0x8B: // OS only
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_8B(%d)\n", param);
break;
}
case 0x8C: // OS only
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_8C(%d)\n", param);
break;
}
case 0x8D: // OS only
{
int16 param1;
int16 param2;
int16 param3;
int16 param4;
int16 param5;
int16 param6;
int16 param7;
int16 param8;
param1 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param2 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param3 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param4 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param5 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param6 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param7 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
param8 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
sprintf(compareString1, "obj[%d]", param1);
sprintf(compareString2, "{%d,%d,%d,%d,%d,%d,%d}", param2, param3, param4, param5, param6, param7, param8);
break;
}
case 0x8E: // OS only
{
byte param1;
param1 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "ADDBG(%d,%s)\n", param1, localScriptPtr + position);
position += strlen((const char *)localScriptPtr + position);
break;
}
case 0x8F: // OS only
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_8F(%d)\n", param);
break;
}
case 0x90: // OS only
{
byte param1;
param1 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "loadABS(%d,%s)\n", param1, localScriptPtr + position);
position += strlen((const char *)localScriptPtr + position);
break;
}
case 0x91: // OS only
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_91(%d)\n", param);
break;
}
case 0x9D: // OS only
{
byte param;
param = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_9D(%d) -> flip img idx\n", param);
break;
}
case 0x9E: // OS only
{
byte param;
param = *(localScriptPtr + position);
position++;
if (param) {
byte param2;
param2 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_9E(%d,%d)\n", param, param2);
} else {
int16 param2;
param2 = READ_BE_UINT16(localScriptPtr + position);
position += 2;
sprintf(lineBuffer, "OP_9E(%d,%d)\n", param, param2);
}
break;
}
case 0xA0: // OS only
{
byte param1;
byte param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_A0(%d,%d)\n", param1, param2);
break;
}
case 0xA1: // OS only
{
byte param1;
byte param2;
param1 = *(localScriptPtr + position);
position++;
param2 = *(localScriptPtr + position);
position++;
sprintf(lineBuffer, "OP_A1(%d,%d)\n", param1, param2);
break;
}
default:
{
sprintf(lineBuffer, "Unsupported opcode %X in decompileScript\n\n", opcode - 1);
position = scriptSize;
break;
}
}
// printf(lineBuffer);
strcpy(decompileBuffer[decompileBufferPosition++], lineBuffer);
exitScript = 0;
if (position >= scriptSize) {
exitScript = 1;
}
} while (!exitScript);
}
void dumpScript(char *dumpName) {
Common::DumpFile fHandle;
uint16 i;
fHandle.open(dumpName);
for (i = 0; i < decompileBufferPosition; i++) {
fHandle.writeString(Common::String(decompileBuffer[i]));
}
fHandle.close();
decompileBufferPosition = 0;
}
#endif
} // End of namespace Cine
|