Category : Word Processors
Archive   : BESIDES.ZIP
Filename : SEQREAD1.SEQ

 
Output of file : SEQREAD1.SEQ contained in archive : BESIDES.ZIP
\ SEQREAD1.SEQ Sequential read by Tom Zimmer

\ Link this file into the FILELIST chain.

FILES DEFINITIONS

VARIABLE SEQREAD1.SEQ

FORTH DEFINITIONS

DECIMAL

\ Read sequential lines from a file, delimited by CRLF.

32767 ( 16383) VALUE IBLEN1 \ input buffer length


\ The value of OBLEN can be reduced to 64 if you want to read lines from
\ normal Forth BLOCK files. You should use BLKTOSEQ.SEQ for this though.

255 VALUE OBLEN1 \ output buffer length

0 VALUE INSTART1
0 VALUE INLENGTH1
0 VALUE INBSEG1 \ the input buffer
CREATE OUTBUF1 oblen1 1+ ALLOT \ the line output buffer

VARIABLE FILEPOINTER1 2 allot \ most recent read

HANDLE INFILE1

: .INFILE1 ( --- )
INFILE1 count type ;



: SAVEPOINTER1 ( --- )
INFILE1 curpointer inlength1 0 d- FILEPOINTER1 2! ;

CODE GET_ALINE1 ( --- a1 )
push es \ Save ES for later restoral
mov di, ' instart1 >body \ Searching from instart1
mov ax, # $0A \ Searching for a Linefeed char
mov cx, ' inlength1 >body \ for inlength1 clipped to oblen1
cmp cx, ' oblen1 >body \ if inlength1 > oblen1
> if mov cx, ' oblen1 >body \ clip search length to oblen1
then mov dx, cx \ save search length in DX
cx<>0 if mov es, ' inbseg1 >body \ searching inbseg1 segment
repnz scasb \ Scan for Linefeed char
then sub dx, cx \ DX = length of line
sub ' inlength1 >body dx \ subtract line from remaining
mov outbuf1 dl byte \ set the length of outbuf1
mov bx, si \ save IP for later restoral
mov si, ' instart1 >body \ moving from instart1
add ' instart1 >body dx \ set start to after line
mov cx, dx \ cx = length to move
mov di, # outbuf1 1+ \ moving to outbuf1
mov ds, ' inbseg1 >body \ from inbseg1 segment
mov ax, cs mov es, ax \ to CODE segment
cx<>0 if repnz movsb \ move the line to outbuf1
then
mov ax, cs mov ds, ax \ restore DS
mov si, bx \ restore IP
pop es \ restore ES
mov ax, # outbuf1 \ return address of buffer
1push end-code

: FILLBUFF1 ( --- ) \ Refill the input buffer.
inbseg1 instart1 over 0 inlength1 cmovel
%off> instart1
inlength1 iblen1 inlength1 -
INFILE1 inbseg1 exhread %+!> inlength1
SAVEPOINTER1 ;

CODE ?FILLBUFF1 ( --- ) \ refill INBUF if needed
cmp ' inlength1 >body # oblen1 1+ word
u>= if mov bx, # FILEPOINTER1 \ Set BX to point to FILEPOINTER1
sub cx, cx \ clear CX
mov cl, outbuf1 \ read byte length of outbuf1
add 2 [bx], cx \ Add to 32bit contents
adc 0 [bx], # 0
next
then \ If we got here, then
mov ax, # ' FILLBUFF1 \ go and re-fill the buffer
jmp ax
end-code

: LINEREAD1 ( --- a1 ) \ read a line delimited by CRLF
?FILLBUFF1 \ re-fill buffer if needed.
GET_ALINE1 ; \ returns line including CRLF



: IBRESET1 ( --- )
%off> instart1
%off> inlength1 ;

\ : $HOPEN ( A1 --- F1 ) \ Returns a boolean for open successful
\ INFILE1 hclose drop
\ INFILE1 $>handle
\ INFILE1 hopen
\ ibreset1 ;


: SEEK1 ( d1 --- ) \ Move the FILEPOINTER1 in INFILE1 to the
INFILE1 movepointer ; \ specified by d1.
: SEQINIT1 iblen1 paragraph alloc 8 = memchk nip %!> inbseg1 ;

SEQINIT1


  3 Responses to “Category : Word Processors
Archive   : BESIDES.ZIP
Filename : SEQREAD1.SEQ

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/