CODING ★ Mallard BASIC to CPC BASIC ★

Coding - Mallard BasicDéplombage des Fichiers Mallard Basic par SpokeBasic - Mallard Basic To CPC Basic (The Amstrad User)Menu - Soft - Basic
★ 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 ★ 

Converting programs written in Mallard BASIC into CPC BASIC or vice versa is not as difficult as some may at first think Chris Wooton takes us through the basics of BASIC conversion!

With the number of PCW Basic programs being published in the Amstrad User rising, it seems, with every issue, many CI XT owners may want ro convert some of these programs into [promotive Basic Obviously one cannot convert every program as the PCW has essential differences from the CPC in the form of the size of its screen, memory size, file management etc.

MALLARD BASIC'S FEWER COMMANDS

Mallard Basic has, a wide range of differences from locomotive ranging from its use of control codes to sending data to the printer The use of control codes stems from the fact that Mallard Basirchas very few of the commands which CPC owners take far granted, eg. CLS and LOCATE and CP/M control codes must be used instead. A list of these control codes can be found (by 6128 owners) in chapter 7 (pages 49-52) of their manual.

The PCW screen, with its dimensions of 90 x 30 characters is considerably larger than CPC MODE 0 and 1 but MODE 2(80 x 25) can be used as long as screen coordinates are changed to cope with the smaller screen.

A function FN at$(x,y) (or similar name) is often defined in PCW programs to return the codes necessary to move the cursor to position x,y on the screen. The easiest way to change this for the CPC is to redefine the function as:

DEF FN at$(x,y)=CHR$(31)+ CHR$(x+1)+ CHR$(y+1).

Another (harder) way of changing the FNat$'s to suit the CPC is replace the PRINT FNat$(x,y) state merits with LOCATE x+1,y+1. This harder than merely redefining this function as sometimes several FNat$'s will appear in the one statement (necessitating splitting to line up). The need to add 1 to the PCW screen co-ordinate; is derive from the fact that for the PCW the co-ordinates of the top left of the screen are 0,0 while on the CPC the are 1,1.

CONVERSION OF ESCAPE CODES INTO CPC BASIC

ESCape sequenceFunctionCPC Equivalent
CHR$(27)+"E"+CHR$(27)+"H"Clears The screenCLS
CHR$(27)+"A"Moves the cursor up 1 linePRINT CHR$(11);
CHR$(27)+"B"Moves the cursor down 1 linePRINT CHR$(10);
CHR$(27)+"C"Moves the cursor left 1 charPRINT CHR$(8);
CHR$(27)+"D"Moves the cursor right' 1 charPRINT CHR$(9);
CHR$(27)+"P"Enters inverse video modePRINT CHR$(11);
CHR$(27)+"Q"Exits inverse video modePRINT CHR$(18);
CHR$(27)+"H"Homes the cursorPRINT CHR$(30);

ESCAPE, CONTROL CODES

Now on to control codes or ESCape codes. These codes derive their name from the ASCII Code (ESC or 27) which prefixes all the control code sequences. Escape codes do a sorts of handy things like clearing the screen, locating the cursor, moving the cursor relative to its current position and entering and exiting inverse video mode. The table shown in the box should aid conversion of these codes.

Note: In some programs, a variable, esc$ is setup to equal CHR$(27) and ESCape sequences are thereafter entered with esc$ instead of CHR$(27) eg.

PRINT esc$+"E"+esc$+"H"

Other differences exist between Mallard ami Locomotive other than those already mentioned. These include the LPRINT command which is equivalent to the CPCs PRINT #8 command

SEQUENTIAL ACCESS FILES

Another important difference is the way in which Mallard Basic opens,, writes to and closes sequential access files (the si me type used on the CPC). Files are opened by the OPEN command followed by 3 parameters. The syntax for the OPEN command is

OPEN < filetype > , < stream number > , < filename >

< filetype > is either "I" (input) or "O" (output). The second is a stream number and the stream is written to in a similar way that the CPC writes to streams (PRINT #< stream >). The last parameter is the disc filename to read from or write to. Eg.

OPEN "I",1;"INPUT"

opens a file called INPUT on the disc as stream number 1. This file is read from by the INPUT and LINE INPUT commands followed by #1 eg. INPUT #1.a$. The OPEN command should be replaced by OPENIN"INPUT" and data read from the file by INPUT #9.

OPEN "0".2"OUTPUT" (equivalent to OPENOUT"OUTPUT" on the CPC) opens a file called OUTPUT on the disc as stream number 2 (the stream number is arbitrary). The file is thus written to by the PRINT in command (PRINT #9 for the CPC). AU open files can be closed by the CLOSE command (CLOSEIN CLOSEOUT on the CPC) or closed individually by CLOSE #< stream number > (CLOSEIN for input files, CLOSEOUT for output files).

EOF is another command associated with sequential files. Assuming only one input file is open, EOF< stream number > is equivalent to the CPC's EOF. Mallard Basic possesses a few commands not directly implemented in Locomotive Basic. These include the SWAP command which swaps two variables (this can be simulated by using a temporary variable) and the FINDS command which returns a string depending on whether a specific file can be found on disc or not.

Random Access (RA) files are not supported on the CPC and any programs which make use of them will be very hard to convert. Commands associated with random access files include HELD (for defining fields), OPEN "R" (for operating RA files) and GET (for moving the file pointer to a particular record).

PCW KEEPS TIME

Those of you who read the PCW section in TAU will probably know that a clock is kept by the PCW in a similar fashion to the TIME command in Locomotive. The differences between this clock and the CPC Time are twofold; 1: the time is stored as hours, minutes and seconds elapsed as opposed to the number of 300th's of a seconds elapsed (on the CPC) and t the PCW does not possess a command to read the time. Instead the PEEK command is used to read the addresses.

To date, about 50 PCW Type-ins have been published in The Am-strad User with programs such as the Spreadsheet, Databaseand the Superannuation calculator well worth the time to be converted.

TAU

★ YEAR: 1988
★ AUTHOR: Chris Wooton

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Coding » Le Bug du DEC$ sur 464
» Coding » Le Bug de l'Openout (CPC Revue)
» Coding » Basic Technique du Chaine Merge
» Coding » Calculons mieux et plus simplement
» Coding » La page pédagogique d'Hebdogiciel n°111: Basic et Langage Machine
» Coding Src's » Execution d'une instruction BASIC en assembleur
Je participe au site:

» 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 043 millisecondes et consultée 3502 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.