Click Here To Go To The Salamander Archive



Nicholas Lloyd
%SHOW_TITLE%

Cover Art


Turbo Compiler


Turbo Compiler


Turbo Compiler

"The machine code version of the first program is no faster than the Basic one, and the second doesn't even run in Basic as it was written in a special way so that the compiler could make sense of it!"
Home Computing Weekly

Blurb

Turbo Compiler is a highly compact machine-coded BASIC compiler for use with both the BBC Microcomputer (Models A and B) and the Acorn Electron microcomputer.

Its small size allows TURBO to compile programs instantaneously within the micro, without the need for immediate use of tape or disk.

Supplied with detailed documentation, TURBO is ideal for constructing fast hybrid programs, or writing 100% machine code programs.

Features:

  • Highly compact machine-coded compiler (2K)
  • Fast compilations in under one second
  • Disk based version also supplied on same cassette
  • Supports sub-set of BASIC commands directly
  • Comprehensive documentation deails how to implement a total of 65 BASIC keywords
  • Compiled code can be used without the compiler being resident
  • Provides an ideal immediate stage for users who wish to move from BASIC programming to the use of machine code and the Acorn operating system
  • TURBO requires a Series 1 Operating System on the BBC Micro

Introduction

TURBO is a basic compiler for the BBC and Acorn Electron microcomputers (in order to run TURBO on the BBC Micro, a 1.0 or later Operating System is required).

Two versions of the program are supplied, one for BBC or Electron users with a normal cassette tape system, the other for BBC users with a disk drive, or using a cassete tape on a machine with a DFS installed.

The compiler occupies only 2K of memory, and will therefore run on both the BBC Model A and the BBC Model B; on the Model B and Electron, TURBO will allow all eight screen modes to be used. As this is such a compact compiler, not all of the BASIC keywords have been implemented. However, Appendix 1 lists all of the BASIC keywords and explains how to achieve, where possible, the same effect if that keyword is not directly supported by TURBO.

The TURBO Compiler is ideal for the user who wishes to write machine code subroutines for games. Indeed, entire games can be written with TURBO, but the user may find that she/he has to divide the program into several sections if it is a long game.

The machine code produced by TURBO is completely independent of the compiler, and so can be used without the compiler itself being resident.

Once the dialect used in TURBO has been picked up, you will find that you can easily write very fast programs. For example, the following program takes about 14.5 seconds to run in BASIC on the BBC Micro, but if you compile it with TURBO, it will take under one second to execute.

  10LETB%=&00
  20LETB%=B%+&01
  30FORA%=00TO&FF
  40NEXTA%
  50IFB%>&FETHEN20

The same savings in time will not be experienced with all programs (depending on complexity) but you will find that your programs wil run considerably faster.

Loading The Compiler

The following instructions are for loading the Turbo Compiler from tape. If you have a disk system, read the section Transferring TURBO To Disk before continuing.

  1. Ensure that the computer is free of any other programs, either by pressing CTRL and BREAK at the same time, or by turning the computer off and on again.
  2. Position the tape at the beginning of side 1.
  3. Type CHAIN"" and press RETURN.
  4. Press the PLAY button on your cassette recorder.
  5. When the first program has loaded, a title page will be displayed and the computer will begin to load the second program. Leave the cassette recorder playing until this second program has finished loading. Ignore any messages the computer may print after both programs have loaded.
  6. Stop the cassette player if you do not have the remote control facility connected. If you wish to load the demonstration program, do not rewind the tape.
  7. Press BREAK. The screen should appear as below (or similar, depending on computer type):
      TURBO BASIC
      BBC Computer 32K
    
  8. Set PAGE to wherever your BASIC program is going to be stored. The minimum setting is &1500. To do this, type PAGE = &1500 (RETURN).

    If you wish to set PAGE higher than the minimum, you will also need to alter memory locations &D20 and &D21.

    For example, if you wanted to set PAGE to &3000, you would also have to poke the low byte of the address to &D20 and the high byte of the address to &D21:

    e.g. Type: PAGE = &3000 and press RETURN
    ?&D20 = &00 and press RETURN
    ?&D21 = &30 and press RETURN
  9. The compiler normally stores the compiled code from the address &2200 upwards. If you wish to change this, memory locations &D1E and D1F must be altered to contain the low and high bytes of this new address. For example, to change the start position of the code to &3200, type the following:

      ?&D1E = &00 and press RETURN
    ?&D1F = &32 and press RETURN
  10. Type NEW and press RETURN to let BASIC get its pointers sorted out.
  11. If you are using a BBC Model A, you will need to enter the following:

    ?&DE4=&3E:?&DE9=&3F:?&FCB=&3F:?&FD5=&3E (RETURN)

    The computer is now ready for you to either load or write a program. There is a demonstration program on the cassette immediately after the compiler.

Note: The demonstration program for use with disk has had all REM statements removed. Disk users who wish to list and study the demonstration program are recommended to do so using the tape demonstration on side one of the cassette.

Transferring TURBO To Disk

Side two of the cassette contains a version of TURBO for use from disk.

To transfer the two programs to disk, proceed as follows:

  1. Type *TAPE and press RETURN.
  2. Position the tape at the beginning of side 2.
  3. Type LOAD"" and press RETURN.
  4. Press the PLAY button on your cassette recorder.
  5. When the first program has loaded, type *DISC and press RETURN.
  6. Type SAVE"DTURBO" and press RETURN.
  7. Type *TAPE and press RETURN. Then type *LOAD"" and press RETURN.
  8. When the second program has loaded, type *DISC and press RETURN.
  9. Type *SAVE DTURBO2 1900 20FA and press RETURN.
  10. Type *TAPE and press RETURN. Then type LOAD"" and press RETURN.
  11. When the demonstration program has loaded, type *DISC and RETURN.
  12. Type SAVE"DDEMO" and press RETURN.

This completes the transfer process.

Loading The Compiler From Disk

If you want to load the program, use the same loading instructions as for the tape system, but with the following changes:

Step 2. If you have a DFS fitted, but want to run the program from tape, turn the tape over to side two and rewind it to the beginning. Then type *TAPE and press RETURN.

Step 3. If you are running TURBO from disk, type CHAIN"DTURBO" and press RETURN.

Step 8. The minimum PAGE setting for disk users is &2100. The memory locations to change if you want another PAGE location, are &1920 and &1921.

Step 9. The default location for storing compiled code is at &2800. If you want to alter this, the memory locations to change are &191E and &191F.

Running the Demonstration Program

It is recommended that you load and run the demonstration program provided, then have a look at the program to see how it works, before attempting to write programs of your own. There are two versions of the demonstration program provided, one for the tape version and one for the disk version. These are on the cassette tape, immediately following the appropriate version of the compiler. The only difference is that the disk version has had all the REM statements removed, due to memory limitations.

To load the demo program, first load TURBO as described earlier. As the demo program uses the preset compile addresses, step 7 simply consists of setting PAGE to 1500 (&2100 for disk users) and step 8 may be ignored. Load the demonstration program by typing LOAD"" (LOAD"DDEMO" if you have saved your demo program onto disk).

You can then compile the program by typing *TURBO and pressing RETURN. The screen will be cleared, some "garbage" characters will appear in the bottom half of the screen, and "OK" will be printed at the top of the screen.

The machine code program can be executed by typing CALL &2200 (CALL &2800 for disk users).

At the end of the first section, the computer will wait for a key to be pressed, and will then draw a pattern of triangles, as well as a set of space invaders.

Pressing another key will cause the space invaders to move across the screen.

Pressing another key will end the demo program.

The first part of the program will also run in normal BASIC so that you can compare speeds, but later sections will not, as they depend on the fact that TURBO only uses numbers from 0 to 255, which is not true in normal BASIC.

Writing Your Own Program

By now you will probably be wanting to write and compile your own programs. It is assumed that the user has a knowledge of BBC BASIC. If there are commands that you do not understand, refer to your User Guide for more information.

It is best to start off by doing some fairly simple programs to get the feel of the compiler before trying to write any games or other programs. Note that if you write a program, compile and execute it, and then wish to stop its execution before it finishes, you must press BREAK. If you do this, step 7 from the loading instructions must be repeated. The source program can be recovered by typing OLD and pressing RETURN. The compiled version will still be in place if you wish to execute it again.

Once you have a program in mind, you can start to write it using the commands recognised by the compiler. These are listed in the next section. If you find that there is a command you wish to use which is not in the list, or if you want more information about one that is, refer to Appendix 1 which lists all the BASIC keywords, and how to use them (or achieve the same effect) with TURBO. See in particular the sections in Appendix 1 on SAVE and LOAD for details of how to save and load compiled code.

When deciding how to allocate the memory, make sure that your compile address (loading step 8) is set above the top of your BASIC program or you will lose your source code when you compile.

Summary of TURBO Commands

PRINT LETvar%=GET
PRINT; LETvar%=INKEY(&hhhh)
PRINTCHR$(&hh) LETvar%=var%?&hhhh
PRINT"hello" LETvar%=car%?dvar%
PRINTCHR$(var%) var%?&hhhh=&hh
PRINT$(var%) var%?&hhhh=var%
GOTOdec var%?dvar%=&hh
GOSUBdec var%?dvar%=var%
RETURN CLS
FORvar%=&hhTO&hh CLG
FORvar%=var%TO&hh MODEdec
FORvar%=&hhTOvar% CALL&hhhh
FORvar%=var%TOvar% VDY&hh
NEXTvar% VDUvar%
LETvar%=&hh REM
LETvar%=var% SOUND&hhhh,&hhhh,&hhhh,&hhhh
LETvar%=var%+&hh $&hhhh="hello"
LETvar%=var%+var% $&hhhh=MID$($&hhhh,var%,var%)
LETvar%=var%-&hh IFvar% > &hh THEN dec
LETvar%=var%-var% IFvar% > var% THEN dec
LETvar%=var%EOR&hh IFvar% < &hh THEN dec ) These two test
LETvar%=var%EORvar% IFvar% < var% THEN dec ) less than or equal
LETvar%=var%AND&hh IFvar% = &hh THEN dec
LETvar%=var%ANDvar% IFvar% = var% THEN dec
LETvar%=var%OR&hh IFvar% <> &hh THEN dec
LETvar%=var%ORvar% IFvar% <> var% THEN dec

Notes:

  1. var% is a variable in the range A% to Z%. It is an eight bit number with a range of 0-255.
  2. dvar% is a double variable in the range A% to Y%. It is a sixteen bit number with the range 0-65535.
  3. &hh is an eight bit number from 0-255 written as two hexadecimal numbers.
  4. &hhhh is a sixteen bit number from 0-65535 written as four hexadecimal numbers.
  5. $&hhhh is a string with a maximum length of 254 characters.
  6. dec is a decimal number.

TURBO Grammar

There are various restrictions on the grammar you can user with TURBO and with numbers and strings. These are listed below.

  1. All line numbers must be in the range 0 to 255. If your program needs more than 255 lines, you will have to split it into more than one section.
  2. Each line may contain only one BASIC statement.
  3. Line numbers, references, and MODEs are all refered to using decimal numbers. All other numbers are in hexadecimal.
  4. When writing hexadecimal numbers, all digits are significant. Thus hex A must be written &0A.
  5. All hexadecimal numbers must be preceded by an ampersand (&).
  6. Spaces should not be left in the program.

The following points should be noted concerning numbers and variables:

  1. All numbers in TURBO are positive hexadecimal numbers.
  2. There are 26 variables which are named A% to Z%. These are integer variables with a range of 0-255.
  3. Note that because these integers are 8 bit hexadecimal, adding &01 to &FF will produce a result of &00.
  4. If you wish to use negative numbers, you must take the complement (subtract the number from &FF and add 1).
  5. Certain instructions use double precision variables. These are sixteen bit numbers with a range of 0-65535. These are referred to by the names A% to Y%. The double precision variable A% is made up of two normal variables, in this case A% and B%. A% contains the low order byte of the number and B% contains the high order byte. To change the double precision variable, you must change both of the normal variables that make it up.

Strings are stored in areas of memory allocated by the user. These are referred to by their address in hexadecimal preceded by a $. For example, a string stored at &3500 would be referenced as $&3500. Strings can be any length between 1 and 254 characters, and are terminated by a carriage return character (&0D).

Compiling Your Program

When you have written your program you will want to compile it into machine code. To do this, simply issue the command *TURBO and press RETURN.

This will compiled your program. The screen will clear and some "garbage" characters will appear on the screen. This is normal. In order to save memory, the compiler uses some of the screen area as work space during the compilation process. If the message OK appears at the top of the screen, your compilation has finished successfully. if a message ERROR &hh appears, the compiler has detected an error. "&hh" is the hexadecimal number in which the error was detected.

To execute your compiled code, type:

 CALL &hhhh and press RETURN

where "hhhh" is the address you specified for saving the compiled code (step 8 in loading).

BASIC and TURBO

You will find many references in Appendix 1 to putting certain functions into a BASIC program then CALLing your compiled code. If you want to transfer information between the BASIC program and compiled code, there are two ways of doing this.

The first is to poke the information into some set area of memory which can then be accessed by your compiled code.

The other way is to change the variables A% to Z%. These variables are stored at memory locations &75 to &8F in alphabetical order. So to change C% you would poke location &78.

To combine BASIC and machine code sections, you must first load the source code for the machine code, then compile it as normal. Then type NEW and load the BASIC program into the computer. To save a combination BASIC and machine code program, you can simply use the *SAVE command using the start address of your BASIC program and the end address of your completed code. (See the SAVE command in Appendix 1 for more information). You may find however, as your programs get larger and more complex, that you wish to save the program in parts to be combined later.

In Appendix 3 you will find an example of this sort of program.

APPENDIX 1 BASIC Keywords

This appendix lists all the BASIC keywords, explaining how the same effect may be achieved using the Turbo Compiler.

ABS All numbers used in TURBO must be positive, so this command serves no purpose.
ACS All numbers used in TURBO must be integers, so this function will not work. If you find it necessary to use trigonometric functions in your proram, this should be done in a BASIC program with compiled BASIC to do the rest.
ADVAL This function is not accessible by using the BASIC keyword but may be achieved as follows:

The variables A%, X% and Y% must be used. A% contains the number of the OSBYTE call, X% must contain the channel number's low byte, and Y% must contain the channel number's high byte.

 10LETX%=&01
 20LETY%=&00
 30LETA%=&80
 40CALL&FFF4
The high byte of the resulting value is stored by X% and the low byte in Y%.

ADVAL(-x) can be achieved by setting Y% to &FF and X% to &FF-x+1.
Further information can be obtained from the User Guide.

AND Two 8 bit numbers may be ANDed together as normal, e.g.
 10LETA%=B%AND&13
Use of AND in an IF/THEN statement can only be achieved by splitting the statement, e.g.
 10IFA%=2ANDB%=4THEN40
would have to become:
 10IFA%<>&02THEN30
 20IFB%=&04THEN40
ASC This may be done by first creating a string containing the character whose ASCII code is wanted, then PEEKing the first location of the string to obtain the value. The following program would obtain the ASCII value of "B". The string location used is &2F00, but any convenient location could be used.
 10$&2F00="B"
 20LETB%=&00
 30LETA%=B%?&2F00
ASN See ACS
ATN See ACS
AUTO May be used as normal
BGET# May be used as follows. The variable Y% must be set up to contain the channel number. The character read will be put into A%. If end of file has been reached, A% will contain &FE. The file must be opened first (see OPENIN).
 10LETY%=&01
 20CALL&FFD7
BPUT# May be used as follows. The variable Y% must be set up to contain the channel number and A% must contain the byte to be written to the file. The file must be opened first (see OPENOUT)
 10LETY%=&01
 20LETA%=&41
 30CALL&FFD4
CALL This can be used as is followed by the hexadecimal location of the routine to be CALLed. A% is passed to the accumulator, X% to the X register and Y% to the Y register. One exiting the call the accumulator is stored in A%, the X register in X% and the Y register in Y%. This is a feature not included in BBC BASIC.
CHAIN The compiled version cannot be CHAINed unless it forms part of an ordinary BASIC program. Use *RUN instead. *RUN and CHAIN may not be used as part of a compiled program.
CHR$ May be used in a PRINT statement as follows. The brackets are required.
 10PRINTCHR$(&20)
 20PRINTCHR$(A%)
 30PRINTCHR$(B%)CHR$(&40)CHR$(E%)
To do the equivalent of B$=CHR$(A%), the following could be used. Don't forget to put a carriage return (&0D) at the end of the string.
 10LETC%=&00
 20C%?2F00=A%
 30C%?2F01=&0D
This sets up a string starting at &2F00.
CLEAR There is no CLEAR command. Variables and strings must be cleared individually.
CLOSE#0 May be achieved as follows. A% must be set to &00 and Y% should be set to the channel number, or to &00 to close all files.
 10LETA%=&00
 20LETY%=&00
 30CALL&FFCE
CLG Use as normal.
CLS Use as normal.
COLOUR This may be done with the following VDU command (&03 is the colour).
 10VDU&11,&03
COS See ACS.
COUNT Not supported by TURBO.
DATA Not supported by TURBO. Data can be stored in an area of memory by a BASIC program, which can then be accessed by the compiled program.
DEF Procedures and functions are not supported by TURBO. Use GOSUB instead.
DEG See ACS.
DELETE May be used as normal for editing source.
DIM Since arrays are not supported by TURBO, this statement is not used. An array could be set up in memory by storing strings with a set gap between them, and then calculating the address of any element within the program.
DIV To divide numbers, a form of repeated subtraction must be used. The following example divides A% by B%, stores the answer in C% and stores the remainder in A%.
 10LETC%=&00
 20LETD%=A%
 30LETD%=D%-B%
 40IFD%>A% THEN80
 50LETA%=D%
 60LETC%=C%+&01
 70GOTO30
 80END
DRAW This may be done using the VDU command. To do DRAW650,970 you must first convert the values to hexadecimal. 650=&028A and 970=&03CA. So to do the command in TURBO BASIC, use:
 10VDU&19,&05,&8A,&02,&CA,&03
ELSE This cannot be used. Split any IF/THEN statements into several lines instead.
END Use as normal.
ENDPROC See DEF.
ENVELOPE The easiest way to use this command is to use it in a normal BASIC program before the compiled section is called. To use it directly from compiled code, you must first set aside an area of memory which is 14 bytes long. The first location contains the envelope number, and the next 13 locations contain the other parameters. Once the data has been stored, the following CALL must be done: A% must contain &08, X% the low byte of the address of the parameters, and Y% the high byte of the parameters' address. For example, if the 14 bytes started at address &2F54,
 10LETA%=&08
 20LETX%=&54
 30LETY%=&2F
 40CALL&FFF1
EOF# See BGET#.
EOR Two 8 bit numbers may be Exclusive ORed together and stored in a variable. You can use this function to get negative numbers by Exclusive ORing the number with &FF and then adding 1.
 10LETF%=G%EORH%
ERL Cannot be used as part of a compiled program.
ERR See ERL.
EVAL Not supported by TURBO.
EXP Not supported by TURBO. Could be done by BASIC program prior to calling compiled code.
EXT# Not supported by TURBO.
FALSE The number 0 should be substituted for FALSE.
FN See DEF.
FOR FOR/NEXT loops may not be nested in TURBO. If youre require nested loops, subsequent loops should be done using IF/THEN statements. Step size is always +1. Note that if the first number is larger than the second, the loop will increase to &FF then zero, one, etc. You can use any one of the following forms of the FOR statement:
 10FORA%=&01TO&09
 20FORA%=B%TO&09
 30FORA%=&01TOC%
 40FORA%=B%TOC%
GCOL This can be done with the VDU command, e.g. GCOL 0,5 would be:
 10VDU&12,&00,&05
GET May be used as follows:
 10LETA%=GET
GET$ Use GET instead.
GOSUB This may be used as normal except that calculated line numbers are not allowed.
GOTO This may be used as normal except that calculated line numbers are not allowed.
HIMEM May not be used in a compiled program, but can be used as a direct command.
IF This may be used in the listed forms. Note that only line numbers may follow the THEN. ELSE is not supported.
 10IF A%>&0D THEN 90
 20IF B%>C% THEN 100
 30IF D%<&38 THEN 200
 40IF E%<F% THEN 170
 50IF G%=&5A THEN 180
 60IF H%=I% THEN 221
 70IF J%<>&21 THEN 222
 80IF K%<>L% THEN 196
Also note that unlike the normal BBC BASIC the less than test (<) actually tests for less than or equal to (<=).
INKEY Use the format below. If a negative number is required then subtract the number from &FFFF and add 1.
 10LETA%=INKEY(&0005)
INKEY$ Use INKEY instead.
INPUT This command is not supported by the compiler, but using the following method a string may be entered. First, allocate a page of memory into which the input will go (e.g. &7000 to &70FF). Also set aside five bytes as a control block (eg &7100 to &7104). The first byte of the control block is the low byte of the input area address, the second byte is the high byte of the input area address. The third byte is the maximum allowed length and the fourth byte is the maximum acceptable ASCII value. The fifth byte contains the maximum acceptable ASCII value.
 10LETA%=&00
 20A%?&7100=&00
 30A%?&7101=&70
 40A%?&7102=&FF
 50A%?&7103=&20
 60A%?&7104=&FF
 70LETA%=00
 80LETX%=&00
 90LETY%=&71
 100CALL&FFF1
Note that before the CALL is issued, A% should be set to &00, X% should be set to the low byte of the control block's address, and Y% should be set to the high byte of the same address.
INPUT# This cannot be used in a program. If necessary, input from files can be done, but it is quite compilcated. It is recommended that BGET# be used instead. More information on files can be found in the User Guide.
INSTR This function is not supported by TURBO. To perform this function a byte by byte comparison of strings would have to be done. The best way is to find the length of the string being searched for and then, using MID$, take out sections of the larger string of the same length and compare this with the string being searched for.
INT All numbers used by TURBO are integers anyway.
LEFT$ Not recognised by the compiler. To do A$=LEFT$(B,5), use:
 10LETA%=&01
 20LETB%=&05
 30$&4000=MID$($&3F00,A%,B%)
LEN Not recognised by the compiler. To find the length of a string at &3000, use the following routine. A% contains the length of the string on exit.
 10LETA%=&00
 20LETB%=A%?&3000
 30IFB%=&0DTHEN60
 40LETA%=A%+&01
 50GOTO20
LET The use of LET is obligatory for the types of commands listed below:
 10LETA%&06
 20LETB%=C%
 30LETD%=E%+&37
 40LETD%=F%+D%
 50LETE%=E%-&02
 60LETH%=I%-J%
 70LETK%=D%EOR&FA
 80LETL%=H%EORI%
 90LETM%=K%AND&AE
 100LETN%=M%ANDX%
 110LETO%=Q%OR&14
 120LETP%=P%ORT%
 130LETQ%=GET
 140LETR%=INKEY(&FFFF)
 150LETS%=T%?&3000
 160LETT%=A%?D%
LIST May be used normally to list the source program.
LISTO See LIST.
LN See EXP.
LOAD May be used normally to load the source program. See SAVE for further details.
LOCAL Cannot be used. See DEF.
LOG See EXP.
LOMEM See HIMEM.
MID$ To use this command you must first set two variables and use them in the command. Note that unlike normal BBC BASIC the statement must be given in full.
 10LETA%=&04
 20LETB%=&07
 30$&6000=MID$($&3500,A%,B%)
MOD See DIV.
MODE Use as normal.
MOVE This command may be achieved using the VDU command (see DRAW). Thus MOVE 300,400 would become:
 10VDU&19,&04,&2C,&01,&90,&01
(decimal 300 = &012C, decimal 400 = &0190)
NEW Use as normal.
NEXT Use as normal.
NOT This may not be used. Alter test conditions instead.
OLD Use as normal. If BREAK has been pressed, don't forget to reset PAGE first.
ON Cannot be used. Use IF/THEN instead.
OPENIN This may be used as follows: A% must be set to &40. X% and Y% must be set to the low and high bytes of the address of the name of the file. For example, suppose the name of the file was TEST and this was stored at &2FF4. The channel number allocated will be returned in A%.
 10LETA%=&40
 20LETX%=&F4
 30LETY%=&2F
 40CALL&FFCE
OPENOUT This is the same as OPENIN except that A% must be set to &80.
OPT This may not be used as assembly code cannot be inserted in BASIC code to be compiled.
OR Two 8 bit numbers may be ORed together as normal, e.g.
 10LET5%=T%OR&52

To use OR in an IF/THEN statement, the statement should be split, e.g.
 10IFD%=W%ORD%=V%THEN100
would become
 10IFD%=W%THEN100
 20IFD%=V%THEN100
PAGE This may be used as a direct command, but not in compiled code.
PI This constant may not be used. Any calculations involving PI would have to be done in a BASIC program prior to calling the compiled code.
PLOT This can be achieved using the VDU command. See DRAW for further details. PLOT85,1280,670 would become:
 10VDU&19,&55,&00,&05,&9E,&02
POINT This command is not recognised by the compiler. To achieve the same effect, (e.g. A%=POINT(500,600) first convert the co-ordinates to the hexadecimal (500=&01F4, 600=&0258). Then set aside a five byte control block as follows:

Byte 1: low byte of X co-ordinate
Byte 2: high byte of X co-ordinate
Byte 3: low byte of Y co-ordinate
Byte 4: high byte of Y co-ordinate
Byte 5: the logical colour will be returned here

In our example the control block is at &2FF0-&2FF4. Then you must set A% to &09, X% and Y% to the low and high bytes of the control block's address, and make the appropriate call. R% will contain the logical colour of the point, or &FF if it is off the screen.

 10LETV%=&00
 20V%?&2FF0=&F4
 30V%?&2FF1=&01
 40V%?&2FF2=&58
 50V%?&2FF3=&02
 60LETA%=&09
 70LETX%=&F0
 80LETY%=&2F
 90CALL&FFF1
 100LETR%=V%?&2FF4
POS Both POS and VPOS can be used as follows. Note that A%=&86 and that on exit from the call X% is set to the co-ordinate and Y% is set to the Y co-ordinate.
 10LETA%=&86
 20CALL&FFF4
PRINT The following forms of the PRINT statement may be used. The basic elements may be combined in any order up to a maximum line length of 255 characters.

The only exceptions are that CHR$ may not follow &hhhh directly, and the semi-colon (;) may only be used at the end of a statement.

 10PRINT
 20PRINT;
 30PRINTCHR$(&45)
 40PRINT"hello"
 50PRINT$&2E80
PRINT# It is recommended that BPUT# is used instead. See INPUT# for further information.
PROC See DEF.
PTR# This may not be used.
RAD See ACS.
READ See DATA.
REM Use as normal.
RENUMBER Use as normal.
REPEAT This function is not allowed. Use IF/THEN instead.
REPORT See ERL.
RESTORE The user must keep track of his own data pointers. (See DATA)
RETURN Use as normal.
RIGHT$ MID$ should be used instead. See LEFT$.
RND This function cannot be used in a program to be compiled. There are however several ways to obtain random numbers in your programs. The first is to store a series of random numbers in a reserved area of memory from a BASIC program before calling the compiled code. For example:
 FORa=&2F00TO&2FFF:?a=RND(6):NEXT
would store random numbers from 1 to 6 between address &2F00 to &2FFF. The second method is to construct some form of random number algorithm. In the following example A% and B% must be seeded first; the new random number is stored in B%. The cycle length for generating random numbers using this example is quite short so use with caution.
 10FORE%=&00TOA%
 20LETF%=C%+B%
 30IFF%>C%THEN60
 40IFF%>B%THEN60
 50LETD%=D%+&01
 60LETC%=F%
 70NEXTE%
 80LETA%=B%
 90LETB%=C%AND&F0
 100LETC%=D%AND&0F
 110LETB%=B%+C%
The third method is to CALL the random number generator in BASIC then PEEK the locations where the numbers are stored, but this method is not recommended as the two versions of the BBC BASIC use different locations and the program would not run on all other machines.
RUN The compiled form of the program cannot be RUN, it must be CALLed instead.
SAVE Your source program may be saved as normal. Saving the compiled code is slightly more complex. You must first find the end of the compiled code. This can be done by peeking locations &70 and &71. If &70 contained &E7 and location &71 contained &2E, the end of your program would be at &2EE7. To find the contents of &70 and &71 in hexadecimal, type:
 PRINT ~?&70,~?&71
At the start, you told the computer where to store the compiled code. This was probably &2200 (for the tape version) but you may have changed it. This is the start address of your program. You can now save it as follows:
 *SAVE programname 2000 2EE7 2200
To reload the compiled code, simply type *LOAD programme. If the program consists entirely of compiled code, you can use the *RUN command. Once the source code is compiled it is completely independent of the compiler.
SGN This may not be used.
SIN See ACS.
SOUND This may be used as normal, except that all the parameters must be written as hexadecimal numbers (four digits). Thus SOUND 1,-13,42,10 will become:
 10SOUND&0001,&FFF3,&002A,&000A
If variable parameters are required, then a call with A% set to &07 and CALL &FFF1 would have to be made. A parameter block similar to that used for the ENVELOPE command would have to be set up first. See User Guide for more information.
SPC Either make up a string of spaces and use MID$ to print a part of it or use a loop to print CHR$(20).
SQR See EXP.
STEP Cannot be used. All steps are +1. If another step is required, use LET in conjunction with IF/THEN statements.
STOP Use END instead.
STR This function is not provided. To store a number as a string the number must first be converted into 3 decimal digits. To do this, first subtract as many hundreds as possible and then tens and finally units, and store each of these three numbers separately. Then add 48 to each of the three to convert them to the ASCII codes for the numbers. The numbers can then be stored in a convenient area of memory, followed by a &0D (carriage return). This is now a string.
STRING$ This function cannot be used, instead you should repeatedly use the string as required.
TAB To print the following:
 PRINTTAB(A%,20)"Hello"
use the following statement:
 10PRINTCHR$(&1F)CHR$(A%)CHR$(&14)"hello"
TAN See ACS.
THEN Use as normal but must be followed by a line number. See IF.
TIME The value of TIME may be written to, or read from. First allocate an area of five bytes (e.g. &2F00). These bytes will contain the new value when being written. X% and Y% must be set to the low and high bytes of the address of the control block, and A% must be set to &01 to read, or &02 to write. The time is stored from least significant byte to most significant byte.
 10LETX%=&00
 20LETY%=&2F
 30LETA%=&01
 40CALL&FFF1
TO Use as normal.
TOP May not be used in a program which is going to be compiled.
TRACE This cannot be used.
TRUE This cannot be used.
UNTIL See REPEAT.
USR Use CALL instead.
VAL This function is not provided. To convert a string to a number, use the reverse of the procedure described for STR$.
VDU Use as normal, except that numbers must be in hexadecimal and double byte numbers are not allowed. Some examples are:
 10VDUA%,B%,C%,D%,&20
 20VDU&11,&03
 30VDU&17,&34,&53,&F2,&8A,&23,&00,&05,&91

PEEK and POKE
As normal in BBC BASIC, the commands PEEK and POKE are represented by a "?". The contents of a memory location may be read by using one of the two forms provided:

 10LETV%=A%?&3000
 20LETV%=A%?C%

The first looks at location A%+&3000 and stores the contents in V%. The second stores the contents of location A%+C% in V%. In this second form, the third variable is special in that it is a double sized variable and can thus have a range of 0-65535. This means that by altering this variable, the user can look at any location; it also makes movement of large areas of memory easier. To alter C% in the second example, both C% and D% must be altered. (See double sixed variables for more information.)

Storing values in memory locations can be done in one of the following four ways:

 10A%?&555E=&26
 20A%?&432C=F%
 30B%?T%=&75
 40F%?Q%=E%

The first two examples are the same as normal BBC BASIC. The third and fourth examples use double sized variables (in this case T% and Q%) as described above.

APPENDIX 2 TURBO Memory Locations

  Tape Disk
Minimum setting of PAGE: &1500 &1500
Default code position: &2200 &2800
Address to change if PAGE not &1500: &D20 low byte
&D21 high byte
&1920 low byte
&1921 high byte
Address to change code position: &D1E low byte
&D1F high byte
&191E low byte
&191F high byte
Location of Turbo Compiler: &D00-&1500 &1900-&2100
Location of A% to Z%: &76-&8F &76-&8F

APPENDIX 3 Sample BASIC/Machine Code Hybrid

Problem: Write a program to print out the word "hello" a random number of times.
Solution: Use the default values for the compile address and set PAGE to &1500 (&2100 for disk users).

Type in the following program which will print "hello" the number of times which A% will be set to.

 10FORB%=&01TOA%
 20PRINT"hello"
 30NEXTB%
 40END

Compile the program in the normal way, then type NEW to remove the source program and type in the BASIC program that follows:

 10?&76=RND(255) set A% to a random number from 1-255
 20CALL&2200 call compiled code to print
 30END

Disk users note that line 20 should read 20CALL&2800

Screenshots

Cover Art Language(s): English
Compatibility: BBC Model B, BBC Model B+, BBC Master 128, Acorn Electron
Release: Professionally released On Cassette
Original Release Date: 1st Sep 1984
Links: Everygamegoing,

Cover Art

Downloads

Turbo Compiler (5.25" Disc)