diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/DrawCall.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/DrawCall.kt new file mode 100644 index 0000000..d64f9d2 --- /dev/null +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/DrawCall.kt @@ -0,0 +1,98 @@ +package net.torvald.tsvm.peripheral + +/** + * VLIW-style of Draw Call bytecodes + * + * Created by minjaesong on 2022-11-29. + */ +internal interface DrawCall { + fun execute(gpu: GraphicsAdapter) +} + +internal class DrawCallCompound(val call1: DrawCall, val call2: DrawCall, val call3: DrawCall) : DrawCall { + override fun execute(gpu: GraphicsAdapter) { + call1.execute(gpu) + call2.execute(gpu) + call3.execute(gpu) + } +} + +internal object DrawCallNop : DrawCall { + override fun execute(gpu: GraphicsAdapter) {} +} + +internal object DrawCallEnd : DrawCall { + override fun execute(gpu: GraphicsAdapter) {} +} + +internal class GotoScanline(val line: Int) : DrawCall { + override fun execute(gpu: GraphicsAdapter) { + gpu.drawCallRscanline = line + } +} + +internal class JumpIfScanline( + val compare: Int, + val whenLessThan: Int, + val whenEqualTo: Int, + val whenGreaterThan: Int +) : DrawCall { + override fun execute(gpu: GraphicsAdapter) { + if (gpu.drawCallRscanline < compare) { + if (whenLessThan != 65535) gpu.drawCallRscanline = whenLessThan - 1 + } + else if (gpu.drawCallRscanline == compare) { + if (whenEqualTo != 65535) gpu.drawCallRscanline = whenEqualTo - 1 + } + else { + if (whenGreaterThan != 65535) gpu.drawCallRscanline = whenGreaterThan - 1 + } + } +} + +internal class DrawCallDrawLines( + val opCount: Int, val colour: Int, + val xposLen1: Int, + val xposLen2: Int = 0, + val xposLen3: Int = 0, + val xposLen4: Int = 0, + val xposLen5: Int = 0, + val xposLen6: Int = 0, + val xposLen7: Int = 0, + val xposLen8: Int = 0 +) : DrawCall { + override fun execute(gpu: GraphicsAdapter) { + TODO("Not yet implemented") + } +} + +internal class DrawCallDrawDoubleLines( + val opCount: Int, val colour: Int, + val xposLen1: Int, + val xposLen2: Int = 0, + val xposLen3: Int = 0, + val xposLen4: Int = 0, + val xposLen5: Int = 0, + val xposLen6: Int = 0, + val xposLen7: Int = 0, + val xposLen8: Int = 0 +) : DrawCall { + override fun execute(gpu: GraphicsAdapter) { + TODO("Not yet implemented") + } +} + +internal class DrawCallCopyPixels( + val opCount: Int, + val xPos: Int, + val lineLength: Int, + val stride1: Int, + val stride2: Int = 0, + val stride3: Int = 0, + val stride4: Int = 0, + val stride5: Int = 0, +) : DrawCall { + override fun execute(gpu: GraphicsAdapter) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt b/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt index 1fd3f21..18458fc 100644 --- a/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt +++ b/tsvm_core/src/net/torvald/tsvm/peripheral/GraphicsAdapter.kt @@ -123,6 +123,8 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi // override var halfrowMode = false + private val instArea = UnsafeHelper.allocate(65536L) + override var rawCursorPos: Int get() = textArea.getShortFree(memTextCursorPosOffset).toInt() set(value) { textArea.setShortFree(memTextCursorPosOffset, value.toShort()) } @@ -287,6 +289,8 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi in 1024L..2047L -> scanlineOffsets[addr - 1024] + in 65536L..131071L -> instArea[addr - 65536] + in 0 until VM.MMIO_SIZE -> -1 else -> null } @@ -308,6 +312,8 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi in 1024L..2047L -> { scanlineOffsets[addr - 1024] = byte } + in 65536L..131071L -> instArea[addr - 65536] = byte + else -> null } } @@ -345,6 +351,11 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi } } + private var drawCallSize = 0 + private val drawCallBuffer = Array(3640) { DrawCallEnd } + internal var drawCallProgramCounter = 0 + internal var drawCallRscanline = 0 + /** * @param mode 0-Low, 1-High */ @@ -744,6 +755,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi chrrom.dispose() unusedArea.destroy() scanlineOffsets.destroy() + instArea.destroy() } private var textCursorBlinkTimer = 0f