mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-13 14:36:06 +09:00
add:uptime and currentTimeInMills for JS sys class
This commit is contained in:
@@ -54,7 +54,8 @@ import kotlin.random.Random
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class VM(
|
class VM(
|
||||||
_memsize: Long
|
_memsize: Long,
|
||||||
|
val worldInterface: WorldInterface
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val id = java.util.Random().nextInt()
|
val id = java.util.Random().nextInt()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.io.FileReader
|
|||||||
|
|
||||||
class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter() {
|
class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter() {
|
||||||
|
|
||||||
val vm = VM(64.kB())
|
val vm = VM(64.kB(), TheRealWorld())
|
||||||
lateinit var gpu: GraphicsAdapter
|
lateinit var gpu: GraphicsAdapter
|
||||||
|
|
||||||
lateinit var batch: SpriteBatch
|
lateinit var batch: SpriteBatch
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.tsvm
|
package net.torvald.tsvm
|
||||||
|
|
||||||
import net.torvald.tsvm.peripheral.GraphicsAdapter
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUlong
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass the instance of the class to the ScriptEngine's binding, preferably under the namespace of "vm"
|
* Pass the instance of the class to the ScriptEngine's binding, preferably under the namespace of "vm"
|
||||||
@@ -13,6 +13,23 @@ class VMJSR223Delegate(val vm: VM) {
|
|||||||
fun malloc(size: Int) = vm.malloc(size)
|
fun malloc(size: Int) = vm.malloc(size)
|
||||||
fun free(ptr: Int) = vm.free(ptr)
|
fun free(ptr: Int) = vm.free(ptr)
|
||||||
|
|
||||||
|
fun uptime(): Long {
|
||||||
|
vm.poke(-69, -1)
|
||||||
|
var r = 0L
|
||||||
|
for (i in 0L..7L) {
|
||||||
|
r = r or vm.peek(-73 - i)!!.toUlong().shl(8 * i.toInt())
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
fun currentTimeInMills(): Long {
|
||||||
|
vm.poke(-69, -1)
|
||||||
|
var r = 0L
|
||||||
|
for (i in 0L..7L) {
|
||||||
|
r = r or vm.peek(-81 - i)!!.toUlong().shl(8 * i.toInt())
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
fun print(s: String) {
|
fun print(s: String) {
|
||||||
//System.out.print("[Nashorn] $s")
|
//System.out.print("[Nashorn] $s")
|
||||||
vm.getPrintStream().write(s.toByteArray())
|
vm.getPrintStream().write(s.toByteArray())
|
||||||
|
|||||||
12
src/net/torvald/tsvm/WorldInterface.kt
Normal file
12
src/net/torvald/tsvm/WorldInterface.kt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package net.torvald.tsvm
|
||||||
|
|
||||||
|
interface WorldInterface {
|
||||||
|
fun currentTimeInMills(): Long
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Real world interface for non-ingame testing. For the Ingame, implement your own.
|
||||||
|
*/
|
||||||
|
class TheRealWorld : WorldInterface {
|
||||||
|
override fun currentTimeInMills(): Long = System.currentTimeMillis()
|
||||||
|
}
|
||||||
@@ -209,7 +209,7 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
|
|||||||
|
|
||||||
if (RTClatched) {
|
if (RTClatched) {
|
||||||
RTClatched = false
|
RTClatched = false
|
||||||
rtc = System.currentTimeMillis()
|
rtc = vm.worldInterface.currentTimeInMills()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user