graphics: fixed bad screen fill command impl; added clearPixels cmd

This commit is contained in:
minjaesong
2021-04-27 14:02:38 +09:00
parent 62e115a32e
commit e031f0d256
4 changed files with 29 additions and 11 deletions

View File

@@ -0,0 +1,19 @@
var imageBits = gzip.decomp(base64.atob(
"H4sICPx7h2ACA3RhbmRlbV9sb2dvXzI0MC5iaW4A7dQ/boMwFAbwz3Ikd4jitUMleoSOGaL6Kj1Cxg6V8NF8FI7AyIBwPv8hOA6kW6Y8IST4WWC/92zvX/GMsABEj9Y7+BEdoD1vUICfIKJ2MNQ2qqhVlop2XU1Sk5WDoyqHZtFmXZukulJtOdOrqqxmuFGdVFbabCpT4D2fqIqqvBW8hVdNP+vnot2Gyqh9rRPOclFk5coKfRNRh1pHnMUjHah7RB1nZQbX9CekgBPl14IOGODdAX/ryj/eq7RJe2rrNE6lfkn7nlRO/6v9uFGBpB3V1HoUvKIqH5RrWtXQa4umbByR1e042OluV2byBPwm3T9Se2DOne5RVnBDc/W/EbIftIk6oOycq3L+rFdWe6fGBh1RdqyBmJUJ2dIpqHR6QrlTFm1ZiKvmXWasjDoGFU57lDt0Q02tns1DteXJYJyKOgTFrPOpcqeuPJGSvuIpcQH1GZbNgAcAAA=="
));
for (let y = 0; y < 64; y++) {
for (let x = 0; x < 30; x++) {
let word = imageBits[y * 30 + x];
for (let i = 0; i < 8; i++) {
graphics.plotPixel(8*x + i, y, ((word >>> (7 - i)) & 1 != 0) ? 255 : 239);
}
}
}
// wait arbitrary time
for (let b=0;b<333333;b++) {
sys.poke(0,(Math.random()*255)|0);
sys.poke(0,0);
}
con.clear();
graphics.clearPixels(255);

View File

@@ -38,7 +38,7 @@ public class AppLoader {
EmulInstance term = new EmulInstance(appConfig, vm, "net.torvald.tsvm.peripheral.TexticsAdapter", "assets/disk0");
EmulInstance portable = new EmulInstance(appConfig, vm, "net.torvald.tsvm.peripheral.CharacterLCDdisplay", "assets/disk0");
new LwjglApplication(new VMGUI(portable), appConfig);
new LwjglApplication(new VMGUI(reference), appConfig);
}
public static ShaderProgram loadShaderFromFile(String vert, String frag) {

View File

@@ -79,6 +79,11 @@ class GraphicsJSR223Delegate(val vm: VM) {
}
}
fun clearPixels(col: Int) {
getFirstGPU()?.poke(250884L, col.toByte())
getFirstGPU()?.poke(250883L, 2)
}
/**
* prints a char as-is; won't interpret them as an escape sequence
*/

View File

@@ -14,6 +14,7 @@ import net.torvald.tsvm.peripheral.GraphicsAdapter.Companion.DRAW_SHADER_FRAG
import java.io.InputStream
import java.io.OutputStream
import kotlin.experimental.and
import kotlin.math.roundToInt
data class AdapterConfig(
val theme: String,
@@ -262,12 +263,7 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super
}
}
2 -> {
framebuffer.setColor(
paletteOfFloats[arg1 * 4],
paletteOfFloats[arg1 * 4 + 1],
paletteOfFloats[arg1 * 4 + 2],
paletteOfFloats[arg1 * 4 + 3]
)
framebuffer.setColor(0f,0f,0f,arg1 / 255f)
framebuffer.fill()
}
}
@@ -767,9 +763,7 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super
}
private fun peekPalette(offset: Int): Byte {
if (offset == 255) return 0 // palette 255 is always transparent
// FIXME always return zero?
if (offset >= 255 * 2) return 0 // palette 255 is always transparent
val highvalue = paletteOfFloats[offset * 2] // R, B
val lowvalue = paletteOfFloats[offset * 2 + 1] // G, A
@@ -778,7 +772,7 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super
private fun pokePalette(offset: Int, byte: Byte) {
// palette 255 is always transparent
if (offset < 255) {
if (offset < 255 * 2) {
val highvalue = byte.toInt().and(0xF0).ushr(4) / 15f
val lowvalue = byte.toInt().and(0x0F) / 15f