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:
@@ -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