mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
dma
This commit is contained in:
@@ -32,7 +32,7 @@ public class AppLoader {
|
||||
// VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{OEMBios.INSTANCE, BasicRom.INSTANCE});
|
||||
// VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{TandemBios.INSTANCE, BasicRom.INSTANCE});
|
||||
// VM vm = new VM(128 << 10, new TheRealWorld(), new VMProgramRom[]{BasicBios.INSTANCE, WPBios.INSTANCE});
|
||||
VM vm = new VM(128 << 10, new TheRealWorld(), new VMProgramRom[]{TsvmBios.INSTANCE});
|
||||
VM vm = new VM(2048 << 10, new TheRealWorld(), new VMProgramRom[]{TsvmBios.INSTANCE});
|
||||
|
||||
// uncomment to target the TerranBASIC runner
|
||||
// VM vm = new VM(64 << 10, new TheRealWorld(), new VMProgramRom[]{TBASRelBios.INSTANCE});
|
||||
|
||||
77
src/net/torvald/tsvm/DMADelegate.kt
Normal file
77
src/net/torvald/tsvm/DMADelegate.kt
Normal file
@@ -0,0 +1,77 @@
|
||||
package net.torvald.tsvm
|
||||
|
||||
import net.torvald.UnsafeHelper
|
||||
import net.torvald.tsvm.peripheral.GraphicsAdapter
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-10-15.
|
||||
*/
|
||||
class DMADelegate(val vm: VM) {
|
||||
|
||||
private val READ = "READ".toByteArray(VM.CHARSET)
|
||||
private val FLUSH = "FLUSH".toByteArray(VM.CHARSET)
|
||||
private val CLOSE = "CLOSE".toByteArray(VM.CHARSET)
|
||||
|
||||
private fun WRITE(n: Int) = "WRITE$n".toByteArray(VM.CHARSET)
|
||||
|
||||
fun ramToFrame(from: Int, devnum: Int, offset: Int, length: Int) {
|
||||
(vm.peripheralTable[devnum].peripheral as? GraphicsAdapter)?.let {
|
||||
val data = ByteArray(length)
|
||||
UnsafeHelper.memcpyRaw(null, vm.usermem.ptr + from, data, UnsafeHelper.getArrayOffset(data), length.toLong())
|
||||
it.framebuffer.pixels.position(offset)
|
||||
it.framebuffer.pixels.put(data)
|
||||
}
|
||||
}
|
||||
|
||||
fun ramToFrame(from: Int, to: Int, length: Int) {
|
||||
for (i in 0..7) {
|
||||
if (vm.peripheralTable[i].type == VM.PERITYPE_GPU_AND_TERM) {
|
||||
ramToFrame(from, i, to, length)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun frameToRam(from: Int, to: Int, devnum: Int, length: Int) {
|
||||
(vm.peripheralTable[devnum].peripheral as? GraphicsAdapter)?.let {
|
||||
val data = ByteArray(length)
|
||||
it.framebuffer.pixels.position(from)
|
||||
it.framebuffer.pixels.get(data)
|
||||
UnsafeHelper.memcpyRaw(data, UnsafeHelper.getArrayOffset(data), null, vm.usermem.ptr + to, length.toLong())
|
||||
}
|
||||
}
|
||||
|
||||
fun frameToRam(from: Int, to: Int, length: Int) {
|
||||
for (i in 0..7) {
|
||||
if (vm.peripheralTable[i].type == VM.PERITYPE_GPU_AND_TERM) {
|
||||
frameToRam(from, to, i, length)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun comToRam(portNo: Int, srcOff: Int, destOff: Int, length: Int) {
|
||||
SerialHelper.sendMessage(vm, portNo, READ)
|
||||
val response = SerialHelper.getStatusCode(vm, portNo)
|
||||
if (response == 0) {
|
||||
val file = SerialHelper.pullMessage(vm, portNo)
|
||||
UnsafeHelper.memcpyRaw(file, UnsafeHelper.getArrayOffset(file) + srcOff.toLong(), null, vm.usermem.ptr + destOff, length.toLong())
|
||||
}
|
||||
}
|
||||
|
||||
fun ramToCom(srcOff: Int, portNo: Int, length: Int) {
|
||||
SerialHelper.sendMessage(vm, portNo, WRITE(length))
|
||||
val response = SerialHelper.getStatusCode(vm, portNo)
|
||||
if (response == 0) {
|
||||
val msg = ByteArray(length)
|
||||
UnsafeHelper.memcpyRaw(null, vm.usermem.ptr + srcOff, msg, UnsafeHelper.getArrayOffset(msg), length.toLong())
|
||||
SerialHelper.sendMessage(vm, portNo, msg)
|
||||
SerialHelper.sendMessage(vm, portNo, FLUSH)
|
||||
SerialHelper.sendMessage(vm, portNo, CLOSE)
|
||||
}
|
||||
}
|
||||
|
||||
fun ramToRam(from: Int, to: Int, length: Int) {
|
||||
UnsafeHelper.memcpy(vm.usermem.ptr + from, vm.usermem.ptr + to, length.toLong())
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,7 @@ object VMRunnerFactory {
|
||||
bind.putMember("gzip", CompressorDelegate)
|
||||
bind.putMember("base64", Base64Delegate)
|
||||
bind.putMember("com", SerialHelperDelegate(vm))
|
||||
bind.putMember("dma", DMADelegate(vm))
|
||||
|
||||
val fr = FileReader("./assets/JS_INIT.js")
|
||||
val prg = fr.readText()
|
||||
|
||||
Reference in New Issue
Block a user