Index | Next

Master 512 Forum by Robin Burton
Beebug Vol. 7 No. 3 July 1988

Robin Burton presents the first of an occasional series for users of the 512 coprocessor.

The 512 coprocessor, which for a reasonable cost, allows a Model B or a Master 128 to run IBM PC software, has proved a popular upgrade among users. With the current special offers on the 512 board (see the News section in this issue), the number of users can only grow. However, the support for 512 users, both in the form of books, and coverage in BEEBUG and other magazines, has been limited. Judging by the letters received recently, many people would like to see this situation changed, and this is your chance.

The size, frequency and content of this column depends on you. We want to know what you want to read about. With such a vast range of software available we cannot cover everything, so your input is vital. There are no restrictions: anything to do with the 512 will be considered.

For example, have you upgraded to DOS+ 2.1? Did it solve any problems? Did it cause any? Which packages do you use? Do you have any hints or tips you would like to pass on to other users? Have you had any particular problems? If you have and you have solved them, how? Are there any user groups out there? We know the Big Ben Club in Holland has a very active 512 section of about 80 members, and there is a group run in the Cambridge area by Andy Smith from Acorn, but what about the rest of us?

I'll start the ball rolling with an example of using the batch facility. It's designed to make life easier, but for many users it is just a source of confusion. You might be aware that batch files are similar to the Beeb's !BOOT or EXEC files, but they can do very much more, because they operate at a completely different level.

Batch files are text files which contain one or more commands of the type you could enter through the keyboard, for example to catalogue a disc, or copy a file. In practice though, you can regard batch files as a means of defining complete self contained functions. They work by stringing simpler commands together, to be executed in sequence within the framework of a very simple 'language'.

DOS+ reserves certain file extensions to indicate file types, so a '.cmd' extension means a command file, '.exe' means an executable file, while '.bat' indicates a batch file. If any command line is not known to DOS+, it looks on disc for a file of that name, and if there is one it takes the action indicated by the file extension. This is why a command error produces 'Bad command or filename', DOS+ can't tell the difference. A '.bat' extension means process the commands in this file automatically line by line. The 512 User Guide does mention batch files, but only in passing, and it does not make any attempt to show their power.

We will use word processing as an example, but the techniques can be applied to virtually any application. Our starting point is a system which has just been started up, so all you have on the screen is the DOS+ message and the A> prompt. The batch file must therefore carry out all the tasks that would otherwise require laborious and error-prone keyboard entry.

To create a batch file, you must be able to enter a text file that contains just printable ASCII characters, with no control codes. Quite a few word processors are able to store text in this way, and those which don't, generally have an option to save plain text. Obviously, the manual for your particular word processor will give more details. Another possibility is to use a text editor such as ED, which is supplied with the system and documented in the 512 User Guide. As an alternative, you could enter the batch file using your favourite Beeb editor or word processor, and then use the 'getfile' utility to transfer it to DOS+ format.

For our example job we will turn the interlace off, select the screen mode and colour and load our word processor software together with an entered filename of our choice. On completion of the edit we also want to make a backup of what we have been working on. Here are the major differences from BBC EXEC files. Firstly a batch file can run the entire session from beginning to end, and on leaving the application it can still be in control. This means that the application actually can be run from within the batch file, rather than simply being started by it. Secondly we can supply variable information, (e.g. filenames), with the initial command. These are passed to the batch file for use during execution.

We will call our batch file 'WP.BAT'. Before writing the batch file, we need to know exactly how to perform each of our operations. For our example, we will assume that our word processor is started using 'wordproc <filename>', where <filename> is a file to be loaded. Further, we will assume that the word processor software disc is in drive B, and the disc in drive A contains the text files, the batch file itself, and a command called 'fset' which is copied from the DOS+ system disc. All our text files will have a '.doc' extension, and the backup files will use '.bak'.

With the document disc in drive A and the applications disc in B, to edit the file 'TEXT.DOC' all we would need to do is enter 'wp text', and press Return. Everything else would then be automatic (except the actual word processing, of course). The wp part of the command triggers the execution of 'WP.BAT', while the filename 'text' is passed as the first parameter. DOS+ just takes the rest of the command line after the filename, and splits it into parameters, with each parameter being separated by one or more spaces. For example, if you typed 'comm hello goodbye', comm is the filename, hello is the first parameter, and goodbye is the second parameter. Within the actual batch file, the first parameter is referred to as '%1', the second as '%2' and so on. The system just substitutes the parameter from the command line for the ' %n' in the file.

Our batch file would typically start something like this:

rem check file and screen setup
echo off
if not exist A:%1.doc goto error1
star TV0,l
colour 1 2
pcscreen 3

The first line, starting with 'rem', is a comment line, and these can be used wherever necessary to make the file easier to read. Blank lines are also ignored, and can therefore be used to separate different parts of the file. Going through line by line: 'echo off' stops DOS+ displaying the rest of the batch file as it is executed, (rather like using VDU 21 in a Beeb EXEC file), while 'cls' simply clears the screen.

The command in the fourth line of the file shows some of the power of batch files. This is a conditional statement, which looks for a file (whose name is substituted for %1), and if it does not exist, jumps to a point elsewhere in the file. The syntax is very similar to that of IF-THEN in most languages. 'exist' is a command to check for a file existing, and in this example, the file is specified as being on drive A:, with the filename being the first parameter, and the extension being '.doc'. The 'not' reverses the result of the call to exist, and the 'goto' goes to a label called 'error1' which we will specify later. Assuming the file is found, the next three lines are executed. These execute *TV 0,1 to turn interlace off, set the text colour to green, and change mode so that the *TV can take effect.

Our batch file continues:

rem load application with named file
echo Loading wordproc with A:%1.doc...
a:fset a:%1.doc [rw]
wordproc a:%1.doc
rem the application executes here
a:fset a:%1.doc [ro]
echo Remove disc from drive B:
echo Insert wpbackup in drive B:
if not exist b:*.bak goto error2

This section starts by printing a message using 'echo' to confirm all is OK, and setting the default drive to B:. The next line calls the command 'fset' with the parameters being the name of our text file, and [rw]. The effect of this is to ensure both read and write access to the file before we start the word processor.

After this, the actual word processor is started up with the filename being specified in the command. At this point, the batch file will be suspended, and the word processor can be used normally. It is only when you leave the word processor to return to the system that execution of the batch file is continued.

When the batch file is continued, it first of all makes our text file read only again, and then prints two messages asking for the word processor disc to be replaced by the backup disc. The 'pause' command makes DOS+ print a prompt and wait for a key to be pressed. As a check that the correct disc has been inserted, we check that at least one file with the extension '.bak' exists already, jumping to an error routine if it doesn't.

The next three lines are:

echo Securing A:%1.doc to B:%1.bak
if not exist b:%1.bak goto copy
b:fset b:%1.bak [rw]

These print a message to show what is being done, and then check if the backup file already exists. If it does, 'fset' is used to make sure the file can be over-written. The ':copy' in the last line is a label. Whenever 'goto copy' is executed, the commands in the file are skipped over until the ':copy' is found, and then execution is continued from that point.

The last part of the body of the batch file is:

copy a:%l.doc b:%1.bak
a:fset b:%1.bak [ro]
echo Backup of A:%1.doc to B:%1.bak complete
echo Run completed OK
goto exit

This just copies the text file to the backup disc, and makes the backup read only. Two messages are printed to tell the user that everything is done, and the last line goes to a routine called exit, which we will define in a minute.

The rest of the file handles the errors:

rem errors and exit
:error1 - named input file missing
echo %1.doc is not on drive A:
echo Load abandoned!
goto exit

:error2 no bak files in drive B:
echo Disc in drive B is not a backup disc
echo ************************************
echo *                                  *
echo * Backup of A:%1.doc HAS FAILED!!! *
echo *                                  *
echo ************************************


These lines just print warning messages and goto the exit routine. The exit routine simply re-selects drive A and exits at the end of the file.

Any errors that occur during execution of a batch file will cause it to terminate. You can also leave a batch file when it is paused by pressing Ctrl-C. If necessary, batch files can be nested, with one calling another by specifying its name, and execution returning to the first one when the second has finished.

If you are new to batch files, it is worth trying the example given here. Just enter the file as one long block, and make any modifications necessary for your particular word processor.

That's all for this month. If you have any suggestions for future 512 articles, please write in and tell us about them.

Index | Next

About the Master 512 | Bibliography