Vector Basic Interpreter Basic 80 Reference Manual Download Page 99

Purpose:

Remarks:

RENUM

[[<new number>] [,[<old number>] [,<increment>]]]

Extended, Disk

To renumber program lines.

<new number> is the first line number to be used
in

the

new sequence.

The default is 10.

<old

number> is the line in the current program where

renumbering

is

to

begin.

The default is the

first line of the program.

<increment>

is

the

increment

to

be used in the new sequence.

The

default is 10.

RENCH also changes all

line

number

references

following

GOTO,

GOSUB,

THEN,

ON •••GOTO,

ON •••GOSUB and ERL statements to reflect the new

line

numbers.

If

a

nonexistent

line number

appears after one of these statements, the error

message

"Undefined

line

xxxxx

in

yyyyy"

is

printed.

The incorrect

line

number

reference

(xxxxx) is not changed by RENUM, but line number

yyyyy may be .changed.

RENUM cannot be used

to

change

the

order

of

program lines (for example, RENUM

15,30

when the

program has three lines numbered

10, 20

and

30)

or

to

create

line numbers greater than

65529.

An "Illegal function call" error will result.

Renumbers the entire program.
The first new line number

will be 10. Lines will

increment by 10.

RENUM

30G,,50

Renumbers the entire pro-
gram. The first new line

number will be

300.

Lines

will increment by 50.

RENUM

1000,900,20

Renumbers the lines from

900

up so they start with

line number

1000

and

increment by 20.

Summary of Contents for Basic Interpreter Basic 80

Page 1: ...5IA iC intc tit tcl c t ...

Page 2: ......

Page 3: ...MIClOSOI l BASIC 88 Rsrision 5 9 RE ERENC MANUPd Revision A January 1 1988 CopyriC ht1988 Vector Graphic Inc Copyright 1979 Microsoft ...

Page 4: ... or changes except en an agreement to the contrary exists Revisions The date and reV1Slon of each page herein appears at the bottom of each page I he revision letter such as A or B changes if the MANUAL has been improved but the PRODUCT itself has not been significantly ItDdified I he date and revision on the Title Page corresponds to that of the page most recently revised When the product itself ...

Page 5: ...pect of the language it is not intended as a training manualfor novice programners Chapter 1discusses BASIC 80 generally Chapter 2 contains the syntax and use of every cxmnand and statenent in BASIC 80 in alphabetic order Chapter 3 describes every intrinsic function in BASIC 80 also alpha betically In the appendices certain tcpics such as disk I O using assembly language subroutines the relationsh...

Page 6: ... ...

Page 7: ...iler you will receiver a manual detailing its use but because it may be relevent to a user of the BASIC aeinterpreter Appendix L discusses the BASIC canpiler in brief Note that Appendix L lists several features which are present in the interpreter but tbich are absent or different in the canpiler Programmers intending to compile BASIC S0programs must pay attention to these differences In a Vector ...

Page 8: ...ver will cause the text to wrap aro md automatically The same is true for any serial terminal that has automatic wrap around en listing progran text or output BASIC a assunes it is outputting to a l32 character widtb printer If your system s printer is narrower it will be able to print lOn Jlines only if the printer or the printer driver software in the operating system has the ability to automati...

Page 9: ...mbly Language Subroutines APPENDIX 0 BASIC SO with the CP M Operating System APPENDIX E APPENDIX I Converting Programs to BASIC SO APPENDIX J Summary of Error Codes and Error Messages APPENDIX K Mathematical Functions ...

Page 10: ......

Page 11: ...SIC commands and statements are not preceded by line numbers They are executed as they are entered Results of arithmetic and logical operations may be displayed immediately and stored for later use but the instructions themselves are lost after execution This mode is useful for debugging and for using BASIC as a calculatorW for quick computations that do not require a complete program The indirect...

Page 12: ... logical line over more than one physical line by use of the terminal s line feed key Line feed lets you continue typing a logical line on the next physical line without entering a carriage return In the SK version line feed has no effect Every BASIC program line begins with a line number Line numbers indicate the order in which the program lines are stored in memory and are also used as reference...

Page 13: ...Plus sign Minus sign Asterisk or multiplication symbol Slash or division symbol Up arrow or exponentiation symbol Left parenthesis Right parenthesis Percent Number or pound sign Dollar sign Exclamation point Left bracket Right bracket Comma Period or decimal point Single quotation mark apostrophe Colon Ampersand Question mark Less than Greater than Backslash or integer division symbol At sign Unde...

Page 14: ...stants are the actual values BASIC uses during execution There are two types of constants string and numeric A string constant is a sequence of up to 255 characters enclosed in double quotation marks string constants alphanumeric Examples of HELLO 25 000 00 Number of Employees Numeric constants are positive or negative numbers Numeric constants in BASIC cannot contain commas There are five types o...

Page 15: ...ing point constants use the letter D instead of E S e Section 1 5 1 Hexadecimal numbers with the prefix H Examples H76 H32 Octal numbers with the prefix 0 or Examples 0347 1234 1 5 1 Single Double Precision 2E Numeric constants In the SK version of BASIC SO all numeric constants are single precision numbers They are stored with 7 digits of precision and printed with up to 6 digits In the Extended ...

Page 16: ...culations in the proqram Before a variable is assigned a value its value is assumed to be zero BASIC 80 variable names may be any length however in the 8K version only the first two characters are significant In the Extended and Disk versions up to 40 characters are significant he characters allowed in a variable name are letters and numbers and the decimal point is allowed in Extended and Disk va...

Page 17: ... 1 LIMIT declares a double precision value declares a single precision value declares an integer value In SX Extended and Disk versions N declares a string value ABC represents a single precision value In the Extended and Disk versions of BASIC SO there is a second method by which variable types may be declared The BASIC SO statements DEFINT DEFSTR DEFSNG and OEFDSL may be inclcded in a program to...

Page 18: ...at of the most precise operand Also the result of an arithmetic operation is returned to this degree of precision EXamples 10 ot 61 7 The arithmetic was performed 20 PRINT Of in double precision and the RUN result was returned in Of 8571428571428571 as a double precision value 10 0 6 7 20 PRINT 0 RON 857143 The arithmetic was performed in double precision and the result was returned to 0 single pr...

Page 19: ...8 times the original single precision value Example 10 A 2 04 20 B A 30 PRINT A S RON 2 04 2 039999961853027 An expression may be simply a string or numeric constant or a variable or it may combine constants and variables with operators to produce a single value Operators perform mathematical or logical operations on values The operators provided by BASIC SO may be divided into four categories 1 A...

Page 20: ...rators are available in Extended and Disk versions of BASIC SO Integer division and modulus arithmetic Integer division is denoted by the operands are rounded to integers 32768 to 32767 before the division quotient is truncated to an integer baCks lash The must be in the range is performed and the For example 10 4 I 2 25 68 6 99 3 The precedence of integer division is multiplication and floating p...

Page 21: ...braically correct sign is supplied as the result and execution continues 1 8 2 Relational Operators Relational operators are used to compare two values The result of the comparison is either true 1 or false 0 This result may then used to make a decision regarding program flow See IF Section 2 26 Operator Relation Tested Expression Equality X Y Inequality x y Less than X Y Greater than x y Less tha...

Page 22: ...on is de ermined as shown in the following table The operators are listed in order of precedence NOT X NOT X 1 0 0 1 AND X y X AND y 1 1 1 1 0 0 0 1 0 0 0 0 OR X Y X OR Y 1 1 1 1 0 1 0 1 1 0 0 0 XOR X Y X XOR Y 1 1 0 1 0 1 0 1 1 0 0 0 IMP X Y X IMP Y 1 1 1 1 0 0 0 1 1 0 0 1 EQV X Y X EQV y 1 1 1 1 0 0 0 1 0 a a 1 Just as the relational operators can be used to make decisions regarding program flow...

Page 23: ...For instance the AND operator maybe used to mask all but one of the bits of a status byte at a machine I O port The OR operator may be used to merge two bytes to create a particular binary value Tbe following examples will help demonstrate how the logical operators work 63 binary 111111 and 16 binary 10000 so 63 AND 16 16 15 binary 1111 and 14 binary 1110 so 15 AND 14 14 binary 1110 1 binary 11111...

Page 24: ...LENAME Strings may be compared using the same relational operators that are used with numbers String comparisons are made by taking one character at a time from each string and comparing the ASCII codes If all the ASCII codes are the same the strings are equal If the ASCII codes differ the lower code number precedes the higher If during string comparison the end of one string is reached the shorte...

Page 25: ...ly in memory simply retype the line using the same line number BASIC SO will automatically replace the old line with the new line More sophisticated editing capabilities are provided in the Extended and Disk versions of BASIC SO See EDIT Section 2 16 To delete the entire program that is currently residing in memory enter the NEW command See Section 2 41 NEW is usually used to clear memory prior to...

Page 26: ......

Page 27: ...trate the use of the instruction Format Notation Wherever the format for a statement or command is given the following rules apply 1 Items in capital letters must be input as shown 2 Items in lower case letters enclosed in angle brackets are to be supplied by the user 3 Items in square brackets J are optional 4 All punctuation except angle brackets and square brackets i e commas parentheses semico...

Page 28: ...ified in an AUTO command is assumed If AUTO generates a line number that is already beinq used an asterisk is print edafter the number to warn the user that any input will replace the existing line However typinq a carriaqe return immediately after the asterisk will save the line and qenerate the next line number AUTO is terminated by typinq Control c The line in which Control c is t ypedis not sa...

Page 29: ...also e USR function Section 3 40 variable name contains an address that is the startinq point in memory of e subroutine variable name may not be an array variable name argument list contains the arquments that are passed to e assembly lanquaqe subroutine The CALL statement qenerates the same callinq sequence used by Microsoft s FORT COBOL and BASIC compilers 110 MYROOT HDOOO 120 CALL MYROOT I J X ...

Page 30: ...able in the current program is passed to the ca led program If the ALL option is omitted the current program must contain a COMMON statement to list the variables that are passed See Section 2 7 Example If the MERGE option is included it allows a subroutine to be brought into the BASIC program as an overlay That is a MERGE operation is performed with the current program and the called program The ...

Page 31: ...piler it is recommended that COMMON be used to pass variables and that overlays not be used If the MERGE option is omitted CHAIN does not preserve variable types or user defined functions for use by the chained proqram That is any OEFINT OEFSNG OEFDBL DEFSTR or DEFFN statement containing shared variables must be restated in the chained program ...

Page 32: ...e hiqhest location available for use by BASIC SO expression2 sets aside stack space for BASIC The default is 1000 bytes or one eighth of the available memory whichever is smaller In previous versions of BASIC SO expression 1 set the amount of string space and expression2 set the end of memory BASIC SO release 5 0 and later allocates string space dynamically An Out of string space error occurs only...

Page 33: ...2 5 Intentially left blank ...

Page 34: ...r file and file number terminates upon execution of a CLOSE The file may then be reOPENed using the same or a different file number likewise that file number may now be reused to OPEN any file A CLOSE for a sequential output file writes the final buffer of output The END statement and the NEW command always CLOSE all disk files automatically STOP does not close disk files See Appendix B ...

Page 35: ...pear anywhere in a program though it is recommended that they appear at the beginning The same variable cannot appear in more than one COMMON statement Array variables are specified by appending to the variable name If all variables are to be passed use CRAIN with the ALL option and omit the COMMON statement 100 COMMON A B C O G 110 CHAIN PROG3 10 ...

Page 36: ...d in conjunction with STOP for debugging When execution is stopped intermediate values may be examined and changed using direct mode statemena E ecution may be resumed with COt or a direct mode GOTO which resumes execution a a specified line number With the Extended and Disk versions CONT may be used to continue execution after an error CONT is invalid if the program has been edited during the bre...

Page 37: ...BASIC SO COMMANDS AND STATEMENTS 2 9 Intentially left blank ...

Page 38: ...of items regardless of how many items are on a line or where the lines are placed in the program list of constants may QOntain numeric constants in any format i e fixed point floating point or inte er No numeric expressions are allowed n the list String constants in DATA statements must be surrounded by double quotation marks only if they contain commas colons or significant leading or trailing sp...

Page 39: ...ter is supplied when the function is called Otherwise the current value of the variable is used The variables in the parameter list represent on a one to one basis the argument variables or values that will be given in the function call Remember in the SK version only one argument is allowed in a function call therefore the DEF FN statement will contain only one variable In Extended and Disk BASIC...

Page 40: ...410 DEF FNAB X Y XA3 YA2 420 T FNAB I J Line 410 de ines the function function is called in line 420 ...

Page 41: ...haracter always takes precedence over a OEFtype statement in the typing of a variable If no type declaration statements are encountered BASIC SO assumes all variables without declaration characters are single precision variables 10 OEFOBL L P All variables beginning with the letters L M N 0 and P will be double precision variables All variables beginning with the letter A will be string variables ...

Page 42: ...is being specified If digit is omitted OEF USRO is assumed The value of integer expression is the starting address of the USR routine See Appendix C Assembly Language Subroutines Any number of OEF USR statements may appear in a program to redefine subroutine starting addresses thus allowing access to as many subroutines as necessary 200 OEF USRO 24000 210 X USRO YA2 2 89 ...

Page 43: ...ASIC SO always re urns to command level after a DELETE is execu ed If line number does not exis an Illegal func ion call error occurs DELETE 40 DELETE 40 100 Dele es lines 40 through 100 inclusive Deletes all lines up to and including line 40 ...

Page 44: ...mum value of its subscript s is assumed to be 10 If a subscript is used that is qreater than the max um specified a Subscript out of ranqe error occurs The minimum value for a subscript is always 0 unless otherwise specified with the OPTION BASE statement see Section 2 46 The D statement sets all the elements of the specified arrays to an initial value of zero 10 DIM A 20 20 FOR I O TO 20 30 READ ...

Page 45: ...ommands are not echoed Most of the Edit Mode subcommands may be preceded by an integer which causes the command to be executed that number of times When a preceding integer is not specified it is assumed to be 1 Edit Mode suCcommands may be categorized according to the following functions 1 Moving the cursor 2 Inserting text 3 Deleting text 4 Finding text s Replacing text 6 Ending and restarting E...

Page 46: ...is typed and the character is not printed X The X subcommand is used to extend the line X moves the cursor to the end of the line goes into insert mode and allows insertion of text as if an Insert command had been qiven When you are finished extending the line type Escape or Carriage Return 3 Deleting Text D i1D deletes i characters to the right of the cursor The deleted characters are echoed betw...

Page 47: ...es you made and exits Edit Mode The E subcommand has the same effect as Carriage Return except the remainder of the line is not printed The Q subcommand returns to BASIC SO command level without saving any of the changes that were made to the line during Edit Mode L The L subcommand lists the remainder of the line saving any changes made so far and repositions the cursor at the beginning of the li...

Page 48: ...xamination first exit Edit Mode with the Q subcommand BASIC SO will return to command level and all variable values will be preserved T oenter Edit Mode on the line you are currently typing type Control A BASIC SO responds with a carriage return an exclamation point 1 and a space The cursor will be positioned at the first character in the line Proceed by typing an Edit Mode subcommand Remember if ...

Page 49: ...vel END statements may be placed anywhere in the program to terminate execution Unlike the STOP statement END does not cause a BREAK message to be printed An END statement at the end of a program is optional BASIC SO always returns to command level after an END is executed ...

Page 50: ...y be redimensioned after they are ERASEd or the previously allocated array space in memory may be used for other purposes If an attempt is made to redimension an array without first ERASEing it a ftRedimensioned array error occurs The Microsoft BASIC compiler does not support ERASE 450 ERASE A B 460 DIM B 99 ...

Page 51: ...gram flow in the error trap routine If the statement that caused the error was a direct mode statement ERL will contain 65535 To test if an error occurred in a direct statement use IF 65535 ERL THEN Otherwise use If the line number is not on the right side of the relational operator it cannot be renumbered by RENUM Because ERL and ERR are reserved variables neither may appear to the left of the eq...

Page 52: ...d by BASIC 80 s error codes It is preferable o use the highest available values so compatibili y may be maintained when more error codes are added o BASIC 80 This user defined error code may then be conveniently handled in an error trap routine See Example 2 If an ERROR statement specifies a code for which no error message has been defined BASIC 80 responds with the message UNPRINTABLE ERROR Execu...

Page 53: ... 110 ON ERROR GOTO 400 120 INPUT WHAT IS YOUR BET B 130 IF B 5000 THEN ERROR 210 400 IF ERR 210 THEN PRINT ROOSE LIMIT IS 5000 410 IF ERL 130 THEN RESUME 120 ...

Page 54: ...e next 40 pos tions to ADD FIELD does NOT place any data in the random file buffer See LSET RSET and GET The total number of bytes allocated in a FIELD statement must not exceed the record length that was specified when the file was OPENed Otherwise a Field overflow error occurs The default record length is 128 Any number of FIELD statements may be executed for the same file and all FIELD statemen...

Page 55: ...with the statement following the NEXT statement This is a FOR NEXT loop If STEP is not specified the increment is assumed to be one If STEP is negative the final value of the counter is set to be less than the initial value The counter is decremented each time through the loop and the loop is executed until the counter is less than the final value initial the step of the The body of the loop is sk...

Page 56: ... 0 9 60 Ok Example 2 10 J O 20 FOR I 1 TO J 30 PRINT I 40 NEX I I In this example the because the initial the final value loop does not execute value of the loop exceeds Example 3 10 r s 20 FOR I 1 TO I S 30 PRINT I 40 NEXT RON 1 2 3 4 5 6 7 S 9 10 Ok In this example the loop executes ten times The final value for the loop variable is always set before the initial value is set Note Previous versio...

Page 57: ...d a record from a random disk file into a random buffer file number is the number under which the file was OPENed If record number is omitted the next record after the last GET is read into the buffer The largest possible record number is 32767 ...

Page 58: ...ubroutine may contain more than one RETURN statement should loqic dictate a return at different points in the subroutine Subroutines may appear anywhere in the program but it is recommended that the subroutine be readily distinguishable from the main program To prevent inadvertant entry into the subroutine it may be preceded by a STOP END or GOTO statement that directs program control around the s...

Page 59: ...nt that statement and those following are executed If it is a nonexecutable statement execution proceeds at the first executable statement encountered aftar line number LIST 10 READ R 20 PRINT R R 30 A a 3 14 RA2 40 PRINT AREA A 50 GOTO 10 60 DATA 5 7 12 Ok RUN R 5 R 7 R 12 Out of data Ok AREA AREA AREA in 10 78 5 153 86 452 16 ...

Page 60: ...n continues with the nex executable statement ELSE is allowed only in Ex ended and Disk versions Extended and Disk versions allow a comma before THEN Nes inq 2 B Statements In the E ended and Disk versions IF THEN ELSE statements may be nested Nes ing is limited only by the length of the line For example IF X Y THEN PRINT IIGREATERIIELSE IF Y X THEN PRINT llLESS THAN IIELSE PRINT EQUAL is a legal ...

Page 61: ...less than 1 0E 6 Example 1 200 IF I THEN GETtl I This statement GETs record number I if I is not zero Example 2 100 IF I 20 I 10 THEN OS 1979 1 GOTO 300 110 PRINT OOT OF RANGE In this example a test determines if I is greater than 10 and less than 20 If I is in this range DB is calculated and execution branches to line 300 If I is not in this range execution continues with line 110 This statement ...

Page 62: ...iven in variable list number of data items supplied must be the as the number of variables in the list items are separated by commas a semicolon the user to return line the The same Data The variable names in the list may be numeric or string variable names including subscripted variables The type of each data item that is input must agree with the type specified by the variable name Strings input...

Page 63: ...e user in response to the question mark 5 SQUAlmD IS 25 Ok LIST 10 PI 3 14 20 INPUT WHAT IS THE RADIUS R 30 A PI RI 2 40 PRINT THE AREA OF THE CIRCLE IS A 50 PRINT 60 GaTO 20 Ok RUN WHAT IS THE RADIUS 7 4 User types 7 4 THE AREA OF THE CIRCLE IS 171 946 WHAT IS THE RADIUS etc ...

Page 64: ... or line feed is assumed to be the start of a number The number terminates on a space carriage return line feed or comma If BASIC 80 is scanning the sequential data file for a string item leading spaces carriage returns and line feeds are also ignored The firs character encountered that is not a space carriage return or line feed is assumed to be the start of a string item If this first character ...

Page 65: ...ose Remarks If a KILL statement is given for a file that is currently OPEN a File already open error occurs KILL is used for all types of disk files program files random data files and sequential data files ...

Page 66: ... value of an expression to a variable Notice the word LET is optional i e the equal sign is sufficient when assigning an expression to a variable name 110 LET 0 12 120 LET E 12A2 130 LET F 12A4 140 LET SUM D E F 110 0 12 120 E 12A2 130 F 12A4 140 SUM D E F ...

Page 67: ...printed unless it is part of the prompt string All input from the end of the prompt to the carriage return is assigned to string variable If LINE INPUT is immediately followed by a semicolon then the carriage return typed by the user to end the input line does not echo a carriage return line feed sequence at the terminal A LINE INPUT may be escaped by typing Control C BASIC SO will return to comma...

Page 68: ...r the carriage return line feed sequence and the next LINE INPUT reads all characters up to the next carriage return If a line feed carriage return sequence is encountered it is preserved LINE INPUT is especially useful a data file has been broken into BASIC 80 program saved in ASCII read as data by another program if each line of fields or if a mode is being Example 10 OPEN O 1 LIST 20 LINE INPUT...

Page 69: ...nd of the program or by typing Control C If line number is included the 8X version will list the program beginning at that liner and the Extended and Disk versions will list only the specified line Format 2 This format allows the following options 1 If only the first number is specified that line and all higher numbered lines are listed 2 If only the second number is specified all lines from the b...

Page 70: ... version lists all programs lines from 500 to the end In Extended and Disk lists line 500 LIST 150 Lists all lines from 150 to the end LIST 1000 Lists all lines from the lowest number through 1000 LIST 150 1000 Lists lines 150 through 1000 inclusive ...

Page 71: ...nter LLIST assumes a 132 character wide printer BASIC SO always returns to command level after an LLIST is executed The options for LLIST are the same as for LIST Format 2 LLIST and LPRINT are not included in implementations of BASIC SO See the examples for LIST Format 2 ...

Page 72: ...eletes all variables and proqram lines currently residing in memory before it loads the designated program However if the R option is us7d with LOAD the program is RUN after it J S LOADed and all open data files are kept open l hus LOAD with the R option may be used to chain several programs or segments of the same program Information may be passed between the programs using their disk data files ...

Page 73: ...ended Disk To print data at the line printer Same as PRINT and PRINT USING except output goes to the line printer See Section 2 49 and Section 2 50 LPRINT assumes a 132 character wide printer LPRINT and LLIST are not included in implementations of BASIC aO ...

Page 74: ...extra positions If the string is too long for the field characters are dropped from the right Numeric values must be converted to strings before they are LSET or RSET See the MKI MKS MKD functions Section 3 25 150 LSET A MKS AMT 160 LSET D OESC See also Appendix B LSET or RSET may also be used with string variable to left justify or a string in a g ven field For program lines a non fielded right j...

Page 75: ...n ASCII format If not a Bad file mode error occurs If any lines in the disk file have the same line numbers as lines in the program in memory the lines from the file on disk will replace the corresponding lines in memory MERGEing may be thought of as inserting the program lines on disk into the program in memory BASIC SO always returns to command level after executing a MERGE command MERGE NUMBRS ...

Page 76: ...ring exp2 The optional m refers to the number of characters from string exp2 that will be used in the replacement If m is omitted all of string exp2 is used However regardless of whether m is omitted or included the replacement of characters never goes beyond the original length of string exp1 10 A KANSAS CITY MO 20 MID A 14 KS 30 PRINT A RUN KANSAS CITY KS MID may also be used as a function that ...

Page 77: ... and new filename must not exist otherwise an error will result After a NAME command the file exists on the same disk in the same area of disk space with the newname Ok NAME IIACCTS AS II LEDGER Ok In this example the file that was formerly named ACCTS will now be named LEDGER ...

Page 78: ...delete the proqram currently in memory and clear all variables NEW is entered at command level to clear memory before entering a new program BASIC SO always returns to command level after a NEW is executed ...

Page 79: ...eger expression should be 3 When tapes are not being punched integer expression should be 0 or 1 for Teletypes and Teletype compatible CRTs integer expression should be 2 or 3 for 30 cps hard copy printers The default value is o Ok NULL 2 Ok 100 INPUT X 200 IF X SO GaTO 800 Two null characters will be printed after each line ...

Page 80: ...equent errors will print an error message and halt execution An ON ERROR GOTO 0 statement that appears in an error trapping subroutine causes BASIC SO to stop and print the error message for the error that caused the trap It is recommended that all error trapping subroutines execute an ON ERROR GOTO 0 if an error is encountered for which there is no recovery action If an error occurs during execut...

Page 81: ...er in the list will be used for For example if the value is three line number in the list will be the of the branch If the value is a the fractional portion is rounded which line branching the third destination non integer In the ON GOSUB statement each line number in the list must be the first line number of a subroutine If the value of expression is negative zero or greater than the number of it...

Page 82: ...ile number is an integer expression whose value is between one and fifteen The number is then associated with the file for as long as it is OPEN and is used to refer other disk I O statements to the file filename is a string expression containing a name that conforms to your operating system s rules for disk filenames reclen is an integer expression which if included sets the record length for r d...

Page 83: ...OPTION BASE n where n is 1 or 0 Extended Disk To declare the subscripts The default base is O If the statement is executed the lowest value an array subscript may have is one ...

Page 84: ... J where I and J are integer expressions in the range 0 to 255 aK Extended Disk To send a byte to a machine output port The integer expression I is the port number and the integer expression J is the data to be transmitted ...

Page 85: ...nge 0 to 65536 With the 8X version data may be POKEd into memory locations above 32768 by supplying a negative number for I The value of I is computed by subtracting 65536 from the desired address For example to POKE data into location 45000 I 45000 65536 or 20536 The complementary funct ionto POKE is PEEX The argument to PEEX is an address from which a byte is to be read See Section 3 27 POKE and...

Page 86: ...ressions the next PRINT statement begins printing on the same line spacing accordingly If the list of expressions terminates without a comma or a semicolon a carriage return is printed at the end of the line If the printed line is longer than the terminal width BASIC SO goes to the next physical line and continues printing Printed numbers are always followed by a space Positive numbers are precede...

Page 87: ...729 21 21 SQUARED IS 441 AND 21 CUBED IS 9261 In this example the semicolon at the end of line 20 causes both PRINT statements to be printed on the same line and line 40 causes a blank line to be printed before the next prompt Example 3 10 FOR X II 1 TO S 20 J J S 30 K K 10 40 J K SO NEXT X Ok RUN S 10 10 20 1S 30 20 40 2S SO Ok In this example the semicolons in the PRINT statement cause each valu...

Page 88: ...SING is used to print strings one of three formatting characters may be used to format the string field Spec fies that only the first character in the given string is to be printed n spaces Specifies that 2 n characters from the string are to be printed If the backslashes are typed with no spaces two characters will be printed with one space three characters will be printed and so on If the string...

Page 89: ...umber will be right justified preceded by spaces in the field A decimal point may be inserted at any position in the field If the format string specifies that a digit is to precede the decimal point the digit will always be printed as 0 if necessary Numbers are rounded as necessary PRINT USING 1 78 0 78 PRINT USING II tt 987 654 987 65 PRINT USING ti it 10 2 5 3 66 789 234 10 20 5 30 66 79 0 23 In...

Page 90: ...al format cannot be used with Negative numbers cannot be used unless the minus sign trails to the right PRINT USING llt i 456 78 456 78 The at the beginning of a format string combines the effects of the above two symbols Leading spaces will be asterisk filled and a dollar sign will be printed before the number specifies three more digit positions one of which is the dollar sign PRINT USING i t 2 ...

Page 91: ...02 PRINT USING iiitAAAA 888888 8889E 06 PRINT USING ttAAAA 123 12E 03 An underscore in the format string causes the next character to be output as a literal character PRINT USING 1il _1 12 34 112 341 The literal character itself may be an underscore by placing __ in the format string If the number to be printed is larger than the specified numeric field a percent sign is printed in front of the nu...

Page 92: ...is reason care should be taken to delimit the data on the disk so that it will be input correctly from the disk In the list of expressions numeric should be delimited by semicolons expressions For example If commas are used as delimiters the extra blanks that are inserted between print fields will also be written to disk String expressions must be separated by semicolons in the list To format the ...

Page 93: ...et A CAMERA AUTOMATIC and B 93604 1 The statement would input CAMERA to AUTOMATIC 93604 1 to B To strings properly on the disk quotes to the disk image using statement A and separate these write double CHR 34 The CAMERA AUTOMATIC and the statement would input CAMERA AUTOMATIC to 93604 1 to B The PRINTt statement may also be used with the USING option to control the format of the disk file For exam...

Page 94: ...om a random buffer to a random disk file file number is the number under which the file was OPENed I f record number is omitted the record will have the next avai able record number after the last PUT The largest possible record number is 32767 See Appendix B ...

Page 95: ...the program is RUN place a RANDOMIZE statement at the beginning of the program and change the argument with each RON 10 Rk mOMIZE 2 0 FOR I 1 TO 5 30 PRINT RND J 40 NEXT I RON Random Number Seed 0 65529 3 user types 3 88598 484668 586328 119426 709225 Ok RUN Random Number Seed 0 65529 4 user types 4 for new sequence 803506 162462 929364 292443 322921 Ok RON Random Number Seed 0 65529 3 same sequen...

Page 96: ...cess the same DATA statment If the num erof variables in list of variables exceeds the numJ er of elements in the DATA statement s an OUT OF DATA messaqe is printed If the number of variables specified is fewer than the number of elements in the DATA statement s subsequent READ statements will beqin reading data at the first unread element If there are no subsequent READ statements the extra data ...

Page 97: ...LIST 10 PRINT CITY STATE ZIP 20 READ C S Z 30 DATA DENVER COLORADO 80211 40 PRINT C S Z Ok RON CITY STATE ZIP DENVER COLORADO 80211 Ok This program READs string and numeric data from the DATA statement in line 30 ...

Page 98: ...anched into from a GaTO or GOSUB statement and execution will continue with the first executable statement after the REM statement In the Extended and Disk versions remarks may be added to the end of a line by preceding the remark with a single quotation mark instead of REM 120 REM CALCULATE AVERAGE VELOCITY 130 FOR I 1 TO 20 140 SUM SUM VeIl 120 FOR I 1 TO 20 130 SUM SUM V I 140 NEXT I ...

Page 99: ... number appears after one of these statements the error message Undefined line xxxxx in yyyyy is printed The incorrect line number reference xxxxx is not changed by RENUM but line number yyyyy may be changed RENUM cannot be used to change the order of program lines for example RENUM 15 30 when the program has three lines numbered 10 20 and 30 or to create line numbers greater than 65529 An Illegal...

Page 100: ...STORE statement is executed the next READ statement accesses the first item in the first DATA statement in the program If line number is specified the next READ statement accesses the first item in the specified DATA statement Example 10 READ A B C 20 RESTOBE 30 READ D E F 40 DATA 57 68 79 ...

Page 101: ...E or RESUME 0 Execution resumes at the statement which caused the error Execution resumes at the statement immediately fol lowing the one which caused the error RESUME line number Execution resumes at line number A RESUME statement that is not in an error trap routine causes a RESUME without error message to be printed 10 ON ERROR GOTO 900 900 IF ERR 230 AND ERL 90 THEN PRINT ftTRY AGAIN RESUME 80...

Page 102: ...t line number BASIC SO always returns to command level after a RUN is executed RON filename R Disk To load a file from disk into memory and run it filename is the name used when the file was SAVEd The default ex ension BAS is supplied RON closes all open current contents of designated program option all data files RON NEWFIL R files and deletes memory before loading However with the remain OPEN th...

Page 103: ...ASCII format Otherwise BASIC saves the file in a compressed binary format ASCII format takes more space on the disk but some disk access requires that files be in ASCII format For instance the MERGE command requires an ASCII format file and some operating system commands may require an ASCII format file Use the P option to protect the file by saving it in an encoded binary for mat When a protected...

Page 104: ...s encountered the following message is printed Unlike the END statement the STOP statement does not close files BASIC SO always returns to command level after a STOP is executed Execution is resumed by issuing a CONT command see Section 2 S 10 INPUT A B C 20 K AA2 5 3 L BA3 26 30 STOP 40 M C K 100 PRINT M RON 1 2 3 BREAK IN 30 Ok PRINT L 30 7692 Ok CONT 115 9 Ok ...

Page 105: ... S ped integer single precision double precision string but the two variables must be of the same type or a Type mismatchn error results LIST 10 A ONE n B ALL C It FOR 20 PRINT A C B 30 SWAP A B 40 P NT A C B RON Ok ONE FOR ALL ALL FOR ONE Ok ...

Page 106: ...s each line number of the program as it is executed The numbers appear enclosed in square brackets The trace flag is disabled with the TROFF statement or when a NEW command is executed TRON Ok LIST 10 K 10 20 FOR J 1 TO 2 30 L K 10 40 PRINTJ1K L SO K K 10 60 NEXT 70 END Ok RUN 10 20 30 40 1 10 20 SO 60 30 40 2 20 30 SO 60 70 Ok TROFF Ok ...

Page 107: ...velops a specified bit pattern The data read at the port is exclusive ORIed with the integer expression J and then AND Ied with I If the result is zero BASIC SO loops back and reads the data at the port again If the result is nonzero execution continues with the next statement If J is omitted it is assumed to be zero It is possible to enter an infinite loop with the WAIT statement in which case it...

Page 108: ...true the process is repeated If it is not true execution resumes with the statement following the WEND statement WHILE WEND loops may be nested to any level Each WEND will match the most recent WHILE An unmatched WHILE statement causes a WHILE without WEND error and an unmatched WEND statement causes a ieNDwithout WEILEn er or 90 SUBBLE SORT ARRAY A 100 FLIPS 1 FORCE ONE PASS 110 WHILE FLIPS 115 F...

Page 109: ... terminal If LPRINT is included the line width is set at the line printer integer expression must have a value in the range 15 to 255 The default width is 72 characters If integer expression is 255 the line width is infinite that is BASIC never inserts a carriage return However the position of the cursor or the print head as given by the POS or LPOS function returns to zero after position 255 ...

Page 110: ...st may be numeric and or string expressions and they must be separated by commas When the printed items are output each item will be separated from the last by a comma Printed strings will be delimited by quotation marks After the last item in the list is printed BASIC inserts a carriage return line feed TE outputs numeric values using the same format as the PRINT statement Section 2 49 10 A SO B ...

Page 111: ...t be separated by commas The difference between WRITE and PRINT is that WRITE inserts commas between the items as they are written to disk and delimits st inqs with quotation marks Therefore it is not necessary for the user to put explicit delimiters in the list A carriaqe return line feed sequence is inserted after the last item in the list is written to disk Let A CA mRA n statement WRITE 1 AS B...

Page 112: ......

Page 113: ...enclosed in parentheses In the formats qiven for the functions in this chapter the arquments have been abbreviated as follows X and Y I and J X and Y Represent any numeric expressions Represent inteqer expressions Represent strinq expressions If a floatinq point va ue is supplied where an inteqer is required BASIC SO wil round the fractional portion and use the resultinq inteqer ...

Page 114: ...7 S 35 Ok 8K Extended Disk Returns a numerical value that is the ASCII code of the first character of the string X See Appendix L for ASCII codes If X is null an ftIllegal function callft error is returned 10 X ftTESTft 20 PRINT ASC X RUN 84 Ok See the CRR function conversion ...

Page 115: ...ians Result is in the range pi 2 to pi 2 The expression X may be any numeric type but the evaluation of ATN is always performed in single precision 10 INPUT X 20 PRINT ATN X RUN 3 1 24905 Ok 10 A 454 67 20 PRINT A CDBL A RUN 454 67 454 6700134277344 Ok ...

Page 116: ...sent CHR 12 to clear a CRT screen and return the cursor to the home position PRINT CHR 66 B Ok See the ASC function conversion Extended Disk Converts X to an integer by rounding the fractional portion If X is not in the range 32768 to 32767 an Overflow error occurs PRINT CINT 4S 67 46 Ok See the CDSL and CSNG functions for converting numbers to the double precision and single precision data type S...

Page 117: ...of COS X is precision 10 X 2 COS 4 20 PRINT X RUN 1 84212 Ok in radians The performed in single 10 Ai 975 3421 20 PRINT Ai CSNG A RUN 975 3421 975 342 Ok See the C NT and CDSL functions for converting numbers to tileinteger and double precision data types ...

Page 118: ...nteger CVS converts a 4 byte string to a single precision number CVD converts an S byte string to a double precision number 70 FIELD 1 4 AS N 12 AS B SO GET 1 90 Y CVS N See also MKI MKS MKD Section 3 25 and Appendix B Returns 1 true if the end of a sequential file has been reached Use EOF to test for end of file while INPUTting to avoid Input past end errors 10 OPEN I 1 DATA 20 C O 30 IF EOF 1 TH...

Page 119: ...ith the appropriate sign is supplied as the result and execution continues 10 X 5 20 PRINT EXP X 1 RUN 54 5982 Ok Returns the truncated integer part of X FIX X is equivalent to SGN X INT ABS X The major difference between FIX and INT is that FIX does not retu the next lower number for negative X PRINT FIX 58 75 58 Ok PRINT FIX 58 75 58 Ok ...

Page 120: ...BASIC SO If the argument is a string FRE returns the number of free bytes in string space PRINT FRE O 14542 Ok Returns a hexadecimal rounded to evaluated string which represents value of the decimal argument an integer before HEX X 10 INPUT X 20 A It HEX X 30 PRINT X DECIMAL IS A HEXADECIMAL RON 32 32 DEC IS 20 HEXADECIMAL Ok the X is is ...

Page 121: ...erminal is used for input no characters will be echoed and all control characters are passed through except Control C which is used to interrupt the execution of the INPUT function Example 1 5 LIST THE CONTENTS OF A SEQUENTIAL FILE IN HEXADECIMAL 100PEN I 1 OATA 20 IF EOF 1 THEN 50 30 PRINT HEX ASC INPUT 1 1 40 GOTO 20 50 PRINT 60 END 100 PRINT TYPE P TO PROCEED OR S TO STOP 110 X INPUT 1 120 IF X...

Page 122: ...ge 0 to 255 If I LEN X or if X is null or if Y cannot be found INSTR returns O If Y is null INSTR returns I or 1 X and Y may be string variables string expressions or string literals 10 X ABCDEB 20 Y B 30 PRINT INSTR X Y INSTR 4 X Y RUN 2 6 Ok SK Extended Disk Returns the largest integer X PRINT INT 99 89 99 Ok PRINT INT 12 11 13 Ok See the FIX and CINT functions which also return integer values ...

Page 123: ...nge 0 to 25 5 If I is greater than LEN X the entire string X will be returned If I O the null string length zero is returned 10 A BASIC SO 20 B LEFT A 5 30 PRINT B BASIC Ok Returns the number of characters in X Non printing characters and blanks are counted 10 X PORTLAND OREGON 20 PRINT LEN X 16 Ok ...

Page 124: ...ET or PUT without a record number is executed With sequential files LOC returns the number of sectors 128 byte blocks read from or written to the file since it was OPENed 8K Extended Disk Returns the natural logarithm of X X must be greater than zero PRINT LOG 45 7 1 86075 Ok ...

Page 125: ...ns a string of length J characters from X beginning with the Ith character I and J must be in the range 0 to 255 If J is omitted or if there are fewer than J characters to the right of the Ith character all rightmost characters beginning with the Ith character are returned If I LEN X MID returns a null string LIST 10 A GOOD 20 B _nMORNING EVENING AFTERNOON 30 PRINT A MID B 9 7 Ok RUN GOOD EVENING ...

Page 126: ...verts an integer to a 2 byte string MKS converts a single precision number to a 4 byte string MKD converts a double precision number to an a byte string 90 AMTw K T 100 FIELD 1 8 AS D 20 AS N 110 LSET D MKS AMT 120 LSET N A 130 POT 1 See also CVI CVS evo Section 3 9 and Appendix B Returns a string which represents the octal value of the decimal argument X is rounded to an integer before OCT X is e...

Page 127: ...t be less than 3276S To PEEK at a memory location above 3276S subtract 65536 from the desired address With Extended and Disk BASIC aO I must be in the range a to 65536 PEEK is the complementary function to the POKE statement Section 2 4S Returns the current cursor position The leftmost position is o X is a dummy argument ...

Page 128: ...number be ween 0 and 1 The same sequence of random numbers is qenera ed each ime the program is RUN unless the random number generator is reseeded see RANDOMIZE Section 2 53 However X O always restarts the same sequence for any given X X O or X omitted generates the nex random number in the sequence X O repeats the last number generated 10 FOR I 1 TO 5 20 PRINT INT RND 100 30 NEXT RUN 24 30 31 51 ...

Page 129: ... O SGN X returns 1 ON SGN X 2 GOTO 100 200 300 branches to 100 if X is negative 200 if X is 0 and 300 if X is positive SK Extended Disk Returns the sine of X in calculated in COS X S X 3 14159 2 PRINT SIN 1 5 997495 Ok radians single SIN X is precision ...

Page 130: ...to an integer and must be in the range 0 to 255 10 FOR I 1 TO 5 20 X SPACE I 30 PRINT X I 40 NEXT I RUN 1 2 3 4 5 SK Extended Disk Prints I blanks on the terminal SPC may only be used with PRINT and LPRINT statements I must be in the range 0 to 255 PRINT OVER SPC 15 THERE OVER THERE Ok ...

Page 131: ...must be 0 10 FOR X 20 PRINT 30 NEXT RUN 10 15 20 25 Ok 10 TO 25 STEP 5 X SQR X 3 16228 3 87298 4 47214 5 Returns a string representation of the value of X 5 REM ARITHMETIC FOR KIDS 10 INPUT TYPE A NUMBER N 20 ON LEN STR N GOSUB 30 100 200 300 400 500 ...

Page 132: ...tion I on the terminal If the current print position is already beyond space I TAB goes to that position on the next line Space 0 is the leftmost position and the right most position is the width minus one I must be in the range 0 to 255 TAB may only be used in PRINT and LPRINT statements 10 PRINT NAME TAB 25 AMOUNT PRINT 20 READ A B 30 PRINT A TAB 25 B 40 DATA G T JONES 25 00 RUN NAME AMOUNT G T ...

Page 133: ...pplied as t he result and execut ion continues SK Extended Disk Calls the user s assembly language subroutine with the argument X digit is allowed in the Extended d Disk versions only digit is in the range 0 t o9 and corresponds t othe digit supplied with the DEF USR st atement for that routine If digit is omitted USRO is assumed See Appendix c 40 B T SIN Y 50 C USR B 2 60 D USR B 3 ...

Page 134: ...er of X is no or a di gi t VAL X 0 10 READ NAME CITY STATE ZIP 20 IF VAL ZIP 90000 OR VAL ZIP 96699 THEN PRINT NAME TAB 25 OUT OF STATE 30 IF VAL ZIP 90801 AND VAL ZIP 90815 THEN PUNT NAME TAB 25 LONG BEACH See the STR func ion for numeric to s inq conversion ...

Page 135: ...VARPTR is usually used to obtain the address of a variable or array so it may be passed to an assembly language subroutine A function call of the form VARPTR A O is usually specified when passing an array so that the lowest addressed element of the array is returned All simple variables should be assigned before calling VARPTR for an array because the addresses of the arrays change whenever a new ...

Page 136: ......

Page 137: ... for X The body of a FOR NEXT loop is skipped if initial value f the loop times the sign of step exceeds the final value times the sign of step See Section 2 22 4 Division by zero and overflow no longer produce fatal errors See Section 1 8 1 2 the the the 5 The RND function has been changed so that RND with no argument is the same as RND with a positive argument The RND function generates the same...

Page 138: ...C uses an RinfiniteR line width that is it does not insert carriage returns WIDTH LPRINT may be used to set the line width at the line printer See Section 2 66 11 The at sign and underscore are no longer used as editing characters 12 Variable names are significant up to 40 characters and can contain embedded reserved words However reserved words must now be delimited by spaces To maintain compatib...

Page 139: ...O pads the buffer with spaces up to the carriage return Any attempt to read or write past the end of the buffer causes a Field overflow error 2 S max record size may be added at the end of the command line to set the maximum record size for use with random files The default record size is 128 bytes A new feature has been added to the INPUT statement A comma may be used instead of a semicolon after...

Page 140: ......

Page 141: ...em will append a default extension BAS to the filename given in a SAVE RUN MERGE or LOAD command Here is a review of the commands and statements used in program file manipulation Writes to disk the program that is currently residing in memory Optional A writes the program as a series of ASCII characters Otherwise BASIC uses a compressed binary format Loads the program from disk into memory Optiona...

Page 142: ...nes have the same number only the line from the disk program is saved After a MERGE command the merged program resides in memory and BASIC returns to command level Deletes the file from the disk filename may be a program file or a sequential or random access data file To change the name of a disk file execute the NAME statement NAME oldfile AS newfile NAME may be used with program files random fil...

Page 143: ...nd is read back in the same way The statements and functions that are used with sequential files are PRINT INPUT PRINT OSING LINE INPUT The following program steps are required to create a sequential file and access the data in the file 2 Write data to the file using the PRINT statement WRITE maybe used instead 3 To access the data in the file you must CLOSE the file and reOPEN it in I mode CLOSEt...

Page 144: ... HIRED H 50 PRINTt1 N D H 60 PRINT GOTO 20 RUN NAME MICKEY MOUSE DEPARTMENT AODIO VISUAL AIDS DATE HIRED 01 12 72 NAME SHERLOCK HOLMES DEPARTMENT RESEARCH DATE HIRED 12 03 65 NAME EBENEEZER SCROOGE DEPA n ACCOUNTING DATE HIRED 04 27 78 NAME StJPERMANN OEPARTMENT AINTENANCE OATE HIRED 08 16 78 ...

Page 145: ...e PRINT USING statement For example the statement PRINT 1 USING ttt tt A B e o could be used to write numeric data to disk without explicit delimiters The comma at the end of the format string serves to separate the items in the disk file The Loe function when used with a sequential file returns the number of sectors that have been written to or read from the file since it was OPENed A sector is a...

Page 146: ...s technique It can be used to create or add onto a file called NAMES This program also illustrates the use of LINE INPUTt to read strings with embedded commas from the disk file Remember LINE INPUT will read in characters from the disk until it sees a carriage return it does not stop at quotes or commas or until it has read 255 characters ...

Page 147: ...20 statements that copy the file are created as if it were a new file 2000 traps a File If this happens skipped and COpy does the is Creating and accessing random files requires more program steps than sequential files but there are advantages to using random files One advantage is that random files require less room on the disk because BASIC stores them in a packed binary format A sequential file...

Page 148: ...8 AS P Use LSET to move the data into the random buffer Numeric values must be made into strings when placed in the buffer To do this use the make functions MKI to make an integer value into a string MKS for a single precision value and MKD for a double precision value SET N X LSET A MKS AMT LSET P TEL Write the data from the buffer to the disk using the PUT statement Look at Program B 4 It takes ...

Page 149: ...T 60 INPUT PHONE TEL PRINT 70 LSET N X 80 LSET A MKS AMT 90 LSET P TEL 100 PUT t1 CODE 110 GOTO 30 5 3 2 2 Access A Random File The following program st eps are required t o access a random file Use the FIELD st atement t o allocat e space in the random buffer for t he variables that will be read from the file FIELD 1 20 AS N 4 AS A 8 AS P NOTE In a program that performs both input and out put on ...

Page 150: ...The LOC function with random files record number The current record last record number that was used in a For example the statement returns the current number is one plus the GET or PUT statement ends program execution if the current record number in filet1 is higher than 50 Program B 6 is an inventory program that illustrates random file access In this program the record number is used as the par...

Page 151: ... QUANTITY IN STOCK Q 320 LSET Q MKI Q 330 INPUT REORDER LEVEL R 340 LSET R MKI R 350 INPUT UNIT PRICE P 360 LSET P MKS P 370 PUTt1 PART 380 RETURN 390 REM DISPLAY ENTRY 400 GOSUB 840 410 IF ASC F 255 THEN PRINT NULL ENTRY RETORN 420 PRINT USING PART NUMBER t PART 4 30 PRINT 0 440 PRINT USING 450 PRINT USING 460 PRINT USING 470 RETURN 4 80 REM ADO TO STOCK 4 90 GOSOB840 500 IF ASC F 255 T PRINT NUL...

Page 152: ...ANTITY CVI Q TAB 50 If REORDER LEVEL CVI R 730 NEXT I 740 RETURN 840 INPUT PART NUMBER PART 850 IF PART 1 OR PART 100 THEN PRINT BAD PART NUMBER GOTO 840 ELSE GETt1 PART RETURN 890 END 900 REM INITLALIZE 910 INPUT ARE YOU SURE B IF B Y THEN RETURN 920 LSET F CHR 255 930 FOR I 1 TO 100 940 POT 1 I 950 NEXT I 960 RETORN ...

Page 153: ...anguage subroutine before it can be loaded During initialization enter the highest memory location minus the amount of memory needed for the assembly language subroutine s BASIC uses all memory available from its starting location up so only the topmost locations in memory can be set aside for user subroutines When an assembly language subroutine is called the stack pointer is set up for 8 levels ...

Page 154: ...nging the address in USRLOC an MIllegal function call error results where the argument is a numeric expression To obtain the argument the assembly language subroutine must call the routine DEINT DEINT places the argument into the D E register pair as a 2 byte 2 s complement integer If the argument is not in the range 32768 to 32767 an Illegal function call error occurs To pass the result back from...

Page 155: ...eing called and corresponds with the digit supplied in the DEl USR statement for that routine If digit is omitted USRO is assumed The address given in the DEF USR statement determines the starting address of the subroutine When the USR function call is made register A contains a value that specifies the type of argument that was given The value in A may be one of the following Value in A m g Argum...

Page 156: ...alter or destroy your program this way To avoid unpredictable results add II to the string literal in the program Example This will copy the string literal into string space and will prevent alteration of program text during a subroutine call Usually the value returned by a USR function is the same type integer string single precision or double precision as the argument that was passed to it Howev...

Page 157: ...al to 3 they are passed in the registers Parameter 1 will be in aL 2 in DE if present and 3 in BC if present 2 If the number of parameters is greater than 3 they are passed as follows 3 Parameters 3 through n in a contiguous data block BC will point to the low byte of this data block i e to the low byte of parameter 3 Note that with this scheme the subroutine must know how many parameters to expec...

Page 158: ...PACE FOR PARAMETER 2 SPACE FOR PARAMETERS 3 5 00100 00200 00300 00400 00500 00600 00700 00800 00900 01000 01100 01200 01300 01400 01500 01600 01700 01800 01900 02000 02100 02200 02300 i B C H L A ARGUMENT TRANSFER POINTS TO 3RO PARAM POINTS TO LOCAL STORAGE FOR PA 3 CONTAINS THE i OF PARAMS TO XFER TOTAL 2 ENTRY AT AT XCHG MOV H B MOV L C AT1 MOV C M L nC H MOV B M INX H XCHG MOV M C INX B MOV M B...

Page 159: ...ose written in assembly language Assembly language subroutines can be written to handle interrupts All interrupt handling routines should save the stack register A L and the PSW Interrupts should always be re enabled before returning from the subroutine since an interrupt automatically disables all further interr pts once it is received The user should be aware of which interrupt vectors are free ...

Page 160: ......

Page 161: ...al with the following exceptions The initialization dialog has been replaced by a set of options which are placed after the MEASIC command to CP M The format of the command line is If filename is present MBASIC proceeds as if a RUN filename command were typed after initialization is complete A default extension of BAS is used none is supplied and the filename is less than 9 characters long This al...

Page 162: ...cations 6 and 7 If the M option is omitted all memory up to the start of FDOS is used Both number of files and highest memory location are numbers that may be either decimal octal preceded by 0 or hexadecimal preceded by H Use all memory and 3 files load and execute PAYROLL BAS Use all memory and 6 files load and execute INVENT BAS Use first 32K of memory and 3 files A MBASIC DATACK F 2 M B9000 Us...

Page 163: ...or extension will match any file or any extension FILES FILES BAS FILES B FILES TEST BAS To close all disk files and write the directory information to a diskette before it is removed from a disk drive ways execute a RESET command before removing a diskette from a disk drive Otherwise when the diskette is used again it will not have the current directory information written on the directory track ...

Page 164: ... used with random files If a GE is done past the end of file EOF will return 1 This may be used to find the size of a file using a binary search or other algorithm 1 CSAVE and CLOAn are not implemented 2 To return to CP M use the SYSTEM command or statement SYSTEM closes all files and then performs a CP M warm start Control C always returns to MBASIC not to CP M 3 FRCIN is at 103 hex and MAKIN is ...

Page 165: ......

Page 166: ......

Page 167: ...sand for string concatenation Each of these must be changed to a plus sign which is the operator for BASIC SO string concatenation In BASIC SO the MID RIGHT and LEFT functions substrings of strings Forms such as A I character in A or A I J to take a substring of to position J must be changed as follows are used to take to access the Ith A from position I BASIC SO X MID A I 1 X MID A I J I 1 X A I ...

Page 168: ... Instead convert this statement to two assignment statements Some BASICs use a backslash 1 to separate multiple statements on a line With BASIC SO be sure all statements on a line are separated by a colon I 4 FUNCTIONS Programs using the MAT functions available in some BASICs must b rewritten using FOR NEXT loops to execute properly ...

Page 169: ...ation etc Return without GOSUB A RETURN statement is encountered for which there is no previous unmatched GOSUB statement 00 4 Out of data A READ statement is executed when there are no DATA statements with unread data remaining in the program FC 5 Illegal function call A parameter that is out of range is passed to a math or string function An FC error may also occur as the result of 1 a negative ...

Page 170: ... Red ensioned array Two DIM statements are given for the same array or a DIM statement is given for an array after the default dimension of 10 has been established for that array range is referenced either with is outside the dimensions with the wrong number a of of Division by zero A division by zero is encountered in an expression or the operation of involution results in zero being raised to a ...

Page 171: ...been modified during a break in execution or Ondefined user function A OSR function is called before the function definition OEF statement is given Extended Versions Only 19 No RESUME An error trapping routine is entered but contains no RESUME statement 20 RESUME without error A RESUME statement is encountered before an error trapping routine is entered Unprintable error An error message is error ...

Page 172: ... that is not OPEN or is out of the range of file numbers specified at initialization 53 File not found A LOAD KILL or OPEN statement references a file that does not exist on the current disk Bad file mode An attempt is made to use PUT GET or LOF with a sequential file to LOAD a random file or to execute an OPEN with a file mode other than I 0 or R File already open A sequential output mode file th...

Page 173: ...T or GET statement the record number is either greater than the maximum allowed 32767 or equal to zero 64 Bad file name An illegal form is used for the filename with LOAD SAVE KILL or OPEN e g a filename with too many characters 66 Direct statement in file A direct statement is encountered while LOADing an ASCII format file The LOAD is terminated Too many files An attempt is made to create a new f...

Page 174: ......

Page 175: ...CANT INVERSE HYPERBOLIC COSECANT INVERSE HYPERBOLIC COTANGENT BASIC 80 Equivalent SEC X 1 COS X CSC X 1 SIN X COT X 1 TAN X ARCSIN X ATN X SQR X X 1 ARCCOS X ATN X SQR X X 1 1 5708 ARCSEC X ATN X SQR X X 1 SGN SGN X 1 1 5708 ARCCSC X ATN X SQR X X 1 SGN X 1 1 5708 ARCCOT X ATN X 1 5708 SINH X EXP X EXP X 2 COSH X EXP X EXP X 2 TANH X EXP X EXP X EXP X 2 1 SECH X 2 EXP X EXP X CSCH X 2 EXP X EXP X ...

Page 176: ......

Page 177: ...nds These specify what files are to be compiled There is no direct mode as with the BASIC SO interpreter Commands that are usually issued in the direct mode with the BASIC SO interpreter are not implemented on the Compiler The following statements and commands are not implemented and will generate an error message AO l O EDIT LOAD FILES CLEAR LIST v ERGE CLOAD LLIST NEW CSAVE RENOM CHAIN CONT RUN ...

Page 178: ... SO as routine must be supplied language subroutine or FORTRAN SO library 2 CHAIN and COMMON The CHAIN and COMMON statements are not implemented on the compiler They will generate a fatal error in the CALL statement symbol i e one that is a global symbol This by the user as an assembly a routine from the The CHAIN and COMMON statements will be implemented in a future release of the BASIC compiler ...

Page 179: ...ot be variables arithmetic expessions or floating point values For example DIMA1 I DIM A1 3 4 6 END During execution of a compiled program an END statement closes files and returns control to the operating system The compiler assumes an END statement at the end of the program so running off the end produces proper program termination 7 ON ERROR GOTO RESUME line number If a program contains ON ERRO...

Page 180: ...o Qt The Compiler is more limited than the interpreter in handling numeric overflow For example when run on the interpreter the following program I 20000 J 20000 K 30000 M I J K yields 10000 for M That is it adds I to J and because the number is too large it converts the result into a floating point number K is then coverted to floating point and subtracted The result of 10000 is found and is conv...

Page 181: ...precedence and parenthetic modification of such precedence but no other guarantee of evaluation order can be made In order to produce the fastest and most compact object code possible make maximum use of integer variables For example this program FOR I 1 TO 10 A I O NEXT I can execute approximately 30 times faster by simply substituting RI for I It is especially advantageous to use integer variabl...

Page 182: ......

Page 183: ... 058 101 e 016 DLE 059 102 f 017 DC1 060 103 g 018 DC2 061 104 h 019 DC3 062 105 i 020 DC4 063 106 j 1 021 NAK 064 107 k 022 SYN 065 A 108 1 023 ETB 066 a 109 m 024 CAN 067 C 110 n 025 EM 068 D 111 0 026 SUB 069 E 112 P 027 ESCAPE 070 F 113 q 028 FS 071 G 114 r 029 GS 072 H 115 s 030 RS 073 I 116 t 031 OS 074 J 117 u 032 SPACE 075 K 118 v 033 076 L 119 w 034 II 077 M 120 x 035 078 N 121 Y 036 079 ...

Page 184: ......

Page 185: ...nstants CON r Control characters Control A COS CP M CSAv E CSAVE CSNG 0 CVD CVI CVS 3 2 1 10 2 4 2 9 3 3 1 7 2 9 2 18 L 4 1 7 2 7 2 11 2 24 3 2 3 2 3 4 M 1 2 4 2 49 2 77 2 3 2 16 2 59 3 23 C 1 L 2 3 3 L 3 L 1 3 21 2 3 C 5 L 2 1 3 2 36 2 41 to 2 42 2 83 to 2 85 2 7 2 11 3 3 2 4 2 9 L 2 1 3 3 4 3 4 2 6 A 1 2 7 2 7 2 7 2 8 a 3 a 8 1 1 2 4 2 9 L 2 1 14 1 4 2 10 2 41 1 4 2 22 3 5 L 3 2 46 2 49 2 76 to ...

Page 186: ...vision Double precision EDIT Edit mode END EOF EM SE ERL ERR ERROR Error Error Error codes messages t apping Escape EXP Exponentiation Expressions FIELD FILES FIX FOR NEXT FRCINT _ FRE Functions GOSUB GOTO HEX Hexadecimal IF GOT0 IF THEN IF THEN ELSE Indirect mode INP INt OT ...

Page 187: ...ion LEFT LEN LET LINE INPUT LINE INPUT Line numbers Line printer Lines LIST LLIST LOAD LaC LOF LOG L gical operators Loops LPOS LPRINT LPRINT USING LSET MAKINT MBASIC MERGE MID Ml D Ml I Ml S MOD operator Modulus arithmetic NAME Negation NEW NULL ...

Page 188: ... OO r Overflow Overla y Paper tape PUX poa POS PlUN r PlUNT USING PRIN Xt PRIN J t USING P ENOM RESET imSTOilE RESma RtrOml RIGa l P N O RSET Rubout RUN 1 4 1 7 3 14 1 5 3 14 2 54 L 3 2 55 2 55 2 8 2 28 a 8 1 9 1 11 2 57 2 58 1 11 3 7 2 4 2 53 2 59 2 59 2 83 2 60 2 62 2 66 2 66 3 15 3 15 3 15 A 1 A 2 A 3 A 3 ...

Page 189: ... Subroutines Subsc i t3 Subuac iion SWAP SYSTE TAB Tab TAN TROFF TP ON osa OSRLOC VAL Variables WAIT WEND WI WIDTH WIDTH w U l 3 1i 3 1 i t 3 i 3 2 i5 3 18 3 18 3 19 t 3 2 10 2 23 2 32 2 i8 L 3 3 19 1 4 3 6 3 10 to 3 11 3 13 3 16 3 19 3 22 I 1 1 14 2 6 3 8 A 1 3 9 1 i 2 15 2 4i to 2 42 3 20 2 3 2 32 2 35 C 1 1 1 2 18 2 51 t 3 1 10 2 19 0 4 ...

Page 190: ......

Reviews: