Save using FFD8

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
Kweepa
Vic 20 Scientist
Posts: 1315
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Save using FFD8

Post by Kweepa »

Hi,
I'm writing some assembly routines to replace cc65's fread and fwrite, because those library functions need 2k of code, presumably mostly to emulate the exact behaviour of the C library functions.
I'm testing in VICE because I don't have a 1541.

Code: Select all

   lda #1    ; logical file
   ldx #8    ; 1 for tape, 8 for disk
   ldy #0    ; secondary address
   jsr $ffba ; setlfs

   lda #8    ; length of name ("savegame")
   ldx #>filename
   ldy #<filename
   jsr $ffbd  ; setnam

   ldx #>start
   ldy #<start
   stx $c1
   sty $c2
   lda #$c1
   ldx #>end
   ldy #<end
   jsr $ffd8
This all works fine, except that if I try to write over the save, it just creates a new file called SAVEGAME.P01 rather than replacing SAVEGAME.P00.

Any advice?
User avatar
tokra
Vic 20 Scientist
Posts: 1123
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Post by tokra »

This is standard VICE-behaviour. You should disable the "Write .P00"-option in "Settings-Peripherhal settings" in VICE. Then it will always overwrite the same file. However for a real 1541 this will provide a "FILE EXISTS" error. So you have to use the @: option to overwrite the file, but since this is buggy in the 1541 the only safe way is to delete the file before writing it.
User avatar
Kweepa
Vic 20 Scientist
Posts: 1315
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Post by Kweepa »

Thanks, I'll do that!

Here's what I have, to delete a file. It seemed to work first time, which scared me.

Code: Select all

cmd: .text "S:savegame" ; scratch savegame
lda #15
ldx #8 ; disk
ldy #15
jsr $ffba ; SETLFS
lda #10
ldx #>cmd
ldy #<cmd
jsr $ffbd ; SETNAM
jsr $ffc0 ; OPEN
lda #15
jsr $ffbd ; CLOSE
Post Reply