SECTION G CODES FILE INTER.G Before starting this section I suggest that you open the CP/M guide ,which was supplied with your PCW, to Appendix III and look at the ESCAPE sequences on page 140. There are many of them and they all affect the screen display. Before they can work in BASIC they need to be translated into a different form. Some are already incorporated into dedicated keys, such as the commands for moving the cursor right and left, but others can be used in BASIC programs to control the screen and to produce many interesting effects. The printer can also be controlled by a series of ESCAPE codes, but this is dealt with elsewhere. In PRIMER we discovered how to clear the screen using PRINT CHR$(27)+"E". In CP/M you can clear the screen simply by pressing [EXIT] and E (in many computers the [EXIT] key is labelled [ESCAPE] ) but this is not possible in MALLARD BASIC so we have to use the CHR$ function. CHR$ converts an ASCII number to it's character equivalent, and CHR$(27) converts 27 to CONTROL-[ or ESCAPE as we prefer to call it. The whole code is formed by adding upper or lower case letters or numbers to CHR$(27).e.g CHR$(27)+"A" The codes can be used in several ways. The simplest is to write in the program where appropriate PRINT CHR$(27)+"E", which as we know clears the screen. To write all this every time we want to clear the screen is not only boring, but uses up memory. It is better to store the code in a short variable and use that instead. Codes which are to be used in a program are usually equated with variables and grouped near the start of a program. Complementary codes can be added together and stored in a variable to actuate more than one command with a single variable. Consider the following extract from a program. 10 home$= CHR$(27)+"H" : REM 'Home the cursor' 20 clear$= CHR$(27)+"E" : REM 'Clear the screen' 30 cls$ = home$+clear$ : REM 'Combines the two' Thus we can achieve three different effects by PRINT home$, PRINT clear$ or PRINT cls$. If you only need the last simply use one line :- 10 cls$=CHR$(27)+"E"+CHR$(27)+"H" It is permissible to use a semi-colon in place of the plus sign and it has the same effect. The line rewritten using semi-colons is:- 10 cls$=CHR$(27);"E";CHR$(27);"H" A few codes are a little more complicated and use additional numbers to specify a position on the screen. For example if you want to place a message at a specific location you could use :- CHR$(27)+"Y"+CHR$(32+r)+CHR$(32+c); where r is the row number( 0 to 32) and c is the column number (0 to 90). We cannot store this in a simple variable if we want to change r and c as required, and so we use the DEF FN command instead. It looks like this. 50 DEF FN posn$(r,c)= CHR$(27)+"Y"+CHR$(32+c)+CHR$(32+r) Later in the program, if we want to type ,say, a heading on row 5, starting at column 30, we would make the line:- 750 PRINT FN posn$(5,30)" The Battle of Waterloo" The variable does not have to be posn$, it can be your choice, but must of course end with $, signifying a string variable. The following lists the Escape codes which are useful to use with MALLARD BASIC. CHR$(27)+"0" Disables the status line at the bottom of the screen, allowing the full 32 rows to be used. CHR$(27)+"1" Cancels the above CHR$(27)+"A" Moves the cursor up one line ( and thus prints there ). CHR$(27)+"E" Clears the screen, but doesn't affect the cursor position CHR$(27)+"H" Homes the cursor to top left hand side of screen. CHR$(27)+"J" Erases to the end of the page. CHR$(27)+"e" Enables the cursor blob (turns it on) CHR$(27)+"f" Disables the cursor blob (turns it off) CHR$(27)+"p" Enters reverse video mode CHR$(27)+"q" Leaves reverse video mode CHR$(27)+"r" Enters underline mode CHR$(27)+"u" Leaves underline mode CHR$(27)+"x" Enters 24 x 80 mode screen (24 rows x 80 columns) CHR$(27)+"y" Returns to PCW standard of 32 rows x 90 columns CHR$(27)+"b"+"63" Reverses the entire screen to light green CHR$(27)+"b"+"0" Returns the screen to dark. CHR$(27)+"Y"+CHR$(32+r)+CHR$(32+c) Prints at any required position on the screen, where r=row and c=column The code for changing the viewport is :- CHR$(27)+"X"+CHR$(32+r)+CHR$(32+c)+CHR$(nr-1+32)+CHR$(nc-1+32) Which looks a little daunting at first sight, but is really quite easy to understand. The first part is the same as the code just shown except that an X replaces the Y. This part indicates the top left-hand corner of the viewport, when r = row and c = column. The next term determines the height, where nr = number of rows, and the last term determines the width, where nc = number of columns. With this command you can make a viewport or 'window' of any size within the screen, but if you are experimenting with this remember the 'antidote' PRINT CHR$(27)+"y". ESCAPE codes or the variables that represent them can be manipulated in the body of a program in all the usual ways, not just used with PRINT and DEF FN. In the program that follows I have used the full codes with the PRINT command all the time (except where I have slipped in a few crafty PRINT cls$ commands previously defined at the start of the program). This is to display the codes more clearly and is not usual practice. End of file INTER.G  is to display the codes more clearly and is not usual pract