mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-12 14:11:50 +09:00
faster partial reading of file wip
This commit is contained in:
@@ -11,6 +11,9 @@ class CompressorDelegate(val vm: VM) {
|
||||
fun comp(str: String) = Companion.comp(str)
|
||||
fun comp(ba: ByteArray) = Companion.comp(ba)
|
||||
|
||||
/**
|
||||
* @return length of the bytes compressed
|
||||
*/
|
||||
fun compFromTo(input: Int, len: Int, output: Int): Int {
|
||||
val inbytes = ByteArray(len) { vm.peek(input.toLong() + it)!! }
|
||||
comp(inbytes).let {
|
||||
@@ -48,6 +51,19 @@ class CompressorDelegate(val vm: VM) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return length of the bytes compressed
|
||||
*/
|
||||
fun decompFromTo(input: Int, len: Int, output: Int): Int {
|
||||
val inbytes = ByteArray(len) { vm.peek(input.toLong() + it)!! }
|
||||
decomp(inbytes).let {
|
||||
it.forEachIndexed { index, byte ->
|
||||
vm.poke(output.toLong() + index, byte)
|
||||
}
|
||||
return it.size
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val GZIP_HEADER = byteArrayOf(31, -117, 8) // .gz in DEFLATE
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ package net.torvald.tsvm
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import net.torvald.UnsafeHelper
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUlong
|
||||
import net.torvald.tsvm.peripheral.IOSpace
|
||||
import java.nio.charset.Charset
|
||||
|
||||
/**
|
||||
@@ -16,6 +18,24 @@ class VMJSR223Delegate(val vm: VM) {
|
||||
fun nanoTime() = System.nanoTime()
|
||||
fun malloc(size: Int) = vm.malloc(size)
|
||||
fun free(ptr: Int) = vm.free(ptr)
|
||||
fun memcpy(from: Int, to: Int, len: Int) {
|
||||
val len = len.toLong()
|
||||
// some special cases for native memcpy
|
||||
val ioSpace = vm.peripheralTable[0].peripheral!! as IOSpace
|
||||
// within scratchpad memory?
|
||||
if (from in 0 until 8388608 && (to + len) in 0 until 8388608)
|
||||
UnsafeHelper.memcpy(vm.usermem.ptr + from, vm.usermem.ptr + to, len)
|
||||
// first serial read buffer -> usermem
|
||||
else if (from in -4097 downTo -8192 && (to + len) in 0 until 8388608)
|
||||
UnsafeHelper.memcpy(ioSpace.blockTransferRx[0].ptr + (-4097 - from), vm.usermem.ptr + to, len)
|
||||
// usermem -> first serial write buffer
|
||||
else if (from in 0 until 8388608 && (to + len) in -4097L downTo -8192L)
|
||||
UnsafeHelper.memcpy(vm.usermem.ptr + from, ioSpace.blockTransferTx[0].ptr + (-4097 - to), len)
|
||||
else
|
||||
for (i in 0 until len) {
|
||||
vm.poke(to + i, vm.peek(from + i)!!)
|
||||
}
|
||||
}
|
||||
fun mapRom(slot: Int) {
|
||||
vm.romMapping = slot.and(255)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user