1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-27 14:29:39 +00:00

Merge branch 'master' of ssh://104.131.86.119:2222/home/pzp/git/8bitworkshop

This commit is contained in:
Steven Hugg 2019-07-19 10:05:55 -04:00
commit d9b40a566d
2 changed files with 16 additions and 3 deletions

View File

@ -60,7 +60,7 @@ type PixelEditorMessage = {
/////////////////
var pixel_re = /([0#]?)([bx$%]|\d'[bh])([0-9a-f]+)(?:;.*$)?/gim;
var pixel_re = /([0#]?)([x$%]|\d'h)([0-9a-f]+)|(\d'b)([01]+)/gim;
function convertToHexStatements(s:string) : string {
// convert 'hex ....' asm format
@ -78,7 +78,9 @@ export function parseHexWords(s:string) : number[] {
var m;
while (m = pixel_re.exec(s)) {
var n;
if (m[2].startsWith('%') || m[2].endsWith("b"))
if (typeof m[4] !== 'undefined')
n = parseInt(m[5],2);
else if (m[2].startsWith('%') || m[2].endsWith("b"))
n = parseInt(m[3],2);
else if (m[2].startsWith('x') || m[2].startsWith('$') || m[2].endsWith('h'))
n = parseInt(m[3],16);
@ -97,7 +99,9 @@ export function replaceHexWords(s:string, words:UintArray) : string {
while (m = pixel_re.exec(s)) {
result += s.slice(li, pixel_re.lastIndex - m[0].length);
li = pixel_re.lastIndex;
if (m[2].startsWith('%'))
if (typeof m[4] !== 'undefined')
result += m[4] + words[i++].toString(2);
else if (m[2].startsWith('%'))
result += m[1] + "%" + words[i++].toString(2);
else if (m[2].endsWith('b'))
result += m[1] + m[2] + words[i++].toString(2); // TODO

View File

@ -60,5 +60,14 @@ describe('Pixel editor', function() {
pixed.replaceHexWords(paldatastr, pixed.parseHexWords(paldatastr)));
node3.refreshLeft();
assert.deepEqual(node2.images, [[0,0,0,0,14,15,14,15,14,0,0,0,0,0,0,0,14,14,14,14,15,14,14,14,14,0,0,0,0,14,14,13,14,15,14,15,14,13,14,14,0,0,0,14,14,14,13,13,13,13,13,14,14,14,0,0,0,14,14,14,14,13,13,14,14,14,14,14,0,0,0,0,14,14,14,14,13,14,14,14,14,0,0,0,0,0,14,14,14,14,13,14,14,14,14,0,0,0,0,0,0,0,14,13,13,13,14,0,0,0,0,13,13,13,13,13,14,14,14,14,14,13,13,13,13,0,0,13,14,14,14,14,14,14,14,14,14,14,0,0,0,14,14,0,14,14,14,14,14,0,14,14,0,0,0,14,14,0,14,14,14,14,14,0,14,14,0,0,0,14,14,0,13,13,13,13,13,0,13,14,0,0,0,13,0,0,14,14,0,14,14,0,0,13,0,0,0,0,0,0,14,13,0,14,14,0,0,0,0,0,0,0,0,13,13,13,0,13,13,13,0,0,1,8]]);
var datastr2 = "const char PALETTE[32] = { \n 0x03, // screen color\n\n 0x11,0x30,0x27,0x0, // background palette 0\n 0x1c,0x20,0x2c,0x0, // background palette 1\n};";
var words2 = pixed.parseHexWords(datastr2);
assert.deepEqual(words2, [0x03,0x11,0x30,0x27,0x00,0x1c,0x20,0x2c,0x00]);
var datastr3 = " 7'o00: bits = 5'b11111; ";
var words3 = pixed.parseHexWords(datastr3);
assert.deepEqual(words3, [31]);
assert.equal(datastr3, pixed.replaceHexWords(datastr3, pixed.parseHexWords(datastr3)));
});
});