Intel 9800758-02 manual Buffers, Defining a Random 1/0 Field-FIELD, Field #3, 20 AS N$

Page 36

Disk File Input/Output

BASIC-SO

Random File I/O

Random I/O requires a bit more care and coding than sequential I/O, but is more flexible because you can move back and forth within a disk file. These are the key differences:

To get data from random disk files to BASIC-80 variables and vice-versa, you must understand how BASIC-80 uses 110 buffer space.

Random 110 operations (GET and PUT) always read or write all 128 bytes of a floppy disk sector. You must specify how this 128-byte string is divided into fields and assigned to string variables.

Because all data in random files is treated as string data, you must convert strings that represent numbers into numeric values if you want to do any calculations with them.· Likewise, if you want to write a numeric value to a ran- dom file, you must first convert it to a string. Special functions are provided to do this.

You must use special assignment statements to put a string variable into an 110 buffer. This is due to the fact that the fields you define in an I/O buffer are of fixed-length; the special assignment statements accommodate variables that are longer or shorter than the specified field.

Unless you simply want to read or write records in sequence, you .must specify which record you want to read or write.

1/0 Buffers

BASIC-80 reserves space for six I/O buffers, each 128 bytes long. One buffer is assigned to each open file (when an OPEN statement is executed). When you read a record from a random file using GET, the 128-byte string is not assigned directly to a variable. It is placed in the 110 buffer assigned to that file, and it is up to you to define what portions of the string are to be assigned to what variable or variables.

To emphasize: the usual variable and line delimiters (", CR) have no special mean- ing. All 128 bytes from the specified sector are placed in the 110 buffer. If fewer than 128 bytes were written to the sector, the remaining character positions in the buffer are set to ASCII blanks (hexadecimal 20) .

Defining a Random 1/0 Field-FIELD

When a sector has been read into the 110 buffer, it exists as a 128-byte string. You must define how the string is to be assigned to a variable or variables. The FIELD statement specifies to BASIC-80 what character positions in the buffer correspond to string variables (initially they must be string variables, because the sector is treated as a 128-byte string).

The FIELD statement tells BASIC-80, for a given file, what character positions, starting with the first, are to be associated with a variable. For example, assume you have opened a random file, assigned it the file number 3 (the OPEN command works just like in sequential 110), and read the first sector from the file. You know that the first 20 characters of each sector contain a name. To assign these 20 bytes to the string variable N$, enter the following FIELD statement:

FIELD #3, 20 AS N$

5-4

Image 36
Contents BASIC-SO Reference Manual A108/0979/7500 FL Preface Page Contents Illustrations Chapter Introduction to BASIC-80 Invoking BASIC-80Examples Introduction to BASIC-80Basic filename MEMTOPaddress FilenameListing the Directory of a Disk Renaming a FileChanging File Attributes Deleting a FileYou can now run, list, or edit the program Save LP ,ACommands StatementsBASIC-80 Commands Contd BASIC-80 StatementsBASIC-80 Statements Contd BASIC-80 FunctionsBASIC-80 Functions Contd Representing Data FunctionsConstants Integer ConstantsDecimal Integer Constants Hexadecimal Integer ConstantsOctal Integer Constants Single-Precision Floating-Point ConstantsDouble-Precision Floating-Point Constants String Constants String VariablesThis is a string constant $ = Enter next data stringL4! = Csng l4 YI,1String Arrays Arithmetic Operators BASIC-SO Operators in Order of Precedence ContdLogical Operators String OperatorNumeric Expressions String ExpressionsEntering and Editing Programs 30 A=8*52 30 A=830 A=8*52 30 A=8*37 30 A--=8xx*522537 Control-R a = 8*37Subcommand Command 3D press 3, then D resultsInteger D If AB thenIf AB then 120 Else Null SET Syntax of the X subcommand is At this point, the other editing subcommands may be usedPrint Undefined SET The E subcommand is entered Integer C character characterMove the cursor to PRINT. Enter 2C RE L Print Undefined SET. Enter a LBASIC-80 Error Messages Syntax Error MessagesOverflow, Underflow, and Divide-by-Zero Error Trapping Trace Facility Error Simulation Error HandlingRestarting Program Execution If line 40 is replaced withOpening a Sequential File Open 1,#1,F1DATESRefer to for further details of Print Using Writing to a Sequential FileReading from a Sequential File If executed four times, it would read all eight valuesClosing a Sequential File Value of R$ would beBuffers Defining a Random 1/0 Field-FIELDField #3, 20 AS N$ Disk File Input/Output Field #3, 20 AS N$, 9 AS SS$Opening and Closing a Random Disk File Reading from a Random 1/0 FileAny of the parameters can be variables To read the next recordWriting to a Random 1/0 File IntegerSingle-precision value Double-precision valueMKI$ Attrib Fdrive numberfilename, W1 Attrib Fdrive numberfilename, WOAuto first lineJ, increment Clear expression,addressCommands and Statements CloseDEF FNX Rules for function name are the same as for variable nameDefsng Defdbl Defstr Defint DIM DeleteError DIREdit ENDError expression ExitField FOR-NEXT-STEPGET GosubFor variable=expression to expression Step expression GET I file number ,record numberIF-THEN-ELSE InputGoto Kill LETLine Input ListLSET, Rset LoadMerge NEWNext 9 16On ... Gosub On ... GotoOpen Option Base OUTPoke Print Using PrintString Fields Numeric fields If X$=SEVEN and Y$=EIGHT, the results of line 40 would bePrun PUTRandomize ReadREM Resume ReturnSave RUN line numberlstring expression ,FLine number RUN filename 60 ENDTRON, Troff ? 5,8,2Wait WidthABS ATNCHR$ CintFunctions Csng CVI CVS10 A# = 1.00/3.00 AO/o =Dskf EOFFIX Ok·Hexs INPInputs INT InstrLEFT$ LEN LOCLOF LOGMID$ MKI$ MKS$ MKD$OCT$ Rights Peek expressionPOS integer RIGHT$ string,integerSGN SINSpaces 10 a =1SPC SPC integerIf A$ = 2 then Print Correct Else Goto SQRexpressionSTR$ expression TAB expressionTAN expression Here is an example of how the USRn statement is used 60 AO/o =Appendix a BASIC-SO Error Codes Table A-I. BASIC-80 Error CodesTable A-I. BASIC-SO Error Codes Contd Appendix B BASIC-SO Reserved Words Page To halt program execution and return to command LevelTo tab across the line To resume program execution after it is stopped byPage Table D-l. Ascii Code List Appendix D Ascii CodesTable D-2. Ascii Code Definition BELAppendixe Calling Subroutines Figure B-1. Internal Representation of Numbers and Strings Some Real Examples RESULT=USR%1VARPTRA, VARPTRB, VARPTRC» PRINTA+B+C= ResultFigure E-2 /8085 Assembly Language Program Figure E-3. PL/M-80 Program Appendix F RMX/SO BASIC-SO Initializing the Predefined RMX/SO BASIC-SO Configuration ISIS-II BASIC-SOTable F-l. Sample Configuration Jumper Wiring OOOOH-OFFFHGenerating Boot-Loaded and PROM-Based Versions BASIC-80 Source FilesBASIC-80 Object Files BASIC-80 Executable FilesGenerating a Boot-Loaded RMX/80 BASIC-80 That are not boot loaded This option is used to allocate memory. It is 1 if the bootSetting baud rates, refer to the RMX/SO Users Guide This option enables your user-written I/O drivers if youISBC 80/20-4 Generating a PROM-Based RMX/80 BASIC-80 Prom F1 RMX820.L1BSTART, & FOBASCM.OBJ,& FORMXBAS.LlB F1 DFSDIR. L1BDIRECTORY ,RENAM E,& F1 MTI810.L1B Configuring DFS on an iSBC 80/10 Adding BASIC-SO to an Existing RMX/SO ConfigurationConfiguration Requirements ISBC SO/10 System ClockPublic Variables Adding User-Written I/O Drivers to RMX/SO BASIC-SO Open 0,#1, L1LlSTFigure F-S. Sample User-Written 1/0 Driver Routine Altering BASIC-80 Workspace Burning a BASIC-80 Program Into PromBaprom F1HEATER.BAS Page Index Ase BASIC-80 RIGHT$,7-1O Request for Readerscomments 111111