mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
gterm wipwipwip
This commit is contained in:
BIN
assets/disk0/tvdos/bin/gfont.gz
LFS
Normal file
BIN
assets/disk0/tvdos/bin/gfont.gz
LFS
Normal file
Binary file not shown.
78
assets/disk0/tvdos/bin/gterm.js
Normal file
78
assets/disk0/tvdos/bin/gterm.js
Normal file
@@ -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<SCRH;i++)graphics.setLineOffset(i,0)
|
||||
}
|
||||
|
||||
function drawUI(scrollY) {
|
||||
for (let y = 0; y < CHARH; y++) for (let x = 0; x < SCRW; x++) graphics.plotPixel(x, (y+scrollY) % SCRH, TITLEBAR_COL)
|
||||
for (let y = 416; y < 432; y++) for (let x = 0; x < SCRW; x++) graphics.plotPixel(x, (y+scrollY) % SCRH, TOOLBAR_COL)
|
||||
for (let y = 432; y < 448; y++) for (let x = 0; x < SCRW; x++) graphics.plotPixel(x, (y+scrollY) % SCRH, TOOLBAR_COL2)
|
||||
}
|
||||
|
||||
/*
|
||||
* @param codepoint unicode code point
|
||||
* @param col x-position of the character in the terminal, ONE-BASED INDEX
|
||||
* @param row y-position of the character in the terminal, ONE-BASED INDEX
|
||||
* @param bgcol background colour of the character
|
||||
* @param fgcol foreground colour of the character
|
||||
* @param scrollY `graphics.getFramebufferScroll()[1]`
|
||||
*/
|
||||
function paintGlyph(codepoint, col, row, bgcol, fgcol, scrollY) {
|
||||
let sheet = fontMain
|
||||
let xi = codepoint % 16
|
||||
let yi = codepoint / 16
|
||||
|
||||
GL.drawSprite(sheet, xi, yi, CHARW*(col - 1), (CHARH*(row|0) + scrollY) % SCRH, fgcol, bgcol)
|
||||
}
|
||||
|
||||
|
||||
drawInit()
|
||||
drawUI(graphics.getFramebufferScroll()[1])
|
||||
|
||||
let ttyFore = 252
|
||||
let ttyBack = 255
|
||||
let curs = 0
|
||||
|
||||
print = function(str) {
|
||||
if ((typeof str === 'string' || str instanceof String) && str.length > 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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user