Re: [cc65] CBM LFN Question

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2010-10-24 18:00:47
Hi!

On Sat, Oct 23, 2010 at 12:28:49PM +0200, Oliver Schmidt wrote:
> I found out easily enough that cbm_opendir() calls cbm_open() which
> works "just like the BASIC comand OPEN". However surprisingly I'm
> unable to find usable information on what those 'logical files' are
> and how BASIC programmers are supposed to use them. The only thing I
> see is that '1' is used typically in commands entered interactively.

Logical file numbers are like file handles. The bad thing about them is, that
they aren't assigned by the kernal (which could easily track the ones already
used), but by the user.

If the library uses a certain lfn, it cannot prevent the user from using the
same one in his own code. This defeats modular programming and is the reason
for the hassle in the library and the "be careful" statements in regard to
mixing POSIX file I/O and CBM file I/O.

> Additionally I'm afraid that the cc65 C library and/or the POSIX file
> i/o functions make certain assumptions about the way 'logical files'
> are used. I've been peeking into the CBM C library source but I must
> admit that I don't understand it - i.e. why the C library seems to use
> 'logical files' from '3' onwards.

Lfns 1 and 2 are used by LOAD and SAVE if I remember correctly. This is the
reason why the library uses lfns starting with 3. The other assumptions are
necessary because of the way, logical file numbers work on the commodores. One
could also write a "logical file number dispatcher" that could by used by the
library and user code, but at the time I wrote the Commodore file I/O it
seemed to me that it should be possible to use either one (maybe with the
exception of LOAD and SAVE, which have a high level functionality that goes
beyond simple file I/O).

> My current guessing would lead me to trying 'logical filenumber' 12
> because the C library starts with number 'logical filenumber' 3 and
> has a maximum of 8 handles.

Yes, 12 should work with the current implementation.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Oct 24 18:00:56 2010

This archive was generated by hypermail 2.1.8 : 2010-10-24 18:01:00 CEST