Skip to content

Instantly share code, notes, and snippets.

@nurpax
Created February 17, 2021 17:30
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 nurpax/a55779dfaf9265b4470f74a3ea9896d8 to your computer and use it in GitHub Desktop.
Save nurpax/a55779dfaf9265b4470f74a3ea9896d8 to your computer and use it in GitHub Desktop.
text example
!use "./text" as text
!byte text("testing 123")
function asc2int(asc) {
return asc.charCodeAt(0)
}
function convertAsciiToScreencode(asc) {
if (asc.length !== 1) {
return null
}
if (asc >= 'a' && asc <= 'z') {
return asc2int(asc) - asc2int('a') + 1
}
if (asc == 'ä') {
return 1;
}
if (asc == 'ö') {
return asc2int('o') - asc2int('a') + 1
}
if (asc >= 'A' && asc <= 'Z') {
return asc2int(asc) - asc2int('A') + 0x41
}
if (asc >= '0' && asc <= '9') {
return asc2int(asc) - asc2int('0') + 0x30
}
const otherChars = {
'@': 0,
' ': 0x20,
'!': 0x21,
'"': 0x22,
'#': 0x23,
'$': 0x24,
'%': 0x25,
'&': 0x26,
'(': 0x28,
')': 0x29,
'*': 0x2a,
'+': 0x2b,
',': 0x2c,
'-': 0x2d,
'.': 0x2e,
'/': 0x2f,
':': 0x3a,
';': 0x3b,
'<': 0x3c,
'=': 0x3d,
'>': 0x3e,
'?': 0x3f
}
if (asc in otherChars) {
return otherChars[asc]
}
return null
}
module.exports = ({}, str) => {
const arr = [];
const s = str.toLowerCase();
for (let c in s) {
arr.push(convertAsciiToScreencode(s[c]));
}
return arr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment