From 1057e7d442a5ef9f8bc90ba815d6468f69ee64fd Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Fri, 31 Mar 2017 17:27:53 +0900 Subject: [PATCH] VT: shit is still rolling - We might need virtual disk image... Former-commit-id: c3278cd9fe1ddad8b26b45577fecb0500365d38b --- .../terrarum/StateGraphicComputerTest.kt | 8 ++++---- src/net/torvald/terrarum/StateUITest.kt | 2 ++ src/net/torvald/terrarum/StateVTTest.kt | 4 ++-- .../virtualcomputer/luaapi/Filesystem.kt | 19 +++++++++++++----- .../terminal/GraphicsTerminal.kt | 7 ------- .../terminal/SimpleTextTerminal.kt | 20 ++----------------- .../virtualcomputer/terminal/Terminal.kt | 15 -------------- 7 files changed, 24 insertions(+), 51 deletions(-) diff --git a/src/net/torvald/terrarum/StateGraphicComputerTest.kt b/src/net/torvald/terrarum/StateGraphicComputerTest.kt index cafa3b7a3..7ab287fbb 100644 --- a/src/net/torvald/terrarum/StateGraphicComputerTest.kt +++ b/src/net/torvald/terrarum/StateGraphicComputerTest.kt @@ -36,7 +36,7 @@ class StateGraphicComputerTest : BasicGameState() { } override fun init(container: GameContainer?, game: StateBasedGame?) { - val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram + /*val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram // it's a-me, Mario! (0..3).forEach { @@ -84,7 +84,7 @@ class StateGraphicComputerTest : BasicGameState() { 0,1,1,1,0,0,0,0, 0,0,2,2,2,0,0,0, 0,0,2,2,2,2,0,0 - )) + ))*/ } var angle = 0.0 @@ -99,7 +99,7 @@ class StateGraphicComputerTest : BasicGameState() { computer.update(container, delta) - val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram + /*val vcard = (computer.getPeripheral("ppu") as PeripheralVideoCard).vram val sprites = vcard.sprites angle += delta / 1000.0 @@ -114,7 +114,7 @@ class StateGraphicComputerTest : BasicGameState() { sprites[2].posY = (Math.sin(angle) * 0 + 100).roundInt() sprites[3].posX = (Math.cos(angle) * 80 + 100).roundInt() - sprites[3].posY = (Math.sin(angle) * 0 + 100).roundInt() + sprites[3].posY = (Math.sin(angle) * 0 + 100).roundInt()*/ } override fun getID() = Terrarum.STATE_ID_TEST_TTY diff --git a/src/net/torvald/terrarum/StateUITest.kt b/src/net/torvald/terrarum/StateUITest.kt index bf2575eea..d959c2fe2 100644 --- a/src/net/torvald/terrarum/StateUITest.kt +++ b/src/net/torvald/terrarum/StateUITest.kt @@ -72,6 +72,8 @@ class StateUITest : BasicGameState() { }) actor.inventory.add(ItemCodex[16], 543) + + actor.inventory.getByID(Tile.STONE)!!.item equipTo actor } override fun init(container: GameContainer?, game: StateBasedGame?) { diff --git a/src/net/torvald/terrarum/StateVTTest.kt b/src/net/torvald/terrarum/StateVTTest.kt index 0dd00dbd2..0779a597e 100644 --- a/src/net/torvald/terrarum/StateVTTest.kt +++ b/src/net/torvald/terrarum/StateVTTest.kt @@ -20,8 +20,8 @@ import org.newdawn.slick.state.StateBasedGame class StateVTTest : BasicGameState() { // HiRes: 100x64, LoRes: 80x25 - val computerInside = TerrarumComputer(8) - val vt = SimpleTextTerminal(SimpleTextTerminal.AMETHYST_NOVELTY, 80, 25, + val computerInside = TerrarumComputer(peripheralSlots = 8) + val vt = SimpleTextTerminal(SimpleTextTerminal.AMBER, 80, 25, computerInside, colour = false, hires = false) diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt index 0f2e34e48..dedb66abf 100644 --- a/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt +++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt @@ -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()) diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/GraphicsTerminal.kt b/src/net/torvald/terrarum/virtualcomputer/terminal/GraphicsTerminal.kt index 196107754..51177fafd 100644 --- a/src/net/torvald/terrarum/virtualcomputer/terminal/GraphicsTerminal.kt +++ b/src/net/torvald/terrarum/virtualcomputer/terminal/GraphicsTerminal.kt @@ -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) diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt index d6e32d293..ae4414478 100644 --- a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt +++ b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt @@ -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) diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/Terminal.kt b/src/net/torvald/terrarum/virtualcomputer/terminal/Terminal.kt index e9138aea3..d3375c434 100644 --- a/src/net/torvald/terrarum/virtualcomputer/terminal/Terminal.kt +++ b/src/net/torvald/terrarum/virtualcomputer/terminal/Terminal.kt @@ -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? } \ No newline at end of file