© 1991 Brian R. Page Blast Off With BASICAppendix A: BASIC Commands Quick ReferenceCIRCLESTATEMENTPURPOSEDisplays a circle on the screen. May be used only in graphics mode. SYNTAXCIRCLE (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. EXAMPLE10 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
CLSSTATEMENTPURPOSEClear the screen. SYNTAXCLS
COLORSTATEMENT IN TEXT MODEPURPOSESets the background and text colors. SYNTAXCOLOR foreground,background EXPLANATIONforeground 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
COLORSTATEMENT IN GRAPHICS MODEPURPOSESets the background and palette colors. SYNTAXCOLOR background,palette EXPLANATIONbackground 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.
DATASTATEMENTPURPOSElists data which may be assigned to variables with the READ statement. SYNTAXDATA field,field,field,... EXPLANATIONfield 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. EXAMPLE10 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
ENDSTATEMENTPURPOSEHalts execution of a BASIC program. SYNTAXEND EXPLANATIONEND may be placed anywhere in a program. As soon as the END statement is executed, program execution stops.
FOR-NEXTSTATEMENTSPURPOSECreates a loop for the repetitive execution of instructions. SYNTAXFOR variable = x TO y STEP z . . . NEXT variable EXPLANATIONvariable 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. EXAMPLE10 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 RETURNSTATEMENTSPURPOSETemporarily branches to a subroutine. SYNTAXGOSUB line. . . RETURN EXPLANATIONline 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. EXAMPLE10 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
GOTOSTATEMENTPURPOSEBranch to a specified line number. SYNTAXGOTO line EXPLANATIONline specifies a line number in the program. This line will be the next one executed after the GOTO. EXAMPLE10 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-ELSESTATEMENTPURPOSEMakes a decision based on a comparison. SYNTAXIF condition THEN alternative 1 ELSE alternative 2 EXPLANATIONcondition 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. EXAMPLES280 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%
INPUTSTATEMENTPURPOSEAccepts keyboard input. SYNTAXINPUT "message", variable,variable,variable,... EXPLANATIONmessage 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.
INTFUNCTIONPURPOSECreates an integer. SYNTAXvariable = INT(x) EXPLANATIONx the integer value of x is assigned to the variable. EXAMPLE10 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)
KEYSTATEMENTPURPOSETurns the display of function key settings on or off. SYNTAXKEY ON KEY OFF EXPLANATIONON 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 PURPOSEReturns the leftmost x characters of a string variable. SYNTAXLEFT$(variable,x) EXPLANATIONvariable a string variable. x the number of leftmost characters needed. EXAMPLE10 WHO$ = "Jabberwocky" 20 FOR X% = 1 TO 11 30 PRINT LEFT$(WHO$,X%) 40 NEXT X%
LINESTATEMENTPURPOSEGraphics mode command to draw lines and boxes. SYNTAXLINE (x,y) - (x,y),color,BF EXPLANATIONx 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. EXAMPLE10 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%
LISTCOMMANDPURPOSEDisplays a BASIC program on the screen. SYNTAXLIST line - line EXPLANATIONline 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.
LLISTCOMMANDPURPOSELists a BASIC program on a printer. SYNTAXLLIST line - line EXPLANATIONline 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.
LOADCOMMANDPURPOSEMoves a BASIC program into memory from a disk file. SYNTAXLOAD "file path",R EXPLANATIONfile 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.
LOCATESTATEMENTPURPOSEPositions the cursor on the display screen. SYNTAXLOCATE row,column EXPLANATIONrow 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. EXAMPLE10 CLS 20 LOCATE 10,20 30 PRINT "Row 10, Column 20" 40 LOCATE 20,50 50 PRINT "Row 20, Column 50"
LPRINTSTATEMENTPURPOSEPrints text on a printer. SYNTAXLPRINT expression EXPLANATIONexpression may be either variables or characters enclosed within quotation marks. LPRINT functions exactly like the PRINT statement, except output appears on the printer.
MERGECOMMANDPURPOSECombines two BASIC programs. SYNTAXMERGE "file path" EXPLANATIONfile 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.
STATEMENTPURPOSEDisplays data on the screen. SYNTAXPRINT expression EXPLANATIONexpression 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. EXAMPLE10 PRINT "1","2","3","4","5" 20 PRINT "1","Here is some long text","2"
RANDOMIZESTATEMENTPURPOSESeeds the BASIC random number generator. SYNTAXRANDOMIZE x EXPLANATIONx 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. EXAMPLE10 RANDOMIZE TIMER 20 PRINT RND 30 PRINT RND
READSTATEMENTPURPOSEAssigns fields in DATA statements to variables. SYNTAXREAD variable,variable,variable,... EXPLANATIONvariable 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. EXAMPLE10 READ WORD1$ 20 READ WORD2$ 30 READ WORD3$ 40 PRINT WORD3$,WORD1$,WORD2$ 50 END 60 DATA My 70 DATA Lips 80 DATA Read
REMSTATEMENTPURPOSEProvides a comment line in a program. SYNTAXREM expression EXPLANATIONexpression any text.
RENUMCOMMANDPURPOSERenumbers the lines of the BASIC program currently in memory. SYNTAXRENUM line EXPLANATIONline 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.
RNDFUNCTIONPURPOSEProduces a random number between 0 and 1. SYNTAXvariable = RND EXPLANATIONvariable 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. EXAMPLE10 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)
RUNCOMMANDPURPOSECauses the BASIC interpreter to execute a program. SYNTAXRUN "file path" EXPLANATIONfile path may include the disk drive, directory, and the file name. If no file path is specified, the program currently in memory is executed.
SAVECOMMANDPURPOSEThe program currently in memory is written to a disk file. SYNTAXSAVE "file path",A EXPLANATIONfile 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.
SCREENSTATEMENTPURPOSESwitches between text mode and graphics mode. SYNTAXSCREEN 0 SCREEN 1 EXPLANATIONScreen 0 is text mode. Screen 1 is graphics mode.
SOUNDSTATEMENTPURPOSECreates a sound out of the personal computer speaker. SYNTAXSOUND frequency,duration EXPLANATIONfrequency 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. EXAMPLE10 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
SYSTEMCOMMANDPURPOSEStops the BASIC interpreter and returns control to DOS. SYNTAXSYSTEM EXPLANATIONAny program or data currently in memory is lost.
TIMERFUNCTIONPURPOSEProduces a single precision number indicating the elapsed time in seconds and hundredth of a second since either midnight or a system reset. SYNTAXvariable = TIMER EXPLANATIONvariable the value of TIMER may be assigned to a variable. EXAMPLE10 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"
WIDTHSTATEMENTPURPOSESets the text width of the display screen. SYNTAXWIDTH 40 WIDTH 80 EXPLANATIONThe screen width may display either 40 or 80 characters.
|
|||||||||||||||