logo for the shell

This commit is contained in:
minjaesong
2020-09-30 18:30:25 +09:00
parent 516eced8e5
commit 084a9f7aab
8 changed files with 65 additions and 18 deletions

View File

@@ -17,13 +17,13 @@ con.getch = function() {
return sys.readKey();
};
con.move = function(y, x) {
print(String.fromCharCode(27,91)+y+";"+x+"H");
print(String.fromCharCode(27,91)+(y|0)+";"+(x|0)+"H");
};
con.addch = function(c) {
graphics.putSymbol(c);
graphics.putSymbol(c|0);
};
con.mvaddch = function(y, x, c) {
move(y, x); addch(c);
con.move(y, x); con.addch(c);
};
con.getmaxyx = function() {
return graphics.getTermDimension();
@@ -48,13 +48,13 @@ 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 % 8)+30)+"m");
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 % 8)+40)+"m");
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");
@@ -64,7 +64,7 @@ con.clear = function() {
print(String.fromCharCode(27,91)+"2J");
};
con.curs_set = function(arg) {
print(String.fromCharCode(27,91)+"?25"+((arg == 0) ? "l" : "h"));
print(String.fromCharCode(27,91)+"?25"+(((arg|0) == 0) ? "l" : "h"));
};
Object.freeze(con);
// system management function

View File

@@ -1,10 +1,32 @@
graphics.setBackground(3,3,3);
var _fsh = {};
_fsh.titlebartex = new GL.Tex(2, 14, [254, 239, 254, 254, 253, 254, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 252, 253, 253, 252, 252, 252, 252, 251, 251, 251]);
_fsh.titlebarTex = new GL.Tex(2, 14, base64.atobarr("/u/+/v3+/f39/f39/f39/f39/P39/Pz8/Pv7+w=="));
_fsh.scrdim = con.getmaxyx();
_fsh.scrwidth = _fsh.scrdim[1];
_fsh.scrheight = _fsh.scrdim[0];
_fsh.brandName = "f\xb3Sh";
_fsh.brandLogoTexSmall = new GL.Tex(24, 14, base64.atobarr("///////////////////////////////////////////z///////////////////////////////z///////////////////////z8/Pz///z////8/Pz8/Pz8/P///////Pz///////z///z8///////8/P///////Pz///////z///z8///////8/Pz8/P/8/Pz8/Pz///z////8/Pz////8/P///Pz//Pz///////z///////z8///8/P///Pz//Pz///////z////////8/P/8/P///Pz//Pz///////z////////8/P/8/P///Pz//Pz///////z///z8/Pz8///8/P///Pz///////////z///////////////////////////////z////////////////////////////////////////////////////"));
GL.drawTexPattern(_fsh.titlebartex, 0, 0, 560, 14);
_fsh.drawTitlebar = function(titletext) {
GL.drawTexPattern(_fsh.titlebarTex, 0, 0, 560, 14);
if (titletext === undefined || titletext.length == 0) {
con.move(1,1);
print(" ".repeat(_fsh.scrwidth));
GL.drawTexImageOver(_fsh.brandLogoTexSmall, 268, 0);
}
else {
con.color_pair(240, 255);// vvv this number must be even
GL.drawTexPattern(_fsh.titlebarTex, 268, 0, 24, 14);
con.move(1, 1 + (_fsh.scrwidth - titletext.length) / 2);
print(titletext);
}
con.color_pair(254, 255);
};
// screen init
con.color_pair(254, 255);
con.clear();
con.curs_set(0);
_fsh.drawTitlebar();

View File

@@ -20,7 +20,23 @@ GL.drawTexPattern = function(tex, x, y, width, height) {
}
}
};
/*
* Draws a texture verbatim - color of 255 will be written to the screen buffer
*/
GL.drawTexImage = function(tex, x, y) {
GL.drawTexPattern(tex, x, y, tex.width, tex.height);
};
/*
* Draws texture with blitting - color of 255 will pass-thru what's already on the screen buffer
*/
GL.drawTexImageOver = function(tex, x, y) {
for (var ty = 0; ty < tex.height; ty++) {
for (var tx = 0; tx < tex.width; tx++) {
var c = tex.texData[ty * tex.width + tx];
if (c != 255) {
graphics.plotPixel(x + tx, y + ty, c);
}
}
}
};
Object.freeze(GL);

BIN
fsh_logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

View File

@@ -100,7 +100,7 @@ class Memvwr(val vm: VM) : JFrame() {
}
if (x + 15 in intArrayOf(3, 7, 11))
sb.append('|')
sb.append(' ')
}
sb.append("|\n")

View File

@@ -1,12 +1,15 @@
package net.torvald.tsvm
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUlong
import java.nio.charset.Charset
/**
* Pass the instance of the class to the ScriptEngine's binding, preferably under the namespace of "vm"
*/
class VMJSR223Delegate(val vm: VM) {
private val SYSTEM_CHARSET = Charsets.ISO_8859_1
fun poke(addr: Int, value: Int) = vm.poke(addr.toLong(), value.toByte())
fun peek(addr: Int) = vm.peek(addr.toLong())!!.toInt().and(255)
fun nanoTime() = System.nanoTime()
@@ -32,11 +35,11 @@ class VMJSR223Delegate(val vm: VM) {
fun print(s: String) {
//System.out.print("[Nashorn] $s")
vm.getPrintStream().write(s.toByteArray())
vm.getPrintStream().write(s.toByteArray(SYSTEM_CHARSET))
}
fun println(s: String) {
System.out.println("[Nashorn] $s")
vm.getPrintStream().write((s + '\n').toByteArray())
vm.getPrintStream().write((s + '\n').toByteArray(SYSTEM_CHARSET))
}
fun println() = print('\n')

View File

@@ -80,12 +80,19 @@ object VMRunnerFactory {
val fr = FileReader("./assets/JS_INIT.js")
val prg = fr.readText()
fr.close()
engine.eval(toSingleLine(prg), context)
engine.eval(sanitiseJS(prg), context)
}
}
override suspend fun executeCommand(command: String) {
engine.eval("\"use strict\";" + encapsulateJS(sanitiseJS(command)), context)
try {
engine.eval("\"use strict\";" + encapsulateJS(sanitiseJS(command)), context)
}
catch (e: javax.script.ScriptException) {
System.err.println("ScriptException from the script:")
System.err.println(command.substring(0, minOf(1024, command.length)))
System.err.println(e)
}
}
override suspend fun evalGlobal(command: String) {
@@ -98,8 +105,7 @@ object VMRunnerFactory {
}
private fun toSingleLine(code: String) = code.replace(Regex("//[^\\n]*"), "").replace('\n', ' ')
private fun sanitiseJS(code: String) = toSingleLine(code).replace("\\", "\\\\")
private fun encapsulateJS(code: String) = "eval('$code')"
private fun sanitiseJS(code: String) = code//.replace("\\", "\\\\")
private fun encapsulateJS(code: String) = "(function(){$code})()"
}