APPLICATIONSDIVERS ★ The procedure to follow is ...|Computing With the Amstrad) ★

RSX Procedures (Computing With the Amstrad)Applications Divers
★ 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 ★ 

Robin Nixon shows how to take a more structured approach to your CPC programming

Having previously been a BBC Micro user 1 was pleasantly surprised on my first encounter with the Amstrad, which has 40k available for Basic programs, a true 16 colour mode and a choice of 27 colours.

The 16 colour mode on the BBC Micro has eight normal and eight flashing colours selectable from eight and only leaves you 10k free for Basic.

Other Amstrad features I was impressed with were the comprehensive jump block, the ease with which you can add resident system extensions (RSXs), and the logical way the screen is laid out, facilitating simple development of machine code sprites.

But, and there's always a but when you compare two micros, there were one or two features I was used to on the BBC Micro which I missed when I started programming the CPC.

The first was the in-built assembler, but this has been overcome by a number of assemblers that are now available commercially.

Second came the use of procedures. The closest the Amstrad gets to procedures is the GOSUB statement which is fine for working on small programs but can make development trickier the longer a program gets. As you add more and more subroutines, remembering where a particular one is located becomes quite a headache.

The problem is avoided on the BBC Micro because procedures can replace GOSUBS and are not line dependent. If you 1ook at Program I, which is written in BBC Basic, you'll see that line 40 is actually the equivalent to GOSUB 1000. However, the subroutine at line 1000 is identified by "name" and when working on a program you never need know where PROCname is in order to call it.

10 REM Program I
20 REM An example of using procedures
30 CLS
40 PROCname
50 REM Rest of program ...
...

...
900 END
1000 DEFPROCname
1010 PRINT Amstrad"
1080 ENDFROC
Program I

Without a GOSUB in sight I think you'll agree that this lends itself to structured programming as well as making your listings more legible to other people.

Program II is a routine that will give you procedures on the CPC. Save it before you run it. It sets up the RSXs |PROC, |DEFPROC, |ENDPROC and |START, |PROC works in exactly the same way as in Program I except that the syntax is slightly changed. In place of typing:

PROCname

you enter:

|PROC,name

The same goes for DEFPROC.

You also have to enter |START as one of the first lines before you use any |PROCS or |DEFPROCS. This is because you are allowed to nest procedures up to 10 deep, which is achieved by storing the return address each time a procedure is called.

|START restores the pointer to the return addresses to 0 so you start on the first level of nesting each time you run the program.

If you leave |STARTS out and press Escape, or the program stops in the middle of a few layers of nesting due to an error, the pointer won't be restored when you re-run the program. The next |ENDPROC encountered will take you back to the procedure that was executing before you pressed Escape or the error occurred.

If you try to nest procedures more than 10 deep "Too many PROCs" will bo reported and you will be returned to Basic with a syntax error. A true Basic error occurs and the program doesn't attempt to continue execution.

Another way this error could occur is if you forget to enter the correct |ENDPROC for each procedure, or put it in the wrong place.

Two other errors can be reported. The first is "Undefined PROC,” which will happen if you type:

|PROC,frod

when you mean:

|PROC,fred

or if you type |PROC,anything when you haven't defined any procedures.

The second error is "No matching PROC." This happens when the program encounters |ENDPROC when when it is not executing a procedure.

To use procedures correctly you must also remember the following points:

  • A |DEFPROC must be the ONLY statement on a line because once the |DEFPROC is found, execution continues from the line following.
  • Statements such as the following, which uses ELSE with more than one i PROC, are not allowed:

    IF a = 1 THEN PROC,one ELSE if a=2 THEN |PR0C,two

    This is because the return address from a procedure is always the start of the statement, and IF . . . THEN . . . ELSE commands are considered as a complete statement. However you can use |PROC in multi-statement lines such as:

    100 |PROC,arnold:PRINT "That was PROC arnold": |PROC,joyce

  • Keywords are not allowed in procedure names. If you want to be sure you haven't used one, type all your procedure names in lower case. If any subsequently appear in upper case, the interpreter has decided they are keywords.
  • Procedure names may not be more than 16 characters long, which should be ample. However, you can type in more than 16 characters but only the first 16 will be recognised and acted upon.
  • |ENDPROC doesn't need the procedure name following it but you can include it to aid program clarity.
  • In long programs put all your procedures at the start so that they can be found quickly, and use a GOTO to jump past them to your main code.

Program III, which is a version of the old classic Mastermind, will serve to illustrate the use of procedures. The main program is included between lines 70-190. Note the |START in line 50.

Try loading one of your old programs and replace the GOSUBs and subroutines with procedures. I think you'll find that you'll never want to go back to GOSUBs again. I certainly don't!

CWTA

★ PUBLISHER: Computing with the Amstrad
★ YEAR: 1987
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LiCENCE: LISTING
★ COLLECTIONS: COMPUTING WITH THE AMSTRAD 1987 , COMPUTING WITH THE AMSTRAD-AUSTRALIAN
★ AUTHOR: Robin Nixon
 

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Procedures-Robin  NixonDATE: 2013-05-07
DL: 287
TYPE: ZIP
SiZE: 5Ko
NOTE: 40 Cyls
.HFE: Χ

Je participe au site:
» Vous avez des infos personnel ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop/c
Page créée en 422 millisecondes et consultée 1680 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.