Author Topic: Import nvrams from MAME  (Read 3501 times)

Offline 90sDoomer

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • @pump_upp - best crypto pumps on telegram !
Import nvrams from MAME
« on: March 30, 2021, 10:29:58 AM »
Hi, i'm tring to import some nvrams generated with MAME into FBN.

I've made this bash script to rename the files, but the binary data inside does not seem compatible:

for f in $(find . -type f -print)
do
    SAVEFILENAME="$(basename $f)"
    GAMENAME="$(basename $(dirname $f))"
    [ "$SAVEFILENAME" = "nvram" ] && cp "$f" "$GAMENAME.fs"
    [ "$SAVEFILENAME" = "eeprom" ] && cp "$f" "$GAMENAME.nv"
    [ "$SAVEFILENAME" = "saveram" ] && cp "$f" "$GAMENAME.memcard"
done
 



Is there a tool/some code i can use to perform the conversion?
« Last Edit: March 30, 2021, 10:59:06 AM by 90sDoomer »

Offline dink

  • Administrator
  • *****
  • Posts: 5014
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Import nvrams from MAME
« Reply #1 on: March 30, 2021, 11:16:41 AM »
It's slightly complicated I'm afraid:
first, fbn's nvram file (.fs) is compressed somehow.  I'm not exactly sure how.  On the other hand, if the nvram is a standard 93c46-style eeprom, its uncompressed as "romname.nv"
most 68k games have byte-swapped nvram in mame, but fbn is not byte swapped.

best regards,
- dink

Offline 90sDoomer

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • @pump_upp - best crypto pumps on telegram !
Re: Import nvrams from MAME
« Reply #2 on: March 30, 2021, 12:17:45 PM »
i've investigated these ".fs" files a bit more: they have an header + Zlib compressed data starting at byte 76.

So this is the updated ver. of my script (still need to find a way to generate the complete header for those .fs files):
Code: [Select]
for f in $(find $HOME/.mame/nvram -type f -print)
do
    SAVEFILENAME="$(basename $f)"
    GAMENAME="$(basename $(dirname $f))"
   
     if [ "$SAVEFILENAME" = "eeprom" ]; then
        # no need to compress these
        # "most 68k games have byte-swapped nvram in mame, but fbn is not byte swapped.
        dd if="$f" of="$GAMENAME.nv" conv=swab
    fi
   
   
    if [ "$SAVEFILENAME" = "nvram" ] || [ "$SAVEFILENAME" = "saveram" ]; then
        echo "FB1 FS1  " > "$GAMENAME.fs"
        truncate -s 76 "$GAMENAME.fs" # makes an empty header
        # TODO: generate the correct 76-bytes header
       
        zlib-flate -compress < "$f" >> "$GAMENAME.fs"
    fi
done
 
« Last Edit: March 30, 2021, 12:29:43 PM by 90sDoomer »

Offline dink

  • Administrator
  • *****
  • Posts: 5014
  • Karma: +449/-1
  • pie? I nearly bought one!
Re: Import nvrams from MAME
« Reply #3 on: March 30, 2021, 03:29:07 PM »
Nice work :)

a little OT:
I wanted to have fbn write uncompressed data for states and nvram data for ages now.  The little bit of time it takes to compress the data causes some games to stutter while saving afar state, since we have a lot less than 1/60th of a second to work with.

Best regards,
- dink

Offline Agozer

  • Newbies
  • *
  • Posts: 44
  • Karma: +1/-0
Re: Import nvrams from MAME
« Reply #4 on: March 31, 2021, 11:53:14 AM »
I've always wondered why FBAlpha's/FBNeo's nvram files were incompatible with MAME. Now I know. Something like an nvram files should be compatible with all emulators, if you ask me. It's created/written by the emulated system -- what benefit could there possibly be for compressing it?

Offline Stifu

  • Member
  • ***
  • Posts: 246
  • Karma: +5/-0
Re: Import nvrams from MAME
« Reply #5 on: March 31, 2021, 12:41:38 PM »
what benefit could there possibly be for compressing it?

Saving space back when HDDs could only hold a few GBs, I guess. Now it is no longer desirable.