home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d969 / ace.lha / ACE / ACE-2.0.lha / DOCS.LHA / ace.doc < prev    next >
Text File  |  1994-01-19  |  87KB  |  2,419 lines

  1.  
  2.                 --------
  3.                 ACE v2.0
  4.                 --------
  5.  
  6.       CONTENTS                       LINE  PAGE
  7.       --------                        ----  ----
  8.  
  9.   (i)   Introduction
  10.  
  11.     What is ACE?..................................80     2
  12.     Who is it for?...............................165     3
  13.  
  14.     ------------------------------------------------
  15.  
  16.  (ii)    Getting started
  17.  
  18.     Installation.................................213     4
  19.     Using the compiler...........................287     5
  20.     Compiler options.............................334     6
  21.     Running ACE programs.........................402     7
  22.     About the example programs...................413     7
  23.  
  24.     ------------------------------------------------
  25.  
  26.  (iii)  A hitch-hiker's guide to ACE 
  27.  
  28.     General comments.............................446     8
  29.  
  30.     The preprocessor and #include files..........477     8
  31.  
  32.     Data types, expressions, constants...........520     9
  33.     Precedence of operators......................602    10
  34.     Identifiers..................................634    11
  35.     Indirection operators........................752    13
  36.  
  37.     Files........................................788    13
  38.  
  39.     Command line and Workbench arguments.........885    15
  40.  
  41.     Subprograms..................................934    16
  42.     Structures..................................1163    19
  43.     Shared library function calls...............1266    21
  44.     Machine code calls..........................1405    23
  45.     External references.........................1477    24
  46.  
  47.     Windows.....................................1521    25
  48.     Screens.....................................1543    25
  49.     Gadgets.....................................1575    26
  50.     Menus.......................................1695    28
  51.     Requesters..................................1719    28
  52.  
  53.     Turtle Graphics.............................1744    29
  54.  
  55.     Sound.......................................1849    30
  56.  
  57.     Event trapping..............................1946    32
  58.  
  59.     Error handling..............................2044    33
  60.  
  61.  
  62.                                   - page 1 -
  63.  
  64.     ------------------------------------------------
  65.  
  66. (iv)    Stop bits
  67.  
  68.     Notes for assembly programmers..............2078    34
  69.     Limitations.................................2123    35
  70.     Known bugs..................................2165    35
  71.     Future versions.............................2182    36
  72.     A note to PD libraries and reviewers........2221    36
  73.     Disclaimer..................................2242    37
  74.     References..................................2249    37
  75.     Final word..................................2291    37
  76.  
  77.         ================================================
  78.  
  79.  
  80. What is ACE?
  81. ------------
  82.  AmigaBASIC Compiler with Extras?
  83.  A Creative Environment? 
  84.  A Compiler for Everyone?
  85.  A Cool Enterprise?
  86.  Automatic Computing Engine (ala Alan Turing)?
  87.  Dr Who's last companion?  
  88.  
  89. Okay, seriously...
  90.  
  91. ACE is a freely distributable, recursive descent, peephole-optimising Amiga 
  92. BASIC compiler which produces A68K-compatible assembly source code. ACE runs 
  93. under Wb 1.3, 2.x and up, as do the executables it produces. ACE will run
  94. in 512K, but more than this is required for programs beyond about 250 lines.
  95.  
  96. ACE supports a large subset of AmigaBASIC. It also provides a variety of 
  97. commands, functions and features not found in AmigaBASIC.
  98.  
  99. In most cases, ACE programs produce results which are similar or identical 
  100. to programs written in AmigaBASIC.
  101.  
  102. Any differences between the two are discussed in this document and the 
  103. command and function reference.
  104.  
  105. The following files constitute a complete ACE package:
  106.  
  107.         executables
  108.         -----------      
  109.     bas        - A shell script which automates
  110.                 the production of ACE executables.
  111.     app        - A simple preprocessor.
  112.     ace        - The BASIC compiler.
  113.     a68k        - Charlie Gibbs' 68000 assembler.
  114.     blink        - The Software Distillery's linker.
  115.     muchmore    - The file viewer by Fridtjof Siebert 
  116.               (version which works under Wb 1.3).
  117.  
  118.      documents
  119.     ---------        
  120.     ace.doc        - The document you are reading which describes ACE.
  121.     ref.doc     - A command and function reference for ACE.
  122.     history        - A history of ACE's development.
  123.  
  124.                                   - page 2 -
  125.  
  126.     a68k.doc    - Documentation for the assembler.
  127.     blink.doc    - Documentation for the linker.
  128.  
  129.     scanned libraries
  130.     -----------------
  131.     ami.lib        - A freely distributable version of amiga.lib.
  132.     startup.lib    - A library of routines needed at the start and
  133.               end of an ACE program run.
  134.     db.lib        - A library of assorted routines used by ACE
  135.               programs.
  136.  
  137.     other stuff
  138.     -----------
  139.     includes    - Some useful ACE include files. 
  140.     icons        - ACE tool and document icons.
  141.     utils        - Miscellaneous utilities.
  142.     examples    - Example programs which demonstrate many of ACE's 
  143.               capabilities.
  144.      AIDE        - A simple graphical front-end for ACE with "make"
  145.               capabilities.
  146.  
  147. With one exception (see the discussion of file requesters under Wb 1.3 in 
  148. the "Requesters" section below) ACE programs do not require any special 
  149. run-time shared libraries, so the executables which the compiler produces 
  150. (via the assembler and linker) are completely portable, requiring only the 
  151. standard Amiga shared libraries in your LIBS: directory. The three ".lib" 
  152. files mentioned above are scanned libraries and code from these is included 
  153. at link time.
  154.  
  155. ACE is written in C (Sozobon's ZC v1.01), while db.lib and startup.lib are 
  156. written in assembler (~60%) and C.
  157.  
  158. A68K and Blink are used to assemble and link the code produced by ACE.
  159. The MicroEmacs (v1.3 & v2.1) editor has been used throughout every stage
  160. of ACE's development. It works for me.
  161.  
  162. The complete ACE package may be freely distributed.
  163.  
  164.  
  165. Who is it for?
  166. --------------
  167. ACE is intended for anyone who already knows BASIC and wants one or more of
  168. the following:
  169.  
  170.     - Faster program execution.
  171.  
  172.     - Independence from the BASIC interpreter, ie: standalone 
  173.       programs which are runnable from the CLI/Shell and Workbench.
  174.  
  175.     - Extra commands, functions and features: turtle graphics,
  176.       command-line (and Workbench) arguments, recursion, SUBs with 
  177.       return values, external references, named constants, structures, 
  178.       include files, better WAVE command, gadgets, requesters, etc.
  179.  
  180. Maybe you don't wish to learn another high-level language, or perhaps you 
  181. already use C or assembler but prefer to use BASIC for some tasks while 
  182. still having the power of a compiled language.
  183.  
  184. ACE is a general purpose language so in theory at least, it can be applied
  185.  
  186.                                   - page 3 -
  187.  
  188. to any programming task you like. In practice however, I find ACE to be most
  189. useful for writing small to medium sized programs where speed is important 
  190. but so is ease of programming.
  191.  
  192. ACE is also a useful prototyping language. It allows you to get something 
  193. up and running quickly to test an idea. You may later decide to re-code in 
  194. C or assembler, or you may just add some polish to the existing ACE program.
  195.  
  196. The latter is becoming more feasible as ACE matures.
  197.  
  198. I have written the following kinds of programs with ACE:
  199.  
  200.     - Shell utilities, eg: basic calculator (ACE:prgs/ShellUtils/bc.b).
  201.     - Fractal/Chaos programs.
  202.     - Neural networks.
  203.     - An 8SVX sound sample player.
  204.     - Astronomy programs, eg: galaxy collision simulator,
  205.       Jovian satellite motion simulator, Messier object database.
  206.     - An Integrated Development Environment (AIDE - see separate
  207.       archive).        
  208.     - A program which matches section headings to line and page 
  209.       numbers to create the document you are now reading from an
  210.       unformatted version of it.
  211.  
  212.  
  213. Installation
  214. ------------
  215. You will need to open a shell to install ACE. Installation consists of:
  216.  
  217.     - Extracting the four archives found in the single supplied ACE 
  218.       archive.
  219.  
  220.     - Adding a few commands to your s:user-startup (Wb 2.x/3.0) or 
  221.       s:startup-sequence (Wb 1.3) file.
  222.  
  223. The ACE distribution archive contains:
  224.  
  225.     - MAIN.lha        (main ACE files with a few examples)
  226.     - DOCS.lha        (documentation for ACE,A68K and Blink)
  227.     - PRGS.lha        (more example programs)
  228.     - AIDE.lha        (a graphical front-end for ACE)
  229.  
  230. All four will fit onto a single floppy disk in their compressed form.
  231.  
  232. You must now extract the files from each archive with:
  233.  
  234.     lha x <archive>
  235.  
  236. If you have a hard disk, just extract all four archives into a directory
  237. created for ACE (eg: sys:ACE). Extract MAIN.lha first. This will set up the 
  238. directory structure and main ACE files.
  239.  
  240. The extraction of MAIN.lha also creates three subdirectories for the last 
  241. three archives. So, finally, extract DOCS.lha, PRGS.lha and AIDE.lha into
  242. the docs, prgs and AIDE subdirectories.
  243.  
  244. If you are using a floppy-only system, extract MAIN.lha onto one disk and 
  245. the last three archives onto other disks to suit yourself. The disk on which 
  246. the main ACE files reside is the volume to which the shell commands discussed 
  247.  
  248.                                   - page 4 -
  249.  
  250. below refer.
  251.  
  252. You now have all the files you require to use ACE.
  253.  
  254. Next, add the following lines to your user-startup or startup-sequence 
  255. script:
  256.  
  257.     assign ACE: <volume or directory>
  258.     path ACE:bin add
  259.  
  260. where <volume or directory> is the name of the disk or directory where
  261. the main ACE files now reside (eg: assign ACE: sys:ACE).
  262.  
  263. In addition, you need to add three more statements to your startup-sequence
  264. or user-startup script:
  265.  
  266.     assign ACElib:       ACE:lib    ; bas finds scanned libraries here.
  267.     assign ACEbmaps:   ACE:bmaps    ; ace looks here for .bmap files.
  268.     assign ACEinclude: ACE:include    ; app uses this for include files.
  269.  
  270. You may also have to set the "s" bit on ACE:bin/bas if it was lost during
  271. the unarchiving process. Do this with the following command:
  272.  
  273.     protect ACE:bin/bas +s add
  274.  
  275. If you're not sure, do it anyway. This simply lets you run the bas script
  276. without having to use the "execute" command.
  277.  
  278. Now reboot your Amiga to let the above path and assign commands take effect.
  279.  
  280. That's it!
  281.  
  282. ** Note: As an alternative to these startup script modifications, you can 
  283. use the "ACEsetup" script to be found in MAIN.lha. Read the comments at 
  284. the top of that script for usage details.
  285.  
  286.  
  287. Using the compiler
  288. ------------------
  289. Starting with ACE v2.0 there are two ways to use the compiler:
  290.  
  291.     - From the shell/CLI.
  292.  
  293.     - Via an Integrated Development Environment: AIDE.
  294.  
  295. Whichever environment you choose to work with ACE in, read on.
  296.  
  297. ACE expects all BASIC source files to have a ".b" extension.
  298.  
  299. If you have a program called foo.b, you would invoke the compiler thus:
  300.  
  301.     ace foo    (or ace foo.b)
  302.  
  303. This would produce foo.s, an A68K-compatible assembly source (text) file.
  304.  
  305. If you wanted to preprocess, compile, assemble and link foo.b, you'd type:
  306.  
  307.     bas foo
  308.  
  309.  
  310.                                   - page 5 -
  311.  
  312. which would yield foo (the executable).
  313.  
  314. The bas script sets the stack to 40000 bytes. Before running ACE by itself,
  315. you will need to set this. A minimum stack size seems to be around 5000
  316. for many ACE compilations, but I recommend 40000 to be safe.
  317.  
  318. If your Amiga GURUs or hangs during a compile or produces garbage in the 
  319. shell, you can be confident that the stack is too small.
  320.  
  321. You can either create a BASIC source file using an editor or in the AmigaBASIC 
  322. environment. If you want to compile a program developed with the interpreter,
  323. just save the program in ASCII format thus:
  324.  
  325.     save "foo.b",a
  326.  
  327. ACE will only compile ASCII source files, not AmigaBASIC's compressed format.
  328.  
  329. For those who don't have access to the AmigaBASIC interpreter but who wish
  330. to convert old AmigaBASIC programs not saved in ASCII format, see the 
  331. ACE:utils directory for a utility called ab2ascii written by Stefan Reisner.
  332.  
  333.  
  334. Compiler options
  335. ----------------
  336. The full command line syntax for ACE is:
  337.  
  338.     ace [-bcEilOw] <sourcefile>[.b]
  339.  
  340. which indicates that there are currently seven optional compiler switches. 
  341.  
  342. The switches can appear in any combination (eg: -bO, -clb, -O, -ObE) but 
  343. *are* case sensitive (so -b does not equal -B).
  344.  
  345. The "b" switch tells the compiler to include code to check for ctrl-c breaks 
  346. by the user. The inclusion of this code can result in noticeably larger
  347. assembly source files, but execution speed doesn't seem to suffer appreciably.
  348. When a ctrl-c is detected, the program will clean up and exit but user-defined
  349. windows and screens will remain open. The use of ON BREAK can get around this 
  350. by allowing for user-controlled clean up (see the "Event Trapping" section
  351. below).
  352.  
  353. The "c" switch includes each line of ACE source code as a comment in the
  354. final assembly source file. This was requested as a debugging aid. Warning:
  355. the presence of such comments interferes with peephole optimisation. Also be
  356. aware that ACE sometimes includes extra code apart from that which you would 
  357. expect purely on the basis of the source code.
  358.  
  359. The "E" switch creates a file in the current directory called ace.err which
  360. contains all error messages generated during a compliation. Error messages
  361. are still displayed to the screen during compilation however.
  362.  
  363. The "i" switch tells ACE to make an icon for the executable resulting from 
  364. the compilation. The file "ACE:icons/exe.info" must exist as it is used as
  365. the source file for the icon. This allows you to use an icon of your own if
  366. you so wish.
  367.  
  368. The "l" switch causes the compiler to display each line of ACE source code 
  369. as it is being compiled.
  370.  
  371.  
  372.                                   - page 6 -
  373.  
  374. The "O" switch causes the assembly source code produced by ACE to be optimised.
  375. At present, simple peephole optimisation is carried out. Assembly code size
  376. reductions of around 5% to 10% are usual. Speed improvements vary, depending
  377. upon the program, however I recommend the use of the -O switch for all programs
  378. where speed is the least bit important. As time goes by, ACE's optimiser will 
  379. be improved.
  380.  
  381. The "w" switch tells ACE to include checks for window close-gadget clicks.
  382. ACE checks all open windows and upon detecting a close-gadget click, the
  383. clicked window is closed and the program exits. However, any other open
  384. windows or screens will not be closed. The use of ON WINDOW can get around 
  385. this by allowing for a user-defined clean-up subroutine (see the "Event 
  386. Trapping" section below).
  387.  
  388. The syntax for the bas script is:
  389.  
  390.     bas [-bcEilOw] <sourcefile> [<objectfile>]
  391.  
  392. where <sourcefile> is the program to be compiled (without the .b extension)
  393. and <objectfile> is a C or assembly module which has been (compiled and) 
  394. assembled to produce an object file.
  395.  
  396. The <objectfile> is linked with the output of ACE+A68K along with db.lib, 
  397. startup.lib and ami.lib. This is necessary when an external function or 
  398. variable in <objectfile> is referenced by an ACE program. For more about 
  399. external functions, see the section "External references" below.
  400.  
  401.  
  402. Running ACE programs
  403. --------------------
  404. ACE programs can be run from either a shell/CLI or Workbench. In the latter
  405. case a tool icon must be created for the executable. One has been provided
  406. with the archive in the icons directory (exe.info). Refer to the "i" switch 
  407. in "Compiler options" above re: automatic icon creation by the compiler.
  408.  
  409. As far as I can tell, ACE programs are pure and so can be made resident once 
  410. the pure bit is set with the protect command. I've had no problems so far.
  411.  
  412.  
  413. About the example programs
  414. --------------------------
  415. I have written a number of programs which illustrate most of the features
  416. of ACE up to this point and you should find these with the distribution.
  417.  
  418. Several programs are related to chaos theory and fractals - a pet interest 
  419. of mine (and of thousands of other programmers :). The remainder are an 
  420. assorted bunch which demonstrate ACE's capabilities.
  421.  
  422. The information for the chaos/fractal programs came from a wide variety of 
  423. sources. The algorithms for henon.b and lorenz.b came from "Dynamical systems 
  424. and fractals: computer graphics experiments in Pascal" by Becker & Dorfler, 
  425. 1990.
  426.  
  427. Some programs are optimised at the source level and some are not. You'll 
  428. find that using integer variables can often result in quite dramatic 
  429. improvements in program execution speed (eg: try replacing op% with op and 
  430. k% with k in ifs.b and you'll see what I mean).
  431.  
  432. There are several examples which demonstrate the use of recursive 
  433.  
  434.                                   - page 7 -
  435.  
  436. subprograms in ACE (eg: fact.b).
  437.  
  438. Another area of interest for me is neural networks and you'll find a 
  439. program called hopnet.b, which shows graphically how a simple Hopfield 
  440. network changes under various conditions.
  441.  
  442. Other programs include a talking clock (tclock.b), a sound sample player 
  443. (play.b) and a command-line calculator (bc.b).
  444.  
  445.  
  446. General comments
  447. ----------------
  448. I made a decision very early on in the project to allow standard I/O (for 
  449. shell/CLI). All other windows are (as of ACE v2.0) Intuition windows.
  450.  
  451. The execution speed of most programs (especially with graphics, eg: ifs.b)
  452. is, as you might expect, *fast* compared to interpreted AmigaBASIC.
  453.   
  454. No error messages are given at run-time (but file and serial I/O errors are 
  455. reported by the ERR function), nor is there any stack overflow or array 
  456. bounds checking. 
  457.  
  458. Labels are supported and can be used with GOSUB and GOTO. Line numbers are 
  459. supported, but are only necessary for old BASIC programs. Also, ACE's rich 
  460. assortment of control constructs makes the use of GOTO largely redundant.
  461.  
  462. Available control constructs are: WHILE..WEND, REPEAT..UNTIL, IF..THEN..ELSE,
  463. IF..THEN..ELSE..END IF, CASE..END CASE, ON..GOTO, ON..GOSUB, SUB..END SUB and 
  464. GOSUB..RETURN.
  465.  
  466. Apart from single line comments with REM and ' ACE allows block comments with
  467. { and }. For example:
  468.  
  469.  { comments can span more than 
  470.    one line like this }
  471.  
  472. Multi-statements are also supported by ACE, eg:
  473.  
  474.  x$="hello":y$="there":say translate$(x$+" "+y$)
  475.  
  476.  
  477. The preprocessor and #include files
  478. ------------------------------------
  479. The ACE preprocessor: APP, is modest when compared to the C preprocessor.
  480.  
  481. Its main function thus far is for the inclusion of files with the #include 
  482. directive. As in C, #include "filename" looks for the file as specified, 
  483. while #include <filename> looks for the file in a local include directory 
  484. (see "Installation"). A file will only ever be included once.
  485.  
  486. The #include directive can also be used in included files, but since file 
  487. inclusion is recursive, watch your stack size (40000 bytes is plenty).
  488.  
  489. APP also handles single-line comments (text following a "'") and block
  490. comments (starting with "{" and ending with "}"). This is partly to allow
  491. #include commands to be commented out and also to make less work for the 
  492. compiler. However, the compiler does still handle comments in case the pre-
  493. processor isn't invoked. APP does not handle REM since this is a BASIC 
  494. statement.
  495.  
  496.                                   - page 8 -
  497.  
  498.  
  499. The syntax for APP is: 
  500.  
  501.     app <source> <dest> 
  502.  
  503. The bas script uses APP by first preprocessing an ACE source file to the
  504. RAM:T directory.
  505.  
  506. Use of #include has the effect of adding lines to the preprocessed ACE 
  507. source, which has an impact upon the physical location of lines from the
  508. main ACE file when transfered to the destination file.
  509.  
  510. ACE include files have two purposes. As in C they can be used to include
  511. constants and structure definitions. Second, as with files like WBarg.h,
  512. ACE include files may contain subprogram definitions and although this is 
  513. quite possible in C, it seems to be less often done under the guise of .h 
  514. files. I have arbitrarily chosen to append all include files with .h but 
  515. there is no reason why this need be so. Purists will probably be aghast.
  516.  
  517. APP will be improved as time goes by. 
  518.   
  519.  
  520. Data types, expressions and constants
  521. ------------------------------------- 
  522. The following fundamental data types are currently supported:
  523.  
  524.     - signed short integers (2 bytes = 16 bits)
  525.     - signed long integers  (4 bytes = 32 bits)
  526.     - single-precision: Motorola fast floating point (4 bytes = 32 bits)
  527.     - strings (default to 1024 bytes including ASCII 0 end-of-string) 
  528.  
  529. Exponential and fixed-point formats are recognised by all ACE functions
  530. and in program text for single-precision numbers.
  531.  
  532. Expression parsing is the same as for AmigaBASIC, as is the precedence of 
  533. operators. Evaluation of _all_ expressions proceeds from left to right.
  534. This includes exponentiation, so 2^3^2 will be evaluated as (2^3)^2.
  535.  
  536. In addition, due to the higher precedence of exponentiation over unary 
  537. negation and the way ACE's recursive descent parser works, 4^(-2) is okay, 
  538. but 4^-2 isn't.
  539.  
  540. ACE supports full 32-bit and single-precision floating point math:
  541.  
  542.     addition, subtraction, multiplication:
  543.         
  544.         - 16-bit integer
  545.         - 32-bit integer
  546.         - single-precision 
  547.  
  548.     division & modulo arithmetic:
  549.  
  550.         - 32-bit integer
  551.         - single-precision
  552.  
  553. Increment and decrement operators are provided in ACE in the following form:
  554.  
  555.     ++<variable> OR --<variable>
  556.  
  557.  
  558.                                   - page 9 -
  559.  
  560. The value of the simple or external variable is incremented or decremented 
  561. by 1.
  562.  
  563. Notice that ++ and -- are pre-increment & pre-decrement operators ONLY. Those 
  564. familiar with C will recognise these operators and their utility. In terms of 
  565. efficiency: ++x is better than x=x+1.  
  566.                     
  567. Unlike interpreted AmigaBASIC, hexadecimal and octal constants can be either 
  568. short or long values. This makes for nicer addressing with PEEK & POKE.
  569.  
  570. Trailing characters (%&!#) after constants cause coercion from one numeric
  571. data type to another, as in AmigaBASIC, eg:
  572.     
  573.     Delay(50&)   '..50 is coerced from short to long integer
  574.     x=12.5*65!   '..65 is coerced from short integer to single-precision
  575.  
  576. As in AmigaBASIC expression evaluation, all operands in an expression are 
  577. converted to the data type of the most precise operand. Logical operators 
  578. (AND,EQV,IMP,NOT,OR,XOR) convert their operands to integer values as does 
  579. the integer division operator "\". Relational operators (= <> > < >= <=) 
  580. yield long integer results.  
  581.   
  582. ACE's boolean values are as follows: 0=false, N=true where N is any 
  583. non-zero long integer. Note that relational operations give -1 for true 
  584. (since: NOT -1 = 0).
  585.  
  586. ACE allows you to define named global signed numeric constants with the 
  587. CONST directive (see command and function reference).
  588.  
  589. Strings have a default length of 1K instead of the usual 32K, since ACE 
  590. programs reserve memory for each string immediately at run-time which could
  591. result in quite memory hungry executables if strings were too large. It is 
  592. possible however, to define strings which are longer or shorter than 1K (see 
  593. STRING command).
  594.  
  595. ACE strings are NULL terminated, ie: the last character is an ASCII 0, as 
  596. in the C programming language.
  597.  
  598. A string literal without a final '"' will be truncated at the end of the 
  599. line.
  600.  
  601.  
  602. Precedence of operators
  603. -----------------------
  604. ACE follows AmigaBASIC in operator precedence, with the addition of structure 
  605. dereferencing and indirection operators.
  606.  
  607.                             operators
  608.                             ---------
  609.  
  610.     1.  Structure Member Dereferencing,        ->
  611.         Parentheses and Address Operator        () @
  612.     2.  Indirection Operators            *% *& *!    
  613.     3.  Exponentiation                ^
  614.     4.  Unary Negation                -
  615.     5.  Multiplication and Floating-Point Division    * /
  616.     6.  Integer Division                \
  617.     7.  Modulo Arithmetic                MOD
  618.     8.  Addition and Subtraction            + -
  619.  
  620.                                   - page 10 -
  621.  
  622.     9.  Relational Operators            = < > <= >= <>
  623.     10. NOT
  624.     11. AND
  625.     12. OR and XOR
  626.     13. EQV
  627.     14. IMP
  628.  
  629. The use of parentheses in an expression forces the enclosed term to be 
  630. evaluated before adjacent terms. Expression evaluation always proceeds 
  631. from left to right in ACE and AmigaBASIC.
  632.  
  633.   
  634. Identifiers
  635. -----------
  636. As in AmigaBASIC an identifier can consist of a combination of letters, 
  637. numbers and periods (".") up to a maximum length of 40 characters. 
  638.  
  639. In ACE the underline ("_") character is also legal. An ACE identifier must 
  640. start with either a letter or an underline character.
  641.  
  642. An identifier can be used to represent the following:
  643.  
  644.         - labels
  645.         - arrays
  646.         - variables
  647.         - structures
  648.         - parameters
  649.         - subprograms
  650.         - defined functions
  651.         - named constants
  652.         - shared library functions
  653.         - external functions or variables
  654.  
  655. Labels are global in ACE, so a main program label and a SUB label cannot 
  656. have the same name.
  657.  
  658. Identifiers can have a qualifier character (%&$!#) appended in order to 
  659. indicate data type, where:
  660.  
  661.         % = short integer
  662.         & = long integer
  663.         ! = single-precision
  664.         # = double-precision -> not supported yet
  665.         $ = string    
  666.  
  667. Examples of valid identifiers are:
  668.  
  669.         x3
  670.         num&
  671.         _putchar
  672.         play.sound
  673.  
  674. An identifer with no qualifier has a default type of single-precision. The 
  675. DEFxxx compiler directives (see command and function reference) have the
  676. same effect as the qualifier characters except they affect all identifiers
  677. starting with a certain letter. Qualifier characters have higher precedence 
  678. than DEFxxx directives. 
  679.  
  680. For shared library functions and external references, a qualifier is used 
  681.  
  682.                                   - page 11 -
  683.  
  684. merely to declare data type. So for example, an external function might be 
  685. declared thus:
  686.  
  687.         external function RangeRand%
  688.  
  689. but can later be referred to as RangeRand.
  690.  
  691. The declaration of external functions/variables and shared library functions
  692. is global no matter where the declaration occurs.
  693.  
  694. Defined constants are unaffected by qualifier characters. The _value_ of a 
  695. defined constant determines its type. Thus CONST x&=1.2 is a single-precision
  696. - NOT a long integer - constant. Needless to say therefore, it is unwise to
  697. use qualifier characters for named constants.
  698.  
  699. The declaration of constants (with CONST) is always global whether the
  700. declaration takes place in the main program or a subprogram.
  701.  
  702. Structure variables hold a long integer value (address), so trailing 
  703. characters have no effect.
  704.  
  705. Structure type definitions are global, but structure variable declarations
  706. are local.
  707.  
  708. ACE allows for *optional* variable declarations with the SHORTINT, LONGINT,
  709. ADDRESS, SINGLE and STRING directives. Such declarations are useful in that:
  710.     
  711.         (i)    They ensure that a variable has a NULL or zero 
  712.             value.
  713.  
  714.         (ii)    They prevent dangerous errors which result from 
  715.             the misspelling of variable names.
  716.  
  717.         (iii)    Most languages have them and they serve to 
  718.             document variable usage explicitly.
  719.  
  720.         (iv)    They provide a "cleaner" way of establishing a 
  721.             variable which is to be shared by a subprogram.
  722.  
  723. My feeling on the matter of variable declarations is that in a small program 
  724. they probably aren't necessary so long as you are careful, but in a large 
  725. program all major variables should be declared for safety.
  726.   
  727. Variable declarations override the DEFxxx compiler directives and qualifier
  728. characters and are local to the current level (main program or subprogram).
  729.  
  730. Summary of identifier properties:
  731.  
  732. +---------------+---------------+------------------+
  733. | Identifier    | Local/Global  | Affected by %&!$ |
  734. +---------------+---------------+------------------+
  735. | ARRAY        | LOCAL        | YES            |
  736. | SIMPLE VAR    | LOCAL        | YES           |
  737. | STRUCTURE VAR | LOCAL        | NO           |            
  738. | PARAMETER    | LOCAL        | YES           |
  739. | STRUCTURE DEF | GLOBAL    | NO           |        
  740. | LABEL        | GLOBAL    | NO           |
  741. | NAMED CONST   | GLOBAL    | NO           |
  742. | SUBPROGRAM     | GLOBAL    | YES           |
  743.  
  744.                                   - page 12 -
  745.  
  746. | DEF FN     | GLOBAL    | YES           |
  747. | LIBRARY FUNC  | GLOBAL    | YES (declaration)|
  748. | EXT VAR/FUNC    | GLOBAL    | YES (declaration)|
  749. +---------------+---------------+------------------+
  750.  
  751.    
  752. Indirection operators
  753. ---------------------
  754. ACE has four indirection operators: @,*%,*&, and *!. These are _similar_
  755. to pointers in C.
  756.  
  757.     @<object>   - returns the absolute address of a data object.
  758.             - note that this is identical to VARPTR(<object>).
  759.     *%<address> - peeks or pokes a short value at the specified address.
  760.     *&<address> - peeks or pokes a long value at the specified address.
  761.     *!<address> - peeks or pokes a single value at the specified address.
  762.  
  763. The indirection operators can therefore be used in a statement (poke) and/or 
  764. as part of an expression (peek), for example:
  765.  
  766.     address x
  767.     y=23.25
  768.     x=@y
  769.     *!x := *!x + 2
  770.     print y
  771.  
  772. will print a value of 25.25.
  773.  
  774. There are two things to notice here. First, the pointers are to addresses, 
  775. not necessarily connected to variables. It would be quite legal to allocate
  776. an area of memory and then dereference it with these operators.
  777.  
  778. Second, when assigning a value to a dereferenced memory location as in the 
  779. above example, the ":=" symbol must be used, simply because of the way the 
  780. parser processes statements. Pascal programmers will recognise this as 
  781. the assignment operator. 
  782.  
  783. See also the section below for information about how to use these operators
  784. to implement variable parameters (call-by-reference) for simple variables in 
  785. ACE subprograms.
  786.  
  787.  
  788. Files
  789. -----
  790. AmigaBASIC sequential files are supported and random files are on the list 
  791. of things to do.
  792.  
  793. The commands and functions for manipulating sequential files in ACE are:
  794.  
  795. commands:
  796.     - OPEN
  797.     - CLOSE
  798.     - PRINT#
  799.     - WRITE#
  800.     - INPUT#
  801.     - LINE INPUT#
  802.  
  803. functions:
  804.     - INPUT$ 
  805.  
  806.                                   - page 13 -
  807.  
  808.     - EOF
  809.     - LOF
  810.     - HANDLE *
  811.  
  812.     * not found in AmigaBASIC
  813.  
  814. Note that for any command which is immediately followed by a # there should 
  815. be at least one space between the keyword and the #, even though I may refer 
  816. to such commands as <name># in the text of this document and in ref.doc.
  817.  
  818. See the command and function reference for details of each of these.
  819.  
  820. When WRITE# is used, the result is identical to AmigaBASIC. For example:
  821.  
  822.     X=12 : Y=-3.2 : Z$="fun eh?"
  823.     OPEN "O",#1,"stuff"
  824.       WRITE #1,X,Y,Z$
  825.     CLOSE #1
  826.  
  827. results in a one-line file of the following format:
  828.  
  829.     12,-3.2,"fun eh?"
  830.  
  831. On the other hand, if the following is used instead: 
  832.  
  833.     PRINT #1,X,Y,Z$ 
  834.  
  835. the file format will be:
  836.  
  837.      12         -3.2        fun eh?
  838.  
  839. while if semicolons are used:
  840.  
  841.     PRINT #1,X;Y;Z$
  842.  
  843. the file format becomes:
  844.  
  845.      12 -3.2 fun eh?
  846.  
  847. INPUT# (eg: INPUT #1,X,Y,Z$) can be used to read values from a file in any 
  848. of the above formats, but bear in mind that strings that are not delimited
  849. by quotes, but contain spaces or tabs will be seen as more than one string 
  850. by INPUT#. So, in the example formats above, while 
  851.  
  852.     "fun eh?" 
  853.  
  854. is one string,
  855.  
  856.     fun eh?
  857.  
  858. is two strings as far as INPUT# is concerned.
  859.  
  860. The formats of sequential files in ACE and AmigaBASIC are now very nearly
  861. identical, the only differences being in ACE tabs (produced by comma 
  862. delimiters in PRINT -- see PRINT in ref.doc) and the number of decimal 
  863. places written for single-precision values (usually more in ACE).
  864.   
  865. If you find ACE file I/O too slow, you may want to use the dos.library 
  866. functions (eg: xRead, xWrite). For this reason, I have included the HANDLE 
  867.  
  868.                                   - page 14 -
  869.  
  870. function which returns the AmigaDOS handle of a file opened with ACE's OPEN 
  871. command. You may also wish to use the ami.lib buffered file I/O functions 
  872. which also require this handle. If HANDLE returns 0, the file doesn't exist.
  873.  
  874. See prgs/IO/print.b for an example of opening a sequential file to a printer. 
  875.  
  876. Although SER: may be opened as a sequential file, it is not possible to 
  877. specify parameters for the serial port (baud rate etc) by this method as 
  878. is possible in AmigaBASIC.
  879.  
  880. Instead, ACE provides a set of special serial I/O commands. See ref.doc for 
  881. details of SERIAL OPEN/CLOSE etc, and prgs/IO/aterm.b for a simple terminal 
  882. program.
  883.  
  884.  
  885. Command line and Workbench arguments
  886. ------------------------------------
  887. When called from a Shell or CLI, an ACE program may have arguments, eg:
  888.  
  889.     tree 30
  890.  
  891. Arguments can be accessed by two ACE functions:
  892.  
  893.     ARGCOUNT and ARG$(n)
  894.  
  895. The former returns a short integer value indicating the number of arguments
  896. for the current program, while the latter returns the nth argument as a string
  897. where n ranges from 0 to argcount. The zeroth argument (ie: ARG$(0)) is the 
  898. name of the program.
  899.  
  900. Workbench arguments are currently supported by ACE in the form of four 
  901. functions in the include file WBarg.h: WBargcount, WBarg$(n), WBargPath$(n) 
  902. and WBargLock&(n).
  903.  
  904. The first three are the most useful. The fourth is mainly for use by 
  905. WBargPath$. 
  906.  
  907. WBargcount returns the number of arguments passed to a program as icons.
  908. As with ARG$(0), the zeroth Workbench argument is the name of the program.
  909.  
  910. To pass arguments to a program via Workbench one of the shift keys is held 
  911. down while the icons which represent the arguments to be passed are activated.
  912. While still depressing the shift key, the application icon is double clicked. 
  913.  
  914. An alternative method of passing arguments is to change the default tool of a 
  915. project icon (eg: document) with the Info option from Workbench.
  916.  
  917. When this project icon is double clicked, the default tool will be loaded.
  918. In this case, if the source code of the default tool (the program) had a line 
  919. such as:
  920.  
  921.     x$ = WBarg$(1)
  922.  
  923. x$ would contain the name of the project file.
  924.  
  925. WBargPath$(n) is used to find the full path of the file name and includes 
  926. trailing ":" and "/" characters.
  927.  
  928. See the include file WBarg.h for further descriptions of each function.
  929.  
  930.                                   - page 15 -
  931.  
  932.  
  933.       
  934. Subprograms
  935. -----------
  936. Subprograms are supported by ACE, but differ from AmigaBASIC subprograms in
  937. a number of ways. Namely, ACE subprograms:
  938.  
  939.     - Are non-static,
  940.  
  941.     - Allow recursion,
  942.  
  943.        - Can be assigned return values.
  944.  
  945. By way of explanation, being non-static means that once a subprogram has 
  946. finished execution, its local variables and parameters cease to exist so 
  947. far as the rest of the program is concerned.
  948.  
  949. Recursive subprograms are an important feature of modern general programming 
  950. languages. For several examples of the use of recursion, see the included 
  951. programs (eg: fact.b, hanoi.b, tree.b).
  952.  
  953. A word of warning about recursion: it can be stack hungry, so it's a good 
  954. idea to set your stack to 20000 or so, just to be safe, although in most 
  955. cases, this will be a lot more than you need. From Workbench, simply change 
  956. the tool's stack size with Info, or with the STACK command in a shell.
  957.  
  958. As with AmigaBASIC, ACE subprogram declarations cannot be nested.
  959.  
  960. The syntax of a subprogram call is the same as in AmigaBASIC:
  961.  
  962.     [CALL] sub-name[(parameter-list)]
  963.  
  964. The only difference is that the parentheses around the parameter list are
  965. not optional when CALL is omitted -- unless there are NO parameters. 
  966.  
  967. CALL *must* be used after THEN in a single-line IF..THEN statement.
  968.  
  969. By default, every subprogram has a return type of single-precision (just like 
  970. variables). The DEFxxx directives can be used to change the default data type 
  971. of subprograms, as can the trailing characters !#$&%. A subprogram name can
  972. also be preceded by SHORTINT,LONGINT,ADDRESS,SINGLE or STRING as yet another
  973. alternative to setting the subprogram's return type.
  974.  
  975. The fact that ACE subprograms can be easily used as functions pretty much 
  976. obviates the need for DEF FN. However for reasons of compatibility with 
  977. AmigaBASIC and other BASICs, as well as its utility for simple functions, 
  978. ACE supports DEF FN (as of v2.0). 
  979.  
  980. A subprogram is given a value either inside the body of the relevant 
  981. subprogram or in the main program (eg: to zero it) - ala Pascal - thus:
  982.  
  983.     sub-name = <expression>
  984.  
  985. However, subprograms cannot be assigned a value in any other way (eg: with
  986. INPUT or READ).
  987.  
  988. A subprogram can be used in an expression, whereupon the subprogram is called
  989. and its value pushed onto the stack for inclusion in the final result of the
  990. expression, eg:
  991.  
  992.                                   - page 16 -
  993.  
  994.  
  995.     x=n*pow(n)
  996.  
  997. where "pow" is a subprogram with one parameter.
  998.  
  999. While subprogram declarations can appear anywhere within the program text,
  1000. ACE requires that declarations precede calls. So:
  1001.  
  1002.     sub test
  1003.       print "hello"
  1004.      end sub
  1005.  
  1006.     test
  1007.  
  1008. is legal, but:
  1009.  
  1010.     test
  1011.  
  1012.     sub test
  1013.       print "hello"
  1014.      end sub
  1015.  
  1016. is not, and will yield an "undeclared subprogram" error. To get around this, 
  1017. a forward declaration can be used:
  1018.  
  1019.     declare sub test
  1020.     
  1021.     test
  1022.  
  1023.     sub test
  1024.       print "hello"
  1025.     end sub
  1026.  
  1027. Forward declarations can include a parameter list. If you later declare
  1028. the actual SUB with a different parameter list and you've already called 
  1029. the subprogram after a forward declaration, the results will be unpredictable.
  1030. I may place tighter controls on this at some stage.
  1031.  
  1032. Actual parameters are checked for number and type against formals, and 
  1033. parameter count mismatches result in a compilation error. An actual parameter
  1034. is coerced to the formal parameter's type.
  1035.  
  1036. ACE's parameter passing mechanism for subprograms is NOT the same as that
  1037. used for assembly code routines or external functions. In other words, the 
  1038. standard C parameter passing mechanism is not used for SUBs. This may be 
  1039. changed in the future as it makes object modules written in ACE incompatible 
  1040. with C or assembler object modules in this respect.
  1041.   
  1042. Changes made to a formal parameter have no effect upon the actual parameter 
  1043. in a simple call to an ACE subprogram, but see "Limitations" re: overwriting 
  1044. of strings/arrays during recursive calls; see also "Structures" below. 
  1045.  
  1046. The formal parameter list consists of identifiers separated by commas. Each 
  1047. identifier may also be preceded by: SHORTINT,LONGINT,ADDRESS,SINGLE or STRING 
  1048. to avoid the use of a qualifier (%&!$).
  1049.  
  1050. Actual parameters can basically be any type of expression. A whole array 
  1051. cannot be passed as a value parameter in ACE however.
  1052.  
  1053.  
  1054.                                   - page 17 -
  1055.  
  1056. There is an arbitrary upper limit of 40 parameters per subprogram at the
  1057. moment, which may be removed at some stage.
  1058.  
  1059. Main program variables and arrays can be accessed and modified within 
  1060. subprograms via the SHARED directive. All shared variables are passed by 
  1061. reference to a subprogram.
  1062.  
  1063. Multiple SHARED statements are allowed within a single subprogram.
  1064.  
  1065. DIM SHARED is not allowed. An array is declared to be shared in exactly the 
  1066. same way as simple variables, for example:
  1067.  
  1068.     DIM x(10)
  1069.  
  1070.     sub thing
  1071.         shared x
  1072.         .
  1073.         .
  1074.         end sub
  1075.  
  1076. Note that parentheses are not required after an array in the shared statement, 
  1077. nor are they legal in ACE.
  1078.  
  1079. The differences between variable parameters and shared variables in ACE 
  1080. are that:
  1081.  
  1082.     - Shared variables only allow access to main program
  1083.       variables from a subprogram, and do not provide a
  1084.       mechanism for changing the value of variables in 
  1085.           one subprogram from another.  
  1086.  
  1087.         - The name of a variable to be shared must correspond
  1088.       to the name of an existing (ie: already referenced/declared) 
  1089.           main program variable.
  1090.  
  1091. Although variable parameters are not explictly provided by ACE there are 
  1092. two ways to implement them: using indirection operators for simple variables 
  1093. and the ADDRESS option of DIM and STRING (see also "Structures" section).
  1094.  
  1095. Here's an example of call-by-reference parameters for simple variables
  1096. (DEFxxx directives are used here for clarity):
  1097.  
  1098.     deflng x  '..x is an address holder
  1099.     defsng n  '..n is a single-precision variable
  1100.  
  1101.     sub doub(x)
  1102.        *!x := *!x * 2  '...n=n*2 [note the ":=" symbol!]
  1103.     end sub
  1104.  
  1105.     n=22.5
  1106.     print n
  1107.     doub(@n)  '..pass the address of n
  1108.     print n
  1109.  
  1110. which passes the single-precision variable n by reference to the subprogram 
  1111. doub, where n is doubled. This will first print 22.5 and then 45.
  1112.  
  1113. For an array, the following could be done:
  1114.  
  1115.  
  1116.                                   - page 18 -
  1117.  
  1118.     deflng    x  '..x is an address holder
  1119.  
  1120.     sub test(x)
  1121.     dim a(10) address x  '..points to n
  1122.       a(3)=a(3)+12
  1123.     end sub
  1124.  
  1125.     dim n(10)
  1126.     n(3)=2
  1127.     print n(3)
  1128.     test(@n)
  1129.     print n(3)
  1130.  
  1131. which would print first 2 and then 14.
  1132.  
  1133. The same mechanism can be used to pass a string variable by reference.
  1134.  
  1135. These variable parameter mechanisms are most useful when used to pass data 
  1136. *between* subprograms, otherwise it is simpler to use SHARED variables.
  1137.    
  1138. The following table shows the possibilities regarding parameters and shared 
  1139. variables in ACE:
  1140.  
  1141. +---------------------+---------+-------------+------------------------------+
  1142. | Data Type / Object  |    Shared     | Value param |    Variable param                  |
  1143. +---------------------+---------+-------------+------------------------------+
  1144. | SHORTINT VARIABLE   |    YES        | YES          |    YES - *%addr                 |
  1145. |              |             |          |                     |
  1146. | LONGINT/ADDRESS VAR |    YES     | YES          |    YES - *&addr                 |
  1147. |              |            |          |                         |
  1148. | SINGLE VARIABLE     |    YES     | YES          |    YES - *!addr                 |
  1149. |              |            |          |                         |
  1150. | STRING VARIABLE     |    YES    | YES          |    YES - STRING x ADDRESS addr  |
  1151. |              |        |          |                         |
  1152. | EXTERNAL VARIABLE   |    NO    | YES          |    YES - *%, *&, *!, STRING ..  |
  1153. |              |        |          |                     |
  1154. | ARRAY              |    YES    | NO          |    YES - DIM x ADDRESS addr     |
  1155. |              |        |          |                         |
  1156. | STRUCTURE          |    YES    | NO          |    YES - See "Structures" below |
  1157. +---------------------+---------+-------------+------------------------------+
  1158.  
  1159. Note: In the above table, "addr" is a long integer address. VARPTR or @ 
  1160. can be used to obtain this. The address is passed to the SUB by value. 
  1161.  
  1162.     
  1163. Structures
  1164. ----------
  1165. Structures have been included in ACE mainly because of their utility in 
  1166. gaining access to operating system functions. 
  1167.  
  1168. Legal structure members are of the following type: BYTE (in structures only),
  1169. SHORTINT, LONGINT, ADDRESS, SINGLE, STRING. The latter can have an optional 
  1170. size specification.
  1171.  
  1172. If an array or structure is required as a structure member, it is necessary
  1173. to use STRING <ident> SIZE <bytes>. The address of the member can then be
  1174. found with @ or VARPTR and assigned to an array or structure variable.
  1175.  
  1176. If you want to have an address (ie: pointer to an object) as a structure
  1177.  
  1178.                                   - page 19 -
  1179.  
  1180. member simply declare it as an item of type ADDRESS (or LONGINT).
  1181.  
  1182. When declaring a structure, the only difference between the following two
  1183. forms:
  1184.  
  1185.         DECLARE STRUCT mystructtype mystruct
  1186.     and
  1187.         DECLARE STRUCT mystructtype *mystruct
  1188.  
  1189. is that for the former, an appropriate data object is created (on a long
  1190. word boundary), but not for the latter.
  1191.  
  1192. In both cases, mystruct contains the start address of a structure of type 
  1193. mystructtype. In the second case, the address is NULL until assigned a value 
  1194. (eg: with ALLOC). In both cases, the address can be reassigned at will, 
  1195. although this should only really be done for structure pointers (the second
  1196. form).
  1197.  
  1198. Since both forms of structure declaration result in an address being stored
  1199. (in mystruct in the example), the dereferencing operator is always "->".
  1200.  
  1201.     examples:
  1202.     --------
  1203.  
  1204.     PRINT mystruct          -  prints the start address of the structure.
  1205.  
  1206.     PRINT mystruct->mins -     prints the value of a member called mins.
  1207.   
  1208. The SIZEOF function can be used to determine the size of a structure type
  1209. if allocating memory for a structure (see linkedlist.b).
  1210.  
  1211. ACE structures are stand-alone data objects, and cannot be elements in an 
  1212. array (although structure addresses can be).
  1213.  
  1214. ACE structures can be SHARED to allow its member's values to be modified, 
  1215. or a structure's address can be passed to a subprogram, eg:
  1216.  
  1217.     struct my
  1218.        longint one
  1219.        longint two
  1220.     end struct
  1221.     
  1222.     sub test(addr&)
  1223.     declare struct my *second
  1224.        second=addr&
  1225.        second->one = second->one * 2
  1226.     end sub
  1227.  
  1228.     '..main
  1229.     declare struct my first
  1230.     first->one=12
  1231.     print first->one
  1232.     test(first)
  1233.     print first->one
  1234.  
  1235. which will print 12 followed by 24.
  1236.  
  1237. The following code allocates enough memory to hold a structure of type "my" 
  1238. gives values to the structure's 2 members, and changes the address held by 
  1239.  
  1240.                                   - page 20 -
  1241.  
  1242. the structure variable "third" to the start of the newly allocated memory 
  1243. area:
  1244.  
  1245.     const PUBLIC=2
  1246.  
  1247.     declare struct my *third
  1248.  
  1249.     sub create(ADDRESS a_struct)
  1250.     declare struct my *temp
  1251.       temp = Alloc(sizeof(my),PUBLIC)
  1252.       temp->one = 16
  1253.       temp->two = 10
  1254.       *&a_struct := temp    '..change structure variable's value
  1255.     end sub
  1256.  
  1257.     '..main
  1258.     create(@third)
  1259.     .
  1260.     .
  1261.  
  1262. Finally, it is not currently possible to use INPUT, (LINE) INPUT# or READ 
  1263. in conjunction with structures.
  1264.  
  1265.     
  1266. Shared library function calls
  1267. -----------------------------
  1268. ACE provides access to shared libraries in the same way as AmigaBASIC does
  1269. with the exception that you MUST declare a function in order to use it. 
  1270.  
  1271. Also, the library in question must either be in LIBS: or in ROM.
  1272.  
  1273. As of version 2.0, ACE and AmigaBASIC are otherwise pretty much the same. 
  1274. The ACE commands also retain their earlier syntax for backward compatibility 
  1275. and convenience.
  1276.  
  1277. The commands are as follows:
  1278.  
  1279. LIBRARY <libname>    
  1280.  
  1281.     - Where <libname> is the name of a shared library with or 
  1282.       without quotes (eg: "graphics", "graphics.library", graphics).
  1283.  
  1284.     - A ".library" or ".bmap" suffix is allowed but optional.
  1285.  
  1286.            - The LIBRARY command opens the shared library and provides
  1287.       a copy of its base address for use internally by function 
  1288.       calls.
  1289.  
  1290.     - If a library can't be opened at run-time, the program 
  1291.       will abort.
  1292.  
  1293.  
  1294. LIBRARY CLOSE [<libname>]
  1295.  
  1296.     - Closes the specified shared library or all open libraries
  1297.       if no library name is given.
  1298.  
  1299.     - Closing a library more than once will cause no harm.
  1300.  
  1301.  
  1302.                                   - page 21 -
  1303.  
  1304.  
  1305. Notes about standard libraries used by ACE:
  1306.  
  1307.     - There are currently six standard libraries which are often opened 
  1308.       by ACE routines during a program run. These are: dos, intuition,
  1309.       graphics, mathffp, mathtrans and translator libraries.
  1310.  
  1311.     - If one of these six is opened by the LIBRARY command it will 
  1312.       be opened at the start of the program *and* closed at the end. 
  1313.       Any other library will be opened and closed at the points in 
  1314.       the program specified by you.
  1315.  
  1316.     - You don't actually have to close any of the six libraries 
  1317.       mentioned above, but it won't hurt.
  1318.  
  1319.     - Moreover, you never have to open or close the dos.library
  1320.       since ACE opens it for EVERY program.
  1321.  
  1322.  
  1323. DECLARE FUNCTION <funcname>[%&!#$][(param-list)] LIBRARY [<libname>]
  1324.         
  1325.     - Where <funcname> is the case sensitive name of a function in a
  1326.       shared library.
  1327.  
  1328.     - <funcname> may have a trailing character (&%#!$) to indicate type,
  1329.       otherwise default data type rules apply for the function's return 
  1330.       value. This character is optional when CALLing the function.
  1331.  
  1332.     - The optional parameter-list is for documentation purposes only
  1333.       and is otherwise ignored.
  1334.  
  1335.     - If <libname> (same as for LIBRARY and LIBRARY CLOSE) is specified, 
  1336.       ACE only looks in the bmap file for that library, otherwise ACE
  1337.       looks for the function in the bmap files for all open libraries 
  1338.       and all the standard libraries known to the compiler. Needless 
  1339.       to say that specifying <libname> results in faster bmap file
  1340.       entry lookups. This option is not given by AmigaBASIC however.
  1341.  
  1342.     - Example: DECLARE FUNCTION SetSoftStyle LIBRARY
  1343.  
  1344.  
  1345. [CALL] <funcname>[(parameter-list)]
  1346.  
  1347.     - Transfers control to the function <funcname>, loading the
  1348.       appropriate registers before doing so, according to the
  1349.       information about that function in the library's bmap file. 
  1350.  
  1351.      - The return value of a function can be accessed by calling
  1352.       a function as part of an expression, eg: addr& = AllocMem(100,2).
  1353.  
  1354. Function declarations are GLOBAL. They are are NOT optional in ACE.
  1355.  
  1356. ** PLEASE NOTE ***
  1357. No type checking of parameters is performed, so expect weirdness if you pass
  1358. values of the wrong type. If the RKM or whatever reference you are using for
  1359. library functions says to use a long integer, then do so. Don't assume that
  1360. a short integer will be coerced to a long integer. It won't. ACE cannot
  1361. get that information from the bmap file in which a function is found and
  1362. parameters are not sign-extended by default.
  1363.  
  1364.                                   - page 22 -
  1365.  
  1366.  
  1367. When passing strings as parameters it is not necessary to add a CHR$(0)
  1368. to the end of a string since ACE strings are already NULL terminated. 
  1369.  
  1370. Either VARPTR or SADD can safely be used to find the address of a string 
  1371. variable or constant. Actually, the use of SADD or VARPTR for strings
  1372. passed to library functions is optional, but it's probably a good idea to 
  1373. use one or the other all the time, for consistency's sake. These comments 
  1374. also apply to calling machine code routines and external functions.
  1375.   
  1376. It is up to YOU to open and close libraries correctly. ACE doesn't keep
  1377. track of this, and will try to jump to a library function so long as 
  1378. it finds a reference to it in a bmap file even if the library hasn't 
  1379. been opened! As mentioned above, it is not necessary to open and close 
  1380. dos.library because _every_ ACE program does this.
  1381.  
  1382. ACE expects the bmap file for a library to be in the directory ACEbmaps:
  1383. (see "Installation"). I have been advised by Commodore Australia that 
  1384. these files may be distributed with ACE but I will wait until I have this 
  1385. in writing before providing them with the archive (I've waited several 
  1386. months already).
  1387.  
  1388. As of version 2.0, I have provided a program (FD2BMAP) which is functionally 
  1389. equivalent to ConvertFD (since this may NOT be freely redistributed) so that 
  1390. bmap files for new libraries can be created. The source code for FD2BMAP is to 
  1391. be found in the ACE:utils/fd2bmap directory and was written in ACE by Harald 
  1392. Schneider, with some modifications by me.
  1393.  
  1394. The 1.3 FD files can be found in the BasicDemos drawer on the Extras disk. 
  1395. The FD files for Release 2.x/3.0 are available from Commodore for about $30 
  1396. (you get six disks of developer goodies: ask for the Native Developers Kit).
  1397.  
  1398. AmigaBASIC cannot handle functions which use address register a5. This is 
  1399. not true for ACE. Neither ACE nor AmigaBASIC allow the use of functions which
  1400. use register a6.
  1401.  
  1402. See library.b for an example of how to use shared library functions in ACE.
  1403.  
  1404.   
  1405. Machine code calls
  1406. ------------------
  1407. ACE supports AmigaBASIC's mechanism for calling machine code routines and
  1408. the passing of parameters to such routines. AmigaBASIC's stack conventions 
  1409. are also followed (ie: C style parameter passing).
  1410.  
  1411. The syntax for calling such a routine is:
  1412.  
  1413.     CALL long-integer-variable-name[(parameter-list)]
  1414.  
  1415. Note that CALL is NOT optional. Also, the variable containing the address 
  1416. of the routine *must* be a long integer in ACE.
  1417.  
  1418. For example, 
  1419.  
  1420.     CALL caps&(length&,addr&)
  1421.  
  1422. will set up the stack like this:
  1423.     
  1424.     8(sp) = addr&
  1425.  
  1426.                                   - page 23 -
  1427.  
  1428.     4(sp) = length&
  1429.     0(sp) = return address
  1430.  
  1431. on entry to the machine code subroutine caps&.
  1432.  
  1433. On exit from a routine, ACE cleans up the stack by POPping all parameters.
  1434.  
  1435. You can use a short integer array, a string or an allocated area of memory
  1436. (with ACE's ALLOC function) to poke the bytes of a machine code routine into. 
  1437. I prefer the latter method.
  1438.  
  1439. Note that because ACE treats ASCII 0 as the end-of-string character, don't 
  1440. use the string-building method, eg:
  1441.  
  1442.     z$=""
  1443.     for i=1 to N
  1444.          read b
  1445.       z$=z$+chr$(b)
  1446.         next
  1447.  
  1448. since if b=0, chr$(b) will be the NULL string. If you want to use a string,
  1449. do the following:
  1450.  
  1451.     z$=""    '..or STRING z$ SIZE 100 (if there are 100 bytes of MC).
  1452.     addr&=sadd(z$)
  1453.     for i&=0 to N-1
  1454.       read b%
  1455.       poke addr&+i&,b%
  1456.     next
  1457.     call addr&
  1458.  
  1459. The latter is okay, so long as you don't allocate other strings with odd 
  1460. sizes. But if you want to be sure that you have an area of memory which 
  1461. is long-word aligned, use ALLOC, eg:
  1462.  
  1463.     addr&=Alloc(100,2)    '..100 bytes of PUBLIC memory
  1464.     for i&=0 to N-1
  1465.       read b%
  1466.       poke addr&+i&,b%
  1467.     next
  1468.     CALL addr&
  1469.  
  1470. The above examples assume the presence of appropriate DATA statements. See 
  1471. the prgs/MC directory for working examples.
  1472.  
  1473. ACE also supports inline assembly code inclusion. See ASSEM..END ASSEM in 
  1474. ref.doc for details.
  1475.  
  1476.  
  1477. External references
  1478. -------------------
  1479. Reference can be made to a variable or function in another file which is
  1480. resolved at link time. You may for instance, have written a function in C
  1481. or assembler. It is possible to pass parameters to, call and obtain return
  1482. values (as with ACE SUBs) from such a function in ACE after declaring an 
  1483. external reference to the function with the EXTERNAL FUNCTION directive 
  1484. (see command and function reference for syntax).
  1485.  
  1486. When passing parameters, standard C parameter passing conventions
  1487.  
  1488.                                   - page 24 -
  1489.  
  1490. are used. Although some C compilers seem to pass all parameters as
  1491. 4 bytes per parameter on the stack, ACE allows 2 (short words) or 4 
  1492. byte parameters. Be aware of this! See prgs/ExternFunc for examples.
  1493.  
  1494. External variables can be assigned values like normal variables, eg:
  1495.  
  1496.         external RangeSeed&
  1497.         RangeSeed=5276&
  1498.     
  1499. All external reference identifiers have an underscore prefixed by ACE but
  1500. this is optional when declaring or using an external reference. C compilers 
  1501. prepend an underscore to external symbols, so ACE does too.
  1502.  
  1503. Note that the names of external references ARE case sensitive.
  1504.  
  1505. Also, the bas script can take as a third argument the name of the object 
  1506. file produced from the original C or assembly source (ie: .o or .lib file) 
  1507. which contains the external function or variable to be linked with your
  1508. ACE program. 
  1509.  
  1510. It's not easy to call ACE SUBs from C or assembler for two reasons:
  1511.  
  1512.     1. ACE SUBs don't currently use C parameter passing conventions.
  1513.     2. ACE produces whole  assembly source programs, not just functions
  1514.        like a C compiler does.
  1515.  
  1516. For now, you'll have to get your hands dirty with the assembly source code 
  1517. produced by ACE if you want to do this. ACE's -c switch may be of some help 
  1518. here.
  1519.  
  1520.         
  1521. Windows
  1522. -------
  1523. You can open up to nine user-defined windows on the Workbench screen. 
  1524. See the command and function reference for the syntax of the WINDOW 
  1525. statement.
  1526.  
  1527. All user-defined windows are now (as of ACE v2.0) Intuition windows with 
  1528. each characteristic being configurable via the "type" parameter as per 
  1529. AmigaBASIC (see ref.doc).
  1530.  
  1531. Windows can be opened on the Workbench screen or a user-defined screen.
  1532.  
  1533. The zeroth window (the shell/CLI, if the program was CLI launched) is now
  1534. the only instance of a DOS console window in ACE.
  1535.  
  1536. The WINDOW function takes a single parameter and returns information about
  1537. the current output window. See ref.doc for details.
  1538.  
  1539. Note that for user-defined windows, close-gadget clicks must be handled by 
  1540. the use of ON WINDOW event trapping or via the "w" compiler option.
  1541.  
  1542.  
  1543. Screens
  1544. -------
  1545. You can open 9 screens at once (memory permitting!).
  1546.  
  1547. By default, when a screen is opened, a BORDERLESS window the same size 
  1548. as the screen is also opened. Subsequent graphics and text commands send 
  1549.  
  1550.                                   - page 25 -
  1551.  
  1552. their output to the newly created screen's window (until the screen is 
  1553. closed). Note that this facility is not provided by AmigaBASIC.
  1554.  
  1555. In addition, you can open user-defined windows onto any screen, in which
  1556. case all output is directed to the current output window.
  1557.  
  1558. Avoid mixing the use of default and user-defined windows. Except for the
  1559. simple case in which you use nothing but screens and their default windows
  1560. you should consider windows to be the primary output destination for graphics
  1561. and text.
  1562.  
  1563. When a screen is closed, ACE makes the screen with the next highest id 
  1564. the current one, so it is advisable to open and close screens in ascending 
  1565. and descending order.
  1566.  
  1567. A special SCREEN function exists in ACE which returns pointers to various
  1568. Intuition structures (window,screen,rastport,viewport). This is detailed in 
  1569. the command and function reference (ref.doc) as are the following commands: 
  1570. SCREEN, SCREEN CLOSE, PALETTE and PRINTS. The latter is now redundant since
  1571. all commands and functions can - as of v2.0 - be used transparently for 
  1572. screens, user-defined windows and the shell/CLI.
  1573.  
  1574.  
  1575. Gadgets
  1576. -------
  1577. ACE supports the Amiga's three standard gadget types: boolean, proportional 
  1578. (vertical and horizontal), and string (including long integer). 
  1579.  
  1580. Since one of my aims is to support all Amigas running everything from Wb 1.3 
  1581. to Wb 3.0, I have chosen to stick with simple Intuition gadgets for now.
  1582.  
  1583. In a future revision, a run-time test may detect machines running Wb 2.x/3.0 
  1584. and use GadTools gadgets instead. Furthermore, other gadget types may then be 
  1585. supported (radio buttons, check boxes etc).
  1586.  
  1587. Memory permitting, up to 255 gadgets can be created during a single program 
  1588. run.
  1589.  
  1590. The GADGET command creates a gadget with specific features while GADGET CLOSE 
  1591. removes the gadget from the window. Once created, a gadget can be enabled or
  1592. disabled, indeed it can be disabled upon creation if so desired. 
  1593.  
  1594. Having created a gadget or gadgets, you must then decide how to receive and
  1595. handle information from them. ACE provides four methods: standard event
  1596. trapping (ON GADGET), polling (via the GADGET function), WAITing for a
  1597. specific gadget or WAITing for any gadget.
  1598.  
  1599. Where it is possible to make your programs modal (ie: focussed upon a single
  1600. event or event type) you should do so. The GADGET WAIT command allows this. 
  1601. See "Event Trapping" for more about modality in ACE programs.
  1602.  
  1603. The following commands set up a window with two boolean gadgets and a close 
  1604. gadget. The latter is set up by Intuition with the WINDOW command.
  1605.  
  1606. The program traps WINDOW and GADGET events. The comments should help you 
  1607. understand the code.
  1608.  
  1609. CONST having_fun = -1&
  1610.  
  1611.  
  1612.                                   - page 26 -
  1613.  
  1614. WINDOW 1,"Gadgets",(0,0)-(640,200),8
  1615.  
  1616. GADGET 1,1,"Hit Me",(3,3)-(75,20),1,1
  1617. GADGET 2,1,"Quit",(100,150)-(200,175),1,2
  1618.  
  1619. ON GADGET GOSUB gadget_handler
  1620. GADGET ON
  1621.  
  1622. ON WINDOW GOTO quit
  1623. WINDOW ON
  1624.  
  1625. '..main loop (actually does nothing, but is necessary for event trapping)
  1626. WHILE having_fun
  1627.   '..have a nap while nothing's happening 
  1628.   '..(don't hog the machine by busy waiting) 
  1629.   SLEEP        
  1630. WEND
  1631.  
  1632. gadget_handler:
  1633.   '..find out which gadget was selected
  1634.   gad = GADGET(1)
  1635.   LOCATE 12,40:PRINT "<<";gad;">>" 
  1636.   if gad = 2 then quit    
  1637. RETURN
  1638.  
  1639. quit:
  1640.   GADGET CLOSE 2
  1641.   GADGET CLOSE 1
  1642.  
  1643.   WINDOW CLOSE 1
  1644. END
  1645.  
  1646. Alternatively, you could poll for a gadget to the exclusion of other events:
  1647.  
  1648. .
  1649. .
  1650. '..await a gadget selection
  1651. REPEAT
  1652.   WHILE NOT GADGET(0)
  1653.     SLEEP  '..be a little nice to the operating system
  1654.   WEND
  1655.   
  1656.   '..which one?
  1657.   gad = GADGET(1)
  1658.   LOCATE 12,40
  1659.   PRINT "<<";gad;">>" 
  1660. UNTIL gad=2
  1661. .
  1662. .
  1663.  
  1664. Finally, you can wait for a gadget:
  1665.  
  1666. .
  1667. .
  1668. GADGET WAIT 2      '.."GADGET WAIT 0" waits for ANY gadget! BEST method!
  1669. .
  1670. .
  1671.  
  1672. See the program prgs/misc/ACEgadgets.b for an example of gadget programming
  1673.  
  1674.                                   - page 27 -
  1675.  
  1676. in ACE.
  1677.  
  1678. For boolean gadgets you can - if you need to - get information about the 
  1679. width and height of the gadget's text font by calling WINDOW(12) and 
  1680. WINDOW(13). If you need more precise width information, use the graphics 
  1681. library TextLength function.
  1682.  
  1683. ACE string gadgets currently only allocate enough text buffer space for 
  1684. the number of characters which can fit into the gadget (as specified by
  1685. the bounding box in the GADGET command).
  1686.  
  1687. In the next revision, this will be changed to allow a larger buffer such as 
  1688. InputBox[$] permits (see the "Requesters" section) either via an optional 
  1689. buffer-size parameter or a fixed-size buffer. I have not yet decided upon 
  1690. the best course to take on this matter.
  1691.  
  1692. For more details about the GADGET commands and function, see ref.doc.
  1693.  
  1694.  
  1695. Menus
  1696. -----
  1697. ACE supports menus ala AmigaBASIC, with two additions: menu item command
  1698. keys and a MENU WAIT command. The latter puts the program to sleep until a 
  1699. menu event occurs. The former is specified by an optional parameter to the 
  1700. MENU command, for example:
  1701.  
  1702.     MENU 1,5,1,"Quit","Q"
  1703.  
  1704. defines menu item number 5 in menu number 1 to be the 'Quit' option and 
  1705. sets up a command-key sequence (Amiga-Q) for that item. The third parameter
  1706. enables the menu item as per AmigaBASIC.
  1707.  
  1708. Note that although ACE adjusts menu text for font size and type as set
  1709. via preferences, some fonts may require you to pad your menu title/item 
  1710. names with blanks when using command keys to avoid overlaps.
  1711.  
  1712. For an example of menu programming with ACE see prgs/ifs.b. For a better
  1713. example, see the source code for AIDE. Over time I will modify some of 
  1714. the other example programs in the archive so that they are menu-driven.
  1715.  
  1716. See ref.doc for more details about the MENU commands and function.
  1717.  
  1718.  
  1719. Requesters
  1720. ----------
  1721. As of version 2.0, ACE supports 3 standard requesters:
  1722.  
  1723.     - System requester
  1724.     - File requester
  1725.     - Input requesters x 2
  1726.  
  1727. My recent experiences with Visual Basic for Windows have led me to add these
  1728. to ACE since I have now come to expect them. You can get the most commonly 
  1729. needed requesters in a single line of ACE code!
  1730.  
  1731. If you are running Wb 2.x and above, ACE generates an ASL file requester.
  1732.  
  1733. For Wb 1.3 an ARP file requester is invoked for two simple reasons:
  1734.  
  1735.  
  1736.                                   - page 28 -
  1737.  
  1738.     - The arp.library is common on Wb 1.3 systems.
  1739.     - The ARP file requester is still quite good.
  1740.  
  1741. See MSGBOX, FILEBOX, INPUTBOX and INPUTBOX$ in ref.doc for more.
  1742.  
  1743.     
  1744. Turtle Graphics
  1745. ---------------
  1746. You may be wondering one or more of the following:
  1747.  
  1748.     - what the heck is Turtle Graphics?
  1749.     - isn't that for kids?
  1750.     - why did he include THAT?
  1751.  
  1752. To answer the first question: Turtle Graphics (TG) originated as a subset of 
  1753. the language LOGO invented by Seymour Papert et al at MIT. LOGO was originally 
  1754. intended as a language for learning. Children are able to write simple programs
  1755. to draw shapes on the computer's screen or move a Turtle - a dome-shaped robot 
  1756. - on a sheet of paper on the floor, learning about geometry "by doing" and
  1757. having fun to boot. 
  1758.  
  1759. LOGO also has many Lisp-like qualities and so can be used as a serious
  1760. language for AI work, although to my knowledge, it's not.
  1761.  
  1762. But I digress. Apart from the fun kids can have with TG, it's actually 
  1763. possible to construct quite complex shapes with it. Combined with recursion,
  1764. TG is a powerful tool. It is particularly useful in plotting many fractal
  1765. shapes (see snowflake.b, dragon.b).
  1766.  
  1767. Since the first LOGO, there have been many manifestations of TG. Turbo Pascal 
  1768. for the PC and the Mac have both had TG.
  1769.  
  1770. A couple of years ago, I  wrote a pure TG subset of LOGO which used the same 
  1771. syntax as the original language and allowed recursive procedures. I've also
  1772. written TG functions in C. Both of these have been useful to me and I've often
  1773. wished that BASIC came with TG built-in. Well, now one dialect does!
  1774.  
  1775. For some examples of the use of Turtle Graphics in ACE, see the following
  1776. programs:
  1777.  
  1778.     - tree.b
  1779.     - flower.b
  1780.     - boxit.b
  1781.     - torus.b
  1782.     - dragon.b
  1783.     - snowflake.b
  1784.     - bst.b
  1785.  
  1786. The above discussion should have answered the second question. As for 
  1787. the third, the answer is: because I wanted to!! :^)
  1788.  
  1789. Okay, enough philosophy. Here's the ACE stuff:
  1790.  
  1791. BACK n        - move turtle back by n.
  1792. FORWARD n    - move turtle forward by n.
  1793. HEADING     - return turtle's current heading in degrees (0..359).
  1794. HOME        - move turtle back to its home position.
  1795. PENDOWN        - put turtle's pen down. 
  1796. PENUP        - lift turtle's pen up.
  1797.  
  1798.                                   - page 29 -
  1799.  
  1800. SETHEADING degs - change turtle's heading to degs.
  1801. SETXY x,y    - change turtle's current x,y location.
  1802. TURN degs    - rotate turtle by degs.
  1803. TURNLEFT degs    - turn turtle left by degs.
  1804. TURNRIGHT degs  - turn turtle right by degs.
  1805. XCOR        - return turtle's current x-coordinate.
  1806. YCOR        - return turtle's current y-coordinate.
  1807.  
  1808. where:
  1809.     - n is pixels (x:y ratio is 2.25:1 -- assumes hi-res screen).
  1810.     - degs is a signed short integer representing degrees with
  1811.       the turtle starting at a 270 degree orientation -- pointing up).
  1812.     - home is the turtle's x,y start location (0,0).
  1813.  
  1814. Note that the X:Y ratio can be modified thus:
  1815.  
  1816.     EXTERNAL _tg_xy_ratio!
  1817.     _tg_xy_ratio = 1.125    '..1.125 is about right for a lo-res screen
  1818.  
  1819. Most LOGO environments use a coordinate system where 0,0 is at the center of
  1820. the screen and positions to the left and down of this origin are negative 
  1821. while those up and to the right are positive. ACE's TG system however, uses 
  1822. the Amiga's normal graphics coordinate system with 0,0 at the top left of 
  1823. the screen/window so as to maintain consistency with ACE's normal graphics 
  1824. commands and functions (eg: POINT, PSET, LINE, PAINT, CIRCLE, AREAFILL).
  1825.   
  1826. If a negative value is specified for the turnleft or turnright commands,
  1827. the turtle will be rotated in the opposite direction to that indicated by
  1828. the the command name. Note that there is also a TURN command.
  1829.  
  1830. When using ACE's TG system, it's best to think of an imaginary turtle (in LOGO
  1831. it's usually a small triangle on the screen) which rotates and moves according
  1832. to your whim. The turtle can either have its pen lowered or raised - and will
  1833. therefore draw or not - which is useful when you need to move in a relative 
  1834. fashion from one location to another without drawing anything.      
  1835.  
  1836. SetXY is like the graphics library Move() command and may need to be preceded 
  1837. by PENUP unless you want to draw a line.
  1838.  
  1839. To change the colour of the pen, use the COLOR command.
  1840.  
  1841. That's probably enough about Turtle Graphics. Oh, by the way, if you ever
  1842. get the chance to read Papert's "Mindstorms", do so. It's good value.
  1843.  
  1844. While I think of it, Sherry Turkle - that's Papert's wife - wrote a book
  1845. called "The Second Self: Computers and the human spirit", which I recommend 
  1846. if you're at all interested in the psychological/social effects of computing.
  1847.  
  1848.  
  1849. Sound
  1850. -----
  1851. ACE provides you with similar functionality as AmigaBASIC for sound
  1852. generation. It also allows you to do some things that AmigaBASIC doesn't.
  1853.  
  1854. See sound.b for an example of how to use ACE's sound facilities in general.
  1855.  
  1856. How many times have you wished that AmigaBASIC would let you produce
  1857. white noise easily like the good ol' C64 and Vic-20 did?
  1858.  
  1859.  
  1860.                                   - page 30 -
  1861.  
  1862. Well, you'll be pleased to know that ACE allows you to do this. All you 
  1863. have to do is allocate about 4000 or more bytes of Chip RAM (upwards of 
  1864. 4000 bytes yields better quality white noise), poke it with random values, 
  1865. (between -128 and 127) call WAVE and you're set (see sound.b)!
  1866.  
  1867. Moreover, you can actually play sound samples (IFF or otherwise) in the
  1868. same way, using just the two commands WAVE and SOUND. In fact, I've written 
  1869. a program in ACE that plays sound samples, recognising the IFF 8SVX format
  1870. (see play.b). 
  1871.  
  1872. As with AmigaBASIC, a sine waveform is the default, but through the WAVE
  1873. statement you can create any waveform you wish including sawtooth, triangle 
  1874. and square.
  1875.  
  1876. WAVE has the following syntaxes:
  1877.  
  1878.     WAVE voice,SIN
  1879.  
  1880. and
  1881.     
  1882.     WAVE voice,waveform-address,byte-count
  1883.  
  1884. where waveform-address is the start of a block of memory where the waveform
  1885. resides (an area of ALLOC'd CHIP memory) and byte-count is the number of bytes 
  1886. in the waveform table.
  1887.  
  1888. The SOUND statement syntax is as follows:
  1889.  
  1890.     SOUND period,duration[,volume][,voice]
  1891.  
  1892. This is different to AmigaBASIC in a number of ways. First, in ACE you
  1893. specify the sampling period NOT the frequency. This was easier to implement
  1894. and still provides the same functionality, but if you want specific notes, 
  1895. you'll have to do the calculations yourself (see equations below).
  1896.  
  1897. Sampling period is inversely proportional to frequency, so a high sampling
  1898. rate corresponds to a low frequency and vice-versa. ACE allows you to
  1899. specify a sampling period in the range 124..32767.
  1900.  
  1901. The duration is a single-precision value as in AmigaBASIC but can range from 
  1902. 0..999 (instead of 0..77). This range is somewhat arbitrary, but gives plenty
  1903. of scope for large sound samples. This specifies the length of time that a 
  1904. tone should be played for. A duration of 18.2 corresponds to about 1 second. 
  1905.  
  1906. Volume defaults to 64 if not specified and can range from 0..64.
  1907.  
  1908. The voice can be in the range 0..3 - since there are 4 audio channels - 
  1909. with 0 & 3 corresponding to the left speaker and 1 & 2 to the right.
  1910. The default voice is 0.
  1911.  
  1912. At the moment, ACE's SOUND statement isn't very good when used to produce a 
  1913. series of short pulses, although this is somewhat dependent upon the waveform 
  1914. in use. In any case, more work needs to be done in this area to prevent 
  1915. "popping" between SOUND statements when the audio hardware is turned on and 
  1916. off in rapid sequence.
  1917.  
  1918. ACE sound is produced by programming the hardware directly. A future version
  1919. will probably utilise the audio device instead. Indeed, it's fair to expect 
  1920. that SOUND in ACE will change in the future to be more in line with AmigaBASIC 
  1921.  
  1922.                                   - page 31 -
  1923.  
  1924. (see also "Future Versions").
  1925.  
  1926. Finally, here's some useful equations for use in conjunction with ACE's SOUND 
  1927. statement:
  1928.  
  1929.     samples/second to period:
  1930.     ------------------------
  1931.     period = 3579546 / samples-per-second
  1932.     
  1933.     musical note to period:
  1934.     ----------------------
  1935.     period = 3579546 / (length * frequency)
  1936.  
  1937.     where length is the size of the waveform table in bytes 
  1938.     (32 bytes for ACE's sine waveform) and frequency is the
  1939.     note itself (eg: middle C is 523.25 Hz).
  1940.  
  1941.     duration value for one waveform cycle:
  1942.     -------------------------------------
  1943.     duration = .279365 * period * length / 1E6 * 18.2
  1944.  
  1945.         
  1946. Event trapping
  1947. --------------
  1948. ACE provides for AmigaBASIC-style event trapping. The following event 
  1949. types are supported:
  1950.  
  1951.     BREAK     -  user break: ctrl-c.
  1952.     MOUSE     -  left mouse button press.
  1953.     TIMER(n)  -  cause a trap every n seconds.
  1954.     ERROR      -  trap file and serial I/O errors.
  1955.     MENU      -  menu selection.
  1956.     WINDOW      -  window event: close-gadget click. 
  1957.     GADGET      -  user-defined gadget selection.
  1958.  
  1959. Event trapping in ACE works by checking for a given event at strategic points
  1960. in a program (before NEXT, WEND, GOTO, CALL, PRINT etc) and if an event is
  1961. detected, control is passed to a trap handling routine. Hence, trapping here
  1962. does not refer to CPU traps (exceptions).
  1963.  
  1964. Even if your program expects to do nothing but trap events, you'll need a
  1965. loop like this:
  1966.  
  1967.     WHILE -1
  1968.       SLEEP     '..don't hog CPU time (intuiticks will be reported though)
  1969.     WEND
  1970.  
  1971. if you wish to have any events handled by your program.
  1972.  
  1973. The specification for the trapping of an event is: 
  1974.  
  1975.     ON <event> GOSUB | GOTO <label>|<line-number> (eg: ON BREAK GOTO quit)
  1976.  
  1977. which indicates the routine to which control is to be passed when an event
  1978. is trapped. This is followed at some stage by:
  1979.  
  1980.     <event> ON  (eg: BREAK ON)  
  1981.  
  1982. which causes the compiled program from that point UNTIL the trap handling 
  1983.  
  1984.                                   - page 32 -
  1985.  
  1986. routine, to contain event trapping code.
  1987.  
  1988. It is a good idea to put trap handlers at the end of a program, since once the
  1989. handler for an event is found by the compiler, no more event trapping code is
  1990. generated for that event even if there is code below the handing routine. In
  1991. other words, the equivalent of an <event> OFF (see below) command is issued 
  1992. once the trap handling code is found by the compiler. 
  1993.  
  1994. Other commands are:
  1995.  
  1996.     <event> STOP
  1997.  
  1998. which disables trapping for the event until another <event> ON is issued, 
  1999. and:
  2000.  
  2001.     <event> OFF
  2002.  
  2003. which disables trapping for the event permanently.
  2004.  
  2005. Just so there is no misunderstanding, the latter two commands prevent the 
  2006. inclusion of event trapping code for a specific event in your program at the 
  2007. assembly source level. They do this from the point in an ACE program at 
  2008. which they are issued.
  2009.  
  2010. Here's a typical example:
  2011.  
  2012.     ON BREAK GOTO quit
  2013.     BREAK ON
  2014.  
  2015.     for i=1 to 1000000
  2016.      print i
  2017.     next
  2018.  
  2019.     quit:
  2020.       PRINT "**break!"
  2021.       STOP
  2022.  
  2023. Please be aware that mixing some event trapping types can have unexpected
  2024. results. More specifically, it is best to trap only one kind of event where
  2025. possible. Also, sitting in a tight loop awaiting a keypress via INKEY$ at
  2026. the same time as trying to trap GADGET events will not work very well.
  2027.  
  2028. During MENU/GADGET event trapping, WINDOW close gadget events are passed 
  2029. onto ACE's WINDOW event trapping mechanism due to the desirability of having 
  2030. both enabled at once. This also holds true for MENU/GADGET WAITing which is
  2031. a far better mechanism to use wherever possible. See "Gadgets" and "Menus"
  2032. section above.
  2033.  
  2034. Where possible, make your program modal (ie: focussed on one event at a time).
  2035.  
  2036. You'll have to experiment to find out what works well together and what 
  2037. doesn't.
  2038.  
  2039. Don't forget though, that you can quite easily have N different kinds of 
  2040. event trapping in one program, and use <event> ON|OFF|STOP to control which 
  2041. events are currently being paid attention to and which are not.
  2042.  
  2043.  
  2044. Error Handling
  2045.  
  2046.                                   - page 33 -
  2047.  
  2048. --------------
  2049. The compiler messages generated by ACE are often different to the ones in the
  2050. AmigaBASIC interpreter (and ACE doesn't beep at you with each error) but they
  2051. are usually fairly clear.
  2052.  
  2053. Syntactically incorrect programs can lead ACE to produce a bunch of spurious 
  2054. error messages. In such cases, it's best to ignore all but the first one or 
  2055. two, unless there are "clusters" of messages which are separated by periods 
  2056. of error-free compilation.
  2057.  
  2058. If you leave out END IF, WEND, UNTIL, NEXT, END SUB, END STRUCT or END CASE, 
  2059. there will be a corresponding number of error messages at the end of the 
  2060. compile. If you leave off two WENDs, you'll get 2 "WHILE without WEND" error
  2061. messages.
  2062.  
  2063. ACE generally reports the first error in a line of code and ignores the rest 
  2064. of the "bad" line. A typical message consists of the line containing the error,
  2065. a carat ("^") marker, and the error message itself. More work still needs to 
  2066. be done on ACE's compile-time error handling, but it's bearable.
  2067.  
  2068. No error messages are issued by ACE programs at run-time. Generally, when a 
  2069. program runs into something it can't do, or an erroneous request - like
  2070. trying to open two files to the same file number or trying to open a library 
  2071. that doesn't exist - the program will either quit or just not have the desired 
  2072. effect. 
  2073.  
  2074. Note that while the ERR function and ON ERROR event trapping are supported,
  2075. only file and serial I/O errors are currently reported via these mechanisms.
  2076.  
  2077.  
  2078. Notes for assembly programmers
  2079. ------------------------------
  2080. I've tried to make the assembly source files that ACE produces as 
  2081. readable as possible by using meaningful data object names. See also
  2082. "Compiler options" re: the compiler's "c" switch.
  2083.  
  2084. Linked library routines use data registers d0-d6 and address registers 
  2085. a0-a3, while d7 is used for array index calculations. Also, a4 and a5 are 
  2086. used as stack frame pointers for variables and parameters.
  2087.  
  2088. Most db.lib routines don't save and restore registers via the stack, but 
  2089. the use of registers is internally consistent (ie: all registers are up for 
  2090. grabs but interdependent routines are written in such a way so as not to 
  2091. conflict).
  2092.  
  2093. The use of linked libraries means that the size of all executables is
  2094. fairly large. But given that disk space and memory are cheap, I'd rather
  2095. this than the alternative of having every executable be dependent upon one
  2096. or more special shared libraries at run-time. However, I will try to reduce
  2097. the size of executables.
  2098.  
  2099. Due to BASIC's tendancy to coerce data types so much for the programmer,
  2100. the resulting code can look a little nasty, and big increases in efficiency 
  2101. can be gained by careful combinations of data types in expressions.
  2102.  
  2103. Writing ACE has so far been a learning experience for me and if when I started,
  2104. I knew what I know now, I would have done many things differently.
  2105.  
  2106. My original rationale for passing parameters via registers to ACE (and shared) 
  2107.  
  2108.                                   - page 34 -
  2109.  
  2110. library functions was to improve execution speed. However, since I call lots 
  2111. of other functions (eg: in ami.lib) which require their parameters to be on 
  2112. the stack, I would probably call ALL functions in this way if I did it again. 
  2113. Oh well.
  2114.  
  2115. Moreover, my desire for internal consistency led me to a rather odd method of 
  2116. passing parameters to SUBs. This allowed me to treat parameters in the same way
  2117. as variables which is all very nice, but it led to other problems, chief among
  2118. them being the need to use a Forbid()/Permit() pair when sending parameters to 
  2119. a SUB. This works fine however, so I'm taking the view that if it 'aint broke,
  2120. I probably shouldn't fix it. 
  2121.  
  2122.  
  2123. Limitations
  2124. -----------
  2125. Variables do NOT get a default zero or NULL value, so don't assume ANYTHING
  2126. about the contents of an uninitialised variable. For example: PRINT X will
  2127. yield garbage if X has not been given a value. The optional variable 
  2128. declarations provided in ACE are therefore worth using since they DO give
  2129. variables an initial zero or NULL value.
  2130.  
  2131. The precision of exponentiation begins to falter with large numbers because
  2132. all exponentiation is currently done with the single-precision math library 
  2133. function SPPow().
  2134.  
  2135. While strings can be defined to be longer (or shorter) than 1K, there
  2136. are some ACE commands and functions which still assume a 1K limit, namely: 
  2137. STRING$, SPACE$, LINE INPUT#, INPUT and SWAP.
  2138.  
  2139. Strings and arrays which are local to a subprogram will be overwritten if
  2140. the SUB has recursive calls to itself. The same applies to string parameters. 
  2141. In all these cases a single static data item is being referenced.
  2142.    
  2143. If you issue RETURN from within a FOR loop, the return address will *not* be 
  2144. the top item on the stack. Instead, FOR..NEXT loop data will be. A GURU will 
  2145. almost certainly result. It is probably better to use a while or repeat loop 
  2146. if you must RETURN from within a loop. See also EXIT FOR in ref.doc which
  2147. allows for the safe, early termination of FOR loops.
  2148.  
  2149. A shared variable cannot be used as a FOR loop index in ACE. Any attempt to
  2150. do so will result in a compilation error.
  2151.  
  2152. IF..THEN NEXT will not have the desired effect (it's bad coding anyway).
  2153. NEXT must always appear on a line by itself or as part of a multi-statement. 
  2154.  
  2155. Expressions and parameter lists cannot currently be split over more than 
  2156. one line.
  2157.  
  2158. The compiler only responds to ctrl-c during the main compilation phase, 
  2159. and not during optimisation or when target code is being written.
  2160.  
  2161. Don't mix the compiler's "b" option with BREAK event trapping, as they will
  2162. conflict.
  2163.  
  2164.  
  2165. Known Bugs
  2166. ---------- 
  2167. The SAY(n) *function* works under release 2.x but not under 1.3. Since the 
  2168. function uses no 2.x-specific code, this is puzzling. The SAY command works 
  2169.  
  2170.                                   - page 35 -
  2171.  
  2172. under both 1.3 and 2.x however.
  2173.  
  2174. A68K sometimes complains about string literal definitions produced by ACE 
  2175. if they are much longer than a single line.
  2176.  
  2177. Some fonts cause the INPUTBOX[$] display (string gadget) to be corrupted. 
  2178. Stick to topaz for this where possible. A future revision will use a 
  2179. GadTools requester (for 2.x machines).
  2180.  
  2181.  
  2182. Future versions
  2183. ---------------
  2184. Random files and double-precision floating-point math are high on the agenda.
  2185.  
  2186. More graphics (eg: GET,PUT) commands and functions are planned and I also 
  2187. intend to fix any remaining differences between ACE and AmigaBASIC in this 
  2188. area. 
  2189.  
  2190. Commands for IFF sound and picture file playing/viewing are likely.
  2191.  
  2192. I may provide support for sprites at some stage. 
  2193.  
  2194. AGA screen modes are likely to be supported sometime.
  2195.  
  2196. Thus far, I've taken the approach of implementing what I most often use 
  2197. and what I have often wished for in BASIC.
  2198.  
  2199. In recent times I have been impressed by three things in the programming 
  2200. world: the rise of Object-Oriented Programming (OOP), Resources (as found
  2201. on the Macintosh and Windows) and Visual BASIC for Windows.
  2202.  
  2203. The idea of resources (pioneered by the Macintosh resource fork and
  2204. ResEdit) is a powerful one and Microsoft and Borland have picked up 
  2205. on this in Windows. I wish the Amiga had them as standard, but alas it 
  2206. doesn't. Still, the emergence of GUI building tools in the Amiga world 
  2207. has gone some way toward making up for this.
  2208.  
  2209. I am trying to add more "visual" stuff to ACE, hence: gadgets, menus,
  2210. requesters, AIDE. You can expect to see more "visualising" of ACE as time
  2211. goes by, including a GUI designer written in ACE for ACE programs. To make 
  2212. ACE like Visual BASIC would take a major rewrite, but I can at least try to 
  2213. take advantage of some of its features and concepts.
  2214.  
  2215. I have no firm plans to include OOP capabilities in ACE, but one never knows. 
  2216.  
  2217. There is some possibility of ACE taking on board some of the list-processing 
  2218. features of certain functional programming languages (eg: Lisp, LOGO).
  2219.  
  2220.  
  2221. A note to PD libraries and reviewers
  2222. ------------------------------------
  2223. I'd appreciate it if you would check with me (if possible) to ensure you
  2224. have the latest version of ACE before including it in your library or
  2225. reviewing it for a magazine. If you don't have e-mail access, I don't
  2226. expect you to do this (snail-mail is a pain isn't it!?).
  2227.  
  2228. Also, to those magazines who have reviewed ACE so far, let me say a big 
  2229. THANK YOU. Good publicity is always appreciated as is acknowledgement of 
  2230. the time I've spent on ACE. I hope I accept criticism with as much grace.
  2231.  
  2232.                                   - page 36 -
  2233.  
  2234.    
  2235. Lastly, the wider ACE travels the happier I am, so I'm pleased to see
  2236. ACE turning up in the odd PD library. Please note however that I don't
  2237. wish people to profit financially from the distribution of ACE. You may
  2238. charge a fee which covers the cost of the disk and the copying thereof,
  2239. but no more.
  2240.  
  2241.  
  2242. Disclaimer
  2243. ----------
  2244. Although every care has been taken in the development and testing of the 
  2245. compiler and its libraries, the author will not be liable for damages caused 
  2246. either directly or indirectly as a result of the use of ACE.
  2247.  
  2248.  
  2249. References
  2250. ----------
  2251. The following references have been used throughout the development of ACE:
  2252.  
  2253. +----------------------------------------------------------------------------+
  2254. | "Amiga BASIC" (manual), 1985, Commodore-Amiga Inc. and Microsoft Inc.      |
  2255. |                                         |
  2256. | "Amiga ROM Kernel Reference Manual: Libraries and Devices", Commodore-Amiga|
  2257. |                                         |
  2258. |  Anderson & Thompson, 1990, "Mapping the Amiga", COMPUTE! Publications Inc.|
  2259. |                                         |
  2260. |  Bleek, Jenrich & Schulz, 1989, "Amiga C for Advanced Programmers", Abacus |
  2261. |                                         |
  2262. |  Bleek, Jenrich & Schulz, 1989, "Advanced System Programmers Guide", Abacus|
  2263. |                                         |
  2264. |  Choi, 1990, "Advanced Programming Techniques", University of Tasmania     |
  2265. |                                         |
  2266. |  Commander, 1987, "Amiga Assembly Language Programming", TAB Books Inc.    |
  2267. |                                         |
  2268. |  Dittrich, 1989, "Amiga Machine Language", Abacus                 |
  2269. |                                         |
  2270. |  Schaun, 1990, "Amiga C for Beginners", Abacus                 |
  2271. +----------------------------------------------------------------------------+
  2272.  
  2273. The most frequently used of these has been "Mapping the Amiga". Despite 
  2274. its not infrequent errors, it remains an excellent resource. I have
  2275. also often referenced the Advanced Amiga C programming book by Bleek et al.
  2276.   
  2277. Although not listed, Commodore's Autodocs for the Amiga (supplied with the
  2278. Native Developer Kit) are also constantly used.
  2279.  
  2280. Young Choi's Advanced Programming notes in many ways provided the impetus
  2281. for the development of ACE. They were used in a compiler construction course
  2282. I took as an undergraduate. I thank Young for introducing me to the joys
  2283. of compiler writing, although I know he didn't intend me to spend *all* my
  2284. time writing compilers. :-)
  2285.  
  2286. Including the Pascal Minus compiler I wrote for that course, and the BASIC 
  2287. interpreter I wrote during the same period, I've since written a version of
  2288. Logo (turtle graphics subset), a Forth interpreter and ACE.
  2289.  
  2290.  
  2291. Final word
  2292. ----------
  2293.  
  2294.                                   - page 37 -
  2295.  
  2296. Let me offer my thanks to Charlie Gibbs for his reliable assembler and to 
  2297. the Software Distillery for Blink. Without these excellent programs, far 
  2298. fewer compilers would have seen the light of day, including ACE.
  2299.  
  2300. Sozobon C (ZC) has always been a reliable workhorse for me, so a vote of
  2301. thanks goes to Sozobon as well. Isn't PD great?
  2302.  
  2303. I'd like to thank those people who have tested ACE so far: Addison Laurent, 
  2304. Byron Montgomerie, Juergen Weinelt, Alan Peyton-Smith, Michael Zielinski,
  2305. Ken Thompson, Peter Zielinski and others.
  2306.  
  2307. These guys have given ACE a good workout on a variety of platforms ranging 
  2308. from an A1000 running Wb 1.3 to 68030 machines running Wb 3.0. They have 
  2309. all pointed out a number of bugs/problems to me which have either been fixed 
  2310. or put on the list of things to fix.
  2311.  
  2312. I'd especially like to thank Michael Zielinski for discovering a particularly 
  2313. serious bug which prevented branches of greater than 32K in length prior
  2314. to v1.02. Also, Enforcer hits reported by him started me on a trail which led 
  2315. to a nasty string-related bug (see entry for 13/4/93 in docs/history).
  2316.  
  2317. Jarto 'Robin' Tarp pointed out how inefficient my first implementation
  2318. of INSTR was. It's considerably faster now (v1.02).
  2319.  
  2320. Let me stress that any remaining bugs in ACE are entirely my fault.
  2321.  
  2322. Many others have given me a great deal of encouragement and made useful 
  2323. comments throughout 1993. I hope this continues.
  2324.  
  2325. I'd also like to thank my wife Karen, for her encouragement and support 
  2326. and for putting up with the number of hours I spend at the computer. IFS
  2327. is her favourite program (see the "Green Fern") so it's dedicated to her.
  2328.  
  2329. Despite ACE's problems (see "Limitations" and "Known Bugs") it is already 
  2330. proving to be a useful tool for me, and if others can derive benefit from it, 
  2331. well, that's great. ACE is gradually coming to support the major features I 
  2332. want it to, but there's still plenty of work to do.
  2333.  
  2334. The provision of calls to shared library functions, external functions, 
  2335. machine code routines, inline assembly code, and include files should 
  2336. go a long way towards making up for ACE's intrinsic shortcomings.
  2337.   
  2338. I hope you enjoy ACE and find it useful. I'm learning a great deal by 
  2339. developing it and having a lot of fun in the process, so I'm not after 
  2340. monetary rewards. Of course, please feel free to donate if you wish!
  2341.  
  2342. What I DO want is feedback. If you have any problems, requests, queries or 
  2343. suggestions, I want to hear from you and I'd like to hear about interesting 
  2344. programs you've written with ACE (send me the source if you like!).
  2345.  
  2346. Obviously I want to know about bugs too. 
  2347.  
  2348. Remember that ACE is FreeWare, so redirect flames to /dev/null (ie: be nice).
  2349.  
  2350. Happy ACEing!
  2351.  
  2352. Regards, David Benn
  2353. 19th January 1994
  2354.  
  2355.  
  2356.                                   - page 38 -
  2357.  
  2358. +-----------------------------------------------+
  2359. |     Internet: dbenn@leven.appcomp.utas.edu.au |
  2360. |                        |
  2361. |   Compuserve: 100033,605                  |
  2362. |                        |
  2363. | Discovery 40: 032432850            |
  2364. |                              |
  2365. |      Phone: (003) 317 680 [home]              |
  2366. |          (003) 243 285 [work]              |
  2367. |                              |
  2368. |    Address: 181 St John Street, Launceston,     |               
  2369. |          Tasmania, Australia, 7250              |
  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.                                   - page 39 -
  2419.