home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
TURBOPAS
/
MAPSTATF.LBR
/
TRANSBUF.LZB
/
TRANSBUF.ÌIB
Wrap
Text File
|
2000-06-30
|
3KB
|
77 lines
{Modified version of
EASYBUFF.PAS ----Easy buffered text output for CP/M Turbo Pascal v.2.00
-sorry, I have long since lost the proper credits for these routines but
they are in my files as public domain material-
These routines work by re-directing USR output to a
buffer which is automatically written to disk when full. }
const zsize = 8192 ; {default 8K buffer}
type outfilename = String[12] ;
var zbuff : array [1..zsize] of char ;
zcount : integer ;
zf : file ;
{------}
procedure bwrite (ch : char) ;
{This replaces the USROUT routine called by write/ln. Instead of going
to the USR device, characters go into a buffer. When the buffer is
full, it is automatically written to disk. Direct bdos calls are
used to write the buffer because using Blockwrite can't be used.
Evidently, Turbo has problems when its i/o procedures call each other.}
var i : integer ;
begin
if zcount < zsize then begin {put char into buffer}
zcount := zcount + 1 ;
zbuff [zcount] := ch ;
end
else begin {handle full buffer}
for i := 1 to zsize div 128 do begin {Flush buffer }
bdos (26, addr(zbuff[1])+128*(i-1)) ; {Set dma addr }
bdos (21, addr(zf)+12); {write 128 bytes }
end ;
for i := 1 to zsize do {re-init buffer }
zbuff [i] := #26 ;
zcount := 1 ; {reset buffer pointer}
zbuff [zcount] := ch ;
end ;
end ;
{------}
procedure initwrite (name: outfilename) ;
{sets up buffer, redirects USR output to buffer, opens output file}
var i :integer ;
begin {initwrite}
zcount := 0 ; {initialize buffer ptr}
usroutptr := addr(bwrite) ; {make our routine the usr routine}
for i := 1 to zsize do {initialize buffer}
zbuff [i] := #26 ;
assign (zf, name) ; {connect to proper file}
rewrite (zf) ;
end ; {initwrite}
{------}
procedure endwrite ;
{Flushes out any remaining characters in buffer, closes file}
var even : boolean ;
sec,i : integer ;
begin {endwrite}
if zcount <> 0 then begin {flush out unwritten buffer}
even := (zcount mod 128 = 0) ;
if even then sec := zcount div 128
else sec := zcount div 128 + 1 ;
for i := 1 to sec do begin {flush buffer}
bdos (26, addr(zbuff[1])+128*(i-1)) ; {set dma addr}
bdos (21, addr(zf)+12) {write 128 bytes}
end ;
end ;
close (zf) ;
end ; {endwrite}
ocedure initwrite (name: