mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
adding gzip/replaced bad base64 impl with libgdx's
This commit is contained in:
@@ -1,151 +1,3 @@
|
||||
// standard print functions
|
||||
function print(s) {
|
||||
sys.print(s);
|
||||
}
|
||||
function println(s) {
|
||||
if (s === undefined)
|
||||
sys.print("\n");
|
||||
else
|
||||
sys.println(s);
|
||||
}
|
||||
function read() {
|
||||
return sys.read();
|
||||
}
|
||||
// ncurses-like terminal control
|
||||
var con = {};
|
||||
con.getch = function() {
|
||||
return sys.readKey();
|
||||
};
|
||||
con.move = function(y, x) {
|
||||
print(String.fromCharCode(27,91)+(y|0)+";"+(x|0)+"H");
|
||||
};
|
||||
con.addch = function(c) {
|
||||
graphics.putSymbol(c|0);
|
||||
};
|
||||
con.mvaddch = function(y, x, c) {
|
||||
con.move(y, x); con.addch(c);
|
||||
};
|
||||
con.getmaxyx = function() {
|
||||
return graphics.getTermDimension();
|
||||
};
|
||||
con.getyx = function() {
|
||||
return graphics.getCursorYX();
|
||||
};
|
||||
con.hitterminate = function() { // ^C
|
||||
sys.poke(-40, 1);
|
||||
return (sys.peek(-41) == 31 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
|
||||
};
|
||||
con.hiteof = function() { // ^D
|
||||
sys.poke(-40, 1);
|
||||
return (sys.peek(-41) == 32 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
|
||||
};
|
||||
con.resetkeybuf = function() {
|
||||
sys.poke(-40, 0);
|
||||
sys.poke(-41, 0); sys.poke(-42, 0); sys.poke(-43, 0); sys.poke(-44, 0);
|
||||
sys.poke(-45, 0); sys.poke(-46, 0); sys.poke(-47, 0); sys.poke(-48, 0);
|
||||
};
|
||||
con.color_fore = function(n) { // 0..7; -1 for transparent
|
||||
if (n < 0)
|
||||
print(String.fromCharCode(27,91)+"38;5;255m");
|
||||
else
|
||||
print(String.fromCharCode(27,91)+(((n|0) % 8)+30)+"m");
|
||||
};
|
||||
con.color_back = function(n) { // 0..7; -1 for transparent
|
||||
if (n < 0)
|
||||
print(String.fromCharCode(27,91)+"48;5;255m");
|
||||
else
|
||||
print(String.fromCharCode(27,91)+(((n|0) % 8)+40)+"m");
|
||||
};
|
||||
con.color_pair = function(fore, back) { // 0..255
|
||||
print(String.fromCharCode(27,91)+"38;5;"+fore+"m");
|
||||
print(String.fromCharCode(27,91)+"48;5;"+back+"m");
|
||||
};
|
||||
con.clear = function() {
|
||||
print(String.fromCharCode(27,91)+"2J");
|
||||
};
|
||||
con.curs_set = function(arg) {
|
||||
print(String.fromCharCode(27,91)+"?25"+(((arg|0) == 0) ? "l" : "h"));
|
||||
};
|
||||
Object.freeze(con);
|
||||
// system management function
|
||||
var system = {};
|
||||
system.maxmem = function() {
|
||||
return sys.peek(-65) | (sys.peek(-66) << 8) | (sys.peek(-67) << 16) | (sys.peek(-68) << 24);
|
||||
};
|
||||
system.halt = function() {
|
||||
exit();
|
||||
};
|
||||
Object.freeze(system);
|
||||
// some utilities functions
|
||||
var base64 = {};
|
||||
base64._lookup = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
base64._revLookup = {"":0,"=":0,"A":0,"B":1,"C":2,"D":3,"E":4,"F":5,"G":6,"H":7,"I":8,"J":9,"K":10,"L":11,"M":12,"N":13,"O":14,"P":15,"Q":16,"R":17,"S":18,"T":19,"U":20,"V":21,"W":22,"X":23,"Y":24,"Z":25,"a":26,"b":27,"c":28,"d":29,"e":30,"f":31,"g":32,"h":33,"i":34,"j":35,"k":36,"l":37,"m":38,"n":39,"o":40,"p":41,"q":42,"r":43,"s":44,"t":45,"u":46,"v":47,"w":48,"x":49,"y":50,"z":51,"0":52,"1":53,"2":54,"3":55,"4":56,"5":57,"6":58,"7":59,"8":60,"9":61,"+":62,"/":63};
|
||||
base64.atob = function(base64str) {
|
||||
var modulo = base64str.length % 4;
|
||||
var ret = [];
|
||||
for (var i = 0; i < base64str.length + modulo; i += 4) {
|
||||
var bits = (base64._revLookup[base64str[i]] << 18) | (base64._revLookup[base64str[i+1]] << 12) | (base64._revLookup[base64str[i+2]] << 6) | (base64._revLookup[base64str[i+3]]);
|
||||
var pads = (base64str[i+2] == "=") ? 2 : ((base64str[i+3] == "=") ? 1 : 0);
|
||||
|
||||
ret.push((bits >> 16) & 255);
|
||||
if (pads <= 1) ret.push((bits >> 8) & 255);
|
||||
if (pads == 0) ret.push(bits & 255);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
base64.atobstr = function(base64str) {
|
||||
var modulo = base64str.length % 4;
|
||||
var ret = "";
|
||||
for (var i = 0; i < base64str.length + modulo; i += 4) {
|
||||
var bits = (base64._revLookup[base64str[i]] << 18) | (base64._revLookup[base64str[i+1]] << 12) | (base64._revLookup[base64str[i+2]] << 6) | (base64._revLookup[base64str[i+3]]);
|
||||
var pads = (base64str[i+2] == "=") ? 2 : ((base64str[i+3] == "=") ? 1 : 0);
|
||||
|
||||
ret += String.fromCharCode((bits >> 16) & 255);
|
||||
if (pads <= 1) ret += String.fromCharCode((bits >> 8) & 255);
|
||||
if (pads == 0) ret += String.fromCharCode(bits & 255);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
base64.btoa = function(inputString) {
|
||||
var modulo = inputString.length % 3;
|
||||
var outStr = "";
|
||||
if (Array.isArray(inputString)) {
|
||||
for (var i = 0; i < inputString.length + ((modulo == 0) ? 0 : 3 - modulo); i += 3) {
|
||||
var bytes = (inputString[i] << 16) | (inputString[i+1] << 8) | inputString[i+2];
|
||||
// for arrays, out-of-bounds have value of undefined;
|
||||
// for strings, out-of-bounds have value of NaN -- both are casted into int 0 on bitwise operations.
|
||||
|
||||
outStr += base64._lookup[(bytes >> 18) & 63];
|
||||
outStr += base64._lookup[(bytes >> 12) & 63];
|
||||
if (i < Math.floor(inputString.length / 3) * 3 | (modulo == 2 || modulo == 0)) outStr += base64._lookup[(bytes >> 6) & 63];
|
||||
if (i < Math.floor(inputString.length / 3) * 3 | modulo == 0) outStr += base64._lookup[bytes & 63];
|
||||
}
|
||||
// pad the output
|
||||
if (modulo == 1) outStr += "==";
|
||||
else if (modulo == 2) outStr += "=";
|
||||
}
|
||||
else if (typeof inputString == "string") {
|
||||
for (var i = 0; i < inputString.length + ((modulo == 0) ? 0 : 3 - modulo); i += 3) {
|
||||
var bytes = (inputString.charCodeAt(i) << 16) | (inputString.charCodeAt(i+1) << 8) | inputString.charCodeAt(i+2);
|
||||
// for arrays, out-of-bounds have value of undefined;
|
||||
// for strings, out-of-bounds have value of NaN -- both are casted into int 0 on bitwise operations.
|
||||
|
||||
outStr += base64._lookup[(bytes >> 18) & 63];
|
||||
outStr += base64._lookup[(bytes >> 12) & 63];
|
||||
if (i < Math.floor(inputString.length / 3) * 3 | (modulo == 2 || modulo == 0)) outStr += base64._lookup[(bytes >> 6) & 63];
|
||||
if (i < Math.floor(inputString.length / 3) * 3 | modulo == 0) outStr += base64._lookup[bytes & 63];
|
||||
}
|
||||
// pad the output
|
||||
if (modulo == 1) outStr += "==";
|
||||
else if (modulo == 2) outStr += "=";
|
||||
}
|
||||
else {
|
||||
throw "Unknown byte representation (with typeof "+typeof bytes+")";
|
||||
}
|
||||
|
||||
return outStr;
|
||||
};
|
||||
Object.freeze(base64);
|
||||
// Polyfilling some functions from ECMAScript6+
|
||||
if (!String.prototype.repeat) {
|
||||
String.prototype.repeat = function(count) {
|
||||
@@ -186,6 +38,14 @@ if (!String.prototype.repeat) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
if (!String.prototype.startsWith) {
|
||||
Object.defineProperty(String.prototype, 'startsWith', {
|
||||
value: function(search, rawPos) {
|
||||
var pos = rawPos > 0 ? rawPos|0 : 0;
|
||||
return this.substring(pos, pos + search.length) === search;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!Array.prototype.filter){
|
||||
Array.prototype.filter = function(func, thisArg) {
|
||||
'use strict';
|
||||
@@ -408,3 +268,86 @@ if ('function' !== typeof Array.prototype.reduceRight) {
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
load = undefined
|
||||
loadWithNewGlobal = undefined
|
||||
// standard print functions
|
||||
function print(s) {
|
||||
sys.print(s);
|
||||
}
|
||||
function println(s) {
|
||||
if (s === undefined)
|
||||
sys.print("\n");
|
||||
else
|
||||
sys.println(s);
|
||||
}
|
||||
function read() {
|
||||
return sys.read();
|
||||
}
|
||||
// ncurses-like terminal control
|
||||
var con = {};
|
||||
con.getch = function() {
|
||||
return sys.readKey();
|
||||
};
|
||||
con.move = function(y, x) {
|
||||
print(String.fromCharCode(27,91)+(y|0)+";"+(x|0)+"H");
|
||||
};
|
||||
con.addch = function(c) {
|
||||
graphics.putSymbol(c|0);
|
||||
};
|
||||
con.mvaddch = function(y, x, c) {
|
||||
con.move(y, x); con.addch(c);
|
||||
};
|
||||
con.getmaxyx = function() {
|
||||
return graphics.getTermDimension();
|
||||
};
|
||||
con.getyx = function() {
|
||||
return graphics.getCursorYX();
|
||||
};
|
||||
con.hitterminate = function() { // ^C
|
||||
sys.poke(-40, 1);
|
||||
return (sys.peek(-41) == 31 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
|
||||
};
|
||||
con.hiteof = function() { // ^D
|
||||
sys.poke(-40, 1);
|
||||
return (sys.peek(-41) == 32 && (sys.peek(-42) == 129 || sys.peek(-42) == 130));
|
||||
};
|
||||
con.resetkeybuf = function() {
|
||||
sys.poke(-40, 0);
|
||||
sys.poke(-41, 0); sys.poke(-42, 0); sys.poke(-43, 0); sys.poke(-44, 0);
|
||||
sys.poke(-45, 0); sys.poke(-46, 0); sys.poke(-47, 0); sys.poke(-48, 0);
|
||||
};
|
||||
con.color_fore = function(n) { // 0..7; -1 for transparent
|
||||
if (n < 0)
|
||||
print(String.fromCharCode(27,91)+"38;5;255m");
|
||||
else
|
||||
print(String.fromCharCode(27,91)+(((n|0) % 8)+30)+"m");
|
||||
};
|
||||
con.color_back = function(n) { // 0..7; -1 for transparent
|
||||
if (n < 0)
|
||||
print(String.fromCharCode(27,91)+"48;5;255m");
|
||||
else
|
||||
print(String.fromCharCode(27,91)+(((n|0) % 8)+40)+"m");
|
||||
};
|
||||
con.color_pair = function(fore, back) { // 0..255
|
||||
print(String.fromCharCode(27,91)+"38;5;"+fore+"m");
|
||||
print(String.fromCharCode(27,91)+"48;5;"+back+"m");
|
||||
};
|
||||
con.clear = function() {
|
||||
print(String.fromCharCode(27,91)+"2J");
|
||||
};
|
||||
con.curs_set = function(arg) {
|
||||
print(String.fromCharCode(27,91)+"?25"+(((arg|0) == 0) ? "l" : "h"));
|
||||
};
|
||||
Object.freeze(con);
|
||||
// system management function
|
||||
var system = {};
|
||||
system.maxmem = function() {
|
||||
return sys.peek(-65) | (sys.peek(-66) << 8) | (sys.peek(-67) << 16) | (sys.peek(-68) << 24);
|
||||
};
|
||||
system.halt = function() {
|
||||
exit();
|
||||
};
|
||||
Object.freeze(system);
|
||||
// some utilities functions
|
||||
|
||||
45
assets/tvdos/filesystem.md
Normal file
45
assets/tvdos/filesystem.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Syntax
|
||||
## Reserved directories
|
||||
* `$DEVICE<device_number>`
|
||||
|
||||
## Reserved files
|
||||
* `$DEVICE<device_number>/$BOOT` — associates to bootloader, exact filename depends on the filesystem the device uses
|
||||
|
||||
# Drivers
|
||||
Filesystem driver is just an executable that can do file I/O to one specific filesystem it supports.
|
||||
|
||||
Filesystem drivers, just as regular TVDOS drivers, resides in `<root>/TVDOS/DRIVERS/`
|
||||
|
||||
# Commands
|
||||
|
||||
## cp
|
||||
`[cp|copy] <source> <destination>`
|
||||
|
||||
Executes following command:
|
||||
```
|
||||
<filesystem>.fs cp <source> <dest>
|
||||
```
|
||||
|
||||
## mv
|
||||
`[mv|move] <from> <to>`
|
||||
|
||||
Executes following command:
|
||||
```
|
||||
<filesystem>.fs mv <from> <to>
|
||||
```
|
||||
|
||||
## touch
|
||||
`touch <path>`
|
||||
|
||||
Executes following command:
|
||||
```
|
||||
<filesystem>.fs touch <path>
|
||||
```
|
||||
|
||||
## format
|
||||
`format -f [tsvm|flat|tree] [ -b <path_to_bootloader> ] <device_number>`
|
||||
|
||||
Executes following command:
|
||||
```
|
||||
<filesystem>.fs format <device_number> [ <path_to_bootloader> ]
|
||||
```
|
||||
@@ -15,11 +15,9 @@ _fsh.scrdim = con.getmaxyx();
|
||||
_fsh.scrwidth = _fsh.scrdim[1];
|
||||
_fsh.scrheight = _fsh.scrdim[0];
|
||||
_fsh.brandName = "f\xb3Sh";
|
||||
_fsh.brandLogoTexSmall = new GL.Texture(24, 14, base64.atob("//////////////////////////////////////////j//////////////"+
|
||||
"/////////////////j////////////////////////z8/P///j///+hoaGhof+hof////////Pz//////j//6Gh//////+hof////////Pz//////j//6"+
|
||||
"Gh//////+hoaGhof//8/Pz8/P///j///+hoaH///+hof//oaH///Pz//////j//////6Gh//+hof//oaH///Pz//////j///////+hof+hof//oaH///P"+
|
||||
"z//////j///////+hof+hof//oaH///Pz//////j//6GhoaGh//+hof//oaH///////////j///////////////////////////////j/////////////"+
|
||||
"////////////////////////////////////////"));
|
||||
_fsh.brandLogoTexSmall = new GL.Texture(24, 14, gzip.decomp(base64.atob(
|
||||
"H4sIAAAAAAAAAPv/Hy/4Qbz458+fIeILQQBIwoSh6qECuMVBukCmIJkDVQ+RQNgLE0MX/w+1lyhxqIUwTLJ/sQMAcIXsbVABAAA="
|
||||
)));
|
||||
_fsh.scrlayout = ["com.fsh.clock","com.fsh.calendar","com.fsh.apps_n_files"];
|
||||
|
||||
_fsh.drawTitlebar = function(titletext) {
|
||||
@@ -61,56 +59,14 @@ _fsh.registerNewWidget = function(widget) {
|
||||
}
|
||||
|
||||
var clockWidget = new _fsh.Widget("com.fsh.clock", _fsh.scrwidth - 8, 7);
|
||||
clockWidget.numberSheet = new GL.SpriteSheet(19, 22, new GL.Texture(190, 22, base64.atob(
|
||||
"///////v7+/v7+/v7+//////////////////////7+//////////7+/v7+/v7+/v7+/v7+/v/////+/v7+/v7+/v7+/v7+/v7///////////////7+/v/"+
|
||||
"///////////7+/v7+/v7+/v7+/v7+/v7+//////////7+/v7+/v7+/v7+/////v7+/v7+/v7+/v7+/v7+/v7////////+/v7+/v7+/v7////////////+"+
|
||||
"/v7+/v7+/v7+/v/////////+/v7+/v7+/v7+/v7+/////////////////v7+/v////////7+/v7+/v7+/v7+/v7+/v7+/v/+/v7+/v7+/v7+/v7+/v7+/"+
|
||||
"v7///////////7+/v7///////////7+/v7+/v7+/v7+/v7+/v7+/v7//////v7+/v7+/v7+/v7+/v7//v7+/v7+/v7+/v7+/v7+/v7+/v////7+/v7+/v"+
|
||||
"7+/v7+/v7///////7+/v7+/v7+/v7+/v7+/v/////+/v7+/v///////v7+/v7////////////+/v7+/v7//////////////////////////v7+/v7+///"+
|
||||
"///////////////7+/v7+/v/////////+/v7////////////+/v7//////////////////////////v7+/v7/////////////////////////////////"+
|
||||
"/v7+/v////7+/v7+/v////7+/v7+/v////7+/v7+//////////7+/v7+///+/v7+/////////////v7+/v////////7+/v7+/v7+/////////////////"+
|
||||
"////////////v7+/v////////////////////7+/v7////////+/v7+/////////////v7+/////////////////////////v7+/v////////////////"+
|
||||
"////////////////////7+/v/////+/v7+//////////7+/v7///7+/v7///////////////7+/v7//v7+///////////////+/v7////////+/v7+/v7"+
|
||||
"+/v/////////////////////////////+/v7//////////////////////v7+/////////v7+//////////////7+/v///////////////////////v7+"+
|
||||
"/v////////////////////////////////////7+/v7//////v7+/////////////v7+///+/v7//////////////////v7+/v7+/v///////////////"+
|
||||
"v7+/v/////////////+/v7//////////////////////////////v7+//////////////////////7+/v///////v7+/v/////////////+/v7///////"+
|
||||
"////////////////7+/v/////////////////////////////////////+/v7///////7+/v////////////7+/v///v7+//////////////////7+/v7"+
|
||||
"+/v/////////////////+/v7//////////////v7+//////////////////////////////7+/v/////////////////////+/v7///////7+/v//////"+
|
||||
"/////////v7+//////////////////////7+/v7////////////////////////////////////+/v7+///////+/v7////////////+/v7///7+/v///"+
|
||||
"//////////////+/v7+/v7//////////////////v7+//////////////7+/v/////////////////////////////+/v7//////////////////////v"+
|
||||
"7+//////7+/v7///////////////7+/v/////////////////////+/v7//////////////////////////////////////v7+/////////v7+///////"+
|
||||
"//////v7+///+/v7//////////////////v7+/v7+//////////////////7+/v/////////////+/v7////////////////////////////+/v7+////"+
|
||||
"/////////////////v7+/v/////+/v7///////7+///////+/v7+/v7+/v7+/v7+/v7+/////v7+//7+/v7+/v7+/v7+/////////////////////v7+/"+
|
||||
"v////////7+/v7//////////v7+/v///v7+//////////////////7+/v7+/v/////////////////+/v7//////////////v7+//////////////////"+
|
||||
"////////7+/v7+/v/////////////////+/v7+/v/////+/v7+///////+/v7///////7+/v7+/v7+/v7+/v7+/v7+//7+/v7+/v7+/v7+/v7+/v7+///"+
|
||||
"///////////////7+/v/////////+/v7+/v7////+/v7+/v7///7+/v/////////////////+/v7+/v7//////////////////v7+//////////////7+"+
|
||||
"/v////////////7+/v7+/v7+/v7+/v7+/v///v7+/v7+/v7+/v7+/v7+/v///////v7+/////////v7+///////////////////////+/v7+/v7+/v7+/"+
|
||||
"v7//////////v7+/v7///////////////7+/v7////////+/v7+/v7+/v7+/v7+/v7+/v/+/v7+///////////////+/v7+/v7+//////////////////"+
|
||||
"7+/v/////////////+/v7//////////v7+/v7+/v7+/v7+/v7+//////7+/v7+/v7+/v7+/v7+/v7//////v7+/v////////7+/v/////////////////"+
|
||||
"////////+/v7+/v7+/v///////////////v7+/v/////////////+/v7//////////v7+/v7+/v7+/v7+/v7+/v7///7+/v7+//////////7+/v7+/v7+"+
|
||||
"/v/////////////////+/v7//////////////v7+/////////v7+/v7+///////////////////////////////////+/v7+/v////7+/v/////////+/"+
|
||||
"v7///////////////////////////7+/v7+/v/////////////////+/v7////////////+/v7+/////////v7+/v7+//////////7+/v7+/v///v7+/v"+
|
||||
"7+/v7+/v7+/v7+/v7+/v7//////////////////v7+//////////////7+/v////////7+/v7////////////////////////////////////////+/v7"+
|
||||
"+//7+/v7//////////v7+///////////////////////////+/v7+/v7//////////////////v7+/////////////v7+//////////7+/v7/////////"+
|
||||
"//////7+/v7//////v7+/v7+/v7+/v7//v7+/v7+//////////////////7+/v/////////////+/v7////////+/v7//////////////////////////"+
|
||||
"/////////////////7+/v/+/v7///////////7+/v///////////////////////////v7+/v7+//////////////////7+/v///////////v7+/v////"+
|
||||
"/////+/v7//////////////////v7+//////////////////////7+/v7+/v/////////////////+/v7//////////////v7+/////////v7+///////"+
|
||||
"////////////////////////////////////+/v7+/v7+///////////+/v7///////////////////////////7+/v7+/v/////////////////+/v7/"+
|
||||
"//////////7+/v///////////v7+//////////////////7+/v////////////////////7+/v7+/v7+///////////////+/v7+//////////////7+/"+
|
||||
"v////////7+/v///////////////////////////////////////////v7+/v7+/v7+/v7+/v7+/v7+/v7+/v/////////////////////+/v7+/v7///"+
|
||||
"///////////////v7+//////////7+/v7///////////7+/v/////////////////+/v7////////////////////+/v7//v7+/v///////////////v7"+
|
||||
"+///////////////+/v7////////+/v7///////////////////////////////////////////7+/v/+/v7+/v7+/v7+/v7+/v7+/v//////////////"+
|
||||
"/////////v7+/v7+//////////////////7+/v/////////+/v7////////////+/v7//////////////////v7+///////////////////+/v7+///+/"+
|
||||
"v7+/////////////v7+/v///////////////v7+/////////v7+//////////////////////////////////////////7+/v7////////////////+/v"+
|
||||
"7//////////////////////////v7+/v7+/v7///////////////7+/v7////////+/v7+/////////////v7+/v///////////////v7+/v/////////"+
|
||||
"////////+/v7+//////7+/v7+///////+/v7+/v////////////////7+/v////////7+/v///////////////////////////////////////v7+/v7+"+
|
||||
"/////////////////v7+///////////////////////+/v7+/v7//v7+/v7//////////v7+/v7//////////v7+//////////////7+/v7+/v///////"+
|
||||
"//+/v7+/v7///////////////7+/v7+/////////v7+/v7+/v7+/v7+/v/////////////////+/v7////////+/v7+/v7+/v7+/v7+/v7+/v7+/v7+/v"+
|
||||
"7+/v7+/v7+/v7+/v7+//////////////////7+/v/////+/v7+/v7+/v7+/v7+/v7+/v7////+/v7+/v7+/v7+/v7+/v7//////////v7+/v/////////"+
|
||||
"//////v7+/v7+/v7+/v7+/v7+/v7///7+/v7+/v7+/v7+/v7+/////////////v7+/v7+/v7+/////////////////////v7+//////////7+/v7+/v7+"+
|
||||
"/v7+/v7+/v7+///+/v7+/v7+/v7+/v7+/v7//////////////////////v7///////7+/v7+/v7+/v7+/v7+/v/////////+/v7+/v7+/v7+/v///////"+
|
||||
"/////7+/v///////////////////v7+/v7+/v7+/v7+/v///////v7+/v7+/v7+/v7////////w=="
|
||||
)));
|
||||
clockWidget.numberSheet = new GL.SpriteSheet(19, 22, new GL.Texture(190, 22, gzip.decomp(base64.atob(
|
||||
"H4sIAAAAAAAAAMWVW3LEMAgE739aHcFJJV5ZMD2I9ToVfcl4GBr80HF8r/FaR1ozMuIyoUu87lEXI0al5qVR5AebSwchSaNE6Nyo1Nw5HXF3SfPT4Bshl"+
|
||||
"EycA8RD96mLlHbuhTgOrfLnUDZspafbSQWk56WEGvQEtWaWwgb8iz7a8AOXhsraO/q9Qw2/GnXovfVN+q2wM/p/oddn2cjF239GX3y11+SWCtc6FTHC1v"+
|
||||
"TVPkDPWWn0w+DDz93UX9v9mF5KIsQ6OdN2KJoB4ui1bXXr0AMp0YfiQo//4XhpK8555dsNehAqVS5uhb5iHn3Kko769J59KmLBe/TSR7hcsd+hr+HnrwR"+
|
||||
"9uvRF9+D3MP14gN7lqx+8OuNT+uqt3NFX3SN9fTbeeHNq+C29pRWzX5+Rcm7SZyjOKJ/2hkSPqul4xN279DrSYvCrNu2NI7ZMp1ouBxK3KBVVnEeAUWbK"+
|
||||
"MUDn5DPsPxmUqHZQjGpy2hergM3EVBAAAA=="
|
||||
))));
|
||||
|
||||
clockWidget.clockColon = new GL.Texture(4, 3, base64.atob("7+/v7+/v7+/v7+/v"));
|
||||
clockWidget.monthNames = ["Spring", "Summer", "Autumn", "Winter"];
|
||||
clockWidget.dayNames = ["Mondag ", "Tysdag ", "Midtveke", "Torsdag ", "Fredag ", "Laurdag ", "Sundag ", "Verddag "];
|
||||
@@ -166,4 +122,7 @@ while (true) {
|
||||
|
||||
con.move(3,1);
|
||||
con.color_pair(201,255);
|
||||
print("cya!");
|
||||
print("cya!");
|
||||
|
||||
let konsht = 3412341241;
|
||||
print(konsht);
|
||||
@@ -6,12 +6,13 @@ Has no affiliation with OpenGL by Khronos Group
|
||||
|
||||
var GL = {};
|
||||
|
||||
// bytes should be able to handle both JSArray and Java ByteArray (toString = "[B")?
|
||||
GL.Texture = function(w, h, bytes) {
|
||||
this.width = w;
|
||||
this.height = h;
|
||||
this.texData = bytes;
|
||||
|
||||
if (!Array.isArray(bytes)) {
|
||||
if (!Array.isArray(bytes) && !bytes.toString().startsWith("[B")) {
|
||||
throw "Texture data is not an instance of array";
|
||||
}
|
||||
};
|
||||
@@ -52,7 +53,7 @@ GL.drawTexPatternOver = function(texture, x, y, width, height) {
|
||||
var tx = xx % texture.width;
|
||||
var ty = yy % texture.height;
|
||||
var c = texture.texData[ty * texture.width + tx];
|
||||
if (c != 255) {
|
||||
if (c != -1) {
|
||||
graphics.plotPixel(x + xx, y + yy, c);
|
||||
}
|
||||
}
|
||||
@@ -71,7 +72,7 @@ GL.drawTexImageOver = function(texture, x, y) {
|
||||
for (var ty = 0; ty < texture.height; ty++) {
|
||||
for (var tx = 0; tx < texture.width; tx++) {
|
||||
var c = texture.texData[ty * texture.width + tx];
|
||||
if (c != 255) {
|
||||
if (c != -1) {
|
||||
graphics.plotPixel(x + tx, y + ty, c);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +94,7 @@ GL.drawSpriteOver = function(sheet, xi, yi, x, y) {
|
||||
for (var ty = 0; ty < sheet.tileHeight; ty++) {
|
||||
for (var tx = 0; tx < sheet.tileWidth; tx++) {
|
||||
var c = sheet.texture.texData[(ty + offy) * sheet.texture.width + (tx + offx)];
|
||||
if (c != 255) {
|
||||
if (c != -1) {
|
||||
graphics.plotPixel(x + tx, y + ty, c);
|
||||
}
|
||||
}
|
||||
|
||||
22
assets/zippytest.js
Normal file
22
assets/zippytest.js
Normal file
@@ -0,0 +1,22 @@
|
||||
serial.println(typeof atob);
|
||||
|
||||
const inputstr =
|
||||
"//////////////////////////////////////////j//////////////"+
|
||||
"/////////////////j////////////////////////z8/P///j///+hoaGhof+hof////////Pz//////j//6Gh//////+hof////////Pz//////j//6"+
|
||||
"Gh//////+hoaGhof//8/Pz8/P///j///+hoaH///+hof//oaH///Pz//////j//////6Gh//+hof//oaH///Pz//////j///////+hof+hof//oaH///P"+
|
||||
"z//////j///////+hof+hof//oaH///Pz//////j//6GhoaGh//+hof//oaH///////////j///////////////////////////////j/////////////"+
|
||||
"////////////////////////////////////////"
|
||||
serial.println(inputstr);
|
||||
//FIXME bad Base64.atob impl
|
||||
serial.println(base64.btoa(base64.atob(inputstr)))
|
||||
|
||||
var zipbin = gzip.comp(base64.atob(inputstr));
|
||||
var zipped = base64.btoa(zipbin);
|
||||
serial.println(zipped);
|
||||
|
||||
//var unzipped = base64.btoa(gzip.decomp(zipbin));
|
||||
var unzipped = base64.btoa(gzip.decomp(base64.atob(zipped)));
|
||||
|
||||
serial.println(unzipped);
|
||||
|
||||
serial.println("It is now safe to turn off");
|
||||
17
src/net/torvald/tsvm/Base64Delegate.kt
Normal file
17
src/net/torvald/tsvm/Base64Delegate.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package net.torvald.tsvm
|
||||
|
||||
import com.badlogic.gdx.utils.Base64Coder
|
||||
|
||||
class Base64Delegate {
|
||||
|
||||
fun atob(inputstr: String): ByteArray {
|
||||
return Base64Coder.decode(inputstr)
|
||||
}
|
||||
|
||||
fun btoa(inputbytes: ByteArray): String {
|
||||
val sb = StringBuilder()
|
||||
sb.append(Base64Coder.encode(inputbytes))
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
}
|
||||
41
src/net/torvald/tsvm/CompressorDelegate.kt
Normal file
41
src/net/torvald/tsvm/CompressorDelegate.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package net.torvald.tsvm
|
||||
|
||||
import com.badlogic.gdx.utils.compression.Lzma
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.zip.GZIPInputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
class CompressorDelegate {
|
||||
|
||||
/*fun comp(ba: ByteArray): ByteArray {
|
||||
val bin = ByteArrayInputStream(ba)
|
||||
val bout = ByteArrayOutputStream(256)
|
||||
Lzma.compress(bin, bout)
|
||||
return bout.toByteArray()
|
||||
}
|
||||
|
||||
fun decomp(ba: ByteArray): ByteArray {
|
||||
val bin = ByteArrayInputStream(ba)
|
||||
val bout = ByteArrayOutputStream(256)
|
||||
Lzma.decompress(bin, bout)
|
||||
return bout.toByteArray()
|
||||
}*/
|
||||
|
||||
fun comp(ba: ByteArray): ByteArray {
|
||||
val baos = ByteArrayOutputStream()
|
||||
val gz = GZIPOutputStream(baos)
|
||||
gz.write(ba); gz.flush(); gz.finish()
|
||||
baos.flush(); baos.close()
|
||||
return baos.toByteArray()
|
||||
}
|
||||
|
||||
fun decomp(ba: ByteArray): ByteArray {
|
||||
val bais = ByteArrayInputStream(ba)
|
||||
val gz = GZIPInputStream(bais)
|
||||
val ret = gz.readBytes()
|
||||
gz.close(); bais.close()
|
||||
return ret
|
||||
}
|
||||
|
||||
}
|
||||
@@ -65,6 +65,7 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
|
||||
|
||||
|
||||
//val fr = FileReader("./assets/tvdos/command.js")
|
||||
//val fr = FileReader("./assets/zippytest.js")
|
||||
val fr = FileReader("./assets/tvdos/fsh.js")
|
||||
//val fr = FileReader("./assets/tbas/basic.js")
|
||||
//val fr = FileReader("./assets/jscon.js")
|
||||
|
||||
@@ -76,9 +76,9 @@ object VMRunnerFactory {
|
||||
init {
|
||||
bind.put("sys", VMJSR223Delegate(vm)) // TODO use delegator class to access peripheral (do not expose VM itself)
|
||||
bind.put("graphics", GraphicsJSR223Delegate(vm))
|
||||
//bind.put("poke", { a: Long, b: Byte -> vm.poke(a, b) }) // kts: lambda does not work...
|
||||
//bind.put("nanotime", { System.nanoTime() })
|
||||
bind.put("serial", VMSerialDebugger(vm))
|
||||
bind.put("gzip", CompressorDelegate())
|
||||
bind.put("base64", Base64Delegate())
|
||||
|
||||
if (extension == "js") {
|
||||
val fr = FileReader("./assets/JS_INIT.js")
|
||||
|
||||
Reference in New Issue
Block a user