RTR logo


BBC BASIC (86) Manual

Utility Routines

Annex E to


There are four utility programs included on the distribution disk.

The first converts programs and some data files from the Acorn BBC Micro format to BBCBASIC(86) format. This program is called FCONVERT.BBC.

The second is called RX.BBC. It is a program for receiving files sent from a BBC Micro via the RS423 port by the program TX.

The third in a program called COMIO.BBC. This program provides support for serial I/O via COM1: or COM2:.

Finally, PEEK.BBC provides read/write access to any byte within the address space of the computer.

Program and Data Format Conversion

Transferring the Files

Before converting the files, you need to transfer them from your Acorn DFS formatted disks to MS-DOS formatted disks. If you don't have access to a BBC Micro, you will need to have the files copied by one of the professional file copy services.


If you have access to a BBC Micro, you can copy the files to your MS-DOS computer via the serial port on the BBC Micro and either COM1: or COM2: on your MS-DOS computer. In order to do this you will need:

Transferring the Comms Program

To transfer the comms program from your PC to a BBC Micro, carry out the following steps.
 10 REM TX V2.00 1 OCT 88
 20 :
 30 REM Send a file byte by byte via
 40 REM the serial port.
 50 :
 60 :
 70 CLS
 80 PRINT "Run RX on your IBM PC BEFORE pressing"
 90 PRINT "                      ******"
100 PRINT "<RETURN following the file name."''
110 INPUT "Name of file to send ? "name$
120 :
130 x=OPENIN(name$)
140 IF x=0 PRINT "File does not exist":END
150 byte=BGET#x
160 IF EOF#x PRINT "File is empty":END
180 PRINT "Sending file ";name$
190 *FX3,7
200 *FX8,7
210 *FX7,7
220 *FX2,1
230 *FX21,1
240 *FX21,2
250 IF INKEY(3000)<>17 THEN 540
270   IF INKEY(0)=19 PROC_xoff
280   VDU byte
290   byte=BGET#x
310 VDU byte 320 CLOSE#0
330 *FX3,0
340 *FX2,0
350 VDU 7
360 PRINT '"File ";name$;" sent to serial port"
370 PRINT "Press the <Esc> key on your"
380 PRINT "MS-DOS computer to terminate"
390 PRINT "the transfer and close the"
400 PRINT "file."
410 END
420 :
430 : 440 ON ERROR OFF
450 *FX3,0
460 *FX2,0
470 CLOSE#0
480 PRINT:REPORT:PRINT " at line ";ERL
490 PRINT '"Transmission aborted"
500 END
510 : 520 DEF PROC_xoff
530 IF INKEY(3000)=17 ENDPROC
540 *FX3,0 550 *FX2,0 560 PRINT '"PC not ready - Program aborting"
570 CLOSE#0
580 END

Transferring a File

You can carry out a similar process using a cassette recorder, but in this case you should enable the tape filing system by issuing the *TAPE command.

Converting the Files Using FCONVERT.BBC

Once you have transferred your files to an MS-DOS formatted disk, you can use the FCONVERT utility to convert them to BBCBASIC(86) format. To do this (assuming you are running BBCBASIC(86)on your MS-DOS computer), type:
and answer the questions displayed. Re-RUN FCONVERT.BBC for every file you want to convert.

Program Files

Unless you are very unlucky, your program should transfer without error. If you have any data statements in your program which contain the value &1A or &0D you will get errors reported, but you will probably find that the program is nearly correct. Try loading and listing the program and see if you can correct the errors.

Data Files

You should transfer the data files to an MS-DOS formatted disk as previously described and then try using the FCONVERT utility to convert them.

For best results, the data files should have been written using PRINT# rather than BPUT#. If a file has been written ENTIRELY with BPUT# it will not, of course, need converting.

Mixed data files are a nuisance. It may be possible to convert them, but you will get a number of 'Bad data' errors reported and you may confuse the utility. If this happens, you will need to write a data conversion program and in order to do this you will need to know the structure of the data file and the way data is stored by the Acorn DFS.

Serial I/O

BBCBASIC(86) relies on the operating system for all its I/O functions. Consequently, support for the serial ports is constrained to that provided by MS-DOS. You can initialise a serial port using the MS-DOS MODE command, open a channel to "COM1" (the first serial port) or to "COM2" (the second serial port) using the OPENIN or OPENOUT functions, and then transfer data using the BGET#, BPUT#, INPUT# or PRINT# statements. However, MS-DOS is not very good at dealing with serial I/O and at high baud rates and/or with a slow computer there is a danger that incoming data will be lost (a 'Device fault' error will occur in these circumstances). Another problem is that there is no 'time out' mechanism built into MS-DOS, so if your BASIC program is waiting for input from the serial port, and no data arrives, if will wait forever (not even the Escape key will work).

To overcome these problems the file COMIO.BBC on the distribution disk contains interrupt-driven assembly-language routines to enable you to use COM1 or COM2 for sending and receiving data. The program COMDEMO.BBC demonstrates the use of these comms routines to provide a very simple terminal emulation program.

Don't worry if if you can't understand the assembly code 'bits' of the program. Look at the examples (COMDEMO.BBC and RX.BBC) and follow the instructions for each of the routines.

The maximum 'safe' speed for the '_com_get' routine depends on how much BBCBASIC programming goes on between getting each character. For simple programs you should try 1200 baud as the starting point. If you want to run faster than this, you may need to implement handshaking. In order to keep the routines simple, hardware handshaking has not been used. You will, therefore, need to include some form of handshaking in your program. The program RX.BBC sends a character back to the program TX.BBC every time an incoming character has been processed successfully. This allows the serial data speed to be set to 9600 baud. Because of the handshaking, the real rate of data transfer is lower than this, but still faster than the 'safe' speed of 1200 baud.

Direct Memory Access

The program PEEK.BBC contains two assembly code routines, a function and a procedure for directly accessing any byte in the computer's address space. The assembly code routines access the memory using the computer's 'natural' addressing mode of paragraph and address. The function and procedure are passed the absolute memory addresses of the byte to be accessed. This address is then converted into paragraph and address before the assembly code routines are called.

Be very careful when using the POKE procedures. You can write to memory which is outside the control of BBCBASIC(86) and this may cause all sorts of problems. Make sure you know where all the 'bits' of the operating system, spooler programs, etc are. Do not change any of these areas unless you are SURE you know what you are doing.

You can use these routines to directly access the screen memory areas. The monochrome/character screen memory starts at address &B0000 and ends at address &B7FFF. The colour/graphics screen memory starts at address &B8000 and ends at address &BFFFF.

If you want to save and re-load screen images, you may find the *SAVE and *LOAD commands will do what you want more efficiently than reading/writing the memory area byte-by-byte.



Best viewed with Any Browser Valid HTML 3.2!
© Doug Mounter and Richard Russell 1999