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

From: Spiro Trikaliotis <ml-cc651trikaliotis.net>
Date: 2013-01-10 21:42:32
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).

For a real EOF, READST will read 0x40 instead. If you ignore it and read
past the EOF, then you will get a 0x42 on subsequent reads.

Regards,
Spiro.

-- 
Spiro R. Trikaliotis
http://www.trikaliotis.net/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Jan 10 21:43:03 2013

This archive was generated by hypermail 2.1.8 : 2013-01-10 21:43:07 CET