File: gfx_gui.cpp

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (4949 lines) | stat: -rw-r--r-- 150,361 bytes parent folder | download | duplicates (2)
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
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
/* 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */

#include "scumm/scumm.h"
#include "scumm/scumm_v2.h"
#include "scumm/scumm_v4.h"
#include "scumm/scumm_v6.h"
#include "scumm/scumm_v8.h"
#include "scumm/gfx.h"
#include "scumm/dialogs.h"
#include "scumm/charset.h"
#include "scumm/string_v7.h"
#include "scumm/sound.h"
#include "scumm/smush/smush_player.h"
#include "scumm/imuse_digi/dimuse_engine.h"

#include "audio/mixer.h"
#include "graphics/cursorman.h"
#include "graphics/thumbnail.h"

namespace Scumm {

void ScummEngine::initBanners() {
	memset(_bannerColors, 0, sizeof(_bannerColors));

	setPalColor(7, 0x5A, 0x5A, 0x5A);
	setPalColor(8, 0x46, 0x46, 0x46);
	setPalColor(15, 0x8C, 0x8C, 0x8C);
	updatePalette();

	setBannerColors(1, 0x00, 0x00, 0x00);
	setBannerColors(2, 0xA8, 0xA8, 0xA8);
	setBannerColors(3, 0x00, 0x00, 0x00);
	setBannerColors(4, 0xFC, 0xFC, 0x54);
	setBannerColors(5, 0x54, 0x54, 0xFC);
	setBannerColors(6, 0xA8, 0xA8, 0xA8);
	setBannerColors(7, 0x00, 0x00, 0x00);
	setBannerColors(8, 0xFC, 0xFC, 0x54);
	setBannerColors(9, 0x54, 0x54, 0xFC);
	setBannerColors(10, 0xFC, 0xFC, 0xFC);
	setBannerColors(11, 0x54, 0x54, 0x54);
	setBannerColors(12, 0xFC, 0xFC, 0xFC);
	setBannerColors(13, 0x54, 0x54, 0x54);
	setBannerColors(14, 0x00, 0x00, 0x00);
	setBannerColors(15, 0xA8, 0xA8, 0xA8);
	setBannerColors(16, 0xFC, 0xFC, 0xFC);
	setBannerColors(17, 0x54, 0x54, 0x54);
	setBannerColors(18, 0xFC, 0xFC, 0xFC);
	setBannerColors(19, 0x54, 0x54, 0x54);
	setBannerColors(20, 0xFC, 0x00, 0x00);
	setBannerColors(21, 0xA8, 0xA8, 0xA8);
	setBannerColors(22, 0xFC, 0xFC, 0xFC);
	setBannerColors(23, 0x54, 0x54, 0x54);
	setBannerColors(24, 0xFC, 0xFC, 0xFC);
	setBannerColors(25, 0x54, 0x54, 0x54);
	setBannerColors(26, 0x00, 0x00, 0x00);
	setBannerColors(27, 0xA8, 0xA8, 0xA8);
	setBannerColors(28, 0xFC, 0xFC, 0xFC);
	setBannerColors(29, 0x54, 0x54, 0x54);
	setBannerColors(30, 0xFC, 0xFC, 0xFC);
	setBannerColors(31, 0x54, 0x54, 0x54);
}

Common::KeyState ScummEngine::showBannerAndPause(int bannerId, int32 waitTime, const char *msg, ...) {
	char bannerMsg[512];
	char localizedMsg[512];
	char localizedY[512];
	char *ptrToBreak;
	int bannerMsgWidth, bannerMsgHeight, roundedWidth;
	int startingPointX, startingPointY;
	int xPos, yPos;
	int rightLineColor, leftLineColor, bottomLineColor, topLineColor;
	int normalTextColor, normalFillColor;

	_messageBannerActive = true;

	int oldScreenTop = _screenTop;

	// There are a few instances in a non-zero _screenTop is not being reset
	// before starting a SMUSH movie (e.g. the very last video in The Dig);
	// let's set it to zero now and restore it at the very end...
	if (isSmushActive())
		_screenTop = 0;

	// Fetch the translated string for the message...
	convertMessageToString((const byte *)msg, (byte *)localizedMsg, sizeof(localizedMsg));
	ptrToBreak = strstr(localizedMsg, "\\n");
	if (!(_game.features & GF_DEMO) && ptrToBreak) { // Change the line break, if any...
		ptrToBreak[0] = '\n';
		ptrToBreak[1] = '\r';
	}

	// Format the string with the arguments...
	va_list va;
	va_start(va, msg);
	vsnprintf(bannerMsg, sizeof(bannerMsg), localizedMsg, va);
	va_end(va);

	// Fetch the localized confirmation letter and substitute it with the 'y' of 'yes'
	if (_game.version == 8) {
		convertMessageToString((const byte *)getGUIString(gsYesKey), (byte *)localizedY, sizeof(localizedY));
	}

	// Backup the text surface...
	if (_game.version < 7 && !_mainMenuIsActive && _game.platform != Common::kPlatformFMTowns) {
		saveSurfacesPreGUI();
		if (_currentRoom != 0 && _charset->_textScreenID == kMainVirtScreen && !(_game.version == 4 && _game.id == GID_LOOM))
			restoreCharsetBg();
	}

	// Pause shake effect
	_shakeTempSavedState = _shakeEnabled;
	setShake(0);

	// Pause the engine
	PauseToken pt = pauseEngine();

	// Gather the colors needed for the banner
	if (_game.version == 4) {
		normalFillColor = 7;
		normalTextColor = 0;
		topLineColor = 15;
		bottomLineColor = 8;
		leftLineColor = 15;
		rightLineColor = 8;
	} else if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD) {
		// AFAIK, the original Sega CD interpreter doesn't have message banners, it just
		// shows the main menu box (e.g. when pausing). In here, we can show the banner,
		// but let's use the main menu box colors to avoid using unintended colors.
		normalFillColor = getBannerColor(4);
		normalTextColor = getBannerColor(2);
		topLineColor = getBannerColor(13);
		bottomLineColor = getBannerColor(14);
		leftLineColor = getBannerColor(15);
		rightLineColor = getBannerColor(16);
	} else {
		int palOffset = (_game.version == 8) ? 0 : 11;
		normalFillColor = getBannerColor(6 * bannerId + 15 + palOffset);
		normalTextColor = getBannerColor(6 * bannerId + 14 + palOffset);

		if (_game.version == 5 && _game.platform == Common::kPlatformMacintosh) {
			// Mac versions of MI1, MI2 and INDY4 invert the colors of the bottom
			// and left lines, which means they have the brightest colors on the top
			// and bottom lines, and the darker colors on the left and right lines.
			topLineColor = getBannerColor(6 * bannerId + 16 + palOffset);
			bottomLineColor = getBannerColor(6 * bannerId + 18 + palOffset);
			leftLineColor = getBannerColor(6 * bannerId + 17 + palOffset);
			rightLineColor = getBannerColor(6 * bannerId + 19 + palOffset);
		} else {
			topLineColor = getBannerColor(6 * bannerId + 16 + palOffset);
			bottomLineColor = getBannerColor(6 * bannerId + 17 + palOffset);
			leftLineColor = getBannerColor(6 * bannerId + 18 + palOffset);
			rightLineColor = getBannerColor(6 * bannerId + 19 + palOffset);
		}
	}

	// Backup the current charsetId, since we're going to switch
	// to charsetId == 1...
	int oldId = _charset->getCurID();
	_charset->setCurID(1);

	// Take all the necessary measurements for the box which
	// will contain the string...
	bool isCOMIDemo = (_game.id == GID_CMI && (_game.features & GF_DEMO) != 0);

	if (_isIndy4Jap)
		_force2ByteCharHeight = true;

	bannerMsgHeight = ((_game.id == GID_DIG || isCOMIDemo) ? getGUIStringHeight("ABC \x80\x78 \xb0\x78") : getGUIStringHeight(bannerMsg)) + 5;

	if (_isIndy4Jap)
		_force2ByteCharHeight = false;

	bannerMsgWidth = getGUIStringWidth(bannerMsg);

	if (_isIndy4Jap)
		bannerMsgWidth += 32;

	if (bannerMsgWidth < 100)
		bannerMsgWidth = 100;

	roundedWidth = (((bannerMsgWidth + 15) & 0xFFF0) + 8) / 2;
	if (_game.version < 7) {
		roundedWidth = bannerMsgWidth / 2;
	}

	if (_game.version == 8) {
		startingPointX = _screenWidth / 2 - roundedWidth - 4;
		startingPointY = _screenHeight / 2 - 10;
		xPos = _screenWidth / 2 + roundedWidth + 3;
		yPos = 1 - bannerMsgHeight;
		_bannerSaveYStart = startingPointY;
	} else if (_isIndy4Jap) {
		startingPointX = 156 - bannerMsgWidth / 2;
		startingPointY = 80;
		xPos = bannerMsgWidth / 2 + 164;
		yPos = -18;
		_bannerSaveYStart = startingPointY - 2;
	} else if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformFMTowns) {
		bannerMsgWidth = getGUIStringWidth(bannerMsg) / 2;
		startingPointX = ((160 - bannerMsgWidth) - 8) & 0xFFF8;
		startingPointY = (bannerMsgWidth + 168) | 0x7;
		xPos = startingPointX + 1; // Bogus value, since it is unused
		yPos = startingPointY + 1; // Bogus value, since it is unused
		_bannerSaveYStart = 78;
	} else {
		startingPointX = 156 - roundedWidth;
		startingPointY = ((_game.version < 7) ? 80 : _screenHeight / 2 - 10);
		xPos = roundedWidth + 163 + ((_game.version < 7) ? 1 : 0);
		yPos = 1 - bannerMsgHeight; // For the normal font this will end up as -12, for CJK modes it will be appropriately adjusted.
		_bannerSaveYStart = startingPointY - ((_game.version < 7) ? 2 : 0);
	}

	// Save the pixels which will be overwritten by the banner,
	// so that we can restore them later...
	if (!_bannerMem) {
		int rowSize = _screenWidth + 8;
		_bannerMemSize = bannerMsgHeight * (_screenWidth + 8);
		_bannerMem = (byte *)malloc(_bannerMemSize * sizeof(byte));
		if (_bannerMem) {
			// FM-Towns games draw the banner on the text surface, so let's save that
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
			if (_game.platform == Common::kPlatformFMTowns && !_textSurfBannerMem) {
				rowSize *= _textSurfaceMultiplier;
				_bannerSaveYStart *= _textSurfaceMultiplier;
				_textSurfBannerMemSize = bannerMsgHeight * rowSize * _textSurfaceMultiplier;
				_textSurfBannerMem = (byte *)malloc(_textSurfBannerMemSize * sizeof(byte));
				if (_textSurfBannerMem) {
					memcpy(
						_textSurfBannerMem,
						&((byte *)_textSurface.getBasePtr(0, _screenTop * _textSurfaceMultiplier))[rowSize * _bannerSaveYStart],
						_textSurfBannerMemSize);
				}

				// We're going to use these same values for saving the
				// virtual screen surface, so let's un-multiply them...
				rowSize /= _textSurfaceMultiplier;
				_bannerSaveYStart /= _textSurfaceMultiplier;
			}
#endif
			memcpy(
				_bannerMem,
				&_virtscr[kMainVirtScreen].getPixels(0, _screenTop)[rowSize * _bannerSaveYStart],
				_bannerMemSize);
		}
	}

	if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformFMTowns) {
		// MI1 for FMTowns does its own thing with hardcoded values here...
		drawBox(startingPointX + 1, 81, startingPointY - 1, 90, normalFillColor);

		drawLine(startingPointX + 1, 80, startingPointY - 1, 80, topLineColor);
		drawLine(startingPointX + 1, 91, startingPointY - 1, 91, bottomLineColor);
		drawLine(startingPointX, 81, startingPointX, 90, leftLineColor);
		drawLine(startingPointY, 81, startingPointY, 90, rightLineColor);

		int tmpRight = _string[5].right;
		_string[5].right = _screenWidth - 1;

		drawGUIText(bannerMsg, nullptr, 160, 82, normalTextColor, true);
		_string[5].right = tmpRight;
	} else {
		// Set up the GUI control, specifying all the related colors, the message and the position...
		setUpInternalGUIControl(0, normalFillColor, normalTextColor,
								topLineColor, bottomLineColor, leftLineColor, rightLineColor, 0, 0,
								startingPointX, startingPointY, xPos, yPos,
								bannerMsg, true, true);

		// Draw it!
		drawInternalGUIControl(0, 0);
	}

	ScummEngine::drawDirtyScreenParts();

	// Wait until the engine receives a new Keyboard or Mouse input,
	// unless we have specified a positive waitTime: in that case, the banner
	// will stay on screen until an input has been received or until the time-out.
	Common::KeyState ks = Common::KEYCODE_INVALID;
	bool leftBtnPressed = false, rightBtnPressed = false;
	if (waitTime) {
		waitForBannerInput(waitTime, ks, leftBtnPressed, rightBtnPressed);
		clearBanner();
	}

	// Restore the text surface...
	if (_game.version < 7 && !_mainMenuIsActive && _game.platform != Common::kPlatformFMTowns) {
		restoreSurfacesPostGUI();
	}

	// Finally, resume the engine, clear the input state, and restore the charset.
	pt.clear();
	clearClickedStatus();
	if (oldId)
		_charset->setCurID(oldId);

	if (_game.version == 8) {
		if (tolower(localizedY[0]) == ks.ascii || toupper(localizedY[0]) == ks.ascii)
			ks = Common::KEYCODE_y;
	}

	// Deactivate this, so it does not trigger as invalid click target inside
	// getInternalGUIControlFromCoordinates() (which can cause serious errors)
	_internalGUIControls[0].relativeCenterX = -1;

	_messageBannerActive = false;

	if (isSmushActive())
		_screenTop = oldScreenTop;

	return ks;
}

Common::KeyState ScummEngine::printMessageAndPause(const char *msg, int color, int32 waitTime, bool drawOnSentenceLine) {
	Common::Rect sentenceline;
	int pixelYOffset = (_game.platform == Common::kPlatformC64) ? 1 : 0;
	int pixelXOffset = (_game.platform == Common::kPlatformC64) ? 1 : 0;

	// Pause the engine
	PauseToken pt = pauseEngine();

	if (drawOnSentenceLine) {
		setSnailCursor();

		_string[2].charset = 1;
		_string[2].ypos = _virtscr[kVerbVirtScreen].topline + pixelYOffset;
		_string[2].xpos = 0 + pixelXOffset;
		_string[2].right = _virtscr[kVerbVirtScreen].w - 1 + pixelXOffset;
		if (_game.platform == Common::kPlatformNES) {
			_string[2].xpos = 16;
			_string[2].color = 0;
		} else if (_game.platform == Common::kPlatformC64 || _game.platform == Common::kPlatformApple2GS) {
			_string[2].color = (_game.platform == Common::kPlatformApple2GS && !enhancementEnabled(kEnhVisualChanges)) ? 1 : 16;
		} else {
			_string[2].color = 13;
		}

		byte string[80];
		const char *ptr = msg;
		int i = 0, len = 0;

		// Maximum length of printable characters
		int maxChars = (_game.platform == Common::kPlatformNES) ? 60 : 40;
		while (*ptr) {
			if (*ptr != '@')
				len++;
			if (len > maxChars) {
				break;
			}

			string[i++] = *ptr++;

			if (_game.platform == Common::kPlatformNES && len == 30) {
				string[i++] = 0xFF;
				string[i++] = 8;
			}
		}
		string[i] = 0;

		if (_game.platform == Common::kPlatformNES) {
			sentenceline.top = _virtscr[kVerbVirtScreen].topline;
			sentenceline.bottom = _virtscr[kVerbVirtScreen].topline + 16;
			sentenceline.left = 16;
			sentenceline.right = _virtscr[kVerbVirtScreen].w - 1;
		} else {
			sentenceline.top = _virtscr[kVerbVirtScreen].topline + pixelYOffset;
			sentenceline.bottom = _virtscr[kVerbVirtScreen].topline + 8 + pixelYOffset;
			sentenceline.left = 0 + pixelXOffset;
			sentenceline.right = _virtscr[kVerbVirtScreen].w - 1 + pixelXOffset;
		}
		restoreBackground(sentenceline);
		drawString(2, (byte *)string);
		drawDirtyScreenParts();
	} else {
		_string[0].xpos = 0 + pixelXOffset;
		_string[0].ypos = 0;
		_string[0].right = _screenWidth - 1 + pixelXOffset;
		_string[0].center = false;
		_string[0].overhead = false;

		byte tmpColor = _string[0].color;
		byte tmpAct = _actorToPrintStrFor;

		_string[0].color = color;
		_actorToPrintStrFor = 0xFF;

		actorTalk((const byte *)msg);

		_actorToPrintStrFor = tmpAct;
		_string[0].color = tmpColor;
	}

	Common::KeyState ks = Common::KEYCODE_INVALID;
	bool leftBtnPressed = false, rightBtnPressed = false;

	// Wait until the engine receives a new Keyboard or Mouse input,
	// unless we have specified a positive waitTime: in that case, the banner
	// will stay on screen until an input has been received or until the time-out.
	if (waitTime) {
		ScummEngine::drawDirtyScreenParts();
		waitForBannerInput(waitTime, ks, leftBtnPressed, rightBtnPressed);

		if (!drawOnSentenceLine)
			stopTalk();
	}

	if (drawOnSentenceLine) {
		setBuiltinCursor(0);
		restoreBackground(sentenceline);

		// Restore the sentence which was being displayed before
		// (MANIAC v1 doesn't do this)
		if (!(_game.id == GID_MANIAC && _game.version <= 1))
			drawSentence();
	}

	// Finally, resume the engine, clear the input state, and restore the charset.
	pt.clear();
	clearClickedStatus();

	return ks;
}

Common::KeyState ScummEngine::showOldStyleBannerAndPause(const char *msg, int color, int32 waitTime) {
	// LOOM VGA uses the new style GUI
	if (_game.version == 4 && _game.id == GID_LOOM) {
		return showBannerAndPause(0, waitTime, msg);
	}

	if (_macScreen) {
		return mac_showOldStyleBannerAndPause(msg, waitTime);
	}

	char bannerMsg[512];
	int bannerMsgWidth, bannerMsgHeight;
	int startingPointY;
	int boxColor;
	int textXPos, textYPos;

	_messageBannerActive = true;

	// Fetch the translated string for the message...
	convertMessageToString((const byte *)msg, (byte *)bannerMsg, sizeof(bannerMsg));

	// Backup the text surface...
	if (!_mainMenuIsActive) {
		saveSurfacesPreGUI();
		if (_currentRoom != 0 && _charset->_textScreenID == kMainVirtScreen && _game.id != GID_LOOM) {
			restoreCharsetBg();
		}
	}

	// Pause shake effect
	_shakeTempSavedState = _shakeEnabled;
	setShake(0);

	// Pause the engine
	PauseToken pt = pauseEngine();

	_forceBannerVirtScreen = true;

	// Backup the current charsetId...
	int oldId = _charset->getCurID();
	_charset->setCurID(_game.version > 3 ? 1 : 0);

	// Take all the necessary measurements for the box which
	// will contain the string...
	bannerMsgHeight = _virtscr[kBannerVirtScreen].h;
	bannerMsgWidth = getGUIStringWidth(bannerMsg);
	if (bannerMsgWidth < 100)
		bannerMsgWidth = 100;

	startingPointY = _virtscr[kBannerVirtScreen].topline;

	boxColor = 0;
	textXPos = _screenWidth / 2;
	textYPos = startingPointY + 2 / _textSurfaceMultiplier;

	if (_game.platform == Common::kPlatformFMTowns) {
		// We replicate an original text centering bug here. The function that measures
		// the text width in Indy 3 FM-Towns JP adds 10 pixels to the width for each
		// character (instead of 8, like the other FM-Towns games do it). Fortunately,
		// that text width measuring function is only used here...
		if (_game.id == GID_INDY3 && _useCJKMode)
			bannerMsgWidth = MIN<int>(bannerMsgWidth * 10 / 8, (_screenWidth - 10));

		boxColor = 8;
		textXPos = (_screenWidth - bannerMsgWidth) / 2;

		// Loom and Zak FM-Towns do this in drawChar(). Indy 3 doesn't.
		if (_game.id != GID_INDY3 && _useCJKMode)
			textXPos -= 8;
	}

	// Draw the GUI control
	memset(_virtscr[kBannerVirtScreen].getBasePtr(0, 0), boxColor, _virtscr[kBannerVirtScreen].w * _virtscr[kBannerVirtScreen].h);
	drawLine(0, startingPointY, _screenWidth - 1, startingPointY, color);
	drawLine(0, startingPointY + bannerMsgHeight - 1, _screenWidth - 1, startingPointY + bannerMsgHeight - 1, color);
	drawGUIText(bannerMsg, nullptr, textXPos, textYPos, color, _game.platform != Common::kPlatformFMTowns);

	_forceBannerVirtScreen = false;

	if (_game.platform == Common::kPlatformFMTowns) {
		// FM-Towns games just exchange the vs content with the respective screen layer area
		// without making any virtscreen strips dirty. It can make a difference, e. g. in bug
		// no. 15027 ("INDY3 (FMTowns): Map lines are drawn incorrectly, plus more issues when
		// leaving Germany"). Making the virtscreen dirty, would cause some wrong colors, due
		// to the way the scripts handle the shadow palette there.
		VirtScreen *vs = &_virtscr[kBannerVirtScreen];
		towns_swapVirtScreenArea(vs, 0, vs->topline * _textSurfaceMultiplier, vs->w, vs->h);
	} else {
		drawDirtyScreenParts();
		updateDirtyScreen(kBannerVirtScreen);
	}

	// Wait until the engine receives a new Keyboard or Mouse input,
	// unless we have specified a positive waitTime: in that case, the banner
	// will stay on screen until an input has been received or until the time-out.
	Common::KeyState ks = Common::KEYCODE_INVALID;
	bool leftBtnPressed = false, rightBtnPressed = false;
	if (waitTime) {
		waitForBannerInput(waitTime, ks, leftBtnPressed, rightBtnPressed);
		if (_game.platform == Common::kPlatformFMTowns) {
			VirtScreen *vs = &_virtscr[kBannerVirtScreen];
			towns_swapVirtScreenArea(vs, 0, vs->topline * _textSurfaceMultiplier, vs->w, vs->h);
		} else {
			memset(_virtscr[kBannerVirtScreen].getBasePtr(0, 0), 0, _virtscr[kBannerVirtScreen].w * _virtscr[kBannerVirtScreen].h);
			_virtscr[kBannerVirtScreen].setDirtyRange(0, _virtscr[kBannerVirtScreen].h);
			updateDirtyScreen(kBannerVirtScreen);
			_virtscr[kMainVirtScreen].setDirtyRange(startingPointY - _virtscr[kMainVirtScreen].topline, startingPointY - _virtscr[kMainVirtScreen].topline + _virtscr[kBannerVirtScreen].h);
		}
	}

	// Restore the text surface...
	if (!_mainMenuIsActive) {
		restoreSurfacesPostGUI();
	}

	// Finally, resume the engine, clear the input state, and restore the charset.
	pt.clear();
	clearClickedStatus();
	if (oldId)
		_charset->setCurID(oldId);

	// Deactivate this, so it does not trigger as invalid click target inside
	// getInternalGUIControlFromCoordinates() (which can cause serious errors)
	_internalGUIControls[0].relativeCenterX = -1;

	_messageBannerActive = false;

	return ks;
}

void ScummEngine::clearBanner() {
	int startingPointY = _bannerSaveYStart;

	// Restore the GFX content which was under the banner,
	// and then mark that part of the screen as dirty.
	if (_bannerMem) {
		int rowSize = _screenWidth + (_game.version >= 4 ? 8 : 0);
		// Don't manually clear the banner if a SMUSH movie is playing,
		// as that will cause some rare small glitches. The SMUSH player
		// will take care of that for us automatically when updating the
		// screen for next frame.
		if (!isSmushActive()) {
			// FM-Towns games draw the banners on the text surface, so restore both surfaces...
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
			if (_game.platform == Common::kPlatformFMTowns && _textSurfBannerMem) {
				startingPointY *= _textSurfaceMultiplier;
				rowSize *= _textSurfaceMultiplier;
				memcpy(
					&((byte *)_textSurface.getBasePtr(0, _screenTop * _textSurfaceMultiplier))[rowSize * startingPointY],
					_textSurfBannerMem,
					_textSurfBannerMemSize);

				// We're going to use these same values for restoring the
				// virtual screen surface, so let's un-multiply them...
				rowSize /= _textSurfaceMultiplier;
				startingPointY /= _textSurfaceMultiplier;
			}
#endif

			memcpy(
				&_virtscr[kMainVirtScreen].getPixels(0, _screenTop)[rowSize * startingPointY],
				_bannerMem,
				_bannerMemSize);

			markRectAsDirty(_virtscr[kMainVirtScreen].number, 0, rowSize, _screenTop, _screenHeight + _screenTop);
			ScummEngine::drawDirtyScreenParts();
			_system->updateScreen();
		}

		free(_bannerMem);
		_bannerMem = nullptr;

		free(_textSurfBannerMem);
		_textSurfBannerMem = nullptr;
	}

	// Restore shake effect
	setShake(_shakeTempSavedState);
}

void ScummEngine::setBannerColors(int bannerId, byte r, byte g, byte b) {
	if (bannerId < 0 || bannerId > 49) {
		debug(1, "ScummEngine::setBannerColors(): invalid slot %d out of range (min %d, max %d)", bannerId, 0, 49);
		return;
	}

	_bannerColors[bannerId] = r | (b << 16) | (g << 8);
}

void ScummEngine::setUpInternalGUIControl(int id, int normalFillColor, int normalTextColor,
										  int topLineColor, int bottomLineColor, int leftLineColor, int rightLineColor,
										  int highlightedTextColor, int highlightedFillColor,
										  int anchorPointX, int anchorPointY, int x, int y, const char *label, bool centerFlag, bool doubleLinesFlag) {

	int effX, effY;
	InternalGUIControl *ctrl;

	effX = x;
	ctrl = &_internalGUIControls[id];
	if (x < 0)
		effX = anchorPointX - x;
	effY = y;
	if (y < 0)
		effY = anchorPointY - y;
	ctrl->relativeCenterX = anchorPointX;
	ctrl->relativeCenterY = anchorPointY;
	ctrl->xPos = effX;
	ctrl->yPos = effY;
	ctrl->label = label;
	ctrl->centerText = centerFlag;
	ctrl->normalFillColor = normalFillColor;
	ctrl->topLineColor = topLineColor;
	ctrl->bottomLineColor = bottomLineColor;
	ctrl->leftLineColor = leftLineColor;
	ctrl->rightLineColor = rightLineColor;
	ctrl->normalTextColor = normalTextColor;
	ctrl->highlightedTextColor = highlightedTextColor;
	ctrl->highlightedFillColor = highlightedFillColor;
	ctrl->doubleLinesFlag = doubleLinesFlag;
}

void ScummEngine::drawInternalGUIControl(int id, bool highlightColor) {
	InternalGUIControl *ctrl;
	int relCentX, relCentY, textHeight;
	int x, y, textXPos, textYPos;
	int textColor, fillColor;
	int boxSizeX, boxSizeY;
	int offset = (_game.version == 8 || _game.id == GID_DIG) ? 2 : 1;
	int topComp = (_game.version < 8) ? _screenTop : 0;

	bool centerFlag;
	char buttonString[512];

	bool isSaveSlot = (id >= GUI_CTRL_FIRST_SG && id <= GUI_CTRL_LAST_SG) && _game.platform != Common::kPlatformSegaCD;

	ctrl = &_internalGUIControls[id];
	relCentX = ctrl->relativeCenterX;
	if (ctrl->relativeCenterX != -1) {
		relCentY = ctrl->relativeCenterY;
		x = ctrl->xPos;
		y = ctrl->yPos;

		boxSizeX = x - ((_game.version == 8) ? ctrl->relativeCenterX : 0);
		boxSizeY = y - ((_game.version == 8) ? relCentY : 0);

		fillColor = highlightColor ? ctrl->highlightedFillColor : ctrl->normalFillColor;

		if (ctrl->doubleLinesFlag) {
			// Draw the main box...
			drawBox(relCentX + 1, relCentY + 1 + topComp, boxSizeX - offset, boxSizeY - offset + topComp, fillColor);

			if (_game.version == 4 && _game.id != GID_LOOM) {
				// This is for MI1 v4 (EGA and VGA floppy versions) and the Passport to Adventure demo;
				// these games use a very early version of this GUI system, with only
				// one line color; we will use the topLineColor to mimick that.

				// Draw the contour lines...
				drawBox(relCentX + 2, relCentY, x - 2, relCentY, ctrl->topLineColor);
				drawBox(relCentX + 2, y, x - 2, y, ctrl->topLineColor);
				drawBox(relCentX, relCentY + 2, relCentX, y - 2, ctrl->topLineColor);
				drawBox(x, relCentY + 2, x, y - 2, ctrl->topLineColor);

				// Draw single pixels for the button roundness effect...
				drawBox(relCentX + 1, relCentY + 1, relCentX + 1, relCentY + 1, ctrl->topLineColor);
				drawBox(x - 1, relCentY + 1, x - 1, relCentY + 1, ctrl->topLineColor);
				drawBox(relCentX + 1, y - 1, relCentX + 1, y - 1, ctrl->topLineColor);
				drawBox(x - 1, y - 1, x - 1, y - 1, ctrl->topLineColor);
			} else {
				// Draw the contour lines for the box; each of the lines is doubled to give a 3D effect.
				drawLine(relCentX + 1, relCentY, x - 1, relCentY, ctrl->topLineColor);
				drawLine(relCentX + 1, y, x - 1, y, ctrl->bottomLineColor);
				drawLine(relCentX, relCentY + 1, relCentX, y - 1, ctrl->leftLineColor);
				drawLine(x, relCentY + 1, x, y - 1, ctrl->rightLineColor);

				drawLine(relCentX + 1, relCentY + 1, x - 1, relCentY + 1, ctrl->topLineColor);
				drawLine(relCentX + 1, y - 1, x - 1, y - 1, ctrl->bottomLineColor);
				drawLine(relCentX + 1, relCentY + 1, relCentX + 1, y - 1, ctrl->leftLineColor);
				drawLine(x - 1, relCentY + 1, x - 1, y - 1, ctrl->rightLineColor);
			}
		} else {
			drawBox(relCentX, relCentY + topComp, x, y + topComp, (highlightColor ? ctrl->highlightedFillColor : ctrl->normalFillColor));
			if (_game.version == 4 && _game.id != GID_LOOM) {
				drawBox(relCentX, relCentY, x, relCentY, ctrl->topLineColor);
				drawBox(relCentX, y, x, y, ctrl->bottomLineColor);
				drawBox(relCentX, relCentY, relCentX, y, ctrl->leftLineColor);
				drawBox(x, relCentY, x, y, ctrl->rightLineColor);
			} else {
				drawLine(relCentX, relCentY, x, relCentY, ctrl->topLineColor);
				drawLine(relCentX, y, x, y, ctrl->bottomLineColor);
				drawLine(relCentX, relCentY, relCentX, y, ctrl->leftLineColor);
				drawLine(x, relCentY, x, y, ctrl->rightLineColor);
			}
		}

		// Calculate the positioning for the text
		int oldId = _charset->getCurID();
		if (_game.id == GID_LOOM) {
			_charset->setCurID(_game.version > 3 ? 1 : 0);
		} else {
			_charset->setCurID(_game.platform == Common::kPlatformSegaCD ? 6 : 1);
		}


		centerFlag = ctrl->centerText;

		textHeight = getGUIStringHeight(ctrl->label.c_str());

		if (centerFlag)
			textXPos = relCentX + (x - ctrl->relativeCenterX) / 2;
		else
			textXPos = relCentX + 2;

		if (_game.version == 8 || _game.id == GID_DIG)
			textYPos = relCentY + (y - relCentY - textHeight) / 2 + 1;
		else
			textYPos = relCentY + (y - 8 - relCentY + 2) / 2;

		// Finally, choose the color and draw the text message
		if (highlightColor)
			textColor = ctrl->highlightedTextColor;
		else
			textColor = ctrl->normalTextColor;

		Common::strlcpy(buttonString, ctrl->label.c_str(), sizeof(buttonString));

		if ((id >= GUI_CTRL_FIRST_SG && id <= GUI_CTRL_LAST_SG) &&
			_mainMenuSavegameLabel == id && _menuPage == GUI_PAGE_SAVE) {
			Common::strlcat(buttonString, "_", sizeof(buttonString));
		}

		if ((id == GUI_CTRL_ARROW_UP_BUTTON || id == GUI_CTRL_ARROW_DOWN_BUTTON) && _useCJKMode && _game.id == GID_DIG) {
			// Instead of printing the "normal" arrow glyphs, the DIG CJK interpreter draws slightly larger arrows
			// using the drawLine function. Instead of making a row of 14 drawLine calls here (like the original),
			// I have implemented it like this...
			static const int8 drwOffsets[2][29] = {
				{ 0, 13, -5, 18, -5, 18, -3, 18, -3, 18, -3, 33, 0, 13, 5, 18, 5, 18, 3, 18, 3, 18, 3, 33, -3, 33, 3, 33, -1 },
				{ 0, 33, -5, 28, -5, 28, -3, 28, -3, 28, -3, 13, 0, 33, 5, 28, 5, 28, 3, 28, 3, 28, 3, 13, -3, 13, 3, 13, -1 }
			};

			for (const int8 *s = drwOffsets[id - GUI_CTRL_ARROW_UP_BUTTON]; *s != -1; s += 4)
				drawLine(textXPos + s[0], relCentY + s[1], textXPos + s[2], relCentY + s[3], textColor);

		} else if (_isIndy4Jap) {
			Common::Rect indyClipRect(relCentX, relCentY, x, y);
			textYPos = (y - relCentY) / 2 + relCentY;
			if ((id < GUI_CTRL_FIRST_SG) || (id > GUI_CTRL_LAST_SG && id != GUI_CTRL_PATH_BUTTON)) {
				textYPos -= 7;
			} else {
				textYPos -= 3;
			}

			drawGUIText(buttonString, isSaveSlot ? &indyClipRect : nullptr, textXPos, textYPos, textColor, centerFlag);
		} else {
			int tmpRight = _string[5].right;
			bool nudgeJapYPos = _language == Common::JA_JPN;

			if (_game.platform == Common::kPlatformSegaCD) {
				nudgeJapYPos &= !(id >= GUI_CTRL_NUMPAD_1 && id <= GUI_CTRL_NUMPAD_0);
				nudgeJapYPos &= (id != GUI_CTRL_NUMPAD_BACK);
				nudgeJapYPos &= (id != GUI_CTRL_ARROW_LEFT_BUTTON);
				nudgeJapYPos &= (id != GUI_CTRL_ARROW_RIGHT_BUTTON);
				nudgeJapYPos &= (id != GUI_CTRL_TEXT_SPEED_SLIDER);

				textYPos -= nudgeJapYPos ? 4 : 2;

				textXPos += 1;
			}

			_string[5].right = _screenWidth - 1;

			// The original CJK DIG interpreter limits the clipping to the save slots. Other elements
			// seem to (theoretically) be allowed to draw text wherever they want...
			Common::Rect clipRect(relCentX, relCentY, x, y);
			drawGUIText(buttonString, isSaveSlot ? &clipRect : nullptr, textXPos, textYPos, textColor, centerFlag);

			_string[5].right = tmpRight;
		}

		// Restore the previous charset
		if (oldId)
			_charset->setCurID(oldId);
	}
}

int ScummEngine::getInternalGUIControlFromCoordinates(int x, int y) {
	int id = 0;
	while (_internalGUIControls[id].relativeCenterX == -1 ||
		   _internalGUIControls[id].relativeCenterX > x ||
		   _internalGUIControls[id].xPos < x ||
		   _internalGUIControls[id].relativeCenterY > y ||
		   _internalGUIControls[id].yPos < y) {

		id++;
		if (id >= ARRAYSIZE(_internalGUIControls))
			return -1;
	}
	return id;
}


#ifdef ENABLE_SCUMM_7_8
void ScummEngine_v7::queryQuit(bool returnToLauncher) {
	if (isUsingOriginalGUI()) {
		if (_quitFromScriptCmd && !(_game.version == 8 && _currentRoom == 92)) {
			_quitByGUIPrompt = true;
			if (returnToLauncher) {
				Common::Event event;
				event.type = Common::EVENT_RETURN_TO_LAUNCHER;
				getEventManager()->pushEvent(event);
			} else {
				quitGame();
			}

			_quitFromScriptCmd = false;
		}

		if (_game.version == 8 && !(_game.features & GF_DEMO) &&
			((ConfMan.hasKey("confirm_exit") && ConfMan.getBool("confirm_exit")) || (_currentRoom == 92 && _quitFromScriptCmd))) {

			int boxWidth, strWidth;
			int ctrlId;
			char yesLabelPtr[512];
			char noLabelPtr[512];
			char msgLabelPtr[512];
			byte *curGrabbedCursor;
			int curCursorWidth, curCursorHeight, curCursorHotspotX, curCursorHotspotY, curCursorState;

			_messageBannerActive = true;
			_comiQuitMenuIsOpen = true;

			int oldScreenTop = _screenTop;
			if (isSmushActive())
				_screenTop = 0;

			// Force the cursor to be ON...
			int8 oldCursorState = _cursor.state;
			_cursor.state = 1;
			CursorMan.showMouse(_cursor.state > 0);

			// "Are you sure you want to quit?"
			convertMessageToString((const byte *)getGUIString(gsQuitPrompt), (byte *)msgLabelPtr, sizeof(msgLabelPtr));
			// "Yes"
			convertMessageToString((const byte *)getGUIString(gsYes), (byte *)yesLabelPtr, sizeof(yesLabelPtr));
			// "No"
			convertMessageToString((const byte *)getGUIString(gsNo), (byte *)noLabelPtr, sizeof(noLabelPtr));

			// Pause the engine...
			PauseToken pt = pauseEngine();

			// Backup the current cursor graphics and parameters
			// and set up the internal v8 cursor...
			curGrabbedCursor = (byte *)malloc(sizeof(_grabbedCursor));
			memcpy(curGrabbedCursor, _grabbedCursor, sizeof(_grabbedCursor));
			curCursorState = isSmushActive() ? 0 : _cursor.state;
			curCursorWidth = _cursor.width;
			curCursorHeight = _cursor.height;
			curCursorHotspotX = _cursor.hotspotX;
			curCursorHotspotY = _cursor.hotspotY;
			setDefaultCursor();
			CursorMan.showMouse(true);

			// Backup the current charsetId, since we're going to switch
			// to charsetId == 1 and start taking measurements for the box...
			int oldId = _charset->getCurID();
			_charset->setCurID(1);

			boxWidth = ((getGUIStringWidth(msgLabelPtr) + 32) & 0xFFF0) + 8;
			if (boxWidth <= 400)
				boxWidth = 400;

			// Set up and draw the main box
			setUpInternalGUIControl(
				0,
				getBannerColor(33),
				getBannerColor(32),
				getBannerColor(34),
				getBannerColor(35),
				getBannerColor(36),
				getBannerColor(37),
				0,
				0,
				320 - boxWidth / 2,
				190,
				boxWidth / 2 + 319,
				-90,
				_emptyMsg,
				true,
				true);

			// Save the pixels which will be overwritten by the dialog,
			// so that we can restore them later. Note that the interpreter
			// doesn't do this, but we have to...
			if (!_bannerMem && !isSmushActive()) {
				_bannerMemSize = _screenWidth * _screenHeight;
				_bannerMem = (byte *)malloc(_bannerMemSize * sizeof(byte));
				if (_bannerMem)
					memcpy(
						_bannerMem,
						_virtscr[kMainVirtScreen].getPixels(0, _screenTop),
						_bannerMemSize);
			}

			drawInternalGUIControl(0, 0);

			// The text is drawn as a separate entity
			drawTextImmediately((const byte *)msgLabelPtr, &_defaultTextClipRect, 320, 200, getBannerColor(32), 1, (TextStyleFlags) true);

			// Now set up and draw the Yes and No buttons...
			if (getGUIStringWidth(noLabelPtr) <= getGUIStringWidth(yesLabelPtr)) {
				strWidth = getGUIStringWidth(yesLabelPtr);
			} else {
				strWidth = getGUIStringWidth(noLabelPtr);
			}

			if (strWidth <= 120)
				strWidth = 120;

			setUpInternalGUIControl(
				0,
				getBannerColor(45),
				getBannerColor(44),
				getBannerColor(46),
				getBannerColor(47),
				getBannerColor(48),
				getBannerColor(49),
				0,
				0,
				420 - (strWidth / 2),
				240, -strWidth,
				-30,
				noLabelPtr,
				true,
				true);

			drawInternalGUIControl(0, 0);

			setUpInternalGUIControl(
				0,
				getBannerColor(39),
				getBannerColor(38),
				getBannerColor(40),
				getBannerColor(41),
				getBannerColor(42),
				getBannerColor(43),
				0,
				0,
				220 - (strWidth / 2),
				240,
				-strWidth,
				-30,
				yesLabelPtr,
				true,
				true);

			drawInternalGUIControl(0, 0);

			// Done, draw everything to screen!
			ScummEngine::drawDirtyScreenParts();

			// Stay in the dialog while we keep pressing CTRL-C...
			Common::KeyState ks;
			bool leftBtnPressed = false, rightBtnPressed = false;
			do {
				clearClickedStatus();
				ks = Common::KEYCODE_INVALID;
				waitForBannerInput(-1, ks, leftBtnPressed, rightBtnPressed);
			} while (ks.keycode == Common::KEYCODE_LCTRL ||
					 ks.keycode == Common::KEYCODE_RCTRL ||
					 (ks.keycode == Common::KEYCODE_c && ks.hasFlags(Common::KBD_CTRL)));

			ctrlId = getInternalGUIControlFromCoordinates(_mouse.x, _mouse.y);
			if ((leftBtnPressed && ctrlId == 0) || (toupper(ks.ascii) == yesLabelPtr[0])) {
				_quitByGUIPrompt = true;
				if (returnToLauncher) {
					Common::Event event;
					event.type = Common::EVENT_RETURN_TO_LAUNCHER;
					getEventManager()->pushEvent(event);
				} else {
					quitGame();
				}
			}

			// Restore the previous cursor...
			_cursor.state = curCursorState;
			CursorMan.showMouse(_cursor.state > 0);
			setCursorHotspot(curCursorHotspotX, curCursorHotspotY);
			setCursorFromBuffer(curGrabbedCursor, curCursorWidth, curCursorHeight, curCursorWidth);
			free(curGrabbedCursor);

			// The interpreter makes us wait 45 full frames;
			// let's wait half that time...
			waitForTimer(45 * 2);

			// Again, he interpreter does not explicitly restore the screen
			// after finishing displaying this query dialog, but we have to...
			if (_bannerMem && !isSmushActive()) {
				memcpy(
					_virtscr[kMainVirtScreen].getPixels(0, _screenTop),
					_bannerMem,
					_bannerMemSize);
				free(_bannerMem);
				_bannerMem = nullptr;

				markRectAsDirty(_virtscr[kMainVirtScreen].number, 0, _screenWidth + 8, _screenTop, _screenHeight + _screenTop);
				ScummEngine::drawDirtyScreenParts();
				_system->updateScreen();
			}

			// Finally, resume the engine, clear the input state, and restore the charset.
			pt.clear();
			clearClickedStatus();
			if (oldId)
				_charset->setCurID(oldId);

			// Restore the old cursor state...
			_cursor.state = oldCursorState;
			CursorMan.showMouse(_cursor.state > 0);

			_comiQuitMenuIsOpen = false;
			_messageBannerActive = false;

			if (isSmushActive())
				_screenTop = oldScreenTop;
		} else {
			ScummEngine::queryQuit(returnToLauncher);
		}
	} else {
		ScummEngine::confirmExitDialog();
	}
}

const char *ScummEngine_v8::getGUIString(int stringId) {
	InfoDialog d(this, 0);
	int resStringId = -1;

	switch (stringId) {
	case gsPause:
		resStringId = 4;
		break;
	case gsRestart:
		resStringId = (_game.features & GF_DEMO) ? 36 : 5;
		break;
	case gsQuitPrompt:
		resStringId = (_game.features & GF_DEMO) ? 30 : 22;
		break;
	case gsYes:
		resStringId = 23;
		break;
	case gsNo:
		resStringId = 24;
		break;
	case gsIMuseBuffer:
		resStringId = 25;
		break;
	case gsVoiceAndText:
		resStringId = 26;
		break;
	case gsTextDisplayOnly:
		resStringId = 27;
		break;
	case gsVoiceOnly:
		resStringId = 28;
		break;
	case gsYesKey:
		resStringId = 29;
		break;
	case gsTextSpeedSlider:
		resStringId = 31;
		break;
	case gsMusicVolumeSlider:
		resStringId = 32;
		break;
	case gsVoiceVolumeSlider:
		resStringId = 33;
		break;
	case gsSfxVolumeSlider:
		resStringId = 34;
		break;
	case gsHeap:
		resStringId = 35;
		break;
	default:
		break;
	}

	if (resStringId > 0)
		return d.getPlainEngineString(resStringId);
	else
		return _emptyMsg;
}

const char *ScummEngine_v7::getGUIString(int stringId) {
	InfoDialog d(this, 0);
	int resStringId = -1;

	switch (stringId) {
	case gsPause:
		resStringId = 4;
		break;
	case gsRestart:
		resStringId = 5;
		break;
	case gsQuitPrompt:
		resStringId = 6;
		break;
	case gsSave:
		resStringId = 7;
		break;
	case gsLoad:
		resStringId = 8;
		break;
	case gsPlay:
		resStringId = 9;
		break;
	case gsCancel:
		resStringId = 10;
		break;
	case gsQuit:
		resStringId = 11;
		break;
	case gsOK:
		resStringId = 12;
		break;
	case gsMustName:
		resStringId = 14;
		break;
	case gsGameNotSaved:
		resStringId = 15;
		break;
	case gsGameNotLoaded:
		resStringId = 16;
		break;
	case gsSaving:
		resStringId = 17;
		break;
	case gsLoading:
		resStringId = 18;
		break;
	case gsNamePrompt:
		resStringId = 19;
		break;
	case gsSelectLoadPrompt:
		resStringId = 20;
		break;
	case gsSavePath:
		resStringId = 21;
		break;
	case gsTitle:
		resStringId = 22;
		break;
	case gsYes:
		break;
	case gsNo:
		break;
	case gsMusic:
		resStringId = 41;
		break;
	case gsVoice:
		resStringId = 42;
		break;
	case gsSfx:
		resStringId = 43;
		break;
	case gsDisabled:
		resStringId = 44;
		break;
	case gsTextSpeed:
		resStringId = 45;
		break;
	case gsDisplayText:
		resStringId = 46;
		break;
	case gsVersion:
		resStringId = 47;
		break;
	case gsSpooledMusic:
		resStringId = 48;
		break;
	case gsReplacePrompt:
		resStringId = 49;
		break;
	case gsVoiceOnly:
		if (_game.id == GID_FT &&
			(_language != Common::EN_ANY && _language != Common::RU_RUS)) {
			resStringId = 52;
		} else {
			resStringId = 50;
		}

		break;
	case gsVoiceAndText:
		resStringId = 51;
		break;
	case gsTextDisplayOnly:
		if (_game.id == GID_FT &&
			(_language != Common::EN_ANY && _language != Common::RU_RUS)) {
			resStringId = 50;
		} else {
			resStringId = 52;
		}
		break;
	case gsTextSpeedSlider:
		resStringId = 53;
		break;
	case gsMusicVolumeSlider:
		resStringId = 54;
		break;
	case gsVoiceVolumeSlider:
		resStringId = 55;
		break;
	case gsSfxVolumeSlider:
		resStringId = 56;
		break;
	case gsHeap:
		resStringId = 57;
		break;
	case gsIMuseBuffer:
		resStringId = 58;
		break;
	default:
		break;
	}

	const char *res =  (resStringId > 0) ? d.getPlainEngineString(resStringId) : _emptyMsg;

	if (_game.id == GID_DIG && resStringId > 0) {
		convertMessageToString((const byte*)res, _guiStringTransBuff, 512);
		res = (const char*)_guiStringTransBuff;
	}

	return res;
}

int ScummEngine_v7::getGUIStringHeight(const char *str) {
	return _textV7->getStringHeight(str);
}

int ScummEngine_v7::getGUIStringWidth(const char *str) {
	return _textV7->getStringWidth(str);
}

void ScummEngine_v7::drawGUIText(const char *buttonString, Common::Rect *clipRect, int textXPos, int textYPos, int textColor, bool centerFlag) {
	drawTextImmediately((const byte *)buttonString, clipRect, textXPos, textYPos, textColor, 1, (TextStyleFlags)centerFlag);
}

int ScummEngine_v7::getMusicVolume() {
	return CLIP<int>(ConfMan.getInt("music_volume") / 2, 0, 127);
}

int ScummEngine_v7::getSpeechVolume() {
	return CLIP<int>(ConfMan.getInt("speech_volume") / 2, 0, 127);
}

int ScummEngine_v7::getSFXVolume() {
	return CLIP<int>(ConfMan.getInt("sfx_volume") / 2, 0, 127);
}

void ScummEngine_v7::setMusicVolume(int volume) {
	_imuseDigital->diMUSESetMusicGroupVol(CLIP<int>(volume, 0, 127));
	ScummEngine::setMusicVolume(CLIP<int>(volume, 0, 127));
}

void ScummEngine_v7::setSpeechVolume(int volume) {
	ScummEngine::setSpeechVolume(CLIP<int>(volume, 0, 127));
	_imuseDigital->diMUSESetVoiceGroupVol(CLIP<int>(volume, 0, 127));
}

void ScummEngine_v7::setSFXVolume(int volume) {
	ScummEngine::setSFXVolume(CLIP<int>(volume, 0, 127));
	_imuseDigital->diMUSESetSFXGroupVol(CLIP<int>(volume, 0, 127));
}

void ScummEngine_v7::toggleVoiceMode() {
	ScummEngine::toggleVoiceMode();
	if (VAR_VOICE_MODE != 0xFF) {
		_splayer->setChanFlag(0, VAR(VAR_VOICE_MODE) != 0);
		_splayer->setChanFlag(2, VAR(VAR_VOICE_MODE) != 2);
	}
}

void ScummEngine_v7::handleLoadDuringSmush() {
	// Notify the SMUSH player that we want to load a game...
	_saveLoadFlag = 2;
	_saveLoadSlot = _mainMenuSavegameLabel - 1 + _curDisplayedSaveSlotPage * 9;

	// Force screen to black to avoid glitches...
	VirtScreen *vs = &_virtscr[kMainVirtScreen];
	memset(vs->getPixels(0, 0), 0, vs->pitch * vs->h);
	vs->setDirtyRange(0, vs->h);
	ScummEngine::drawDirtyScreenParts();

	// The original at this point does this, but we automatically
	// handle the corresponding operations automatically in our
	// SMUSH player...
	//
	//_splayer->release();
	//_splayer->resetAudioTracks();
}

int ScummEngine_v7::getBannerColor(int bannerId) {
	if (_game.version == 8) {
		byte *palette = isSmushActive() ? _splayer->getVideoPalette() : _currentPalette;
		byte r, g, b;
		r = (_bannerColors[bannerId] >> 0) & 0xFF;
		g = (_bannerColors[bannerId] >> 8) & 0xFF;
		b = (_bannerColors[bannerId] >> 16) & 0xFF;
		return getPaletteColorFromRGB(palette, r, g, b);
	}

	int color = readArray(88, 0, bannerId);
	if (isSmushActive()) {
		color = (int)getPaletteColorFromRGB(_splayer->getVideoPalette(),
											_currentPalette[3 * color + 0],
											_currentPalette[3 * color + 1],
											_currentPalette[3 * color + 2]);
	}

	return color;
}
#endif

int ScummEngine_v4::getBannerColor(int bannerId) {
	const byte *palette = (_renderMode == Common::kRenderCGA) ? _GUIPaletteCGA : _GUIPalette;

	return (int)palette[bannerId - 6];
}

int ScummEngine_v6::getBannerColor(int bannerId) {
	return readArray(110, 0, bannerId);
}

int ScummEngine::getBannerColor(int bannerId) {
	byte *arrAddr = getResourceAddress(rtString, 21);
	return (int)arrAddr[bannerId];
}

void ScummEngine::saveSurfacesPreGUI() {
	// Why are we saving three surfaces? Bear with me:
	// texts in v6 and below are drawn sometimes onto the main surface, while
	// other times they are drawn onto the text surface.
	//
	// Now, the original interpreters just killed every text after the
	// menu is closed; this includes dialog texts, plain printed strings and
	// possibly more.
	//
	// We can do better than that! Let's save both the main and the text surfaces
	// so that we can restore them later when we're done with the menu.
	//
	// Some edge cases can happen though: i.e. during the SAMNMAX credits there's
	// not enough space for the menu to be drawn completely on the main surface,
	// so the last line is being drawn on the verb surface; to address this, we
	// save and restore that too.

	if (_game.version < 3 || _game.version > 6 ||
		(_game.version == 3 && _game.platform == Common::kPlatformFMTowns))
		return;

	_tempTextSurface = (byte *)malloc(_textSurface.pitch * _textSurface.h * sizeof(byte));
	_tempMainSurface = (byte *)malloc(_virtscr[kMainVirtScreen].w * _virtscr[kMainVirtScreen].h * sizeof(byte));
	_tempVerbSurface = (byte *)malloc(_virtscr[kVerbVirtScreen].w * _virtscr[kVerbVirtScreen].h * sizeof(byte));

	if (_tempMainSurface) {
		for (int y = 0; y < _virtscr[kMainVirtScreen].h; y++) {
			memcpy(&_tempMainSurface[y * _virtscr[kMainVirtScreen].w],
				_virtscr[kMainVirtScreen].getBasePtr(_virtscr[kMainVirtScreen].xstart, y),
				_virtscr[kMainVirtScreen].w);
		}
	}

	if (_tempVerbSurface) {
		memcpy(_tempVerbSurface,
			_virtscr[kVerbVirtScreen].getBasePtr(0, 0),
			_virtscr[kVerbVirtScreen].pitch * _virtscr[kVerbVirtScreen].h);
	}

	if (_tempTextSurface) {
		memcpy(_tempTextSurface, _textSurface.getBasePtr(0, 0), _textSurface.pitch * _textSurface.h);

		// For each v4-v6 game (except for LOOM VGA which does its own thing), we take the text surface
		// and stamp it on top of the main screen: this is done to ensure that the GUI is drawn on top
		// of possible subtitle texts instead of having the latters being deleted or being drawn on top
		// of the GUI...
		if (!(_game.version == 4 && _game.id == GID_LOOM) &&
			!(_game.version == 5 && _game.platform == Common::kPlatformFMTowns)) {
			for (int y = 0; y < _screenHeight; y++) {
				for (int x = 0; x < _screenWidth; x++) {
					// Only draw non transparent pixels
					if (_tempTextSurface[x + y * _screenWidth] != 0xFD) {
						if (x < _virtscr[kMainVirtScreen].pitch && y < _virtscr[kMainVirtScreen].h)
							_virtscr[kMainVirtScreen].setPixel((_virtscr[kMainVirtScreen].xstart + x) % _virtscr[kMainVirtScreen].pitch,
								y + (_virtscr[kMainVirtScreen].xstart + x) / _virtscr[kMainVirtScreen].pitch, _tempTextSurface[x + y * _screenWidth]);
					}
				}
			}
		}

		// A bit of trickery to prevent in-game texts to be positioned on top of the GUI banners:
		// draw transparent lines on the text surface, over the area of the main virtual screen.
		if (_game.id == GID_LOOM && _game.version == 3 && _game.platform != Common::kPlatformFMTowns) {
			int yBegin = _virtscr[kMainVirtScreen].topline;
			int yEnd = _virtscr[kMainVirtScreen].topline + _virtscr[kMainVirtScreen].h;
			for (int y = yBegin; y < yEnd; y++) {
				memset(_textSurface.getBasePtr(0, y), 0xFD, _virtscr[kMainVirtScreen].w);
			}
		}
	}
}

void ScummEngine::restoreSurfacesPostGUI() {

	if (_game.version < 3 || _game.version > 6 ||
		(_game.version == 3 && _game.platform == Common::kPlatformFMTowns))
		return;

	if (_tempTextSurface) {
		memcpy(_textSurface.getBasePtr(0, 0), _tempTextSurface, _textSurface.pitch * _textSurface.h);

		// Signal the restoreCharsetBg() function that there's text
		// on the text surface, so it gets deleted the next time another
		// text is displayed. Just don't do that for LOOM, or it might
		// randomly cause the distaff to disappear on rare occasions. :-)
		if (_game.id != GID_LOOM) {
			_postGUICharMask = true;
		}

		free(_tempTextSurface);
		_tempTextSurface = nullptr;
	}

	if (_tempMainSurface) {
		for (int y = 0; y < _virtscr[kMainVirtScreen].h; y++) {
			memcpy(_virtscr[kMainVirtScreen].getBasePtr(_virtscr[kMainVirtScreen].xstart, y),
				&_tempMainSurface[y * _virtscr[kMainVirtScreen].w],
				_virtscr[kMainVirtScreen].w);
		}

		free(_tempMainSurface);
		_tempMainSurface = nullptr;

		_virtscr[kMainVirtScreen].setDirtyRange(0, _virtscr[kMainVirtScreen].h);
	}

	if (_tempVerbSurface) {
		memcpy(_virtscr[kVerbVirtScreen].getBasePtr(0, 0),
			_tempVerbSurface,
			_virtscr[kVerbVirtScreen].pitch * _virtscr[kVerbVirtScreen].h);

		free(_tempVerbSurface);
		_tempVerbSurface = nullptr;

		_virtscr[kVerbVirtScreen].setDirtyRange(0, _virtscr[kVerbVirtScreen].h);
	}
}

void ScummEngine::showDraftsInventory() {
	bool leftMsClicked = false, rightMsClicked = false;

	// FM-Towns stuff...
	int textSurfBannerMemSize = 0;
	byte *textSurfBannerMem = nullptr;
	int rowSize = _screenWidth;
	int draftsWidgetHeight = _virtscr[kMainVirtScreen].h;
	int screenMemSize = 0;
	byte *screenMem = nullptr;

	Common::KeyState ks;

	// Pause the engine...
	PauseToken pt = pauseEngine();

	_shakeTempSavedState = _shakeEnabled;
	setShake(0);

	// Save surfaces...
	if (_game.platform != Common::kPlatformFMTowns) {
		saveSurfacesPreGUI();
	} else {
		// FM-Towns games draw GUI elements on the text surface, so let's save that
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
		rowSize *= _textSurfaceMultiplier;
		textSurfBannerMemSize = (draftsWidgetHeight) * rowSize * _textSurfaceMultiplier;
		textSurfBannerMem = (byte *)malloc(textSurfBannerMemSize * sizeof(byte));
		if (textSurfBannerMem) {
			memcpy(
				textSurfBannerMem,
				((byte *)_textSurface.getBasePtr(0, _screenTop * _textSurfaceMultiplier)),
				textSurfBannerMemSize);
		}

		// We're going to use these same values for saving the
		// virtual screen surface, so let's un-multiply them...
		rowSize /= _textSurfaceMultiplier;
#endif

		screenMemSize = (draftsWidgetHeight) * (rowSize);
		screenMem = (byte *)malloc(screenMemSize * sizeof(byte));
		if (screenMem) {
			memcpy(
				screenMem,
				_virtscr[kMainVirtScreen].getPixels(0, _screenTop),
				screenMemSize);
		}
	}

	// Save the current cursor state...
	saveCursorPreMenu();

	// Do the thing!
	setUpDraftsInventory();
	drawDraftsInventory();

	// Notify that the menu is now active
	_mainMenuIsActive = true;

	// Clear keypresses and mouse presses
	clearClickedStatus();

	// Menu loop
	while (!shouldQuit()) {
		// Update the screen and the cursor while we're in the loop
		waitForTimer(1);

		// Wait for any mouse button presses...
		waitForBannerInput(-1, ks, leftMsClicked, rightMsClicked, false);

		if (leftMsClicked || rightMsClicked) {
			break;
		}
	}

	_mainMenuIsActive = false;

	// Restore the old cursor state...
	restoreCursorPostMenu();

	// Restore surfaces...
	if (_game.platform != Common::kPlatformFMTowns) {
		restoreSurfacesPostGUI();
	} else {
		// FM-Towns games draw GUI elements on the text surface, so restore both surfaces...
#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
		if (_game.platform == Common::kPlatformFMTowns && textSurfBannerMem) {
			rowSize *= _textSurfaceMultiplier;
			memcpy(
				((byte *)_textSurface.getBasePtr(0, _screenTop * _textSurfaceMultiplier)),
				textSurfBannerMem,
				textSurfBannerMemSize);

			// We're going to use these same values for restoring the
			// virtual screen surface, so let's un-multiply them...
			rowSize /= _textSurfaceMultiplier;

			free(textSurfBannerMem);
			textSurfBannerMem = nullptr;
		}
#endif

		if (screenMem) {
			memcpy(
				_virtscr[kMainVirtScreen].getPixels(0, _screenTop),
				screenMem,
				screenMemSize);

			markRectAsDirty(_virtscr[kMainVirtScreen].number, 0, rowSize, _screenTop, _screenHeight + _screenTop);
			ScummEngine::drawDirtyScreenParts();
			_system->updateScreen();

			free(screenMem);
			screenMem = nullptr;
		}
	}

	// Restore shake effect...
	setShake(_shakeTempSavedState);

	// Resume the engine.
	pt.clear();
	clearClickedStatus();
}

void ScummEngine::setUpDraftsInventory() {
	int yConstant = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);
	bool isLoomVGA = (_game.version == 4) || _game.platform == Common::kPlatformFMTowns;

	// French&Hebrew labels are quite long, so throughout the following code
	// there are slight adjustments to French&Hebrew text positioning...
	bool isLongLanguage = _language == Common::FR_FRA || _language == Common::HE_ISR || _language == Common::RU_RUS;
	int xOffset = isLongLanguage ? 10 : 0;

	if (isLoomVGA) {
		setUpInternalGUIControl(GUI_CTRL_OUTER_BOX,
			7,
			0,
			15,
			8,
			15,
			8,
			14,
			1 ,
			20,
			yConstant - 60,
			300,
			((yConstant + 60) < 0 ? -120 : yConstant + 60),
			_emptyMsg, 1, 1);

		// Inner box
		setUpInternalGUIControl(GUI_CTRL_INNER_BOX,
			7,
			0,
			8,
			15,
			8,
			15,
			14,
			1,
			26,
			yConstant - 47,
			300 - 6,
			yConstant - 47 + 102,
			_emptyMsg, 1, 1);
	} else {
		setUpInternalGUIControl(GUI_CTRL_OUTER_BOX,
			getBannerColor(4),
			getBannerColor(2),
			getBannerColor(14),
			getBannerColor(14),
			getBannerColor(14),
			getBannerColor(14),
			getBannerColor(6),
			getBannerColor(4),
			20 - xOffset,
			yConstant - 60,
			300 + xOffset,
			((yConstant + 60) < 0 ? -120 : yConstant + 60),
			_emptyMsg, 1, 0);

		// Inner box
		setUpInternalGUIControl(GUI_CTRL_INNER_BOX,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(13),
			getBannerColor(13),
			getBannerColor(13),
			getBannerColor(13),
			getBannerColor(6),
			getBannerColor(7),
			26 - xOffset,
			yConstant - 47,
			300 - 6 + xOffset,
			yConstant - 47 + 102,
			_emptyMsg, 1, 0);
	}
}

static const char *loomDraftsNames[7][18] = {
	// ENGLISH
	{
		"Drafts",
		"Opening:",       "Straw Into Gold:",  "Dyeing:",
		"Night Vision:",  "Twisting:",         "Sleep:",
		"Emptying:",      "Invisibility:",     "Terror:",
		"Sharpening:",    "Reflection:",       "Healing:",
		"Silence:",       "Shaping:",          "Unmaking:",
		"Transcendence:",
		"Unknown:"
	},

	// GERMAN
	{
		"Spr\x81\x63he",
		"\x99\x66\x66nen:",  "Stroh in Gold:",   "F\x84rben:",
		"Dunkelsicht:",      "Verdrehen:",       "Schlaf:",
		"Entleeren:",        "Unsichtbarkeit:",  "Angst:",
		"Sch\x84rfen:",      "Spiegelung:",      "Heilen:",
		"Stille:",           "Formen:",          "Zerst\x94ren:",
		"Transzendenz:",
		"Unbekannt:"
	},

	// FRENCH
	{
		"Trames",
		"Ouverture:",            "De la paille \x85 l'or:",  "Teinture:",
		"Vision de nuit:",       "Trame tordue:",            "Sommeil:",
		"Vidange:",              "Camouflage:",              "Terreur:",
		"Trame \x85 aiguiser:",  "Reflet:",                  "Gu\x82rison:",
		"Silence:",              "Formation:",               "Trame d\x82\x66\x61ite:",
		"Transcendance:",
		"Inconnu:"
	},

	// SPANISH
	{
		"Hechizos",
		"Apertura:",            "Oro a Paja:",     "Tinte:",
		"Visi\xA2n Nocturna:",  "Retorcer:",       "Sue\xA4o:",
		"Vacio:",               "Invisibilidad:",  "Terror:",
		"Afilado:",             "Reflexion:",      "Curativo:",
		"Silencio:",            "Moldear:",        "Deshacer:",
		"Trascendencia:",
		"Desconocido:"
	},

	// JAPANESE
	{
		"\x82\xdc\x82\xb6\x82\xc8\x82\xa2",
		"\x8a\x4a\x82\xaf\x82\xe9:",
		"\x82\xed\x82\xe7\x82\xf0\x8b\xe0\x89\xdd\x82\xc9\x95\xcf\x82\xa6\x82\xe9:",
		"\x90\xf5\x82\xdf\x82\xe9:",
		"\x88\xc3\x88\xc5\x82\xc5\x95\xa8\x82\xf0\x8c\xa9\x82\xa6:",
		"\x82\xcb\x82\xb6\x82\xe9:",
		"\x96\xb0\x82\xe7\x82\xb9\x82\xe9:",
		"\x83\x4a\x83\x89\x82\xc9\x82\xb7\x82\xe9:",
		"\x8c\xa9\x82\xa6\x82\xc8\x82\xad\x82\xb7\x82\xe9:",
		"\x95\x7c\x82\xaa\x82\xe7\x82\xb9\x82\xe9:",
		"\x90\xeb\x82\xe7\x82\xb9\x82\xe9:",
		"\x89\x66\x82\xb5\x8f\x6f\x82\xb7:",
		"\x8e\xa1\x97\xc3\x82\xb7\x82\xe9:",
		"\x90\xc3\x82\xa9\x82\xc9\x82\xb3\x82\xb9\x82\xe9:",
		"\x8c\x60\x82\xf0\x95\xcf\x82\xa6\x82\xe9:",
		"\x94\x6a\x89\xf3\x82\xb7\x82\xe9:",
		"\x92\xb4\x89\x7a\x82\xb3\x82\xb9\x82\xe9:",
		"\x96\xa2\x92\x6d:"
	},

	// HEBREW
	{
		"\x9a\x85\x90\x89\x82\x90\x8e",
		":\x84\x87\x89\x9a\x94",
		":\x81\x84\x86\x8c \x99\x97 \x9a\x8b\x89\x94\x84",
		":\x84\x92\x89\x81\x96",
		":\x84\x8c\x89\x8c \x9a\x89\x89\x80\x98",
		":\x81\x85\x81\x89\x91",
		":\x84\x90\x89\x99",
		":\x84\x97\x98\x84",
		":\x84\x80\x98\x90 \x89\x9a\x8c\x81\x8c \x84\x8b\x89\x94\x84",
		":\x84\x83\x87\x94\x84",
		":\x84\x86\x87\x99\x84",
		":\x84\x89\x8e\x83\x84",
		":\x89\x85\x94\x89\x98",
		":\x84\x97\x9a\x99\x84",
		":\x84\x98\x85\x96 \x9a\x90\x89\x9a\x90",
		":\x84\x91\x89\x98\x84",
		":\x9a\x85\x81\x82\x99\x90",
		":\x92\x85\x83\x89\x20\x80\x8c"
	},

	// RUSSIAN
	{
		"\x93\xA7\xAE\xE0\xEB",
		"\x8E\xE2\xAA\xE0\xEB\xA2\xA0\xAD\xA8\xA5:",
		"\x91\xAE\xAB\xAE\xAC\xA0 \xA2 \xA7\xAE\xAB\xAE\xE2\xAE:",
		"\x8E\xAA\xE0\xA0\xE8\xA8\xA2\xA0\xAD\xA8\xA5:",
		"\x8D\xAE\xE7\xAD\xAE\xA5 \xA7\xE0\xA5\xAD\xA8\xA5:",
		"\x91\xAA\xE0\xE3\xE7\xA8\xA2\xA0\xAD\xA8\xA5:",
		"\x91\xAE\xAD:",
		"\x8E\xAF\xE3\xE1\xE2\xAE\xE8\xA5\xAD\xA8\xA5:",
		"\x8D\xA5\xA2\xA8\xA4\xA8\xAC\xAE\xE1\xE2\xEC:",
		"\x93\xA6\xA0\xE1:",
		"\x87\xA0\xE2\xAE\xE7\xAA\xA0:",
		"\x8E\xE2\xE0\xA0\xA6\xA5\xAD\xA8\xA5:",
		"\x88\xE1\xE6\xA5\xAB\xA5\xAD\xA8\xA5:",
		"\x8C\xAE\xAB\xE7\xA0\xAD\xA8\xA5:",
		"\x8F\xE0\xA8\xA4\xA0\xAD\xA8\xA5 \xE4\xAE\xE0\xAC\xEB:",
		"\x90\xA0\xA7\xA2\xAE\xAF\xAB\xAE\xE9\xA5\xAD\xA8\xA5:",
		"\x8F\xE0\xA5\xAE\xA1\xE0\xA0\xA6\xA5\xAD\xA8\xA5:",
		"\x8D\xA5\xA8\xA7\xA2\xA5\xE1\xE2\xAD\xEB\xA9:"
	},

};

void ScummEngine::drawDraftsInventory() {
	int base, xPos, textHeight, heightMultiplier, draft, textOffset, xOffset,
		inactiveColor, unlockedColor, newDraftColor, titleColor, notesColor,
		namesWidth, notesWidth;

	char notesBuf[6];
	const char **names;
	const char *notes = "cdefgabC";

	int yConstant = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);
	bool isLoomVGA = _game.version == 4 || _game.platform == Common::kPlatformFMTowns;

	// French&Hebrew labels are quite long, so throughout the following code
	// there are slight adjustments to French&Hebrew text positioning...
	bool isLongLanguage = _language == Common::FR_FRA || _language == Common::HE_ISR || _language == Common::RU_RUS;

	switch (_language) {
	case Common::EN_ANY:
	case Common::EN_GRB:
	case Common::EN_USA:
		names = loomDraftsNames[0];
		break;
	case Common::DE_DEU:
		names = loomDraftsNames[1];
		break;
	case Common::FR_FRA:
		names = loomDraftsNames[2];
		break;
	case Common::ES_ESP:
		names = loomDraftsNames[3];
		break;
	case Common::JA_JPN:
		names = loomDraftsNames[4];
		break;
	case Common::HE_ISR:
		names = loomDraftsNames[5];
		break;
	case Common::RU_RUS:
		names = loomDraftsNames[6];
		break;
	default:
		names = loomDraftsNames[0];
	}

	// ACT 1: Draw the widget graphics!
	//
	// Draw the inner and outer widgets...
	drawInternalGUIControl(GUI_CTRL_OUTER_BOX, 0);
	drawInternalGUIControl(GUI_CTRL_INNER_BOX, 0);

	// Draw the cute bar delimiter in the middle of the widget to separate the two text columns...
	if (isLoomVGA) {
		drawLine(160,     yConstant - 47, 160,     yConstant + 55, 15);
		drawLine(160 + 1, yConstant - 47, 160 + 1, yConstant + 55, 7);
		drawLine(160 + 2, yConstant - 47, 160 + 2, yConstant + 55, 7);
		drawLine(160 + 3, yConstant - 47, 160 + 3, yConstant + 55, 8);
	} else {
		drawLine(160,     yConstant - 47, 160,     yConstant + 55, getBannerColor(13));
		drawLine(160 + 1, yConstant - 47, 160 + 1, yConstant + 55, getBannerColor(4));
		drawLine(160 + 2, yConstant - 47, 160 + 2, yConstant + 55, getBannerColor(4));
		drawLine(160 + 3, yConstant - 47, 160 + 3, yConstant + 55, getBannerColor(13));
	}

	drawMainMenuTitle(names[0]); // Write "Drafts" on top of the menu widget

	// ACT 2: Draw the actual useful stuff, text! :-P
	//
	// Drafts are stored in SCUMM global variables; we choose the appropriate
	// first entry in the variables at which these drafts start.
	if (_game.version == 4 || _game.platform == Common::kPlatformPCEngine) {
		// DOS CD version / PC-Engine version
		base = 100;
	} else if (_game.platform == Common::kPlatformMacintosh) {
		// Macintosh version
		base = 55;
	} else {
		// Other versions
		base = 50;
	}

	inactiveColor = 8;
	unlockedColor = isLoomVGA ? 1 : getBannerColor(18);
	newDraftColor = isLoomVGA ? 14 : getBannerColor(21);

	// This is used to offset text elements in the event that
	// we are dealing with a language which has very long strings...
	xOffset = isLongLanguage ? 10 : 0;

	for (int i = 0; i < 16; i++) {
		draft = _scummVars[base + i * 2];

		// In which row are we rendering our text?
		heightMultiplier = i < 8 ? i : (i % 8);
		textHeight = getGUIStringHeight("A") + 3;

		// Has the draft been unlocked by the player?
		titleColor = (draft & 0x2000) ? unlockedColor : inactiveColor;

		// Has the new draft been used at least once?
		notesColor = (draft & 0x4000) ? unlockedColor : newDraftColor;

		// Has the draft been unlocked? Great: put it in our text buffer
		// otherwise just prepare to render the "????" string.
		if (draft & 0x2000) {
			Common::sprintf_s(notesBuf, sizeof(notesBuf), "%c%c%c%c",
							  notes[draft & 0x0007],
							  notes[(draft & 0x0038) >> 3],
							  notes[(draft & 0x01c0) >> 6],
							  notes[(draft & 0x0e00) >> 9]);
		} else {
			notesColor = inactiveColor;
			Common::sprintf_s(notesBuf, sizeof(notesBuf), "????");
		}

		// Hebrew rendering vs All-The-Other-LTR-Languages rendering:
		//
		// This is one case in which instead of doing all sorts of tricks
		// to have as few lines as possible, I prefer to duplicate code
		// for the sake of readability, so just so you know... this is
		// done on purpose... :-)
		if (_language != Common::HE_ISR) {
			// Where are we positioning the text?
			// Left column or right column?
			// (Objective: Leave three pixels to the left)
			if (isLoomVGA) {
				xPos = i < 8 ? 31 : 167;
			} else {
				xPos = i < 8 ? 30 : 167;
			}

			textOffset = xOffset;

			if (i >= 8) {
				textOffset = 0;
			}

			// Draw the titles of the drafts...
			if (draft & 0x2000) {
				drawGUIText(names[i + 1], nullptr, xPos - textOffset, yConstant - 40 + textHeight * heightMultiplier, titleColor, false);
			} else {
				// Draw "Unknown:" as the title of the draft
				drawGUIText(names[17], nullptr, xPos - textOffset, yConstant - 40 + textHeight * heightMultiplier, titleColor, false);
			}

			notesWidth = getGUIStringWidth(notesBuf);

			// Text position adjustments for the notes...
			// (Objective: Leave three pixels to the right)
			if (!isLoomVGA) {
				if (i >= 8)
					xPos += isLongLanguage ? 8 : -2;
				else if (isLongLanguage)
					xPos -= xOffset - 1;
				else
					xPos += 1;
			} else {
				if (i >= 8)
					xPos -= _game.platform == Common::kPlatformFMTowns ? 3 : 2;
				else
					xPos += _game.platform == Common::kPlatformFMTowns ? 0 : 1;
			}

			// Draw the notes of the draft... notice how we are subtracting
			// notesWidth: we are forcing the text aligning on the left.
			drawGUIText(notesBuf, nullptr, xPos - notesWidth + 127 + textOffset, yConstant - 40 + textHeight * heightMultiplier, notesColor, false);
		} else {
			// Hebrew language, let's swap the layout!

			// Where are we positioning the text?
			// Left column or right column?
			// (Objective: Leave three pixels to the left)
			xPos = i >= 8 ? 30 : 167;
			textOffset = xOffset;

			if (i < 8) {
				textOffset = 0;
			}

			// Draw the notes of the drafts...
			drawGUIText(notesBuf, nullptr, xPos - textOffset, yConstant - 40 + textHeight * heightMultiplier, notesColor, false);
			namesWidth = getGUIStringWidth(names[i + 1]);

			// Text position adjustments for the titles...
			// (Objective: Leave three pixels to the right)
			if (i < 8)
				xPos += 8;
			else
				xPos -= xOffset - 1;

			// Draw the titles of the drafts... notice how we are subtracting
			// namesWidth: we are forcing the text aligning on the left.
			if (draft & 0x2000) {
				namesWidth = getGUIStringWidth(names[i + 1]);
				drawGUIText(names[i + 1], nullptr, xPos - namesWidth + 127 + textOffset, yConstant - 40 + textHeight * heightMultiplier, titleColor, false);
			} else {
				// Draw "Unknown:" as the title of the draft
				namesWidth = getGUIStringWidth(names[17]);
				drawGUIText(names[17], nullptr, xPos - namesWidth + 127 + textOffset, yConstant - 40 + textHeight * heightMultiplier, titleColor, false);
			}
		}
	}

	// Update the screen with all the new stuff!
	ScummEngine::drawDirtyScreenParts();
	_system->updateScreen();
}

void ScummEngine::toggleVoiceMode() {
	if (VAR_VOICE_MODE != 0xFF) {
		VAR(VAR_VOICE_MODE) = (VAR(VAR_VOICE_MODE) != 1) ? 1 : 0;
		ConfMan.setInt("original_gui_text_status", VAR(VAR_VOICE_MODE));
		ConfMan.setBool("speech_mute", VAR(VAR_VOICE_MODE) == 2);
		ConfMan.setBool("subtitles", VAR(VAR_VOICE_MODE) > 0);
		syncSoundSettings();
		ConfMan.flushToDisk();
	}
}

void ScummEngine::setMusicVolume(int volume) {
	volume = CLIP<int>(volume, 0, 127);
	if (_game.version < 7)
		_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume * 2);
	ConfMan.setInt("music_volume", volume * 2);
	ConfMan.flushToDisk();

	if (_game.version < 7)
		ScummEngine::syncSoundSettings(); // Immediately update volume for old iMUSE and sound systems
}

void ScummEngine::setSpeechVolume(int volume) {
	volume = CLIP<int>(volume, 0, 127);
	if (_game.version < 7)
		_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, volume * 2);
	ConfMan.setInt("speech_volume", volume * 2);
	ConfMan.flushToDisk();

	if (_game.version < 7)
		ScummEngine::syncSoundSettings(); // Immediately update volume for old iMUSE and sound systems
}

void ScummEngine::setSFXVolume(int volume) {
	volume = CLIP<int>(volume, 0, 127);
	if (_game.version < 7)
		_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, volume * 2);
	ConfMan.setInt("sfx_volume", volume * 2);
	ConfMan.flushToDisk();

	if (_game.version < 7)
		ScummEngine::syncSoundSettings(); // Immediately update volume for old iMUSE and sound systems
}

int ScummEngine::getMusicVolume() {
	return CLIP<int>(_mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType) / 2, 0, 127);
}

int ScummEngine::getSpeechVolume() {
	return CLIP<int>(_mixer->getVolumeForSoundType(Audio::Mixer::kSpeechSoundType) / 2, 0, 127);
}

int ScummEngine::getSFXVolume() {
	return CLIP<int>(_mixer->getVolumeForSoundType(Audio::Mixer::kSFXSoundType) / 2, 0, 127);
}

void ScummEngine::queryQuit(bool returnToLauncher) {
	char msgLabelPtr[512];
	char localizedYesKey;

	if (_quitFromScriptCmd) {
		_quitByGUIPrompt = true;
		if (returnToLauncher) {
			Common::Event event;
			event.type = Common::EVENT_RETURN_TO_LAUNCHER;
			getEventManager()->pushEvent(event);
		} else {
			quitGame();
		}

		_quitFromScriptCmd = false;
	}

	convertMessageToString((const byte *)getGUIString(gsQuitPrompt), (byte *)msgLabelPtr, sizeof(msgLabelPtr));
	if (msgLabelPtr[0] != '\0') {

		// WORKAROUND: In the german version of LOOM FM-Towns, the string in the game data is stored with a '\r'
		// character at the end. This means that the string being displayed on screen will end with "(J oder N)J",
		// and localizedYesKey will be assigned to '\r'. Let's fix this by truncating the relevant string.
		if (enhancementEnabled(kEnhMinorBugFixes) && _game.id == GID_LOOM &&
			_game.platform == Common::kPlatformFMTowns &&
			strstr(msgLabelPtr, "(J oder N)J\r")) {
			msgLabelPtr[Common::strnlen(msgLabelPtr, sizeof(msgLabelPtr)) - 1] = '\0';
		}

		localizedYesKey = msgLabelPtr[Common::strnlen(msgLabelPtr, sizeof(msgLabelPtr)) - 1];
		msgLabelPtr[Common::strnlen(msgLabelPtr, sizeof(msgLabelPtr)) - 1] = '\0';

		// "Are you sure you want to quit?  (Y/N)"
		Common::KeyState ks;
		if (ConfMan.hasKey("confirm_exit") && ConfMan.getBool("confirm_exit") && ChainedGamesMan.empty()) {
			_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);

			if (_game.version > 4) {
				ks = showBannerAndPause(0, -1, msgLabelPtr);
			} else if (_game.version < 3) {
				ks = printMessageAndPause(msgLabelPtr, 0, -1, true);
			} else {
				ks = showOldStyleBannerAndPause(msgLabelPtr, 12, -1);
			}

			_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
		} else {
			ks = Common::KeyCode(localizedYesKey);
		}

		if (tolower(localizedYesKey) == ks.ascii || toupper(localizedYesKey) == ks.ascii ||
			(ks.keycode == Common::KEYCODE_c && ks.hasFlags(Common::KBD_CTRL)) ||
			(ks.keycode == Common::KEYCODE_x && ks.hasFlags(Common::KBD_ALT))) {
			_quitByGUIPrompt = true;
			if (returnToLauncher) {
				Common::Event event;
				event.type = Common::EVENT_RETURN_TO_LAUNCHER;
				getEventManager()->pushEvent(event);
			} else {
				Common::Event event;
				event.type = Common::EVENT_QUIT;
				getEventManager()->pushEvent(event);
			}
		}
	}
}

void ScummEngine::queryRestart() {
	char msgLabelPtr[512];
	char localizedYesKey;

	convertMessageToString((const byte *)getGUIString(gsRestart), (byte *)msgLabelPtr, sizeof(msgLabelPtr));
	if (msgLabelPtr[0] != '\0') {
		localizedYesKey = msgLabelPtr[Common::strnlen(msgLabelPtr, sizeof(msgLabelPtr)) - 1];
		msgLabelPtr[Common::strnlen(msgLabelPtr, sizeof(msgLabelPtr)) - 1] = '\0';

		_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);

		// "Are you sure you want to restart?  (Y/N)"
		Common::KeyState ks;
		if (_game.version > 4) {
			ks = showBannerAndPause(0, -1, msgLabelPtr);
		} else if (_game.version < 3) {
			ks = printMessageAndPause(msgLabelPtr, 4, -1, false);
		} else {
			ks = showOldStyleBannerAndPause(msgLabelPtr, 12, -1);
		}

		_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);

		if ((tolower(localizedYesKey) == ks.ascii || toupper(localizedYesKey) == ks.ascii) ||
			(_game.version == 8 && ks.keycode == Common::KEYCODE_y)) {

			if (_game.version < 5)
				restoreCharsetBg();

			int fadeOutType;
			switch (_game.id) {
			case GID_MANIAC:
			case GID_ZAK:
			case GID_INDY3:
				fadeOutType = 1;
				break;
			case GID_LOOM:
				fadeOutType = _game.version == 4 ? 134 : -1;
				break;
			case GID_MONKEY:
			case GID_MONKEY2:
			case GID_INDY4:
			case GID_TENTACLE:
			case GID_SAMNMAX:
				fadeOutType = 134;
				break;
			case GID_FT:
			case GID_DIG:
				fadeOutType = -1;
				break;
			case GID_MONKEY_EGA:
				fadeOutType = 128;
				break;
			default:
				fadeOutType = 129;
			}

			if (fadeOutType != -1)
				fadeOut(fadeOutType);

			restart();
		}
	}
}

// This function is actually not a thing in the original, it's here to
// make things a little bit more modern and avoid making the menu feel
// artificially slow.
bool ScummEngine::shouldHighlightLabelAndWait(int clickedControl) {
	return ((clickedControl >= GUI_CTRL_SAVE_BUTTON && clickedControl <= GUI_CTRL_PATH_BUTTON) ||
			(clickedControl == GUI_CTRL_DISPLAY_TEXT_CHECKBOX ||
			 clickedControl == GUI_CTRL_SPOOLED_MUSIC_CHECKBOX)) || _game.platform == Common::kPlatformSegaCD;
}

void ScummEngine::fillSavegameLabels() {
	bool availSaves[100];
	listSavegames(availSaves, ARRAYSIZE(availSaves));
	Common::String name;
	int curSaveSlot;
	bool isLoomVga = (_game.id == GID_LOOM && _game.version == 4);

	_savegameNames.clear();

	for (int i = GUI_CTRL_FIRST_SG; i <= GUI_CTRL_LAST_SG; i++) {
		curSaveSlot = i + (isLoomVga ? _firstSaveStateOfList : _curDisplayedSaveSlotPage * 9);
		if (_game.version > 4 || isLoomVga) {
			if (availSaves[curSaveSlot]) {
				if (getSavegameName(curSaveSlot, name)) {
					_savegameNames.push_back(Common::String::format("%2d. %s", curSaveSlot, name.c_str()));
				} else {
					// The original printed "WARNING... old savegame", but we do support old savegames :-)
					_savegameNames.push_back(Common::String::format("%2d. WARNING: wrong save version", curSaveSlot));
				}
			} else {
				_savegameNames.push_back(Common::String::format("%2d. ", curSaveSlot));
			}
		} else {
			if (availSaves[curSaveSlot]) {
				if (getSavegameName(curSaveSlot, name)) {
					_savegameNames.push_back(Common::String::format("%s", name.c_str()));
				} else {
					// The original printed "WARNING... old savegame", but we do support old savegames :-)
					_savegameNames.push_back(Common::String::format("%s", "WARNING: wrong save version"));
				}
			} else {
				_savegameNames.push_back(Common::String());
			}
		}
	}
}

bool ScummEngine::canWriteGame(int slotId) {
	bool saveList[100];
	char msgLabelPtr[512];
	char localizedYesKey;

	if (_game.version < 7)
		return true;

	listSavegames(saveList, ARRAYSIZE(saveList));
	if (saveList[slotId]) {
		convertMessageToString((const byte *)getGUIString(gsReplacePrompt), (byte *)msgLabelPtr, sizeof(msgLabelPtr));

		// Fallback to a hardcoded string
		if (msgLabelPtr[0] == '\0') {
			Common::strlcpy(msgLabelPtr, "Do you want to replace this saved game?  (Y/N)Y", sizeof(msgLabelPtr));
		}

		localizedYesKey = msgLabelPtr[Common::strnlen(msgLabelPtr, sizeof(msgLabelPtr)) - 1];
		msgLabelPtr[Common::strnlen(msgLabelPtr, sizeof(msgLabelPtr)) - 1] = '\0';

		_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);

		// "Do you want to replace this saved game?  (Y/N)"
		Common::KeyState ks = showBannerAndPause(0, -1, msgLabelPtr);

		_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);

		return (tolower(localizedYesKey) == ks.ascii || toupper(localizedYesKey) == ks.ascii);
	}

	return true;
}

bool ScummEngine::userWriteLabelRoutine(Common::KeyState &ks, bool &leftMsClicked, bool &rightMsClicked) {
	bool hasLoadedState = false;
	int firstChar = (_game.version == 4 && _game.id != GID_LOOM) ? 0 : 4;
	bool opResult = true;
	beginTextInput();

	while (!shouldQuit()) {
		waitForTimer(1);

		waitForBannerInput(-1, ks, leftMsClicked, rightMsClicked);
		rightMsClicked = false;
		if (ks.keycode == Common::KEYCODE_RETURN) {
			clearClickedStatus();
			opResult = executeMainMenuOperation(GUI_CTRL_OK_BUTTON, -1, -1, hasLoadedState);

			endTextInput();
			return opResult;
		} else if (leftMsClicked) {
			clearClickedStatus();
			break;
		}

		// Handle special key presses
		int curLen = _savegameNames[_mainMenuSavegameLabel - 1].size();
		if (ks.keycode == Common::KEYCODE_BACKSPACE) {
			 // Prevent the user from deleting the header (" 1. ")
			if (curLen > firstChar) {
				_savegameNames[_mainMenuSavegameLabel - 1].deleteLastChar();
				_internalGUIControls[_mainMenuSavegameLabel].label = _savegameNames[_mainMenuSavegameLabel - 1];
				drawInternalGUIControl(_mainMenuSavegameLabel, 1);
				ScummEngine::drawDirtyScreenParts();
				_system->updateScreen();
			}
		} else if (ks.ascii >= 32 && ks.ascii <= 122) { // Handle characters
			if (curLen < 39) {
				_savegameNames[_mainMenuSavegameLabel - 1] += (char)ks.ascii;
				_internalGUIControls[_mainMenuSavegameLabel].label = _savegameNames[_mainMenuSavegameLabel - 1];
				drawInternalGUIControl(_mainMenuSavegameLabel, 1);
				ScummEngine::drawDirtyScreenParts();
				_system->updateScreen();
			}
		}

		clearClickedStatus();
	}

	endTextInput();
	return false;
}

void ScummEngine::saveCursorPreMenu() {
	// Force the cursor to be ON...
	_oldCursorState = _cursor.state;
	_cursor.state = 1;
	CursorMan.showMouse(_cursor.state > 0);

	if (_game.version > 6) {
		// Backup the current cursor graphics and parameters
		// and set up the main menu cursor...
		// V6 handles this within scripts, so this is not needed.
		_curGrabbedCursor = (byte *)malloc(sizeof(_grabbedCursor));
		if (_curGrabbedCursor) {
			memcpy(_curGrabbedCursor, _grabbedCursor, sizeof(_grabbedCursor));
			_curCursorState = isSmushActive() ? 0 : _cursor.state;
			_curCursorWidth = _cursor.width;
			_curCursorHeight = _cursor.height;
			_curCursorHotspotX = _cursor.hotspotX;
			_curCursorHotspotY = _cursor.hotspotY;
			setDefaultCursor();
		}
	}

	CursorMan.showMouse(true);
}

void ScummEngine::restoreCursorPostMenu() {
	if (_game.version > 6 && _curGrabbedCursor) {
		// Restore the previous cursor...
		_cursor.state = _curCursorState;
		CursorMan.showMouse(_cursor.state > 0);
		if (_enableEGADithering) {
			_curCursorHotspotX >>= 1;
			_curCursorHotspotY >>= 1;
		}
		setCursorHotspot(_curCursorHotspotX, _curCursorHotspotY);
		setCursorFromBuffer(_curGrabbedCursor, _curCursorWidth, _curCursorHeight, _curCursorWidth, true);
		free(_curGrabbedCursor);
		_curGrabbedCursor = nullptr;
	}

	// Restore the old cursor state...
	_cursor.state = _oldCursorState;
}

void ScummEngine::showMainMenu() {
	char saveScreenTitle[512];
	int args[NUM_SCRIPT_LOCAL];
	bool leftMsClicked = false, rightMsClicked = false;
	int clickedControl = -1;
	int heldControl = -1;
	int curMouseX, curMouseY;
	bool hasLoadedState = false;

	Common::KeyState ks;

	memset(args, 0, sizeof(args));

	// Run the passcode script without args to fetch the current
	// value of the passcode, which is then stored in var 63.
	if (_game.platform == Common::kPlatformSegaCD) {
		runScript(61, 0, 0, nullptr);
	}

	// Generate the thumbnail, in case the game is saved
	Graphics::createThumbnail(_savegameThumbnail);

	// Pause the engine
	PauseToken pt = pauseEngine();

	// Run the entrance savescreen script, if available.
	// This is only available in v6 and automatically brings up the
	// default cross cursor. The post-save/load script will restore
	// the previous cursor.
	if (VAR_PRE_SAVELOAD_SCRIPT != 0xFF)
		runScript(VAR(VAR_PRE_SAVELOAD_SCRIPT), 0, 0, nullptr);

	int oldSaveSound = _saveSound;
	int oldScreenTop = _screenTop;

	_saveSound = 1;

	if (isSmushActive())
		_screenTop = 0;

	_shakeTempSavedState = _shakeEnabled;
	setShake(0);

	if (_game.version < 7) {
		// Below version 7, we draw texts on a separate surface which is then composited
		// on top of the main one during ScummEngine::drawDirtyScreenParts().
		// This results in texts overlapping on top of the menu; let's simulate the end result
		// of the original by copying the text surface over the main one just before showing
		// the menu...
		saveSurfacesPreGUI();

		// V6 games should call for stopTalk() instead, but that's a bit too drastic;
		// this ensures that we can at least hear the speech after the menu is closed.
		if (_charset->_textScreenID == kMainVirtScreen && !(_game.version == 4 && _game.id == GID_LOOM) &&
			!(_game.version == 5 && _game.platform == Common::kPlatformFMTowns))
			restoreCharsetBg();
	}

	_menuPage = GUI_PAGE_MAIN;
	setUpMainMenuControls();
	drawMainMenuControls();

	if (_game.platform == Common::kPlatformAmiga || _game.platform == Common::kPlatformFMTowns) {
		convertMessageToString((const byte *)getGUIString(gsInsertSaveDisk), (byte *)saveScreenTitle, sizeof(saveScreenTitle));
		drawMainMenuTitle(saveScreenTitle);
	} else if (_game.version > 4 && _game.id != GID_MONKEY2 && _game.id != GID_MONKEY) {
		convertMessageToString((const byte *)getGUIString(gsTitle), (byte *)saveScreenTitle, sizeof(saveScreenTitle));
		drawMainMenuTitle(saveScreenTitle);
	}

	updateMainMenuControls();

	// Save the current cursor state...
	saveCursorPreMenu();

	// Notify that the menu is now active
	_mainMenuIsActive = true;

	// Clear keypresses and mouse presses
	clearClickedStatus();

	// Menu loop
	while (!shouldQuit()) {
		// Update the screen and the cursor while we're in the loop
		waitForTimer(1);

		if (_menuPage == GUI_PAGE_SAVE && _mainMenuSavegameLabel > 0) {
			if (userWriteLabelRoutine(ks, leftMsClicked, rightMsClicked))
				break;
		} else {
			// Wait for any mouse button presses...
			waitForBannerInput(-1, ks, leftMsClicked, rightMsClicked, _menuPage != GUI_PAGE_MAIN);
		}

		if (leftMsClicked || rightMsClicked || _mouseWheelFlag) {
			curMouseX = _mouse.x;
			curMouseY = _mouse.y;
			clickedControl = getInternalGUIControlFromCoordinates(curMouseX, curMouseY);

			// Mouse wheel movement with cursor over the list box. If there are actual button
			// clicks, we ignore the wheel.
			if (!(leftMsClicked || rightMsClicked)) {
				// Unfortunately, there can be space (vertically) between the save slot controls,
				// so the mouse wheel will not catch if the cursor happens to be right at that pixel.
				// Thus, we also have to check for the GUI_CTRL_OUTER_BOX and the see if the cursor
				// is within the save list bounds.
				if (clickedControl == GUI_CTRL_OUTER_BOX && _internalGUIControls[GUI_CTRL_FIRST_SG].relativeCenterX != -1 &&
					_internalGUIControls[GUI_CTRL_LAST_SG].relativeCenterX != -1) {
						Common::Rect saveList(_internalGUIControls[GUI_CTRL_FIRST_SG].relativeCenterX,
							_internalGUIControls[GUI_CTRL_FIRST_SG].relativeCenterY,
							_internalGUIControls[GUI_CTRL_LAST_SG].xPos + 1,
							_internalGUIControls[GUI_CTRL_LAST_SG].yPos + 1);
						// Doesn't matter which slot we assign, we just want to trigger the next if-clause.
						clickedControl = saveList.contains(curMouseX, curMouseY) ? GUI_CTRL_FIRST_SG : -1;
				}

				if (clickedControl >= GUI_CTRL_FIRST_SG && clickedControl <= GUI_CTRL_LAST_SG) {
					if (_mouseWheelFlag == Common::EVENT_WHEELUP)
						clickedControl = (_internalGUIControls[GUI_CTRL_ARROW_UP_BUTTON].relativeCenterX != -1) ? GUI_CTRL_ARROW_UP_BUTTON : -1;
					else if (_mouseWheelFlag == Common::EVENT_WHEELDOWN)
						clickedControl = (_internalGUIControls[GUI_CTRL_ARROW_DOWN_BUTTON].relativeCenterX != -1) ? GUI_CTRL_ARROW_DOWN_BUTTON : -1;
				} else {
					clickedControl = -1;
				}
			}

			// Allow the user to drag the volume and text speed sliders horizontally;
			// this feature isn't available in the original interpreters (v6-v7),
			// but it makes the sliders a lot more comfortable to use, so there shouldn't be
			// any harm in this.
			while ((_game.version >= 6) && (_menuPage == GUI_PAGE_MAIN) && (_leftBtnPressed & 1)) {
				// Allow the engine to fetch new mouse states...
				waitForTimer(1);

				// Register one and only one control for the duration of this loop...
				if (heldControl == -1)
					heldControl = getInternalGUIControlFromCoordinates(curMouseX, curMouseY);

				// Choose among the available sliders, register the new mouse coordinates,
				// and execute the control operation...
				switch (heldControl) {
				case GUI_CTRL_MUSIC_SLIDER:
				case GUI_CTRL_SPEECH_SLIDER:
				case GUI_CTRL_SFX_SLIDER:
				case GUI_CTRL_TEXT_SPEED_SLIDER:
					curMouseX = _mouse.x;
					curMouseY = _mouse.y;
					executeMainMenuOperation(heldControl, curMouseX, curMouseY, hasLoadedState);
					break;
				default:
					break;
				}
			}

			heldControl = -1;

			clearClickedStatus();
			leftMsClicked = false;
			rightMsClicked = false;

			if (clickedControl != -1) {
				if (clickedControl < GUI_CTRL_FIRST_SG || clickedControl > GUI_CTRL_LAST_SG ||
					_game.platform == Common::kPlatformSegaCD) {
					// Avoid highlighting the main container boxes :-)
					if (clickedControl != GUI_CTRL_OUTER_BOX && clickedControl != GUI_CTRL_INNER_BOX) {
						// Highlight the control
						drawInternalGUIControl(clickedControl, 1);
						ScummEngine::drawDirtyScreenParts();

						// Wait a little bit (the original waited 120 quarter frames, which feels like molasses).
						// We only perform this artificial wait for buttons; the original also did this for
						// sliders but it feels artificially slow, and we don't want that here :-)
						if (shouldHighlightLabelAndWait(clickedControl))
							waitForTimer(60);

						// Dehighlight it
						drawInternalGUIControl(clickedControl, 0);

						// Execute the operation pertaining the clicked control
						if (executeMainMenuOperation(clickedControl, curMouseX, curMouseY, hasLoadedState))
							break;
					}
				} else if (_game.platform != Common::kPlatformSegaCD) {
					int tmp = _mainMenuSavegameLabel;
					_mainMenuSavegameLabel = clickedControl;

					drawInternalGUIControl(tmp, 0);

					// For v4 we activated the first slot by default; deactivate it...
					if (_game.version == 4 && _game.id != GID_LOOM)
						drawInternalGUIControl(GUI_CTRL_FIRST_SG, 0);

					drawInternalGUIControl(_mainMenuSavegameLabel, 1);

					ScummEngine::drawDirtyScreenParts();
					_system->updateScreen();

					if (_menuPage == GUI_PAGE_LOAD && (_game.version != 4 || _game.id == GID_LOOM)) {
						if (executeMainMenuOperation(GUI_CTRL_OK_BUTTON, curMouseX, curMouseY, hasLoadedState))
							break;
					}
				}
			}
		}

		if (shouldQuit() && !_quitByGUIPrompt) {
			clearClickedStatus();
			if (_game.platform != Common::kPlatformSegaCD)
				if (executeMainMenuOperation(GUI_CTRL_QUIT_BUTTON, 0, 0, hasLoadedState) || _quitByGUIPrompt)
					break;
		}
	}

	_saveSound = oldSaveSound;

	if (isSmushActive())
		_screenTop = oldScreenTop;

	_mainMenuIsActive = false;

	if (_game.version > 6)
		_completeScreenRedraw = true;

	// Restore the old cursor state only if we're not loading a game...
	if (_saveScriptParam != GAME_PROPER_LOAD && _saveLoadFlag != 2 &&
		!(_game.platform == Common::kPlatformSegaCD && hasLoadedState)) {
		restoreCursorPostMenu();
	} else if (_saveLoadFlag == 2) {
		_cursor.state = (_game.id == GID_MONKEY && _game.platform == Common::kPlatformMacintosh) ? 1 : 0;
	}

	// Run the exit savescreen script, if available
	if (_saveScriptParam != 0 || _game.version == 6) {
		args[0] = _saveScriptParam;
		if (VAR_POST_SAVELOAD_SCRIPT != 0xFF) {
			runScript(VAR(VAR_POST_SAVELOAD_SCRIPT), 0, 0, args);
			_saveScriptParam = 0;
		}
	}

	// A little bit of hackery: since we handle the main loop a little bit
	// differently (basically we start from a different position, but the order
	// remains the same), we call displayDialog() here to refresh the dialog texts
	// immediately and avoid getting a frame in which their color is wrong...
	if (_game.version == 7)
		displayDialog();

	if (_game.version < 7 && !hasLoadedState) {
		restoreSurfacesPostGUI();

		// Restore shake effect
		setShake(_shakeTempSavedState);
	} else {
		free(_tempTextSurface);
		_tempTextSurface = nullptr;
		free(_tempMainSurface);
		_tempMainSurface = nullptr;
		free(_tempVerbSurface);
		_tempVerbSurface = nullptr;
		free(_curGrabbedCursor);
		_curGrabbedCursor = nullptr;
	}

	_savegameThumbnail.free();

	// Resume the engine
	pt.clear();
	clearClickedStatus();
}

bool ScummEngine::executeMainMenuOperationSegaCD(int op, int mouseX, int mouseY, bool &hasLoadedState) {
	switch (op) {
	case GUI_CTRL_PLAY_BUTTON:
		return true;
	case GUI_CTRL_LOAD_BUTTON:
		_menuPage = GUI_PAGE_LOAD;
		setUpMainMenuControls();
		drawMainMenuControls();
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_RESTART_BUTTON:
		_menuPage = GUI_PAGE_RESTART;
		setUpMainMenuControls();
		drawMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_OK_BUTTON:
		if (_menuPage == GUI_PAGE_RESTART) {
			_cursor.state = 0;
			CursorMan.showMouse(false);
			hasLoadedState = true;
			restart();
			return true;
		} else if (_menuPage == GUI_PAGE_CODE_CONFIRM) {
			_bootParam = atoi(_mainMenuSegaCDPasscode);

			// We are running script 61 twice:
			// - The first time we are providing it the passcode as an argument;
			// - The second time we give no arguments, allowing var 63 to be updated.
			// This will let us know whether we have successfully loaded a game or not.

			// First time...
			int args[NUM_SCRIPT_LOCAL];
			memset(args, 0, sizeof(args));
			args[0] = _bootParam;

			runScript(61, 0, 0, args);

			// Second time...
			args[0] = 0;
			runScript(61, 0, 0, args);

			hasLoadedState = _scummVars[63] == _bootParam;

			_bootParam = 0;

			if (!hasLoadedState) {
				_menuPage = GUI_PAGE_INVALID_CODE;
				setUpMainMenuControls();
				drawMainMenuControls();
				updateMainMenuControls();
				ScummEngine::drawDirtyScreenParts();

				waitForTimer(420);

				_menuPage = GUI_PAGE_MAIN;
				setUpMainMenuControls();
				drawMainMenuControls();
				updateMainMenuControls();
				ScummEngine::drawDirtyScreenParts();
			} else {
				return true;
			}
		}

		break;
	case GUI_CTRL_CANCEL_BUTTON:
		_menuPage = GUI_PAGE_MAIN;
		setUpMainMenuControls();
		drawMainMenuControls();
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_ARROW_LEFT_BUTTON:
	case GUI_CTRL_ARROW_RIGHT_BUTTON:
		if (_menuPage == GUI_PAGE_MAIN) {
			if (op == GUI_CTRL_ARROW_LEFT_BUTTON) {
				_defaultTextSpeed = CLIP<int>(_defaultTextSpeed - 1, 0, 9);
			} else {
				_defaultTextSpeed = CLIP<int>(_defaultTextSpeed + 1, 0, 9);
			}

			ConfMan.setInt("original_gui_text_speed", _defaultTextSpeed);
			setTalkSpeed(_defaultTextSpeed);
			syncSoundSettings();
			ConfMan.flushToDisk();
			drawMainMenuControls();
			updateMainMenuControls();
			ScummEngine::drawDirtyScreenParts();
		}
		break;
	case GUI_CTRL_TEXT_SPEED_SLIDER:
		_defaultTextSpeed = CLIP<int>((mouseX - 150) / 9, 0, 9);

		ConfMan.setInt("original_gui_text_speed", _defaultTextSpeed);
		setTalkSpeed(_defaultTextSpeed);
		syncSoundSettings();
		ConfMan.flushToDisk();
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_NUMPAD_0:
	case GUI_CTRL_NUMPAD_1:
	case GUI_CTRL_NUMPAD_2:
	case GUI_CTRL_NUMPAD_3:
	case GUI_CTRL_NUMPAD_4:
	case GUI_CTRL_NUMPAD_5:
	case GUI_CTRL_NUMPAD_6:
	case GUI_CTRL_NUMPAD_7:
	case GUI_CTRL_NUMPAD_8:
	case GUI_CTRL_NUMPAD_9:
	case GUI_CTRL_NUMPAD_BACK:
	{
		int inputNum = (op == GUI_CTRL_NUMPAD_0) ? 0 : op;
		uint curIdx = Common::strnlen(_mainMenuSegaCDPasscode, sizeof(_mainMenuSegaCDPasscode));

		if (op == GUI_CTRL_NUMPAD_BACK) {
			if (curIdx > 0) {
				_mainMenuSegaCDPasscode[curIdx - 1] = '\0';
			}

		} else {
			_mainMenuSegaCDPasscode[curIdx] = '0' + inputNum;

			if (curIdx >= 3) { // Last digit
				updateMainMenuControls();
				drawDirtyScreenParts();

				waitForTimer(120);

				_menuPage = GUI_PAGE_CODE_CONFIRM;
				setUpMainMenuControls();
			}
		}

		drawMainMenuControls();
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	}
	default:
		break;
	}

	return false;
}

bool ScummEngine::executeMainMenuOperation(int op, int mouseX, int mouseY, bool &hasLoadedState) {
	if (_game.platform == Common::kPlatformSegaCD) {
		return executeMainMenuOperationSegaCD(op, mouseX, mouseY, hasLoadedState);
	}

	char saveScreenTitle[512];
	Common::String formattedString;
	int curSlot;
	bool isLoomVga = (_game.id == GID_LOOM && _game.version == 4);
	size_t labelSkip = (_game.version == 4 && _game.id != GID_LOOM) ? 0 : 4;
	bool rtlRequest = getEventManager()->shouldReturnToLauncher();

	switch (op) {
	case GUI_CTRL_SAVE_BUTTON:
		_mainMenuSavegameLabel = 0;
		fillSavegameLabels();
		_menuPage = GUI_PAGE_SAVE;
		setUpMainMenuControls();
		drawMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_LOAD_BUTTON:
		_mainMenuSavegameLabel = 0;
		fillSavegameLabels();
		_menuPage = GUI_PAGE_LOAD;
		setUpMainMenuControls();
		drawMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_PLAY_BUTTON:
		return true;
	case GUI_CTRL_QUIT_BUTTON:
		getEventManager()->resetQuit();
		getEventManager()->resetReturnToLauncher();
		queryQuit(rtlRequest);
		if (_game.version == 7)
			return true;
		break;
	case GUI_CTRL_OK_BUTTON:
		if (_menuPage == GUI_PAGE_SAVE) {
			// We check for an empty label since v4 might generate that...
			if (_mainMenuSavegameLabel > 0 && !_savegameNames[_mainMenuSavegameLabel - 1].substr(labelSkip).empty()) {
				convertMessageToString((const byte *)getGUIString(gsSaving), (byte *)saveScreenTitle, sizeof(saveScreenTitle));
				formattedString = Common::String::format(saveScreenTitle, _savegameNames[_mainMenuSavegameLabel - 1].substr(labelSkip).c_str());
				drawMainMenuTitle(formattedString.c_str());
				ScummEngine::drawDirtyScreenParts();
				_system->updateScreen();

				waitForTimer(60);

				Common::String dummyString;
				_saveLoadDescription = _savegameNames[_mainMenuSavegameLabel - 1].substr(labelSkip);

				curSlot = _mainMenuSavegameLabel + (isLoomVga ? _firstSaveStateOfList : _curDisplayedSaveSlotPage * 9);
				if (canWriteGame(curSlot)) {
					restoreCursorPostMenu();

					// Temporarily restore the shake effect to save it...
					setShake(_shakeTempSavedState);

					if (saveState(curSlot, false, dummyString)) {
						setShake(0);
						saveCursorPreMenu();
						_saveScriptParam = GAME_PROPER_SAVE;
						drawMainMenuControls();
						return true;
					} else {
						setShake(0);
					}
				} else {
					convertMessageToString((const byte *)getGUIString(gsGameNotSaved), (byte *)saveScreenTitle, sizeof(saveScreenTitle));
					if (_game.id == GID_DIG) {
						showBannerAndPause(1, -1, saveScreenTitle);
						drawMainMenuControls();
					} else {
						drawMainMenuTitle(saveScreenTitle);
					}

					ScummEngine::drawDirtyScreenParts();
				}
			} else {
				convertMessageToString((const byte *)getGUIString(gsMustName), (byte *)saveScreenTitle, sizeof(saveScreenTitle));
				drawMainMenuTitle(saveScreenTitle);
				ScummEngine::drawDirtyScreenParts();
			}

			// The original, after doing the above, immediately redraws the menus,
			// effectively overwriting the title we've just changed.
			// In a DOS machine one could effectively see the changed title for a
			// fraction of time, before reverting to the normale one.
			// We, on the other hand, wouldn't be able to see changed title at all,
			// so let's comment the following instruction :-)
			//
			//drawMainMenuControls();

		} else if (_menuPage == GUI_PAGE_LOAD) {
			if (_mainMenuSavegameLabel > 0) {
				convertMessageToString((const byte *)getGUIString(gsLoading), (byte *)saveScreenTitle, sizeof(saveScreenTitle));
				formattedString = Common::String::format(saveScreenTitle, _savegameNames[_mainMenuSavegameLabel - 1].substr(labelSkip).c_str());

				if (_savegameNames[_mainMenuSavegameLabel - 1].size() == labelSkip) {
					drawMainMenuControls();
					ScummEngine::drawDirtyScreenParts();
					break;
				}

				drawMainMenuTitle(formattedString.c_str());
				ScummEngine::drawDirtyScreenParts();
				_system->updateScreen();

				waitForTimer(60);

				if (isSmushActive()) {
					handleLoadDuringSmush();
					return true;
				}

				if ((_game.version != 4 || _game.id != GID_LOOM) && _game.version < 7) {
					_postGUICharMask = true;
				}

				curSlot = _mainMenuSavegameLabel + (isLoomVga ? _firstSaveStateOfList : _curDisplayedSaveSlotPage * 9);
				if (loadState(curSlot, false)) {
					hasLoadedState = true;

#ifdef ENABLE_SCUMM_7_8
					if (!_spooledMusicIsToBeEnabled)
						_imuseDigital->diMUSEDisableSpooledMusic();
#endif

					setSkipVideo(0);
					_saveScriptParam = GAME_PROPER_LOAD;
					return true;
				} else {
					convertMessageToString((const byte *)getGUIString(gsGameNotLoaded), (byte *)saveScreenTitle, sizeof(saveScreenTitle));
					if (_game.id == GID_DIG) {
						showBannerAndPause(1, -1, saveScreenTitle);
						drawMainMenuControls();
					} else {
						drawMainMenuTitle(saveScreenTitle);
					}

					ScummEngine::drawDirtyScreenParts();
				}

				// See the comment for the Save control
				//
				//drawMainMenuControls();
			}
		}

		break;
	case GUI_CTRL_CANCEL_BUTTON:
		_menuPage = GUI_PAGE_MAIN;
		setUpMainMenuControls();
		drawMainMenuControls();

		if (_game.platform == Common::kPlatformAmiga || _game.platform == Common::kPlatformFMTowns) {
			convertMessageToString((const byte *)getGUIString(gsInsertSaveDisk), (byte *)saveScreenTitle, sizeof(saveScreenTitle));
			drawMainMenuTitle(saveScreenTitle);
		} else if (_game.version > 4 && _game.id != GID_MONKEY2 && _game.id != GID_MONKEY) {
			convertMessageToString((const byte *)getGUIString(gsTitle), (byte *)saveScreenTitle, sizeof(saveScreenTitle));
			drawMainMenuTitle(saveScreenTitle);
		}

		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_ARROW_UP_BUTTON:
	case GUI_CTRL_ARROW_DOWN_BUTTON:
		if (_menuPage != GUI_PAGE_MAIN) {
			if (!isLoomVga) {
				if (op == GUI_CTRL_ARROW_UP_BUTTON) {
					_curDisplayedSaveSlotPage--;
				} else {
					_curDisplayedSaveSlotPage++;
				}

				_curDisplayedSaveSlotPage = CLIP<int>(_curDisplayedSaveSlotPage, 0, 10);
			} else {
				// LOOM VGA uses its own system to scroll the savegame list, based
				// on high or low the arrow button is pressed...
				if (op == GUI_CTRL_ARROW_UP_BUTTON) {
					_firstSaveStateOfList -= ((_virtscr[kMainVirtScreen].h / 2) - mouseY + _virtscr[kMainVirtScreen].topline + 54) / 14;
				} else {
					_firstSaveStateOfList += (mouseY - (_virtscr[kMainVirtScreen].h / 2) - _virtscr[kMainVirtScreen].topline + 45) / 14;
				}

				_firstSaveStateOfList = CLIP<int>(_firstSaveStateOfList, 0, 90);
			}

			_mainMenuSavegameLabel = 0;
			fillSavegameLabels();

			// Update the control labels with the newly changed savegame names
			for (int i = GUI_CTRL_FIRST_SG; i <= GUI_CTRL_LAST_SG; i++)
				_internalGUIControls[i].label = _savegameNames[i - 1];

			drawMainMenuControls();
			ScummEngine::drawDirtyScreenParts();
		} else {
			drawInternalGUIControl(GUI_CTRL_ARROW_UP_BUTTON, 0);
			drawInternalGUIControl(GUI_CTRL_ARROW_DOWN_BUTTON, 0);
			ScummEngine::drawDirtyScreenParts();
		}

		break;
	case GUI_CTRL_PATH_BUTTON:
		// This apparently should't do anything
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_MUSIC_SLIDER:
		setMusicVolume(((mouseX - (_game.version == 7 ? 111 : 105)) << 7) / 87);
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_SPEECH_SLIDER:
		setSpeechVolume(((mouseX - (_game.version == 7 ? 111 : 105)) << 7) / 87);
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_SFX_SLIDER:
		setSFXVolume(((mouseX - (_game.version == 7 ? 111 : 105)) << 7) / 87);
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_TEXT_SPEED_SLIDER:
		_defaultTextSpeed = CLIP<int>((mouseX - (_game.version == 7 ? 108 : 102)) / 9, 0, 9);

		ConfMan.setInt("original_gui_text_speed", _defaultTextSpeed);
		setTalkSpeed(_defaultTextSpeed);
		syncSoundSettings();
		ConfMan.flushToDisk();
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_DISPLAY_TEXT_CHECKBOX:
		toggleVoiceMode();
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	case GUI_CTRL_SPOOLED_MUSIC_CHECKBOX:
		_spooledMusicIsToBeEnabled ^= 1;

#ifdef ENABLE_SCUMM_7_8
		// Just for safety, this should never be nullptr...
		if (_imuseDigital) {
			if (_spooledMusicIsToBeEnabled) {
				_imuseDigital->diMUSEEnableSpooledMusic();
			} else {
				_imuseDigital->diMUSEDisableSpooledMusic();
			}
		}
#endif
		updateMainMenuControls();
		ScummEngine::drawDirtyScreenParts();
		break;
	default:
		break;
	}

	return false;
}

void ScummEngine_v4::setUpMainMenuControls() {
	if (_game.id == GID_LOOM && _game.version == 4) {
		ScummEngine::setUpMainMenuControls();
		return;
	}

	int yConstant = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);

	for (int i = 0; i < ARRAYSIZE(_internalGUIControls); i++) {
		_internalGUIControls[i].relativeCenterX = -1;
	}

	// Outer box
	setUpInternalGUIControl(GUI_CTRL_OUTER_BOX,
		getBannerColor(6),
		getBannerColor(6),
		getBannerColor(7),
		getBannerColor(7),
		getBannerColor(7),
		getBannerColor(7),
		getBannerColor(7),
		getBannerColor(6),
		20,
		yConstant - 58,
		300,
		yConstant + 58,
		_emptyMsg, 0, 0);

	if (_menuPage == GUI_PAGE_MAIN) {
		// Save button
		setUpInternalGUIControl(GUI_CTRL_SAVE_BUTTON,
			getBannerColor(10),
			getBannerColor(11),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(12),
			getBannerColor(13),
			242,
			yConstant - 25,
			-50,
			-12,
			getGUIString(gsSave), 1, 1);

		// Load button
		setUpInternalGUIControl(GUI_CTRL_LOAD_BUTTON,
			getBannerColor(10),
			getBannerColor(11),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(12),
			getBannerColor(13),
			242,
			yConstant - 11,
			-50,
			-12,
			getGUIString(gsLoad), 1, 1);

		// Play button
		setUpInternalGUIControl(GUI_CTRL_PLAY_BUTTON,
			getBannerColor(10),
			getBannerColor(11),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(12),
			getBannerColor(13),
			242,
			yConstant + 3,
			-50,
			-12,
			getGUIString(gsPlay), 1, 1);

		// Quit button
		setUpInternalGUIControl(GUI_CTRL_QUIT_BUTTON,
			getBannerColor(10),
			getBannerColor(11),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(12),
			getBannerColor(13),
			242,
			yConstant + 17,
			-50,
			-12,
			getGUIString(gsQuit), 1, 1);
	}

	if (_menuPage == GUI_PAGE_SAVE || _menuPage == GUI_PAGE_LOAD) {
		// OK button
		setUpInternalGUIControl(GUI_CTRL_OK_BUTTON,
			getBannerColor(10),
			getBannerColor(11),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(12),
			getBannerColor(13),
			242,
			yConstant - 11,
			-50,
			-12,
			getGUIString(gsOK), 1, 1);

		// Cancel button
		setUpInternalGUIControl(GUI_CTRL_CANCEL_BUTTON,
			getBannerColor(10),
			getBannerColor(11),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(9),
			getBannerColor(12),
			getBannerColor(13),
			242,
			yConstant + 3,
			-50,
			-12,
			getGUIString(gsCancel), 1, 1);

		// Savegame names
		for (int i = GUI_CTRL_FIRST_SG, j = 11; i <= GUI_CTRL_LAST_SG; i++, j += 11) {
			setUpInternalGUIControl(i,
				getBannerColor(15),
				getBannerColor(16),
				getBannerColor(14),
				getBannerColor(14),
				getBannerColor(14),
				getBannerColor(14),
				getBannerColor(17),
				getBannerColor(18),
				28,
				yConstant - 56 + j,
				-206,
				-9,
				_savegameNames[i - 1].c_str(), 0, 0);
		}
	}
}

void ScummEngine::setUpMainMenuControls() {
	if (_game.platform == Common::kPlatformSegaCD) {
		setUpMainMenuControlsSegaCD();
		return;
	} else if (_isIndy4Jap) {
		setUpMainMenuControlsIndy4Jap();
		return;
	}

	int yConstant;
	bool isLoomVGA = (_game.id == GID_LOOM && _game.version == 4);

	yConstant = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);

	for (int i = 0; i < ARRAYSIZE(_internalGUIControls); i++) {
		_internalGUIControls[i].relativeCenterX = -1;
	}

	// Outer box
	setUpInternalGUIControl(GUI_CTRL_OUTER_BOX,
		isLoomVGA ? 7  : getBannerColor(4),
		isLoomVGA ? 0  : getBannerColor(2),
		isLoomVGA ? 15 : getBannerColor(13),
		isLoomVGA ? 8  : getBannerColor(14),
		isLoomVGA ? 15 : getBannerColor(15),
		isLoomVGA ? 8  : getBannerColor(16),
		isLoomVGA ? 14 : getBannerColor(6),
		isLoomVGA ? 1  : getBannerColor(4),
		20,
		yConstant - 60,
		300,
		((yConstant + 60) < 0 ? -120 : yConstant + 60),
		_emptyMsg, 1, 1);

	// Inner box
	setUpInternalGUIControl(GUI_CTRL_INNER_BOX,
		isLoomVGA ? 7  : getBannerColor(4),
		isLoomVGA ? 0  : getBannerColor(5),
		isLoomVGA ? 8  : getBannerColor(18),
		isLoomVGA ? 15 : getBannerColor(17),
		isLoomVGA ? 8  : getBannerColor(20),
		isLoomVGA ? 15 : getBannerColor(19),
		isLoomVGA ? 14 : getBannerColor(6),
		isLoomVGA ? 1  : getBannerColor(7),
		26,
		yConstant - 47,
		212 - (isLoomVGA ? 10 : 0),
		yConstant - 47 + 102,
		_emptyMsg, 1, 1);

	if (_menuPage == GUI_PAGE_MAIN) {
		// Save button
		setUpInternalGUIControl(GUI_CTRL_SAVE_BUTTON,
			isLoomVGA ? 7  : getBannerColor(4),
			isLoomVGA ? 0  : getBannerColor(5),
			isLoomVGA ? 15 : getBannerColor(17),
			isLoomVGA ? 8  : getBannerColor(18),
			isLoomVGA ? 15 : getBannerColor(19),
			isLoomVGA ? 8  : getBannerColor(20),
			isLoomVGA ? 14 : getBannerColor(6),
			isLoomVGA ? 1  : getBannerColor(7),
			242 - (isLoomVGA ? 10 : 0),
			yConstant - 23,
			292,
			yConstant - 23 + 12,
			getGUIString(gsSave), 1, 1);

		// Load button
		setUpInternalGUIControl(GUI_CTRL_LOAD_BUTTON,
			isLoomVGA ? 7  : getBannerColor(4),
			isLoomVGA ? 0  : getBannerColor(5),
			isLoomVGA ? 15 : getBannerColor(17),
			isLoomVGA ? 8  : getBannerColor(18),
			isLoomVGA ? 15 : getBannerColor(19),
			isLoomVGA ? 8  : getBannerColor(20),
			isLoomVGA ? 14 : getBannerColor(6),
			isLoomVGA ? 1  : getBannerColor(7),
			242 - (isLoomVGA ? 10 : 0),
			yConstant - 8,
			292,
			yConstant - 8 + 12,
			getGUIString(gsLoad), 1, 1);

		// Play button
		setUpInternalGUIControl(GUI_CTRL_PLAY_BUTTON,
			isLoomVGA ? 7  : getBannerColor(4),
			isLoomVGA ? 0  : getBannerColor(5),
			isLoomVGA ? 15 : getBannerColor(17),
			isLoomVGA ? 8  : getBannerColor(18),
			isLoomVGA ? 15 : getBannerColor(19),
			isLoomVGA ? 8  : getBannerColor(20),
			isLoomVGA ? 14 : getBannerColor(6),
			isLoomVGA ? 1  : getBannerColor(7),
			242 - (isLoomVGA ? 10 : 0),
			yConstant + 7,
			292,
			yConstant + 19,
			getGUIString(gsPlay), 1, 1);

		// Quit button
		setUpInternalGUIControl(GUI_CTRL_QUIT_BUTTON,
			isLoomVGA ? 7  : getBannerColor(4),
			isLoomVGA ? 0  : getBannerColor(5),
			isLoomVGA ? 15 : getBannerColor(17),
			isLoomVGA ? 8  : getBannerColor(18),
			isLoomVGA ? 15 : getBannerColor(19),
			isLoomVGA ? 8  : getBannerColor(20),
			isLoomVGA ? 14 : getBannerColor(6),
			isLoomVGA ? 1  : getBannerColor(7),
			242 - (isLoomVGA ? 10 : 0),
			yConstant + 22,
			292,
			yConstant + 34,
			getGUIString(gsQuit), 1, 1);
	}

	if (_menuPage != GUI_PAGE_MAIN || !(_game.id == GID_MONKEY2 || _game.id == GID_MONKEY)) {
		// Arrow up button
		setUpInternalGUIControl(GUI_CTRL_ARROW_UP_BUTTON,
			isLoomVGA ? 7  : getBannerColor(9),
			isLoomVGA ? 0  : getBannerColor(10),
			isLoomVGA ? 15 : getBannerColor(17),
			isLoomVGA ? 8  : getBannerColor(18),
			isLoomVGA ? 15 : getBannerColor(19),
			isLoomVGA ? 8  : getBannerColor(20),
			isLoomVGA ? 14 : getBannerColor(11),
			isLoomVGA ? 1  : getBannerColor(12),
			216 - (isLoomVGA ? 10 : 0),
			yConstant - 43,
			232 - (isLoomVGA ? 10 : 0),
			yConstant - 43 + 47,
			_arrowUp, 1, 1);

		// Arrow down button
		setUpInternalGUIControl(GUI_CTRL_ARROW_DOWN_BUTTON,
			isLoomVGA ? 7  : getBannerColor(9),
			isLoomVGA ? 0  : getBannerColor(10),
			isLoomVGA ? 15 : getBannerColor(17),
			isLoomVGA ? 8  : getBannerColor(18),
			isLoomVGA ? 15 : getBannerColor(19),
			isLoomVGA ? 8  : getBannerColor(20),
			isLoomVGA ? 14 : getBannerColor(11),
			isLoomVGA ? 1  : getBannerColor(12),
			216 - (isLoomVGA ? 10 : 0),
			yConstant + 7,
			232 - (isLoomVGA ? 10 : 0),
			yConstant + 52,
			_arrowDown, 1, 1);
	}

	if (_menuPage == GUI_PAGE_SAVE || _menuPage == GUI_PAGE_LOAD) {
		if (_menuPage == GUI_PAGE_SAVE) {
			// OK button
			setUpInternalGUIControl(GUI_CTRL_OK_BUTTON,
				isLoomVGA ? 7  : getBannerColor(4),
				isLoomVGA ? 0  : getBannerColor(5),
				isLoomVGA ? 15 : getBannerColor(17),
				isLoomVGA ? 8  : getBannerColor(18),
				isLoomVGA ? 15 : getBannerColor(19),
				isLoomVGA ? 8  : getBannerColor(20),
				isLoomVGA ? 14 : getBannerColor(6),
				isLoomVGA ? 1  : getBannerColor(7),
				242 - (isLoomVGA ? 10 : 0),
				yConstant - 8,
				292,
				yConstant - 8 + 12,
				getGUIString(gsOK), 1, 1);
		}

		// Cancel button
		setUpInternalGUIControl(GUI_CTRL_CANCEL_BUTTON,
			isLoomVGA ? 7  : getBannerColor(4),
			isLoomVGA ? 0  : getBannerColor(5),
			isLoomVGA ? 15 : getBannerColor(17),
			isLoomVGA ? 8  : getBannerColor(18),
			isLoomVGA ? 15 : getBannerColor(19),
			isLoomVGA ? 8  : getBannerColor(20),
			isLoomVGA ? 14 : getBannerColor(6),
			isLoomVGA ? 1  : getBannerColor(7),
			242 - (isLoomVGA ? 10 : 0),
			(_menuPage == GUI_PAGE_LOAD ? yConstant - 1 : yConstant + 7),
			292,
			(_menuPage == GUI_PAGE_LOAD ? yConstant - 1 : yConstant + 7) + 12,
			getGUIString(gsCancel), 1, 1);

		// Savegame names
		for (int i = GUI_CTRL_FIRST_SG, j = 0; i <= GUI_CTRL_LAST_SG; i++, j += 11) {
			setUpInternalGUIControl(i,
				isLoomVGA ? 7  : getBannerColor(9),
				isLoomVGA ? 0  : getBannerColor(10),
				isLoomVGA ? 7  : getBannerColor(4),
				isLoomVGA ? 7  : getBannerColor(4),
				isLoomVGA ? 7  : getBannerColor(4),
				isLoomVGA ? 7  : getBannerColor(4),
				isLoomVGA ? 14 : getBannerColor(11),
				isLoomVGA ? 1  : getBannerColor(12),
				28,
				yConstant - 45 + j,
				210 - (isLoomVGA ? 10 : 0),
				-9,
				_savegameNames[i - 1].c_str(), 0, 0);
		}
	}
}

void ScummEngine::setUpMainMenuControlsIndy4Jap() {
	int yConstant = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);

	for (int i = 0; i < ARRAYSIZE(_internalGUIControls); i++) {
		_internalGUIControls[i].relativeCenterX = -1;
	}

	// Outer box
	setUpInternalGUIControl(GUI_CTRL_OUTER_BOX,
		getBannerColor(4),
		getBannerColor(2),
		getBannerColor(13),
		getBannerColor(14),
		getBannerColor(15),
		getBannerColor(16),
		getBannerColor(6),
		getBannerColor(4),
		20,
		yConstant - 64,
		300,
		yConstant + 64,
		_emptyMsg, 1, 1);

	// Inner box
	setUpInternalGUIControl(GUI_CTRL_INNER_BOX,
		getBannerColor(4),
		getBannerColor(5),
		getBannerColor(18),
		getBannerColor(17),
		getBannerColor(20),
		getBannerColor(19),
		getBannerColor(6),
		getBannerColor(7),
		26,
		yConstant - 43,
		-176,
		-102,
		_emptyMsg, 1, 1);

	if (_menuPage == GUI_PAGE_MAIN) {
		// Save button
		setUpInternalGUIControl(GUI_CTRL_SAVE_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			232,
			yConstant - 39,
			-60,
			-18,
			getGUIString(gsSave), 1, 1);

		// Load button
		setUpInternalGUIControl(GUI_CTRL_LOAD_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			232,
			yConstant - 18,
			-60,
			-18,
			getGUIString(gsLoad), 1, 1);

		// Play button
		setUpInternalGUIControl(GUI_CTRL_PLAY_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			232,
			yConstant + 3,
			-60,
			-18,
			getGUIString(gsPlay), 1, 1);

		// Quit button
		setUpInternalGUIControl(GUI_CTRL_QUIT_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			232,
			yConstant + 24,
			-60,
			-18,
			getGUIString(gsQuit), 1, 1);
	}

	// Arrow up button
	setUpInternalGUIControl(GUI_CTRL_ARROW_UP_BUTTON,
		getBannerColor(9),
		getBannerColor(10),
		getBannerColor(17),
		getBannerColor(18),
		getBannerColor(19),
		getBannerColor(20),
		getBannerColor(11),
		getBannerColor(12),
		206,
		yConstant - 39,
		-16,
		-47,
		_arrowUp, 1, 1);

	// Arrow down button
	setUpInternalGUIControl(GUI_CTRL_ARROW_DOWN_BUTTON,
		getBannerColor(9),
		getBannerColor(10),
		getBannerColor(17),
		getBannerColor(18),
		getBannerColor(19),
		getBannerColor(20),
		getBannerColor(11),
		getBannerColor(12),
		206,
		yConstant + 11,
		-16,
		-45,
		_arrowDown, 1, 1);

	if (_menuPage == GUI_PAGE_SAVE || _menuPage == GUI_PAGE_LOAD) {
		// Path button
		setUpInternalGUIControl(GUI_CTRL_PATH_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			232,
			yConstant - 39,
			-60,
			-18,
			"C:/FATE", 1, 1);

		if (_menuPage == GUI_PAGE_SAVE) {
			// OK button
			setUpInternalGUIControl(GUI_CTRL_OK_BUTTON,
				getBannerColor(4),
				getBannerColor(5),
				getBannerColor(17),
				getBannerColor(18),
				getBannerColor(19),
				getBannerColor(20),
				getBannerColor(6),
				getBannerColor(7),
				232,
				yConstant - 18,
				-60,
				-18,
				getGUIString(gsOK), 1, 1);
		}

		// Cancel button
		setUpInternalGUIControl(GUI_CTRL_CANCEL_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			232,
			(_menuPage == GUI_PAGE_LOAD ? yConstant - 8 : yConstant + 3),
			-60,
			-18,
			getGUIString(gsCancel), 1, 1);

		// Savegame names
		for (int i = GUI_CTRL_FIRST_SG, j = 0; i <= GUI_CTRL_LAST_SG; i++, j += 11) {
			setUpInternalGUIControl(i,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(4),
				getBannerColor(4),
				getBannerColor(4),
				getBannerColor(4),
				getBannerColor(11),
				getBannerColor(12),
				28,
				yConstant - 41 + j,
				-172,
				-9,
				_savegameNames[i - 1].c_str(), 0, 0);
		}
	}
}

void ScummEngine::setUpMainMenuControlsSegaCD() {
	int yConstant;
	bool isJap = _language == Common::JA_JPN;

	yConstant = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);

	for (int i = 0; i < ARRAYSIZE(_internalGUIControls); i++) {
		_internalGUIControls[i].relativeCenterX = -1;
	}

	// Outer box
	setUpInternalGUIControl(GUI_CTRL_OUTER_BOX,
							getBannerColor(4),
							getBannerColor(2),
							getBannerColor(13),
							getBannerColor(14),
							getBannerColor(15),
							getBannerColor(16),
							getBannerColor(6),
							getBannerColor(4),
							20,
							yConstant - 60,
							300,
							((yConstant + 60) < 0 ? -120 : yConstant + 60),
							_emptyMsg, 1, 1);

	// Load button
	setUpInternalGUIControl(GUI_CTRL_LOAD_BUTTON,
							getBannerColor(4),
							getBannerColor(5),
							getBannerColor(17),
							getBannerColor(18),
							getBannerColor(19),
							getBannerColor(20),
							getBannerColor(6),
							getBannerColor(7),
							isJap ? 26 : 44,
							yConstant - 31,
							isJap ? 111 : 103,
							yConstant - 31 + 22,
							getGUIString(gsLoad), 1, 1);

	// Play button
	setUpInternalGUIControl(GUI_CTRL_PLAY_BUTTON,
							getBannerColor(4),
							getBannerColor(5),
							getBannerColor(17),
							getBannerColor(18),
							getBannerColor(19),
							getBannerColor(20),
							getBannerColor(6),
							getBannerColor(7),
							isJap ? 26 : 44,
							yConstant - 5,
							isJap ? 111 : 103,
							yConstant - 5 + 22,
							getGUIString(gsPlay), 1, 1);

	// Restart button
	setUpInternalGUIControl(GUI_CTRL_RESTART_BUTTON,
							getBannerColor(4),
							getBannerColor(5),
							getBannerColor(17),
							getBannerColor(18),
							getBannerColor(19),
							getBannerColor(20),
							getBannerColor(6),
							getBannerColor(7),
							isJap ? 26 : 44,
							yConstant + 21,
							isJap ? 111 : 103,
							yConstant + 21 + 22,
							getGUIString(gsRestart), 1, 1);

	if (_menuPage == GUI_PAGE_MAIN) {
		// Arrow left button
		setUpInternalGUIControl(GUI_CTRL_ARROW_LEFT_BUTTON,
								getBannerColor(4),
								getBannerColor(5),
								getBannerColor(17),
								getBannerColor(18),
								getBannerColor(19),
								getBannerColor(20),
								getBannerColor(6),
								getBannerColor(7),
								235,
								yConstant + 18,
								247,
								yConstant + 34,
								_arrowLeft, 1, 1);

		// Arrow right button
		setUpInternalGUIControl(GUI_CTRL_ARROW_RIGHT_BUTTON,
								getBannerColor(4),
								getBannerColor(5),
								getBannerColor(17),
								getBannerColor(18),
								getBannerColor(19),
								getBannerColor(20),
								getBannerColor(6),
								getBannerColor(7),
								248,
								yConstant + 18,
								260,
								yConstant + 34,
								_arrowRight, 1, 1);

		setUpInternalGUIControl(GUI_CTRL_TEXT_SPEED_SLIDER,
								getBannerColor(9),
								getBannerColor(10),
								getBannerColor(18),
								getBannerColor(17),
								getBannerColor(20),
								getBannerColor(19),
								getBannerColor(10),
								getBannerColor(12),
								152,
								yConstant + 18,
								235,
								yConstant + 34,
								_uncheckedBox, 1, 1);
	} else if (_menuPage == GUI_PAGE_RESTART || _menuPage == GUI_PAGE_CODE_CONFIRM) {
		// OK button
		setUpInternalGUIControl(GUI_CTRL_OK_BUTTON,
								getBannerColor(4),
								getBannerColor(5),
								getBannerColor(17),
								getBannerColor(18),
								getBannerColor(19),
								getBannerColor(20),
								getBannerColor(6),
								getBannerColor(7),
								isJap ? 115 : 149,
								yConstant + 21,
								200,
								yConstant + 43,
								getGUIString(gsOK), 1, 1);

		// Cancel button
		setUpInternalGUIControl(GUI_CTRL_CANCEL_BUTTON,
								getBannerColor(4),
								getBannerColor(5),
								getBannerColor(17),
								getBannerColor(18),
								getBannerColor(19),
								getBannerColor(20),
								getBannerColor(6),
								getBannerColor(7),
								206,
								yConstant + 21,
								isJap ? 291 : 257,
								yConstant + 43,
								getGUIString(gsCancel), 1, 1);
	} else if (_menuPage == GUI_PAGE_LOAD) {
		const char numbers[10][2] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

		setUpInternalGUIControl(GUI_CTRL_NUMPAD_0,
								getBannerColor(4),
								getBannerColor(5),
								getBannerColor(17),
								getBannerColor(18),
								getBannerColor(19),
								getBannerColor(20),
								getBannerColor(6),
								getBannerColor(7),
								197,
								yConstant + 43,
								211,
								yConstant + 57,
								numbers[0], 1, 1);

		setUpInternalGUIControl(GUI_CTRL_NUMPAD_BACK,
								getBannerColor(4),
								getBannerColor(5),
								getBannerColor(17),
								getBannerColor(18),
								getBannerColor(19),
								getBannerColor(20),
								getBannerColor(6),
								getBannerColor(7),
								211,
								yConstant + 43,
								239,
								yConstant + 57,
								_arrowLeft, 1, 1);

		for (int row = 0; row < 3; row++) {
			for (int col = 0; col < 3; col++) {
				setUpInternalGUIControl(row * 3 + (col + 1),
										getBannerColor(4),
										getBannerColor(5),
										getBannerColor(17),
										getBannerColor(18),
										getBannerColor(19),
										getBannerColor(20),
										getBannerColor(6),
										getBannerColor(7),
										197 + col * 14,
										yConstant + 29 - row * 14,
										211 + col * 14,
										yConstant + 43 - row * 14,
										numbers[row * 3 + (col + 1)], 1, 1);
			}
		}
	}
}

void ScummEngine_v6::setUpMainMenuControls() {
	int yConstantV6;

	// V7 auxiliary constants
	int cid = _charset->getCurID();
	_charset->setCurID(1);
	int lh = getGUIStringHeight("ABC \x80\x78 \xb0\x78");
	_charset->setCurID(cid);
	int yCntr = _screenHeight / 2;
	int calculatedHeight = (110 + lh) / 2;
	int yOffset = _useCJKMode ? 0 : 1;

	// V6 auxiliary constant
	yConstantV6 = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);

	for (int i = 0; i < ARRAYSIZE(_internalGUIControls); i++) {
		_internalGUIControls[i].relativeCenterX = -1;
	}

	// Outer box
	setUpInternalGUIControl(GUI_CTRL_OUTER_BOX,
		getBannerColor(4),
		getBannerColor(2),
		getBannerColor(13),
		getBannerColor(14),
		getBannerColor(15),
		getBannerColor(16),
		getBannerColor(6),
		getBannerColor(4),
		(_game.version == 7 ? 16 : 20),
		(_game.version == 7 ? yCntr - calculatedHeight - yOffset : yConstantV6 - 60),
		(_game.version == 7 ? 303 : 300),
		(_game.version == 7 ? yCntr + calculatedHeight + yOffset : yConstantV6 + 60),
		_emptyMsg, 1, 1);

	// Inner box
	setUpInternalGUIControl(GUI_CTRL_INNER_BOX,
		getBannerColor(4),
		getBannerColor(5),
		getBannerColor(18),
		getBannerColor(17),
		getBannerColor(20),
		getBannerColor(19),
		getBannerColor(6),
		getBannerColor(7),
		(_game.version == 7 ? 22 : 26),
		(_game.version == 7 ? yCntr - calculatedHeight + lh + 4 : yConstantV6 - 47),
		(_game.version == 7 ? -183 : -176),
		-102,
		_emptyMsg, 1, 1);

	if (_menuPage == GUI_PAGE_MAIN) {
		if (_game.id == GID_FT) {
			// Spooled music checkbox
			setUpInternalGUIControl(GUI_CTRL_SPOOLED_MUSIC_CHECKBOX,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(18),
				getBannerColor(17),
				getBannerColor(20),
				getBannerColor(19),
				getBannerColor(11),
				getBannerColor(12),
				108,
				57,
				-12,
				-12,
				_uncheckedBox, 1, 1);

			// Music volume slider
			setUpInternalGUIControl(GUI_CTRL_MUSIC_SLIDER,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(18),
				getBannerColor(17),
				getBannerColor(20),
				getBannerColor(19),
				getBannerColor(10),
				getBannerColor(12),
				108,
				71,
				-90,
				-12,
				_uncheckedBox, 1, 1);

			// Speech volume slider
			setUpInternalGUIControl(GUI_CTRL_SPEECH_SLIDER,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(18),
				getBannerColor(17),
				getBannerColor(20),
				getBannerColor(19),
				getBannerColor(10),
				getBannerColor(12),
				108,
				85,
				-90,
				-12,
				_uncheckedBox, 1, 1);

			// SFX volume slider
			setUpInternalGUIControl(GUI_CTRL_SFX_SLIDER,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(18),
				getBannerColor(17),
				getBannerColor(20),
				getBannerColor(19),
				getBannerColor(10),
				getBannerColor(12),
				108,
				99,
				-90,
				-12,
				_uncheckedBox, 1, 1);
		} else if (_game.variant && strcmp(_game.variant, "Floppy")) {
			// Music volume slider
			setUpInternalGUIControl(GUI_CTRL_MUSIC_SLIDER,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(18),
				getBannerColor(17),
				getBannerColor(20),
				getBannerColor(19),
				getBannerColor(10),
				getBannerColor(12),
				(_game.version == 7 ? 108 : 102),
				(_game.version == 7 ? yCntr - calculatedHeight - yOffset + 25 : yConstantV6 - 39),
				-90,
				-12,
				_uncheckedBox, 1, 1);

			// Speech volume slider
			setUpInternalGUIControl(GUI_CTRL_SPEECH_SLIDER,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(18),
				getBannerColor(17),
				getBannerColor(20),
				getBannerColor(19),
				getBannerColor(10),
				getBannerColor(12),
				(_game.version == 7 ? 108 : 102),
				(_game.version == 7 ? yCntr - calculatedHeight - yOffset + 43 : yConstantV6 - 25),
				-90,
				-12,
				_uncheckedBox, 1, 1);

			// SFX volume slider
			setUpInternalGUIControl(GUI_CTRL_SFX_SLIDER,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(18),
				getBannerColor(17),
				getBannerColor(20),
				getBannerColor(19),
				getBannerColor(10),
				getBannerColor(12),
				(_game.version == 7 ? 108 : 102),
				(_game.version == 7 ? yCntr - calculatedHeight - yOffset + 61 : yConstantV6 - 11),
				-90,
				-12,
				_uncheckedBox, 1, 1);
		}

		if (_game.variant && strcmp(_game.variant, "Floppy")) {
			// Display text checkbox
			setUpInternalGUIControl(GUI_CTRL_DISPLAY_TEXT_CHECKBOX,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(18),
				getBannerColor(17),
				getBannerColor(20),
				getBannerColor(19),
				getBannerColor(11),
				getBannerColor(12),
				(_game.version == 7 ? 108 : 102),
				(_game.version == 7 ? yCntr - calculatedHeight - yOffset + 85 : yConstantV6 + 17),
				-12,
				-12,
				_uncheckedBox, 1, 1);

			// Text speed slider
			setUpInternalGUIControl(GUI_CTRL_TEXT_SPEED_SLIDER,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(18),
				getBannerColor(17),
				getBannerColor(20),
				getBannerColor(19),
				getBannerColor(10),
				getBannerColor(12),
				(_game.version == 7 ? 108 : 102),
				(_game.version == 7 ? yCntr - calculatedHeight - yOffset + 99 : yConstantV6 + 31),
				-90,
				-(lh + 4),
				_uncheckedBox, 1, 1);
		}

		// Save button
		setUpInternalGUIControl(GUI_CTRL_SAVE_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			(_game.version == 7 ? 235 : 232),
			(_game.version == 7 ? yCntr - calculatedHeight + yOffset * 6 + 30 : yConstantV6 - 23),
			-60,
			-(lh + 4),
			getGUIString(gsSave), 1, 1);

		// Load button
		setUpInternalGUIControl(GUI_CTRL_LOAD_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			(_game.version == 7 ? 235 : 232),
			(_game.version == 7 ? yCntr - calculatedHeight + lh  + yOffset * 6 + 37 : yConstantV6 - 8),
			-60,
			-(lh + 4),
			getGUIString(gsLoad), 1, 1);

		// Play button
		setUpInternalGUIControl(GUI_CTRL_PLAY_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			(_game.version == 7 ? 235 : 232),
			(_game.version == 7 ? yCntr - calculatedHeight + lh * 2  + yOffset * 6 + 44 : yConstantV6 + 7),
			-60,
			-(lh + 4),
			getGUIString(gsPlay), 1, 1);

		// Quit button
		setUpInternalGUIControl(GUI_CTRL_QUIT_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			(_game.version == 7 ? 235 : 232),
			(_game.version == 7 ? yCntr - calculatedHeight + lh * 3  + yOffset * 6 + 51 : yConstantV6 + 22),
			-60,
			-(lh + 4),
			getGUIString(gsQuit), 1, 1);
	}

	if (_game.version == 6 || _menuPage != GUI_PAGE_MAIN) {
		// Arrow up button
		setUpInternalGUIControl(GUI_CTRL_ARROW_UP_BUTTON,
			getBannerColor(9),
			getBannerColor(10),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(11),
			getBannerColor(12),
			(_game.version == 7 ? 209 : 206),
			(_game.version == 7 ? yCntr - calculatedHeight + lh + 8: yConstantV6 - 43),
			-16,
			-47,
			_arrowUp, 1, 1);

		// Arrow down button
		setUpInternalGUIControl(GUI_CTRL_ARROW_DOWN_BUTTON,
			getBannerColor(9),
			getBannerColor(10),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(11),
			getBannerColor(12),
			(_game.version == 7 ? 209 : 206),
			(_game.version == 7 ? yCntr - calculatedHeight + lh + 58 : yConstantV6 + 7),
			-16,
			-45,
			_arrowDown, 1, 1);
	}

	if (_menuPage == GUI_PAGE_SAVE || _menuPage == GUI_PAGE_LOAD) {
		if (_menuPage == GUI_PAGE_SAVE) {
			// OK button
			setUpInternalGUIControl(GUI_CTRL_OK_BUTTON,
				getBannerColor(4),
				getBannerColor(5),
				getBannerColor(17),
				getBannerColor(18),
				getBannerColor(19),
				getBannerColor(20),
				getBannerColor(6),
				getBannerColor(7),
				(_game.version == 7 ? 235 : 232),
				(_game.version == 7 ? yCntr - calculatedHeight + lh + yOffset * 6 + 37: yConstantV6 - 8),
				-60,
				-(lh + 4),
				getGUIString(gsOK), 1, 1);
		}

		// Cancel button
		int cancelButtonAnchorY;
		if (_menuPage == GUI_PAGE_LOAD) {
			if (_game.version == 7) {
				cancelButtonAnchorY = yCntr - calculatedHeight + (lh + 7) / 2 + lh + yOffset * 6 + 37;
			} else {
				cancelButtonAnchorY = yConstantV6 - 1;
			}
		} else {
			if (_game.version == 7) {
				cancelButtonAnchorY = yCntr - calculatedHeight + lh * 2 + yOffset * 6 + 44;
			} else {
				cancelButtonAnchorY = yConstantV6 + 7;
			}
		}
		setUpInternalGUIControl(GUI_CTRL_CANCEL_BUTTON,
			getBannerColor(4),
			getBannerColor(5),
			getBannerColor(17),
			getBannerColor(18),
			getBannerColor(19),
			getBannerColor(20),
			getBannerColor(6),
			getBannerColor(7),
			(_game.version == 7 ? 235 : 232),
			cancelButtonAnchorY,
			-60,
			-(lh + 4),
			getGUIString(gsCancel), 1, 1);

		// Savegame names
		for (int i = GUI_CTRL_FIRST_SG, j = 11; i <= GUI_CTRL_LAST_SG; i++, j += 11) {
			setUpInternalGUIControl(i,
				getBannerColor(9),
				getBannerColor(10),
				getBannerColor(4),
				getBannerColor(4),
				getBannerColor(4),
				getBannerColor(4),
				getBannerColor(11),
				getBannerColor(12),
				(_game.version == 7 ? 24 : 28),
				(_game.version == 7 ? yCntr - calculatedHeight + j + lh - 5 : yConstantV6 + j - 56),
				(_game.version == 7 ? -179 : -172),
				-9,
				_savegameNames[i - 1].c_str(), 0, 0);
		}
	}
}

void ScummEngine::drawMainMenuControls() {
	if (_game.platform == Common::kPlatformSegaCD) {
		drawMainMenuControlsSegaCD();
		return;
	}

	char namePrompt[256];
	char loadPrompt[256];
	char insertDisk[256];

	// Outer box
	drawInternalGUIControl(GUI_CTRL_OUTER_BOX, 0);

	if (_menuPage == GUI_PAGE_MAIN) {
		drawInternalGUIControl(GUI_CTRL_SAVE_BUTTON, 0); // Save button
		drawInternalGUIControl(GUI_CTRL_LOAD_BUTTON, 0); // Load button
		drawInternalGUIControl(GUI_CTRL_PLAY_BUTTON, 0); // Play button
		drawInternalGUIControl(GUI_CTRL_QUIT_BUTTON, 0); // Quit button

		if (_game.version > 4 &&
			_game.id != GID_MONKEY2 && _game.id != GID_MONKEY &&
			_game.platform != Common::kPlatformAmiga &&
			_game.platform != Common::kPlatformFMTowns)
			drawInternalGUIControl(GUI_CTRL_INNER_BOX, 0); // Inner box

		if ((_game.version == 5 &&
			(_game.id != GID_MONKEY2 && _game.id != GID_MONKEY &&
			_game.platform != Common::kPlatformAmiga &&
			_game.platform != Common::kPlatformFMTowns)) ||
			_game.version == 6) {
			drawInternalGUIControl(GUI_CTRL_ARROW_UP_BUTTON, 0);   // Arrow up button
			drawInternalGUIControl(GUI_CTRL_ARROW_DOWN_BUTTON, 0); // Arrow down button
		}

		if ((VAR_FIXEDDISK != 0xFF && VAR(VAR_FIXEDDISK) == 0) ||
			_game.platform == Common::kPlatformAmiga || _game.platform == Common::kPlatformFMTowns) {
			convertMessageToString((const byte *)getGUIString(gsInsertSaveDisk), (byte *)insertDisk, sizeof(insertDisk));
			drawMainMenuTitle(insertDisk);
		}
	}

	if (_menuPage == GUI_PAGE_SAVE || _menuPage == GUI_PAGE_LOAD) {
		if (_game.version > 4 || (_game.version == 4 && _game.id == GID_LOOM))
			drawInternalGUIControl(GUI_CTRL_INNER_BOX, 0);     // Inner box

		drawInternalGUIControl(GUI_CTRL_PATH_BUTTON, 0);   // Path button
		drawInternalGUIControl(GUI_CTRL_OK_BUTTON, 0);     // Ok button
		drawInternalGUIControl(GUI_CTRL_CANCEL_BUTTON, 0); // Cancel button

		// Savegame names
		for (int i = GUI_CTRL_FIRST_SG; i <= GUI_CTRL_LAST_SG; i++) {
			if ((_game.version == 4 && _game.id != GID_LOOM) && _mainMenuSavegameLabel == 0 && i == 1)
				drawInternalGUIControl(i, 1);
			else
				drawInternalGUIControl(i, 0);
		}

		if (_game.version > 4 || (_game.version == 4 && _game.id == GID_LOOM)) {
			drawInternalGUIControl(GUI_CTRL_ARROW_UP_BUTTON, 0);   // Arrow up button
			drawInternalGUIControl(GUI_CTRL_ARROW_DOWN_BUTTON, 0); // Arrow down button
		}

		if (_menuPage == GUI_PAGE_SAVE) {
			convertMessageToString((const byte *)getGUIString(gsNamePrompt), (byte *)namePrompt, sizeof(namePrompt));
			drawMainMenuTitle(namePrompt);
		} else if (_menuPage == GUI_PAGE_LOAD) {
			convertMessageToString((const byte *)getGUIString(gsSelectLoadPrompt), (byte *)loadPrompt, sizeof(loadPrompt));
			drawMainMenuTitle(loadPrompt);
		}
	}

	if (_mainMenuSavegameLabel)
		drawInternalGUIControl(_mainMenuSavegameLabel, 1);

	ScummEngine::drawDirtyScreenParts();
	_system->updateScreen();
}

void ScummEngine::drawMainMenuControlsSegaCD() {
	char buf[256];
	char formattedBuf[256];
	bool isJap = _language == Common::JA_JPN;

	int yConstant = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);
	int stringColor = getBannerColor(2);

	drawInternalGUIControl(GUI_CTRL_OUTER_BOX, 0);
	drawInternalGUIControl(GUI_CTRL_LOAD_BUTTON, 0);
	drawInternalGUIControl(GUI_CTRL_PLAY_BUTTON, 0);
	drawInternalGUIControl(GUI_CTRL_RESTART_BUTTON, 0);

	convertMessageToString((const byte *)getGUIString(gsPause), (byte *)buf, sizeof(buf));
	drawGUIText(buf, nullptr, isJap ? 38 : 24, yConstant - 52, stringColor, false);

	convertMessageToString((const byte *)getGUIString(gsCurrentPasscode), (byte *)buf, sizeof(buf));
	drawGUIText(buf, nullptr, isJap ? 128 : 137, yConstant - 52, stringColor, false);

	Common::sprintf_s(buf, sizeof(buf), "%04d", _scummVars[63]);
	drawGUIText(buf, nullptr, 184, yConstant - 34, stringColor, false);

	if (_menuPage != GUI_PAGE_CODE_CONFIRM && _menuPage != GUI_PAGE_LOAD) {
		for (uint i = 0; i < sizeof(_mainMenuSegaCDPasscode); i++) {
			_mainMenuSegaCDPasscode[i] = '\0';
		}
	}

	if (_menuPage == GUI_PAGE_MAIN) {
		drawInternalGUIControl(GUI_CTRL_TEXT_SPEED_SLIDER, 0);
		drawInternalGUIControl(GUI_CTRL_ARROW_LEFT_BUTTON, 0);
		drawInternalGUIControl(GUI_CTRL_ARROW_RIGHT_BUTTON, 0);
	} else if (_menuPage == GUI_PAGE_LOAD) {
		drawInternalGUIControl(GUI_CTRL_NUMPAD_0, 0);
		drawInternalGUIControl(GUI_CTRL_NUMPAD_1, 0);
		drawInternalGUIControl(GUI_CTRL_NUMPAD_2, 0);
		drawInternalGUIControl(GUI_CTRL_NUMPAD_3, 0);
		drawInternalGUIControl(GUI_CTRL_NUMPAD_4, 0);
		drawInternalGUIControl(GUI_CTRL_NUMPAD_5, 0);
		drawInternalGUIControl(GUI_CTRL_NUMPAD_6, 0);
		drawInternalGUIControl(GUI_CTRL_NUMPAD_7, 0);
		drawInternalGUIControl(GUI_CTRL_NUMPAD_8, 0);
		drawInternalGUIControl(GUI_CTRL_NUMPAD_9, 0);

		drawInternalGUIControl(GUI_CTRL_NUMPAD_BACK, 0);

		drawInternalGUIControl(GUI_CTRL_OK_BUTTON, 0);
		drawInternalGUIControl(GUI_CTRL_CANCEL_BUTTON, 0);

		convertMessageToString((const byte *)getGUIString(gsEnterPasscode), (byte *)buf, sizeof(buf));
		drawGUIText(buf, nullptr, isJap ? 166 : 146, yConstant - 18, stringColor, false);
	} else if (_menuPage == GUI_PAGE_RESTART) {
		drawInternalGUIControl(GUI_CTRL_OK_BUTTON, 0);
		drawInternalGUIControl(GUI_CTRL_CANCEL_BUTTON, 0);

		convertMessageToString((const byte *)getGUIString(gsRestartGame), (byte *)buf, sizeof(buf));
		drawGUIText(buf, nullptr, isJap ? 163 : 151, yConstant + 4, stringColor, false);
	} else if (_menuPage == GUI_PAGE_CODE_CONFIRM) {
		drawInternalGUIControl(GUI_CTRL_OK_BUTTON, 0);
		drawInternalGUIControl(GUI_CTRL_CANCEL_BUTTON, 0);

		convertMessageToString((const byte *)getGUIString(gsConfirmPasscode), (byte *)buf, sizeof(buf));
		Common::sprintf_s(formattedBuf, sizeof(formattedBuf), buf, atoi(_mainMenuSegaCDPasscode));
		drawGUIText(formattedBuf, nullptr, isJap ? 129 : 135, yConstant + 4, stringColor, false);
	} else if (_menuPage == GUI_PAGE_INVALID_CODE) {
		convertMessageToString((const byte *)getGUIString(gsInvalidPasscode), (byte *)buf, sizeof(buf));
		drawGUIText(buf, nullptr, isJap ? 152 : 141, yConstant + 28, stringColor, false);
	}

	ScummEngine::drawDirtyScreenParts();
	_system->updateScreen();
}

void ScummEngine::updateMainMenuControls() {
	if (_game.platform == Common::kPlatformSegaCD) {
		updateMainMenuControlsSegaCD();
		return;
	}

	if ((_game.variant && !strcmp(_game.variant, "Floppy")) || _game.version < 6)
		return;

	int cid = _charset->getCurID();
	_charset->setCurID(1);
	int lh = getGUIStringHeight("ABC \x80\x78 \xb0\x78");
	_charset->setCurID(cid);

	char msg[256];

	// V7 auxiliary constants
	int yCntr = _screenHeight / 2;
	int calculatedHeight = (110 + lh) / 2;
	int textColor = getBannerColor(2);
	int yOffset = _useCJKMode ? 0 : 1;

	// V6 auxiliary constant
	int yConstantV6 = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);

	strncpy(_mainMenuMusicSlider, "\v\v\v\v\v\v\v\v\v\v\v\v\v\v\v\v", sizeof(_mainMenuMusicSlider));
	strncpy(_mainMenuSpeechSlider, "\v\v\v\v\v\v\v\v\v\v\v\v\v\v\v\v", sizeof(_mainMenuSpeechSlider));
	strncpy(_mainMenuSfxSlider, "\v\v\v\v\v\v\v\v\v\v\v\v\v\v\v\v", sizeof(_mainMenuSfxSlider));
	strncpy(_mainMenuTextSpeedSlider, "\v\v\v\v\v\v\v\v\v\v\v\v\v\v\v\v", sizeof(_mainMenuTextSpeedSlider));

	_mainMenuMusicSlider[getMusicVolume() / 8] = '\f';
	_mainMenuSpeechSlider[getSpeechVolume() / 8] = '\f';
	_mainMenuSfxSlider[getSFXVolume() / 8] = '\f';

	if (VAR_CHARINC != 0xFF)
		_mainMenuTextSpeedSlider[15 - (15 * VAR(VAR_CHARINC) / 9)] = '\f';

	_internalGUIControls[GUI_CTRL_MUSIC_SLIDER].label      = _mainMenuMusicSlider;
	_internalGUIControls[GUI_CTRL_SPEECH_SLIDER].label     = _mainMenuSpeechSlider;
	_internalGUIControls[GUI_CTRL_SFX_SLIDER].label        = _mainMenuSfxSlider;
	_internalGUIControls[GUI_CTRL_TEXT_SPEED_SLIDER].label = _mainMenuTextSpeedSlider;

	if (_sound->isAudioDisabled()) {
		_internalGUIControls[GUI_CTRL_MUSIC_SLIDER].label  = getGUIString(gsDisabled);
		_internalGUIControls[GUI_CTRL_SPEECH_SLIDER].label = getGUIString(gsDisabled);
		_internalGUIControls[GUI_CTRL_SFX_SLIDER].label    = getGUIString(gsDisabled);
	}

	if (_spooledMusicIsToBeEnabled) {
		_internalGUIControls[GUI_CTRL_SPOOLED_MUSIC_CHECKBOX].label = _checkedBox;
	} else {
		_internalGUIControls[GUI_CTRL_SPOOLED_MUSIC_CHECKBOX].label = _uncheckedBox;
	}

	_internalGUIControls[GUI_CTRL_DISPLAY_TEXT_CHECKBOX].label = _checkedBox;

	if (VAR_VOICE_MODE != 0xFF && VAR(VAR_VOICE_MODE) == 0) {
		_internalGUIControls[GUI_CTRL_DISPLAY_TEXT_CHECKBOX].label = _uncheckedBox;
		_internalGUIControls[GUI_CTRL_TEXT_SPEED_SLIDER].label = getGUIString(gsDisabled);
	}

	drawInternalGUIControl(GUI_CTRL_MUSIC_SLIDER,  0); // Music slider
	drawInternalGUIControl(GUI_CTRL_SPEECH_SLIDER, 0); // Speech slider
	drawInternalGUIControl(GUI_CTRL_SFX_SLIDER,    0); // SFX slider

	if (_game.id == GID_FT)
		drawInternalGUIControl(GUI_CTRL_SPOOLED_MUSIC_CHECKBOX, 0); // Spooled music checkbox

	drawInternalGUIControl(GUI_CTRL_DISPLAY_TEXT_CHECKBOX, 0); // Display text checkbox
	drawInternalGUIControl(GUI_CTRL_TEXT_SPEED_SLIDER,     0); // Text speed slider

	if (_game.version == 7) {
		// Full Throttle has the "Spooled Music" checkbox,
		// not rendered in the other games, so adjust that...
		if (_game.id == GID_FT) {
			convertMessageToString((const byte *)getGUIString(gsSpooledMusic), (byte *)msg, sizeof(msg));
			drawGUIText(msg, nullptr, 29, yCntr - calculatedHeight - yOffset + 19, textColor, false);

			convertMessageToString((const byte *)getGUIString(gsMusic), (byte *)msg, sizeof(msg));
			drawGUIText(msg, nullptr, 29, yCntr - calculatedHeight - yOffset + 33, textColor, false);

			convertMessageToString((const byte *)getGUIString(gsVoice), (byte *)msg, sizeof(msg));
			drawGUIText(msg, nullptr, 29, yCntr - calculatedHeight - yOffset + 47, textColor, false);
		} else {
			convertMessageToString((const byte *)getGUIString(gsMusic), (byte *)msg, sizeof(msg));
			drawGUIText(msg, nullptr, 29, yCntr - calculatedHeight - yOffset + 25, textColor, false);

			convertMessageToString((const byte *)getGUIString(gsVoice), (byte *)msg, sizeof(msg));
			drawGUIText(msg, nullptr, 29, yCntr - calculatedHeight - yOffset + 43, textColor, false);
		}

		convertMessageToString((const byte *)getGUIString(gsSfx), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, 29, yCntr - calculatedHeight - yOffset + 61, textColor, false);

		convertMessageToString((const byte *)getGUIString(gsDisplayText), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, 29, yCntr - calculatedHeight - yOffset + 88, textColor, false);

		convertMessageToString((const byte *)getGUIString(gsTextSpeed), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, 29, yCntr - calculatedHeight - yOffset + 102, textColor, false);

		drawLine(23, yCntr - calculatedHeight - yOffset + 77, 204, yCntr - calculatedHeight - yOffset + 77, getBannerColor(17));
		drawLine(23, yCntr - calculatedHeight - yOffset + 78, 204, yCntr - calculatedHeight - yOffset + 78, getBannerColor(4));
		drawLine(23, yCntr - calculatedHeight - yOffset + 79, 204, yCntr - calculatedHeight - yOffset + 79, getBannerColor(4));
		drawLine(23, yCntr - calculatedHeight - yOffset + 80, 204, yCntr - calculatedHeight - yOffset + 80, getBannerColor(18));

		// The following line is from the Aaron Giles' interpreter of FT, based on the first DOS version;
		// for some reason it doesn't get displayed in the DOS version, and it also overflows
		// onto the internal panel lines, so let's just not draw it...
		// drawLine(24, yCntr - calculatedHeight + 81, 204, yCntr - calculatedHeight + 81, getBannerColor(4));
	} else {
		convertMessageToString((const byte *)getGUIString(gsMusic), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, 33, yConstantV6 - 36, textColor, false);

		convertMessageToString((const byte *)getGUIString(gsVoice), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, 33, yConstantV6 - 22, textColor, false);

		convertMessageToString((const byte *)getGUIString(gsSfx), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, 33, yConstantV6 - 8, textColor, false);

		convertMessageToString((const byte *)getGUIString(gsDisplayText), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, 33, yConstantV6 + 19, textColor, false);

		convertMessageToString((const byte *)getGUIString(gsTextSpeed), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, 33, yConstantV6 + 34, textColor, false);

		drawLine(27, yConstantV6 + 8,  201, yConstantV6 + 8,  getBannerColor(17));
		drawLine(27, yConstantV6 + 9,  201, yConstantV6 + 9,  getBannerColor(4));
		drawLine(27, yConstantV6 + 10, 201, yConstantV6 + 10, getBannerColor(4));
		drawLine(27, yConstantV6 + 11, 201, yConstantV6 + 11, getBannerColor(18));
	}

	ScummEngine::drawDirtyScreenParts();
	_system->updateScreen();
}

void ScummEngine::updateMainMenuControlsSegaCD() {
	char msg[256];
	int yConstant = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);
	bool isJap = (_language == Common::JA_JPN);

	if (_menuPage == GUI_PAGE_MAIN) {
		// Fill the slider string of symbols shaped like a "=" character
		strncpy(_mainMenuTextSpeedSlider, "\x3a\x3a\x3a\x3a\x3a\x3a\x3a\x3a\x3a\x3a", sizeof(_mainMenuTextSpeedSlider));

		if (VAR_CHARINC != 0xFF)
			_mainMenuTextSpeedSlider[9 - VAR(VAR_CHARINC)] = '\x3b'; // The cursor of the slider

		_internalGUIControls[GUI_CTRL_TEXT_SPEED_SLIDER].label = _mainMenuTextSpeedSlider;

		drawInternalGUIControl(GUI_CTRL_TEXT_SPEED_SLIDER, 0);

		convertMessageToString((const byte *)getGUIString(gsTextSpeed), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, isJap ? 118 : 167, yConstant, getBannerColor(2), false);

		convertMessageToString((const byte *)getGUIString(gsSlowFast), (byte *)msg, sizeof(msg));
		drawGUIText(msg, nullptr, isJap ? 151 : 158, yConstant + 37, getBannerColor(2), false);
	} else if (_menuPage == GUI_PAGE_LOAD) {
		drawLine(155, yConstant + 15, 191, yConstant + 15, getBannerColor(17));
		drawLine(155, yConstant + 28, 191, yConstant + 28, getBannerColor(17));
		drawLine(155, yConstant + 15, 155, yConstant + 28, getBannerColor(17));
		drawLine(191, yConstant + 15, 191, yConstant + 28, getBannerColor(17));

		drawGUIText(_mainMenuSegaCDPasscode, nullptr, 157, yConstant + 16, getBannerColor(2), false);
	}

	ScummEngine::drawDirtyScreenParts();
	_system->updateScreen();
}

void ScummEngine::drawMainMenuTitle(const char *title) {
	if (_game.platform == Common::kPlatformSegaCD)
		return;

	int boxColor, stringColor;
	int yConstantV6 = _virtscr[kMainVirtScreen].topline + (_virtscr[kMainVirtScreen].h / 2);

	if (_game.version == 4) {
		if (_game.id == GID_LOOM) {
			boxColor = 7;
			stringColor = 0;
		} else {
			boxColor = getBannerColor(6);
			stringColor = getBannerColor(8);
		}
	} else {
		boxColor = getBannerColor(4);
		stringColor = getBannerColor(2);
	}

	// Override for Drafts menu - LOOM FM-Towns.
	// This code path will ONLY be activated when looking at the Draft menu,
	// as this version can't access this code elsewhere.
	if (_game.id == GID_LOOM && _game.platform == Common::kPlatformFMTowns) {
		boxColor = 7;
		stringColor = 0;
	}

	if (_game.id == GID_DIG) {
		int cid = _charset->getCurID();
		_charset->setCurID(1);
		int lh = getGUIStringHeight("ABC \x80\x78 \xb0\x78");
		_charset->setCurID(cid);
		int yCntr = _screenHeight / 2;
		int calculatedHeight = (110 + lh) / 2;
		int yOffset = _useCJKMode ? 0 : 1;

		drawBox(18,
			yCntr - calculatedHeight + _screenTop - yOffset + 4,
			301,
			yCntr - calculatedHeight + _screenTop - yOffset + 3 + lh,
			boxColor);

		drawGUIText(title, nullptr,
			159,
			yCntr - calculatedHeight - yOffset + 4,
			stringColor,
			true);
	} else if (_game.version == 7) {
		drawBox(18, _screenTop + 44, 301, _screenTop + 52, boxColor);
		drawGUIText(title, nullptr, 159, 44, stringColor, true);
	} else if (_game.version == 4) {
		if (_game.id == GID_LOOM) {
			drawBox(22, yConstantV6 - 57, 298, yConstantV6 - 49, boxColor);
			drawGUIText(title, nullptr, 160, yConstantV6 - 57, stringColor, true);
		} else {
			drawBox(21, yConstantV6 - 55, 299, yConstantV6 - 47, boxColor);
			drawGUIText(title, nullptr, 160, yConstantV6 - 55, stringColor, true);
		}
	} else if (_isIndy4Jap) {
		drawBox(22, yConstantV6 - 60, 298, yConstantV6 - 44, boxColor);
		drawGUIText(title, nullptr, 160, yConstantV6 - 60, stringColor, true);
	} else {
		drawBox(22, yConstantV6 - 56, 298, yConstantV6 - 48, boxColor);
		drawGUIText(title, nullptr, 160, yConstantV6 - 56, stringColor, true);
	}

	ScummEngine::drawDirtyScreenParts();
	_system->updateScreen();
}

int ScummEngine::getGUIStringHeight(const char *str) {
	return _charset->getFontHeight();
}

int ScummEngine::getGUIStringWidth(const char *str) {
	return _charset->getStringWidth(0, (const byte *)str);
}

void ScummEngine::drawGUIText(const char *buttonString, Common::Rect *clipRect, int textXPos, int textYPos, int textColor, bool centerFlag) {
	int tmpRight = _string[5].right;

	_string[5].xpos = textXPos;
	_string[5].ypos = textYPos;
	_string[5].right = clipRect ? clipRect->right : _screenWidth - 1;
	_string[5].center = centerFlag;
	_string[5].color = textColor;

	if (_game.platform == Common::kPlatformSegaCD)
		_string[5].charset = 6;
	else
		_string[5].charset = _game.version > 3 ? 1 : 0;

	drawString(5, (const byte *)buttonString);
	_string[5].right = tmpRight;
}

void ScummEngine::getSliderString(int stringId, int value, char *sliderString, int size) {
	char *ptrToChar;
	char tempStr[256];
	if (_game.version > 2) {
		Common::strlcpy(tempStr, getGUIString(stringId), sizeof(tempStr));
		convertMessageToString((const byte *)tempStr, (byte *)sliderString, size);

		ptrToChar = strchr(sliderString, '=');

		if (!ptrToChar) {
			ptrToChar = strstr(sliderString, "xxx");
		}

		if (ptrToChar) {
			if (stringId == gsTextSpeedSlider) {
				memset(ptrToChar, '\v', 10);
				ptrToChar[9 - value] = '\f';
			} else {
				memset(ptrToChar, '\v', 9);
				ptrToChar[value / 15] = '\f';
			}
		}
	} else {
		if (stringId == gsTextSpeedSlider) {
			Common::strlcpy(tempStr, getGUIString(stringId), sizeof(tempStr));

			// Format the string with the arguments...
			Common::sprintf_s(sliderString, size, tempStr, value);
		}
	}
}

const char *ScummEngine_v6::getGUIString(int stringId) {
	InfoDialog d(this, 0);
	int resStringId = -1;

	switch (stringId) {
	case gsPause:
		resStringId = 4;
		break;
	case gsRestart:
		resStringId = 5;
		break;
	case gsQuitPrompt:
		resStringId = 6;
		break;
	case gsSave:
		resStringId = 7;
		break;
	case gsLoad:
		resStringId = 8;
		break;
	case gsPlay:
		resStringId = 9;
		break;
	case gsCancel:
		resStringId = 10;
		break;
	case gsQuit:
		resStringId = 11;
		break;
	case gsOK:
		resStringId = 12;
		break;
	case gsInsertSaveDisk:
		resStringId = 13;
		break;
	case gsMustName:
		resStringId = 14;
		break;
	case gsGameNotSaved:
		resStringId = 15;
		break;
	case gsGameNotLoaded:
		resStringId = 16;
		break;
	case gsSaving:
		resStringId = 17;
		break;
	case gsLoading:
		resStringId = 18;
		break;
	case gsNamePrompt:
		resStringId = 19;
		break;
	case gsSelectLoadPrompt:
		resStringId = 20;
		break;
	case gsTitle:
		resStringId = 21;
		break;
	case gsTextSpeed:
		resStringId = 22;
		break;
	case gsDisplayText:
		resStringId = 23;
		break;
	case gsMusic:
		resStringId = 24;
		break;
	case gsVoice:
		resStringId = 25;
		break;
	case gsSfx:
		resStringId = 26;
		break;
	case gsDisabled:
		resStringId = 27;
		break;
	case gsVoiceOnly:
		resStringId = 28;
		break;
	case gsVoiceAndText:
		resStringId = 29;
		break;
	case gsTextDisplayOnly:
		resStringId = 30;
		break;
	case gsTextSpeedSlider:
		resStringId = 31;
		break;
	case gsMusicVolumeSlider:
		resStringId = 32;
		break;
	case gsVoiceVolumeSlider:
		resStringId = 33;
		break;
	case gsSfxVolumeSlider:
		resStringId = 34;
		break;
	case gsHeap:
		resStringId = 35;
		break;
	case gsRecalJoystick:
		if (_game.id == GID_SAMNMAX && !strcmp(_game.variant, "Floppy")) {
			resStringId = 37;
		} else {
			resStringId = 36;
		}
		break;
	case gsMouseMode:
		resStringId = 38;
		break;
	case gsHeapExt:
		resStringId = 39;
		break;
	default:
		break;
	}

	if (resStringId > 0)
		return d.getPlainEngineString(resStringId);
	else
		return _emptyMsg;
}

const char *ScummEngine::getGUIString(int stringId) {
	InfoDialog d(this, 0);
	int resStringId = -1;
	bool isSegaCD = _game.platform == Common::kPlatformSegaCD;
	switch (stringId) {
	case gsPause:
		resStringId = isSegaCD ? 20 : 4;
		break;
	case gsRestart:
		resStringId = isSegaCD ? 23 : 5;
		break;
	case gsRestartGame:
		resStringId = 5;
		break;
	case gsQuitPrompt:
		resStringId = 6;
		break;
	case gsSave:
		resStringId = 7;
		break;
	case gsLoad:
		resStringId = 8;
		break;
	case gsPlay:
		resStringId = 9;
		break;
	case gsCancel:
		resStringId = 10;
		break;
	case gsQuit:
		resStringId = 11;
		break;
	case gsOK:
		resStringId = 12;
		break;
	case gsInsertSaveDisk:
		resStringId = 13;
		break;
	case gsMustName:
		resStringId = 14;
		break;
	case gsGameNotSaved:
		resStringId = 15;
		break;
	case gsGameNotLoaded:
		resStringId = 16;
		break;
	case gsSaving:
		resStringId = 17;
		break;
	case gsLoading:
		resStringId = 18;
		break;
	case gsNamePrompt:
		resStringId = 19;
		break;
	case gsSelectLoadPrompt:
		resStringId = 20;
		break;
	case gsTitle:
		resStringId = 21;
		break;
	case gsVoiceOnly:
		resStringId = 22;
		break;
	case gsVoiceAndText:
		resStringId = 23;
		break;
	case gsTextDisplayOnly:
		resStringId = 24;
		break;
	case gsTextSpeedSlider:
		if (_game.version <= 2) {
			return "TextRate %d";
		} else {
			resStringId = 25;
		}

		break;
	case gsMusicVolumeSlider:
		resStringId = 26;
		break;
	case gsHeap:
		resStringId = 27;
		break;
	case gsSnapOn:
		switch (_game.version) {
		case 2:
			resStringId = 28;
			break;
		case 3:
			resStringId = 30;
			break;
		default:
			resStringId = 32;
		}

		break;
	case gsSnapOff:
		switch (_game.version) {
		case 2:
			resStringId = 29;
			break;
		case 3:
			resStringId = 31;
			break;
		default:
			resStringId = 33;
		}

		break;
	case gsRecalJoystick:
		resStringId = 34;
		break;
	case gsMouseMode:
		resStringId = 35;
		break;
	case gsMouseOn:
		resStringId = 36;
		break;
	case gsMouseOff:
		resStringId = 37;
		break;
	case gsJoystickOn:
		resStringId = 38;
		break;
	case gsJoystickOff:
		resStringId = 39;
		break;
	case gsSoundsOn:
		resStringId = 40;
		break;
	case gsSoundsOff:
		resStringId = 41;
		break;
	case gsVGAMode:
		resStringId = 42;
		break;
	case gsEGAMode:
		resStringId = 43;
		break;
	case gsCGAMode:
		resStringId = 44;
		break;
	case gsHerculesMode:
		resStringId = 45;
		break;
	case gsTandyMode:
		resStringId = 46;
		break;
	case gsSlowFast:
		resStringId = 22;
		break;
	case gsCurrentPasscode:
		resStringId = 24;
		break;
	case gsEnterPasscode:
		resStringId = 25;
		break;
	case gsInvalidPasscode:
		resStringId = 26;
		break;
	case gsConfirmPasscode:
		resStringId = 27;
		break;
	case gsTextSpeed:
		resStringId = 28;
		break;
	default:
		break;
	}

	if (resStringId > 0)
		return d.getPlainEngineString(resStringId, (_game.id == GID_INDY3) && stringId == gsQuitPrompt);
	else
		return _emptyMsg;
}

} // End of namespace Scumm