From 47b3cd0cad965936e5d12d19afa8fa3a912c290d Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 9 Jan 2023 01:41:35 +0900 Subject: [PATCH] bias lighting (wut?) on playmov; gpu background is now 8bpp --- assets/bios/tsvmbios.js | 4 +- assets/disk0/tvdos/bin/color.js | 2 +- assets/disk0/tvdos/bin/playmov.js | 49 ++++++++++++++++++- terranmon.txt | 2 +- tsvm_core/src/net/torvald/tsvm/VM.kt | 3 ++ .../tsvm/peripheral/GraphicsAdapter.kt | 15 +++--- 6 files changed, 63 insertions(+), 12 deletions(-) diff --git a/assets/bios/tsvmbios.js b/assets/bios/tsvmbios.js index 051931e..48a1288 100644 --- a/assets/bios/tsvmbios.js +++ b/assets/bios/tsvmbios.js @@ -16,7 +16,7 @@ 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);} // unhide screen -graphics.setBackground(0,4,15);con.color_pair(239,255); +graphics.setBackground(0,68,255);con.color_pair(239,255); for(let i=0;i<2560;i++)graphics.putSymbolAt(1+(i/80)|0,1+(i%80),0); // unscramble let tmr=0;let n=560*2;while(n>0){ @@ -36,7 +36,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>> 4) / 15.0, (rg & 15) / 15.0, (ba >>> 4) / 15.0] +} + +let oldBgcol = [0.0, 0.0, 0.0] + renderLoop: while (seqread.getReadCount() < FILE_LENGTH) { let t1 = sys.nanoTime() @@ -94,6 +107,7 @@ while (seqread.getReadCount() < FILE_LENGTH) { } // background colour packets else if (65279 == packetType) { + AUTO_BGCOLOUR_CHANGE = false let rgbx = seqread.readInt() graphics.setBackground( (rgbx & 0xFF000000) >>> 24, @@ -120,6 +134,39 @@ while (seqread.getReadCount() < FILE_LENGTH) { gzip.decompFromTo(gzippedPtr, payloadLen, ipfbuf) // should return FBUF_SIZE decodefun(ipfbuf, -1048577, -1310721, width, height, (packetType & 255) == 5) + + // calculate bgcolour from the edges of the screen + if (AUTO_BGCOLOUR_CHANGE) { + let samples = [] + for (let x = 8; x < 560; x+=32) { + samples.push(getRGBfromScr(x, 3)) + samples.push(getRGBfromScr(x, 445)) + } + for (let y = 29; y < 448; y+=26) { + samples.push(getRGBfromScr(8, y)) + samples.push(getRGBfromScr(552, y)) + } + + let out = [0.0, 0.0, 0.0] + samples.forEach(rgb=>{ + out[0] += rgb[0] + out[1] += rgb[1] + out[2] += rgb[2] + }) + out[0] = out[0] / samples.length / 2.0 // darken a bit + out[1] = out[1] / samples.length / 2.0 + out[2] = out[2] / samples.length / 2.0 + + let bgr = (oldBgcol[0]*5 + out[0]) / 6.0 + let bgg = (oldBgcol[1]*5 + out[1]) / 6.0 + let bgb = (oldBgcol[2]*5 + out[2]) / 6.0 + + oldBgcol = [bgr, bgg, bgb] + + graphics.setBackground(Math.round(bgr * 255), Math.round(bgg * 255), Math.round(bgb * 255)) + } + + // defer audio playback until a first frame is sent if (!audioFired) { audio.play(0) diff --git a/terranmon.txt b/terranmon.txt index fe17f1e..cc84bcf 100644 --- a/terranmon.txt +++ b/terranmon.txt @@ -155,7 +155,7 @@ From the start of the memory space: 250880 bytes Framebuffer 3 bytes - Initial background (and the border) colour RGB, of which only the lower 4 bits per each channel are used + Initial background (and the border) colour RGB, 8 bits per channel 1 byte command (writing to this memory address changes the status) 1: reset palette to default diff --git a/tsvm_core/src/net/torvald/tsvm/VM.kt b/tsvm_core/src/net/torvald/tsvm/VM.kt index f682eab..ee5cad6 100644 --- a/tsvm_core/src/net/torvald/tsvm/VM.kt +++ b/tsvm_core/src/net/torvald/tsvm/VM.kt @@ -190,6 +190,9 @@ class VM( fun peek(addr:Long): Byte? { val (memspace, offset) = translateAddr(addr) + +// println("peek $addr -> ${offset}@${memspace?.javaClass?.canonicalName}") + return if (memspace == null) null else if (memspace is UnsafePtr) { diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt index 44f6b38..7f971fc 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt @@ -192,9 +192,9 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi } if (theme.contains("color")) { - unusedArea[0] = 2 - unusedArea[1] = 3 - unusedArea[2] = 4 + unusedArea[0] = 32 + unusedArea[1] = 48 + unusedArea[2] = 64 } setCursorPos(0, 0) @@ -202,7 +202,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi override fun peek(addr: Long): Byte? { val adi = addr.toInt() - if (framebuffer2 != null) { + if (framebuffer2 != null && addr >= 262144) { return when (addr - 262144) { in 0 until 250880 -> framebuffer2[addr - 262144] else -> null @@ -982,9 +982,10 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi 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) + fun getBackgroundColour() = Color( + unusedArea[0].toUint() / 255f, + unusedArea[1].toUint() / 255f, + unusedArea[2].toUint() / 255f, 1f) private val isRefSize = (WIDTH == 560 && HEIGHT == 448)