Improving compiler.

This commit is contained in:
2022-01-04 21:36:37 -08:00
parent c9ebb85d13
commit dfd205ce22
28 changed files with 500 additions and 183 deletions

29
scripts/string2gb.js Normal file
View File

@@ -0,0 +1,29 @@
const fs = require('fs');
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) => {
const letters = [];
for(let i = 0; i < string.length; i++) {
letters.push(getCodeFrom(string[i]));
}
out = '#include "libs.h"\n\n';
out += `#define STR_${name}_LENGTH ${string.length}\n`;
out += `extern const uint8_t STR_${name}_DATA[];\n\n\n`
out += `const uint8_t STR_${name}_DATA[] = {\n` + arrayToString(letters) + `\n};`;
fs.writeFileSync('out.c', out);
}
module.exports = {
string2gb
};