Jump to content
  • 0
JohnGill

r38 broken kernal save routine??

Question

Hi all, I've got a bit of code that saves a specified block of memory to a file.

It works fine in r37, but it doesn't work in r38, I'm guessing the implementation of the kernal save has been affected with the SD card management additions in r38.

What do I need to change to get it working again in r38? Hoping someone can shed some light on this, thanks in advance!
 




			
		

Share this post


Link to post
Share on other sites

17 answers to this question

Recommended Posts

  • 0

A few things I'm seeing.... First of all, I'm not sure how you're calling the code, but if you're doing it with "SYS $2F00" for example, this will not behave as expected, since your filename definition is at the beginning.  It should be moved to the end, after the "rts".  Secondly, as pointed out, your secondary address should be 1 when calling SETLFS.  0 saves it as a BASIC program, 1 does a raw save, which is what it looks like you're trying to do.  Third, the length of your filename is 11, not 10, so A should #$0B when you call SETNAM.

Edit: Nevermind what I said about the SA needing to be 1 when calling SETLFS.  I took a look at the code in the emulator for non-sdcard saves, and the ROM for sdcard saves, and it seems the SA isn't even used by the X16 for saving.

Edit edit: I was wrong about the third thing too 😅

Edited by Ender
  • Thanks 1

Share this post


Link to post
Share on other sites
  • 0

Ugh, sorry, I've only just noticed the block of code I thought I'd copied and pasted in the past above has mysteriously disappeared. I'm on my phone at the mo, I'll update once I'm back in front of my pc.

Share this post


Link to post
Share on other sites
  • 0

this is what SHOULD have been in the original post!  It saves a block of normal low-memory (non-banked) onto the file system, same folder as where the emulator is run from.

worked fine in r37, doesn't work in r38...

 

Bitmap in Untitled-1.png

Edited by JohnGill

Share this post


Link to post
Share on other sites
  • 0

Same code works for me in r38 but I have the SETLFS parameters like this (a/y reversed from how you have it):

(for completeness - I also call SETNAM before SETLFS)

    lda #$00                                    ; logical number
    ldx #$08                                    ; device 8
    ldy #$01                                    ; secondary address
    jsr SETLFS
Edited by Getafix
Additional info
  • Thanks 1

Share this post


Link to post
Share on other sites
  • 0

Both the LOAD and the SAVE functions don't need a logical file number.  SAVE needs a secondary "address" only when saving to a Datasette (tape).  Therefore, the secondary address isn't needed on the Commander X16 -- only index register .X needs to be set before calling SETLFS.

Your subroutine works in R38.  But I, also, was fooled because I didn't know where the "working directory" was.  When I launched the emulator from CBM prg Studio, it's working folder was the same as the Studio's working folder.  I looked at the CBM prg Studio's desktop icon's properties.  For me, it's "Start in:" field is blank; therefore, the Desktop is the "working" location.

If all of that is true for you, then you should be able to find "BANKXX.PRG" on your Windows Desktop.

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites
  • 0
18 hours ago, Getafix said:

Same code works for me in r38 but I have the SETLFS parameters like this (a/y reversed from how you have it):

(for completeness - I also call SETNAM before SETLFS)

    lda #$00                                    ; logical number
    ldx #$08                                    ; device 8
    ldy #$01                                    ; secondary address
    jsr SETLFS

Hmm one step forward -

I tried switching over the order that I call SETNAM and SETLFS so that SETNAM is called first, and that now makes the subroutine complete normally in r38  - it now RTSes back to basic properly which it didn't before. But there's no file written in the emulator directory. I'm running the emulator "manually" from its own folder, not from the emulator launcher within CBM Prg studio. I even did a search on my entire hard disk for "bankxx.prg" in case it was being written somewhere I wasn't expecting it - but nothing there. I tried switching over the a / y, still no file written. I tried removing the y as suggested by Greg, still no file written.

I copied and pasted the exact same .prg file into my r37 folder and ran it using the r37 emulator, and bankxx.prg is written into the r37 directory fine - all 8Kb + 2 header bytes of it.  I don't get it... there's obviously something else at play here since it's working fine for you and @Greg King - any ideas what I could check next?

 

Edited by JohnGill

Share this post


Link to post
Share on other sites
  • 0

I just typed this in:

.code
    lda #8 
    tax
    tay
    jsr $ffba
 
    lda #$a
    ldx #<filename
    ldy #>filename
    jsr $ffbd
 
    stz $0
    lda #$70
    sta $1
 
    lda #0
    ldx #0
    ldy #$90
 
    jmp  $ffd8
filename: .byte "bankxx.prg"

I compiled with cc65 using: 

cl65 -t cx16 -u __EXEHDR__ cx16.lib .\save.s -o save.prg -C cx16-asm.cfg

I get BANKXX.PRG in the folder where I have the code (save.s), by using the command line (windows Powershell)  

~\Games\CX16\x16emu.exe -prg .\save.prg -run

I tried omitting the setting of x and y before calling SETLFS and it did not work.  I know 1 and 0 worked, but 8 and 8 also worked so something of what @Greg King said made sense, but it's not quite arbitrary?  I will stick with a/x/y 8/0/1.

Share this post


Link to post
Share on other sites
  • 0
29 minutes ago, Getafix said:

I just typed this in:

.code
    lda #8 
    tax
    tay
    jsr $ffba
 
    lda #$a
    ldx #<filename
    ldy #>filename
    jsr $ffbd
 
    stz $0
    lda #$70
    sta $1
 
    lda #0
    ldx #0
    ldy #$90
 
    jmp  $ffd8
filename: .byte "bankxx.prg"

I compiled with cc65 using: 

cl65 -t cx16 -u __EXEHDR__ cx16.lib .\save.s -o save.prg -C cx16-asm.cfg

I get BANKXX.PRG in the folder where I have the code (save.s), by using the command line (windows Powershell)  

~\Games\CX16\x16emu.exe -prg .\save.prg -run

I tried omitting the setting of x and y before calling SETLFS and it did not work.  I know 1 and 0 worked, but 8 and 8 also worked so something of what @Greg King said made sense, but it's not quite arbitrary?  I will stick with a/x/y 8/0/1.

With SETLFS, A is the logical number, I don't think it actually matters what it is in this case.  X is the device number, that should be 8. Y is the secondary address. I actually took a look at the code in the emulator and the ROM, and it seems as though the secondary address isn't even used.  In the original C64, 0 meant save as a BASIC program, 1 meant do a raw save, and 2 was for saving to a data casette. But from what I can tell in the X16, it doesn't matter for saves. So the reason it wasn't working for you is because you didn't set X.  Y and A don't seem to matter.

Share this post


Link to post
Share on other sites
  • 0
1 hour ago, Ender said:

A few things I'm seeing.... First of all, I'm not sure how you're calling the code, but if you're doing it with "SYS $2F00" for example, this will not behave as expected, since your filename definition is at the beginning.  It should be moved to the end, after the "rts".  Secondly, as pointed out, your secondary address should be 1 when calling SETLFS.  0 saves it as a BASIC program, 1 does a raw save, which is what it looks like you're trying to do.  Third, the length of your filename is 11, not 10, so A should #$0B when you call SETNAM.

Edit: Nevermind what I said about the SA needing to be 1 when calling SETLFS.  I took a look at the code in the emulator for non-sdcard saves, and the ROM for sdcard saves, and it seems the SA isn't even used by the X16 for saving.

I think you've cracked it Ender, thanks - I do indeed call the subroutine from basic with a sys call, so I'll try moving the filename to the end of the code, I bet that fixes it (and correct the filename length) on my phone at the mo so will try it in the morning

Share this post


Link to post
Share on other sites
  • 0
24 minutes ago, Ender said:

So the reason it wasn't working for you is because you didn't set X.  Y and A don't seem to matter.

Got my registers mixed up! 😫 Sorry about that. 

Share this post


Link to post
Share on other sites
  • 0

@Ender, the file-name is ten characters long, not eleven -- his code is correct about that!

Reread the beginning of my earlier post.  I was very definite about SETLFS.  It is true for all Commodore and Commodore-like computers.

Share this post


Link to post
Share on other sites
  • 0
1 hour ago, Getafix said:

I compiled with cc65 using: 

cl65 -t cx16 -u __EXEHDR__ cx16.lib .\save.s -o save.prg -C cx16-asm.cfg

You don't need to include "cx16.lib" on that command-line.  cl65 links the proper library for you.

Share this post


Link to post
Share on other sites
  • 0
1 hour ago, Greg King said:

@Ender, the file-name is ten characters long, not eleven -- his code is correct about that!

Reread the beginning of my earlier post.  I was very definite about SETLFS.  It is true for all Commodore and Commodore-like computers.

Ah right, it's 2 x's not 3. Sorry about that. Are you sure about the secondary address on the X16 though? It doesn't seem to be used in the SAVE function in the emulator, and, as far as I can tell, in kernal/cbm/channel/save.s, the SA gets overwritten at the beginning and it's not saved beforehand and used later on (unlike in load).

Edited by Ender

Share this post


Link to post
Share on other sites
  • 0

Yep cracked it - thanks all!  Now I can make a save / load game routine for my hexes game!

Good spot @Ender on that "filename" positioning. My 6502 assembly skills are coming in hops and crawls! 😄 😄 

Untitled-1.png

Share this post


Link to post
Share on other sites
  • 0
10 hours ago, Ender said:

Are you sure about the secondary address on the X16, though? It doesn't seem to be used in the SAVE function in the emulator; and, as far as I can tell, in kernal/cbm/channel/save.s, the SA gets overwritten at the beginning and it's not saved beforehand and used later on (unlike in load).

Yes, that's what I wrote.  Only tape devices use the SA (during a SAVE).  But, the Commander X16 doesn't support a tape device.  That is why the SA isn't used there.

Share this post


Link to post
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.


×
×
  • Create New...

Important Information

Please review our Terms of Use