mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-08 04:01:51 +09:00
make colour change in terminal work on command.js; video will draw on centre of the app window
This commit is contained in:
@@ -11,7 +11,7 @@ for(let i=0;i<2560;i++)graphics.putSymbolAt(1+(i/80)|0,1+(i%80),239);
|
||||
// draw logo
|
||||
for(let i=0;i<logo.length;i++){graphics.plotPixel(i%560,95+(i/560)|0,logo[i])}
|
||||
// scramble lines
|
||||
let m=4;let r=()=>{let i=Math.random()*2-1;return(i<0)?i-1:i+1};
|
||||
let m=5;let r=()=>{let i=Math.random()*2-1;return(i<0)?i-1:i+1};
|
||||
let o=[];for(let y=0;y<164;y++){
|
||||
let k=Math.round(r()*560/m)|0;
|
||||
o.push(k);graphics.setLineOffset(95+y,k*m);}
|
||||
@@ -22,7 +22,7 @@ for(let i=0;i<2560;i++)graphics.putSymbolAt(1+(i/80)|0,1+(i%80),0);
|
||||
let tmr=0;let n=560*2;while(n>0){
|
||||
for(let y=0;y<164;y++){o[y]-=Math.sign(o[y]);graphics.setLineOffset(95+y,o[y]*m);}
|
||||
// wait for timer
|
||||
tmr=sys.nanoTime();while(sys.nanoTime()-tmr<250000*m)Math.sqrt(tmr) // waste some cpu time
|
||||
tmr=sys.nanoTime();while(sys.nanoTime()-tmr<300000*m)Math.sqrt(tmr) // waste some cpu time
|
||||
n-=m;}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ Object.freeze(_BIOS);
|
||||
tmr = sys.nanoTime();
|
||||
while (sys.nanoTime() - tmr < 2147483648) sys.spin();
|
||||
// clear screen
|
||||
graphics.clearPixels(255);con.color_pair(254,255);
|
||||
graphics.clearPixels(255);con.color_pair(239,255);
|
||||
con.clear();con.move(1,1);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
18
assets/disk0/tvdos/bin/color.js
Normal file
18
assets/disk0/tvdos/bin/color.js
Normal file
@@ -0,0 +1,18 @@
|
||||
let backs = {0:[0,0,0],1:[3,2,15],2:[3,9,4],3:[6,13,15],4:[15,4,4],5:[15,6,15],6:[15,13,0],7:[14,14,14]}
|
||||
let fores = {0:240,1:49,2:61,3:114,4:211,5:219,6:230,7:254}
|
||||
|
||||
if (exec_args[1]) {
|
||||
let b = exec_args[1][0].toUpperCase()
|
||||
let f = exec_args[1][1].toUpperCase()
|
||||
|
||||
if (b == f) return 1
|
||||
let ba = backs[b]
|
||||
let fo = fores[f]
|
||||
|
||||
if (!ba || !fo) return 2
|
||||
|
||||
serial.println(fo)
|
||||
|
||||
graphics.setBackground(ba[0], ba[1], ba[2])
|
||||
con.color_pair(fo, 255)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ function print_prompt_text() {
|
||||
con.color_pair(253,255);
|
||||
}
|
||||
else {
|
||||
con.color_pair(253,255);
|
||||
// con.color_pair(253,255);
|
||||
if (errorlevel != 0)
|
||||
print(CURRENT_DRIVE + ":/" + shell_pwd.join("/") + " [" + errorlevel + "]" + PROMPT_TEXT);
|
||||
else
|
||||
@@ -490,13 +490,13 @@ else {
|
||||
|
||||
let cmdExit = false;
|
||||
if (goInteractive) {
|
||||
con.reset_graphics();
|
||||
con.curs_set(1);
|
||||
greet();
|
||||
|
||||
let cmdHistory = []; // zeroth element is the oldest
|
||||
let cmdHistoryScroll = 0; // 0 for outside-of-buffer, 1 for most recent
|
||||
while (!cmdExit) {
|
||||
con.reset_graphics();
|
||||
con.curs_set(1);
|
||||
print_prompt_text();
|
||||
|
||||
var cmdbuf = "";
|
||||
|
||||
@@ -12,8 +12,8 @@ public class AppLoader {
|
||||
public static String appTitle = "Totally Simple Virtual Machine";
|
||||
public static Lwjgl3ApplicationConfiguration appConfig;
|
||||
|
||||
public static int WIDTH = 560;//810;//720;
|
||||
public static int HEIGHT = 448;//360;//480;
|
||||
public static int WIDTH = 640;//810;//720;
|
||||
public static int HEIGHT = 480;//360;//480;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ShaderProgram.pedantic = false;
|
||||
@@ -37,14 +37,13 @@ public class AppLoader {
|
||||
// uncomment to target the TerranBASIC runner
|
||||
// VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{TBASRelBios.INSTANCE});
|
||||
|
||||
EmulInstance reference = new EmulInstance(vm, "net.torvald.tsvm.peripheral.ReferenceGraphicsAdapter", "assets/disk0");
|
||||
EmulInstance reference2 = new EmulInstance(vm, "net.torvald.tsvm.peripheral.ReferenceLikeLCD", "assets/disk0");
|
||||
EmulInstance term = new EmulInstance(vm, "net.torvald.tsvm.peripheral.Term", "assets/disk0");
|
||||
EmulInstance portable = new EmulInstance(vm, "net.torvald.tsvm.peripheral.CharacterLCDdisplay", "assets/disk0");
|
||||
EmulInstance reference = new EmulInstance(vm, "net.torvald.tsvm.peripheral.ReferenceGraphicsAdapter", "assets/disk0", 560, 448);
|
||||
EmulInstance reference2 = new EmulInstance(vm, "net.torvald.tsvm.peripheral.ReferenceLikeLCD", "assets/disk0", 560, 447);
|
||||
EmulInstance term = new EmulInstance(vm, "net.torvald.tsvm.peripheral.Term", "assets/disk0", 720, 480);
|
||||
EmulInstance portable = new EmulInstance(vm, "net.torvald.tsvm.peripheral.CharacterLCDdisplay", "assets/disk0", 628, 302);
|
||||
EmulInstance wp = new EmulInstance(vm, "net.torvald.tsvm.peripheral.WpTerm", "assets/wpdisk", 810, 360);
|
||||
|
||||
EmulInstance wp = new EmulInstance(vm, "net.torvald.tsvm.peripheral.WpTerm", "assets/wpdisk");
|
||||
|
||||
new Lwjgl3Application(new VMGUI(reference), appConfig);
|
||||
new Lwjgl3Application(new VMGUI(reference, WIDTH, HEIGHT), appConfig);
|
||||
}
|
||||
|
||||
public static ShaderProgram loadShaderFromFile(String vert, String frag) {
|
||||
|
||||
@@ -15,10 +15,12 @@ fun ByteArray.startsWith(other: ByteArray) = this.sliceArray(other.indices).cont
|
||||
data class EmulInstance(
|
||||
val vm: VM,
|
||||
val display: String,
|
||||
val diskPath: String = "assets/disk0"
|
||||
val diskPath: String = "assets/disk0",
|
||||
val drawWidth: Int,
|
||||
val drawHeight: Int
|
||||
)
|
||||
|
||||
class VMGUI(val loaderInfo: EmulInstance) : ApplicationAdapter() {
|
||||
class VMGUI(val loaderInfo: EmulInstance, val viewportWidth: Int, val viewportHeight: Int) : ApplicationAdapter() {
|
||||
|
||||
val vm = loaderInfo.vm
|
||||
|
||||
@@ -137,7 +139,10 @@ class VMGUI(val loaderInfo: EmulInstance) : ApplicationAdapter() {
|
||||
fun poke(addr: Long, value: Byte) = vm.poke(addr, value)
|
||||
|
||||
private fun renderGame(delta: Float) {
|
||||
gpu.render(delta, batch, 0f, 0f)
|
||||
val clearCol = gpu.getBackgroundColour()
|
||||
Gdx.gl.glClearColor(clearCol.r, clearCol.g, clearCol.b, clearCol.a)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
gpu.render(delta, batch, (viewportWidth - loaderInfo.drawWidth).div(2).toFloat(), (viewportHeight - loaderInfo.drawHeight).div(2).toFloat())
|
||||
}
|
||||
|
||||
private fun setCameraPosition(newX: Float, newY: Float) {
|
||||
|
||||
@@ -598,18 +598,22 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super
|
||||
private var glowDecay = config.decay
|
||||
private var decayColor = Color(1f, 1f, 1f, 1f - glowDecay)
|
||||
|
||||
fun getBackgroundColour() = Color(unusedArea[0].toInt().and(15).toFloat() / 15f,
|
||||
unusedArea[1].toInt().and(15).toFloat() / 15f,
|
||||
unusedArea[2].toInt().and(15).toFloat() / 15f, 1f)
|
||||
|
||||
open fun render(delta: Float, uiBatch: SpriteBatch, xoff: Float, yoff: Float) {
|
||||
framebuffer2.setColor(-1);framebuffer2.fill()
|
||||
for (y in 0 until 448) {
|
||||
for (y in 0 until config.height) {
|
||||
var xoff = unusedArea[20L + 2*y].toUint().shl(8) or unusedArea[20L + 2*y + 1].toUint()
|
||||
if (xoff.and(0x8000) != 0) xoff = xoff or 0xFFFF0000.toInt()
|
||||
val xs = (0+xoff).coerceIn(0,559) .. (559+xoff).coerceIn(0,559)
|
||||
val xs = (0+xoff).coerceIn(0,config.width-1) .. (config.width-1+xoff).coerceIn(0,config.width-1)
|
||||
|
||||
if (xoff in -559..559) {
|
||||
if (xoff in -(config.width-1)..config.width-1) {
|
||||
for (x in xs) {
|
||||
// this only works because framebuffer is guaranteed to be 8bpp
|
||||
framebuffer2.pixels.put(y*560+x,
|
||||
framebuffer.pixels.get(y*560 + (x - xoff)) // coerceIn not required as (x - xoff) never escapes 0..559
|
||||
framebuffer2.pixels.put(y*config.width+x,
|
||||
framebuffer.pixels.get(y*config.width + (x - xoff)) // coerceIn not required as (x - xoff) never escapes 0..559
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -633,9 +637,7 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super
|
||||
|
||||
|
||||
outFBOs[0].inUse {
|
||||
val clearCol = Color(unusedArea[0].toInt().and(15).toFloat() / 15f,
|
||||
unusedArea[1].toInt().and(15).toFloat() / 15f,
|
||||
unusedArea[2].toInt().and(15).toFloat() / 15f, 1f)
|
||||
val clearCol = getBackgroundColour()
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 1f)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user