; ; NAME: FILEIN.M68 ; OBJNAM .SBR ; ; FUNCTION: This subroutine is used to read data from a sequential ; file. It differs from AlphaBasic input in that it does not look for ; control characters in the data; it keeps reading until 1) the buffer ; is full, or 2) the end of the file is returned. It returns the data ; read and the length of the data returned. ; ; CALLING SEQUENCE: XCALL FILEIN,OPTION,AREA{,BUFFER|NAME{,LENGTH}} ; where ; Name Type Use ; OPTION Float 1=open ; 2=read ; 3=close ; AREA X,616 DDB and buffer ; BUFFER Any Returned data (READ call) ; NAME String Filename (OPEN call) ; LENGTH Float Length of returned data (READ call) ; ; AUTHOR: Tom Dahlquist ; ; EDIT HISTORY: ; When Who What ; 01/16/84 TAD Written. ; SEARCH SYS SEARCH SYSSYM ASECT .=0 PRMCNT: BLKW 1 TYPE1: BLKW 1 ADDR1: BLKL 1 SIZE1: BLKL 1 TYPE2: BLKW 1 ADDR2: BLKL 1 SIZE2: BLKL 1 TYPE3: BLKW 1 ADDR3: BLKL 1 SIZE3: BLKL 1 TYPE4: BLKW 1 ADDR4: BLKL 1 SIZE4: BLKL 1 PSECT .=0 VMAJOR=1 VMINOR=1 VEDIT=0 FILEIN: PHDR -1,0,PH$REU!PH$REE CMPW @A3,#3 ; must be at least 3 args... BLO RETURN ; back if not... MOVW TYPE1(A3),D6 ; get type of first... ANDW #7,D6 ; must be float... CMPW D6,#4 ; back if not... BNE RETURN CMP SIZE2(A3),#616. ; right size? BNE RETURN ; back if not. MOV ADDR1(A3),A0 ; get option... FFTOL @A0,D0 ; D1=option... MOV ADDR2(A3),A0 ; A0->DDB... CMPW D0,#1 ; OPEN... BEQ OPEN CMPW D0,#2 ; READ... BEQ READ CMPW D0,#3 ; CLOSE BEQ CLOSE RETURN: RTN ; ; OPEN--clear the DDB, initialize it, open file. ; OPEN: CLEAR @A0,D.DDB ; clear it... LEA A6,D.DDB(A0) ; A6->I/O buffer... MOV A6,D.BUF(A0) ; put into DDB... MOVB #D$INI,D.FLG(A0) ; set INITed... MOV ADDR3(A3),A2 ; A2->filename... FSPEC @A0,DAT ; put filename into DDB, and OPENI @A0 ; open it. RTN ; ; READ--move bytes to buffer until it is full, or file is empty. ; READ: CMPW @A3,#4 ; must have fourth arg... BLO RETURN MOVW TYPE4(A3),D6 ; check type of it... ANDW #7,D6 CMPW D6,#4 BNE RETURN MOV ADDR3(A3),A1 ; A1->buffer... MOV SIZE3(A3),D0 ; D0=length of buffer... DEC D0 ; minus 1 for DBF... CLR D2 ; D2 used as counter... LOOP: FILINB @A0 ; ask for next byte... TST D.SIZ(A0) ; anything left? BEQ EOF ; br if not... MOVB D1,(A1)+ ; move it in... ADDW #1,D2 ; increment counter... DBF D0,LOOP ; and loop. BR SETLTH EOF: CLRB (A1)+ ; clear rest of buffer... DBF D0,EOF SETLTH: MOV ADDR4(A3),A1 ; A1->length variable... FLTOF D2,@A1 ; convert length... RTN ; ; CLOSE--close the file. ; CLOSE: CLOSE @A0 RTN END .