mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-14 00:14:05 +09:00
script modules and 'require()'
This commit is contained in:
@@ -21,7 +21,7 @@ _fsh.brandLogoTexSmall = new GL.Texture(24, 14, gzip.decomp(base64.atob(
|
|||||||
_fsh.scrlayout = ["com.fsh.clock","com.fsh.calendar","com.fsh.todo_list", "com.fsh.quick_access"];
|
_fsh.scrlayout = ["com.fsh.clock","com.fsh.calendar","com.fsh.todo_list", "com.fsh.quick_access"];
|
||||||
|
|
||||||
_fsh.drawWallpaper = function() {
|
_fsh.drawWallpaper = function() {
|
||||||
let wp = files.open("A:/tvdos/wall.bytes")
|
let wp = files.open("A:/home/wall.bytes")
|
||||||
// filesystem.open("A", "/tvdos/wall.bytes", "R")
|
// filesystem.open("A", "/tvdos/wall.bytes", "R")
|
||||||
let b = sys.malloc(250880)
|
let b = sys.malloc(250880)
|
||||||
// dma.comToRam(0, 0, b, 250880)
|
// dma.comToRam(0, 0, b, 250880)
|
||||||
|
|||||||
@@ -1062,8 +1062,17 @@ Object.freeze(unicode);
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// install other stuffs
|
// install other stuffs
|
||||||
let glfile = files.open("A:/tvdos/gl.js")
|
var require = (absdir) => {
|
||||||
const GL = eval(glfile.sread())
|
let moduleFile = files.open(absdir)
|
||||||
|
if (!moduleFile.exists) throw Error("No such file: " + absdir)
|
||||||
|
let moduleScript = moduleFile.sread()
|
||||||
|
return eval(`let exports = {}; ${moduleScript}; Object.freeze(exports)`)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var GL = require("A:/tvdos/include/gl.js")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let checkTerm = `if (sys.peek(-49)&1) throw new InterruptedException();`
|
let checkTerm = `if (sys.peek(-49)&1) throw new InterruptedException();`
|
||||||
let injectIntChk = (s, n) => {
|
let injectIntChk = (s, n) => {
|
||||||
@@ -1091,6 +1100,8 @@ var execApp = (cmdsrc, args, appname) => {
|
|||||||
execAppPrg(args);
|
execAppPrg(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Boot script
|
// Boot script
|
||||||
|
|||||||
@@ -594,6 +594,19 @@ shell.stdio = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object.freeze(shell.stdio)
|
Object.freeze(shell.stdio)
|
||||||
|
// install an improved version of require that takes care of relative path
|
||||||
|
shell.require = require
|
||||||
|
require = function(path) {
|
||||||
|
// absolute path?
|
||||||
|
if (path[1] == ":") return shell.require(path)
|
||||||
|
else {
|
||||||
|
// if the path starts with ".", look for the current directory
|
||||||
|
// if the path starts with [A-Za-z0-9], look for the DOSDIR/includes
|
||||||
|
if (path[0] == '.') return shell.require(shell.resolvePathInput(path).full + ".js")
|
||||||
|
else return shell.require(`A:${_TVDOS.variables.DOSDIR}/include/${path}.js`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
shell.execute = function(line) {
|
shell.execute = function(line) {
|
||||||
if (0 == line.size) return
|
if (0 == line.size) return
|
||||||
let parsedTokens = shell.parse(line) // echo, "hai", |, less
|
let parsedTokens = shell.parse(line) // echo, "hai", |, less
|
||||||
|
|||||||
@@ -188,6 +188,15 @@ while (readCount < FILE_LENGTH) {
|
|||||||
if (65535 == packetType) {
|
if (65535 == packetType) {
|
||||||
frameUnit -= 1
|
frameUnit -= 1
|
||||||
}
|
}
|
||||||
|
// background colour packets
|
||||||
|
else if (65279 == packetType) {
|
||||||
|
let rgbx = readInt()
|
||||||
|
graphics.setBackground(
|
||||||
|
(rgbx & 0xFF000000) >>> 24,
|
||||||
|
(rgbx & 0x00FF0000) >>> 16,
|
||||||
|
(rgbx & 0x0000FF00) >>> 8
|
||||||
|
)
|
||||||
|
}
|
||||||
// video packets
|
// video packets
|
||||||
else if (packetType < 2047) {
|
else if (packetType < 2047) {
|
||||||
// iPF
|
// iPF
|
||||||
|
|||||||
10
assets/disk0/tvdos/include/example.js
Normal file
10
assets/disk0/tvdos/include/example.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
exports.greet = function() { println("Hello, module!") }
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Try in your user program:
|
||||||
|
|
||||||
|
let m = require("A:/tvdos/include/example.js")
|
||||||
|
m.greet()
|
||||||
|
|
||||||
|
*/
|
||||||
@@ -4,10 +4,9 @@ TVDOS Graphics Library
|
|||||||
Has no affiliation with OpenGL by Khronos Group
|
Has no affiliation with OpenGL by Khronos Group
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const GL = {};
|
|
||||||
|
|
||||||
// bytes should be able to handle both JSArray and Java ByteArray (toString = "[B")?
|
// bytes should be able to handle both JSArray and Java ByteArray (toString = "[B")?
|
||||||
GL.Texture = function(w, h, bytes) {
|
exports.Texture = function(w, h, bytes) {
|
||||||
this.width = w;
|
this.width = w;
|
||||||
this.height = h;
|
this.height = h;
|
||||||
this.texData = bytes;
|
this.texData = bytes;
|
||||||
@@ -16,7 +15,7 @@ GL.Texture = function(w, h, bytes) {
|
|||||||
throw "Texture data is not an instance of array";
|
throw "Texture data is not an instance of array";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
GL.MonoTex = function(w, h, bits) {
|
exports.MonoTex = function(w, h, bits) {
|
||||||
this.width = w;
|
this.width = w;
|
||||||
this.height = h;
|
this.height = h;
|
||||||
this.texData = bits;
|
this.texData = bits;
|
||||||
@@ -25,16 +24,16 @@ GL.MonoTex = function(w, h, bits) {
|
|||||||
throw "Texture data is not an instance of array";
|
throw "Texture data is not an instance of array";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
GL.SpriteSheet = function(tilew, tileh, tex) {
|
exports.SpriteSheet = function(tilew, tileh, tex) {
|
||||||
this.tileWidth = tilew;
|
this.tileWidth = tilew;
|
||||||
this.tileHeight = tileh;
|
this.tileHeight = tileh;
|
||||||
this.texture = tex;
|
this.texture = tex;
|
||||||
|
|
||||||
if (!tex instanceof GL.Texture) {
|
if (!tex instanceof exports.Texture) {
|
||||||
throw "Texture is not an instance of GL.Texture";
|
throw "Texture is not an instance of exports.Texture";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getOffX = function(x) { // THIS, or: GL.SpriteSheet.prototype.getOffX
|
this.getOffX = function(x) { // THIS, or: exports.SpriteSheet.prototype.getOffX
|
||||||
let tx = this.tileWidth * (x|0);
|
let 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;
|
if (tx + this.tileWidth > this.texture.width) throw "Sprite x-offset of "+tx+" is greater than sprite width "+this.texture.width;
|
||||||
return tx;
|
return tx;
|
||||||
@@ -46,19 +45,19 @@ GL.SpriteSheet = function(tilew, tileh, tex) {
|
|||||||
return ty;
|
return ty;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
GL.drawTexPattern = function(texture, x, y, width, height, framebuffer, fgcol, bgcol) {
|
exports.drawTexPattern = function(texture, x, y, width, height, framebuffer, fgcol, bgcol) {
|
||||||
if (!(texture instanceof GL.Texture) && !(texture instanceof GL.MonoTex)) throw Error("Texture is not a GL Texture types");
|
if (!(texture instanceof exports.Texture) && !(texture instanceof exports.MonoTex)) throw Error("Texture is not a GL Texture types");
|
||||||
|
|
||||||
let paint = (!framebuffer) ? graphics.plotPixel : graphics.plotPixel2
|
let paint = (!framebuffer) ? graphics.plotPixel : graphics.plotPixel2
|
||||||
for (let yy = 0; yy < height; yy++) {
|
for (let yy = 0; yy < height; yy++) {
|
||||||
for (let xx = 0; xx < width;) {
|
for (let xx = 0; xx < width;) {
|
||||||
let tx = xx % texture.width;
|
let tx = xx % texture.width;
|
||||||
let ty = yy % texture.height;
|
let ty = yy % texture.height;
|
||||||
if (texture instanceof GL.Texture) {
|
if (texture instanceof exports.Texture) {
|
||||||
let c = texture.texData[ty * texture.width + tx];
|
let c = texture.texData[ty * texture.width + tx];
|
||||||
paint(x + xx, y + yy, c);
|
paint(x + xx, y + yy, c);
|
||||||
}
|
}
|
||||||
else if (texture instanceof GL.MonoTex) {
|
else if (texture instanceof exports.MonoTex) {
|
||||||
let octet = texture.texData[ty * (texture.width >> 3) + (tx >> 3)];
|
let octet = texture.texData[ty * (texture.width >> 3) + (tx >> 3)];
|
||||||
for (let i = 0; i < 8; i++) {
|
for (let i = 0; i < 8; i++) {
|
||||||
let bit = ((octet >>> (7 - i)) & 1 != 0)
|
let bit = ((octet >>> (7 - i)) & 1 != 0)
|
||||||
@@ -66,25 +65,25 @@ GL.drawTexPattern = function(texture, x, y, width, height, framebuffer, fgcol, b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xx += (texture instanceof GL.MonoTex) ? 8 : 1;
|
xx += (texture instanceof exports.MonoTex) ? 8 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
GL.drawTexPatternOver = function(texture, x, y, width, height, framebuffer, fgcol) {
|
exports.drawTexPatternOver = function(texture, x, y, width, height, framebuffer, fgcol) {
|
||||||
if (!(texture instanceof GL.Texture) && !(texture instanceof GL.MonoTex)) throw Error("Texture is not a GL Texture types");
|
if (!(texture instanceof exports.Texture) && !(texture instanceof exports.MonoTex)) throw Error("Texture is not a GL Texture types");
|
||||||
|
|
||||||
let paint = (!framebuffer) ? graphics.plotPixel : graphics.plotPixel2
|
let paint = (!framebuffer) ? graphics.plotPixel : graphics.plotPixel2
|
||||||
for (let yy = 0; yy < height; yy++) {
|
for (let yy = 0; yy < height; yy++) {
|
||||||
for (let xx = 0; xx < width;) {
|
for (let xx = 0; xx < width;) {
|
||||||
let tx = xx % texture.width;
|
let tx = xx % texture.width;
|
||||||
let ty = yy % texture.height;
|
let ty = yy % texture.height;
|
||||||
if (texture instanceof GL.Texture) {
|
if (texture instanceof exports.Texture) {
|
||||||
let c = texture.texData[ty * texture.width + tx];
|
let c = texture.texData[ty * texture.width + tx];
|
||||||
if ((c & 255) != 255) {
|
if ((c & 255) != 255) {
|
||||||
paint(x + xx, y + yy, c);
|
paint(x + xx, y + yy, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (texture instanceof GL.MonoTex) {
|
else if (texture instanceof exports.MonoTex) {
|
||||||
let octet = texture.texData[ty * (texture.width >> 3) + (tx >> 3)];
|
let octet = texture.texData[ty * (texture.width >> 3) + (tx >> 3)];
|
||||||
for (let i = 0; i < 8; i++) {
|
for (let i = 0; i < 8; i++) {
|
||||||
let bit = ((octet >>> (7 - i)) & 1 != 0)
|
let bit = ((octet >>> (7 - i)) & 1 != 0)
|
||||||
@@ -92,21 +91,21 @@ GL.drawTexPatternOver = function(texture, x, y, width, height, framebuffer, fgco
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xx += (texture instanceof GL.MonoTex) ? 8 : 1;
|
xx += (texture instanceof exports.MonoTex) ? 8 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
* Draws a texture verbatim - color of 255 will be written to the screen buffer
|
* Draws a texture verbatim - color of 255 will be written to the screen buffer
|
||||||
*/
|
*/
|
||||||
GL.drawTexImage = function(texture, x, y, framebuffer, fgcol, bgcol) {
|
exports.drawTexImage = function(texture, x, y, framebuffer, fgcol, bgcol) {
|
||||||
GL.drawTexPattern(texture, x, y, texture.width, texture.height, framebuffer, fgcol, bgcol);
|
exports.drawTexPattern(texture, x, y, texture.width, texture.height, framebuffer, fgcol, bgcol);
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
* Draws texture with blitting - color of 255 will pass-thru what's already on the screen buffer
|
* Draws texture with blitting - color of 255 will pass-thru what's already on the screen buffer
|
||||||
*/
|
*/
|
||||||
GL.drawTexImageOver = function(texture, x, y, framebuffer, fgcol) {
|
exports.drawTexImageOver = function(texture, x, y, framebuffer, fgcol) {
|
||||||
GL.drawTexPatternOver(texture, x, y, texture.width, texture.height, framebuffer, fgcol);
|
exports.drawTexPatternOver(texture, x, y, texture.width, texture.height, framebuffer, fgcol);
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
* @param xi x-index in the spritesheet, ZERO-BASED INDEX
|
* @param xi x-index in the spritesheet, ZERO-BASED INDEX
|
||||||
@@ -116,7 +115,7 @@ GL.drawTexImageOver = function(texture, x, y, framebuffer, fgcol) {
|
|||||||
* @param overrideFG if the value is set and the current pixel of the sheet is not 255, plots this colour instead
|
* @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
|
* @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, framebuffer, overrideFG, overrideBG) {
|
exports.drawSprite = function(sheet, xi, yi, x, y, framebuffer, overrideFG, overrideBG) {
|
||||||
let paint = (!framebuffer) ? graphics.plotPixel : graphics.plotPixel2
|
let paint = (!framebuffer) ? graphics.plotPixel : graphics.plotPixel2
|
||||||
let offx = sheet.getOffX(xi);
|
let offx = sheet.getOffX(xi);
|
||||||
let offy = sheet.getOffY(yi);
|
let offy = sheet.getOffY(yi);
|
||||||
@@ -137,7 +136,7 @@ GL.drawSprite = function(sheet, xi, yi, x, y, framebuffer, overrideFG, overrideB
|
|||||||
* @param y y-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 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, framebuffer, overrideFG) {
|
exports.drawSpriteOver = function(sheet, xi, yi, x, y, framebuffer, overrideFG) {
|
||||||
let paint = (!framebuffer) ? graphics.plotPixel : graphics.plotPixel2
|
let paint = (!framebuffer) ? graphics.plotPixel : graphics.plotPixel2
|
||||||
let offx = sheet.getOffX(xi);
|
let offx = sheet.getOffX(xi);
|
||||||
let offy = sheet.getOffY(yi);
|
let offy = sheet.getOffY(yi);
|
||||||
@@ -150,5 +149,3 @@ GL.drawSpriteOver = function(sheet, xi, yi, x, y, framebuffer, overrideFG) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.freeze(GL); // this returns frozen 'GL'
|
|
||||||
@@ -400,6 +400,7 @@ METADATA -
|
|||||||
3,16: ADPCM Stereo
|
3,16: ADPCM Stereo
|
||||||
<special>
|
<special>
|
||||||
255,255: sync packet (wait until the next frame)
|
255,255: sync packet (wait until the next frame)
|
||||||
|
254,255: background colour packet
|
||||||
|
|
||||||
Packet Type High Byte (iPF Type Numbers)
|
Packet Type High Byte (iPF Type Numbers)
|
||||||
0..7: iPF Type 1..8
|
0..7: iPF Type 1..8
|
||||||
@@ -438,6 +439,12 @@ GLOBAL TYPE 255 Packet -
|
|||||||
Sync Packet (subset of GLOBAL TYPE 255 Packet) -
|
Sync Packet (subset of GLOBAL TYPE 255 Packet) -
|
||||||
uint16 0xFFFF (type of packet for Global Type 255)
|
uint16 0xFFFF (type of packet for Global Type 255)
|
||||||
|
|
||||||
|
Background Colour Packet -
|
||||||
|
uint16 0xFEFF
|
||||||
|
uint8 Red (0-255)
|
||||||
|
uint8 Green (0-255)
|
||||||
|
uint8 Blue (0x255)
|
||||||
|
uint8 0x00 (pad byte)
|
||||||
|
|
||||||
|
|
||||||
Frame Timing
|
Frame Timing
|
||||||
|
|||||||
Reference in New Issue
Block a user