Fix on fonts, fixed special char printing (>=0x80) on Term, essentially changing encoding from UTF-8 to ISO-8859-1
Former-commit-id: 78d4423e896301aebdec2f27893bb2aefaf4aada Former-commit-id: e317df0eca8da1598159648bc44c30b86663d8a5
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -28,7 +28,7 @@ class TinyAlphNum : Font {
|
|||||||
private val mappingTable = HashMap<Int, Int>()*/
|
private val mappingTable = HashMap<Int, Int>()*/
|
||||||
|
|
||||||
init {
|
init {
|
||||||
fontSheet = SpriteSheet("./assets/graphics/fonts/cp949.png", W, H)
|
fontSheet = SpriteSheet("./assets/graphics/fonts/milky.png", W, H)
|
||||||
//chars.forEachIndexed { i, c -> mappingTable[c.toInt()] = i }
|
//chars.forEachIndexed { i, c -> mappingTable[c.toInt()] = i }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
Created by minjaesong on 16-09-15.
|
Created by minjaesong on 16-09-15.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
-------------
|
||||||
|
-- ALIASES --
|
||||||
|
-------------
|
||||||
|
|
||||||
fs.run = function(p)
|
fs.run = function(p)
|
||||||
local f = fs.open(p, "r")
|
local f = fs.open(p, "r")
|
||||||
@@ -11,6 +14,9 @@ end
|
|||||||
|
|
||||||
_G.loadstring = _G.load
|
_G.loadstring = _G.load
|
||||||
|
|
||||||
|
_G.print = term.print
|
||||||
|
|
||||||
|
|
||||||
--------------
|
--------------
|
||||||
-- HEXUTILS --
|
-- HEXUTILS --
|
||||||
--------------
|
--------------
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import li.cil.repack.org.luaj.vm2.lib.TwoArgFunction
|
|||||||
import li.cil.repack.org.luaj.vm2.lib.ZeroArgFunction
|
import li.cil.repack.org.luaj.vm2.lib.ZeroArgFunction
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||||
|
import net.torvald.terrarum.virtualcomputer.luaapi.Term.Companion.checkIBM437
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
@@ -368,7 +369,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
|
|||||||
|
|
||||||
private class FileClassWriteBytes(val fos: FileOutputStream): OneArgFunction() {
|
private class FileClassWriteBytes(val fos: FileOutputStream): OneArgFunction() {
|
||||||
override fun call(byteString: LuaValue): LuaValue {
|
override fun call(byteString: LuaValue): LuaValue {
|
||||||
val byteString = byteString.checkjstring()
|
val byteString = byteString.checkIBM437()
|
||||||
val bytearr = ByteArray(byteString.length, { byteString[it].toByte() })
|
val bytearr = ByteArray(byteString.length, { byteString[it].toByte() })
|
||||||
fos.write(bytearr)
|
fos.write(bytearr)
|
||||||
|
|
||||||
@@ -378,7 +379,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
|
|||||||
|
|
||||||
private class FileClassPrintText(val fw: FileWriter): OneArgFunction() {
|
private class FileClassPrintText(val fw: FileWriter): OneArgFunction() {
|
||||||
override fun call(string: LuaValue): LuaValue {
|
override fun call(string: LuaValue): LuaValue {
|
||||||
val text = string.checkjstring()
|
val text = string.checkIBM437()
|
||||||
fw.write(text)
|
fw.write(text)
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
}
|
}
|
||||||
@@ -386,7 +387,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
|
|||||||
|
|
||||||
private class FileClassPrintlnText(val fw: FileWriter): OneArgFunction() {
|
private class FileClassPrintlnText(val fw: FileWriter): OneArgFunction() {
|
||||||
override fun call(string: LuaValue): LuaValue {
|
override fun call(string: LuaValue): LuaValue {
|
||||||
val text = string.checkjstring() + "\n"
|
val text = string.checkIBM437() + "\n"
|
||||||
fw.write(text)
|
fw.write(text)
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
}
|
}
|
||||||
@@ -415,7 +416,7 @@ internal class Filesystem(globals: Globals, computer: BaseTerrarumComputer) {
|
|||||||
private class FileClassReadAllBytes(val path: Path): ZeroArgFunction() {
|
private class FileClassReadAllBytes(val path: Path): ZeroArgFunction() {
|
||||||
override fun call(): LuaValue {
|
override fun call(): LuaValue {
|
||||||
val byteArr = Files.readAllBytes(path)
|
val byteArr = Files.readAllBytes(path)
|
||||||
val s: String = java.lang.String(byteArr, "ISO-8859-1").toString()
|
val s: String = java.lang.String(byteArr, "IBM437").toString()
|
||||||
return LuaValue.valueOf(s)
|
return LuaValue.valueOf(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import li.cil.repack.org.luaj.vm2.*
|
|||||||
import li.cil.repack.org.luaj.vm2.lib.*
|
import li.cil.repack.org.luaj.vm2.lib.*
|
||||||
import net.torvald.terrarum.virtualcomputer.terminal.Teletype
|
import net.torvald.terrarum.virtualcomputer.terminal.Teletype
|
||||||
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
|
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIs must have some extent of compatibility with ComputerCraft by dan200
|
* APIs must have some extent of compatibility with ComputerCraft by dan200
|
||||||
@@ -26,6 +27,7 @@ internal class Term(globals: Globals, term: Teletype) {
|
|||||||
if (term is Terminal) {
|
if (term is Terminal) {
|
||||||
globals["term"]["emitRaw"] = Term.EmitRaw(term)
|
globals["term"]["emitRaw"] = Term.EmitRaw(term)
|
||||||
globals["term"]["emit"] = Term.Emit(term)
|
globals["term"]["emit"] = Term.Emit(term)
|
||||||
|
globals["term"]["emitString"] = Term.EmitString(term)
|
||||||
globals["term"]["resetColor"] = Term.ResetColour(term)
|
globals["term"]["resetColor"] = Term.ResetColour(term)
|
||||||
globals["term"]["resetColour"] = Term.ResetColour(term)
|
globals["term"]["resetColour"] = Term.ResetColour(term)
|
||||||
globals["term"]["clear"] = Term.Clear(term)
|
globals["term"]["clear"] = Term.Clear(term)
|
||||||
@@ -44,18 +46,28 @@ internal class Term(globals: Globals, term: Teletype) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun LuaValue.checkIBM437(): String {
|
||||||
|
if (this is LuaString)
|
||||||
|
return m_bytes.copyOfRange(m_offset, m_length).toString(Charset.forName("ISO-8859-1"))
|
||||||
|
// it only works if Charset is ISO-8859, despite of the name "IBM437"
|
||||||
|
else
|
||||||
|
throw LuaError("bad argument (string expected, got ${this.typename()})")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class WriteString(val tty: Teletype) : LuaFunction() {
|
class WriteString(val tty: Teletype) : LuaFunction() {
|
||||||
override fun call(p0: LuaValue): LuaValue {
|
override fun call(p0: LuaValue): LuaValue {
|
||||||
if (tty is Terminal)
|
if (tty is Terminal)
|
||||||
tty.writeString(p0.checkjstring())
|
tty.writeString(p0.checkIBM437())
|
||||||
else
|
else
|
||||||
tty.writeChars(p0.checkjstring())
|
tty.writeChars(p0.checkIBM437())
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun call(s: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
|
override fun call(s: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
|
||||||
if (tty is Terminal)
|
if (tty is Terminal)
|
||||||
tty.writeString(s.checkjstring(), x.checkint(), y.checkint())
|
tty.writeString(s.checkIBM437(), x.checkint(), y.checkint())
|
||||||
else
|
else
|
||||||
throw LuaError("couldn't move cursor; TTY is one-dimensional")
|
throw LuaError("couldn't move cursor; TTY is one-dimensional")
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
@@ -65,15 +77,15 @@ internal class Term(globals: Globals, term: Teletype) {
|
|||||||
class PrintString(val tty: Teletype) : LuaFunction() {
|
class PrintString(val tty: Teletype) : LuaFunction() {
|
||||||
override fun call(p0: LuaValue): LuaValue {
|
override fun call(p0: LuaValue): LuaValue {
|
||||||
if (tty is Terminal)
|
if (tty is Terminal)
|
||||||
tty.printString(p0.checkjstring())
|
tty.printString(p0.checkIBM437())
|
||||||
else
|
else
|
||||||
tty.printChars(p0.checkjstring())
|
tty.printChars(p0.checkIBM437())
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun call(s: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
|
override fun call(s: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
|
||||||
if (tty is Terminal)
|
if (tty is Terminal)
|
||||||
tty.printString(s.checkjstring(), x.checkint(), y.checkint())
|
tty.printString(s.checkIBM437(), x.checkint(), y.checkint())
|
||||||
else
|
else
|
||||||
throw LuaError("couldn't move cursor; TTY is one-dimensional")
|
throw LuaError("couldn't move cursor; TTY is one-dimensional")
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
@@ -87,16 +99,23 @@ internal class Term(globals: Globals, term: Teletype) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EmitRaw(val term: Terminal) : OneArgFunction() {
|
class EmitRaw(val term: Terminal) : ThreeArgFunction() {
|
||||||
override fun call(p0: LuaValue): LuaValue {
|
override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
|
||||||
term.emitChar(p0.checkint())
|
term.emitChar(p0.checkint(), x.checkint(), y.checkint())
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Emit(val term: Terminal) : OneArgFunction() {
|
class Emit(val term: Terminal) : ThreeArgFunction() {
|
||||||
override fun call(p0: LuaValue): LuaValue {
|
override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
|
||||||
term.emitChar(p0.checkint().toChar())
|
term.emitChar(p0.checkint().toChar(), x.checkint(), y.checkint())
|
||||||
|
return LuaValue.NONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EmitString(val term: Terminal) : ThreeArgFunction() {
|
||||||
|
override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
|
||||||
|
term.emitString(p0.checkIBM437(), x.checkint(), y.checkint())
|
||||||
return LuaValue.NONE
|
return LuaValue.NONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ open class SimpleTextTerminal(
|
|||||||
open protected val colourScreen = if (colour) Color(4, 4, 4) else Color(19, 19, 19)
|
open protected val colourScreen = if (colour) Color(4, 4, 4) else Color(19, 19, 19)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
override fun getColor(index: Int): Color = colours[index]
|
override fun getColor(index: Int): Color = colours[index]
|
||||||
|
|
||||||
override fun update(gc: GameContainer, delta: Int) {
|
override fun update(gc: GameContainer, delta: Int) {
|
||||||
@@ -191,14 +192,14 @@ open class SimpleTextTerminal(
|
|||||||
|
|
||||||
/** Emits a bufferChar. Does not move cursor
|
/** Emits a bufferChar. Does not move cursor
|
||||||
* It is also not affected by the control sequences; just print them out as symbol */
|
* It is also not affected by the control sequences; just print them out as symbol */
|
||||||
override fun emitChar(bufferChar: Int) {
|
override fun emitChar(bufferChar: Int, x: Int, y: Int) {
|
||||||
screenBuffer.drawBuffer(cursorX, cursorY, bufferChar.toChar())
|
screenBuffer.drawBuffer(x, y, bufferChar.toChar())
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Emits a char. Does not move cursor
|
/** Emits a char. Does not move cursor
|
||||||
* It is also not affected by the control sequences; just print them out as symbol */
|
* It is also not affected by the control sequences; just print them out as symbol */
|
||||||
override fun emitChar(c: Char) {
|
override fun emitChar(c: Char, x: Int, y: Int) {
|
||||||
screenBuffer.drawBuffer(cursorX, cursorY, c.toInt().and(0xFF).toChar(), colourKey)
|
screenBuffer.drawBuffer(x, y, c.toInt().and(0xFF).toChar(), colourKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints a char and move cursor accordingly. */
|
/** Prints a char and move cursor accordingly. */
|
||||||
@@ -244,18 +245,21 @@ open class SimpleTextTerminal(
|
|||||||
/** Emits a string and move cursor accordingly. */
|
/** Emits a string and move cursor accordingly. */
|
||||||
override fun writeString(s: String, x: Int, y: Int) {
|
override fun writeString(s: String, x: Int, y: Int) {
|
||||||
setCursor(x, y)
|
setCursor(x, y)
|
||||||
emitString(s)
|
|
||||||
val absCursorPos = cursorX + cursorY * width + s.length
|
for (i in 0..s.length - 1) {
|
||||||
setCursor(absCursorPos % width, absCursorPos / width)
|
printChar(s[i])
|
||||||
|
wrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Emits a string. Does not move cursor */
|
/** Emits a string, does not affected by control sequences. Does not move cursor */
|
||||||
override fun emitString(s: String) {
|
override fun emitString(s: String, x: Int, y: Int) {
|
||||||
val x = cursorX
|
setCursor(x, y)
|
||||||
val y = cursorY
|
|
||||||
|
|
||||||
for (i in 0..s.length - 1)
|
for (i in 0..s.length - 1) {
|
||||||
printChar(s[i])
|
emitChar(s[i])
|
||||||
|
wrap()
|
||||||
|
}
|
||||||
|
|
||||||
setCursor(x, y)
|
setCursor(x, y)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ interface Terminal : Teletype {
|
|||||||
fun setCursor(x: Int, y: Int)
|
fun setCursor(x: Int, y: Int)
|
||||||
/** Emits a bufferChar. Does not move cursor
|
/** Emits a bufferChar. Does not move cursor
|
||||||
* It is also not affected by the control sequences; just print them out as symbol */
|
* It is also not affected by the control sequences; just print them out as symbol */
|
||||||
fun emitChar(bufferChar: Int)
|
fun emitChar(bufferChar: Int, x: Int = cursorX, y: Int = cursorY)
|
||||||
/** Emits a char. Does not move cursor
|
/** Emits a char. Does not move cursor
|
||||||
* It is also not affected by the control sequences; just print them out as symbol */
|
* It is also not affected by the control sequences; just print them out as symbol */
|
||||||
fun emitChar(c: Char)
|
fun emitChar(c: Char, x: Int = cursorX, y: Int = cursorY)
|
||||||
/** Prints a char and move cursor accordingly. */
|
/** Prints a char and move cursor accordingly. */
|
||||||
override fun printChar(c: Char)
|
override fun printChar(c: Char)
|
||||||
/** Emits a string. Does not move cursor */
|
/** Emits a string, does not affected by control sequences. Does not move cursor */
|
||||||
fun emitString(s: String)
|
fun emitString(s: String, x: Int = cursorX, y: Int = cursorY)
|
||||||
/** Emits a string and move cursor accordingly, then do LF */
|
/** Emits a string and move cursor accordingly, then do LF */
|
||||||
fun printString(s: String, x: Int = cursorX, y: Int = cursorY)
|
fun printString(s: String, x: Int = cursorX, y: Int = cursorY)
|
||||||
/** Emits a string and move cursor accordingly. */
|
/** Emits a string and move cursor accordingly. */
|
||||||
|
|||||||