Closed johnwayner closed 3 days ago
Some of the commands do not necessarily refer to a disk operation (I presume that like in the older ROM versions, OPEN can open a channel to the keyboard, and certainly to an IEC printer) so maybe DS
should not always be cleared...
Fair point. From a quick test of C128 in VICE, it indeed looks like opening a channel to a non-disk device does not clear DS/DS$. This could probably happen in BASIC DOS set-up.
OPEN 5,8,5,"NOTPRESENT,S,R"
PRINT DS
OPEN 1,3
PRINT#1,"HI"
PRINT DS
Note that RUN
will reset DS as part of start-of-program run state, even though it's not always a disk operation. We should double-check that that still works with whatever fix we decide.
Did a quick code review, this isn't definitive, but I'm looking for the fewest number of jsr Clear_DS
calls that will accomplish this. My first guess that appears to cover almost all of the list:
open_file
: SAVE
, LIST fname
, LOADIFF
, SAVEIFF
, KEY LOAD
, SPRITE LOAD
, EDIT
save and load, IMPORT
, DISK
, APPEND
, DOPEN
, TYPE
trans
: COLLECT
, HEADER
, RECORD
, DCLEAR
, COPY
, CONCAT
, RENAME
, CHDIR
, MKDIR
, SCRATCH
, BACKUP
, LOCK
, UNLOCK
load_it
: LOAD
, VERIFY
, DLOAD
, DVERIFY
, RUN fname
savenp
: DSAVE
(or just dsave
)save_keep_eal
: BSAVE
(or just bsave
)directory
: DIRECTORY
, DIRECTORY U12
bload_boot
: BLOAD
, BOOT fname
, BVERIFY
dclose
: DCLOSE
merge
: MERGE
chdir
: CHDIR U12
OPEN
and CLOSE
are tricky, unfortunately. Within BASIC, they're just calling KERNAL routines. To replicate the C128 behavior precisely, these would need extra logic to test the device ID for "is a disk." My first guess is that we should punt on getting this exactly right and just have every OPEN
and CLOSE
clear DS.
OK, I audited all the commands.
DOPEN#1,"TEST",W
does not reset DS. DOPEN#1,"TEST"
does.MERGE "FNAME"
does not reset DS.CHDIR "SDDIR",U12
does not reset DS. CHDIR "D81DIR"
does.DOPEN# W sets bit 6 of parsts
, which causes sendp
to be called with A=8 (vs. A=4 for non-W), where A is "number of bytes in format." It looks like this simply translates to ",W" in the DOS filename string, and everything else is the same. I'm not sure how this call path fails to update DS, so I don't know the appropriate fix yet.
As noted above, MERGE
and CHDIR U12
have unique call paths, so that makes sense. Maybe explicit Clear_DS
calls are appropriate here.
DLOAD "BAD"
while in EDIT mode actually swallows the error incorrectly. It is exiting to list_done
when the disk status >= 20, which might be incorrect; list_err
might be more correct. It's similar to IMPORT
, which works. I'll mess with it.
I can say that blindly adding jsr Clear_DS
to all the places I listed caused all kinds of problems. 😅 Cleaning up just these few paths is the more appropriate change.
All the other commands listed are clearing DS correctly, as far as I can tell. These appear to be Read_DS
calls that are reading the 0 directly from the disk device, and not Clear_DS
calls.
Filed a separate bug for EDIT mode DLOAD not reporting errors: https://github.com/MEGA65/mega65-rom-public/issues/142
Submitted a change to fix MERGE and CHDIR U12 to reset DS.
This bug is now specifically about DOPEN#1,W.
Test Environment (required)
Describe the bug
DS
andDS$
should be cleared when a new disk operation is executed.To Reproduce See screen shots.
Expected behavior The following commands are disk operations and should (maybe?) clear
DS
andDS$
:LOAD
SAVE
VERIFY
OPEN
CLOSE
DLOAD
DSAVE
DIRECTORY
(orDIR
, orCATALOG
)APPEND
COLLECT
COPY
DCLEAR
HEADER
(orFORMAT
)RENAME
SCRATCH
(orDELETE
orERASE
)BACKUP
BLOAD
BSAVE
BVERIFY
CHDIR
?CONCAT
DCLOSE
DISK
DVERIFY
IMPORT
?LOADIFF
LOCK
MERGE
RUN
SAVEIFF
SPRITE
(LOAD
andSAVE
) ?TYPE
UNLOCK
Whew... so many. Maybe this is why
DS
was originally cleared each time it was read?Screenshots![ds_not_cleared](https://github.com/MEGA65/mega65-rom-public/assets/12048/9dc4e4df-d8d5-4214-84a8-2b467c871550)
Similar program on C128:![c128_ds_test](https://github.com/MEGA65/mega65-rom-public/assets/12048/c124d8ee-e00d-4cd3-a13b-27dfc9128733)
Additional context This previously closed issue changed how
DS
andDS$
were cleared: https://github.com/MEGA65/mega65-rom-public/issues/85 These disk operations should have been modified to ensure they cleared them.Related documentation issue: https://github.com/MEGA65/mega65-user-guide/issues/590