Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-11

Make FPC closer to hardware

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Florian Klaempfl
to leledumbo
Show quoted text 6 lines
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.

Too slow in the common use case.

Reply by email

Frank Peelo
to leledumbo: Let Write(Ln) work without file system support? Perhaps just by supplying a routine to…
leledumbo wrote 8 lines
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

Reply by email

Frank Peelo
to leledumbo
leledumbo wrote
Well, it's just an example. I'm saying that because the need of file system support is quite frustrating that I need to write my own write routines.

yes, but for example you /don't/ need to write your own write routines. (You *can't* write writeln in Pascal!) You can implement just the driver underneath. As the CRT unit does. It's not "one character at a time", it's "one bufferful at a time"; this is an efficiency thing. You /could/ write a tfdd that called your "one char at a time" functions.

The FreePascal people have written a portable compiler with this language, so it must be possible to do system stuff with it!

Frank

Reply by email

leledumbo
to Frank Peelo
Frank Peelo wrote
yes, but for example you /don't/ need to write your own write routines. (You *can't* write writeln in Pascal!)

I know, I'm just saying Write routines, doesn't have to be the same as Write(Ln) which has variable number of arguments. I'm writing one for each type (.i.e WriteString, WriteLong, etc).

Frank Peelo wrote 6 lines
You can implement just the driver underneath. As the CRT unit does. It's not "one character at a time", it's "one bufferful at a time"; this is an efficiency thing. You /could/ write a tfdd that called your "one char at a time" functions.

What driver? Well, it's not difficult to have that "one bufferful at a time" thing. Perhaps I'll take a look at Crt unit source.

Frank Peelo wrote
The FreePascal people have written a portable compiler with this language, so it must be possible to do system stuff with it!

That's what I saw from other OSes, which already have everything needed. I guess I should ask them.

View this message in context: http://www.nabble.com/Make-FPC-closer-to-hardware-tp20513082p20572459.html Sent from the Free Pascal - General mailing list .

Reply by email