vm update

This commit is contained in:
minjaesong
2026-04-10 20:36:55 +09:00
parent 102801d8b0
commit ca977b074d
6 changed files with 90 additions and 8 deletions

View File

@@ -149,6 +149,16 @@ class GraphicsJSR223Delegate(private val vm: VM) {
}
}
fun plotPixelMode1(x: Int, y: Int, colour: Int, plane: Int) {
getFirstGPU()?.let {
val planesize = it.config.width * it.config.height / 4
if (x in 0 until it.config.width/2 && y in 0 until it.config.height/2) {
it.poke(y.toLong() * it.config.width/2 + x + planesize * plane, colour.toByte())
it.applyDelay()
}
}
}
/**
* Sets absolute position of scrolling
*/

View File

@@ -624,6 +624,8 @@ class VM(
return null
}
private val zeroBlock = ByteArray(MALLOC_UNIT)
internal fun malloc(size: Int): Int {
if (size <= 0) throw IllegalArgumentException("Invalid malloc size: $size")
@@ -635,6 +637,22 @@ class VM(
return blockStart * MALLOC_UNIT
}
internal fun calloc(size: Int): Int {
if (size <= 0) throw IllegalArgumentException("Invalid malloc size: $size")
val allocBlocks = ceil(size.toDouble() / MALLOC_UNIT).toInt()
val blockStart = findEmptySpace(allocBlocks) ?: throw OutOfMemoryError("No space for $allocBlocks blocks ($size bytes requested)")
allocatedBlockCount += allocBlocks
mallocSizes[blockStart] = allocBlocks
for (i in 0 until allocBlocks) {
UnsafeHelper.memcpyRaw(zeroBlock, UnsafeHelper.getArrayOffset(zeroBlock), null, usermem.ptr + (blockStart + i) * MALLOC_UNIT, MALLOC_UNIT.toLong())
}
return blockStart * MALLOC_UNIT
}
internal fun free(ptr: Int) {
val index = ptr / MALLOC_UNIT
val count = mallocSizes[index] ?: throw OutOfMemoryError("No allocation for pointer 0x${ptr.toHex()}")

View File

@@ -109,6 +109,7 @@ class VMJSR223Delegate(private val vm: VM) {
fun nanoTime() = System.nanoTime()
fun malloc(size: Int) = vm.malloc(size)
fun calloc(size: Int) = vm.calloc(size)
fun memset(dest: Int, ch: Int, count: Int) = vm.memset(dest, ch, count)
fun free(ptr: Int) = vm.free(ptr)
fun forceAlloc(ptr: Int, size: Int) = vm.forceAlloc(ptr, size)