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
|
/* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
* /\____/
* \_/__/
*
* General setup utility for the Allegro library.
*
* By Shawn Hargreaves.
*
* Unicode support added by Eric Botcazou.
*
* See readme.txt for copyright information.
*/
#define ALLEGRO_USE_CONSOLE
#include <stdio.h>
#include <string.h>
#include "allegro.h"
#include "allegro/internal/aintern.h"
#ifdef ALLEGRO_LINUX
#include <sys/time.h>
#endif
#ifdef ALLEGRO_INTERNAL_HEADER
#include ALLEGRO_INTERNAL_HEADER
#endif
#include "setup.h"
/* these can be customised to suit your program... */
#ifndef SETUP_TITLE
#define SETUP_TITLE "Allegro Setup " ALLEGRO_VERSION_STR ", " ALLEGRO_PLATFORM_STR
#endif
#ifndef SETUP_CFG_FILE
#define SETUP_CFG_FILE "allegro.cfg"
#endif
#ifndef SETUP_KEYBOARD_FILE
#define SETUP_KEYBOARD_FILE "keyboard.dat"
#endif
#ifndef SETUP_LANGUAGE_FILE
#define SETUP_LANGUAGE_FILE "language.dat"
#endif
#ifndef SETUP_DATA_FILE
#define SETUP_DATA_FILE "setup.dat"
#endif
#ifndef SETUP_SCREEN_W
#define SETUP_SCREEN_W 320
#define SETUP_SCREEN_H 200
#endif
/* define if you want to use compiled datafiles */
/* #undef SETUP_USE_COMPILED_DATAFILES */
/* to save executable size, since we only need VGA 13h, 256 color mode */
#if (defined ALLEGRO_DOS) && (!defined SETUP_EMBEDDED)
#if (SETUP_SCREEN_W == 320) && (SETUP_SCREEN_H == 200)
BEGIN_GFX_DRIVER_LIST
GFX_DRIVER_VGA
END_GFX_DRIVER_LIST
#endif
#ifdef ALLEGRO_COLOR8
BEGIN_COLOR_DEPTH_LIST
COLOR_DEPTH_8
END_COLOR_DEPTH_LIST
#endif
#endif
/* helper for converting a static string */
static char *uconvert_static_string(char *str)
{
int size;
char *new_str;
if (need_uconvert(str, U_ASCII, U_CURRENT)) {
size = uconvert_size(str, U_ASCII, U_CURRENT);
new_str = malloc(size);
do_uconvert(str, U_ASCII, new_str, U_CURRENT, size);
return new_str;
}
else
return str;
}
/* helper for converting a static const string */
static AL_CONST char *uconvert_static_const_string(AL_CONST char *str)
{
int size;
char *new_str;
if (need_uconvert(str, U_ASCII, U_CURRENT)) {
size = uconvert_size(str, U_ASCII, U_CURRENT);
new_str = malloc(size);
do_uconvert(str, U_ASCII, new_str, U_CURRENT, size);
return new_str;
}
else
return str;
}
/* helper for converting a static string array */
static char **uconvert_static_string_array(char *str_array[])
{
int i = 0;
while (str_array[i]) {
str_array[i] = uconvert_static_string(str_array[i]);
i++;
}
return str_array;
}
/* info about a hardware driver */
typedef struct SOUNDCARD
{
int id;
AL_CONST char *name;
char **param;
AL_CONST char *desc;
int present;
} SOUNDCARD;
static SOUNDCARD *soundcard;
static SOUNDCARD digi_cards[64], midi_cards[64];
/* different types of parameter */
typedef enum PARAM_TYPE
{
param_none,
param_int,
param_hex,
param_id,
param_bool,
param_file,
param_list,
param_num,
param_str
} PARAM_TYPE;
/* info about a soundcard parameter */
typedef struct PARAMETER
{
char *name;
PARAM_TYPE type;
char value[512];
char *def;
int *detect;
char *label;
char *e1, *e2;
char *desc;
} PARAMETER;
/* list of soundcard parameters */
static PARAMETER parameters[] =
{
/* name type value default detect label extra1 extra2 desc */
{ "digi_card", param_id, "", "-1", NULL, "", NULL, NULL, "" },
{ "midi_card", param_id, "", "-1", NULL, "", NULL, NULL, "" },
{ "quality", param_int, "", "0", NULL, "Qual:", NULL, NULL, "Sample mixing quality (0 = fast mixing of 8 bit data into 16 bit buffers, 1 = true 16 bit mixing, 2 = interpolated 16 bit mixing)" },
{ "digi_volume", param_int, "", "-1", NULL, "Vol:", NULL, NULL, "Digital sound volume (0 to 255)" },
{ "midi_volume", param_int, "", "-1", NULL, "Vol:", NULL, NULL, "MIDI music volume (0 to 255)" },
{ "digi_voices", param_int, "", "-1", NULL, "Chan:", NULL, NULL, "Number of channels reserved for playing digital sounds (higher values increase polyphony but degrade speed and quality)" },
{ "midi_voices", param_int, "", "-1", NULL, "Chan:", NULL, NULL, "Number of channels reserved for playing MIDI music (higher values increase polyphony but degrade speed and quality)" },
{ "flip_pan", param_bool, "", "0", NULL, "Pan:", NULL, NULL, "Reverses the left/right stereo placement" },
#ifndef ALLEGRO_WINDOWS
{ "sound_port", param_hex, "", "-1", &_sound_port, "Port:", NULL, NULL, "Port address (usually 220)" },
{ "sound_dma", param_int, "", "-1", &_sound_dma, "DMA:", NULL, NULL, "DMA channel (usually 1)" },
{ "sound_irq", param_int, "", "-1", &_sound_irq, "IRQ:", NULL, NULL, "IRQ number (usually 7)" },
{ "sound_freq", param_list, "", "-1", &_sound_freq, "Freq:", NULL, NULL, "Sample mixing frequency (higher values sound better but require more CPU processing time)" },
{ "sound_bits", param_int, "", "-1", &_sound_bits, "Bits:", NULL, NULL, "Bits per sample (8 or 16: higher values sound better but require more memory)" },
{ "sound_stereo", param_bool, "", "0", &_sound_stereo, "Stereo:", NULL, NULL, "Use device in stereo mode" },
#endif
#ifdef ALLEGRO_DOS
{ "fm_port", param_hex, "", "-1", &_fm_port, "Port:", NULL, NULL, "Port address (usually 388)" },
{ "mpu_port", param_hex, "", "-1", &_mpu_port, "Port:", NULL, NULL, "Port address (usually 330)" },
{ "mpu_irq", param_int, "", "-1", &_mpu_irq, "IRQ:", NULL, NULL, "IRQ number (usually 7)" },
{ "ibk_file", param_file, "", "", NULL, "IBK:", "IBK", NULL, "Custom .IBK instrument patch set" },
{ "ibk_drum_file", param_file, "", "", NULL, "drumIBK:", "IBK", NULL, "Custom .IBK percussion patch set" },
#endif
#ifdef DIGI_OSS
{ "oss_driver", param_str, "", "/dev/dsp", NULL, "Drv:", "", NULL, "Name of the driver (e.g. /dev/dsp)" },
{ "oss_numfrags", param_int, "", "-1", NULL, "NumFr:", NULL, NULL, "Number of fragments (use 2, other values make little difference)" },
{ "oss_fragsize", param_num, "", "-1", NULL, "Siz:", NULL, NULL, "Size of fragment (small values -- choppy sound, large values -- delayed sound)" },
#endif
#ifdef MIDI_OSS
{ "oss_midi_driver", param_str, "", "/dev/sequencer", NULL, "Drv:", "", NULL, "Name of the driver (e.g. /dev/sequencer)" },
#endif
#ifdef DIGI_ESD
{ "esd_server", param_str, "", "", NULL, "Srv:", "", NULL, "Name of the server" },
#endif
#ifdef DIGI_ALSA
{ "alsa_card", param_int, "", "", NULL, "Card:", NULL, NULL, "ALSA card number" },
{ "alsa_pcmdevice", param_int, "", "", NULL, "Dev:", NULL, NULL, "ALSA PCM device number" },
{ "alsa_numfrags", param_int, "", "", NULL, "NumFr:", NULL, NULL, "Number of fragments (use 2, other values make little difference)" },
#endif
#ifdef MIDI_ALSA
{ "alsa_rawmidi_card", param_int, "", "", NULL, "Card:", NULL, NULL, "ALSA RawMIDI card number" },
{ "alsa_rawmidi_device",param_int, "", "", NULL, "Dev:", NULL, NULL, "ALSA RawMIDI device number" },
#endif
#ifdef MIDI_BEOS
{ "be_midi_quality", param_int, "", "1", NULL, "Qual:", NULL, NULL, "BeOS MIDI synthetizer instruments quality (0 = low, 1 = high)" },
{ "be_midi_freq", param_list, "", "-1", NULL, "Freq:", NULL, NULL, "BeOS MIDI sample mixing frequency in Hz" },
{ "be_midi_interpolation",param_int, "", "0", NULL, "Intrp:", NULL, NULL, "BeOS MIDI sample interpolation method (0 = none, 1 = fast linear, 2 = linear)" },
{ "be_midi_reverb", param_int, "", "0", NULL, "Revrb:", NULL, NULL, "BeOS MIDI reverberation intensity (0 to 5)" },
#endif
#ifdef MIDI_CORE_AUDIO
{ "ca_midi_quality", param_int, "", "127", NULL, "Qual:", NULL, NULL, "CoreAudio MIDI synthetizer render quality (0 = low, 127 = high)" },
{ "ca_midi_reverb", param_int, "", "0", NULL, "Revrb:", NULL, NULL, "CoreAudio MIDI reverberation intensity (0 to 5)" },
#endif
#ifdef MIDI_DIGMID
{ "patches", param_file, "", "", NULL, "Patches:", "CFG;DAT", NULL, "MIDI patch set (GUS format default.cfg or Allegro format patches.dat)" },
#endif
{ NULL, param_none, "", "", NULL, NULL, NULL, NULL, NULL }
};
/* helper for converting a parameter array */
static void uconvert_static_parameter(PARAMETER *p)
{
while (p->name) {
p->name = uconvert_static_string(p->name);
usetc(p->value, 0);
p->def = uconvert_static_string(p->def);
p->label = uconvert_static_string(p->label);
if (p->e1)
p->e1 = uconvert_static_string(p->e1);
if (p->e2)
p->e2 = uconvert_static_string(p->e2);
p->desc = uconvert_static_string(p->desc);
p++;
}
}
/* This is the important bit, where we decide what drivers and parameters to
* list. We ask the system driver for a list of the available drivers, and
* then fill in extra information for any that we know about (eg. which
* port numbers and suchlike things they want to use). If we don't know
* about a driver, we can still select it, but obviously won't be able to
* give the user any of the more specialised options for it.
*/
static void find_sound_drivers(void)
{
static char *digi_param[] = {"11", "digi_volume", NULL};
static char *midi_param[] = {"11", "midi_volume", NULL};
_DRIVER_INFO *info;
int c;
/* have to do this at runtime to work with DLL linkage */
parameters[0].detect = &digi_card;
parameters[1].detect = &midi_card;
parameters[2].detect = &_sound_hq;
/* fill in list of digital drivers */
digi_cards[0].id = DIGI_AUTODETECT;
digi_cards[0].name = uconvert_static_string("Autodetect");
digi_cards[0].param = uconvert_static_string_array(digi_param);
digi_cards[0].desc = uconvert_static_string("Attempt to autodetect the digital sound hardware");
digi_cards[0].present = FALSE;
if (system_driver->digi_drivers)
info = system_driver->digi_drivers();
else
info = _digi_driver_list;
c = 1;
while ((info->driver) && (info->id != DIGI_NONE)) {
digi_cards[c].id = info->id;
digi_cards[c].name = digi_cards[c].desc = uconvert_static_const_string(((DIGI_DRIVER *)info->driver)->ascii_name);
digi_cards[c].param = NULL;
digi_cards[c].present = FALSE;
switch (info->id) {
#ifdef DIGI_SB10
case DIGI_SB10:
{
static char *param[] = {"sound_port", "sound_dma", "sound_irq", "digi_volume", "digi_voices", "sound_freq", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("SB v1.0, 8 bit mono using single-shot dma");
break;
}
#endif
#ifdef DIGI_SB15
case DIGI_SB15:
{
static char *param[] = {"sound_port", "sound_dma", "sound_irq", "digi_volume", "digi_voices", "sound_freq", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("SB v1.5, 8 bit mono using single shot dma");
break;
}
#endif
#ifdef DIGI_SB20
case DIGI_SB20:
{
static char *param[] = {"sound_port", "sound_dma", "sound_irq", "digi_volume", "digi_voices", "sound_freq", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("SB v2.0, 8 bit mono using auto-initialised dma");
break;
}
#endif
#ifdef DIGI_SBPRO
case DIGI_SBPRO:
{
static char *param[] = {"sound_port", "sound_dma", "sound_irq", "flip_pan", "quality", "sound_freq", "digi_volume", "digi_voices", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("SB Pro, 8 bit stereo DAC");
break;
}
#endif
#ifdef DIGI_SB16
case DIGI_SB16:
{
static char *param[] = {"sound_port", "sound_dma", "sound_irq", "flip_pan", "quality", "sound_freq", "digi_volume", "digi_voices", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("SB16 or AWE32, 16 bit stereo DAC");
break;
}
#endif
#ifdef DIGI_AUDIODRIVE
case DIGI_AUDIODRIVE:
{
static char *param[] = {"sound_port", "sound_dma", "sound_irq", "flip_pan", "quality", "sound_freq", "digi_volume", "digi_voices", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("ESS AudioDrive (16 bit stereo DAC)");
break;
}
#endif
#ifdef DIGI_SOUNDSCAPE
case DIGI_SOUNDSCAPE:
{
static char *param[] = {"02", "flip_pan", "quality", "sound_freq", "digi_volume", "digi_voices", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("Ensoniq Soundscape (16 bit stereo DAC)");
break;
}
#endif
#ifdef DIGI_WINSOUNDSYS
case DIGI_WINSOUNDSYS:
{
static char *param[] = {"sound_port", "sound_dma", "sound_irq", "flip_pan", "quality", "sound_freq", "digi_volume", "digi_voices", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("Windows Sound System or compatible (AD1848, CS4248, CS4231/A or CS4232 CODEC)");
break;
}
#endif
#ifdef DIGI_OSS
case DIGI_OSS:
{
static char *param[] = {"flip_pan", "sound_bits", "sound_stereo", "oss_numfrags", "oss_fragsize", "sound_freq", "oss_driver", "digi_volume", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("Open Sound System");
break;
}
#endif
#ifdef DIGI_ESD
case DIGI_ESD:
{
static char *param[] = {"flip_pan", "sound_bits", "sound_stereo", "sound_freq", "esd_server", "digi_volume", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("Enlightened Sound Daemon");
break;
}
#endif
#ifdef DIGI_ARTS
case DIGI_ARTS:
{
static char *param[] = {"flip_pan", "sound_bits", "sound_stereo", "sound_freq", "digi_volume", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("aRts");
break;
}
#endif
#ifdef DIGI_ALSA
case DIGI_ALSA:
{
static char *param[] = {"flip_pan", "sound_bits", "sound_stereo", "alsa_numfrags", "alsa_card", "alsa_pcmdevice", "sound_freq", "digi_volume", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("ALSA Sound System");
break;
}
#endif
#ifdef DIGI_BEOS
case DIGI_BEOS:
{
static char *param[] = {"flip_pan", "sound_bits", "sound_stereo", "sound_freq", "digi_volume", NULL};
digi_cards[c].param = uconvert_static_string_array(param);
digi_cards[c].desc = uconvert_static_string("BeOS Sound");
}
#endif
}
info++;
c++;
}
digi_cards[c].id = DIGI_NONE;
digi_cards[c].name = uconvert_static_string("No Sound");
digi_cards[c].param = NULL;
digi_cards[c].desc = uconvert_static_string("The Sound of Silence...");
digi_cards[c].present = FALSE;
/* fill in list of MIDI drivers */
midi_cards[0].id = MIDI_AUTODETECT;
midi_cards[0].name = uconvert_static_string("Autodetect");
midi_cards[0].param = uconvert_static_string_array(midi_param);
midi_cards[0].desc = uconvert_static_string("Attempt to autodetect the MIDI hardware");
midi_cards[0].present = FALSE;
if (system_driver->midi_drivers)
info = system_driver->midi_drivers();
else
info = _midi_driver_list;
c = 1;
while ((info->driver) && (info->id != MIDI_NONE)) {
midi_cards[c].id = info->id;
midi_cards[c].name = midi_cards[c].desc = uconvert_static_const_string(((MIDI_DRIVER *)info->driver)->ascii_name);
midi_cards[c].param = NULL;
midi_cards[c].present = FALSE;
switch (info->id) {
#ifdef MIDI_OPL2
case MIDI_OPL2:
{
static char *param[] = {"22", "fm_port", "midi_volume", "", "ibk_file", "ibk_drum_file", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("(mono) OPL2 FM synth (used in Adlib and standard SB cards)");
break;
}
#endif
#ifdef MIDI_2XOPL2
case MIDI_2XOPL2:
{
static char *param[] = {"22", "fm_port", "midi_volume", "", "ibk_file", "ibk_drum_file", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("(stereo) Two OPL2 FM synths (early SB Pro cards)");
break;
}
#endif
#ifdef MIDI_OPL3
case MIDI_OPL3:
{
static char *param[] = {"22", "fm_port", "midi_volume", "", "ibk_file", "ibk_drum_file", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("(stereo) OPL3 FM synth (Adlib Gold, later SB Pro boards, SB16)");
break;
}
#endif
#ifdef MIDI_AWE32
case MIDI_AWE32:
{
static char *param[] = {"21", "midi_voices", "midi_volume", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("SoundBlaster AWE32 (EMU8000 synth chip)");
break;
}
#endif
#ifdef MIDI_SB_OUT
case MIDI_SB_OUT:
{
static char *param[] = {"21", "sound_port", "midi_volume", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("Raw SB MIDI output to an external synth module");
break;
}
#endif
#ifdef MIDI_MPU
case MIDI_MPU:
{
static char *param[] = {"22", "mpu_port", "mpu_irq", "", "midi_volume", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("MIDI output to an external synth module or wavetable card");
break;
}
#endif
#ifdef MIDI_OSS
case MIDI_OSS:
{
static char *param[] = {"21", "oss_midi_driver", "midi_volume", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("Open Sound System");
break;
}
#endif
#ifdef MIDI_ALSA
case MIDI_ALSA:
{
static char *param[] = {"22", "alsa_rawmidi_card", "alsa_rawmidi_device", "", "midi_volume", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("ALSA RawMIDI");
break;
}
#endif
#ifdef MIDI_BEOS
case MIDI_BEOS:
{
static char *param[] = {"be_midi_quality", "be_midi_interpolation", "be_midi_reverb", "be_midi_freq", "midi_volume", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("BeOS MIDI");
break;
}
#endif
#ifdef MIDI_CORE_AUDIO
case MIDI_CORE_AUDIO:
{
static char *param[] = {"22", "ca_midi_quality", "ca_midi_reverb", "", "midi_volume", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("CoreAudio MIDI synthesizer");
break;
}
#endif
#ifdef MIDI_DIGMID
case MIDI_DIGMID:
{
static char *param[] = {"22", "midi_voices", "midi_volume", "", "patches", NULL};
midi_cards[c].param = uconvert_static_string_array(param);
midi_cards[c].desc = uconvert_static_string("Software wavetable synthesis using the digital sound hardware");
break;
}
#endif
}
info++;
c++;
}
midi_cards[c].id = MIDI_NONE;
midi_cards[c].name = uconvert_static_string("No Sound");
midi_cards[c].param = NULL;
midi_cards[c].desc = uconvert_static_string("The Sound of Silence...");
midi_cards[c].present = FALSE;
}
/* in some places we need to double-buffer the display... */
static BITMAP *buffer;
/* background graphic, font, and test sounds */
#ifdef SETUP_USE_COMPILED_DATAFILES
extern DATAFILE setup_data[];
#else
static DATAFILE *setup_data;
#endif
/* dialogs do fancy stuff as they slide on and off the screen */
typedef enum DIALOG_STATE
{
state_start,
state_slideon,
state_active,
state_slideoff,
state_exit,
state_chain,
state_redraw
} DIALOG_STATE;
/* info about an active dialog */
typedef struct ACTIVE_DIALOG
{
DIALOG_STATE state;
int time;
DIALOG *dialog;
DIALOG_PLAYER *player;
BITMAP *buffer;
DIALOG_STATE (*handler)(int c);
} ACTIVE_DIALOG;
/* list of active dialogs */
static ACTIVE_DIALOG dialogs[4];
static int dialog_count = 0;
/* scrolly text message at the base of the screen */
#define SCROLLER_LENGTH (SCREEN_W/8+2)
static volatile int scroller_time = 0;
static char scroller_msg[256];
static int scroller_pos = 0;
static int scroller_alpha = 256;
static char *scroller_string = EMPTY_STRING;
static char *wanted_scroller = EMPTY_STRING;
static int scroller_string_pos = 0;
/* helper function for clearing the scroller message */
static void clear_scroller(void)
{
int i;
char *p;
p = scroller_msg;
for (i=0; i<SCROLLER_LENGTH; i++)
p += usetc(p, ' ');
}
/* helper function to shift the scroller message */
static void shift_scroller(int c)
{
int i;
char *buffer, *p_src, *p_dest;
buffer = malloc(SCROLLER_LENGTH * uwidth_max(U_CURRENT));
p_src = scroller_msg + uwidth(scroller_msg);
p_dest = buffer;
for (i=0; i<SCROLLER_LENGTH-1; i++)
p_dest += usetc(p_dest, ugetx(&p_src));
usetc(p_dest, c);
ustrncpy(scroller_msg, buffer, SCROLLER_LENGTH);
free(buffer);
}
/* timer interrupt handler */
static void inc_scroller_time(void)
{
scroller_time++;
}
END_OF_STATIC_FUNCTION(inc_scroller_time);
/* dialog procedure for animating the scroller text */
static int scroller_proc(int msg, DIALOG *d, int c)
{
int redraw = FALSE;
int ch, a, i, x;
char *p;
char tmp[32];
if (msg == MSG_IDLE) {
while (scroller_time > 0) {
scroller_pos--;
if (scroller_pos <= -8) {
scroller_pos = 0;
if ((ch = ugetat(scroller_string, scroller_string_pos)) != 0) {
shift_scroller(ch);
scroller_string_pos++;
}
else
shift_scroller(' ');
if (wanted_scroller != scroller_string) {
scroller_alpha -= MIN(32, scroller_alpha);
if (scroller_alpha <= 0) {
clear_scroller();
scroller_string = wanted_scroller;
scroller_string_pos = 0;
for (i=0; i<4; i++) {
if ((ch = ugetat(scroller_string, scroller_string_pos)) != 0) {
shift_scroller(ch);
scroller_string_pos++;
}
}
scroller_alpha = 256;
}
}
else
scroller_alpha += MIN(16, 256-scroller_alpha);
}
redraw = TRUE;
scroller_time--;
}
}
else if (msg == MSG_RADIO) {
clear_scroller();
scroller_string = wanted_scroller;
scroller_string_pos = ustrlen(scroller_string);
scroller_alpha = 256;
redraw = TRUE;
}
if (redraw) {
freeze_mouse_flag = TRUE;
acquire_screen();
p = scroller_msg;
for (i=0; i<SCROLLER_LENGTH; i++) {
x = i*8+scroller_pos;
a = 16 + CLAMP(0, 15-ABS(SCREEN_W/2-x)/(SCREEN_W/32), 15) * scroller_alpha/256;
textprintf_ex(screen, font, x, SCREEN_H-16, a, 0, uconvert_ascii("%c", tmp), ugetx(&p));
}
release_screen();
freeze_mouse_flag = FALSE;
}
return D_O_K;
}
/* helper for drawing a dialog onto a memory bitmap */
static void draw_dialog(ACTIVE_DIALOG *d)
{
BITMAP *oldscreen = screen;
int nowhere;
if (d->player->focus_obj >= 0) {
object_message(d->dialog+d->player->focus_obj, MSG_LOSTFOCUS, 0);
d->dialog[d->player->focus_obj].flags &= ~D_GOTFOCUS;
d->player->focus_obj = -1;
}
if (d->player->mouse_obj >= 0) {
object_message(d->dialog+d->player->mouse_obj, MSG_LOSTMOUSE, 0);
d->dialog[d->player->mouse_obj].flags &= ~D_GOTMOUSE;
d->player->mouse_obj = -1;
}
d->player->res &= ~D_WANTFOCUS;
clear_bitmap(d->buffer);
screen = d->buffer;
dialog_message(d->dialog, MSG_DRAW, 0, &nowhere);
screen = oldscreen;
}
/* start up another dialog */
static void activate_dialog(DIALOG *dlg, DIALOG_STATE (*handler)(int c), int chain)
{
ACTIVE_DIALOG *d = &dialogs[dialog_count];
int i;
for (i=0; dlg[i].proc; i++) {
if (dlg[i].proc == scroller_proc) {
dlg[i].proc = NULL;
centre_dialog(dlg);
dlg[i].proc = scroller_proc;
break;
}
}
d->state = state_start;
d->time = retrace_count;
d->dialog = dlg;
d->player = init_dialog(dlg, -1);
d->buffer = create_bitmap(SCREEN_W, SCREEN_H);
d->handler = handler;
draw_dialog(d);
if (dialog_count > 0) {
draw_dialog(&dialogs[dialog_count-1]);
dialogs[dialog_count-1].state = (chain ? state_chain : state_slideoff);
dialogs[dialog_count-1].time = retrace_count;
}
}
/* main dialog update routine */
static int update(void)
{
BITMAP *oldscreen = screen;
ACTIVE_DIALOG *d;
DIALOG_STATE state;
PALETTE pal;
BITMAP *b;
int pos, ppos, pppos;
int ret;
char tmp[256];
if (dialog_count <= 0)
return FALSE;
d = &dialogs[dialog_count-1];
if (d->state == state_active) {
/* process the dialog */
if (_mouse_screen != screen) {
set_mouse_sprite(NULL);
show_mouse(screen);
}
ret = update_dialog(d->player);
if (!ret) {
if (d->handler)
state = d->handler(d->player->obj);
else
state = state_exit;
if (state == state_exit) {
/* exit this dialog */
draw_dialog(d);
d->state = state_exit;
d->time = retrace_count;
}
else if (state == state_redraw) {
/* redraw the dialog */
d->player->res |= D_REDRAW;
}
}
else {
pos = find_dialog_focus(d->dialog);
if ((pos >= 0) && (d->dialog[pos].dp3))
wanted_scroller = d->dialog[pos].dp3;
}
}
else {
/* sliding on or off */
show_mouse(NULL);
b = setup_data[BACKGROUND].dat;
stretch_blit(b, buffer, 0, 0, b->w, b->h, 0, 0, SCREEN_W, SCREEN_H);
textout_centre_ex(buffer, font, uconvert_ascii(SETUP_TITLE, tmp), SCREEN_W/2, 0, -1, 0);
wanted_scroller = empty_string;
screen = buffer;
scroller_proc(MSG_IDLE, NULL, 0);
screen = oldscreen;
pos = retrace_count - d->time;
if ((dialog_count == 1) && (d->state == state_start))
pos *= 64;
else if ((dialog_count == 1) && (d->state == state_exit))
pos *= 48;
else if (d->state == state_start)
pos *= 96;
else
pos *= 128;
pos = CLAMP(0, 4096-pos, 4096);
pppos = (4096 - pos * pos / 4096);
pos = pppos / 16;
/* draw the slide effect */
switch (d->state) {
case state_start:
ppos = pos;
stretch_sprite(buffer, d->buffer, 0, 0, SCREEN_W+(1024-pppos/4)*SCREEN_W/320, SCREEN_H+(1024-pppos/4)*SCREEN_H/200);
break;
case state_slideon:
ppos = pos;
stretch_sprite(buffer, d->buffer, 0, 0, SCREEN_W*ppos/256, SCREEN_H*ppos/256);
break;
case state_slideoff:
case state_chain:
ppos = 256 - pos;
stretch_sprite(buffer, d->buffer, SCREEN_W/2-SCREEN_W*ppos/512, SCREEN_H/2-SCREEN_H*ppos/512, SCREEN_W*ppos/256, SCREEN_H*ppos/256);
break;
case state_exit:
ppos = 256 - pos;
stretch_sprite(buffer, d->buffer, SCREEN_W-SCREEN_W*ppos/256, SCREEN_H-SCREEN_H*ppos/256, SCREEN_W*ppos/256, SCREEN_H*ppos/256);
break;
default:
ppos = 0;
break;
}
if ((dialog_count == 1) && (d->state != state_slideon) && (d->state != state_slideoff) && (d->state != state_chain)) {
fade_interpolate(black_palette, setup_data[SETUP_PAL].dat, pal, ppos/4, 0, 255);
set_palette(pal);
}
else
vsync();
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
if (pos >= 256) {
/* finished the slide */
switch (d->state) {
case state_start:
case state_slideon:
/* become active */
d->state = state_active;
d->player->res |= D_REDRAW;
break;
case state_slideoff:
/* activate next dialog, and then get ready to slide back on */
dialogs[dialog_count].time = retrace_count;
dialog_count++;
d->state = state_slideon;
break;
case state_exit:
/* time to die! */
shutdown_dialog(d->player);
destroy_bitmap(d->buffer);
dialog_count--;
if (dialog_count > 0)
dialogs[dialog_count-1].time = retrace_count;
break;
case state_chain:
/* kill myself, then activate the next dialog */
shutdown_dialog(d->player);
destroy_bitmap(d->buffer);
dialogs[dialog_count].time = retrace_count;
dialogs[dialog_count-1] = dialogs[dialog_count];
break;
default:
break;
}
}
}
return TRUE;
}
/* helper for checking which drivers are valid */
static void detect_sound(void)
{
int i;
for (i=0; digi_cards[i].id != DIGI_NONE; i++) {
if (detect_digi_driver(digi_cards[i].id) == 0)
digi_cards[i].present = FALSE;
else
digi_cards[i].present = TRUE;
}
digi_cards[i].present = TRUE;
for (i=0; midi_cards[i].id != MIDI_NONE; i++) {
if (detect_midi_driver(midi_cards[i].id) == 0)
midi_cards[i].present = FALSE;
else
midi_cards[i].present = TRUE;
}
midi_cards[i].present = TRUE;
}
/* helper for initialising the sound code */
static int init_sound(char *msg)
{
char b1[256], b2[256], tmp[32];
int i, begin, end;
show_mouse(NULL);
detect_sound();
if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) == 0)
return 0;
if (ustrlen(allegro_error) <= 32) {
ustrzcpy(b1, sizeof(b1), allegro_error);
usetc(b2, 0);
}
else {
begin = ustrlen(allegro_error)*9/16;
end = 10;
for (i=begin; i>end; i--)
if (ugetat(allegro_error, i) == ' ')
break;
ustrzncpy(b1, sizeof(b1), allegro_error, i);
ustrzcpy(b2, sizeof(b2), allegro_error+uoffset(allegro_error, (i == end) ? end : i+1));
}
alert(msg, b1, b2, uconvert_ascii("Ok", tmp), NULL, 0, 0);
return -1;
}
static BITMAP *popup_bitmap = NULL;
static BITMAP *popup_bitmap2 = NULL;
/* helper for displaying a popup message */
static void popup(AL_CONST char *s1, AL_CONST char *s2)
{
int w, w2, c, ct;
if (!popup_bitmap) {
c = MAX(512*SCREEN_W/320, 512*SCREEN_H/200);
ct = 16*SCREEN_W/320;
acquire_screen();
for (w=c; w>=0; w-=2) {
line(screen, w, 16, 0, 16+w, 0);
if (!(w%ct)) {
release_screen();
vsync();
acquire_screen();
}
}
for (w=0; w<c; w+=2) {
line(screen, w+1, 16, 0, 17+w, 0);
if (!(w%ct)) {
release_screen();
vsync();
acquire_screen();
}
}
release_screen();
popup_bitmap = create_bitmap(SCREEN_W, SCREEN_H);
popup_bitmap2 = create_bitmap(SCREEN_W, SCREEN_H);
blit(screen, popup_bitmap, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
}
blit(popup_bitmap, popup_bitmap2, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
if ((s1) || (s2)) {
if (s1)
w = text_length(font, s1);
else
w = 0;
if (s2)
w2 = text_length(font, s2);
else
w2 = 0;
w = MAX(w, w2);
rectfill(popup_bitmap2, (SCREEN_W-w)/2-15, SCREEN_H/2-31, (SCREEN_W+w)/2+15, SCREEN_H/2+31, 0);
rect(popup_bitmap2, (SCREEN_W-w)/2-16, SCREEN_H/2-32, (SCREEN_W+w)/2+16, SCREEN_H/2+32, 255);
if (s1)
textout_centre_ex(popup_bitmap2, font, s1, SCREEN_W/2, SCREEN_H/2-20, -1, -1);
if (s2)
textout_centre_ex(popup_bitmap2, font, s2, SCREEN_W/2, SCREEN_H/2+4, -1, -1);
}
blit(popup_bitmap2, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
}
/* ends the display of a popup message */
static void end_popup(void)
{
if (popup_bitmap) {
blit(popup_bitmap, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
destroy_bitmap(popup_bitmap);
popup_bitmap = NULL;
destroy_bitmap(popup_bitmap2);
popup_bitmap2 = NULL;
}
}
/* joystick test display */
static void plot_joystick_state(BITMAP *bmp, int i)
{
char buf[512], tmp[256];
int j, x, y;
int c = 0;
if (joystick_driver) {
if (num_joysticks > 1)
textprintf_ex(bmp, font, SCREEN_W/2-96, SCREEN_H/2-60+c*20, -1, -1, uconvert_ascii("%s (%d/%d)", tmp),
joystick_driver->name, i+1, num_joysticks);
else
textprintf_ex(bmp, font, SCREEN_W/2-96, SCREEN_H/2-60+c*20, -1, -1, "%s", joystick_driver->name);
c++;
}
for (j=0; j<joy[i].num_sticks; j++) {
if (joy[i].stick[j].num_axis == 2) {
if (joy[i].stick[j].flags & JOYFLAG_ANALOGUE) {
x = (joy[i].stick[j].axis[0].pos+128)*SCREEN_W/256;
y = (joy[i].stick[j].axis[1].pos+128)*SCREEN_H/256;
hline(bmp, x-12, y, x+12, 15);
vline(bmp, x, y-12, y+12, 15);
circle(bmp, x, y, 12, 1);
circlefill(bmp, x, y, 4, 31);
}
else {
uszprintf(buf, sizeof(buf), uconvert_ascii("%s:", tmp), joy[i].stick[j].name);
if (joy[i].stick[j].axis[1].d1)
ustrzcat(buf, sizeof(buf), uconvert_ascii(" up", tmp));
if (joy[i].stick[j].axis[1].d2)
ustrzcat(buf, sizeof(buf), uconvert_ascii(" down", tmp));
if (joy[i].stick[j].axis[0].d1)
ustrzcat(buf, sizeof(buf), uconvert_ascii(" left", tmp));
if (joy[i].stick[j].axis[0].d2)
ustrzcat(buf, sizeof(buf), uconvert_ascii(" right", tmp));
textout_ex(bmp, font, buf, SCREEN_W/2-96, SCREEN_H/2-60+c*20, -1, -1);
c++;
}
}
else {
uszprintf(buf, sizeof(buf), uconvert_ascii("%s: %s %4d %s", tmp),
joy[i].stick[j].name,
uconvert_ascii((joy[i].stick[j].axis[0].d1) ? "<-" : " ", tmp),
joy[i].stick[j].axis[0].pos,
uconvert_ascii((joy[i].stick[j].axis[0].d2) ? "->" : " ", tmp));
textout_ex(bmp, font, buf, SCREEN_W/2-96, SCREEN_H/2-60+c*20, -1, -1);
c++;
}
}
for (j=0; j<joy[i].num_buttons; j++) {
uszprintf(buf, sizeof(buf), uconvert_ascii("%s: %c", tmp), joy[i].button[j].name, joy[i].button[j].b ? '*' : 0);
if (j&1) {
textout_ex(bmp, font, buf, SCREEN_W/2+32, SCREEN_H/2-60+c*20, -1, -1);
c++;
}
else
textout_ex(bmp, font, buf, SCREEN_W/2-96, SCREEN_H/2-60+c*20, -1, -1);
}
textout_centre_ex(bmp, font, uconvert_ascii("- press a key to accept -", tmp), SCREEN_W/2, SCREEN_H-16, 255, -1);
}
/* helper for calibrating the joystick */
static void joystick_proc(int type)
{
int i, c;
char tmp1[256], tmp2[32];
scroller_proc(MSG_RADIO, NULL, 0);
scare_mouse();
remove_joystick();
if (install_joystick(type) != 0) {
alert(uconvert_ascii("Error:", tmp1), allegro_error, NULL, uconvert_ascii("Ok", tmp2), NULL, 0, 0);
unscare_mouse();
return;
}
for (i=0; i<num_joysticks; i++) {
while (joy[i].flags & JOYFLAG_CALIBRATE) {
popup(calibrate_joystick_name(i), uconvert_ascii("and press a button", tmp1));
rest(10);
do {
poll_joystick();
} while ((!joy[i].button[0].b) && (!joy[i].button[1].b) && (!keypressed()));
if (calibrate_joystick(i) != 0) {
remove_joystick();
alert(uconvert_ascii("Error calibrating joystick", tmp1), NULL, NULL, uconvert_ascii("Ok", tmp2), NULL, 0, 0);
end_popup();
unscare_mouse();
return;
}
rest(10);
do {
poll_joystick();
} while ((joy[i].button[0].b) || (joy[i].button[1].b));
clear_keybuf();
}
}
if (!popup_bitmap)
popup(NULL, NULL);
do {
poll_mouse();
} while (mouse_b);
clear_keybuf();
i = 0;
c = 0;
while ((!c) && (!mouse_b)) {
poll_joystick();
poll_mouse();
blit(popup_bitmap, popup_bitmap2, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
plot_joystick_state(popup_bitmap2, i);
blit(popup_bitmap2, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
if (keypressed()) {
c = readkey();
switch (c>>8) {
case KEY_UP:
case KEY_RIGHT:
i++;
c = 0;
break;
case KEY_DOWN:
case KEY_LEFT:
i--;
c = 0;
break;
default:
c &= 0xFF;
break;
}
if (i >= num_joysticks)
i = num_joysticks-1;
if (i < 0)
i = 0;
}
}
end_popup();
do {
poll_mouse();
} while (mouse_b);
clear_keybuf();
unscare_mouse();
}
/* helper for choosing a mouse type */
static void mouse_proc(int type)
{
remove_mouse();
_mouse_type = type;
install_mouse();
}
#ifdef ALLEGRO_LINUX
static void get_mouse_drivers(_DRIVER_INFO **list, int *list_size);
/* Number of devices tested. */
#define NUM_FD 6
/* Some devices can't be read one byte at a time. */
#define PACKET_SIZE 16
static void reset_for_select(int *fd, fd_set *readfds, struct timeval *timeout)
{
int n;
FD_ZERO(readfds);
for (n=0; n<NUM_FD; n++) {
if (fd[n] != -1)
FD_SET(fd[n], readfds);
}
if (timeout) {
timeout->tv_sec = 0;
timeout->tv_usec = 0;
}
}
static int detect_mouse(void)
{
int fd[NUM_FD];
char *devices[NUM_FD] = {
"/dev/mouse",
"/dev/input/mice", /* Collects all the evdev mice, PS/2-style */
"/dev/input/event0",
"/dev/input/event1",
"/dev/input/event2",
"/dev/input/event3"
};
fd_set readfds;
struct timeval timeout;
int n, i;
int w,l,r,t,b;
int retval = -1;
char buffer_array[NUM_FD][16*PACKET_SIZE];
int buffer_size = sizeof(buffer_array[0]);
char *buffer;
char tmp1[256], tmp2[256], tmp3[64], tmp4[64];
AL_CONST char *drv_name;
int count_array[NUM_FD] = {0, 0, 0, 0};
int count;
_DRIVER_INFO *list;
int list_size;
remove_mouse();
/* We try to open several devices because we don't know yet which one
* is the mouse. If at least one was opened, we continue detection.
*/
retval = -1;
for (n=0; n<NUM_FD; n++) {
fd[n] = open(devices[n], O_RDONLY | O_NONBLOCK);
if (fd[n] != -1)
retval = 0;
}
if (retval == -1) {
alert(uconvert_ascii("Couldn't open any device file:", tmp1), ustrerror(errno), NULL, uconvert_ascii("Ok", tmp2), NULL, 0, 0);
goto End;
}
popup(uconvert_ascii("Move your mouse around", tmp1), uconvert_ascii("Press any key to cancel", tmp2));
/* Flush the files. */
while (TRUE) {
reset_for_select(fd, &readfds, &timeout);
retval = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout); /* zero timeout */
if ((retval == -1) && (errno != EINTR)) {
alert(uconvert_ascii("Couldn't flush device files:", tmp1), ustrerror(errno), NULL, uconvert_ascii("Ok", tmp2), NULL, 0, 0);
goto End;
}
if (retval == 0)
break;
if (retval > 0) {
for (n=0; n<NUM_FD; n++) {
if ((fd[n] != -1) && FD_ISSET(fd[n], &readfds)) {
while (read(fd[n], buffer_array[n], PACKET_SIZE) > 0)
;
}
}
}
}
w = buffer_size;
l = (SCREEN_W - w)/2;
r = l + w;
t = SCREEN_H/2 + 64;
b = t + 16;
rect(popup_bitmap2, l-1, t-1, r, b+1, gui_fg_color);
blit(popup_bitmap2, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
/* Read the data produced by the user moving the mouse.
* In most case data will be read from only one file.
*/
for (count = 0; count < buffer_size; ) {
reset_for_select(fd, &readfds, NULL);
if (select(FD_SETSIZE, &readfds, NULL, NULL, &timeout) > 0) {
for (n=0; n<NUM_FD; n++) {
if ((fd[n] != -1) && FD_ISSET(fd[n], &readfds)) {
unsigned int size = MIN(PACKET_SIZE, buffer_size - count_array[n]);
count_array[n] += read(fd[n], buffer_array[n]+count_array[n], size);
if (count_array[n] > count) {
for ( ; count != count_array[n]; count++) {
vline(popup_bitmap2, l + count*w/buffer_size, t, b, gui_mg_color);
blit(popup_bitmap2, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
}
}
}
}
}
if (keypressed() && readkey())
break;
}
/* Catch problems with data reading. */
if (count < buffer_size) {
if (count == 0)
popup(uconvert_ascii("No data received", tmp1), NULL);
else
popup(uconvert_ascii("Insufficient data received", tmp1), NULL);
retval = -1;
goto End;
}
/* The buffer with the most data is very likely the mouse device. */
buffer = NULL;
for (n=0; n<NUM_FD; n++) {
if (count_array[n] == count)
buffer = buffer_array[n];
}
ASSERT(buffer);
popup(uconvert_ascii("Analysing data...", tmp1), NULL);
/* Ask the drivers if they understand the mouse. */
get_mouse_drivers(&list, &list_size);
for (i = 0; i < list_size; i++) {
MOUSE_DRIVER *drv = list[i].driver;
if (drv->analyse_data && drv->analyse_data (buffer, count)) {
drv_name = get_config_text(drv->ascii_name);
if (alert(uconvert_ascii("This driver understands your mouse:", tmp1), drv_name, uconvert_ascii("Select it?", tmp2),
uconvert_ascii("Yes", tmp3), uconvert_ascii("No", tmp4), 'y', 'n') == 1)
break;
}
}
if (i < list_size) {
retval = i;
}
else {
alert(uconvert_ascii("No driver understands your mouse", tmp1), uconvert_ascii("Try using the GPM repeater", tmp2),
uconvert_ascii("or set the device filename by hand", tmp3), uconvert_ascii("Ok", tmp4), NULL, 0, 0);
retval = -1;
}
End:
for (n=0; n<NUM_FD; n++) {
if (fd[n] != -1)
close(fd[n]);
}
end_popup();
install_mouse();
return retval;
}
#endif
/* helper function for building a frequency list */
#define FREQ_ENTRY_SIZE 64
static void build_freq_list(char *freq[], int nfreq, int freq_value[])
{
int i;
char tmp[64];
for (i=0; i<nfreq; i++) {
freq[i] = malloc(FREQ_ENTRY_SIZE);
uszprintf(freq[i], FREQ_ENTRY_SIZE, uconvert_ascii("%d hz", tmp), freq_value[i]);
}
}
static void destroy_freq_list(char *freq[], int nfreq)
{
int i;
for (i=0; i<nfreq; i++) {
if (freq[i]) {
free(freq[i]);
freq[i] = NULL;
}
}
}
/* dialog callback for retrieving the SB frequency list */
static char *freq_getter(int index, int *list_size)
{
static char *freq[4];
if (index < 0) {
if (list_size) {
switch (soundcard->id) {
#if (defined DIGI_SB10) || (defined DIGI_SB15)
case DIGI_SB10:
case DIGI_SB15:
*list_size = 2;
break;
#endif
#ifdef DIGI_SBPRO
case DIGI_SBPRO:
*list_size = 3;
break;
#endif
default:
*list_size = 4;
break;
}
}
else {
destroy_freq_list(freq, 4);
}
return NULL;
}
/* first time ? */
if (!freq[0]) {
#ifdef DIGI_AUDIODRIVE
if (soundcard->id == DIGI_AUDIODRIVE) {
int ess_freq[] =
{
11363,
17046,
22729,
44194
};
build_freq_list(freq, 4, ess_freq);
}
else
#endif
#ifdef DIGI_SOUNDSCAPE
if (soundcard->id == DIGI_SOUNDSCAPE) {
int esc_freq[] =
{
11025,
16000,
22050,
48000
};
build_freq_list(freq, 4, esc_freq);
}
else
#endif
#ifdef DIGI_WINSOUNDSYS
if (soundcard->id == DIGI_WINSOUNDSYS) {
int wss_freq[] =
{
11025,
22050,
44100,
48000
};
build_freq_list(freq, 4, wss_freq);
}
else
#endif
#ifdef ALLEGRO_DOS
{
int sb_freq[] =
{
11906,
16129,
22727,
45454
};
build_freq_list(freq, 4, sb_freq);
}
#else
{
int default_freq[] =
{
11025,
22050,
44100,
48000
};
build_freq_list(freq, 4, default_freq);
}
#endif
}
return freq[index];
}
/* dialog callback for retrieving information about the soundcard list */
static char *card_getter(int index, int *list_size)
{
static char buf[256];
char tmp[64];
int i;
if (index < 0) {
i = 0;
while (soundcard[i].id)
i++;
if (list_size)
*list_size = i+1;
return NULL;
}
if (soundcard[index].present)
uszprintf(buf, sizeof(buf), uconvert_ascii("- %s", tmp), soundcard[index].name);
else
uszprintf(buf, sizeof(buf), uconvert_ascii(" %s", tmp), soundcard[index].name);
return buf;
}
static char keyboard_type[256] = EMPTY_STRING;
static int num_keyboard_layouts = 0;
static char *keyboard_layouts[256];
static char *keyboard_names[256];
static char language_type[256] = EMPTY_STRING;
static int num_language_layouts = 0;
static char *language_layouts[256];
static char *language_names[256];
/* helper for sorting the keyboard list */
static void sort_keyboards(void)
{
int done, i;
do {
done = TRUE;
for (i=0; i<num_keyboard_layouts-1; i++) {
if (ustricmp(keyboard_names[i], keyboard_names[i+1]) > 0) {
char *tl = keyboard_layouts[i];
char *tn = keyboard_names[i];
keyboard_layouts[i] = keyboard_layouts[i+1];
keyboard_names[i] = keyboard_names[i+1];
keyboard_layouts[i+1] = tl;
keyboard_names[i+1] = tn;
done = FALSE;
}
}
} while (!done);
}
/* helper for sorting the language list */
static void sort_languages(void)
{
int done, i;
do {
done = TRUE;
for (i=0; i<num_language_layouts-1; i++) {
if (ustricmp(language_names[i], language_names[i+1]) > 0) {
char *tl = language_layouts[i];
char *tn = language_names[i];
language_layouts[i] = language_layouts[i+1];
language_names[i] = language_names[i+1];
language_layouts[i+1] = tl;
language_names[i+1] = tn;
done = FALSE;
}
}
} while (!done);
}
/* dialog callback for retrieving information about the keyboard list */
static char *keyboard_getter(int index, int *list_size)
{
if (index < 0) {
if (list_size)
*list_size = num_keyboard_layouts;
return NULL;
}
return keyboard_names[index];
}
/* dialog callback for retrieving information about the language list */
static char *language_getter(int index, int *list_size)
{
if (index < 0) {
if (list_size)
*list_size = num_language_layouts;
return NULL;
}
return language_names[index];
}
/* counts how many joystick drivers we have, and returns a list of them */
static void get_joystick_drivers(_DRIVER_INFO **list, int *list_size)
{
_DRIVER_INFO *l;
int c;
if (system_driver->joystick_drivers)
l = system_driver->joystick_drivers();
else
l = _joystick_driver_list;
c = 0;
while (l[c].driver)
c++;
*list = l;
*list_size = c;
}
/* dialog callback for retrieving information about the joystick list */
static AL_CONST char *joystick_getter(int index, int *list_size)
{
_DRIVER_INFO *list;
int size;
get_joystick_drivers(&list, &size);
if (index < 0) {
*list_size = size;
return NULL;
}
return uconvert_static_const_string(((JOYSTICK_DRIVER *)list[index].driver)->ascii_name);
}
/* counts how many mouse drivers we have, and returns a list of them */
static void get_mouse_drivers(_DRIVER_INFO **list, int *list_size)
{
_DRIVER_INFO *l;
int c;
if (system_driver->mouse_drivers)
l = system_driver->mouse_drivers();
else
l = _mouse_driver_list;
c = 0;
while (l[c].driver)
c++;
*list = l;
*list_size = c;
}
/* dialog callback for retrieving information about the mouse list */
static AL_CONST char *mouse_getter(int index, int *list_size)
{
_DRIVER_INFO *list;
int size;
get_mouse_drivers(&list, &size);
if (index < 0) {
*list_size = size;
return NULL;
}
return uconvert_static_const_string(((MOUSE_DRIVER *)list[index].driver)->ascii_name);
}
/* dialog procedure for the soundcard selection listbox */
static int card_proc(int msg, DIALOG *d, int c)
{
int ret = d_list_proc(msg, d, c);
d->dp3 = (void*)soundcard[d->d1].desc;
return ret;
}
/* dialog procedure for the filename selection objects */
#define FILENAME_SIZE 512 /* > 80 chars * max UTF8 char width */
static int filename_proc(int msg, DIALOG *d, int c)
{
PARAMETER *p = d->dp2;
BITMAP *b;
char buf[FILENAME_SIZE], buf2[256], tmp[256];
char *q;
int ret;
if (msg == MSG_START) {
if (!p->e2)
p->e2 = malloc(FILENAME_SIZE);
ustrzcpy(p->e2, FILENAME_SIZE, p->value);
}
else if (msg == MSG_END) {
if (p->e2) {
free(p->e2);
p->e2 = NULL;
}
}
ret = d_check_proc(msg, d, c);
if (ret & D_CLOSE) {
if (ugetc(p->value)) {
ustrzcpy(p->e2, FILENAME_SIZE, p->value);
usetc(p->value, 0);
}
else {
scroller_proc(MSG_RADIO, NULL, 0);
ustrzcpy(buf2, sizeof(buf2), p->desc);
q = ustrchr(buf2 + uwidth(buf2), '(');
if (q) {
usetc(q, 0);
usetat(buf2, -1, 0);
}
ustrzcpy(buf, sizeof(buf), p->e2);
if (file_select_ex(buf2, buf, p->e1, sizeof(buf), 0, 0)) {
ustrzcpy(p->value, sizeof(p->value), buf);
ustrzcpy(p->e2, FILENAME_SIZE, buf);
}
scare_mouse();
b = setup_data[BACKGROUND].dat;
stretch_blit(b, screen, 0, 0, b->w, b->h, 0, 0, SCREEN_W, SCREEN_H);
textout_centre_ex(screen, font, uconvert_ascii(SETUP_TITLE, tmp), SCREEN_W/2, 0, -1, 0);
unscare_mouse();
}
if (p->value[0])
d->flags |= D_SELECTED;
else
d->flags &= ~D_SELECTED;
ret &= ~D_CLOSE;
ret |= D_REDRAW;
}
return ret;
}
/* wrapper for d_list_proc() to free up the dp2 parameter */
static int d_xlist_proc(int msg, DIALOG *d, int c)
{
void *old_dp2;
int ret;
old_dp2 = d->dp2;
d->dp2 = NULL;
ret = d_list_proc(msg, d, c);
d->dp2 = old_dp2;
return ret;
}
static char backup_str[256] = "Go back to the previous menu";
static char digi_desc[256] = EMPTY_STRING;
static char midi_desc[256] = EMPTY_STRING;
static DIALOG main_dlg[] =
{
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help message) */
{ d_button_proc, 30, 32, 125, 23, -1, 16, 0, D_EXIT, 0, 0, "Autodetect", NULL, "Attempt to autodetect your soundcard (ie. guess :-)" },
{ d_button_proc, 166, 32, 125, 23, -1, 16, 0, D_EXIT, 0, 0, "Test", NULL, "Test the current settings" },
{ d_button_proc, 30, 60, 125, 23, -1, 16, 0, D_EXIT, 0, 0, "Digital Driver", NULL, "Manually select a driver for playing digital samples" },
{ d_button_proc, 166, 60, 125, 23, -1, 16, 0, D_EXIT, 0, 0, "Midi Driver", NULL, "Manually select a driver for playing MIDI music" },
{ d_button_proc, 30, 88, 125, 23, -1, 16, 0, D_EXIT, 0, 0, "Locale", NULL, "Select a keyboard layout and system language" },
{ d_button_proc, 166, 88, 125, 23, -1, 16, 0, D_EXIT, 0, 0, "Joystick", NULL, "Calibrate your joystick" },
{ d_button_proc, 30, 116, 125, 23, -1, 16, 0, D_EXIT, 0, 0, "Mouse", NULL, "Configure your mouse" },
{ d_button_proc, 30, 144, 125, 23, -1, 16, 0, D_EXIT, 0, 0, "Save and Exit", NULL, "Exit from the program, saving the current settings into the file '" SETUP_CFG_FILE "'" },
{ d_button_proc, 166, 144, 125, 23, -1, 16, 0, D_EXIT, 0, 0, "Just Exit", NULL, "Exit from the program, without saving the current settings" },
{ scroller_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
static DIALOG test_dlg[] =
{
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help message) */
{ d_button_proc, 100, 50, 121, 25, -1, 16, 0, D_EXIT, 0, 0, "MIDI", NULL, midi_desc },
{ d_button_proc, 30, 87, 81, 25, -1, 16, 0, D_EXIT, 0, 0, "Left", NULL, digi_desc },
{ d_button_proc, 120, 87, 81, 25, -1, 16, 0, D_EXIT, 0, 0, "Centre", NULL, digi_desc },
{ d_button_proc, 210, 87, 81, 25, -1, 16, 0, D_EXIT, 0, 0, "Right", NULL, digi_desc },
{ d_button_proc, 100, 124, 121, 25, -1, 16, 0, D_EXIT, 0, 0, "Exit", NULL, backup_str },
{ scroller_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
static DIALOG card_dlg[] =
{
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help message) */
{ d_button_proc, 30, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "OK", NULL, "Use this driver" },
{ d_button_proc, 166, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "Cancel", NULL, backup_str },
{ card_proc, 20, 36, 281, 84, 255, 16, 0, D_EXIT, 0, 0, card_getter, NULL, NULL },
{ scroller_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
static DIALOG locale_dlg[] =
{
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help message) */
{ d_button_proc, 30, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "OK", NULL, "Use this keyboard layout and language" },
{ d_button_proc, 166, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "Cancel", NULL, backup_str },
{ d_list_proc, 8, 50, 147, 68, 255, 16, 0, D_EXIT, 0, 0, keyboard_getter, NULL, "Select a keyboard layout" },
{ d_list_proc, 166, 50, 147, 68, 255, 16, 0, D_EXIT, 0, 0, language_getter, NULL, "Select language for system messages" },
{ d_ctext_proc, 81, 30, 0, 0, 16, -1, 0, 0, 0, 0, "Keyboard", NULL, NULL },
{ d_ctext_proc, 239, 30, 0, 0, 16, -1, 0, 0, 0, 0, "Language", NULL, NULL },
{ scroller_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
static DIALOG joystick_dlg[] =
{
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help message) */
{ d_button_proc, 30, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "OK", NULL, "Use this joystick type" },
{ d_button_proc, 166, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "Cancel", NULL, backup_str },
{ d_list_proc, 60, 36, 201, 84, 255, 16, 0, D_EXIT, 0, 0, (void*)joystick_getter, NULL, "Select a type of joystick" },
{ scroller_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
static DIALOG mouse_dlg[] =
{
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help message) */
{ d_button_proc, 30, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "OK", NULL, "Use this mouse type" },
{ d_button_proc, 166, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "Cancel", NULL, backup_str },
{ d_list_proc, 70, 36, 181, 84, 255, 16, 0, D_EXIT, 0, 0, (void*)mouse_getter, NULL, "Select a type of mouse" },
{ scroller_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
#ifdef ALLEGRO_LINUX
static DIALOG linux_mouse_dlg[] =
{
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help message) */
{ d_button_proc, 30, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "OK", NULL, "Use this mouse type" },
{ d_button_proc, 166, 132, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "Cancel", NULL, backup_str },
{ d_list_proc, 30, 36, 151, 84, 255, 16, 0, D_EXIT, 0, 0, mouse_getter, NULL, "Select a type of mouse" },
{ d_button_proc, 192, 36, 125, 25, -1, 16, 0, D_EXIT, 0, 0, "Detect", NULL, "Attempt to detect the type of your mouse" },
{ scroller_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
#endif
/* this one is generated depending on which parameters we need */
static DIALOG param_dlg[32];
static int param_ok;
/* handle input from the parameter dialog */
static DIALOG_STATE param_handler(int c)
{
PARAMETER *p;
DIALOG *d = param_dlg;
int i;
char tmp[64];
if (c == param_ok) {
/* save the changes */
while (d->proc) {
p = d->dp2;
if (p) {
switch (p->type) {
case param_int:
case param_num:
if (p->value[0])
i = ustrtol(p->value, NULL, 0);
else
i = -1;
set_config_int(uconvert_ascii("sound", tmp), p->name, i);
ustrzcpy(p->value, sizeof(p->value), get_config_string(uconvert_ascii("sound", tmp), p->name, empty_string));
break;
case param_hex:
if (p->value[0])
i = ustrtol(p->value, NULL, 16);
else
i = -1;
set_config_hex(uconvert_ascii("sound", tmp), p->name, i);
ustrzcpy(p->value, sizeof(p->value), get_config_string(uconvert_ascii("sound", tmp), p->name, empty_string));
break;
case param_id:
if (p->value[0])
i = ustrtol(p->value, NULL, 0);
else
i = -1;
set_config_id(uconvert_ascii("sound", tmp), p->name, i);
ustrzcpy(p->value, sizeof(p->value), get_config_string(uconvert_ascii("sound", tmp), p->name, empty_string));
break;
case param_bool:
set_config_int(uconvert_ascii("sound", tmp), p->name, (d->flags & D_SELECTED) ? 1 : 0);
ustrzcpy(p->value, sizeof(p->value), get_config_string(uconvert_ascii("sound", tmp), p->name, empty_string));
break;
case param_file:
set_config_string(uconvert_ascii("sound", tmp), p->name, p->value);
ustrzcpy(p->value, sizeof(p->value), get_config_string(uconvert_ascii("sound", tmp), p->name, empty_string));
break;
case param_list:
i = ustrtol(freq_getter(d->d1, NULL), NULL, 0);
set_config_int(uconvert_ascii("sound", tmp), p->name, i);
ustrzcpy(p->value, sizeof(p->value), get_config_string(uconvert_ascii("sound", tmp), p->name, empty_string));
break;
case param_str:
set_config_string(uconvert_ascii("sound", tmp), p->name, p->value);
ustrzcpy(p->value, sizeof(p->value), get_config_string(uconvert_ascii("sound", tmp), p->name, empty_string));
break;
default:
break;
}
}
d++;
}
}
else {
/* discard the changes */
while (d->proc) {
p = d->dp2;
if (p)
ustrzcpy(p->value, sizeof(p->value), get_config_string(uconvert_ascii("sound", tmp), p->name, empty_string));
d++;
}
}
return state_exit;
}
/* sets up the soundcard parameter dialog box */
static void setup_param_dialog(void)
{
PARAMETER *p;
DIALOG *d = param_dlg;
char **c = soundcard->param;
char *s;
char tmp[64];
int pos = 0;
int xo = 0;
int yo = 0;
int i, x, y, f, g;
#define DLG(_p, _x, _y, _w, _h, _f, _b, _k, _l, _d1, _d2, _dp, _pa, _m) \
{ \
d->proc = _p; \
d->x = _x; \
d->y = _y; \
d->w = _w; \
d->h = _h; \
d->fg = _f; \
d->bg = _b; \
d->key = _k; \
d->flags = _l; \
d->d1 = _d1; \
d->d2 = _d2; \
d->dp = _dp; \
d->dp2 = _pa; \
d->dp3 = _m; \
d++; \
}
while (*c) {
if ((uisdigit(ugetat(*c, 0))) && (uisdigit(ugetat(*c, 1)))) {
xo = ugetat(*c, 0) - '0';
if (xo)
xo = 100 / xo;
yo = ugetat(*c, 1) - '0';
if (yo)
yo = 38 / yo;
}
else {
x = 16 + (pos%3) * 100 + xo;
y = 30 + (pos/3) * 38 + yo;
pos++;
p = NULL;
for (i=0; parameters[i].name; i++) {
if (ustricmp(parameters[i].name, *c) == 0) {
p = ¶meters[i];
break;
}
}
if (p) {
switch (p->type) {
case param_int:
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help) */
DLG(d_box_proc, x, y, 89, 22, 255, 16, 0, 0, 0, 0, NULL, NULL, NULL);
DLG(d_text_proc, x+4, y+3, 0, 0, 255, 16, 0, 0, 0, 0, p->label, NULL, NULL);
DLG(d_edit_proc, x+54, y+3, 32, 16, 255, 16, 0, 0, 3, 0, p->value, p, p->desc);
break;
case param_hex:
if (ustricmp(p->value, uconvert_ascii("FFFFFFFF", tmp)) == 0)
ustrzcpy(p->value, sizeof(p->value), uconvert_ascii("-1", tmp));
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help) */
DLG(d_box_proc, x, y, 89, 22, 255, 16, 0, 0, 0, 0, NULL, NULL, NULL);
DLG(d_text_proc, x+4, y+3, 0, 0, 255, 16, 0, 0, 0, 0, p->label, NULL, NULL);
DLG(d_edit_proc, x+54, y+3, 32, 16, 255, 16, 0, 0, 3, 0, p->value, p, p->desc);
break;
case param_bool:
if (ustrtol(p->value, NULL, 0) != 0)
f = D_SELECTED;
else
f = 0;
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help) */
DLG(d_box_proc, x, y, 89, 22, 255, 16, 0, 0, 0, 0, NULL, NULL, NULL);
DLG(d_text_proc, x+4, y+3, 0, 0, 255, 16, 0, 0, 0, 0, p->label, NULL, NULL);
DLG(d_check_proc, x+54, y+3, 32, 16, 255, 16, 0, f, 0, 0, uconvert_static_string(" "),p,p->desc);
break;
case param_file:
if (ugetc(p->value))
f = D_SELECTED | D_EXIT;
else
f = D_EXIT;
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help) */
DLG(d_box_proc, x, y, 89, 22, 255, 16, 0, 0, 0, 0, NULL, NULL, NULL);
DLG(d_text_proc, x+4, y+3, 0, 0, 255, 16, 0, 0, 0, 0, p->label, NULL, NULL);
DLG(filename_proc, x+62, y+3, 32, 16, 255, 16, 0, f, 0, 0, empty_string, p, p->desc);
break;
case param_list:
i = ustrtol(p->value, NULL, 0);
freq_getter(-1, &f);
if (i > 0) {
for (g=0; g<f; g++) {
s = freq_getter(g, NULL);
if (i <= ustrtol(s, NULL, 0))
break;
}
}
else {
g = 2;
}
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help) */
DLG(d_xlist_proc, x, y-8, 89, 68, 255, 16, 0, 0, g, 0, freq_getter, p, p->desc);
break;
case param_num:
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help) */
DLG(d_box_proc, x, y, 89, 22, 255, 16, 0, 0, 0, 0, NULL, NULL, NULL);
DLG(d_text_proc, x+4, y+3, 0, 0, 255, 16, 0, 0, 0, 0, p->label, NULL, NULL);
DLG(d_edit_proc, x+40, y+3, 46, 16, 255, 16, 0, 0, 6, 0, p->value, p, p->desc);
break;
case param_str:
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help) */
DLG(d_box_proc, x, y, 89, 22, 255, 16, 0, 0, 0, 0, NULL, NULL, NULL);
DLG(d_text_proc, x+4, y+3, 0, 0, 255, 16, 0, 0, 0, 0, p->label, NULL, NULL);
DLG(d_edit_proc, x+40, y+3, 46, 16, 255, 16, 0, 0, 20, 0, p->value, p, p->desc);
break;
default:
break;
}
}
}
c++;
}
param_ok = (int)(d - param_dlg);
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (p) (help) */
DLG(d_button_proc, 30, 142, 125, 25, -1, 16, 13, D_EXIT, 0, 0, uconvert_static_string("OK"), NULL, uconvert_static_string("Use these parameters"));
DLG(d_button_proc, 166, 142, 125, 25, -1, 16, 0, D_EXIT, 0, 0, uconvert_static_string("Cancel"), NULL,backup_str);
DLG(scroller_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL);
DLG(d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL);
DLG(NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL);
activate_dialog(param_dlg, param_handler, TRUE);
}
/* helper for converting a static dialog array */
static void uconvert_static_dialog(DIALOG *d)
{
while (d->proc) {
if ((d->proc == d_button_proc) || (d->proc == d_ctext_proc)) {
if (d->dp)
d->dp = uconvert_static_string((char *)d->dp);
if (d->dp3 && (d->dp3 != backup_str) && (d->dp3 != digi_desc) && (d->dp3 != midi_desc))
d->dp3 = uconvert_static_string((char *)d->dp3);
}
else if (d->proc == d_list_proc) {
if (d->dp3)
d->dp3 = uconvert_static_string((char *)d->dp3);
}
d++;
}
}
/* handle input from the test dialog */
static DIALOG_STATE test_handler(int c)
{
switch (c) {
case 0:
/* MIDI test */
play_midi(setup_data[TEST_MIDI].dat, FALSE);
return state_redraw;
case 1:
/* left pan */
play_sample(setup_data[TEST_SAMPLE].dat, 255, 0, 1000, FALSE);
return state_redraw;
case 2:
/* centre pan */
play_sample(setup_data[TEST_SAMPLE].dat, 255, 128, 1000, FALSE);
return state_redraw;
case 3:
/* right pan */
play_sample(setup_data[TEST_SAMPLE].dat, 255, 255, 1000, FALSE);
return state_redraw;
default:
/* quit */
remove_sound();
return state_exit;
}
return state_active;
}
/* handle input from the card selection dialog */
static DIALOG_STATE card_handler(int c)
{
int i;
char tmp[64];
switch (c) {
case 0:
case 2:
/* select driver */
i = (soundcard == digi_cards) ? 0 : 1;
soundcard += card_dlg[2].d1;
set_config_id(uconvert_ascii("sound", tmp), parameters[i].name, soundcard->id);
ustrzcpy(parameters[i].value, sizeof(parameters[i].value), get_config_string(uconvert_ascii("sound", tmp), parameters[i].name, empty_string));
if (soundcard->param)
setup_param_dialog();
else
return state_exit;
break;
default:
/* quit */
return state_exit;
}
return state_active;
}
/* handle input from the locale selection dialog */
static DIALOG_STATE locale_handler(int c)
{
char buf[256], tmp[256];
switch (c) {
case 0:
case 2:
case 3:
/* select driver */
if (locale_dlg[2].d1 < num_keyboard_layouts)
ustrzcpy(keyboard_type, sizeof(keyboard_type), keyboard_layouts[locale_dlg[2].d1]);
if (locale_dlg[3].d1 < num_language_layouts) {
ustrzcpy(language_type, sizeof(language_type), language_layouts[locale_dlg[3].d1]);
push_config_state();
uszprintf(buf, sizeof(buf), uconvert_ascii("language = %s\n", tmp), language_type);
set_config_data(buf, ustrsize(buf));
reload_config_texts(NULL);
pop_config_state();
}
return state_exit;
default:
/* quit */
return state_exit;
}
return state_active;
}
/* handle input from the joystick selection dialog */
static DIALOG_STATE joystick_handler(int c)
{
_DRIVER_INFO *list;
int list_size;
switch (c) {
case 0:
case 2:
/* select joystick */
get_joystick_drivers(&list, &list_size);
joystick_proc(list[joystick_dlg[2].d1].id);
return state_exit;
default:
/* quit */
return state_exit;
}
return state_active;
}
/* handle input from the mouse selection dialog */
static DIALOG_STATE mouse_handler(int c)
{
_DRIVER_INFO *list;
int list_size;
#ifdef ALLEGRO_LINUX
int x;
#endif
switch (c) {
case 0:
case 2:
/* select mouse */
get_mouse_drivers(&list, &list_size);
#ifdef ALLEGRO_LINUX
if (system_driver->id == SYSTEM_LINUX)
mouse_proc(list[linux_mouse_dlg[2].d1].id);
else
#endif
mouse_proc(list[mouse_dlg[2].d1].id);
return state_exit;
#ifdef ALLEGRO_LINUX
case 3:
if (system_driver->id == SYSTEM_LINUX) {
x = detect_mouse();
if (x >= 0) {
get_mouse_drivers(&list, &list_size);
mouse_proc(list[x].id);
}
}
return state_exit;
#endif
default:
/* quit */
return state_exit;
}
return state_active;
}
/* handle input from the main dialog */
static DIALOG_STATE main_handler(int c)
{
char b1[256], b2[256], tmp1[256], tmp2[256];
int i;
AL_CONST char *s;
char* s2;
DATAFILE *data;
_DRIVER_INFO *list;
DIALOG *dlg;
int list_size;
switch (c) {
case 0:
/* autodetect */
scroller_proc(MSG_RADIO, NULL, 0);
for (i=0; parameters[i].name; i++) {
set_config_string(uconvert_ascii("sound", tmp1), parameters[i].name, empty_string);
parameters[i].value[0] = 0;
}
reserve_voices(-1, -1);
if (cpu_family <= 4)
_sound_hq = 0;
else if (cpu_family <= 5)
_sound_hq = 1;
else
_sound_hq = 2;
if (init_sound(uconvert_ascii("Unable to autodetect!", tmp1)) != 0)
return state_redraw;
uszprintf(b1, sizeof(b1), uconvert_ascii("Digital: %s", tmp1), uconvert_ascii(digi_driver->ascii_name, tmp2));
uszprintf(b2, sizeof(b2), uconvert_ascii("MIDI: %s", tmp1), uconvert_ascii(midi_driver->ascii_name, tmp2));
alert(uconvert_ascii("- detected hardware -", tmp1), b1, b2, uconvert_ascii("Ok", tmp2), NULL, 0, 0);
for (i=0; parameters[i].name; i++) {
if (parameters[i].detect) {
switch (parameters[i].type) {
case param_int:
case param_num:
case param_bool:
case param_list:
set_config_int(uconvert_ascii("sound", tmp1), parameters[i].name, *parameters[i].detect);
break;
case param_id:
set_config_id(uconvert_ascii("sound", tmp1), parameters[i].name, *parameters[i].detect);
break;
case param_hex:
set_config_hex(uconvert_ascii("sound", tmp1), parameters[i].name, *parameters[i].detect);
break;
default:
break;
}
}
else
set_config_string(uconvert_ascii("sound", tmp1), parameters[i].name, parameters[i].def);
ustrzcpy(parameters[i].value, sizeof(parameters[i].value), get_config_string(uconvert_ascii("sound", tmp1), parameters[i].name, empty_string));
}
remove_sound();
return state_redraw;
case 1:
/* test */
scroller_proc(MSG_RADIO, NULL, 0);
if (init_sound(uconvert_ascii("Sound initialization failed!", tmp1)) != 0)
return state_redraw;
uszprintf(digi_desc, sizeof(digi_desc), uconvert_ascii("Driver: %s Description: %s", tmp1),
uconvert_ascii(digi_driver->ascii_name, tmp2), digi_driver->desc);
uszprintf(midi_desc, sizeof(midi_desc), uconvert_ascii("Driver: %s Description: %s", tmp1),
uconvert_ascii(midi_driver->ascii_name, tmp2), midi_driver->desc);
activate_dialog(test_dlg, test_handler, FALSE);
break;
case 2:
/* choose digital driver */
soundcard = digi_cards;
for (i=0; soundcard[i].id; i++)
if (soundcard[i].id == get_config_id(uconvert_ascii("sound", tmp1), uconvert_ascii("digi_card", tmp2), DIGI_AUTODETECT))
break;
card_dlg[2].d1 = i;
activate_dialog(card_dlg, card_handler, FALSE);
break;
case 3:
/* choose MIDI driver */
soundcard = midi_cards;
for (i=0; soundcard[i].id; i++)
if (soundcard[i].id == get_config_id(uconvert_ascii("sound", tmp1), uconvert_ascii("midi_card", tmp2), MIDI_AUTODETECT))
break;
card_dlg[2].d1 = i;
activate_dialog(card_dlg, card_handler, FALSE);
break;
case 4:
/* read list of keyboard mappings */
if (num_keyboard_layouts <= 0) {
if (find_allegro_resource(b1, uconvert_ascii(SETUP_KEYBOARD_FILE, tmp1), NULL, NULL, NULL, NULL, NULL, sizeof(b1)) == 0)
data = load_datafile(b1);
else
data = NULL;
if (!data) {
scroller_proc(MSG_RADIO, NULL, 0);
alert(uconvert_ascii("Error reading " SETUP_KEYBOARD_FILE, tmp1), NULL, NULL, uconvert_ascii("Ok", tmp2), NULL, 0, 0);
}
else {
ustrzcat(b1, sizeof(b1), uconvert_ascii("#", tmp1));
for (i=0; data[i].type != DAT_END; i++) {
s = get_datafile_property(data+i, DAT_ID('N','A','M','E'));
if (s) {
s2 = ustrstr(s, uconvert_ascii("_CFG", tmp1));
if ((s2) && (ugetat(s2, 4) == 0)) {
s2 = ustrdup(s);
usetat(s2, -4, 0);
keyboard_layouts[num_keyboard_layouts] = s2;
ustrzcpy(b2, sizeof(b2), b1);
ustrzcat(b2, sizeof(b2), s);
push_config_state();
set_config_file(b2);
s = get_config_string(NULL, uconvert_ascii("keyboard_name", tmp1), s2);
s2 = ustrdup(s);
keyboard_names[num_keyboard_layouts] = s2;
pop_config_state();
num_keyboard_layouts++;
}
}
}
unload_datafile(data);
}
}
/* find the currently selected keyboard mapping */
if (num_keyboard_layouts > 0) {
sort_keyboards();
for (i=0; i<num_keyboard_layouts; i++)
if (ustricmp(keyboard_type, keyboard_layouts[i]) == 0)
break;
if (i==num_keyboard_layouts) {
uszprintf(b1, sizeof(b1), uconvert_ascii("(%s)", tmp1), keyboard_type);
scroller_proc(MSG_RADIO, NULL, 0);
alert(uconvert_ascii("Warning: current keyboard", tmp1), b1, uconvert_ascii("not found in " SETUP_KEYBOARD_FILE, tmp2),
uconvert_ascii("Ok", NULL), NULL, 0, 0);
keyboard_layouts[num_keyboard_layouts] = ustrdup(keyboard_type);
keyboard_names[num_keyboard_layouts] = ustrdup(keyboard_type);
num_keyboard_layouts++;
}
locale_dlg[2].d1 = i;
}
/* read list of languages */
if (num_language_layouts <= 0) {
if (find_allegro_resource(b1, uconvert_ascii(SETUP_LANGUAGE_FILE, tmp1), NULL, NULL, NULL, NULL, NULL, sizeof(b1)) == 0)
data = load_datafile(b1);
else
data = NULL;
if (!data) {
scroller_proc(MSG_RADIO, NULL, 0);
alert(uconvert_ascii("Error reading " SETUP_LANGUAGE_FILE, tmp1), NULL, NULL, uconvert_ascii("Ok", tmp2), NULL, 0, 0);
}
else {
ustrzcat(b1, sizeof(b1), uconvert_ascii("#", tmp1));
for (i=0; data[i].type != DAT_END; i++) {
s = get_datafile_property(data+i, DAT_ID('N','A','M','E'));
if (s) {
s2 = ustrstr(s, uconvert_ascii("TEXT_CFG", tmp1));
if ((s2) && (ugetat(s2, 8) == 0)) {
s2 = ustrdup(s);
usetat(s2, -8, 0);
language_layouts[num_language_layouts] = s2;
ustrzcpy(b2, sizeof(b2), b1);
ustrzcat(b2, sizeof(b2), s);
push_config_state();
set_config_file(b2);
s = get_config_string(NULL, uconvert_ascii("language_name", tmp1), s2);
s2 = ustrdup(s);
language_names[num_language_layouts] = s2;
pop_config_state();
num_language_layouts++;
}
}
}
unload_datafile(data);
}
}
/* find the currently selected language mapping */
if (num_language_layouts > 0) {
sort_languages();
for (i=0; i<num_language_layouts; i++)
if (stricmp(language_type, language_layouts[i]) == 0)
break;
if (i==num_language_layouts) {
uszprintf(b1, sizeof(b1), uconvert_ascii("(%s)", tmp1), language_type);
scroller_proc(MSG_RADIO, NULL, 0);
alert(uconvert_ascii("Warning: current language", tmp1), b1, uconvert_ascii("not found in " SETUP_LANGUAGE_FILE, tmp2),
uconvert_ascii("Ok", NULL), NULL, 0, 0);
language_layouts[num_language_layouts] = ustrdup(language_type);
language_names[num_language_layouts] = ustrdup(language_type);
num_language_layouts++;
}
locale_dlg[3].d1 = i;
}
if ((num_keyboard_layouts > 0) || (num_language_layouts > 0))
activate_dialog(locale_dlg, locale_handler, FALSE);
break;
case 5:
/* calibrate joystick */
joystick_dlg[2].d1 = 0;
get_joystick_drivers(&list, &list_size);
install_joystick(JOY_TYPE_AUTODETECT);
for (i=0; list[i].driver; i++) {
if (list[i].id == _joy_type) {
joystick_dlg[2].d1 = i;
break;
}
}
remove_joystick();
activate_dialog(joystick_dlg, joystick_handler, FALSE);
break;
case 6:
/* configure mouse */
dlg = mouse_dlg;
#ifdef ALLEGRO_LINUX
if (system_driver->id == SYSTEM_LINUX)
dlg = linux_mouse_dlg;
#endif
dlg[2].d1 = 0;
get_mouse_drivers(&list, &list_size);
for (i=0; list[i].driver; i++) {
if (list[i].id == _mouse_type) {
dlg[2].d1 = i;
break;
}
}
activate_dialog(dlg, mouse_handler, FALSE);
break;
case 7:
/* save settings and quit */
set_config_file(uconvert_ascii(SETUP_CFG_FILE, tmp1));
set_config_string(uconvert_ascii("system", tmp1), uconvert_ascii("keyboard", tmp2), keyboard_type);
set_config_string(uconvert_ascii("system", tmp1), uconvert_ascii("language", tmp2), language_type);
set_config_id(uconvert_ascii("mouse", tmp1), uconvert_ascii("mouse", tmp2), _mouse_type);
for (i=0; parameters[i].name; i++) {
if (parameters[i].value[0])
set_config_string(uconvert_ascii("sound", tmp1), parameters[i].name, parameters[i].value);
else
set_config_string(uconvert_ascii("sound", tmp1), parameters[i].name, uconvert_ascii(" ", tmp2));
}
save_joystick_data(NULL);
return state_exit;
default:
/* quit */
return state_exit;
}
return state_active;
}
#ifdef SETUP_EMBEDDED
int setup_main(void)
#else
int main(void)
#endif
{
char buf[512], tmp1[256], tmp2[256];
int i;
#ifndef SETUP_EMBEDDED
if (allegro_init() != 0)
return 1;
install_mouse();
install_keyboard();
install_timer();
fade_out(4);
if (set_gfx_mode(GFX_AUTODETECT, SETUP_SCREEN_W, SETUP_SCREEN_H, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message(uconvert_ascii("Unable to set graphic mode\n%s\n", tmp1), allegro_error);
return 1;
}
#endif
set_palette(black_palette);
#ifdef SETUP_USE_COMPILED_DATAFILES
#ifndef ALLEGRO_USE_CONSTRUCTOR
fixup_datafile(setup_data);
#endif
#else
setup_data = load_datafile(uconvert_ascii("#", tmp1));
if (!setup_data) {
if (find_allegro_resource(buf, uconvert_ascii(SETUP_DATA_FILE, tmp1), NULL, NULL, NULL, NULL, NULL, sizeof(buf)) == 0)
setup_data = load_datafile(buf);
}
if (!setup_data) {
#ifdef SETUP_EMBEDDED
set_palette(default_palette);
alert(uconvert_ascii("Error loading " SETUP_DATA_FILE, tmp1), NULL, NULL, uconvert_ascii("OK", tmp2), NULL, 13, 0);
#else
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("%s", uconvert_ascii("Error loading " SETUP_DATA_FILE "\n", tmp1));
#endif
return 1;
}
#endif
set_mouse_range(0, 20, SCREEN_W-1, SCREEN_H-32);
font = setup_data[SETUP_FONT].dat;
clear_scroller();
buffer = create_bitmap(SCREEN_W, SCREEN_H);
LOCK_VARIABLE(scroller_time);
LOCK_FUNCTION(inc_scroller_time);
install_int_ex(inc_scroller_time, BPS_TO_TIMER(160));
set_config_file(uconvert_ascii(SETUP_CFG_FILE, tmp1));
uconvert_static_parameter(parameters);
for (i=0; parameters[i].name; i++)
ustrzcpy(parameters[i].value, sizeof(parameters[i].value), get_config_string(uconvert_ascii("sound", tmp1), parameters[i].name, parameters[i].def));
ustrzcpy(keyboard_type, sizeof(keyboard_type), get_config_string(uconvert_ascii("system", tmp1), uconvert_ascii("keyboard", tmp2), empty_string));
for (i=0; keyboard_type[i]; i++)
if (!uisspace(keyboard_type[i]))
break;
if (!keyboard_type[i])
ustrzcpy(keyboard_type, sizeof(keyboard_type), uconvert_ascii("us", tmp1));
ustrzcpy(language_type, sizeof(language_type), get_config_string(uconvert_ascii("system", tmp1), uconvert_ascii("language", tmp2), empty_string));
for (i=0; language_type[i]; i++)
if (!uisspace(language_type[i]))
break;
if (!language_type[i])
ustrzcpy(language_type, sizeof(language_type), uconvert_ascii("en", tmp2));
find_sound_drivers();
set_config_data(empty_string, 0);
for (i=0; parameters[i].name; i++)
set_config_string(uconvert_ascii("sound", tmp1), parameters[i].name, parameters[i].value);
detect_sound();
if (need_uconvert(backup_str, U_ASCII, U_CURRENT)) {
do_uconvert(backup_str, U_ASCII, tmp1, U_CURRENT, sizeof(tmp1));
ustrzcpy(backup_str, sizeof(backup_str), tmp1);
}
uconvert_static_dialog(main_dlg);
uconvert_static_dialog(test_dlg);
uconvert_static_dialog(card_dlg);
uconvert_static_dialog(locale_dlg);
uconvert_static_dialog(joystick_dlg);
uconvert_static_dialog(mouse_dlg);
#ifdef ALLEGRO_LINUX
uconvert_static_dialog(linux_mouse_dlg);
#endif
activate_dialog(main_dlg, main_handler, FALSE);
dialog_count++;
do {
} while (update());
/* to avoid leaking memory */
freq_getter(-1, NULL);
destroy_bitmap(buffer);
for (i=0; i<num_keyboard_layouts; i++) {
free(keyboard_layouts[i]);
free(keyboard_names[i]);
}
for (i=0; i<num_language_layouts; i++) {
free(language_layouts[i]);
free(language_names[i]);
}
set_mouse_range(0, 0, SCREEN_W-1, SCREEN_H-1);
#ifndef SETUP_USE_COMPILED_DATAFILES
unload_datafile(setup_data);
#endif
remove_int(inc_scroller_time);
return 0;
}
#ifndef SETUP_EMBEDDED
END_OF_MAIN()
#endif
|