(continued from my earlier question MSX-DOS 1 BDOS error codes?)
I am having a problem reading files using BDOS after changing the disk. The BDOS function _RDBLK (27h) will just report an error value after having partially read some of the file, but the error handler installed via ERRADR (F323h) is not even called.
I have tried a couple of things, including first search for files before opening _SFIRST (11h) and even 'resetting' the disk _DSKRST (0Dh), but nothing seems to work.
I am nearly 100% certain that the problem is not in my code (as in, it is not mutilating any memory outside of the TPA or anything) because I still have the problem in very simple use cases.
I am beginning to suspect that it has something to do with the disk system not 'knowing' that the disk has been changed. Thus, probably BDOS is still accessing the disk using the old FAT tables (or DPBs, whatever these are?) that is still cached in memory.
I have been trying to figure out where the FAT is stored in memory. Through DPBLIST (F355h) I think the FAT should be located at E597h in memory and higher. When I look at that memory, there is some readable stuff in there (such as the file names). Whenever I open a file using BDOS _FOPEN (0Fh) I see some of that memory change, but it is not clear what it means to me, because some data changes there, even if I hadn't switch the disk yet.
So while digging on the internet and this website, I found a mention of this DISK ROM function: 4013h (DSKCHG)
Effect: Check if disk has been changed.
Input: A = Drive number (0=A:)
B = Media descriptor
C = Media descriptor
HL = Base address of DPB
Output: F = Carry set on error, carry reset on success
A = If error: errorcode (see DSKIO)
B = if success: 1=Disk not changed, 0=Unknown, -1=Disk changed
Note: If the disk has been changed or may have been changed (unknown) read
the boot sector or the FAT sector for a disk media descriptor and
transfer a new DPB as with GETDPB
It seems to suggest that it will make sure that the correct FAT and such is loaded in memory again, which may solve my problem, but I have no idea how to safely call this function (either directly or indirectly)?
Any help would be much appreciated :)
