Page 1 of 1

TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Sun Nov 06, 2022 4:04 am
by MooingLemur

I'm still trying to get my head around CBM file I/O, and this alleged bug wasn't helping to progress my understanding ?

Basically the TL;DR: if you OPEN 1,8,0,"$", and partially read through it, then you open another file OPEN 2,8,2,"FILE" and read from it, close it, then switch back to reading from logical file 1, you'll end up with corrupted data from it.

Furthermore, if you close file 1, and then reopen it and try to read, it will continue to give you corrupted data until you close and reopen it once more.

I haven't determined yet if this is only for uses SA 0 (which I think is necessary for opening "$"), or if this also applies to multiple sequential files being open for read.

Issue opened with test case: https://github.com/commanderx16/x16-rom/issues/361

 

Before I go down any further rabbit holes, does anyone have any other known gotchas for having multiple files open?


TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Sun Nov 06, 2022 11:37 am
by desertfish

is this only for the "$" file  (directory) or does it happen with 2 regular files as well?


TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Sun Nov 06, 2022 1:50 pm
by BruceMcF


On 11/6/2022 at 12:04 AM, MooingLemur said:




I'm still trying to get my head around CBM file I/O, and this alleged bug wasn't helping to progress my understanding ?



Basically the TL;DR: if you OPEN 1,8,0,"$", and partially read through it, then you open another file OPEN 2,8,2,"FILE" and read from it, close it, then switch back to reading from logical file 1, you'll end up with corrupted data from it.



Furthermore, if you close file 1, and then reopen it and try to read, it will continue to give you corrupted data until you close and reopen it once more.



I haven't determined yet if this is only for uses SA 0 (which I think is necessary for opening "$"), or if this also applies to multiple sequential files being open for read.



Issue opened with test case: https://github.com/commanderx16/x16-rom/issues/361



 



Before I go down any further rabbit holes, does anyone have any other known gotchas for having multiple files open?



The directory was originally designed to be used with LOAD in Basic, because the processor in the drive (with its 2KB of RAM in the 1541) is converting the directory into the format of a Basic listing, so directory display can just re-used the existing LIST keyword. I presume that the reason to OPEN it is that you are emulating a LOAD but you are putting the data somewhere else (eg, HighRAM).

I do not know whether any file you open in LOAD mode will be corrupted or just the Directory, but it makes sense that the Directory would be.


TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Sun Nov 06, 2022 11:24 pm
by MooingLemur


On 11/6/2022 at 1:50 PM, BruceMcF said:




I do not know whether any file you open in LOAD mode will be corrupted or just the Directory, but it makes sense that the Directory would be.



Are you saying that the corruption is expected, or just that you're not especially surprised because of the CBM legacy of it usually being loaded rather than streamed in byte by byte?


TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Mon Nov 07, 2022 12:24 am
by MooingLemur


On 11/6/2022 at 11:37 AM, desertfish said:




is this only for the "$" file  (directory) or does it happen with 2 regular files as well?



Looks like I was able to work with two regular files at once.  However I had initially suspected otherwise, because seek (15,8,15,"Pcxxxx") seems to do an implicit CHKIN to the channel that you performed a seek on, and I wasn't prepared for that ?


TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Mon Nov 07, 2022 1:34 am
by neutrino

What happens if you open two directories? ie something like: OPEN 1,8,0,"$" => GET #1.. => OPEN 2,8,0,"$" => GET #2.. => CLOSE 2 => GET #1.. => CLOSE 1

I suspect internal data structures per channel isn't kept apart properly.

 


TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Mon Nov 07, 2022 1:40 am
by MooingLemur


On 11/7/2022 at 1:34 AM, neutrino said:




What happens if you open two directories? ie something like: OPEN 1,8,0,"$" => GET #1.. => OPEN 2,8,0,"$" => GET #2.. => CLOSE 2 => GET #1.. => CLOSE 1



I suspect internal data structures per channel isn't kept apart properly.



 



My understanding of how all of this works is that you cannot use the same secondary address (in this case 0) for more than one open file concurrently, so this would be an impossible test.   On a 1541, this would also be true, because the secondary address is how the drive distinguishes I/O streams.   However, reading from two different drives, one could try this, but I suspect this is likely a CMDR-DOS problem and not a general KERNAL problem.


TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Mon Nov 07, 2022 2:09 am
by neutrino

How about? OPEN 1,8,4,"$" => GET #1.. => OPEN 2,8,5,"$" => GET #2.. => CLOSE 2 => GET #1.. => CLOSE 1

Reference: https://www.c64-wiki.com/wiki/OPEN

Makes me wonder if this behavior is present on a C64.

 


TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Mon Nov 07, 2022 3:00 am
by MooingLemur


On 11/7/2022 at 2:09 AM, neutrino said:




How about? OPEN 1,8,4,"$" => GET #1.. => OPEN 2,8,5,"$" => GET #2.. => CLOSE 2 => GET #1.. => CLOSE 1



Reference: https://www.c64-wiki.com/wiki/OPEN



Makes me wonder if this behavior is present on a C64.



 



At least on the X16, "$" can't be read unless the SA is 0.  I've tried others (2-14) but can't get any data from it.


TIL you can't step through a directory listing and open/read through another file at the same time without corruption.

Posted: Mon Nov 07, 2022 4:22 am
by BruceMcF


On 11/6/2022 at 8:34 PM, neutrino said:




What happens if you open two directories? ie something like: OPEN 1,8,0,"$" => GET #1.. => OPEN 2,8,0,"$" => GET #2.. => CLOSE 2 => GET #1.. => CLOSE 1



I suspect internal data structures per channel isn't kept apart properly.



If you tried to open the same directory twice without closing it, there is no reason to expect it to work on any IEC connected disk drive, so it doesn't seem like it is something the writers of the SD DOS system would try to support either.

For that in particular, it's not clear what the point of reading the same directory twice would be.

Also, the routine that uses the data in the directory to create the PRG file to load as a directory listing likely does it in a specific location in the relevant HighRAM segment, so it doesn't seem likely that it would be capable of creating two copies of the directory PRG anyway.