Home

AMOS AlphaBasic

image

Contents

1. 1 June 1982 255 10013 00 CHANGE PAGE PACKET 4 FOR THE ALPHA BASIC USER S MANUAL 1 0 INTRODUCTION This amp th change page packet for the AlphaBASIC User s Manual DWM 00100 012 Revision B0 contains update instructions a new title page and the manual pages that we have revised It updates the manual to Revision BD4 This packet should be implemented only in versions that have been updated to Revision level BO3 that is only if your manual includes the contents of change page packet 3 1 1 UPDATE INSTRUCTIONS To make the update process easier your copy of the AlphaBASIC User s Manual should be loose in a 3 ring binder First remove the title page from this change page packet and exchange it for the title page in your copy of the manual If your copy has been updated with change page packet 3 the title page you replace will show a BOS revision level The new title page reflects revision level 804 Now remove the remaining change pages from this packet and substitute them for the original pages Listed below As you exchange these pages for the originals note that we have marked all revised portions of the text with change bars vertical black Lines in the Left margin Also notice that the number of the manual appears at the bottom of each change page Original Pages Revised Pages Title page 1i vii through ix 2 9 2 10 5 1 S 2 11 5 11 6 12 21 through 12 4 15 11 13 12 16 1 16 2 T 7 3 17 4 18 1 through 18
2. QUERY 1010 QUERYSUCSCQUERY IF QUERY FY INSURANCE 1 ELSE INSURANCE 0 1015 ID NUM z REC NUM Customer number is just record 1020 Write whole record increment records in use counter and bump 1025 REC NUM so we are ready to write to next record 1030 WRITE 2 CUSTOMER INFO IN USE IN USE 1 REC NUM REC NUM 1 1035 PRINT Customer ID Number iss ID NUM 1040 GOTO GET INFO 1048 1050 We want to stop entering data 1055 EXIT 1060 PRINT Now closing output file 1065 REC NUM 0 WRITE 2 HEADER RECORD 1070 PRINT Total number of records in files 1078 PRINT TOTAL RECS Records in uses IN USE 1080 CLOSE 2 1085 RETURN Changed 31 October 1981 CHAPTER 16 CHAINING TO BASIC AND SYSTEM PROGRAMS The CHAIN statement terminates execution of the current program and initiates the execution of a new program or system function The new program to be executed must be named in the CHAIN statement itself that name may be a full file specification The file named in the statement may be another ALphaBASIC program compiled only or it may be a system command or command file This allows your program to execute a command fiie and invoke system commands as well as execute other AlphaBASIC commands 16 1 CHAINING TO ANOTHER ALPHABASIC PROGRAM CHAIN assumes a default extension of RUN which designates a new AlphaBASIC program ta be executed If the extension of the evaluated file specification is
3. GENERAL INFORMATION Page 3 6 The INCLUDE must be the first command on the Line no Line number and the filespec can be any valid AMOS file specification that optionally includes a device name and or PPN The default extension is BSI BASIC Include file If you do not specify a device and or PPN the search pattern is the same as that for RUN modules Ci e user PPN user CP 0 DSKO L 7 612 As COMPIL accesses each file defined in a INCLUDE command you see Copying from filename The filename is the filespec you specified in the INCLUDE command Multiple INCLUDE commands in the same file are allowed but a file that is copied in may not itself contain a INCLUDE command If yeu load into interactive BASIC a file containing one or more INCLUDE commands BASIC ignores them Changed 31 October 1981 CHAPTER 4 ALPHABASIC VARIABLES 4 1 VARIABLE NAMES An AiphaBASIC variable name may contain any number of alphanumeric characters and is not Limited to a single letter or to a letter and a digit as in most BASIC implementations The first character of the name must be alphabetic from A to Z and a to z and the variable name may begin with any reserved word unless NOEXPAND mode is set see Section 3 8 EXPAND and NOEXPAND Modes For a List of AlphaBASIC reserved words see Appendix C Reserved Words Apostrophes may also be used in variable names to improve clarity You may use both upper and lower case
4. the data record specified by the relative key is returned To the free list for reuse by a code 5 call The index file is not modified and the symbolic key in the statement is ignored This call must be made only to the primary index file number Code Same as code 2 above except that ISAM also returns the symbolic key The symbolic key variable in your code 7 ISAM statement must be the same size as or larger than the key defined in the ISAM 3ndex file Changed 31 October 1981 USING ISAM FROM WITHIN BASIC Page 19 5 19 4 OPENING AN INDEXED FILE As with other types of files an indexed file must be opened with a specific file channel number prior to any references to the file by other statements The OPEN statement follows the same format as that used by the normal random files except that you specify INDEXED or INDEXED EXCLUSIVE mode OPEN file channel filespec INDEXED record size relativerkey OPEN amp file channel filespec INDEXED EXCLUSIVE record size relat ive key amp file channel Any numeric expression that evaluates to an integer from 0 45535 0 is defined as the user terminal filespec Any string expression that evaluates to a Legal AMOS file specification Coptionaliy including account and device specifications Specifies the data file primary index file or the secondary index file The primary index file always has the same name as the data file but has the IDX extension the data file has the IDA
5. were ever enabled It is recommended that all error trapping routines execute the ON ERROR GOTO 9 statement for all errors which have no special recovery processing NOTE If an error occurs within the error trapping routine itself that error is processed and the error message Error in error trapping occurs There is no method to detect errors within the error recovery routine 17 2 ERROO FUNCTION The ERR function returns the following data based on conditions at the time of the error ERR ODO numeric code specifying the type of error detected ERR TO Last Line number encountered prior ta the error ERR 2 Last file number accessed only relevant for file errors 17 2 1 Error Codes Returned by ERR Code Meaning 1 Control C interrupt 2 System error 3 Qut of memory amp Out of data 5 NEXT without FOR amp RETURN without GOSUB 7 RESUME without ERROR 8 Subscript out of range 5 Floating point overflow 10 Divide by zero 11 lilegal function value 12 XCALL subroutine not found 13 File already open 14 IO to unopened file 15 Record size overflow 16 File specification error 17 File not found 18 Device not ready 19 Device full 20 Device error 21 Device in use 22 illegal user code 23 Protection violation 24 Write protected 25 File type mismatch 26 Device does not exist d Bitmap kaput ERROR TRAPPING Page 17 3 28 Disk not mounted 29 File already exists 30 Redimensioned array 31 illegal record number
6. 32 Invalid filename 3A Stack overflow 34 Invalid syntax code 35 Unsupported Function 36 invalid subroutine version For example if PRINT ERRCO returns a 10 you know that the program tried to divide a number by zero 17 5 RESUME STATEMENT The RESUME statement is used to resume execution of the program after the error recovery procedure has been performed ft also re enables Controi C detection which jis turned off while BASIC processes the error trapping routine The statement takes on two forms similar to the forms of the ON ERROR GOTO statement The first form specifies a Line number or label within the program where the execution is to be resumed RESUME 410 RESUME TRY AGAIN F The second form specifies a Line number of zero or no Line number at all and causes the execution to be resumed at the statement which caused the error to occurz RESUME 9 RESUME Both forms cause the error condition to be cleared and error trapping to be enabled again NOTE You must never use the GOTO statement to exit from an error trapping routine You must use RESUME This is because RESUME clears the Error stack but GOTO does not which causes problems for Later error handling 17 4 CONTROL C TRAPPING When you type a Control C on your keyboard during the execution of an AlphaBASIC program the program is suspended at the next statement Action taken then depends upon the status of the error trapping flag If no error trappin
7. Changed 1 October 1981 ALPHABASIC FILE I O SYSTEM Page 15 15 155 160 165 170 VFS 180 185 190 195 200 205 210 215 220 225 230 235 240 245 250 255 260 265 270 ars 280 285 290 295 300 305 310 315 520 325 330 335 340 345 350 555 560 365 370 375 380 385 390 395 400 405 415 420 i RE MAPI REC NUM F MAPI RESULT F MAPI QUERY S 3 MAPT NVAL F i i i i i i H ST Contains current record number LOOKUP command result variable Scratch variable init to null Scratch variable for user input w dee hb sum BEGIN MAIN PROGRAM Use LOOKUP command to see if file already exists If it does go to routine that will read information from the files otherwise create file First ask user for total number of records we can write to file Then see how many bytes this requires 64 TOTAL RECSO We can fit exactly 8 records per disk block 512 8 44 If can t fit even number of records per block allocate one extra block Now that we know how many disk blocks to allocate ALLOCATE and OPEN the file ART LOOKUP CUSTMR DAT RESULT IF RESULT lt gt 0 GOTO READ FILE PRINT TAB 1 00 TABCTIO T t Clear screen position cursor INPUT Enter total number of file records TOTAL RECS BYTES TOTAL RECS REC SIZE BLOCKS BYTES 512 IF BLOCKS lt gt INT BYTES 512 THEN BLOCKS FIX BLOCKSO 4 ALLOCATE CUSTMR DAT BLOCKS OPEN 2 CUSTMR DAT RANDOM REC SIZE REC NUM
8. Open the data index file with an OPEN statement Locate the record you want via one of the methods above 1 by using a code 1 or code 2 ISAM statement Check to make sure that the record was found Use the ERF function Now the correct relative key is in the relative key variable defined by the OPEN statement so use the WRITE statement to rewrite the data record Remember to specify the file channel number associated with the data primary index file Repeat steps 2 through amp for all records you want to rewrite Close the files teps above do not change the index files so do not change the symbolic n the record you rewrite USING ISAM FROM WITHIN BASIC Page 19 12 If you need to change the symbolic key s in the data record you must first delete the key in the correct index file code 4 and then add the new key to the index fite code 3 You do not need to delete and re create the data record during this operation unless you are entering completely new data 19 9 6 Deleting a Data Record Deleting a data record from an indexed sequential file entails not only deleting the record itself from the data file but also deleting all symbolic keys associated with that data record from all index files 1 Open the data primary index file and all secondary index files needed sate the data record via one of the symbolic keys a code 1 ISAM a ios E Check to see that the statement was executed successfully i e
9. breakpoint interrupts and other functions that suspend program execution After partially Lordi Nd through a program you may execute the remainder of it normally by using the CONT command Also you may start over at the beginning and execute it normally by using the RUN command if you try to single step past the end of the program you see x End of Program and the next Linefeed executes the first program statement again step a statement that asks for input from the terminal enter owed by a RETURN then you may proceed to the next statement her Linefeed if you single the input foll by typing anot bd Remember that the single step function is performed by hitting the Line feed key and not by tually entering the words single step The following is a demonstration of the single step process for a small p as ale would see it on your CRT The symbol Y represents the Linefeed key which you press to see the next statement and the results of it You do not actually see an echo of the linefeed key on the CRT Note that Line 30 is a multi statement Line When single stepping all statements on a Line are executed BASIC returns control to the interactive mode at the beginning of each Line Changed 30 April 19812 INTERACTIVE COMMAND SUMMARY Page 9 9 LIST GED 10 30 PRINT This is a demonstration of single step 20 FORIs1TOS3 7 30 PRINT TORT PRIMI PRINT 10 1 I PRINT 10 I I EO NEXT I SEAT Y
10. is an abbreviation of the REM statement and is used the same way Like the REM statement anything following the symbol on the Line is ignored For instances 40 PRINT TRY ANOTHER TIME IF THEY MISS BETWEEN 50 GOTO AGAIN LONE AND THREE TIMES NOTE If the REM or keyword is the Last statement on the program line you do not need to precede it with a colon the statement separator symbol GENERAL INFORMATION Page 3 3 3 5 INTERACTIVE MODE DIRECT STATEMENTS AlphaBASIC immediately executes any Line you enter if that Line does not start with a Line number Such Lines may be of two types BASIC system commands and direct statements A BASIC system command performs a system function for example the LIST command tells AlphaBASIC to display the program currently in memory BASIC system commands may never be part of a program Line Direct statements on the other hand are normal program statements that may also appear within a program line For example the PRINT statement tells ALphaBASIC to display a specified numeric or string value and may appear either as a direct statement or as part of a program Some statements are not allowed as direct statements for example the GOSUB statement 3 6 PROGRAM LABELS ALphaBASIC allows the use of program labels to identify Locations in a program A program Label is composed of one or more alphanumeric characters which are not separated by a space or other delimiter The first character must
11. ELSE 4 PRINT ALL dane Changed 0 April 198132 INTERACTIVE AND COMPILER MODES Page 2 8 NOTE Since COMPIL does not require that your program contain Line numbers it does na checking for duplicate Line nunbers or lines out of numeric seguence if your program contains these kinds of errors it will compile using COMPIL However if you use interactive mode and load the program in BASIC which requires Line numbers will be unable to handle the program correctly and errors will result For example in the case of duplicate Line numbers BASIC will merely take the Last Line in the file bearing the duplicate number 2 2 0 Compiling a Program To compile a program in compiler mode at AMOS command level enter COMPIL followed by the specification of the file you want to compile You may supply a full file specification including account and device specifications The default extension is BAS The default account and device are the ones you are Logged intoa After you enter the file specification type a RETURN For examples COMPIL REVRSE RET Now you see a number of statistics on your terminal as COMPIL compiles your program amp typical display might look something Like this COMPIL ACMSLS ED Phase 1 Initial work memory is 2510 10 bytes Phase 2 Adjust st object fite and p process errors Tiesa MAP levet 350 MAP FIL s Sgt Ec KA Syntax error 980 SUSMTD SLSMTD SUS SHTO SSLAMT Memory usage 7 ES
12. Line Feed vt 1 m3 41 OB Vertical Tab FF 04 T OC Form Feed CR i Om 13 Op Carriage Return so 016 14 Of Shift Out SI 1 O7 j 15 OF Shift In i DLE 020 16 10 Data Link Escape pet O24 17 i 14 Device Control 1 DEZ 022 18 12 Device Control 2 pez 023 49 13 Device Control 5 DCA 024 20 14 Device Control 4 NAK i 025 21 15 Negative Acknowledge SYN 026 o 16 Synchronous Idle i ETB 0 23 1 End of Transmission Blocks CAN 030 24 18 Cancel EM 031 25 19 End of Medium SS 032 2 1A Special Sequence j ESE 033 2 1B Escape i FS 084 28 36 File Separator G 035 29 15 Group Separator RS 036 30 1E Record Separator Us Miss 31 TF Unit Separator CMT ENS tne ee een E c E ity i ca tee ced THE ASCII CHARACTER SET Page D 3 PRINTING CHARACTERS DECIMAL HEX CHARACTER MEANING 32 20 Space 33 21 Exclamation Mark 34 22 Quotation Mark 35 23 Number Sign 36 24 Dollar Sian 37 25 Percent Sign 38 26 Ampersand 39 aT Apostrophe 40 28 Opening Parenthesis 41 29 Closing Parenthesis 42 2A Asterisk 43 2B PLus A 054 44 ac Comma 055 45 2D Hyphen or Minus 056 46 2E Period f 057 47 ZF Slash 0 060 48 30 lero 1 061 49 31 One 2 062 50 32 Two 3 063 51 p 53 Three amp 064 52 Ra Four 5 065 53
13. OPERATOR PRECEDENCE sus xa RR pa aan aa de am T a MODE INDEPENDENCE daseaaeskuecn ex Te da EE ae PT M UNE wa CHAPTER 4 DATA FORMATS 4 1 FLOATING POINT FORMAT 4 2 STRING FORMAT SR eee 5 A ROB RoOR AH TR amp o HRB mushertesosumesnnadecesnesaszasca Oe Changed 50 April 1981 ALPHA BASIC USER S MANUAL Page iv 6 5 BINARY FORMAT le xerdcesacsc ecw bene m OR Rem e RR DITE 5 4 INTEGER FORMAT aos ERAS A RIA RR alee eae OTS 6 5 UNFORMATTED oleenanssonnueonecsansccesueosn 075 CHAPTER 7 SUBSTRING MODIFIERS 7 1 SUBSTRING MODIFIER FORMATS AND FEATURES f 1 CHAPTER 8 MEMORY MAPPING SYSTEM 1 ALLOCATING VARIABLE STORAGE coconsnasensanoren 2 MAP STATEMENT FORMAT casnuneccevnnnsseuanene Baek MAP Level anrasan ance nee ES c vain in 8 2 2 Variable Name acanennnenennunnnanennane 8 5 Type CODE lacs gu EN Boe eo Unformatted Data 2 oo nacos 62223 2 String Pata v eek VAS 8 2 3 5 Floating Point Data onoanono o 8 2 3 4 Binary Data s ooocnnnananenaossa S A 8 i 1 Qe Qo P P co CO Qo os a A SUID c 1 20 i QM Vm un LIS EE CUI E E E T E Bic Oe VALUES ais es mA did BO SR SORTA elie de Rak ecran ta a BA E i EXAMPLES qam RR ERU mum mm A OR OR RC ROSE PRU USING THE MAP STATEMENTS anno oaoocornsrsoanaona P711 LOCATING VARIABLES DURING DEBUGGING suaesaasss 8711 8 5 1 tXahpleS es ka wee EUR I RUE RR n m eh e ee AS s a Vn CHAPTER 9 INTERACTIVE COMMAND SUMMARY 9
14. STRSIZ SUB TAB TAN THEN TIME TO UCS USING VAL WORD WRITE XCALL XOR Changed 31 October 1981 subroutine exit right string right string random number run program save program set scale factor sign set significance sine spaces spaces square root step stop program numeric to string conversion numeric to string conversion set string size sub GOSUB tab tangent optional statement verb system time to upper case string using string to numeric conversion memory word write file external subroutine call logical XOR Page C 3 APPENDIX D THE ASCII CHARACTER SET contain charts that List the complete ASCII character The next few pages of the set We provide the octal decimal and hexadecimal representations ASCII values Note that the first 32 characters are non printing Control characters THE ASCII CHARACTER SET Page D 2 THE CONTROL CHARACTERS p oars aaa c PO nae CHARACTER i OCTAL DECIMAL HEX x MEANING i jo ne T a ee i NULL 000 p 0 i 00 Null cil sfapsckeot i SOH j 0m 1 01 Start of Heading STX j 00e 2 02 Start of Text ETX 003 3 03 End of Text m ECT 004 4 04 i End of Transmission ENG 005 5 05 Enquiry ACK 006 6 06 Acknowledge i mm i i A n7 1 i s oO s os Back Space H BN Vit k i i lia pS e e HT 01 9 09 Horizontal Tab OLF 012 10 04
15. Secunia un m X eee LEMOA CNA amp 9 su Ade Ree Hoo EL E AN Set amp 9 X m 9 9 p 9 n 9 er er Amen m N 9 o S mp Ss 25 9 HR 6 mW T oO O9 BEING Fe eS WoR OP m XS 9 ow tod HEE amp R S P BR OG x 6 AP BES MM NEMUS 9 9 mw S 8 teen 9 X5 0 BS e 8 9 fF wa X or LEFT A X0 amp 0 amp amp o B HA 5 s de ms 9 eas eana MID A X Y or MID AS X Y RIGHT CAS 0 UCSCATO VAL CAS THE ASCII CHARACTER SET or RIGHTS AS X aa P oSBOO X amp o P dom Ou HR amp 4 KES BE 9 M 9 a a amp B B BK G 5 ES o3 9 5 ox wn MESSAGES OUTPUT BY ALPHABASIC Page ix A 14 A 14 A 14 A 14 ATA Aeth A 14 A 14 A 14 A 14 A 15 A 15 A 15 A 15 A 15 A 15 A 16 A 16 A 16 A 16 A 16 amp 16 A 17 An hol A 17 A 17 And Ant A 1 A 18 A 18 SAMPLE PROGRAM NUMERIC CONVERSION FOR BASES 2 16 ALPHA BASIC USER S MANUAL Page xi PREFACE AlphaBASIC is a particularly powerful version of BASIC that has been expanded in several important areas The following chapters describe the AlphaBASIC features and operations We assume that vou are already familiar with the BASIC programming Language and that you are interested in getting to know AlphaBASIC Therefore this book emphasizes features of AlphaBASIC that differ from those of conventional BASICs without going into much detail on standard BASIC statements and commands This book is not
16. This is handy for the storage of small integer data in a single byte such as flags or for the storage of memory references as word values with a range of up to 65535 in two bytes Since BASIC converts all binary variables to floating point format before performing any arithmetic calculations binary arithmetic is actually slower than normal fioating point arithmetic and is used mainly for compacting data into files and arrays where the floating point size of six bytes is inefficient When canversions from floating point to binary are done any data that does not fit within the defined size of the target variable is merely last with error message given Where required range checks are your responsibi as the programmer before you make a floating point number move to a bina variable area The best way to understand this is to play with a few examples in interactive mode Please take note that the use of binary numeric variables is not allowed in some instances FOR NEXT Loops may not use a binary variable as the control variable although they may be used in the expressions designating the initial and terminating values of the control variable as weil as in the STEP expression MEMORY MAPPING SYSTEM Page 8 6 The size parameter in the MAP statement is optional but if it is used it must be a decimal number specifying the number of bytes in the variable If it is omitted it defaults to 0 for unformatted and string types 4 for floating
17. Write initial file header to Record 0 REC NUM 0 File header is control record that tells us how many records are in file TOTAL RECSO and of those how many are in use IN USED REC NUM O IN USE 0 WRITE 2 HEADER RECORD REC NUM 1 i Get ready to write to next record i Clear screen and position cursor PRINT TAB 1 0 Entering info s TABCTO 1 PRINT When vou are through enter a RETURN for Customer Name GOSUB GET INFO t Get info and write it to file READ INFORMATION FROM EXISTING FILE Open file for input Get control record to see how many records are in use Ask user if wants to read from file if not exit Check to see if existing file is empty if so exit Tell the user what customers we have info for ask which customer user wants info on 1 customer ALL or none Check to make sure user enters valid customer number Just a RETURN snuLl means user wants to quit Display desired info until user enters a RETURN to quit AD FILE OPEN 83 CUSTMR DAT RANDOM REC SIZE REC NUM REC NUM 0 READ 3 HEADER RECORD PRINT INPUT Do you want to read file Y or N QUERY QUERY UCSCQUERYO gt IF QUERY N GOTO READ EXIT i Clear screen and position cursor PRINT TAB 1 0 0 Reading file s TABC10 1 IF CIN USE 0 THEN PRINT File is empty SOTO READ EXIT i Show user what customers we have info on PRINT Here is a list of the customers for whom we have info FOR REC NUM 1 TO IN US
18. amp THEN amp PRINT IT IS LUNCHTIME amp ELSE amp PRINT GO BACK TO WORK PRINT TIME 60 60 CLKFRG 10000 The maximum size of any Line including blanks tabs and any continuation Lines is 500 characters 3 3 LINE NUMBERS Program Line numbers range from 1 to 65534 Programs used in interactive mode must contain Line numbers Programs to be compiled in compiler mode do not need to have Line numbers Therefore if you create your program using VUE and are going to use COMPIL you may omit the line numbers from the program Unnumbered Lines may enhance the structured look of your source program as shown in Section 3 2 NOTE Tf you include Line numbers that does mean that if an error occurs BASIC will be able to tell you which Line the error occurred in 3 4 COMMENTS CREM AND VI AiphaBASIC supports the ability to insert comments into the source program using two methods The keyword REM may appear alone on a line followed hy the comment or may be inserted on the same Line as a statement to comment on the purpose of the statement You may follow the REM or remarks keyword with anything vou want For example 7O REM ANYTHING YOU WISH TO SAY 100 PRINT A REM VARIABLE A MEANS ALLOWANCE Note that Line 100 above is a legal multi statement Line however no statement may follow a REM statement on a Line When the program isa compiled everything in the Line following the REM statement is ignored The comment symbol
19. even though you may have specified a symbolic key contained in a secondary index file Repeat these procedures to step through the data records in the order of the symbolic keys in the index files Close all files when you are done DWM 00100 01 REV BOA USING ISAM FROM WITHIN BASIC Page 19 11 19 9 4 1 19 9 5 Reading Data Records Randomly by Symbolic Key Open the data index file with an OPEN statement You must alse open any secondary index file you want to use Use a code 1 ISAM statement to locate the data record you want to find The statement must contain the symbolic key associated with the data record you want and must contain the file channel number associated with the index file that contains the symbolic key Check for a record not found error this indicates that the symbolic key was not found in the specified index file If the record was found the proper relative key is now in the relative key variable defined in the OPEN statement Use a READ statement to read in the data The READ statement includes the file channel number associated with the data file primary index file even if the symbolic key used belonged to a secondary index file Repeat steps 2 through 4 for each record you want Close all files Updating Data Records You may sometimes want to change the data in a record in the data file You may do so by first finding the record you want and then rewriting it The key S i 4
20. 1 BREAK dax ee reae a E aue wes OTA m Qe Qu Q BYE Sou erae e USER aaa Cae 6 TOR RACER E US Ware ee Pe c CO E S 4 MOLLE guess lm eee a ek AE EN CONT i nen enna eames nse a ene n ena nna dee eesnanne Ha amo AM ob DELETE ia ta a mem EIER alm ORE CE RU wae Rie E mor Rx Ro IEA El 3 A OC MAR e ad E 2 S G R LIST PDT 5 CORD AAA REA AAA E NEW serocararsrsaranacianonsaneonoronecranoon s e E RUN ee ere ae ele nr aa eee m dU A G SAVE VAVE L L nns nonaneonsane nannuunpnaetosnuaeteenaum SINGLE STEP CLINEFEED ceaeeneononocuaso DT DX 000 40 00 0 0 p e CHAPTER 19 PROGRAM STATEMENTS MILES ALLOCATE oi loo en WG Swipe ae eS Raa ees ger ER a A Nee C eM n E A etree ne ered laden le d xmas aae mmc e 10 DIM pu ME A A as VS 10 PTEEBASE Quels Rx rx err RA WR A eod VOSS FORZ NEXT AND STER a a aa ase POTE N A GOSUB COR CALL AND RETURN a sonaconsoranasasas 1075 10 GOTO 10 8 Lo do hO AUR RARER HR RRR A6 S Q9 X A P 10 2 TOR m o8 o O6 HoO D Co m amp 5 B amp o D Ro ROU OR OM OR 6 RD ARRAS 9 5 8 V wp EM Pr bw JD OUR e EN ALPHA BASIC USER S MANUAL Page v 10 10 IF THEN AND ELSE Lease mace taras dor 10 9 18 11 INPUT ia bac Ras aues STO 10412 INPUT LINE gt of sous we ease eae Davus due RAE TOII ILE 4 sk dheawnd Ran OR R ii as DES 10 15 LOOKUP S cin tie OX Mas ide xa II Pets POSTS LET ES kae tee xi e uc etes rn deis 10 16
21. 19 15 53 10 READ The READ statement reads a selected Logical record from a random file which has been opened for random access processing The logical record which is transferred by the system 1 0 is the one whose record number is currently in the record number variable mentioned in the OPEN statement The format of the READ statement is READ Hfile channeit variabletTC variable 2 variableN The variables in the List may be any format but they obviously should match that of the designated record format The data is read into the variables as unformatted bytes without regard to variable type The data is transferred into each variable until the variable has been completely filled Then the next variable in the List is filled and se on 1f the record is Longer than the variable List specifies all excess data in the record will not be transferred An attempt to transfer more data than is in the logical record size results in an error message The most efficient use of the random files comes when the variable or variables used are mapped by the MAP statement to the exact picture of the record format in use See Chapter 8 Memory Mapping System for information on MAP statements Also see the sample program at the end of this chapter for a demonstration of creating and reading a random file 15 3 11 WRITE The WRITE statement is used to write a selected Logical record into a random file which has been opened for random access p
22. 2 F MAP2 WORK 1 F DISPLAY BANNER MISCELLANEOUS VARIABLES input string converted to base 10 iflag set if invalid digit found iflag reset when first non blank character found FFOR NEXT index 1 IFOR NEXT index 2 scratch variable used in I conversion to output base ISTART OF PROGRAM PRINT CHRE 34 CONVRT CHRTSOSAO CONVERT BETWEEN NUMBER BASES PRINT TABC1O Enter positive numbers any base from 2 to 16 PRINT TARC1O CEnter a zero to FROM BASE to end the program ENTER IN BASE PRINT IN BASEO INPUT FROM BASE IN BASE 1f IN BASE GOTO END OF PROGRAM ENTER INPUT BASE blank Line between header i or previous conversion iset to zero in case of carriage return lenter input base tif zero carriage return end IF IN BASE gt 2 AND IN BASE lt 16 GOTO ENTER OUT BASE PRINT CHRSOO INVALID BASE SOTO ENTER IN BASE ENTER OUT BASE OUT BASES INPUT TO BASE OUT BASE LF OUT BASE GOTO ENTER IN BASE IF OUT BASE gt 2 AND OUT BASEX 16 GOTO PRINT CHRS OO INVALID BASE GOTO ENTER OUT BASE ENTER IN NUMBER TN NUMBERS PRINT BASE IN BASE NUMBER INPUT LINE UT IN NUMBER VALIDATE NUMBER LEADING BLANK 1 ERROR FLAG O SASETO NUMBER 0 FOR LOOP 1z1 TO LENCIN NUMBER bases 2 to 16 only ipe enter base ENTER OUTPUT BASE set to zero in case of carriage return lenter output base lif zero carriage return re enter input base ENT
23. 23 Four blanks precede the number 23 Note that other formatting characters discussed below e g the and symbols also define digit positions as weil as perform special formatting functions NOTE You cannot format string data with a numeric field format string If you try to do so BASIC just prints the format string indicating that it was unable to format the data For example PRINT USING Hi there GED 3 2 4 The Period Symbol Decimal Point You may include one period within a numeric field to specify where a decimal point ts to appear in the formatted number For example PRINT USING HAHH HHU 23545 502 1100 657 200 5 95 produces 2545 50 1100 86 200 00 If the number specified contains more digits to the right of the decimal point than the format string BASIC rounds the number so that it contains the right number of digits in the fractional part If the format string contains more digits to the right of the decimal point than the specified number BASIC fills in the unused digit positions with zeros as in the case of the number 200 above If the format string specifies any digits in front of the decimal point BASIC prints at least one digit in front of the decimal point for each number even if that digit is a zero 13 2 3 The Symbol Floating Dollar Sign The f symbol at the front of a numeric field format string tells BASIC to insert a dollar sign at the front of the formatted number Th
24. BASIC Page 19 16 1020 PRINT LABELS 1030 Read null key to get to front of file 1040 NAME SPACEC25 1050 TSAM H1 1 NAME 1060 Loop thru file doing sequential reads until we hit the end 1070 LOOP 1080 ISAM 1 2 NAME 1090 IF ERFC1 38 THEN GOTO PROMPT t We hit end of file 1100 IF ERF lt gt O THEN GOTO ISAM ERROR 1110 READ 1 LABEL 1120 PRINT 1130 PRINT NAME HASH 1140 PRINT ADDRESS STATE ZIP 1150 GOTO LOOP 1180 1170 END IT 1180 Be sure and close files before we exit 1190 CLOSE 1 1200 CLOSE 2 1210 END 1220 1250 ISAM ERROR ERFCX returned an SAM error 1240 PRINT FATAL ISAM ERROR i other than RECORD NOT FOUND 1250 END APPENDIX A SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS The following four sections summarize the syntax of the AMOS monitor commands that invoke and control BASIC and the ALphaBASIC commands statements and functions Commands are instructions to BASIC that affect the way it handles a program For example the SAVE command telis BASIC to save a copy of a program on the disk Commands are not part of the program itself and may only be used in interactive mode Statements are instructions to BASIC from within the program you might think of them as program verbs which tell BASIC how to operate on the program data For example the PRINT statement tells BASIC to display the specified data Although most often part of a program you can also use some s
25. BET When BASIC is ready to communicate with you you see the prompt You are now inside BASIC p 1 7 Loading Creating and Saving BASIC Programs To load a source program into memory use the LOAD command For example LOAD NEWPRGL22 47 BET INTERACTIVE AND COMPILER MODES Page 2 3 BASIC will load in the specified BAS file This program file could have been created using one of the system text editors or might have been saved from a previous interactive mode sessions Or instead of Loading in an existing program you can start creating a new source program by simply typing in the program Editing the program takes place in the conventional manner by typing each line with its Line number first BASIC keeps Lines in sequence automatically so you may enter them in any numeric order To edit a program line you must re type the entire Line As you enter program Lines BASIC scans that Line Looking for syntax errors If you enter a line incorrectly BASIC will tell you so For examples READY 10 HELP WHAT AM I DOING RET Ines ha If you want to save a source program use the SAVE command For example SAVE NEWPRG The command above saves the source program MEWPRG BAS as a disk file in the account you are logged into You can save the compiled version of that program by specifying the RUN extension SAVE NEWPRG RUN RED if you have not previously compiled the source program or if you have changed the program sin
26. END LOOP 80 ff 4 lt 0 print error message and set I to terminal value 90 NEGATIVE VALUE 100 PRINT You can t have negative pennies 1 100 110 End of loop where we increment or decrement I 120 END LOOP 130 NEXT I If I 100 we re all done 140 PRINT We re all done 10 8 GOSUB OR CALL AND RETURN The formats are SOSUB Label or Line number CALL Label or Line number RETURN PROGRAM STATEMENTS Page 10 6 Calls a subroutine which starts at the Line number or Label referenced by the GOSUB or CALL statements The subroutine exits via the RETURN statement which returns control to the statement following the GOSUB or CALL statement Executing a RETURN statement without first executing a GOSUB statement results in an error message Both GOSUB and RETURN are illegal as direct statements Note that the CALL verb is merely another way of specifying GOSUB for those programmers used to this verb from other Languages It is often the case that you want to perform the same operation at various points within your program A subroutine is a set of program statements that you may execute more than once simply by including an invocation for that subroutine called a call within your program at the point where you would Like to execute the routine For example QO This program contains a subroutine that validates numeric entries 20 i to make sure that they are greater than 0 and are less than 100 30 PRINT We are goin
27. FROM WITHIN BASIC Page 19 10 19 9 3 IF ERFC1 lt gt O THEN GOTO ISAM ERROR If no error occurred the record number of the next free record is in the relative key variable defined by the OPEN statement Now you can write your data to the data file WRITE 1 INFO Now you must add the symbolic keys for that data record to the index files using a code 3 ISAM statement Those symbolic keys will then Link to that data record Be sure to check for an ISAM error after each addition After adding all your information close the ISAM files Reading Data Records in Symbolic Key Order ISAM stores symbolic keys in the index file in ASCII collating sequence To retrieve 1 fs a records in the order in which their keys appear in an index files Open the indexed sequential file with an OPEN statement If vou also want to open one or mere secondary index files that trosscindex to the primary index file use one OPEM statement for each secondary index file Use a code 2 ISAM statement to find the next symbolic key Check to make sure that the ISAM statement didn t return an error For examples IF ERFC1 38 THEN PRINT End of the file GOTO PROMPT IF ERF TIO lt gt 0 THEN GOTO ISAM ERROR The proper relative key is in the relative key variable specified by the OPEN statement now use a READ statement to read in the data record associated with that key Remember that the READ statement is done to the primary data index file
28. Labet ELSE statement Line Label The conditional processing statement with many different optional formats Other AlphaBASIC statements are legal within the statement Aiso IF THEN ELSE statements may be nested to any depth A 5 12 INPUT INPUT C prompt string variablet variable2 variab len pt co be entered from your terminal and assigned to the specified j variable s during program run Input is prompted with a 38 you supply a text prompt Commas are the terminators tems you input A carriage return from the terminal without ts input and Leaves all the following variables aad INPUT file channel variablet lt variable 3 corr ato enters data from associated with the specified file channel For use with sequential INPUT LINE lt prompte string variablet Main purpose is to read entire Line of input into string variables Acts the same as INPUT for numeric variables Far string variables allows an f data except carriage return and linefeed to be entered verbatim from your terminal during program execution and assigned to the specified string variable No quotation marks for literal strings are entire Line of SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 9 required There is no prompt symbol by default but you can define the orompt text in the statement INPUT LINE ffile channel variable enters data from the file associated with the specified file number For use w
29. Level For example ES Operator interrupt in line 10 of NUM RUN a In the interactive mode you may restart a program from the beginning following a Control C by using the RUN command or single step Linefeed command 9 6 DELETE The DELETE command is used to delete groups of source Lines from the program text It takes the form DELETE Line 1t line 2 If the command is followed by a single Line number only that Line is deleted If the command is followed by two Line numbers separated by a comma all Lines of text which fall between and including the two Line numbers are deleted from the program NOTEs Although you usually separate the two Line numbers with a comma you can also use a dash space or other non numeric character Here is an example listing before and after a DELETE INTERACTIVE COMMAND SUMMARY E Page 9 5 LIST RET 10 FOR I 1 TO 10 20 PRINT INT TABIL S ONE 3 0 PRINT TAB 53 TWO 40 PRINT TASTE SI S SIX 50 PRINT TRB CE TENT 60 NEXT I READY DELETE 20 40 GED READY CYST Rey 10 FOR I 1 TO 10 50 T PRINT TABES TEN 60 NEXT T READY Remember you can say DELETE 20 40 or DELETE 20 40 too 9 7 LIST The LIST command takes the form LIST CLinefl1C Llinelt232 The source program if one is loaded into memory Lines are listed in numeric sequence on your terminal If no line numbers follow the LIST command BASIC Lists the entire program You may
30. Monitor Calls Manual DS5 10003 00 18 3 6 Program Headers ALL AlphaBASIC subroutines must contain a program header at the start of the subroutine Program headers are defined by using the PHDR macro M DWM 00100 01 REV BO4 CHAPTER 19 USING ISAM FROM WITHIN BASIC This chapter discusses the ISAM information management system and its use from within BASIC It is important when reading the following sections that you be familiar with opening and using random data files Tf you are not refer first to Chapter 15 AlphaBASIC File I O System The ISAM program is a tool for organizing and retrieving data The name stands for Indexed Sequential Access Method and refers to the manner in which the data is organized AlphaBASIC has the ability to process indexed sequential files by Linking to the ISAM assembly language package which must reside either in system memory or in individual user memory ISAM supports multiple index files via some elementary ISAM statements that allow the direct control of index file and data file items This chapter assumes that you are familiar with the Alpha Micro ISAM system For more detailed information on ISAM files and the ISAM assembly Language package please refer to the ISAM System User s Guide DWM 00100 06 n M DUES 19 1 FILE STRUCTURE An indexed sequential file consists of one data file and one or more index files which
31. ON GOSUB CALL seais 1014 10 17 ON de GOTO a TORT 10 18 OPEN ved wanna dana UR NOUO ROC CA CR ICE eae o oe ca SIS VOTE PRINT a ET 10620 PRINT USING a wd OST 10 21 RANDOMIZE uoce ness e bec e OST 10 22 READ RESTORE AND DATA esenouesecosessso 10 18 TIU ET SCALE queue m Fu d aO RA or e a ecc Ld 10 24 SIGNIFICANCE o 1020 jr 5 SU OP TT ME vr 10 26 STRSIZ vex Ee x ud esq ea vv dass mene dore TO wer WRITE o s dO eH 10 28 XCALL caesar ae enc E EVE S xesexa 02 CHAPTER 11 BASIC FUNCTIONS PESTE NUMERIC FUNCTIONS as d dowd VALENS ABO DO er pes Rake a deca o sow d Ed VA RS Gea eR d Fx ww Ra er RR As BRE Viele EXPO donde sukeesnes nase ra hber Tl FACTOR cyan aaa scale rk x VAR Pda FIKRI a a Time e IE cars lE A db Vid OST arras Tes PES A amus ARIAL R RO IA OA 11 3 PISO SONO So aoa a Qe CE CROCO ac ev eo INES TT gel SARC dates Wag A E Pi TTE MALENA Dear cx absense rena c AS 11 2 TRIGONOMETRIC FUNCTIONS waconcuconranvovavcee 1173 14 5 CONTROLS FUNCTIONS quid nec ate maaan Cy COR ada OTTER 114341 ERROR Wout ave Qaa XAR CR aa xiao AR 11 3 2 ERE Wak wie ex m x Tb ir ERROD Ii xh CR a cane s Tien 11 3 4 OTHER CONTROL FUNCTIONS a onasonorne 1175 Ti 4 STRING FUNCTIONS aveue anes ctew sane ra 115 TE ASCO Sadao eee cen Rr kae ten ITO 11 4 2 CHR OO OR CHROO es nro lS rr INSIROGAS BE ti Ab VE ESAS a a SE 5 LEFTCAS X or LEFTSCAG X nonoonsosa 1176 E EENCARE acid wax xa AY doa ERR Na owe DR 7 MIDCAS X Y
32. P Running programs a ara SAVES ou ge see ceca ae ise dg Saving a program a e a a a Saving a source file Saving an object file Seale oa ah ae pe ha a ge a a a Scale offset e a Scaling factor s e e sss SOOO oa a ao a ea RS ou lt 8 Semicolon separator Semicolon symbol 7 sequential disk file aa a Sequential input processing SONO uoo m cw xus SIGNIFICANCE a a a asos aa SINO a l0 oe oe Se Single step s s a so s saa Soft gt a w a soa AO a Source code a a s so e n a Source program a s so SPACES CH X X a ges ge 5x SPACE X 2 4 0 SOURCE OE tes emne ge Wo ged Square brackets s a s s sa Statement modifier Statement verb a soa SERS p STOF exl Cu a re te Uu a QR Bie pees Bs tes ae S Whe m LR UM Se STRECKE g aoa ely va e de les Bho ce SAGA 4L ay ee Ne cae Ge gd E String argument s s s a String array a s aa aaa Changed 31 October 1981 INDEX a a e s s ao na s s amp s 8 e 8 s x a e e L o g se 2 a soso s E e a 2 a t 0 e a e Page Index 8 rand 13 19 E eR me s 8 12 C 1 2 10 18 A 11 17 1 17 3 to 17 4 A 9 B 5 10 5 A 7 B 5 4 2 11 7 A 17 11 7 A 17 7 1 10 18 11 3 A 14 18 2 2 1 to 2 2 2 4 2 6 10 20 15 2 A 5 A 5 B 1 B 4 B 6 1 1 2 1 2 6 2 1 to 2 2 2 9 A 3 B 5 2 9 10 16 to 10 17 15 1 to 15 2 11 4 11 3 A 14 4 2 10 20 A
33. PRINT SGRC T D EA In the same way you can use the string function LEFTS to excerpt characters from numeric data as if that data were a string PRINT LEFT C 123 2 12 PRINT LEFTS CA456 2 A 6 1 NUMERIC FUNCTIONS These functions require arguments which can be evaluated as numbers X may be any expression but if it contains string variables or Literals they must represent numeric values For example ABSOC 11 42 returns 13 DyM OO0100 01 REV BOd SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 14 A 4 1 1 ABSOO Returns the absolute value of the argument X A 4 1 2 CHR X Returns a single character having the ASCII decimal value of X Only one character is generated for each CHR function call A 4 1 5 EXPOO Returns the constant e 2 71828 raised to the power X A 5 1 4 FACTOO Returns the factorial of X 4 4 1 5 FIXOO Returns the integer part of X fractional part truncated A 4 1 6 INTOO Returns the Largest integer less than or equal to the argument X A amp 4 1 7 LOGOO Returns the natural base e Logarithm of the argument X A 4 1 8 LOGIO Returns the decimal base 10 logarithm of the argument X A 4 1 9 RNDOO Returns a random number generated by a pseudo random number generator based on the seed The argument X controls the number to be returned If X is negative it is used as the seed to start a new sequence of numbers If X is zero or positive the next number in the sequence
34. UL cip us S PLACE STAMP 1 i HERE 3 HER i AS i H X t e E TALONG LINE alpha mero E 17881 Sky Park North i P O Bax 18347 l irvine California 82714 3 ATTN TECHNICAL PUBLICATIONS Gba dX AES A ERE mc c cc c c vc c rIPP FOLD FOLD O das Nu ok 09 BE UR IN OI cro Hp SA HELD Ge to aca e om vt um D amem
35. Upper Upper Upper Upper Upper Upper Upper Upper Upper Upper Upper upper Upper Upper Upper Upper Upper Upper upper Upper Upper Upper pper Upper Upper Opening Bracket Case Page D 4 m i x 2 Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Back Slash Closing Bracket Circumfiex Underiine Grave Lower Lower Lower Lower Lower Lower Lower Lower Lower Lowe Fr Lower Lower Lower Lower Lower Accent Case Letter Case Letter fase Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter Case Letter fase Letter Case Letter THE ASCII CHARACTER SET CHARACTER OCTAL p 160 a 161 i r 162 163 t 164 u 465 v 166 inf 16 X 170 y 171 z Fo DEL eee Changed 31 October 1981 DECIMAL MEA Lower Lower Lower Lower Lower Lower Lower Lower Lower Lower Lower Vertic Tilde belete NING Case Case Case Case Case Case Case Case Case Case Case Letter Letter Letter Letter Letter Letter Letter Letter Letter Letter Letter O
36. XO or LEFTSCAS 0 LEFT AS X Returns the leftmost X characters of the string expression Af if AS reads Now is the time the function LEFT AS 7 produces the substring Now is which includes the trailing blank after is Returns the Length in characters of the string expression AS If AS is Wherefore art thou Romeo the function LENCAS returns the number 28 because there are 28 characters in that string including spaces and punctuation 11 4 7 MID AS X Y or MIDSCAS X Y s the substring composed of the characters of the string expression A ting at the Xth character and extending for Y characters A mull string turned if X is greater than the Length of AS If AS reads The quick orown fox jumped over the sleeping dog then the function MIDCAS 1 15 DwM OOTOO 01 REV BOS BASIC FUNCTIONS Page 11 7 MIDCAS 17 15 returns the substring fox jumped over which begins at the seventeenth Letter of the string and is fifteen characters long 17 4 8 RIGHTCAR X or RIGHTS AS X Returns the rightmost X characters of the string expression AS If A is I THINK THEREFORE I AM the function RIGHTCAS 4 produces the substring Y AME As another example RIGHT 1234 2 returns 34 Remember that you can use numeric arguments for many string functions 11 4 9 SPACEOO or SPACES OO Returns a string of X spaces in length The statement 70 PRINT COLUMN A PRINT SPACEGO PRINT COLUMN E outputs the foliowing COLUMN A CO
37. a INP UT x e 4o x o9 cm s Input call i i ow wo ow ia INPUT LINE on INPUT mode a a a 2 s a INSTR OX A BS sonoro we INT conversion a a s s ENTEOKD eue tar ee der Part ea cS oe Integer constant a a a s Integer truncation a s s a Integer variable s Interactive Interactive Interactive command mode a compiler a a interpreter a INDEX z s c a e s a a gt a Li e Re of a a woo E a s s s amp a E e a s a R e aR Interactive mode s s a a s a Interactive mode direct statement Interrupting programs amp SAM rt ae ae e a re a 5 a m ISAM statement w arns 8 2 ISMBLD s 1 om on KILL 4 us ss Label s a n Label name soa CESTCADI a d fe vel seo Man s TC SOO wo ides ear gh Ros dence le mid LAOR i al e LEFTS Lefte rel s x 8 s ative 4 m Asc e yay MV HAC De de a ae Humber a 2 s m wo ws Linefeed a a a gt a a Linefeed key ae LTST gregn ec Aub E cux qud vH EL cmo e LOAD ao a ES z a a a gt n a Changed 31 October 1981 a s R a e a HOR gt es a a e e R 8 m a e cR e s a a or 6 1 1 41 12 1 to 12 2 1 71 12 2 10 9 A 8 3 5 to 3 6 B 2 B 4 B 6 19 1 18 7 19 2 19 5 A 10 19 1 19 7 19 2 19 5 A 10 18 4 5 10 10 11 4 15 1 15 5 15 10 to 15 12 4 8 11 4 10 1
38. a BASIC tutorial but is a technical manual intended for the experienced BASIC programmer We encourage you to contact your local Alpha Micro dealer for help im answering specific questions you may have about AlphaBASIC l BIBLIOGRAPHY If you are not familiar with BASIC you may be interested in taking a Look at one or more of the books listed below We have f und these books to be helpful to the beginning BASIC programmer Albrecht Ra Le et al BASIC 2nd Edition John Wiley amp Sons 1978 Brown J R Instant BASIC Dilithium Press 1977 Cassel D BASIC Made Easy A Guide to Programming Microcomputers and Minicomputers Reston Publishing Co 1980 Dwyer T and Critchtield M A Bit of BASIC Addison Wesley 1980 ALPHA BASIC USER S MANUAL Page Dwyer T and Critchfield M BASIC and the Personal Computer Addison Wesley 1978 Hirsch S C BASIC Programming Self Taught Reston Publishing Co 1980 Kemeny J G and Kurtz T E BASIC Programming 3rd Edition John Wiley amp Sons 1980 CONVENTIONS USED IN THIS MANUAL xii To make our examples concise and easy to understand we ve adopted a number of graphics conventions throughout our manuals Optional elements of a BASIC statement or command When these symbols appear in a sample statement or command they designate elements that you may omit Underlined characters indicate those characters that AMOS prints o
39. a full file specification including device and account specifications The PROGRAM STATEMENTS Page 10 2 CHAIN statement causes the current program to be cleared from memory The specified file is then located and executed from the beginning A chained BASIC program must be a fully compiled program with the extension RUN in order to be referenced by the CHAIN command It may be in user memory having previously been loaded via the monitor LOAD command or it may be in system memory The System Operator may place a file in system memory by modifying the system initialization command file If it is not already in memory it is loaded from the specified disk account into user memory and then executed If it cannot be located you are returned to AMOS command level with the error message PEO dnd progran NAME RUN Some examples of the CHAIN statement TO CHAIN PAYROL 70 CHAIN DSKT PAYROL CMDD100 71 There is no provision to start the chained file at any point other than the beginning You may pass common variables between chained BASIC programs either by writing them out to a file and then having the chained program read them back in or by using the COMMON assembly Language subroutine See COMMON BASIC Subroutine to Provide Common Variable Storage pwM DOTOU TIOD TA the BASIC Programmer s information section of the AM 100 documentation package For more Programs information on CHAIN see Chapter 16 Chaining to
40. a or LI s a R g s e a gt os point point ing point oating point oating point ating point point array as e o data a a a format a a hardware instruction number s s gt variable a e a E e EI 3 o c a a a a s x cow z s El e E s R e a s gt x Bos sa e Ss R om e a os E a GETMEM monitor call a GOSB soa canoe uie uae LES ae COTOS A A ue dar ede a a Changed 51 October 1981 INDEX e e m a m e 98 9 e a e a 2 e gt o a a s e gt e e 8 2 a oo gt s 8 e e soon e E a LEE Page Index 4 10 16 10 16 10 16 10 16 11 5 5 1 13 1 2 1 n3 13 7 18 1 2 1 18 1 ag Stop 2 9 9 7 16 1 11 2 A 14 15 1 15 4 15 10 15 8 15 10 15 12 15 8 15 9 15 6 15 11 15 11 15 12 11 4 2 9 19 1 10 3 A 7 11 2 A 1 8 4 8 5 14 1 1 1 4 2 6 1 4 1 6 3 B 10 4 A 7 B 4 to B 5 A 11 13 1 12 2 11 1 11 1 11 1 11 1 11 1 s BS 4 184 1 2 10 5 A 7 B 3 B 5 to B 6 1 2 10 8 A B B 3 B 6 ALPHA BASIC USER S MANUAL Hardware floating point Higher level Language TAQ port em ow dae a S 1 0 processing s TOOK a Sey wLhcefatoitue 4 r d HIMMEL XR LE A ENG CUBE a xxx oU ow Index f1TL 32 R3 INDEXED a a 25 2 o 0 Indexed Sequential File aa INDEXED EXCLUSIVE s a INIT monitor call a
41. abort the Listing by entering Control C which returns you to interactive command mode if one Line number follows the LIST command only the single Line following that Line number is listed If the command is followed by two Line numbers separated by a comma space or other non numeric character only the indicated Lines and the Lines between them are Listed Some examples READY READY READY CIST ED LIST 10 GET LIST 10 30 GE 10 X 1 10 Xat 10 X 20 7 POWERS OF Twos 0 POWERS OF TWO 30 FOR A 0 TO 10 l READY 30 FOR AsU TO 10 AQ SAG UI ues VOR REM SO XSX 2 NEXT READY READY NOTE Remember that the 2 symbol is an abbreviation for the PRINT keyword INTERACTIVE COMMAND SUMMARY Page 9 6 9 8 LOAD The LOAD command copies the specified BASIC program into memory from the disk so that you can edit or execute it You must give a valid AMOS file specification after the LOAD command If you do not supply a fite extension BASIC uses the default extension of BAS If you do not supply an account and device specification BASIC assumes the account and device you are logged into For example READY LOAD PAYROL RET The command above tells BASIC to search for and Load into memory the disk file PAYROL BAS that exists in the account and device you are logged into If BASIC can t find the file you want to load it displays an error message For example if you try to load in the non existing
42. and RUN need reside in memory Your source program is read in a line at a time from the disk and the statements except comments are compiled into object code When you execute a program from the monitor only the run time package and your object file need be in memory 2 2 1 Creating a Program There are two ways to create a source program for use in compiler mode you can either use AlphaBASIC in interactive mode to type in the program save that program on disk and then exit BASIC or you can use one of the system text editors EDIT or VUE The usual way to create a program that is going to be compiled with COMPIL is to use VUE to create the BAS file VUE is a Sscreen oriented text editor that allows you to see your program on the terminal screen as you type it in You can move the cursor around on the screen and change or delete text at the current cursor position INTERACTIVE AND COMPILER MODES Page 2 7 2 2 1 1 Program form The form your program may take differs somewhat DO UBL between compiler mode and interactive mode If you create and save your source program in interactive mode that program must of course contain Line numbers Otherwise BASIC would interpret each statement as a direct statement when you tried to type the program in COMPIL however does not require that a program contain Line numbers That means that if you create your program using VUE you do not need to include Line numbers in that program
43. are variablezexpression USING format string PRINT USING format string expression List PRINT expression USING format string Changed 31 October 1981 PROGRAM STATEMENTS Page 10 18 PRINT USING is supported for formatting output and is described extensively in Chapter 15 Formatting Output PRINT USING and Extended Tabs 10 21 RANDOMIZE The format is RANDOMIZE Resets the random number generator seed to begin a new random number sequence starting with the next RNDOO function call See Section 11 1 9 for information on the random number generator 10 22 READ RESTORE AND DATA The formats are READ variablet variable2 variableN RESTORE DATA datatC data2 dataN These calls allow data to be an integral part of the source program with a method for getting this data into specific variables in an orderly fashion DATA statements are followed by one or more literal values separated oy commas String Literals need not be enclosed in quotes unless the literal data contains a comma ALL data statements are placed into a dedicated area in memory no matter where they appear in the source program READ Statements are followed by one or more variables separated by commas Each time a READ statement is executed the next item of data is retrieved from the DATA statement pool and Leaded inte the variable named in the READ statement If there is no more data left in the data pool the program can only continue to read data if a REST
44. basically performs the same function as the MIDS function The beginning and ending positions are defined as character positions within the string relative to either the Left or right end A positive value represents the character position relative to the Left end of the string with character position 1 representing the first leftmost position A negative value represents the character position relative to the right end of the string with character position 1 representing the Last rightmost position For example assume the following string has the letters ABCDEF in dt The positions are defined in terms of positions 1 through 6 Left relative or positions 1 through 6 right relative SUBSTRING MODIFIERS Page Fez D E F 6 characters within main string 4 5 6 Left relative position values A em A right relative position values OS x V8 n UD 4 Q4 c5 Allowing negative values for right relative positions provides the ability to pick out digits within a numeric string without having to calculate the total size of the string first and then working from the Left Remember that the mode independence of ALphaBASIC allows you to apply string operations to numeric data The substring length argument used by the second format may also take an negative values for a more flexible format Normally the Length is a positive value which represents the number of characters counting the beginning position and incrementing the index
45. be operated upon at execution time BASIC returns the ASCII value of A or 65 11 4 2 CHR OX OR CHROO 3 Returns a si character type PRINT returned to sgle character having the ASCII decimal value of X Only one is generated for each CHR function call For instance if you CHR 90 as a direct statement the upper case letter Z is YOU a DwM DO0100 01 REV BOA BASIC FUNCTIONS Page 11 6 11 4 3 INSTR X A B Performs a search for the substring B within the string AS beginning at the Xth character position It returns a value of zero if BS is not in AS or the character position if B is found within AS Character position is measured from the start of the string with the first character position represented as one Some direct statements will illustrate ASs ELEPHANT Bhs ANT AS CROCODILE PRINT INSTR 1 A 8 INSTR 2 A COD INSTR 8 MEADOWLARK LARK 6 h 0 Substring B amp starts The specified string The specified string LARK the sixth character begins at the fourth is not found in the string from the left character position ARK which is the string starting at the 8th position NOTE Remember the 2 symbol is an abbreviation for PRINT 11 4 4 LESCAS Returns a string which is similar to the argument string CAS but with all characters translated to lower case If AS is A is for Alpha the function LCS AS yields the string a is for alpha 11 4 5 LEETIAS
46. be transferred in and out of disk files For example take a look at the MAP statements below that define a logical record Our program probably uses a file that contains a Large number of Logical records in this format each record containing information about a single check In effect MAP statements give us a way to form a template in memory into which we can read information from the file and transfer information from the program to the file This allows us to quickly and efficiently read in an entire group of information whose elements may be of different types and sizes and to access information in that group flexibly and simply For example MEMORY MAPPING SYSTEM Page 8 11 t REM Program to Process Checks 20 50 MAPI CHECK INFO i Define logical record AQ MAP2 CHECK NUMBER F 50 MAP2 THE DATE 6 60 MAP AMOUNT F ro MAP2 TAX DEDUCTABLE B 1 80 MAP PAYEE S 20 90 MAP2 CATEGORY S 20 100 MAP2 BANK ACCOUNTS C5 110 MAP3 SAVINGS S 20 120 MAPS CHECKING S 20 130 MAPI TERM S 20 Define file that contains info about checking account balance 140 MAP2 ACCOUNT BALANCE S 22 DSKT BALANC DATU200 11 Once these MAP statements have been executed we can access the group af variables as a whole by specifying CHECK INFO or we can access specific sub fields in the record for example BANK ACCOUNT or CHECKING 8 4 USING THE MAP STATEMENTS MAP statements may be used as direct statements in interactive mo
47. dace ue me Je de Ge ge i Ge Xm e Ja J gt ke J gt J Xm Xe Xe D X Ie 8 DON AAN A A LS dal a ad LCR Er TRE Ere 5 2 ERE OSA P a Li 2 Un a a a 2 meg C E z a 5 2 Ts A SSISNAGEORSS ET uw 3 E a DuM DOOT00 01 REV BOS ALPHA BASIC USER S MANUAL 2 2 2 s 6 5 g 2 s LEE a g m lana e 1 ae 3 ele m 26 28 9 1 s 2 Lo dod e qa E UE a ec i an a p a a s a y LEES a a a a mpr 3 Gr e m 8 a PRR PPP RPP DPR RPP PRP EOP RRR PRP RRP PE s e Li a e a 5 sz e a 4 OO OO o DO Um WW hn a 2 QUT Mte Soo un coge e e Ge Xe A P A Je ec D gt ae s g 2 a a APPENDIX B APPENDIX C RESERVED WORDS APPENDIX D APPENDIX E INDEX DWM 00100 01 REV BO4 ABS OO CHR OO EXP OX FACTOO FIXOO INT OO LOG OO LOG10 RND CX 10 SGNOO 11 SR OO 21 12 STROO or STRSOO ONOMETRIC FUNCTIONS FUNCTIONS DATE TIME BYTE and WORD EOF X ERF OO ERR OD MEMOO SPACEOO or SPACESOO FUNCTIONS ASCCASO INSTR X LCSCASD LEFT A LEN CAS SWORD AES we sa AME m B m Bom o s oO eH HB D 5S Bo G B P BS amaaa nara a eee mom a ow Me D 9 GO b R G HoR PR ROM m W 9 amp a 6 OR V 9 9 amp o m SH m mw om og anu na epee 5 o SG D s B 9 mw mom o e vw TEC EUR RAPERE MODICO Seema rer Rae he uo 9 aros meruuchas Som X m oM m nmana on ecanane
48. data has been entered Remember that the mode independence ef AlphaBASIC permits the entry of numeric data for string variables AlphaBASIC automatically converts such data to string format If a value has not been assigned to a variable BASIC assumes that the variable contains a zero if a numeric variable or a null if a string variable If you type a RETURN or a Control C in response to an INPUT statement request for data BASIC Leaves the variable being inputted set to a zero or null if a value has not yet been assigned or to the value previously assigned to the variable Changed 31 October 19817 PROGRAM STATEMENTS Page 10 12 For example AA INPUT A PRINT A Pe If you type a RETURN or Control C in response to a data request and the INPUT statement contains several variables BASIC skips over any variables remaining in the INPUT statement leaving their values unchanged An example might help to clarify 10 INPUT Enter day month year DAY MONTH YEAR 20 PRINT Day DAY Month MONTH Year YEAR 30 PRINT 2 GOTO 10 RUN Enter day _month year 21 4 2 Day 21 Month 4 Year 0 Enter day month year amp 975 Day 8 T Month 4 _ Year 0 PAR pe IRR bay 21 Month m Year 1980 Enter day month year C Operator interrupt in Line 10 You may also use the INPUT statement to read data from sequential files It takes the form INPUT 4file channel variable1
49. e 8 a e Tae O TUS 2 d xx i e x a s s gt 9 9 e 8 interrupt s sosa YY i Tt 9 2 Ars woo 9 59 1 n eo a AMG ooo m n n 0 n n n2 5 105 10 14 An return linefeed n a e 10 17 wo os omn oo a s neo wo Tri 15 2 16 1 A 6 ow Wow x 4 ckow ow 2 ATS CHRSOD so s a a a 11 5 tick o d wow 12m3 ALS e s a a 9 a a e 5 9 a l 15 71 15 8 19 6 Ar B 2 Language u oos 1 1 to 1 2 ymBOl GI x Gea le xxu o 3 5 Separator a a Comma symbol Ce a s s a ae Command file s s 2 a s a en COMMON waha we x Ok Gk oe es x x Common variable a a soa COMPIL A oL uo arte IT an a m COMPTIL displ o DES COMPIL PRG a aa e soa wo ee OP fi wh t6 to 10 17 oy ub ae ie 271 2 6 2 8 5 465 2 8 1 B 5 C 1 AN OS i i 4 NEM ROOMS a o E JE o9 a c o c9 sq 9 na o C ta 2 6 9 35 Ark Compiled program s a a s a s so E 8 1 a eo 9 o amp R P 3 P pm MIA wa BS ws er o6 A 2 1 to 2 2 2 6 ODE VON Se te Fae eR ed aie res a 2 9 f do WO s veh wt o ua cid e ov ee tee UNT JUL We PA We d c Ome DE E Gee CR whom ee e UR ds E P ri gt e a E Li a pS i iLing a program s s s s s s a 2 8 j tant seuil ow AAA m J 2 6 9 2 to 9 3 A 4 3 1 PA A A wo X X cd cie Continuation line a a a aa Control function a w
50. edit your program and also during its compilation and execution Checks ar made to tell you if you have run out of memory If you do you get an error message If you run out of memory while COMPIL is compiling your program compilation is aborted and vou are returned to AMOS command Level 3 8 EXPAND AND NOEXPAND MODES AlphaBASIC normally scans the source text of the program in EXPAND mode which dictates that reserved words verbs functions commands etc be terminated by a space or a character that jis illegal in variable names This allows Labels and variables to begin with reserved words In other words the variable name PRINTMASTER is not interpreted as PRINT MASTER in expanded mode In the EXPAND mode the statement FOR A 1 TO 10 cannot be written as FORA 1T010 These are the two commands which you may apply to switch back and forth between the normal EXPAND mode and the NOEXPAND mode EXPAND sets syntax scanner to expanded mode NOEXPAND sets syntax scanner to non expanded mode The default mode is EXPAND mode Note that the object code which is generated as a result of a compilation is not affected in size execution speed or anything else by the mode in which it is compiled NOEXPAND is usually used only when running programs written on other st 3 9 LOWER CASE CHARACTERS ALphaBASIC supports Lower case letters aez and upper case letters A Z in both the input source program and in the run time execution of programs The
51. enough free memory to finish compiling your program Program names You tried to SAVE or LOAD a program without providing a filename Enter the filename at this point Protection violation Your program tried to write into another account where you do not have write privileges Record size overflow Your program tried to read a file reord into a variable larger than the file record size Redimensioned array You tried to redimension an array RESUME without error A RESUME statement was encountered but no error has occurred RETURN without GOSUB A return statement was encountered but not corresponding GOSUB has been executed Runtime was x x seconds BASIC is telling vou how long it took to run your program Runtime package RUN PRG not found BASIC or COMPIL was unable to locate the run time package or did not have sufficient memory in which to load it 9RUN file is in an incompatible format The program file you tried to RUN is not a RUN file or is from a different processor type 1 Source Line overflow A Line in the source program including continuation Lines exceeds 500 characters Stack overflow BASIC s internal stack has overflowed This is often caused by nesting GOSUBs too deep or branching out of FOR NEXT loops Subroutine not found The specified subroutine could not be found DwM OOTOU D1 REV BO4 MESSAGES OUTPUT BY ALPHABASIC e Page B 6 Subscript out of range The specified subseript is outsi
52. every three digits to the Left of the decimal point For example PRINT 6507501 89 USING HERRIA HAY produces 6 507 501 89 BASIC treats any comma to the right of the decimal point as non formatting printable character Each comma defines one digit position 15 2 7 The Symbol Asterisk FILL By including a double asterisk symbol at the front of your format string you teli BASIC to replace any leading blanks that would normally be output in front of a number with asterisks This is especially useful when printing checks The double asterisk defines two digit positions For example PRINT 231 69 USING xHHHHH d HH produces AGdekk 2 31 69 NOTE You will probably use esterisk fill formatting when printing dollar amounts remember that you may include a dollar sign symbol in the format string Far examples PRINT 231 659 USING x SRHHER mu prints 3 8231 69 13 2 8 The 2 Symbol Leading Zeros To generate leading zeros include the Z symbol within your format string The format string must begin with one symbol followed by a series of 7s The total size of the formatted string is the number of Zs plus the one symbol for example PRINT 123 USING 22222 produces 000125 Changed 0 April 1981 FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 135 8 15 2 9 The Minus Symbol Trailing Minus Sign You may cause the sign of a number to be printed following the number by ending a numeric field in a
53. fonction EXPTESSILON 4 oL a a Function with argument Numeric constant e a a Numeric variable aa Changed 31 October 1981 INDEX a s a E gt a e 5 5 a R e s a e 5 c5 moms a a s s a Li s So gt gt 9 a c a os oon e es e c 10 4 11 74 12 3 2 6 Po id Poo H Li fes 12 2 11 4 2 76 2 76 E 3 d EJ i a 2 i 9 fo D OX Rn Os d i PR i maj PO 5 13 71 10 9 10 3 1174 11 4 11 4 11 5 11 5 A 15 10 18 A 6 B 5 4 1 6 1 A 15 A 15 8 11 A 5 Amh B 1 B 4 B 6 B 4 10 2 A 6 B 6 18 2 10 1 976 A 8 A 7 B 1 A 16 A 16 A 16 17 2 A 16 10 20 14 1 141 13 11 9 2 10 16 10 16 10 16 tp d0 15 VST Page index 3 ALPHA BASIC USER S MANUAL ing Literal a lg variable a s a so n bisp aa orecessor a a re ic term o s wwe A ue Extended TAB aoso a Extension BAS e a Extensi SBAS a ana ar ees DAT PRO o oe ck RUN Ca a dew Se SOBR ct o a El a 2 a s enston pension SXTtensien PACT CX EaI A et ee R statement AOS EN LE Ce ww ed a a 8 m 0 c3 9 o5 5 D EE EE eos mo 3 8 3 2 m s m a oar sac si Er age oae Sah te Le te ee ae o o 5 o9 c9 o o o om 2 1 9 e e on psp FUMES o a e a a a a icatio n eas ture 2 a 3 es
54. format string with a minus sign If the number is positive BASIC prints a blank after the number if it is negative BASIC prints a minus sign after the number For example 10 MAP1 MASK 5 26 Ve 7A STAHHBH dd 20 C zs Credit D z Debit 30 PRINT USING MASK CS 545 67 0 567 89 C 100 89 D 3456 33 produces Credit 545 67 Debit 5557 BO Credit 100 89 Debit ETT ES 15 2 10 The Symbol Exponential Format You may specify exponential format by following the numeric field in a format string with four circumflexes These symbols define the spaces taken up by the E nn exponent characters BASIC Left justifies the significant digits adjusting the exponent as necessary s with other numeric formats BASIC allows any decimal point arrangement For example 10 PRINT USING fARAR 0 100 2345 66 5000 0004 prints 099998405 Coa DEES 15 5 FORMATTING EXAMPLES AND HINTS ALL of our examples above used the PRINT statement to print formatted data Remember that you may also format a value without displaying it by using the USING modifier without the PRINT statement for example AS B USING C The statement above formats the number in B using the format string in c and leaves a string result in A NOTE This format of the USING modifier FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 15 9 is only for formatting numeric data Also note that even though we are format
55. forms 1 A variable name in which case the argument entry in the List references the selected variable within the user impure area This variable is available to the called subrout ine for both nspection and modification 2 n expression numeric or string in whieh case the expression is evaluated and the result is placed on the arithmetic stack referenced by R5 on AMOS systems or AS on AMOS L systems his result instead of a single variable is then referenced in he argument List entry It ds only available for inspection ince the stack is cleared when the subroutine exits The user routine is free to use and modify all general work registers six on the AMOS systems RO RS 15 on the AMOS L systems AO A6 and D D7 and may use the stack for work space as required When the subroutine has completed execution a return must be made to the run time system by executing the RTN subroutine return instruction 8 1 AUTOMATIC SUBROUTINE LOADING When a BASIC program calls a subroutine via an XCALL statement BASIC attempts to locate the subroutine in user or system memory If it is unable to do so it load the subroutine from the disk following the search pattern outlined in Section 5 10 Library Searching If a BASIC program fetches a subroutine fram disk BASIC loads it into memory only for the duration of its execution Once the subroutine has completed its execution it is removed from memory if it was l
56. i factor so that they are stored properly in addition a command is generated in the executable program which causes the Ling to be performed on INPUT and PRINT values when the program is j e different SCALE statements are executed in the same me very strange results may come out unless you are totally is happening with compile time and run time conversions lay with this one a bit before delving into it full steam Changed 31 October 1981 SCALED ARITHMETIC Page 14 53 lf vou are using a positive scaling factor to adjust real numbers note that using SCALE does nothing to prevent inaccuracies if the scale factor you use is not Large enough to cause AlphaBASIC to handle your data as integers For example if you want to handle numbers that have three digits to the right of the decimal point a scaling factor of 2 will Leave one digit to the right of the decimal point and scaling error can still occur So if you will be using numbers with a fractional part of two digits use 4 scaling factor of 2 if the fractional part will be three digits use a scaling factor of 33 and so on One other word of caution Floating point numbers that are stored in files by the sequential output PRINT statement are unscaled and output in ASCII with no problems Floating point numbers that are written to random access files by using the WRITE statement are not unscaled first any program that reads this file as input must either be operating in the same s
57. indicates that the terminal is being used as the file 0 if the file is not yet at end of file during input calls E if the file has reached the end of file condition Due to the method used by the AMOS operating system for processing files the end of file status is not achieved until after an INPUT statement has been executed which reaches the end of file condition Any INPUT statements which reach end of file return numeric zero or null string values forever more This means that the normal sequence for processing sequential input files would be to INPUT the data into the variables and then test the EOF X status before actually using the data in those variables since if an end of file has been reached that data will be no good End of file should only be tested for sequential input files Files open for output or for random processing always return a zero value 1 5 2 ERFOO The ERF function returns an indication of a file soft error condition Soft errors during file access operations do not give you any indication unless you query the file with the ERF function If the returned value of X is not zero an error or abnormal condition exists as a result of the preceding file operation The only soft errors currently returned concern ISAM file operations For more information see Chapter 19 Using ISAM From Within BASIC BASIC FUNCTIONS Page 11 5 11 3 3 ERROO Returns a status code which refers to program status during error
58. it while you are working with the file For information on the file locking subroutines XLOCK and FLOCK see the BASIC Programmer s Information section of the AM 100 documentation packet When your program opens an indexed file in INDEXED EXCLUSIVE mode ISAM will not allow another user to access the specified indexed file if they try to do so they see a file not found error message This means that you only have to worry about file Locking at the moment im which you are opening the indexed file You may prevent another program from accessing your indexed file at the moment that you are opening it by securing the file via the file Locking routines XLOCK or FLOCK or just by making sure that no other user is runnina a program that accesses the file Remember The advantage of an indexed file opened in INDEXED EXCLUSIVE mode is that no other user can access the file while you are using it lf vou need to have several programs access the file use the INDEXED mode in that case remember to use file locking procedures to prevent users from trying to access the file at the same time One feature of the INDEXED EXCLUSIVE mode is that it temporarily renames the TDX file to an IDY extension to prevent ISAM from Letting other programs access the file If something should go wrong such as a system crash ISAM may not be able to rename the file to its original IDX extension and you will have to do so yourself For more information on I
59. number is specified Sets a breakpoint L3 at the specified Line number if the specified number is positive or clears a breakpoint at the specified Line number if it is negative SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 4 A 2 2 BYE BYE Returns you to AMOS command level A 2 5 COMPILE COMPILE Compiles the program currently in memory 2 4 CONT CONT Program execution resumes from the Last point of cessation A 2 5 CONTROL C Press CONTROL KEY and C KEY simultaneously Terminal rings and you see the message Operator interrupt in Line nonn a Interrupts a running program and returns you to interactive mode A 2 6 DELETE DELETE Line it line 2 Deletes the program Line s between and including those specified Anal LIST LIST tline 1 l inest 22 Lists the entire program in memory or the Line s between and including those specified SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 5 A 2 8 LOAD LOAD filespec The default file extension is BAS Loads the specified program into memory from the disk A 2 9 NEW NEW Clears memory of all source code object code user symbols and variables A 2 10 RUN RUN Checks a flag to determine if the program has been compiled If not the program is compiled RUN then initiates the execution of the program in memory starting at the lowest Line number A 2 11 SAVE SAVE filespect RUN Saves the program in memary on the disk with the specif
60. of disk blocks in the file CNURT DAT or a Q if the file does not exist We must multiply BLOCKS by the blocking factor of the file to see how many Logical records can fit in the file Changed 31 October 1981 ALPHABASIC FILE 1 0 SYSTEM Page 15 10 15 3 5 ALLOCATE The ALLOCATE statement preallocates a random file on the disk which you may then open for random processing n attempt to allocate a file which already exists results in an error message A random file need only be allocated once and may then be opened for random read write operations as many times as desired The statement format is ALLOCATE filespec number of hlocks As in the OPEN statement the filespec is any string expression which evaluates to a legal file description The number of blocks is a floating point expression which represents the number of physical 512 byte disk blocks to be allocated to the file for example ALLOCATE FILES BLOCKS ALLOCATE NEW DAT 20 15 3 6 FILEBASE During normal operation BASIC refers to the first record in a random file as record number zero 3 e vou set the record number variable to zero to access the first record in the file In some applications you may want BASIC to refer to this first record by some number other than zero for instance to allaw you to use zero to flag some special condition such as a deleted record The FILEBASE command aliows you to set the number used to refer to the first record For examp
61. on 60 Hz or 50 Hz Since TIME returns the number of clock ticks since 12 00 if your System has been on for a couple of days this number can easily cause HOURS to exceed 23 Line 160 converts the value of HOURS to a number within the range of a 24 hour clock Note the use of the PRINT USING statement in Line 170 to orint single digit time values with a leading zero The next chapter contains more information on PRINT USING DWM DOTOO0 01 REV 804 CHAPTER 13 FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Mast BASIC business applications programs spend a great deal of effort in generating reports and printouts in which data must be neatly and clearly presented In other words correctly formatting output is usually a major concern of the BASIC programmer AlphaBASIC provides several important features that help you to format data This chapter discusses how to employ the USING modifier to format numeric and string data via format strings We also discuss the extended tab functions that allow you to control the output of data on the terminal screen 13 1 THE USING MODIFIER The USING modifier allows you to format numeric or string data using a format string sometimes called an editing mask specified by you Although you can use the USING modifier to store the formatted data in a string variable you may also use it in combination with the PRINT statement to send the formatted data to a terminal display or to a file for info
62. or SPACESOD Returns a string of X spaces in length DWM DOO10t SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 17 A 4 4 STRING FUNCTIONS The arguments of these functions are Literal strings or string variables For example if AS is Now is the time the LEN function which computes the number of characters in a string returns 15 in both of these cases PRINT LEN C Now is the time PRINT LEN CASO A 4 4 1 ASCCAS Returns the ASCII decimal value of the first character in string AS The function ASCC C returns the ASCII decimal value of the character C 47 A h h 2 INSTROC AS B Performs a search for the substring BS within the string A beginning at the Xth character position It returns a value of zero if BS is not in AS or the character position if B amp is found within A Character position is measured from the start of the string with the first character position represented as one A 4 65 5 LCSCAS Returns a string which is identical to the argument string AS with all characters translated to lower case Arkaka LEFTCAS X or LEFTSCAS X LEFTSCAS X Returns the leftmost X characters of the string expression AS A 4 4 5 LENCAS Returns the number of characters in the string expression AS A 45 4 6 MIDCAS X Y or MID CAS X Y Returns the substring composed of the characters of the string expression A starting at the Xth character and extending for Y characters A null string is retu
63. positive or no Leading blank if the number is negative BASIC displays string data with no Leading or trailing blanks You may place more than one expression after the PRINT keyword if you separate them with commas or semicolons If you separate the expressions by semicolons BASIC does not print extra spaces when it prints the evaluations of those expressions For example PRINT 12412 32 8 2 returns There are no blanks between the numbers above except for the normal Leading and trailing blanks displayed with numeric data if vou separate the expressions by commas BASIC prints the data in print zones BASIC divides the area in which data is to be displayed into five zones of 14 spaces each If an expression in a PRINT statement is followed by a comma BASIC prints that expression in the next available print zone For example the statements 20 PRINT 34 1024 32 100 2 20 20 ER INT RAT UBB WC opp ENT ndi display iM Sr 1024 wee 100 2 8 AA AE Oeste ee trea ee M 5 o LONE rr e a Changed 31 October 1981 PROGRAM STATEMENTS Page 10 17 When you Look at the display above remember that BASIC prints numeric data with a Leading and trailing blank if the number is positive but just a trailing blank if the number is negative Note that the strings in Line 30 were displayed on two different Lines that is because when BASIC still has an expression to print after it has printed something in the fifth z
64. source code If it has not BASIC automatically compiles the source program to ensure that the object code is up to date RUN resets all variables to zero and strings to nuli and it then executes the compiled object code Execution may be interrupted at any time by typing a Control C on your terminal READY The program currently in memory begins at the Lowest Line number 9 11 SAVE The SAVE command saves the entire source program on the disk in the specified account and device You must enter the name of the program 1 6 characters following the SAVE command The program is saved in ASCII format The default extension is BAS and the default account and device are the device and account you are logged into The program may be displayed or edited with the normal text editors outside of AlphaBASIC If a previous version of the program same name already exists on the disk in the account you are writing the file to that program is first deleted before the new program is saved BASIC does not automatically create a backup file The program name may be a full system file specification SAVE PAYROL RET SAVE DSK2 PAYROL BASTSO 11 RET READY READY erre The SAVE command may also be used to save the compiled object program on disk for Later running without recompilation To save the object program enter the program name followed by the explicit extension RUN Tf vou have changed the program since the last time it was
65. specific types of keys The relative key is already familiar to us since it is the same type of key used to access normal random files The relative key is the floating point record number variable specified in the OPEN statement for the indexed fiie It contains the number of the logical record to be accessed A relative key when used with an indexed file is used only to access a specific record in a data fiie The symbolic key is new to us and is used only with indexed files Symbolic keys are ASCII strings of variable Lengths and are used to access the index file primary or secondary Symbolic keys are specified in the ISAM statements when accessing the index file and are used to retrieve the relative key of the associated data record in the data file The concept of symbolic versus relative keys and their different uses is an important one and misuse of them causes the ISAM system ta malfunction in a number of ways Symbolic keys are used with the ISAM statement relative keys are used with the OPEN statement so that READ and WRITE statements can be successfully performed In most instances the use of the relative key is transparent to you and is merely a device automatically set up and referenced by the above calls Changed 41 October 1981 USING ISAM FROM WITHIN BASIC Page 19 3 19 3 THE ISAM STATEMENT You access Indexed files by a special statement in ALphaBASIC called the 18AM statement This statement has the general form IS
66. string to be formatted is smaller than the string field BASIC adds trailing blanks to the string to make it the same size as the field and thus Left justifies it in the field You may combine string fields and numeric fields within a single format string See the section below for information on numeric fields For examples 5 STRSIZ 25 10 MAPI MASK S 42 X 1 char TEUER WHE Ya PS charren 15 Ce Cin millions 20 PRINT USING MASK YEAR 1979 234 556 CB YEAR 1980 5678 456 C0 produces YEAR 1979 254 56 in millions YEAR 1980 5678 46 in millions NOTE Remember that the default string size is 10 characters sa you will want to explicitly define any strings over 10 characters via MAP statements or include a STRSIZ statement in your program to adjust the default string Size FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 13 4 15 2 2 The Symbol One character String Field The exclamation mark identifies a one character string field BASIC replaces the exclamation mark with a corresponding string If the string constant or string variable contains more than one character BASIC ignores any characters past the first For example 10 STRSIZ 40 20 MASK The temperature is HAA gi 30 PRINT USING MASKS 50 F 10 C 68 F 20 C 86 E 30 C 104 F AQ C prints The temperature The temperature The temperature he temperature If no string is avail
67. system is that it gives you a way to define entire groups of related information e g logical record that contains fields of information about a customer Each element of such a group does not have to be of the same size or data type You can reference a single element of the group or the group as a whole You will probably find memory mapping to be of most use when you are performing sophisticated disk 1 0 or when you are setting up a group of variables for transferring data between your program and an assembly Language subroutine See Chapter 18 Calling External Assembly Language Subroutines for more information on assembly Language subroutines Memory mapping is a powerful tool somewhat akin to COBOL data description techniques or Pascal record definitions that gives you a flexible and efficient way to transfer data in and out of programs This chapter discusses how the compiler usually allocates variables in memory and how you can use the memory mapping features via the MAP statement to override the usual storage allocation We also discuss one of the AlphaBASIC debugging features Locating variables in memory while in interactive mode 8 7 ALLOCATING VARIABLE STORAGE During compilation BASIC allocates memory storage for all defined variables in an area that is contiguous and predictable The compiled program references all variables through an indexing scheme Each variable in the working storage area has a representative i
68. the maximum size in bytes of all following strings STRSIZ must be assigned a positive integer A 5 29 WRITE WRITE amp file channel variableli variable2 variableN Writes the data currently assigned to the specified variable s into the random file associated with the specified file channel It writes into the Logical record whose record number is currently in the record variable defined by the OPEN statement for the file SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 13 A 5 30 XCALL XCALL routine fargument 1 argument2 lt argument Ni Calls an assembly Language program as a BASIC subroutine The argument may be a variable or an expression A 4 ALPHABASIC FUNCTION STATEMENTS The following is a List of the ALphaBASIC functions Functions almost always require an argument Depending on the function the argument may be a variable a string or a fixed value The argument is used either to control the function or as data upon which the function operates We have organized the ALphaBASIC functions into two categories those that accept numeric arguments and those that accept string arguments However be aware that because of the mode independence of AlphaBASIC such distinctions are often hazy For example although the square root function SGR is a numeric function you can give it a string argument as tong as the mode independence feature can convert that string to numeric data For example PRINT SaRCT4 4
69. to catch Control C on input 190 ON ERROR GOTO CATCH CTRLC 200 INPUT Enter a number between 1 and 65555 NUMBER 210 If user typed a Control C we ve already caught it so turn off our 220 l error trapping and turn regular BASIC error trapping back on in 230 case other error occurs 240 ON ERROR GOTO O 250 IF NUMBER lt D GOTO GET NUMBER 260 CURRENTSNUMBER 270 280 Now calculate answer 290 300 CALCULATE 310 TF CCURRENT 2 FIXCCURRENT 2 THEN amp SCRATCHZSCRATCHE UO U ELSE SCRATCHSSCRATCHA 1 320 TF FIXCCCURRENT 2 D GOTO DISPLAY Done 330 CURRENTSFIXCCURRENT 2 Get rid of remainder 340 GOTO CALCULATE 350 560 Display routine Reverses string so that answer is in proper order 370 A80 DISPLAY 290 FOR I 1 TO LENCSCRATCH2 400 ANSWERSANSWER SCRATCHE 111 410 NEXT I 420 PRINT The decimal number i NUMBER IS ANSWER in binary 430 SCRATCH s ANSWER t Initialize answer to nuli 460 GOTO GET NUMBER 430 ERROR 460 470 480 40 500 510 520 530 540 550 560 570 A sam TRAPPING Page 17 6 Error trapping routine Just looks for Control C Gives user chance to quit or resume CATCH CTRLC TF CERRCO lt gt CONTROL C THEN RESUME INPUT Do you wish to quit Y or N QUERY QUERY UCSCQUERY IF QUERY N THEN RESUME GO AHEAD PRINT PRINT So long PRINT END GO AHEAD User wants to resume after C PRINT PRINT Resuming 3 PRINT GOTO GET NU
70. to the Mini Report Generator PRINT 220 PRINT We will first ask vou to enter three titles max 10 char 230 PRINT acters each These will form the heading of your report 260 PRINT Then we ll ask for each Line of the report PRINT 250 PRINT Field 1 is a string maximum of 10 characters 260 PRINT Enter zero to end report En PRINT Field 2 is a number maximum of 7 characters to 280 PRINT be expressed as a dollar amount Don t enter commas 290 PRINT Field 3 is a number maximum of 10 characters 300 PRINT that can represent any non dollar data PRINT 310 RETURN 400 GET HEADER Input and write header to file af INPUT Enter Title H1 TITLES 620 INPUT Enter Title 82 TITLE2 amp 50 INPUT Enter Title 3 TITLE3S irite header to file T 4 USING HEADING TITLETST TITLE2S S TITLES PRINT 1 400 RETURN 500 WRITE REPORT Input and write data to file 510 PRINT PRINT Line amp 4 I Keep track of number of Lines 520 INPUT Enter Field 1 FIELDIS 530 IF FIELDIS D THEN RETURN 540 INPUT Enter Field 2 FIELD2 550 INPUT Enter Field 3 T FIELDS 540 PRINT 7 USING MASK FIELO1TS FIELDZ FIELDS 570 f 7 530 GOTO WRITE REPORT We can use the program to generate very different tvpes of reports For examples FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 13 11 i T EM voe PART NO NE E medie Q000002376 ui
71. to the right A negative Length causes the index to move to the Left and returns a substring whose Last character is the one marked by the beginning position argument Perhaps a few examples may clarify the use of substring modifiers Assume the main string is A and it contains the above example of ABCDEF The following substrings are returned AST 67 equals BCO ASU 2 4 equals BCDE ASUS 31 equals C ASES 31 equals CDE AS 3 23 equals DE ASU3 21 equals CDE ASD 21 equals BC AS 3 23 equals CD amp A D4 13 equals D ASLA 11 equals D For example ASES 2 tells AlphaBASIC to return the substring that begins at character position 3 from the left and ends with character position from the right that is to return all characters between C and E inclusive ASU3 21 however tells AlphaBASIC to return the substring that begins with character position 3 from the left and extends 2 character positions toward the left that is to return all characters starting with and working backward two positions to B inclusive Any position values or length values which would cause the substring to overflow out of either end of the main string are truncated at the string end A I3S 103 equals CDEF ASU 14 54 equals ABCDEF The main string to which the substring modifier is applied is actually any expression and does not need to be a defined single string variable Far examples Qs CAS BS C 023103 8 TABLETAT QAZA O 14
72. within parentheses The following are examples of legal variables A AS NUMBER STRINGS MASTER INVENTORY RECORD HEADER MOM ALWAYS LIKED YOU BEST 21234567 NEW ARRAY 3 3 4 2 NUMERIC VARIABLES The normal mode of processing numeric variables as apposed to string variables is in 11 digit accuracy which might be termed single and one half precision compared to normally accepted standards This is due te the hardware floating paint instructions which are implemented in the Alpha Micro computer Integer and binary variables are also considered numeric variables but are always converted to floating point format prior to performing mathematical operations on them ALL printing of numeric variables is done under normal BASIC format with the significance being variable under user control from 1 to 11 digits The SIGNIFICANCE statement is used to set up this value See Section 10 24 SIGNIFICANCE 4 amp STRING VARIABLES AlphaBASIC supports string variables in both single and array form The memory that is allocated for each string variable is the number of bytes representing the maximum size that the string is allowed to expand to Each string is variable in size within this maximum Limit and a null byte is stored at the end of each string to indicate its current actual size if the string is shorter than the maximum At the start of each compilation the default size to be used for strings is 10 characters maximum The STRSI
73. your car 8634 7 A tac SNO na Based on national av averages your car will pe this way After the first Year your car will be worth about 6 648 79 After the second year your car will be worth about 5 186 05 After the third Year your car will be worth about 4 096 98 After the fourth year your car Eum be worth about 3 318 56 After the Fifth year your cai car will t be worth about 2 087 59 Would vou Like to see Aor Ner ceprec Tarton scheduLe N Goodbye tatement 300 restored the data in the data pool built from Line 200 in case the user of this program had elected to continue The READ statement is also used for reading data from random access files The format is READ Hfile channel variabletC variable 2 variableN It is discussed in detail in Chapter 15 AlphaBASIC File 1 0 System 10 23 SCALE The format is SCALE value SCALE is a scaled arithmetic modifier Tt is discussed in detail in Chapter 14 Scaled Arithmetic Changed 31 October 1981 PROGRAM STATEMENTS Page 10 20 10 24 SIGNIFICANCE The format is SIGNIFICANCE value The significance statement allows you to dynamically change the default value of the numeric significance of the system for unformatted printing The significance value can be any value from 1 through 11 and represents the maximum number of digits to be printed in unformatted numbers Rounding off to the specifi
74. 0 DW m9 M X X 9 9 8 SOR HG Y S END od Wow o mos o amp os amp m 9 mom Bom mop BERS HH HS AH OY aw PILEBASE io waa ese n AES e Re EA aca gx OAD amp M z E a Xe X Me Wm J Xm 3 Ln be OO IRE y FOR TO STEP and NEXT ssasuasnosserane GOSUB or CALL and RETURN ceceveesers GUT cui nies e nde E E Ue kae pida thy THEN and ELSE 4 ux es a ROS HERO RW Lp 3 5 e Li x ad o 2 x OQ A OBS b PO os INPUT nnaneecemmennanaccneaneneusensane INPUT LINE 6b woR mo Pos 9 m wo 9 RP OS 9 WS HE EA o x PE KILL omo WOS m o amp OH OB SEH ORM HHH SEEK 8 o EMS RAR RRA a 3 3 a LEE quac EK NE ater TI NNI Uie Rx ROK ir AAA SA RE ON ERROR GOTO and RESUME ccccueuauan ON GOSUB or CALL ce once nal ONTGOTO bd Stalemate eae alae lb EUR NUS BS amide a OPEN eos a ROUX rg Wide eon a AA A Ral odie a 2 5 E y E m A T S PRINT ONG So m som m Box ow mom o X X m Wow RAS m od ETOH gom ox vow o9 0 PRINT USING svesecace naive coma die eee el aed RANDOMIZE pian occu wb ve boas ee ele wee oe 4 READ and RESTORE co ccnconcacuuvaunanucn A aie ca aime wi et ER mrw WE mE ERES Bec Bee ISNIPIOANCE det setae aae Seige eRe PIS STOP dex ear die o Sin ese NOR ARA RACE ae aw aa WIBOqE waa GARA KW AGE OR nee a e ew A wre arl acu igh ire o EUR RR Maj a 30 XCALL M Due E E ee BASIC FUNCTION STATEMENTS asccaccnaeaavan NUMERTIC FUNCTIONS ee nom
75. 0 GOTO CALCULATE OUT NUMBER PRINT CHRSC7 INVALID BASE IN BASE NUMBER lbad character GOTO ENTER IN BASE CALCULATE OUT NUMBER gt NUMBERS CONTINUE CALCULATION WORK T INT CBASE70 NUMBER OUT BASE found display message and istart over CONVERT TO OUTPUT BASE istart with null string remainder of number base is base 10 value of next i digit going from right to left OUT NUMBERZVALID DIGITUT4BASETU NUMBER WORK 1 OUT BASE TI OUT NUMBER RASETO NUMBERZWORK 4 UTR to adjust for position in valid digits string inew number is integer part i of number base IF BASET NUMBER 20 GOTO CONTINUE CALCULATION done when new PRINTOUT NUMBER t number 0 PRINT OUTPUT NUMBER PRINT BASE OUT BASE NUMBER OUT NUMBER XT END OF PROGRAM END ii ENTER IN BASE start over from the top END OF PROGRAM go through the formalities ALPHA BASIC USER S MANUAL INDEX 2 a 9 gt a C ILE 5 2 2 9 s 8 gt a s 8 por oa 9 c 9 mo 8 B amp E 8 c 8 4 Gc 8 8 9 e 2 8 o 8 5 2 a s a 4 s o e a m s u u a nh W a ABSCXJ Ao 0x ca 4 Absolute value a s a unt specification ACSC E oa E ELCOCATE a owe AlphaBASIC ALphabetic character Alphanumeric character AM 100 instruction set AMOS command level AMOS monitor level Ampersand symbol amp Apostrophe s a a
76. 0 bytes until some time in the future You write a program which copies the 100 byte file inte a new 120 byte file and then you update the main parameter file to indicate that the new record size for the vendor file is 120 bytes instead of 100 Each program now opens the file using the new 120 byte record size since it is read in from the parameter file at run time but only READS or WRITEs the first 100 bytes of each record due to the variables used by the READ and WRITE calls AA 2 E Yi en po Fl y 1 0 STATEMENTS tions in this chapter show you the general format of each of the statements and give detailed examples of their uses Although you will want to read each of those sections carefully we d Like to give a summary here of how to create and use sequential and random files Remember that ihe steps below are only suggestions and you may want to omit or add steps USING SEQUENTIAL FILES FOR OUTPUT 1 Use the LOOKUP command to see if the file already exists When you output to a sequential file you are creating a brand new file if a file of the same name and extension already exists in ALPHABASIC FILE 1 0 SYSTEM Page 15 53 the account vou are writing to BASIC automatically deletes the old file for you before it opens the new output file Therefore if you don t want BASIC to delete an existing file be sure to use the LOOKUP command before vou open a file for output to make sure that such a file does not already ex
77. 107 SUBSTRING MODIFIERS Page 7 3 The mode independence feature allows substring modifiers to be applied to numeric expressions See Chapter 5 AlphaBASTC expressions for information on mode independence A string is returned but if the destination is a numeric variable another conversion 1s made on the substring to return a numeric value 10 INPUT Enter number NUMBER INPUT Enter another NUMBER 20 SUM NUMBER NUMBER2 30 PRINT NUMBER INUMBER2 SUM Strip off rightmost digit and test it for divisibility 40 IF SUML 1 1 0 THEN PRINT Divisible by 5 and 2 50 IF SUML 1 1 5 THEN PRINT Divisible by 5 Be sure you understand the concept of mode independence before you begin to use substring modifiers or you may get answers you don t expect For example Lines 30 and 40 in the small program below return different answers even though the subscripting is performed exactiy the same in both cases This is because the mode independence feature examines the data type of the destination variable before allowing any operations to be performed When it scans Line 30 BASIC knows that a string result is expected because STRINGS is a string variable and sa reads the symbol as a string concatenation operator In Line 40 BASIC knows that a numeric result is expected because NUMERIC is a numeric variable and so reads the symbol as an addition operator 10 VALUET s 123 20 VALUEZS 456 30 STRING
78. 12 11 4 A 15 2 6 9 8 A 5 11 4 1 2 2 1 to 2 4 9 3 10 1 11 7 A 16 11 7 A 16 11 3 A 15 7 1 10 1 10 1 10 4 A 7 9 8 10 20 A 12 B 2 5 3 11 7 A 15 11 7 A 15 11 1 10 3 ALPHA BASIC USER S MANUAL String conversion s a String data a s gt String format String function String literal a as e a String MULE opah k ws String size swa Default size as a SIRSIZS X at jay dieu String variable Array mode s s a s a Single mode a a a SURSEZ 14s mun gece rto m Subfreld mo osu Subroutine s a s a a a Subroutine Linking a SUbser iok a de a wo Subscripting w 2 Substring 8 Substring modifier a Substring overflow a Substring truncation Symbolic key a s aaa SYNTAX uo a cae a Syntax error a a Syntax parser e System command e System function a a e TAB e 6 Zee ten us a as Se TR fy TANOO Ata m Gee aah A Terminal oc xc ow o THEN lt a tele da er ec cae TEMES Le Ga toad ete og oa Md oF Timesharing s s a ra TO a ae A XC a Trailing blank a a a Tree structure Trigonometric function Type tode 4 e ow xx A y HCSSCAS a 2 2 kon UCESCA As ue oss Ge ur xus uUCSOD EE MC EDS E Unformatted data Unformatted variable a Upper case character User impure area e USING a uu el te ism e Us USING MODIFIER fs VAL CA ELN E TESEI variable n g
79. 14 2 CHAPTER 15 ALPHABASIC FILE 1 0 SYSTEM 15 1 SEQUENTIAL ASCII FILES coonoonoomscsronsansos 15 2 15 2 RANDOM FILES sasnnanamnanaonmunonnmnennusonasen 1575 15 2 1 Logical Records orconeasanonnosono 1573 15 2 2 Blocking Factor and Record Size 15 3 1943 PILE I 0 STATEMENTS s sassnoaosuasesanaasanasan 1974 ILL OPEN sends sc esu e ori Eg eh xag ax 1926 15 3 2 CLOSE sarncanoconansroonacanonanscana 1978 155325 KILL vay abe ued aia 1088 15 2 44 LOOKUP ra se arie e 15 9 19 249 ALLOCATE xx sw esa aa LOU 10 15 3 6 FILEBASE essachonsonassuesenenzea 12710 15 5 7 INPUT eseesnsoooshesnessesecce 15710 155344 INPUT LINE era 19412 15 2 9 PRINT Loz66RIe 00 64 RAE REBATE S 15 11 15 3 10 READ l seenenscsanuossocneascenea 15713 15 3 11 WRITE eusesecenuucesuscesenssases 12713 13 4 SAMPLE PROGRAM o2onanonosonarnoosanenonasonssn 12714 Changed 31 October 1981 ALPHA BASIC USER S MANUAL CHAPTER 16 CHAINING TO BASIC AND SYSTEM PROGRAMS 16 1 CHAXNING TO ANOTHER ALPHABASIC PROGRAM 16 2 CHAINING TO SYSTEM FUNCTIONS s eoo CHAPTER 17 ERROR TRAPPING 17 1 ON ERROR GOTO STATEMENT due Sub Nom erase S 17 2 ERROO FUNCTION scocaononoa a ee ava euin cn A 17 2 1 Error Codes Returned by ERR 17 3 RESUME STATEMENT PTUS A 17 4 CONTROL C TRAPPING cnncccennavacance APA 17 5 SAMPLE PROGRAMS cccacacsacunnuwesunan m CHAPTER 18 CALLING EXTERNAL ASSEMBLY LANGUAGE SUBROUTINES 18 1 AUTOMATIC SUBR
80. 2 15 10 A 8 15 7 A 10 11 6 A 17 6 3 11 2 A 14 6 3 6 3 4 1 6 2 to 6 3 9 2 2 1 du 1 1 2 1 to 2 2 10 1 3 3 2 9 9 4 Go 11 4 19 1 19 3 19 2 19 13 A 3 15 8 A 9 3M mS E 11 6 95 A 1417 10 16 4 2 1176 A 17 q 11 6 Amt 10 14 A 9 es en 3 275 2 7 3 2 to 3 3 T8 A 5 26 5 2 p Ar Bea B 6 x ae T p 277 9 6 A 5 B 5 to B Page Index 5 6 ALPHA BASIC USER S MANUAL Loading a program s s s e BOG OKI XL usos uox LOGTO C M ES Logical Boolean operator Logical record s e eaa s LOOKUP ol oco xw ow ck ROOD 44 s EAN Vey tay ti Lower case character s MAP uou le e Ux dI APS MAP statement s e s e OPTOI ss RAE aa Ode Ay wu er UR wp os TYPE COME 2 2 4 ow Ma bug uro ce qe cR Bee Variable name s s s s s a MAP statement format a MAP statement syntax Mapped variable s s a Mathematical operator Mathematical variable Maximum Line length e MEMCXX Au el Room e ea R Memory allocation e a Memory mapping a s s e e Memory partition a a a o Memory use s s s MIDS FuUnGEION w dox xw o Mode independence gt Monitor level a a a MOUNT 205 SR Lue ee eh ae Multiple statement iine a Name terminator a a a a NEWS a coron Scu T cee Se de s He NEXT es IO cw de NOEXPAND a a a so n es a Normal Cummapped Null byte 9 s 5 a NUCL string s ec a K
81. 20 INPUT Enter two numbers A B 30 PRINT A B A B 40 END 50 DIVIDE BY ZERO SO If error is not divide by zero exit the program FO IF CERRO lt gt 10 THEN END 80 PRINT Division by zero undefined setting A and B to 1 90 A 1 8B8 1 Reset A and B so that division works 100 RESUME Go back to Line where problem occurred Two sample runs of the program Look Like this Enter two Dumbers 2 3 666667 Enter two numbers 5 0 AB Division by zero undefined setting A and B to 1 A B ET cen p OTERO DWM OO100 01 REV BOK ERROR TRAPPING Page 17 5 The following program shows a small uncomplicated error trap routine that handles a Control C Notice that we enable the error trapping routine CATCH CTRLC just before the user enters input Directly afterward we disable our routine and re enable the regular BASIC error trapping vie the ON ERROR GOTO 0 statement This i to catch any errors other than a Control C that might occur in the rest of the program 10 ERROR TRAPPING SAMPLE PROGRAM 20 30 Define error code for Control C and various string variables 40 50 MAPI CONTROL C E 1 60 MAPI SCRATCH S 16 TO MAPT ANSWER S 16 80 MAPI QUERY S 1 90 100 Begin Main Program 110 120 START PRINT 130 PRINT This program converts positive decimal numbers to binary 140 150 l Ask user for decimal number 180 170 GET NUMBER 180 Turn on our error trap
82. 35 Five 6 066 54 36 Six 7 067 55 37 Seven 8 070 56 38 Eight i 9 071 57 39 Nine 972 58 ZA Colon z 073 59 3B Semicolon lt O74 60 RC Less Than 075 61 30 Equal Sign gt 0 62 ZE Greater Than i4 077 63 SF 4 Question Mark a 100 646 40 Commercial At E Heelers ERES ead Changed 41 October 1981 THE ASCII CHARACTER SET oe i i Tan Ba LL OG ON P Se c UD E re x Uu Dx E CL o4 U SO 42 d L8 o pU b n Do Tea D a des Changed 31 5 3 5 Tt o X H H E a CHARACTER r 101 102 103 104 105 106 107 110 11 112 113 114 118 116 117 120 121 122 123 124 125 126 12 130 131 132 133 134 135 136 137 140 141 142 143 144 145 146 147 130 151 152 ae 154 155 156 157 1981 FON E aee msc DECIMAL 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10 102 103 104 105 106 107 108 109 110 11 i HEX i A41 4 amp 2 43 44 45 46 4 48 49 4A i 48 4c 4D 4E 50 51 i 52 53 54 55 56 57 58 Ch DN Os VA AS SS 4 CEN CS OS sa Le b Py C3 m m QOO o OS oh o 6B c 6D 6E E roms MEANING Upper
83. 4 19 9 19 10 19 13 19 14 A 1535 through A 16 B 5 through B 6 1 C 2 Title page 1i vii through ix e 9 2 10 51 52 11 5 11 6 12 1 through 12 4 13 11 13 12 16 1 16 2 17 3 17 4 18 1 thraugh 18 7 19 9 19 10 19 13 19 14 A 13 through A 16 B 3 through B 6 C 1 6C 2 SOFTWARE MANUAL AlphaBASIC USER S MANUAL LONA NA OC 1 00 071 FAE V EX aloha micro FIRST EDITION REVISIONS INCORPORATED _REVISION AQQ 1977 BOO d x October 1980 8501 October 30 1980 BO April 30 1980 803 October 31 1981 804 June 1 1982 1982 ALPHA MICROSYSTEMS THE INFORMATION CONTAINED IN THIS MANUAL IS BELIEVED TO BE ACCURATE AND RELIABLE HOWEVER NO RESPONSIBILITY FOR THE ACCURACY COMPLETENESS OR USE OF THIS INFORMATION I8 ASSUMED BY ALPHA MICRO This book reflects AMOS versions 4 64 and AMOS L versions 1 0 and later THE FOLLOWING ARE TRADEMARKS OF ALPHA MICROSYSTEMS IRVINE Ca 92714 Aipha Micro AMOS AiphaBASIC AlphaPASCAL Aiphal ISP AlphaVUE AiphaSERV AlphaACCOUNTING D315 AUPHAMIGROSYSTEMS s 17881 Sky Park North irvine CA 92714 ALPHA BASIC USER S MANUAL Page iii Tabie of Contents CHAPTER 1 INTRODUCTION TO ALPHABASIC CHAPTER 2 INTERACTIVE AND COMPILER MODES Le INTERACTIVE MODE vs cux du ars A RATER ACA RU 2 1 1 Loadina Creating and Saving BASIC Programs 4 06 dew s 56 Ros a RON I clag Direct Statements e woke Ji d E naria 3 Compilina and Running a Program s 2 1 5 1 Compiler Option
84. 9 4 CONT CONT for continue causes a suspended program to continue execution from the point at which it was suspended You may suspend a program by using a BREAK command previous to program execution or by using a STOP statement within the program You may not continue a program after it has finished The following is an example of CONT after a STOP statement suspended a program Program stop in Line 700 The program continues by next executing the first Line numbered higher than Line 700 CONT also continues a program which you have partially executed using the single step feature INTERACTIVE COMMAND SUMMARY Page 9 4 9 5 CONTROL C Pressing the Control and C keys simultaneously interrupts a running program and returns you to interactive command mode Depending on the operation being performed the Control C symbol C may be displayed on the terminal screen The Line number of the source program which was interrupted is displayed via the message Operator interrupt in Line nn The program may be restarted from the beginning by the RUN command Type a Controli C or Type a Control C C displays Operator interrupt in tine 700 Operator interrupt in Line 700 READY NOTE In the compiler mode while running a program typing a Control C causes almost the same message to appear The difference is that it always displays the Control C C and gives the filename of the program as weil It then returns you to AMOS command
85. AD has another operation within the file 1 0 system which has no relation to the DATA or RESTORE statements READ file channel variablei variable2 variableNnt This operation of the READ statement reads into the specified variable s data from the random file associated with the specified file channel it reads from the logical record whose record number is currently in the record variable defined by the OPEN statement for that file SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 12 A 35 25 SCALE SCALE value Sets the number of decimal places by which all floating point numbers are offset when they are calculated to minimize error propagation A 3 26 SIGNIFICANCE SIGNIFICANCE value where the value is between 1 and 11 Sets the maximum number of printable digits in unformatted numbers Numbers are calculated in full 11 diait accuracy then rounded off to the value of significance just prior to printing Not in effect when PRINT USING statements are being used A 5 27 STOP STOP Suspends program execution and returns you to interactive mode or AMOS monitor Level depending on where you were at program commencement You see a message identifying the Line of the program stop In the compiler mode from the AMOS monitor Level the message adds Enter CR to continues From the interactive mode of BASIC the program may be cantinued by the CONT or single step linefeed commands A 5 28 STRSIZ STRSI2 value Assigns
86. AM sfile channel code symbolic key ALL ISAM statements follow the above format using a different numeric value in code to specify the specific function to be performed by the ISAM package ALL ISAM statements directly translate into a specific type of call to the assembly Language ISAM program A symbolic key must always be specified even for those functions which do not require the use of one This simplifies syntax checking and execution coding You may use a dummy string variable if you desire Briefly the following codes are used by the TSAM statement 1 Find a record in the data file by symbolic key i e return the relative record number in the variable specified by the OPEN statement that opens the data file primary index file 2 Find the next data record by the order in which the symbolic keys appear in the index file Return the relative record number in the variable specified by the OPEN statement 5 Add a symbolic key to an index file amp Delete a symbolic key from an index file 5 Locate the next free data record in the data file returning the relative record number in the variable specified in the OPEN statement 6 Delete a record from a data file and return that record to the free list T Perform code 2 explained above and return the symbolic key An error results if an ISAM statement is executed with the value of code not equal to one of the above numbers The code may be any legal nume
87. ASIC performs automatic string and numeric conversions as necessary to ensure that the result is in the proper format Far example if two strings are multiplied together they are first automatically converted to numeric format before the multiptication takes place If the result is then to become a string it is reconverted back to string format before the assignment jis performed In other words the statement AS BS 345 4s perfectly legal and will work correctly This is a powerful feature which can save much programming effort when used correctly There is a seemingly ambiguous situation which arises from this mode independence The plus symbol is used both as an addition operator for numeric operations and as a concatenation operator for string operations The value of 34 5 is equal to 39 but the value of USAU US ds equal to the string 345 The operation of the plus symbol is unambiguous in its operation but may take a Little thought to figure out its exact usage in a given situation A few examples might help If the first operand is numeric and the second is string we convert the second to numeric form and perform addition 34 S equals 39 If the first operand is string and the second operand is numeric we convert the second to string and perform concatenation 34 5 equals 345 DWM O0100 01 REV BOG ALPHABASIC EXPRESSIONS Page 5 3 1f the first operand is string and the second operand is numeric we convert
88. ATEZRINDATE 70 PRINT Monthz MONTH Dayz DAY Year YEAR For example if the system date is set to January 10 1982 a sample run of the program above might Look Like Month 1 Day 10 Year 32 Enter Month Day Year 4 21 52 RET Month 4 Day 21 Year 52 8 3 EXAMPLES The following two statements produce identical arrays 100 MAPT A1 10 F 110 DIM A1C10 Both statements produce arrays containing ten floating point variables referenced as AICI thru 4100 Statement 100 however defines its MEMORY MAPPING SYSTEM Page 3 9 placement in memory in relation to other mapped variables Similarly the two statements at 300 and 310 produce the same two dimensional array as the statement at 320 l i l 300 MAPI BX 5 310 MAP2 81 20 F 320 DIM B1 5 20 inspect the following statements 400 MAPI CXCTOO 410 MAP CT F 420 MAP2 D1 F 430 DIM CTCTQD 440 DIM DIOH The statements at 430 and 440 produce two arrays each with ten variables The statements at 400 410 and 420 produce one array with twenty variables in it The variables are still referenced as C1CD thru CICO and D101 thru DIOM but their placement in memory is quite different The C1 variables are interlaced with the DI variables giving C1 1 DIC C1 DIC 10D DIG C1010 07010 There are also ten unformatted variables CX 1 thru CXM which each contain the respective pairs of Ci D1 variables in tandem Referencing
89. Apostrophe symbol O APPEND mode a Application program Argument e a a e Argument liist s s Arithmetic stack sa Array allocation aa Array default size Array variable Numeric variable String variable a A uoces 2 car cae Se NSO i Ghee Bay Got Changed 31 October 1981 Index Lal H P9 2 7 3 1 573 10 16 anh 5 10 16 to 10 17 A 10 8 7 8 11 11 2 A 14 11 2 2 9 11 74 A 15 er 1 i 13 4 f f d it ap EE H in AZ iJ coda A i 4 T e o mo d i 11 5 to 11 6 E OO a PO Lab gt 3 e VA PS A 4 3 1 i j Qd UA er 1195 A 17 2 11 5 d qe qe 49 00 o Q4 9 39 NJ PG O09 ss a nh 15 3 15 10 A 6 B 1 to 8 2 Page Index 1 P ks gt BASIC USER S MANUAL INDEX Page Index 2 us 5 E bed collating sequence s 3 5 ASCII format eaa a a en a 15 BONO a aos aw sos Tiek ATS Assembly Language a a a 2 td AYN ee ee r Ar15 At QU 8 7 8 11 18 4 8 3 BASIC a ss c 2 1 to 2 2 A 2 B 1 C 1 BASIC acronym sos n s sosa gt RQ Fe gu gn wma i BASIC Compiien 7 8 5 m a a s oc a A4 j e m interpreter a s MO MMC E A d sd bed de deb ded ded Ped m a e gt e h R data 9 e pasowe n 1 i OO C PG VU A eA o od EI a am
90. BASIC and System 1 is 10 3 CLOSE The format iss CLOSE ffile channel This statement closes an 1 0 file to further processing It is discussed in detail in Chapter 15 AlphaBASIC File 1 0 System 10 4 DIM The format is DIM variabieT exprit expr2 exprN3 4 C variableNCexprl1C exprd expr N22 The dimension statement defines an array which is allocated dynamically at execution time Once allocated an array cannot be redimensioned during the execution of the program There is no limit to the number of subscripts that may be used to define the individual levels within the array The statement DIM AC20 0 defines an array with 20 elements referenced as A 1 PROGRAM STATEMENTS Page 10 3 through ACID Multiple arrays may be dimensioned by a single DIM statement by separating them with commas Subscripts are evaluated at execution time and not at compile time thereby allowing variables as well as numeric constants to be used as subscripts The statement DIM A B C allocates an array whose size depends on the actual values of B and C at the time the DIM statement is executed If a reference to an array is made during program execution without a previous DIM statement to define the array BASIC assigns a default array size of 10 elements for each subscript level referred to String arrays may be allocated such as DIM A 5 The size of the array depends on the current default string size in effect as specified by the Last
91. C The control variable used may be subscripted and must be a floating point variable The delimiters indicating the number of incrementations or decrementations to be performed on that variable may be any valid expression FOR initializes the variable to the first expression NEXT increments or decrements the value of the variable each subsequent loop The variable name may be omitted in the NEXT statement in which case the variable of the previous FOR statement is the one that is incremented The control variable is incremented or decremented in units indicated by the STEP statement If no STEP modifier is used the step value is assumed to be a positive 1 Unlike some other BASICs an AlphaBASIC FOR NEXT loop will always be performed at least once even if you specify something Like FOR I G to 0 FOR and NEXT statements are illegal as direct statements except when they are incorportated into the same multi statement Line For example FOR I 1 TO 10 PRINT I NEXT I Here are examples of some of the different forms FOR NEXT loops may take 10 FOR COUNTER 1 TO 10 20 IF COUNTER 2 INTCCOUNTER 2 THEN PRINT COUNTER is even amp ELSE PRINT COUNTER is odd 3Q NEXT COUNTER 10 INPUT Enter date of first Sunday in the month DAY 20 PRINT The Sundays this month are on these dates PRINT DAY 30 FOR A DAY TO 37 STEP 7 PRINT A NEXT A FOR I 10 TO 1 STEP 1 PRINT I 2 20 20 NEXT Loops within loops are legal and are
92. COMPILING Compile time was 0 20 seconds TO PRINT This 1s a demonstration of single step This 38 a is a demonstration of single step Y LO FOR ES 1103 30 PRINT 10 I PRINT 1O I I PRINT 0 I I E ig aU Y 40 NEXT I Y 30 PRINT 10 I PRINT 10 1 1 PRINT 107141 20 OTEERE Ae 40 200 y 40 NEXT I 30 PRINT 10 I PRINT 10 1 1 PRINT 107141 z LE SUCH EUM LI Eun 270 3000 Y m NEXU End of Program CHAPTER 10 PROGRAM STATEMENTS The source program contains statements which are executed in Sequence one at a time as BASIC encounters them Each of these statements normally starts with a verb followed by optional variables or statement modifiers Many of these statements can also be used in the interactive mode as direct statements This chapter lists all the program statements and gives some examples for clarity 10 1 ALLOCATE The format is ALLOCATE filespec number of blocks This statement allocates a random access file on the disk It is discussed in detail in Chapter 15 AlphaBASIC File I O System 10 2 CHAIN The format is CHAIN filespec where the filespec may take the forms Devn BASIC program nametC RUN Cp pn fbevn kAMOS monitor command PRG Ep pnJ Devn tcommand fiie CMDIIp pn1 Cbevn tcommand file DOCUp pnid The CHAIN statement causes control to be passed to the specified BASIC program command file or monitor command program The program name may be
93. DWM O0700 01 REV 804 Page soa 17 2 17 42 17 3 17 43 17 4 vii ALPHA BASIC USER S MANUAL Page viii APPENDIX SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS amp 1 AMOS MONITOR COMMANDS AAA eee a ew Awe a AA Ae Vel BASE 224g ups d 9 x X IA aoe Avr COMPIL alae ka usekwede ees eae um A125 KONTOLE 2l ekaseraesseuccezsweme wwe ATUS A t UN mn a a a a ASS A 2 ALPHABASIC COMMANDS oonoononaconoanannanooaras Amd 3 4 BREAK arica ds E RUE SUR oc em esta AE 2G A a AER CURE award asas PT n s COMPILE aaa era uae EAE ra CASE CONT sack ara e Re Ree a ES EO AORN C we Roe e NE CONTROESC cias a ACE DELETE ales ale a o dax s eA ea Ad NNN N N N NNN g 2 a 4 R s a A WV A LA A E i E GUNT p ag A eh a das x i E Ss 4 odo QA CM OR CR Xe US Xa VA XS Vv Vm d EDAD cv sud weeds ea acera ei RU ou ators a Pre 5 a Ie 3 De 0X Je ip ae Je p E a e D Q0 gt 1 NEW eaa ea RA ain ACA AUR Ante RR OR RR AL a mie EJ ze j IU RUN iis de sw dace RRA E E ae Aoa Aela tI SANE and ak eva WOO WR Rabe a ane AT A 2 12 SINGLE STEP CLINEFEED nncvenncavavee S A 3 ALPHABASIC STATEMENTS c 05 a ex Fx Axa wr Kou NT ALLOCATE lice nein pare ais e aa M CHAIN cuya wee svaons qe seite A i A AT D d eS God eH m e e E ROW XS ROG 4 amp oS B eT H He Toe S won o a 5 3 CLOSE uase chr asume nana sax 5 S de 3e H i DIM Wo A S Bo d Bo REA
94. E READ 3 CUSTOMER INFO PRINT PRINT CUSTOMER Zz s ID NUM SPACE SD CUSTOMER NAME NAME NEXT REC NUM Changed 31 October 1981 ALPHABASIC FILE 1 0 SYSTEM Page 15 16 425 430 435 440 445 455 460 465 470 475 480 485 490 495 500 505 XR NSE AST v XJ OVE X Pe L4 Ga DO DO e CO UC Dan oO LEV 431 143 57 E i ow wi C i wi d wn CO uos wn 910 315 920 925 930 235 940 i H BE EI i Find out what info we should display T NUM QUERY s PRINT Set initial choice to null PRINT Enter the ID number of the customer whose info you want to PRINT see Enter just a carriage return to end programs enter ALL INPUT to see info for all customers QUERY IF QUERYz U GOTO READ EXIT User wants to quit QUERY USCCQUERY IF QUERY TALL THEN GOTO DISPLAY ALL i Check to see that customer number is valid Convert string to numeric so that we do numeric not string compar son NOUERY VALCQUERY IF CNQUERY lt 1 OR NQUERY gt IN USE THEN amp PRINT PRINT Invalid number GOTO GET NUM Read desired record set REC NUM to customer number REC NUM NG ERY READ 3 CUSTOMER INFO GOSUB DISPLAY INFO display record GOTO GET NUM See if user wants to see another User wants to display all customer records DISPLAY ALL t FOR REC NUM 1 TO IN USE READ 3 CUSTOMER INFO Get next record 2 DISPLAY INFO Display information i
95. ER IN NUMBER ibases 2 to 16 only re enter output base ENTER INPUT NUMBER tset to null string in case i of carriage return prompt for input number enter input number S CHECK CONVERT INPUT NUMBER linitialize flags initialize base 10 number icheck one character at a time IF IN NUMBERILOOP 1 11 GOTO NON BLANK skip if none blank IF LEADING BLANK 0 LOOP T LEN CIN NUMBER tif not Leading GOTO END LOOP 1 l blank end conversion of SAMPLE PROGRAM NUMERIC CONVERSION FOR BASES 2 16 Page E 3 2455 2460 2465 2470 2475 2480 2485 2490 2495 2500 2505 2510 2515 800 2805 2900 GE 2905 3000 2010 NON BLANK LEADING SLANK 0 ERROR FLAG 1 FOR LOOP 2z1 TO IN BASE input number t otherwise skip it PROCESS NON BLANK CHARACTERS treset leading blank flag f non biank found lassume invalid character until valid one found CHECK FOR VALID DIGIT using i valid character List IF IN NUMBERCLOOP 1 11 lt gt VALID DIGITELOOP 27 1 GOTO END LOOP 2 linvalid character i try next BASETO NUMBERZBASET NUMBER IN BASE LOOP 2 1 convert and shift ERROR FLAG 0 LOOP 2SIN BASE END LOOP Z NEXT LOOP Z IF ERROR FLAG lt gt 0 LOOP 1 LENCIN NUMBER END LOOP 1 NEXT LOOP 1 ireset valid found ino need to check i more digits inext valid or end 13f bad character f found check 3 no further inext character in i input string or end LF ERROR FLAG
96. FILES FOR INPUT QUTPUT 1 Use the LOOKUP command to see if the file already exists if it does you can skip down to step 3 2 If the file doesn t exist you must create it First decide what size the logical records will be Cin decimal bytes Then compute the blocking factor as discussed in Section 15 2 2 Blocking Factor and Record Size Use the ALLOCATE command to create the file with the number of disk blocks needed 5 Use the OPEN statement to open the file for RANDOM processing Specify the size of the logical records in the file and the record number variable that will hold the number of the Logical record you are currently accessing 4 Use READ and WRITE statements specifying the ile channel number associated with the file by the OPEN statement to read and write data in the file Remember to change the record number variable to the correct record number before performing each read or write eration so that you access the logical record you want Make ire that the record number variable contains a valid record number before performing the file I O Si 5 When you are finished reading and writing the file use the CLOSE statement to close the file USING RANDOM FILES IN RANDOM FORCED MODE When a random file is open in this mode a READ operation forces a disk access even if the requested block is already in memory Likewise if a WRITE is performed the block is reread modified and forced out to disk even
97. In addition you may indent your program Lines in any fashion you desire By omitting Line numbers including Line Labels and using indentation judiciously you cam give your source program a much more structured look than is usually possible with BASIC programs CA Label is a special name defined by you that identifies a location within a program COMPIL also allows the use of continuation Lines within a source program Specify a continuation Line by making an ampersand 8 the Last character on that iine For example IF Answer RIGHT NUMBER THEN amp PRINT Very Good amp ELSE amp PRINT Try again if you use LOAD in interactive mode to load a program that uses continuation Lines BASIC concatenates contiguous continuation Lines into one Line The maximum iine E including any continuation Lines tabs or blanks is 500 characters Then if you save that program back out to the disk any continuation Lines are gone Below is a small example of a valid program that uses continuation tines indentation and Labels and has no Line numbers Program to print name in reverse STRSIZ 20 Dd zx doni lt A T START INPUT LINE En TF LENCNAMES GOTO START ter your name NAMES 0 THEN amp LOOP COUNTER LENCNAMES FOR I 1 TO COUNTER PRINT NAMESECOUNTER 17 COUNTER x COUNTER 1 NEXT INPUT Do you want instant replay Y or N QUERYS IF QUERYS Y OR QUERYS y THEN amp GOTO LOOP R amp
98. L t Add key to primary index file ISAM H1 3 NAME IF ERF 1 lt gt 0 THEN GOTO ISAM ERROR Add key to secondary index file ISAM 2 3 HASH IF ERF 2 lt gt 0 THEN GOTO ISAM ERROR GOTO PROMPT DELETE RECORD INPUT ENTER NAME s NAME NAME NAME SPACEC2S LENCNAMEDO verify that the key exists ISAM 1 1 NAME IF ERF I 33 THEN PRINT RECORD NOT FOUND GOTO PROMPT IF ERF 1 lt gt O THEN GOTO ISAM ERROR READ 1 LABEL Delete the key from the primary index ISAM H1 4 NAME IF EREC lt gt O THEN GOTO ISAM ERROR Delete the key from the secondary index ISAM 2 4 HASH LF ERF 2 lt gt 0 THEN GOTO ISAM ERROR Delete the data record in data fiie ISAM 1 6 NAME IF ERF 1 lt gt Q THEN GOTO ISAM ERROR GOTO PROMPT INQUIRE RECORD INPUT BY NAME 1 OR HASH 2 FUNCTION LF FUNCTION 2 THEN GOTO BY HASH INPUT NAME 5 NAME NAME NAME SPACE C25 lt LEN CNAME Locate the record ISAM 1 1 NAME LE ERF 1 33 THEN PRINT RECORD NOT FOUND GOTO PROMPT LF ERF 1 lt gt 0 THEN GOTO ISAM ERROR Read the record READ RECORD READ 1 LABEL PRINT NAME HASH PRINT ADDRESS STATE ZIP GOTO PROMPT Locate record by hash cade 940 BY HASH INPUT HASH s HASH HASH HASH SPACE 10 LENCHASH ISAM 42 1 HASH TF ERF 2 33 THEN PRINT RECORD NOT FOUND GOTO PROMPT IF ERF 2 lt gt 0 THEN GOTO ISAM ERROR GOTO READ RECORD USING ISAM FROM WITHIN
99. LUMN 8 where the 10 spaces between the first and second strings are the result of the SPACECI function SPACE is especially handy for padding strings to a fixed Length For example 5 STRSIZ 25 10 Name must be 25 spaces 20 INPUT Name NAMES 20 IF LENCNAMES lt 25 THEN NAMES NAMES SPACE C25 LEN NAMES 11 4 10 STROX or STRSOO Returns a string which is the character representation of the numeric expression X No leading space is returned for positive numbers 11 4 11 UCSCASO Returns a string which is similar to the argument string CAS except that all characters are translated to upper case If AS is M is for Micro the function UCSCAS yields the string M IS FOR MICRO Changed 0 Aprili 19812 SYSTEM FUNCTIONS AlphaBASIC supports a unique group of operators called system functions which provide the ability to get to the I O ports physical memory sometimes referred to in other BASICs as PEEK and POKE and various system parameters The syntax of a system function parallels that of a standard function with the reserved word representing the desired function followed by optional arguments enclosed within parentheses The major difference is that the reserved word of a system function may appear on the Left side of an assignment statement where it is used as an output or write condition to the system function System functions used within expressions on the right side of an assignment statement perform an input
100. Line editor built into the interactive system accepts and stores source input text in iower case or upper case characters Lower case letters when used within variable names and Labels are unique and separate from the corresponding upper case letters In other words the variable a is separate from the variable A and the variable Tom is separate from the variables TOM and tom Lower case letters may be used as the first character of a variable name or program Label just as upper case letters may be Reserved words are treated somewhat differently from the above system When a reserved word is expected the syntax parser temporarily translates all Lower case letters to upper case and then checks for a reserved word match 1f the word is not a reserved word the translation is not retained and the Lower case letters are used for variable name matches The following statements are all considered to be identical GENERAL INFORMATION Page 3 3 FOR A 1 TO 100 STEP 2 For A 1 To 100 Step 2 For A 1 to 100 step 2 for A 1 to 100 step 2 The entire string processing system supports Lower case characters That is lower case letters used within string Literals inside quotes are retained and printed as lower case Lower case letters which are entered into string variables by means of the INPUT statement are aiso retained as lower case letters Note that all lower case characters are considered greater than any upper case character
101. Link to the data file The data file is structured in the same way as a normal random access file except that ISAM Links all records which are not currently active to each other in a chain called the free data record list ALL data records reside in the data file and the data records may be any size up to the maximum of 512 bytes As in the normal random file data records are not split across physical 512 byte block boundaries in the file Index files are arranged in a complex balanced tree structure and contain one symbolic key for each active data record plus a link to that data record in the data file This Link is the relative record number and is used in the same manner as its counterpart in a normal random access file The index file also contains an array of internal Links which comprise the sequential access tree structure Two references used in this manual may be confusing if they are not understood When we talk about an indexed file we are speaking of the Changed 31 October 1981 USING ISAM FROM WITHIN BASIC Page 19 2 entire file structure in general including the data file and one or more index files We talk about an index file when specifically speaking of the portion of the structure which contains only the symbolic keys and the tree links ISAM stores symbolic keys in an index file in ASCII collating sequence Index files may be primary or secondary IMPORTANT NOTE Both INDEXED and INDEXED EXCLUSIVE modes require th
102. MBER ple run of the program above Looks Like this RUN CNVRT RED ee ta UNE ELS Tard 655 535 24 8E The decimal number 24 is 11000 in binary Enter a number between 1 and 65535 C you typed a Control C do you wish to quit Y or M VE So long CHAPTER 18 CALLING EXTERNAL ASSEMBLY LANGUAGE SUBROUTINES AlphaBASIC supports the use of external assembly language subroutine programs callable from your BASIC programs There are several good reasons why you might want to use an assembly Language program to carry out a function rather than using another BASIC program Assembly language programs are generally much smaller and faster than equivalent BASIC programs when speed and size are important factors you may want to code your programs into assembly Language Yet another reason for using assembly language programs is simply that some tasks are too awkward or even impossible to do from within a higher level language Assembly Language programs are uniquely suitable for applications that require that you work more closely with the hardware or operating system than is convenient or possible in BASIC This chapter explains how to write your own assembly Language subroutines for BASIC and on calling such routines from within a BASIC program Although you may want to write your own assembly Language subroutines note that we do provide a set of existing assembly Language subroutines in the BASIC Li
103. NDEXED EXCLUSIVE mode see Important Notice for ISAM Users in the User s Information section of the AM TOO documentation 19 8 ERROR PROCESSING Every ISAM statement may potentially return some kind of an error These errors fall into two categories hard or soft errors Hard errors are those errors returned to ISAM by the monitor such errors indicate invalid disk operations e g file not found i Soft errors occur within the ISAM processor and indicate an error or condition peculiar only to ISAM files USING TSAM FROM WITHIN BASIC Page 19 8 Hard errors cause AlphaBASIC to print an error message and abort to the monitor or if error trapping is enabled pass control to your own error trapping routine See Chapter 17 Error Trapping especially Section 17 1 ON ERROR GOTO Statement for information on writing your own error trapping routines 19 8 1 Soft Errors Soft errors never result in an error message or error trap and BASIC does not stop program execution when a soft error occurs It is therefore up to your program to test for such errors You must test for a soft error after every ISAM statement Otherwise you have no way of knowing whether or not the statement was successfully executed Use the ERF file error function ERF is used in much the same way as the EOF function You must specify the file number used in the ISAM statement whose success you want to test if the ERF function returns a zero the preceding ISAM statem
104. ORE statement is executed which reinitializes the reading of the data pool from the beginning again Otherwise an error message results and the program is aborted Here are some forms that READ and DATA may take DATA 1 2 3 4 5 DATA 4 3 0 555 0NE STRING A 4 READ A B C READ AS READ 2 3 B C4 The following is a program example using READ RESTORE and DATA 10 Sample program to illustrate READ DATA and RESTORE 20 PRINT TABCIO This program gives you an estimate of your automobile s 30 PRINT TABC1O value due to depreciation over a period of five years 40 PRINT INPUT LINE How much did you pay for your car WORTH 50 PRINT Based on national averages your car will depreciate this way Changed 31 October 1981 PROGRAM STATEMENTS Page 10 19 60 PRINT FOR T 1 TO 5 70O PRINT After the Us s READ YEARS PRINT YEARS year your car gt 80 PRINT will be worth about s READ PERCENT 90 WORTH WORTH PERCENT 100 PRINT WORTH USING CSSUUUGR du 110 NEXT I PRINT 200 DATA first 77 second 78 third 79 fourth 81 f ifth 24 300 RESTORE 310 INPUT LINE Would you Like to see another depreciation Schedule LS 320 IF L 0 1 1 z Y 0R L 1 1 2 y THEN GOTO 40 ELSE PRINT Goodbye A program run of the above exampte might read This program gives you an estimate of of your automobile 5 value due to depreciation Over a a period of five Xears How much did you pay for
105. OUTINE LOADING 2nononesossosno 18 2 SPECIFIC INFORMATION FOR AMOS SYSTEMS 18 2 1 REGISTER PARAMETERS mem 18 2 2 ARGUMENT LIST FORMAT nenceesvcsrener 18 2 3 FREE MEMORY USAGE oonoonansnsncos sapie 18 3 SPECIFIC INFORMATION FOR AMOS L SYSTEMS 18 3 1 REGISTER PARAMETERS waanneascaansaases 18 3 2 ARGUMENT LIST FORMAT esce do ces 18 3 3 CONVERTING ARGUMENTS TO BINARY FORMAT 18 3 4 FREE MEMORY USAGE aesocececiackvessees 18 3 5 LOCATING OPEN FILES ad 18 3 6 PROGRAM HEADERS osoonosonsanesssonsaso CHAPTER 39 USING ISAM FROM WITHIN BASIC 19 1 FILE STRUCTURE ee es LR Re EUR eee era 19 2 SYMBOLIC AND RELATIVE KEYS cooncononosnssacone 19 3 THE ISAM STATEMENT cnncncncaanun We AUR E daa 19 5 1 The ISAM Statement Codes naassaaaa RS 19 4 OPENING AN INDEXED FILE ssssnsoassnasoassopua 19 5 READ AND WRITE STATEMENTS onnononconanonoonan 19 6 CLOSING AN INDEXED FILE cnucenesccenncncne 19 7 INDEXED EXCLUSIVE MODE cannencecues CA 19 8 ERROR PROCESSING Aaa v adda RUE M RR E qe RUN RR E se TaBe t e E sva cx ui ER Re i 19 9 USING INDEXED SEQUENTIAL FILES ese ne 19 9 1 Creating an Indexed File m 19 9 2 Adding Pata to an Indexed File 19 9 3 Reading Data Records in Symbolic Key Order Tv 19 9 4 Reading Data Records Randomly by Symbolic Key ononooononoa 19 9 5 Updating Data Records oonoanonoon 19 9 6 Deleting a Data Record sss no 19 10 SAMPLE ISAM PROGRAM sns DOR
106. PEN 1 DATFIL INPUT OPEN 15 PAYROL TMP OUTPUT OPEN A C OUTPUT OPEN 3 DSKT 0FILE ASCE200 201 OUTPUT OPEN 1 VENDOR DAT RANDOM 100 RECNUM OPEN HT X MIDS AS 2 33 OUTPUT OPEN 425 MASTER INDEXED 8D RELKEY The OPEN statement is one of the only statements which reference the file by its actual ASCII filespec in the standard operating system format Most references in the program are made to the file channel number which is assigned in the OPEN statement file channel The CLOSE statement ends the transfer of data to or from a file Once a file has been closed no further references are allowed to that file until another OPEN statement for that file is executed Any files that are still open when the program exits are closed automatically The format of the CLOSE statement is CLOSE file channel ifies the file channel number associated with the where Hfile channel spec ose For example if you have previously opened a file file vou want to cl VENDOR DAT OPEN 3 VENDOR DATL 200 13 INPUT to close that file use the statement CLOSE 3 19 3 3 KILL The KILL statement erases one file from the disk it does not need a file channel number and no OPEN or CLOSE need he performed to KILL a file The format for the KILL statement is KILL filespec For example KILL NEWDAT DAT Changed 41 October 1987 ALPHABASIC FILE I O SYSTEM Page 15 9 As in the OPEN statement the filespec is an
107. S VALUETS VALUE2 5 1 31 40 NUMERIC VALUET1 VALUE23 2 1 31 50 PRINT NUMERIC z NUMERIC STRING STRINGS The program above prints NUMERIC 579 _ STRINGS 123 You may apply substring modifiers to subscripted variables or expressions containing subscripted variables Be careful not to confuse substring modifiers with subscripted variables For example A C02 3 designates a location in array A ASD 2 31 designates a substring of string AS A 2 33 04 53 designates a substring of the string in location A 2 These are valid uses of the substring modifiers as as ASS 002057 CAS 1 88 03 5 35 og Substring modifiers return a string value These may be used as part of string expressions For example Q AS BSL2757 CASE2 2 CR lA AR SUBSTRING MODIFIERS Page 7 4 You may apply substring modifiers to the left side of an assignment in order to alter a substring within a string variable Only that portion of the string defined by the substring modifier is changed The other characters in the string are not altered This may not be applied to numeric variables for example AD 35 2 23 is not valid Tf AS contains ABCDEF ASf2 4 ARS causes AS to contain the string AQRSEF CHAPTER 8 MEMORY MAPPING SYSTEM One of the unique features of AlphaBASIC is that it allows you to specify the pattern in which variables are allocated in memory The advantage to such a memory mapping
108. STRSIZ command since each element in the array must be this number of bytes For instance if the current STRSIZ is 10 the statement DIM AS 5 would allocate 5 elements 10 bytes per element or 50 bytes of memory for the array Below are some examples of valid DIM statements DIM AGM DIM C 8 8 C 10 4 DIM TEST A B 4 DIM ACBCAD 10 5 END The format is END This statement causes the program to terminate execution The END statement does not terminate compilation of the program nor is it required at the end of the program If other program statements follow the end of the program e g subroutines terminating the program with END prevents your program from incorrectly entering those statements and trying to execute them 10 6 FILEBASE The format is FILEBASE n This statement sets the number used to refer to the first record of a random file It is discussed in detail in Chapter 15 AlphaBASIC File I O System PROGRAM STATEMENTS Page 10 4 10 7 FOR NEXT AND STEP The format is FOR control variable expression TO expressiong2 STEP Jexpression3 7 Statements NEXT control variable These statements initialize and control program loops A Loop is a structure in which the same statement or statements can be performed several times Whether or not a loop is executed depends upon the value of a special control variable AlphaBASIC FOR NEXT loops follow the same format and restrictions as do other forms of BASI
109. T 8050008578 DUDQUUQS6s5 EN comme Shaft He ART nn NAN AAAA _PAYROLLH PAPI CIA Er EON 13 4 EXPANDED TAB functio has been expanded beyond the normal usage to tude terminal screen handling such as cursor controi and other special inctions To be used only in a PRINT statement the TAB function operates in the traditional manner when supplied with only a single numeric argument such as TAB XO In this case the function causes the carriage to be positioned over to the X41 column on the current Line For instance TADOS aub cause 3 spaces te be printed and the following characters would begin in column six When supplied with two arguments such as TABIR CO sucus the TAB function performs special CRT functions the value f COO nanat pe of R is positive the R C arguments are treated as Crow column for positioning the cursor on the terminal een The rs are then printed beginni in that po ma As in ions the Rand C arguments may be expressions C ferminais are jin with row 1 top of screen and column 1 Left end of each you use TAB for cursor positioning remember to follow the TAB m ith a semicolon Cesga PRINT TAB 23 5 otherwise BASIC will output a carriage return linefeed after it positions the cursor thus destroying your careful positioning If the value of R js Il the function is interpreted as a e terminal command and the appropriate com
110. TLONS 12 130 MAPS BALANCE F 140 MAPS CREDIT F 150 MAPS YTD F Here are the results of using the 8 command in interactive mode ta determine the Locations of several of the variables above MEMORY MAPPING SYSTEM Page 8 14 READY SCUSTOMER ID RET MAP1 Unformatted size 279 located at 0 278 STRANSACTIONS SET MAP Unformatted Array 12 size 18 base Located at 63 acrTY RET MAPS String size 10 Located at 45 54 IHOME RET MAPS Binary size 5 located at 57 59 aCREDIT SET MAPS Floating point Array 12 size 6 base located at 69 We can also use the command to locate unmapped variables For example READY DIM A 2 2 4 GED aA ET Dynamic Floating point Array 2 3 4 size 6 base Located at 1032 Az15 GED SA RET Fixed RUN ng point size 6 Located at 72 77 Dynamic FI Coating point Array 2 3 Nn size ALIIS base located at 1052 Note that we allocated two different variables a fixed floating point variable A and a dynamic floating point Array variable A 2 3 4 CHAPTER 9 INTERACTIVE COMMAND SUMMARY Whenever AlphaBASIC interactive mode is not either compiling or executing a program it is in interactive command mode that means is waiting for a command from your terminal to initiate some action The action taken depends on the type of input you enter which falls into one of the following main categories in it PS State
111. X variable2 variableN NOTE INPUT skips over nulls in data and just waits for the next character This is important to know if you plan to input from devices For more information on this use of the statement see Chapter 15 Al phaBASIC File 1 0 System 10 12 INPUT LINE The format is INPUT LINE prompt string variablel Changed 37 October 1981 PROGRAM STATEMENTS Page 10 13 Although you may specify a numeric variabie the real purpose of INPUT LINE is to allow you to enter string data from your terminal that includes commas quotation marks blanks and other special characters You will usually want to use INPUT see the section above for inputting numeric data or multiple items of string data INPUT LINE Loads into the specified string variable an entire Line up to but not including the carriage return and Linefeed that end the line bo nat specify more than one string variable in the INPUT LINE statement BASIC never prints a question mark prompt for INPUT LINE as it does far INPUT but you may include your own prompt string which BASIC will display as a request for data Such a prompt string must be a string Literal enclosed in quotation marks Unlike INPUT if you type a RETURN in response to a data request INPUT LINE sets the variable to zero if numeric variable or null Cif string variable Remember in Like case INPUT Leaves the value of the variable unchanged When you use INPUT LINE remem
112. Z statement may be used within the program to alter the value to be used for all new string variables which follow String variables may be concatenated by use of the plus sign between two strings String variables may be assigned values by enclosing string Literals in quotes String functions such as LEFT RIGHTS MIDS etc are implemented to assist in manipulating portions of strings or substrings In addition a powerful substring modifying system may be used to operate on portions of strings within expressions Chapter 7 Substring Modifiers is devoted to this unique option of ALphaBASIC ALPHABASIC VARIABLES Page 4 3 Unformatted mapped variables are also considered string variables when they are used in expressions or printed See Chapter 8 Memory Mano ing System for information on mapped unformatted variables NOTE Of course an unformatted variable may contain non string data If this the case then using the PRINT statement to display either that variable or an expression containing it will result in a very odd display since the data is not in a printable form 4 5 ARRAY VARIABLES You may designate arrays by numeric or string variables BASIC dynamically allocates unmapped array variables during execution when it encounters a DIM statement in the program During execution if no DIM statement has been encountered when the first reference to the array is made a default array size of 10 elements for each subscript lev
113. a LEES a E LI c s 2 e 2 e a s 9 5 a LI w LEE a n e a Ed e gt a s a p 9 e s a a L e 5 a E a a a a s a e gt 6 a LI oy a s a a es R 5 E s LI a s Page Index 7 1e2 2415 2 4 10 14 A 10 10 14 A 10 10 15 A 10 17 1 A 9 8 5 15 1 15 4 15 6 15 12 to 15 13 19 2 19 5 A 10 B 1 to B 2 5 3 E 18 7 A 10 18 1 1574 5 1 12 1 63 15 3 12 1 12 1 15 1 4 2 590 10916 1591 135911 1493 15 1 18 11 to 15 12 A 10 10 17 10 20 12 4 13 1 15 12 A 10 B 3 10 16 m i PI oe yi nn nat BO POPG L4 LA DO o4 EM dM i r 9 2 9 8 10 2 10 5 10 20 d i 31 E E t 10 2 C i S i 15 7 A 10 15 1 15 3 19 1 15 4 15 6 to 15 7 10 18 10 18 11 3 10 18 10 18 A 11 8 5 1 1 10 18 to 10 19 15 1 15 4 15 7 15 13 19 2 19 6 A 11 B 3 B 5 2 2 13 7 A 10 ALPHA BASIC USER S MANUAL Recordesize noa Relative key oa aa aaa REM s cu a esr ie Se Ec ae Reserved word s a Resident monitor a RESTORE er wl oov uu RESUME 4 Lx oux ow RETURN ow woo Se Y ee a is REC LE aR VD WC UR URDU GHTSCAS X nw a ee Me uoo os n Righterelative position RNDCXM oe wx ouk xo RTN instruction s RUN Ao on at uu ue e Dur E ee eae RUNSME uoo ce Woe cas at ty Run time package a asoa RUN PRG a a no noanoa
114. a variable returns a zero the string is null 6 5 BINARY FORMAT Binary variables are specified via MAP statements and are similar to integer variables in other implementations of BASIC A binary variable may be from 7 to 5 bytes in Length and may be signed when all 5 bytes are specified When Less than 5 bytes are specified in a MAP statement as the Length the binary value may be Loaded as a negative number but it is always returned as a positive number of full magnitude The upper bit preloaded as the sign takes on its specific value in the equivalent positive binary variable For instance a I byte binary may be loaded with positive numbers from O through 255 decimal or negative numbers from 1 through 128 but the negative numbers are returned as the positive values of 255 through 128 respectively Only S byte binary variables return the original sign and value when loaded with a negative number Binary variables may be used in expressions but they are slower than floating point variables because they are always converted first to floating point format before any mathematical operations are performed on them Binary variables are useful in integer and Logical Boolean operations ar for storing values in small amounts of memory Cfloatina point numbers always take 6 bytes of memory regardless of their values ALL logical operations performed within expressions AND OR XOR NOT etc cause the values to be converted first to signe
115. able to be substituted for the symbol BASIC simply prints the symbol instead For example if we took our sample program bove removed the first F from the PRINT USING expression list the of our display would look Like this The temperature is 50 10 e ett meer ONIN 15 2 3 The Symbol Numeric Fields in a format string always indicates that you want to format Each symbol in a format string represents one numeric digit The simplest numeric format string would consist of just symbols For example PRINT C USING REHHE The statement above tells BASIC to format the numeric variable C into a field of four digits with no fractional part If the format string causes BASIC to remove the fractional part of a number BASIC rounds the number to the next integer rather than truncating it For example T 2367 88 USING 4484 RET if the numeric field is too small to contain the specified number for example if we had specified the number 650456 56 with the format string j 5 2 N 1 CHHHSU BASIC prints the number in standard BASIC format preceded by a vb symbol indicating overflow For example PRINT 150450 USING Hitt GET FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 13 5 If the numeric field is larger than the specified number BASIC right justifies the number in the field inserting leading blanks into the digit positions not needed For example PRINT USING AH HH 23 RED
116. ach 3 word block describing one argument is as follows Word 1 Variable type code Bits 0 3 contain the type code for the specific variable O unformated 2 string 4 floating point 6 binary 7 through 17 are currently unassigned Bit 4 is set to indicate the variable is subscripted or cleared to indicate the variable is not subscripted Other bits in the type code word are meaningless Word 2 Absolute address of variable in a user impure area This address is the first byte of the variable no matter what its type or size might be Word 5 Size of the variable in bytes Note that the above descriptions also apply to the expression arguments except that the results are located above the address specified by RS instead of below it The argument list is built in free memory directly above the currently allocated user impure area R points to the word immediately following the Last word in the argument List You may sean the argument List and determine its end either by decrementing the count word at the base of the List or by scanning until the scan index reaches the address in R 18 2 3 Free Memory Usage When the subroutine is called indexes R and RS mark the beginning and end of the free memory that is currently available for use as workspace This area is not preserved by the run time system and the subroutine must not count on its security between XCALL statements Note that the word at R4 may be used as the first word but t
117. al to number A and Less than number B you can use the expression CBA RND O44 Note that the INT function is used when generating random integer numbers Far example to generate a random integer greater than or equal to 5 and less than 31 use the expression INTC26 RNDCO 45 where 26zB 11 1 10 SGNOO Returns a value of 1 0 or 1 depending on the sign of the argument X Gives 1 if X is negative O if X is O and 1 if X is positive 11 1 11 SQROO Returns the square root of the argument X 11 1 12 VALCA Returns the numeric value of the string variable or string literal A converted to floating point under normal BASIC format rules for example VALCU T23 0 returns 123 11 2 TRIGONOMETRIC FUNCTIONS The following trig functions are implemented in full 11 digit accuracy SINOO Sine of X COS OO Cosine of X BASIC FUNCTIONS Page 11 4 TANCK Tangent of X ATNOO Aretangent of X ASNOX rcsine of X ACSOD Arccosine of X DATNCX Y Double arctangent of X Y 1 5 CONTROL FUNCTIONS Control functions indicate the status of file input and output operations and provide information on system operations 11 5 1 EOFO0 The EOF function returns a value giving the status of a file whose file channel number is X The file is assumed to be open for sequential input processing The values returned by the EOF function are 1 if the file is not open or the file channel number X is zero NOTE A file channel number of zero
118. alid illegal record number The relative record number specified in a random file processing statement i e READ or WRITE jis either Less than the current FILEBASE or outside of the file Illegal SCALE argument The argument given in a SCALE statement is invalid the argument must range between 30 and 30 Illegal size for variable type The specified variable size is not valid for the particular variable type Floating point variables must be size 6 and binary variables must have sizes 1 through 5 Illegal STRSIZ argument The argument given in a STRSIZ statement is invalid illegal subroutine name The name specified as a subroutine is not valid Tllegal subscript The subscript expression is not valid DWM 00100 07 REV BOG MESSAGES OUTPUT BY ALPHABASIC Page B 4 1 legal TAB format Your program has incorrectly specified a TAB function Illegal type code The variable type code a MAP statement 3s not valid Illegal user code The specified PPN was not found on the specified device or is not in a valid format 7 nsufficient memory to initialize RUN Memory is too full to handle complete execution of RUN 1nsufficient memory to load program xxxxxxx The RUN program did not find enough free memory to be able to load the specified program Internal stack error xxxxxx yyyyyy Please submit an SPR Please submit an SPR stating that you received this error message and specifying the xxxxxx yyyyyy nu
119. arget function desired Some valid examples are CHAIN SYSTAT LIT T 4 CHAIN TESTI CMD CHAIN DSKO ZBCKUP CMDD2 231 CHAIN TRANS DODL110 Q Note that if the device and account are not specified the action taken is the same as if you had entered the command directly from your keyboard That is if you omit device and account specifi cations the monitor command processor searches for command files or programs in the following order 1 System memory c User memory 5 The account and device vou are logged into NOTE To load a file into your user memory partition use the monitor Level LOAD command To load the file inte system memory where it may be accessed by all users an the system the System Operator must add the appropriate SYSTEM command Line to the system initialization command file DWM O00100 01 REV BO4 CHAINING TO BASIC AND SYSTEM PROGRAMS Page 16 3 Note also that when you chain to a monitor command after the command has finished executing it returns you to the monitor Level rather than BASIC This means that if you wish to automatically return to some AlphaBASIC program you have to execute a command file whose final command is a RUN command which specifies that original BASIC program CHAPTER 17 ERROR TRAPPING ALphaBASIC allows your program to trap errors that would normally cause the system to print an error message and abort the program run When you are in interactive mode an err
120. ariable 1 MEMORY MAPPING SYSTEM Page 8 5 If no explicit type code is entered BASIC assumes unformatted data type xX 8 2 3 1 Unformatted Data Unformatted data is absolute in memory You usually only define an unformatted variable so that you can reference a group of other variables as one unit The contents of unformatted data variables should only be moved to other unformatted data variables For ail practical purposes unformatted data variables are treated Like string variables except that they are terminated only by the explicit size of the variable 8 2 3 2 String Data String variables are terminated either hy the explicit size of the variable or by a null byte 0 if the string is shorter than the allocated size Moving a Long string to a short one truncates all characters which do not fit into the new string variable Moving a short string to a long one causes the remainder of the Long variable to be filled with null 0 bytes so that the actual data size of the string is preserved for concatenation and printing purposes 8 2 3 3 Floating Point Data Each floating point number always takes up Six bytes The record number variable in a random mode OPEN statement must loating point The result variable of a LOOKUP statement must also be floating point 8 2 3 4 Binary Data Binary variables may range in size from 1 to 5 bytes giving from 8 to 39 bits of binary unsigned numeric data or 40 bits of binary signed data
121. at of an atsign 8 followed by a variable name The system searches for the requested variable and prints out all parameters about the variable for you on the terminal This may actually be two definitions since the variable AU may actually be two different variables one would be a single floating point number and the other would be a subscripted array The information returned about the variable is the type of variable string binary etc e the dimensions of the array if the variable is indeed an array the size of the variable in bytes and the offset to the variable from the base of the memory area which is used to allocate all variables If you enter a reserved word such as PRINT the system tells you that the name is a reserved word The general format of the definition Line which is returned by the system isi memory t yne variable type dimensions size n location For actual examples of the definition Line see Section 8 6 1 Examples below Memory type means the method of memory allocation used when defining the variable The memory type may be MAPn where n is a number from 1 to 16 FIXED or DYNAMIC variables FIXED variables are not defined by a MAP statement and are allocated automatically when the compiler finds references to them in the program This is the normal method used by other BASIC versions to allocate variables DYNAMIC variable arrays are allocated by a DIM statement or by a default reference to a subscr
122. at ISAM be able to write to the disk containing the index files even if you do not plan to do anything more than read from the disk therefore make sure that that disk containing the index files is not write protected ALL indexed sequential files must be created by the ISMBLD program prior to access by any ALphaBASIC program There is no method for the creation of a new indexed file within the ALphaBASIC language since this would require a prohibitive amount of seldom used code You may however create indexed files by using the feature that allows a BASIC program to create and then execute a command file This cammand file could set up parameters and then call the ISMBLD program to perform the actual creation of the files For compatibility with existing structures the data file must have an extension of IDA and all index files must have an extension of IDX There must be at least one index file which is called the primary index file There may also be additional index files called secondary index files which also Link to the primary data file The primary index file must always be opened in any program in order to gain access to the data file This is true even if you only intend to access the data file through one of the secondary index files in the current program For information on file structures and operating the ISMBLD program refer to the ISAM System me M 19 2 SYMBOLIC AND RELATIVE KEYS Indexed files are accessed by one of two
123. awhile to get the hang of it The origin parameter must be the Last parameter on the line it takes this form an symbol followed by the name af the previously mapped variable whose area you wish to overlay This variable must be on the same Level as the variable you are presently allocating If size and value parameters are not included in this statement you may omit them with no dummy commas For example 10 MAP1 CUSTOMER ID 20 MAP2 NAME S 13 30 MAP2 ID NUM F 40 MAP2 SEX B 1 50 MAPI PRODUCT INVENTORY CUSTOMER ID 60 MAP2 BRAND S 13 70 MAP2 PARTNO F 80 MAP2 RESALE B 1 The MAP statements above allocate the variable CUSTOMER ID which takes up a total of 20 bytes Then it allocates the variable PRODUCT INVENTORY also taking up 20 bytes and specifies via the 3SCUSTOMER ID origin parameter that PRODUCT INVENTORY will occupy the same space in memory as CUSTOMER ID The following statements define three areas which all occupy the same 48 byte memory area but which may be referenced in three different ways 100 MAPI ARRAY 110 MAP2 INDEX 8 F 200 MAP1 ADDRESS ARRAY 210 MAP2 STREET S 24 220 MAP2 CITY S 14 230 MAP2 STATE S 4 300 MAPT DOUBLE ARRAY GARRAY 310 MAP2 UNIT 4 320 MAP3 CODE B 2 330 MAP RESULT F MEMORY MAPPING SYSTEM Page 8 8 Statements 100 110 define an array with 8 floating point elements a total of 48 bytes in memory Statements 200 230 define an area with three string variables in
124. ay NUMBER PRINT 23 amp PRINT U 2345 678 USING RSHHAH HAT 45 678 USING S S4HHH Hit ING SSESSEH HH 2545 678 NOTE You may use the first and second formats oniy for numeric data vou may use the third format for string and numeric data Also remember that USING has the Lowest precedence of all operators Therefore all other operations in expressions surrounding the USING operator are performed before formatting is done For example PRINT 2344 USING SZ g e gg produces 27 0 The format string may be a string expression for example MIDECAB 4 5 a string constant for example or a string variable for example MASK e the third PRINT USING variant above you may supply a list o s to be formatted separating the expressions with commas as with PRINT statement e g PRINT USING HABRA HH ABC If more expressions than the format string is meant to handle BASIC he format string until each of the elements in the expression List has been orndtted If you supply fewer expressions than the format string is meant to handle BASIC ignores the unused portion of the format string TA NOTE You may also send formatted data to a file by specifying a file channel number after the PRINT keyword e g PRINT 41 USING sos expresston List For information on sending data to files see tior 3 9 UPRINT U 18 2 FORMATTING CHARACTERS Ow discuss the n characters that make up the format al Dharatter con
125. be an upper case alphabetic character A Z or a lower case alphabetic character a z Apostrophes may be used within labels in place of spaces for clarity since apostrophes are not recognized as delimiters A label when used must be the first item on a line and must be terminated by a colon te It is important to remember that you may not place a space between the Label and its colon to do so wilt cause BASIC to think that you have entered a multi statement Line rather than a labeled Line A Label may be followed by a program statement on the same Line or it may be the only item on the line The use of Labels is similar to the use of Line numbers with GOTO and GOSUB statements and makes the program easier to document Here are some examples of Labels using apostrophes 10 START PROGRAM INPUT Enter two numbers to get sum A B 20 PRINT A 4 B A B 30 IF ASB lt gt O GOTO SUM NOT ZERO 40 PRINT Sum is zero 50 GOTO START PROGRAM 60 SUM NOT ZERO 70 PRINT Sum is not zero amp GOTO START PROGRAM 90 END where Start Program and Sum Not Zero are labels Note that a reference to a label as seen in Lines 30 50 and 80 is neither the first item on a Line nor is it terminated by a colon The reference must be identical to the actual label in its case upper and or lower and in the placement of apostrophes GENERAL INFORMATION Page 3 4 3 f MEMORY ALLOCATION The compiler system allocates memory dynamically as you
126. be used to store a terminator word to stop the scanning of the argument List AS This is the arithmetic stack index used by the run time system The stack is built at the top of the user partition and grows downward as items are added to it When the external subroutine is called AS points to the current stack base Since the arithmetic stack may contain valid data the external subroutine must not use the word indexed by A5 or any words above it 18 3 2 Argument List Format The list of arguments specified in the XCALL statement may range from no are ts at all to a number Limited only by the space on the command iine To pass these arguments to the external subroutine an argument List is i in memory which describes each variable named in the List and tells 1 it can be located in the user impure area The variables themselves are not actually passed to the subroutine but rather their absolute locations in memory are In this way the subroutine may inspect them and modify them directly in their respective locations This does not apply to expressions which are built on the stack as described previously A5 points to the first word of the argument List which is a binary count of how many arguments were contained in the XCALL statement Following this count word comes one 3 word descriptor block for each argument specified f there are no arguments in the XCALL statement the argument List consists only of the single count word contain
127. bel Line N ON expression CALL Label line if Label Line amp 2 Label Line N The expression can be any valid expression which is evaluated and truncated to a positive integer result The result of the expression evaluation is then tested The subroutine at Label linef1 is executed if the result is 1 the subroutine at label linef2 is executed if it is 2 etc If the result is zero negative or greater than N the program falls through to the next statement As with the GOSUB statement the verb CALL may be used in place of the verb GOSUB giving an ON CALL statement Here is an animation program using ON GOSUB Changed 31 October 1981 xe PROGRAM STATEMENTS Page 10 15 10 I INT OG RNDCO 1 Random number from 1 to 3 20 ON I GOSUB UP DOWN STRAIGHT Go to 1 of 3 subroutines 30 GOTO 10 40 UP PRINT TAB 1 3 RETURN Draw symbol go up 1 row 50 DOWN PRINT TAB 1 4 X RETURN Go down 1 row draw symbol 60 STRAIGHT PRINT p RETURN Draw symbol 10 17 ON GOTO The format iss ON expression GOTO label Line 1 label Line 2 label lLine N The ON GOTO statement allows multi path GOTO branching to one of several points within the program based on the result of evaluating an expression The expression can be any valid expression which is evaluated and truncated to a positive integer result The result is then tested to branch to Label Lines1 if 1 label line 2 if 2 Label Line 3 if 3 etc If the re
128. ber that the default size of unmapped string variables is ten bytes if you want to use strings Larger than that use the STRSIZ statement to reset the default string size See Section 10 26 for information on STRSIZ Some examples of the statement are INPUT LINE AS INPUT LINE ENTER YOUR FULL NAME PLEASE NAME You may also use the INPUT LINE statement to read data from a sequential file It takes the form INPUT LINE file channel variablet For more information on using INPUT LINE and files see Chapter Tor ALphaBASIC File 1 0 System 10 13 KILL The format is KILL filespec KILL deletes a file from a disk It is discussed in detail in Chapter 15 AlphaBASIC File 1 0 System Changed 31 October 1981 PROGRAM STATEMENTS Page 10 14 10 14 LOOKUP The format is LOOKUP filespec result variable The result variable must be a floating point number This statement searches for a file and returns its size It is discussed in detail in Chapter 15 ALphaBASIC File I O System 10 15 LET The format is LET variable expression Assigns a calculated value to a specific variable during execution of the program You do not have to specify the LET keyword in an assignment statement LET AS 12 4 LET SUMC4 5 ATHSQRCBTD LET C JANUARY AS 12 4 4 5 AT SQR B1 IANUARY oe it LE SUM CE 10 16 ON GOSUB CALL The formats are ON expression GOSUB Label line 1 Label line 2 la
129. ble to perform all of these functions If your terminal has additional features Alpha Micro recommends starting at 64 decimal when you assign function codes in your terminal driver DWM DOTOO 01 REV BO4 CHAPTER 14 SCALED ARITHMETIC ALphaBASIC uses a floating point format which gives an accuracy of 11 significant digits Unfortunately this accuracy is absolute only when dealing with numbers that are total integers i e there are no numbers to the right of the decimal point This fact stems from the conversions that are required from decimal input to the binary floating point format used in the hardware For most business users the actual range of numbers contains two digits to the right of the decimal point and nine digits to the left af the decimal point When the fractional part of the number is converted between decimal and binary formats a small but significant error is sometimes introduced which may propagate into inaccuracies when dealing with absolute dollars and cents values As an example of the kinds of inaccuracies that can occur take a look at the foliowing program 10 SIGNIFICANCE 11 20 PRINT 26 4 INT C26 4 Instead of the expected answer of 4 we see the answer 39999999999 This is not an error in BASIC but simply represents the side effects af converting a decimal fraction to binary representation and back again Some decimal fractions cannot be exactly expressed as a binary fraction in a finite number of d
130. brary Account DSKO 7 61 For information on these subroutines see the AlphaBASIC XCALL Subroutine User s Manual DPSS 10008 00 In addition a set of business oriented assembly language subroutines is available from your dealer To call an assembly language subroutine from an AlphaBASIC program use the XCALL statement The syntax for this statement is as follows XCALL routinefargument 1 argument2 argumentN The routine to be called is an assembly Language program which has been assembled using the machine Language assembler The resulting PRG program file tor LIT program on AMOS L systems must then be renamed to give it the assumed extension SBR indicating that it is a subroutine and not a runnabie program bwM 00100 01 REV BO4 CALLING EXTERNAL ASSEMBLY LANGUAGE SUBROUTINES Page 18 2 When the XCALL statement is executed by the AlphaBASIC run time system the named subroutine is located in memory and then called as a subroutine see Section 18 1 below for mare information on automatic subroutine loading AlphaBASIC first saves all registers then sets certain parameters into those registers for use by the external subroutine The addresses of the arguments are calculated and entered into an argument List in memory along with their sizes and type codes The base address of this List is then passed to the user routine in register RA on AMOS systems or AS on AMOS L systems The arguments may be one of two basic
131. c number of digits is not performed until just before the printing of the result The statement SIGNIFICANCE 8 for instance sets the number of printable digits to 8 The value is interpreted at run time and therefore may be any valid numeric expression including variables The current significance of the system is ignored when PRINT USING is in effect Note that the SIGNIFICANCE statement only affects the final printed result of all numeric calculations The calculations themselves and the storage of intermediate results are always performed in full 11 digit precision to minimize the propagation of errors The significance of the system is set at 6 digits when the system is first started This is equivalent to standard single precision formats used in most of the popular versions of BASIC The significance is not reset by the RUN command and therefore may be set in interactive mode in a direct statement just prior to the actual running of a test program Of course any SIGNIFICANCE statements encountered during the execution of the program reset the value 10 25 STOP The format is STOP Causes the program to suspend execution and print the message Program stop at line nonn If vou are in interactive mode you may then continue to the next statement in sequence by executing a CONT command or a single step command 10 26 STRSIZ The format is STRSIZ value The string size statement sets the default value for ali unmapped strings wh
132. caling mode in which the data was written or else must apply the scale factor explicitly to all values from the file Binary and string values of course are never modified regardless of the scaling factor currently in use Changed 31 October 1981 CHAPTER 15 ALPHABASIC FILE I 0 SYSTEM This chapter contains information on creating and using disk files from within vour BASIC programs Since these processes differ somewhat depending on whether you want to use sequential or random data files we discuss sequential and random files generally before getting into the specific commands you can use to manipulate these files Note the sample program at the end of the chapter it demonstrates defining a logical record computing the logical record blocking factor for a random file allocating a random file opening and closing a random file searching for a file and writing and reading data to and from a random file AlpraBASIC supports both sequential and random access disk files You may write data either in ASCII or in packed binary formats Files that AlphaBASIC programs create are compatible with all other system utility formats and BASIC files may be interchanged with files from other Languages That is BASIC data files can be read and manipulated by programs written in other Languages Conversely files created by other languages and system utilities may be read and manipulated by programs written in AlphaBASIC iles are created and re
133. called nested loops Loops may be nested to many levels Each time the outermost loop is incremented for decremented once the loop nested within it is executed from beginning to end During the execution of the second loop the third Loop if any is fully executed each time the second variable is incremented And so on for each nested loop in the series For example 10 This program prints out a two dimensional array 20 l and demonstrates nested loops PROGRAM STATEMENTS Page 10 5 30 DIM MATRIX S 5 40 The nested Loops 50 FOR T 1 TO 5 60 FOR J 1 TO 5 70 MATRIXCI J m I J 80 PRINT MATRIX I J 90 NEXT J 100 PRINT 110 NEXT I The program above prints 0 1 2 3 4 agree eere erem entente mre en It is not good programming practice to branch out of a Loop before its completion via GOTOs ON GOTOs etc unless you give careful consideration to the BASIC system stack area The stack area used by the loop is not reclaimed if you branch out of the loop and doing so can cause a stack overflow error during program execution A cleaner way of exiting a loop is Simply to set the control variable to the terminal value specified in the FOR statement Far example 10 REM Example of exiting out of a FOR NEXT Loop 20 30 START LOOP 40 FOR Iz1 TO 100 50 INPUT Enter number of pennies PENNIES 60 TF PENNIES O GOTO NEGATIVE VALUE Don t jump out of the loop TO PRINT You have PENNIES 100 dollars GOTO
134. ce the Last time you compiled it BASIC automatically compiles it for you when you save a RUN file to ensure that you are saving the most current version If you try to save a RUN file when there is no source program in memory BASIC reports No source program in text buffer Since there is no way to convert an object file back to a source program file you will want to save both the BAS and RUN versions of your program For information on the SAVE and LOAD commands see Sections 9 8 and 9 11 2 1 2 Direct Statements Program statements that do not begin with a line number are considered direct statements and BASIC executes them immediately For example READY PRINT A 9 INTERACTIVE AND COMPILER MODES Page 2 4 Although it looks as if it is being interpreted a direct statement is actually compiled then it is applied against the current set of defined variables You can define variables and change variable values using direct statements Certain statements are meaningless as direct statements and so are not allowed for example RESUME GOSUB etc BASIC allows multi statement Lines as direct statements Multi statement Lines are Lines which contain more than one statement the statements are separated by colons As you enter direct statements BASIC checks them to see that they are in proper form and that they are legal for use as direct statements You see an error message if you enter a statement incor
135. characters in your variable names Note that although AlphaBASIC folds reserved words to upper case it does not translate variable names e g the variable name REC SIZE is considered unique and separate from the variable name Rec Size See Section 3 9 for a discussion of how ALphaBASIC handles upper and lower case characters Normal unmapped variables are considered floating point variables unless their names are terminated by a dollar sign in which case they are considered string variables Variables defined via a MAP statement called mapped variables are defined by an explicit type code and therefore do not follow the standard convention of using a dollar sign for string variables they may take on any kind of data format regardless of the name terminator Mapped variables are a special form of AlphaBASIC variable that enable you to perform sophisticated data 1 0 For information on mapped variables see Chapter 8 Memory Mapping System Integer variables are specified by appending a percent sign to the variable name NOTE The integer variable was added for compatibility reasons However AlphaBASIC does not perform integer arithmetic Following a variable name with a X symbol is equivalent to using the integer function on that variable For example COUNTERX is the same as INTCCOUNTER ALPHABASTC VARIABLES Page 4 2 Subscripting of array variables follows the standard conventions of other BASICs by enciosing the subscripts
136. compiled BASIC now automatically compiles the program for you Then the object program is saved on the disk SAVE PAYROL RUN GET Saves the object program on the disk as PAYROL RUN REA DY Chanaed AQ April 1981 INTERACTIVE COMMAND SUMMARY Page 9 8 In the interests of security BASIC will not let you save a program that is in an account that is not within the same project as the account you are togged into for example if you are logged into 0SK2 L100 23 and want ta save a program in DSK2 3540 13 you see READY SAVE NEWPREC340 1 GED Cannot OPEN NEWPRG BASL3S40 11 Protection violation 9 12 SINGLE STEP LINEFEED The single step function is a feature not found in many versions of BASIC and is very useful in debugging programs and in teaching the principles of BASIC programming to newcomers To use the single step command type Linefeed That is press the terminal key labeled LF LINEFEED or Y 2 The single oa function causes the current line in the program to be listed on your terminal and then executed Any output generated by the execution of a PRINT statam nt then follows on the next Line After the Line has been executed the execution pointer is advanced to the next Line and control returns to vou in the in teractive command mode Successive single step commands may be used to follow the program through its paces Single step is legal at the beginning of the program after program STOP statements
137. condary be closed using the normal CLOSE statement referencing the correct file channel number Failure to do so may result in destroying the Link structure NOTE It makes no difference in which order you close the ISAM files however remember that vou cannot access a secondary index file if you have already closed the primary index 19 7 INDEXED EXCLUSIVE MODE When your program is the only program that needs to access an ISAM indexed file you can specify INDEXED EXCLUSIVE as the mode in which you open the fiie For example OPEN 45 PAYROL INDEXED EXCLUSIVE 100 REC NUM USING ISAM FROM WITHIN BASIC Page 19 7 The statement above opens the data file PAYROL IDA and the primary index file PAYROL IDX in exclusive mode The main advantage of INDEXED EXCLUSIVE mode is a Large increase in the speed with which your programs can access the indexed file It also prevents other users from accessing your indexed file until you close the file Otherwise it works in the same way as INDEXED mode In INDEXED EXCLUSIVE mode ISAM knows that no other program is going to access the indexed file while your program is working with it Therefore ISAM can take full advantage of prior knowledge about the file for every access and can speed up your access time considerably When your program opens an indexed file in the more common INDEXED mode you must use file locking procedures to protect your indexed file if other programs are going to access
138. d S hyte binary format before the logical operation is performed The value 1 represents a 40 bit mask of all ones Any relational comparison between two expressions or variables returns a 1 if true or a D if false Changed 30 April 1981 DATA FORMATS Page 6 35 6 4 INTEGER FORMAT Integer variables and constants are specified by appending a percent sign to the variable name which is the standard convention in use by other BASICS AlLphaBASIC generates floating point variables and performs automatic integer truncation for all integer variables specified in this manner Integer constants are generated as their equivalent floating point values and are included only for compatibility with existing program structures Since integer variables are effectively floating point variables with an additional INT conversion performed they are actually slower than regular floating point variables This is the opposite of most other BASICs which usually store integer variables as 2 byte signed values and perform special integer arithmetic on them True integer variables may be defined by using the MAP statement and the B binary type code See Section 8 3 Type Code for a description of the B type code 6 5 UNFORMATTED An unformatted numeric variable specified via a MAP statement defines a fixed size area of storage used to contain absolute unformatted data which may be in any of the above formats This format is normally used in t
139. de as a Learning tool to see how the variables are allocated They are not designed to be practical in the interactive mode however and are best used by putting them into a program file and compiling the program in the interactive mode if an error occurs in the syntax of the statement the variable will already have been added to the tree in memory The main advantage to testing MAP statements in interactive mode is that BASIC checks the MAP statement syntax as you enter the statement thus giving you immediate feedback if any errors occur MAP statements must come at the beginning of the program before any references to the variables being mapped If a reference is made to the variable before it is mapped such as LET A 5 8 the variable is assigned by the normal variable allocation routines and the MAP statement then gives an error since the variable is already defined As a convenience all MAP statements force allocation to the next even byte boundary so that binary word data can be assigned properly 8 5 LOCATING VARIABLES DURING DEBUGGING Since the mapping scheme is fairly complex to understand fully a command has been implemented which assists vou in locating the mapped variables and in understanding the allocation techniques used by the AlphaBASIC memory mapping system tt is valid only as a BASIC system command and has no MEMORY MAPPING SYSTEM Page 8 12 meaning if used within a program text The command has the general form
140. de the range specified in the DIM or MAP statement for the subscripted variable Syntax error The syntax of the specified line is invalid System commands are illegal within the source program ASIC system commands LOAD DELETE LIST etc are not valid Within a BASIC source program System error This is used as a catch all error message indicating that BASIC cannot identify the exact problem during the execution of the specified line For example if BASIC encounters a Buffer net INITed error message it displays System error because it doesn t know how to handle this condition Temporarily all arrays must be Less than 32K The array size you specified is Larger than 32K bytes U nabie to find INC ree file xxxxxx Xxx One of your INCLUDE commands specifies a file xD0000 xxx which BASIC Sanne locate Undefined Line number or Label The Line number or Label specified in a GOTO or GOSUB statement is hn not defined within the program nmapped variable You COMPILed a program using the M option and COMPIL encountered an unmapped variable Unsupported function Your program called a function which RUNSML does not support ALphaBASIC allows an alternate version of RUM called RUNSML The program is identical to RUN PRG except that it does not support trigonometric functions nor the EXP LOG L0610 FACT and operations Using RUNSML saves memory for users who do not need these functions Since RUNSML ca
141. due to their position in the ASCII collating sequence To assist in processing and comparing input which contains lower case letters the UCSOQ function has been implemented This function returns a string which is identical to the argument string 00 with all characters translated to upper case The inverse function LCSOO returns a string with all characters translated to Lower case 3 10 LIBRARY SEARCHING Whenever a program called via RUN or CHAIN or a subroutine called via XCALL is requested BASIC follows a specific pattern in looking for the requested RUN or SBR module If you specify an account then BASIC uses the current default device and the specified account If you do not specify an account the search sequence is as follows where P pn designates the Project programmer number that specifies your account System memory User memory default disk fUser P pn Default disk User P 07 DSK E 7 63 If you specify a device BASIC does not search in memory but proceeds directly to that device Note that earlier versions of BASIC pre 4 2 used a different search algorithm that was the reverse of the one outlined above 35 11 INCLUDE FILES The INCLUDE command allows COMPIL to fetch source code from another file during compilation so that you don t have to repeatedly type in frequentiy used code At the point in the program where you want the transferred code to begin enter 4INCLUDE filespec Changed 31 October 19812
142. e na oC Bo d i D We de 9 4 9 8 17 5 A 3 to A 4 QUSE wl S e Rue xoc oe god Control C trapping a a s s a a a eA M A B PO LA PO DO PO PO PO A aj d PP Pad ra PAJ m a uh d c i A i Changed 31 October 1981 ALPHA BAS EG USER S MANUAL Control variable s s a COSC LA a aas an TX is CPU Line clock a a aso Creating a program s a a DATA Goa ah tw LER ee VES ae US Data file Data format s s a a Array structure s Binary variable a Floating paint variable Simple variable a String variable a a a Unformatted variable a Data record amp Data structure a s DATA ANDE a a tee a AU os DATE a ee ae are Me cee ew DATNCX YO V uoce wt er ew Debugging Debugging features DELETE ae IR eu Wu ux Device specification a a SU a Ta A Dimension array a a Direct statement a s a a Disk storage s sa Dummy command file s aa Duplicate Line number a program s s a Mask a 2 Editing Edi END m a aet oc ae uer Sete ARR End of file EOFCXO a Ao AG dee ca ciate War ow ERFCKXY i oo uw ENREDO e cus onec ux ERROR x uo a ee ana Error propagation a s a Error trapping s Even address a a Exclamation mark symbol t Exclamation symbol i Execution mode s a EXPEXO bee el Ri EXPAND s s n Expanded mode a a e s a Expanded TAB
143. e 90 back to Line 50 until the user types a Controlec if you use GOTOs on a multi statement Line remember to place it Last on the Line any statements after the GOTO will never get executed For example 10 PRINT GROSS NET GROSS DEDUCTION GOTO GET TAX PRINT DEDUCTION the last statement PRINT DEDUCTIONS can never be executed PROGRAM STATEMENTS Page 10 9 10 10 IF THEN AND ELSE The format is IF expression THEN Cstatement Label l ine ELSE statement label Lined The conditional pracessing features in AlphaBASIC give a wide variety of formats which duplicate just about all the functions performed by other versions of BASIC Some of the format combinations that are acceptable are TF expression THEN Lines IF expression THEN GOTO Line Label IF expression GOTO Line Label IF expression THEN Line ELSE GOTO Line Label IF expression THEN GOTO Line Label ELSE GOTO Line Label IF expression THEN statement IF expression statement IF expression statement ELSE statement iF expression THEN statement ELSE statement Notice from the examples above that you may sometimes omit the GOTO keyword when transferring control to another program location You may not omit the GOTO keyword when 1 you are referring to a Label or 2 when you are referring to either a program Label or a Line number in an ELSE clause You may also omit the THEN keyword except when you are transferring control to another program Locatio
144. e Length of the variable riame is not a significant concern Label names may also be used ta identify points in the program for GOTO and GOSUB branches Label names are alphanumeric and help to clarify the program structure for example EXIT ERROR or EVALUATE ANSWER 2 CHAPTER 2 INTERACTIVE AND COMPILER MODES The major purpose of this chapter is to explore the differences between the two modes in which you can use BASIC We will also discuss how to create compile and run your programs The ALphaBASIC system consists of three programs RUN PRG the monitor level BASIC run time package COMPIL PRG the monitor level disk based BASIC compiler and BASIC PRG which combines an interactive compiler and run time package to simulate a BASIC interpreter You use RUN and COMPIL from AMOS command Level to run and compile AlphaBASIC programs outside of BASIC You use the BASIC PRG program when you want to use ALphaBASIC as an interactive interpreter Your choice of interactive or compiler mode depends on several factors your personal preference the amount of memory you have in your partition the stage of development your program is in and the physical form of your program Interactive mode simulates a BASIC interpreter by allowing you to deal directly with BASIC This is the mode that most BASIC users are probably familiar with Interactive mode permits direct editing of the source program in memory and immediate feedback as each program L
145. e double dollar sign symbol defines two digit positions one of which is taken up by the dallar sign itself for example FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 13 6 PRINT USING SSHHAHH HU 17500 66 100 365 2 produces 17500 66 100 00 345 20 Notice the difference between using the double dollar sign to produce a floating dollar sign and simply using the single non formatting character in the format string PRINT USING SAHHHH 4 17500 66 100 345 2 produces 17500 66 FT Because you will use the symbol to format data that represents money amounts you may want to use the floating comma symbol in combination with the symbol See the paragraph below for information on this formatting character Remember that you can include non formatting characters in a format string In the case above a single dollar sign is not a formatting character and so BASIC simply prints it as part of the formatted data As another example PRINT USING SH4X 25 45 56 78 99 84 produces 23 STR 100 In the example above the X symbol is not a special formatting character As another example PRINT USING The telephone number is HAR 448 BHHY 714 555 1212 produces The telephone number is 714 555 1212 FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 13 7 13 2 6 The Comma Symbol Floating Commas By including a comma in your format string you tell BASIC to insert a comma
146. e is n teger it has absolute accuracy Just before printing BASIC divides nis number by the scaling factor to reduce it to its intended value of er conversions have been included into the system to take care of all the Little subtle effects of storing scaled numbers For example whe nverting scaled numbers to integer or binary format BASIC must unscale e number first before converting it When BASIC multiplies two scale numbers together the result is a number which must be unscaled ance while division of two scaled numbers creates exactly the opposite problem Dealing with scaled numbers for exponential Logarithmic and trigonometric functions creates even more exotic problems ALL these conversions are done automatically by AlphaBASIC so you are relieved of the programming task of keeping track of them Oo D is normally entered at the start of a program and in effect throughout the program The statement for setting the am into scaled mode is ng factor n must be a decimal digit in the range of 30 to 30 it may not be a variab since scaling is done at compile time for constant values as well n time for input and output conversions Negative ng window to the Left NOTE You won t often use a since that takes care of the case where your her than too small caution are in order here Once BASIC detects the SCALE during compilation BASIC scales all constant values that follow
147. e to the Acme Dental Package 50 Perform initialization of data files PROGRAM 40 50 60 70 80 90 100 110 115 200 210 220 300 310 320 330 400 amp 10 420 500 510 520 You can 10 20 30 AQ 50 60 100 110 120 130 140 15 160 200 210 220 230 240 250 300 510 320 The prog STATEMENTS Page 10 7 GOSUB INIT t Ask user to pick function from main menu GOSUB MENU Do End of day Processing GOSUB DAY END Finish up close files and exit GOSUB FINISH UP END i The subroutines start here INIT PRINT This section will initialize files RETURN MENU PRINT This section will display the main menu and PRINT ask user for selections RETURN DAY END PRINT This section will perform day end processing RETURN FINISH UP PRINT This section will close files and clean up final data RETURN nest subroutines For example Demonstrating nested subroutines PRINT Main Programs GOSUB OUTERMOST OUTERMOST calls NEXTMOST and INNERMOST PRINT Return from Outermost END Here are the subroutines QUTERMOST gt PRINT Outermost subroutine GOSUB NEXTMOST PRINT Return from Nextmost RETURN NEXTMOST PRINT Nextmost subroutine GOSUB INNERMOST PRINT Return from Innermost RETURN INNERMOST PRINT innermost subroutine RETURN ram above prints PROGRAM STATEMENTS Page 10 8 Main Program Outermost subroutine Nextmost subro
148. ease feel free to attach additional comments Hf you require a written response check here E NOTE This form is for comments on dacumentatian oniy To submit reports on software probierns use Software Performance Reports SPRs available from Alpha Micro Please comment an the usefulness arganization and ciarity of this manual REV BOS What kinds of manuals would vou like to see in the future Please indicate the type of reader that you represent check all that ap yh C Aipha Micro Dealer or CEM E Non programmer using Alpha Micro computer for Ll Business applications Education applications T s we Fi C Scientific applications Lj Other please specify Assembiy language Higher ievel ianguage Experienced programmer iittie programming ex perience Student Other please specify NAME DATES FEBRES A e NN eis TCR PHONE NUMBER _ Sec PE ite ORGANIZATION corer TM ro a Reve eed E SMA eui cr 3 oe itt hs a T PR E GI or T Ml F STATE STAPLE l STAPLE eH ih de Oke cuti due dm I ON set pne hmm ncs O AG AD cs C i i en guapa i due mus FOLD FOLD 9595 ERROAEHHR OHARA H RAH HHREHRAREHRHAHRRHRHOHREHRHHREROEHHSHEORHR HERE HETERHHASCRRORERRAAAHBREEHEA Sr Vi ee oim een cada Sa SIR AME i do ace une som pem num D a OU
149. el is used This means that all DIM statements must be executed in the program prior to any actual references to the array Arrays may be any number of levels deep but practicality dictates some reasonable Limit of 20 or so Each level is referenced by a subscript value starting with element 1 and extending to element N Once an array has been dimensioned by a DIM statement it may not be redimensioned by a subsequent DIM statement in the same program At no time may the number of subscripts vary in any of the references to any element in the array The number of subscripts in each element reference must also match the number of subscripts in the corresponding DIM statement which defined the array size See Section 10 4 DIM for more information on the DIM statement Changed 50 April 19812 CHAPTER 5 ALPHABASIC EXPRESSIONS 5 1 ARITHMETIC EXPRESSIONS An expression can contain variables constant values operator symbols functions or any combination of the above For example 14 CFIXCTOTAL RECS REC SIZE 512 Parentheses are used to designate hierarchy within expression terms the normal mathematical hierarchy prevails in the absence of parentheses ALphaBASIC recognizes the following mathematical operators unary plus or addition equal unary minus or subtraction lt Less than multiplication l gt greater than f division lt gt unequal i raise to power gt lt unequal ok raise to power H uneq
150. el line it label line 2 label linewN Enables multi path branching to subroutines based on the positive integer value of the expression i e on exoressions1 branch to tabel line t etc A 5 19 ON GOTO ON expression GOTO Label Line i label line 2 label lLine N Enables multi path transfers of program control based on the positive integer value of the expression i e on expression 1 branch to Labei Lineft1 etc A 20 OPEN OPEN file channel filespec modet record size record variable Assians a specific integer file channel number to the specified file and also specifies whether the file is being opened for input output or random both input and output operations or ISAM operations Mode may he INPUT QUTPUT APPEND RANDOM FORCED RANDOM INDEXED or INDEXED EXCLUSIVE If the mode selected is RANDOM record size is an expression that specifies the Logical record size and record lt vartable is a variable that maintains the current Logical record number A 5 21 PRINT PRINT iexpression list iexpression list Outputs a blank Line or the expressionts specified A semicolon or comma at the end of the List of expressions inhibits carriage returnn Linefeed after a PRINT output The expressions to be printed may consist of numeric or string expressions string or numeric variables numeric constants string Literals functions or combinations of the above String Literais must be placed within quotation
151. elative key Code 3 ISAM adds the specified symbolic key to the index file along with the relative key The relative key must be in the corresponding variable specified in the OPEN statement ISAM normally sets up this relative key by a prior code 5 ISAM statement which delivers the next free data record to be used This relative key then becomes the result of any index search which locates this specific associated symbolic key Code 4 gt ISAM locates the specified symbolic key in the index file deletes it then returns the corresponding data record relative key so that the data record may be deleted and returned to the free List by using a code 6 ISAM statement If ISAM cannot Locate the symbolic key in the index file it gives you a record not found error Code 5 ISAM List and retu extracts the next available data record from the free irns the relative key in preparation for a code 3 index key addition statement If no more data records are free in the data file ISAM returns a data file full error ALL free records in the data file are kept in a Linked List called the free List This List is built initially by ISMBLD and contains all the records in the data file As code 6 ISAM statements are executed ISAM again returns the records to the free List for reuse ISAM does not modify the index file and ignores the symbolic key in the statement This call must be made only te the primary index file number Code amp
152. ening MAP statement You may reference variables at any level of the hierarchy A graphic example may help to clarify this idea MAP Patient Info MAP Name Address insurance 4 N 7 MAPS Last First Street Num City The diagram above shaws three levels of variables that have been mapped with MAPT MAP2 and MAP3 statements You may reference the level 1 variable Patient Info as a whole or may reference one of the variables on Levels 2 and 3 that represent sub groups of the variable Patient Info such as Name Address or Street When referencing any variable in the group you automatically get the information in any of the variabies below that variable in the hierarchy For example when you reference Name you get the information in the variables Last and First As BASIC allocates the variables Name and Address it automatically includes them Cand their sub variables within the variable Patient Info The MAP statements for the variable group above might look Like this MEMORY MAPPING SYSTEM Page 8 4 MAPI PATIENT INFO MAP2Z NAME MAPS LAST S 15 MAP3 FIRST S 13 MAP ADDRESS Patient address MAPS STREET S 30 MAPS NUM S 10 MAPS CITY S 30 MAP2 INSURANCE B 1 Set flag if has insurance NOTE We will discuss each of the elements of a MAP statement in the sections below To eliminate potential allocation problems BASIC forces all MAPI Level variables to begin on an even memory address This ensures that cer
153. ent was successfully executed if ERF returns a nonzero number some errar was detected and your program must take corrective action before accessing the file again For example ISAM He 2 PART NO IF ERFC2 lt gt O THEN GOTO ISAM ERROR The routine ISAM ERROR might print an error message and then exit See Section 11 3 2 ERF OO for more information on ERF The soft error codes returned by ERF are 52 Illegal TSAM statement code 33 Record not found in index file search 34 Duplicate key found in index file during attempted key addition 35 Link structure is smashed and must be re created 36 Index file is full 37 Data file is full Ci e free List is empty 38 End of file during sequential key read 19 9 USING INDEXED SEQUENTIAL FILES The sections below give step by step instructions for using indexed files For a complete demonstration of using ISAM from within BASIC refer to the sample BASIC program in Section 19 10 at the end of this chapter Remember thet you must load the ISAM program into memory before using a BASIC program that uses ISAM statements Use the monitor LOAD command LOAD SYS IS8AM PRG USING ISAM FROM WITHIN BASIC E Page 19 9 NOTE The SYS device specification is an ersatz device specification that specifies the System Library account DSKO 1 41 The command above is the same as LOAD DSKO ISAM PRGDT 6431 0 On the AMOS L system the PRG is replaced by SYS 19 9 1 Crea
154. erals in a dedicated memory area at program execution The DATA statement enables data to be an integral part of the prog Numeric items may not contain commas within them Individual dat strings or constants are separated by commas in the DATA statements The data between each pair of commas is drawn consecutively from dedicated memory area and assigned to the respective READ statement variable until either data is exhausted or no further READ statements occur If data is exhausted using RESTORE reinitializes the data placed data pool by the DATA statement Notice the READ and RESTORE commands below the Du DIM varjabletCexort expr2 exprN variablen expr1 exprd xprNn Defines one or more arrays which are allocated at the time of program execution String and or numeric variables are allowed and any number of SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A subscripts may be used to define the separate levels of each array Subscripts may be any legal numeric expression containing variables or constants A 3 6 END END Causes the program to terminate execution It is not required unless other program Lines e g subroutines follow the program end A 3 FILEBASE FILEBASE n Teils BASIC that the first record in the fite is record number n not record number zero You may use any numeric argument with FILEBASE FILEBASE does not associate its value with a specific file but only takes ef
155. es have not already been explicitiy closed via a CLOSE statement BASIC cannot open two files with the same file channel number at the same time but after BASIC closes a file another file may be opened using the same file channel number ALL file statements are valid as direct statements but BASIC closes any open files before it executes another RUN command This prevents statements in an executing program from reading or writing to files which were opened by a direct statement Under the current version of AlphaBASIC each open file requires about 580 bytes of free memory for buffers and control blocks 15 1 SEQUENTIAL ASCII FILES Sequential disk files are the easiest to understand and implement in Manele dre BASIC writes data to a sequential file in ASCII format and tores numeric data as ASCII string values A sequential data file usually d the extension DAT unless you explicitly order otherwise in the OPEN statement that opens that file NOTE Sequential files may not contain non ASCII data e g binary or floating point data Therefore you may only use PRINT INPUT and INPUT LINE for transferring data to and from sequential files Remember that PRINT converts floating point and binary data to printable ASCII form The READ and WRITE statements do not convert data to ASCII form and so are used for transferring data to and from random files sequential data files are normal ASCII files in all respects and you nipulate them by
156. ession RECSIZ and the relative key variable RELKEY are identical in both statements This is important since they both refer to the same data file MASTER IDA ISAM statements may then be made referring to either index file 1 or 2 but all READ and WRITE statements must be made to the data file 1 which ts associated with the primary index file In other words READ and WRITE statements must not be made to file He 19 5 READ AND WRITE STATEMENTS The ISAM calls do not access the data records themselves but merely deliver back the relative key of the associated data record to be used Normal READ and WRITE statements are then used ta actually retrieve or write into the data record itself These READ and WRITE statements follow the same format used when accessing a normal random access data file in AlphaBASIC The relative key associated with the primary file as specified in the OPEN statement must contain a valid relative key for the operation or an error results READ and WRITE statements as mentioned before must only be made using the primary index file chanmel number For example 10 OPEN K3 PAYROL INDEXED 67 NUM REC 20 ISAM 3 1 NAME t Get record 50 READ 3 LABEL Read record 19 6 CLOSING AN INDEXED FILE In order to ensure that all data records have been rewritten to the data file and that all Links in the index file have been properly updated and rewritten to the disk it is imperative that all index files primary and se
157. extension INDEXED Specifies indexed sequential mode INDEXED EXCLUSIVE Specifies indexed exclusive made See Section 19 7 for more information record size Expression that specifies the logical record size for the data file relativeckey variable Floating point variable that contains the record number of the Logical record you want to access The filespec must refer to the name given to the index fiie during the ISMBLD creation If this is a call to open a secondary index file you must have already previously opened the corresponding primary index file on another file number so that the data file may be accessed As an example assume that an indexed file structure consists of the primary index and data files named MASTER IDX and MASTER IDA respectively The structure also has secondary index files named ADRESS IDX and PAYROL TDM which access the MASTER IDA file in different sequences If you desire to pracess the file structure via the sequence used by the ADRESS IDX index file the following two statements are required OPEN 1 MASTER INDEXED RECSIZ RELKEY OPEN 42 ADRESS INDEXED RECSIZ RELKEY The first statement opens both the data file and the primary index fiie NOTE Remember that there are now three files opened 1 the data file USING ISAM FROM WITHIN BASIC Page 19 6 MASTER IDA 2 the primary index file MASTER IDX and 3 the secondary index file ADRESS IDX Note that the record size expr
158. f you mix floating point and string input you must use commas to separate the data being input For example if A B and C are numeric variables and D and ES are string variables consider the following legal examples Changed 31 October 1981 PROGRAM STATEMENTS Page 10 11 INPUT A B C Separate floating point data with commas 1 2 3 INPUT A B C Or separate floating point data with spaces 2123 INPUT A B DT C Separate string data from numeric data with commas 2 1 2 DAY 3 INPUT D ES Separate string data from other string data with commas 2 DAY MONTH NOTE For information on the statement to use if you want to enter strings that contain commas quotes and other special characters see Section 10 12 INPUT LINE lf a user of your program does not enter as many items of data as are expected by the variables in the INPUT statement BASIC displays a double question mark to ask for more For examples de H 5 INPUT A B C 442 92 3 The direct statement above asks for three items of numeric data Because we only entered two values BASIC responded with a 22 symbol to ask for the third value Be careful to correctly enter the type of data that the variables in the INPUT statement expect If an error occurs for example if you enter a string for a numeric variable BASIC sets that variable to zero for example INPUT AT ME PRINT A1 0 Therefore your programs should make sure that the correct
159. fect when the program it is in is executed A 3 8 FOR TO STEP and NEXT FOR variable expression TO expression STEP value program statements if any to be affected by the loop NEXT variable Initializes a loop during program execution Variables may be subscripted STEP defaults to positive 1 if not specified Tf STEP is negative the values must be specified fram Larger to smaller i 2 FOR A 10 TO 1 STEP 1 FOR X 1 TO 10 STEP 2 The statement NEXT with the optional variable specifying the particular Loop continues the loop until the second value following TO is reached by incrementation or decrementation A 3 9 GOSUB or CALL and RETURN GOSUB Lapel or Line CALL Label or Lined specified subroutine specified subroutine RETURN RETURN GOSUB and CALL perform identical functions If a Label is specified the SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 8 subroutine must be prefaced by the Label nat and a colon otherwise the first Line of the subroutine must start with the specified Line Subroutines may be nested RETURN terminates the subroutine and returns control to the statement following the GOSUB or CALL statement A 5 10 GOTO GOTO Label or Line Unconditional transfer statement transfers control to the Label or Line number indicated Tt may also be written GO TO TF expression THEN statement line label ELSE statement t ine H Label IF expression st atement lines HH
160. ferenced by the general statements OPEN CLOSE NPUT INPUT LINE PRINT READ and WRITE ALL file references are done by a file channel number which may be any integer value from 0 to 65535 You might think of the file channel number as designating an information channel Once a file has been associated with it the file channel serves as a pipeline through which data can be transferred between your program and the file Once you close that file the file channel is no longer associated with it and you may open another file on that file channel You may never have two files open at the same time with the same file channel The file channel always follows the verb in any file 1 0 statement and may be any numeric expression which is preceded by a pound sign File channel zero is defined as your terminal and is Legal in file statements to allow you to write generalized programs which may selectively output to either a file or to the terminal at run time However you may not use HO as a file channel for a random file Pu oC Changed 30 April 1981 ALPHABASIC FILE I O SYSTEM Page 15 2 There is no absolute Limit to the number of files that may be open at any given time in a program but since each file requires a certain amount of memory there is a practical Limit to this number based on memory available in your partition BASIC automatically closes all open files when the program exits or when a CHAIN statement is executed if the fil
161. file LSTSQR BASE100 11 you see Cannot OPEN LSTSQR BAS 100 11 file not found The LOAD command does not clear the text buffer before it loads the requested file and therefore may be used to concatenate or merge several programs or subroutines together to be saved as a single program The separate routines must not duplicate Line numbers in the other routines that they are to be merged with or else the new line numbers will overlay the old ones just as if the file had been edited in from your terminal IMPORTANT NOTE You should always use the NEW command prior to any LOAD command if you desire to ensure that the text buffer is clear Two examples of LOAD READY READY LOAD PWRS2 BET LOAD BSK2 PWRS2 BAST50 47 READY READY 9 9 NEW This command clears out all current source code object code user symbols and variables It initializes the compiler to accept new source program statements or direct statements READY NEW hey READY INTERACTIVE COMMAND SUMMARY Page 9 7 if you do not use the NEW command before Loading in a new program any lines in the new program with the same Line numbers as other program Lines already in memory will overlay and replace the old Lines you will thus merge the old and new programs 9 10 RUN This is the usual command to use to initiate the execution of the program which is in memory BASIC first checks to see if the program has been compiled since the Last editing change to the
162. form BREAK Line i lLine 2 l inest NO BREAK allows you to set breakpoints from the interactive mode on one or more Lines in the program in memory prior to running the program During execution when BASIC encounters a line that has a breakpoint set on it BASIC suspends program execution and prints the message Break at line anm The system then returns to interactive command mode to allow you to inspect or change variable values This suspension of execution occurs before the Line that has the breakpoint set on it is executed There is no Limit to the number of breakpoints that may be set in one program There is no additional overhead paid in execution speed when breakpoints are set Breakpoints are cleared from within the interactive mode by typing a minus sign in front of the Line number or by recompiling the program which always clears all breakpoints If you type BREAK and do not follow it with a Line number BASIC Lists all current breakpoints on your terminal BREAK RET or BREAK RET No breakpoints set 30 The following are various forms of the BREAK command BREAK Lists all currently set breakpoints if any BREAK 120 Sets a breakpoint at Line 120 BREAK 120 CLears the breakpoint at Line 120 BREAK 120 130 40 500 Sets breakpoints at lines 120 130 40 and 500 BREAK 50 60 Clears the breakpoint at 50 and sets one at 60 Once a breakpoint has been reached you may optionally continue the execution of
163. four main categories of functions Numeric and trigonometric functions return numeric values Control functions are used to indicate the status of file input and output operations and system operations String functions operate on numeric values or strings of one or more characters in Length and return string values Functions are different from program statements in that they return a value in order to see or use that value you must include the function in a program statement that evaluates the expression that the function call is a part of For example 10 SARCI will not display a value You must either assign the value returned by the function to a variable or display the value via a PRINT statement if you want to use or see the value returned For example 20 ROOT SQRCTAD 30 RESULT ROOT S RCNUMBER 24 or 40 PRINT Answers are r SGR 16 100 S R 24 11 1 NUMERIC FUNCTIONS Numeric functions accept a string or numeric argument and return a numeric value Note that the mode independence feature of the expression processor performs automatic conversions 1f a numeric argument is used where a string argument is expected and vice versa BASIC FUNCTIONS Page 11 2 11 1 1 ABSOO Returns the absolute value of the argument X For example ABS 32 4 returns 32 4 and ABS 17 2 returns 17 2 11 1 2 ASCCA Returns the ASCII decimal value of the first character of argument A The argument may be either a st
164. g is enabled the program is aborted and the appropriate message is printed on the terminal If error trapping is enabled the error trapping routine is entered with the code in ERR Q being set to 1 This feature allows you to prevent users from inadvertently exiting programs during critical times such as file updates DWM 00100 01 REV BOS ERROR TRAPPING Page 17 4 Control C action jis suspended during error recovery processing to prevent accidentally aborting the program during an error routine The Control C is detected immediately upon execution of the RESUME statement the program continues with the Line following the one that was interrupted if the RESUME statement did not specify a Line number 17 5 SAMPLE PROGRAMS The simple program below contains an error trapping routine that handles divide by zero errors Note that a su iccessful error trapping routine must either resolve the error or exit the program For example if the program below had merely printed an error message and then RESUMEd back to the Line where the error occurred the divide by zero error would still exist BASIC would again transfer control to the error trapping routine and we would be in an eternal Loop Instead the program resolves the error by changing the values of the problem variables to 1 and then resuming program execution this time around a divide by zero error cannot occur and everything is all right 10 ON ERROR GOTO DIVIDE BY ZERO
165. g to perform several mathematical operations 40 PRINT Your entries must be greater than O and less than 100 50 PRINT INPUT Enter two numbers to be added A B 60 GOSUB VALIDATE t Check to make sure numbers are valid 70 PRINT A 4 Bi mUI AB 80 PRINT INPUT Enter two numbers to be subtracted A B 90 GOSUB VALIDATE i Check to make sure numbers are valid 100 PRINT A Bi z A B 110 PRINT INPUT Enter two numbers to be divided A B 120 GOSUB VALIDATE i Check to make sure numbers are valid 130 PRINT A U Bi m A B 140 PRINT PRINT That s all 150 END 200 Subroutine to validate the data 210 VALIDATE 220 IF A lt 0 OR B lt 0 THEN amp PRINT Error negative or zero number END 230 IF A gt 100 OR B gt 100 THEN amp PRINT Error Number too big END 240 RETURN Remember that amp ampersand is the symbol for a continuation line Note that we inciuded an END statement at Line 150 to separate the main program from our subroutine otherwise BASIC executes the VALIDATE subroutine after it reaches line 140 and we get a RETURN without GOSUB error Also note that the use of GOSUBs helps to modularize your programs and thus makes them easier to design and maintain Even before you completely flesh out your programs you can insert dummy routines that will Later contain complete code For example D 10 This program will be a complete dental package 20 PRINT Welcom
166. he mapping system to define contiguous storage which is subdivided inte multiple variables of different formats No conversion ever takes place when moving data to and from this format Unformatted variables are treated as string variables when used in expressions CHAPTER 7 SUBSTRING MODIFIERS ALphaBASIC supports a unique method of manipulating substrings A substring is a portion of an existing string and may be as small as a single character or as Large as the entire string Substring modifiers allow the substring ta be defined in terms of character positions within the string relative to either the left or right end of the string The length of the substring is defined either in terms of its beginning and ending positions or in terms of its beginning position and its Length Substrings are defined by referencing the desired string followed by the substring modifier The substring modifier is two numeric arguments enclosed within square brackets 7 4 SUBSTRING MODIFIER FORMATS AND FEATURES The substring modifier takes on two distinct formats Cbeginning positian ending positiond beginmina position substring lengthl The first format defines the substring in terms of its beginning and ending positions within the string and uses a comma to separate the two arguments The second format defines the substring in terms of its beginning position within the string and its Length using a semicolon to separate the arguments The second format
167. he file is not open or the file number X is zero Q if the file is not yet at end of file during inputs 1 if the file has reached the end of file condition EOF should only be tested for sequential input files A 4 5 5 ERFOO Returns a file error condition cade If the returned value of X is nat zero an error or abnormal condition exists as a result of the preceding file operation See Chapter 19 for a List of the error codes returned by ERF A 4 3 6 ERROO Returns a during error trapping See returned by ERR status code for X which refers to program status Chapter 17 for a list of the error codes A 4 5 7 IOC The I0 system function allows the 256 1 0 ports to be selectively read from or written to In both cases only one byte is considered and an output expression greater than 255 merely ignores the unused bits The range of ports available is 0 to 255 1000 lt expr gt writes the low byte of expr to decimal port X A 1000 treads decimal port X and places the result into A Note On the AMOS L system if x is 0 235 it accesses the 256 external IO ports as it does on the AM 100 T the addresses on the AMOS L system are FFFFO O FFFFFFO If the number is 256 511 it accesses the internal on board 10 ports addresses FFFEOO FEFE F gt A 4 5 8 MEMCX Returns a positive integer which specifies the number of ri y ar bytes currently in use for various memory eas used by the compiler system Asta SPACEOD
168. he word at ARS is the base of the arithmetic stack and must not be destroved The last word of actually free memory is at 2 R5 The run time system has its own internal memory management system and does not wonform to the AMOS operating system memory management method Therefore the external subroutine must not use the GETMEM monitor calis to generate a block of work space in memory Also if any file calls are to be done they must be done with internal buffers since the INIT cali sets up a buffer by using the GETMEM monitor call DWM OQ100 01 REV BOS CALLING EXTERNAL ASSEMBLY LANGUAGE SUBROUTINES Page 18 5 18 3 SPECIFIC INFORMATION FOR AMOS L SYSTEMS 18 3 1 Register Parameters The following registers are set up by the run time system to be used as required by the external subroutine They may be modified if desired since they have been saved before the subroutine was called AD indexes the user impure variable area 40 is used throughout the run time system to reference all user variables Details on the format of this area are not available at this time AQ may be used as a work register A3 Points to the base of the argument List A3 may be used to scan the argument List for retrieval of the argument parameters A Points to the base of the free memory area that may be used by the external subroutine as work space This is actually the address of the first word following the argument List in memory and if desired may
169. her versions af BASIC Other values of the jument return memory allocations which pertain to various areas in use E DWM OQ100 01 REV BO4 SYSTEM FUNCTIONS Page 12 3 by the compiler and may or may not be of use to YOU The byte counts returned for the various values of X are Free memory space remaining in current user partition 7 Total size of current user partition Size of source code text area Size of user label tree 7 Size of user symbol tree variable names and user function names Size of compiled object code area Size of data pool resulting from all compiled DATA statements Size of array index area dynamic Links to variable arrays Size of variable storage area excluding arrays Size of dummy data termination field always zero Size of file I O Linkage and buffer area Size of variable array storage area dynamically allocated at run time WO OD cd CR OVER de V4 PR 24 7 i Some of these values will be meaningless when running the run time object module in compiler mode such as 2 3 and 4 NOTE The statement PRINT MEM is equivalent to the statement PRINT MEMCO 12 8 TIME The TIME system function reguires no argument and is used to retrieve the time of day as stored in the system monitor communications area The time is stored as a two word integer representing the number of clock ticks since midnight On the AMOS L system TIME returns the number of seconds since mid
170. ht One clock tick represents one interrupt from the CPU Line clock usually 60 or 50 Hz Dividing the time by the clock rate gives the number of seconds since midnight Converting this to current time is then accomplished by successive divisions by 60 to get minutes and again by 60 to get hours On the AMOS L system TIME returns the seconds since midnight The TIME cannot be set on the L the TIMEzexpression command will be ignored pression sets time of day in system to expr returns time ofeday in clock ticks into A DWM OO100 01 REV BOA SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 16 A amp 5 5 BYTE and WORD These system functions allow you to inspect and alter any memory locations within the 64K memory addressing range of the machine The BYTE functions deal with 8 bits of data in the range of 0 255 and the WORD functions deal with 16 bits of data in the range of 0 65535 inclusive Any unused bits are ignored with no error message BYTECX expr writes the low byte of expr into decimal memory loc X WORDCX expr writes the low word of expr into decimal memory Loc X A BYTEOO treads decimal memory Loc X and places the byte into A A WORD X treads decimal memory Loc X and places the word into A A 5 5 4 EOF X The EOF Cend of file function returns a value giving the status af a sequential file open for input whose file number is X The values returned by the EOF function are 71 if t
171. i Total work space 4712 bytes Cabel symbol tree 420 bytes Variable Symbol tree 1186 bytes Data statement pool U bytes Variable indexing area Zf bytes Compiler work stack TRU bytes Excess avail table memory 11918 bytes babel ccn COLERE tel io EE RRS E de PR Note that COMPIL tells you if any error exists within the source proaram when it processes your file Linas 6 and 5 of the display above The Excess available memory message is useful for Letting you know how clase you are to running out of memory If you do run out of memory during a compilation you see the message Out of memory compilation aborted and COMPIL returns your terminal to AMOS 68 command level When COMPIL has finished processina your file it returns you to monitor level and writes the object program to the disk as a file bearing the name of your source program and a RUN extension However if COMPIL detects errors in the source program no RUN version is output Changed 30 April 1981 INTERACTIVE AND COMPILER MODES Page 2 9 22 2 1 Compiler Options Three compiler options are available fer use with COMPIL 0 T and M To choose an option include the symbol at the end of the file specification that you supply to COMPIL followed by the appropriate option request code For examples COMPIL NEWFIX BAS O GET The compiler mode 0 option is the same as the 0 option for the interac
172. ich are encountered for the first time during the compilation phase Initially the default value of all strings in the absence of a STRSIZ Changed 31 October 19813 PROGRAM STATEMENTS Page 10 21 statement is 10 bytes The statement STRSIZ 25 for instance causes all newly allocated strings which follow to have a maximum size of 25 bytes instead of 10 bytes This includes the allocation of string arrays The size value is evaluated at compilation time and therefore must be a single positive integer 10 27 WRITE The format is WRITE file channel expression List Writes a record to a random access file It is discussed in detail in Chapter 15 AlphaBASIC File I O System 10 28 XCALL The format is XCALL routinet argument1 argument2 argumentN Executes an external assembly language subroutine Assembly language subroutines are discussed in detail in Chapter 18 Calling External Assembly Language Subroutines For information on the assembly Language subroutines available for use with BASIC programs see the BASIC Programmer s Information section of the AMOS Software Update Documentation Packet Changed 31 October 1981 CHAPTER 11 BASIC FUNCTIONS The following is a list of the currently implemented AlphaBASIC functions Functions compute and return a value and are elements of an expression The function either operates on or is controlled by the argument which is enclosed in parentheses There are
173. ider expanding it so that it does This is for two reasons 1 you will be using the same number of physical disk blocks whether or not you expand the record Size so you re not saving anything by not doing so and 2 this Leaves you room for future expansion of the data in the record l When you are opening a random file you must specify the logical record size in the OPEN statement also specifying RANDOM mode it is possible to get things fouled up if you do not have the record size correct No logical record size is maintained within the file structure itself This fact does make it nice in one respect a file which is accessed by many programs can have its record size expanded without recompiling all the accessing programs Here is how Assume as an example that you have a file which i8 considered the parameter descriptor file for all other files in the entire system This file gives the record size as 190 bytes for the vendor name and address file ALL programs which reference the vendor file first read this parameter file to get the size of the vendor file logical record The programs then set the size into a variable and use this variable in the OPEN statement for the record size Each READ or WRITE statement then manipulates the 100 bytes of data by reading or writing to or from variables whose size totals 100 bytes Let s say you now want to expand the file to 120 bytes and that most of the programs do not have to make use of the extra 2
174. ied name and default extension of BAS If the extension RUN is specified the object code is saved on the disk with the program name and extension RUN A 2 12 SINGLE STEP LINEFEEDO Press linefeed key Executes the current program Line and returns you to interactive mode A 5 ALPHABASIC STATEMENTS Statements are used within the source program Some of them may be used as direct statements Note that those statements that accept a file specification accept it as a string literal for example DSKO INIT BAS enclosed in quotation marks as a string variable for example FSPECH or a string expression for example MIDSC A 1 6 which evaluates to a valid file specification SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 6 ALLOCATE filespec number of hlocks Allac a random file on the disk with the specified number of disk blocks Then you can use the OPEN statement to open the file for random processing amp 3 2 CHAIN CHAIN filespec Causes the current program to be deleted from memory and the program with the specified filename and the optional device name and extension to be tas f e loaded into memory and executed Closes the specified file No further reading to or writing from that file is allowed until another OPEN statement for that file is processed Ail files are automatically closed at program completion A 3 4 DATA DATA datad dataN Stores numeric constants or string Lit
175. if the buffer is not yet full This mode is intended to make it easie for people to use FLOCK and similar locking routines The command format for using RANDOM FORCED mode is OPEN Hfile channel filespec RANDOM FORCED record size recordi t variabie For an explanation of OPEN refer to the next section 15 3 1 OPEN You must open a file be TAE you can transfer data to or from the file The OPEN statement assign a unique file channel number to a file and also specifies the name that Ee either to be given to an output file or to be used in locating an input file The general format is OPEN Hfile channel filespec mode record size record variable The parts of this OPEM command are defined as follows Changed 30 April 1981 ALPHABASIC FILE 1 0 SYSTEM Page 15 7 file channel Any numeric expression which evaluates to an integer from 0 65535 0 is defined as the user terminal and treated as such If the file is randem you cannot use 0 as the file channel filespec Any string expression which evaluates to a legal file description May be a string variable or string Literal If it is a string literal remember to enclose it in quotation marks mode Specifies the mode for opening the file INPUT Opens an existing sequential file for input operations OUTPUT Creates a sequential file for output operations RANDOM Opens an existing random file for random read write INDEXED Opens an ISAM data file and pr
176. igits and so round off error occurs The error was only visible because our program set the number of significant digits to 11 The usual number of significant digits is six Such errors can accumulate and present themselves when you do a Large number of multiplications and divisions using decimal fractions AlphaBASIC incorporates a scaling feature which helps to alleviate this problem by storing all floating point numbers with a scale offset This offset designates where the 11 absolute accuracy digits are located in relation to the decimal point BASIC does this by multipiying every input number by the scaling factor and then dividing it out again before printing Changed 31 October 1981 SCALED ARITHMETIC Page 14 2 Cea Comey a EE ET t This is a simplified explanation and many other checks and conversions are done internally to scaled numbers The coral im me i o REP ne scaling factor represents the number of decimal places that the 11 digit Haad O e AE ES hide t a H i X window is effectively shifted to the right in any floating point number For example the most common application is in a business environment where 2 the scaling factor of 2 would be used to give absolute 11 place accuracy to number which extend 2 places to the right of the decimal point This means that value of 50 12 is multiplied by the scaling factor of 2 digits 100 and stored as the floating point value of 5012 Since this valu
177. imary index file INDEXED EXCLUSIVE Opens an ISAM data file and primary index file for exclusive access APPEND Opens a sequential file so that you write data to the end of it RANDOM FORCED Opens an existing random file At time of next disk access reads specified block from disk whether or not it is already in memory or writes specified block to disk whether or not buffer is full The remaining two options must be used for RANDOM RANDOM FORCED INDEXED and INDEXED EXCLUSIVE modes only Recordesize n expression which dynamically specifies at run time the Logical record size for read write operations on the file Recordit variable non subscripted numeric variable which must contain the record number of the desired random access for READ or WRITE statements when they are executed Jt must be a floating point variable Any attempts your program makes to read or write to a file which has not been opened result in the error message 10 to unopened file in Line nnn and the program is aborted The filespec string may be as brief as the name of the file in which case it is assumed to have an extension of DAT and to CChanged 31 October 1981 ALPHABASIC FILE 1 0 SYSTEM Page 15 8 reside in your disk account The filespec string may be a complete file specification if you desire giving the explicit Location of the fite which may be in another disk account or even on another disk drive Some examples are O
178. indeed RUN either explicitly or by default the specified BASIC program is loaded into memory and executed If you do not specify a device and account BASIC follows the search pattern outlined in Section 3 10 Library Searching in Looking for RUN files If you do specify a device and account BASIC Looks in the spetified area ALL variables in the new program are first cleared to zero prior to execution Also all variables in the current program are set to zero for null if strings The BASIC program that you specify must be a compiled RUN file Some examples of Legal CHAIN statements are CHAIN PAYROL CHAIN PAYROL RUN CHAIN DSKT sPAYROLE 101 137 Due to the fact that programs are compiled and not interpreted there is no way to execute a program at any entry point other than its physical beginning There is also no internal method for passing parameters between programs but you can accomplish this function for yourself by using the BASIC assembly Language subroutine COMMON to store data in a common memory area COMMON allows you to store information either in system memory where programs run by all users on the system can access the information or an individual user s memory partition where only programs run by that user can DWM 00700 07 REV BOG CHAINING TO BASIC AND SYSTEM PROGRAMS Page 16 2 access the information For details on using COMMON see COMMON BASIC Subroutine to Provide Lommon Variable Storage i
179. ine is edited In this mode you are in BASIC and can use AlphaBASIC s unique program debugging features To execute a program in this mode you must first load in or create in memory your uncompiled source program After you have finished compiling and executing the program you are still in BASIC and are not returned to monitor Level until you use the BASIC command BYE Compiler mode allows you to compile programs from the monitor level without ever entering BASIC You first create the source program a BAS file using one of the system text editors Then from the AMOS monitor Level you compile the program The compiler automatically saves this compiled version of your source program called the object program on the disk as a RUN file the file is available for execution then or Later using the AiphaBASIC run time package RUN PRG After you execute the object program from the monitor level the run time package returns you to monitor level INTERACTIVE AND COMPILER MODES Page 2 2 Whether you use interactive or compiler mode the resulting object program is re entrant and may be loaded into system memory for use by multiple users 2 1 INTERACTIVE MODE Perhaps the major advantage of interactive mode is that it allows you ta talk to BASIC while you are creating or editing your program You are free to enter entire programs which will be executed when you use the RUN command or you can enter single statements outside of a program f
180. ing the value of zero DWM OD100 01 REV BOS CALLING EXTERNAL ASSEMBLY LANGUAGE SUBROUTINES Page 18 6 The format of each 10 byte block describing one argument is as follows Entry 1 One word containing a variable type code Bits 0 3 contain the type code for the specific variable O unformated 2 string 4 floating point 6 binary 7 through 17 are currently unassigned Bit 4 is set to indicate the variable is subscripted or cleared to indicate the variable is not subscripted Other bits in the type code word are meaningless Entry 2 One Longword containing an absolute address of variable in a user impure area This address is the first byte of the variable no matter what its type or size might be Entry 3 One Longword containing the size of the variable in bytes Note that the above descriptions also apply to the expression arguments except that the results are located above the address specified by AS instead of below it The argument list is built in free memory directly above the currently allocated user impure area A4 amp points to the word immediately following the last word in the argument List You may scan the argument List and determine its end either by decrementing the count word at the base of the List or by scanning until the scan index reaches the address in A4 18 3 5 Converting Arguments to Binary Format A standard subroutine GTARB is provided in the system subroutine Library SYSLIB LIB to assist in conver
181. ipted variable Variables defined in a MAP statement are MAPI through MAPT6 variables Variable type is the type of the variable and may be UNFORMATTED STRING FLOATING POINT or BINARY If the variabie is an array the dimensions are listed after the variable type code in the format ARRAY n n n where n n n are the values of the subscripts in use by the array If the array is dynamic and has not been allocated yet the subscript values are replaced by the Letter X to indicate that they are not known at this point Remember that any variable defined in a MAP statement which is in a lower level relative to another variable inherits all subscripts from that higher level variable The size of the variables are given in decimal bytes In the case of arrays the size represents the size of each single element within the array The Location of the variable is a Little tricky to explain si actually an offset to the base of a storage area that is set the allocation of user variables As each new variable or array is allocated it is assigned a location which is relative to the base of this storage area The location information given here is an example to help you understand the relative placement of the variables in the mapping system and does not represent the actual memory Locations which they occupy There are two distinct areas in use for variables and thus the offsets of the variables are to one of these two areas ALL FIXED and MAPI thro
182. is returned depending on the current value of the seed this jis the normal mode A 4 1 10 SGNOO Returns a value of 1 O or 1 depending on the sign of the argument X Gives 1 if X is negative 0 if X is 0 and 1 if X is positive oWwM DO100 01 REV BO4 SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS d Page A 15 A 4 1 11 SQROD Returns the square root of the argument X A A 1 12 STROO or STRSOO Returns a string which is the character representation of the numeric expression X No Leading space is returned for positive numbers amp 4 2 TRIGONOMETRIC FUNCTIONS The following trig functions are implemented in full 11 digit accuracy SINOO Sine of X COS OO Cosine of X TANOO Tangent of X ATNOO Arctangent of X ASN OO Arcsine of X ACS OO Arccosine of X DATNCX YO double arctangent of X Y A ga S CONTROL FUNCTIONS The following control functions test certain file conditions and control and re eturn information about certain system operations A 4 3 1 DATE The DATE system function sets and returns the two word system date You cannot set the DATE on the AMOS L system expression sets system date to expr DATE 5 DATE treturos system date into A A 4 3 2 TIME The TIME system function requires no argument and is used to set and retrieve the time of day as stored in the system monitor communications area The time is stored as a two word integer representing the number of clock ticks since midnig
183. ist If the file already exists you can go ahead and open it if you want BASIC to delete the existing file for you or you can choose another file name and use the LOOKUP command again to see if that file already exists mS Use the OPEN statement to open the file for OUTPUT Begin using PRINT statements specifying the file channel number associated with the file by the OPEN statement to write data to the file When finished use the CLOSE statement to close the file USING SEQUENTIAL FILES FOR INPUT la 2 5 ise the LOOKUP command to see if the file already exists Cif it doesn t exist double check your file names Use the OPEN statement to open the fiie for INPUT Begin using INPUT LINE or INPUT statements to read data from the file specifying the file channel number associated with the file by the OPEN statement Check the EOF function after each input to make sure you haven t read beyond the end of the file When finished use the CLOSE statement to close the file USING SEQUENTIAL FILES IN APPEND MODE Use the LOOKUP command to see if the file exists Use the OPEN statement to open the file for APPEND Use the PRINT statement specifying the file channel number ssociated with the file by the OPEN statement to write data to he end of the file H E a t hen finished use the CLOSE statement to close the file Changed 30 April 1981 ALPHABASIC FILE 1 0 SYSTEM Page 15 6 USING RANDOM
184. it for a total of 42 bytes Normally this area would follow the 48 byte ARRAY area in memory but the origin parameter in statement 200 causes it to overlay the first 42 bytes of the ARRAY area instead Statements 300 330 define another array area of a different format with 6 elements each element being composed of one 2 byte binary variable CODE and one floating point variable RESULT The origin parameter in statement 300 also causes this area to overlay the ARRAY area exactly Cautions The above scheme allows variables to be referenced in a different format than when they were entered into memory If you load the 8 elements INDEXCTI through INDEX 8 with floating point values and then reference the variable STREET as a string you get the first four floating point variables INDEX 1 through INDEX 4 which Look very strange in string format Below is a practical example of the use of the origin parameter The program below translates the binary data stored in the system DATE Location into floating point form 10 The system stores the date in binary form the small program 15 below translates the binary date into floating point form It 20 also allows you to set the system date from within BASIC 25 MAPT BINDATE B 4 30 MAPT FILLDATE SGBINDATE 35 MAP2 MONTH B 1 40 MAP2 DAY B 1 45 MAP2 YEAR B 1 50 BINDATE DATE 55 PRINT Month MONTH Dayi DAY Yearz YEAR 60 INPUT Enter Month Day Year MONTH DAY YEAR 65 D
185. ith sequential files 4 3 74 KILL KILL filespec Erases the specified file from the disk A file can be killed without beina opened or closed Only files in your account or project can be killed LET variable expression ig a value to a variable Use of the actual word LET is optional 22 LET A21 may be written A 1 A 3 16 LOOKUP LOOKUP filespec variable Looks for the specified file If found the specified variable assumes the number of disk blocks the file contains 1f not found the specified variable assumes O If the file is sequential variable contains positive number if file is random variable contains negative number A 5 17 ON ERROR GOTO and RESUME ON ERROR GOTO Label iinef ON ERROR GOTO 07 Disables further error trapping RESUME label linef RESUME Branch to area of program resumption Branch to l ne causing error As a result of a program error control is transferred to the specified ab ar Line number for processing In the error trapping routine the statement RESUME causes the program to resume at the statement causing the spror or at the Label or line number specified In the case of a Control C the program resumes at the statement immediately following he one that was interrupted by the Control C Changed 30 April 1981 SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 10 A 3 18 ON GOSUB or CALL ON expression GOSUB Label Line 1 label line 2 label line N ON expression CALL Lab
186. le FIL TH BASE 1 le is record number one not c argument with FILEBASE tells BASIC that the first record in the fi record number zero You may use any numeri Note that FILEBASE does not associate its value with a file but only takes effect when you execute the program it is in If one program uses a FILEBASE command when referencing a file all other programs which reference that file should also use a FILEBASE command with the same value 15 3 7 INPUT Once a sequential file has been opened for input you may use a special form af the INPUT statement to read data from the file The INPUT statement uses a file channel number corresponding to the file channel assigned in the OPEN statement The variables in the list may be either numeric or string variables but must follow the format of the data in the file being read Weird results occur if you attempt to read string data into a numeric variable or vice versa The general format of the INPUT statement is INPUT file charnel variablet variable variablen Changed 31 October 1981 ES ALPHABASIC FILE 1 0 SYSTEM Page 15 11 During the reading of the input data into the variable List all Leading Spaces are bypassed unless they are enclosed within quotes just as in the normal form of the INPUT statement Also all carriage returns and Line feeds are bypassed allowing the file created by the PRINT statements to contain formatted line data if desired Commas space
187. le es variablen Allows data to be entered from your terminal and loaded into specific variables at run time The INPUT statement contains one or more variables separated by commas If you omit the optional prompt string BASIC displays a question mark on the terminal display to signal a request for data entry If you provide the prompt string BASIC displays it instead of the question mark to prompt the user of your program for data NOTE If you wish to suppress a prompt altogether use a null prompt string for examples INPUT UULQAS BT Your prompt string must be in the form of a string literal that is it must be enclosed with quotation marks For example INPUT Enter your account number ACCOUNT NUM Enter your account number You may specify both numeric and string variables in the INPUT statement A numeric variable requires that the data entered be in one of the acceptable floating point formats String variables require that the data be an ASCII string of characters Some examples of valid INPUT statements are INPUT A INPUT Enter account name and age NEW ACCOUNT NAMES AGE INPUT U UAB C INPUT Enter positive number NUMBER INPUT QC8 If you specify multiple variables in the INPUT statement you are expected to enter multiple items of data If the data being entered is numeric vou may separate data items with commas or spaces If the data being entered is string you must separate data items with commas I
188. mand code must be ifisd as the argument The codes are transmitted to the terminal E TOV file in SKOsD1 6 which dees the actual interpretation and performs the special our terminal The following list gives the standard decimal for all the terminal drivers supported by Alpha Micro fede Function 0 Clear screen and set normal intensity 3 Cursor home move to 1 1 upper left corner g Cursor return move to column 1 without ijne feed 3 Cu unsor up one row 4 Cursor down one row DWM 00100 01 REV BO4 FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 15 12 5 Cursor Left one column 6 Cursor right one column Lock keyboard amp Untock keyboard 9 Erase to end of iine 10 Erase to end of screen 11 Enter background display mode reduced intensity 12 Enter foreground display mode normal intensity 1 Enable protected fields 14 Disable protected fields TS Detete Line 16 Insert iine 1 Delete character 18 Insert character 19 Read cursor address 20 Read chracter at current curser address 21 Start blinking field 2d End blinking field 25 Start iine drawing mode 24 End iine drawing mode 25 Set horizontal position 26 Set vertical position 27 Set terminal attributes 28 Cursor On 29 Cursor Off The actual routines that perform the screen controls are in the specific terminal drivers and not in ALphaBASIC itself Not all terminal drivers have all of the functions above simply because not all terminals are a
189. marks The word PRINT may be replaced with the question mark symbol Changed 30 April 1981 SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 11 A 3 22 PRINT USING variable expression USING format string PRINT USING format string expression list PRINT expression USING format string For formatted output where the characters are specifically positioned The string contains one or more special formatting characters to control the printed output such as character placement field size leading asterisks floating dollar signs numeric sign commas exponential format and numeric string size The List is made of the expression s you want printed A 5 23 RANDOMIZE RANDOMIZE Resets the random number generator seed to begin a new random number sequence starting with the next RNDOO function call 4 3 24 READ and RESTORE READ variablel variable2 variablen Assigns next group s of data in dedicated memory to variable s RESTORE Readies data in the dedicated memory area for rereading from the beginning of the data pool READ and RESTORE along with the DATA statement enable data to be an integral part of the program The data in the data pool is drawn consecutively from the dedicated memory area by READ and assigned to the respective READ statement variable until either data is exhausted or no further READ statements occur If data is exhausted using RESTORE reinitializes the data pool See the DATA statement above RE
190. mbers given in the message Invalid filename The specified filename was not a Legal filename Invaiid subroutine version The subroutine specified in the XCALL statement is not the correct type for the processor L or T you are running on invalid syntax code n internal error has occurred in BASIC Please notify Alpha Micro of this error Provide an example of what caused it 10 to unopened file The program tried to write to or from a file that was not open Line number must he from 1 65534 The Line number entered is not in the legal range of Line numbers Line x not found The specified Line was not found for a DELETE LIST etc Nested INCLUDE files are not permitted Your program contains a INCLUDE command that specifies a file which also contains a INCLUDE command NEXT without FOR A NEXT statement was encountered without a matching FOR statement No breakpoints set There are currently no breakpoints set in your program No source program in text buffer You tried to compile when there was no program in memory Operator interrupt You typed a Control C to interrupt program execution DWM OOT00 01 REV B04 MESSAGES OUTPUT BY ALPHABASIC l Page B 5 Out of data A READ statement was encountered after the data in all DATA statements had been used Out of memory BASIC has run out of memory in which to execute your program Out of memory Compilation aborted COMPIL is telling you that it does not have
191. ments Program statements are either contained within a BASIC program or are used for immediate compilation and execution at the interactive command Level for immediate compilation and execution of a statement enter the statement without a Line number Statements entered following Line numbers any integer between 1 and 65534 inclusive are used to build a source program in memory on a single line basis BASIC automatically adds the single ines to the source program in the numeric order of their Line numbers Entering a line number alone and then a RETURN deletes the Line associated with that Line number from the source program 2 interactive system commands Commands result in controlled actions by BASIC which can affect the source program in memory files on the disk and the system itself Commands are never entered into the program as statements Tf vou attempt to do so AlphaBASIC responds with an error message Statements are covered in detail in Chapter 10 of this manual The remainder of this chapter details the available interactive commands tne corresponding actions performed and shows examples as you would actually see them Most of the interactive commands are entered after the prampt READY We distinguish the commands you may enter by the fet symbol which means type a RETURN INTERACTIVE COMMAND SUMMARY Page 9 2 9 1 BREAK This is a debugging feature not usually found in other versions of BASIC It takes the
192. mple 10 FOR I 1 TO 10 PRINT THIS IS A LOOP NEXT 1 The normal rules apply for instance a DATA statement cannot contain other statements on the same Line and no other statements may follow a comment designated by the REM or keywords Direct statements may also be multiple statement Lines You should always use spaces around the colons since BASIC will otherwise try to treat two commands e g PRINTsPRINT as a label and a single command The one situation where you do not have to use spaces around the colon that separates two statements is when you are in NOEXPAND mode See Section 3 8 for information on EXPAND and NOEXPAND modes 3 2 CONTINUATION LINES COMPIL allows the use of continuation Lines within the source programa That is statements may be continued on the next Line by using the ampersand 8 symbol as the Last character on the Line However you must not assign a Line number to a continued Line Since any statement Line may be indented as you please in the compiler mode considered use of continuation Lines and indentation plus optionally eliminating Line numbers Cas discussed in the next section enables you to give your source program a much more structured Look than allowed by more conventional SASICs or AlphaBASIC in the interactive mode For examples Changed 31 October 198 GENERAL INFORMATION Page 3 2 IF TIME 50 60 CLKFRQ 10000 gt 120000 amp AND TIME 60 60 CLKFRG 10000 lt 130000
193. n and are omitting the GOTO keyword The above formats may be nested to any depth and rather than go into detail we suggest that you experiment with them to determine the actual restrictions that exist Some examples TF A 5 THEN GOTO PROGRAM EXIT IF AsS GOTO PROGRAM EXIT IF A gt 14 THEN 110 ELSE GOTO 220 IF B z END PRINT END OF TEST TF TOTAL gt 14 5 GOTO START IF P 5 AND Qu6 IF R PRINT 567 ELSE PRINT 56 ELSE PRINT NONE IP A PRINT 1 ELSE IF B THEN 335 ELSE GOTO 345 IF A AND B THEN PRINT A and B are nonzero Note that the expression evaluated by the IF statement is usuallv an expression that contains relative operators e g IF A s B IF A gt 9 etc However the expression may be any legal expression For example D B 1 IF 8 THEM PRINT B is not zero Hou IF B AND A PRINT nonzero numbers ELSE PRINT at least one zero number When the IF statement evaluates the expression it returns either a zero for false or a 1 number for true and conditionally performs the specified operations in response to that evaluation Changed 31 October 1981 PROGRAM STATEMENTS Page 10 10 NOTE A multi statement Line may take the place of a single statement in an IF THEN statement For example IF A 3 THEN PRINT 4 PRINT 5 ELSE PRINT Answer is Q If A equals three the statement above prints amp 5 Otherwise 1t prints Answer is 0 INPUT prompt string variablel variab
194. n be used in place of RUN PRG SON Micro dealers may rename RUNSML to RUN PRG But if you error message you know you have the RUNSML version of its name gt Your pro am tried to write on a write protected device Wrong number of subscripts The number of subscripts specified is not the same as the number defined in the DIM or MAP statement for the subscrioted variable bwM 00100 REV BOS APPENDIX RESERVED WORDS Below is a list of the reserved words used by the BASIC compiler Some of these reserved words designate routines that have not been implemented at this time However you must not use any of these reserved words as variable names or labels NOTE This restriction applies to string variables as well as numeric variables For instance ENDS and ENB are both illegal variable names ABS absolute value ACS arccosine ALLOCATE allocate file AND Logical AND APPEND write to end of seauential files ASE ASCII value ASN arcsine ATN arctangent BREAK set breakpoint BYE exit to monitor BYTE memory byte CALL call subroutine CHAIN chain next program CHR character value CHRE character value CLOSE close file COMPILE compile program CONT continue execution COS cosine DATA data statement DATE system date DATN double arctangent DEF define function DELETE delete Lines DIM dimension ELSE else END end of program EOF end of file EQV logical equivalence ERF file error ERR error stat
195. n entered we compile it COMPIL SAMPLE RET After we compile the program and before we run it we first use the program ISMBLD to build the ISAM files LABELS IDA the data file LABELS IDX the primary index file and HASH IDX the secondary index file Note that we build an empty ee 1 e we type a RETURN after the Load from files prompt We use the BASIC program below to place data into the file ISMBLD LABELS RET ition of key 1 D Size E record 67 RET Number of records to allocate 50 GED per index block 10 RED index blocks to to allocate 20 RET im y Directory Y Ret Data file device BET r SISNBLD HASH o Size of key 10 GED a record 67 BET records to allocate 50 RET per index block 10m index blocks to allocate 20 RET ary Directory NN Secondary index to file LABELS BET cords Loaded On T AMOS L system you are not asked how many entries per index block ISAM does this for vou and informs you of the number Now before we run our ne program we must load ISAM into memory OAD DSK ISAM PRGLT 43 Use LIT on AMOS LO RED On the AMOS L system vou would use ISAM SYS Then we run our BASIC program RUN SAMPLE GEL DWM DO100 01 REV BOM USING 500 510 520 530 540 550 260 570 580 590 600 610 420 630 660 650 660 670 TSAM FROM WITHIN BASIC Page 19 15 WRITE 1 LABE
196. n others the use of these extended versions allows the programmer a wider range of applications greater ease in programming or greater efficiency and speed ALphaBASIC is iust such an extension of the BASIC Language with several features not found in other implementations These features not only enhance the performance of traditional uses of the Language but also make business applications easier to program For instance programmers familiar with COBOL s powerful hierarchial data structures will appreciate AlphaBASIC features which make data manipulation and assembly Language subroutine Linking similarly convenient Floating point hardware in the processor is fully supported greatly increasing the speed of mathematical computations ALlphaBASIC runs in one of two modes interactive or compiler mode Interactive mode operates much Like a traditional interactive interpreter that is you create alter and test your program which resides totally in memory This mode is convenient for the creation and debugging of new programs or the dynamic alteration of existing programs Compiler mode is more useful for programs which are to be put into production use or for testing programs which are too Large to fit in memory in the interactive mode In compiler mode you compile the program at monitor level and store the compiled object code on the disk During the actual running of the compiled program only the object cade and a minimal run time execution
197. n record NEXT l GOTO See if user wants to Look again Time to leave program READ EXIT PRINT PRINT Closing display file CLOSE 3 E ND B Subroutine to display information in record DISPLAY INFO PRINT PRINT CUSTOMER dz ID NUM m s NAME PRINT SPACECS Street address SPACE C7 STREET PRINT SPACECS City s CITY SPACECS State STATE PRINT SPACE CSO Car model MODEL Car year YEAR PRINT SPACE S IF CINSURANCE RE Hos ee 0 PRINT No insurance ELSE PRINT Car is insured Make sure we re not trying to add data to a full file IF IN USE TOTAL RECS THEN PRINT Pile is full GOTO EXIT Clear NAME to null so we can test to see if user wants to quit NAME zx UU Start entering data Pad it to proper length with sp aces so that complete Logical record comes out to exactly 64 3 bytes Changed 31 October 1981 ALPHABASIC FILE 1 0 SYSTEM Page 15 17 945 INPUT Customer name NAME IF NAME GOTO EXIT 950 NAME NAME SPACECZO LENCNAME 955 INPUT Street address STREET 280 STREET STREET SPACE 15 LENCSTREET 965 INPUT City CITY 970 CITY CITY SPACECT2 LENCCITY 975 INPUT State STATE 980 STATE STATE SPACEC2 LENCSTATE 985 INPUT Car model MODEL 990 MODEL MODEL SPACECTO LENCMODEL 995 INPUT Car year YEAR 1000 YEAR YEAR SPACEC4 LENCYEAR 1005 INPUT Car insurance Y or N
198. n the BASIC Programmer s Information section of the AMOS Software Update Documentation Packet In addition to sharing informatio on You can use the common area to pass parameters to the chained program for example the current program can pass a parameter to the new program which it uses in an ON GOTO statement to execution at some point in the new program based on the value passed parameter Another way to make sure that chained programs can share information is the use of disk files The current BASIC program can open a data file write the variables it wants to share into that files and then close the file When the new file is chained in it can open the file and read the necessary information 16 2 CHAINING TO SYSTEM FUNCTIONS It is sometimes desirable to transfer execution to a system function or a command file from a BASIC program If the extension of the file in the CHAIN statement is not RUN the file is a soc eee or system command file a PRG Com the AMOS L system LIT 00 0r GMD file In this case the AlphaBASIC run time package ratas a dummy command file at the top of the current user partition and transfers control to the monitor command processor The monitor then interprets this dummy command fiie as a direct command and executes it Note that thedummy command file created by the run time package is merely the one line name specified im the CHAIN statement It is not the command file itself which 4s the t
199. n your terminal display For example throughout this document you see an underlined dot which indicates the prompt symbol that the operating system prints on your terminal when you are at AMOS command level Carriage return symbol The symbol marks the place in your keyboard entry to type a RETURN Ci e hit the key labeled RETURN For example BASIC ET tells you After an AMOS prompt type BASIC and a RETURN Indicates a Cantrol character If you type a Controi C in the compiler mode of AlphaBASIC for instance you see a C on your terminal display Refer to the AMOS User s Guide DWM Q0100 35 for more information on Controi characters Changed 30 October 1980 CHAPTER 1 INTRODUCTION TO ALPHABASIC The acronym BASIC stands for Beginners All purpose Symbolic Instruction Code BASIC is a higher level programming language created to be a versatile tool for Learning computer programming and also to provide a relatively simple language for a wide variety of applications But today BASIC is more than a learning tool or a beginner s tool for higher level programming It can be said that most programming on small interactive systems is done in BASIC This is in part because of the inherent similarity of BASIC to the English Language Over the years since its inception BASIC has been added to and modified as new concepts of programming have emerged Some implementations of BASIC are more extensive tha
200. night so that in the example below CLOCK would equal 1 You are responsible for conversions to printable format in those cases where it fs peguired One clock tick represents one interrupt from the CPU Line clock which is usually 60 hz for domestic systems and 50 hz for overseas systems Dividing the time by the clock rate gives the number of seconds since midnight Converting this to current time is then accomplished by successive divisions by 60 to get minutes and again by 60 to get hours On the AMOS L system you cannot set the time The TIME expression command will be ignored TIME expression isets time of day in system to expression A TIME ireturns time of day in clock ticks into A DWM 00100 07 REV 204 SYSTEM FUNCTIONS Page 12 4 The small program below converts the value returned by TIME into actual hours minutes and seconds 100 T TIME Get time 720 CLOCK 40 Clock frequency in Hz 150 HOURS INT T CCLOCK 3 Compute hours 140 MINS INTCT CCLOCK 2 CHOURS 60 Compute minutes 150 Compute seconds 160 SECS INT T CLOCIO CCHOURS 60 2 MINS 600 170 H MOD Adjust HOURS to 24 hour clock range 180 IF HOURS gt 23 THEN HOURS HOURS 24 GOTO H MOD 190 PRINT HOURS USING UHIU 28 s MINS USING BO amp i SECS USING 2 There are a couple of things yeu should note about the program above Ts 53 The value CLOCK will vary depending on whether your system operates
201. nitial value of the variable the default is zero for numeric data and null for strings Origin ds an optional reference to a previously defined variable s Location in memory which permits overlaying of variables in memory MEMORY MAPPING SYSTEM Page 8 3 If you skip an element in the MAP statement for example you want to specify the value but don t want to specify the gize you must retain the comma indicating the missing element For examples MAP 1 NEW VARIABLE F 23 the MAP statement above defines the variable NEW VARIABLE assigns if the data type F for floating point does not assign it a size and does assign it the initial value of 23 Without the extra comma BASIC would think that you were trying to assign a size of 23 bytes to NEW VARIABLE an illegal operation for floating point variables 8 2 1 MAP Level MAPn represents the level of the mapped variable It must be within the range of MAPI through MAP16 MAP statements are hierarchial in mature For example a variable mapped with a MAPI statement may consist of several sub variables mapped via a MAPZ statement Each of those variables may in turn consist of several variables mapped via a MAPS statement And so on up to MAP S MAP16 represents the Lowest level or innermost variable MAPI represents the highest level variable You do not need to map levels in strict numeric sequence for example a MAPS statement may follow a MAPS statement without an interv
202. nt form 10 1 The system stores the date in binary form the small program 15 below translates the binary date into floating point form It 20 i also allows you to set the system date from within BASIC 25 MAPT BINDATE B 4 30 MAPT FILLDATE BINDATE 35 MAP2 MONTH B 1 40 MAP2 DAY B 1 5 MAP2 YEAR B 1 50 BINDATE DATE 55 PRINT Month MONTH Day DAY Years YEAR 60 INPUT Enter Month Day Year MONTH DAY YEAR 65 DATE BINDATE 70 PRINT Month MONTH Day DAY Year YEAR The 10 system function allows the 286 1 0 ports to be selectively read from or written to in both cases only one byte is considered and an output expression greater than 255 merely ignores the unused bits The range of ports available is O to 255 t a M 1000 lt expr gt writes the low byte of expr to decimal port X 1000 reads decimal port X and places the result into A the AMOS L system if x is 0 255 it accesses the 256 external IO i does on the AM 100 T the addresses on the AMOS L system are FFF If the number is 256 511 it accesses the internal IO ports addresses FFFEDO FFFEFF 3 12 4 amp MEMUD Returns a positive integer value which specifies the decimal number of bytes ently in use for various memory areas used by the compiler system The common use of this is to return the number of free bytes left in the memory partition This MEMCO call duplicates the action performed by FREQX function in ot
203. oaded via this automatic dure S Therefore if a subroutine is to be called a Large number of times it js wise to load it into memory using the monitor LOAD command to avoid the overhead of fetching the subroutine from disk NOTE Subroutines Loaded into memory via the monitor LOAD command remain in memory until you reset the system or until you use the monitor command DEL to delete them DWM 00100 07 REV BOS CALLING EXTERNAL ASSEMBLY LANGUAGE SUBROUTINES Page 18 5 18 2 SPECIFIC INFORMATION FOR AMOS SYSTEMS 18 2 1 Register Parameters The following registers are set up by the run time system to be used as required by the external subroutine They may be modified if desired since they have been saved before the subroutine was called RO Indexes the user impure variable area RO is used throughout the run time system to reference all user variables Details on the format of this area are not available at this time RO may be used as a work register R3 Points to the base of the argument List R3 may be used to scan the argument list for retrieval of the argument parameters R Points to the base of the free memory area that may be used by the external subroutine as work space This is actually the address of the first word following the argument List in memory and if desired may be used to store a terminator word to stop the scanning of the argument List l R5 This is the rithmetic stack index used by the run
204. ogram are LOOKUP ALLOCATE OPEN CLOSE READ and WRITE Notice that we also use the extended TAB functions to clear the screen and position the cursor and use the MAP statement to define all Logical records and variables used in the program t SAMPLE PROGRAM TO CREATE AND ACCESS A RANDOM FILE t This program simulates a very simple information management system Notice that we use MAP statements to map all variables used in the program although this is not strictly necessary Cexcept for the definition of the Control record and Logical record templa ates it l is handy to have all variables defined at the front of the program i Control record that contains info about file MAI HEADER RECORD TAL RECS F i Total number of records in file N USE F Number of records in use ILLER S 52 Filler bytes needed to pad record i to 66 bytes 2S HIDE Logical record 64 decimal bytes i MAPI CUSTOMER INFO 5 mar NAME S 20 Name and address 0 2 STREET S 10 5 MAP2 CITY S 11 00 MAP STATE S 2 108 MAP ID NUM F i Customer ID number 110 MAPZ TARTINFO 1185 MAPS MODEL S TO Information about car 120 MAPS YEAR Sp 125 MAPA INSURANCE B 1 Does owner have insurance 130 135 Miscellaneous variables used by the program 140 MAPT BLOCKS F of disk blocks used by file 145 MAP BYTES F 8 of bytes used by all records 150 MAPT REC STIZE F 6 64 af bytes in record 64 decimal
205. one it starts over again with the first zone on the next Line If you end the PRINT statement expression list with a semicolon or comma BASIC does not output a carriage return line feed when it finishes displaying that expression List This will make the output resulting from the next PRINT or INPUT statement to appear on the current display line The next output will appear in the next print zone if the current PRINT statement ends with a comma or the next output will appear immediately following the Last character of the current PRINT Statement if the PRINT statement ends with a semicolon Here are a few examples of the PRINT statement for illustrative purposes we are assuming that AS is HERE and A equals 7 PRINT ields a blank Line PRINT A iYields 7 PRINT AS i iebds HERE PRINT 142 ivields 3 PRINT ANY TEXT Yields ANY TEXT PRINT NOTE THE COMMA AS Yields NOTE THE COMMA HERE YOU ARE NUMBER gt A Yields YOU ARE NUMBER 7 YOU ARE W APSUIN CLASS Yields YOU ARE 7 IN CLASS PRINT THERE ARE iSemicolon suppresses carriage PRINT A DAYS LEFT Ireturn Linefeed and yields I THERE ARE DAYS LEFT Remember that the symbol is an abbreviation for the PRINT keyword You may also use the PRINT statement for writing data to sequential files it takes the forms PRINT gfile channel expression list For details on this refer to Chapter 15 AlphaBASIC File 1 0 System 10 20 PRINT USING The formats
206. one of these CX variables references a 12 byte unformatted tem composed of the Cl D1 pair of the same subscript This type of formatting would be useful in sophisticated techniques only The following defines a more complex area 100 MAPT ARRAYT 110 MAP2 UNITX SO 120 MAP3 SIZA B 2 130 MAPS SIZB B 2 140 MAP3 NTOT F 150 MAPS FLAGC 1O B 1 160 MAPS CNAME S 20 170 MAP2 TOTAL F 180 MAP1 THING F 190 MAPT WORK1 X 40 The area that is allocated by the above statements requires a total of 252 bytes of contiguous memory storage Three levels are represented in various formats Statement 100 defines a Level 1 unformatted area called ARRAYT which is subdivided into two Level 2 items Statement 110 defines the first of these which is an area called UNITX The optional dimension indicates that five of these identical areas exist which must be referenced in the program by the subscripted variable names UNITX 1 through UNTTX 5 Each one of these areas is then further subdivided into five level 3 items statements 120 160 Since the level 2 is subscripted because it occurs 5 times so must each of the level 3 items be subscripted There are 5 variables named SIZAC1 thru SIZACS occurring once in each of the respective variables UNITK 1 thru UNITXCS The same holds true for the MEMORY MAPPING SYSTEM Page 8 10 variables SIZB NTOT and CNAME Statement 150 however creates a special case since it co as a dimension also Normally this wo
207. or occurred INTERACTIVE AND COMPILER MODES Page 2 6 2 1 4 hebugging Features unigue feature which is very useful for debugging programs is the single step command Every time you type a line feed alone on a line BASIC Lists and executes the next program statement At that point you can inspect variables or alter their values before yeu continue program execution via the CONT command or typing another Line feed Note that any change in the source program results in BASIC re compiling the program before the next single step command is actually carried out See Chapter 9 Interactive Command Summary for more information on single stepping programs and an setting and clearing breakpoints 2 COMPILER MODE Compiler mode consists of using the disk based compiler COMPIL and the run time package RUN at monitor level to compile and execute programs without entering BASIC Although you do not have the interactive features of AlphaBASIC available ta you in compiler mode you do have the advantages of being able to compile source programs that are too Large to fit into memory and of reducing the amount of memory you need to compile and execute programs Remember that interactive mode keeps the BASIC interactive compiler the run time package and your source program all in memory at the same time When vou compile a program in interactive mode the object code also resides in memory On the other hand in compiler mode only COMPIL
208. or MIDSCAS X U 11 76 8 RIGHT AS or RIGHTSCAS X ccunsecen 11 7 9 SPACECX or SPACESQQO oononnscoranass 117 I0 STROO or STREOO isti ve An e ane 11 7 TV TUCS CAG GENE back P AUR Ba was css des ilr Changed 31 October 1981 ALPHA BASIC USER S MANUAL E Page vi CHAPTER 12 SYSTEM FUNCTIONS 12 1 BYTEOO AND WORDOO ssenaasasnsnasaseosnannse LET Le DATE a wk XA omana AUG EAE ER REA EE Vere Peed TOCK qaskka ue a x Td A acr RW ER TOTO leat MEMO pc a is DE 12 3 12 5 TIME Pom OW of oS Rob POR Ke RFR mom mon WoW ROW Rom O NOR OR BOR He BOR m P He en CHAPTER 13 FORMATTING OUTPUT PRINT USING AND EXTENDED TABS 15 1 THE USING MODIFIER oooosonnsnonsnesenenssosa 12371 13 2 FORMATTING CHARACTERS oonenonsoononansonasasa 1572 13 2 1 The Symbol CString Fields 133 13 2 2 The Symbol One character String Field 2oocosos 13 4 3 The Symbol Numeric Fields 13 4 amp The Period Symbol Decimal Point 15 5 5 The Symbol Floating Dollar Sign i n hh 135 6 The Comma Symbol Floating Commas 13 7 7 The Symbol Asterisk FILO conose T5 7 8 The Z Symbol Leading Zeros sasaesnsea Tan 9 The Minus Symbol Trailing Minus Sign aso oaonasososona 1378 13 2 10 The Symbol Exponential Format ono oncorsonsanos 1378 13 3 FORMATTING EXAMPLES AND HINTS cwenaccsenennene 1378 13 4 EXPANDED TAB FUNCTIONS o ononanconsosssanenona 12711 CHAPTER 74 SCALED ARITHMETIC fha SCALE scenh eee ee eek O
209. or direct execution You can interrupt a program and since you are stili in BASIC can display and change variable values and then resume program operation You will probably be most interested in using interactive mode if the interactive nature of the compiler is of particular use to you for example if you are new to AlphaBASIC and want to try out various statements and smali programs or if a program is in an early development stage and you want to make use of interactive mode s debugging features One disadvantage in using interactive mode has to do with memory requirements Your source program your object program and BASIC PRG all reside in memory at the same time In addition BASIC Loads into memory the BASIC run time package RUN PRG The BASIC PRG file itself is fairly Large since it contains a compiler as well as the code that allows it to simulate an interactive interpreter This all means that using BASIC in interactive mode uses up more memory than compiling and executing a program outside of BASIC Because BASIC PRG is re entrant you may place it in system memory to save room in user partitions If you do so you may also want to place RUN PRG in system memory However since BASIC is a fairly Large program you probably will only want to put it in system memory if most of the users on your system do a great deal of BASIC program development To use interactive mode at monitor Level type BASIC followed by a RETURN BASIC
210. or read operation and deliver back a result to be used in the expression evaluation 12 1 BYTEOO AND WORDOO The BYTE and WORD system functions allow you to inspect and alter any memory Locations within the 64K memory addressing range of the machine These operations have often been called PEEK and POKE statements in other implementations of BASIC The BYTE functions deal with 8 bits of data in the range of 0 255 and the WORD functions deal with 16 bits of data in the range of 0 65535 inclusive Any unused bits are ignored with no error message Note that these commands are not protected it is possible to cause severe damage to the operating system in memory if you use the commands improperly BYTEOO lt expr gt writes the low byte of expr into decimal memory Loc WORDOO lt expr gt iwreites the iow word of expr into decimal memory Loc A BYTE OO treads decimal memory loc X and places the byte into WORDOOD lreads decimal memory loc X and places the word into DWM 00100 01 REV BOG SYSTEM FUNCTIONS Page 12 2 12 2 DATE The DATE tem function is identical to the TIME function except that it sets and returns the two word system date On the AMOS L system vou cannot set the DATE function The system will ignore a DATE lt expr gt command DATE lt exor gt isets system date to expr A DATE returns system date into A The following progra transiates the binary data stored in the system DATE Location into ionge poi
211. or returns you to ALphaBASIC if you are ih compiler mode an error returns you to the monitor Use of the ON ERROR GOTO and RESUME statements causes immediate action to be taken to recover from errors detected within the program 17 1 ON ERROR GOTO STATEMENT Error trapping is enabled and disabled by using the ON ERROR GOTO statement in one of two forms The first form specifies a line number Cor label within the program When the program encounters this ON ERROR statement it stores the Line number and sets a flag enabling error trapping If an error occurs any time after this BASIC transfers control to the routine specified by the Line number or Label Examples of this form of the statement are ON ERROR GOTO 500 ON ERROR GOTO TRAP ROUTINE The error routine must then take appropriate action based on the type of error The second form of the statement disables further user error trapping by specifying a line number of zero or leaving the iine number off completely ON ERROR GOTO O ON ERROR GOTO After executing the above form if an error occurs the program prints the standard error message and aborts the program run A special case exists when the above statement is encountered within an error recovery routine prior to executing the RESUME statement In this instance the user error trapping is disabled and the existing error is forced to be processed by BASIC s error hahdling as if no error trapping ERROR TRAPPING Page 17 2
212. other special be input Also INPUT LINE accepts blank Lines as input The statement may be used in sequential file processing as well as dard terminal INPUT statement You will usually use INPUT LINE ina one string variable to read in one Line of the file at a time See Section 10 12 for more information on INPUT LINE the sta 5 i M 3 9 PRINT sequential file for output vou will write data to it with a eens form of the PRINT statement using a file channel number which to the file channel assigned in the OPEN statement ALi the Tenes available to you when you use the normal form of the PRINT which outputs to the terminal are alsa available far sending fite including PRINT USING for formatted data PRINT writes data in the same format as it would appear if you used PRINT to senc a terminal display i e 1f you left off the file channel tlowing are the format and some examples of the PRINT statement Once vou heve opened a f COPTRe Soar number PRINT file channmel expression List 75 cr w ot i 1D u d 31 October 1981 ALPHABASIC FILE I O SYSTEM Page 15 13 PRINT 1 Ag Bz C PRINT H USING AG A SQRLA PRINT 801 USING PHAR HE e AICI PRINT 4 THIS IS A SINGLE LINE PRINT 2 WRITE TQ PRINT ZONES Section 15 3 7 explains the required format for data when you are using the INPUT statement to read the data from the file For more information an PRINT see Section 10
213. package need to be in memory thereby conserving space The compiler and the run time package are both written as reentrant programs This means that in a timesharing environment any or all users who are running or INTRODUCTION TO ALPHABASIC Page 1 2 debugging programs may optionally share one copy in system memory of the compiler and the run time package Once created by the compiler the object programs also known as compiled programs are also totally re entrant and sharable thereby further reducing memory requirements if several users desire to run the same application program ALphaBASIC supports floating point string binary and unformatted data formats ALL data formats may be simple variables or array structures in addition the unique memory mapping system allows you to specify the ordering of variables im prearranged groupings for more efficiant processing This system is similar to the data formatting capabilities of the COBOL Language and Lends itself well to business applications where the manipulation of formatted data structures is of prime concern Variable names are not Limited to the single character and single digit format of many BASICs but may be any number of alphanumeric characters in Length as long as the first character is alphabetic This is another feature which makes AlphaBASIC well suited for business applications Since the source code is compiled and need not be in memory when the program is eventually run th
214. pecification including device name filename and extension and account number The default extension is BAS If the file you specify is not found the system error message Cannot OPEN Filespec file not found SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 3 is returned to you When the file is found the system begins to process the file At the end of the compilation process a new file has been created in your account called by the filename and with the extension RUN This is the compiled program A 1 3 Contral C Type a CONTROL and a C simultaneously C Operator interrupt in line nnnn of FILE RUN A Control C interrupts the execution of the program currently running Returns you to AMOS command Level Antah RUN RUN filespec RET The program commences At this command the monitor loads the ALphaBASIC run time package RUN into memory and executes it RUN in turn Loads the fully compiled program which is specified having the extension RUN into memory and executes it Your program begins to run from the beginning Interruptions to the program may occur if there is an error in programming if there is a STOP statement in the program if you type a Control C during execution oF if the program finishes A 2 ALPHABASIC COMMANDS The commands are used in the interactive mode of BASIC to control BASIC itself A 2 1 BREAK BREAK Line 1 Line 2 l ine N ists all breakpoints set if no Line
215. pening Brace al Line Closing Brace Page b 5 APPENDIX E SAMPLE PROGRAM NUMERIC CONVERSION FOR BASES 2 16 This appendix contains a sample AlphaBASIC program that converts a number between one number base and another You may convert numbers from the binary through hexadecimal 2 16 number bases to another number base in the same range For example you can translate an octal number to its hexadecimal form or vice versa Below is a sample run of the program CONVRT CONVERT BETWEEN NUMBER BASES A A merce eean Enter positive i am ay base from 2 to 16 A BASE RUN Maen 364 RET RASE 2 NUMBER 101101100 FROM BASE 0 BET a The program 10 CONVRT PROGRAM TO CONVERT BETWEEN NUMBER BASES 100 MAP IN VARIABLES INPUT BASE VARIABLES 105 MAP IN NUMBER S 50 input number string 110 MAP2 IN BASE F base of input number 2 through 16 valid 200 MAP1 OUT VARIABLES I OUTPUT BASE VARIABLES 205 MAP2 OUT NUMBER S 50 toutput number string 210 MAP2 OUT BASE F base of output number i through 16 valid SOO MAPI VALID DIGIT S 16 0125456789ABCDEF VALIO DIGITS base x contains x leftmost 1 digits Changed 523 April 19813 SAMPLE PROGRAM NUMERIC CONVERSION FOR BASES 2 16 Page E 2 900 MAPT MISC VARIABLES 905 910 915 920 925 930 1000 1005 1010 1015 2000 2005 MAP2 BASETO NUMBER F MAP2 ERROR FLAG F MAP2 LEADING BLANK F MAPZ LOOP 1 F MAP2 LOOP
216. point types and 2 for binary types The size parameter of floating point variables must be 6 or omitted 8 2 5 Value An initial value may be given to any mapped variable except an array variable by including any valid expression in the value parameter This value may be a numeric constant a string constant or a complete expression including variables Remember however that the expression is resolved when the MAP statement is executed at run time and the current value of any variable within the value expression is the one used to calculate the assignment result MAP statements may be executed more than once if you desire to reload the initial values Note that if you omit the size parameter such as for floating point variables but you use the value parameter there must be an extra comma to indicate the missing size parameter MAPI PI F 5 14159265359 MAPI HOLIDAY S 9 CHRISTMAS The first example preloads the value 3 14159265359 into the floating point variable called PI The second example preloads the letters CHRISTMAS into the string variable called HOLIDAY 8 2 6 Origin In some instances it may be desirable to redefine records or array areas of different formats so that they occupy the same memory area For instance a file may contain several different record formats with the first byte of the record containing a type code for that record format The origin parameter allows you to redefine the record area in the differen
217. r Numeric argument a a s e a Numeric conversion a s a Numeric function s a a a Numeric significance sa Numeric variable s saas Binary Sos 4 b d e wo floating point a e Ilnfeger ww vue aec a a 9 String x oom m Ck Re Unformatted Object code s a s e s a e Object file a a a a Changed 31 October 1981 INDEX ms s m e s x a as gt a a C e Re x L rR gt a s s R8 a s e on a a e e s m s s a a a R e e s Li R LES 3 e E e LIE a e e won s a g e 2 u s a a x s oc e a gt a 9 c E e e a e gt gt 2n sc 2 3 11 2 A 14 11 3 amp 14 bre 15 3 8 5 10 4 3 4 15 9 A 9 Bel to B 2 4 1 i 8 11 B 3 to B 4 B 6 8 2 ii wo i i od d i 3 j 1 wong Di se AR do CR d OR Oh Pd PS i ARS A 16 pr H ct o A j RE i i T 1 11 6 A 17 7 2 to 7 3 11 1 11 5 2 1 to 2 2 2 8 4 i PI g PQ Om Eq LIE i j PO QU o A XA 9 DO L4 o4 nO un d O00 00 DO Oe Co OO O0 O Ch i 8 1 j E amp 1 2 4 9 6 A 5 104 A 7 B 3 to B 5 5 4 4 1 8 5 6 2 10 10 11 4 11 7 Ant 11 1 aed Est 11 1 10 20 4 Q 4 2 6 72 B 4 hele 6 1 8 4 4 72 6 3 6 72 8 4 Ami 6 3 Bek let 9252 9 73 2 3 Page Index 6 ALPHA BASIC USER S MANUAL Object program s sa ON CALL S Qux ee
218. r bit is the sign of the mantissa The next 8 bits represent the signed exponent in excess 128 notation aiving a range of approximately 2 9 10 39 thru 1 7 10 38 The remaining 39 bits contain the mantissa which is normalized with an implied high order bit of One This gives an effective 40 bit mantissa which results in an accuracy of 11 significant digits DATA FORMATS Page 6 2 6 2 STRING FORMAT The string format is used for the storage of alphanumeric text data String variables require one byte of storage for each character and may be fixed in nosition using the memory mapping system If a string is shorter than the maximum Length a null byte is stored following the Last character to terminate the string NOTE When AlphaBASIC compares a string of spaces and a null empty string it sees them as equal This is by design and demanstrates how AlphaBASIC compares strings If two strings are of equal length AlohaBASIC compares the strings on a character to character basis if they are of different lengths AlphaBASIC pads the shorter of the two with spaces until the strings are of equal length and the comparison proceeds For exampie the string PAST DUE is equal to the string PAST DUE e As you can see using this algorithm causes a null string to be treated as a string of spaces during comparison The proper way to check for a null FRE string is to use the LENS function rather than to see if it is equal to 1f LENS string
219. r you For example if your logical record size is defined as 3100 bytes then each black on the disk contains 5 logical records with the Last 12 bytes of each block being unused Therefore the most efficient use of random files comes when the logical record size is a power of 2 that is it divides evenly into 512 bytes 32 64 128 etc 15 2 2 Blocking Factor and Record Size Random access files are preallocated once using the ALLOCATE statement which gives the number of physical Si byte blocks to allocate It is up to you to calculate the maximum number of logical records required in the file and then to calculate how many disk blocks are required to completely contain the number of Logical records you desire For instance assume the Logical record size is 100 and you need a maximum of 252 logical records in your file Each disk block is 512 bytes and therefore contains 5 logical records You need 252 logical records so dividing 252 by 5 gives 50 full disk blocks plus 2 logical records remaining Since the fiie must be ALPHABASIC FILE 1 0 SYSTEM Page 15 4 allocated in whole disk blocks you need 51 blocks which gives you a maximum of 253 Logical records These Logical records are referenced in Ai program as records Res 252 since the first record of any random fil is record D unles you have used FILEBASE See Section 10 6 FILEBASE nj NOTE When souk record size does not divide evenly into 512 bytes it is a good idea to cons
220. ram You h M ave specified a DELETE command without specifying what Line cs D s are to be deleted Device does not exist The device you specified in a file operation OPEN LOOKUP etc does not exist Changed 30 April 1981 MESSAGES OUTPUT BY ALPHABASIC Page Bez TDevice driver must be loaded into user or system memory If you are accessing a non DSK device the appropriate device driver must be loaded into user or system memory Device error An error has occurred on the referenced device Device full The specified device has run out of room during a WRITE CLOSE or A ALLOCATE operation Remember that an ALLOCATE requires contiguous disk space so that a Device full error may occur when there are still a number of non contiguous blocks available Device in use The specified device is currentiy assigned to another user Device not ready The specified disk is not ready for use Disk not mounted The specified disk has not been mounted Mount it via the MOUNT monitor command or via the XMOUNT subroutine Divide by zero Your program attempted to perform a division by zero Duplicate Label Your program has defined the same Label name more than once kee End of Program You have reached the end of the program during single stepping Enter CR to continue You have reached a STOP statement in your program You may tinue from the STOP statement via a carriage return or may rt the run via a Con
221. rd naming conventions of BASIC ALL variables not defined in a MAP statement are then automatically assigned storage in sequence for total compatibility with existing standards The mapping system has another distinct advantage for complex programs in its allocation of arrays With the MAP statement you have the ability to override the standard array allocation scheme and to force the allocation to proceed in amore flexible manner Conventional BASIC array elements must all be of the same data type AlophaBASIC allows several variables of different data types to be combined in a single contiguous array which can provide efficiency in the manipulation of associated data structures 8 2 MAP STATEMENT FORMAT The MAP statement has the following form MAPn variable name dimensions CCCCtypect size value origini where MAPn gives the level of the MAP statement The rest of the elements are optional depending on the kind of variable you are defining for example 3f you are defining an array variable you will include the optional dimensions in the MAP statement Type identifies the data type of the variable if omitted the default is Unformatted Size identifies the number of bytes the contents of the variable will use if vou omit Size the default is zero bytes for unformatted and string data two bytes for binary data and six bytes for floating point variables since such variables are always six bytes long Value is an optional i
222. re executing the program Therefore if you need to compile the source program and then run it you may simply use the RUN command and BASIC will compile and execute the program for you For example INTERACTIVE AND COMPILER MODES Page 2 5 REDY 10 REM This is a small program RET 20 FOR 1 1 TO 5 RED 30 PRINT Little tasks make Large return 40 NEXT I RET RUN RET COMPILE Compile time was 0 13 seconds Little 4 tasks make Large return Little tasks make Large return Little tasks make large return Little tasks make large return Little tasks make large return READY To iust compile the program but not run it use the COMPILE command Far example COMPILE HET Compite time was 0 13 seconds Once the program is compiled the object code resides in memory along with the source program You can write it out to disk as a RUN file by using the SAVE command nd specifying the RUN extension 1 43 1 Compiler Options You may specify the O compiler option to the interactie compiler The 0 option tells BASIC to strip out any references to Line numbers in your compiled object cade It does not change your Source program By removing Line number references from your object program you ensure that your compiled program will be smaller and will run faster However if an error occurs while executing the program the resulting error message will not show the number of the Line where the err
223. rectiy Or if it is not a legal direct statement 2 1 3 Compiling and Running a Program Although interactive mode simulates an interactive interpreter in operation BASIC PRG is a full compiler As you enter a direct statement BASIC compiles it and gives you immediate feedback Whenever you change the Source program in memory BASIC sets a switch that indicates that the program must be re compiled before it is executable again The source program that you have loaded in from the disk or created while in BASIC resides in memory Before you can execute that program it must be compiled Running in interactive mode always involves the compilation and running of a source program which is in memory and never includes running a saved disk object program directly Also in interactive mode you may compile only the program currently in memory NOTE To erase anything in memory in preparation for leading in a new program or creating a new program use the NEW command If you do not erase the program in memory BASIC wili merge the new program into whatever is in memory If any line numbers from the new program duplicate Line numbers of an old program in memory the new Lines will replace the old Lines in memory fo execute the program use the RUN command NOTE If you try to use any of the execution commmands e g RUN or CONT and if the program has been changed since the Last time it was compiled BASIC automatically re compiles it for you befo
224. ric expression which is resolved at run time 19 5 1 The ISAM Statement Codes Below is a fuller explanation of the ISAM codes Some require a relative key as input others return a relative key to be used when accessing the data record This relative key is returned in the variable specified by the OPEN statement for the index file being accessed by the ISAM statement This then sets up the system for an immediate access to the corresponding data record via a READ or WRITE statement Changed 31 October 1981 USING ISAM FROM WITHIN BASIC Page 19 4 Code 1 ISAM searches in the specified index file for the key which matches the symbolic key in the ISAM statement If a match is found ISAM returns the associated relative key so that your program can access the data file If the key is not found ISAM returns an error code 53 see Section 19 8 Error Processing Code 2 ISAM accesses the specified index file and locates the next symbolic key ISAM then returns the corresponding relative key in preparation for a READ or WRITE to the data file tf this ds the first access to the file following the OPEN statement ISAM Locates the first symbolic key If this statement fotlows a previous code 7 statement ISAM Locates the next symbolic key following the code 1 key If there are no more keys in the index file ISAM returns an end of index file error 38 and your program should not access the data file further until ISAM returns a valid r
225. ring Literal or string variable For example ASCC A ASCCASO 11 1 3 EXPOO Returns the constant e 2 7182818285 raised to the power X 11 1 amp FACTOO Returns the factorial of X 11 1 5 FIXOO Returns the integer part of X fractional part truncated 11 1 6 INTOO Returns the largest integer Less than or equal to the argument X The only time you will see a difference between using INT and FIX is if vou are working with negative numbers For example the Largest integer less than or equal to 23 4 1s 23 However the Largest integer Less than or equal to 23 4 is 2 amp 4 FIX would have returned 23 11 1 7 10600 Returns the natural base e Logarithm of the argument X BASIC FUNCTIONS Page 11 3 11 1 8 10610 Returns the decimal base 10 logarithm of the argument X 11 1 9 RNb OO Returns a random number generated by a pseudo random number generator The number returned is based on a previous value known as the seed and is between 0 and 1 The argument X controls the number to be returned If X is negative it is used as the seed to start a mew sequence of numbers if X is zero or positive the next number in the sequence is returned depending on the current value of the seed this is the normal mode The RANDOMIZE statement may be used to create a seed which is truly random and not based on a fixed beginning value set by the system NOTE lf you want to generate a random number greater than or equ
226. rmation on PRINT see Section 310 19 PRINT and Section 15 3 9 PRINT By formatting data we mean the process of adjusting the appearance of data e g by inserting commas or spaces so that it fits the pattern of a specific format string t might help to think of the format string as a template or pattern with which you are going to control the format of your data The USING modifier allows you to apply the format string to your data Using format strings and the USING modifier you can do such things as Line columns of numbers ue by their decimal points insert dollar signs and commas into numeric data to represent dollar amounts Line up numeric and string data within specified fields generate and print leading zeros for numeric data print asterisks instead of leading spaces print numeric data in exponential form etc FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 13 2 The ections below talk about the special formatting characters within the es string that allow you to perform such adjustments The statement expression i gt E4 be i Vari anoles you use the USING modifier take these forms where a numeric or string constant or a numeric or string PE i ous a How o x T variable expression USING format string PRINT expression USING format string PRINT USING format string expression list For example if you want to format the number 2345 678 with the format string SSZS84 9 vou could s
227. rned if X gt LENCAS Astha RIGHTCAS X or RIGHTS AS X Returns the rightmost X characters of the string expression A SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 18 An4 amp 8 UCSCAS Returns a string which is identical to the argument string A with all characters translated to upper case um 4 4 9 VALCAS Returns the numeric value of the string expression A onverted under normal BASIC format rules APPENDIX B MESSAGES OUTPUT BY ALPHABASIC Below is a complete list of all messages output by the AliphaBASIC system 3 i e BASIC RUN and COMPIL along with a brief explanation of each Bitmap kaput Your program attempted a file operation COPEN ALLOCATE etc on a device with a bad bitmap Break at line n The program reached the breakpoint that was set at line n an t continue You have attempted to continue a program which is not stopped at a breakpoint or which has reached a point where it can qo no further e g it has reached an END statement 5 Cannot find xxxxxxx The program xxxxxxx was not found COMPILE RASIC is telling you that it is compiling your program Compile time was x x seconds BASIC is telling yeu how ong in elapsed time not comput ing time it took to compile your programa Copying from xXxxxXX XXX The program you are compiling contains a INCLUDE command This message is displayed as the file specified in the INCLUDE command is copied into your prog
228. rocessing The Logical record which is transferred by the system 1 0 is the one whose record number is currently in the record number variable mentioned in the OPEN statement The format of the WRITE statement is WRITE file channel expression List The variables in the List may be any format but they obviously should match that of the designated record format The data is written into the logical record from the user variables as unformatted bytes without regard to variabile type The data is transferred from each variable until the variable has been completely emptied Then the next variable in the List is Changed 31 October 1981 ALPHABASIC FILE I O SYSTEM Page 15 14 used and so on If the record is Longer than the variable list specifies ali excess data in the record will not be modified An attempt to transfer more data than is in the logical record size results in an error message The most efficient use of random files comes when the variable or variables used are mapped by the MAP statement to the exact picture of the record format in use 15 4 SAMPLE PROGRAM The program below gives a very simple demonstration of Limited data manip putatip Notice that you could easily write modules that would expand its funct to dri deleting customer records changing data dr existing custome r records adding more customer records ta a partially filled file and so on Some of the file handling commands demonstrated by the pr
229. s be forced to one or the other type by use of the STR and VAL functions For more examples of mode independence see the sample programs in Chapter T Substring Modifiers Changed 31 October 1981 Ez CHAPTER 6 DATA FORMATS This chapter discusses the various forms which your data may take Note that if you do not use MAP statements to define your data your variables may only take on fioating point numeric values or string values 1f vou use MAP statements however you have a great deal more versatility in the format of your data and can define binary and unformatted data as well MAP statements also give you a way to define powerful hierarchial data structures that allow sophisticated data manipulation For information on using MAP statements see Chapter 8 Memory Mapping System That chapter alsa discusses how BASIC assigns memory Locations to data 5 3 FLOATING POINT FORMAT ALL numeric variables are assigned floating point format unless specified otherwise in the program The standard precision in use by the Alpha Micro aystem can be called single and one half since it Lies midway between what are known as single precision and double precision formats The reason for this is that the hardware floating point instructions all work in this format Floating point numbers occupy six bytes of storage and are in the format dictated by the hardware instructions Of the 48 bits in use for each byte variable the high orde
230. s aavcascaacexs 4 1 4 Debugaina Features sanonnanasaan o o u ONPILER MODE ara a SI Inn nich eR REIR RISUS AUR 2 1 Creating a Program ano ocononassnonss n 2 295 141 Program FORM dgaewws s x rhon 8 m 2 2 20 fomnilina a Program onoanoonoanon noo 2 2 2 1 Compiler Options waanenneencas 0298 RUANDA PEO quse eiaa RUE WIR i P i i E j i OO UO UD Ch OO Vu ov OA P gt z s i is a J CO 9 BO PO PO PO DO DO PO PO i z HOP O08 o d d CHAPTER 3 GENERAL INFORMATION NI 1 MULTIPLE STATEMENT LINES onoonacoocnnonsonsanos 371 5 2 CONTINUATION LINES cononcasonsencaosarancaosas A Taw LINE NUMBERS like Re RU PX ae Rae EON NW Rede v ME 5 4 COMMENTS CREM AND FIY De ewww e nan een cares 372 5 INTERACTIVE MODE DIRECT STATEMENTS onooononono 573 Sato PROGRAM LABELS Lue wea wee Gre E AW GN VY CE xe E IS Aero MEMORY ALLOCATION sedis aa sa ne 3 8 EXPAND AND NOEXPAND MODES ooononavanoonansanss Ach 3 9 LOWER CASE CHARACTERS osoconcansanananeanesaaona ath 5 10 LIBRARY SEARCHING canccvsnaescesneeeewsnseweas 979 STI INCLUDE FILES uncer aurada E eee eae eka cana ee 5 CHAPTER 4 ALPHABASTC VARIABLES AST VARTABLE NAMES RR E EXE a MI fae NUMERIC VARIABLES e cents ere e te n nr eR PR ETE au STRING QARDTABLES cobs oid sus xa pwE PEN S or as bee 4 4 ARRAY VARIABLES z es a 5 6 ns enneaonane4 ne nnoonoenossu E CHAPTER 5 ALPHABASIC EXPRESSIONS x4 ARITHMETIC EXPRESSIONS iaa Re Rn Ro I 9 20
231. s and end of Line characters all terminate numeric data and then are bypassed As with the non file version of the INPUT statement described in Section 10 11 the data being input must be in the proper format In the case of the file version of the INPUT statement that means you must be aware of the rules for properly separating data when you first write the data out to the file using the PRINT statement Here are the rules to follow when writing data to a file 1 Separate all floating point data with spaces or commas 2 Separate all string data with commas 5 Separate all floating point data and string data with commas Keep in mind the characteristics of the PRINT statement when writing data to a file so that you do not conflict with the rules above Section 10 1 discusses the PRINT statement Using PRINT to send data to a file formats that data in exactly the same way that it would if you were to use PRINT to send data to the terminal screen Remember that PRINT does not separate the data with commas for you For example the following statement PRINT 8100 HELLO AGE DATE sends the following Line to the file HELLO AGE DATE If you try to use INPUT to read that data in the file into three different string variables the first variable will contain HELLO AGE DATE and the other two string variables will contain null data To read the data above as three separate pieces of string data remember ta separate the data by explicitl
232. sult i zero negative or greater than N the program falls through to the next statement The following is a portion of a menu selection program 10 PRINT TABC 22 Select One of the Following Operations PRINT 20 PRINT TABC25 1 Insert Edit NAME Information 30 PRINT TABC25 2 Insert Edit PHONE NUMBER Information 40 PRINT TAB 25 S Quit without insertion or editing 50 PRINT INPUT Your choice 1 2 or 32 A 60 ON A GOTO NAME PHONE QUIT 100 NAME INPUT Select a name N CTHE PROGRAM CONTINUES WITH ALL THREE ALTERNATIVES 10 18 OPEN The format is OPEN Afile channel filespec modet recsize recnum Opens an 1 0 file for processing It is discussed in detail in Chapter 15 AlphaBASIC File 1 0 System Changed 31 October 1981 PROGRAM STATEMENTS Page 10 16 10 19 PRINT The format is PRINT expression iist The PRINT statement telis BASIC to evaluate and display the expressions that you specify For example PRINT Se4 HELLO YOU returns 7 HELLO YOU BASIC prints a carriage return line feed after the expression List Remember that an expression may consist of a string or numeric variable numeric constant string literal function with arguments operator symbols or a combination of these elements for example the following is one string expression STRING DATA NAMES MID AS 1 2 BASIC displays numeric data with a trailing blank It also prints one Leading blank if the number is
233. t gt Changed 31 October 1981 INDEX a a a 5 m amp 2 a a t 8 a R e a EE o E a s LI s amp a a 9 s e a s e a a a R 8 Bo amp E a s e o s mc RON on e w a es 8 e a a 5 ao o a a a e a 2 a s e a a a ea s a ES a a L L e a a a a a Bz a R LI som s Ro o e a a a pod od 1 f ODO 9 BO B3 BO Xu dp Po XWn nm An i py aes to 4 2 i i 10 2 i 1196 fX T 7 2 8 5 19 1 to 19 2 12 1 16 2 13 11 B 3 11 4 A 15 11 4 10 9 A 8 12 2 to 12 3 A 15 1 1 to 1 2 A 7 10 16 19 1 11 3 4 1 18 2 4 1 4 35 5 18 3 13 1 123 1 5 3 11 3 A 18 5 6 5 2 6 1 Page Index 9 ALPHA BASIC USER S MANUAL Variable length a s aaa Variable name Variable tree s a so eau VUE uu ou ae Lu x ume Word boundary s s e s a MORDER aoa a so s o a noa WRITE aom e a Sr aes ek ox XC EL 5 ae ca a ra ds ras L US AMOUNT 43 4 2 w 2 v 3 x03 CONE uiu Vu oae Changed 31 October 1981 INDEX Page Index 10 1 2 1 2 4 1 8 11 2 6 8 4 12 1 A 16 14 3 15 1 15 4 15 7 15 13 19 2 19 6 A 12 8 2 to B 3 18 1 A 13 B 2 10 16 Lowe TECHNICAL PUBLICATIONS FILE REFERENCE AlphaBASIC User s Manual DWM 00100 01 TECHNICAL PUBLICATIONS READERS COMMENTS We appreciate your help in evaluating our documentation efforts Pl
234. t formats to be expected When the record is read into the area the type code in the first byte can be used to execute the proper routine for the record type Each different routine can access the record in a different format by the different variable names in that format ALL record formats actually occupy the same area in memory This feature directly parallels the REDEFINES verb in the COBOL Language data division Using the origin parameter can save arge amounts of memory For instance suppose you have three very large variables of 256 bytes each that define logical records and that you never se these variables at the same time Sy defining the variables so that hey occupy the same area of memory your program only uses 256 bytes for e variables instead of 748 bytes MEMORY MAPPING SYSTEM Page B Normally a MAP statement causes allocation of memory to begin at the point where the tast variable with the same level number Left off The origin parameter allows this to be modified so that allocation begins back at the base of some previously defined variable and therefore overlays the same memory area If the new variable is smaller than the previous one for the exact same size it is totally contained within the previous one If it is Larger than the previous one it spills over into newly allocated memory or possibly into another variable area of the same level depending on whether there were more variables following it Play with this one
235. tain binary and floating point variables will begin on word boundaries for assembly Language Subroutine processing The AM 100 instructian set performs most efficiently when word data is aligned on word boundaries 8 2 2 Variable Name The variable name is the name that your program uses ta reference the mapped variable it must follow the rules for AlphaBASIC variable names However since you may explicitly specify the type you do not need to follow the normal conventions for identification such as requiring that a string variable name be followed by a dollar sign If the variable name is followed by a set of subscripts within parentheses the variable is assigned as an array with the dimensions specified by the subscripts just as if a DIM statement had been used For example the statement MAPT A F assigns a single floating point variable called A but the statement MAP1 A 5 10 F assigns a floating point array with 50 elements in it 5 X 10 just as if the statement DIM AC5 10 had been executed Note that since these mapped arrays are assigned memory at compile time and not at run time the subscripts must be decimal numbers instead of variables 8 2 3 Type Code The type code is a single character code which specifies the type of variable to be mapped into memory The following variable types are implemented in AlphaBASIC unformatted absolute data variable string variable floating point variable binary unsigned numeric v
236. tatements directly in interactive mode outside of a program Functions are elements of an expression which compute and return a value For example ABSOO computes and returns the absolute value of X You may also use functions in combination with program statements directly in interactive mode outside of a program The syntax of the commands statements and functions is illustrated in this appendix using certain conventions The curly brackets and Y are used to enclose options available for certain commands and statements These may be nested several deep Certain commands and statements permit a series of optional elements The elements are numbered 1 through N and the variable number of elements in this available series is pictured using three dots ire For example INPUT prompt string variablel variableZ variablen indicates that your INPUT statement may request an input of a minimum of one numeric or string variable You may also cause it to request two numeric or string variables but if you do the two variables must be separated by commas And so forth to variableN where N is some arbitrary number You may also optionally supply a string Literal prompt string SUMMARY OF COMMANDS STATEMENTS AND FUNCTIONS Page A 2 For the AMOS monitor commands the underlined dot represents the AMOS prompt you see at the AMOS command level The RET indicates that you should type a RETURN at the point where you see the symbol following
237. tem in the index area which contains ali the information needed to define and locate that variable The working storage area therefore contains only the pure variables themselves without any associated or intervening descriptive information The index area is a separate entity physically located before the working storage area 1n memory MEMORY MAPPING SYSTEM Page 8 2 The allocation of the variable storage area for any program is predictable and BASIC normally does it as it encounters each variable during compilation Since this scheme is not easily followed by human beings a different method must be derived which can override normal allocation processes if you wish to have the variables allocated in a predetermined manner Also the disk 1 9 system requires that variables used be in a specific relationship to each other when used in some of the more sophisticated programs The MAP statement has been included in AlphaBASIC for the purpose of allocating variables in a specific manner MAP statements are non executable at run time but merely direct the compiler in the definition and allocation of the referenced variables Each MAP statement contains a unique variable name to which the statement applies When the compiler encounters this statement it allocates the next contiguous space in working storage as required and assigns it to that variable The type of the variable is also specified in this statement and may be used to override the standa
238. that ERE returned a zero For examples IF ERF 2 3 THEN PRINT Record not found GOTO PROMPT IF ERF 2 lt gt O THEN GOTO ISAM ERROR 4 Read the data record with a READ statement The file number must be the number associated with the data primary index file Extract each symbolic key from that record 5 Now you must delete all symbolic keys that are associated with the deleted record tm each index file Use code 4 ISAM statements to do so specifying the symbolic keys you extracted from the data record in the step above amp After you delete each symbolic key check for errors 7 Now go ahead and delete the data record by using a code 6 ISAM statement 8 Check to see that no error occurred 9 Close all files NOTE A good check on the file structure would be to store the relative key in another variable and then compare the relative keys returned by each ISAM code 4 statement to ensure that the symbolic keys all did indeed Link to the correct data record You should also check after each ISAM statement to see if any error occurred USING ISAM FROM WITHIN BASIC Page 19 13 19 10 SAMPLE ISAM PROGRAM The sample program below will make clearer the use of the commands discussed above For more information on using ISAM from within a BASIC program consult the ISAM System User s Guide DWM 00100 06 We first create or enter our program using the text editor VUE We ll call it SAMPLE BAS After the program has bee
239. the disk Now RUN executes your program Upon completion or if you type a Control C to interrupt the program RUN returns you to AMOS command Level DWM 00100 01 REV BO4 INTERACTIVE AND COMPILER MODES Page 2 10 Note that the RUN command serves two different functions depending on whether you are in compiler or interactive mode In compiler mode RUN is a monitor command used to execute a compiled BASIC program that has previously been saved on the disk or loaded into memory The command RUN PAYROL RET will run PAYROL RUN and then exit back to AMOS command Level without ever entering BASIC in interactive mode the RUN command is a BASIC command that compiles and executes the current source program that you are editing and testing when it finishes you are still in BASIC NOTE Do not use the monitor command RUN on files with BAS extensions On the AMOS L system if you try to run a RUN file that was produced on the AM 100 T system or any non RUN file you will get the error message RUN file is in an incompatible format mera Ucero DWM ODTOO 01 REV BO4 CHAPTER 3 GENERAL INFORMATION This chapter gives general information about the form that your ALphaBASIC program may take For example we discuss multiple statement Lines EXPAND and NOEXPAND modes program labels and Line numbers 35 1 MULTIPLE STATEMENT LINES The system supports multiple statement Lines by using colons to separate the statements For exa
240. the program by either a CONT command or a single step command For information on the single step debugging feature see Section 239 12 Single Step Linefeed You may start the program over again by using the RUN command it will once more break at the first breakpoint set n any case the breakpoints remain set after they have been reached until they are explicitly cleared by a BREAK nn command are generally cleared by compiling the program or you leave BASIC 9 2 BYE BYE says goodbye to the BASIC interactive mode and returns your terminal to the AMOS command Level You then see the AMOS prompt Remember that any program left in memory is Lost forever so you may want to save it first using the SAVE command This is the format of BYE INTERACTIVE COMMAND SUMMARY Page 95 BYE 9 35 COMPILE When using COMPILE in the interactive mode do not specify a source program BASIC compiles the current source program in memory The object code is built up in another area of memory The compiled program is not executed instead control is returned to the interactive command mode and you see the READY prompt Compilation sets all variables to zero and deletes all variables that may have been generated as a result of direct statements READY COMPTLE GED Compile time was 7 07 seconds oS tet errr A ArH READY If no program is in memory you get an error message and a prompt READY COMPTLE GED UES AREACODE
241. the second to string and perform concatenation META 4 5 equals ik Td NOTE The above two examples apply only when we are not expecting a particular type of variable or term This generally occurs only in a PRINT expression such as PRINT 34 5 At other times we are expecting a specific type of variable the conversion of the first variable is then performed prior to inspecting the operator plus sign The operation of the plus sign is implicitly specified by the result of the first variable Take the following example 5 de METAS de The multiplication operator forces us to expect a numeric term to follow The 34 string is therefore immediately converted to numeric 34 and multiplied by the 5 The plus sign then performs numeric addition instead of concatenation The result is in numeric format and is converted to string format if its destination is a string The following are a few examples as they would be seen if you were to use them in an actual program 10 A 34 5 20 8 34 S 30 34 5 4G D E rag An nem 50 AS 34 5 60 BS 34 5 70 C 34 5 80 DR 2 maU de gu 90 PRINT ABCD 100 PRINT AS BS CH DS READY RUN eek AA Lec MONS Ld 345 345 METE 345 You can see that conversion is affected by the type of variable being used You might Like to try a few examples of your own on your system to see what the results are Remember any potentially ambiguous expression may alway
242. the text When we use the term filespec we are talking about an AMOS file specification which contains the name of the file and optionally includes a device account and extension specification for instance ibevn tfilenameC extHCUProject programer number 1 A 1 AMOS MONITOR COMMANDS These commands are used only from the AMOS command Level They are illustrated much as you would see them on your terminal A 1 1 BASIC BASIC GED READY Places you in the interactive mode of AlphaBASIC and gives you the prompt word READY From here you may enter certain statements or statement function combinations without Line numbers BASIC responds to valid entries with immediate results Invalid entries cause an error message to be returned You may also enter any valid statements functions constant values variables arithmetic operators strings data or expressions meaning any combination of the above as long as they are preceded by a line number from 1 to 65534 These lines combine to form a BASIC program Line entries invalid due to syntactical errors or illegal formats are reported immediately via error messages Other illegal entries which cannot be detected immediately are reported during program compilation or program run You exit from BASIC back to the AMOS command Level via the BYE command COMPIL filespec RET The file specification may simply be the filename of a BASIC program in your account or it may be a complete file s
243. time system The stack is built at the top of the user partition and grows downward as items are added to it When the external subroutine is called R5 points to the current stack base Since the arithmetic stack may contain valid data the external subroutine must not use the word indexed by RS or any words above it 18 2 2 Argument List Format The List of arguments specified in the XCALL statement may range from no arguments at all to a number Limited only by the space on the command Line To pass these arguments to the external subroutine an argument List js built in memory which describes each variable named in the List and tells where it can be located in the user impure area The variables themselves are not actually passed to the subroutine but rather their absolute Locations im memory are in this way the subroutine may inspect them and modify them directly in their respective locations This does not apply to expressions which are built on the stack as described previously DWM DO0100 01 REV BOA CALLING EXTERNAL ASSEMBLY LANGUAGE SUBROUTINES Page 18 4 R3 points to the first word of the argument list which is a binary count of how many arguments were contained in the XCALL statement Following this count word comes one 3 word descriptor block for each argument specified If there are no arguments in the XCALL statement the argument List consists only of the single count word containing the value of zero The format of e
244. ting an Indexed File Use the ISMBLD program to create a data index file combination If you want a secondary index file use ISMBLD again to create that file While using ISMBLD you may either load the empty data index file with information from an ordinary sequential file or you may leave the file empty and iet your BASIC program enter the data For information on using ISMBLD see the ISAM System User s Guide 19 9 2 Adding Data to an Indexed File From within your BASIC program 1 Open the data index file with an OPEN statement For example OPEN 1 PHONES INDEXED RECSIZE RELKEY Remember to open any secondary index files that you might want to use via separate OPEN statements on different file channel numbers OPEN 3 IDNUM INDEXED RECSIZE RELKEY 37 Use a code 1 ISAM statement ta see if the index entry vou want to add already exists For example ISAM H1 1 NAME Check to see if an error was returned IF ERFCT O THEN PRINT Duplicate name GOTO GET NAME if no error occurred the index entry already exists and you can t add it If you are using secondary index files also check to see that the secondary jad entries don t already exist Now use a code 5 ISAM statement to get the next free data record For example ISAM 7 5 DUMMY c ie r esa Sf data file is full Check to make sure that an err free List is empty did not occur Far example DWM OQTOU O1 REV BOS USING ISAM
245. ting floating point and string arguments ta binary format for processing within an AlphaBASIC subroutine For further Manual DS5 10003 00 information see Appendix C in the AMOS L Monitor Cal 18 53 4 Free Memory Usage When the subroutine is called indexes A4 and AS mark the beginning and end of the free memory that is currently available for use as workspace This area is not preserved by the run time sys tem and the subroutine must not count on its security between XCALL statements Note that the word at 8A4 may be used as the first word but the word at NAS is the base of the arithmetic stack and must not be destroyed The last word of actually free memory is at 2 A5 fhe run time system has its own internal memory management system and does not conform to the AMOS L operating system memory management method DWM OOTOOQ 01 REV 804 CALLING EXTERNAL ASSEMBLY LANGUAGE SUBROUTINES Page 18 7 Therefore the external subroutine must not use the GETMEM monitor calis to generate a block of work space in memory Also if any file calls are to be done they must be done with internal buffers since the INIT call sets up a buffer by using the GETMEM monitor call 18 5 5 Locating Open Files standard library routine FLSET is provided in the system subroutine Library SYSLIB LIB to locate the DDB associated with a file that has been opened by an AlphaBASIC program For further information see Appendix C of the AMOS L
246. ting numeric data the result is always a string This type of format allows you to create headings and image lines that vou use more than once and to inspect and manipulate formatted date before printing it You may not use the USING modifier recursively That is vou may not use a format string that is itself the result of a USING modifier For example if you have specified C B USING vou may not say NS D USING C When using the PRINT USING format remember that PRINT USING differs from the regular PRINT statement in that the use of semicolons to separate the elements of the print List has no effect on the spacing of those formatted elements Below is a sample program that uses the USING modifier to format output into a small report Tt also demonstrates the use of subroutines MAP statements and file handiing FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 13 10 5 Tiny report generator 10 STRSIZ 100 20 MAPI HEADING S 49 V Teme Vo 10 A MEI 30 MAPT MASK S 54 i Vm a SSHHHHRHH HA RZZZ222722 40 l Main Program 50 GOSUB INSTRUCTIONS 60 OPEN 81 REPORT DAT OUTPUT TO GOSUB GET HEADER 80 1 51 90 GOSUB WRITE REPORT 100 CLOSE 7 110 END Display instructions Open file to hold report Get and write header for report Initialize iine counter Get and write data to report Close out file sma bum amm sum yame aime 200 INSTRUCTIONS Display instructions 210 PRINT Welcome
247. tive mode see Section 2 1 3 1 above The 0 option code tells COMPIL to strip gut any Line number references in your compiled object code file This makes your object code file smaller and makes the program run faster but any error messages do not include the number of the Line at which the error occurred The compiler mode T option is primarily for debugging purposes It telis COMPIL to display each Line of your source program as it scans that Line If a problem occurs during compilation you can use the T option to determine the Line in which the problem occurs You can also use T to gauge the speed with which certain statements compile When you use the M option an error message is displayed any time COMPIL encounters an unmapped variable This option aids programmers who wish to verify that all variables have been mapped See chapter 8 MEMORY MAPPING SYSTEM for information on mapping variables 4 2 5 Running a Program To run a program in compiler mode at AMOS command Level enter RUN the name of the RUN program vou want to execute and a RETURN For example ARUN LOOP RE You may supply a full file specification including device name and account number The monitor looks for the run time package RUN PRG in memory if it is not found in system or user memory AMOS loads RUN into memory from the disk RUN initializes memory Looks for your program in memory and if it is not there toads the specified RUN file from
248. trapping There are 33 separate codes A complete List of these codes is found in Section 17 2 1 Error Codes Returned by ERR If X is O ERR returns the specific code of the error detected if X is 1 ERR returns the number of the last program Line encountered before the error occurred If X is 2 ERR returns the file number of the Last file accessed 11 3 4 OTHER CONTROL FUNCTIONS See Chapter 12 System Functions for information on the following functions MEMCXD Returns the number of free bytes BYTECX Enables vou to WORDOD Enables you to bring in system memory in 8 data bits from a memory location in 16 data bits from memory Location DATE Sets or reads the system date 19000 e Enables the 1 0 ports to be read from or written to TIME Sets or reads the system time 11 4 STRING FUNCTIONS The following string functions accept numeric or string arguments and return strings Note that the mode independence feature of the expression processor performs automatic conversions if a numeric argument is used where a string argument is expected and vice versa 11 4 1 ASCOO Returns the ASCII decimal value of the first character in string AS If the string A reads for example Zirconium s atomic number is the result of the statement PRINT ASCCAS is 90 the ASCII value in base 10 of upper case 2 For the statement PRINT ASCC AS O where the argument is between quotation marks and fs the Literal string to
249. trol c Error in Error Trapping An error occurred while you were in the error trapping routine file already exists Your program tried to create a file which already exists File already open You have attempted to open a file that is already open on the same fiie number not found BASIC was unable to locate the specified file 1 E gt Filespec error The file specification you gave in a file operation OPEN LOOKUP etc is im error ALL file specifications must conform to the system standard i e Devn Filename xtensionfp pn1 MESSAGES OUTPUT BY ALPHABASIC Pr beu o Page B 3 File type mismatch Your program tried to perform a sequential operation on a random file or vice versa Floating point overflaw A floating point overflow occurred during a calculation Illegal expression The specified expression is not valid Illegal function value The specified value is not valid for the particular function ILLiegai GOTO or GOSUB The format of the GOTO or GOSUB statement is invalid illegal Line number The specified Line number is invalid esg not between 1 and 6583453 Tllegal NEXT variable The variable in the NEXT statement is invatid e g not floating point Tilegal or undefined variable in overlay The variable specified in a MAP statement overlay via 8 has not been previously defined or is not a mapped variable Illegal PRINT USING format The edit format used in a PRINT USING statement is inv
250. trol the output of your data Characte other than these special e a EE which appear in a format string are output literally as part of your data Changed 30 April 1981 FORMATTING OUTPUT PRINT USING AND EXTENDED TABS Page 15 3 15 2 1 The Symbol String Fields Although you will mast often be interested in formatting numeric data you may also specify fields for string data via the backslash symbol Two backstashes define a string field whose size equals the number of characters enclosed in the backslashes plus the backslashes themselves Although the usual practice is to enclose blanks in the string field e g Hy 103 AlphaBASIC permits the use of any characters Since these characters are never printed but simply define the size of the field by which a string is to be formatted non blank characters serve only as a comment However when using several string fields within a single format string it can be useful to visually separate them from the spaces between the fields by using non blanks within the backslashes For exemple Ne fieldi A field2 V field3 String fields allow you to define the placement and size of string data For example if A z Now is the time then PRINT USING As he once said osa emre sonn VU LAS produces As he once said Now is the time lf the string to be formatted is larger than the string field BASIC ignores the extra characters If the
251. ual pa string Literal Mm Less than or equal NOT Logical NOT zx Less than or equal AND Logical AND gt greater than or equal OR Logical OR gt greater that or equal XOR logical XOR US ING expression formatting EQV Logical equivalence MIN minimum value MAX maximum value Note that AlphaBASIC automatically evaluates expressions for you For example consider the statement PRINT 32x100 2 MAX 25430 54 BASIC evaluates the first section of the expression 42 100 2 which equals 1600 then evaluates the Last section 25430 54 which equals 25 5556 Finally BASIC applies the MAX operator to the parts of the expression DwWM O0O100 01 REV BOA ALPHABASIC EXPRESSIONS Page 5 2 5 2 OPERATOR PRECEDENCE The precedence of operators determines the sequence in which mathematical operations are performed when evaluating an expression that does not have overriding parentheses to dictate hierarchies AiphaBASIC uses the following operator precedence exponentiation unary olus and minus multiplication and division addition and subtraction relational operations comparisons Logical NOT Logical AND OR XOR EQV MIN MAX USING NOTE The USING operator allows you to format numeric or string data using a format string For information on USING see Chapter 13 Formatting Output PRINT USING and Extended Tabs 5 3 MODE INDEPENDENCE Expressions may contain any mixture of variable types and constants in any arrangement ALphaB
252. uch more flexible method for storing and retrieving data in different formats Random files are written in unformatted or packed data mode Random file disk blocks are contiguously allocated on the disk The major advantage of random files over sequential files is the flexibility with which you may access data in a random file You may only open a sequential file for input or output but you may open a random file for input and output simultaneously Accessing data in a sequential file requires that you step through the file record by record In the case of a random file however you may access any record without referring to any other record in that file In addition random files can contain data in any format supported by AlphaBASIC unlike sequential files which may only contain ASCII data 15 2 1 Logical Records ALL program accesses to random files are made via the Logical record approach A Logical record is defined as a fixed number of bytes whose format is explicitly under control of the program performing the access Physical blocks on the disk are each 512 bytes long and each random file must be preallocated as some given number of these 512 byte blocks Logical records may be any length from 1 byte to 512 bytes Logical records can never overlap physical disk blocks The AlohaBASIC I O system automatically computes the number of Logical records that fit into one disk block and performs the blocking and unblocking functions fo
253. ugh MAP16 MEMORY MAPPING SYSTEM Page 8 13 variables are allocated in the fixed storage area while all DYNAMIC arrays are allocated in the dynamic array storage area As dynamic arrays are dimensioned their positions may shift relative to one another and relative to the dynamic storage area base Variables in the fixed storage area never change position relative to each other or to the storage area base Array location information that is given is only pertinent to the base of the array itself which is the location of the first element within the array The actual range of locations used by the array may or may not be contiguous in memory depending on whether overlapped dimensioning techniques are being used in the MAP statements Simple notiarray variables are defined as a location range which telis exactly where the entire variable lies within the storage area Keep in mind that this S command is to assist you in following the allocation of variables particularly in more complex mapping schemes A few minutes at the terminal with direct MAP statements followed by a commands will help vou see how the mapping scheme works 8 5 1 Examples Given the sample MAP statements below 10 MAP1 CUSTOMER ID 20 MAP2 NAME 30 MAP3 FIRST S 15 40 MAPS LAST S 15 50 MAP ADDRESS 60 MAPS STREET S 15 70 MAPS CITY S 10 80 MAR STATE S 2 90 MAP2 PHONE 100 MAPS HOME B 3 110 MAP3 BUSINESS B 3 120 MAP TRANSAC
254. uld create an area of 10 sequential bytes referenced as FLAGCTO thru FLAG IO In our example however this T0 byte area occurs once in each of the higher level areas of UNITX 1 thru UNITX 5 This then implicitly defines a double subscripted variable ranging from FLAG 1 1 thru FLAG 5 10 Statement 170 causes the allocation to return to level 2 where one floating point variable is allocated The total storage requirement for the Level 1 variable ARRAY comes out to 206 bytes as follows 40 bytes for each of the five areas UNITXOD thru UNITX 5 plus 6 bytes for the one variable TOTAL Notice that since TOTAL starts a new level 2 it does not occur 5 times as do the level 3 items which comprise UNITXOD thru UNITXO Following the above group in memory come two more variables defined in statements 180 and 190 THING is a normal floating point variable whic occupies 6 bytes and WORK is an unformatted area whose size is 40 bytes Note that since WORKI was not subdivided into one or more level 2 items a size clause was required to explicitly define its storage requirements Note also that the variable UNITX 1 refers to the 40 byte item comprised of the variables in order SIZAC1 SIZBCD NTOTCD FLAGCT 1 thru FLAG 1 17022 and CNAMECT Moving the variable UNITX 1 to another area such as WORKI transfers the entire 40 bytes with no conversions of any data You may often use MAP statements to define groups of information that will
255. urs ON GOSUB a ON GOTO ON ERROR GOTO s a a OPEN uum ih uw MS Gots Operator 2 2 Operator precedence OUTPUT mode s s a a a Packed binary format Parameter descriptor file Parentheses REEK uS da BP us Percent sign 4 s Physical block a s a Physical memory s a a e POE nanan ai Noc zw cer ake de Pound sign 82 s Precision PRENT Rz ee tay ko ae ce PRINT USING 2 s 5 p Print zone Program compilation Program debugging a Program execution s Program form e gt a a indentation interruption a Label s s a ao LIDE a cc T e le ae te Program statement e a Prompt a w wo Program Program Program Program Program RANDOM mode s s aa Random access disk file Random access file aa RANDOM file type a a aa RANDOM FORCED mode a a Random number s s Random number generator Random number sequence RANDOMIZE a a Range check a s s e gt Re entrant code a s READ 0 ew E dy wee READY 2 le ae how d Record number variable E Is a gt s Ga amp n P gt gt 2 m s b S t Ga 7 s E st d ET we a A D EM es e i m te e din de LJ e s R e Lj LJ a us R R ca seed ma amp 7 amp e a 5 a e Changed 31 October 1981 INDEX a s Li e a e Li Li et a a amp RF
256. us ERROR error EXP exponentiation DpWM DOO0100 01 REV BO RESERVED WORDS EXPAND FACT FILEBASE FIX FOR GO GOSUB GOTO IF a INCLUDE INDEXED INDEXED EXCLUSIVE INPUT INPUT LINE INSTR INT to ISAM KILL LCS LEFT LEFTS LEN LET LINE LIST LOAD LOG LOG10 LOOKUP MAP MAX MEM MID MIDS MIN NEW NEXT NOEXPAND NOT ON OPEN OR OUTPUT PRINT RANDOM RANDOM FORCED RANDOMIZE READ REM RESTORE RESUME RETURN RIGHT RIGHTS DWM 00100 01 REV BOA expand mode on factorial fiie base offset fix loop initiation program jump call subroutine program jump conditional test fetch source code from another fil ISAM file ISAM fite input data input data Line search string integer input output ISAM control kill file lower case string Left string left string tength string variable assignment Line List text load program natural logarithm base 10 logarithm lookup file map variable maximum value memory size mid string mid string minimum value new program Loop termination expand mode off logical complement on GOTO GOSUB ERROR open file Logical OR output print on terminal file random file random file randomize RNB function read data remark Line restore data resume after error subroutine exit right string right string Page 2 e RESERVED WORDS RETURN RIGHT RIGHTS RNG RUN SAVE SCALE SGN SIGNIFICANCE SIN SPACE SPACES SQR STEP STOP STR STRE
257. using the system i editors the printer spooler of the other system utilities To open a sequential file use the OPEN statement specifying either INPUT OUTPUT or APPEND mode Use the PRINT statement followed by a non zero file channel number to write data to sequential files The PRINT statement automatically appends a carriage return Lline feed to your data in the same manner that it does when sending data to a terminal display See Section 10 19 for information on using commas and semicolons to format PRINT statement output Use the INPUT or INPUT LINE statements followed by a non zero file channel number to read data from a sequential file Remember that the INPUT statement reads one piece of data for each variable specified while the INPUT LINE statement Cif you specify a string variable reads into the specified string variable the entire Line of ASCII data up to but not including the carriage return Line feed at the end of the line INPUT and INPUT LINE work exactiy the same for files as they do for terminal input except that vou omit a prompt string and must include a file channel number Changed 30 April 19819 ALPHABASIC FILE I O SYSTEM Page 15 5 Sections 15 5 7 and 15 3 8 talk about INPUT and INPUT LINE Also see Sections 10 11 and 10 12 for more information on INPUT and INPUT LINE 15 2 RANDOM FILES Random access or direct access files are more complex than sequential files but offer a m
258. utine Innermost subroutine Return from Innermost Return from Nextmost Return from Outermost NOTE You should always exit a subroutine via the RETURN statement for that subroutine rather than using a GOTO statement The reason for this is that subroutine processing places certain information on BASIC s stack area if you do not execute a RETURN statement the stack area used by that subroutine is not reclaimed Doing multiple branches out of a subroutine thus results in a stack overflow error message 10 9 GOTO The format is GOTO label or Line number o ad T 50 TO Label or Line number The GOTO statement transfers execution of the program to a new program line This program iine must be identified either by a Line number or a Label somewhere in the program You may use GOTOs to transfer control to a program Line that is either before or after the program Line containing the GOTO statement itself For example 10 Program to demonstrate use of GOTOs 20 PRINT This program computes your account balance Enter a 30 PRINT Control C to stop enter deposits as negative amount 0 INPUT Enter old account balance BALANCE 50 CALCULATE BALANCE 0 PRINT INPUT Enter debit amount DEBIT 70 BALANCE BALANCE DEBIT 80 PRINT Debit was sDEBIT Current balance is BALANCE 90 GOTO CALCULATE BALANCE You can see that Lines 50 through 90 constitute an endless loop in which control is eternally transferred from Lin
259. y placing commas into For examples you must ti he file PRINT 4100 HELLO Up AGE g DATE sends the following Line to the file HELLO AGE DATE which will be input correctly by the following statement INPUT 100 AS BE CS Changed 31 October 1981 ALPHABASIC FILE 1 0 SYSTEM Page 15 12 Note that the statement PRINT 2100 HELLO A 24 T DATE will improperly format the data in the file because the unquoted commas above will cause PRINT to separate the data with spaces as well as commas HELLO 7 24 DATE For more information on INPUT see Section 10 11 Also see the section on INPUT LINE below 15 3 8 INPUT LINE After sequential file has been opened for input the data can be read from the file by a special form of the INPUT LINE statement which uses a nnel number corresponding to the file channel assigned in the OPEN statement The variables in the List may be either numeric or string variables but must follow the format of the data in the file being read Unpredictable results occur if you attempt to read string data into a umeric variable or vice versa The general format of the INPUT LINE statement is fii H Rem hi m INPUT LINE Zfile channel variable INE statement operation is identical to that of the INPUT the exception that input into a string variable accepts the up to but not including the carriage return and Line feed that This allows commas quotes blanks and
260. y string expression which evaluates to a legal file description KILL assumes an extension of DAT If you try to erase a file that does not exist you see the error message File not found You may not erase a file that exists in an account outside of the project you are logged into For example if you are logged into account 110 23 and the program you are running tries to kill a file in account L200 13 you see a protection violation error message 1 5 3 4 LOOKUP The LOOKUP statement Looks for a file on the disk and returns a flag which telis you if the file was found and if so how many disk blocks it contains The format for the statement is LOOKUP filespec result variable As in the OPEN statement the filespec is any string expression which evaluates to a legal file description The result variable is any Legal floating point variable which receives the result of the search The LOOKUP result variable may return 0 File was not found Positive n File was found it is a sequential file and contains n disk blocks Negative in File was found it is a random file and contains n disk blocks Remember that the number returned by LOOKUP is the number of physical disk blocks used by the file You must multiply this number of 512 byte blocks by the file s blocking factor to find out how many Logical records your file contains For example after we execute LOOKUP CNURT DAT BLOCKS the variable BLOCKS contains the number

Download Pdf Manuals

image

Related Search

Related Contents

Quantum FastStor 2 User's Manual  TECDIS Manual EN rev 1_9  PDF herunterladen - Safety-Pro    GGS 16 Professional  mondes d`autres    

Copyright © All rights reserved.
Failed to retrieve file