diff --git a/assets/FontROM7x14.png b/assets/FontROM7x14.png index d50fcfd..ac140a0 100644 Binary files a/assets/FontROM7x14.png and b/assets/FontROM7x14.png differ diff --git a/assets/disk0/fontredef.js b/assets/disk0/fontredef.js new file mode 100644 index 0000000..0aa789b --- /dev/null +++ b/assets/disk0/fontredef.js @@ -0,0 +1,33 @@ +sys.poke(-1299460, 4) + +let off = -1300607 - (14*0x4F) +let char = [0,42,85,62,65,85,65,81,93,65,62,0,0,0] +for (let i = 0; i < char.length; i++) { + sys.poke(off - i, char[i]) +} + +// check if things are copied well +for (let k = 0; k < 14*128; k += 14) { + let c = (k / 14)|0 + let x = 7 * ((c % 16)|0) + let y = 14 * ((c / 16)|0) + + for (let l = 0; l < 14; l++) { + let byte = sys.peek(-1300607 - k - l) + for (let b = 0; b < 7; b++) { + let px = 239 * ((byte >> (6 - b)) & 1) + graphics.plotPixel(200+x+b, 200+y+l, px) + } + } +} + + +sys.poke(-1299460, 6) + +for (let y=0; y < 16; y++) { + for (let x = 0; x < 16; x++) { + con.addch(y*16+x) + con.curs_right() + } + println() +} \ No newline at end of file diff --git a/src/net/torvald/tsvm/DMADelegate.kt b/src/net/torvald/tsvm/DMADelegate.kt index 0318295..84704c3 100644 --- a/src/net/torvald/tsvm/DMADelegate.kt +++ b/src/net/torvald/tsvm/DMADelegate.kt @@ -20,6 +20,7 @@ class DMADelegate(val vm: VM) { UnsafeHelper.memcpyRaw(null, vm.usermem.ptr + from, data, UnsafeHelper.getArrayOffset(data), length.toLong()) it.framebuffer.pixels.position(offset) it.framebuffer.pixels.put(data) + it.framebuffer.pixels.position(0) // rewinding to avoid graphical glitch } } @@ -37,6 +38,7 @@ class DMADelegate(val vm: VM) { val data = ByteArray(length) it.framebuffer.pixels.position(from) it.framebuffer.pixels.get(data) + it.framebuffer.pixels.position(0) // rewinding to avoid graphical glitch UnsafeHelper.memcpyRaw(data, UnsafeHelper.getArrayOffset(data), null, vm.usermem.ptr + to, length.toLong()) } } diff --git a/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt b/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt index 5adceee..991348a 100644 --- a/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt +++ b/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt @@ -6,7 +6,9 @@ import com.badlogic.gdx.graphics.g2d.Gdx2DPixmap import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.glutils.FrameBuffer +import com.badlogic.gdx.graphics.glutils.PixmapTextureData import com.badlogic.gdx.math.Matrix4 +import com.badlogic.gdx.utils.GdxRuntimeException import net.torvald.UnsafeHelper import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUint import net.torvald.tsvm.AppLoader @@ -67,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 chrrom0 = Texture(Pixmap(Gdx2DPixmap(Gdx.files.internal("./assets/"+config.chrRomPath).read(), Gdx2DPixmap.GDX2D_FORMAT_ALPHA))) + protected var chrrom = Pixmap(Gdx2DPixmap(Gdx.files.internal("./assets/"+config.chrRomPath).read(), Gdx2DPixmap.GDX2D_FORMAT_ALPHA)) + protected var chrrom0 = Texture(1,1,Pixmap.Format.RGBA8888) protected val faketex: Texture internal val textArea = UnsafeHelper.allocate(7682) @@ -162,6 +165,7 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super faketex = Texture(pm) pm.dispose() + // initialise with NONZERO value; value zero corresponds to opaque black, and it will paint the whole screen black // when in text mode, and that's undesired behaviour // -1 is preferred because it points to the colour CLEAR, and it's constant. @@ -309,25 +313,27 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super val ch = config.height / config.textRows if (cw > 8 || ch > 15) throw UnsupportedOperationException() - chrrom0.textureData.prepare() - val pixmap = chrrom0.textureData.consumePixmap() + val pixmap = chrrom val scanline = ByteArray(cw) val dataOffset = mode * chrrom0.width * chrrom0.height / 2 for (char in 0 until 128) { + val px = (char % 16) * cw; val py = (char / 16) * ch + val off = dataOffset + (py * 16 * cw) + px for (line in 0 until ch) { - pixmap.pixels.position((char / 16) * (cw * 16 * ch) + (char % 16) * cw + dataOffset) + pixmap.pixels.position(off + (line * 16 * cw)) pixmap.pixels.get(scanline) + pixmap.pixels.position(0) // rewinding to avoid graphical glitch var word = 0 for (bm in 0 until scanline.size) { val pixel = (scanline[bm] < 0).toInt() word = word or (pixel shl (scanline.size - 1 - bm)) } - mappedFontRom[char * ch + line] + mappedFontRom[char * ch + line] = word.toByte() } } - pixmap.dispose() +// try { pixmap.dispose() } catch (e: GdxRuntimeException) {} } /** @@ -341,27 +347,25 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super if (cw > 8 || ch > 15) throw UnsupportedOperationException() - chrrom0.textureData.prepare() - val pixmap = chrrom0.textureData.consumePixmap() + val pixmap = chrrom val scanline = ByteArray(cw) val dataOffset = mode * chrrom0.width * chrrom0.height / 2 for (char in 0 until 128) { + val px = (char % 16) * cw; val py = (char / 16) * ch + val off = dataOffset + (py * 16 * cw) + px for (line in 0 until ch) { - val word = mappedFontRom[char * ch + line] + val word = mappedFontRom[char * ch + line].toInt() for (bm in 0 until scanline.size) { - val pixel = 255 * (word and (1 shl (scanline.size - 1 - bm)).toByte() < 0).toInt() + val pixel = 255 * ((word shr (cw - 1 - bm)) and 1) scanline[bm] = pixel.toByte() } - pixmap.pixels.position((char / 16) * (cw * 16 * ch) + (char % 16) * cw + dataOffset) + pixmap.pixels.position(off + (line * 16 * cw)) pixmap.pixels.put(scanline) + pixmap.pixels.position(0) // rewinding to avoid graphical glitch } } - chrrom0.dispose() - chrrom0 = Texture(pixmap) - - pixmap.dispose() } @@ -671,6 +675,7 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super try { textBackTex.dispose() } catch (_: Throwable) {} chrrom0.dispose() + chrrom.dispose() unusedArea.destroy() } @@ -685,6 +690,10 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super unusedArea[2].toInt().and(15).toFloat() / 15f, 1f) open fun render(delta: Float, uiBatch: SpriteBatch, xoff: Float, yoff: Float) { + // must reset positions as pixmaps expect them to be zero + framebuffer.pixels.position(0) + chrrom.pixels.position(0) + framebuffer2.setColor(-1);framebuffer2.fill() for (y in 0 until config.height) { var xoff = unusedArea[20L + 2*y].toUint().shl(8) or unusedArea[20L + 2*y + 1].toUint() @@ -702,6 +711,8 @@ open class GraphicsAdapter(val vm: VM, val config: AdapterConfig, val sgr: Super } + chrrom0.dispose() + chrrom0 = Texture(chrrom) rendertex.dispose() rendertex = Texture(framebuffer2, Pixmap.Format.RGBA8888, false) diff --git a/terranmon.txt b/terranmon.txt index 7711fa9..e4d2aa0 100644 --- a/terranmon.txt +++ b/terranmon.txt @@ -158,7 +158,7 @@ From the start of the memory space: 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 Low Font ROM (char 128–255) 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 12 bytes