APPLICATIONSPROGRAMMATION ★ Program of the Month — Amstrad Basic Compiler ★

Amstrad Basic CompilerApplications Programmation
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

This Basic compiler enables programs written in Amstrad Basic to be compiled directly into machine code. This invariably results in faster and more compact programs.

Over 50 Basic keywords are supported by the compiler (including those dealing with sound and graphics), but there are some restrictions on the use of variables and expressions.

To use the compiler, type in the listing exactly as shown (except that all REM statements may be omitted if desired) and save it to tape or disk. (If saving to disk on the CPC464, be sure to save it as an ASCII file — otherwise you will not be able to merge it later.) Next, load or type in the program you wish to compile, and test it thoroughly under Basic.

When you are satisfied with the program's performance, you should then save it in case you wish to modify it at a later date. You must now renumber it so that the last line number is less than 1000, and ensure that the last line of the program terminates with an END statement.

Now merge in the compiler itself (if you don't still have it in memory) and run it using RUN 1000; this may take a few minutes if your program is very long, but the compiler will keep you informed of its progress at each stage. If any errors are reported, you should correct the offending line and re-compile from the beginning.

When your program has been successfully compiled, you may save it to tape or disk as a binary file (using the addresses generated at the end of the compilation) or run it immediately by CALLing the start address.

The accepted commands, together with any limitations, are shown below:

  • BORDER As Basic.
  • CALL No parameters allowed — only the address to call.
  • CLEAR No parameters allowed — simply clears all variables to zero. CLG As Basic.
  • CLS As Basic.
  • DRAW/DRAWR As Basic.
  • END As Basic.
  • ENT/ENV As Basic.
  • FOR .. .NEXT As Basic, except that the loop must not be jumped out of, and each NEXT (which must not be followed by a variable) will always refer to the most recent FOR.
  • GOTO/GOSUB As Basic, except that the ON ... GOTO and ON .. .GOSUB structures are not supported.
  • IF ... THEN As Basic but no ELSE statement allowed, and statements such as IF ... THEN (line number) must be written as IF... THEN GOTO (line number).
  • INK As Basic.
  • LET As Basic — that is, optional. LOCATE As Basic.
  • MODE As Basic.
  • MOVE/MOVER As Basic.
  • ORIGIN As Basic — that is, both ORIGIN x,y and ORIGIN x,y,l,r,t,b are supported.
  • PAPER As Basic.
  • PEN As Basic.
  • PLOT/PLOTR As Basic.
  • POKE As Basic.
  • PRINT As Basic, except only one argument allowed (number, variable or quoted string) per PRINT statement. A semi-colon may be appended as in Basic, but not a comma. If the argument is preceded by #n, (where n is a number between 0 and 8), output will be directed to the appropriate screen window (or to the printer if #8 is used).
  • REM As Basic — the remainder of the line is entirely ignored by the compiler.
  • RELEASE As Basic.
  • RETURN As Basic.
  • RUN As Basic, but no line number allowed. To simulate RUN 100, use CLEAR : GOTO 100.
  • SOUND As Basic.
  • TAG/TAGOFF As Basic.
  • WHILE/WEND As Basic, but loop must not be jumped out of.
  • WINDOW As Basic, including WINDOW SWAP.

The following Basic functions are also supported:

  • ABS As Basic.
  • CHR$ As Basic, but only accepted in PRINT statements.
  • INKEY$ Used in the form I = INKEY$ — equivalent to Basic I = ASC(INKEY$). Note that if no key is pressed, INKEY$ returns a value of -1.
  • JOY As Basic.
  • NOT Argument must be enclosed in parentheses.
  • PEEK As Basic.
  • POS/VPOS As Basic.
  • RND No argument permitted. Returns an integer result between -32768 and +32767.
  • SGN As Basic.
  • TEST/TESTR As Basic.
  • XPOS/YPOS As Basic.

Where appropriate, statements may also include #n, (where n is a number between 0 and 7) to specify a particular screen window.

Only simple integer variables are supported, and these should consist of a single letter (A . . Z) or two identical letters (AA . . ZZ). Lower-case letters may be used if desired, but the compiler makes no distinction between these and capitals. Any numbers used must be integers between -32768 and +32767.

All the standard arithmetic and relational operators may be used (with the exception of a), but note that all expressions are evaluated from left to right, with no precedence of operators. This system may take some getting used to — especially if you are familiar with the method used by Basic — and care must be taken in formulating expressions to ensure that you achieve the desired result. For example, the expression A = 2 + 4*3 will yield a result of 14 in Basic, as it is evaluated as 2 + (4 * 3) (because * has a higher priority than + ), but when compiled, the result would be 18, as by evaluating from left to right, the expression becomes A = (2 + 4) * 3.

To obtain the same result in Basic, the expression must be re-written as A = 2 + 4(4*3) or A = 4*3 + 2.

Expressions of this kind will probably be easy to cope with, but it is all too easy to be misled by relational expressions such as IF A > B + 3 which will not be compiled as IF A > (B + 3), which is the case with Basic, but would yield the nonsensical result of IF(A > B) + 3.

As a general rule, expressions of this type should have the right-hand side of the inequality enclosed in parentheses.

Note also that where a minus occurs in an expression, it must be enclosed in brackets if it occurs immediately after another arithmetic or relational operator. Thus the statement PRINT -2*3 will correctly evaluate to -6, but the statement PRINT 3 * -2 should be written as PRINT 3 * (-2).

As an example of the speed improvement which can be obtained when using the compiler, try out the following one-line Basic program:

100 MODE 0 : WHILE b < 400 : WHILE a < 640 : PLOT a,b : a = a+4 : WEND : a =0 : b = b + 2 : WEND : END

This program fills up the screen by plotting every individual point in the current pen colour. When run under Basic, it takes over three minutes to run, while the compiled version takes less than 20 seconds!

Australian Personal Computer

★ PUBLISHER: Australian Personal Computer
★ YEAR: 1986
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LICENCE: LISTING
★ AUTHOR: Stephen Devine

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Amstrad  Basic  Compiler    (Australian  Personal  Computer)    LISTING    ENGLISHDATE: 2018-09-23
DL: 99 fois
TYPE: PDF
SIZE: 1223Ko
NOTE: 7 pages/PDFlib v1.6

Je participe au site:
» Newfile(s) upload/Envoye de fichier(s)
★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » RSX Variablendump (CPC Magazin)
» Applications » Animateur Basic (Amstrad Magazine)
» Applications » Debog
» Applications » Breakpoint (Amstrad Action)
» Applications » Ruptures d'écrans avec R9=7 et R5=0
» Applications » Sprites hautnah (CPC Magazin)

QUE DIT LA LOI FRANÇAISE:

L'alinéa 8 de l'article L122-5 du Code de la propriété intellectuelle explique que « Lorsque l'œuvre a été divulguée, l'auteur ne peut interdire la reproduction d'une œuvre et sa représentation effectuées à des fins de conservation ou destinées à préserver les conditions de sa consultation à des fins de recherche ou détudes privées par des particuliers, dans les locaux de l'établissement et sur des terminaux dédiés par des bibliothèques accessibles au public, par des musées ou par des services d'archives, sous réserve que ceux-ci ne recherchent aucun avantage économique ou commercial ». Pas de problème donc pour nous!

CPCrulez[Content Management System] v8.7-desktop
Page créée en 734 millisecondes et consultée 525 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.