[fpc-pascal] Make FPC closer to hardware
Frank Peelo
f26p at eircom.net
Mon Nov 17 12:45:03 CET 2008
leledumbo wrote:
>
> Micha Nelissen wrote:
>
>>....example?
>>
>
> Let Write(Ln) work without file system support? Perhaps just by supplying a
> routine to write one character, and let other write routines use it.
I think it already has what you want there.
Doesn't call a function for each char, though. That was last seen in
TurboPascal 3. TurboPascal v4 introduced Text File Device Drivers. These
do the same thing, but much more efficiently and flexibly.
Basically, you write 4 functions for your device to handling opening the
file, doing I/O, flushing any internal buffers and closing (e.g. if you
were writing a device driver to send output via carrier pigeon, they
might be called PigeonOpen, PigeonInOut, PigeonFlush and PigeonClose),
and then an Assign... procedure (AssignPigeon) to associate these
functions with a text file. Then use Write(Ln) to that text file, and
the stuff goes through your driver procedures. If you want to just use
Writeln('blablabla') instead of Writeln(f, 'blablabla') then your Assign
procedure will assign the file the '' name.
You've already guessed from the name of the InOut function that this can
be used to replace the keyboard input as well as screen output.
Googling for
Pascal "text file device driver" example
finds links like the following:
http://docs.codegear.com/docs/radstudio/radstudio2007/RS2007_helpupdates/HUpdate3/EN/html/devcommon/standardroutinesov_xml.html
http://www.opensc.ws/ebooks/Delphi%205%20-%20Object%20Pascal%20Language%20Guide.pdf
(see section 8.4)
Or here's an example of creating routines which take chars from
Write(Ln) and sending them to somewhere else (to a stream):
http://www.hu.freepascal.org/lists/fpc-pascal/2004-December/007763.html
There's the CRT unit source code, crt.pp, as well.
Frank
More information about the fpc-pascal
mailing list