mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-13 22:46:06 +09:00
gpu 'draw call bytecode' implementation WIP
This commit is contained in:
98
tsvm_core/src/net/torvald/tsvm/peripheral/DrawCall.kt
Normal file
98
tsvm_core/src/net/torvald/tsvm/peripheral/DrawCall.kt
Normal file
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -123,6 +123,8 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
|
|||||||
|
|
||||||
// override var halfrowMode = false
|
// override var halfrowMode = false
|
||||||
|
|
||||||
|
private val instArea = UnsafeHelper.allocate(65536L)
|
||||||
|
|
||||||
override var rawCursorPos: Int
|
override var rawCursorPos: Int
|
||||||
get() = textArea.getShortFree(memTextCursorPosOffset).toInt()
|
get() = textArea.getShortFree(memTextCursorPosOffset).toInt()
|
||||||
set(value) { textArea.setShortFree(memTextCursorPosOffset, value.toShort()) }
|
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 1024L..2047L -> scanlineOffsets[addr - 1024]
|
||||||
|
|
||||||
|
in 65536L..131071L -> instArea[addr - 65536]
|
||||||
|
|
||||||
in 0 until VM.MMIO_SIZE -> -1
|
in 0 until VM.MMIO_SIZE -> -1
|
||||||
else -> null
|
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 1024L..2047L -> { scanlineOffsets[addr - 1024] = byte }
|
||||||
|
|
||||||
|
in 65536L..131071L -> instArea[addr - 65536] = byte
|
||||||
|
|
||||||
else -> null
|
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<DrawCall>(3640) { DrawCallEnd }
|
||||||
|
internal var drawCallProgramCounter = 0
|
||||||
|
internal var drawCallRscanline = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mode 0-Low, 1-High
|
* @param mode 0-Low, 1-High
|
||||||
*/
|
*/
|
||||||
@@ -744,6 +755,7 @@ open class GraphicsAdapter(private val assetsRoot: String, val vm: VM, val confi
|
|||||||
chrrom.dispose()
|
chrrom.dispose()
|
||||||
unusedArea.destroy()
|
unusedArea.destroy()
|
||||||
scanlineOffsets.destroy()
|
scanlineOffsets.destroy()
|
||||||
|
instArea.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var textCursorBlinkTimer = 0f
|
private var textCursorBlinkTimer = 0f
|
||||||
|
|||||||
Reference in New Issue
Block a user