From 0898e8478eb77dcaa06524f2f895da21610e28c7 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 19 Oct 2021 09:33:45 +0900 Subject: [PATCH] methods to reset font rom to default --- assets/disk0/fontredef.js | 10 ++++++-- .../tsvm/peripheral/GraphicsAdapter.kt | 25 ++++++++++++++++--- terranmon.txt | 11 +++++--- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/assets/disk0/fontredef.js b/assets/disk0/fontredef.js index 0aa789b..e1a2382 100644 --- a/assets/disk0/fontredef.js +++ b/assets/disk0/fontredef.js @@ -1,4 +1,10 @@ -sys.poke(-1299460, 4) +if ("reset" == (exec_args[1] || "").toLowerCase()) { + sys.poke(-1299460, 20) + sys.poke(-1299460, 21) + return 0 +} + +sys.poke(-1299460, 16) let off = -1300607 - (14*0x4F) let char = [0,42,85,62,65,85,65,81,93,65,62,0,0,0] @@ -22,7 +28,7 @@ for (let k = 0; k < 14*128; k += 14) { } -sys.poke(-1299460, 6) +sys.poke(-1299460, 18) for (let y=0; y < 16; y++) { for (let x = 0; x < 16; x++) { diff --git a/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt b/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt index 991348a..626ddf4 100644 --- a/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt +++ b/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt @@ -69,7 +69,8 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super val channel = it % 4 rgba.shr((3 - channel) * 8).and(255) / 255f } - protected var chrrom = Pixmap(Gdx2DPixmap(Gdx.files.internal("./assets/"+config.chrRomPath).read(), Gdx2DPixmap.GDX2D_FORMAT_ALPHA)) + protected fun getOriginalChrrom() = Pixmap(Gdx2DPixmap(Gdx.files.internal("./assets/"+config.chrRomPath).read(), Gdx2DPixmap.GDX2D_FORMAT_ALPHA)) + protected var chrrom: Pixmap = getOriginalChrrom() protected var chrrom0 = Texture(1,1,Pixmap.Format.RGBA8888) protected val faketex: Texture @@ -298,8 +299,9 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super framebuffer.setColor(0f,0f,0f,arg1 / 255f) framebuffer.fill() } - 4, 5 -> readFontRom(opcode - 4) - 6, 7 -> writeFontRom(opcode - 6) + 16, 17 -> readFontRom(opcode - 16) + 18, 19 -> writeFontRom(opcode - 18) + 20, 21 -> resetFontRom(opcode - 20) } } @@ -368,6 +370,23 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super } + /** + * @param mode 0-Low, 1-High + */ + open fun resetFontRom(mode: Int) { + val pixmap = getOriginalChrrom() + val data = ByteArray(chrrom0.width * chrrom0.height / 2) + val dataOffset = mode * chrrom0.width * chrrom0.height / 2 + pixmap.pixels.position(dataOffset) + pixmap.pixels.get(data) + + chrrom.pixels.position(dataOffset) + chrrom.pixels.put(data) + chrrom.pixels.position(0) + + pixmap.dispose() + } + override fun resetTtyStatus() { ttyFore = TTY_FORE_DEFAULT diff --git a/terranmon.txt b/terranmon.txt index e4d2aa0..9055d5a 100644 --- a/terranmon.txt +++ b/terranmon.txt @@ -157,10 +157,13 @@ From the start of the memory space: 1: reset palette to default 2: fill framebuffer with given colour (arg1) 3: do '1' then do '2' - 4: copy Low Font ROM (char 0–127) to mapping area - 5: copy High Font ROM (char 128–255) to mapping area - 6: write contents of the font ROM mapping area to the Low Font ROM - 7: write contents of the font ROM mapping area to the High Font ROM + + 16: copy Low Font ROM (char 0–127) to mapping area + 17: copy High Font ROM (char 128–255) to mapping area + 18: write contents of the font ROM mapping area to the Low Font ROM + 19: write contents of the font ROM mapping area to the High Font ROM + 20: reset Low Font ROM to default + 21: reset High Font ROM to default 12 bytes argument for "command" (arg1: Byte, arg2: Byte) write to this address FIRST and then write to "command" to execute the command