Page 1 of 1

Has (over)writing files via Assembly's SAVE changed between R41 and R46?

Posted: Mon Dec 18, 2023 5:26 am
by ShawnL624
I have code that loads a file, changes the loaded data, and writes it back into the same file. I noticed when I moved to R46, it will save the file if it doesn't exist, but doesn't appear to overwrite the file if it does. (R45 behaves the same as R46, but I haven't tried with earlier versions.) I've attached a small .asm that shows what I'm seeing.

In R41, I see something like this when I run the PRG multiple times (assuming there is no HISCORE.BIN in the directory when I start). First run makes the file; the second run loads, changes, and saves; the third run sees the second's output, etc:

Code: Select all

LOAD"SAVETEST.PRG",8,1
RUN
00000000 -> 00001000
RUN
00001000 -> 00002000
RUN
00002000 -> 00003000
RUN
00003000 -> 00004000
In R45, R46 (again, I haven't tested R42, R43, or R44), it seems like the file will get created, but subsequent attempts to update it do not work:

Code: Select all

LOAD"SAVETEST.PRG",8,1
RUN
00000000 -> 00001000
RUN
00001000 -> 00002000
RUN
00001000 -> 00002000
RUN
00001000 -> 00002000
I checked through the release notes and didn't see anything specifically about this. So, I wanted to see if this was expected and/or what I'm doing wrong.

Cheers!

Re: Has (over)writing files via Assembly's SAVE changed between R41 and R46?

Posted: Mon Dec 18, 2023 5:44 am
by Ed Minchau
Yeah, you missed a change in I believe r42. Now, if you want to overwrite a file, the filename needs @: prepended. So, if your file is TEST.BIN to overwrite it you'd need to use @:TEST.BIN instead.

Re: Has (over)writing files via Assembly's SAVE changed between R41 and R46?

Posted: Mon Dec 18, 2023 2:16 pm
by ShawnL624
Thank you!

Re: Has (over)writing files via Assembly's SAVE changed between R41 and R46?

Posted: Thu Dec 28, 2023 12:57 am
by TomXP411
Yep, Ed's correct.

Commodore disk drives have always had overwrite protection: they will fail with an error, and a blinky drive LED, if you try to save to a filename that already exists.

The solution is to use save-and-overwrite: prepend @: to your filename.

This has always existed in CBM-DOS, and it was added to the Host FS and CMDR-DOS drivers to make HostFS and CMDR-DOS consistent with Commodore and CMD drives.

Also of note: https://en.wikipedia.org/wiki/Commodore ... eplace_bug

There's also another feature of save-and-replace that's not often talked about: from one article I read, save-and-replace writes the replacement file before removing the old version of the file. So never save-and-replace if you don't have room for a second copy of the file you're saving.