portal64-still-alive/tools/generate_level_ld.js

33 lines
972 B
JavaScript
Raw Normal View History

2022-07-24 10:52:28 -04:00
const fs = require('fs');
const path = require('path');
const InvalidTokenCharacter = /[^A-Za-z0-9_]/gim;
function getSegmentName(objectLocation) {
2022-07-24 10:52:28 -04:00
const levelName = path.basename(objectLocation);
const noExtension = levelName.slice(0, levelName.length - path.extname(levelName).length);
return noExtension.replace(InvalidTokenCharacter, '_');
}
function generateLD(segmentLocation, objectLocation) {
const segmentName = getSegmentName(objectLocation);
2022-07-24 10:52:28 -04:00
return `
BEGIN_SEG(${segmentName}, ${segmentLocation})
2022-07-24 10:52:28 -04:00
{
${objectLocation}(.data);
${objectLocation}(.bss);
}
END_SEG(${segmentName})
`;
}
function generateData(segmentLocation, objectLocations) {
return objectLocations.map(objectLocation => generateLD(segmentLocation, objectLocation)).join('\n');
2022-07-24 10:52:28 -04:00
}
const output = process.argv[2];
const segmentLocation = process.argv[3];
2022-07-24 10:52:28 -04:00
fs.writeFileSync(output, generateData(segmentLocation, process.argv.slice(4)));