Locomotive BASIC

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search

For other BASIC language versions see the Category:BASIC


CPC Start Screen showing Locomotive copyright and BASIC version

Locomotive BASIC was a BASIC interpreter for the Amstrad CPC range of computers.

It was availlable directly from in-built ROMs on CPC old generation and on the Plus System Cartridge for the Plus range.

Contents

Description

Locomotive BASIC, was one of the best and fastest BASIC implementations of the era. The language benefited both from a clean, well-thought out implementation of the core language by Locomotive, and by the excellent firmware of the CPC, which lent most of its advanced features to the BASIC.

Unlike the competing Commodore 64, it featured a comprehensive graphic capabilities with its PLOT, DRAW, PAPER, INK, PEN, BORDER and (in BASIC 1.1) FILL commands. It had extensive sound commands, granting control of the AY-3-8912 via the firmware's volume and tone envelope system. With the SOUND command, you could select channels, set envelopes, pitch, noise and volume. That was something unmatched by other computers of that era.

Also there was simple interface for memory management, with MEMORY and LOAD commands. The latter allowed for loading of raw screen data, thus providing easy picture showing. Both through this (combined with CALL, PEEK and POKE) and the firmware's RSX system, it was easy to mix BASIC and assembly code, thereby speeding up programs by coding the slowest parts directly in machine code. Many successful programs, including games such as Radzone and applications such as PowerPage, made use of this technique.

With DEF FN, ON variable GOTO and ON variable GOSUB, Locomotive BASIC provided the rudiments of "structured programming", though nowhere near the extent of the PROCedures of BBC Basic.

All in all, if you compare BASIC interpreters of that era, the Locomotive's seems to be the best 'all-rounder' regarding the combination of speed and complexity, and still some of its features were unmatched by others.

If you are interested in more information about the different versions of the CPC's BASIC and the technical details, you can have a look at the article "Technical information about Locomotive BASIC".

Another helpful and further resource of information about BASIC and a similar comprehension to this is Grimware's Website about the CPC http://www.grimware.org/doku.php/documentations/software/locomotive.basic/start

History

The CPC implementation of Locomotive BASIC was developed directly from Locomotive Software's existing Z80 BASIC. The existence of this is cited as one of the reasons Locomotive requested that Amstrad change the CPC's processor from a 6502 to a Z80.

The 464 shipped with BASIC 1.0 on ROM.

The language was revised and debugged for the 664, 6128 and Plus machines to become BASIC 1.1. Changes were minor but significant for the programmer, and included:

  • DEC$ bug removed (in BASIC 1.0, it required two opening brackets and was undocumented)
  • Better handling of string arguments to RSXs (|DIR,"*.BAS" rather than a$="*.BAS":|DIR,@a$)
  • DATA statements can appear anywhere within a line; in BASIC 1.0, they had to be at the end of a line
  • FILL command (fill area with solid colour)
  • COPYCHR$ function (fetch character from screen)
  • Better garbage collection
  • Some number-handling bugs removed (e.g. in FOR loops with negative start/end values)
  • FRAME (CALL &BD19)
  • Extra, optional 'plotting mode' parameter for DRAW/PLOT commands (supported only through control codes on BASIC 1.0)
  • GRAPHICS PAPER, GRAPHICS PEN commands
  • ON BREAK CONT (disable ESCape)
  • CLEAR INPUT (flush keyboard buffer)
  • The AUTO command show the whole line if it exist, it only printed a * on the 464

Some parts of 'BASIC' were actually housed in the firmware ROM, but were not officially accessible to other programs. This included the line editor.

The 'pure BASIC' parts of Locomotive BASIC - i.e. those not concerned with CPC-specific firmware and hardware features - were upgraded to become Mallard BASIC, the CP/M language shipped with the PCW. This also featured exceptionally advanced random-access file handling, a feature missing from the CPC.

Variables

Real (Floating Point) Numbers

This is the default type for a Locomotive BASIC variables, but can be clarified using ! after the variable name, e.g., real!=500.0. You can force all variables starting with specific letters to be this type by using the DEFREAL keyword. In many cases you don't want to use these, as they are slower than using the integer type, and use more memory (5 bytes, as opposed to 2).

Signed 16-bit Integers

Defined using % after the variable name, e.g., integer%=500. You can force all variables starting with specific letters to be this type by using the DEFINT keyword. These can store values between -32,768 and 32,767. To assign a 16-bit value to a signed integer directly, you should give the number in a hexadecimal format, e.g., uint=&c0000.

Strings

These are defined by using $ after the variable name, e.g., str$="Hello". You can force all variables starting with specific letters to be this type by using the DEFSTR keyword. A String can be up to 255 characters long.

Type Conversions

The BASIC functions ROUND, INT, CINT and FIX can be used to convert real numbers into integers taking some care about rounding. The difference is in rounding mode - ROUND rounds to nearest, FIX rounds to zero, INT always rounds down, and CINTrounds up. e.g., value%=INT(3.14). Note that if you don't specify the % you will actually get a real number still.

To convert an integer to a real number, you can use the UNT function which will take the value supplied and return the two's complement number. e.g., real=UNT(&ABCD).

w=UNT(50000)
Ready
PRINT w
-15536
Ready
█

If you want an integer result from division, use the \ integer division operator. e.g., int=value\divisor. This is as opposed to the standard / division operator, that can create a real number.

Command list

Commands and operators

AFTER ‹time delay›[,‹timer number›] GOSUB ‹line number›

Waits for ‹time delay›/50 seconds and then jumps NON-RECURRING to the subroutine at ‹line number› (see also "EVERY i[,t] GOSUB line").

AUTO [‹line number›][,‹increment›]

Automatically generates line numbers starting at ‹line number› with ‹increment› after each entered line number. Use [ESC] to leave AUTO mode. Default values for ‹line number› and ‹increment› are 10.
Example:
AUTO 100,5 :REM generates line numbers 100, 105, 110...

BORDER ‹colour›[,‹colour›]

Changes the colour of the border. If the second argument is supplied the border flashes between the two colours.

CALL ‹address expression›[,‹list of: parameter›]

Allows a machine code routine to be called by BASIC. Variables, string values and constants can be passed to the routine. Values of any supported type can be passed back by supplying a variable with @ in front of it. This passes the address of the variable to the routine although it doesn't implicitly know the data type.
Example:
CALL 0 :REM resets the computer completely

CAT

Displays the names of the files on the tape or disc. Tape files are displayed in the order they are encountered. Disc files are sorted alphabetically by ACSII code. Only files matching the current user are displayed. Files marked as system are not displayed.
Examples:
CAT :REM lists all disc files in alpha-numeric (ASCII) order
|TAPE :CAT :REM lists names of all tape files in their storage order

CHAIN ‹file name›[,‹line number expression›]

Enables the specified program to be loaded and RUN automatically. If the optional parameter ‹line number expression› is specified, the program execution will commence from that line.

CHAIN MERGE ‹file name›[,‹line number expression› | [,[‹line number expression›],DELETE ‹line number range›]]

Loads the specified program from tape or disc, merges it into the program in memory, and starts execution of the merged program. The parameter DELETE ‹line number range› is used to delete part of the original program before running it, if required.

CLEAR

Clears all variables from memory, leaving the program in memory unchanged. All open files are abandoned.
The command clear inside a subroutine (GOSUB... RETURN) will also clear the "stack pointer" address of the gosub heap. That means that a RETURN won't work and a GOTO has to be used instead.

CLG [‹masked ink›]

Clears the graphics screen to colour specified by ‹masked ink›. If parameter ‹masked ink› is not specified then the graphics screen is cleared to the colour specified by the GRAPHICS PAPER statement.

CLOSEIN

Closes any input file (tape or disc).

CLOSEOUT

Closes any output file (tape or disc).

CLS [#‹stream expression›]

Clears the window specified by ‹stream expression›. If ‹stream expression› is omitted it defaults to #0 (usually the whole screen). The text cursor of the stream is moved to the upper left corner.

CONT

CONTinues program execution interrupted either by [ESC] [ESC] or as a result of STOP within a program. A program cannot be continued after being modified.

CURSOR ‹expression›

‹expression› must be either 0 or 1.

DATA x1[,x2,x3...]

Defines a data section to be used by READ calls.
Data values can be of any type (integer, real or string) as long as the corresponding READ calls use a variable of the right type.
Example:
10 DATA "Hello, world!", 42
20 READ message$:PRINT message$
30 READ answer:PRINT "The answer is:";answer
See also: READ, RESTORE

DEF

DEF means "define" and comes along with defining a function in case of DEF FN or defining variables in case of DEFREAL, DEFINT or DEFSTR.
DEF FN must come before using the statement FN.
DEF with a variable declaration should come before using a variable.
(see also FN)

DEFINT ‹letter range›

Forces all variables(s) starting with the specified letter(s) to be integer variables. Singular letters could be defined or a range by a minus symbol between two letters.
Examples:
20 DEFINT a-z:' sets all variables starting with an A until Z as integer.

or

10 DEFINT F,S ..... (or 10 DEFINT A-Z)
20 FIRST=111.11:SECOND=22.2
30 PRINT FIRST,SECOND:' prints out 111      22

DEFREAL ‹letter range›

Sets the default for variable(s) with the specified first letter(s) to a floating point figure.

DEFSTR ‹letter range›

Sets the default for variable(s) with the specified first letter(s) to string(s) variables.

DEG

Switch to degrees mode for trigonometric functions (SIN, COS...).
See also: RAD

DELETE [first line][-[last line]]

Deletes the current program completely (without arguments) or only the given line or line range. Even
DELETE -
is legal, it has the same effect as
DELETE
The lines specified do not have to exist, all lines matching the range will be deleted and having no matches does not cause an error.

DI

Disables interrupts (but not[ESC]) until re-enabled by EI command or by RETURN at end of an interrupts service routine.
This means that DI (if it's activated in a subroutine) is useful helping a low-priority-interrupt not to be stopped by a higher-priority-interrupt. RETURN then re-enable the interrupt without EI.

DIM a[%|!|$](d1[,d2[,...]])

Creates array a with single or multiple dimensions. You may optionally specify integer (%), real (!) or string ($) type otherwise it defaults to the current type set for the first letter of the array name. d1 is size of first dimension-1, d2 is size of second dimension-1 and so on. DIM x(10) will create an array with 11 elements, x(0) is the first element, x(10) is the eleventh and last. You can specify as many dimensions as will fit on one 255 character line, which is a maximum of 125. Trying to create an array that already exists will generate an Array already dimensioned error. If an array is not specified by DIM before being accessed, each dimension value defaults to 10. The maximum dimensions that can be created this way is three.

DRAW x,y[,[i1][,i2]]

Draws a line from the current cursor position to position x,y. i1 specifies colour, i2 is the drawing style.
4 drawing styles:
i2 = 0 normal colour
i2 = 1 XOR colour
i2 = 2 AND colour
i2 = 3 OR colour
Example:
CLG 2
DRAW 500,400,0 :REM draws a line from 0,0 to 500,400

DRAWR xr,yr[,[i1][,i2]] ====

Draws a line from current graphics cursor position to current cursor x position + xr, current cursor y position + yr. i1 and i2 as DRAW.
Example:
Move 200,200
DRAWR 100,100,0 - draws a line from 200,200 to 300,300

EDIT ‹line›

Copies one program line to screen in edition mode.

EI

Enable interrupts which have been disabled by DI

END

Indicates end of program

ENT ‹tone envelope number›[,‹tone env. section›][,‹tone env. section›][,‹tone env. section›][,‹tone env. section›][,‹tone env. section›]

The ENT command define the TONE shape of a sound which means manipulating the frequency in a certain range.
The command could looks like:
ENT NUMBER,STEPS?,VERTICAL?,HORIZONTAL?
It is possible to define 15 different envelope shapes. So NUMBER could be 1-15.
Each ? stands for up to five sections (1-5), where each STEP<>VERTICAL<>HORIZONTAL with the same ? are belong together.
STEP: means how many steps in each section (0-127) > one step is 1/100 of a second!
VERTICAL: means how big is the step size from bottom to top (-128 to 127)
HORIZONTAL: means how big is the step size from left to right (0-255)

ENV ‹volume envelope number›[,‹volume env. section›][,‹volume env. section›][,‹volume env. section›][,‹volume env. section›][,‹volume env. section›]

The ENV command define the VOLUME shape of a sound which means manipulating the loudness in a certain range.
The command could looks like:
ENV NUMBER,STEPS?,VERTICAL?,HORIZONTAL?
It is possible to define 15 different envelope shapes. So NUMBER could be 1-15.
Each ? stands for up to five sections (1-5), where each STEP<>VERTICAL<>HORIZONTAL with the same ? are belong together.
STEP: means how many steps in each section (0-127) > one step is 1/100 of a second!
VERTICAL: means how big is the step size from bottom to top (-128 to 127)
HORIZONTAL: means how big is the step size from left to right (0-255)

ERASE v1[% | ! | $][,v2[% | ! | $][,...]]

Erases the specified array(s) and frees the memory used. Must specify existing array(s) or an Improper argument error will be generated.

ERL

Returns the line number of the last error encountered.

ERROR i

Returns the error message whose error code number is i.

EVERY i[,t] GOSUB ln

BASIC branches to the subroutine at line ln EVERY (reccuring) i/50 seconds. (see also "AFTER i[,t] GOSUB line")
There are 4 delay timers from 0 to 3 which can be specified with ‹timer number›. If omitted ‹timer number› defaults to 0.
In the case of parallel task has 3 the highest and 0 the lowest priority.
With DI or EI you can disable or enable the timing interrupt. With REMAIN <timer number> you can also disable an AFTER or EVERY construct and stores the "remaining" time (> REMAIN)
Interrupts run as long as the main loop / program runs, even the main programm is paused > press ESC only once not twice for a break.
It is important to know or realise that low-priority-interrupts which occurs simultanously to higher-priority-interrupts are not lost. Their task remains or handled again after finishing the higher-prio interrupt.
10 REM > interrupts
20 EVERY 50,0 GOSUB 100: REM > lowest priority
30 EVERY 100,1 GOSUB 200
40 EVERY 200,2 GOSUB 300:
50 AFTER 1000,3 GOSUB 400: REM > highest priority
60 WHILE flag=0
70 a=a+1:print a
80 WEND
90 END
100 REM #0
110 PEN 2:PRINT "timer 0":PEN 1
120 RETURN
200 REM #1
210 PEN 2:PRINT "timer 1":PEN 1
220 RETURN
300 REM #2
310 PEN 2:PRINT "timer 2":PEN 1
320 RETURN
400 REM #3
410 flag=1:PEN 2:PRINT "no more interrupts..."
420 RETURN
Hint: Timing with interrupts is important, especially if more than one interrupts run. If the interval of a subroutine driven by an interrupt is too long than the processor can never get back to deal the main program again. Work out timing by measuring the subroutine or by trial and error.
There are system internal interrupts (highest level) which cannot be influenced by BASIC interrupts (e.g. keyboard scan > BREAK key.)
The next level of sytem internal interrupts CAN be influenced by BASIC interrupts. For example the sound queue which will be created by "ON SQ <chanel> GOSUB <line>". Those sound interrupts have an independent time tricker but their priority is parallel to the second priority times of BASICs interrupts. Therefore interrupts with timer 3 could "interrupt" them.

FILL i

Fills an area of a graphics screen i colour i (0-15). Default value of i is the current graphics pen colour. Only available in Basic 1.1.

FN

BASIC allows the program to define and use simple value returning functions. DEF FuNction is the definition part of this mechanism and creates program-specific function which works within the
program in the same way as a function such a COS operates as a built-in function of BASIC. It may be invoked throughout the program. Variable types must be consistent and the DEF FN
command should be written in part of the program outside the execution loop.
Syntax : DEF FN<name>[(<formal parameters>)]=<general expression>
Example: "with the definition of..."
10 gn=9.80665
20 DEF FNgrv=s0+v0*t+0.5*gn*t^2
30 s0=0:v0=0:t=5
40 PRINT "...after";t;"seconds your dropped stone falls";FNgrv;"metres"
"the results are..."
:...after 5 seconds your dropped stone falls 122.58315 metres

FOR TO STEP NEXT

Creating a counting loop (control strucutre) with a starting condition. Inside the counting loop one or more commands will be executed.
The loop consists of of following specifications:
1. FOR
2. a control variable
3. =
4. starting value
5. TO
6. target value
7. STEP [optional]
8. increment / step size
... instructions between
9. NEXT
10. control variable [optional]
You have to use the command STEP if you wish to count backwards. It's good to name the control variable after NEXT for readability and better program style.
After each loop the computer checks internaly if the target value has been reached (like an IF ... THEN ... ELSE instruction). If the target value is reached NEXT closes the loop and calculates another step, so the control variable will be changed last time.
The default STEP value - if not specified - is one (1).
Example:
10 FOR I=1 TO 10
20 PRINT I;
30 NEXT I
40 PRINT I
RUN
1   2   3   4   5   6   7   8   9   10   11
READY

FRAME

Smooths character and graphics movement and reduces flicker (waits for a VSYNC signal). Only available in Basic 1.1. On a CPC 464 you can use CALL &BD19 instead.

GOSUB i

Jumps to subroutine which is given as argument.
Example:
10 PRINT "Calling subroutine"
20 GOSUB 100
30 PRINT "Back from subroutine"
40 END
100 REM Begin of the subroutine
110 PRINT "Subroutine started"
120 RETURN

GOTO i

Jumps to the line number which is given as argument.
Example:
10 GOTO 100
20 REM not executed
30 REM not executed
100 PRINT "Hello World!"
GOTO is the simplest form of a jump or creating a loop without condition controll.
Example: (unconditional and endless loop)
10 PRINT "#";
20 GOTO 10
Combine the GOTO command with an IF...THEN...ELSE instruction for creating a condition-controlled loop with the test at the end. Helpful because the Locomotive Basic has no practical DO...WHILE... loop.
Example: (condition at the end)
10 I=1
20 PRINT I
30 I=I+1
40 IF I<25 THEN GOTO 10
50 END

GRAPHICS

...works only in combination with the command PEN or PAPER to set the plotting/drawing pen or background colour.
If the TAG command is used to set text at the graphics cursor GRAPHICS PEN or GRAPHICS PAPER instead of the regular PEN or PAPERis necessary to colour the text.

IF THEN ELSE

Asks for a choice with the IF...THEN...ELSE statement.
IF compares the entry condition in a logical way
THEN contains instruction if the comparison is true
ELSE contains instruction if it's false.
Example:
10 INPUT "guess a figure:",f
20 IF f=10 THEN PRINT "right": END: ELSE GOTO 10
In case of nested choices there's a possibility to that with an IF...THEN instruction but not very recommended:
10 INPUT "guess a figure:",f
20 IF f=10 THEN PRINT "right": END: ELSE IF f<10 THEN PRINT "too small" ELSE PRINT "too big"
30 GOTO 10
Other nested structures like IF...THEN...ELSE...ELSE won't work first because the Locomotive Basic only looks after the first ELSE instruction found and can't execute more single commands as a block for a certain condition in comparision to e.g. "PASCAL" > begin...end-block, "C" > {...}-block.

INK

[...]

INPUT[#‹stream expression›][,]

[...]

KEY

[...]

LET

Used to define variables. You don't need to use the LET command because it is just a command which was added for compatibility reasons.
Example:
10 LET a$ = "hello world"
20 PRINT a$

LINE INPUT [#‹stream expression›][,]‹variable›[,‹variable›]

[...]

LIST [‹line number›][-[‹line number›]], [#‹stream expression›]

A command for listing the Basic program code.
Possibility for manipulating display is using line numbers with a minus symbol.
Example:
LIST 100-
List every line after line number 100.
LIST -100
List every line until line number 100 has reached.
LIST 100-200
List every line between line number 100 and 200 included
With the help of seperate window definitions it is possible to print out long listings, better differents parts / slices of it into different window predefined
Example:
LIST 1000-1100,#1
LIST 3000-3100,#2
...prints out two parts of one program out into two windows (if they are defined well)

LOAD ‹file name›[,‹address›]

[...]

LOCATE[#‹stream expression›][,] x,y

Moves the text cursor to the x,y location.
x starts at 1 on the left and goes up to 20 (in mode 0), 40 (in mode 1) or 80 (in mode 2).
y starts at 1 at the top and ends at 25 at the bottom.

MASK [i1][,i2]

Sets bits in each adjacent group of 8 pixel on (1) or off (0) according to binary value of i1 (0-255). i2 determines whether the first point of the line is to plotted (1) or not (0).
Example:
10 CLG 2:MASK 1:MOVE 0,0:DRAW 500,400
20 MASK 15:MOVE 0,0:DRAW 500,400

MEMORY ‹memory address›

Allocates the amount of memory to be used by BASIC by setting the address of the highest byte it may use.

MERGE

[...]

MID$ (‹string›,‹start position›[,‹length of substring›])

With the MID$ command there are two applications possible:
1. MID$ creates a new substring out of the give ‹string› and starts at the defined position ‹start position› and print the number of given characters by ‹length of substring›.
If no length is defined every character from ‹start position› will be printed out.
If a higher value of ‹start position› or ‹length of substring› than the real length of the initial string is defined a blank string will be printed.
The range of ‹start position› or ‹length of substring› is from 0 up to 255 characters.
2. With MID$ you're able to manipulates given strings by inserting a new string.
Take care of the two different applications and using in BASIC.


Example for the 1. application:
10 a$="Hello"
20 PRINT MID$(a$,2,2)
run
el
Ready
Example for the 2. application
10 a$="Hello"
20 MID$(a$,2,3)="ipp"
30 PRINT a$
run
Hippo
Ready

MODE

Changes the screen mode: MODE 0 is 160x200 in 16 colors, MODE 1 is 320x200 4 colors, MODE 2 is 640x200 2 colors and MODE 3 is 160x200 in 4 colors.

MOVE x,y [[,i1][,i2]]

Moves the graphic cursor to position x,y. The parameter i1 may be used to change the pen (drawing) colour. The parameter i2 specifies the logical colour, as in DRAW.
4 drawing styles:
i2 = 0 normal colour
i2 = 1 XOR colour
i2 = 2 AND colour
i2 = 3 OR colour

MOVER xr,yr[,[i1][,i2]]

moves the graphic cursor (relative) from current position to current cursor x position + xr, current cursor y position + yr. i1 and i2 as in MOVE.

NEW

Clears BASIC RAM which means program and variables. Keeps symbol defintion (if defined) and screen mode without clearing.

ON BREAK CONT

Prevents the interruption of program execution by the ESC key.

ON BREAK GOSUB ln

Passes control to subroutine at line ln when ESC ESC pressed.

ON BREAK STOP

Restores normal function of ESC key during program execution.

ON ERROR GOTO ln

Passes the control to line ln if an error is detected in the program.
ON ERROR GOTO 0, Turns of the error trap, and restores normal error processing.

ON variable GOTO ln x1, x2, x3, x4, ...

In case of passing more choices ON variable GOTO ln x1, x2, x3, x4, ... points to a table with the jumping target.
Example:
10 PRINT "1. LOAD - 2. SAVE - 3. EXIT"
20 INPUT choice
30 ON choice GOTO 1000, 2000, 3000
40 CLS: GOTO 10
1000 PRINT "1. LOAD":END
2000 PRINT "2. SAVE":END
3000 END
In case that the variable choice won't fullfil the condition (in a range between line 0 and 65535) the next instruction will be executed (here: Line 40). If "choice" is smaller than 0 an error will occur.

ON variable GOSUB ln x1, x2, x3, x4, ...

In case of passing more choices targeting to SUBROUTINES ON variable GOSUB ln x1, x2, x3, x4, ... points to a jumping table.
Example:
10 PRINT "1. LOAD - 2. SAVE - 3. EXIT"
20 INPUT choice
30 ON choice GOSUB 1000, 2000, 3000
40 CLS: GOTO 10
1000 PRINT "1. LOAD":RETURN
2000 PRINT "2. SAVE":RETURN
3000 END
In case that the variable choice won't fullfil the condition (in a range between line 0 and 65535) the next instruction will be executed (here: Line 40). If "choice" is smaller than 0 an error will occur.

ON SQ(x) GOSUB ln x1, x2, x3, x4, ...

ON SQ(x) can trigger an interrupt when e.g. a space or free channel in queue.
Using that command is a one way interrupt trigger and shouldn't be mixed with EVERY or AFTER commands.
See also the SQ(x) command for more details.

==== OPENIN ‹filename› ====: Opens the specified data file for reading. It have to be an ASCII file. ( The command closein closes reading data file. ): The stream number followed by <command>INPUT</command> has to set to #9.

OPENOUT ‹filename›

Opens the specified data file for writing. It writes an ASCII file. (To close writing use the command closein.)

ORIGIN x,y[,l,r,t,b]

The command defines the origin ('world reference point') for the graphics coordinate system. Normally the reference origin is in the left, bottom corner of the default screen and has 0,0. So the most left coordinate value could be by default 639 and the most top value 399. Independent from the actual modus (2, 1 or 0) the range for the x coordinate are always 640 points and for the y coordinate 400 points. In theory you are able to address 256,000 pixel but only 128,000 are visible due to the maximal resolution of the hardware.
x,y are the the new coordinates for the 'world reference '.
l,r,t,b are optional and set the borders for the new graphical window (works in the same way like the WINDOW command for a text window). l,r,t,b means left, right, tob and bottom coordinates.
If a new graphical window (borders) is defined every point or drawn line won't be plotted (clipped internally).
Example (the line drawn will be cutted):
ORIGIN 320,200,250,450,100,300
DRAW 0,200

OUT ‹address›,‹value›

Outputs a value (range of 0-255) to a specific I/O address.
Watch out http://cpcwiki.eu/index.php/I/O_Port_Summary

PAPER[#‹stream expression›][,]

[...]

PEN[#‹stream expression›][,]

[...]

PLOT

[...]

PLOTR

[...]

POKE add

Alters contents of memory location add to value i (0-255)

PRINT[#‹stream expression›][,]

[...]

RAD

Switch to radians mode for trigonometric functions (SIN, COS...).
See also: DEG

RANDOMIZE [seed]

Resets the pseudo-random generator to the given seed (starting value of the 'random' series). What is strange is that if no seed is given, one is interactively prompted for.
A common idiom to have a random random seed is to do:
RANDOMIZE TIME
RANDOMIZE TIME isn't still a 'real' random number but to hit the same series again is pretty hard due to the time elapsed.
The algorithm used for randomizing is the following: the generator starts with the seed, adds 1, multiplies by 75 (fiddle factor), divides by 65537 and then uses the remainder -1.

READ variable

Gets the next data item (from DATA commands), stores it in the given variable and moves to the next item.

The variable must be of the correct type.

See also: DATA, RESTORE

RELEASE chanel

Releases a sound which was hold on (by a SOUND command) before. It uses the same bit matrix like the SOUND command for the first parameter
  1. (&x00000001) releases chanel A
  2. (&x00000010) releases chanel B
  3. (&x00000011) releases chanel A and B
  4. (&x00000100) releases chanel C
  5. (&x00000101) releases chanel A and C
  6. (&x00000110) releases chanel B and C
  7. (&x00000111) releases chanel A, B and C
Example:
10 SOUND 65,1000,100
20 PRINT"PRESS R TO LET IT SOUND"
30 IF INKEY(50)=-1 THEN 30
40 RELEASE 1

REM [any text]

Introduces a comment.

RENUM [‹newLine›][,‹oldLine› | ,[‹oldLine›],‹step›]

Renumbers the lines of the current program.
By default, the whole program is renumbered starting at line 10 with multiples of ten. Any parameter that is left out defaults to 10. It is important to note that jumps (GOTO, GOSUB and the like) are automatically converted to the new line numbers.
The whole set of parameters can be used to renumber only the last part of a program.
Example:
10 GOTO 20
20 GOTO 30
30 GOTO 10
becomes, after calling RENUM 100,20,5
10 GOTO 100
100 GOTO 105
105 GOTO 10

RESTORE [line]

Resets the data pointer used by READ. When used without parameters, resets the pointer to the first data in the program. Otherwise, resets the pointer to the given line number.
Example:
10 DATA 10,11,12,13,14
20 DATA 20
READ i:PRINT i
 10
Ready
READ i:PRINT i
 11
Ready
RESTORE
Ready
READ i:PRINT i
 10
Ready
RESTORE 20
Ready
READ i:PRINT i
 20
Ready


See also: DATA, READ

RESUME [line] or NEXT

Command causes the program to resume after an error code and if it is interrupted by an ON ERROR GOTO jump
So it can either resume
  • (if there's no line number stated) at the same line after error code (and if there are more statements in one line)

or

  • at the line number stated (optional)

or

  • with the NEXT parameter (optional) ... at the line followed by the error line

RETURN

Terminates a subroutine and returns control to the line following the GOSUB call (see GOSUB)

RUN [line] or "filename"

Runs the current program, optionally starting at a given line. If no line number is given, starts at the first line.
If a string is used after RUN command a programm will be loaded and executed from storage medium (e.g. Tape, Disc). With that command protected BASIC programs can be executed.
Exampel:
RUN"disc"

SAVE "filename" [,filetype][,paramter1,parameter2,parameter3]

Command saves the current BASIC program / content from RAM onto a storage medium (e.g. Tape, Disc)
Filetype could be:
  • ,A for a ASCII file
  • ,B for a binary file (store RAM content as it is)
  • ,P for a regular, protected BASIC file
without that parameter the content will be stored as a regular BASIC file
The three parameters after filetype could be used in combination with the binary filetype (,B).
  • parameter1 defines the starting address of memory range
  • parameter2 defines the length (range of memory)
  • parameter3 defines the entry point (optional)

SOUND

the SOUND command has following shape:
SOUND Channel,Period,Duration,Volume,Volume-Envelope,Tone-Envelope,Noise
C: Selecting channel is done bitwise (combinations are possible of course):
(Bit 0) &x00000001 = 1 = channel A (middle)
(Bit 1) &x00000010 = 2 = channel B (left)
(Bit 2) &x00000100 = 4 = channel C (right)
more function about channel are
(Bit 3) &x00001000 = 8 = Rendezvous with channel A
(Bit 4) &x00010000 = 16 = Rendesvous with channel B
(Bit 5) &x00100000 = 32 = Rendesvous with channel C
(Bit 6) &x01000000 = 64 = Hold
(Bit 7) &x10000000 = 128 = Flush
P: the period number can be a figure between 0 and 4095 (2^12-1... 12 means that we have 12 tones (inclusive half-tones) in nine octaves on the CPC in sum and their distance between is the twelves square root of two), where 8 octaves are available. E.g. Octave 0 starts on middle C with number 478.
To calculate the period you can use following formula: period=1,000,000/(16*frequency) or in short period=(65,000/frequency)
(e.g. the note "A" with the frequency 440 Hz has the period 142 on the CPC)
D: the duration of the note is measured in 1/100th of a second and can be any positive number in the range 1-32,767. 0 and negative number are in combination with ENT and ENV commands usefull. A negative number means repititions.
V: the volume number range from 0-7 on a CPC 464 (BASIC 1.0) or 0-15 on a CPC664/6128 (BASIC 1.1)
ENV: and ENT: For shaping the sound ENV (Volume) and ENT (Frequency) commands are available. The relation between SOUND and those commands comes with a figure between 1 to 15 for ENV (5th parameter) and 1 to 15 for ENT (6th parameter).
N: the seventh parameter can be used for blending in noise between the range of 0-15 (BASIC 1.0) or 0-30 (BASIC 1.1). The higher the number the 'deeper' or 'dirty' is the noise.

SPC <n>

in conjunction with PRINT the SPC command prints out a certain number (n) of spaces.
Example:
PRINT "Hello";SPC(10);"World";
Hello          World

SPEED <n1,n2>

...in conjunction with the INK command SPEED defines the frequency of colour changes if a colour change was defined. The duration is calculated by n1=... or n2 =duration/50 seconds.

SQ (channel)

Returns a bit significant integer showing state of the sound queue for specified channel where channel 1,2,3, = A, B, C
Bits 0,1 and 2 Number of free entries in the queue
Bits 3,4 and 5 Redezvous state at head of the queue
Bit 6 Head of the queue is held
Bit 7 Channel is currently active

STOP

Breaks program execution at line containing the STOP statement. The message BREAK in is output with the line number.

SWAP

SWAP works only in combination with the window command. Every error or status messages from the operating system will be displayed normaly on WINDOW#0 (=main window). WINDOW SWAP changes the main window to the desired target window.
Example (if a window with number 4 was defined before...):
WINDOW SWAP 0,4

SYMBOL n,i1[,i2,i3,i4,i5,i6,i7,i8]

Redefines the appearance of the character at index n.
Each of the following eight integers defines the contents of one pixel row, starting at the top of the character.
Each character fits in an 8x8 pixel grid.
Missing lines are considered as empty.
Example:
SYMBOL 255,255,129,129,129,129,129,129,255
PRINT CHR$(255)
Defines character 255 to look like an empty square and prints it.
Initially, only characters with indices ranging from 240 to 255 can be redefined.
See also SYMBOL AFTER to allow redefinition of arbitrary characters.

SYMBOL AFTER n

Allows the redefinition of character symbols from index n included.
Symbol redefinitions are made using the SYMBOL command above.
Initially, only symbols from index 240 to 255 can be redefined. This initial situation can be restored with SYMBOL AFTER 240. Symbol previously redefined are restored to their original appearance.

TAB

[...]

TAG [#st]

Allows text to print at graphics cursor position.
see TAGOFF

TAGOFF [#st]

Directs text to stream st printing it at previous text cursor position.

TROFF

Turns off the program flow trace (see TRON)

TRON

Turns on the program flow trace for debugging. Causes the line number of each statement executed to be displayed.

USING

The USING assignement defines the format of the PRINT output. Its appointment happens by characters where each has a certain meaning.

Numbers / Figures

the character:
# stands for a figure between 0 - 9
. stands for a decimal point
+ generates a positive sign if the value is positive
- generates a negative sign if the value is nagative
** generates a asterix for each empty "location" before the printed character
$$ generates a Dollar characters before the printed character (the same with the pound note)
, generates a comma every each three decimals (thousands per figure) and has to be set before the decimal point or at the end if without a decimal point.
^ generates a scientific notation (with exponents) and a the end of the format appointment

Strings

the character:
! prints out only the first character
\xxx\ prints out only with x-numbers defined length of the string (from left to right). x means a blank sign made with the space bar
& the whole string is printed out as given (unknown function)
a print output (numbers) with "%" in the beginning shows that not enough positions has to be declared (at all or before the decimal point).
Example:
10 figure=123456789
20 word$="Hello"
30 print using "+**,##########";figure
40 print using "\   \";word$

creates following output:

*****+12,345,679
Hel

WAIT add, i1[,i2]

Waits until the I/O port at add returns a value (0-255). The value returned is XORed with i2 and the ANDed with i1. This is repeated until a non-zero result occurs.

WHILE WEND

[...]

WIDTH

[...]

WINDOW[#‹stream expression›],[L],[R],[T],[B]

It is possible to define in BASIC eight (8) independent windows for text output. Overlapping is possible.
#STREAM: eight window are possible. No. zero (0) is the main window where error or status messages were put out by default.
each position is included inside the window
L = left column / R = right column (dependent of the mode 0 = 20 / 1 = 40 / 2 = 80)
T = top row / B = bottom row (always from 1 to 25)
Example:
MODE 1
WINDOW#1,1,40,1,6
...defines the first top quarter of the screen for window No. 1

WRITE [#st,] v[$], v[$]

Writes the values of the specified variable to the specified stream.
Example:
10 OPENOUT "DUMMY"
20 INPUT A$,A
30 WRITE #9,A$,A
40 CLOSEOUT

ZONE i

Changes the width of the print zone. Default is 13.
Example:
10 MODE 2
20 PRINT"normal zone (13)"
30 PRINT 1,2,3,4
RUN
normal zone(13)
1           2            3            4
READY
20 PRINT"now with different zone(5)"
30 ZONE 5
40 PRINT 1,2,3,4
RUN
now with different zone(5)
1     2     3     4
READY

Operators

A logical status in Locomotive Basic will be represented by a "-1" for TRUE and by a "0" for FALSE.
Example:
PRINT (1=1)
-1
PRINT (1=2)
0

AND

Possible combinations with the AND Function:
NPUT1	INPUT2	OUTPUT
======================
TRUE	TRUE	TRUE
FALSE	FALSE	FALSE
TRUE	FALSE	FALSE
FALSE	TRUE	FALSE
Example:
PRINT 128 AND 64
0
looking at the BIT combination for a better understanding:
	10000000
AND	01000000
================
=	00000000
even in BASIC it is possible to manipulate single BITs although there are no special commands but AND, OR and XOR.
first an example for a loop with an increasing counter WITHOUT an AND:
10 counter=0
20 counter=counter+1
30 IF counter=32 THEN counter=0
40 GOTO 20
then a shorter example WITH and AND:
10 counter=0
20 counter=(counter+1) AND 31
30 GOTO 20
in the second example all more significant BITs will be deleted (a common method in assembler programming)
Beware: it only works here with BIT/number conditions one figure smaller than 1, 3, 7, 15, 31, 63 and 127

MOD

[...]

NOT

NOT executes a bit for bit negation of the current value. The output is a 16-Bit-Word.
Example:
10 value1=1
20 value2=NOT value1
30 PRINT value2
run
-2
for a better understanding...
10 value1=1
20 PRINT HEX$(value1):PRINT BIN$(value1,8)
30 value2=NOT value1
40 PRINT HEX$(value2):PRINT BIN$(value2,8)
run
1
00000001
FFFE
1111111111111110

OR

Possible combinations with the OR Function:
NPUT1	INPUT2	OUTPUT
======================
TRUE	TRUE	TRUE
FALSE	TRUE	TRUE
TRUE	FALSE	TRUE
FALSE	FALSE	FALSE

XOR

Possible combinations with the XOR Function:
NPUT1	INPUT2	OUTPUT
======================
TRUE	TRUE	FALSE
FALSE	TRUE	TRUE
TRUE	FALSE	TRUE
FALSE	FALSE	FALSE

Functions

ABS (n)

Returns the absolute value of n by ignoring the sign value.
Example
PRINT ABS(-3.5) - prints 3.5

ASC (s)

Returns ASCII code number of first character of string s

ATN (n)

Returns the arctangent of n.

BIN$ (i1,[i2])

Returns binary representation of i1 between -32768 and 65535. The number of binary digits (0s and 1s) is specified by i2 (0-16)
Example:
PRINT BIN$(66,8) - prints 01000010

CHR$ (n)

Returns the character for a given index n. For instance CHR$(65) returns the character 'A'. Valid indices range from 0 (zero) to 255.
As an example, try the following basic program :
10 print chr$(208+rnd(2));:goto 10
It will draw a random maze with characters 208 and 209, which are an horizontal and a vertical bar.
The CHR$ code between 0 and 31 will not print out a character but perform a function:
===============================================================================
|  VALUE    | NAME   | PARAMETERS   | EFFECT                                  |
===============================================================================
| DEC | HEX |        |              |                                         |
===============================================================================
| 0   | &00 | NUL    | NONE         | DOES NOTHING                            |
| 1   | &01 | SOH    | 0-255        | PRINTS CHARACTER TO SCREEN              |
| 2   | &02 | STX    | NONE         | TURNS TEXT CURSOR OFF                   |
| 3   | &03 | ETX    | NONE         | TURNS TEXT CURSOR ON IN IMMEDIATE       |
|     |     |        |              | MODE                                    |
| 4   | &04 | EOT    | 0-2          | SET SCREEN MODE                         |
| 5   | &05 | ENQ    | 0-255        | PRINT CHARACTER AT GRAPHICS CURS.       |
| 6   | &06 | ACK    | NONE         | TURNS ON TEXT SCREEN (SEE ALSO CHR$(21))|
| 7   | &07 | BEL    | NONE         | MAKE A SHORT BEEP                       |
| 8   | &08 | BS     | NONE         | MOVES TEXT CURSOR BACK ONE CHARACTER    |
| 9   | &09 | TAB    | NONE         | MOVES TEXT CURSOR FORWARD ONE CHARACTER |
| 10  | &0A | LF     | NONE         | MOVES TEXT CURSOR DOWN ONE CHARACTER    |
| 11  | &0B | VT     | NONE         | MOVES TEXT CURSOR UP ONE CHARACTER      |
| 12  | &0C | FF     | NONE         | CLEARS SCREEN OR WINDOWS (= CLS)        |
| 13  | &0D | CR     | NONE         | MOVES CURSOR TO LEFT EDGE OF WINDOW ON  |
|     |     |        |              | CURRENT LINE                            |
| 14  | &0E | SO     | 0-15         | SETS PAPER COLOUR                       |
| 15  | &0F | SI     | 0-15         | SETS PEN COLOUR                         |
| 16  | &10 | DLE    | NONE         | DELETES CHARACTER UNDER TEXT CURSOR     |
| 17  | &11 | DC1    | NONE         | CLEARS LINE FROM LEFT OF WINDOW UP TO   |
|     |     |        |              | AND INCLUDING CURRENT CHARACTER         |
| 18  | &12 | DC2    | NONE         | CLEARS FROM CURRENT CHARACTER TO RIGHT  |
|     |     |        |              | EDGE OF THE WINDOW                      |
| 19  | &13 | DC3    | NONE         | CLEARS FROM START OF WINDOW UP TO AND   |
|     |     |        |              | INCLUDING CURRENT CHARACTER             |
| 20  | &14 | DC4    | NONE         | CLEARS FROM CURRENT CHARACTER TO END OF |
|     |     |        |              | WINDOW                                  |
| 21  | &15 | NAK    | NONE         | TURNS OFF TEXT SCREEN (SEE ALSO CHR$(6))|
| 22  | &16 | SYN    | 0 AND 1      | TURNS TRANSPARENT OPTION OFF AND ON     |
| 23  | &17 | ETB    | 0-3          | SET GRPAHICS PLOTTING MODE              |
| 24  | &18 | CAN    | NONE         | CHANGE TO INVERSE CHARACTER DISPLAYING  |
| 25  | &19 | EM     | NINE PARAM.  | DEFINES A CHARACTER (= SAME AS SYMBOL)  |
|     |     |        | EACH 0-255   |                                         |
| 26  | &1A | SUB    | FOUR PARAM.  | DEFINES A TEXT WINDOW (=SAME AS WINDOW) |
|     |     |        | 1-80, 1-80   | FROM LEFT, RIGHT, TOP TO BOTTOM         |
|     |     |        | 1-25, 1-25   | FROM LEFT, RIGHT, TOP TO BOTTOM         |
| 27  | &1B | ESC    | NONE         | DOES NOTHING ON SCREEN (PRINTER SIGNAL) |
| 28  | &1C | FS     | THREE PARAM. | SETS INK COLOUR TO FLASH BETWEEN TWO    |
|     |     |        | 0-15, 0-32   | INK NO, COLOUR 1, COLOUR 2              |
|     |     |        | 0-32         |                                         |
| 29  | &1D | GS     | TWO PARAM.   | SETS BORDER COLOUR TO FLASH BETWEEN TWO |
|     |     |        | 0-31, 0-31   | COLOURS                                 |
| 30  | &1E | RS     | NONE         | HOMES CURSOR TO TOP LEFT OF SCREEN      |
| 31  | &1F | US     | TWO PARAM.   | MOVES CURSOR TO CELL SPECIFIED BY TWO   |
|     |     |        | 1-80, 1-25   | PARAMETERS (=SAME AS LOCATE)            |
===============================================================================

CINT (n)

Returns rounded up integer value of n between -32768 and 32767.
Example:
PRINT CINT(3.8) - print 4

COPYCHR$ (st)

Copies character from current position in specified stream.

COS (n)

Returns cosine of n in degrees or radians (se DEG and RAD)

CREAL (n)

Converts integer n to real numeric variable.

DEC$(n, format)

Retruns the decimal string representation of n, according to the specified format (see PRINT USING)

DERR

Gives the most recent error code number returned by Amsdos.

EOF

Checks to see if end of specified file has been reached during input. Returns 0 (false) until the end of file, then -1 (true)


This example reads a file from disc and print it out on screen. Like the "TYPE" command in CP/M or "|TYPE,file" of the UTOPIA-ROM.
10 OPENIN "text.txt"
20 WHILE NOT EOF
30 LINE INPUT#9,a$
40 PRINT a$
50 WEND
60 CLOSEIN

ERR

Returns the error code number of the last error encountered.

EXP (i)

Returns the result of calculating e to the power i.
Example:
PRINT EXP(1) - prints 2.71828183

FIX (n)

Removes the fractional part of n (see INT)

FRE (n/se)

Returns the amount of unused memory, irrespective of the nature or value of the dummy argument inside the bracket.
Examples:
PRINT FRE(o) or PRINT FRE("hello")

HEX$ (i1, i2)

Returns a string hexadecimal digit representation of i1 (0-65535). The number of hex digits in the string is given by i2 (0-15)

HIMEM

Returns address of the highest memory address used by BASIC.

INKEY (i)

Checks to see if key number i is being pressed.
Value returned          [SHIFT]        [CTRL]       Specified key
-1                      ignored        ignored      up
0                       up             up           down
32                      down           up           down
128                     up             down         down
160                     down           down         down

INKEY$

Checkts the keyboard and returns the string character of the key pressed. The string character returned is normally assigned to a string variable. If no key pressed, a null string is returned.

INP (‹address›)

Returns a value read from the defined I/O address
Watch out http://cpcwiki.eu/index.php/I/O_Port_Summary
Example
PRINT INP(&FF00)
255
Ready

INSTR ([‹startposition›,]‹explored string›,‹seeking string›)

This function looks inside "explored string" after "seeking string" and return a number where the found string appear for the first time.
Returns zero if not successfull.
Startposition could be a figure between 1 and 255.
Example
a$="ABCD":PRINT INSTR(a$,"C") 
3
Ready
2. Example
a$="Hello":IF INSTR(a$,"i")<>0 THEN PRINT "no" else a$
no
Ready

INT (n)

As in FIX if n is positive; if n is negative, it rounds it down.
Example:
PRINT INT(3.99), INT(-3.99) - prints 3                      -4

JOY (i)

Returns bit-significant value from specified joystick. i = 0 or 1.
Bit             Value returned
0(up)                  1
1(down)                2
2(left)                4
3(right)               8
4(fire 2)              16
5(fire 1)              32

LEFT$ (se, i)

Returns a substring of se. The substring begins at the left-most character of se and contains i characters.
Example:
A$="ABCDEFG":PRINT LEFT$(A$,3) - prints ABC

LEN (se)

Returns the number of characters in se (0 - 255)

LOG (n)

Returns the natural logarithm (to base e) of n.

LOG10 (n)

Returns the logarithm to base 10 of n.

LOWER$ (se)

Returns a copy of se in which all alphabetical characters are converted to lower case (see also UPPER)
Example
PRINT LOWER$("A1B2c3") - print a1b2c3

MAX (list of n)

Returns the maximum value from the given list.
Example:
PRINT MAX(3,8,25,1,2,9) - prints 25

MIN (list of n)

Returns the minimum value from the given list (see MAX)

PEEK (add)

Returns the contents of the specified memory location (0-65535)

PI

Returns value of PI (3.14159265)

POS (#st)

Returns column number of print position relative to left edge of text window on stream st. st must be specified.
Example:
PRINT POS(#0) - prints 1

REMAIN (i)

Returns count remaining in delay timer i (0-3) then disables it.
For the reason that REMAIN is no normal command but a "function" it is necessary in case of a proper functionality to link the command.
a example in combination with an interrupt delay timer 1:
PRINT REMAIN(1)

or to stop several/all interrupts at the same time...

A=REMAIN(0)=REMAIN(1)=REMAIN(2)=REMAIN(3)
Hint: Take care of interrupts due to parallel working (the same cycle time) or if they are stopped with the BREAK key. Interrupts which were disabled for a certain time will be stored in buffer (for a maximum of 128 entries) and made up their task afterwards in the priorisation as declared.

RIGHT$ (se,i)

Returns a substring of length i (0-255) characters from se, ending at the rightmost character of se.
Example
PRINT RIGHT$("ABCDEFG",3) - prints EFG

RND [(n)]

Generates the next random number between 0 and 1 (exklusiv) in the current squence if n is positive or omitted.
If n = 0, the random number generated will be the same as the last random number generated.
Example:
PRINT RND(0)
 0.536703827
Ready
PRINT RND(1)
 0.271940658
Ready
PRINT RND(0)
 0.271940658
Ready
Exampel for generating an integer random number between 1 and 1000
10 A=INT((RND(1)*1000)+1)
20 PRINT A
30 GOTO 10
Exampel for generating a random number between a lower and higher border
10 INPUT "Low border",low
20 INPUT "High border",high
30 A=INT(RND(1)*(high-low))+low
40 PRINT A

ROUND (n[,i1])

Rounds n to a number of decimal places or to the power of ten specified by i. If i is negative, the n is rounded to give an absolute integer with i zeros before the decimal point.
Example:
PRINT ROUND(1562.357,2):PRINT ROUND(1562.375,-2) - prints 1562.36 1600

SGN (n)

Returns 1 if n is positive, 0 if n = 0, -1 if n is negative.

SIN (n)

Returns sine of n in degree or radian mode (see DEG and RAD)

SPACE$(i)

Creates a string containing i spaces (0-255)

SQ (channel)

Returns a bit significant integer showing state of the sound queue for specified channel where channel 1, 2, 3 = A, B, C.
Bits 0,1 and 2     number of free entries in the queue
Bits 3,4 and 5     redezvous state at head of the queue
Bit 6              head of the queue is held
Bit 7              channel is currently active

SQR (n)

Returns the square root of n.

STR$(n)

Returns the string representation of number n.
Useful for converting a number to a string in case of string manipulation. E.g. after converting a figure to a string then the most left character holds the sign: a minus in case the figure is negative and a space in case the figure is positiv.
Example:
10 FIGURE=-1599
20 FIGURE$=STR$(FIGURE)
30 PRINT FIGURE$
-1599

10 FIGURE=1769
20 FIGURE$=STR$(FIGURE)
30 PRINT FIGURE$
 1769
(there's a blank on the left-hand of the number "1769")
If you want to add e.g. zero before the figure in case of a high score with fix digit-number then you're able to add zero(s) in front of a string instead of a figure.

STRING$

Returns i copies of the string character specified by s.
Example:
PRINT STRING$(3,"*") - prints ***

TAN (n)

Returns the tangent of n. The DEG and RAD commands can be used to force the result to either mode.

TEST (x,y)

Moves the graphics cursor by x and y and returns the value of the ink at that position.

TESTR (x,y)

Moves the graphics cursor by x and y relative to its current position and returns the value of ink at that position.

TIME

Returns time elapsed since the computer was switched on or reset.
One second = TIME/300.

UNT (add)

Returns an integer(-32768 to 32767) which is the two's complement of add.
Example:
PRINT UNT(&FF66) - prints -154

UPPER$(se)

Gives copy of se with all alphabetic characters in upper case.

VAL(se)

Returns the numeric value (including signs) of first numeric character(s) in se. Returns 0 if se starts with a non-number.
Example:
PRINT VAL("-12.34x"),VAL("A-12") - prints -12.34     0
Exception: if <se> starts with "&" + character (and it's between "A" and "F") the whole character will be handled like a hexadezimal numeric character (...often used in DATA Loaders). The returning numeric value is a  signed integer (16-Bit Word).
PRINT VAL("&A") - returns a 10

PRINT VAL("&7FFF") - returns a 32767

PRINT VAL("&8000") - returns a -32768

VPOS (#st)

Reports the current row (line) position of the text cursor relative to the top of the text windows of the specified stream.

XPOS

Returns the current horizontal (x) position of the graphics cursor.

YPOS

Returns the current vertical (y) position of the graphics cursor.

Error codes

  1. Unexpected NEXT - NEXT encountered without matching FOR.
  2. Syntax Error - Typing error or incorrect punctuation.
  3. Unexpected RETURN - RETURN encountered when there was no active GOSUB.
  4. DATA exhaused - Trying to READ data when data pointer has reached end of data.
  5. Improper argument - The argument for a function is not legal (e.g. PRINT SQR(-10)).
  6. Overflow - The computer cannot handle integers smaller than -32768 (signed) or larger than 65535 (unsigned) or floating point numbers greater than ±1.7E38.
  7. Memory full - Not enough free RAM available to complete the operation. Program too big or control structures too deeply nested.
  8. Line does not exist - Attempt to RUN, GOTO or GOSUB a non-existent line number.
  9. Subscript out of range - Value of a subscript in an array is outside of range specified by DIM declaration or wrong number of dimensions supplied.
  10. Array already dimensioned - Arrays can only be DIMensioned once within a program.
  11. Division by zero - Trying to divide a number by zero.
  12. Invalid direct command - Using a statement as a direct command which is not allowed outside a program, e.g. DEF FN.
  13. Type mismatch - Wrong data type encountered, string data instead of numeric value or vice versa.
  14. String space full - String memory area is full.
  15. String too long - String may not exceed 256 characters.
  16. String expression too complex - A string expression needs to be broken down into smaller expressions.
  17. Cannot CONTinue - CONT can only be used if program was stopped by [ESC] or a STOP in program - not after END. If the program is modified before issuing CONT you will also get this error.
  18. Unknown user function - A DEF FN must be executed before calling an FN function.
  19. RESUME missing - End of program has been reached while in error processing mode. Use ON ERROR GOTO before RESUME.
  20. Unexpected RESUME - RESUME is only used in error processing mode, ON ERROR GOTO statement must be used first.
  21. Direct Command found - A line without a line number has found while loading a file.
  22. Operand missing - An incomplete expression has been found.
  23. Line too long - The line contains too many statements.
  24. EOF met - Trying to input data beyond end of data file.
  25. FILE type error - Using a program file instead of a data file to read or write (or vice versa).
  26. NEXT missing - The NEXT of a FOR ... NEXT loop is missing.
  27. File already open - Trying to open an open file. Use CLOSEIN or CLOSEOUT first.
  28. Unknown command - Given when an unknown command follows a |. e.g. |DISC on a CPC464 without AMSDOS installed.
  29. WEND missing - The WEND part of the WHILE ... WEND loop is missing.
  30. Unexpected WEND - WEND encountered without a corresponding active WHILE.
  31. File not open - Attempting to read from or write to a file without OPENing it first.
  32. Broken in - During handling with files (read, write, change etc.) different problems could appear. BASIC reacts with Error code 32 due to it. You have to mask the DERR code with AND &7F (mask Bit 7) and compare the result with the following table to get explained what happened:
Decimal (binary) number:
  • 14 (0000 1110) Stream in an unclear condition
  • 15 (0000 1111) reached End of File (hard eof
  • 16 (0001 0000) > unknown command or filename
  • 17 (0001 0001) > there's already a file existing with the same name
  • 18 (0001 0010) > there's no file with that name
  • 19 (0001 0011) > full directory20 (0001 0100) > full disc
  • 21 (0001 0101) > disc was removed during reading
  • 22 (0001 0110) > only readable
  • 26 (0001 1010) > reached End of File (soft end)
Does AMSDOS has already given out a failure then Bit 7 will be set. That means add 128 decimal to DERR code.
  • Unknown error - Executing ERROR command with any other legal error code number (up to 255).


Other Basic Dialects available for the CPC

Web links

Contributors

Almasys, Briggsy, C2r, CJ Dennis, CPCLER, CPM User, ChaRleyTroniC, FindYWay, Gryzor, HAL6128, Hal 6128, Laurentvaucher, MacDeath, Morn, Nich, Octoate, Polluks, Prodatron, PulkoMandy, Torn, Villain, Ygdrazil, ZilogMonkey

Personal tools
Namespaces

Variants
Actions
Contents
Hardware
Software
Printed matter
The Scene
Toolbox
CPC-Topsites