mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
VT: shit is still rolling
- We might need virtual disk image... Former-commit-id: c3278cd9fe1ddad8b26b45577fecb0500365d38b
This commit is contained in:
@@ -5,6 +5,7 @@ import org.luaj.vm2.lib.OneArgFunction
|
||||
import org.luaj.vm2.lib.TwoArgFunction
|
||||
import org.luaj.vm2.lib.ZeroArgFunction
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.toHex
|
||||
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
|
||||
import net.torvald.terrarum.virtualcomputer.luaapi.Term.Companion.checkIBM437
|
||||
import java.io.*
|
||||
@@ -87,7 +88,7 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
// Worst-case: we're on Windows or using a FAT32 partition mounted in *nix.
|
||||
// Note: we allow / as the path separator and expect all \s to be converted
|
||||
// accordingly before the path is passed to the file system.
|
||||
private val invalidChars = Regex("""[\\:*?"<>|]""") // original OC uses Set(); we use regex
|
||||
private val invalidChars = Regex("""[<>:"|?*\u0000-\u001F]""") // original OC uses Set(); we use regex
|
||||
|
||||
fun isValidFilename(name: String) = !name.contains(invalidChars)
|
||||
|
||||
@@ -117,15 +118,23 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
// remove first '/' in path
|
||||
var path = luapath.checkIBM437().validatePath()
|
||||
if (path.startsWith('/')) path = path.substring(1)
|
||||
|
||||
|
||||
val finalPath: String
|
||||
|
||||
if (path.startsWith("media/")) {
|
||||
val device = path.substring(6, 9)
|
||||
val subPath = path.substring(9)
|
||||
return computerDir + this.computerValue.getAsString("device") + subPath
|
||||
finalPath = computerDir + this.computerValue.getAsString("device") + subPath
|
||||
}
|
||||
else {
|
||||
return computerDir + this.computerValue.getAsString("boot") + "/" + path
|
||||
finalPath = computerDir + this.computerValue.getAsString("boot") + "/" + path
|
||||
}
|
||||
|
||||
// remove trailing slash
|
||||
return if (finalPath.endsWith("\\") || finalPath.endsWith("/"))
|
||||
finalPath.substring(0, finalPath.length - 1)
|
||||
else
|
||||
finalPath
|
||||
}
|
||||
|
||||
fun combinePath(base: String, local: String) : String {
|
||||
@@ -166,7 +175,7 @@ internal class Filesystem(globals: Globals, computer: TerrarumComputer) {
|
||||
class IsDirectory(val computer: TerrarumComputer) : OneArgFunction() {
|
||||
override fun call(path: LuaValue) : LuaValue {
|
||||
Filesystem.ensurePathSanity(path)
|
||||
|
||||
|
||||
val isDir = Files.isDirectory(Paths.get(computer.getRealPath(path)).toAbsolutePath())
|
||||
val exists = Files.exists(Paths.get(computer.getRealPath(path)).toAbsolutePath())
|
||||
|
||||
|
||||
@@ -37,8 +37,6 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
||||
private val colourKey: Int
|
||||
get() = backColour.shl(4) or (foreColour).and(0xFF)
|
||||
|
||||
override var lastInputByte = -1
|
||||
|
||||
override fun getColor(index: Int) = videoCard.CLUT[index]
|
||||
|
||||
override val displayW: Int; get() = videoCard.width //+ 2 * borderSize
|
||||
@@ -272,11 +270,6 @@ class GraphicsTerminal(private val host: TerrarumComputer) : Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
override fun getKeyPress(): Int? {
|
||||
//TODO("not implemented")
|
||||
return null
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val WHITE7500 = Color(0xe4eaff)
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ open class SimpleTextTerminal(
|
||||
* Terminals must support AT LEAST 4 colours.
|
||||
* Color index 0 must be default background, index 3 must be default foreground
|
||||
*/
|
||||
open protected val colours = if (colour) CLUT else CLUT.copyOfRange(0, 3)
|
||||
open protected val colours = if (colour) CLUT else CLUT.copyOfRange(0, 4)
|
||||
|
||||
val phosphor = if (colour) WHITE7500 else phosphorColour
|
||||
open val colourScreen = if (colour) Color(8, 8, 8) else Color(19, 19, 19)
|
||||
@@ -339,26 +339,10 @@ open class SimpleTextTerminal(
|
||||
}
|
||||
}
|
||||
|
||||
override var lastInputByte: Int = -1
|
||||
var sb: StringBuilder = StringBuilder()
|
||||
private var inputOpen = false
|
||||
private var keyPressVisible = false
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
lastInputByte = c.toInt()
|
||||
|
||||
if (inputOpen) {
|
||||
if (c == ASCII_CR)
|
||||
printChar(ASCII_LF)
|
||||
else if (keyPressVisible)
|
||||
printChar(c)
|
||||
if (!asciiControlInUse.contains(c)) sb.append(c)
|
||||
else if (key == Key.BACKSPACE && sb.isNotEmpty()) sb.deleteCharAt(sb.length - 1)
|
||||
}
|
||||
host.keyPressed(key, c)
|
||||
}
|
||||
|
||||
override fun getKeyPress(): Int? = lastInputByte
|
||||
|
||||
private fun isOOB(x: Int, y: Int) =
|
||||
(x < 0 || y < 0 || x >= width || y >= height)
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ interface Terminal : Teletype {
|
||||
var backColour: Int
|
||||
var foreColour: Int
|
||||
|
||||
var lastInputByte: Int
|
||||
|
||||
// to be used in UI
|
||||
override val displayW: Int
|
||||
val displayH: Int
|
||||
@@ -65,17 +63,4 @@ interface Terminal : Teletype {
|
||||
fun emitTone(duration: Millisec, freq: Double)
|
||||
|
||||
override fun bell(pattern: String)
|
||||
/** Requires keyPressed() event to be processed.
|
||||
*
|
||||
* null indicates the input stream is waiting for an input
|
||||
*
|
||||
* implementation:
|
||||
*
|
||||
* private var lastInputByte: Int? = null
|
||||
* override fun keyPressed(key: Int, c: Char) {
|
||||
lastInputByte = c.toInt()
|
||||
lastInputByte = null
|
||||
}
|
||||
*/
|
||||
fun getKeyPress(): Int?
|
||||
}
|
||||
Reference in New Issue
Block a user