r39 patched Kernal to fix LOAD into HiRAM functionality
Posted: Sun Dec 05, 2021 8:26 pm
@desertfish found another bug where a full-page copy would misdirect byte 0 when destination address is not page aligned and bank wrap occurs. His test bed caught this on loads to $A002, but it would have happened on any non-page-aligned block copy of 256 bytes. Fortunately I was able to save some other bytes and this patch only added a few more net bytes in size.
I’ve patched this and will update the attached image shortly.
@Edmond D I do want to make code that behaves as advertised. A LOAD that allows you to bulldoze the stack is one thing, but a low-level routine that just glitches in certain cases is much less acceptable. In the former case, you can at least look at the file size beforehand and throw an error before calling LOAD. But the latter is something you'd have no control over from the outside.
And as @Scott Robison points out, there's no way to pre-check down to the last byte whether a read into $9E01 or not, but there is a possible way to do it. The macptr routine accepts .A=num_bytes. If .A=0 then the device decides how many. fat32_read limits to 256 bytes. I would have to go re-read the code with a non-zero amount in mind to see what would happen if an arbitrary amount reached fat32_read, but in theory, LOAD could see that it's in page 9E and then request only enough bytes to fill the page. If the return value is "still loading" then throw error.
I agree that this might make more sense with a "safe load" frontend than to encumber the primary load function with this extra overhead.
The changes to fat32.s were necessary for bank ram loading, even if I'd implemented a different HLOAD command analogous to VLOAD, but for HI-RAM loading.... the block copy was borked and needs to work that way regardless of the front-end packaging.