Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix special var names #37

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions src/byte-mangling.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ module.exports = {

intToBytes,
bytesToInt,
asciiToBytes,
bytesToAscii,
zeroTerminate,

chunkArray
}
Expand Down Expand Up @@ -156,25 +155,12 @@ function _bytesSafeInteger(bytes) {
return false;
}

function asciiToBytes(string, length) {
length = length || string.length + 1;
const TE = typeof TextEncoder !== 'undefined' ? TextEncoder : require('util').TextEncoder;
const bytes = new TE("utf-8").encode(string);
const result = new Uint8Array(length);
result.set(bytes.slice(0,length));
return result;
}

function bytesToAscii(bytes) {
// A string can be zero-terminated. Make sure we respect that
const index = bytes.indexOf(0);
if ( index >= 0 ) {
bytes = bytes.slice(0, index);
}

// Interpret the rest as UTF-8 bytes
const TD = typeof TextDecoder !== 'undefined' ? TextDecoder : require('util').TextDecoder;
return new TD("utf-8").decode(bytes);
// Terminate an array of bytes at the first zero, stripping off the zero and
// anything that may come after. If no zeroes are found, don't touch the input.
function zeroTerminate(bytes) {
const firstZero = bytes.indexOf(0);
if ( firstZero == -1 ) return bytes;
return bytes.slice(0, firstZero);
}

// Split up an array in pieces, each of a size defined in sizes. If we run out
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/ez80/ti83pce.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const properties = {
productName: "TI-83 Premium CE"
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/ez80/ti83pceep.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const properties = {
productName: "TI-83 Premium CE"
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/ez80/ti84pce.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const properties = {
productName: "TI-84 Plus CE"
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/ez80/ti84pcet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const properties = {
productName: "TI-84 Plus CE"
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/ez80/ti84pcetpe.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const properties = {
productName: "TI-84 Plus CE"
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/z80/ti82a.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const properties = {
productName: "TI-82 Advanced"
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/z80/ti84p.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const properties = {
productId: 0xe003
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/z80/ti84pcse.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const properties = {
productName: "TI-84 Plus C Silver Edition"
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/z80/ti84pse.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const properties = {
productName: "TI-84 Plus Silver Edition"
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
3 changes: 3 additions & 0 deletions src/calculators/z80/ti84pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const properties = {
productName: "TI-84 Plus T"
},

// This is the character encoding scheme that the device expects
characterEncoding: 'TI-84 Plus',

// These are the file types we can send this particular device
compatibleFiles: [
'TI-83',
Expand Down
53 changes: 53 additions & 0 deletions src/character-encoding/convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// All the conversion magic for character encoding, to and from different
// formats and bytes

module.exports = {
parseAsUTF,
parseAsTIChars,
UTFToBytes
};

const charEncodings = {
'TI-73': require('./ti73'),
'TI-82': require('./ti82'),
'TI-83': require('./ti83'),
'TI-84 Plus': require('./ti8x+'),
'TI-85': require('./ti85'),
'TI-86': require('./ti86'),
'TI-89': require('./ti9x'),
'TI-92': require('./ti9x'),
'TI-92 Plus': require('./ti9x'),
'TI-V200': require('./ti9x'),
//'TI-CBL2': require(???),
}

function parseAsUTF(bytes) {
// A string can be zero-terminated. Make sure we respect that
const index = bytes.indexOf(0);
if ( index >= 0 ) bytes = bytes.slice(0, index);

// Interpret the rest as UTF-8 bytes
const TD = typeof TextDecoder !== 'undefined' ? TextDecoder : require('util').TextDecoder;
return new TD("utf8").decode(bytes);
}

function parseAsTIChars(bytes, calcType) {
// A string can be zero-terminated. Make sure we respect that
const index = bytes.indexOf(0);
if ( index >= 0 ) bytes = bytes.slice(0, index);

// Interpret the rest as a TI encoded string
const charset = charEncodings[calcType];
if (!charset) return "Decoding error: can't decode strings for this calculator type";
let output = '';
for ( c of bytes ) {
output += String.fromCharCode(charset[c]);
}
return output;
}

function UTFToBytes(string) {
const TE = typeof TextEncoder !== 'undefined' ? TextEncoder : require('util').TextEncoder;
const bytes = new TE("utf-8").encode(string);
return new Uint8Array(bytes);
}
7 changes: 7 additions & 0 deletions src/character-encoding/normalize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// The character sets from tilibs contain hexadecimal numbers and characters.
// In C this is all just binary numbers, but JavaScript interprets the
// characters as strings and messes things up. This normalizes it all back down
// to numeric values.

module.exports = charset =>
charset.map(c => typeof c == 'string' ? c.charCodeAt(0) : c);
52 changes: 52 additions & 0 deletions src/character-encoding/ti73.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Conversion table for going from TI characters to UTF16
// Adapted from https://github.com/debrouxl/tilibs/blob/experimental2/libticonv/trunk/src/charset.cc

module.exports = require('./normalize')([
'\0', 0x3b7, 'u', 'v', 'w', 0x25b6, 0x2191, 0x2193, // [0x01-0x05] != TI83
0x222b, 'x', 176, 184, 183, 0x22ba, 179, 'F',

0x221a, 180, 178, 0x2220, 176, 0x2b3, 0x22ba, 0x2264,
0x2260, 0x2265, 0x2212, 0xd875dda4,0x2192,'?', 0x2191, 0x2193,

' ', '!', '\"', '#', 0x2074, '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',

'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',

'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',

'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 0x3b8, '\\', ']', '^', '_',

'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',

'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '{', '|', '}', '~', '=',

0x2080, 0x2081, 0x2082, 0x2083, 0x2084, 0x2085, 0x2086, 0x2087,
0x2088, 0x2089, 192+1, 192+0, 192+2, 192+4, 224+1, 224+0,

224+2, 224+4, 200+1, 200+0, 200+2, 200+4, 231+1, 231+0,
231+2, 231+4, 204+1, 204+0, 204+2, 204+3, 236+1, 236+0,

236+2, 236+3, 210+1, 210+0, 210+2, 210+4, 242+1, 242+0,
242+2, 242+4, 217+1, 217+0, 217+2, 217+3, 249+1, 249+0,

249+2, 249+3, 199, 231, 209, 204, '\'', '`',
0x0a8, 0x0bf, 0x0a1, 0x3b1, 0x3b2, 0x3b3, 0x394, 0x3b4,

0x3b5, '[', 0x3bb, 0x3bc, 0x3c0, 0x3c1, 0x3a3, 0x3c3,
0x3c4, 0x3d5, 0x3a9, 'x', 'y', '?', 0x2026, 0x25c0,

0x25fe, '?', 0x2212, 178, 176, 179, '\n', '_',
'_', 169, 'L', 0x212f, 'L', 'N', '_' /*))*/,0x2192,

'_', '_', '_', '_', '_', '_', '_', '_',
'_', '_', '_', '_', '_', '_', '_', '_',

'_', '_', '_', '_', '_', '_', '_', '_',
'_', '_', '_', '_', '_', '_', '_', '_',
]);
52 changes: 52 additions & 0 deletions src/character-encoding/ti80.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Conversion table for going from TI characters to UTF16
// Adapted from https://github.com/debrouxl/tilibs/blob/experimental2/libticonv/trunk/src/charset.cc

module.exports = require('./normalize')([
' ', 0x2588, '_', 0x2191, 'A', 0x25b6, '%', '(', // 0x00-0x7F
')', '\"', ',', '!', 176, '\'', 0x2b3, 180,

178, 'a', 'b', 'c', 'd', 'e', 'n', 'r',
0x2423, 'x', 'y', 0x2081, 0x2080, 0x3c0, 0xffff, '=',

'X', 'Y', 'T', 'R', 0x3b8, 0x2025, 0x25a1, 0x207a,
0x2d9, '{', '}', 179, '.', 0x1d07, 0x2044, ':',

'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '=', 0x2260, '>', 0x2265, '<', 0x2264,

'?', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',

'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 0x3b8, '+', '-', 0x00d7, '/',

'^', 0x207b, 0x221a, 0x3a3, 0x3c3, 0x1e8b, 0x1e8f, 0x394,
0x1d1b, 0x2191, 0x2193, 0x2e3, 247, '_', '_', '_',

'_', '_', '_', '_', '_', 0x2592, 0x2af0, 179,
'_', '_', '_', '_', '_', '_', '_', '_',

' ', 0x2588, '_', 0x2191, 'A', 0x25b6, '%', '(', // 0x80-0xFF onwards: same as 0x00-0x7F
')', '\"', ',', '!', 176, '\'', 0x2b3, 180,

178, 'a', 'b', 'c', 'd', 'e', 'n', 'r',
0x2423, 'x', 'y', 0x2081, 0x2080, 0x3c0, 0xffff, '=',

'X', 'Y', 'T', 'R', 0x3b8, 0x2025, 0x25a1, 0x207a,
0x2d9, '{', '}', 179, '.', 0x1d07, 0x2044, ':',

'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '=', 0x2260, '>', 0x2265, '<', 0x2264,

'?', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',

'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 0x3b8, '+', '-', 0x00d7, '/',

'^', 0x207b, 0x221a, 0x3a3, 0x3c3, 0x1e8b, 0x1e8f, 0x394,
0x1d1b, 0x2191, 0x2193, 0x2e3, 247, '_', '_', '_',

'_', '_', '_', '_', '_', 0x2592, 0x2af0, 179,
'_', '_', '_', '_', '_', '_', '_', '_',
]);
52 changes: 52 additions & 0 deletions src/character-encoding/ti82.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Conversion table for going from TI characters to UTF16
// Adapted from https://github.com/debrouxl/tilibs/blob/experimental2/libticonv/trunk/src/charset.cc

module.exports = require('./normalize')([
'\0', 'b', 'o', 'd', 'h', 0x25b6, 0x2191, 0x2193,
0x222b, 'x', 176, 184, 183, 0x22ba, 179, 'F',

0x221a, 180, 178, 0x2220, 176, 0x2b3, 0x22ba, 0x2264,
0x2260, 0x2265, 0x2212, 0xd875dda4,0x2192,'?', 0x2191, 0x2193,

' ', '!', '\"', '#', 0x2074, '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',

'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',

'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',

'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 0x3b8, '\\', ']', '^', '_',

'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',

'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '{', '|', '}', '~', '=',

0x2080, 0x2081, 0x2082, 0x2083, 0x2084, 0x2085, 0x2086, 0x2087,
0x2088, 0x2089, 192+1, 192+0, 192+2, 192+4, 224+1, 224+0,

224+2, 224+4, 200+1, 200+0, 200+2, 200+4, 231+1, 231+0,
231+2, 231+4, 204+1, 204+0, 204+2, 204+3, 236+1, 236+0,

236+2, 236+3, 210+1, 210+0, 210+2, 210+4, 242+1, 242+0,
242+2, 242+4, 217+1, 217+0, 217+2, 217+3, 249+1, 249+0,

249+2, 249+3, 199, 231, 209, 204, '\'', '`',
0x0a8, 0x0bf, 0x0a1, 0x3b1, 0x3b2, 0x3b3, 0x394, 0x3b4,

0x3b5, '[', 0x3bb, 0x3bc, 0x3c0, 0x3c1, 0x3a3, 0x3c3,
0x3c4, 0x3d5, 0x3a9, 'x', 'y', '?', 0x2026, 0x25c0,

0x25fe, '?', 0x2212, 178, 176, 179, '\n', 0x3b7,
0x25b6, '_', '_', '_', '_', '_', '_', '_',

'_', '_', '_', '_', '_', '_', '_', '_',
'_', '_', '_', '_', '_', '_', '_', '_',

'_', '_', '_', '_', '_', '_', '_', '_',
'_', '_', '_', '_', '_', '_', '_', '_',
]);
Loading