|
Echo #03
31 марта 1997 |
|
Book - Secrets ZX-Spectrum: ZX-BASIC.

Chapter 3.
ZX - B E J P & K
In this chapter we briefly presented an alphabetical list of
functions and commands language ZX-BASIC. His view is, even
those Who knows this dialect, as we
provides information missed in the original instruction manual.
The list uses the following notation:
@ - Single letter;
V - variable of any type;
X, Y, Z - numerical expressions with the actual values;
K, M, N - numerical expressions with values automatically
set to the nearest integer;
E - a numerical expression or string;
F - Line;
S - a sequence of commands, each separated by a colon;
C - a sequence of instructions that determine the color and
flashing mode (INK, PAPER, BRIGHT, FLASH, OVER, INVERSE),
separated by commas and semicolons.
Symbols in square brackets
([]), We can not use it. For example:
LOAD F CODE [M [, N]] means that the true
are the forms:
LOAD F CODE
LOAD F CODE M
LOAD F CODE M, N.
In this case, SPECTRUM usually complements
missing parameters values from the context, in this case -
learned from the tape. Recording @ [Z] means or @ Z, or @, ie,
allowed use as a numerical variable, so
and text.
SPECTRUM almost all cases, accepts as parameters
expressions requiring preliminary calculations. Restrictions
affect only valid values of the calculated results and their
types. Expressions such as K, M, N can to give as a result of
any real smaller number 65535 (2 ^ 16-1), which will be rounded
the nearest whole numbers. Signaled the emergence of more
as an error message INTEGER OUT OF
RANGE.
3. 1. Program Structure
Program in BASIC - is a sequence of statements separated by
the line. Each line begins with a number - a positive integer
in the range of 1 ... 9999. Numbered operators can
be entered in any order, they
will be automatically sorted by ascending numbers. Optional
number row, such as 1, 2, 3, ... This style
programming is not recommended. Convenient
use numbers in 10, ie 10,
20, 30 ,..., which will facilitate the insertion of new
lines between the old.
Entering a new line with existing
number, is replacing the old version
this line. Be placed in
program text strings that contain only
line number to the optical isolation
program fragments.
Identity operator of the program can be
significantly longer than the screen line (32
sign), but may not contain more than 127
instructions. Teams in the operator must
be separated by a colon. Between instructions in a row you can
place any number of spaces to improve readability
program.
Pressing <ENTER> completes input strings.
The computer checks the syntax and, if
it starts with numbers, include it in an existing program,
inserting it into the desired location, and if the number is
omitted, the computer starts for the immediate implementation
introduced a series of commands.
3. 2. Data Types
ZX-BASIC is able to directly
operate with numbers and text. Numbers can be entered in one of
three forms:
- Integer: 0, +17, -12, 35, and so
on;
- Decimal: 31. 1768, 3303, 12, -. 72 and
etc.;
- Exponential: 7.32E-7 denotes
number of 7.32 * 10 ^ -7;
The maximum value of the real
number can not exceed 1.7E +38. Numbers
stored up to 9-10 digit
figures. Gaps in the middle of recording the numbers do not
permitted. SPECTRUM to highlight
require the maximum number of 14 digits.
Value, requiring no more than 8 digits are displayed
accurately. Others in the exponential form.
Another type of data ZX-BASIC are
text constants, also called chains (strings). Is any sequence
of characters (characters with codes from 0 to 256), placed in
quotation marks. In a text constant, you can also include a
control (control characters), keywords, codes and even the
character codes are not involved in the ZX-SPECTRUM. The length
of the text constant - a number contained in it
characters rather than the number of signs necessary
to highlight the constant on-screen. This
number limited only by the size of allowable
memory. Allowed, and the texts of a length of 0;
e. empty.
During construction of the text, most characters can be
entered directly from the keyboard. But some may require
additional effort. To enter in the text of quote, you must enter
it with the keyboard twice. Universal way to insert a text
string of characters not involved in the ZX, is to use
alpha-numeric expressions and function CHR $. For example, the
construction of "IT" + CHR $ 13 + "TEXT" will result in Text:
IT
TEXT
ZX-BASIC does not know the logical variables. This role is
performed by a number. Values different from 0, interpreted as
TRUE equal 0 - FALSE. The result of calculation logic
expressions are the numbers 0 and 1.
In addition to the constants ZX-Basic allows the use of
numeric and text variables. They serve to store Computer
constants of a certain type. Variable names are modified to
assigns them to the programmer.
The variables that store a number or string
characters are called simple variables.
In addition they can also apply the so-called table variables
(arrays), but they must be declared instruction
DIM. Admitted as numeric arrays, so
and character. Element number table
is the number and character - a single
character code from 0 to 255. Operators sign arrays can be used
as alphanumeric variables constant
length, defined Last Index
(Dimension) of the declaration of the array.
Number of dimensions is limited 255. Indexes can not exceed
65535. On practice, these values should be considerably
smaller because of the possible sizes memory. The declaration
of the array is given only upper bound of the index. The lower
limit always taken 1.
3. 3. Names
One of the disadvantages ZX-BASIC, a restriction in the
definition of names used variables. Only a simple numeric
variables can be any sequence of letters, numbers and spaces.
The first character name must be literature.
All other variables must be
single-letter names, including variables, control loops (FOR. ..
NEXT).
Text variables differ from the number by the $ sign placed
after the letters. This also applies to the names of
user-defined functions using the directive DEF FN and its
arguments.
For naming the program can be used both small and large
letters. ZX-SPECTRUM automatically replaces big letters to
small. All spaces are ignored.
Restricting the use of partial names
offset by the possibility of using
the same characters as the name of variables
different types. Natural requirement
in this case: text variable should not
marked by the same symbol as the sign
array. For example, the letter A in the program may refer to:
A - numerical or control variable;
A $ or A $ (I, J) - text variable
or sign array;
A (I) - a numeric array;
FN A. .. - Function with a numeric value;
FN A $ ... - Function with a text value;
DEF FN A $ (A, A $,...) - parameters in the function
definition.
All this leads to ambiguity
interpretation of these names.
3. 4. Expressions
Expression in the ZX-BASIC built of permanent variables,
operators, functions, as well as parentheses. The sequence of
actions that will define the terms parentheses and priorities
of individual operations. Below we consider all permissible
ZX-BASIC operations in sequence their priorities.
3. 4. A selected text
The operation can be performed on strings, text variables,
as well as landmark arrays. For chains and variable parameters
that determine the extracted fragment, should be recorded in
parentheses. For arrays, this data is placed in the last index,
or if its absence, in some brackets, similar to simple
variables. These parameters may be submitted:
- Absent, not change the subject;
(K) - arithmetic expression, the result - a single
character, located in the K-th position of the text;
(K TO M) - arithmetic expression with
keyword "TO", the result - a fragment
text, including characters from the K-th to M-th
inclusive. If K> M> 0, the result
- An empty string, and if the text is shorter than
M, signaled an error. For example, when
Program Performance:
10 LET A $ = "TEXT"
20 DIM B $ (2, 3)
30 LET B $ (1) = "ABC"
40 LET B $ (2) = "XYZ"
we get:
A $ = A $ () = A $ (TO) = A $ (1 TO 5) = "TEXT"
A $ (1) = A $ (TO 1) = A $ (1 TO 1) = 'T'
A $ (3 TO 3) = A $ (3) = A $ (5-2) = "K"
A $ (TO 2) = A $ (1 TO 2) = "TE"
A $ (3 TO) = A $ (3 TO 5) = "FTC"
A $ (2 TO 4) = "CEN"
B $ (1) = B $ (a,) = B $ (1) () = B $ (a, TO) =
= B $ (1) (TO) = B $ (1, 1 TO 3) =
= B $ (1) (1 TO 3) = "ABC"
B $ (2, 2) = B $ (2) (2) = B $ (2, 2 TO 2) =
= B $ (2) (2TO2) = "Y".
In other dialects of BASIC similar
role functions:
LEFT (A $, N) = A $ (TO N)
RIGHT (A $, N) = A $ (N TO)
MID (A $, K, M) = A $ (K TO M)
TL (A $) = A $ (2 TO)
3. 4. 2 Exponentiation
Arguments the exponentiation operations are real numbers.
Reason must always be positive. Keep in mind that A ^ B is
calculated as EXP (B * LN (A)), so A ^ 2 will be calculated
based longer than the A * A.
3. 4. 3 minus the sign of (-)
The argument of this operation is always a number. The
result - the same number with opposite sign. Less as a sign of
should be distinguished from those designated as symbol of
subtraction. A high priority of this operation allows us to
write A *- B, which is interpreted as A * (-B). In
other dialects of BASIC use of the two
operations in a row are not allowed.
3. 4. 4 Multiplication and division (*, /)
Multiplication and division arithmetic performed in the same
sequence in which occur in the expression. Signs of
multiplication can be omitted. Multiplication is performed
faster than the computer division, therefore better to write A
*. 5 instead of A / 2.
3. 4. 5 Addition and subtraction (+, -)
For numeric arguments to these symbols mean addition and
subtraction. Both operations have the same priority and are
executed in the next occurrence.
Plus, when applied to the text constant and variable gives
the text, which is composed of the symbols of the first and
added to its end, the characters of the second. In contrast to
the addition of numbers permutation property does not hold
here.
3. 4. 6 characters relations (=, <,>, <=,
> =, <>)
This dvuhargumentnye comparison operations
one type. They all have the same
priority and the mean ratio: EQUALS,
LESS, MORE, LESS OR EQUAL, MORE
Or equal, not equal. The result is
number 1, if the ratio is observed and 0
if not. Results of the audit relationship
can be used in arithmetic
expressions as ordinary numbers.
As an example, analyze the following problem:
we have to program a numeric array B, declared instruction DIM
B (100). Necessary to determine how many elements of this array
of more than 7. The easiest way this can be to achieve the
commands:
LET X = 0
FOR I = 1 TO 100
LET X = X + (B (I)> 7): NEXT I
After executing these commands, the variable
X will contain the desired number.
These same operators are applied to the text variables and
constants. Result compare operation symbol sequence is
determined by the lexicographic order. Smallest code in the
empty text. Comparing alternate character by character
sought first in which the two sequences differ. In less adopted
the text in which the first differing character has a smaller
code. For example, the following relations are true:
"" <"TEKST" <"TZ" <"TZ0"
3. 4. 7 Logical negation (NOT)
This operation is the logical negation of the values of a
numeric expression, which is its argument, which is regarded as
logical value.
| 0 if X <> 0
NOT X = |
| 1, if X = 0
Remember that logical expressions like
(A> B) OR (C = D) computer interprets as numeric expressions.
3. 4. 8 Logical And (AND)
Logical AND - dvuhargumentnaya operation. This is a very
useful operation, the application of which goes far beyond the
calculation of logical expressions. The first argument of the
operation AND can be both numeric and alpha-numeric expression.
The second should be just a number. Below is the definition of
logical AND, as understood ZX-BASIC:
| X, if Y <> 0
X AND Y = |
| 0, if Y = 0
| F, if Y <> 0
F AND Y = |
| "", When Y = 0
Definition it may seem strange
and not related to the fact that we used to take the logical I.
Note that if the AND operator will be between
two logical expressions, then 1 will be
its result if and only if both expressions are true. The
advantage of this definition of the operators AND shown in the
examples below. Let us assume that variable MAKSIMUM we want to
assign value of the maximum of the numbers A and B. For
this, only one instruction:
LET MAKSIMUM = (A AND A> B) + (B AND
A <= B)
Brackets in this expression is mandatory
because of the high priority of the operation +.
Even more visible results can be obtained by working with
texts. The next program will recognize the floor using their
Name:
10 PRINT "give your name": A $
20 PRINT "HELLO SIR" + ("AND" AND A $ (LEN
A $) = "A")
Com. Ed.: The book was translated from Polish.
Not raspologaya operation AND of this type would need to be
re-used instructions IF ... THEN, as well as GOTO .. .
3. 4. 9 logical addition (OR)
Operation OR - dvuhargumentnaya. Both arguments must be
numeric expressions. The effect of this operation as follows:
| 1, if Y <> 0
X OR Y = |
| X, if Y = 0
Application of OR is the logical expressions
significantly less than the AND. For example, the user,
calculates a maximum of two numbers can be written in the
following form:
LET MAKSIMUM = A * (0 OR A> B) + B * (0 OR
A <= B).
3. 5 Functions
ZX-BASIC provides a set of standard
functions for mathematical calculations, operations on
sequences of signs, and to survey the screen and keyboard.
Except for the ATTR, POINT and
SCREEN $ arguments are constants
or single variables (simple or
arrays) is not required to enter in brackets.
ABS X - Absolute value of X.
ACS X - Arccosine X (in radians). If
X does not belong to the range [-1,1], is indicated by the
error A (Invalid argument).
ASN X - arcsine of X (in radians). Restriction on use is the
same as that ACS.
ATN X - arctangent of X (in radians).
ATTR (K, M) - Specifying attributes in K-m
operator, and M-th column. Way to encode attributes described
in the chapter "Using the memory." If the parameters are not in
ranges from 0 <= K <23 and 0 <= M <= 31 is signaled by an error
B (the excess of the permissible value).
BIN - Convert a binary number
unsigned (maximum 16 digits) to decimal (on screen) or in the
form adopted in ZX-SPECTRUM (in memory). ZX-BASIC has
function, performing the inverse transformation of a decimal
number to binary.
CHR $ K - Substitution of the appropriate character ASCII,
or control character if K does not belong to the range [0, 255]
signaled an error B.
CODE F - Replacement of ASCII characters on the number.
Argument is any alphanumeric And digital expression, and
function value is the first character of this expression, or 0
if the argument is an empty string.
COS X - Cosine (X in radians).
EXP X - The function e ^ x.
IN K - Poll port processor. Corresponds to the two assembly
instructions CPU Z80:
LD BC, K, and
IN A, (C).
Value of the function IN is an
number in the range [0, 255]. This single statement, which might
lead to what your program does not
will be performed on other specimens
ZX-SPECTRUM! Application of IN to read from the keyboard: each
row is divided into two groups of five and each group of five
belong to a port (or buffer as someone calls it):
_____________________________________
| | |
| | Buffer number |
| KEY |---------------------|
| | 10 LIMITED | 16-hexadecimal |
|---------------|---------|-----------|
| CS ... V | 65276 | # FEFE |
| A ... G | 65022 | # FDFE |
| Q ... T | 64510 | # FBFE |
| 1 ... 5 | 63486 | # F7FE |
| 0 ... 6 | 61438 | # EFFE |
| P ... Y | 57342 | # DFFE |
| ENTER ... H | 49150 | # BFFE |
| SPACE ... B | 32766 | # 7FFE |
|_______________|_________|___________|
Five bits in this buffer signal which key is pressed
(0-pressed, 1 is pressed). Difficulties arise with the three
older bits. In a second version of the ZX-SPECTRUM (oldest),
they are always equal to 1. Cledovatelno IN 64510 = 255 means
the release of the key between Q and T. Version 2 sixth bit is
0, and in this situation IN 64510 = 191. In version 3 state
sixth bit is not defined and requires additional surgery, such
as:
LET P = IN K: LET P = P-32 * INT (P/32)
Reading from the keyboard using the IN does
the ability to recognize multiple simultaneous keypresses.
INKEY $ - Reading keyboard. Value
function is the sign of the key pressed.
The keyboard is read in the modes of L and C. If
a few keystrokes or not pressed any
one, the value INKEY $ will be empty
chain. This function does not wait for a keypress.
INT X - The whole part number. The actual number is rounded
to the nearest whole not exceeding X. For example:
INT 3.1 = INT 3.9 = 3, INT -5.1 =- 6.
LEN F - Length of the chain of characters.
LN X - Natural logarithm of X. If
X <= 0, signaled with error A.
PEEK K - The contents of the memory cell with address K.
PI - The value of constant 3.14159265
(Pi).
POINT (K, M) - Checks the status of the screen. This
function has a value of 1, if the point on the screen with the
coordinates (K, M) is the color of ink (brought) and 0 if
has a background color. Detects derived
point even when pouring the background color with the color of
ink and they are invisible. Coordinates should be in the ranges
0 <= K <255 and 0 <= M <= 175.
RND - random number generator.
The next value is SEED/65536,
SEED where double-byte system variable
with the address 23671 (# 5C76). Every time a challenge RND is
modified in accordance with the formula: SEED = ((SEED +1) * 75
MOD 65537) -1 (X MOD Y: the remainder after dividing X by Y).
Thus the generated sequence within 65536. Variable SEED
You can set the initial value of the instruction RANDOMIZE K.
SCREEN $ (K, M) - Detects symbol on the screen. This
function is based on the shape determines the character
displayed in the intersection of K-th row and M-th column.
Recognized only characters with codes from 32 to 127. In case
of no Character Recognition, the value function is an empty
text. Coordinates must be within the ranges
0 <= K <= 23 and 0 <= M <= 31.
SGN X - Badge number. Function value
are the numbers -1, 0, 1 depending on
sign of the argument.
SIN X - Sine (X in radians).
SQR X - The square root of X. If
X <0 error signaled A.
STR $ X - Replacement of a chain of characters. This
function replaces the binary representation of numbers on the
character, which may be provided on the screen.
TAN X - Tangent (X in radians). X is not
must be a multiple PI / 2.
USR - The work of this function depends on
type argument. Her challenge with a numeric argument (USR K)
activates the machine code at address K. After its
implementation, and return control to BASIC, the value
function is the contents of a pair of registers
BC. If you call with a text expression (USR F), where F
contains little or big letter 'A to U inclusive,
function value is the address of
UDG, from which stores 8 byte,
determine the form of a graphic symbol,
user-defined and the resulting
G mode by pressing the appropriate letters.
VAL F - Calculates the value of a numeric
expression, represented in symbolic
form. Very important function with a variety of applications.
If the expression F is not is true (for BASIC), a numeric
expression, an error is signaled C. In the course of
calculation can be other errors, depending on the type of
expression.
VAL $ F - Defines the text
expression, represented in symbolic
form. Scope of less than
VAL. Difficult to find situations in which it
application is necessary, but the output text variables with
names that are unknown to be determined only during program
execution. Assume that the value of the variable A $ is a
letter, defines the name of an alphanumeric variable. Not
having this feature, we would have considerable difficulty in
printing the variable. PRINT VAL $ (A $+"$").
Unfortunately, not all functions are performed
in full accordance with the intention of the authors
ZX-BASIC interpreter. In the chapter "Errors
system, we present the known inaccuracies
to serve as a SCREEN $, STR $, and USR.
3.6 How ZX-BASIC
ZX-BASIC presents us with 50 instructions. All of them can be
placed in a program or executed immediately,
as the orders issued from the keyboard.
BEEP X, Y - Allows you to generate sounds. 0.5 <= X <10.5 -
playing time in seconds. -60 <= Y <= 69.8 - pitch. Value Y = 0
corresponds to the note "si" middle octave. Range Y corresponds
to approximately three octaves. Out of the valid values
signaled by the message B. During the generation of tone is not
controlled by key , And therefore the interruption of a
program is possible only upon completion of this instructions.
BORDER K - This command sets the color of the frame (border)
on the TV screen. 0 <= K <= 7 - The number of the selected
color. Exit beyond signaled by the message B.
BORDER K team set the color
background in the bottom of the screen, designed for system
messages and data entry instructions INPUT.
BRIGHT K - Shade the background. K = 0 - normal, K = 1 -
bright. K = 8 - is in This field is defined in its earlier
ottenok.BRIGHT K may act as an independent or as part of
statement PRINT or INPUT, acting in this case
for the duration of headache
instruktsii.Proverim it to print CHR $
19 + CHR $ K. These characters can be entered as a
program text and in text
constant, pressing in advanced mode
(Cursor E) key <8> how BRIGHT 0 and press <9> how BRIGHT 1.
CAT ... - This statement can only be used with connected
ZX-ITERFEYSOM-1.
CIRCLE [C,], K, M, N - Conclusion of the circle
radius N centered at the point (K, M) Color
C. If C is omitted, it is accepted INK 8
PAPER 8, BRIGHT 8, FLASH 8. Valid
values: 0 <= K <= 255; 0 <= M <= 175.
Trying to draw a circle outside the
display an error B.
CLEAR [K] - Clears the region variables
freeing the memory occupied by them, erase the screen and stack
address to return from subroutines, executes a RESTORE, resets
the pointers that determine the coordinates for depicting and
writing instruction. If is set K, its value will be accepted as
a new RAMTOP. K must be within 23821 ... 65535, otherwise the
message M (RAMTOP NO GOOD). If the memory computer already has
a program, then K must correspondingly increase. Too little
RAMTOP value may make it impossible
execution of programs and commands from the keyboard.
CLOSE # K - This command disables the K-th
flow from the channel attributed to him. Although K
can take values from 0 to 15,
practice attempt off flows from 0
3 system is ignored. See chapter on "Channels and streams" and
"system error".
CLS - Clears the screen and clears the screen
Indices printing instructions and graphics.
After erasing the screen gets the color defined by the latest
regulations PAPER and BRIGHT.
CONTINUE - This instruction allows
to continue the program after a stop. If an interrupt was
received as a result of error signaled from 9 to L, then after
CONTINUE will repeat the last executed instruction, in other
cases will follow the instructions. This
allows you to fix the keyboard found
errors and continue. This instruction
not applicable to the directives given by a
keyboard. Localization CONTINUE the program is not done on
purpose, because her job depends on the current values of
system variables OLDPPC and OSPPC. Ie, in its
turn, modifies the system and track and manage their condition
can be difficult, especially during
testing program.
COPY - SPECTRUM If the printer is connected, then the
contents of this team in 1922 the upper rows will be copied to
paper (Copied not only text but also figures). In the absence
of the printer, this statement is simply ignored. SPECTRUM
itself determines whether the printer is connected. During
findings of the internal timer is stopped. FRAMES system
variables at this time does not modified.
DATA - Allows you to place the text
program listings data. The list can be
place any expression:
100 DATA SIN X + COS X +1, "VALUE"
+ ("Put." AND Z> 0 + ("negative." AND Z <0)
110 READ Z, Z $
Variable Z takes the value of SIN X + COS X
+ 1 calculated for the current values of X and
Y. Variable Z $ will contain the string
"The value of POSITION." or "VALUE Negative." in
Depending on the calculated Z. Meaningless to ask the DATA
command from the keyboard as SPECTRUM after checking the syntax
immediately forget about it. The program can
attend any number of instructions
DATA, posted anywhere.
DEF FN[$]([a [$],2 [$],....,I [$]]) =
E - Determination of the function the user.
Function name can only be one letter, perhaps with a $ sign.
Its use determines the type of function as a text. After the
name in brackets is mandatory You can specify a list of
arguments separated by commas. You can define bezargumentnyh
functions. Argument names should be odnoliternymi (possibly with
$ sign). Restriction on the number of arguments: 52 (26 numeric
and 26 alpha-numeric). After the closing parenthesis of the
parameter list and the "=" follows the definition function.
They can be any expression of the type consisting of a fixed,
variable, arguments, standard functions and functions defined
by the programmer. Should avoid a recursive procedure call,
both indirectly and directly. SPECTRUM does not recognize this
situation. After filling out the memory will message (1 or 6),
or even reach system crash. Instruction DEF FN has
sense to ask the keyboard. But with the keyboard, you can call
functions that are available in the program. Placing definitions
functions and their call is not important. In
the case of multiple definitions in the text
program functions with the same name and
types, the current definition is
version placed in the row with the smallest
number. Note that the function definition can serve the names
of the variables used elsewhere in the program. Unique: the
variables that have names identical parameter names become
for the "invisible" and instead
act values of the function.
DIM[$]( K1 ,...., KJ) - Announcement
array. This command allocates memory
place for a numeric or text array. The dimension of the array
is limited by the 255. Some index of the specified upper
boundary, the lower is always
1. The order clears the memory existing
array with the same name as the same type.
Values that define the dimensions must
be known at the time of executing the DIM, but not necessarily
at the time the program starts. Numeric arrays at the moment
definitions are automatically filled with zeros, and text -
with spaces. Elements the sign of the array are single
characters. Such arrays can be interpreted as arrays of simple
text variables the same, predetermined, length. The length of
this set last set parameter that determines the array. Refer to
an array of characters as a list of simple text variables
should be lowered when the last index. If a program announced:
DIM A $ (10): DIM B $ (5,20),
then A $ = A $ () is an alphanumeric variable of length 10 and
B $ (I) = B $ (I,) is the five variables with a length of 20.
If
LET A $ = "ARA",
the length of A $
20 characters, too, lacks the symbols are automatically padded
with spaces.
DRAW [C,] K, M [, X] - This instruction
allows you to draw straight line segments (X is omitted or is
0) and fragments of a circular arc with central angle X,
expressed in radians. Beginning of the picture is the last
point graphics instructions (POLT, DRAW, CIRCLE) - (XOLD,
YOLD), and end point (XOLD + K, YOLD + M). If X> 0, then the arc
drawn counterclockwise, and for X <0
- Clockwise. Curious recommend to verify the following commands:
PLOT 55,27: DRAW OVER 1, 120, 120,
59-3 * PI
ERASE ...- instruction operates
only if the ZX-INTERFACE-1
FLASH K - Enable flicker field.
K = 0 - no flicker, K = 1 - there is a flicker and
K = 8 - means that the status of the field
should remain unchanged. FLASH as
self-instruction specifies how the emission within the whole
program is placed on the list, or PRINT INPUT, only during the
performance of the specific instructions.
FOR @ = X TO Y [STEP Z] loop: perform
to @ X to Y increments Z (Z> 0 - an increase, Z <0 - decrease).
End of the cycle indicates the command NEXT @. The task is to
create a FOR statement control variable (after the destruction
of memory or number of control variables with the same name).
This variable is in memory representation other than numerical
variables, but its value is stored as Y and Z, and the line
number instructions FOR. After forming the controlled variable:
Can the cycle be performed at least times. If yes, then control
is passed following the FOR statement. If not, then
following the NEXT @ team. If NEXT @
not, then the message I. If STEP
omitted, then Z = 1. Despite the fact that
ZX-BASIC does not formally distinguish numbers with
floating on the whole, the entire X,
Y, Z processing cycle is accelerated by 20%.
FORMAT ...- instruction is valid only
if ZX-INTERFACE-1.
GOSUB K - Calling the subroutine. This team puts in a
special stack your own address, and then passes control to the
line under the number K (or the first greater). Next, commands
are executed before meeting with the team RETURN, after which
removed from the stack address of the last GOSUB
and control is passed to address the following
him. Subroutines allow you to perform
the same sequence of commands
different parts of the program without their repeated
recurrence. To a depth of subroutine call is no limit. Allowed
rekurentnost, ie subroutine call itself themselves.
GO TO K - Go to line number K
or the next. If no such line, then
The program ends with the message 0. This
command typed from the keyboard launches
program with the specified string. Running the program with the
help of GO TO (in comparison to RUN) has the advantage that it
does not cause the loss variables.
IF X THEN S - Conditional statement. If
value of the expression X is different from 0, the following
command sequence S. In Otherwise, all commands to the end
lines are skipped and control passes to the next line.
INK K - Determination of color next
characters on the screen. This command defines
color black. The values of K from 0 to 7 define the number of
the selected color, 8 - indicates consent to the color of the
previously defined for the field screen, 9 - specifies the use
of white or black colors Depending on the contrast set in this
field, the background color. In the lower line of the screen,
the system always uses INK 9. This instruction can be applied
both independently and in a list
statements PRINT, INPUT, CIRCLE, etc..
INPUT ...- Lets run-time input from the keyboard data
for the listed variables. This command also allows entry into
the lower part screen. The inscription is preserved only for a
while input. The keyword INPUT should
list of elements that determine what and how
must be fulfilled. List Items
must be separated by a comma, a semicolon-
commas or apostrophes. The comma indicates that it is necessary
to move the cursor to the next half the screen in the same
line, and if not, then the beginning of the next
line. The apostrophe indicates the transition to a new line,
and the semicolon does not change cursor position. Items in the
list provided to the map on the screen, must be constants or
expressions, enclosed in parentheses. Specifications Color INK,
PAPER, BRIGHT, FLASH, INVERSE and OVER it possible to obtain any
color effects. Variables whose values should be set from the
keyboard should be entered in the list one by one between
delimited. If we want the program to be considered with a
keyboard array element A (I, J) and inform the user what she
expects from him, then we use Instructions:
INPUT "Enter Base Element value"; A (": I ;",",";( J );")=;
A (I, J)
INPUT instruction is waiting for input data and ends only
after entering all variables specified in the list. Each
the value of variables when writing to
complete pressing <ENTER>. If
enter text variable, then the key
<ENTER> Instead of typing in its value will
addition of the variable space.
Requests for numeric variables can not be ignored in this way
and it is necessary enter any number, using any
expression, there are variables and
constants. When reading the values of numerical variables at
the bottom of the screen blinking cursor L or C, but when you
enter the sign sequence of the cursor will appear, along with
the surrounding quotes. If necessary, you can remove them. It
is possible to read text without these quotes. In this case,
the text variable you must mark the list with the keyword LINE.
One LINE will relate to one variable. Never use the word with
the numeric variables. During the execution of instructions
INPUT, two bottom of the screen, if necessary, will move up,
creating free space for output and input data.
This domain may be possible to expand
up to 22 lines. Entering data is based on the editor. Due to
this before you <ENTER> Possible any revision of these
quantities. In the INPUT besides You can post TAB n, as well as
AT K, N. The action of the first of them is moving the cursor
to the n-th column in this or next line. In turn, AT will place
the cursor at position (K, N), which means that the K-line and
the N-th column. Some difficulties may cause the fact that the
position of the origin - of the field (0,0) varies with the
expansion of bottom screen. Field always points to the left
the upper corner of the workspace editor and
value of the field (K, N) is determined by this. Attempts to
expand the area above 22 lines end error signal 5. Before that,
the computer can express its disapproval of grunt.
INVERSE K - Another determinant
chroma. K = 0 denotes the flashing
define a background color and ink, and K = 1, rearrange them.
Can be used both independently and in a list of instructions
PRINT, INPUT, CIRCLE, etc.
LET V = E-Assigning variable values. Its implementation is
based on the evaluation of an expression E, and assign the
resulting variable V, if such a variable already exists. If V
is not yet, then it organized in the field of memory. This does
not apply to arrays, which must be declared before
use.
LIST [K] - Displays the text of programs written in BASIC
with the ZX-K-th row. If K is omitted, the value is
K = 0. This command sets the current row in K, making it
available for editing. The conclusion is always done before the
end of the text of the program to 22 line (see PRINT).
Interrupt can be after the bottom of the screen issue: SCROLL?
- By pressing one of the lower Key: BREAK, STOP, or N.
LLIST [K]-instruction is similar to LIST,
but the print is made on the attached
printer. When the printer is not, LLIST only
sets the current row to
line K. During printing, the program stops the timer (system
variables FRAMES are not modified).
LOAD ... - SPECTRUM can be read with
Tape different data types. LOAD F
is read from the tape program
BASIC language written on the tape as a set with the name F.
All other data sets on the tape are ignored. Instead of the
full set of finds can be given empty string of characters: LOAD
"". Then will read you the first set of data
BASIC language, regardless of its name.
After finding the tape needed blocks that are in memory of the
program and variables are removed (modified by the relevant
system variables and only small number of memory cells changes
its value) and prepared a place
for the new program. Access to remote
According to the system is impossible.
LOAD F DATE @ [S ][()] - Reads a numeric or text array, and
places it in of variables named @, removing
in front of this array with the same name and those
same data type. @ Must be the name under
who performed the array before writing to tape. The dimension
of the arrays are not given, but the brackets are required. As
text arrays can be read and write simple variables of this type.
LOAD F CODE [K [, N]] - The shape operator
can read a set of bytes without
determine their structure. Parameter K says, to what address
should be written in memory of the read block, while N
determines its length. If these options are omitted, the
set will be read at the same place, with
which was dropped on the tape. This
instruction does not check whether the read block to destroy
vital for system information, and carelessly filled
appropriate area of memory with new information. Setting the
value of the parameter N less than the actual length of
recruitment to tape, signaled by the message R, and
therefore, this statement can only read the intro blocks
(Unless it is turned off the tape in the process
reading).
LOAD F SCREEN $ - is a special case LOAD F CODE and responds
exactly LOAD F CODE 16384,6912 reads the screen with
attributes. After the data and
programs on a tape there are 2 kinds of errors.
Technical problems signaled by the message R. When reading is
too long units (a special case when RAMTOP set too low) appears
4.
LPRINT ...- instruction works like
PRINT, but the data is sent to the printer.
When the printer is not, the instruction is ignored. Placed in
the list of qualifiers LPRINT colors PAPER, INC, FLASH, BRIGHT
will ignored. Separators, as well as TAB
operate normally. In the first AT
parameter (line number) is omitted. Print
by using a buffer length of 32
mark (256 bytes). Print actually comes after filling the
buffer, the teams move to the new line, as well as at the
moment normal completion of the program. After the termination
of a program error or user intervention seal by pressing
<ENTER>.
MERGE F - Reading program in BASIC from a cassette tape and
attach it to those already existing in memory. Line, whose
numbers in both programs overlap, replaced by new ones. As well
as the variables with the same name. The remaining rows and the
variables entered in the appropriate area of memory. This
allows create libraries of routines for later use. Action
instruction based on reading the entire block in the workspace,
and only after of the old and new programs combined. At long
programs that process may take several minutes. Directive
can be applied even when the memory
nothing. Differs from the LOAD F significantly long lead time
and order that does not start the program even if it
was recorded SAVE F LINE K (which is very
valuable for the pirates!). Instead of the name can be
use an empty text.
MOVE - The command is valid only in the presence of
ZX-INTERFACE-1.
NEW - Instructions operates virtually
as a power failure. Initializes
BASIC system, retaining only the system
variables RAMTOP, PRAM, RASP, PIP, UDG.
Memory below RAMTOP cleared and the area above
RAMTOP remains intact.
NEXT @ - Instructions, closing the cycle
(FOR ...). After meeting with Larry NEXT @ @ finds the control
variable increases its value by step, and compares with the
limit value. If it has not yet surpassed, then control is
passed to the statement following the corresponding FOR.
Otherwise case, the program will begin with
following the NEXT @ command. If the field variables are not
there exists a numerical @ variable, it is signaled by the
message 2. If this variable is not managing - message 1. At the
same time can be arranged up to 26 cycles. Control variables
can be used as an inside loop and outside
it as a normal numeric variables. After
opening of the cycle can not be modified or
limit, a single step. There is no limit on the relative
positions of cycles. For example, the construction below is
unacceptable in other versions of BASIC, would be perceived
ZX-BASIC, a correct design:
100 FOR I = 1 TO 10
200 FOR J = 10 TO 20
300 PRINT I, J
400 NEXT I
500 NEXT J
OPEN # K - Specification channel directives
allows you to connect the K-th stream to the specified channel
(see section on "Channels and streams). "Naked" SPECTRUM
(without external devices, and specifically without the
ZX-INTERFACE-1) recognizes only the channels "S", "K", "P",
"s", "k", "p". You can not use streams 0 ... 3, the other 4 ...
15 are available to the user.
OUT M, N - M should be a number from 0 ... 65535, N - in the
range -255 ... 255, with negative numbers
will automatically increase by 256
(Hence OUT M, -3 is the same,
that OUT M, 253). This instruction allows
BASIC level to send information to the ports
O processor can be used to
work with external devices. This
User analog assembly instructions:
LD A, N
LD BC, M
OUT (C), A
OVER K - Qualifier ways of applying
dots or symbols. K = 0 means the replacement
existing point or mark on a new and
K = 1 causes the imposition of new signs on the already
existing ones. In places where old and new
mark or point have the same color -
is the background color, the same place where the different
colors - there is ink color. The new figure is, therefore, the
inversion previous color. This allows you to delete
single points, lines on the screen and so on.
As well as to specifiers colors scope set mode drawing
may be global in the whole program
or only for the duration of a typewriter
or risuyuschey instructions.
PAPER K - Qualifier background color. K value from 0 to 7
determines the number of the selected color, 8 indicates
consent to color, previously defined for the field screen, 9
specifies the use of white or black colors depending on the
Contrast set in this field
background color. At the bottom of the screen, the system
always uses PAPER 9. This statement can be used as an
independent, and a list of instructions PRINT, INPUT,
CIRCLE, and so on. The background color may appear
in two different shades (sm.BRIGHT).
PAUSE K - Temporarily stopping the program. The parameter K
determines the delay in the 50's fractions of seconds. Pressing
any key aborts a pause, regardless of the distance time. The
value of K = 0 means stop, continuing to press any key
(See section "System Errors").
PLOT [E,] K, M - Draw a single point with coordinates 0 <=
ABS K <= 255 and 0 <= ABS M <= 175 on the screen. The origin is
placed in the lower left corner, above the 2-row reserved for
system messages. This directive can not be applied in two
Lower operators.
POKE K, N - This instruction is in a cell with
address 0 <= K <= 65,535 loads the number of
-255 <= M <= 255 (increased by 256, for
M <0).
PRINT ... - Quick display
sequence of characters and numbers. PRINT
prints the elements of the list in the upper
22 lines screen. The list can accommodate the same thing as on
the lists INPUT. No need to enter the expression in
brackets, which before the call to be
calculated. Better to use AT K, N, if
position of the origin is a regular (upper left corner).
Parameter 0 <= K <= 21 defines a row, and 0 <= M <= 31
- Column. Allowable values
parameters signaled by the message 5.
After filling out the 22 lines the screen before
rest of the output, the computer offers
continue output (SCROLL?). Key
, <N> Or terminates the program with the message
D, the remaining express consent to shift the screen.
RANDOMIZE [K] - In principle, this procedure is to
initialize the random number generator (RND). If the parameter
K is given and is not 0, then it is placed in the system
variable SEED. That is there with him, has been described above
(Function RND). Missing parameter or set K = 0 will cause
placement in two SEED low byte of system variables FRAMES.
Side application instructions RANDOMIZE
can be assigned values and junior
high byte of the integer K
Hosted in the range 1 ... 65535.
Fewer bytes is referred to as PEEK 23670,
a senior as PEEK 23671.
READ V1, V2, ... - This command sets
another variable from the list of values
respective expressions, enclosed in
lists DATA. Each of the statements READ
modifies the corresponding system variable DATADO, remembering
a list of expressions DATA was read last. Attempt to read
non-existent data signaled by the message E.
REM - Insert comments. After the word
REM can accommodate any sequence of characters (with the
exception of the symbol with Code 13), which is when the
ignored.
RESTORE [K] - This instruction establishes a system pointer
to the first expression in the list of DATA in line with the
number of K or the first large. If K is omitted, the default
value is 0. Before the new starting the program instruction GO
TO necessarily need to use a directive RESTORE (if in this
program are the operators of READ).
RETURN - Return from subroutine.
RUN [K] - Running the program in BASIC.
Program execution begins with the string
K or if K is omitted from the beginning of the program.
Before starting the program automatically RUN
executes the command CLEAR, which corresponds to
elimination of all variables.
SAVE ... - Instructions inverse LOAD. C
it means to tape record the program
in Basic, the numeric or symbolic arrays
as well as a sequence of bytes for
clarify their structure. Form of the command is the same as
that of LOAD with the difference that must not omit a single
parameter. Name under which the block should be recorded on
tape, must be non-empty sequence of characters in length, not
exceeding 10. When writing programs in BASIC after the name can
be placed LINE K. Recorded so the program after reading will
automatically start with line with the number K.
STOP - Stop the program. The program can be continued by
pressing .
VERIFY ... - The presentation of this
How similar instructions LOAD ...
. However, nothing in the computer does not read, but only
checks whether the contents of the memory areas with that is
recorded on tape. All identified discrepancies message signaled
R.
3.7 Control characters
Among the characters used in
ZX-SPECTRUM, a so-called control characters. They have codes
less than 32 (Not all codes are used). Their application at the
ZX-BASIC limited since the same effects can be obtained
with other instructions. However, they
essential for programming in machine
codes. Below are those input which gives an effect:
CHR $ 6 - This symbol may be used instead of a comma as a
separator lists INPUT and PRINT.
CHR $ 8 - shifts the cursor on one
box to the left. CHR $ 9 - See the chapter "System Error".
CHR $ 15 - This is the symbol keys <ENTER>. In
lists INPUT and PRINT can be used
instead of a single apostrophe. The programs
ZX-BASIC it is placed at the end of each
line.
CHR $ 16 - Keyword INK.
CHR $ 17 - Keyword PAPER.
CHR $ 18 - Keyword FLASH.
CHR $ 19 - Keyword BRIGHT.
CHR $ 20 - Keyword INVERSE.
CHR $ 21 - Keyword OVER.
CHR $ 22 - keyword AT.
CHR $ 23 - Keyword TAB.
Characters from CHR $ CHR $ 16 to 21 should
recruited in the form of CHR $ K + CHR $ M or
CHR $ K; CHR $ M, where M is the value corresponding to the
instructions of the parameter.
After the character CHR $ CHR $ 22 and 23 should
follow the 2 parameters. For AT is understandable,
and for TAB is the only argument is two bytes. In practice, the
value the second byte (the elder) does not matter, because this
number is taken modulo 32.
The remaining control characters used by the editor in the
process of reading the keyboard and has no practical values
for programmers. During the sequence of signs, symbols do not
described above, with codes below 32 are replaced
voprostitelnym sign.
3.8 System messages.
Each error detected by the computer
in the program, calls the shutdown and call the appropriate
message at the bottom screen. These messages have the same
standard form:
NO TEXT MESSAGES K: M
Number - any number from 0 to 9 or letter from
A to R. Text of report in English the reason for the transfer
of control to the editor. Numbers K: M informed in a row which
instruction caused the message. K =
0 refers usually to the commands given by directly using the
keypad.
0 OK
Normal completion of commands issued
from the keyboard, the end of the program, or go through GO TO
on the line with the highest number. When servicing an "error"
do not modify the system variables
OLDPPC and OSPPC, resulting in a team
CONTINUE, issued after this message
again will cause the execution of the last
instruction in the program (this does not apply to
Directives from the keyboard).
1 NEXT without FOR
Larry met manual NEXT
@. In the field variables do not have control
variable with the given name of the @, but there
simple numeric variable @. If it were not
was such that in a similar situation
would receive a message 2. Most
frequent cause of errors is the lack of
corresponding instruction FOR or transition
inside the loop.
2 Variable not found
Trying to use a variable that is not
existing in the field variables, and therefore one that is not
attached no difference with
LET, READ, INPUT, FOR, or DIM.
3 Subscript wrong
Array indices exceeded the limit
value (but fit in the range
0 ... 65535), or set incorrectly
number, as well as an attempt to assign characters
simple alpha-numeric variable, with
dimension greater than the length of the variable.
If the indices exceed the value 65535, then
in a similar situation appears
B.
4 Out of memory
Not enough space in memory to perform the required action.
Most often when follow instructions for LET, READ, INPUT,
DIM, GOSUB, LOAD, MERGE, attempts to recursive function calls.
Generally, the reason is too low position RAMTOP.
For the withdrawal of emergency may
be necessary to remove any
line from the program, so as to obtain
space required to comply with the directives given by the
keyboard.
5 Out of screen
INPUT is trying to take more than 22 lines
or parameters of AT indicate the field for 22
top of the screen.
6 Nomber too big
During the calculations carried out was an attempt to go
beyond 1.7E38. This is to end with attempt to divide by zero,
or computing TAN (PI / 2).
7 RETURN without GOSUB
An attempt to execute RETURN without prior GOSUB, and when
the number of GOSUB performed less than the number executed
RETURN.
8 End of file
This message may appear if ZX-INTEFEYSA-1.
9 STOP statement
Follow the instructions STOP.
A Invalid argument
Invalid argument specified standard
functions, for example, attempt to calculate the SQR
or LN for negative numbers, or alphanumeric argument of USR is
not one correct letters. This error does not refers to the
arguments of the functions defined by the programmer.
B Integer out of range
Integer parameter statement exceeded the limit value.
C Nonsens in BASIC
Analyzed text is incorrect from the point
of language rules. Most often occurs when the arguments of VAL
or VAL $ does not represent the true form of expression.
This message appears when you try to
Unrecognized command execution system
For example, read and run the program,
working with MICRODRIVE, and ZX-INTEFEYS-1
not connected.
D BREAK-CONT repeats
The work program is interrupted during execution of
instructions associated with external devices (printer, tape
recorder or TV set - after the question SCROLL? pressed
, Or <N>). Typed CONTINUE directive to repeat it
times interrupted by the team.
E Out of DATA
Trying to read data from the list of DATA,
if he is exhausted.
F Invalid file name
An attempt to write to a tape set without
name or the name is longer than 10 characters.
G No room for line
Lack of space in memory to another
assembly program, if it is too long
or too low set RAMTOP.
H Stop in INPUT
The program was stopped during the statement INPUT.
I FOR without NEXT
Initialized cycle can not be
never executed (eg, FOR I = 1 TO 0);
and the program of instruction is not NEXT.
J Invalid I / O device
Error when connected ZX-INTERFACE-1.
K Invalid colour
Arguments INK, PAPER, BORDER,
BRIGHT, FLASH, OVER and INVERSE left behind
limits defined for this instruction. This message may also
appear after entering a character that controls the color
if the next input character is introduced with a mismatch
control character.
L BREAK into program
Interrupting the program by the user.
M RAMTOP no good
Attempt to assign a system variable
RAMTOP too small or too big
magnitude.
N Statement lost
Trying to run through RETURN,
NEXT or CONTINUE transition to non-existent instructions.
O Invalid stream
An attempt to send information to flow
connect to any channel or channel number greater than 15.
P FN without DEF
Caused by the instruction that has not been determined.
Q Parametr error
Mismatch of the number or types of
arguments when calling the user-defined functions.
R Tape loading error
Required set was found on the tape
but for some reason can not be read into the computer.
Other articles:
Similar articles:
В этот день... 15 November