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
|
Basic V Guide
~~~~~~~~~~~~~
Contents
~~~~~~~~
Introduction
History
Features
Constants
Variables
Keywords
Line Numbers
Operators
Assignment Operators
Indirection Operators
Array Operations
Built-in Functions
Pseudo Variables
Procedures and Functions
Error Handling
Issuing Commands to the Underlying Operating System
Statement Types
Statements
Commands
The Program Environment
Screen Output
VDU Commands
PLOT Codes
Basic Keywords, Commands and Functions
Introduction
~~~~~~~~~~~~
The following notes give a brief introduction to Basic V and to
the environment that the interpreter emulates. They describe the
entire language but not in any great detail; more attention is
given to features specific to this version of Basic. Useful
information can be found on the web site 'The BBC Lives!' where
scanned version of manuals such as the 'BBC Microcomputer User
Guide' can be found. The information in these manuals is not 100%
relevant to Basic V but they are good for background information
and many details of Basic II, the predecessor of (and to all
intents and purposes, a strict subset of) Basic V.
These notes describe the Basic language. The file 'use' contains
information on how to use the interpreter and on the features
and limitations of the different versions of the program.
History
~~~~~~~
At the start of the 1980s the British Broadcasting Corporation was
looking for a microcomputer to be used for their series 'The
Computer Programme'. The machine chosen became known as the 'BBC
Micro' and it was made by Acorn Computers. It was an extremely
potent and flexible little computer that some people still use to
this day. The dialect of Basic on it was called 'BBC Basic'. This
was an extended Basic that added such features as procedures and
multi-line functions. It was also one of the fastest Basic
interpreters available on an eight-bit computer. The interpreter
was well integrated with the rest of the machine: it was possible
to directly call operating system functions from Basic programs
and there was also a built-in assembler. If something could not be
done in Basic or was too slow it was possible to write the code in
assembler. Many programs were written that used a combination of
Basic and assembler. Compilers and interpreters for languages such
as BCPL, C and Pascal were written for the BBC Micro, but by far
the most popular language was Basic.
In 1987 Acorn brought out the Archimedes. This included a new
version of the BBC Basic interpreter that had many additional
features such as 'CASE' statements and multi-line 'IF' statements.
It kept its reputation for speed. This version of Basic was called
'Basic V' and it is the dialect of the language implemented by
this interpreter.
The operating system that ran on the Archimedes and the machines
that have succeeded it over the years is called 'RISC OS'. This
was designed and written by Acorn Computers.
Features
~~~~~~~~
The main features of Basic V are:
1) It is a structured Basic with a full range of statement
types such as WHILE and REPEAT loops, a block IF statement
and a CASE statement.
2) It has procedures and multi-line functions which can have
local variables and arrays.
3) It has 'indirection operators' which allow data structures to
be constructed and manipulated. Memory can be allocated from
the Basic heap that can be referenced using these operators.
(This is not to say that the dialect includes data structures
per se but they can be set up and used in a way that appears
to be reminiscent of BCPL.)
4) The Acorn-written interpreters include an assembler.
Programs can be written using a mix of Basic and assembler.
All the features of the Basic interpreter are available to
the assembler, so that, for example, functions written in
Basic are used as macros.
5) Speed: the interpreter is very fast.
Notation
~~~~~~~~
A few words on the notation used in these notes might be in
order.
In describing the syntax of statements, parts of the statement
are often put in angle brackets <like this>. The purpose of
this is to say what goes at that part of the statement, for
example:
GOSUB <line number>
This says that the keyword GOSUB is to be followed by a line
number if a GOSUB statement is used in the program. Another
example:
ON ERROR <statements>
This one says that in an 'ON ERROR' statement, the keywords
'ON ERROR' are followed by one or more Basic statements.
In some cases, parts of a statement are in square brackets,
for example:
IF <expression> THEN <line number>
[ ELSE <line number> ]
This means that that part of the statement is optional. In
the example, the '[ ELSE <line number> ]' part of the
statement can be omitted.
Constants
~~~~~~~~~
The interpreter supports five types of variable:
- Decimal integer
- Hexadecimal integer
- Binary integer
- Floating point
- String
Hexadecimal constants begin with a '&' and binary ones with a '%'.
Strings are enclosed in '"'. It is possible to embed a '"' is a
string by preceding it with another '"'. Examples:
&FFFF
&123456
%1001101
%1
"abcdefghij"
"klmnop""qrst"
Variables
~~~~~~~~~
The interpreter supports three main types:
Integer e.g. abc%
Floating point e.g. def
String e.g. ghi$
Integer variables are 32 bits wide. A variable is denoted as being
an integer by having a '%' at the end of the name.
Floating point variables are 64 bits wide. If a variable does
not have either a '%' or a '$' suffix then it is a floating
point variable.
String variables have a '$' suffix at the end of their name. They
can refer to strings that have a maximum length of 65,536
characters.
Note that it is possible for variables of different types to have
the same name, for example, 'abc%', 'abc' and 'abc$' can all exist
at the same time. The '%' and '$' are considered to be part of the
name. Similarly, it is possible to have arrays and simple
variables of the same name, for example:
abcd$ <-- String variable
abcd$() <-- String array
What happens is that the '(' is considered to be part of the name
of the array.
Variable names are case sensitive, so that 'abcd' and 'AbCd' are
different variables.
Basic V has two classes of variables, the normal dynamic variables
that are created when the program runs and a set of what are
called 'static' variables which comprises of the integer variables
A% to Z%. These variables are independent of any program in that
their valaues are not reset or changed when a program is loaded or
modified. They can, for example, be used to pass values from
one program to another.
Keywords
~~~~~~~~
Keywords are Basic's reserved words. They are split into two types
in this interpreter, Basic keywords and Basic commands. Examples
of the former are 'IF', 'ENDPROC' and 'WHILE'. Examples of
commands are 'LOAD', 'LIST' and 'NEW'. A complete list of keywords
is given at the end of these notes.
Basic keywords have to be in upper case. On the other hand,
commands can be given in either lower or upper case to make it
more convenient to type them in.
The interpreter tries to be clever with keywords. In general
keywords cannot be used as variable names but there are cases
where if a keyword is followed by a letter it is not identified as
a keyword, for example, 'COUNT' on its own is a keyword but
'COUNTER' can be used as a variable without any problems. The
keywords taht can are treated in this way are marked with a '*'
in the keyword list at the end of the notes.
Line Numbers
~~~~~~~~~~~~
Each line in a Basic program has a line number. This is used when
editing a program at the command line and in the program by such
statements as 'GOTO', 'GOSUB', 'ON GOTO', and 'RESTORE'. Basic V
is a structured Basic and line numbers are largely superfluous if
statement types such as these are not used. They are still needed
to identify the line on which an error was detected when a program
runs. Programs and libraries can be written without line numbers
using a text editor such as 'vi'. Line numbers will automatically
be added when the program is loaded. Similarly, programs can be
saved without line numbers, although the default is to include
them.
Line numbers are in the range 0 to 65279.
Operators
~~~~~~~~~
Basic V supports the usual range of operators. The following list
details what is available. The operators are given in priority
order, with operators of the same priority grouped together. From
highest to lowest priority they are:
^ Exponentiation
------------------
* Multiplication
/ Division
DIV Integer division
MOD Integer modulus
------------------
+ Addition and string concatenation
- Subtraction
------------------
= Equals
<> Not equals
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<< Left shift
>> Arithmetic right shift
>>> Logical right shift
------------------
AND Logical AND
------------------
OR Logical OR
EOR Exclusive OR
There is a point to watch out for when using the comparison and
shift operators. It is not possible to chain these together in an
expression, for example:
abc% >> 2 <= 10
will give an error. The solution is to put brackets around the
first part of the expression thus:
(abc% >> 2) <= 10
This is a feature of Basic V.
Assignment Operators
~~~~~~~~~~~~~~~~~~~~
As well as using '=' for assignments in the normal way, Basic V
has two other assignment operators:
<variable> += <expression>
<variable> -= <expression>
'+=' adds <expression> to the variable <variable> and '-='
subtracts it.
Examples:
abc% += 1
ghi(N%) -= count
xyz$ += "abcd"
table%!offset% -= X%
$(table%+name%) += "xyz"
Indirection Operators
~~~~~~~~~~~~~~~~~~~~~
These are equivalent to 'peek' and 'poke' in other versions of
Basic except that they are far more flexible and powerful.
Strictly speaking these are not proper operators but language
constructs.
There are two types of operator, unary and dyadic. The unary ones
are:
? Reference to a one byte integer
! Reference to a four byte integer
| Reference to a floating point value
$ Reference to a string
The dyadic operators are:
? Reference to a one byte integer
! Reference to a four byte integer
Note that there are not dyadic versions of '$' and '|'.
Unary operators can be followed by a variable, array reference or
an expression in parentheses. For dyadic operators, the item
before the operator must be a variable or array reference. A
variable, array reference or expression in parentheses follows the
operator.
Examples of unary operators:
$pointer%
!abc%
?(abc%+10)
$text%
$text% = "abc"
Examples of dyadic operators:
pointer%!offset%
abc%?next%
array%(N%)!field%
The operators all work in the same way. The value of the
expression after the operator (unary version) or of the variable
before the operator (dyadic version) is interpreted as an address.
The value after the operator in the dyadic version is a byte
offset from that address.
Indirection operators cannot be chained together, that is, they
cannot be used in an expression such as:
pointer%!offset%!field%
In general, indirection operators can be used in the same way and
places as normal variables and the two forms of reference can be
freely mixed.
Examples:
IF $text%="quit" THEN STOP
table%!offset% = table%!offset2
!(table%+offset%) = !(table%+offset2)
abc = |address+1.0
PROCabcd(!table%, table%!4)
FOR table%!8=1 TO 10: NEXT
The interpreter limits the range of addresses that can be read
from or written to using indirection operators to the Basic
workspace. It is not possible to access any location outside this
block of memory.
Indirection operators can be used to built up and manipulate data
structures. However they are not true data structures in the sense
of structs in a C program and there are no checks on the legality
of references (beyond ensuring that the addresses are in range).
It is possible for a program to allocate memory from the Basic
heap to be used used for data structures and accessed via the
indirection operators. A special form of the DIM statement is
used for this:
DIM table% 100
Strictly speaking this allocates a byte array with indexes 0 to
100. From a more practical point of view, it allocates a 101 byte
block of memory and puts its address in table%. This block can
then be manipulated using the indirection operators as desired,
for example:
$table%="an error message"
table%!0 = 0: table%!4 = 99
In fact, blocks of memory allocated this way can only be
referenced via indirection operators.
Array Operations
~~~~~~~~~~~~~~~~
The interpreter supports some arithmetic operations on entire
arrays. There are some restrictions: the arrays have to be the
same size (number of dimensions and size of each dimension) and of
exactly the same type. Also, general expressions involving arrays
are not allowed, nor is it possible to return an array as the
result from a function. What is allowed is as follows:
Assignment
----------
<array 1> = <array 2>
The contents of <array 2> are copied to <array 1>
<array> = <expression>
All elements of array <array> are set to <expression>
<array> = <expression 1> , <expression 2> , ... , <expression n>
Each expression <expression x> is evaluated and then assigned
to the x'th element of the array <array>. There can be fewer
expressions than there are elements in the array, in which case
the remaining array elements are left unchanged.
<array 1> += <array 2>, <array 1> -= <array2>
Each element of <array 2> is added to <subtracted from) the
corresponding element in <array 1>.
<array> += <expression>, <array> -= <expression>
The expression <expression> is evaluated and the result added
to <subtracted from) each element of <array>.
Examples:
abc%() = def%()
ghi$() = "test"
jkl() = 0.0, 1.1, 2.2, 3.3, FNxyz(4.4)
abc%() += def%()
jhl() -= PI
Addition and Subtraction
------------------------
<array 1> = <array 2> + <array 3>
Add the corresponding elements of <array 2> and <array 3> and
store the result in the same element in <array 1>.
<array 1> = <array 2> - <array 3>
Subtract the elements in <array 3> from the corresponding element
in array <2> and store the result in <array 1>.
<array 1> = <array 2> + <expression>
<array 1> = <expression> + <array 2>
Add <expression> to each element of <array 2>, storing the result
of each addition in the corresponding element of <array 1>.
<array 1> = <array 2> - <expression>
<array 1> = <expression> - <array 2>
Subtract <expression> from each element of <array 2>, storing the
result of each subtraction in the corresponding element of
<array 1>.
Examples:
abc%() = def%() + ghi%()
jkl() = mno() - pqr()
aaa$() = bbb$() + "ccc" + FNddd(eee$)
abc%() = 1 - def%()
Multiplication and Division
---------------------------
<array 1> = <array 2> * <array 3>
Multiply each element of <array 2> by the corresponding element
in <array 3> and store the result in <array 1>.
<array 1> = <array 2> / <array 3>
Divide each element of <array 2> by the corresponding element
in <array 3> and store the result in <array 1>.
<array 1> = <array 2> DIV <array 3>
Carry out an integer division of each element of <array 2> by the
corresponding element in <array 3> and store the result in
<array 1>.
<array 1> = <array 2> MOD <array 3>
Carry out an integer division of each element of <array 2> by the
corresponding element in <array 3> and store the remainder in
<array 1>.
<array 1> = <array 2> * <expression>
<array 1> = <expression> * <array 2>
Multiply each element of <array 2> by the value <expression> and
store the result in the corresponding element in <array 1>.
<array 1> = <array 2> / <expression>
Divide each element of <array 2> by the value <expression> and
store the result in the corresponding element in <array 1>.
<array 1> = <expression> / <array 2>
Divide <expression> by each element of <array 2> and store the
result in the corresponding element in <array 1>.
<array 1> = <array 2> DIV <expression>
Carry out an integer division of each element of <array 2> by the
value <expression> and store the result in the corresponding
element in <array 1>.
<array 1> = <expression> DIV <array 2>
Carry out an integer division of <expression> by each element of
<array 2> and store the result in the corresponding element in
<array 1>.
<array 1> = <array 2> MOD <expression>
Carry out an integer division of each element of <array 2> by the
value <expression> and store the remainder in the corresponding
element in <array 1>.
<array 1> = <expression> MOD <array 2>
Carry out an integer division of <expression> by each element of
<array 2> and store the remainder in the corresponding element in
<array 1>.
Examples:
abc() = def() * ghi()
abc() = 10.0 * ghi()
jkl%() = mno%() MOD 100
abc() = 1 / abc()
Matrix Multiplication
---------------------
<array 1> = <array 2> . <array 3>
Perform a matrix multiplication of <array 2> and <array 3> and
store the result in <array 1>.
Note that '.' is used as the matrix multiplication operator.
Built-in Functions
~~~~~~~~~~~~~~~~~~
The interpreter has a fairly standard set of functions. One
feature of this dialect of Basic is that many of the functions
look like monadic operators, for example, a call to the 'LEN'
function can be written as 'LEN abc$' as well as 'LEN(abc$)'.
Function names can often be abbreviated when typing them at the
command line. The abbreviated version of the name is the first
few characters of the name followed by a dot, for example, the
'LE' is the abbreviated form of 'LEFT$('. The names are given
in full when the program is listed.
Following is a list of functions implemented and a summary of
their actions. More detailed information on the vast majority of
them can be found in the manuals on the 'The BBC Lives!' web site.
Entries marked with a '*' after the name are functions added in
this interpreter.
<factor> represents a simple expression that consists of just a
variable name, array reference or constant or a complete
expression in parentheses.
<expression> is a full expression. Sometimes this is written as
<string expression> or <numeric expression> to qualify the type
of expression, or abbreviated to <expr> to reduce clutter.
<array> is a reference to a whole array.
ABS
Use: ABS <factor>
Returns the absolute value of the numeric value
<factor>
ACS
Use: ACS <factor>
Returns the arccosine of the numeric value <factor>
ADVAL
Use: ADVAL <factor>
This is an unsupported function. Either use of it is
flagged as an error or it returns zero, depending on the
options used to start the interpreter.
ARGC *
Use: ARGC
Returns the number of parameters on the command line.
This will be zero if there are no parameters.
ARGV$ *
Use: ARGV$ <factor>
Returns parameter number <factor> on the command line
as a string. ARGV$ 0 returns the name of the program.
ARGV$ 1 is the first parameter, ARGV$ 2 the second and
so forth. ARGV$ ARGC is the last parameter.
ASN
Use: ASN <factor>
Returns the arcsine of the numeric value <factor>
ATN
Use: ATN <factor>
Returns the arctan of the numeric value <factor>
BEAT
Use: BEAT
Returns information from the RISC OS sound system.
This function returns zero.
BGET
Use: BGET# <factor>
Returns the next byte from the file with handle <factor>
CHR$
Use: CHR$ <factor>
Returns a string consisting of a single character with
ASCII code <factor>
COLOUR
Use: COLOUR(<red expression>, <green expression>,
<blue expression>)
This takes the colour with the specified colour
components and returns a number that represents the
closest match to that colour in the current screen
mode. This value is for use with the 'COLOUR OF' and
'GCOL OF' statements. It has no meaning otherwise.
Example:
red = COLOUR(255, 0, 0): COLOUR OF red
COS
Use: COS <factor>
Returns the cosine of the numeric value <factor>
COUNT
Use: COUNT
Returns the number of characters printed on the current
line by PRINT.
DEG
Use: DEG <factor>
Converts the angle <factor> from radians to degrees.
DIM
Use: a) DIM(<array>)
b) DIM(<array>, <expression>)
a) returns the number of dimensions in array <array>.
b) returns the highest index of dimemsion <expression> of
array <array>.
END
Use: END
Returns the address of the top of the Basic heap.
EOF
Use: EOF# <factor>
Returns TRUE if the file with handle <factor> is at end of
file.
ERL
Use: ERL
Returns the number of the line that contained the last error
encountered by the interpreter or zero if no error has been
seen.
ERR
Use: ERR
Returns the error number of the last error encountered by
the interpreter or zero.
EVAL
Use: EVAL <factor>
Evaluates the string <factor> as if it were an expression in
a statement in the program and returns the result.
EXP
Use: EXP <factor>
Returns the exponentional of the numeric value <factor>.
FALSE
Use: FALSE
The function returns the value corresponding to 'false' in
the interpreter (zero).
GET
Use: GET
Returns the next character pressed on the keyboard as a
number, waiting if there is not one available.
GET$
Use: a) GET$
b) GET$# <factor>
a) Returns the next character pressed on the keyboard as a
one character string, waiting if there is not one
available.
b) Returns the next line from the open file with handle
<factor> as a character string.
INKEY
Use: INKEY <factor>
If numeric value <factor> is greater than or equal to zero,
return the next character pressed on the keyboard as a number
but only wait for <factor> centiseconds. Return -1 if no key
pressed in that time.
If numeric value <factor> is -256, return a number that
identifies the operating system under which the program is
running. (See the 'use' guide for the values returned.)
If numeric factor <factor> is less than zero and greater
than -256, return TRUE if the key with RISC OS internal
key number <factor> is being pressed otherwise return FALSE.
INKEY$
Use: INKEY$ <factor>
This is the same as INKEY but returns its result as a single
character string. In the case of a keyboard read with
timeout, an empty string is returned if the time limit
expires instead of -1.
INSTR(
Use: INSTR(<expr1> , <expr2> [, <expr3>])
Search string <expr1> for the string <expr2> returning the
index (starting from 1) of the start of <expr2> in <expr1>
if the string is found otherwise return zero. <expr3> is
an option expression that gives a starting point in <expr1>
at which to start looking for <expr2>.
INT
Use: INT <factor>
Returns the integer part of number <factor>, rounding down
(towards minus infinity).
LEN
Use: LEN <factor>
Returns the length of string <factor>.
LISTO *
Use: LISTO
Returns the current LISTO setting.
LN
Use: LN <factor>
Return the natural log of number <factor>.
LOG
Use: LOG <factor>
Returns the base 10 log of number <factor>.
MOD Use: MOD <array>
Returns the modulus (square root of the sum of the
squares) of numeric array <array>.
MODE Use: MODE
Returns the number of the current RISC OS screen mode.
NOT
Use: NOT <factor>
Returns the logical negation (ones complement) of numeric
value <factor>.
OPENIN
Use: OPENIN <factor>
Opens the file named by the string <factor> for input and
returns its numeric handle or zero if it cannot be opened.
OPENOUT
Use: OPENOUT <factor>
Opens the file named by the string <factor> for output and
returns its numeric handle. If the file exists already its
length is reset to zero.
OPENUP
Use: OPENUP <factor>
Opens the file named by the string <factor> for both input
and output and returns its numeric handle.
PI
Use: PI
Returns the value PI.
POINT(
Use: POINT(<x expr>,<y expr>)
Returns the colour number of the point on the graphics
screen with graphics coordinates (<x expr>, <y expr>).
POS
Use: POS
Returns the offset (from 0) of the text cursor from
the left-hand side of the screen.
QUIT
Use: QUIT
Returns TRUE if the interpreter was started with the
option '-quit', that is, the interpreter will be exited
from when the Basic program finishes running.
RAD
Use: RAD <factor>
Convert the angle <factor> given in degrees to radians.
REPORT$
Use: REPORT$
Returns the message for the last error encountered.
RND
Use: a) RND
b) RND(<negative expr>)
c) RND(0)
d) RND(1)
e) RND(<expression>)
a) Return a pseudo-random number in the range -2147483648
to 2147483647
b) Initialises the random number generator with seed value
<negative expr>.
c) Returns the last number generated by RND(1).
d) Returns a floating point number in the range 0 to 1.
e) Returns an integer number in the range 1 to <expression>.
SGN
Use: SGN <factor>
Returns -1 if the numeric value <factor> is less than
zero, zero if it is zero or 1 if it is greater than zero.
SIN
Use: SIN <factor>
Returns the sine of numeric value <factor>.
SQR
Use: SQR <factor>
Returns the square root of numeric value <factor>.
STR
Use: a) STR <factor>
b) STR~ <factor>
a) Converts the numeric value <factor> to a decimal
string.
b) Converts the numeric value <factor> to a hexadecimal
string.
STRING$(
Use: STRING$( <expression>, <string expr> )
Returns a string made from the string <string expr> repeated
<expression> times.
SUM
Use: SUM <array>
If <array> is a numeric array it returns the sum of all of
the elements of the array. If <array> is a string array it
returns a string made from all of the elements of <array>
concatenated.
SUM LEN
Use: SUM LEN <array>
Returns the total length of all of the strings in string
array <array>.
TAN
Use: TAN <factor>
Returns the tangent of numeric value <factor>
TEMPO
Use: TEMPO
Unsupported RISC OS feature. The function returns zero or
generates an error depending on intepreter command line
options.
TINT
Use: TINT(<x expr>,<y expr>)
Returns the TINT value of the position with x and y
graphics coordinates <x expr> and <y expr> on the screen
in 256 colour modes.
TOP
Use: TOP
Returns the address of the first byte after the Basic
program.
TRACE
Use: TRACE
Returns the handle of the file to which TRACE output is
being written or zero if a file is not being used.
TRUE
Use: TRUE
Returns the value used by the interpreter for 'true' (-1).
USR
Use: USR <factor>
Calls machine code at address <factor>. Not implemented
this interpreter except in one special case. See the
'use' guide.
VAL
Use: VAL <factor>
Converts the string <factor> to a number.
VERIFY( *
Use: VERIFY(<expr 1>, <expr 2> [, <expr 3>] )
Returns the offset of the first character in string
expression <expr 1> that is not in string <expr 2>
or zero if all characters in <expr 1> are in <expr 2>.
<expr 3> is the optional position at which to start
the search.
VDU
Use: VDU <factor>
Returns the value of the RISC OS mode variable given by
<factor>. This can be used to determine such things as
the screen width, the number of colours and so forth.
Refer to the section 'Mode Variables' below for more
details.
VPOS
Use: VPOS
Returns the offset (from zero) from the top of the screen of
the text cursor.
WIDTH
Use: WIDTH
The function returns the current value of 'WIDTH' (the
width of the current line as set by the program) or zero
if a line width has not been defined via the WIDTH
statement.
XLATE$( *
Use: a) XLATE$(<expr 1>)
b) XLATE$(<expr 1>, <expr 2>)
a) Returns the string expression <expr 1> with all
upper case characters converted to lower case.
b) Returns the string expression <expr 1> with the
characters translated using string expression or
string array <expr 2>. Characters in <expr 1> are
replaced with the character in the position
corresponding to the ASCII code of the original
character.
Pseudo Variables
~~~~~~~~~~~~~~~~
Pseudo variables are a half way house between a function and a
variable. When they appear in the right hand side of an expression
they are functions but they can also appear on the left hand side of
an expression too.
Pseudo variables cannot follow the keyword 'LET', that is, using
them in statements such as:
LET FILEPATH$="."
is not permitted. Similarly, they can only be followed by '=',
that is, assignments of the form '<something>+=<value>' are not
allowed.
EXT
As a function:
Use: EXT# <factor>
Returns the size of the open file with the handle
<factor>.
Example:
oldsize% = EXT#file%
On left-hand side:
Use: EXT# <factor> = <expression>
Change the size of the open file with handle <factor>
to <expression> bytes.
Example:
IF action$="delete" THEN EXT#file% = 0
FILEPATH$
As a function:
Use: FILEPATH$
Returns the list of directories to search when trying to
find a library or a program.
Example:
PRINT"Current search path: ";FILEPATH$
On left-hand side:
Use: FILEPATH$ = <expression>
Sets the directory list to the string expression
<expression>. Note that there are no checks to make sure
that the directory names are valid. Setting FILEPATH$
to an empty string is allowed.
Example:
FILEPATH$ = "/home/mine,/usr/local/basic"
HIMEM
As a function:
Use: HIMEM
Returns the address of the end of the Basic workspace.
Example:
PRINT "Top of workspace is at ";~HIMEM
On left-hand side:
Use: HIMEM = <expression>
This sets the address of the top of the Basic workspace
to the value of the numeric expression <expression>. If
the new value of HIMEM puts it in the Basic program or
outside the Basic workspace, the statement is ignored.
Example:
HIMEM = HIMEM-1000
The places where HIMEM can be changed are limited. It
cannot be altered in a procedure, function or subroutine,
nor in the body of a loop. The only safe place to change
it is at the start of a program.
LEFT$
As a function:
Use: LEFT$(<string expression> [, <expression>)
Returns the left-hand <expression> characters from the
string <string expression>. <expression> can be omitted,
in which case <string expression> with the last character
removed is returned.
Examples:
LEFT$(abc$, 4)
LEFT$($table%, 10)
LEFT$(xyz$(X%))
On left-hand side:
Use: LEFT$(<string variable> [, <expression>])
= <string expression>
This replaces the left-hand characters of string <string
variable> with the string expression <string expression>.
<expression> says how many characters to replace. If it is
omitted then the length of <string expression> is used. If
this value exceeds the original length of <string variable>
then the length of <string variable> is used instead.
<string variable> can be a normal string variable, an array
reference or a string referenced by the string indirection
operator.
Examples:
LEFT$(abc$)="1234"
LEFT$(abc$, 2)="abcdefgh"
LEFT$(xyz$(X%), 5)="123"
LEFT$($table%, 3)="pqrst"
LOMEM
As a function:
Use: LOMEM
Returns the address of the start of the Basic heap
Example:
PRINT"Variables start at ";~LOMEM
On left-hand side:
Use: LOMEM = <expression>
This changes the address of the start of the Basic heap to
the numeric value <expression>. All of the variables created
so far are discarded when LOMEM is changed. If the value
is outside the range TOP to HIMEM it is ignored. The
assignment is also ignored if LOMEM is changed in a function
or procedure.
Examples:
LOMEM = LOMEM+1000
MID$
As a function:
Use: MID$(<string expression>, <start expression>
[, <length expression>] )
Returns a substring from the string <string expression>
starting at character position <start expression>. The
substring is of length <length expression> characters.
<length expression> can be omitted, in which case the
the string from the <start expression>'th character to
the end of the string is returned.
If <start expression> is negative or exceeds the length
of the string the empty string is returned. If <length
expression> is negative or exceeds the number of
characters in the string, the original string is
returned.
Examples:
A$ = MID$(B$, 10)
A$ = MID$(B$, 10, 20)
A$ = MID$($table%, 5, 10)
On left-hand side:
Use: MID$(<string variable>, <start expression>
[, <length expression>] ) = <string expression>
The characters of the string <string variable>
starting at character position <start expression> are
overwritten by characters from string <string expression>.
<length expression> is optional and says how many
characters are to be taken from <string expression>. If
it is omitted then all of <string expression> is used.
Only the existing characters of <string variable> are
overwritten. The length of the string is never changed.
If <start expression> is negative then <string variable>
is overwritten from the start of the string. If it exceeds
the length of <string variable> then nothing is changed.
If <length expression> is negative then the length of
<string expression> is used instead.
Examples:
MID$(A$, 5) = "ABCD"
MID$(A$, 10, 10) = X$ + "abcdefghijklmnop"
MID$($table%, 10) = "12345"
PAGE
As a function:
Use: PAGE
Returns the address of the start of the Basic program.
Example:
PRINT"The program starts at ";~PAGE
On left-hand side:
Use: PAGE = <expression>
This sets the address of the start of the Basic program
in memory to <expression>. Any program currently loaded
is discarded. The change is ignored if the value of
<expression> is outside the range of the value of PAGE
when the interpreter was started to HIMEM.
Note: one trick possible with the Acorn interpreter is
to hold several programs in memory at the same time and
to switch between them by altering PAGE. This does not
work with the current version of this interpreter.
Example:
PAGE = PAGE + 1000
PTR
As a function:
Use: PTR# <factor>
Returns the value of the offset in bytes of the file
pointer in the open file with handle <factor>.
Example:
place = PTR# thefile%
On left-hand side:
Use: PTR# <factor> = <expression>
Sets the file pointer of the open file with handle <factor>
to <expression>. This is offset into the file in bytes.
Example:
PTR# thefile% = 0
RIGHT$
As a function:
Use: RIGHT$(<string variable> [, <expression>] )
Returns a string containing the right-most <expression>
characters from the string <string variable>. It is
possible to omit <expression>, when just the last
character is returned. If <expression> is zero or
negative, the empty string is returned. If it exceeds
the length of <string variable>, the original string is
returned.
Examples:
RIGHT$(A$, 5)
RIGHT$(X%) + RIGHT$(Y$)
Om left-hand side:
Use: RIGHT$(<string variable> [, <expression>]) =
<string expression>
The right-most <expression> characters of the string
<string variable> are overwritten with character from
<string expression>. If <expression> is omitted, the
length of the string <string expression> is used instead.
If it is zero or negative, <string variable> is left
unchanged. The length of the string <string variable>
is never changed.
Examples:
RIGHT$(A$) = "1234"
RIGHT$(A$, 5) = "abcdefgh"
RIGHT$($table%, 1) = A$
TIME
As a function:
Use: TIME
Returns the current value of the centisecond counter.
This is a 32-bit timer updated one hundred times per
second, although the real accuracy depends on the
underlying operating system.
Example:
newtime = TIME+100
On left-hand side:
Use: TIME = <expression>
Sets the centisecond counter to <expression>.
Example:
TIME = 0
TIME$
As a function:
Use: TIME$
Returns the current date and time as a string in the
form: "www,dd mmm yyyy.hh:mm:ss"
Example:
now$ = TIME$
On left-hand side:
Use: TIME$ = <expression>
Sets the date and time to the string expression
<expression>. This feature is not implemented.
Procedures and Functions
~~~~~~~~~~~~~~~~~~~~~~~~
Basic V has both procedures and multi-line functions. They can
both take parameters of any sort, including arrays, and it is
possible to return values via parameters. They can also have local
variables.
Procedures and functions are declared in the same way:
Procedures: DEF PROC<name> [ ( <parameter list> ) ]
Functions: DEF FN<name> [ ( <parameter list> ) ]
<name> is the name of the procedure or function. The keywords
'PROC' and 'FN' are considered to be part of the name.
<parameter list> is the list of variables to be used as formal
parameters. There can be any number of these. Names are separated
by commas. Parameters where values are to be returned are preceded
by the keyword RETURN.
Examples:
DEF PROCabc
DEF PROCxyz(aa$)
DEF FNpqr(X%, abc%, def$)
DEF PROCijk(RETURN X%, RETURN Y%)
DEF FNmno(array())
DEF PROCpqr(array1$(), RETURN array2$())
When a procedure or function is called, the current values of the
variables that are to be used as parameters are saved before they
are set to the values they will take for the call. When the call
ends their old values are restored.
All of the parameters are evaluated before the values are assigned
to the parameter variables.
Procedures and functions are called in the normal way, for
example:
PROCxyz("abcd")
value = FNpqr(A%+1, B%+2, C$+"3")
Calls to procedures are ended with ENDPROC. Calls to functions end
with an '=' followed by the value the function is to return, for
example:
DEF PROCabc(X%)
IF X%=0 THEN ENDPROC
Y% = Y% DIV X%
ENDPROC
DEF FNxyz(X%)
IF X%=0 THEN = 0
= Y% DIV X%
Note that the name of a function does not include the type of the
result it will return. It is possible for the same function to
return both string and numeric values, but this is of very limited
use. (The only place it will not give an error is in a PRINT
statement.)
Recursive calls to procedures and functions are allowed. The only
limit on the depth of the recursion is the amount of memory
available.
Procedures and functions can have local variables. These are
defined by means of the LOCAL statement. The format of this is:
LOCAL <list of variables>
for example:
LOCAL abc%, def, ghi$, jkl$
Any number of local variables can be declared. It is also possible
to have local arrays. These are slightly more complicated in that
the array is declared to be local and its dimensions defined
separately, thus:
LOCAL array()
DIM array(100)
The scope of local variables is dynamic, that is, they are not
restricted to the procedure or function in which they were
defined. It is perhaps easier to understand this by considering
what happens: when a variable is declared to be local, its value
(if the variable exists already) is saved and the value reset to
zero (or the empty string). When the procedure or function is
returned from, the old value is restored. Declaring a variable to
be local does not create a new version of that variable. The same
variable is still used but its old value is saved first.
Error Handling
~~~~~~~~~~~~~~
Basic V provides two statements for dealing with errors, ON ERROR
and ON ERROR LOCAL. ON ERROR is the less sophisticated of the two.
If an error is detected, the interpreter ends all loops and
returns from all procedures, functions and subroutines before
continuing with the statements after ON ERROR. It is not possible
to recover from the error and restart the program at the point
where it occured. Most of the time all that can be done is to tidy
up and abort the program. ON ERROR LOCAL gives more control in
that when an error occurs, the statements after the ON ERROR LOCAL
are executed but everything is left as it was at the time of the
error. This means it is possible to trap errors and recover from
them.
The statement 'ON ERROR OFF' turns off the trapping of errors
in the program. This should be used at the start of an error
handler to prevent errors in the error handler causing an
infinite loop.
To allow for finer control over errors, Basic V also has two
statements that allow different error handlers to be used at
different points in the program, LOCAL ERROR and RESTORE error.
LOCAL ERROR stores details of any existing error handler and
allows a new one to be set up. RESTORE ERROR restores the error
handler to the saved one. If LOCAL ERROR is used in a function or
procedure, the old error handler is restored when the function or
procedured calls ends.
Care should be taken if using ON ERROR LOCAL within the body of a
loop. If an error is detected once the program has exited from the
loop, it will branch back into it when the interpreter goes to the
statements after ON ERROR LOCAL. The interpreter is unaware of the
context of the error handler (that is, it has back into the body
of a loop) and unpredictable results might ensue.
The function REPORT$ returns the last error message. ERR returns
the number of that error and ERL the number of the line in which
it occured. Note that this does not say whether the error occured
in the program or a library. The REPORT statement displays the
last error message. The ERROR statement can be used to report
user-generated errors. The interpreter allows the use of the LIST
command in programs, so it is possible for error handlers to list
the line in which the error occured by the statement
LIST ERL
Note that the line listed will always be in the Basic program so
if the error occured in a library the wrong line will be shown.
Some of the errors that the interpreter flags are classed as
'fatal', for example, running out of memory. The Basic program is
always abandoned if a fatal error occurs. It is not possible to
trap them with ON ERROR or ON ERROR LOCAL.
Issuing Commands to the Underlying Operating System
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are two ways in which commands can be send to the operating
system on which the interpreter is running. The most flexible way
is the OSCLI statement. The second way is to put the command on
a line preceded by a '*', for example:
10 *date
20 IF flag THEN *help
Whatever follows the '*' up to the end of the line is passed as
the command.
There is no restriction on the commands that can be issued this
way.
Statement Types
~~~~~~~~~~~~~~~
Statements are broken into two types, executable statements that
can appear in a program and commands that, in general, can only
be used on the command line.
Many of the keywords and commands can be abbreviated when they
are typed in. They will be shown in their complete form when the
program is listed. The rule is to type in the minimum number
of characters of the keyword and then follow it with a dot,
for example:
P.
can be type instead of 'PRINT'. The minimum abbreviation for each
keyword and command is given in the section 'Basic Keywords,
Commands and Functions' at the end of these notes.
All of the Basic V statement types are described below. However,
not all versions of the Basic V interpreter support all of them,
in particular, the graphics statements might not be available.
Statements
~~~~~~~~~~
In the following:
<factor> represents a simple expression that consists of just a
variable name, array reference or constant or a complete
expression in parentheses.
<expression> is a full expression. Sometimes this is written as
<string expression> or <numeric expression> to qualify the type
of expression, or abbreviated to <expr> to reduce clutter.
<array> is a reference to a whole array.
<statements> is one or more Basic statements.
Items in square brackets are optional.
BEATS
Unsupported statement for controlling the RISC OS sound system.
BPUT
Syntax: a) BPUT#<factor>, <expression> [;]
b) BPUT#<factor>, <expr 1>, <expr 2>, ... ,<expr n> [;]
BPUT is used to write data to a file. The handle of the file is
given by <factor>. <expression> is the value to be written. If
<expression> is numeric, the result of the expression modulo 256
(that is, the least significant byte) is written to the file. If
<expression> is a string, the complete string is written to the
file. If the string expression is followed by a ';' that is all
that happens. If the ';' is absent, a 'newline' character (ASCII
code 10) is also written to the file after the string.
The second form of the BPUT statement is the same as the first
except that a list of items to be written separated by commas
can be supplied. If the last item is a string expression then
a new line character is also written to the file unless the
expression is followed by a ';'.
Examples:
BPUT#outfile, X%
BPUT#outfile, A$
IF TRACE THEN BPUT#TRACE, "Result so far is "+STR$X%
BPUT#outfile, 1, 2, 3, 4, 5
BPUT#outfile, STR$A%, " ", STR$B%
CALL
This is an unsupported statement that allows machine code
subroutines to be called.
CASE
Syntax: CASE <expression> OF
This marks the start of a CASE statement. This statement must be
the last one on a line.
The complete syntax of a CASE statement is:
CASE <expression> OF
WHEN <expression 1>: <statements>
WHEN <expression 2>: <statements>
OTHERWISE: <statements>
ENDCASE
The expression <expression> is evaluated. The interpreter then
searches for 'WHEN' statements and evaluates each expression after
the 'WHEN' in turn and compares it to the result of <expression>.
If they are equal it starts executing the statements <statements>
after the 'WHEN' from that point to the next 'WHEN', 'OTHERWISE'
or 'ENDCASE'. At this point it jumps to the statements after the
ENDCASE.
Any number of expressions (limited by the length of the line) can
follow the WHEN keyword. They are separated by commas.
The expressions after the WHEN keyword do not have to be
constants. Any type of expression is allowed and they can be of
numeric or string types.
The WHEN keyword must be the first item on a line after the line
number (except for any intervening blanks). The same goes for the
OTHERWISE and ENDCASE keywords.
CASE statements can be nested to any depth.
Examples:
CASE day$ OF
WHEN "Monday": PRINT"It is Monday"
WHEN "Tuesday", "Thursday":
PRINT"It is Tuesday or Thursday"
WHEN "Friday":
PRINT"It is Friday"
WHEN "Wednesday": PRINT"It it the middle of the week"
OTHERWISE
PRINT"It is the weekend"
ENDCASE
As general expressions can be used after the WHEN, CASE statements
are very flexible. Here one is being used in place of a series of
IF statements:
CASE TRUE OF
WHEN abc%<10: state%=1
WHEN abc%=10: state%=2
WHEN abc%>20 AND abc%<20: state%=3
OTHERWISE: state%=99
ENDCASE
CHAIN
Syntax: CHAIN <string expression>
CHAIN loads and runs the program named by the string <string
expression>. The programs currently in memory is replaced by this
one and the values of all variables lost, with the exception of
the static integer variables.
Extension: The interpreter searches for the program to load in the
directories given by the pseudo-variable FILEPATH$.
CIRCLE
Syntax: a) CIRCLE <x expression>,<y expression>,<expression>
b) CIRCLE FILL <x expression>,<y expression>,<expression>
a) This draws a circle outline centred at (<x expression>,
<y expression>) and with a radius <expression> in the current
graphics foreground colour.
b) This version plots a filled circle centred at (<x expression>,
<y expression>) and with a radius <expression> using the current
graphics foreground colour.
CLG
Syntax: CLG
This statement clears the graphics window (normally the whole
screen) to the current graphics background colour.
CLEAR
Syntax: CLEAR
CLEAR discards all of the variables and arrays created so
far in the program. It also clears the chain of called
procedures and functions so it should not be used in a
procedure or function.
Example:
IF silly% THEN CLEAR
CLOSE
Syntax: CLOSE# <factor>
The CLOSE statement closes one or more open files. <factor> is a
numeric value that gives the handle of the file to close. If
<factor> is zero then *all* files that have been opened by the
Basic program are closed.
Example:
CLOSE#outfile%
CLS
Syntax: CLS
CLS clears the screen (or the current text window if one
is being used). It also sends the cursor to the top left-hand
corner of the screen.
Example:
IF full% THEN CLS
COLOUR
Syntax: a) COLOUR <expression>
b) COLOUR <colour expression> TINT <tint expression>
c) COLOUR <red expression> , <green expression> ,
<blue expression>
d) COLOUR <logical expression> , <physical expression>
e) COLOUR <colour expression> , <red expression> ,
<green expression> , <blue expression>
f) COLOUR OF <expression> ON <expression>
g) COLOUR OF <red expression>, <green expression>,
<blue expression> ON <red expression>,
<green expression>, <blue expression>
The COLOUR statement is used to change the colour being used when
writing text on the screen. It is also used to change the physical
colour corresponding to the given logical colour.
a) This sets the colour to be used when writing text on the
screen. <expression> is a numeric value. It is reduced
modulo the number of colours available in the current screen
mode. The colour changed is the logical colour.
If the original value of <expression> is less than 128, the colour
changed is the text foreground colour; otherwise the background
colour is altered. 128 is subtracted from the vale of <expression>
to get the colour number.
b) This version of the statement is used in 256 colour modes to
set the colour used for writing text on the screen. <colour
expression> sets the logical colour and <tint expression> sets the
'tint' value. If the value of <colour expression> is less than 128
then the foreground colour is changed otherwise the background one
is altered. Whether or not <colour expression> is less than 128
affects whether the foreground tint value or background tint value
is the one changed by <tint expression>.
The colour value is reduced modulo 64 to obtain the colour. The
tint value has set values: 0, 64, 128 and 192. The increasing tint
value has an effect on the brightness of the colour. See the
section '256 Colour Modes' below for an explanation of how the
colour and tint work together.
c) This sets the current text foreground colour to the colour with
components <red expression>, <green expression>, <blue expression>.
The values of the colour components are reduced modulo 256. The
colour is mapped to the nearest equivalent colour in the current
screen mode.
d) This version of the COLOUR statement changes the mapping
between the logical colour number and the colour displayed on the
screen in screen modes which have less than 256 colours. <logical
expression> is the logical colour number whose mapping is to be
changed. The value is reduced modulo the number of colours in the
current screen mode. <physical colour> is the colour number of the
physical colour to be used. The colour numbers are given in the
section '2, 4 and 16 Colour Modes' below.
e) This version of the statement is related to c) above in that it
alters the colour displayed for a given logical colour number in
screen modes with more than sixteen colours available. <colour
expression> is the number of the colour to change and <red
expression>, <green expression> and <blue expression> are the red,
green and blue components of the new colour. These are reduced
modulo 256. The colour number is also reduced modulo 256.
f) This version of the statement has two parts, the 'OF' part
and the 'ON' part. The 'OF' part gives the foreground colour
and the 'ON' part the background colour. Either of these parts
can be omitted but not both of them. The value <expression>
is the colour number to use.
g) This version has two parts, the 'OF' part and the 'ON'
part where the 'OF' part is used to give the foreground
colour and the 'ON' part the background colour. The three
expressions after each keyword, <red expression>, <green
expression> and <blue expression>, give the red, green
and blue components of the colour to use. The colour that
will actually be used is the closest match to this colour
in the current screen mode. Either the 'OF' or the 'ON'
part can be left out but not both.
Examples:
COLOUR 5
COLOUR 23 TINT &C0
COLOUR 2, 128, 128, 128
COLOUR OF 0, 0, 255 ON 0, 0, 0
COLOUR ON 191, 191, 191
COLOUR ON COLOUR(191, 191, 191)
The 'COLOUR OF' statement (along with 'GCOL OF') represent
a new way of selecting colours to use on screen. Along with
the 'COLOUR()' function they provide a means of specifying
colours independently of the screen mode, for example:
pink = COLOUR(255, 127, 255)
blue = COLOUR(0, 0, 255)
COLOUR OF pink ON blue
This avoids use of the 'TINT' keyword.
DATA
Syntax: DATA <items of data>
The DATA statement provides the data to be read by a READ
statement. It must be the first keyword on a line after the
line number.
<items of data> is one or more items of data separated by
commas.
DEF
'DEF' marks the start of a procedure or function definition. It
must be the first non-blank item on a line after the line number.
Refer to the section 'Procedures and Functions' above for more
information.
Examples:
DEF PROCfirst
DEF FNsecond(X%)
DIM
Syntax: DIM <list of arrays>
The DIM statement is used to declare arrays. <list of arrays>
contains one or more arrays to be declared separated by
commas. There are two types of array declation. The
format of a normal array declaration is:
<name>( <expression 1> , ... , <expression n> )
where <name> is the name of the array and <expression 1> to
<expression n> are the array's dimensions. Arrays can have up to
ten dimensions and their size is limited only by the available
memory.
Array indexes start at zero with the size given in the array
declaration as the highest index of each dimension.
Note that the '(' is considered part of the array name.
Examples:
DIM abc%(100), def(10,10), ghi$(size%+10)
The second form is used to allocated blocks of memory. There
are two versions of this:
<variable> <expression>
<variable> LOCAL <expression>
where <variable> is the name of a variable and <expression> is the
size of the block to allocate in bytes. The address of the block
is stored in <variable>.
The first form can be used anywhere but the second can only be
used in a procedure or function. In the second case the block
is allocated on the Basic stack and is automatically returned
when the procedure or function containing the DIM statement ends.
In the first case memory is obtained from the Basic heap and
it cannot be returned to the heap for reuse later.
To be more accurate, the second form allocates a byte array with a
low index of zero and a high index of <expression>. For this
reason the size of the block allocated is actually <expression>+1
bytes.
Examples:
DIM heap% 100000, block% 100
DIM abc%(10), block% 1000
DIM xyz% LOCAL 1000
LOCAL ptr%: DIM ptr% LOCAL 100
One trick is to declare an array in this way with a size of -1
bytes. This stores the address of the current top of the Basic
heap in the variable, for example:
DIM heaptop% -1
The same effect can be obtained using the function 'END'.
Local Arrays
------------
The interpreter allows local arrays to be created in procedures
and functions. The memory for these is reclaimed when the procedure
or function call ends.
The way in which local arrays are defined is as follows:
LOCAL <array>
DIM <array>
In other words, the array is declared local first and then its
dimensions are defined, for example:
LOCAL abc$()
DIM abc$(10,10)
DRAW and DRAW BY
Syntax: a) DRAW <x expression> , <y expression>
b) DRAW BY <x expression> , <y expression>
The DRAW statement draws a line in the current graphics foreground
colour from the current graphics cursor position to the one given
by <x expression>, <y expression>.
a) <x expression> and <y expression> are absolute coordinates.
b) <x expression> and <y expression> are the offsets from the
current graphics cursor position of the end point of the line.
Examples:
DRAW 500,100: DRAW 500,500: DRAW 100,100
DRAW BY 400,0: DRAW BY 0,400: DRAW BY -400,-400
ELLIPSE
Syntax: a) ELLIPSE <x expression> , <y expression> ,
<semi-major> , <semi-minor> , <angle>
b) ELLIPSE FILL <x expression> , <y expression> ,
<semi-major> , <semi-minor> , <angle>
The ELLIPSE statement draws an ellipse. The coordinates of the
centre are (<x expression>, <y expression>). <semi-major> and
<semi-minor> are the lengths of the semi-major and semi-minor axes
respectively. <angle> is the angle between the semi-major axis and
the x axis in radians.
Note that values other than zero for the angle only work in the
RISC OS version of the program in the current version of the
interpreter.
a) This draws an ellipse outline.
b) This draws a filled ellipse.
Example:
ELLIPSE 500, 500, 400, 200, 0.5
ELSE
Syntax: ELSE
The ELSE statement is part of an IF statement. Refer to the
section on the IF statement for more information.
END
Syntax: END
As a statement, END stops the program.
Example:
IF alldone THEN END
ENDCASE
Syntax: ENDCASE
Part of a 'CASE' statement. It marks the end of the statement.
Refer to the section on the 'CASE' statement above for more
details.
ENDIF
Syntax: ENDIF
Part of a block 'IF' statement. It marks the end of the statement.
Refer to the section on the 'IF' statement below for more
information.
ENDPROC
Syntax: ENDPROC
The ENDPROC statement is used to return from a procedure to the
calling routine. Variables corresponding to RETURN parameters are
set to the their returned values, all local variables declared in
the procedure are restored to their original values and local
arrays destroyed. The effects of any LOCAL DATA or LOCAL ERROR
statements are undone. Control then passes back to the statement
after the procedure call.
Example:
IF count%=0 THEN ENDPROC
ENDWHILE
Syntax: ENDWHILE
ENDWHILE marks the end of a WHILE loop. Refer to the section
below on the WHILE statement for more information.
Example:
ENDWHILE
ENVELOPE
Syntax: ENVELOPE <expression 1> , ... , <expression 14>
This is an unsupported statement. It was used as part of the sound
system on the BBC Micro but it is completely redundant in Basic V.
ERROR
Syntax: ERROR <error expression> , <string expression>
The ERROR statement is used to generate a user-defined error.
<error expression> is the number of the error and <string
expression> is the error message. Errors raised this way can be
trapped just like any other using ON ERROR and ON ERROR LOCAL.
Example:
ERROR 25, "Bad error"
FALSE
Syntax: FALSE
FALSE returns the value corresponding to 'false' in the
interpreter, zero.
Example:
flag = FALSE
FILL and FILL BY
Syntax: a) FILL <x expression>, <y expression>
b) FILL BY <x expression> , <y expression>
The FILL statement is used to flood-fill areas with the current
graphics foreground colour.
a) <x expression> and <y expression> give the coordinates of the
point at which to start the flood fill.
b) <x expression> and <y expression> give the offsets from the
current graphics cursor position at which to start the flood
fill.
Example:
FILL 500,100
FOR
Syntax: FOR <variable> = <start expression> TO <end expression>
[ STEP <step expression> ]
The FOR statement marks the start of a FOR loop. <start
expression> and <end expression> are numeric values that give the
start and end values for the loop index, <variable>. <step
expression> is optional and gives the amount by which the loop
index is incremented or decremented on each iteration. If omitted,
it defaults to one.
Execution continues from the statement after the FOR statement to
the first NEXT statement encountered. At this point the loop index
is incremented (or decremented if the step value is negative) and
compared against the end expression. If it exceeds that value (or
is less than it if the step is negative) the loop is terminated,
otherwise program execution continues back at the statement after
the FOR.
The body of the loop will be executed at least once.
<end expression> and <step expression> are evaluated only once, at
the start of the loop.
As with all the loop constructs, exiting the loop will
automatically undo the effect of any LOCAL DATA or LOCAL ERROR
statements that were used in the loop. Loops badly nested within
the FOR loop body will also be silently ignored.
Examples:
FOR N% = 1 TO 10: NEXT
FOR N% = 10 TO 1 STEP -1: NEXT
FOR abc = FNstart TO FNfinish STEP 10: NEXT
FOR array%(5) = 1 TO 10: NEXT array%(5)
The last example shows that the loop index does not have to be
a simple variable.
GCOL
Syntax: a) GCOL <colour expression>
b) GCOL <colour expression> TINT <tint expression>
c) GCOL <action expression> , <colour expression>
d) GCOL <action expression> , <colour expression>
TINT <tint expression>
e) GCOL <red expression> , <green expression> ,
<blue expression>
f) GCOL OF <expression> ON <expression>
g) GCOL OF <action expression>, <expression>
ON <action expression>, <expression>
h) GCOL OF <red expression>, <green expression>,
<blue expression> ON <red expression>,
<green expression>, <blue expression>
i) GCOL OF <action expression>, <red expression>,
<green expression>, <blue expression>
ON <action expression>, <red expression>,
<green expression>, <blue expression>
GCOL is used to set the graphics foreground or background colour.
The various combinations are as follows:
a) Set the graphics colour to logical colour number <colour
expression>. This value is reduced modulo the number of colours
available in the current screen mode in 2, 4 and 16 colour modes
and modulo 64 in 256 colour modes. If the value is less than 128
then the foreground colour is altered. If it is 128 or more, 128
is subtracted from the colour number and the background colour
changed.
b) Set the graphics colour to logical colour number <colour
expression> and the 'tint' value to <tint expression>. This
version is used in 256 colour modes. The colour number is reduced
modulo 64. The tint value should be set to 0, 64, 128 or 192.
c) This form changes the graphics colour to logical colour number
<colour expression> and sets the graphics plot action to <action
expression>. The RISC OS version of the interpreter supports the
full range of plot actions but others are restricted to just plot
action zero, where each point plotted overwrites the one already
there.
d) This is a combination of cases b) and c) and is used in 256
colour modes. The graphics colour is set to colour number <colour
expression> with tint value <tint expression>. The graphics plot
action is set to <action expression>.
e) The current graphics foreground colour is set to the colour
with colour components <red expression>, <green expression> and
<blue expression>. The colour used will be the closest match to
the specified colour in the current screen mode.
f) and g) are very similar. There are two parts to the statement,
the 'OF' part and the 'ON' part. The 'OF' part gives the colour
to use for the graphics foreground colour and the 'ON' part
the background colour. In case f), only the colour is given but
in g) both the colour and the graphics plotting action are
supplied. It is possible to leave out either of the 'OF' or
the 'ON' parts but not both.
h) and i) are similar. There are two parts to the statement,
the 'OF' part and the 'ON' part. The 'OF' part gives the
components of the colour to use for the graphics foreground
colour and the 'ON' part the components of the background
colour. The actual colour used will be the closest match to
the specified colour in the current screen mode. In case h),
only the colour is given but in i) both the colour and the
graphics plotting action are supplied. It is possible to
leave out either of the 'OF' or the 'ON' parts but not both.
Examples:
GCOL OF 192,192,192
GCOL OF 0, 0, 0 ON 255,255,255
GCOL OF 1, 15
GCOL OF COLOUR(0, 0, 255)
The 'CCOL OF' statement (along with 'COLOUR OF') represent
a new way of selecting colours to use on screen. Along with
the 'COLOUR()' function they provide a means of specifying
colours independently of the screen mode, for example:
pink = GCOL(255, 127, 255)
blue = GCOL(0, 0, 255)
GCOL OF pink ON blue
This avoids the use of the 'TINT' keyword, which is really
only of use in old-style RISC OS 256 colour modes.
GOSUB
Syntax: a) GOSUB <line number>
b) GOSUB ( <expression> )
The GOSUB statement calls a subroutine. Control passes back to the
statement after the GOSUB by means of a RETURN statement.
a) The subroutine to be called starts at line <line number>.
b) The line number of the subroutine to be called is found given
by the numeric expression <expression>.
Note that the RENUMBER command will update the line numbers in the
first form of GOSUB above but it cannot handle the second form.
Example:
GOSUB 1000
GOTO
Syntax: a) GOTO <line number>
b) GOTO ( <expression> )
Program execution continues at the line specified on the GOTO
statement.
a) The number of the line is given explicitly and so the
interpreter can go to that line immediately.
b) The line number is given by the numeric expression
<expression>.
Note that the RENUMBER command will update the line numbers in the
first form of GOTO above but it cannot handle the second form.
IF
Syntax: a) IF <expression> [ [ THEN ] <statements> ]
[ ELSE <statements> ]
b) IF <expression> THEN <line number>
[ ELSE <line number> ]
c) IF <expression> THEN
<statements>
[ ELSE
<statements> ]
ENDIF
a) The first form of IF statement is the single line IF.
The numeric expression <expression> is evaluated. If the
result is not zero ('true') the statements after the THEN
keyword are executed otherwise the ones after the ELSE
keywords are executed.
There can be any number of statements after the THEN or ELSE
separated by colons. The only limit is the length of the
line. Those statements can include further IF statements and
some confusion can arise as to which IF statement an ELSE
clause applies. If the interpreter has to look for an ELSE
as the result of the IF expression is zero, it stops at the
first one it finds after the current IF.
It is possible to omit the THEN clause or the ELSE clause. It is
also possible to leave out the THEN. If the item after the IF
expression is neither a THEN nor a ELSE keyword, the THEN keyword
is assumed.
Examples:
IF abc$="xyz" THEN PROCabc: PROCdef
IF def<2.0 ELSE PRINT"def is too large"
IF X% PROCpqr
IF abc$="abc" THEN PRINT"abc": abc$="def" ELSE abc$="abc"
b) This is a variation on the single line IF. Either or both of
the THEN and ELSE keywords can be followed by a line number
instead of one or more statements. Program execution continues at
that line iIf the interpreter finds a line number after a THEN or
ELSE keyword.
Examples:
IF abc%=1 THEN 100
IF def<2.0 THEN PROCabc ELSE 200
IF ghi$="abc" ELSE 300
c) The second form of the IF statement is the block IF.
If there is nothing else on the line after a THEN keyword or
just a REM statement then the IF statement is a block IF.
The ELSE part is optional but if it is included the ELSE keyword
must be the first item on the line after the line number and any
leading blanks. The statements for the ELSE part can start on the
same line as the ELSE.
The ENDIF must be the first item on the line after the line number
and any preceding blanks.
Block IF statements can be nested to any depth.
Examples:
IF X%=1 THEN
PROCabc
ENDIF
IF X%=2 THEN
PROCabc
ELSE
PROCdef
ENDIF
IF X%=2 THEN
IF Y%=1 THEN STOP
ELSE
PROCabc
PROCdef
ENDIF
IF X=2 THEN REM X is set to 2
PROCabc
ELSE
PROCdef
ENDIF
Note in this last example that there is a REM statement after the
THEN but the statement is still seen as a block IF.
INPUT
Syntax: a) INPUT <list of variables>
b) INPUT# <factor>, <list of variables>
c) INPUT LINE <list of variables>
d) LINE INPUT <list of variables>
The INPUT statement is used to read data from the terminal
of from a file.
a) This form of INPUT statement reads from the terminal. The
format is more accurately specified as:
INPUT [<prompt> [,]] <list of variables>
[<prompt> [,]] <list of variables>] ...
<prompt> is a prompt displayed before the input is read. It
can be made up of any number of the following: a string,
the function TAB() and "'". TAB() is used to display the
prompt at a specific position on the screen. "'" causes a
skip to the next line. Examples:
INPUT TAB(10, 10) "Value: "
INPUT "Size"
INPUT TAB(0, 10) "Enter coordinates:" ' "X: "
TAB() takes two parameters, the column number and the row number
to which to move the text cursor, that is, the point at which the
next character will be written.
If the prompt is followed by a comma, a '?' is printed after the
prompt.
If the prompt is left out, a '?' will be displayed as the prompt.
<list of variables> is the list of variables to receive the
values read. There can be any number of these. The variable
names can be separated with blanks, commas or semicolons.
Examples:
INPUT X%,Y%
INPUT abc(1), abc(2), abc(3)
INPUT xyz$, ghi%
Values typed in are separated by commas. Leading blanks are
ignored when they are read. When reading a string, trailing blanks
as far as the next comma or the end of the are considered to be
part of the string.
Strings can be enclosed in double quotes.
Numeric values can be entered in hexadecimal or binary as well as
decimal. Hexadecimal values are preceded with a '&' and binary
ones with a '%'. (Note that this is an extension in this
interpreter.)
If insufficient values are supplied or an error found, the
interpreter prompts again for a value to be entered.
Multiple Prompts
----------------
It is possible to repeat as many prompt and variable list
sequences as desired. When 'return' is pressed the next prompt is
displayed and the next set of values read. Any values not used
from the previous read are discarded.
Example:
INPUT "Name: " name$ "Address: " address$
b) The second form of INPUT statement is used to read data from a
file. <factor> is the handle of the file from which input is to be
taken and <list of variables> gives the variables to received
those values.
Note that the data is assumed to be formatted binary data produced
using PRINT#. INPUT# cannot be used to read text from a file.
Example:
INPUT# file% , abc(1), abc(2), xyz$
c) and d) These are a variation on format a). The difference is
that each value read is taken from a new line.
Example:
LINE INPUT "Coordinates: " X% Y%
LET
Syntax: LET <variable> = <expression>
<expression> is evaluated and the result assigned to the variable
<variable>.
Only the '=' assignment operator is allowed here.
Pseudo-variables, for example, PTR#, cannot be used after LET.
LIBRARY
Syntax: a) LIBRARY <expression 1>, <expression 2>, ... , <expression n>
b) LIBRARY LOCAL <list of variables>
This statement has two purposes. In case a), it is used to read
libraries of Basic procedures and functions into memory.
<expression 1> to <expression n> are strings that give the names
of the libraries. There can be any number of these. The libraries
are held in memory until the Basic program is run again or edited
or the statements NEW or CLEAR used.
When a procedure or function is called, the interpreter checks to
see if it is one already encountered. If not it searches the Basic
program for it. If it cannot be found the interpreter then
searches the loaded libraries and it if still cannot locate it,
the libraries loaded via the INSTALL command. Libraries are
searched in the reverse order to which they were loaded, for
example, given:
LIBRARY "aaaaa"
LIBRARY "bbbbb"
LIBRARY "ccccc"
'ccccc' will be searched first, then 'bbbbb' and lastly
'aaaaa'.
Libraries can be seen as an extension of the program in memory
rather than separate entities. They can have their own private
variables (declared using LIBRARY LOCAL) but any other variables
created in procedures and functions in the library will be added to
those the program creates.
LIBRARY LOCAL is used to define variables and arrays that will be
private to a library. Only the library will be able to reference
these variables and arrays.
The syntax of the statement is as follows:
LIBRARY LOCAL <list of variables and arrays>
where <list of variable and arrays> is a list of variable and
array names separated by commas, for example:
LIBRARY LOCAL abc%, def%, ghi$, jkl(), mno(), pqr$()
In the case of arrays, this merely defines that the array is local
to the library. The dimensions of the array have to be declared
using a DIM statement in the normal way, for example:
LIBRARY LOCAL jkl(), pqr$()
DIM jkl(100), pqr$(table_size%)
There can be as many LIBRARY LOCAL and DIM statements as
necessary but they have to be before the first DEF PROC or DEF FN
statement in the library. They also have to be the first item on
the line.
The variables can only be referenced in the library. They are not
visible outside it. This is different to the way in which local
variables are dealt with in a procedure or function, where local
varables can be accessed by any procedure of function called by
the procedure in which they were declared. They can duplicate the
names of variables in the Basic program or other libraries.
When looking for a variable in a library, the interpreter first
searches for it amongst the library's private variables and then
in the Basic program's.
The variables and arrays are created the first time the library is
referenced. In practice this means that they are set up when
the interpreter has to search the library for a procedure or
function.
Private variables in a library can further be used as local
variables in a procedure or function. Note that they can only be
accessed in the library, for example:
LIBRARY LOCAL abc%, def, ghi$, jkl(), mno$()
DIM jkl(100)
DEF PROCaaa(abc%)
LOCAL def, ghi$
ENDPROC
DEF PROCbbb(def, jkl())
LOCAL mno$()
DIM mno$(100)
ENDPROC
DEF PROCccc(xyz, abc%)
ENDPROC
Here, abc%, def, ghi$, jkl() and mno$() are all declared to be
private to the library. The dimensions of jkl() are also defined.
In PROCaaa, abc% is used as a formal parameter (effectively a
local variable) and def and ghi$ declared to be local to the
procedure. Any procedure or function *in the library* that PROCaaa
calls that use def and ghi$ will use PROCaaa's local versions.
Any procedure or function that PROCaaa calls that are *outside*
the library *will not* see these variables.
In PROCbbb, def and jkl() are used as formal parameters and mno$()
is defined as a local array and its dimensions given. Note that
this is the first place where the dimensions have been defined.
In PROCccc, two variables are used as formal parameters, xyz and
abc%. This case is more complex in that abc% is one of the
library's private variables whereas xyz is not. xyz is one of the
Basic program's variables. abc% can only be referenced in the
library but xyz is visible anywhere.
The rules for the scope of private library variables may sound
complex but they are quite simple. The point to remember is that
a private variable in *only* accessible in the library in which it
was declared. If a variable is not declared on a LIBRARY LOCAL
statement then it is visible anywhere.
LINE
Syntax: a) LINE <x expression 1> , <y expression 1> ,
<x expression 2> , <y expression 2>
b) LINE INPUT <list of variables>
a) This form of the statement draws a line on the screen in the
current graphics foreground colour from coordinates
(<x expression 1> , <y expression 1>) to
(<x expression 2> , <y expression 2>).
Example:
LINE 100, 100, 400, 500
b) This is a version of the INPUT statement. It is described
in the section on INPUT above.
LOCAL
Syntax: a) LOCAL <list of variables>
b) LOCAL DATA
c) LOCAL ERROR
a) This version of the LOCAL statement is used in a procedure or
function to declare local variables. The keyword LOCAL is followed
by any number of variable names separated by commas, for example:
LOCAL abc%, def, ghi$, jkl
Arrays can also be declared to be local, but the definition of
a local array is slightly more complicated in that the new
array dimensions have to be given on a DIM statement, for example:
LOCAL xyz()
DIM xyz(100,10)
LOCAL statements can only appear in procedure or function.
The term 'local variables' is somewhat misleading in this context
in that the variables are accessible not just in the procedure or
function in which they are declared but anywhere in the program.
What actually happens is that if the variable already exists, its
old value is saved and then it is reset to zero (or the empty
string in the case of string variables). When the procedure or
function in which the variable was declared local is exited from,
the old value is restored. Variables that do not exist are created
by the LOCAL statement but they are not destroyed when the
procedure or function is left.
Anything that can appear on the left-hand side of an assignment
can in fact be declared as a local variable, so that, for example,
individual elements can be declared local if need be! Example:
LOCAL abc(25), abc(30)
This would declare two elements of array abc(), elements 25
and 30, to be local. The array abc() has to exist already for
this to work. Another example:
LOCAL block%!4, block%?20, $text%
This would preserve the integer value at address block%!4, the
byte at block%?20 and the string at $text%.
b) 'LOCAL DATA' saves the current value of the DATA statement
pointer. It can be reset to its original value by 'RESTORE DATA'.
Example:
LOCAL DATA
RESTORE 100
READ abc%
RESTORE DATA
Uses of LOCAL DATA can be nested without any problems.
Note that there are times when the DATA pointer will be set back
to its old value automatically:
1) If LOCAL DATA is used in a procedure or function the old value
will be restored when the function or procedure is exited from.
2) If it is used inside a WHILE, REPEAT or FOR loop, the value
will again be restored when the loop ends.
It is possible to leave out the RESTORE DATA but it is probably
best to include it.
c) The 'LOCAL ERROR' statement is used to save the details of the
current 'ON ERROR' error handler so that it can be changed and
restored later. 'RESTORE ERROR' is used to reset it. Example:
LOCAL ERROR
ON ERROR LOCAL PROClocal_error: ENDPROC
X=X/0
RESTORE ERROR
There is no limit on the number of times LOCAL ERROR can be used
(other than the memory available). It is possible to nest LOCAL
ERROR statements, that is, LOCAL ERROR can be used in a procedure,
say, and then it can be used again in the procedures that that
procedure calls without any problems.
As with LOCAL DATA, there are times when the old error handler
details will be restored automatically. They are:
1) If LOCAL ERROR is used in a procedure or function the old
handler will be restored when the function or procedure is
exited from.
2) If it is used inside a WHILE, REPEAT or FOR loop, the handler
will again be restored when the loop ends.
So RESTORE ERROR can be omitted but it is probably best to include
it.
MODE
Syntax: a) MODE <expression>
b) MODE <x expression>, <y expression>, <depth>, <rate>
a) The MODE statement is used to change the screen mode.
<expression> is the new screen mode. It can be either a number
or a string.
If the mode is numeric, it has to be in the range 0 to 127. This
gives the RISC OS screen mode number. The range of modes defined
corresponds to those available under RISC OS 3.1 (modes 0 to 46)
but whether or not all of these are available depends on the
machine on which the program is being run. Mode numbers greater
than 46 are undefined and mode 0 is used instead. There is one
special mode, mode 127. This corresponds to the screen or window
size of the environment in which the interpreter is being run, for
example, if the program is being run in an xterm under NetBSD with
a window size of 96 characters by 50 lines, mode 0 (80 by 32) will
use only part of this but mode 127 will switch to the entire
window.
The details of the screen mode can also be given as a string.
This can be the RISC OS screen mode number as a string or a
more precise specification of the resolution and the number of
colours to be used.
A mode string has the format:
X<x resolution> Y<y resolution> [ C<colours> ] [ G<levels> ]
where <x resolution> and <y resolution> give the screen size in
pixels, <colours> gives the number of colours for a colour
screen mode and <levels> the number of levels for grey-scale.
Example:
MODE "X800 Y600 C256"
The number of colours or grey scale levels is optional. The parts
of the mode string can be separated by any number of commas or
blanks.
As with numeric screen modes, whether or not the screen mode is
available depends on the machine on which the interpreter is being
used.
b) In this version of the statement, <x expression> and
<y expression> give the desired size of the screen in graphics
units. <depth> is a value that gives the number of colours
and <rate> the frame rate. The last parameter, <rate> can be
left out, in which case the highest frame rate available will
be used.
The program will attempt to match the details of the requested
mode with those available and will only switch to that mode if
it finds a match.
The possible values for <depth> are as follows:
1 2 colours
2 4 colours
4 16 colours
6 256 colours, old-style RISC OS mode
8 256 colours, new-style RISC OS mode
16 32K colours
32 16M colours
The values possible depend on the version of the program being
used. In general, depths of 16 and 32 are only available in the
version of the program that runs under RISC OS.
Under RISC OS, a depth of 6 specifies an old-style Archimedes
type 256 colour screen mode in which the extent to which
colours can be changed is limited. A depth of 8 indicates that
a newer type (RISC OS 3.5 and later) screen mode is to be used
where all of the colours can be changed.
Examples:
MODE 1024, 768, 8
MODE 640, 512, 2, 75
MOUSE
Syntax: a) MOUSE ON
b) MOUSE OFF
c) MOUSE <x variable> , <y variable> , <button variable>
[ , <timestamp variable> ]
d) MOUSE STEP <expression> [, <expression> ]
e) MOUSE COLOUR <expression> , <red expression>,
<green expression> , <blue expression>
f) MOUSE RECTANGLE <left expression> , <bottom expression>,
<right expression> , <top expression>
g) MOUSE TO <x expression> , <y expression>
The MOUSE statement is used to control various aspects of the
mouse.
a) MOUSE ON turns on the mouse pointer if it is not being
displayed.
b) MOUSE OFF turns off the mouse pointer.
c) This version of the statement reads the current position of the
mouse and the button state. The values are stored in <x variable>,
<y variable> and <button variable>. There is one optional
parameter, <timestamp variable>, which is set to the time at which
the mouse position was recorded derived from the centisecond
timer.
Example:
MOUSE xpos%, ypos%, buttons%
d) MOUSE STEP is used to the mouse multiplier, that is the number
of graphics units on the screen that each step of the mouse makes.
One or two values can be given. <expression> is a number greater
than or equal to zero. If one value is supplied then both the X
and Y steps are set to this value. If there are two values, the X
multiplier is set to the first value and the Y multiplier to the
second. It is possible to set the multiplier in either direction
to zero, in which case the mouse will not move in that direction.
Examples:
MOUSE STEP 4,3
MOUSE STEP 2,0
e) MOUSE COLOUR sets the colour of the mouse pointer on screen.
<expression> is in the range one to three and says which of the
three mouse colours to change. <red expression>, <green expression>
and <blue expression> are the colour components of the new colour.
Example:
MOUSE COLOUR 1, 255, 0, 0
f) MOUSE RECTANGLE defines a box on the screen outside of which
the mouse pointer cannot be moved. It requires four parameters,
<left expression>, <bottom expression>, <right expression> and
<top expression> which give the coordinates of the bottom
left-hand and top right-hand corners of the box in graphics
units.
Example:
MOUSE RECTANGLE 100, 100, 900, 600
g) The MOUSE TO statement moves the mouse pointer to the
coordinates (<x expression>, <y expression>) on the screen. The
position is expressed in graphics units.
Example:
MOUSE TO 600, 800
MOVE and MOVE BY
Syntax: a) MOVE <x expression> , <y expression>
b) MOVE BY <x expression> , <y expression>
The MOVE statements move the graphics cursor to the position
specified without drawing a line.
a) MOVE moves the cursor to position <x expression>,
<y expression>.
b) MOVE BY moves the cursor by an amount <x expression> and <y
expression> in the X and Y directions relative to the old graphics
cursor position.
Examples:
MOVE 500, 500
MOVE BY 100, 60
NEXT
Syntax: NEXT [ <variable name> ]
The NEXT statement is part of the FOR loop. It marks the end
of the loop. <variable name> is optional, and is the name of
the FOR loop index variable. Refer to the section above on
the FOR statement for more details.
Example:
NEXT N%
It is possible to end a number of loops on a single NEXT
statement. The syntax for this type of NEXT is:
NEXT [ <variable name 1> ] , [ <variable name 2> ] , ...
[ <variable name n> ]
In other words, NEXT is followed by a list of variable names
separated by commas. However, the variable names can be omitted,
in which case NEXT is followed by a series of commas, one less in
total than the number of FOR loops being ended at that point.
Examples:
FOR X% = 1 TO 10
FOR Y% = 1 TO 10
NEXT Y%,X%
FOR abc = 1 TO 100
FOR def = 1 TO 100
NEXT ,
OF
'OF' is part of a CASE statement. Refer to the section on
CASE statements above for more details.
Example:
CASE abc% OF
WHEN 1: PRINT"1"
ENDCASE
OFF
Syntax: OFF
This statement turns off the text cursor so that it is not
displayed.
Example:
IF hide% THEN OFF
ON
Syntax: a) ON
b) ON <expression> GOTO <line number 1> , ... ,
<line number n> [ ELSE <statement> ]
c) ON <expression> GOSUB <line number 1> , ... ,
<line number n> [ ELSE <statement> ]
d) ON <expression> PROC<name 1>, ... ,
PROC<name n> [ ELSE <statement> ]
e) ON ERROR <statements>
f) ON ERROR OFF
g) ON ERROR LOCAL <statements>
The ON keyword is used in a variety of statements as follows:
a) ON on its own turns on the text cursor if it is turned off
so that it is being displayed on the screen.
b) In this form of ON statement, the expression <expression> is
used to control which line to branch to next. <expression> is a
number greater than or equal to one. If it is one, the first line
listed after the GOTO keyword is the one to branch to, if it is
two, the second one list is the destination and so forth. Two
things can happen if <expression> is less than one or greater than
the number of line numbers given. If the ELSE part is supplied,
the interpreter jumps to the statement after this. Note that only
a single statement is allowed here. If there is no ELSE part, an
error is raised.
The line numbers after the GOTO can be given as expressions if
desired, but the RENUMBER command will probably fail if this is
done because it cannot deal with line numbers given in this way.
Examples:
ON abc% GOTO 100, 500, 900
ON def GOTO 1000, 2000, 3000, 4000 ELSE STOP
ON ghi% GOTO FNline1, FNline2, 1000, abc%*10+1
c) ON ... GOSUB is similar to ON ... GOTO. The expression
is used to control which subroutine to call. When the subroutine
call ends, the program continues to run at the statement after the
ON ... GOSUB. <expression> is used as an index to choose which
line number after the GOSUB to call. If the value of <expression>
is n, the n'th line number is the one selected. There are two
possibilities if <expression> is less than one or the greater than
the number of line numbers supplied. If there is an ELSE part, the
interpreter branches to that. If there is no ELSE, an error is
flagged.
The line numbers can be given as expressions if required.
Example:
ON abc% GOSUB 1000, 2000, 3000
ON def GOSUB 1000, 2000 ELSE PROCerror: PRINT"Done"
In second example, if def is set to one, the subroutine at line
1000 will be called. When it returns, execution resumes at the
statement 'PRINT"Done"' as this is the statement after the
ON ... GOSUB. Similarly, when PROCerror returns, execution
also continues with the PRINT statement.
d) ON ... PROC is again similar to ON ... GOTO. The result of
numeric expression <expression> is used as an index to locate the
procedure to call. If the value of <expression> is n, the n'th
procedure listed is the one called. When the procedure call has
ended, execution continue at the statement after the ON ... PROC.
There are two possibilities if <expression> is out of range, that
is, is less than one or greater than the number of PROC
statements after the expression. If there is an ELSE part, the
interpreter continues at that statement, otherwise an error is
reported.
Example:
ON abc% PROCaaa, PROCbbb(X%), PROCccc("abc")
ON def PROCaaa, PROCaaa, PROCbbb(1) ELSE STOP
e) ON ERROR
The ON ERROR statement is used to deal with errors that the
interpreter detects in the Basic program. When an error occurs the
interpreter continues with the statements after the 'ON ERROR'.
However, before it does so it automatically returns from all
procedures, functions and subroutines as well as ending any loops.
It is therefore not possible to recover from an error and resume
execution of the program at the point at which it was detected.
Example:
ON ERROR PROCcomplain: END
The section 'Error Handling' above discusses trapping errors in
programs in more detail.
f) ON ERROR OFF
This statement turns off the trapping of errors by the
Basic program.
g) The ON ERROR LOCAL statement is used to trap errors in the
Basic program. When one of these statements is executed by the
interpreter it notes the address of the statements after the
keywords ON ERROR LOCAL. When an error is detected it continues at
those statements.
ON ERROR LOCAL statement gives more control than ON ERROR in that
everything is left as it was at the time of the error. This means
that it is possible to trap errors and recover from them, resuming
at the point of the error.
Example:
ON ERROR LOCAL PRINT"Error - ";REPORT$
INPUT X,Y
PRINT X/Y
Here, if an error occured when inputting the values X and Y or
when X is divided by Y, the interpreter would branch to the PRINT
statement after the ON ERROR LOCAL, display the error message and
ask for input again.
The section 'Error Handling' above discusses trapping errors in
programs in more detail.
ORIGIN
Syntax: ORIGIN <x expression> , <y expression>
This statement changes the coordinates of the graphics origin.
<x expression> and <y expression> specify the new coordinates.
Example:
ORIGIN xplace, yplace
OSCLI
Syntax: OSCLI <string expression> [ TO <string array>
[ , <variable> ] ]
The OSCLI statement is used to issue a command to the operating
system on which the interpreter. <string expression> is the
command. <string array> is an array that will be used to hold the
output from the command. It is optional. If it is not present then
the command output goes to the normal place. <variable> is set to
the number of lines stored in <string array>. Again, it is
optional.
The existing contents of <string array> are discarded before the
output from the command is stored in it. Elements of the array
that are not used are set to the empty string. The first element
of the array used is 1, so the output is found in elements 1 to
<variable>. If there is more output than will fit in the array the
excess is discarded. There is nothing to indicate that this has
happened so it is up to the user to ensure that the array is large
enough.
Examples:
F% = OPENIN filename$: size% = EXT#F%: CLOSE#F%
DIM block% size%
OSCLI "load "+filename$+" "+STR$~block%
OSCLI <command> [ TO <string array> [ , <variable> ] ]
OSCLI "ex" TO array$(), lines%
FOR N%=1 TO lines%
IF LEFT$(array$(N%), 1)="a" THEN PRINT array$(N%)
NEXT
OTHERWISE
Syntax: OTHERWISE [: <statements>]
Part of a 'CASE' statement. When none of the cases given on WHEN
statements match the expression on the CASE statement, the program
continues at the statements after OTHERWISE. Refer to the section
on the 'CASE' statement above for more details.
OVERLAY
Syntax: OVERLAY
This statement is not supported by the interpreter.
PLOT
Syntax: PLOT <code> , <x expression> , <y expression>
This statement carries out the graphics operation with code
<code>. <x expression> and <y expression> are the two
parameters that plot codes use.
Plot codes are at the heart of the graphics support. They carry
out graphics operations such as drawing lines and shapes. Many of
the more common operations have their own statements, for example,
MOVE and DRAW. PLOT allows any of the codes to used in a program.
The section 'Plot Codes' below gives more details.
Examples:
PLOT 4, 100, 100
PLOT 5, 500, 100
PLOT 5, 500, 500
PLOT 5, 100, 100
This plots a triangle. It could also be written as:
MOVE 100, 100
DRAW 500, 100
DRAW 500, 500
DRAW 100, 100
On the other hand, a filled triangle would have to be drawn using:
MOVE 100, 100
MOVE 500, 100
PLOT 85, 500, 500
as there is no Basic statement to draw one.
POINT and POINT BY
Syntax: a) POINT <x expression> , <y expression>
b) POINT BY <x expression> , <y expression>
The POINT statement is used to plot a single point on the screen.
a) This form of the statement plots the point at coordinates
(<x expression>, <y expression>) on the screen.
b) This versions of the statement plots the point at the position
<x expression> and <y expression> graphics units in the X and Y
direction relative to the current graphics cursor.
Examples:
POINT 500, 100
PONT BY xoffset%, yoffset%
POINT TO
Syntax: POINT TO <x expression> , <y expression>
This statement is similar to the MOUSE TO statement. Normally
the pointer on screen is tied to the mouse but it does not
have to be. POINT TO is used to move the pointer when it is
not following the mouse. <x expression> and <y expression>
give the x and y coordinates in graphics units to which the
pointer is to be moved.
Example:
POINT TO 500, 500
PRINT
Syntax: a) PRINT <list of expressions>
b) PRINT# <factor>, <list of expressions>
The first version of the PRINT statement displays data on screen
and the second writes it to a file.
a) This version of the statement is used to display information on
the screen. <list of expressions> is a list of items to be
displayed. These are separated by blanks, ',' ';' or "'". In
addition there are two functions specifically for controlling
output.
Each item in <list of expression> can be an expression whose
value is to be displayed or a print function. The print functions
are:
TAB( <expression> )
This moves the text cursor to character position
<expression> on the current line. If the text cursor is
already beyond that column, move to the next line and
skip to the required column.
TAB( <x expression>, <y expression> )
Move the text cursor to column <x expression>, row
<y expression> on the screen.
SPC <expression>
Print <expression> blanks.
The rules describing how values are displayed are quite involved:
1) The print format of numbers is controlled by a special variable
called '@%'. See the section below for details on the values
that this can take.
2) Whilst @% affects the format used for a number, ';' and ','
affect the way in which it will be laid out.
',' causes two things: numbers will be printed right-justified
occupying the number of characters set by field width in @%.
Secondly, it causes the text cursor to be moved to the next
column whose number is a multiple of the field width.
';' causes numbers to be printed left-justified. They occupy
only as many characters as needed to express the number.
By default, numbers are printed right-justified.
If the first expression after the PRINT keyword is numeric and
the result has to be printed left-justified, the expression has
to be preceded with a ';' thus: 'PRINT ; abc%'.
3) If a numeric expression is preceded by a '~' then the value is
printed in hexadecimal. In fact the '~' acts as a switch and
and the results of all numeric expressions from this point to
the next ';' or ',' will be printed in hexadecimal.
4) If an expression is separated from the previous one by a space
then the second expression is formatted in same way as the
previous one.
5) If an expression is separated from the previous one by a "'"
the second expression is displayed on the next line. It will
be formatted in the same way as the previous expression.
6) The functions TAB() and SPC do not affect how numbers will
be formatted.
7) Strings are always printed left-justified and do not use the
field width set by @%.
Examples:
PRINT abc def
PRINT ~pqr% xyz%
PRINT ghi$, "abcde", ~abc%
PRINT abc$ TAB(20) def
PRINT TAB(1,1) "a" TAB(2,2) "b" TAB(3,3) "c"
PRINT ; xyz%
PRINT CHR$13 ; SPC20 ; X%
PRINT "Line 1" ' "Line 2" ' "Line 3"
The Format Variable @%
----------------------
This controls how numbers are formatted when they are printed. It
can also affect the function STR$.
@% can best be thought of as being made up of four distinct
byte-sized fields. They are laid out as follows:
<flags> <format> <places> <width>
with <flags> in the most significant byte of @% and <width>
in the least signicant byte.
<flags> contains two flag bits:
&80 Use ',' as decimal point
&01 Format is used by the function STR$
<format> controls how numbers are output. The values it can take
are:
0 General format
1 Exponent format
2 Floating point format
<places> gives the number of digits to print. The range is 1 to
255.
<width> is the field width, the number of characters that can be
used when displaying a number. The range is zero to 255
characters. This affects how a number will be displayed as well
as the number of characters skipped when using a ',' in a
PRINT statement.
The default value of @% is &90A, that is, use general output
format, display up to nine digits after the decimal point and use
a field width of ten characters.
To make it easier to use, @% can be set using by assigning the
desired format to it as a string.
@% = "<format string>"
<format string> is composed as follows:
[+] [<format>] [<width>] [ . <places>]
Starting the string with a '+' indicates that the format is used
to be used by the function STR$ .
<format> gives the format to use:
G General format
E Exponent format
F Floating point format
<width> is the field width.
<places> gives the number of digits to print. If the format is F,
it is the number of digits after the decimal point.
If ',' is used instead of '.' before the number of places, ',' is
used as the decimal point character instead of '.'.
Note that all of these parts are optional. Only the parts of the
format supplied in the string will be changed.
Examples:
@% = "G15.12"
@% = "E"
@% = "10"
@% = ","
@% = "+.10"
b) PRINT# writes data to the file with file handle <factor>.
<list of expressions> is the data to be written. Note that
the output is in binary, not text. It is designed to be read
by the INPUT# statement.
Examples:
PRINT#file%, xyz, abc%(X%), "abcdefghij"
QUIT
Syntax: QUIT [ <expression> ]
The QUIT statement is used to exit from the interpreter. It
canoptioanlly be followed by a numeric expression. This value
is passed back to the operating system under which the program
is running as a return or status code. If omitted it defaults
to zero.
READ
Syntax: READ <list of variables>
The READ statement is used to read values supplied via DATA
statements elsewhere in the program. <list of variables>
is the list of variables to which the values will be assigned.
When reading the value of a numeric variable, the value in
the data statement is treated as a Basic expression. The text
on the DATA statement is read as far as the next comma or the
end of the line and then evaluated. The result of the expression
is the value assigned to the variable.
If the variable being read is a string variable, the text on the
DATA statement is read as far as the next comma or the end of the
line. Blanks preceding any text are ignored but trailing blanks
are considered to be part of the string. The string can be
enclosed in double quotes if need be.
Examples:
abc% = 100
READ xyz%, pqr%
DATA abc%+10, 99
Here the expression 'abc%+10' is evaluated when xyz% is read and
xyz% will be set to 110.
READ abc$, def$
DATA aaa , " bbb "
abc$ will be set to the string 'aaa ' and def$ to ' bbb '.
The RESTORE statement can be used to change the DATA statement
from which data will be read. LOCAL DATA and RESTORE DATA can be
used to save the current DATA statement pointer and to retrieve
its value later.
RECTANGLE
Syntax: a) RECTANGLE <left expression> , <bottom expression>,
<width expression> [, <height expression> ]
b) RECTANGLE FILL <left expression> , <bottom expression>,
<width expression> [, <height expression> ]
c) RECTANGLE <left expression> , <bottom expression>,
<width expression> [, <height expression> ]
TO <x expression> , <y expression>
d) RECTANGLE FILL <left expression> , <bottom expression>,
<width expression> [, <height expression> ]
TO <x expression> , <y expression>
The RECTANGLE statement has two uses, to draw a rectangle and to
move or copy a rectangular portion of the screen to another part
of the screen.
a) This form draws a box on the screen. The botton left-hand
corner of the box is at the coordinate
(<left expression> , <bottom expression>) and the width and height
are given by <width expression> and <height expression>.
<height expression> can be omitted, in which case the height is
taken to be the same as the width.
b) This version draws a filled rectangle. The botton left-hand
corner of the rectangle is at the coordinate
(<left expression> , <bottom expression>) and the width and height
are given by <width expression> and <height expression>.
<height expression> can be omitted, in which case the height is
taken to be the same as the width.
c) This statement copies an area of the screen. The botton
left-hand corner of the area is given by the coordinate
(<left expression> , <bottom expression>) and the width and height
are given by <width expression> and <height expression>.
<height expression> can be omitted, in which case the height is
taken to be the same as the width. <x expression> and
<y expression> are the coordinates of the bottom left-hand
corner of the copied area.
d) This form moves an area of the screen. The botton left-hand
corner of the area is given by the coordinate
(<left expression> , <bottom expression>) and the width and height
are given by <width expression> and <height expression>.
<height expression> can be omitted, in which case the height is
taken to be the same as the width. <x expression> and
<y expression> are the coordinates of the bottom left-hand
corner of the location to which the area will be moved. The old
area is set to the background graphics colour.
Examples:
RECTANGLE 400, 400, 500, 200
RECTANGLE FILL 200, 200, width%, height%
RECTANGLE FILL 200, 200, size%
RECTANGLE left%, bottom%, with% TO 1000, 1000
RECTANGLE FILL left%, bottom%, with% TO 1000, 1000
REM
Syntax: REM <comments>
The REM statement is used to include comments in a program.
When a REM statement is encountered, the interpreter skips
to the next line in the program.
Example:
REM Here be dragons
REPEAT
Syntax: REPEAT
REPEAT marks the start of a REPEAT loop. The format of
one of these is:
REPEAT
<statements>
UNTIL <expression>
The block of statements <statements> is executed. The numeric
expression <expression> is evaluated when the UNTIL is reached. If
the result is zero (the value Basic used to represent false) the
program jumps back to the start of <statements> and continues from
that point again. If the result is not zero, execution continues
with the statement after the UNTIL. In other words, <statements>
will be executed repeatedly until the value of <expression> is not
zero.
REPEAT loops can be nested to any depth.
It is possible to start the loop on the same line REPEAT, missing
out the ':' statement separator.
The interpreter is not fussy about where the UNTIL is located, for
example, the following sort of code is allowed:
IF flag THEN UNTIL X%>10 ELSE UNTIL Y%>10
The interpreter silently ignores incorrectly nested loops of
different types so that, for example, the following will not give
an error:
REPEAT
FOR X% = 1 TO 10
UNTIL Y% = 0
Note that the effect of any LOCAL DATA or LOCAL ERROR statements
in the body of the loop will be reversed when the loop ends, that
is, the data pointer and error handler details will be restored to
the values they had when the LOCAL DATA or LOCAL ERROR was
encountered.
REPORT
Syntax: REPORT
The REPORT statement displays the error message for the last
error encountered in a program.
Example:
DEF PROCerror
PRINT"Program failed with error ";
REPORT
PRINT" at line ";ERL
END
REPORT is used to print the error message. There is a function
REPORT$ that returns it as a string then would be more convenient
in code such as the example above. Other useful functions in this
context are ERR and ERL which return the number of the last
error and the line in which it occured.
RESTORE
Syntax: a) RESTORE [ <line number> ]
b) RESTORE + <expression>
c) RESTORE DATA
d) RESTORE ERROR
The RESTORE statement has two uses: firstly, it is used to control
which DATA statement is to be used to provide data for a READ
statement and secondly it returns various internal pointers to
values previous saved.
a) This version of the statement sets the data pointer to point at
the DATA statement at or after line <line number>. The line number
can be an expression. It can also be omitted, when the data
pointer is reset to the first DATA statement in the program.
Example:
RESTORE
RESTORE 100
IF flag THEN RESTORE start% ELSE RESTORE finish%
b) This form of the statement sets the data pointer to a line
relative to the one in which the statement is found. <expression>
gives the number of lines to skip. It has to be a positive
value greater than or equal to zero. The data pointer is moved
to the DATA statement at or after the line indicated by the
RESTORE statement.
RESTORE +0
RESTORE +10
RESTORE +offset%
c) RESTORE DATA restores the data pointer to the value it had the
last time a LOCAL DATA was executed. RESTORE DATA has to match up
with a LOCAL DATA statement.
Note that RESTORE DATA is not always necessary as the data
pointer will be automatically restored under some conditions,
for example, if LOCAL DATA is used in a procedure, there will
be an implicit RESTORE DATA when the procedure call ends.
The data pointer is also restored automatically if LOCAL DATA is
used inside a FOR, WHILE or REPEAT loop when the program leaves
the loop.
Example:
LOCAL DATA
RESTORE 100
READ X%
RESTORE DATA
d) RESTORE ERROR restores the Basic error handler set up by ON
ERROR or ON ERROR LOCAL to its condition when the last LOCAL
ERROR statement was executed. RESTORE error has to match up with
a LOCAL ERROR statement.
Note that RESTORE ERROR is not always necessary as the details of
the error handler will be automatically restored under some
conditions, for example, if LOCAL ERROR is used in a procedure,
there will be an implicit RESTORE ERROR when the procedure call
ends. The error handler details are also restored automatically if
LOCAL ERROR is used inside a FOR, WHILE or REPEAT loop when the
program leaves the loop.
Example:
LOCAL ERROR
ON ERROR LOCAL REPORT
INPUT X%
RESTORE ERROR
RETURN
Syntax: RETURN
The RETURN statement is used to return from a subroutine invoked
via GOSUB to the statement after the GOSUB.
Example:
IF X%=0 RETURN
RUN
Syntax: a) RUN [ <line number> ]
b) RUN <string expression>
a) The first form of the RUN statement starts a program running.
The line number <line number> is optional. If supplied, execution
starts at that line in the program. If omitted, execution starts
at the beginning of the program.
b) The second version of the RUN statement is identical to the
CHAIN statement. The expression <string expression> provides the
name of the program to run. If the program can be found it is
loaded into memory and run. Any variables that existed at the time
the RUN command (with the exception of the static integer
variables, A% to Z%) are destroyed.
SOUND
Syntax: a) SOUND OFF
b) SOUND ON
c) SOUND <channel> , <amplitude> , <pitch> ,
<duration> , <delay>
This statement is used to make a sound. It is only supported under
the RISC OS version of the interpreter.
a) SOUND OFF turns off the sound system.
b) SOUND ON turns on the sound system.
c) This version of the statement is used to make a sound.
STEP
Syntax: STEP <expression>
The STEP statement is part of a FOR statement. The expression
<expression> gives the amount by which the FOR loop index
variable is incremented (or decremented if negative) on each
iteration of the FOR loop. Refer to the section on the FOR
statement for more details.
Example:
FOR N% = 10 TO 1 STEP -1: NEXT
FOR X% = 1 TO 5 STEP 2: NEXT
STEREO
Unsupported statement for controlling the RISC OS sound system.
STOP
Syntax: STOP
The STOP statement ends the run of a program. It differs from
END in that STOP is trapped as an error.
Example:
IF bad THEN STOP
SWAP
Syntax: SWAP <variable 1> , <variable 2>
The SWAP statement exchanges the values of the two variables
<variable 1> and <variable 2>. The variables have to be of the
same type, that is, numeric variables can switch values and
string variables can but types cannot be mixed.
Arrays can also be swapped but they have to be of exactly the
same type, although the array dimensions can be different.
Examples:
SWAP X%, Y%
SWAP abc(X%), abc(X%+1)
SWAP array1(), array2()
DIM aaa(25), bbb(10,10,10): SWAP aaa(), bbb()
The last example demonstrates that arrays of different sizes and
even with differing numbers of dimensions can be swapped.
SYS
Syntax: SYS <swi expression>, <expression 1>, ... ,
<expression n> [ TO <variable 1> , ... ,
<variable n> [ ; <flag variable>] ]
The SYS statement is only supported by the RISC OS version of
the interpreter. It is used to issue a SWI (RISC OS operating
system call) from a Basic program.
<swi expression> identified the SWI to call. This can be a number
or a string giving the name of the SWI. <expression 1> to
<expression n> are the parameters for the call. They can be
numbers or strings. Basic strings are converted to null-terminated
strings for the call. It is not possible to check that the types
of the parameters supplied are correct for the SWI call so it is
up to the programmer to ensure they are right.
Values can be returned from the SWI call. They are stored in the
variables <variable 1> to <variable n>. The type of the variable
is used to decide on the type of the value returned. Strings
returned by the SWI are converted to Basic strings. The processor
flags can also be returned by the call if <flag variable> is
supplied. It is possible to discard values returned by leaving
the position for that parameter after the 'TO' empty. The third
example below illustrates this (the first two values returned by
the SWI are not wanted).
Examples:
SYS "OS_Write0", "abcdefgh"
SYS 3
SYS "OS_Byte", 134 TO , , row
TEMPO
Unsupported statement for controlling the RISC OS sound system.
THEN
Syntax: THEN
The THEN keyword is used in an IF statement. Refer to the section
above on the IF statement for more information.
Example:
IF X%=1 THEN X%=2
TINT
Syntax: TINT <expression> , <tint expression>
The TINT statement only has an effect in 256 colour screen modes.
It sets the tint number <expression> to <tint expression>.
<tint expression> can take the values 0, 64, 128 or 192.
There are four colours settings used by the interpreter as
follows:
Text foreground colour
Text background colour
Graphics foreground colour
Graphics background colour
Each of these has a tint value associated with it that is used
in 256 colour screen modes. This statement allows the tint values
to be changed without having to change the colours as well. The
values to use to identify the tint to change are as follows:
0 Text foreground
1 Text background
2 Graphics foreground
3 Graphics background
Example:
TINT 0, 64
TO
Syntax: TO <expression>
The TO keyword is used in FOR loops to give the final value
for the loop variable. Refer to the section on the FOR statement
above for more information.
Example:
FOR N% = 1 TO 10: NEXT
TRACE
Syntax: a) TRACE ON
b) TRACE OFF
c) TRACE TO <expression>
d) TRACE CLOSE
e) TRACE PROC
f) TRACE GOTO
The TRACE statement is used to help debug Basic programs. It
controls the various trace options possible.
a) This form turns on the line number trace. This lists the number
of each line executed.
b) This turns off all the traces.
c) This sends the trace output to the file named by the string
expression <expression>. Normally output goes to the screen but
it is directed to a file if this statement is used.
d) This closes the trace file. Trace output continues on the
screen.
e) TRACE PROC displays the names of each procedure or function
as it is entered and left.
===>PROC<name> indicates that the procedure has been entered.
PROC<name>---> indicates that the procedure has been left.
The trace can be turned off with the statement:
TRACE PROC OFF
f) TRACE GOTO lists the origin and destination line numbers
every time a branch occurs in a program, for example, whenever
a procedure or function is called or there is a jump to the
top of a loop. It can be used to see the path through the
program in a more concise form than just displaying the number
of every line executed. The output from the trace is of the
form:
[<line number 1>-><line number 2>]
This says that a branch has occured from <line number 1>
to <line number 2>.
This trace can be turned off with the statement:
TRACE GOTO OFF
Sending Trace Output to a File
------------------------------
'TRACE TO' is used to send trace output to a file. The handle of
the file can be found by using TRACE as a function. If it is not
zero, output is going to the file with this handle. It is possible
to put extra data into the trace file, for example:
IF TRACE THEN BPUT#TRACE,"initialisation finished"
TRUE
Syntax: TRUE
The TRUE keyword returns the value Basic uses to represent
'true' (-1).
Example:
flag = TRUE
UNTIL
Syntax: UNTIL <expression>
The UNTIL keyword forms part of a 'REPEAT UNTIL' loop. Refer to
the section on the REPEAT statement for more information.
Example:
REPEAT
X%+=1
UNTIL X%=10
VDU
Syntax: VDU <expression 1> , ... , <expression n>
The VDU command sends output to the screen. The numeric
expressions <expression 1> to <expression n> are evaluated
one by one and the result sent to the screen driver. The
main purpose of this command is to send screen control codes
(the so-called 'VDU commands').
The amount of data sent for each expression depends on what
follows the expression. If there is a comma after it or it is the
last expression in the statement, one byte of data (the least
significant byte of the result) is sent. If there is a semicolon
after it, two bytes of data are sent, the two least significant
bytes of the result. The least significant byte is sent first, for
example:
VDU 31, 10, 10
This VDU command sends three bytes of data to the screen
driver.
VDU 29, 640; 512;
This example sends five bytes, 29 as one byte, 640 as two bytes
as it is followed by a ';' and 512 as two bytes.
If a '|' is used instead of a comma or semicolon, nine zeroes are
sent. This is useful when using the VDU 23 commands as nine bytes
of data has to be provided for these when the actual command might
need only one or two bytes. The extra zeroes are ignore or treated
as no-ops.
Examples:
VDU 31, 1, 1, ASC"a", 31, 2, 2, ASC"b"
The VDU statement allows any VDU command to be issued but the most
common ones are more conveniently handled by Basic statements, for
example, VDU 17 can be used to change the colour used for
displaying text but the COLOUR statement is easier.
VOICE
Unsupported statement for controlling the RISC OS sound system.
VOICES
Unsupported statement for controlling the RISC OS sound system.
WAIT
Syntax: a) WAIT
b) WAIT <expression>
a) This version of the statement causes the program to be halted
until the next vsync interrupt. It is used to synchronise drawing
output on the screen with the hardware to make the output look
neater.
Example:
WAIT
b) This version is used to make the program wait for a period
of time. <expression> is a numeric expression that gives the
time for which the program will pause in centiseconds. Pressing
the 'escape' key (either 'Esc' or control C, depending on the
environment) will cause the program to resume execution.
Example:
WAIT 500
This will make the program pause for five seconds.
WHEN
Syntax: WHEN <expression> [,<expression>] :
Part of a 'CASE' statement. Refer to the section on the 'CASE'
statement above for more details.
WHILE
Syntax: WHILE <expression>
The WHILE statement marks the start of a WHILE loop. The format
of one of these is:
WHILE <expression>
<statements>
ENDWHILE
The numeric expression <expression> is evaluated and if it is not
zero the loop entered. The program then continues until it comes
across an ENDWHILE. This is the end of the loop. The expression
<expression> is evaluated again and as long as the result is not
equal to zero the program branches back to the first statement
after the WHILE statement.
Note that the first ENDWHILE found is considered to be the end
of the loop. It is possible for different ENDWHILEs to be used
in the same loop, for example, it is possible to write code
such as:
WHILE X%<10
X%+=1
IF X%<5 THEN ENDWHILE ELSE ENDWHILE
If the expression <expression> is zero the first time the WHILE
statement is executed, the loop is skipped. Note that the
interpreter searches for the first ENDWHILE it can find and
assumes that that is the end of the loop. This could give a
problem if code like the example above is used.
The interpreter allows loops to be nested incorrectly and silently
ignores this sort of error, for example:
WHILE X%<10
X%+=1
REPEAT
Y%+=1
ENDWHILE
The interpreter will not complain about the missing 'UNTIL' part
of the nested REPEAT loop.
Note also that the effects of any LOCAL DATA or LOCAL ERROR
statements encountered in the loop will be reversed when the
program leaves the WHILE loop.
WIDTH
Syntax: WIDTH <expression>
This statement sets the number of characters printed on each line
by the PRINT statement to <expression> characters. It
automatically wraps round to the next line when that number is
reached. The default is the width of the screen or text window.
This version of the interpreter ignores WIDTH.
Example:
WIDTH 40
Commands
~~~~~~~~
Commands can only be entered on the command line with the
exceptions of LIST and LVAR which can be used in programs as well.
As with keywords, commands can often be abbreviated by typing the
first few characters of the command name and following that with a
dot, for example, 'l.' is the abbreviated form of the 'list'
command. The section 'Basic Keywords, Commands and Functions' at
the end of these notes gives the abbreviated versions of each
command.
On the command line, commands can be entered in mixed case (as
opposed to keywords, which have to be in upper case). If in a
program they are treated as normal keywords and have to be in
upper case. This can give rise to unexpected results, for example
the program:
10 list = 1.23
20 PRINT list
will print the number 1.23, but if:
list = 1.23
is entered on the command line it gives a syntax error as 'list'
is seen as a command. 'list' is in lower case in the program and
therefore it is not identified as the 'list' command. It is a
variable called 'list' in the program. It is best to avoid the use
of commands as variable names in programs where possible.
The commands available are:
APPEND
Not implemented.
AUTO
Not implemented.
CRUNCH
Ignored.
DELETE
Syntax: DELETE <line number 1> [ , <line number 2> ]
The DELETE command is used to delete a single line or a range of
lines from a Basic program. If a single line number is given then
only that line is removed. If two line numbers are provided then
all lines in that range are erased. It is not possible to retrieve
lines that have been deleted in error.
Example:
DELETE 100
EDIT
Syntax: EDIT [ <line number> ]
If a line number is supplied after the EDIT command, that line
is transfered to the command line where it can be edited.
If no line number is given, the program in memory is transferred
to a text editor where it can be more easily edited. When the
program is saved, the interpreter loads it back into memory.
The program is transferred to the editor using the current LISTO
settings to format it. This is not always the best way to do it
so there is a variation on the EDIT command, EDITO that can be
used instead.
Examples:
EDIT 100
EDIT
EDITO
Syntax: EDITO <expression>
EDITO is a variation of the EDIT command. It allows the format of
the program to be controlled when it is transferred to the editor.
<expression> is a numeric expression that gives the 'LISTO' value
to be used to format the program. As with EDIT, the program is
loaded back into memory when the program is saved in the editor
and the editor exited from.
The expression <expression> controls the format. The LISTO values
useful in this context are:
1 Insert a space after the line number.
2 Indent program structures such as block IF statements.
8 Omit line numbers.
The LISTO value is obtained by adding together these numbers. If
<expression> is 10, the program is transferred to the editor
without line numbers and with structures indented.
Example:
EDITO 8
HELP
Syntax: HELP
HELP displays some information on the program in memory and LISTO
and TRACE debug options.
INSTALL
Syntax: INSTALL <expression 1>, <expression 2> , ... , <expression n>
This command loads the Basic libraries named by the string
expressions <expression 1> to <expression n> into memory. If only
the names of the libraries are supplied, that is, the directory in
which they live are not given explicitly, the interpreter searches
for them in the directories given by the pseudo-variable
FILEPATH$.
The libraries are permanently loaded into memory, unlike libraries
that are loaded via the LIBRARY statement which are discarded under
some circumstances. It is not possible to unload these libraries. On
the other hand the same library can be loaded via LIBRARY and it will
be searched before the version loaded using INSTALL.
The library search order is:
1) Search libraries loaded via LIBRARY in the reverse order
to that in which they were loaded.
2) Search libraries loaded via INSTALL in the reverse order
to that in which they were loaded.
Note that libraries are seen as an extension to the program
in memory rather than separate entities. They can have their own
private variables (declared using LIBRARY LOCAL) but any other
variables created in procedures and functions in the library will
be added to those the program creates.
Example:
INSTALL "proclib"
LIST
Syntax: LIST [ <line number 1> [ , <line number 2> ] ]
The LIST command lists lines in the Basic program. If no line
number is given then the whole program is listed. If one line
number is supplied then just that line is displayed. If two line
numbers are given then all lines in that range are shown.
The lines are formatted according to the current setting of LISTO.
One useful option when listing a large number of lines is LISTO
32, which causes the interpreter to pause when twenty lines have
been listed until either the space bar or return is pressed.
The line numbers can be given by expressions and, unlike other
commands, LIST can be used in a running program.
Examples:
LIST
LIST 100,200
DEF PROCerror
PRINT REPORT$;" at line ";ERL
LIST ERL
ENDPROC
LISTIF
Syntax: LISTIF <search string>
The LISTIF command provides a simple string search facility.
<search string> is the string to look for. Every line where the
string is found is listed.
There are no wild card facilities.
Example:
LISTIF PROCerror
LISTIF abc%
LISTO
Syntax: LISTO <expression>
LISTO is primarily used to control how programs are formatted
when they are listed. It also provides the default format used
when transferring a program to a text editor or when saving a
program.
<expression> gives the new LISTO value. This is formed by adding
together one or more of the following values:
1 Insert a space after the line number.
2 Indent program structures such as block IF statements.
8 Omit the line number.
16 List keywords in lower case.
32 Pause after displaying twenty lines when listing program.
The LISTO value is obtained by combining these, for example,
indent structures, omit line numbers and list keywords in lower
case would be 2+8+16 = 26.
As noted above, the LISTO value is used by default when
transfering programs to an editor or saving them. This might not
always be the best format so the commands affected, EDIT and SAVE,
have variations where the LISTO value to be used for that command
invocation is given.
Really, the LISTO values are bit settings and the LISTO value is
obtained by OR'ing them together.
Examples:
LISTO 26
LISTO (2+8+16)
LISTO (LISTO+1)
LOAD
Syntax: LOAD <string expression>
The LOAD command is used to load a program into memory. Any
existing program and any variables created are discarded before
the new program is read.
If the name is just the name of the file, that is, it does not
contain any directory names, the interpreter looks first in the
current directory and the searches through the directories listed
by the pseudo-variable FILEPATH$ to find the program.
The name of the file is recorded and will be used as the name to
use by default by the SAVE command when the program is saved. Note
that the name (as shown by 'HELP') will normally include the name
of the directory in which the program was found.
Example:
LOAD "abc"
LOAD FNget_name
LVAR
Syntax: LVAR [ <letter> ]
The LVAR command is used to list the variables, procedures and
functions that have been created or called in the program. If a
letter is supplied then only items whose name starts with that
letter are listed. Note that only a single letter can be given: it
is not possible to give a pattern for the names to be listed.
Variables are listed with their current values. The dimensions of
arrays are given but not the values of the elements. The types of
the parameter of procedures and functions are given. Some entries
for procedures and functions give the line where they were found
and no parameters. These are procedures and functions that the
interpreter has found in the program but that have not been called
yet.
Examples:
LVAR
LVAR x
NEW
Syntax: NEW [ <expression> ]
The NEW command has two purposes. Its main use is to discard the
program in memory and any variables that have been created. If the
keyword NEW is followed by an expression, it not only does this
but changes the size of the Basic workspace to <expression> bytes.
The size of the Basic workspace is fixed. It can be specified when
the interpreter starts via the command line option '-size'. The
only way to change it when the interpreter is running is via the
NEW command.
Libraries loaded via INSTALL are retained over the change of
workspace size but the program in memory is lost and cannot be
recovered.
Example:
NEW
NEW 1000000
OLD
Syntax: OLD
The OLD command is used to attempt to recover a program in memory.
It is of limited use. It only stands a chance of working after
a plain NEW command (that is, one that does not change the
workspace size). If it appears that there is a program in memory
it carries out a number of checks to see if the program is intact.
If so it sets up the program again so that it can be run. If any
errors are detected the program is marked as a 'bad program'. It
cannot be run or edited. The checks carried out are not foolproof
and it is possible that a corrupted program will pass the tests.
Example:
OLD
RENUMBER
Syntax: RENUMBER [ <start expression> [ , <step expression> ] ]
The renumber command renumbers the lines of a program in memory.
<start expression> and <step expression> give the line number to
use for the first line and the increment from line to line. One or
both can be omitted, in which case they both default to ten.
<start expression> is in the range zero to 65279.
<step expression> is in the range one to 65279.
The renumber command will renumber the lines of the program and
any explicit references to line numbers on GOTO, GOSUB, ON GOTO,
ON GOSUB and RESTORE statements. Line numbers which are given by
expressions cannot be dealt with. Any line number references that
refer to lines in the program that are missing are left unchanged
and a warning message put out. If the highest line number allowed
(65279) is exceeded the command renumbers the program again with
a start value of one and a step of one.
Examples:
RENUMBER
RENUMBER 1000
RENUMBER 100,1
SAVE
Syntax: SAVE [ <string expression> ]
The SAVE command saves the program in memory in the file named by
<string expression>. The file is saved as plain text so that it
can be edited with any text editor.
<string expression> can be omitted. If this happens, the command
looks for a file name in two places:
1) It checks the first line of the program. If there is a '>' that
is followed by some text, that text is used as the name of the
file. (This follows an Acorn convention where the first line of
a file gives its name).
2) If the first check fails, the name saved from the last 'LOAD'
or 'SAVE' command is used.
An error is reported if a name cannot be found.
The program is saved in text form using the current LISTO settings
to format it. If this is not what is desired, the SAVEO command
can be used.
The name <string expression> is saved for use by later SAVE
commands if it is supplied.
Examples:
SAVE "abcdefgh"
SAVE A$+"/abc"
SAVE
SAVEO
Syntax: SAVEO <expression> [ , <string expression> ]
The SAVEO command is just like the SAVE command. It saves the
program in memory in the file named <string expression>. The
difference between it and SAVE is that the LISTO value to be used
to format the program when writing it to the file is specified by
<expression>. The LISTO values useful in this context are:
1 Insert a space after the line number.
2 Indent program structures such as block IF statements.
8 Omit line numbers.
The LISTO value is obtained by adding together these numbers. If
<expression> is 10, the program is saved without line numbers and
with structures indented.
As with SAVE, <string expression> can be omitted. If this happens,
the command looks for a file name in two places:
1) It checks the first line of the program. If there is a '>' that
is followed by some text, that text is used as the name of the
file. (This follows an Acorn convention where the first line of
a file gives its name).
2) If the first check fails, the name saved from the last 'LOAD'
or 'SAVE' command is used.
An error is reported if a name cannot be found.
The name <string expression> is saved for use by later SAVE
commands if it is supplied.
Examples:
SAVEO 10 , "abcdefgh"
SAVEO 3
TEXTLOAD
Syntax: TEXTLOAD <string expression>
This command is a synonym for the LOAD command in this
interpreter. Refer to the section on the LOAD command above for
more details.
TEXTSAVE
Syntax: TEXTSAVE [ <string expression> ]
This command is a synonym for the SAVE command in this
interpreter. Refer to the section on the SAVE command above for
more details.
TEXTSAVEO
Syntax: TEXTSAVEO <expression> [ , <string expression> ]
This command is a synonym for the SAVEO command in this
interpreter. Refer to the section on the SAVEO command above for
more details.
TWIN
Syntax: TWIN
This command is a synonym for the EDIT command in this
interpreter. Refer to the section on the EDIT command above for
more details.
TWINO
Syntax: TWINO <expression>
This command is a synonym for the EDITO command in this
interpreter. Refer to the section on the EDITO command above for
more details.
The Program Environment
~~~~~~~~~~~~~~~~~~~~~~~
The interpreter provides a partial emulation of the operating
system under which the Acorn interpreter runs, RISC OS. The
emulation is limited to supporting the control codes used for
screen output and the file handling used by the program. It is not
an attempt to write a RISC OS emulation layer.
Screen Output
~~~~~~~~~~~~~
The interpreter emulates the RISC OS VDU drivers for screen output
so some details of how these work and the facilities available
follow.
VDU Driver
----------
The VDU driver is the portion of RISC OS that handles screen
output. RISC OS mixes text and graphics on the same screen. The
screen size can be measured in text coordinates or graphics
coordinates.
Text coordinates have their origin at the top left-hand corner of
the screen and extend to the left and downwards:
(0,0)
+----------+
| |
| |
+----------+
(79,31)
Graphics coordinates have their origin at the bottom left-hand
corner of the screen and extend to the left and upwards:
(1279,1023)
+----------+
| |
| |
+----------+
(0,0)
The values in the diagrams are just examples.
Text coordinates are just character positions on screen. The range
of the coordinates varies according the screen resolution.
Graphics coordinates are more complex. Going back to the days of
the BBC Micro, the range of the coordinates was fixed at 0 to 1279
in the X direction and 0 to 1023 in the Y direction. This was
independent of the screen resolution; the operating system mapped
the graphics on to it. Later the mapping was changed when the
range of screen resolutions available was increased and larger
sizes became available. Up to a resolution of 640 by 512 pixels,
the graphics coordinates are in the range given earlier (with a
couple of exceptions). For sizes larger than that, the general
rule is that the graphics coordinate range is twice that of the
pixels, for example, the graphics coordinate range for a screen
resolution of 800 by 600 is 1600 by 1200 (0 to 1599 and 0 to
1199).
Graphics coordinates in the X and Y direction are in the range
-32768 to 32767.
The screen resolution and number of colours can be set using the
'MODE' command. This can be either a number that identifies the
mode to use or a string that gives its details.
Colours
-------
RISC OS supports colour depths of 1, 2, 4, 8, 15 and 24 bits per
pixel. The interpreter support 1, 2, 4 and 8 bit. The way colours
are dealt with in 2 colour (1 bit), 4 colour (2 bit) and 16 colour
(4 bit) modes is straight forwards but manipulating colours in 256
colour modes is slightly awkward due to the way the colour system
was originally designed back in the days of the BBC Micro. (The
old system was probably kept for compatibility.)
2, 4 and 16 Colour Modes
------------------------
There are logical colours and physical colours. The colour
corresponding to each logical colour can be changed by means of
VDU 19. The number corresponding to each physical colour is
as follows:
0 (8) Black
1 (9) Red
2 (10) Green
3 (11) Yellow
4 (12) Blue
5 (13) Magenta
6 (14) Cyan
7 (15) White
(Note: in this program colour numbers 8 to 15 simply repeat
colours 0 to 7. Under RISC OS they give flashing colours.)
256 Colour Modes
----------------
In 256 colour modes the colour is broken into two components, the
colour and a 'tint' value used to modify it. The colour portion is
six bits and the tint two bits. The colours in these modes are
constructed from sixty three colours, each of which has four
brightness levels. Unlike the other colour depths, the 256 colour
palette is essentially fixed and the colour number made up of the
colour and tint determines which of these fixed colours to used.
The tint value affects the brightness of the colours. It changes
the level of all three (red, green and blue) colours components at
the same time. It has four values: 0, 1, 2 and 3 but these are
written as 0, 64, 128 and 192.
The VDU drivers works in terms of the following colours when
writing text or plotting graphics:
Text foreground colour
Text background colour
Graphics foreground colour
Graphics background colour
Text and Graphics Windows
-------------------------
It is possible to define text and graphics windows so that output
goes to a restricted portion of the screen. Effectively the
windows by default occupy the entire screen but they can be
changed at any time.
Text-only Modes
---------------
Three of the screen modes, modes 3, 6 and 7, do not support
graphics. There are a hangover from the days of the BBC Micro.
VDU Commands
~~~~~~~~~~~~
The VDU commands are the escape sequences that the interpreter
uses to control output, for example, to move the cursor to a
specific location on the screen. It is customary to refer to these
as 'VDU commands'.
The ASCII character codes in the range 0 to 31 are used. The
format of a VDU code is a single command byte followed by up to
nine bytes of data. The complete list follows:
0 Does nothing
1 Send next character to the printer
2 Enable sending of characters to the printer
3 Disable sending sending of character to the printer
4 Display text at the text cursor position
5 Display text at the graphics cursor position
6 Enable the VDU drivers
7 Sound the console bell
8 Move the cursor back one character
9 Move the cursor forwards one character
10 Move the cursor down one line
11 Move the cursor up one line
12 Clear the text screen
13 Move the cursor to the start of the line
14 Enable page mode
15 Disable page mode
16 Clear the graphics window
17 Change the current text colou
18 Change the current graphics colour
19 Map logical colour to physical colour
20 Reset logical colours to default values
21 Disable the VDU driver
22 Change the screen mode
23 Various commands
24 Define the graphics window
25 Issue a graphics command
26 Restore default text and graphic windows
27 Do nothing
28 Define the text window
29 Define the graphics origin
30 Send cursor to top left-hand corner of window
31 Send cursor to given position in window
The interpreter does not support all of these. The following table
says what works where. The column marked 'Text' says whether the
code is supported (yes), flagged as an error (no) or ignored
(ignore) in text-only versions of the program. The column
'Graphics' gives the same information for versions that support
graphics.
Code Text Graphics
---- ---- --------
0 yes yes
1 yes yes
2 ignored ignored
3 ignored ignored
4 ignored ignored
5 no yes
6 ignored ignored
7 yes yes
8 yes yes
9 yes yes
10 yes yes
11 yes yes
12 yes yes
13 yes yes
14 ignored ignored
15 ignored ignored
16 no yes
17 yes yes
18 no yes
19 yes yes
20 yes yes
21 ignored ignored
22 yes yes
23 yes yes
24 no yes
25 no yes
26 yes yes
27 yes yes
28 yes yes
29 no yes
30 yes yes
31 yes yes
Details of the supported commands follow.
VDU 0
Does nothing.
VDU 1
Under RISC OS this sends the next character to the printer stream.
Under other operating systems it sends the next character
uninterpreted to the output stream, that is, it can be used to
output values that would normally be treated as VDU commands to
the output stream.
VDU 4
Display text at the text cursor position.
VDU 5
Display text at the graphics cursor position. Text is sent to the
current graphics cursor position with the graphic cursor defining
the position of the top left-hand corner of the character. The
graphics cursor position in the X direction is updated by the
width of a character expressed in graphics units. If the edge of
the window is reached output continues on the next line, that is,
the graphics Y coordinate is decreased by the height of a
character expressed in graphics units and the X coordinate is
reset to the edge of the graphics window.
Note that text written in this mode overwrites what is currently
on the screen without clearing the background of each character.
VDU 7
Sound the console bell.
VDU 8
Move the cursor back one character. The text cursor is moved back
one character, moving up a line and wrapping around to the
right-hand edge of the text window if it is at the left-hand edge
of the window. If the cursor is at the top left-hand corner of the
window it wraps around to the end of the line and scrolls the
window down by one line.
If text output is being sent to the graphics cursor the actions
are basically the same but they affect the graphics cursor instead
and leave the text cursor unchanged. The only difference is that
the cursor wraps around to the bottom right-hand corner of the
window if it was originally positioned in the top left-hand corner
instead of scrolling the screen. Changes in the X and Y
coordinates are by the width and height of a character expressed
in graphics units respectively.
VDU 9
Move the cursor forwards one character. The actions performed
follow the same pattern as VDU 8. The text cursor is moved
forwards by one character, moving down a line and wrapping around
to the left-hand edge of the text window if it was originally
positioned at the right-hand edge of the window. If it was
originally positioned at the bottom right-hand corner of the
window it is move to the left-hand edge and the window is scrolled
up one line.
If text output is being sent to the graphics cursor the actions
afffect the graphics cursor instead of the text cursor. As in the
case of VDU 8, the only difference is when the graphics cursor is
at the bottom right-hand corner of the graphics window. It wraps
around to the top left-hand corner.
VDU 10
Move the cursor down one line. The text cursor is moved down the
window by one line. If it was originally on the bottom line of the
text window it remains on that line and the window is scrolled
upwards by one line. If text is being sent to the graphics cursor,
the Y coordinate of the graphic cursor position is decreased by
the height of a character expressed in graphics units. If the
graphics cursor was originally at the bottom of the window it
wraps around to the top.
VDU 11
Move the cursor up one line. Again this follows the same pattern
as VDU 10. The text cursor is moved up by one line unless it was
originally positioned on the top line of the window, in which case
it is left there and the window is scrolled down by one line.
If output is going to the graphics cursor, the Y coordinate of the
cursor is increased by the height of a character expressed in
graphics units unless the cursor was located at the top of the
window, in which case it is moved to the bottom.
VDU 12
Clear the text window. The text window is set to the text
background colour.
VDU 13
Move the cursor to the start of the line. The cursor is moved to
the left-hand edge of the window on the current line. If output is
being sent to the graphics cursor it is the graphics cursor that
is moved otherwise it is the text one.
VDU 16
Clear the graphics window. The entire graphics window is set to
the current graphics background colour.
VDU 17
Change the current text colour. This is followed by one byte of
data, the new colour number. If this is less than 128 the
foreground colour is changed, otherwise the background colour is
the one altered, the number of the colour to use being given by
the colour number-128.
The colour number is reduced modulo the number of colours
available in the current screen mode in 2, 4 and 16 colour modes.
In 256 colour modes it is reduced modulo 64. This alters the
colour value but not the tint (see the section '256 Colour Modes'
above for an explanation of this).
VDU 18
Change the current graphics colour. This is followed by two
bytes of data:
Byte 1 Plot action
2 Colour number
The 'plot action' controls how graphics are plotted on the
screen. Currently the only value supported here is zero,
causing each point to overwrite what was previously at that
place on the screen.
If the colour number is less than 128 the foreground graphics
colour is changed, otherwise the background colour is updated. 128
is subtracted from the colour number to get the number of the
colour to use. The colour number is then reduced modulo the number
of colours available in the current screen mode in 2, 4 and 16
colour modes. In 256 colour modes it is reduced modulo 64 to
change the colour value. It does not affect the tint (see the
section 256 Colour Modes' above for more information on this).
VDU 19
Map logical colour to physical colour.
This requires five bytes of data after the command as follows:
Byte 1 Logical colour number
2 Physical colour number
3 Red component
4 Green component
5 Blue component
The logical colour number is reduced modulo the number of colours
available in the current screen mode in 2, 4 and 16 colour modes.
If the physical colour number is in the range zero to fifteen
the physical colour corresponding to the given logical colour
is changed to the value supplied. The red green and blue
colour components are ignored. This version of the VDU command
only has an effect in 2, 4 and 16 colour modes.
If the physical colour number is sixteen, the colour for the
given logical colour number is changed to the one with the
red, green and blue components supplied in bytes 3, 4 and 5.
Physical colour numbers greater than sixteen are ignored in
versions of the interpreter that do not run under RISC OS.
VDU 20
Reset logical colours to default values.
VDU 22
Change the screen mode. This takes one byte of data, the new
screen mode. It causes the text and graphics windows to be set to
cover the whole screen, resets the colour palette to its default
for that mode and moves the text and graphics cursors to their
respective origins.
VDU 23
VDU 23 has two purposes. Firstly, it allows any of the characters
with codes in the range 32 to 255 to be redefined and, secondly,
it is the code used for a range of commands that affect the
operation of the VDU drivers.
VDU 23 requires nine bytes of data. The format is:
Byte 1 Command or character code
2 to 9 Command or character data
If the first byte, the command byte, is in the range 32 to 255 VDU
23 is being used to define the layout of the character with that
code. The eight bytes of data that follow contain the image for
that character. If the command byte is in the range 0 to 31 then
it is a command for the VDU driver. Eight bytes of data must be
supplied but the command might ignore them.
Only two of the VDU 23 commands are supported:
23,1 Hide or show the text cursor.
23,17 Set the 'tint' value in 256 colour screen modes.
23,1
----
The two values defined are:
23,1,0 This removes the text cursor
23,1,1 This displays the text cursor
23,17
-----
The format of this command is:
23,17,<option>,<tint>
where:
<option> says what to set:
0 Set foreground text tint value
1 Set background text tint value
2 Set foreground graphics tint value
3 Set background graphics tint value
5 Swap foreground and background text colours
<tint> sets the new tint value. Four values are allowed: 0, 64,
128 and 192.
VDU 24
Define the graphics window.
This requires eight bytes of data after the command as
follows:
Bytes 1 and 2 x coordinate of left-hand side of window.
Bytes 3 and 4 y coordinate of bottom of window.
Bytes 5 and 6 x coordinate of right-hand side of window.
Bytes 7 and 8 y coordinate of top of window.
Each pair of bytes is treated as a two byte signed integer with
the least significant byte sent first. The coordinates are given
relative to the current screen origin. The command is ignored if
any of the coordinates lie outside the screen.
VDU 25
Issue a graphics command. Any graphics operation such as drawing a
line or plotting a circle goes can be carried out using VDU 25.
The code is followed by five parameter bytes as follows:
Byte 1 Graphics PLOT code
2 Low byte of first parameter
3 High byte of first parameter
4 Low byte of second parameter
5 High byte of second parameter
See the section 'PLOT Codes' below for details of the graphics
commands allowed.
VDU 26
Restore default text and graphic windows. The text and graphics
windows are set to full screen. The text cursor is moved to the
top left-hand corner of the screen and the current graphics
position set to (0, 0), which is at the bottom left-hand corner of
the screen. The graphics origin is also reset to this position.
VDU 27
Does nothing.
VDU 28
Define the text window.
This command requires four bytes of data as follows:
Byte 1 column number of left-hand side of window.
2 Row number of bottom of window.
3 Column number of right-hand side of window.
4 Row number of top of window.
If any of the coordinates are off the screen the command is
ignored.
VDU 29
Define the graphics origin.
This requires four bytes of data after the command as
follows:
Bytes 1 and 2 x coordinate of graphics origin.
Bytes 3 and 4 y coordinate of graphics origin.
The pair of bytes is treated as a two byte signed integer with the
low-order byte send first. The coordinates are absolute, that is,
they are not specified relative to the current graphics origin.
VDU 30
Send cursor to top left-hand corner of window. The text cursor
(or the graphics cursor if text is being plotted at the graphics
cursor) is sent to the top left-hand corner of the window.
VDU 31
Send cursor to given position in window.
This requires two bytes of data after the command:
Byte 1 Column number
2 Row number
The text cursor (or the graphics cursor if text is being plotted
at the graphics cursor) is sent to the position corresponding to
text coordinate (column, row) on the screen.
PLOT Codes
~~~~~~~~~~
Plot codes form the heart of the graphics support. Normally use of
these is hidden behind Basic statements such as 'MOVE', 'DRAW' and
'CIRCLE' but they can be used directly in programs by means of the
'PLOT' statement and VDU 25.
The codes are in the range 0 to 255. Each code can really be
thought of as containing three fields which specify the operation,
how the graphics coordinates are to be interpreted and how to
treat the graphics colours. The graphic operation is given by
(plot code DIV 8). How to treat the coordinates and colours is
given by (plot code MOD 8). It is easier to understand plot codes
if they are written in binary. They can be expressed in this way
as:
xxxxx y zz
where 'xxxxx' is the graphics operation, 'y' says how to treat the
coordinates and 'zz' how to handle the colours. 'y' and 'zz' are
defined as follows:
'y' values:
0 Treat coordinate as relative
1 Treat coordinate as absolute
'zz' values:
0 Only move the graphics cursor.
1 Plot graphics using graphics foreground colour.
2 Plot graphics using logical inverse of colour at
each point.
3 Plot graphics using graphics background colour.
The interpreter does not support the full range of PLOT codes. The
ones implemented are:
0- 7 Draw a solid line
64- 71 Plot a single point
80- 87 Draw a filled triangle
96-103 Draw a filled rectangle
112-119 Draw a filled parallelogram
128-135 Flood fill background
144-151 Plot a circle outline
152-159 Draw a filled circle
184-191 Move or copy a rectangle
192-199 Draw an ellipse outline
200-207 Plot a filled ellipse
Typical plot codes used are 4 (move graphics cursor), 5 (draw a
line) and 69 (plot a point).
Mode Variables
~~~~~~~~~~~~~~
The VDU function can be used to find out information about the
current screen mode being used, for example, the width of the
screen in characters or in pixels. It is used as in the following
example:
width% = VDU 1
PRINT"Screen width in characters is "; width%
The allowed values and what they return are as follows:
0 ModeFlags 0 if mode is capable of graphics
1 if mode is text only.
1 ScrRCol Width of screen in characters - 1
2 ScrBRow Height of screen in characters - 1
3 NColour Number of colours allowed - 1
11 XWindLimit Width of screen in pixels - 1
12 YWindLimit Height of screen in pixels - 1
128 GWLCol Graphics window left limit in pixels
129 GWBRow Graphics window bottom limit in pixels
130 GWRCol Graphics window right limit in pixels
131 GWTRow Graphics window top limit in pixels
132 TWLCol Text window left limit in characters
133 TWBRow Text window bottom limit in characters
134 TWRCol Text window right limit in characters
135 TWTRow Text window top limit in characters
136 OrgX Graphics X origin in RISC OS graphics units
137 OrgY Graphics Y origin in RISC OS graphics units
153 GFCOL Graphics foreground colour
154 GBCOL Graphics background colour
155 TForeCol Text foreground colour
156 TBackCol Text background colour
157 GFTint Graphics foreground tint value
158 GBTint Graphics background tint value
159 TFTint Text foreground tint value
160 TBTint Text background tint value
161 MaxMode Highest screen mode number supported
The names in the second columns are what the mode variables are
called in RISC OS documentation.
If the value passed to the function is not one of the above,
the function returns 0.
The mode variables that return graphics information will return
zero in versions of the program that do not support graphics.
The RISC OS version of the program supports the full range of
mode variables. The ones given above represent only a selection
of them. The complete list can be found on pages 703 to 705 and
710 and 711 of volume 1 of the RISC OS Programmer's Reference
Manual.
Basic Keywords, Commands and Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Basic Keywords
--------------
This is a list of all of the Basic keywords and their minimum
abbreviations. The '.' after each abbreviated name is considered
to be part of the name.
Keyword Abbreviation Keyword Abbreviation
AND A. BEATS BE.
BPUT BP. CALL CA.
CASE CAS. CHAIN CH.
CIRCLE CI. CLG CLG
CLEAR CL. CLOSE CLO.
CLS CLS COLOUR C.
DATA D. DEF DEF
DIM DIM DIV DI.
DRAW DR. ELLIPSE ELL.
ELSE EL. END END
ENDCASE ENDC. ENDIF ENDI.
ENDPROC E. ENDWHILE ENDW.
ENVELOPE ENV. EOR EOR
ERROR ERR. FALSE FA.
FILL FI. FN FN
FOR F. GCOL GC.
GOSUB GOS. GOTO G.
HIMEM H. IF IF
INPUT I. LET LET
LIBRARY LIB. LINE LIN.
LOCAL LOC. MOD MOD
MODE MO. MOUSE MOU.
MOVE MOV. NEXT N.
NOT NOT OF OF
OFF OFF ON ON
OR OR ORIGIN OR.
OSCLI OS. OTHERWISE OT.
OVERLAY OV. PLOT PL.
POINT POINT PRINT P.
PROC PROC QUIT Q.
READ REA. RECTANGLE REC.
REM REM REPEAT REP.
REPORT REPO. RESTORE RES.
RETURN R. RUN RU.
SOUND SO. STEP S.
STEREO STER. STOP STO.
SWAP SW. SYS SY.
TEMPO TE. THEN TH.
TINT TIN. TO TO
TRACE TR. TRUE TRU.
UNTIL U. VDU V.
VOICE VOICE VOICES VO.
WAIT WA. WHEN WHE.
WHILE W. WIDTH WI.
Basic Commands
--------------
Following is a list of all of the Basic commands and their
minimum abbreviations.
APPEND AP. AUTO AU.
CRUNCH CR. DELETE DEL.
EDIT ED. EDITO EDITO
HELP HE. INSTALL INSTAL.
LIST L. LISTIF LISTIF
LISTO LISTO LOAD LO.
LVAR LVA. NEW NEW
OLD O. RENUMBER REN.
SAVE SA. SAVEO SAVEO
TEXTLOAD TEX. TEXTSAVE TEXTS.
TEXTSAVEO TEXTSAVEO TWIN TWIN
TWINO TWINO
In addition, although 'RUN' and 'QUIT' are classed as keywords
they are really commands and be entered in mixed case like
any of the commands listed above.
Functions and Pseudo Variables
------------------------------
Following is a list of all of the Basic functions and pseudo
variables and their minimum abbreviations.
ABS AB. ACS AC.
ADVAL AD. ARGC ARGC
ARGV$ ARGV$ ASC AS.
ASN ASN ATN AT.
BEAT BEAT BGET B.
CHR$ CHR$ COS COS
COUNT COU. DEG DE.
EOF EOF ERL ERL
ERR ERR EVAL EV.
EXP EXP EXT EXT
FILEPATH$ FILE. GET GET
GET$ GE. INKEY INKEY
INKEY$ INK. INSTR( INS.
INT INT LEFT$( LE.
LEN LEN LN LN
LOG LOG LOMEM LOM.
MID$( M. OPENIN OP.
OPENOUT OPENO. OPENUP OPENU.
PAGE PA. PI PI
POS POS PTR PTR
RAD RA. RIGHT$( RI.
RND RN. SGN SG.
SIN SI. SQR SQR
STR$ STR. STRING$( STRI.
SUM SU. SUMLEN SUMLEN
TAN T. TIME TI.
TIME$ TIME$ TOP TOP
USR US. VAL VA.
VERIFY( VE. VPOS VP.
XLATE$ XL.
|