User File #31784617158843553

Upload All User Files

#31784617158843553 - Final Fantasy VI (J) - checksum lua script

ff6_lsnes_checksum.lua
1068 downloads
Uploaded 6/23/2016 9:52 AM by keylie (see all 119)
Script to make easier the manipulation of the checksum. You must set the save slot and the last address written in the lua script. Then the two numbers printed on screen (computed and stored checksums) must match when you perform the reset.
saveslot = 3 -- between 1 and 3
lastaddress = 0x1F64 -- last WRAM address written before triggering the reset

-- End of configuration

sramaddress = 1 + lastaddress - 0x1600 + 0xA00 * (saveslot - 1)
sramend = 0xA00 * saveslot - 3

printcheck = function()
  checksum = 0
  for i=0x1600, lastaddress do
    checksum = checksum + memory2.WRAM:byte(i)
  end
  
  for j=sramaddress,sramend do
    checksum = checksum + memory2.SRAM:byte(j)
  end
  
  writtenchecksum = memory2.SRAM:word(sramend+1)
  gui.text(8, 420, string.format("Checksum computed %x, stored %x", bit.band(checksum, 0xffff), writtenchecksum))
  
end

callback.register("paint", printcheck)