Zsnes savestate file format

Discussion of development of software for any "obsolete" computer or video game system.
AnisSaouliBH
Posts: 11
Joined: Fri Aug 21, 2020 10:55 am

Zsnes savestate file format

Post by AnisSaouliBH » Fri Aug 21, 2020 4:35 pm

Hi
Um... Do anyone knows zsnes savestate file format something like header format and data offsets etc...
I mostly intrested in palette location part.
:wink:

Note: i already have readen the document in romhacking.net (it didn't help me).

User avatar
Memblers
Site Admin
Posts: 3876
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Zsnes savestate file format

Post by Memblers » Fri Aug 21, 2020 9:38 pm

Is there an SNES emu that will let you view the contents of palette RAM? If so, copy a sequence of values, and search for them in a save state from the same screen.

Oziphantom
Posts: 913
Joined: Tue Feb 07, 2017 2:03 am

Re: Zsnes savestate file format

Post by Oziphantom » Sat Aug 22, 2020 4:48 am

Use the source code
https://github.com/emillon/zsnes/blob/m ... c/zstate.c

static void copy_snes_data(unsigned char **buffer, void (*copy_func)(unsigned char **, void *, size_t))

Code: Select all

{
  //65816 status, etc.
  copy_func(buffer, &curcyc, 1);
  copy_func(buffer, &curypos, 2);
  copy_func(buffer, &cacheud, 1);
  copy_func(buffer, &ccud, 1);
  copy_func(buffer, &intrset, 1);
  copy_func(buffer, &cycpl, 1);
  copy_func(buffer, &cycphb, 1);
  copy_func(buffer, &spcon, 1);
  copy_func(buffer, &stackand, 2);
  copy_func(buffer, &stackor, 2);
  copy_func(buffer, &xat, 2);
  copy_func(buffer, &xdbt, 1);
  copy_func(buffer, &xpbt, 1);
  copy_func(buffer, &xst, 2);
  copy_func(buffer, &xdt, 2);
  copy_func(buffer, &xxt, 2);
  copy_func(buffer, &xyt, 2);
  copy_func(buffer, &xp, 1);
  copy_func(buffer, &xe, 1);
  copy_func(buffer, &xpc, 2);
  copy_func(buffer, &xirqb, 1);
  copy_func(buffer, &debugger, 1);
  copy_func(buffer, &Curtableaddr, 4);
  copy_func(buffer, &curnmi, 1);
  //SPC Timers
  copy_func(buffer, &cycpbl, 4);
  copy_func(buffer, &cycpblt, 4);
  //SNES PPU Register status
  copy_func(buffer, &sndrot, 3019);
}
my guess its it somewhere in the sndrot which is PPU Status registers. To which find that struct and get its offset.

AnisSaouliBH
Posts: 11
Joined: Fri Aug 21, 2020 10:55 am

Re: Zsnes savestate file format

Post by AnisSaouliBH » Sat Aug 22, 2020 5:28 am

:? I am still confused and i couldn't understand this source code can anyone explains it for me? I am making software that extract palette and graphics from the zsnes savestate for that reason i need more explaination about it.

Oziphantom
Posts: 913
Joined: Tue Feb 07, 2017 2:03 am

Re: Zsnes savestate file format

Post by Oziphantom » Sat Aug 22, 2020 6:13 am

yeah I can't find where it is defined either. maybe it is missing some files. But that should give you a good easy area of the file to target. finding 256 bytes that match should probably give 2 areas that match as they will have a WRAM and CGRAM copy in most games. In this case you want the first one.

AnisSaouliBH
Posts: 11
Joined: Fri Aug 21, 2020 10:55 am

Re: Zsnes savestate file format

Post by AnisSaouliBH » Sat Aug 22, 2020 6:43 am

God , this zsnes savestate format like a mastery.

I wonder how yy-chr author make it to understand.

Is there is anyone really knows this savestate format ?

Oziphantom
Posts: 913
Joined: Tue Feb 07, 2017 2:03 am

Re: Zsnes savestate file format

Post by Oziphantom » Sat Aug 22, 2020 6:58 am

well it changes over the years. __ZS_kNight_ _DEMO_ would be the people that know it the best. However ZSNES is relic, a long empty ghost town that people only visit when they want to play "that one old hack that is ZSNES specific" so nobody current really has it worked out. But its should be somewhat easy to data mine it and find the offsets you need. You are aware they are compressed and hence you need to unzip it first right?

AnisSaouliBH
Posts: 11
Joined: Fri Aug 21, 2020 10:55 am

Re: Zsnes savestate file format

Post by AnisSaouliBH » Sat Aug 22, 2020 7:05 am

I tried many ways to figure out the palette offset and i found it not making sens
I mean the snes color format is B5G5R5 0BBBBBGG GGGRRRRR wich means it only require two bytes to store color data.
I used bizhawk emulator for extracting color bytes and i used hex editor to search for the matching bytes in zsnes savestate but it wasn't found (i maked sure the zsnes and bizhawk running game in the exact position for matching conditions).
What's wrong? :?: :?: :?: :?:

Oziphantom
Posts: 913
Joined: Tue Feb 07, 2017 2:03 am

Re: Zsnes savestate file format

Post by Oziphantom » Sat Aug 22, 2020 7:25 am

I cracked one open v0.6 in the header in a hex editor and modified the area at 0x618 - 0x817 with 00s and the sprites all went black. Might be a starting point to work out how colours are stored.

AnisSaouliBH
Posts: 11
Joined: Fri Aug 21, 2020 10:55 am

Re: Zsnes savestate file format

Post by AnisSaouliBH » Sat Aug 22, 2020 7:41 am

I tried it and wow everything blacked out.
I am going to do it in other games to make sure.

AnisSaouliBH
Posts: 11
Joined: Fri Aug 21, 2020 10:55 am

Re: Zsnes savestate file format

Post by AnisSaouliBH » Sat Aug 22, 2020 10:33 am

After some hex-editing i found something explains why i couldn't find the offset using bizhawk extracted colors, that's because the color format in zsnes is R5B5G5 and bizhawk uses normal R5G5B5 and i can say that the palette problem solved (really thank you :wink: ) and now moving to hard part about graphics locations in zsnes savestate.

Oziphantom
Posts: 913
Joined: Tue Feb 07, 2017 2:03 am

Re: Zsnes savestate file format

Post by Oziphantom » Sat Aug 22, 2020 10:51 am

AnisSaouliBH wrote:
Sat Aug 22, 2020 10:33 am
zsnes is R5B5G5 and bizhawk uses normal R5G5B5
???

The registers are most probably in order. So look for the PPU register values in hex that you know to be true

AnisSaouliBH
Posts: 11
Joined: Fri Aug 21, 2020 10:55 am

Re: Zsnes savestate file format

Post by AnisSaouliBH » Sat Aug 22, 2020 11:10 am

Now i only need to know where graphics located and how located.

AnisSaouliBH
Posts: 11
Joined: Fri Aug 21, 2020 10:55 am

Re: Zsnes savestate file format

Post by AnisSaouliBH » Sat Aug 22, 2020 12:01 pm

It's easy to locat the graphics in savestate using yy-chr but i want to make program that locate and extract graphics for it's own that's why i want to know how zsnes decide to place the graphics in the savestate.

AnisSaouliBH
Posts: 11
Joined: Fri Aug 21, 2020 10:55 am

Re: Zsnes savestate file format

Post by AnisSaouliBH » Sat Aug 22, 2020 4:49 pm

Anyone know how ?
Or maybe it's impossible ?

Post Reply