Re: [cc65] CBM LFN Question

From: Spiro Trikaliotis <ml-cc651trikaliotis.net>
Date: 2010-10-25 11:19:11
* On Sun, Oct 24, 2010 at 09:39:02PM +0200 Ullrich von Bassewitz wrote:
> 
> On Sun, Oct 24, 2010 at 09:11:19PM +0200, Spiro Trikaliotis wrote:
> > BTW: The cc65 runtime could get rid of all the LFN problems by just
> > "poking" the addresses at the right time. Of course, this would require
> > some direct calling into the KERNAL (instead of using the KERNAL jump
> > table) every now and then...
> 
> Could you elaborate on this a bit? Do you mean just using one table entry and
> overwriting it with the necessary lfn info before each kernal call that needs
> an lfn? 

This would be one option, yes. Another one is the following:


First: Note that I will use the addresses in the C64 KERNAL, as I am
most familiar with that one. At the end, I will list a table for the
entry points at other CBM computers.

Also note that this is untested, but I do not see any reason why this
should not work.

The following KERNAL routines need an LFN:

1. SETLFS ($FFBA)
2. OPEN ($FFC0)
3. CLOSE ($FFC3)
4. CHKIN ($FFC6)
5. CHKOUT ($FFC9)

Note that these routines are also the only ones which use the table of
open files. All other routines only use LA ($B8), SA ($B9), FA ($BA),
FNADDR ($BB/$BC), FNLEN ($B7) directly.

Let's have a look at what they are doing (neglecting not important things):

1. SETLFS
   $FFBA -> $FE00
   Only stores data in LA ($B8), SA ($B9) and FA ($BA).

2. OPEN
   $FFC0 -> $F34A
   - $F34A - $F350: LFN (LA, $B8) == 0 --> return with error "not input file" (?)
   - $F351 - $F358: find entry with that LFN in table of open files (LAT, SAT, FAT table)
                    if found -> return with error "file open"
   - $F359 - $F361: check if there is room for a new entry. Not -> return with error "too many files open"
   - $F362 - $F376: store LA, SA and FA into table (LAT, SAT, FAT). Note that SA with be ORed with the constant IEEE_OPEN (the constant $60)
   - $F377 - $F378: If file to open is keyboard -> quit with success
   - $F379 - $F49D: Handle opening of specific devices

   Thus, to completely avoid using the table of open files, one can do the following:

   - set LA, SA and FA (directly, or via SETLFS), and possibly FNLEN and FNADDR (via SETNAM)
   - LDA SA
   - JMP $F377


3. CLOSE
   $FFC3 -> $F291
   - $F291 - $F297: check if file exists in table of open files (LAT, SAT, FAT).
                    if not found -> return with success (!)
   - $F298 - $F29A: jsr SetActiveFile ($F31F) --> copy data from table of open files (LAT, SAT, FAT) into LA, FA, SA
   - $F29B - $F29C: Push index into table of open files (LAT, SAT, FAT) onto stack
   - $F29D - $F2F0: Handle CLOSE functionality for specific devices
   - $F2F1 - $F30E: Delete entry from list of open files (LAT, SAT, FAT) by using the index pushed onto the stack before (in $F29B-$F29C)

   Thus, to completely avoid using the table of open files, one can do the following:

   - PUSH the constant 0 onto the stack (to allow to pop it back at $F2F1, and to make sure it is equal to (LDTND - 1))
   - Set LDTND ($98) to 1 (number of open files; this will ensure that the number of open files will be 1 afterwards, so, no copy will be done after closing)
   - set LA, SA and FA (directly, or via SETLFS)
   - jsr $F29D

4. CHKIN
   $FFC6 -> $F20E

   - $F20E - $F215: check if file exists in table of open files (LAT, SAT, FAT).
                    if not found -> return with error "file not open"
   - $F216 - $F218: jsr SetActiveFile ($F31F) --> copy data from table of open files (LAT, SAT, FAT) into LA, FA, SA
   - $F219 - $F24F: Process functionality for specific devices

   Thus, to completely avoid using the table of open files, one can do the following:

   - set LA, SA and FA (directly, or via SETLFS)
   - lda FA (we cannot use the LDA FA at $F219, as it is not available on C128 and Plus/4!)
   - jsr $F21B

5. CHKOUT
   $FFC9 -> $F250

   - $F250 - $F257: check if file exists in table of open files (LAT, SAT, FAT).
                    if not found -> return with error "file not open"
   - $F258 - $F25A: jsr SetActiveFile ($F31F) --> copy data from table of open files (LAT, SAT, FAT) into LA, FA, SA
   - $F25B - $F290: Process functionality for specific devices

   Thus, to completely avoid using the table of open files, one can do the following:

   - set LA, SA and FA (directly, or via SETLFS)
   - lda FA (we cannot use the LDA FA at $F219, as it is not available on C128 and Plus/4!)
   - jsr $F25D



The addresses for other Commodore computers are:

            C64    VIC20    C128    PLUS4
- mOPEN:   $F377   $F437   $EFDF    $EF7B
- mCLOSE:  $F29D   $F356   $F194    $EE6B
- mCHKIN:  $F21B   $F2D4   $F10E    $F219
- mCHKOUT: $F25D   $F316   $F154    $ED6B

- LA        $B8     $B8     $B8      $AC
- FA        $B9     $B9     $B9      $AD
- SA        $BA     $BA     $BA      $AE
- LDTND     $98     $98     $98      $97

I hope I did not miss anything.

Regards,
Spiro.

-- 
Spiro R. Trikaliotis                              http://opencbm.sf.net/
http://www.trikaliotis.net/                     http://www.viceteam.org/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Oct 25 11:19:29 2010

This archive was generated by hypermail 2.1.8 : 2010-10-25 11:19:32 CEST