Over the next few issues First Steps
will be presenting a complete A - Z guide to Atari Basic aimed at
beginners but with, I hope, some hints and tips which more advanced
users may find helpful. It would take a whole book to cover the
subject in depth but I have included examples of many commands to
enable you to understand them better. If you need additional help or
help in other directions do not hesitate to write to me (with an SAE).
I will try to solve your problems or, at least, turn you in the right
direction.
Many of the BASIC commands have
abbreviations which are shown in brackets. In addition to making
typing faster, these can let you use a great many statements over the
three available command lines only. When LISTed, the commands will
appear as normal but spread over more than three lines. Use of
abbreviations in typing listings will not affect checking utilities
such as TYPO II. The drawback is that editing of entered lines is
limited to the first three screen lines.
Direct mode uses no line numbers and
will execute directly after <RETURN>, deferred mode is preceded
by a line number and will work after RUN <RETURN>
is entered.
ABS
This will return the absolute value of
a variable or expression. This means that you will see the value
without regard to the sign (which will always be positive). This will
be handy when you want a value returned from a mathematical equation,
but no sign.
Example: ? ABS(-0.05)
ADR
This will return the decimal address of
a specified string. The address will change as the computer shifts the
string around in memory to protect it. Most often used with machine
code routines that have been placed into a string and recalled using
USR.
Example: X=USR(ADR(S$))
or S=ADR(S$):X=USR(S)
AND
A
logical operator used mainly with IF/THEN statements. All conditions
must be true for it to work. Example 1 will only equal 3 when X=1 and
Y=2 at the same time. Similarly, with example 2 the expression A will
equal 1 (true) when B is greater than 0 and less than 5, otherwise A
will equal 0 (false).
Example: IF X=1 AND Y=2 THEN Z=3
Example:
A=(B<5) AND (B>0)
ASC
This will return the ATARI-ASCII (ATASCII)
number for the alphanumeric (text character) supplied. The example
will return the ATASCII code 65.
Example: ? ASC("A")
ATN
This will return the arctangent value
for a given variable. Care must be taken to note if the computer is
running in degree or radian mode.
Example: A=ATN(45)
BYE. (B.)
This command will revert to the memo
pad or blackboard mode in 400/800 machines (as will no cartridge), and
to the self-test mode in XL models. Basic programs and handlers (RS232
etc.) will still be held in memory and can be recalled only through
SYSTEM RESET. The screen editor works but RETURN does not send a line
to the interpreter. In older machines, BYE sets up a GRAPHICS 0
screen, however, if you were to set up any other graphic mode with a
window and call BYE, only the window will be in the memo pad mode.
This is because the window is GRAPHICS 0 itself. This means that you
can leave some pretty display for someone to see, but not tamper with.
Or you could exit to BYE to test the graphic symbol keys. Not a lot
can be done with this command, but you can show more than just a
simple screen.
CHR$
This is the opposite of ASC. This will
return the alphanumeric for a given ATASCII value. The example will
return 'A'
Example: ? CHR$(65)
CLOAD
This command will load, from tape into
RAM, a program that has been stored using CSAVE. After <RETURN>,
you will hear a single tone. Press the play button on the recorder.
Then press <RETURN> to enter the program. Anything that was
previously stored in RAM will be wiped out. Once in memory, the
program can be LISTed or RUN. You can use a file name such as
CLOAD"C:NAME" for convenience, but the filename will be
ignored. There is a program (ACE from English Software) that will
differentiate between programs stored on tape. It stores programs by
filenames and will only load the program with the given filename,
skipping over the other files - in the same way as the BBC micro.
CLOG
This will return the logarithm to the
base 10 of a given value.
Example: A=CLOG(65)
CLOSE (CL)
This command will close any I/O device
number that has been opened.
Example: CLOSE #2
CLR
This will clear any strings, arrays, or
variables that have been previously dimensioned in the program. Please
note that ALL dimensioning will be cleared, whereupon you will have to
redimension. This can be very handy when
you only use a string at the start of a program. After use it can be
cleared to save memory. It is also useful in debugging programs.
Unfortunately it is often seen in programs because of bad programming
techniques.
COLOR (C.)
This statement ranges from 0 to 255. In
four colour graphic modes, 0-3 will correspond to the first four
SETCOLOR statements. COLOR 4-255 will then repeat, as only four
colours are available. In two colour modes, 0 and 1 will correspond to
the two SETCOLORS, and then 2 onwards will repeat this pattern. In
text mode 0 however, COLOR will correspond to the 256 alphanumeric
(text) characters available. In the other two text modes, only the
first six bits will determine the character (a maximum of 64). The
last two bits will set the colour of the character (a maximum of
four).
When a graphic screen is called up all
pixels will be set to 0. Therefore nothing will appear when you use
PLOT unless a COLOR statement has been included. COLOR 0 will
correspond to the background colour, that is why no colour appears.
The example will print the first 40 characters on a GRAPHICS 0 screen.
If you try changing to another graphics mode you will notice the
colouring effect that has been mentioned.
Example: 10 GR.0: FOR CH=O TO 39: C. CH: PLOT CH,0:NEXT CH
COM
This is the same as DIM. Not normally
used, it was taken from the original Microsoft Basic that ATARI Basic
is derived from. It means to COMmon variables.
CONT (CON.)
Using this and <RETURN> will
cause the program to start running again after STOP, END, or BREAK has
been encountered. The only problem is that, if the program has been
stopped in the middle of a command line, it will continue on the next
line. Therefore a loop may not be executed and an error may appear. It
is normally used during debugging, but it has a use during the 'forced
read/write mode' (PAGE 6, issue 6) when, contrary to ATARI's Reference
Manual, it can be used in the deferred mode.
COS
This returns the cosine value for a
given variable. Again, care must be taken about degree/radian mode.
Example: A=COS(45)
CSAVE
This transfers what is stored in RAM
onto tape (RAM will not be wiped clean). Two tones will be heard when
you press <RETURN>. You must now press both play and record
buttons on the recorder. Press <RETURN> to transfer the program.
A program saved this way can only be re-entered using CLOAD. Under
certain conditions it is safer to precede CSAVE with LPRINT (LP.).
Disregard any error message generated.
DATA (D.)
This
statement is always used with READ. It holds all the information that
will be used by a program. The bits of data to be read are separated
by commas, and any spaces will be considered as part of the data (this
is one of the most common causes of faulty programs). The number of
READs must equal the amount of data stored, otherwise ERROR 6 (out of
data) will occur. The computer will take care of precisely where the
next bit of data to be read lies in the table. Therefore data
statements can be placed anywhere in the program. Some people prefer
to have the DATA associated with the READ statement, for easier
debugging. Others prefer all DATA to be together, at the end of the
program, for neatness. Both work equally well.
Example:
10 DIM D$(6):FOR T=1 TO 6:READ D$:? D$: NEXT T
20 DATA THIS,HAS,6,ITEMS,OF,DATA
DEG (DE.)
This
will set trigonometrical functions to degrees. The computer is set to
radian mode on power-up.
DIM (DI.)
This
will dimension all strings, arrays and matrices. This means that
memory has been set aside to store data in the above forms. It is good
programming to place DIM statements at the start of a program. It must
be noted that an array (a one dimensional list) and a matrix (a two
dimensional table) both start at 0, whereas a string starts at 1.
Example: 10 DIM A(10): REM Store eleven.
10 DIM M(4,9): REM Store 5 times 10.
10 DIM A$(20): REM Store twenty.
DOS (DO.)
The Disk Operating System (DOS)
consists of two parts. The DOS System (DOS-SYS) which is loaded into
RAM during power-up of the computer with the drive switched on, and
the Disk Utility Package (DUP-SYS) which is loaded by the command DOS.
It will have no effect if DOS-SYS has not been loaded. Calling DOS
will clear RAM, unless a MEM-SAVE file has been set up to store the
current program. Returning to Basic will make the MEM-SAVE file load
the original program. This can take a long time. Types of DOS
(Mini-Dos, Tinydos, etc) use Basic POKEs or XIO to accomplish various
functions without having to load up DUP-SYS.
DRAWTO (DR.)
An initial point must be set up using
PLOT. A line will be drawn from this point to a second point at the
co-ordinates given by DRAWTO. This second point will now become the
initial point for another line again using DRAWTO. A graphic mode and
colour must be designated first
Example: 10 GR.8:C.1:PL. 0,0:DR. 160,80:PL. 319,159
END
This terminates a program, closing all
files and sound channels. BASIC normally does this, so you should not
need END except during debugging. However you will find some programs
do not shut off sounds when complete, so END is needed occasionally.
ENTER (E.)
This will transfer a program to RAM
that has been saved using LIST. It will not overwrite an existing
program, providing that the line numbers are not the same. This is an
excellent way of storing small subroutines and adding them to existing
programs without disturbing the program. This can be done with disk or
cassette.
Example: ENTER "C:"
ENTER "D:PART2.BAS"
EXP.
This will return the exponential of a
given variable. It is safer to limit this to six figures for accuracy.
Example: ? EXP(5)
continues next issue
top