© 1991 Brian R. Page

Blast Off With BASIC

Appendix A: BASIC Commands Quick Reference

 

CIRCLE

STATEMENT

PURPOSE

Displays a circle on the screen. May be used only in graphics mode.

SYNTAX

CIRCLE (X,Y),radius,color,start,end

EXPLANATION

(X,Y) specify the coordinates of the center of the circle.

X is horizontal axis (left to right across the screen), and Y is the vertical axis (top to bottom).

X must be a number in the range of 0 through 319. Y must be in the range 0 through 199.

,radius is the distance, specified in points, from the center of the circle to the edge specified.

,color is a number in the range 1 through 3 which selects a color from the palette currently in use (see the COLOR statement).

,start,end indicate the beginning and ending positions for a partial circle. Positions are specified in radians beginning from the extreme right hand side of the circle. Circles are always drawn counterclockwise. One degree is equal to 0.0174532 radians. Therefore, the starting and ending positions may be listed in degrees multiplied by 0.0174532. If either the starting or ending points are negative numbers, BASIC draws a line from the point to the center of the circle.

EXAMPLE

10 SCREEN 1
20 COLOR 1,1
30 RPD! = .0174532
40 CIRCLE (160,100),60,1                      'FULL CIRCLE
50 CIRCLE (50,100),30,2,(0 * RPD!),(270 * RPD!)       'PARTIAL CIRCLE
60 CIRCLE (280,100),40,3,(-60 * RPD!),(-120 * RPD!)   'PIE

 

 

 

CLS

STATEMENT

PURPOSE

Clear the screen.

SYNTAX

CLS

 

 

 

COLOR

STATEMENT IN TEXT MODE

PURPOSE

Sets the background and text colors.

SYNTAX

COLOR foreground,background

EXPLANATION

foreground specifies a number in the range 0 through 15 to select a color for text.

,background selects a number in the range 0 through 7 for the screen background color.

0 Black

8 Gray 1 Blue

9 Bright Blue

2 Green

10 Bright Green

3 Cyan

11 Bright Cyan

4 Red

12 Bright Red

5 Magenta

13 Bright Magenta

6 Brown

14 Yellow

7 White

15 High-intensity White

 

 

 

COLOR

STATEMENT IN GRAPHICS MODE

PURPOSE

Sets the background and palette colors.

SYNTAX

COLOR background,palette

EXPLANATION

background specifies a number in the range 0 through 15 to select a color for screen background. ,palette selects a number 0 or 1 to chose a palette of three colors.

The actual color of a line or circle is specified by the graphics commands using the colors made available by the palette.

COLOR PALETTE 0 PALETTE 1
1 Green Cyan
2 Red Magenta
3 Brown White

 

 

 

DATA

STATEMENT

PURPOSE

lists data which may be assigned to variables with the READ statement.

SYNTAX

DATA field,field,field,...

EXPLANATION

field

Each field may be a string or number which will be assigned to a variable by a READ statement. Each field must be separated by a comma. If the data field contains a comma, semicolon, or blank spaces, that item must be enclosed within quotation marks. DATA statements are accessed in numerical order. The data in a field must match the variable type used in the READ statement. For example, an attempt to assign alphabetic characters to an integer variable will result in a Syntax error.

EXAMPLE

           10  FOR X% = 1 TO 2
           20    READ INFO$
           30    PRINT INFO$
           40  NEXT X%
           50  FOR Y% = 1 TO 2
           60    READ CHAR$,NUM%
           70    PRINT CHAR$,NUM%
           80  NEXT Y%
           90  END
           100 DATA Here is some input
           110 DATA "which contains a comma, and lots of spaces"
           120 DATA characters,3.14159265
           130 DATA more characters and,3245

 

 

  

END

STATEMENT

PURPOSE

Halts execution of a BASIC program.

SYNTAX

END

EXPLANATION

END may be placed anywhere in a program. As soon as the END statement is executed, program execution stops.

 

 

 

FOR-NEXT

STATEMENTS

PURPOSE

Creates a loop for the repetitive execution of instructions.

SYNTAX

FOR variable = x TO y STEP z

.

.

.

NEXT variable

EXPLANATION

variable the number which is to be used as a counter. This name must be the same on both the FOR and the NEXT statements.

x the variable is set to this value as the loop begins.

y when the variable is greater than this value (for a positive STEP number), the loop is discontinued and execution resumes with the instruction following the NEXT statement. For a negative STEP value, execution stops when x becomes less than y.

z the number z is added to x each time a NEXT statement is executed. Z may be positive, negative, fractional, or zero. If STEP is not used with the statement, 1 is added to x each time a NEXT statement is executed.

EXAMPLE

            10 FOR X% = 1 TO 5
            20  FOR FREQ% = 900 TO 970 STEP 10
            30    SOUND FREQ%,.5
            40  NEXT FREQ%
            50  FOR FREQ% = 970 TO 900 STEP -10
            60    SOUND FREQ%,.5
            70   NEXT FREQ%
            80 NEXT X%
            90 END

 

 

 

 

GOSUB AND RETURN

STATEMENTS

PURPOSE

Temporarily branches to a subroutine.

SYNTAX

GOSUB line. . . RETURN

EXPLANATION

line is the first line number in a subroutine. Execution continues until a RETURN statement is encountered. GOSUB-RETURN statements may be nested. A RETURN statement causes BASIC to return execution to the last executed GOSUB statement. Upon return from a subroutine, execution continues with the next instruction following the GOSUB.

EXAMPLE

   10  GOSUB 60
   20  GOSUB 40
   30  END
   40  PRINT "The first subroutine, at line 40, is the last one called"
   50  RETURN
   60  CLS
   70  PRINT "Subroutine beginning at line 60"
   80  GOSUB 100
   90  RETURN
   100 PRINT "Nested subroutine beginning at line 100"
   110 RETURN

 

 

 

 

GOTO

STATEMENT

PURPOSE

Branch to a specified line number.

SYNTAX

GOTO line

EXPLANATION

line specifies a line number in the program. This line will be the next one executed after the GOTO.

EXAMPLE

            10 PRINT "This is line 10"
            20 GOTO 50
            30 PRINT "This is line 30"
            40 GOTO 70
            50 PRINT "This is line 50"
            60 GOTO 30
            70 END

 

 

 

 

IF-THEN-ELSE

STATEMENT

PURPOSE

Makes a decision based on a comparison.

SYNTAX

IF condition THEN alternative 1 ELSE alternative 2

EXPLANATION

condition is some relationship which BASIC tests to see if it is true. If the condition is true, then alternative 1 is executed. If the condition is not true, alternative 2 is performed.

alternative 1 is any valid BASIC statement.

alternative 2 is any valid BASIC statement.

EXAMPLES

             280 IF CHOICE% = 2 THEN GOTO 600 ELSE GOTO 300
             290 IF CHOICE% <> 2 THEN GOTO 300 ELSE GOTO 600
             300 IF GUESS% = NUMBER% THEN GOTO 140
             310 IF GUESS%  NUMBER% THEN PRINT "Too High"
             320 IF GUESS% <= 0 THEN GOTO 500
             340 IF SUB! = 4 THEN GOTO 500
             350 IF ANSWER$ = "y" THEN ANSWER$ = "Y"
             360 IF QUANTITY% - SUB% <1 THEN GOTO 600
             370 IF X% = 2 THEN TWOS% = TWOS% + 1

 

 

 

 

INPUT

STATEMENT

PURPOSE

Accepts keyboard input.

SYNTAX

INPUT "message", variable,variable,variable,...

EXPLANATION

message contains text to display on the screen before accepting input for the variables. The message may be omitted.

variable the name of a variable to hold the keyboard input. More than one variable may be created by a single INPUT statement. Each variable name must be separated from the others by commas and the keyboard input must similarly separate data fields by commas.

 

 

 

INT

FUNCTION

PURPOSE

Creates an integer.

SYNTAX

variable = INT(x)

EXPLANATION

x the integer value of x is assigned to the variable.

EXAMPLE

            10 PRINT "The integer of 6.5 is" INT(6.5)
            20 PRINT "The integer of 6.2 is" INT(6.2)
            30 PRINT "The integer of -4.7 is " INT(-4.7)
            40 PRINT "The integer of -4.3 is " INT(-4.3)

 

 

 

 

KEY

STATEMENT

PURPOSE

Turns the display of function key settings on or off.

SYNTAX

KEY ON

KEY OFF

EXPLANATION

ON causes the keys to be displayed at the bottom of the screen. OFF causes the key display to disappear. The function keys may still be used even with the display not present.

 

 

 

LEFT$

FUNCTION

PURPOSE

Returns the leftmost x characters of a string variable.

SYNTAX

LEFT$(variable,x)

EXPLANATION

variable a string variable. x the number of leftmost characters needed.

EXAMPLE

            10 WHO$ = "Jabberwocky"
            20 FOR X% = 1 TO 11
            30   PRINT LEFT$(WHO$,X%)
            40 NEXT X%

 

 

 

 

LINE

STATEMENT

PURPOSE

Graphics mode command to draw lines and boxes.

SYNTAX

LINE (x,y) - (x,y),color,BF

EXPLANATION

x specifies the horizontal coordinate. This is a number in the range of 0 through 319.

y specifies the vertical coordinate. This is a number in the range of 0 through 199.

color specifies a number in the range of 1 through 3 to select one of the colors made available with the palette selection of the COLOR statement.

,B instructs BASIC that the coordinates given are opposite corners of a box. With this option, a single LINE command may be used to draw a rectangle.

,BF causes BASIC to fill in the box with the color specified.

EXAMPLE

            10 SCREEN 1
            20 LINE (0,0) - (319,199),1,B          'EMPTY BOX
            30 LINE (50,30) - (70,90),2,BF         'FILLED BOX
            40 LINE (25,20) - (60,20),3            'LINE
            50 LINE (20,180) - (300,10),2          'DIAGONAL
            60 FOR X% = 230 TO 270                 'TRIANGLE
            70  LINE (250,150) - (X%,180)
            80 NEXT X%

 

 

 

 

LIST

COMMAND

PURPOSE

Displays a BASIC program on the screen.

SYNTAX

LIST line - line

EXPLANATION

line specifies a line number to list. If no line numbers are specified the entire program is listed. If one line number is specified, only that one line is displayed. If a range of line numbers is specified, only that range is displayed.

 

 

 

LLIST

COMMAND

PURPOSE

Lists a BASIC program on a printer.

SYNTAX

LLIST line - line

EXPLANATION

line specifies a line number to list on a printer. If no line numbers are specified the entire program is printed. If one line number is specified, only that one line is printed. If a range of line numbers is specified, only that range is printed.

 

 

 

LOAD

COMMAND

PURPOSE

Moves a BASIC program into memory from a disk file.

SYNTAX

LOAD "file path",R

EXPLANATION

file path may include the disk drive, directory, and file name. ,R causes the program to RUN after it is loaded into memory. This option may be omitted.

 

 

 

LOCATE

STATEMENT

PURPOSE

Positions the cursor on the display screen.

SYNTAX

LOCATE row,column

EXPLANATION

row a number in the range 1 through 25, numbered from the top of the screen down. Line 25 may not be used until a KEY OFF statement has been executed to remove the function key labels.

,column a number in the range 1 through 40 in graphics mode, or 1 through 80 in text mode. A PRINT statement following a LOCATE positions output at the indicated position on the screen.

EXAMPLE

            10 CLS
            20 LOCATE 10,20
            30 PRINT "Row 10, Column 20"
            40 LOCATE 20,50
            50 PRINT "Row 20, Column 50"

 

 

 

LPRINT

STATEMENT

PURPOSE

Prints text on a printer.

SYNTAX

LPRINT expression

EXPLANATION

expression may be either variables or characters enclosed within quotation marks. LPRINT functions exactly like the PRINT statement, except output appears on the printer.

 

 

 

MERGE

COMMAND

PURPOSE

Combines two BASIC programs.

SYNTAX

MERGE "file path"

EXPLANATION

file path may include the disk drive, directory, and file name. A file to be merged must have been saved with the ,A option of the SAVE command.

 

 

 

PRINT

STATEMENT

PURPOSE

Displays data on the screen.

SYNTAX

PRINT expression

EXPLANATION

expression may include variables or data enclosed within quo- tation marks. Output may be positioned in print zone fourteen characters wide by separating the fields with commas.

EXAMPLE

            10 PRINT "1","2","3","4","5"
            20 PRINT "1","Here is some long text","2"

 

 

 

RANDOMIZE

STATEMENT

PURPOSE

Seeds the BASIC random number generator.

SYNTAX

RANDOMIZE x

EXPLANATION

x specifies a number in the range -32,768 through 32,767. For a given seed, the BASIC random number generator produces the same sequence of random numbers. For more truly random numbers, the BASIC TIMER function is often used as the seed. To use a random number, see the RND function. The random number generator must be seeded before the RND function can be used.

EXAMPLE

            10 RANDOMIZE TIMER
            20 PRINT RND
            30 PRINT RND

 

 

 

READ

STATEMENT

PURPOSE

Assigns fields in DATA statements to variables.

SYNTAX

READ variable,variable,variable,...

EXPLANATION

variable identifies a variable to hold the data contained in the DATA statement.

DATA statements are READ in line number order. An attempt to READ beyond the last DATA statements results in an Out of data error message. The type of data contained in the DATA statements must match the variable types used in the READ statement.

EXAMPLE

            10 READ WORD1$
            20 READ WORD2$
            30 READ WORD3$
            40 PRINT WORD3$,WORD1$,WORD2$
            50 END
            60 DATA My
            70 DATA Lips
            80 DATA Read

 

 

 

REM

STATEMENT

PURPOSE

Provides a comment line in a program.

SYNTAX

REM expression

EXPLANATION

expression any text.

 

 

 

RENUM

COMMAND

PURPOSE

Renumbers the lines of the BASIC program currently in memory.

SYNTAX

RENUM line

EXPLANATION

line specifies the beginning line number to use for the program. Program lines will be numbered by tens. If line is not specified, numbering begins with line 10.

 

 

 

RND

FUNCTION

PURPOSE

Produces a random number between 0 and 1.

SYNTAX

variable = RND

EXPLANATION

variable the contents of RND may be assigned to a variable. RND acts like a single precision variable holding a fractional number. The random number generator must be seeded before the RND function can be used. See the RANDOMIZE statement to seed the generator.

EXAMPLE

            10  RANDOMIZE TIMER
            20  PRINT INT(RND * (9 + 1))
            30  PRINT INT(1 + RND * 9)
            40  PRINT INT(RND * (10 + 1))
            50  PRINT INT(1 + RND * 10)
            60  PRINT INT(RND * (99 + 1))
            70  PRINT INT(1 + RND * 99)
            80  PRINT INT(RND * (100 + 1))
            90  PRINT INT(1 + RND * 100)
            100 PRINT INT(RND * (999 + 1))
            110 PRINT INT(1 + RND * 999)

 

 

 

RUN

COMMAND

PURPOSE

Causes the BASIC interpreter to execute a program.

SYNTAX

RUN "file path"

EXPLANATION

file path may include the disk drive, directory, and the file name. If no file path is specified, the program currently in memory is executed.

 

 

 

SAVE

COMMAND

PURPOSE

The program currently in memory is written to a disk file.

SYNTAX

SAVE "file path",A

EXPLANATION

file path may include the disk drive, directory, and file name.

,A the disk file is saved in ASCII format of ordinary text characters with no compression of blank spaces. This option must be used if the file is going to be used with a MERGE command.

 

 

 

SCREEN

STATEMENT

PURPOSE

Switches between text mode and graphics mode.

SYNTAX

SCREEN 0

SCREEN 1

EXPLANATION

Screen 0 is text mode. Screen 1 is graphics mode.

 

 

 

SOUND

STATEMENT

PURPOSE

Creates a sound out of the personal computer speaker.

SYNTAX

SOUND frequency,duration

EXPLANATION

frequency specifies a tone in Hertz (Hz) in the range 37 to 32767. The upper limit of the range is the code for silence.

duration specifies how long the tone will be sounded. Duration is specified in clock ticks. One second is equal to 18 clock ticks.

EXAMPLE

       10 C! = 65.4                           'C NOTE FROM 2nd OCTAVE
       20 FOR X% = 1000 TO 10000 STEP 1000
       30  SOUND X%,1
       40 NEXT X%
       50 SOUND 32767,9                       'SILENCE
       60 SOUND (4 * C!),4.5                  'MIDDLE C

 

 

 

SYSTEM

COMMAND

PURPOSE

Stops the BASIC interpreter and returns control to DOS.

SYNTAX

SYSTEM

EXPLANATION

Any program or data currently in memory is lost.

 

 

 

TIMER

FUNCTION

PURPOSE

Produces a single precision number indicating the elapsed time in seconds and hundredth of a second since either midnight or a system reset.

SYNTAX

variable = TIMER

EXPLANATION

variable the value of TIMER may be assigned to a variable.

EXAMPLE

       10 BEGTIME! = TIMER
       20 INPUT "Press ENTER after you have read this message",GARBAGE$
       30 ENDTIME! = TIMER
       40 HOWLONG! = ENDTIME! - BEGTIME!
       50 PRINT "It took you"HOWLONG!"seconds to read the message"

 

 

 

WIDTH

STATEMENT

PURPOSE

Sets the text width of the display screen.

SYNTAX

WIDTH 40

WIDTH 80

EXPLANATION

The screen width may display either 40 or 80 characters.

 

 

Return to Table of Contents