Skip to content

Instantly share code, notes, and snippets.

@kion-dgl
Created July 5, 2019 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kion-dgl/779c6bff06edca42105db49ae79c1a06 to your computer and use it in GitHub Desktop.
Save kion-dgl/779c6bff06edca42105db49ae79c1a06 to your computer and use it in GitHub Desktop.
A short script that looks through the high work memory for sega saturn to look for possible xp data structs
"use strict";
const fs = require("fs");
const fp = fs.readFileSync("hwram.bin");
const ptr_keys = [
"vlist_offset",
"plist_offset",
"attr_offset",
"vntbl"
];
let i = 0;
do {
let struct = {
offset : i,
vlist_offset : fp.readUInt32BE(i + 0),
vlist_count : fp.readUInt32BE(i + 4),
plist_offset : fp.readUInt32BE(i + 8),
plist_count : fp.readUInt32BE(i + 12),
attr_offset : fp.readUInt32BE(i + 16),
vntbl : fp.readUInt32BE(i + 20)
};
let isStruct = true;
ptr_keys.forEach(function(key) {
if((struct[key] % 4) !== 0) {
isStruct = false;
}
if((struct[key] & 0x06000000) !== 0x06000000) {
isStruct = false;
}
});
for(let key in struct) {
if(struct[key] === 0) {
isStruct = false;
}
}
if(struct.vlist_count > 0xffff) {
isStruct = false;
}
if(struct.plist_count > 0xffff) {
isStruct = false;
}
if(!isStruct) {
i += 4;
continue;
}
formatHex(struct);
console.log(struct);
i += 0x18;
} while(i < fp.length - 0x18);
function formatHex(obj) {
for(let key in obj) {
let num = obj[key].toString(16);
while(num.length < 6) {
num = "0" + num;
}
obj[key] = "0x" + num;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment