For other BASIC language versions see the Category:BASIC
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.
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 CINT
rounds 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 anArray already dimensioned
error. If an array is not specified byDIM
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›
- Display 1 program line for editing.
The following keys can be used in editing mode, or during typing in BASIC:
CTRL+TAB - toggle overwrite/insert mode CTRL+CURSOR LEFT or CTRL+CURSOR UP - go to start of line CTRL+CURSOR RIGHT or CTRL+CURSOR DOWN - go to end of line CURSOR LEFT - move left one character CURSOR RIGHT - move right one character ESC - quit editing and do not accept changes ENTER/RETURN - quit editing and accept changes SHIFT + CURSOR UP/DOWN/LEFT/RIGHT - enter copy mode. You can move the cursor to where you want to copy from. Hold SHIFT and cursors to move copy cursor. COPY - copy character covered by copy cursor. DEL - delete character and go back a char CLR - delete character under cursor CTRL + CAPS LOCK - toggle shift lock.
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 20 50 END
GRAPHICS
- ...works only in combination with the command
PEN
orPAPER
to set the plotting/drawing pen or background colour. - If the
TAG
command is used to set text at the graphics cursorGRAPHICS PEN
orGRAPHICS PAPER
instead of the regularPEN
orPAPER
is 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 ‹pen›,‹colour›,[‹second colour›]
- Used to set the colour palette for each of the 16 available inks.
- pen specifies the pen slot to use.
- colour specifies the system colour to use (0..27.)
- if the second colour is provided, Locomotive Basic will blink between the colour and second colour.
- In MODE 0, all 16 pens are available. In MODE 1, only 4 pens are available (0..3). In MODE 2, only 2 pens are available (0..1.)
- By default, pen 0 is the background colour and pen 1 is the foreground/text colour.
- Examples:
10 MODE 2 20 INK 0,3: REM Set background colour to red 30 INK 1,26: REM Set foreground/text colour to white
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 separate window definitions it is possible to print out long listings, better differentiate 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›]
With this directive you may load any file in memory
Basic files (extension .BAS) are loaded in Basic memory, you cannot choose loading address
Binary files are loaded to the default address location stored in the AMSDOS header but you may force loading address (&C000 for a screen)
TAPE convention:
When loading tape files, the basic display a message every block which may cause trouble. Message output may be disabled by using prefix "!" before the filename.
It's also possible to load the next file disregarding his name using only "!" => LOAD "!"
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 160×200 in 16 colours, MODE 1 is 320×200 4 colours, MODE 2 is 640×200 2 colours and MODE 3 is 160×200 in 4 colours.
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
orAFTER
commands.
- See also the
SQ(x)
command for more details.
OPENIN ‹filename›
- Opens the specified data file for reading. It has to be an ASCII file. ( The command
CLOSEIN
closes reading data file. ) - Read from the file using
INPUT #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 theWINDOW
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
- (&x00000001) releases chanel A
- (&x00000010) releases chanel B
- (&x00000011) releases chanel A and B
- (&x00000100) releases chanel C
- (&x00000101) releases chanel A and C
- (&x00000110) releases chanel B and C
- (&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=(62,500/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 INK <n1,n2>
- SPEED INK command defines the frequency of colour changes if a colour change was defined. The duration is calculated by n1=... or n2 =duration/50 seconds.
SPEED KEY <start,repeat>
- SPEED KEY command defines the delay after which a key repeat (for keys that do repeat). The first parameter is the delay before the first repeat and the second parameter is the delay between further repeats. Delay is in 1/50th of seconds.
SPEED WRITE <n>
- SPEED WRITE defines the speed at which data is to be saved or written to a cassette unit. n=1 means 2000 baud, n=0 (default) means 1000 baud. When reading from the tape, the correct speed is automatically selected.
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 (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the ABSolute value of the given numeric expression (n). This means that negative numbers are returned as positive.
- Associated keywords: SGN
- Example:
PRINT ABS(-67.98) 67.98
ASC (<string expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the numeric value of the first character in the <string expression> (s).
- Associated keywords: CHR$
- Example:
PRINT ASC("x") 120
ATN (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Calculates the Arc-TaNgent of the <numeric expression> (n) to a real number ranging from -PI/2 to +PI/2 of the value specified.
- Note that DEG and RAD can be used to force the result of the below calculation to degrees or radians respectively.
- Associated keywords: COS, DEG, RAD, SIN, TAN
- Example:
PRINT ATN(1) 0.785398163
BIN$ (<unsigned integer expression>,[<integer expression>])
- BASIC 1.0 & 1.1
- FUNCTION: Produces a string of BINary digits respresenting the value of the <unsigned integer expression>, using the number of binary digits instruced by the second <integer expression> (in the range of 0 to 16). If the number of digits instructed is too great, the resulting expression will be filled with leading zeros; if the number of digits instructed is too small, the resulting expression will NOT be shortened to the instructed number of digits, but will produced in as many digits as are required.
- The <unsigned integer expression> to be converted into binary form must yield a value in the range -32768 to 65535.
- Associated keywords: DEC$, HEX$, STR$
- Example:
PRINT BIN$(66,8) 01000000
CHR$ (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Converts an <integer expression> in the range 0 to 255, to its CHaRacter $tring equivalent, using the AMSTRAD character set shown in the ASCII table or e.g. in the manual part 3.
- Note that 0 to 31 are control characters; hence the below example prints CHR$(x) in the range 32 to 255
- Associated keywords: ASC, LEFT$, RIGHT$, MID$, STR$
- Example:
10 FOR X=32 to 255 20 PRINT X;CHR$(X); 30 NEXT
- A further 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.
- Control Codes Table:
=============================================================================== | 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 (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the value of the <numeric expression> (n), Converting it to a rounded INTeger in the range -32768 to 32767.
- Associated keywords: CREAL, FIX, INT, ROUND, UNT
- Example:
10 n=1.9999 20 PRINT CINT(n) run 2
COPYCHR$ (#stream)
- : BASIC 1.1
- FUNCTION: COPies a CHaRacter from the current position in the stream (which MUST be specified). The below program copies a character from location 1,1 (top left), and reproduces it at location 1,20.
- If the character read is not recognized, a null string is returned.
- Associated keywords: LOCATE
- Example:
10 CLS 20 PRINT "top corner" 30 LOCATE 1,1 40 a$=COPYCHR$(#0) 50 LOCATE 1,20 60 PRINT a$
COS (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Calculates the COSinus of the <numeric expression> (n).
- Note that DEG and RAD can be used to force the result of the below calculation to degrees or radians respectively.
- Associated keywords: ATN, DEG, RAD, SIN
- Example:
DEG PRINT COS(45) 0.707106781
CREAL (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the value of the <numeric expression> (n), Converting it to REAL.
- Associated keywords: CINT
- Example:
10 a=PI 20 PRINT CINT(a) 30 PRINT CREAL(a) run 3 3.14159265
DEC$(<numeric expression>, <format template>)
- BASIC 1.1
- FUNCTIION: Returns a DECimal string representation of the <numeric expression> (n), using the specified <format template> to control the print format of the resulting string.
- The format template may contain ONLY the characters:
- + - $ £ * # , . ^
- The use of these 'format field specifiers' is described under the keyword PRINT USING.
- Associated keyword: BIN$, HEX$, PRINT USING, STR$
- Example:
PRINT DEC$(10^7,"££########,.##") £10,000,000.00
DERR
- BASIC 1.1
- FUNCTION: Reports the last error code returned by the disc filing system. The value of DERR may be used to ascertain the particular Disc ERRor that occurred. See the listing of error messages below.
- Associated keywords: ERL, ERR, ERROR, ON ERROR GOTO, RESUME
- Example:
LOAD "xyz.abc" XYZ .ABC not found Ready PRINT DERR 146
- Table of Disc ERRor codes:
- If AMSDOS has already reported an error, then bit 7 is set, hence the value of DERR is offset by 128.
=============================================================================== | VALUE | DERR value | DESCRIPTION | =============================================================================== | 0 | 0 or 22 | [ESC] has been pressed | | 14 | 142 (128+14) | The stream is not in a suitable state. | | 15 | 143 (128+15) | Hard end of file has been reached. | | 16 | 144 (128+16) | Bad command, usually an incorrect filename. | | 17 | 145 (128+17) | File already exists. | | 18 | 146 (128+18) | File does not exists. | | 19 | 147 (128+19) | Direcotry is full. | | 20 | 148 (128+20) | Disc is full. | | 21 | 149 (128+21) | Disc changed while file were open. | | 22 | 150 (128+22) | File is Read/Only. | | 26 | 154 (128+26) | Soft end of file has been detected. | | | | | ===============================================================================
- Other values returned by DERR originate from the disc controller and are bit significant, always with bit 6 set.
- The significance of each bit is as follows:
=============================================================================== | BIT | Significance | =============================================================================== | 0 | Address mark missing. | | 1 | Not writable - disc is write protected. | | 2 | No data - can't find the sector. | | 3 | Drive not ready - no disc in the drive. | | 4 | Overrun error. | | 5 | Data error - CRC error. | | 6 | Always set to 1 to indicate error from disc controller. | | 7 | Set to 1 if error has already been reported by AMSDOS. | ===============================================================================
EOF
- BASIC 1.1
- FUNCTION: Checks to see if end of specified file has been reached during input. Returns 0 (false) until the end of file, then -1 (true).
- Associated keywords: OPENIN, CLOSEIN
- 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
- BASIC 1.0 & 1.1
- FUNCTION: Reports the number of the last ERRor encountered. See the table below of error messages. In the example below you will see that ERRor number 8 is a 'Line does not exist' error.
- Example:
GOTO 500 Line does not exist Ready PRINT ERR 8
- NOTE: BASIC 1.0 (officially) describes error codes until 30 (without an attached floppy disc controller). 31 & 32 are floppy disc error codes.
- Table of ERRor codes:
======================================================================================== | VALUE | NAME | DESCRIPTION | ======================================================================================== | 1 |Unexpected NEXT |A NEXT command has been encountered while not in a | | | |FOR loop, or the control variable in the NEXT | | | |command does not match that in the FOR. | | 2 |Syntax Error |BASIC cannot understand the given line because | | | |a construct within it is not legal. | | 3 |Unexpected RETURN |A RETURN command has been encountered when not in a | | | |subroutine. | | 4 |DATA exhausted |A READ command has attempted to read beyond the end | | | |of the last DATA. | | 5 |Improper Argument |This is a general purpose error. The value of a | | | |function's argument, or a command parameter is | | | |invalid in some way. | | 6 |Overflow |The result of an arithmetic operation has over- | | | |flowed. This may be a floating point overflow, in | | | |which case some operation has yielded a value | | | |greater than 1.7E^38 (approx.). Alternatively, this | | | |may be the result of a failed attempt to change a | | | |floating point number to a 16 bit signed integer. | | 7 |Memory full |The current program or its variables may be simply | | | |too big, or the control structure is too deeply | | | |nested (nested GOUSBs, WHILEs or FORs). | | | |A MEMORY command will give this error if an attempt | | | |is made to set the top of BASIC's memory too low, or| | | |to an impossible high value. Note that an open file | | | |has a buffer allocated to it, and that may restrict | | | |the values that MEMORY may use. | | 8 |Line does not exist |The line referenced cannot be found. | | 9 |Subcript out of range |One of the subscripts in an array reference is too | | | |big or too small. | | 10 |Array already dimensioned|One of the arrays in a DIM statement has already | | | |been declared. | | 11 |Division by zero |May occur in real division, integer division, | | | |integer modulus or exponentiation. | | 12 |Invalid direct command |The last command attempted is not valid in direct | | | |mode. | | 13 |Type mismatch |A numeric value has been presented where a string | | | |value is required or vice versa, or an invalidly | | | |formed number has been found in READ or INPUT. | | 14 |String space full |So many strings have been created that there is no | | | |further room available, even after 'garbage | | | |collection'. | | 15 |String too long |Strings exceeds 255 characters in length. May be | | | |generated by appending strings together. | | 16 |String expression too |String expressions may generate a number of | | |complex |intermediate string values. When the number of these| | | |values exceeds a reasonable limit, this error | | | |results. | | 17 |Cannot CONTinue |For one reason or another the current program | | | |be restarted using CONT. Note that CONT is intended | | | |for restarting after a STOP command, [ESC][ESC], | | | |or an error, and that any alteration of the | | | |program in the meantime makes a restart impossible. | | 18 |Unknown user function |No DEF FN has been executed for the FN just | | | |invoked. | | 19 |RESUME missing |The end of the program has been encountered while | | | |in error processing mode (i.e. in an ON ERROR GOTO | | | |routine). | | 20 |Unexpected RESUME |RESUME is only valid while in error processing mode | | | |(i.e. in an ON ERROR GOTO routine). | | 21 |Direct command found |When loading a file, a line without a line number | | | |has been found. | | 22 |Operand missing |BASIC has encountered an incomplete expression. | | 23 |Line too long |A line when converted to BASIC internal-form becomes| | | |too big. | | 24 |EOF met |An attempt has been made to read past end of the | | | |file input stream. | | 25 |File type error |The file being read is not of a suitable type. | | | |OPENIN is only prepared to open ASCII text files. | | | |Similarly, LOAD, RUN, etc, are only prepared to | | | |deal with file types produces by SAVE. | | 26 |NEXT missing |Cannot find a NEXT to match a FOR command. A line | | | |number accompanying this message indicates the FOR | | | |command to which this error applies. | | 27 |File already open |An OPENIN or OPENOUT command has been executed | | | |before the previously opened file has been closed. | | 28 |Unknown command |BASIC cannot find a taker for an external command, | | | |i.e. a command preceded by a bar |. | | 29 |WEND missing |Cannot find a WEND to match a WHILE command. | | 30 |Unexpected WEND |Encountered a WEND when not in a WHILE loop, or a | | | |WEND that does not match the current WHILE loop. | | 31 |File not open |(see 'Disc ERRors above). | | | |If access attempted when no file was open. | | 32 |Broken in |(see 'Disc ERRors above). | | | |If access attempted when no file was open. | | | | | | | |If value 31 or 32 are stated, DERR could be | | | |interrogate to give more detailed information. | | | |(see example below.) | ========================================================================================
- Example for ERR 31 / 32:
10 ON ERROR GOTO 1000 20 OPENOUT "myfile.asc" 30 WRITE #9,"test-data" 40 CLOSEOUT 50 END 1000 amsdoserr=(DERR AND &7F):REM mask off bit 7 1010 IF ERR<31 THEN END 1020 IF ERR=31 THEN PRINT "are you sure you've typed line 20 correctly?":END 1030 IF amsdoserr=20 THEN PRINT "disc is full, suggest you use a new data disc":END 1040 IF amsdoserr=&X01001000 THEN PRINT "put a disc in the drive, then press a key":WHILE INKEY$="":WEND:RESUME 1050 END
EXP (<integer expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Calculates 'E' to the power given in the <numeric expression> (i), where 'E' is approximately 2,7182818-the number whose natural logarithm is 1.
- Associated keywords: LOG
- Example:
PRINT EXP(6.876) 968.743625
FIX (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Unlike CINT, FIX merely removes the part of the numeric expression, to the right of the decimal point, and leaves an integer result, rounding towards zero.
- Associated keywords: CINT, INT, ROUND
- Example:
PRINT FIX(9.99999) 9
FRE (<numeric expression>/<string expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Establishes how much FREe memory remains unused by BASIC. The form FRE("") forces a 'GARBAGE COLLECTION' before returning a value for available space.
- NOTE: BASIC uses only the first 64K of the memory.
- Associated keywords: HIMEM, MEMORY
- Examples:
PRINT FRE(0) or PRINT FRE("hello") PRINT FRE("")
HEX$ (<unsigned integer expression>, <field width>)
- BASIC 1.0 & 1.1
- FUNCTION: Produces a $tring of HEXadecimal digits representing the value of the <unsigned integer expression>, using the number of hexadecimal digits instructed by the <field width> (in the range 0 to 16). If the number of digits instructed is too great, the resulting expression will be filled with leading zeros; if the number of digits instructed is too small, the resulting expression will NOT be shortened to the instructed number of digits, but will be produced in as many digits as are required.
- The <unsigned integer expression> to be converted into hexadecimal form must yield a value in the range -32768 to 65535.
- Accociated keywords: BIN$, DEC$, STR$, UNT
- Example:
PRINT HEX$(255,4) 00FF
HIMEM
- BASIC 1.0 & 1.1
- FUNCTION: Returns the address of the Highest byte of Memory use by BASIC, (which may altered by e.g. the MEMROY command).
- Before resetting the highest byte of available memory using the MEMORY command, it is advisable to issue the 'command mm=HIMEM'. You will thereafter be able to return to the previous memory capacity by issuing the command: 'MEMORY mm'
- NOTE: BASIC uses only the first 64K of memory.
- Associated keywords: FRE, MEMORY, SYMBOL, SYMBOL AFTER.
- Example:
...on a CPC464
PRINT HIMEM 43903
...on a CPC6128
PRINT HIMEM 42619
INKEY (<integer expression>)
- BASIC 1.0 & 1.1
- FUNCTION: INterrogates the KEYboard to report which keys are being pressed. The keyboard is scanned every 0.02 (1/50) second.
- The function is useful for spotting whether a certain key is down or up, by detecting the returned value of -1 (which occurs regardless of [SHIFT] and [CONTROL] key status).
- The example below detects when [SHIFT] and V (key number 55) are pressed together, then ends the program. Refer the manual for the key numbers.
- Associated keywords: CLEAR INPUT, INKEY$, JOY
- Example:
10 IF INKEY(55)<>32 THEN 10 20 PRINT "You've pressed [SHIFT] and V" 30 CLEAR INPUT run
- The state of [SHIFT] and [CONTROL] in conjunction with the key specified in the <integer expression> is identified as follows:
============================================================================== |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$
- BASIC 1.0 & 1.1
- FUNCTION: INterrogates the KEYboard, returning the current $tring reflecting any key that is pressed. It provides operator interaction without hitting [ENTER] after every answer. If there is a key pressed, then the function responds. If no key is pressed, INKEY$ returns an empty string.
- In the example below, lines 40 and 70 tell the program to loop back to line 30 after interrogating the keyboard string.
- Associated keywords: CLEAR INPUT, INKEY
- Example:
10 CLS 20 PRINT "Select Yes or No (Y/N)?" 30 a$=INKEY$ 40 IF a$="" THEN 30 50 IF a$="y" OR a$="Y" THEN 80 60 IF a$="N" OR a$="n" THEN 90 70 GOTO 30 80 PRINT "You have selected YES": END 90 PRINT "You have selected NO": run
INP (‹port number›)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the INPut value from the I/O address specified in the <port number>.
- Associated keywords: OUT, WAIT
- Example:
PRINT INP(&FF00) 255 Ready
INSTR ([‹startposition›,]‹searched string›, ‹searched for string›)
- BASIC 1.0 & 1.1
- FUNCTION: Searches the first <searched string> expression to find the first occurance of the <searched for string expression<, and reports the position of its occurance within the <searched string>. If the <searched for string> does not occur within the <searched string>, then 0 is reported.
- The position at which to start searching the <searched string> is optionally specifiable using the <start position> parameter which must yield an integer number in the range 1 to 255.
- Associated keywords: none
- 1. 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
- 3. Example:
10 CLS 20 alphabet$="ABCDEFGHIJKLMNOPQRSTUVWXYZ" 30 INPUT "Enter a letter";a$ 40 b$=UPPER$(a$) 50 PRINT b$;" is number"; 60 PRINT INSTR(alphabet$,b$); 70 PRINT "in the alphabet.":PRINT 80 GOTO 40 run
INT (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Rounds the number to the nearest smaller INTeger, removing any fractional part. Returns then same value as FIX for positive number, but returns one less than FIX for negative numbers which are not already integers.
- Associated keyword: CINT, FIX, ROUND
- Example:
PRINT INT(3.99), INT(-3.99) 3 -4
JOY (<integer expression>)
- BASIC 1.0 & 1.1
- FUNCTION: The JOY function reads a bit significant result from the joystick in the <integer expression> (either 0 or 1).
================================ |Bit | Value decimal | ================================ |0(up) | 1 | |1(down) | 2 | |2(left) | 4 | |3(right) | 8 | |4(fire 2) | 16 | |5(fire 1) | 32 | ================================
LEFT$ (<string expression>, <required length>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the number of characters (in the range 0 to 255) specified in the <required length> parameter (<integer expression>), after extracting them from the LEFT of the <string expression>. If the <string expression> is shorter than the <required length>, the whole <string expression> is returned.
- Associated keywords: MID$, RIGHT$
- 1. Example:
A$="ABCDEFG":PRINT LEFT$(A$,3) - prints ABC
- 2. Example:
10 CLS 20 a$="AMSTRAD" 30 FOR n=1 to 7 40 PRINT LEFT$(a$,n) 50 NEXT run
LEN (<string expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the total number of characters (i.e. the LENgth) of the <string expression>.
- Associated keywords: none
- Example:
10 LINE INPUT "Enter a phrase";a$ 20 PRINT "The phrase is"; 30 PRINT LEN(a$);"characters long." run
LOG (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Calculates the natural LOGarithm (base of e) of <numeric expression> which mustbe greater than zero.
- Associated keywords: EXP, LOG10
- Example:
PRINT LOG(9999) 9.21024037
LOG10 (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the logarithm to base 10 of <numeric expression> which must be greater than zero.
- Associated keywords: EXP, LOG
- Example:
PRINT LOG10(9999) 3.99995657
LOWER$ (<string expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns a new string expression which is a copy of the specified <string expression> but in which all alphabetic characters in the range A to Z are converted to lower case. Useful for processing input where the answers may come in mixed upper/lower case.
- Associated keywords: UPPER$
- 1. Example:
A$="AMSTRAD":PRINT A$="AMSTRAD":PRINT LOWER$(A$) Amstrad
- 2. Example:
10 a$="SEE HOW THE LETTERS CHANGE TO ... NUMBERS 1234 NOT..." 20 PRINT LOWER$(a$+"LOWER CASE") see how the letters change to ... numbers 1234 not... LOWER CASE
MAX (<list of: numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the MAXimum value from the <list of: numeric expression>s.
- Associated keywords: MIN
- Example:
10 n=66 20 PRINT MAX(1,n,3,6,4,3) run 66
MIN (<list of: numeric expression>)
BASIC 1.0 & 1.1
- FUNCTION: Returns the MINimum value from the <list of: numeric expression>s.
- Associated keywords: MAX
- Example:
PRINT MIN (3,6,2.999.8,9,) 2.999
PEEK (<address expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Reports the contents of the Z80 memory location specified in the <address expression> which should be in the range &0000 to &FFFF (0 to 65535). In all cases PEEK will return the value at the RAM address specified (not the ROM), and will be in the range &00 to &FF (0 to 255)
- Associated keywords: POKE
- Example:
10 MODE 1: ZONE 7 20 WINDOW 1,40,1,2:WINDOW #1,1,40,3,25 30 PRINT "memory-address" 40 LOCATE 20,1:PRINT "memory-contents" 50 FOR n=1 to 65535 60 p=PEEK(n) 70 PRINT #1,n,"(&";HEX$(n);")"; 80 PRINT #1,TAB(20);p,"(&";HEX$(p);")" 90 NEXT run
PI
- BASIC 1.0 & 1.1
- FUNCTION: The value of the ratio between the circumference and the diameter of a circle.
- Associated keywords: DEG, RAD
- Example:
PRINT PI 3.14159265
POS (#<stream expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Reports the current horizontal POSition of the text cursor relative to the left edge of the text window. The <stream expression> MUST be specified, and does NOT default to #0.
- POS(#8) reports the current horizontal carriage position for the printer, where 1 is the extreme left hand edge.
- POS(#9) reports the logical position in the disc file stream, i.e. the number of printing characters sent to the stream since the last carriage return.
- Associated keywords: VPOS, WINDOW
- Example:
10 MODE 1: BORDER 0:LOCATE 8,2 20 PRINT "use cursor left/right keys" 30 WINDOW 1,40,12,12:CURSOR 1,1 40 FOR n=1 TO 19:PRINT CHR$(9);:NEXT 50 IF INKEY(1)<>-1 THEN PRINT CHR$(9); 60 IF INKEY(8)<>-1 THEN PRINT CHR$(8); 70 LOCATE #1,2,24 80 PRINT #1,"text cursor "; 90 PRINT #1,"horizontal position = "; 100 PRINT #1,POS(#0):GOTO 50 run
REMAIN (<integer expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns count REMAINing count from the delay timer specified in <integer expression> (= timer number in the range 0 to 3), and disable it. If the delay timer was not enabled zero will be returned.
- Associated keywords: AFTER, DI, EI, EVERY
- 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.
- an 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.
- further example:
10 AFTER 500,1 GOSUB 40 20 AFTER 100,2 GOSUB 50 30 PRINT "program running":GOTO 30 40 REM this GOUSB-Routine will not be called as it is disabled in line 80 50 PRINT:PRINT "Timer 1 will now be "; 60 PRINT "disabled by REMAIN." 70 PRINT "Time-units remaining were:"; 80 PRINT REMAIN(1) run
RIGHT$ (<string expression>, <integer expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the number of characters (in the range 0 to 255) specified in the <integer expression> (=required length) parameter, after extracting them from the RIGHT of the <string expression>. If the <string expression> is shorter than the <integer expression>, the whole <string expression> is returned.
- Associated keywords: LEFT$, MID$
- Example:
10 MODE 1:a$="AMSTRAD computer" 20 FOR n=1 TO 16:LOCATE 41-n,n 30 PRINT RIGHT$(a$,n) 40 NEXT
RND [(<numeric expression>)]
- BASIC 1.0 & 1.1
- FUNCTION: Returns the next RaNDom number in sequence if the <numeric expression> has a positive value or is not specified.
- If the <numeric expression> yields a value of zero, RND returns a copy of the last random number generated.
- If the <numeric expression> yields a negative value, a new random number sequence is started, the first number of which is returned.
- Associated keywords: RANDOMIZE
- 1. Example:
PRINT RND(0) 0.536703827 Ready PRINT RND(1) 0.271940658 Ready PRINT RND(0) 0.271940658 Ready
- 2. Example:
- Example for generating an integer random number between 1 and 1000
10 A=INT((RND(1)*1000)+1) 20 PRINT A 30 GOTO 10
- 3. Example:
- 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
- 4. Example:
10 RANDOMIZE 20 FOR x=1 TO -1 STEP -1 30 PRINT "rnd parameter=";x 40 FOR n=1 TO 6 50 PRINT RND(x) 60 NEXT n,x run
ROUND (<numeric expression>[,<integer expression>])
- BASIC 1.0 & 1.1
- FUNCTION: Rounds <numeric expression> to a number of decimal places or to the power of ten specified by <integer expression>. If <integer expression> less than zero, the <numeric expression> is rounded to give an absolute integer with <integer expression> number of zeros before the decimal point.
- Associated keywords: ABS, CINT, FIX, INT
- 1. Example:
PRINT ROUND(1562.357,2),ROUND(1562.375,-2) 1562.36 1600
- 2. Example:
10 FOR n=4 TO -4 STEP -1 20 PRINT ROUND (1234.5678,n) 30 PRINT "with integer expression";n 40 NEXT run
SGN (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Determines the SiGN of the <numeric expression>. Returns -1 if <numeric expression> is less than 0, returns 0 if <numeric expression> = 0, and returns 1 if <numeric expression> is greater than zero.
- Associated keywords: ABS
- Example:
10 FOR n=255 to -200 STEP -20 20 PRINT "SGN returns"; 30 PRINT SGN(n);"for a value of";n 40 NEXT n run
SIN (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Calculates the Real value for the Sine of <numeric expression>, defaulting to the Radian (RAD) measure mode unless otherwise declared by a DEG command.
- Associated keywords: ATN, COS, DEG, RAD, TAN
- Example:
10 CLS:DEG:ORIGIN 0,20 20 FOR n=0 to 720 30 y=SIN(n) 40 PLOT n*640/720,198*y:NEXT 50 GOTO 50 run
SPACE$(<integer expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Creates a string of spaces of the given length, (in the range 0 to 255) specified in the <integer expression>.
- Associated keywords: SPC, STRING$, TAB
- Example:
10 MODE 1 20 PRINT "Put 9 spaces between me"; 30 PRINT SPACE$(9); 40 PRINT "and you!" run
SQ (<channel>)
- BASIC 1.0 & 1.1
- FUNCTION: Reports the state of the Sound Queue for the specified <channel> which must be an integer expression, yielding one the values:
- 1: for channel A
- 2: for channel B
- 4: for channel C
- The SQ function returns a bit significant integer, comprising the following bit settings:
- Bit 0,1 and 2: the number of free entries in the queue
- Bit 3,4 and 5: the rendezvous state at the head of this queue
- Bit 6 : the head of the queue is held
- Bit 7 : the channel is currently active
- ... where Bit 0 is the least significant bit, and Bit 7 is the most significant bit.
- It can be seen, that if Bit 6 is set, Bit 7 cannot be set at the same time, and vice versa. Similarly if Bits 3, 4, or 5 are set, Bit 6 and 7 cannot be set.
- Associated keywords: ON SQ GOSUB, SOUND
- Example:
10 SOUND 65,100,100 20 PRINT SQ(1) run 67
SQR (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the SQuare Root of the specified <numeric expression>.
- Associated keywords: none
- Example:
PRINT SQR(9) 3
STR$ (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Converts the <numeric expression> to a decimal STRing representation.
- 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.
- Associated keywords: BIN$, DEC$, HEX$, VAL
- 1. Example:
10 FIGURE=-1599 20 FIGURE$=STR$(FIGURE) 30 PRINT FIGURE$ -1599
- 2. Example:
10 FIGURE=1769 20 FIGURE$=STR$(FIGURE) 30 PRINT FIGURE$ 1769
- NOTE: (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.
- 3. Example:
10 a=&FF:REM 255 hex 20 b=&x1111:REM 15 binary 30 c$="***" 40 PRINT c$+SR$(a+b)+c$ run *** 270***
STRING$ (<length>,<character specifier>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns a string expression consisting of the <character specifier> repeated the number of time (in the range 0 to 255) specified in the <length>.
- Associated keywords: SPACE$
- 1. Example:
PRINT STRING$(40,"*") ****************************************
- 2. Example:
PRINT STRING(40,42) ****************************************
- NOTE: the <character specifier> 42 refers to the ASCII value of the character '*' and is also equivalent to PRINT STRING$(40,CHR$(42))
TAN (<numeric expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Calculates the TANgent of the <numeric expression>, which must be in the range -200,000 to +200,000.
- NOTE: DEG and RAD can be used to force the result of the calculation to degrees or radians respectively.
- Associated keywords: ATN, COS, DEG, RAD, SIN
- Example:
PRINT TAN(45) 1.61977519
TEST (<x co-ordinate>,<y co-ordinate>)
- BASIC 1.0 & 1.1
- FUNCTION: Moves the graphics cursor to the absolute position specified by the <x> and <y co-ordinate>s, and reports the value of the ink at the new location.
- Associated keywords: MOVE, MOVER, TESTR, XPOS, YPOS
- Example:
10 CLS 20 PRINT "Your are using pen number"; 30 PRINT TEST(10,386) 40 PRINT "Try changing PENs and MODEs"; 50 PRINT "....then RUN again." run
TESTR (<x offset>,<y offset>)
- BASIC 1.0 & 1.1
- FUNCTION: Moves the graphics cursor by the amount specified in the <x> and <y offset>s relative to its current position, and reports the value of the ink at the new location.
- Associated keywords: MOVE, MOVER, TEST, XPOS, YPOS
- Example:
10 MODE 0:FOR x=1 TO 15:LOCATE 1,x 20 PEN x:PRINT STRING$(10,143);:NEXT 30 MOVE 200,400:PEN 1 40 FOR n=1 TO 23:LOCATE 12,n 50 PRINT "pen";TESTR(0,-16):NEXT run
TIME
- BASIC 1.0 & 1.1
- FUNCTION: Reports the elapsed time since the computer was last switched-on or reset, (excluding periods when reading or writing to disc).
- Each second of real time is equal to the returned value = TIME/300.
- Associated keyword: AFTER, EVERY, WEND, WHILE
- Example:
10 CLS:REM clock 20 INPUT "hour";hour 30 INPUT "minute";minute 40 INPUT "second";second 50 CLS:datum=INT(TIME/300) 60 WHILE hour<13 70 WHILE minute<60 80 WHILE tick<60 90 tick=(INT(TIME/300)-datum)+second 100 LOCATE 1,1 110 PRINT USING "## ";hour,minute,tick 120 WEND 130 tick=0:second=0:minute=minute+1 140 GOTO 50 150 WEND 160 minute=0:hour=hour+1 170 WEND 180 hour=1 190 GOTO 60 run
UNT (<address expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Return an integer in the range -32768 to +32767 which is the twos-complement equivalent of the unsigned value of the <address expression>.
- Associated keywords: CINT, FIX, INT, ROUND
- Example:
PRINT UNT(&FF66) -154
UPPER$(<string expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns a new string expression which is a copy of the specified <string expression> but in which all alphabetic characters in the range A to Z are converted to upper case. The function is useful for processing input which may come in mixed upper / lower case.
- Associated keywords: LOWER$
- Example:
10 CLS: a$="my, how you've grown!" 20 PRINT UPPER$(a$) run
VAL(<string expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Returns the numeric VALue, (including any negative sign and decimal point) of the first character(s) in the specified <string expression>.
- If the first character is not a number, then 0 is returned. If the first character is a negative sign or decimal point followed by non-numeric characters, a 'Type mismatch' error (13) will be reported.
- Associated keywords: STR$
- 1. Example:
PRINT VAL("-12.34x"),VAL("A-12") -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).
- 2. Example:
PRINT VAL("&A") 10 PRINT VAL("&7FFF") 32767 PRINT VAL("&8000") -32768
- 3. Example:
10 CLS: PRINT "I know my times tables!" 20 PRINT:PRINT "Press a key (1 to 9)" 30 a$=INKEY$:IF a$="" THEN 30 40 n=VAL(a$):if n<1 or n>9 then 30 50 FOR x=1 to 12 60 PRINT n;"X";x;"=";n*x 70 NEXT:GOTO 20 run
VPOS (#<stream expression>)
- BASIC 1.0 & 1.1
- FUNCTION: Reports the current vertical POSition of the text cursor relative to the top of the text window. The <stream expression> MUST be specified, and does NOT default to #0.
- Associated keywords: POS, WINDOW
- Example:
10 MODE 1:BORDER 0:LOCATE 8,2 20 PRINT "use cursor up/down keys" 30 WINDOW 39,39,1,25:CURSOR 1,1 40 LOCATE 1,3 50 IF INKEY(0)<>-1 THEN PRINT CHR$(11); 60 IF INKEY(2)<>-1 THEN PRINT CHR$(10); 70 LOCATE #1,3,24 80 PRINT #1,"text cursor "; 90 PRINT #1,"vertical position ="; 100 PRINT #1,VPOS(#0):GOTO 50 run
XPOS
- BASIC 1.0 & 1.1
- FUNCTION: Reports the current horizontal (X)POSition of the graphics cursor.
- Associated keywords: MOVE, MOVER, ORIGIN, YPOS
- Example:
10 MODE 1:DRAW 320,200 20 PRINT "graphics cursor X position = "; 30 PRINT XPOS
YPOS
- BASIC 1.0 & 1.1
- FUNCTION: Reports the current vertical (Y)POSition of the graphic cursor.
- Associated keywords: MOVE, MOVER, ORIGIN, XPOS
- Example:
10 MODE 1:DRAW 320,200 20 PRINT "graphics cursor Y position = "; 30 PRINT YPOS