Jump to content
  • 0

Kernal SAVE always fails


Fippy
 Share

Question

Hey commander experts,

Kernal SAVE is always failing for me, LOAD works fine, or at least in the loading code into different banks does.

I'm using emu r38. Obviously missing something obvious. I followed Matt's Kernal video. The Error code is 04 (FILE_NOT_FOUND), which is a little odd on a SAVE

Here's the snippet of my code, pretty much hardcoded values to test.

  lda #1
  ldx #SD_DEVICE
  ldy #0                 ; I've tried #1 as well
  jsr SETLFS

  lda #11
  ldx #<filename
  ldy #>filename
  jsr SETNAM

  lda #$A0          ; data segment starts at $08A0
  sta TEMP          ; stores start address (TEMP is $3A in zp)
  lda #$08
  sta TEMP+1

  lda #TEMP         ; start addr
  ldx #$FF
  ldy #$09
  jsr SAVE
  bcs @error
........

filename: .byte "savgame.bin"

 

 

Edited by Fippy
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

I personally have not used the Kernal's SAVE routine, rather only sequential file writing using CHROUT into a file. And I have gotten that to work only with SD card images. Since LOAD, however, does (somewhat) work with the host filesystem, it's not obvious to me why SAVE shouldn't also work.

What is the string that you are passing to the SAVE routine? Does the file you are trying to write to already exist?

 

Edit: just saw it, "savegame.bin"

 

When saving files with the CHROUT method, I pass "@0:savegame.bin,s,w"

The @ symbol says that any existing file with that name should be overridden. The ",s" says that it's a sequential file (not sure if that applies if you are SAVEing) and ",w" to tell the drive that I intend to write to the file. I don't know if any of this is necessary when using SAVE, but hey, more options to try out 😉

Edit 2: is the filename string residing in RAM bank 1? If so, I could imagine (according to what Ed Minchau said) that SAVE tries to read the filename but it is not there since it is reading from bank 0 instead. So you would need to put the file name into main RAM.

Edited by kliepatsch
Link to comment
Share on other sites

  • 0
On 9/26/2021 at 6:15 PM, Fippy said:

Hey commander experts,

Kernal SAVE is always failing for me, LOAD works fine, or at least in the loading code into different banks does.

I'm using emu r38. Obviously missing something obvious. I followed Matt's Kernal video. The Error code is 04 (FILE_NOT_FOUND), which is a little odd on a SAVE

Here's the snippet of my code, pretty much hardcoded values to test.

  lda #1
  ldx #SD_DEVICE
  ldy #0                 ; I've tried #1 as well
  jsr SETLFS

  lda #11
  ldx #<filename
  ldy #>filename
  jsr SETNAM

  lda #$A0          ; data segment starts at $08A0
  sta TEMP          ; stores start address (TEMP is $3A in zp)
  lda #$08
  sta TEMP+1

  lda #TEMP         ; start addr
  ldx #$FF
  ldy #$09
  jsr SAVE
  bcs @error
........

filename: .byte "savgame.bin"

 

 

There's a big problem when trying to save data from the RAM banks: the Kernel uses bank 00 in the middle of the save operation. 

The solution I've been using is to always leave bank FF (3F on a 512k system) free. Then I copy 7000-8FFF into that bank, copy the bank I want to save into 7000-8FFF, save the file from that location,  and then copy bank FF (or 3F) back down to 7000-8FFF. 

Link to comment
Share on other sites

  • 0
On 9/26/2021 at 9:01 PM, Ed Minchau said:

There's a big problem when trying to save data from the RAM banks: the Kernel uses bank 00 in the middle of the save operation. 

I'm not trying to save from RAM Banks but from main memory ($08A0). I was just commenting that I was using RAM Banks, sorry if I confused the issue. Because I need a LOT of data, my code goes into RAM bank 1 and the data resides in the main 38k chunk. You can see the $08A0 address in the code above and no Bank selecting, unless there's something else I'm not aware of.

Link to comment
Share on other sites

  • 0
On 9/26/2021 at 10:54 PM, Fippy said:

I'm not trying to save from RAM Banks but from main memory ($08A0). I was just commenting that I was using RAM Banks, sorry if I confused the issue. Because I need a LOT of data, my code goes into RAM bank 1 and the data resides in the main 38k chunk. You can see the $08A0 address in the code above and no Bank selecting, unless there's something else I'm not aware of.

Your SETLFS needs to be set to A=01, X=08, Y=01.  Is SD_DEVICE = 08?

Link to comment
Share on other sites

  • 0
On 9/26/2021 at 11:05 PM, kliepatsch said:

Edit 2: is the filename string residing in RAM bank 1? If so, I could imagine (according to what Ed Minchau said) that SAVE tries to read the filename but it is not there since it is reading from bank 0 instead. So you would need to put the file name into main RAM.

This was it! The filename was buried in my code in RAM Bank 1, since it fixed data. I moved it to my data segment in main RAM and now the Save works just great.

Thanks folks. 🙂

Edited by Fippy
  • Like 4
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use