This repository has been archived on 2024-11-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Dawn-GB/scripts/string2gb.js

37 lines
986 B
JavaScript

const fs = require('fs');
const path = require('path');
const { arrayToString } = require('./util');
const FONT_CHARACTER_FIRST = 33;
const FONT_DATA_POSITION = 4;
const getCodeFrom = l => {
const cc = l.charCodeAt(0)
if(l == '\n' || l == ' ') return cc;
return cc - FONT_CHARACTER_FIRST + FONT_DATA_POSITION
}
const string2gb = (string, name, dirOut) => {
const letters = [];
for(let i = 0; i < string.length; i++) {
letters.push(getCodeFrom(string[i]));
}
let outH = '#include "libs.h"\n\n';
outH += `#define STR_${name}_LENGTH ${string.length}\n`;
outH += `extern const uint8_t STR_${name}_DATA[];`;
let outC = `#include "${name}.h"\n\n`;
outC += `const uint8_t STR_${name}_DATA[] = {\n` + arrayToString(letters) + `\n};`;
const fileH = path.join(dirOut, `${name}.h`);
const fileC = path.join(dirOut, `${name}.c`);
fs.writeFileSync(fileH, outH);
fs.writeFileSync(fileC, outC);
return { fileH, fileC };
}
module.exports = {
string2gb
};