From a84bdddd66b4cf8dd026aa516438441f1fda1a7e Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 2 Jan 2022 23:12:41 +0900 Subject: [PATCH] gterm wipwipwip --- assets/disk0/tvdos/bin/gfont.gz | 3 + assets/disk0/tvdos/bin/gterm.js | 78 +++++++++++++++++++ assets/disk0/tvdos/gl.js | 30 +++++-- .../net/torvald/tsvm/CompressorDelegate.kt | 4 + .../torvald/tsvm/GraphicsJSR223Delegate.kt | 6 ++ 5 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 assets/disk0/tvdos/bin/gfont.gz create mode 100644 assets/disk0/tvdos/bin/gterm.js diff --git a/assets/disk0/tvdos/bin/gfont.gz b/assets/disk0/tvdos/bin/gfont.gz new file mode 100644 index 0000000..48a1254 --- /dev/null +++ b/assets/disk0/tvdos/bin/gfont.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf24e55f80ccae9e1d76c0b618ff4f51131e8f1372ac6cab1e4c475030599f1a +size 2000 diff --git a/assets/disk0/tvdos/bin/gterm.js b/assets/disk0/tvdos/bin/gterm.js new file mode 100644 index 0000000..b651e86 --- /dev/null +++ b/assets/disk0/tvdos/bin/gterm.js @@ -0,0 +1,78 @@ +const SCRW = 560 +const SCRH = 448 +const CHARW = 7 +const CHARH = 16 +const ROWS = 28 +const COLS = 80 + +const TITLEBAR_COL = 254 +const TOOLBAR_COL = 64 +const TOOLBAR_COL2 = 69 + +let isFileThere = filesystem.open("A", "/tvdos/bin/gfont.gz", "R") +if (isFileThere != 0) { + printerrln("Main Font file not found") + return isFileThere +} + + +const fontMainTexBytes = gzip.decomp(filesystem.readAll("A")) +const fontMainTex = new GL.Texture(CHARW*16, CHARH*16, fontMainTexBytes) +const fontMain = new GL.SpriteSheet(CHARW, CHARH, fontMainTex) + +function drawInit() { + con.reset_graphics();con.curs_set(0);con.clear(); + graphics.clearPixels(255);graphics.resetPalette();graphics.setFramebufferScroll(0,0); + for(let i=0;i 0) { + let scrollY = graphics.getFramebufferScroll()[1] + let cp = unicode.utf8toCodepoints(str) + for (let i = 0; i < cp.length; i++) { + let c = cp[i] + + if (10 == c || 13 == c) { + curs = (Math.ceil(curs / COLS)|0) * COLS + } + else { + paintGlyph(c, 1+(curs % COLS), 1+(curs / COLS), ttyBack, ttyFore, scrollY) + curs += 1 + } + } + } +} + +// TODO basically port the GraphicsAdapter.kt into here + diff --git a/assets/disk0/tvdos/gl.js b/assets/disk0/tvdos/gl.js index 707f5d5..4969330 100644 --- a/assets/disk0/tvdos/gl.js +++ b/assets/disk0/tvdos/gl.js @@ -35,13 +35,13 @@ GL.SpriteSheet = function(tilew, tileh, tex) { } this.getOffX = function(x) { // THIS, or: GL.SpriteSheet.prototype.getOffX - var tx = this.tileWidth * x; + var tx = this.tileWidth * (x|0); if (tx + this.tileWidth > this.texture.width) throw "Sprite x-offset of "+tx+" is greater than sprite width "+this.texture.width; return tx; }; this.getOffY = function(y) { - var ty = this.tileHeight * y; + var ty = this.tileHeight * (y|0); if (ty + this.tileHeight > this.texture.height) throw "Sprite y-offset of "+ty+" is greater than sprite height "+this.texture.height; return ty; }; @@ -106,24 +106,42 @@ GL.drawTexImage = function(texture, x, y, fgcol, bgcol) { GL.drawTexImageOver = function(texture, x, y, fgcol) { GL.drawTexPatternOver(texture, x, y, texture.width, texture.height, fgcol); }; -GL.drawSprite = function(sheet, xi, yi, x, y) { +/* + * @param xi x-index in the spritesheet, ZERO-BASED INDEX + * @param yi y-index in the spritesheet, ZERO-BASED INDEX + * @param x x-position on the framebuffer where the sprite will be drawn + * @param y y-position on the framebuffer where the sprite will be drawn + * @param overrideFG if the value is set and the current pixel of the sheet is not 255, plots this colour instead + * @param overrideBG if the value is set and the current pixel of the sheet is 255, plots this colour instead + */ +GL.drawSprite = function(sheet, xi, yi, x, y, overrideFG, overrideBG) { var offx = sheet.getOffX(xi); var offy = sheet.getOffY(yi); 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)]; - graphics.plotPixel(x + tx, y + ty, c); + if ((c & 255) == 255) + graphics.plotPixel(x + tx, (y + ty)|0, (overrideBG !== undefined) ? overrideBG : c); + else + graphics.plotPixel(x + tx, (y + ty)|0, (overrideFG !== undefined) ? overrideFG : c); } } }; -GL.drawSpriteOver = function(sheet, xi, yi, x, y) { +/* + * @param xi x-index in the spritesheet, ZERO-BASED INDEX + * @param yi y-index in the spritesheet, ZERO-BASED INDEX + * @param x x-position on the framebuffer where the sprite will be drawn + * @param y y-position on the framebuffer where the sprite will be drawn + * @param overrideFG if the value is set and the current pixel of the sheet is not 255, plots this colour instead + */ +GL.drawSpriteOver = function(sheet, xi, yi, x, y, overrideFG) { var offx = sheet.getOffX(xi); var offy = sheet.getOffY(yi); 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) != 255) { - graphics.plotPixel(x + tx, y + ty, c); + graphics.plotPixel(x + tx, (y + ty)|0, overrideFG || c); } } } diff --git a/tsvm_core/src/net/torvald/tsvm/CompressorDelegate.kt b/tsvm_core/src/net/torvald/tsvm/CompressorDelegate.kt index 511d269..92a824e 100644 --- a/tsvm_core/src/net/torvald/tsvm/CompressorDelegate.kt +++ b/tsvm_core/src/net/torvald/tsvm/CompressorDelegate.kt @@ -22,6 +22,8 @@ object CompressorDelegate { return bout.toByteArray() }*/ + fun comp(str: String) = comp(str.toByteArray(VM.CHARSET)) + fun comp(ba: ByteArray): ByteArray { val baos = ByteArrayOutputStream() val gz = GZIPOutputStream(baos) @@ -30,6 +32,8 @@ object CompressorDelegate { return baos.toByteArray() } + fun decomp(str: String) = decomp(str.toByteArray(VM.CHARSET)) + fun decomp(ba: ByteArray): ByteArray { val bais = ByteArrayInputStream(ba) val gz = GZIPInputStream(bais) diff --git a/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt b/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt index 201187a..887cb19 100644 --- a/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt +++ b/tsvm_core/src/net/torvald/tsvm/GraphicsJSR223Delegate.kt @@ -54,6 +54,12 @@ class GraphicsJSR223Delegate(val vm: VM) { } } + fun getFramebufferScroll(): IntArray { + getFirstGPU()?.let { return intArrayOf(it.framebufferScrollX, it.framebufferScrollY) } + return intArrayOf(0, 0) + } + + fun scrollFrame(xdelta: Int, ydelta: Int) { getFirstGPU()?.let { it.framebufferScrollX = (it.framebufferScrollX + xdelta) fmod it.framebuffer.width