Users browsing this thread: 1 Guest(s)
FF4 SNES SRM Checksum

#11
Posts: 7
Threads: 1
Thanks Received: 0
Thanks Given: 0
Joined: Feb 2017
Reputation: 0
Status
None
I wrote a quick MATLAB script (code below) that generates the correct checksum based on your comments and from the assembly you sent. It mostly works save for that pesky initial checksum value. The initial value at address $41 unfortunately does not seem to be 0, and further, it seems to depend on either the save slot or some combination of information contained within. Luckily the initial value is always a fairly low number (> -100 or so signed... ~>65460 if unsigned). Also, the same initial value for slot 0 on one file isn't necessarily the same initial value for slot 0 on another file.

Is there something from your ROM assembly source that specifies what goes into address $41? It's got to be deterministic and probably calculated during some part of the save routine.

I forgot how much I disliked assembly code (and all the direct, indirect, absolute, immediate, etc. addressing schemes)! If I had some easy way of getting the disassembly from the ROM and being able to debug it, I could look into it as well at some point. What sort of debugging/disassembly setup are you using?

*** MATLAB script follows in case anybody else would like to use it ***

% Open the FF2 SNES SRM save file
fid = fopen('FF4_in_use.srm', 'r');

% User selects which save slot to use (0, 1, 2, or 3)
slot_offset = 0;

% Position file pointer at correct byte offset in file
fseek(fid, (slot_offset*2048), 'bof');

% Read 2kB save slot data. Cast as 8-bit Unsigned Integer
bytes = fread(fid, 2048, 'uint8=>uint8');

% Store off checksum in file
checksum = (uint32(bytes(2045))*256) + uint32(bytes(2046));

% Apply starting offset (LDA $41) - Seems to be based on slot number?
if(slot_offset == 0)
D8acc = intmax('uint16') - 81;
end
if(slot_offset == 1)
D8acc = intmax('uint16') - 22;
end
if (slot_offset == 2)
D8acc = intmax('uint16') - 71;
end
if (slot_offset == 3)
D8acc = intmax('uint16') - 72;
end

% Compute 16-bit data values and accumulate. Loop 0x7fa times
% NUMber of ELements in BYTES - 6 = 0x7fa
for i=1Sadnumel(bytes)-6)
% Handle initial word 0x00bb
if(i==1)
a = 0;
b = bytes(i);
c = uint32(uint32(a)*256) + uint32(b);
% Handle other words 0xaabb
else
a = bytes(i-1);
b = bytes(i);
c = uint32(uint32(a)*256) + uint32(b);
end
% Look at sanity check hex value of 0xaabb
d = dec2hex(c, 4);
% Accumulate running checksum
D8acc = uint32(D8acc) + uint32©;
end

while (D8acc >= 65536)
D8acc = D8acc - 65536;
carry = 1;
end

% Get final calculated checksum and compare to save slot checksum
E8acc = dec2hex(D8acc, 4);
checksum_hex = dec2hex(checksum, 4);
if (E8acc == checksum_hex)
disp('CHECKSUMS MATCH');
else
disp('CHECKSUMS DO NOT MATCH');
end

fclose(fid);
  Find
Quote  



Messages In This Thread
FF4 SNES SRM Checksum - by stonerbot613 - 02-10-2017, 09:44 PM
RE: FF4 SNES SRM Checksum - by madsiur - 02-11-2017, 10:55 AM
RE: FF4 SNES SRM Checksum - by stonerbot613 - 02-12-2017, 12:15 AM
RE: FF4 SNES SRM Checksum - by madsiur - 02-12-2017, 12:46 AM
RE: FF4 SNES SRM Checksum - by Vertigo - 02-12-2017, 12:48 AM
RE: FF4 SNES SRM Checksum - by stonerbot613 - 02-12-2017, 01:11 AM
RE: FF4 SNES SRM Checksum - by m06 - 02-12-2017, 03:05 PM
RE: FF4 SNES SRM Checksum - by stonerbot613 - 02-12-2017, 03:50 PM
RE: FF4 SNES SRM Checksum - by m06 - 02-12-2017, 04:09 PM
RE: FF4 SNES SRM Checksum - by assassin - 02-12-2017, 04:41 PM
RE: FF4 SNES SRM Checksum - by stonerbot613 - 02-13-2017, 12:34 AM
RE: FF4 SNES SRM Checksum - by m06 - 02-13-2017, 04:00 AM
RE: FF4 SNES SRM Checksum - by assassin - 02-13-2017, 06:37 AM
RE: FF4 SNES SRM Checksum - by stonerbot613 - 02-13-2017, 03:21 PM
RE: FF4 SNES SRM Checksum - by m06 - 02-13-2017, 04:38 PM
RE: FF4 SNES SRM Checksum - by stonerbot613 - 02-13-2017, 05:34 PM
RE: FF4 SNES SRM Checksum - by m06 - 02-13-2017, 07:10 PM
RE: FF4 SNES SRM Checksum - by assassin - 02-13-2017, 07:37 PM
RE: FF4 SNES SRM Checksum - by m06 - 03-01-2017, 01:37 PM
RE: FF4 SNES SRM Checksum - by Grandirus - 04-27-2017, 12:26 AM

Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite