mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
new iteration of the ingame computer -- display adapter
This commit is contained in:
BIN
assets/mods/dwarventech/gui/8025_textonly.png
Normal file
BIN
assets/mods/dwarventech/gui/8025_textonly.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.3 KiB |
BIN
assets/mods/dwarventech/gui/lcd.tga
LFS
Normal file
BIN
assets/mods/dwarventech/gui/lcd.tga
LFS
Normal file
Binary file not shown.
BIN
assets/mods/dwarventech/gui/led_green.tga
LFS
Normal file
BIN
assets/mods/dwarventech/gui/led_green.tga
LFS
Normal file
Binary file not shown.
BIN
assets/mods/dwarventech/gui/led_orange.tga
LFS
Normal file
BIN
assets/mods/dwarventech/gui/led_orange.tga
LFS
Normal file
Binary file not shown.
@@ -30,6 +30,8 @@ object UnsafeHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun memcpy(srcAddress: Long, destAddress: Long, copyLength: Long) = unsafe.copyMemory(srcAddress, destAddress, copyLength)
|
fun memcpy(srcAddress: Long, destAddress: Long, copyLength: Long) = unsafe.copyMemory(srcAddress, destAddress, copyLength)
|
||||||
|
|
||||||
|
fun memcpyRaw(srcObj: Any?, srcPos: Long, destObj: Any?, destPos: Long, len: Long) = unsafe.copyMemory(srcObj, srcPos, destObj, destPos, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New plan: screw teletype and gui; only the simple 80*24 (size may mary) dumb terminal
|
||||||
|
*
|
||||||
|
* Created by minjaesong on 2019-07-09.
|
||||||
|
*/
|
||||||
|
class LuaComputerVM {
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
|
||||||
|
|
||||||
|
import net.torvald.UnsafeHelper
|
||||||
|
import net.torvald.terrarum.gameworld.fmod
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only one kind of display adapter should exist in the game: they add nothing to the game and the game
|
||||||
|
* shouldn't put much emphasis on computers anyway.
|
||||||
|
*
|
||||||
|
* The actual draw code must not exist in this class!
|
||||||
|
*
|
||||||
|
* Created by minjaesong on 2019-07-09.
|
||||||
|
*/
|
||||||
|
class MDA(val width: Int, val height: Int) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (width % 2 == 1) throw IllegalArgumentException("Display width must be an even number (width = $width)")
|
||||||
|
}
|
||||||
|
|
||||||
|
private val glyphs = UnsafeHelper.allocate(width.toLong() * height)
|
||||||
|
private val attributes = UnsafeHelper.allocate(width.toLong() * height)
|
||||||
|
|
||||||
|
var cursor = 0
|
||||||
|
private set
|
||||||
|
var background = 0
|
||||||
|
var foreground = 1
|
||||||
|
var blink = true
|
||||||
|
|
||||||
|
init {
|
||||||
|
glyphs.fillWith(0)
|
||||||
|
attributes.fillWith(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Attibutes memory map:
|
||||||
|
|
||||||
|
for every byte:
|
||||||
|
|
||||||
|
(msb) 0000 bbff (lsb)
|
||||||
|
|
||||||
|
where:
|
||||||
|
|
||||||
|
bb: background colour
|
||||||
|
ff: foreground colour
|
||||||
|
|
||||||
|
Colours:
|
||||||
|
|
||||||
|
0: black
|
||||||
|
1: light grey
|
||||||
|
2: dark grey
|
||||||
|
3: white
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
private fun wrapAround(x: Int, y: Int) = (x fmod width) to (y fmod height)
|
||||||
|
private fun toAddress(x: Int, y: Int) = (y * width + x).toLong()
|
||||||
|
inline private fun Pair<Int, Int>.toAddress() = toAddress(this.first, this.second)
|
||||||
|
|
||||||
|
fun rawGet(offset: Int) = glyphs[offset.toLong()] to attributes[offset.toLong()]
|
||||||
|
|
||||||
|
fun get(x: Int, y: Int): Pair<Byte, Byte> {
|
||||||
|
val a = wrapAround(x, y).toAddress()
|
||||||
|
return glyphs[a] to attributes[a]
|
||||||
|
}
|
||||||
|
|
||||||
|
fun set(x: Int, y: Int, glyph: Byte, attribute: Byte) {
|
||||||
|
val a = wrapAround(x, y).toAddress()
|
||||||
|
glyphs[a] = glyph
|
||||||
|
attributes[a] = attribute
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setCursor(x: Int, y: Int) {
|
||||||
|
cursor = wrapAround(x, y).toAddress().toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun setText(x: Int, y: Int, text: ByteArray, attirbute: ByteArray) {
|
||||||
|
UnsafeHelper.memcpyRaw(text, 0, null, glyphs.ptr + wrapAround(x, y).toAddress(), text.size.toLong())
|
||||||
|
UnsafeHelper.memcpyRaw(attirbute, 0, null, attributes.ptr + wrapAround(x, y).toAddress(), text.size.toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setText(x: Int, y: Int, text: ByteArray, attribute: Byte) {
|
||||||
|
setText(x, y, text)
|
||||||
|
val a = wrapAround(x, y).toAddress()
|
||||||
|
for (i in 0 until text.size) {
|
||||||
|
attributes[a + i] = attribute
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setText(x: Int, y: Int, text: ByteArray) {
|
||||||
|
setText(x, y, text, (background.shl(0b11) or foreground).toByte())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun dispose() {
|
||||||
|
glyphs.destroy()
|
||||||
|
attributes.destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
|
||||||
|
|
||||||
|
import net.torvald.terrarum.KVHashMap
|
||||||
|
import net.torvald.terrarum.Second
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
|
import net.torvald.terrarum.ceilInt
|
||||||
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VDUtil
|
||||||
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VirtualDisk
|
||||||
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject.ComputerPartsCodex
|
||||||
import org.luaj.vm2.Globals
|
import org.luaj.vm2.Globals
|
||||||
import org.luaj.vm2.LuaError
|
import org.luaj.vm2.LuaError
|
||||||
import org.luaj.vm2.LuaTable
|
import org.luaj.vm2.LuaTable
|
||||||
@@ -7,13 +14,6 @@ import org.luaj.vm2.LuaValue
|
|||||||
import org.luaj.vm2.lib.TwoArgFunction
|
import org.luaj.vm2.lib.TwoArgFunction
|
||||||
import org.luaj.vm2.lib.ZeroArgFunction
|
import org.luaj.vm2.lib.ZeroArgFunction
|
||||||
import org.luaj.vm2.lib.jse.JsePlatform
|
import org.luaj.vm2.lib.jse.JsePlatform
|
||||||
import net.torvald.terrarum.KVHashMap
|
|
||||||
import net.torvald.terrarum.Terrarum
|
|
||||||
import net.torvald.terrarum.Second
|
|
||||||
import net.torvald.terrarum.ceilInt
|
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VDUtil
|
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VirtualDisk
|
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject.ComputerPartsCodex
|
|
||||||
import org.lwjgl.BufferUtils
|
import org.lwjgl.BufferUtils
|
||||||
import org.lwjgl.openal.AL10
|
import org.lwjgl.openal.AL10
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@@ -30,7 +30,7 @@ import kotlin.collections.HashMap
|
|||||||
* @param term : terminal that is connected to the computer fixtures, null if not connected any.
|
* @param term : terminal that is connected to the computer fixtures, null if not connected any.
|
||||||
* Created by minjaesong on 2016-09-10.
|
* Created by minjaesong on 2016-09-10.
|
||||||
*/
|
*/
|
||||||
class TerrarumComputer(peripheralSlots: Int) {
|
class TerrarumComputerOldOld(peripheralSlots: Int) {
|
||||||
|
|
||||||
val DEBUG_UNLIMITED_MEM = false
|
val DEBUG_UNLIMITED_MEM = false
|
||||||
val DEBUG = true
|
val DEBUG = true
|
||||||
@@ -161,7 +161,7 @@ class TerrarumComputer(peripheralSlots: Int) {
|
|||||||
if (peripheralTable[slot] == null) {
|
if (peripheralTable[slot] == null) {
|
||||||
peripheralTable[slot] = peri
|
peripheralTable[slot] = peri
|
||||||
peri.loadLib(luaJ_globals)
|
peri.loadLib(luaJ_globals)
|
||||||
println("[TerrarumComputer] loading peripheral $peri")
|
println("[TerrarumComputerOld] loading peripheral $peri")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw RuntimeException("Peripheral slot is already taken by: ${peripheralTable[slot]?.tableName}")
|
throw RuntimeException("Peripheral slot is already taken by: ${peripheralTable[slot]?.tableName}")
|
||||||
@@ -179,7 +179,7 @@ class TerrarumComputer(peripheralSlots: Int) {
|
|||||||
}
|
}
|
||||||
if (found >= 0) {
|
if (found >= 0) {
|
||||||
peripheralTable[found] = null
|
peripheralTable[found] = null
|
||||||
println("[TerrarumComputer] unloading peripheral $peri")
|
println("[TerrarumComputerOld] unloading peripheral $peri")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw IllegalArgumentException("Peripheral not exists: $peri")
|
throw IllegalArgumentException("Peripheral not exists: $peri")
|
||||||
@@ -383,13 +383,13 @@ class TerrarumComputer(peripheralSlots: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LuaFunGetTotalMem(val computer: TerrarumComputer) : ZeroArgFunction() {
|
class LuaFunGetTotalMem(val computer: TerrarumComputerOldOld) : ZeroArgFunction() {
|
||||||
override fun call(): LuaValue {
|
override fun call(): LuaValue {
|
||||||
return LuaValue.valueOf(computer.memSize)
|
return LuaValue.valueOf(computer.memSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ComputerEmitTone(val computer: TerrarumComputer) : TwoArgFunction() {
|
class ComputerEmitTone(val computer: TerrarumComputerOldOld) : TwoArgFunction() {
|
||||||
override fun call(millisec: LuaValue, freq: LuaValue): LuaValue {
|
override fun call(millisec: LuaValue, freq: LuaValue): LuaValue {
|
||||||
computer.playTone(millisec.checkdouble().toFloat(), freq.checkdouble())
|
computer.playTone(millisec.checkdouble().toFloat(), freq.checkdouble())
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
@@ -447,7 +447,7 @@ class TerrarumComputer(peripheralSlots: Int) {
|
|||||||
|
|
||||||
//AL.destroy()
|
//AL.destroy()
|
||||||
|
|
||||||
if (DEBUG) println("[TerrarumComputer] !! Beep queue clear")
|
if (DEBUG) println("[TerrarumComputerOld] !! Beep queue clear")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun enqueueBeep(duration: Double, freq: Double) {
|
fun enqueueBeep(duration: Double, freq: Double) {
|
||||||
@@ -5,7 +5,7 @@ import org.luaj.vm2.lib.OneArgFunction
|
|||||||
import org.luaj.vm2.lib.TwoArgFunction
|
import org.luaj.vm2.lib.TwoArgFunction
|
||||||
import org.luaj.vm2.lib.ZeroArgFunction
|
import org.luaj.vm2.lib.ZeroArgFunction
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Term.Companion.checkIBM437
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Term.Companion.checkIBM437
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
@@ -27,7 +27,7 @@ import java.util.*
|
|||||||
* Use .absoluteFile whenever possible; there's fuckin oddity! (http://bugs.java.com/bugdatabase/view_bug.do;:YfiG?bug_id=4483097)
|
* Use .absoluteFile whenever possible; there's fuckin oddity! (http://bugs.java.com/bugdatabase/view_bug.do;:YfiG?bug_id=4483097)
|
||||||
*/
|
*/
|
||||||
@Deprecated("Fuck permission and shit, we go virtual. Use FilesystemTar")
|
@Deprecated("Fuck permission and shit, we go virtual. Use FilesystemTar")
|
||||||
internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) {
|
internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// load things. WARNING: THIS IS MANUAL!
|
// load things. WARNING: THIS IS MANUAL!
|
||||||
@@ -102,7 +102,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
/** actual directory: <appdata>/Saves/<savename>/computers/<drivename>/
|
/** actual directory: <appdata>/Saves/<savename>/computers/<drivename>/
|
||||||
* directs media/ directory to /<uuid> directory
|
* directs media/ directory to /<uuid> directory
|
||||||
*/
|
*/
|
||||||
fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer.getRealPath(luapath: LuaValue) : String {
|
fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld.getRealPath(luapath: LuaValue) : String {
|
||||||
// direct mounted paths to real path
|
// direct mounted paths to real path
|
||||||
val computerDir = Terrarum.currentSaveDir.absolutePath + "/computers/"
|
val computerDir = Terrarum.currentSaveDir.absolutePath + "/computers/"
|
||||||
/* if not begins with "(/?)media/", direct to boot
|
/* if not begins with "(/?)media/", direct to boot
|
||||||
@@ -147,7 +147,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
*
|
*
|
||||||
* actual directory: <appdata>/Saves/<savename>/computers/<drivename>/
|
* actual directory: <appdata>/Saves/<savename>/computers/<drivename>/
|
||||||
*/
|
*/
|
||||||
class ListFiles(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class ListFiles(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Don't use this. Use isFile */
|
/** Don't use this. Use isFile */
|
||||||
class FileExists(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class FileExists(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IsDirectory(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class IsDirectory(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IsFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class IsFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IsReadOnly(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class IsReadOnly(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** we have 4GB file size limit */
|
/** we have 4GB file size limit */
|
||||||
class GetSize(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class GetSize(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
/**
|
/**
|
||||||
* difference with ComputerCraft: it returns boolean, true on successful.
|
* difference with ComputerCraft: it returns boolean, true on successful.
|
||||||
*/
|
*/
|
||||||
class Mkdir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class Mkdir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -240,7 +240,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
/**
|
/**
|
||||||
* moves a directory, overwrites the target
|
* moves a directory, overwrites the target
|
||||||
*/
|
*/
|
||||||
class Mv(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : TwoArgFunction() {
|
class Mv(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
|
||||||
override fun call(from: LuaValue, to: LuaValue) : LuaValue {
|
override fun call(from: LuaValue, to: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(from)
|
FilesystemDir.ensurePathSanity(from)
|
||||||
FilesystemDir.ensurePathSanity(to)
|
FilesystemDir.ensurePathSanity(to)
|
||||||
@@ -259,7 +259,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
* copies a directory, overwrites the target
|
* copies a directory, overwrites the target
|
||||||
* difference with ComputerCraft: it returns boolean, true on successful.
|
* difference with ComputerCraft: it returns boolean, true on successful.
|
||||||
*/
|
*/
|
||||||
class Cp(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : TwoArgFunction() {
|
class Cp(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
|
||||||
override fun call(from: LuaValue, to: LuaValue) : LuaValue {
|
override fun call(from: LuaValue, to: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(from)
|
FilesystemDir.ensurePathSanity(from)
|
||||||
FilesystemDir.ensurePathSanity(to)
|
FilesystemDir.ensurePathSanity(to)
|
||||||
@@ -275,7 +275,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
/**
|
/**
|
||||||
* difference with ComputerCraft: it returns boolean, true on successful.
|
* difference with ComputerCraft: it returns boolean, true on successful.
|
||||||
*/
|
*/
|
||||||
class Rm(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class Rm(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConcatPath(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : TwoArgFunction() {
|
class ConcatPath(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
|
||||||
override fun call(base: LuaValue, local: LuaValue) : LuaValue {
|
override fun call(base: LuaValue, local: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(base)
|
FilesystemDir.ensurePathSanity(base)
|
||||||
FilesystemDir.ensurePathSanity(local)
|
FilesystemDir.ensurePathSanity(local)
|
||||||
@@ -321,7 +321,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
* writeBytes = function(string as bytearray)
|
* writeBytes = function(string as bytearray)
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
class OpenFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : TwoArgFunction() {
|
class OpenFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
|
||||||
override fun call(path: LuaValue, mode: LuaValue) : LuaValue {
|
override fun call(path: LuaValue, mode: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -401,7 +401,7 @@ internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.mo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetParentDir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class GetParentDir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
FilesystemDir.ensurePathSanity(path)
|
FilesystemDir.ensurePathSanity(path)
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ import java.util.*
|
|||||||
* Don't convert '\' to '/'! Rev-slash is used for escape character in sh, and we're sh-compatible!
|
* Don't convert '\' to '/'! Rev-slash is used for escape character in sh, and we're sh-compatible!
|
||||||
* Use .absoluteFile whenever possible; there's fuckin oddity! (http://bugs.java.com/bugdatabase/view_bug.do;:YfiG?bug_id=4483097)
|
* Use .absoluteFile whenever possible; there's fuckin oddity! (http://bugs.java.com/bugdatabase/view_bug.do;:YfiG?bug_id=4483097)
|
||||||
*/
|
*/
|
||||||
internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) {
|
internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
|
||||||
|
|
||||||
/*init {
|
/*init {
|
||||||
// load things. WARNING: THIS IS MANUAL!
|
// load things. WARNING: THIS IS MANUAL!
|
||||||
@@ -83,7 +83,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
* computer.diskRack[SOMEUUID]->subpath
|
* computer.diskRack[SOMEUUID]->subpath
|
||||||
* else, computer.diskRack["hda"]->subpath
|
* else, computer.diskRack["hda"]->subpath
|
||||||
*/
|
*/
|
||||||
fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer.getFile(path: VDPath) : DiskEntry? {
|
fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld.getFile(path: VDPath) : DiskEntry? {
|
||||||
val disk = this.getTargetDisk(path)
|
val disk = this.getTargetDisk(path)
|
||||||
|
|
||||||
if (disk == null) return null
|
if (disk == null) return null
|
||||||
@@ -98,7 +98,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
* computer.diskRack["fd1"]
|
* computer.diskRack["fd1"]
|
||||||
* else, computer.diskRack[<boot device>]
|
* else, computer.diskRack[<boot device>]
|
||||||
*/
|
*/
|
||||||
fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer.getTargetDisk(path: VDPath) : VirtualDisk? {
|
fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld.getTargetDisk(path: VDPath) : VirtualDisk? {
|
||||||
if (path.hierarchy.size >= 2 &&
|
if (path.hierarchy.size >= 2 &&
|
||||||
Arrays.equals(path[0], "media".toEntryName(DiskEntry.NAME_LENGTH, sysCharset))) {
|
Arrays.equals(path[0], "media".toEntryName(DiskEntry.NAME_LENGTH, sysCharset))) {
|
||||||
val diskName = path[1].toCanonicalString(sysCharset)
|
val diskName = path[1].toCanonicalString(sysCharset)
|
||||||
@@ -111,7 +111,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer.getDirectoryEntries(path: VDPath) : Array<DiskEntry>? {
|
fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld.getDirectoryEntries(path: VDPath) : Array<DiskEntry>? {
|
||||||
val directory = this.getFile(path)
|
val directory = this.getFile(path)
|
||||||
|
|
||||||
if (directory == null) return null
|
if (directory == null) return null
|
||||||
@@ -140,7 +140,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
*
|
*
|
||||||
* actual directory: <appdata>/Saves/<savename>/computers/<drivename>/
|
* actual directory: <appdata>/Saves/<savename>/computers/<drivename>/
|
||||||
*/
|
*/
|
||||||
class ListFiles(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class ListFiles(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
val path = VDPath(path.checkPath(), sysCharset)
|
val path = VDPath(path.checkPath(), sysCharset)
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileExists(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class FileExists(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
val path = VDPath(path.checkPath(), sysCharset)
|
val path = VDPath(path.checkPath(), sysCharset)
|
||||||
val disk = computer.getTargetDisk(path)
|
val disk = computer.getTargetDisk(path)
|
||||||
@@ -170,28 +170,28 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IsDirectory(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class IsDirectory(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
val path = VDPath(path.checkPath(), sysCharset)
|
val path = VDPath(path.checkPath(), sysCharset)
|
||||||
return LuaValue.valueOf(computer.getFile(path)?.contents is EntryDirectory)
|
return LuaValue.valueOf(computer.getFile(path)?.contents is EntryDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IsFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class IsFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
val path = VDPath(path.checkPath(), sysCharset)
|
val path = VDPath(path.checkPath(), sysCharset)
|
||||||
return LuaValue.valueOf(computer.getFile(path)?.contents is EntryFile)
|
return LuaValue.valueOf(computer.getFile(path)?.contents is EntryFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IsReadOnly(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class IsReadOnly(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
return LuaValue.valueOf(false)
|
return LuaValue.valueOf(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** we have 2 GB file size limit */
|
/** we have 2 GB file size limit */
|
||||||
class GetSize(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class GetSize(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
val path = VDUtil.VDPath(path.checkPath(), sysCharset)
|
val path = VDUtil.VDPath(path.checkPath(), sysCharset)
|
||||||
val file = computer.getFile(path)
|
val file = computer.getFile(path)
|
||||||
@@ -213,7 +213,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
/**
|
/**
|
||||||
* returns true on success
|
* returns true on success
|
||||||
*/
|
*/
|
||||||
class Mkdir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class Mkdir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
return tryBool {
|
return tryBool {
|
||||||
val path = VDPath(path.checkPath(), sysCharset)
|
val path = VDPath(path.checkPath(), sysCharset)
|
||||||
@@ -241,7 +241,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
/**
|
/**
|
||||||
* moves a directory, overwrites the target
|
* moves a directory, overwrites the target
|
||||||
*/
|
*/
|
||||||
class Mv(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : TwoArgFunction() {
|
class Mv(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
|
||||||
override fun call(from: LuaValue, to: LuaValue) : LuaValue {
|
override fun call(from: LuaValue, to: LuaValue) : LuaValue {
|
||||||
return tryBool {
|
return tryBool {
|
||||||
val pathFrom = VDPath(from.checkPath(), sysCharset)
|
val pathFrom = VDPath(from.checkPath(), sysCharset)
|
||||||
@@ -258,7 +258,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
* copies a directory, overwrites the target
|
* copies a directory, overwrites the target
|
||||||
* difference with ComputerCraft: it returns boolean, true on successful.
|
* difference with ComputerCraft: it returns boolean, true on successful.
|
||||||
*/
|
*/
|
||||||
class Cp(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : TwoArgFunction() {
|
class Cp(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
|
||||||
override fun call(from: LuaValue, to: LuaValue) : LuaValue {
|
override fun call(from: LuaValue, to: LuaValue) : LuaValue {
|
||||||
return tryBool {
|
return tryBool {
|
||||||
val pathFrom = VDPath(from.checkPath(), sysCharset)
|
val pathFrom = VDPath(from.checkPath(), sysCharset)
|
||||||
@@ -293,7 +293,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
/**
|
/**
|
||||||
* difference with ComputerCraft: it returns boolean, true on successful.
|
* difference with ComputerCraft: it returns boolean, true on successful.
|
||||||
*/
|
*/
|
||||||
class Rm(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class Rm(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
return tryBool {
|
return tryBool {
|
||||||
val path = VDPath(path.checkPath(), sysCharset)
|
val path = VDPath(path.checkPath(), sysCharset)
|
||||||
@@ -304,7 +304,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConcatPath(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : TwoArgFunction() {
|
class ConcatPath(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
|
||||||
override fun call(base: LuaValue, local: LuaValue) : LuaValue {
|
override fun call(base: LuaValue, local: LuaValue) : LuaValue {
|
||||||
TODO()
|
TODO()
|
||||||
}
|
}
|
||||||
@@ -336,7 +336,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
* writeBytes = function(string as bytearray)
|
* writeBytes = function(string as bytearray)
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
class OpenFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : TwoArgFunction() {
|
class OpenFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
|
||||||
override fun call(path: LuaValue, mode: LuaValue) : LuaValue {
|
override fun call(path: LuaValue, mode: LuaValue) : LuaValue {
|
||||||
val path = VDPath(path.checkPath(), sysCharset)
|
val path = VDPath(path.checkPath(), sysCharset)
|
||||||
val disk = computer.getTargetDisk(path)!!
|
val disk = computer.getTargetDisk(path)!!
|
||||||
@@ -421,7 +421,7 @@ internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetParentDir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class GetParentDir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(path: LuaValue) : LuaValue {
|
override fun call(path: LuaValue) : LuaValue {
|
||||||
val path = VDPath(path.checkPath(), sysCharset).getParent()
|
val path = VDPath(path.checkPath(), sysCharset).getParent()
|
||||||
return LuaValue.valueOf(path.toString())
|
return LuaValue.valueOf(path.toString())
|
||||||
@@ -3,7 +3,7 @@ package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
|
|||||||
import net.torvald.terrarum.gameactors.ai.toLua
|
import net.torvald.terrarum.gameactors.ai.toLua
|
||||||
import org.luaj.vm2.lib.OneArgFunction
|
import org.luaj.vm2.lib.OneArgFunction
|
||||||
import org.luaj.vm2.lib.ZeroArgFunction
|
import org.luaj.vm2.lib.ZeroArgFunction
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Term.Companion.checkIBM437
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Term.Companion.checkIBM437
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype
|
||||||
import org.luaj.vm2.*
|
import org.luaj.vm2.*
|
||||||
@@ -15,7 +15,7 @@ import org.luaj.vm2.*
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2016-09-19.
|
* Created by minjaesong on 2016-09-19.
|
||||||
*/
|
*/
|
||||||
internal class HostAccessProvider(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) {
|
internal class HostAccessProvider(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
globals["machine"] = LuaTable()
|
globals["machine"] = LuaTable()
|
||||||
@@ -42,19 +42,19 @@ internal class HostAccessProvider(globals: Globals, computer: net.torvald.terrar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IsHalted(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer): ZeroArgFunction() {
|
class IsHalted(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld): ZeroArgFunction() {
|
||||||
override fun call(): LuaValue {
|
override fun call(): LuaValue {
|
||||||
return LuaValue.valueOf(computer.isHalted)
|
return LuaValue.valueOf(computer.isHalted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NativeReadStdin(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : ZeroArgFunction() {
|
class NativeReadStdin(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : ZeroArgFunction() {
|
||||||
override fun call(): LuaValue {
|
override fun call(): LuaValue {
|
||||||
return computer.stdin!!.read().toLua()
|
return computer.stdin!!.read().toLua()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HaltComputer(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : ZeroArgFunction() {
|
class HaltComputer(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : ZeroArgFunction() {
|
||||||
override fun call() : LuaValue {
|
override fun call() : LuaValue {
|
||||||
computer.isHalted = true
|
computer.isHalted = true
|
||||||
computer.luaJ_globals.load("""print(DC4.."system halted")""").call()
|
computer.luaJ_globals.load("""print(DC4.."system halted")""").call()
|
||||||
@@ -63,13 +63,13 @@ internal class HostAccessProvider(globals: Globals, computer: net.torvald.terrar
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Time elapsed since the power is on. */
|
/** Time elapsed since the power is on. */
|
||||||
class NativeGetMilliTime(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : ZeroArgFunction() {
|
class NativeGetMilliTime(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : ZeroArgFunction() {
|
||||||
override fun call(): LuaValue {
|
override fun call(): LuaValue {
|
||||||
return LuaValue.valueOf(computer.milliTime)
|
return LuaValue.valueOf(computer.milliTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NativeThreadSleep(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OneArgFunction() {
|
class NativeThreadSleep(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
|
||||||
override fun call(mills: LuaValue): LuaValue {
|
override fun call(mills: LuaValue): LuaValue {
|
||||||
computer.currentExecutionThread.join(mills.checklong())
|
computer.currentExecutionThread.join(mills.checklong())
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
@@ -5,12 +5,12 @@ import org.luaj.vm2.Globals
|
|||||||
import org.luaj.vm2.LuaTable
|
import org.luaj.vm2.LuaTable
|
||||||
import org.luaj.vm2.LuaValue
|
import org.luaj.vm2.LuaValue
|
||||||
import org.luaj.vm2.lib.OneArgFunction
|
import org.luaj.vm2.lib.OneArgFunction
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-09-25.
|
* Created by minjaesong on 2016-09-25.
|
||||||
*/
|
*/
|
||||||
class Input(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) {
|
class Input(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ import org.luaj.vm2.LuaTable
|
|||||||
import org.luaj.vm2.LuaValue
|
import org.luaj.vm2.LuaValue
|
||||||
import org.luaj.vm2.lib.TwoArgFunction
|
import org.luaj.vm2.lib.TwoArgFunction
|
||||||
import org.luaj.vm2.lib.ZeroArgFunction
|
import org.luaj.vm2.lib.ZeroArgFunction
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
|
||||||
import org.luaj.vm2.LuaFunction
|
import org.luaj.vm2.LuaFunction
|
||||||
import org.luaj.vm2.lib.OneArgFunction
|
import org.luaj.vm2.lib.OneArgFunction
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ import org.luaj.vm2.lib.OneArgFunction
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2016-09-27.
|
* Created by minjaesong on 2016-09-27.
|
||||||
*/
|
*/
|
||||||
class PcSpeakerDriver(val globals: Globals, host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) {
|
class PcSpeakerDriver(val globals: Globals, host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
globals["speaker"] = LuaTable()
|
globals["speaker"] = LuaTable()
|
||||||
@@ -67,7 +67,7 @@ class PcSpeakerDriver(val globals: Globals, host: net.torvald.terrarum.modulecom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EnqueueTone(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : TwoArgFunction() {
|
class EnqueueTone(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
|
||||||
/**
|
/**
|
||||||
* @param freq: number (hertz) or string (A-4, A4, B#2, ...)
|
* @param freq: number (hertz) or string (A-4, A4, B#2, ...)
|
||||||
*/
|
*/
|
||||||
@@ -84,7 +84,7 @@ class PcSpeakerDriver(val globals: Globals, host: net.torvald.terrarum.modulecom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ClearQueue(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : ZeroArgFunction() {
|
class ClearQueue(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : ZeroArgFunction() {
|
||||||
override fun call(): LuaValue {
|
override fun call(): LuaValue {
|
||||||
host.clearBeepQueue()
|
host.clearBeepQueue()
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
|
||||||
|
|
||||||
import org.luaj.vm2.Globals
|
import org.luaj.vm2.Globals
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
|
||||||
import org.luaj.vm2.LuaTable
|
import org.luaj.vm2.LuaTable
|
||||||
import org.luaj.vm2.LuaValue
|
import org.luaj.vm2.LuaValue
|
||||||
import org.luaj.vm2.lib.OneArgFunction
|
import org.luaj.vm2.lib.OneArgFunction
|
||||||
@@ -14,7 +14,7 @@ import java.net.URL
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2016-09-24.
|
* Created by minjaesong on 2016-09-24.
|
||||||
*/
|
*/
|
||||||
internal class PeripheralInternet(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer)
|
internal class PeripheralInternet(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld)
|
||||||
: net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral("internet"){
|
: net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral("internet"){
|
||||||
|
|
||||||
override val memSize = 1024
|
override val memSize = 1024
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
|
||||||
|
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
|
||||||
import org.luaj.vm2.Globals
|
import org.luaj.vm2.Globals
|
||||||
import org.luaj.vm2.LuaTable
|
import org.luaj.vm2.LuaTable
|
||||||
import org.luaj.vm2.LuaValue
|
import org.luaj.vm2.LuaValue
|
||||||
@@ -11,7 +11,7 @@ import org.luaj.vm2.LuaValue
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2016-09-27.
|
* Created by minjaesong on 2016-09-27.
|
||||||
*/
|
*/
|
||||||
internal class PeripheralPSG(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer)
|
internal class PeripheralPSG(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld)
|
||||||
: net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral("psg") {
|
: net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral("psg") {
|
||||||
|
|
||||||
override val memSize = 1024
|
override val memSize = 1024
|
||||||
@@ -8,7 +8,7 @@ import org.luaj.vm2.lib.*
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2017-02-08.
|
* Created by minjaesong on 2017-02-08.
|
||||||
*/
|
*/
|
||||||
/*class PeripheralVideoCard(val host: TerrarumComputer, val termW: Int = 80, val termH: Int = 25) :
|
/*class PeripheralVideoCard(val host: TerrarumComputerOld, val termW: Int = 80, val termH: Int = 25) :
|
||||||
Peripheral("ppu") {
|
Peripheral("ppu") {
|
||||||
companion object {
|
companion object {
|
||||||
val blockW = 8 // MUST BE 8
|
val blockW = 8 // MUST BE 8
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.standalone
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Game
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
|
||||||
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
|
||||||
|
import com.badlogic.gdx.graphics.Color
|
||||||
|
import com.badlogic.gdx.graphics.Texture
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.MDA
|
||||||
|
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2019-07-09.
|
||||||
|
*/
|
||||||
|
class StandaloneApp : Game() {
|
||||||
|
|
||||||
|
lateinit var font: TextureRegionPack
|
||||||
|
|
||||||
|
lateinit var background: Texture
|
||||||
|
lateinit var execLed: Texture
|
||||||
|
lateinit var waitLed: Texture
|
||||||
|
|
||||||
|
lateinit var batch: SpriteBatch
|
||||||
|
|
||||||
|
lateinit var vmThread: Thread
|
||||||
|
|
||||||
|
val display = MDA(80, 25)
|
||||||
|
|
||||||
|
override fun create() {
|
||||||
|
font = TextureRegionPack(Gdx.files.internal("assets/mods/dwarventech/gui/lcd.tga"), 12, 16)
|
||||||
|
|
||||||
|
background = Texture(Gdx.files.internal("assets/mods/dwarventech/gui/8025_textonly.png"))
|
||||||
|
execLed = Texture(Gdx.files.internal("assets/mods/dwarventech/gui/led_green.tga"))
|
||||||
|
waitLed = Texture(Gdx.files.internal("assets/mods/dwarventech/gui/led_orange.tga"))
|
||||||
|
|
||||||
|
batch = SpriteBatch()
|
||||||
|
|
||||||
|
//Gdx.input.inputProcessor = TVMInputProcessor()
|
||||||
|
|
||||||
|
|
||||||
|
//vmThread = Thread(vm)
|
||||||
|
//vmThread.start()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private val height: Int; get() = Gdx.graphics.height
|
||||||
|
|
||||||
|
private val lcdOffX = 74f
|
||||||
|
private val lcdOffY = 56f
|
||||||
|
|
||||||
|
private val lcdCol = arrayOf(
|
||||||
|
Color(0x14141400),
|
||||||
|
Color(0x141414AA),
|
||||||
|
Color(0x14141455),
|
||||||
|
Color(0x141414FF)
|
||||||
|
)
|
||||||
|
|
||||||
|
private var textCursorDrawTimer = 0f // 0f..0.5f: not draw
|
||||||
|
|
||||||
|
override fun render() {
|
||||||
|
Gdx.graphics.setTitle("Terrarum Lua Computer Standalone — F: ${Gdx.graphics.framesPerSecond}")
|
||||||
|
|
||||||
|
batch.inUse {
|
||||||
|
batch.color = Color.WHITE
|
||||||
|
batch.draw(background, 0f, 0f)
|
||||||
|
|
||||||
|
|
||||||
|
// draw the screen
|
||||||
|
textCursorDrawTimer += Gdx.graphics.rawDeltaTime
|
||||||
|
if (textCursorDrawTimer > 1f) textCursorDrawTimer -= 1f
|
||||||
|
val cursorX = display.cursor % display.width
|
||||||
|
val cursorY = display.cursor / display.height
|
||||||
|
|
||||||
|
for (i in 0 until display.width * display.height) {
|
||||||
|
val drawX = ((i % display.width) * font.tileW).toFloat()
|
||||||
|
val drawY = ((i / display.width) * font.tileH).toFloat()
|
||||||
|
val (g, a) = display.rawGet(i)
|
||||||
|
val glyph = g.toUint()
|
||||||
|
val glyphBack = glyph + 256
|
||||||
|
val back = (a.toUint() ushr 0x3) % lcdCol.size
|
||||||
|
val fore = a.toUint() % lcdCol.size
|
||||||
|
|
||||||
|
if (display.blink && i == display.cursor && textCursorDrawTimer >= 0.5f) {
|
||||||
|
batch.color = lcdCol[1]
|
||||||
|
batch.draw(
|
||||||
|
font.get(0, 8),
|
||||||
|
lcdOffX + drawX,
|
||||||
|
(this.height - font.tileH) - (lcdOffY + drawY)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// print background
|
||||||
|
batch.color = lcdCol[back]
|
||||||
|
batch.draw(
|
||||||
|
font.get(glyphBack % font.horizontalCount, glyphBack / font.horizontalCount),
|
||||||
|
lcdOffX + drawX,
|
||||||
|
(this.height - font.tileH) - (lcdOffY + drawY)
|
||||||
|
)
|
||||||
|
// print foreground
|
||||||
|
batch.color = lcdCol[fore]
|
||||||
|
batch.draw(
|
||||||
|
font.get(glyph % font.horizontalCount, glyph / font.horizontalCount),
|
||||||
|
lcdOffX + drawX,
|
||||||
|
(this.height - font.tileH) - (lcdOffY + drawY)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// end of draw the screen
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//vm.resumeExec()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
background.dispose()
|
||||||
|
display.dispose()
|
||||||
|
//vm.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun SpriteBatch.inUse(action: () -> Unit) {
|
||||||
|
this.begin()
|
||||||
|
action.invoke()
|
||||||
|
this.end()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*class TVMInputProcessor(val vm: TerranVM) : InputProcessor {
|
||||||
|
override fun touchUp(p0: Int, p1: Int, p2: Int, p3: Int): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mouseMoved(p0: Int, p1: Int): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun keyTyped(p0: Char): Boolean {
|
||||||
|
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun scrolled(p0: Int): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun keyUp(p0: Int): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun touchDragged(p0: Int, p1: Int, p2: Int): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun keyDown(p0: Int): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun touchDown(p0: Int, p1: Int, p2: Int, p3: Int): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
private fun Byte.toUint() = java.lang.Byte.toUnsignedInt(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val config = LwjglApplicationConfiguration()
|
||||||
|
config.width = 1106
|
||||||
|
config.height = 556
|
||||||
|
config.foregroundFPS = 100
|
||||||
|
config.vSyncEnabled = false
|
||||||
|
config.resizable = false
|
||||||
|
|
||||||
|
LwjglApplication(StandaloneApp(), config)
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2017-02-08.
|
* Created by minjaesong on 2017-02-08.
|
||||||
*/
|
*/
|
||||||
/*class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
/*class GraphicsTerminal(private val host: TerrarumComputerOld) : Terminal {
|
||||||
lateinit var videoCard: PeripheralVideoCard
|
lateinit var videoCard: PeripheralVideoCard
|
||||||
|
|
||||||
override val width: Int; get() = videoCard.termW
|
override val width: Int; get() = videoCard.termW
|
||||||
@@ -7,7 +7,7 @@ package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
|
|||||||
* Created by minjaesong on 2016-09-07.
|
* Created by minjaesong on 2016-09-07.
|
||||||
*/
|
*/
|
||||||
/*open class SimpleTextTerminal(
|
/*open class SimpleTextTerminal(
|
||||||
phosphorColour: Color, override val width: Int, override val height: Int, private val host: TerrarumComputer,
|
phosphorColour: Color, override val width: Int, override val height: Int, private val host: TerrarumComputerOld,
|
||||||
colour: Boolean = false, hires: Boolean = false
|
colour: Boolean = false, hires: Boolean = false
|
||||||
) : Terminal {
|
) : Terminal {
|
||||||
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
|
||||||
|
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-09-10.
|
* Created by minjaesong on 2016-09-10.
|
||||||
*/
|
*/
|
||||||
class TerminalInputStream(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : InputStream() {
|
class TerminalInputStream(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : InputStream() {
|
||||||
|
|
||||||
override fun read(): Int {
|
override fun read(): Int {
|
||||||
//System.err.println(Thread.currentThread().name)
|
//System.err.println(Thread.currentThread().name)
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
|
package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
|
||||||
|
|
||||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer
|
import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-09-10.
|
* Created by minjaesong on 2016-09-10.
|
||||||
*/
|
*/
|
||||||
class TerminalPrintStream(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : PrintStream(TerminalOutputStream(host))
|
class TerminalPrintStream(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : PrintStream(TerminalOutputStream(host))
|
||||||
|
|
||||||
class TerminalOutputStream(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer) : OutputStream() {
|
class TerminalOutputStream(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OutputStream() {
|
||||||
override fun write(b: Int) = host.term.printChar(b.and(0xFF).toChar())
|
override fun write(b: Int) = host.term.printChar(b.and(0xFF).toChar())
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
|
|||||||
*/
|
*/
|
||||||
class FixtureBasicTerminal(phosphor: Color) : FixtureBase(BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1)) {
|
class FixtureBasicTerminal(phosphor: Color) : FixtureBase(BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1)) {
|
||||||
|
|
||||||
/*val computer = TerrarumComputer(8)
|
/*val computer = TerrarumComputerOld(8)
|
||||||
val vt: Terminal = SimpleTextTerminal(phosphor, 80, 25, computer)
|
val vt: Terminal = SimpleTextTerminal(phosphor, 80, 25, computer)
|
||||||
val ui = UITextTerminal(vt)
|
val ui = UITextTerminal(vt)
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ open class FixtureComputerBase : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1,
|
|||||||
/** Connected terminal */
|
/** Connected terminal */
|
||||||
var terminal: FixtureBasicTerminal? = null
|
var terminal: FixtureBasicTerminal? = null
|
||||||
|
|
||||||
var computerInside: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer? = null
|
var computerInside: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// UUID of the "brain"
|
// UUID of the "brain"
|
||||||
@@ -26,7 +26,7 @@ open class FixtureComputerBase : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1,
|
|||||||
|
|
||||||
fun attachTerminal(uuid: String) {
|
fun attachTerminal(uuid: String) {
|
||||||
val fetchedTerminal = getTerminalByUUID(uuid)
|
val fetchedTerminal = getTerminalByUUID(uuid)
|
||||||
computerInside = net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputer(8)
|
computerInside = net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld(8)
|
||||||
computerInside!!.attachTerminal(fetchedTerminal!!)
|
computerInside!!.attachTerminal(fetchedTerminal!!)
|
||||||
actorValue["computerid"] = computerInside!!.UUID
|
actorValue["computerid"] = computerInside!!.UUID
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user