Re: Cursory analyses of CBM readdir bug (was: [cc65] Re: readdir bug)

From: Daniel Serpell <daniel.serpell1gmail.com>
Date: 2013-01-11 01:00:19
Hi!

On Thu, Jan 10, 2013 at 5:42 PM, Spiro Trikaliotis
<ml-cc65@trikaliotis.net> wrote:
> Hello,
>
> btw: I do not consider this OT, as it is something people should be
> aware when programming with cc65.
>
> * On Thu, Jan 10, 2013 at 11:59:18AM +0100 silverdr@wfmh.org.pl wrote:
>
>> This is the use case I am referring to and I get white, no matter
>> whether the file opened correctly or not. It is honest question - I'd
>> be glad not to use status channel in this case but I know no other way
>> to confirm that the file opened correctly (or not).
>
> Yes, you are right.
>
> The "problem" is how the C64 opens the file:
>
> $FFC0: KERNAL OPEN: JMP indirectly to $F34A
> $F34A: generic OPEN routine
> $F37F JSR §F3D5 if the file to be opened is on the IEC bus.
> $F3DD clear the status (READST)
> Then:
> $F3E3 LISTEN, no check for error code
> $F3EA send secondary address after listen
> $F3ED-$F3F5: If the listen + secondary address failed, return "DEVICE
>              NOT PRESENT"
> $F3F6-$F404: Output the name bytes onto the IEC Bus; NO ERROR CHECKING
>              IS PERFORMED!
> $F406 JMP $F654
>
> And here the best things occur:
> $F654 JSR $EDFE send UNLISTEN
> $F657 CLC
> $F658 RTS
>
> Back to
> $F382 BCC $F3D3
> $F3D3 CLC
> $F3D4 RTS
>
> Thus, if the LISTEN was successfull, we will ALWAYS get a success (CLC)
> on return from this routine, regardless if wheather the actual name
> transfer is successfull or not.
>
> Note that this does not even take into account if he file could be
> opened. In fact, the drive will only start to search for the file after
> the UNLISTEN, that is, immediately before the return of the OPEN
> routine.
>
> Also, as long as there were no severe transmission errors, READST will
> also return 0.
>
> Thus, the only way to find out if the OPEN was successfull is to read
> the error channel, or (much easier): read the first byte. If the OPEN
> was not successfull, READST will return 0x42 (0x40 = EOF, 0x02 = time
> out).

Then, why this is not done in CC65 lib? (the "read the first byte" thing).
Seems a lot simpler than opening another channel, and you probably
will read at least one byte after opening.

Note that I don't know anything about C64 disk access :-)

    Daniel.
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Fri Jan 11 01:00:33 2013

This archive was generated by hypermail 2.1.8 : 2013-01-11 01:00:36 CET