Contents / Reference section / BASIC keywords / Previous letter / Next letter / Index
PAGE is a variable which gives the address in memory where BASIC has stored (or will store) the user's program. This is usually automatically set to be the lowest available address in the computer's Random Access Memory but can be changed by the user.
PAGE can be used to enable the computer to store two different programs at the same time in different areas of memory. Use with care.
PRINT PAGE
10 PAGE=&5000
20 PRINT ~PAGE
235 PAGE=TOP+1000
A pseudo-variable giving the address used by the interpreter for the start of the user program. The least significant byte of PAGE is always set to zero by the computer. In other words user programs always start on a "page" boundary where one page is 100 bytes hex (256 bytes decimal).
PAGE=<numeric>
or
<num-var>=PAGE
TOP, LOMEM, HIMEM
PI has the value 3.14159265. It is used in the example to calculate the area of a circle radius R.
100 AREA=PI*R*R
PRINT PI
PI=3.14159265
<num-var>=PI
PLOT is the multi-purpose point, line and triangle drawing statement in BASIC.
The first number which follows the keyword PLOT tells the computer what kind of point, line or triangle it is going to draw. The two following numbers give the X and Y co-ordinates to be used in plotting the point or drawing the line or triangle.
PLOT K,X,Y plots to the point at X, Y in a manner determined by the value of K. The effect of each value of K will be:
0 move relative to last point
1 draw line relative in the current graphics foreground colour
2 draw line relative in the logical inverse colour
3 draw line relative in current graphics background colour
4 move to absolute position
5 draw line absolute in the current graphics foreground colour
6 draw line absolute in logical inverse colour
7 draw line absolute in current graphics background colour
Higher values of K have other effects which are related to the effects given by the values 0 to 7
8-15 as 0-7 but with the last point in the line omitted in inverting actions' - eg using G C0L4
16-23 as 0-7 but with a dotted line
24-31 as 0-7 but with a dotted line and without the last point on the line
32-63 are reserved for the Graphics Extension ROM
64-71 as 0-7 but only a single point is plotted 72-79 reserved
80-87 as 0-7 but plot and fill a triangle. When filling solid triangles with colour the computer fills the triangle between the coordinates given and the last TWO points visited.
88-255 reserved for future expansions.
See the VDU driver section of the User Guide on page 377 for an alternative interpretation of the numbers given above.
Suppose that in the above example PLOT K,X,Y the value of X was 50 and the value of Y was 80 then
"Draw line relative' would mean: draw a line to the point on the screen 50 places to the right of the origin and 80 places up from the origin.
"Logical Inverse Colour" is explained next.
In two-colour modes the logical inverse colour of logical colour 0 is logical colour 1.
In four colour modes the following apply
logical | inverse |
0 | 3 |
1 | 2 |
2 | 1 |
3 | 0 |
In the sixteen colour mode logical colour 0 becomes 15, logical colour 1 becomes 14 and so on.
When drawing lines the computer draws a line from the last point to the X,Y position given.
Normally the origin is set at the bottom left of the screen, but its position may be moved to any point by using the VDU 29 statement. See page 388 for more information.
The graphics screen is 1280 points (0-1279) wide and 1024 (0-1023) points high
The most commonly used PLOT statements are PLOT 4, and PLOT 5, so these two have been given duplicate keywords; MOVE and DRAW.
To print a string at a specific place on the screen use the TAB(X,Y) statement. As an alternative one can join the graphics and text cursors together with the statement VDU 5 so that the computer prints text at the graphics cursor position. Once that has been done then the graphics cursor can be moved with MOVE, DRAW and PLOT statements.
100 PLOT 3,X, Y
PLOT 6,100,220
A statement controlling the generation of points, lines and triangles on the screen.
PLOT <numeric>,<numeric>,<numeric>
MODE, CLG, MOVE, DRAW, POINT, VDU, GCOL
To find out the colour of a certain position on the screen. Suppose that you are playing a game involving moving a car around a race track. On the race track are pools of green oil. To find out if the place where your car is about to move to has oil on it (so that the car will skid) you need to be able to find out if the screen is coloured green at that point.
The number returned is the logical colour of the screen at the graphic point specified. If the selected point is off the screen then the number returned will be -1. There must not be a space between the word POINT and the opening bracket.
1340 colour=POINT(X,Y)
100 IF POINT(X,Y)=2 THEN PRINT "SKID!!"
A function returning a number representing the colour on the screen at the specified co-ordinates. If the point is off the screen then the function returns -1.
<num-var>=POINT(<numeric>,<numeric>)
PLOT, DRAW, MOVE, GCOL
This function finds out how far across the screen the flashing cursor is. The left hand side of the screen is position 0 and the right hand side is position 19,39 or 79 depending on the MODE that has been selected.
1005 X=POS
320 distance=POS
A function returning the horizontal position of the cursor in the current text window.
<num-var>= POS
COUNT, TAB, VPOS
To print spaces on the screen up to a certain horizontal position- for example to align columns
100 column=12
110 REPEAT PRINT" ";
120 UNTIL POS=column
This does not print anything on paper. It does, however, print words and numbers on the screen.
Anything enclosed in inverted commas will be "printed" exactly as it is.
Things not enclosed in inverted commas will be assumed to be variable names and the contents of the variable will be printed out. The exact layout of the numbers and figures on the screen will depend on the punctuation used in the PRINT statement.
The items following the word PRINT are referred to as the "print list".
The screen behaves as if it is divided into vertical strips (or fields) which are (initially) 10 characters wide.
A comma after an item in the print list will cause enough spaces to be printed to ensure that the next item will be printed in the next field.
A semi-colon after an item in the print list will cause the next item to be printed on the same line and immediately following the previous item.
If the print list does not end with a semi-colon then the next PRINT statement will print its output on a new line.
PRINT by itself leaves a blank line. A new line can be forced at any stage in the print list by inserting an apostrophe.
The table below gives examples as they would appear, except that commas have been inserted where spaces would be - to aid counting.
Print position12345678901234567890
PRINT 1,2 ,,,,,,,,,1,,,,,,,,,2
PRINT 10,200 ,,,,,,,,10,,,,,,,200
PRINT;10;200 10200
PRINT "Answer";A Answer42
PRINT "Answer"A Answer,,,,,,,,42
PRINT "Answer",A Answer,,,,,,,,,,,,42
PRINT 1/2 ,,,,,,,0.5
PRINT 1/3 0.333333333
PRINT 3.3'2.25 ,,,,,,,3.3
,,,,,,2.25
The printer can be turned on at any time by typing CTRL B or by the statement VDU 2 in a program. The output of all PRINT statements will then appear on the printer as well as the screen. CTRL C turns the printer output off. See page 404 for more information about the printer.
Considerable flexibility has been built into the interpreter to enable it to print numbers in several different layouts. There is no need to learn to use these options at first but they will be invaluable when layout is crucial. A more detailed explanation of the advanced features is given below.
It is possible to control the overall field width, the total number of figures printed and the number of decimal places printed.
All these features are set with one variable called @%.
In brief, setting
@%=131594 will give 2 decimal places
@%=131850 will give 3 decimal places
@%=10 will return to the normal output format.
For a detailed understanding of the format it is best to consider @% as a four byte number (e.g.@=&01020903) each byte controlling one aspect of the print format. The most significant byte will be called B4. It has a value of 01 in the example above. The least significant byte is called B1 and has the value 03 in the example above.
B4 is tested by the function STR$ to determine the format of strings created by that function. If B4=01 then strings will be formatted paying attention to the setting of @% otherwise @% will be ignored by STR$. Initially B4=00.
B3 selects the basic format thus
00 General format (G format)
01 Exponent format (E format)
02 Fixed format (F format)
In G format numbers that are integers will be printed as integers. Numbers in the range 0.1 to 1 will be printed as 0.1 etc. Numbers less than 0.1 will be printed in exponent format.
Exponent format will always print numbers in scientific notation; 100 becomes 1E2, 1000 becomes 1E3 and 1200 becomes 1.2E3.
Fixed format prints numbers with a fixed number of decimal places. If the number cannot be fitted into the selected field width it reverts to G format. The decimal points are aligned vertically which is ideal for scientific and accounting programs.
B2 controls the total number of digits printed in the selected format. If B2 is too large or too small for the mode selected then B2 is taken as 9. The number is rounded to fit in the B2 digit field.
In G format B2 gives the maximum number of digits that can be printed before reverting to E format. Range 1-9.
In E format B2 specifies the total number of digits to be printed before and after the decimal point - but not counting the digits after the E. Another way of looking at it is to say that (B2-1) digits will follow the decimal point. In E format 3 characters or spaces always follow the final E. Range of B2 in E format is 1-9.
In F format B2 specifies the number of digits to follow the decimal point. Range 0-9.
Bl sets the overall print field width and may have any value in the range 0 to 255 which in hexadecimal is &00 to &FF.
For example accounting purposes would often require fixed format 2 decimal places and 10 character field width.
The four bytes of @ are built up thus
@%=& 00 00 00 00B4 - zero 00
B3 - fixed format 02
B2 - 2 decimal places 02
B1 - character field 0A
so @%=&0002020A the "&" indicating that the number is in hexadecimal. You can, of course, omit the leading zeros.
Here are some other formats:
format | (G2) | (G9) | (F2) | (E2) |
@%=& | 0000020A | 0000090A | 0002020A | 0001020A |
100 | 1E2 | 100 | 100.00 | 1.0E2 |
10 | 10 | 10 | 10.00 | 1.0E1 |
1 | 1 | 1 | 1.00 | 1.0E0 |
0.1 | 0.1 | 0.1 | 0.10 | 1.0E-1 |
0.01 | 1E-2 | 1E-2 | 0.01 | 1.0E-2 |
0.005 | 5E-3 | 5E-3 | 0.01 | 5.0E-3 |
0.001 | 1E-3 | 1E-3 | 0.00 | 1.0E-3 |
0 | 0 | 0 | 0.00 | 0.0E0 |
-10 | -10 | -10 | -10.00 | -1.0E1 |
A statement causing numeric and string values printed on the screen.
PRINT {['][,|;]<string>|<numeric>}['][;]
PRINT#, TAB, POS, STR$, WIDTH, INPUT, VDU
This records numbers and words on cassette or disc. In other words it stores data on a file. Numbers and strings are stored in a special internal format. Before this statement is used the file must have been opened using the OPENIN or OPENOUT statements. See the section on files on page 188 for more information.
PRINT# file, X,Y,Z,A$,"Monday",33
A statement which writes data to files. All values are written in a special internal format:
Integer variables are written as &40 followed by the twos complement representation of the integer in four bytes, least significant byte first.
Real variables are written as &FF followed by four bytes of mantissa and one byte exponent. The mantissa is sent lowest significant bit (LSB) first. 31 bits represent the magnitude of the mantissa and 1 bit the sign. The exponent byte is in two's - complement excess 128 form.
String variables are written as &00 followed by a 1 byte "byte count" followed by the characters in the string in reverse order.
PRINT#<num-var>{,<numeric>|<string>}
This is used as the first part of a name to indicate that it refers to a procedure. See the keyword DEF on page 230 for a fuller description.
10 DEF PROChello(X)
20 LOCAL Z
30 FOR Z=0 TO X
40 PRINT "Hello - how about this for BASIC!"
50 NEXT Z
60 ENDPROC
A reserved word used at the start of all user declared procedures. There must not be a space between PROC and the rest of the procedure name.
DEF PROC<variable-name>[(<string-var>|<num-var>{,<string-var>|<num-var>})]
DEF, ENDPROC, LOCAL
10 REM Tower of Hanoi problem
20 INPUT "Number of disks",F
30 PROChanoi(F,1,2,3)
40 END
50 DEF PROChanoi(A,B,C,D) IF A=0 ENDPROC
60 PROChanoi(A-1,B,D,C)
70 PRINT "Move disk " ;A; " from pile " ;B; " to pile " ;C
80 PROChanoi (A-1,D,C,B)
90 ENDPROC
This statement is not available on cassette based systems. It selects which item in a long file is to be read or written next. Strings and numbers are stored in a long line one after the other. Each integer number occupies 5 bytes, each real number occupies 6 bytes and each string takes up the number of letters in the string plus 2. See the entry PRINT# on page 328 for more details of the file format. The file-pointer can be moved up and down the file to point to any selected word or number. Note that you have to keep a careful track of where each word or number starts to use the function. The number immediately following the keyword PTR# is the channel number allocated to the file when it was opened. A file must be open on the selected channel before this function is used. Files are opened with the OPENIN and OPENOUT statements. See page 188 for more information on file handling.
PRINT PTROX
560 PTR#file=PTR#file+80
85 PTR#channel=0
A statement and function which allows the programmer to move a pointer to a serial file and thus enables random access.
<num-var>=PTR#<num-var>
or
PTR#<num-var>=<numeric>
INPUT#, PRINT#, BGET#, BPUT#, OPENIN, OPENOUT, EXT#, EOF#