sf2000/tools/saveStateTool.htm
vonmillhausen 25ce2e3221 Transitioned to shared Javascript library
There was a lot of repeated JS across all my tools (e.g., image conversion, BIOS hash checking, etc.), and so I decided to move all shared code out to its own separate library. This will improve scalability and maintainability at the cost of portability - a fair trade in my opinion.

This work also involved large-scale refactoring of all of the tools. There's no actual functional difference (all the tools should behave exactly the same), bar some UI improvements for the oldest tools as a result of moving to the same codebase used by the more recent tools.
2023-06-26 14:11:01 +01:00

680 lines
56 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Data Frog SF2000 Save State Tool</title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="tools.css">
</head>
<body>
<h1>Data Frog SF2000 Save State Tool</h1>
<p>The SF2000 supports save states for games, but it bundles the save state data into a custom format including a thumbnail and metadata; this bundle can't be directly used as save state data for other emulator platforms (e.g., Retroarch). This tool allows you to extract raw save-state data and thumbnails from SF2000 save-state bundles, in case you want to use them with the same emulator on another device; it also allows you to take save states from another device, and convert them to a format the SF2000 can parse. Please note this tool is provided as-is; make sure you have backups of anything you care about before potentially replacing any files on your SF2000's microSD card! 🙂</p>
<p>This tool makes use of the <a href="https://github.com/nodeca/pako">pako</a> JavaScript library.</p>
<div id="initialWarning"></div>
<hr>
<div id="steps">
<section id="modeSection">
<h2>Step 1: Select Operating Mode</h2>
<p>This tool can operate in two main modes - you can use it to convert save states <em>from</em> the SF2000 format <em>to</em> raw save-state data (and optionally download the thumbnail), or you can use it to convert raw save state data <em>from</em> another emulator <em>to</em> the SF2000 format. Choose the mode you want, and follow the next instruction that appears.</p>
<div class="controlContainer">
<label class="control"><input type="radio" id="radioFrom" name="toolMode" value="fromSF2000" autocomplete="off"> Convert <em>from</em> SF2000</label><br>
<label class="control"><input type="radio" id="radioTo" name="toolMode" value="toSF2000" autocomplete="off"> Convert <em>to</em> SF2000</label>
</div>
</section>
</div>
<script src="pako.js"></script>
<script src="tools.js"></script>
<script>
// Global Variables
// ================
var previewCanvasData; // Binary data used for drawing to our preview canvas
var saveFileName; // Name of the save state file chosen by the user
var downloadName; // Name we're going to give any download being sent to the user
var saveData; // Binary data of a save state file
var thumbData; // Binary data of a save state thumbnail
var thumbWidth; // Integer width of a save state thumbnail
var thumbHeight; // Integer height of a save state thumbnail
var romFileGood; // Boolean indicating if a chosen save state file appears to be binary or not
// Display our initial warning note...
setMessage("warning", "initialWarning", "<strong><em>NOTE:</em></strong> This tool will <em>not</em> convert save states from one emulator's format to another; it <em>only</em> gives you either the raw save state data the SF2000 generated (when converting <em>from</em> the SF2000), or allows you to take any random file and shove it into the container format the SF2000 uses for save states (when converting <em>to</em> the SF2000)… whether or not the SF2000 is able to understand the file you give it is up to the SF2000, not to me! If you're converting save states to the SF2000, and the SF2000 doesn't work with whatever kind of save state you provided, there's nothing I can do about that.<br><br>You can <a href=\"https://vonmillhausen.github.io/sf2000/#emulators\" target=\"_blank\" rel=\"noreferrer noopener\">find a reference to all the specific emulators and versions used by the SF2000 here</a>; you'll probably only have success if you're using at least the same emulator, if not also the same version. Also, to have any chance of success, you must be using the exact same ROM on both devices, and make sure save state compression is turned off if your save state is coming from Retroarch!");
// When the tool loads, add some event watchers for when the Step 1 radio
// buttons change; and depending on which mode the user selects, begin
// rewriting the rest of the page...
var modes = document.getElementsByName("toolMode");
for (var i = 0; i < modes.length; i++) {
modes[i].addEventListener("change", function() {
// Clear out any HTML that might already exist after Step 1, just so
// things are nice and clean for Step 2 to load into...
while(document.getElementById("modeSection").nextSibling) {
document.getElementById("modeSection").nextSibling.remove();
}
// Add the appropriate Step 2 depending on what was selected...
if (this.value == "fromSF2000") {
setupStepTwo_From();
}
else if (this.value == "toSF2000") {
setupStepTwo_To();
}
});
}
// This function sets up the HTML for "Convert from SF2000 > Step 2", selecting
// a save state file from the SF2000's microSD card that the user wants to
// convert to raw save state data and/or a thumbnail...
function setupStepTwo_From() {
// Create the new section, add our heading and our instruction paragraph...
var html = "<section id=\"selectSF2000File\"><h2>Step 2: Select SF2000 Save State File</h2><p>Select the SF2000 save state file you want to convert from. The save states are usually stored in the <code>save</code> subfolder where the ROM for the game is located. There can be up to four saves states per game, with the extensions <code>.sa0</code>, <code>.sa1</code>, <code>.sa2</code> and <code>.sa3</code> respectively.</p><div id=\"step2Messages\"></div>";
// Add our file chooser...
html += "<div class=\"controlContainer\"><label class=\"control\"><input id=\"inputSAFile\" type=\"file\" accept=\".sa0,.sa1,.sa2,.sa3,.skp,application/octet-stream\"></label></div>";
// Close off our section...
html += "</section>";
// Finally, add a <hr> separator after the last step, and append the new step...
document.getElementById("steps").insertAdjacentHTML("beforeend", "<hr>");
document.getElementById("steps").insertAdjacentHTML("beforeend", html);
// Attach our event handler to our new file input control...
var sf2000SaveInput = document.getElementById("inputSAFile");
sf2000SaveInput.addEventListener("change", function() {
// The user has chosen a new file; it should be a binary blob we can try
// to interpret as a save state file. First let's clear any old messages...
document.getElementById("step2Messages").innerHTML = "";
// And also remove any old HTML after the current section...
while(document.getElementById("selectSF2000File").nextSibling) {
document.getElementById("selectSF2000File").nextSibling.remove();
}
// Now let's read in our file data as a binary stream...
var frSave = new FileReader();
saveFileName = event.target.files[0].name;
frSave.readAsArrayBuffer(event.target.files[0]);
frSave.onload = function(event) {
// Let's run the file's data through our validation function; if the
// function returns true, then the file was a valid SF2000 save
// state file, and our global variables have been updated with the
// save and thumbnail data... otherwise, it returns false and we let
// the user know the file didn't appear to be valid...
if (validateSave(new Uint8Array(event.target.result))) {
// Great, the user selected a valid SF2000 format save state file!
// On to Step 3!
setupStepThree_From();
}
else {
// Whoops, the file doesn't looke like it was an SF2000 save state file.
// Let the user know and return...
setMessage("error", "step2Messages", "ERROR: The selected file does not appear to be a valid SF2000 save state file.");
return;
}
}
});
}
// This function sets up the HTML for "Convert to SF2000 > Step 2", selecting
// the non-SF2000 save state file the user wants to convert to an SF2000 save
// state bundle...
function setupStepTwo_To() {
// Start our new section, add our header and our instructions...
var html = "<section id=\"selectStateFile\"><h2>Step 2: Save State File</h2><p>Select the save state file from your non-SF2000 emulator that you want to convert to an SF2000-compatible save state bundle.</p><div id=\"step2Messages\"></div>";
// Add our file chooser...
html += "<div class=\"controlContainer\"><label class=\"control\"><input id=\"inputStateFile\" type=\"file\"></label></div>";
// Close our section...
html += "</section>";
// Finally, add a <hr> separator after the last step, and append the new step...
document.getElementById("steps").insertAdjacentHTML("beforeend", "<hr>");
document.getElementById("steps").insertAdjacentHTML("beforeend", html);
// Attach our event handler to our new file input control...
var userFileInput = document.getElementById("inputStateFile");
userFileInput.addEventListener("change", function() {
// First let's clear any old messages...
document.getElementById("step2Messages").innerHTML = "";
// And also remove any old HTML after the current section...
while(document.getElementById("selectStateFile").nextSibling) {
document.getElementById("selectStateFile").nextSibling.remove();
}
// Now let's read in the file...
var frImage = new FileReader();
frImage.readAsDataURL(event.target.files[0]);
frImage.onload = function(event) {
// The file is loaded; let's check to make sure we got a binary file (can't
// really do much more validation than that, alas)...
if (!event.target.result.includes("application/octet-stream")) {
// Whoops! Doesn't look like the user provided a binary file, so can't be
// a save state!
setMessage("error", "step2Messages", "ERROR: The selected file does not appear to be a binary file, and therefore can't be a save state file; please make sure you're selecting a valid emulator save state file.");
return;
}
// If we're here then it was a binary file; read the data into our global
// saveData buffer...
var base64Data = event.target.result.substring(event.target.result.indexOf(",") + 1);
var binaryData = atob(base64Data);
saveData = new Uint8Array(binaryData.length);
for (var i = 0; i < binaryData.length; i++) {
saveData[i] = binaryData.charCodeAt(i);
}
// Let's check the provided data for Retroarch's save-state headers, and
// strip them out if we find them...
saveData = stripRetroarchHeaders(saveData);
// On to Step 3!
setupStepThree_To();
}
});
}
// This function sets up the HTML for "Convert from SF2000 > Step 2 > Step 3"...
function setupStepThree_From() {
// In this section, we'll be presenting the user with the thumbnail of
// their save state, and a download button for downloading the save
// state data itself. Let's start building our HTML...
var html = "<section id=\"sf2000StateDownload\"><h2>Step 3: Download Save State Data</h2><p>Below you'll find the thumbnail for your chosen save state file, as well as a download button which will let you download the raw save state data for use with other emulators/devices. If you want to save the thumbnail as well, just right-click or tap-and-hold on it like any other image, and save it that way.</p>";
// Next, we'll add the image preview...
html += "<div class=\"controlContainer\"><div class=\"control\"><canvas id=\"thumbnailPreview\"></canvas></div></div>";
// ... and the Download button...
html += "<div class=\"controlContainer\"><div class=\"control\"><input id=\"saveStateDownload\" type=\"button\" value=\"Download\"></div></div>";
// ... and lastly we'll close off our section...
html += "</section>";
// Add a <hr> separator after the previous step, and append the new step...
document.getElementById("steps").insertAdjacentHTML("beforeend", "<hr>");
document.getElementById("steps").insertAdjacentHTML("beforeend", html);
// Now, add our interactivity by attaching our event handler to the download
// button...
var downloadButton = document.getElementById("saveStateDownload");
downloadButton.addEventListener("click", function() {
// Before we kick-off our download function, let's determine the file
// name for the download. We'll default to just adding ".state" to the
// end, but we'll check specifically for the SF2000 double-extension
// naming convention (e.g., "Game.zgb.sa0"), and in that case we'll
// strip off both extensions and *then* add .state (Retroarch save
// state naming convention)...
downloadName = saveFileName + ".state";
var match = saveFileName.match(/(.+)\.([^.]+)\.([^.]+)/);
if (match) {
downloadName = match[1] + ".state";
}
downloadToBrowser(saveData, "application/octet-stream", downloadName);
});
// The last thing to do here in Step 3 is to perform our initial image
// data conversion and preview rendering... so let's do it!
convertFromSF2000AndRender();
}
// This function sets up the HTML for "Convert to SF2000 > Step 2 > Step 3"...
function setupStepThree_To() {
// In this section, we'll be rendering the HTML for some controls - the
// user needs to select the ROM file their new save state is for (so we
// can name the save state file correctly), and choose whether their new
// save state should be stored in slot 1, 2, 3 or 4 (again, required for
// the file name). Let's start by creating our new section, and add its
// heading and instruction paragraph...
html = "<section id=\"processUserFile\"><h2>Step 3: Select Game ROM And Slot Number</h2><p>To name your new SF2000 save state properly, this tool needs to know two things - the name of the game ROM file the save state is for, and which save slot (1, 2, 3 or 4) the save state should take up. Use the controls below to select your game ROM file from your SF2000's microSD card, and to choose which save slot you want.</p><p>When you've chosen a ROM file and a slot number, the Download button will become enabled, and can be used to download your new save state file. Put it in the <code>save</code> subfolder along-side wherever your ROM file is stored on the SF2000's microSD card (e.g., if your ROM file is <code>sd:/ROMS/Apotris.gba</code>, and you chose save slot 1, you'd put the resulting save state in <code>sd:/ROMS/save/Apotris.gba.sa0</code>).</p><p>The one special case is with arcade games; the ROM you need to select is one of the ones in the <code>sd:/ARCADE/bin/</code> folder, and the resulting save state bundle goes into <code>sd:/ARCADE/save/</code>. As an example, if you wanted to transfer a save state to the SF2000 for the game \"Metal Slug\" in slot 3, you'd select <code>sd:/ARCADE/bin/mslug.zip</code> and Slot 3, and the final location to put the save state would be <code>sd:/ARCADE/save/mslug.zip.sa2</code> - I hope that makes sense! You can <a href=\"https://vonmillhausen.github.io/sf2000/arcade/DataFrog_SF2000_FBA.html\" target=\"_blank\" rel=\"noreferrer noopener\">find a list of all potential arcade zip-file names and the full name of the game they represent here</a>, if it helps - the first column (\"rom\") is the name of the zip-file without the <code>.zip</code> part, and the second column (\"fullname\") is the full name of the game/romset.</p><div id=\"step3Messages\"></div>";
// Now let's add our controls (file browser for the game ROM, and four
// radio button inputs for the save state slot number); we'll group them
// in one of our control containers for neatness...
html += "<div class=\"controlContainer\">";
// ROM file browser...
html += "<div class=\"control\"><label>Select game ROM: <input id=\"inputROMFile\" type=\"file\"></label></div>";
// Save state slot number...
html += "<div id=\"slotSelector\" class=\"control\"><label><input type=\"radio\" name=\"saveSlot\" value=\"0\"> Save Slot 1</label><label><input type=\"radio\" name=\"saveSlot\" value=\"1\"> Save Slot 2</label><label><input type=\"radio\" name=\"saveSlot\" value=\"2\"> Save Slot 3</label><label><input type=\"radio\" name=\"saveSlot\" value=\"3\"> Save Slot 4</label></div>";
html += "</div>";
// ... and our Download button...
html += "<div class=\"controlContainer\"><div class=\"control\"><input id=\"saveStateDownload\" type=\"button\" value=\"Download\" disabled></div></div>";
// ... and lastly we'll close off our section...
html += "</section>";
// Add a <hr> separator after the previous step, and append the new step...
document.getElementById("steps").insertAdjacentHTML("beforeend", "<hr>");
document.getElementById("steps").insertAdjacentHTML("beforeend", html);
// Now we'll attach event listeners for all of the interactive elements in
// this step. Mostly this will just be for storing the provided details;
// we'll also call a little helper function for each one which'll determine
// if the Download button should be enabled or not...
// Let's start with the ROM file select...
var romFileInput = document.getElementById("inputROMFile");
romFileInput.addEventListener("change", function() {
// First let's clear any old messages...
document.getElementById("step3Messages").innerHTML = "";
// We're using a cheeky global variable to store whether this event
// listener thinks the chosen file is "good" (i.e., a binary file);
// a separate function then uses this information as part of a check
// to determine if the Download button should be enabled or not. We
// default to "false", and only set to true if the newly chosen file
// appears to be a binary file...
romFileGood = false;
// Now let's read in the file; we don't really care about its contents
// per-se (we only need it for its file name), but we may as well confirm
// it's a binary file while we're here...
var frImage = new FileReader();
saveFileName = event.target.files[0].name;
frImage.readAsDataURL(event.target.files[0]);
frImage.onload = function(event) {
// Check to make sure it's binary...
if (!event.target.result.includes("application/octet-stream")) {
// It's not! Our romFileGood variable is already set to false, so
// run our Download button state-checking function to make sure
// the button is disabled...
userStateDownloadCheck();
// Display a message to the user and return...
setMessage("error", "step3Messages", "ERROR: The selected file does not appear to be a binary file, and therefore can't be a game ROM file; please make sure you're selecting a valid game ROM file.");
return;
}
else {
// The file appears to be binary, at least! Update our romFileGood
// global to true, and run our Download button state-checking
// function (button may still be disabled if a save state slot
// hasn't been selected)...
romFileGood = true;
userStateDownloadCheck();
}
}
});
// Next up, our radio buttons...
var slots = document.getElementsByName("saveSlot");
for (var i = 0; i < slots.length; i++) {
slots[i].addEventListener("change", function() {
// The only thing we'll do here is run our Download button
// state-checking function; we'll pull the actual data from the
// selected radio button at run time during the download process...
userStateDownloadCheck();
});
}
// And last but not least, our Download button...
var dButton = document.getElementById("saveStateDownload");
dButton.addEventListener("click", function() {
// We're actually going to be doing quite a bit here - we'll assemble
// the binary blob of the new save state bundle before handing it off
// to our download function. First, let's try zlib-deflating the user's
// save state data...
var compressedSaveState = compressZlib(saveData);
if (!(compressedSaveState instanceof Uint8Array)) {
// Oh! We failed to compress the save state data using the pako
// library for some reason... display a message to the user and
// return...
setMessage("error", "step3Messages", "ERROR: Failed to compress the chosen save state file's data!");
return;
}
// We also need to check our compressed data is of an appropriate size...
if (compressedSaveState.length < 0 || compressedSaveState.length > 4294967295) {
setMessage("error", "step3Messages", "ERROR: Compressed save state data is not valid (either it was 0 bytes in length, or was larger than 4 GB)!");
return false;
}
// Great! We have enough data now to start assembling our final binary
// blob; we'll just re-use our saveData global for convenience...
saveData = new Uint8Array(4 + compressedSaveState.length + 4 + 4 + 4 + 15979 + 4);
// We'll also use a little "offset" variable, to help keep track of
// where we are in the array as we go...
var offset = 0;
// The first four bytes are a little-endian Uint32 version of our
// compressed save state data's length...
saveData[offset + 0] = compressedSaveState.length & 0xFF;
saveData[offset + 1] = (compressedSaveState.length >> 8) & 0xFF;
saveData[offset + 2] = (compressedSaveState.length >> 16) & 0xFF;
saveData[offset + 3] = (compressedSaveState.length >> 24) & 0xFF;
offset += 4;
// The next sequence of bytes are all of our compressed save state data,
// so let's just copy it in...
for (var i = 0; i < compressedSaveState.length; i++) {
saveData[offset] = compressedSaveState[i];
offset += 1;
}
// For reasons, we'll need our current offset a little later on, so
// let's make a note of it now...
var thumbnailStart = offset;
// The next three sets of four bytes are little-endian Uint32 versions
// of our thumbnail image's width, height and compressed data length;
// I've got all of those numbers pre-calculated, so I'll just add them
// in...
// Width...
saveData[offset + 0] = 64;
saveData[offset + 1] = 1;
saveData[offset + 2] = 0;
saveData[offset + 3] = 0;
offset += 4;
// Height...
saveData[offset + 0] = 240;
saveData[offset + 1] = 0;
saveData[offset + 2] = 0;
saveData[offset + 3] = 0;
offset += 4;
// Length...
saveData[offset + 0] = 107;
saveData[offset + 1] = 62;
saveData[offset + 2] = 0;
saveData[offset + 3] = 0;
offset += 4;
// Next comes the zlib compressed thumbnail data itself; I've already
// got that too :)
thumbData = atob("eJztnU18E9e5/3sDAfOS+2FJd7CDGzA2ecO3XcS8WjbJDV5d+26KWWGagGXSBpsusHgxliGfD/YqVjdFWd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fTA8uxH8DOQ3x31AvdviSOZqcW5mzGZaJuMeqOkTYxJf1NW4cXrlPTUINwVZ+Js8jGyavgSlybfm5fW19WR4MU7FM8tyMr5I3C2scQw1CL4OwJsqizfHeJfuvMFcgZ0vx1nyy/Fn+Ks1fQflLhKy5pB5ciPfm8+AQbxauqDOER9ik9wDxmJk146um/0rGbM6Z5z7rBt8cUUrfTFOLwJLLnyEvf74cevzX9eAQH87nwYX4cDQ3LVyWP8tfJflbsv8W0Hfv5dTlNU//vd/8TO8aHcUqzKfp1/L2TcEl/MGl1BV4sNd/hS2uCcFrmL5bCG+atIj++4ZSPg/WzBWRM5dalj/L30rgT/tvROaW2mtQFv+N4MFhzPll1zmPGT/L7C/QDBoyOffz3CAO8/Lo9d8AHy7Kf0N8ONxJi5Plz/JXSf58/Xcpa44X8m9pK7SVxH+12jwKeizg+eKr+RTGWhBzWdeHzOPBbziKlMP4MBaFF/HOwh032vwjy5/lr5z8FeK/Bc8zD9GyeW+I/wZ5bSkY9stVAhVSgxTiv4V4cGQmAzy4MFeNLsuf5a+S/Pn5byFM5nBZTpXKf0P8OIqvBilpKIr3msx5OXN5K1UGU8Yaw/Jn+Vup/M21zhXMXBYDRfwLdGVP/0HUXtSYVyX21jAV5LuOsj7xYmuRIP/1+HBU//X14TLmf5Y/y18l+Ataf83lMWIWU1YfLhdPRXqtV1G9N5L/hvQbvGEoEmsrwH8tf5a/SvNXjAfn+HCxnvxPxKYvowVIrtnt/byX03/Fg6P6b44HL3MOY/mz/FWSv/8H7F6WNw==");
for (var i = 0; i < thumbData.length; i++) {
saveData[offset] = thumbData.charCodeAt(i);
offset += 1;
}
// And lastly, our final 4 bytes are a little-endian Uint32 version of
// the offset within the file where the thumbnail stuff starts...
saveData[offset + 0] = thumbnailStart & 0xFF;
saveData[offset + 1] = (thumbnailStart >> 8) & 0xFF;
saveData[offset + 2] = (thumbnailStart >> 16) & 0xFF;
saveData[offset + 3] = (thumbnailStart >> 24) & 0xFF;
offset += 4;
// Just as a final sanity check, offset should now be equal to
// saveData.length... let's confirm!
if (offset !== saveData.length) {
setMessage("error", "step3Messages", "ERROR: Inconsistent data length when building save state bundle!");
return false;
}
// Before we kick-off our download function, let's determine the file
// name for the download. The SF2000 uses a slightly odd naming
// convention for its save state files. If the ROM is in the "USER"
// folder on the microSD card, then the extension of the ROM file
// gets capitalised in the save state name (e.g., "Apotris.sfc" would
// become "Apotris.SFC.sa0")... but this *only* happens in the "USER"
// folder from what I can tell. There's no way for me to know what
// folder the user's selected ROM is stored in, so I'm not going to
// bother matching that same convention here (and the SF2000 doesn't
// seem to care about the capitalisation when it comes to loading
// save states)... just thought I'd mention it! So all we're going to
// do here is just stick the appropriate ".sa#" extension on the end
// of whatever's store in saveFileName...
downloadName = saveFileName + ".sa" + document.querySelector('input[name="saveSlot"]:checked').value;
// Right, that should be everything we need... to the Downloadmobile!
downloadToBrowser(saveData, "application/octet-stream", downloadName);
});
}
// This function takes in a Uint8Array object, and attempts to inflate it using
// the pako library; returns a Uint8Array object containing the inflated data
// on success, or null on failure...
function decompressZlib(data) {
if (!(data instanceof Uint8Array)) {
return null;
}
try {
let decompressed = pako.inflate(data);
return decompressed;
} catch (error) {
return null;
}
}
// This function takes in a Uint8Array object, and attempts to deflate it
// using the pako library; returns a Uint8Array object containing the defalated
// data on success, or null on failure...
function compressZlib(data) {
if (!(data instanceof Uint8Array)) {
return null;
}
try {
let compressed = pako.deflate(data);
return compressed;
} catch (error) {
return null;
}
}
// This function validates that a provided Uint8Array object matches the format
// of an SF2000 save state file, and assigns the state data, thumbnail data and
// thumbnail dimensions to our global storage variables. The function returns
// true when successfully processing the array, or false otherwise...
function validateSave(data) {
// First check if data is a Uint8Array object...
if (!(data instanceof Uint8Array)) {
return false;
}
// Check if data has at least 20 bytes...
if (data.length < 20) {
return false;
}
// Read the first four bytes as a little-endian number and store it in saveLength...
let saveLength = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24);
// Check if saveLength is positive and does not exceed the remaining bytes...
if (saveLength <= 0 || saveLength > data.length - 16) {
return false;
}
// Check if the next two bytes are [120, 156] (zlib header used by SF2000)...
if (data[4] !== 120 || data[5] !== 156) {
return false;
}
// Attempt to inflate the zlib data and store it in saveData...
saveData = decompressZlib(data.slice(4, 4 + saveLength));
if (!(saveData instanceof Uint8Array)) {
return false;
}
// Read the next four bytes as a little-endian number and store it in thumbWidth...
thumbWidth = data[4 + saveLength] + (data[5 + saveLength] << 8) + (data[6 + saveLength] << 16) + (data[7 + saveLength] << 24);
// Check if thumbWidth is positive...
if (thumbWidth <= 0) {
return false;
}
// Read the next four bytes as a little-endian number and store it in thumbHeight...
thumbHeight = data[8 + saveLength] + (data[9 + saveLength] << 8) + (data[10 + saveLength] << 16) + (data[11 + saveLength] << 24);
// Check if thumbHeight is positive...
if (thumbHeight <= 0) {
return false;
}
// Read the next four bytes as a little-endian number and store it in thumbLength...
let thumbLength = data[12 + saveLength] + (data[13 + saveLength] << 8) + (data[14 + saveLength] << 16) + (data[15 + saveLength] << 24);
// Check if thumbLength is positive and does not exceed the remaining bytes...
if (thumbLength <= 0 || thumbLength > data.length - (16 + saveLength)) {
return false;
}
// Check if the next two bytes are [120, 156] (zlib header used by SF2000)...
if (data[16 + saveLength] !== 120 || data[17 + saveLength] !== 156) {
return false;
}
// Store the next thumbLength bytes in thumbData, and attempt to inflate it...
thumbData = decompressZlib(data.slice(16 + saveLength, 16 + saveLength + thumbLength));
if (!(thumbData instanceof Uint8Array)) {
return false;
}
// Check to make sure there's only four remaining bytes...
if (data.length - (16 + saveLength + thumbLength) !== 4) {
return false;
}
// Store the last four bytes in lastFour...
let lastFour = data[data.length - 4] + (data[data.length -3 ] <<8 )+ (data[data.length -2 ]<<16 )+ (data[data.length -1 ]<<24 );
// Confirm the last four bytes equal the offset within the data of thumbWidth,
// i.e., first zlib stream length + 4...
if (lastFour !== saveLength + 4) {
return false;
}
// Provided data seems good, so return true...
return true;
}
// This function runs through our binary save state data, and checks it for any
// of Retroarch's save state headers. If it finds them, it strips them out...
// See https://github.com/libretro/RetroArch/blob/master/tasks/task_save.c
function stripRetroarchHeaders(input) {
// Define an array of the possible Retroarch headers that we're looking for...
let headers = ["RASTATE" + String.fromCharCode([1]), "MEM ", "RPLY", "ACHV", "END "];
// Define a helper function that checks if a header starts at the provided
// index in the data stream...
function isHeader(array, i) {
// Starting at an index of i, convert the next 8 bytes to a string...
let str = String.fromCharCode(...array.slice(i, i + 8));
// Check if the string includes any of our defined headers...
for (let i = 0; i < headers.length; i++) {
if (str.includes(headers[i])) {
// It does! A header has been found, return true...
return true;
}
}
// If we're here, we didn't find a matching header, so return false...
return false;
}
// Create an intermediate storage array with the same length as input; we
// don't know how long our output length will be yet, but it won't be any
// longer than input, and this array will hold our modified data while we
// work...
let intermediate = new Uint8Array(input.length);
// Now, it's on to the meat of this function. We're going to loop through
// all of our current save state data, byte by byte, and check to see if
// we find a Retroarch save state header starting at the current byte. If
// we don't, we just copy the current byte to our intermediate storage
// array. If we *do* find a Retroarch header, we skip forward 8 bytes (all
// the Retroarch save state header blocks are 8 bytes long)...
let index = 0;
let intermediateIndex = 0;
while (index < input.length && !isNaN(input[index])) {
// Check if we have a header starting at the current index in our data...
if (isHeader(input, index)) {
// We do! Don't write any data, and just skip forward 8 bytes...
index += 8;
}
else {
// No header here, so write the current byte to our intermediate
// storage array...
intermediate[intermediateIndex] = input[index];
// ... and increment our indexes...
index++;
intermediateIndex++;
}
}
// If we're here, intermediate should contain our final output data.
// If the output data length is the same as the input data lenth, then
// we didn't change anything and can just return the input. Otherwise,
// we stripped *something* from the input data... so we'll copy our
// new, shorter intermediate data to a correctly sized Uint8Array
// object, and return that instead...
if (intermediateIndex == input.length) {
return input;
}
else {
let output = new Uint8Array(intermediateIndex);
for (let i = 0; i < intermediateIndex; i++) {
output[i] = intermediate[i];
}
return output;
}
}
// This function checks if we're both happy that the user-selected ROM file
// is binary, AND that a save state slot radio button has been selected; if
// both are true, it enables the download button, otherwise it makes sure
// the button is disabled...
function userStateDownloadCheck() {
if (romFileGood === true && document.querySelector('input[name="saveSlot"]:checked')) {
// Looks good - enable Download button!
var dButton = document.getElementById("saveStateDownload");
dButton.removeAttribute("disabled");
}
else {
// No good - disable Download button!
var dButton = document.getElementById("saveStateDownload");
dButton.setAttribute("disabled", "");
}
}
// This function takes our global thumbData object (Uint8Array), converts
// it to an ImageData object and assigns it to our previewCanvasData
// global; it then renders that ImageData to our preview canvas...
function convertFromSF2000AndRender() {
previewCanvasData = rgb565ToImageData(thumbData, thumbWidth, thumbHeight);
var canvas = document.getElementById("thumbnailPreview");
var context = canvas.getContext("2d");
canvas.width = previewCanvasData.width;
canvas.height = previewCanvasData.height;
context.clearRect(0, 0, canvas.width, canvas.height);
context.putImageData(previewCanvasData, 0, 0);
}
</script>
<hr>
<p><a rel="license" href="https://creativecommons.org/publicdomain/zero/1.0/">CC0</a>: public domain. Version 1.2, 20230626.1</p>
</body>
</html>