gb64 icon indicating copy to clipboard operation
gb64 copied to clipboard

Help with converting to/from save format?

Open euan-forrester opened this issue 2 years ago • 10 comments

Hey, I'm the author of savefileconverter.com (https://github.com/euan-forrester/save-file-converter) and I'm trying to add the ability to convert to and from GB64 files to the site.

I can convert from GB64 format to a 'normal' SRAM save that I can load in another emulator, but I haven't been able to successfully convert a 'normal' SRAM save from another emulator into GB64 format.

I've attached my best attempt so far, where I've just overwritten the first 8kB of the compressed data from a working save with my new save data, recompressed it, and updated the compressed size in the header. But I just see an empty save when I load the ROM in GB64. I'm feeling a bit stuck because it looks almost identical to the file I created with GB64.

Legend of Zelda, The - Link's Awakening (USA, Europe)-emulator-to-everdrive.fla.zip

This is the working save that I made with GB64:

Legend of Zelda, The - Link's Awakening (USA, Europe)-everdrive.fla.zip

Can you give me any more information about how to create these files?

Here's the code I'm using so far if you're curious: https://github.com/euan-forrester/save-file-converter/blob/gb64/frontend/src/save-formats/FlashCarts/N64/GB64Emulator.js

Thank you very much for any help you're able to give me!

euan-forrester avatar Oct 11 '22 04:10 euan-forrester

I'm assuming you found the code that reads and writes save data https://github.com/lambertjamesd/gb64/blob/master/src/save.c

There are a few different save file modes depending on how much free memory there is so the SRAM of the GB cart is not guaranteed to be in the save file.

For backwards compatibility reasons if the emulator doesn't detect a save file header it will assume the save data is just raw SRAM information. So when converting to GB64 you could just save the gameboy SRAM uncompressed and the emulator should read that just fine.

I'm pretty busy with a game jam right now that ends this month. after that I may have some more time to help out.

lambertjamesd avatar Oct 11 '22 15:10 lambertjamesd

Yep I found it and that was how I was able to parse out the file!

And yeah I saw the different modes and was going to add code for checking for them once I got the basics going. I think I need to take a closer look there because I don't remember seeing a mode that didn't include the SRAM information.

My theories for what I'm doing wrong are maybe:

  • The emulator state that I'm writing to the save file isn't compatible with the SRAM information
  • I'm not using GB64 itself correctly to load the data
  • Or something else entirely!

But that's a good tip about just writing out the SRAM information uncompressed without a header. I'll try that and see if I can get it to work.

Ideally, I'd like to write out a "proper" file (and make sure I'm handling all the modes correctly when reading) and so I'd love any help you're able to give me once your game jam is done and you have a bit more time. But I'll try this out in the meantime and see if it gets me going.

Thank you very much!

euan-forrester avatar Oct 11 '22 16:10 euan-forrester

After a bit more investigation, it seems that my first problem is that I don't understand how saving and loading work :). Here's my steps:

  1. Everdrive X7 set up with GB64 emulator in ED64/emu as gb.v64 and gbc.v64 (i.e. as by default in the latest firmware)
  2. Overwrite existing 128kB save with 8kB raw SRAM file in ED64/gamedata, named as ROM name + .fla
  3. Turn on N64 and load up Pokemon Snap, a game which also uses Flash saving in an effort to clear out any data the Everdrive might load from its own hardware
  4. Verify Pokemon Snap data has been loaded correctly, then reset N64
  5. Load up Zelda: Link's Awakening ROM
  6. The old save data is present in the file select screen inside Zelda
  7. Loading a save state (with C down) loads the save state I'd previously made with Zelda
  8. Turn off N64 and inspect SD card to find my 8kB file was replaced with a 128kB file

So I'm confused about why I see the old data still being loaded even though I tried clearing it out of the Everdrive hardware with step 2, and overwrote the file with step 1.

Clearly I don't understand how this all works! I know you're super busy at the moment and I certainly don't expect an answer anytime soon, but I wanted to write down the steps I took before I forgot.

Thank you for any future help you're able to give me!

euan-forrester avatar Oct 12 '22 23:10 euan-forrester

I have no idea why it would be doing that. Do you have a copy of the save data you are trying this with? Maybe I will try it out.

lambertjamesd avatar Oct 13 '22 20:10 lambertjamesd

Interesting! Well at least I’m not crazy then :)

I’m out of town and on my phone but the file is here: https://github.com/euan-forrester/save-file-converter/tree/gb64/frontend/tests/unit/save-formats/data/flashcarts/n64/gb64emulator

It has the suffix “-emulator” and is 8kB long. It should have one save slot occupied, called something like “Emulator”

Let me know if you can’t find it and I’ll poke around better once I’m at home

Thank you! I’m curious what you find!

On Thursday, October 13, 2022, lambertjamesd @.***> wrote:

I have no idea why it would be doing that. Do you have a copy of the save data you are trying this with? Maybe I will try it out.

— Reply to this email directly, view it on GitHub https://github.com/lambertjamesd/gb64/issues/30#issuecomment-1278170218, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI3JWTG34JC3GQJOUYDP5ATWDBZQ7ANCNFSM6AAAAAARB4IBAI . You are receiving this because you authored the thread.Message ID: @.***>

euan-forrester avatar Oct 14 '22 03:10 euan-forrester

Hey I'm back in town and just wanted to follow up here -- the file is this one: https://github.com/euan-forrester/save-file-converter/blob/gb64/frontend/tests/unit/save-formats/data/flashcarts/n64/gb64emulator/Legend%20of%20Zelda%2C%20The%20-%20Link's%20Awakening%20(USA%2C%20Europe)-emulator.sav

(it's hard to see the filenames even on desktop view!)

And the saves look like this:

Screen Shot 2022-10-18 at 2 12 25 PM

euan-forrester avatar Oct 18 '22 21:10 euan-forrester

Hey I just wanted to check in to see if your game jam has finished and if you've been able to think about this at all. It's pretty clear that I'm doing something wrong, but I'm not sure what it is!

euan-forrester avatar Nov 14 '22 03:11 euan-forrester

I just wanted to share some updates here:

I found that the issue with the save not being loaded was because of the everdrive overwriting the contents of the SD card save of the last run game whenever it boots to the menu, even on first boot. So the correct order of operations for replacing a save is:

  • Boot the everdrive
  • Run a different game (that also saves using Flash memory?)
  • Turn off the N64
  • Replace the save file on the SD card
  • Boot the everdrive
  • Run the game whose save you just replaced

With that I started to see some error messages from gb64 when trying to load the save which were helpful in debugging.

I was not able to load raw SRAM data [padded out to 128kB to make the everdrive happy]: I got this error: https://github.com/lambertjamesd/gb64/blob/391b553966ef1ff45368bad8bb28fea119aa20de/src/save.c#L515

The error messages helped to point me to an error in my code (needed to write out gzip format compressed data not deflated data) and now I have a proof of concept working: I can get gb64 to load a file that I wrote.

I've just got a few minor questions:

  • Do you have any advice on how to initialize the rest of the compressed data?
  • What size it should be? (I just have a hardcoded size for gb and another for gbc from looking at a couple of files generated by gb64).
  • Which value should I put in for StoredInfoType (currently I'm putting in 0, which corresponds to "all", and the emulator crashes when trying to load a save state when running off a file I create).
  • Which values of StoredInfoType can I extract SRAM data for? I currently have it as 0 (all), 1 (settings RAM), or 2 (RAM): is that correct?
  • I don't have any version 0 or 1 files to test with -- do you have any? It looks like they're virtually the same, just with the data uncompressed instead of compressed. In both cases it looks like the data begins at offset 0x80

Thanks for your help, and I'll let you know when I have this working on the site! I think there's been a recent upsurge in popularity in gb64 since it started being included in the everdrive 64 firmware by default, and I've had a few users ask if I can add support for converting to gb64 format.

euan-forrester avatar Dec 19 '22 01:12 euan-forrester

Sorry for disappearing on this. I will try to get to this this week.

lambertjamesd avatar Dec 19 '22 16:12 lambertjamesd

No worries at all! I totally understand how life gets in the way!

euan-forrester avatar Dec 19 '22 23:12 euan-forrester