diff --git a/src/net/torvald/terrarum/StateInGame.kt b/src/net/torvald/terrarum/StateInGame.kt
index 6547e3940..7223eda64 100644
--- a/src/net/torvald/terrarum/StateInGame.kt
+++ b/src/net/torvald/terrarum/StateInGame.kt
@@ -93,6 +93,8 @@ constructor() : BasicGameState() {
@Throws(SlickException::class)
override fun init(gameContainer: GameContainer, stateBasedGame: StateBasedGame) {
// state init code. Executed before the game goes into any "state" in states in StateBasedGame.java
+
+ Terrarum.gameStarted = true
}
override fun enter(gc: GameContainer, sbg: StateBasedGame) {
diff --git a/src/net/torvald/terrarum/StateVTTest.kt b/src/net/torvald/terrarum/StateVTTest.kt
index 4a386417e..c66061024 100644
--- a/src/net/torvald/terrarum/StateVTTest.kt
+++ b/src/net/torvald/terrarum/StateVTTest.kt
@@ -21,7 +21,8 @@ class StateVTTest : BasicGameState() {
// HiRes: 100x64, LoRes: 80x25
val computerInside = BaseTerrarumComputer()
- val vt = SimpleTextTerminal(SimpleTextTerminal.BLUE_NOVELTY, 80, 25, computerInside, colour = false, hires = false)
+ val vt = SimpleTextTerminal(SimpleTextTerminal.WHITE, 80, 25,
+ computerInside, colour = false, hires = false)
val vtUI = Image(vt.displayW, vt.displayH)
diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt
index 88dcd9242..6ed9358fb 100644
--- a/src/net/torvald/terrarum/Terrarum.kt
+++ b/src/net/torvald/terrarum/Terrarum.kt
@@ -140,6 +140,8 @@ constructor(gamename: String) : StateBasedGame(gamename) {
var VSYNC = true
val VSYNC_TRIGGER_THRESHOLD = 56
+ var gameStarted = false
+
lateinit var ingame: StateInGame
lateinit var gameConfig: GameConfig
diff --git a/src/net/torvald/terrarum/console/SetTime.kt b/src/net/torvald/terrarum/console/SetTime.kt
index f7ec7b589..8e3786c71 100644
--- a/src/net/torvald/terrarum/console/SetTime.kt
+++ b/src/net/torvald/terrarum/console/SetTime.kt
@@ -13,7 +13,7 @@ class SetTime : ConsoleCommand {
Terrarum.ingame.world.time.setTime(timeToSet)
- Echo().execute("Set time to ${Terrarum.ingame.world.time.elapsedSeconds()} " +
+ Echo().execute("Set time to ${Terrarum.ingame.world.time.elapsedSeconds} " +
"(${Terrarum.ingame.world.time.hours}h${formatMin(Terrarum.ingame.world.time.minutes)})")
}
else {
diff --git a/src/net/torvald/terrarum/gameworld/WorldTime.kt b/src/net/torvald/terrarum/gameworld/WorldTime.kt
index 5820f59db..5ee501345 100644
--- a/src/net/torvald/terrarum/gameworld/WorldTime.kt
+++ b/src/net/torvald/terrarum/gameworld/WorldTime.kt
@@ -1,50 +1,93 @@
package net.torvald.terrarum.gameworld
/**
+ * The World Calendar implementation of Dwarven Calendar (we're talking about DF!)
+ *
+ * Please see:
+ * https://en.wikipedia.org/wiki/World_Calendar
+ * http://dwarffortresswiki.org/index.php/DF2014:Calendar
+ *
+ * Normal format for day is
+ * Tysdag 12th Granite
+ *
+ * And there is no AM/PM concept, 22-hour clock is forced.
+ *
* Created by minjaesong on 16-01-24.
*/
class WorldTime {
- internal var seconds: Int
- internal var minutes: Int
- internal var hours: Int
+ internal var seconds: Int // 0 - 59
+ internal var minutes: Int // 0 - 59
+ internal var hours: Int // 0 - 21
+ // days on the year
internal var yearlyDays: Int //NOT a calendar day
- internal var days: Int
- internal var months: Int
- internal var years: Int
+ internal var days: Int // 1 - 31
+ internal var months: Int // 1 - 12
+ internal var years: Int // 1+
- internal var dayOfWeek: Int //0: Mondag-The first day of weekday
+ internal var dayOfWeek: Int //0: Mondag-The first day of weekday (0 - 7)
internal var timeDelta = 1
@Transient private var realMillisec: Int
val DAY_NAMES = arrayOf(//daynames are taken from Nynorsk (å -> o)
- "Mondag", "Tysdag", "Midtedag" //From Islenska Miðvikudagur
+ "Mondag", "Tysdag", "Midvikdag" //From Islenska Miðvikudagur
, "Torsdag", "Fredag", "Laurdag", "Sundag", "Verdag" //From Norsk word 'verd'
)
val DAY_NAMES_SHORT = arrayOf("Mon", "Tys", "Mid", "Tor", "Fre", "Lau", "Sun", "Ver")
+ val MONTH_NAMES = arrayOf(
+ "Opal", "Obsidian", "Granite", "Slate", "Felsite", "Hematite",
+ "Malachite", "Galena", "Limestone", "Sandstone", "Timber", "Moonstone"
+ )
+ val MONTH_NAMES_SHORT = arrayOf("Opal", "Obsi", "Gran", "Slat", "Fels", "Hema",
+ "Mala", "Gale", "Lime", "Sand", "Timb", "Moon")
@Transient val REAL_SEC_IN_MILLI = 1000
+ companion object {
+ /** Each day is 22-hour long */
+ val DAY_LENGTH = 79200 //must be the multiple of 3600
+
+ val HOUR_SEC: Int = 3600
+ val MINUTE_SEC: Int = 60
+ val HOUR_MIN: Int = 60
+ val GAME_MIN_TO_REAL_SEC: Float = 60f
+
+ fun parseTime(s: String): Int =
+ if (s.length >= 4) {
+ s.toLowerCase().substringBefore('h').toInt() * WorldTime.HOUR_SEC +
+ s.toLowerCase().substringAfter('h').toInt() * WorldTime.MINUTE_SEC
+ }
+ else if (s.endsWith("h", true)) {
+ s.toLowerCase().substring(0, s.length - 1).toInt() * WorldTime.HOUR_SEC
+ }
+ else {
+ s.toInt()
+ }
+ }
+
init {
seconds = 0
minutes = 30
hours = 8
- yearlyDays = 1
+ yearlyDays = 73
days = 12
months = 3
years = 125
- dayOfWeek = 0
+ dayOfWeek = 1 // Tysdag
realMillisec = 0
}
fun update(delta: Int) {
+ val oldsec = seconds
+
//time
realMillisec += delta * timeDelta
- seconds = Math.round(GAME_MIN_TO_REAL_SEC.toFloat() / REAL_SEC_IN_MILLI.toFloat() * realMillisec.toFloat())
+ val newsec = Math.round(GAME_MIN_TO_REAL_SEC.toFloat() / REAL_SEC_IN_MILLI.toFloat() * realMillisec.toFloat())
+ seconds = newsec
if (realMillisec >= REAL_SEC_IN_MILLI)
realMillisec -= REAL_SEC_IN_MILLI
@@ -57,22 +100,23 @@ class WorldTime {
* 0 == 6 AM
* @return
*/
- fun elapsedSeconds(): Int {
- return (HOUR_SEC * hours + MINUTE_SEC * minutes + seconds) % DAY_LENGTH
- }
+ val elapsedSeconds: Int
+ get() = (HOUR_SEC * hours + MINUTE_SEC * minutes + seconds) % DAY_LENGTH
val isLeapYear: Boolean
get() = years % 4 == 0 && years % 100 != 0 || years % 400 == 0
+ /** Sets time of this day. */
fun setTime(t: Int) {
days += t / DAY_LENGTH
hours = t / HOUR_SEC
minutes = (t - HOUR_SEC * hours) / MINUTE_SEC
seconds = t - minutes * MINUTE_SEC
+ yearlyDays += t / DAY_LENGTH
}
fun addTime(t: Int) {
- setTime(elapsedSeconds() + t)
+ setTime(elapsedSeconds + t)
}
fun setTimeDelta(d: Int) {
@@ -125,41 +169,14 @@ class WorldTime {
if (months > 12) {
months = 1
years++
+ yearlyDays = 1
}
}
- fun getFormattedTime(): String {
- fun formatMin(min: Int): String {
- return if (min < 10) "0${min.toString()}" else min.toString()
- }
+ fun getFormattedTime() = "${String.format("%02d", hours)}h${String.format("%02d", minutes)}"
- return "${hours}h${formatMin(minutes)}"
- }
-
- fun getDayNameFull(): String = DAY_NAMES[dayOfWeek]
- fun getDayNameShort(): String = DAY_NAMES_SHORT[dayOfWeek]
-
- companion object {
- /**
- * 22h
- */
- val DAY_LENGTH = 79200 //must be the multiple of 3600
-
- val HOUR_SEC: Int = 3600
- val MINUTE_SEC: Int = 60
- val HOUR_MIN: Int = 60
- val GAME_MIN_TO_REAL_SEC: Float = 60f
-
- fun parseTime(s: String): Int =
- if (s.length >= 4) {
- s.toLowerCase().substringBefore('h').toInt() * WorldTime.HOUR_SEC +
- s.toLowerCase().substringAfter('h').toInt() * WorldTime.MINUTE_SEC
- }
- else if (s.endsWith("h", true)) {
- s.toLowerCase().substring(0, s.length - 1).toInt() * WorldTime.HOUR_SEC
- }
- else {
- s.toInt()
- }
- }
+ fun getDayNameFull() = DAY_NAMES[dayOfWeek]
+ fun getDayNameShort() = DAY_NAMES_SHORT[dayOfWeek]
+ fun getMonthNameFull() = MONTH_NAMES[months - 1]
+ fun getMonthNameShort() = MONTH_NAMES_SHORT[months - 1]
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt
index 963268de7..9ed2f5ed7 100644
--- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt
+++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt
@@ -131,7 +131,7 @@ class BasicDebugInfoWindow : UICanvas {
printLineColumn(g, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
printLineColumn(g, 2, 2, "Env colour temp $ccG" + MapDrawer.colTemp)
- printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame.world.time.elapsedSeconds()}" +
+ printLineColumn(g, 2, 5, "Time $ccG${Terrarum.ingame.world.time.elapsedSeconds}" +
" (${Terrarum.ingame.world.time.getFormattedTime()})")
printLineColumn(g, 2, 6, "Mass $ccG${player.mass}")
diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua b/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua
index f4f8c2e61..ee06e3d94 100644
--- a/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua
+++ b/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua
@@ -6,10 +6,32 @@
Some codes were taken from OpenComputers, which is distributed under MIT
--]]
+-- global functions
+_G.runscript = function(s, src, ...)
+ if s:byte(1) == 27 then error("Bytecode execution is prohibited.") end
+
+ local code, reason = load(s, src)
+
+ if code then
+ xpcall(code(...), eprint)
+ else
+ print(DLE..tostring(reason)) -- it catches syntax errors
+ end
+end
+
+fs.dofile = function(p, ...)
+ local f = fs.open(p, "r")
+ local s = f.readAll()
+ _G.runscript(s, "="..p, ...)
+end
+
+-- EFI is expected to locate in "boot/efi"
+if fs.exists("boot/efi") then fs.dofile("boot/efi") end
+
computer.realTime = function() return 0 end
-- global variables
-_G._VERSION = "Luaj-jse 3.0.1 (Lua 5.2.3)"
+_G._VERSION = _VERSION.." (Lua 5.2.3)"
_G.EMDASH = string.char(0xC4)
_G.UNCHECKED = string.char(0x9C) -- box unchecked
_G.CHECKED = string.char(0x9D) -- box checked
@@ -969,18 +991,6 @@ sandbox._G = sandbox
-- path for any ingame libraries
package.path = "/net/torvald/terrarum/virtualcomputer/assets/lua/?.lua;" .. package.path
--- global functions
-_G.runscript = function(s, src, ...)
- if s:byte(1) == 27 then error("Bytecode execution is prohibited.") end
-
- local code, reason = load(s, src)
-
- if code then
- xpcall(code(...), eprint)
- else
- print(DLE..tostring(reason)) -- it catches syntax errors
- end
-end
_G.__scanMode__ = "UNINIT" -- part of inputstream implementation
local screenbufferdim = term.width() * term.height()
@@ -989,14 +999,15 @@ if term.isCol() then screencolours = 8
elseif term.isTeletype() then screencolours = 1 end
local screenbuffersize = screenbufferdim * screencolours / 8
-computer.prompt = DC3.."> "..DC4
-computer.verbose = true -- print debug info
-computer.loadedCLayer = {} -- list of loaded compatibility layers
-computer.bootloader = "/boot/efi"
-computer.OEM = ""
+if not computer.prompt then computer.prompt = DC3.."> "..DC4 end
+if not computer.verbose then computer.verbose = true end -- print debug info
+if not computer.loadedCLayer then computer.loadedCLayer = {} end -- list of loaded compatibility layers
+-- if no bootloader is pre-defined via EFI, use default one
+if not computer.bootloader then computer.bootloader = "/boot/bootloader" end
+if not computer.OEM then computer.OEM = "" end
computer.beep = emittone
computer.totalMemory = _G.totalMemory
-computer.bellpitch = 1000
+if not computer.bellpitch then computer.bellpitch = 1000 end
local getMemory = function()
collectgarbage()
return collectgarbage("count") * 1024 - 6.5*1048576 + screenbuffersize
@@ -1021,7 +1032,7 @@ print("Rom basic "..DC2.._VERSION..DC4)
print("Copyright (C) 1994-2013 Lua.org, PUC-Rio")
print("Ok")
-while not native.isHalted() do
+while not machine.isHalted() do
term.setCursorBlink(true)
io.write(computer.prompt)
local s = __scanforline__()
@@ -1039,5 +1050,5 @@ while not native.isHalted() do
end
::quit::
-native.closeInputString()
+machine.closeInputString()
return
diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/lua/ROMLIB.lua b/src/net/torvald/terrarum/virtualcomputer/assets/lua/ROMLIB.lua
index ba4d7e9f7..12f76902c 100644
--- a/src/net/torvald/terrarum/virtualcomputer/assets/lua/ROMLIB.lua
+++ b/src/net/torvald/terrarum/virtualcomputer/assets/lua/ROMLIB.lua
@@ -8,11 +8,11 @@
_G.io = {}
-fs.dofile = function(p, ...)
+--[[fs.dofile = function(p, ...)
local f = fs.open(p, "r")
local s = f.readAll()
_G.runscript(s, "="..p, ...)
-end
+end]] -- implementation moved to BOOT.lua
_G.loadstring = _G.load
@@ -46,12 +46,12 @@ override fun keyPressed(key: Int, c: Char) {
and THIS exact part will close the input for this function.
]]
_G.__scanforline__ = function(echo) -- pass '1' to not echo; pass nothing to echo
- native.closeInputString()
- native.openInput(echo or 0)
+ machine.closeInputString()
+ machine.openInput(echo or 0)
_G.__scanMode__ = "line"
local s
repeat -- we can do this ONLY IF lua execution process is SEPARATE THREAD
- s = native.getLastStreamInput()
+ s = machine.getLastStreamInput()
until s
-- input is closed when RETURN is hit. See above comments.
return s
@@ -59,12 +59,12 @@ end
-- use Keys API to identify the keycode
--[[_G.__scanforkey__ = function(echo) -- pass '1' to not echo; pass nothing to echo
- native.closeInputString()
- native.openInput(echo or 0)
+ machine.closeInputString()
+ machine.openInput(echo or 0)
_G.__scanMode__ = "a_key"
local key
repeat -- we can do this ONLY IF lua execution process is SEPARATE THREAD
- key = native.getLastKeyPress()
+ key = machine.getLastKeyPress()
until key
-- input is closed when any key is hit. See above comments.
return key
diff --git a/src/net/torvald/terrarum/virtualcomputer/computer/BaseTerrarumComputer.kt b/src/net/torvald/terrarum/virtualcomputer/computer/BaseTerrarumComputer.kt
index 88f7933e7..6a9f87671 100644
--- a/src/net/torvald/terrarum/virtualcomputer/computer/BaseTerrarumComputer.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/computer/BaseTerrarumComputer.kt
@@ -1,20 +1,18 @@
package net.torvald.terrarum.virtualcomputer.computer
import com.jme3.math.FastMath
-import li.cil.repack.org.luaj.vm2.Globals
-import li.cil.repack.org.luaj.vm2.LuaError
-import li.cil.repack.org.luaj.vm2.LuaTable
-import li.cil.repack.org.luaj.vm2.LuaValue
-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.jse.JsePlatform
+import org.luaj.vm2.Globals
+import org.luaj.vm2.LuaError
+import org.luaj.vm2.LuaTable
+import org.luaj.vm2.LuaValue
+import org.luaj.vm2.lib.TwoArgFunction
+import org.luaj.vm2.lib.ZeroArgFunction
+import org.luaj.vm2.lib.jse.JsePlatform
import net.torvald.terrarum.KVHashMap
-import net.torvald.terrarum.gameactors.ActorValue
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.virtualcomputer.luaapi.*
import net.torvald.terrarum.virtualcomputer.terminal.*
import net.torvald.terrarum.virtualcomputer.worldobject.ComputerPartsCodex
-import net.torvald.terrarum.virtualcomputer.worldobject.FixtureComputerBase
import org.lwjgl.BufferUtils
import org.lwjgl.openal.AL
import org.lwjgl.openal.AL10
@@ -73,6 +71,12 @@ class BaseTerrarumComputer() {
lateinit var term: Teletype
private set
+ // os-related functions. These are called "machine" library-wise.
+ private val startupTimestamp: Long = System.currentTimeMillis()
+ /** Time elapsed since the power is on. */
+ val milliTime: Int
+ get() = (System.currentTimeMillis() - startupTimestamp).toInt()
+
init {
computerValue["memslot0"] = 4864 // -1 indicates mem slot is empty
computerValue["memslot1"] = -1 // put index of item here
@@ -96,7 +100,6 @@ class BaseTerrarumComputer() {
// boot device
computerValue["boot"] = computerValue.getAsString("hda")!!
-
}
fun attachTerminal(term: Teletype) {
@@ -125,6 +128,7 @@ class BaseTerrarumComputer() {
Input(luaJ_globals, this)
Http(luaJ_globals, this)
PcSpeakerDriver(luaJ_globals, this)
+ WorldInformationProvider(luaJ_globals)
// secure the sandbox
@@ -141,6 +145,7 @@ class BaseTerrarumComputer() {
luaJ_globals["totalMemory"] = LuaFunGetTotalMem(this)
luaJ_globals["computer"] = LuaTable()
+ // rest of the "computer" APIs should be implemented in BOOT.lua
if (DEBUG) luaJ_globals["emittone"] = ComputerEmitTone(this)
}
@@ -167,8 +172,6 @@ class BaseTerrarumComputer() {
}
driveBeepQueueManager(delta)
-
-
}
fun keyPressed(key: Int, c: Char) {
@@ -267,19 +270,19 @@ class BaseTerrarumComputer() {
private var beepQueueFired = false
private fun driveBeepQueueManager(delta: Int) {
- // start beep queue
+ // start emitTone queue
if (beepQueue.size > 0 && beepCursor == -1) {
beepCursor = 0
}
- // continue beep queue
+ // continue emitTone queue
if (beepCursor >= 0 && beepQueueLineExecTimer >= beepQueueGetLenOfPtn(beepCursor)) {
beepQueueLineExecTimer -= beepQueueGetLenOfPtn(beepCursor)
beepCursor += 1
beepQueueFired = false
}
- // complete beep queue
+ // complete emitTone queue
if (beepCursor >= beepQueue.size) {
clearBeepQueue()
if (DEBUG) println("!! Beep queue clear")
diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt
index 8148f41c0..4feb68a67 100644
--- a/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/Filesystem.kt
@@ -1,9 +1,9 @@
package net.torvald.terrarum.virtualcomputer.luaapi
-import li.cil.repack.org.luaj.vm2.*
-import li.cil.repack.org.luaj.vm2.lib.OneArgFunction
-import li.cil.repack.org.luaj.vm2.lib.TwoArgFunction
-import li.cil.repack.org.luaj.vm2.lib.ZeroArgFunction
+import org.luaj.vm2.*
+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.virtualcomputer.computer.BaseTerrarumComputer
import net.torvald.terrarum.virtualcomputer.luaapi.Term.Companion.checkIBM437
diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/HostAccessProvider.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/HostAccessProvider.kt
index e9d485770..23264fa37 100644
--- a/src/net/torvald/terrarum/virtualcomputer/luaapi/HostAccessProvider.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/HostAccessProvider.kt
@@ -1,36 +1,35 @@
package net.torvald.terrarum.virtualcomputer.luaapi
-import li.cil.repack.org.luaj.vm2.Globals
-import li.cil.repack.org.luaj.vm2.LuaFunction
-import li.cil.repack.org.luaj.vm2.LuaTable
-import li.cil.repack.org.luaj.vm2.LuaValue
-import li.cil.repack.org.luaj.vm2.lib.OneArgFunction
-import li.cil.repack.org.luaj.vm2.lib.ZeroArgFunction
+import org.luaj.vm2.lib.OneArgFunction
+import org.luaj.vm2.lib.ZeroArgFunction
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
import net.torvald.terrarum.virtualcomputer.luaapi.Term.Companion.checkIBM437
import net.torvald.terrarum.virtualcomputer.terminal.Teletype
+import org.luaj.vm2.*
/**
* Provide Lua an access to computer object that is in Java
*
+ * The "machine" refers to the computer fixture itself in the game world.
+ *
* Created by minjaesong on 16-09-19.
*/
internal class HostAccessProvider(globals: Globals, computer: BaseTerrarumComputer) {
init {
- globals["native"] = LuaTable()
- globals["native"]["println"] = PrintLn()
- globals["native"]["isHalted"] = IsHalted(computer)
+ globals["machine"] = LuaTable()
+ globals["machine"]["println"] = PrintLn()
+ globals["machine"]["isHalted"] = IsHalted(computer)
- globals["native"]["closeInputString"] = NativeCloseInputString(computer.term)
- globals["native"]["closeInputKey"] = NativeCloseInputKey(computer.term)
- globals["native"]["openInput"] = NativeOpenInput(computer.term)
- globals["native"]["getLastStreamInput"] = NativeGetLastStreamInput(computer.term)
- globals["native"]["getLastKeyPress"] = NativeGetLastKeyPress(computer.term)
+ globals["machine"]["closeInputString"] = NativeCloseInputString(computer.term)
+ globals["machine"]["closeInputKey"] = NativeCloseInputKey(computer.term)
+ globals["machine"]["openInput"] = NativeOpenInput(computer.term)
+ globals["machine"]["getLastStreamInput"] = NativeGetLastStreamInput(computer.term)
+ globals["machine"]["getLastKeyPress"] = NativeGetLastKeyPress(computer.term)
- // while lua's dofile/require is fixiated to fs, this command allows
- // libraries in JAR to be loaded.
- //globals["native"]["loadBuiltInLib"] = NativeLoadBuiltInLib()
+ globals["machine"]["milliTime"] = NativeGetMilliTime(computer)
+
+ globals["machine"]["sleep"] = NativeBusySleep(computer)
globals["__haltsystemexplicit__"] = HaltComputer(computer)
}
@@ -98,4 +97,21 @@ internal class HostAccessProvider(globals: Globals, computer: BaseTerrarumComput
return LuaValue.NONE
}
}
+
+ /** Time elapsed since the power is on. */
+ class NativeGetMilliTime(val computer: BaseTerrarumComputer) : ZeroArgFunction() {
+ override fun call(): LuaValue {
+ return LuaValue.valueOf(computer.milliTime)
+ }
+ }
+
+ class NativeBusySleep(val computer: BaseTerrarumComputer) : OneArgFunction() {
+ override fun call(mills: LuaValue): LuaValue {
+ val starttime = computer.milliTime
+ val sleeptime = mills.checkint()
+ if (sleeptime > 1000) throw LuaError("Cannot busy-sleep more than a second.")
+ while (computer.milliTime - starttime < sleeptime) { }
+ return LuaValue.NONE
+ }
+ }
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/Http.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/Http.kt
index f662c80c3..fa5efe605 100644
--- a/src/net/torvald/terrarum/virtualcomputer/luaapi/Http.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/Http.kt
@@ -1,6 +1,6 @@
package net.torvald.terrarum.virtualcomputer.luaapi
-import li.cil.repack.org.luaj.vm2.Globals
+import org.luaj.vm2.Globals
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
/**
diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/Input.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/Input.kt
index f613744ab..f56c0c7bc 100644
--- a/src/net/torvald/terrarum/virtualcomputer/luaapi/Input.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/Input.kt
@@ -1,9 +1,9 @@
package net.torvald.terrarum.virtualcomputer.luaapi
-import li.cil.repack.org.luaj.vm2.Globals
-import li.cil.repack.org.luaj.vm2.LuaTable
-import li.cil.repack.org.luaj.vm2.LuaValue
-import li.cil.repack.org.luaj.vm2.lib.OneArgFunction
+import org.luaj.vm2.Globals
+import org.luaj.vm2.LuaTable
+import org.luaj.vm2.LuaValue
+import org.luaj.vm2.lib.OneArgFunction
import net.torvald.terrarum.gamecontroller.Key
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/PcSpeakerDriver.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/PcSpeakerDriver.kt
index 1291e494a..b340c2000 100644
--- a/src/net/torvald/terrarum/virtualcomputer/luaapi/PcSpeakerDriver.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/PcSpeakerDriver.kt
@@ -1,10 +1,10 @@
package net.torvald.terrarum.virtualcomputer.luaapi
-import li.cil.repack.org.luaj.vm2.Globals
-import li.cil.repack.org.luaj.vm2.LuaTable
-import li.cil.repack.org.luaj.vm2.LuaValue
-import li.cil.repack.org.luaj.vm2.lib.TwoArgFunction
-import li.cil.repack.org.luaj.vm2.lib.ZeroArgFunction
+import org.luaj.vm2.Globals
+import org.luaj.vm2.LuaTable
+import org.luaj.vm2.LuaValue
+import org.luaj.vm2.lib.TwoArgFunction
+import org.luaj.vm2.lib.ZeroArgFunction
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
/**
diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/Security.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/Security.kt
index ec1b3b931..bf9b597d8 100644
--- a/src/net/torvald/terrarum/virtualcomputer/luaapi/Security.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/Security.kt
@@ -1,8 +1,8 @@
package net.torvald.terrarum.virtualcomputer.luaapi
-import li.cil.repack.org.luaj.vm2.Globals
-import li.cil.repack.org.luaj.vm2.LuaValue
-import li.cil.repack.org.luaj.vm2.lib.OneArgFunction
+import org.luaj.vm2.Globals
+import org.luaj.vm2.LuaValue
+import org.luaj.vm2.lib.OneArgFunction
import net.torvald.terrarum.gameworld.toUint
import org.apache.commons.codec.binary.Base64
import org.apache.commons.codec.digest.DigestUtils
diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/Term.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/Term.kt
index 8f046be6b..05fbaabb2 100644
--- a/src/net/torvald/terrarum/virtualcomputer/luaapi/Term.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/Term.kt
@@ -1,14 +1,14 @@
package net.torvald.terrarum.virtualcomputer.luaapi
-import li.cil.repack.org.luaj.vm2.*
-import li.cil.repack.org.luaj.vm2.lib.*
+import org.luaj.vm2.*
+import org.luaj.vm2.lib.*
import net.torvald.terrarum.virtualcomputer.terminal.Teletype
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
import java.nio.charset.Charset
/**
* Controls terminal as if it was a monitor
- * (not sending control sequences but just drives it, as if it was not a terminal @ 9600 baud)
+ * (not sending control sequences but just drives it directly)
*
* Created by minjaesong on 16-09-12.
*/
diff --git a/src/net/torvald/terrarum/virtualcomputer/luaapi/WorldInformationProvider.kt b/src/net/torvald/terrarum/virtualcomputer/luaapi/WorldInformationProvider.kt
new file mode 100644
index 000000000..73aedd141
--- /dev/null
+++ b/src/net/torvald/terrarum/virtualcomputer/luaapi/WorldInformationProvider.kt
@@ -0,0 +1,131 @@
+package net.torvald.terrarum.virtualcomputer.luaapi
+
+import org.luaj.vm2.Globals
+import org.luaj.vm2.LuaFunction
+import net.torvald.terrarum.Terrarum
+import net.torvald.terrarum.gameworld.WorldTime
+import org.luaj.vm2.LuaTable
+import org.luaj.vm2.LuaValue
+import org.luaj.vm2.lib.ZeroArgFunction
+import java.util.*
+
+/**
+ * Implementation of lua's os.date, to return world info of the game world.
+ *
+ * Created by minjaesong on 16-09-28.
+ */
+class WorldInformationProvider(globals: Globals) {
+
+ init {
+ globals["os"]["time"] = LuaValue.NIL // history is LONG! Our 32-bit Lua's epoch is destined to break down...
+ globals["os"]["date"] = OsDateImpl()
+ }
+
+ companion object {
+ fun getWorldTimeInLuaFormat() : LuaTable {
+ val t = LuaTable()
+ if (Terrarum.gameStarted) {
+ val time = Terrarum.ingame.world.time
+
+ // int Terrarum World Time format
+ t["hour"] = time.hours
+ t["min"] = time.minutes
+ t["wday"] = time.dayOfWeek
+ t["year"] = time.years
+ t["yday"] = time.yearlyDays
+ t["month"] = time.months
+ t["sec"] = time.seconds
+ t["day"] = time.days
+ }
+ else {
+ t["hour"] = 0
+ t["min"] = 0
+ t["wday"] = 1
+ t["year"] = 0
+ t["yday"] = 1
+ t["month"] = 1
+ t["sec"] = 0
+ t["day"] = 1
+ }
+
+ return t
+ }
+
+ val defaultDateFormat = "%a %d %B %Y %X"
+
+ /** evaluate single C date format */
+ fun String.evalAsDate(): String {
+ if (Terrarum.gameStarted) {
+ val time = Terrarum.ingame.world.time
+ return when (this) {
+ "%a" -> time.getDayNameShort()
+ "%A" -> time.getDayNameFull()
+ "%b" -> time.getMonthNameShort()
+ "%B" -> time.getMonthNameFull()
+ "%c" -> "%x".evalAsDate() + " " + "%X".evalAsDate()
+ "%d" -> time.days.toString()
+ "%H" -> time.hours.toString()
+ "%I" -> throw IllegalArgumentException("%I: AM/PM concept does not exists.")
+ "%M" -> time.minutes.toString()
+ "%m" -> time.months.toString()
+ "%p" -> throw IllegalArgumentException("%p: AM/PM concept does not exists.")
+ "%S" -> time.seconds.toString()
+ "%w" -> time.dayOfWeek.toString()
+ "%x" -> "${String.format("%02d", time.years)}-${String.format("%02d", time.months)}-${String.format("%02d", time.days)}"
+ "%X" -> "${String.format("%02d", time.hours)}:${String.format("%02d", time.minutes)}:${String.format("%02d", time.seconds)}"
+ "%Y" -> time.years.toString()
+ "%y" -> time.years.mod(100).toString()
+ "%%" -> "%"
+ else -> throw IllegalArgumentException("Unknown format string: $this")
+ }
+ }
+ else {
+ return when (this) {
+ "%a" -> "---"
+ "%A" -> "------"
+ "%b" -> "----"
+ "%B" -> "--------"
+ "%c" -> "%x".evalAsDate() + " " + "%X".evalAsDate()
+ "%d" -> "0"
+ "%H" -> "0"
+ "%I" -> throw IllegalArgumentException("%I: AM/PM concept does not exists.")
+ "%M" -> "0"
+ "%m" -> "0"
+ "%p" -> throw IllegalArgumentException("%p: AM/PM concept does not exists.")
+ "%S" -> "0"
+ "%w" -> "0"
+ "%x" -> "00-00-00"
+ "%X" -> "00:00:00"
+ "%Y" -> "0"
+ "%y" -> "00"
+ "%%" -> "%"
+ else -> throw IllegalArgumentException("Unknown format string: $this")
+ }
+ }
+ }
+
+ val acceptedDateFormats = arrayOf("%a", "%A", "%b", "%B", "%c", "%d", "%H", "%I", "%M", "%m", "%p", "%S", "%w", "%x", "%X", "%Y", "%y", "%%" )
+ }
+
+ /**
+ * Changes: cannot get a representation of arbitrary time.
+ */
+ class OsDateImpl() : LuaFunction() {
+ // no args
+ override fun call(): LuaValue {
+ return call(defaultDateFormat)
+ }
+
+ override fun call(format: LuaValue): LuaValue {
+ var arg = format.checkjstring()
+ acceptedDateFormats.forEach {
+ if (arg.contains(it))
+ arg = arg.replace(it, it.evalAsDate(), ignoreCase = false)
+ }
+ return LuaValue.valueOf(arg)
+ }
+
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/LuaConsole.java b/src/net/torvald/terrarum/virtualcomputer/terminal/LuaConsole.java
deleted file mode 100644
index 5acbbe083..000000000
--- a/src/net/torvald/terrarum/virtualcomputer/terminal/LuaConsole.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * $Id: LuaConsole.java 79 2012-01-08 11:08:32Z andre@naef.com $
- * See LICENSE.txt for license terms.
- */
-
-package net.torvald.terrarum.virtualcomputer.terminal;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-
-import li.cil.repack.com.naef.jnlua.LuaException;
-import li.cil.repack.com.naef.jnlua.LuaRuntimeException;
-import li.cil.repack.com.naef.jnlua.LuaState;
-
-/**
- * A simple Lua console.
- *
- *
- * The console collects input until a line with the sole content of the word
- * go is encountered. At that point, the collected input is run as a Lua
- * chunk. If the Lua chunk loads and runs successfully, the console displays the
- * returned values of the chunk as well as the execution time based on a
- * System.nanoTime() measurement. Otherwise, the console shows the
- * error that has occurred.
- *
- *
- *
- * Expressions can be printed by prepending = to the expression at the
- * beginning of a chunk. The console translates = into
- * return followed by a space and executes the chunk immediately.
- * No separate go is required. Therefore, expressions printed this way
- * must be entered on a single line.
- *
- */
-public class LuaConsole {
- // -- Static
- private static final String[] EMPTY_ARGS = new String[0];
-
- /**
- * Main routine.
- *
- * @param args
- * the command line arguments
- */
- public static void main(String[] args) {
- LuaConsole luaConsole = new LuaConsole(args);
- luaConsole.run();
- System.exit(0);
- }
-
- // -- State
- private LuaState luaState;
-
- // -- Construction
- /**
- * Creates a new instance.
- */
- public LuaConsole() {
- this(EMPTY_ARGS);
- }
-
- /**
- * Creates a new instance with the specified command line arguments. The
- * arguments are passed to Lua as the argv global variable.
- *
- * @param args
- */
- public LuaConsole(String[] args) {
- luaState = new LuaState();
-
- // Process arguments
- luaState.newTable(args.length, 0);
- for (int i = 0; i < args.length; i++) {
- luaState.pushString(args[i]);
- luaState.rawSet(-2, i + 1);
- }
- luaState.setGlobal("argv");
-
- // Open standard libraries
- luaState.openLibs();
-
- // Set buffer mode
- luaState.load("io.stdout:setvbuf(\"no\")", "=consoleInitStdout");
- luaState.call(0, 0);
- luaState.load("io.stderr:setvbuf(\"no\")", "=consoleInitStderr");
- luaState.call(0, 0);
- }
-
- // -- Properties
- /**
- * Returns the Lua state of this console.
- *
- * @return the Lua state
- */
- public LuaState getLuaState() {
- return luaState;
- }
-
- // -- Operations
- /**
- * Runs the console.
- */
- public void run() {
- // Banner
- System.out.println(String.format("JNLua %s Console using Lua %s.",
- LuaState.VERSION, LuaState.LUA_VERSION));
- System.out.print("Type 'go' on an empty line to evaluate a chunk. ");
- System.out.println("Type = to print an expression.");
-
- // Prepare reader
- BufferedReader bufferedReader = new BufferedReader(
- new InputStreamReader(System.in));
- try {
- // Process chunks
- chunk: while (true) {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- OutputStreamWriter outWriter = new OutputStreamWriter(out,
- "UTF-8");
- boolean firstLine = true;
-
- // Process lines
- while (true) {
- String line = bufferedReader.readLine();
- if (line == null) {
- break chunk;
- }
- if (line.equals("go")) {
- outWriter.flush();
- InputStream in = new ByteArrayInputStream(out
- .toByteArray());
- runChunk(in);
- continue chunk;
- }
- if (firstLine && line.startsWith("=")) {
- outWriter.write("return " + line.substring(1));
- outWriter.flush();
- InputStream in = new ByteArrayInputStream(out
- .toByteArray());
- runChunk(in);
- continue chunk;
- }
- outWriter.write(line);
- outWriter.write('\n');
- firstLine = false;
- }
- }
- } catch (IOException e) {
- System.out.print("IO error: ");
- System.out.print(e.getMessage());
- System.out.println();
- }
- }
-
- /**
- * Runs a chunk of Lua code from an input stream.
- */
- protected void runChunk(InputStream in) throws IOException {
- try {
- long start = System.nanoTime();
- luaState.setTop(0);
- luaState.load(in, "=console", "t");
- luaState.call(0, LuaState.MULTRET);
- long stop = System.nanoTime();
- for (int i = 1; i <= luaState.getTop(); i++) {
- if (i > 1) {
- System.out.print(", ");
- }
- switch (luaState.type(i)) {
- case BOOLEAN:
- System.out.print(Boolean.valueOf(luaState.toBoolean(i)));
- break;
- case NUMBER:
- case STRING:
- System.out.print(luaState.toString(i));
- break;
- default:
- System.out.print(luaState.typeName(i));
- }
- }
- System.out.print("\t#msec=");
- System.out.print(String.format("%.3f", (stop - start) / 1000000.0));
- System.out.println();
- } catch (LuaRuntimeException e) {
- e.printLuaStackTrace();
- } catch (LuaException e) {
- System.err.println(e.getMessage());
- }
- }
-}
diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt
index 873f03322..c118a099f 100644
--- a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt
@@ -223,7 +223,7 @@ open class SimpleTextTerminal(
}
else {
when (c) {
- ASCII_BEL -> beep()
+ ASCII_BEL -> bell(".")
ASCII_BS -> { cursorX -= 1; wrap() }
ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE }
ASCII_LF -> newLine()
@@ -318,13 +318,13 @@ open class SimpleTextTerminal(
* @param duration: milliseconds
* @param freg: Frequency (float)
*/
- override fun beep(duration: Int, freq: Float) {
+ override fun emitTone(duration: Int, freq: Float) {
// println("!! Beep playing row $beepCursor, d ${Math.min(duration, maxDuration)} f $freq")
host.clearBeepQueue()
host.enqueueBeep(duration, freq)
}
- /** for "beep code" on modern BIOS. */
+ /** for "emitTone code" on modern BIOS. */
override fun bell(pattern: String) {
host.clearBeepQueue()
@@ -336,7 +336,7 @@ open class SimpleTextTerminal(
for (c in pattern) {
when (c) {
- '.' -> { host.enqueueBeep(50, freq); host.enqueueBeep(50, 0f) }
+ '.' -> { host.enqueueBeep(80, freq); host.enqueueBeep(50, 0f) }
'-' -> { host.enqueueBeep(200, freq); host.enqueueBeep(50, 0f) }
'=' -> { host.enqueueBeep(500, freq); host.enqueueBeep(50, 0f) }
' ' -> { host.enqueueBeep(200, 0f) }
diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/Terminal.kt b/src/net/torvald/terrarum/virtualcomputer/terminal/Terminal.kt
index 4f2850cfd..a1c8c6a69 100644
--- a/src/net/torvald/terrarum/virtualcomputer/terminal/Terminal.kt
+++ b/src/net/torvald/terrarum/virtualcomputer/terminal/Terminal.kt
@@ -61,13 +61,8 @@ interface Terminal : Teletype {
* @param duration: milliseconds
* @param freg: Frequency (float)
*/
- fun beep(duration: Int = 80, freq: Float = 1000f)
- /**
- * Pattern: - .
- * . 80 ms
- * - 200 ms
- * ( ) 80 ms
- */
+ fun emitTone(duration: Int, freq: Float)
+
override fun bell(pattern: String)
/** Requires keyPressed() event to be processed.
*
diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt
index 121c3ca62..b4a0ff097 100644
--- a/src/net/torvald/terrarum/weather/WeatherMixer.kt
+++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt
@@ -76,7 +76,7 @@ object WeatherMixer {
fun render(g: Graphics) {
// we will not care for nextSkybox for now
- val timeNow = Terrarum.ingame.world.time.elapsedSeconds()
+ val timeNow = Terrarum.ingame.world.time.elapsedSeconds
val skyboxColourMap = currentWeather.skyboxGradColourMap
val lightColourMap = currentWeather.globalLightColourMap
diff --git a/work_files/romapidoc/api_machine.tex b/work_files/romapidoc/api_machine.tex
new file mode 100644
index 000000000..3ee52eff3
--- /dev/null
+++ b/work_files/romapidoc/api_machine.tex
@@ -0,0 +1,8 @@
+The Machine API provides means to control the machine itself.
+
+\begin{tabularx}{\textwidth}{l l X}
+ \textbf{\large Function} & \textbf{\large Return} & \textbf{\large Description}
+ \\ \\
+ \endhead
+ machine.milliTime() & int & Returns how many time the machine is up, in milliseconds (one thousandth of seconds).
+\end{tabularx}
\ No newline at end of file
diff --git a/work_files/romapidoc/api_os.tex b/work_files/romapidoc/api_os.tex
new file mode 100644
index 000000000..d5939531c
--- /dev/null
+++ b/work_files/romapidoc/api_os.tex
@@ -0,0 +1,33 @@
+The OS library provides functions and constants for the system. Most of the functions in the standard Lua are faithfully reconstructed, but there are some functions that behaves differently.
+
+\begin{tabularx}{\textwidth}{l l X}
+ \textbf{\large Function} & \textbf{\large Return} & \textbf{\large Description}
+ \\ \\
+ \endhead
+ os.clock() & number & Returns time passed since the computer is on.
+ \\ \\
+ os.date(format: string) & string & Returns world's current time in desired format, or default if no arguments are provided. NOTE: displaying different time is not possible; Lua's TIME\_T is only 32 bit, world's history can be much longer.
+\end{tabularx}
+
+\subsection{Date Format String}
+
+\begin{tabularx}{\textwidth}{c X c X}
+ \textbf{\large } & \textbf{\large Description} & \textbf{\large } & \textbf{\large Description}
+ \\ \\
+ \endhead
+ \textbf{\%a} & Short day name. (e.g. ``Tys'') & \textbf{\%A} & Full day name. (e.g. ``Tysdag'')
+ \\ \\
+ \textbf{\%b} & Short month name. (e.g. ``Gran'') & \textbf{\%B} & Full month name. (e.g. ``Granite'')
+ \\ \\
+ \textbf{\%c} & Date and time. (e.g. ``25-03-12 08:30:00'') & \textbf{\%d} & Current days.
+ \\ \\
+ \textbf{\%H} & Current hours. & \textbf{\%M} & Current minutes.
+ \\ \\
+ \textbf{\%m} & Current months. & \textbf{\%S} & Current seconds.
+ \\ \\
+ \textbf{\%w} & Current day of week in int. & \textbf{\%x} & Full date. (e.g. ``25-03-12'')
+ \\ \\
+ \textbf{\%X} & Full clock time. (e.g. ``08:30:00'') & \textbf{\%Y} & Current year. (e.g. ``125'')
+ \\ \\
+ \textbf{\%y} & Last two digits of current year. (e.g. ``25'') & \textbf{\%\%} & Per cent mark.
+\end{tabularx}
\ No newline at end of file
diff --git a/work_files/romapidoc/api_terminal.tex b/work_files/romapidoc/api_terminal.tex
index bb1a21848..18ee91795 100644
--- a/work_files/romapidoc/api_terminal.tex
+++ b/work_files/romapidoc/api_terminal.tex
@@ -20,6 +20,8 @@ Note: cursor coordinates starts from one, not zero.
\\ \\
term.scroll(\textbf{n}: int) & nil & Make a new line \textbf{n} times.
\\ \\
+ term.bell(pattern: string) & nil & Strikes a bell. Go to section \emph{Lua Globals} > \emph{Bell Codes} for accepted patterns.
+ \\ \\
term.isTeletype() & bool & Returns \textbf{true} if the terminal is teletype.
\\ \\
\multicolumn{3}{c}{\textbf{Graphic terminals only}}
@@ -95,7 +97,7 @@ Character 0x9E (currency symbol) and 0xFA (middle dot) can be accessed with foll
\textbf{\large No.} & \textbf{\large Description} & \textbf{\large No.} & \textbf{\large Description}
\\ \\
\endhead
- 7 & BEL. Emits short beep. & 8 & BS. Moves cursor to left 1 character.
+ 7 & BEL. Emits short emitTone. & 8 & BS. Moves cursor to left 1 character.
\\ \\
9 & TAB. Inserts appropriate horizontal space. Tab size is variable. & 10 & LF. Prints a new line.
\\ \\
diff --git a/work_files/romapidoc/luaglobals.tex b/work_files/romapidoc/luaglobals.tex
index 40d8ee2ce..3c48d9d17 100644
--- a/work_files/romapidoc/luaglobals.tex
+++ b/work_files/romapidoc/luaglobals.tex
@@ -8,7 +8,7 @@ ROMBASIC adds global functions and constants for operability.
\endhead
\unemph{\_G.}runScript(\textbf{fun}: str, \textbf{env}: str) & nil & Runs Lua script \textbf{fun} with the environment tag \textbf{env}.
\\ \\
- \unemph{\_G.}bell(\textbf{pattern}: str) & nil & Strike bell (or beeper) with pattern. See section \emph{Bell Codes} for more information. Aliased to \unemph{\_G.}beep.
+ \unemph{\_G.}bell(\textbf{pattern}: str) & nil & Strike bell (or beeper) with pattern. See section \emph{Bell Codes} for more information. Aliased to \unemph{\_G.}emitTone.
\\ \\
computer.totalMemory() & int & Returns the total size of the memory installed in the computer, in bytes.
\\ \\
@@ -51,7 +51,7 @@ ROMBASIC adds global functions and constants for operability.
\\ \\
computer.OEM & string & Manufacturer of the computer. If you \emph{are} a manufacturer, you may want to fill in this variable with your own company's name.
\\ \\
- computer.beep(\textbf{len}, \textbf{freq}) & nil & Generates square wave. \textbf{len} is integer, in milliseconds, \textbf{freq} is number, in Hertz.
+ computer.emitTone(\textbf{len}, \textbf{freq}) & nil & Generates square wave. \textbf{len} is integer, in milliseconds, \textbf{freq} is number, in Hertz.
\end{tabularx}
\subsection{Bell Codes}
@@ -59,9 +59,9 @@ ROMBASIC adds global functions and constants for operability.
Bell Codes are patterns for driving bell/beeper. Each code is followed by short break of 50 milliseconds.
\begin{tabularx}{\textwidth}{l X l X}
- \textbf{.} (dot) & Short beep. 50 ms & \textbf{-} (dash) & Medium beep. 200 ms
+ \textbf{.} (dot) & Short emitTone. 80 ms & \textbf{-} (dash) & Medium emitTone. 200 ms
\\ \\
- \textbf{=} (equal) & Long beep. 500 ms & \textbf{,} (comma) & Short break. 50 ms
+ \textbf{=} (equal) & Long emitTone. 500 ms & \textbf{,} (comma) & Short break. 50 ms
\\ \\
(space) & Break. 200 ms
\end{tabularx}
\ No newline at end of file
diff --git a/work_files/romapidoc/romapidoc.aux b/work_files/romapidoc/romapidoc.aux
index 41e998df7..a29ce1b79 100644
--- a/work_files/romapidoc/romapidoc.aux
+++ b/work_files/romapidoc/romapidoc.aux
@@ -49,28 +49,39 @@
\@writefile{toc}{\contentsline {section}{\numberline {1.4}Keys}{11}{section.1.4}}
\@writefile{toc}{\contentsline {subsection}{\numberline {1.4.1}Accepted Key Names}{11}{subsection.1.4.1}}
\gdef \LT@vi {\LT@entry
+ {2}{104.04007pt}\LT@entry
+ {2}{45.37001pt}\LT@entry
+ {1}{185.58992pt}}
+\gdef \LT@vii {\LT@entry
+ {2}{29.40001pt}\LT@entry
+ {1}{138.0pt}\LT@entry
+ {2}{29.6pt}\LT@entry
+ {1}{138.0pt}}
+\@writefile{toc}{\contentsline {section}{\numberline {1.5}OS}{12}{section.1.5}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.5.1}Date Format String}{12}{subsection.1.5.1}}
+\gdef \LT@viii {\LT@entry
{2}{136.82pt}\LT@entry
{1}{45.25516pt}\LT@entry
{1}{152.92484pt}}
-\@writefile{toc}{\contentsline {section}{\numberline {1.5}Security}{12}{section.1.5}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {1.5.1}Functions}{12}{subsection.1.5.1}}
-\gdef \LT@vii {\LT@entry
+\@writefile{toc}{\contentsline {section}{\numberline {1.6}Security}{13}{section.1.6}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.6.1}Functions}{13}{subsection.1.6.1}}
+\gdef \LT@ix {\LT@entry
{2}{102.18004pt}\LT@entry
{1}{45.25516pt}\LT@entry
{2}{180.42001pt}}
-\@writefile{toc}{\contentsline {section}{\numberline {1.6}Shell}{13}{section.1.6}}
-\gdef \LT@viii {\LT@entry
+\@writefile{toc}{\contentsline {section}{\numberline {1.7}Shell}{14}{section.1.7}}
+\gdef \LT@x {\LT@entry
{2}{161.65002pt}\LT@entry
{1}{45.25516pt}\LT@entry
{1}{128.09482pt}}
-\@writefile{toc}{\contentsline {section}{\numberline {1.7}Speaker}{14}{section.1.7}}
-\gdef \LT@ix {\LT@entry
+\@writefile{toc}{\contentsline {section}{\numberline {1.8}Speaker}{15}{section.1.8}}
+\gdef \LT@xi {\LT@entry
{2}{139.76003pt}\LT@entry
{1}{45.25516pt}\LT@entry
{1}{149.98482pt}}
-\@writefile{toc}{\contentsline {section}{\numberline {1.8}Terminal}{15}{section.1.8}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {1.8.1}Functions}{15}{subsection.1.8.1}}
-\gdef \LT@x {\LT@entry
+\@writefile{toc}{\contentsline {section}{\numberline {1.9}Terminal}{16}{section.1.9}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.9.1}Functions}{16}{subsection.1.9.1}}
+\gdef \LT@xii {\LT@entry
{1}{22.26001pt}\LT@entry
{1}{39.16003pt}\LT@entry
{1}{22.26001pt}\LT@entry
@@ -79,64 +90,69 @@
{1}{49.88002pt}\LT@entry
{1}{22.26001pt}\LT@entry
{1}{58.02002pt}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {1.8.2}Standard Colours}{17}{subsection.1.8.2}}
-\gdef \LT@xi {\LT@entry
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.9.2}Standard Colours}{18}{subsection.1.9.2}}
+\gdef \LT@xiii {\LT@entry
{1}{28.3155pt}\LT@entry
{1}{139.1845pt}\LT@entry
{1}{28.3155pt}\LT@entry
{1}{139.1845pt}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {1.8.3}Codepage}{18}{subsection.1.8.3}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {1.8.4}Accepted Control Sequences}{18}{subsection.1.8.4}}
-\gdef \LT@xii {\LT@entry
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.9.3}Codepage}{19}{subsection.1.9.3}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.9.4}Accepted Control Sequences}{19}{subsection.1.9.4}}
+\gdef \LT@xiv {\LT@entry
{2}{134.13005pt}\LT@entry
{1}{45.25516pt}\LT@entry
{1}{155.61479pt}}
-\gdef \LT@xiii {\LT@entry
- {2}{118.04002pt}\LT@entry
+\gdef \LT@xv {\LT@entry
+ {2}{135.95003pt}\LT@entry
{2}{36.06001pt}\LT@entry
- {1}{180.89996pt}}
-\@writefile{toc}{\contentsline {section}{\numberline {1.9}Lua Globals}{19}{section.1.9}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {1.9.1}Functions}{19}{subsection.1.9.1}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {1.9.2}Constants}{19}{subsection.1.9.2}}
-\gdef \LT@xiv {\LT@entry
+ {1}{162.98996pt}}
+\@writefile{toc}{\contentsline {section}{\numberline {1.10}Lua Globals}{20}{section.1.10}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.10.1}Functions}{20}{subsection.1.10.1}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.10.2}Constants}{20}{subsection.1.10.2}}
+\gdef \LT@xvi {\LT@entry
{1}{49.09001pt}\LT@entry
- {1}{90.49004pt}\LT@entry
+ {1}{108.52003pt}\LT@entry
{1}{53.81001pt}\LT@entry
- {1}{104.22pt}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {1.9.3}Bell Codes}{20}{subsection.1.9.3}}
-\@writefile{toc}{\contentsline {section}{\numberline {1.10}Changes from Generic Lua Environment}{22}{section.1.10}}
+ {1}{122.25pt}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.10.3}Bell Codes}{22}{subsection.1.10.3}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {1.10.4}Changes from Generic Lua Environment}{22}{subsection.1.10.4}}
+\gdef \LT@xvii {\LT@entry
+ {2}{94.0pt}\LT@entry
+ {1}{45.25516pt}\LT@entry
+ {1}{195.74484pt}}
+\@writefile{toc}{\contentsline {section}{\numberline {1.11}Machine}{23}{section.1.11}}
\@writefile{lof}{\addvspace {10pt}}
\@writefile{lot}{\addvspace {10pt}}
-\@writefile{toc}{\contentsline {chapter}{\chapternumberline {2}Compatibility Layers---ComputerCraft}{23}{chapter.2}}
-\gdef \LT@xv {\LT@entry
+\@writefile{toc}{\contentsline {chapter}{\chapternumberline {2}Compatibility Layers---ComputerCraft}{25}{chapter.2}}
+\gdef \LT@xviii {\LT@entry
{2}{108.45001pt}\LT@entry
{2}{125.76003pt}}
-\@writefile{toc}{\contentsline {section}{\numberline {2.1}Bit}{24}{section.2.1}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {2.1.1}Functions}{24}{subsection.2.1.1}}
-\gdef \LT@xvi {\LT@entry
+\@writefile{toc}{\contentsline {section}{\numberline {2.1}Bit}{26}{section.2.1}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {2.1.1}Functions}{26}{subsection.2.1.1}}
+\gdef \LT@xix {\LT@entry
{1}{77.19011pt}\LT@entry
{1}{68.63008pt}\LT@entry
{1}{76.35007pt}\LT@entry
{1}{76.36005pt}}
-\@writefile{toc}{\contentsline {section}{\numberline {2.2}Colors}{25}{section.2.2}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {2.2.1}Constants}{25}{subsection.2.2.1}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {2.2.2}Functions}{25}{subsection.2.2.2}}
-\@writefile{toc}{\contentsline {section}{\numberline {2.3}Term}{26}{section.2.3}}
-\@writefile{toc}{\contentsline {section}{\numberline {2.4}Filesystem}{27}{section.2.4}}
+\@writefile{toc}{\contentsline {section}{\numberline {2.2}Colors}{27}{section.2.2}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {2.2.1}Constants}{27}{subsection.2.2.1}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {2.2.2}Functions}{27}{subsection.2.2.2}}
+\@writefile{toc}{\contentsline {section}{\numberline {2.3}Term}{28}{section.2.3}}
+\@writefile{toc}{\contentsline {section}{\numberline {2.4}Filesystem}{29}{section.2.4}}
\@writefile{lof}{\addvspace {10pt}}
\@writefile{lot}{\addvspace {10pt}}
-\@writefile{toc}{\contentsline {chapter}{\chapternumberline {3}Compatibility Layers---OpenComputers}{29}{chapter.3}}
+\@writefile{toc}{\contentsline {chapter}{\chapternumberline {3}Compatibility Layers---OpenComputers}{31}{chapter.3}}
\@writefile{lof}{\addvspace {10pt}}
\@writefile{lot}{\addvspace {10pt}}
-\@writefile{toc}{\contentsline {chapter}{\chapternumberline {4}Peripherals}{31}{chapter.4}}
-\gdef \LT@xvii {\LT@entry
+\@writefile{toc}{\contentsline {chapter}{\chapternumberline {4}Peripherals}{33}{chapter.4}}
+\gdef \LT@xx {\LT@entry
{2}{71.78003pt}\LT@entry
{1}{45.25516pt}\LT@entry
{2}{153.90001pt}}
-\@writefile{toc}{\contentsline {section}{\numberline {4.1}Line Printer}{32}{section.4.1}}
-\@writefile{toc}{\contentsline {subsection}{\numberline {4.1.1}Functions}{32}{subsection.4.1.1}}
+\@writefile{toc}{\contentsline {section}{\numberline {4.1}Line Printer}{34}{section.4.1}}
+\@writefile{toc}{\contentsline {subsection}{\numberline {4.1.1}Functions}{34}{subsection.4.1.1}}
\@writefile{lof}{\addvspace {10pt}}
\@writefile{lot}{\addvspace {10pt}}
-\@writefile{toc}{\contentsline {chapter}{\chapternumberline {5}References}{33}{chapter.5}}
-\memsetcounter{lastsheet}{35}
-\memsetcounter{lastpage}{35}
+\@writefile{toc}{\contentsline {chapter}{\chapternumberline {5}References}{35}{chapter.5}}
+\memsetcounter{lastsheet}{37}
+\memsetcounter{lastpage}{37}
diff --git a/work_files/romapidoc/romapidoc.log b/work_files/romapidoc/romapidoc.log
index 2133dc7cf..60e8bbc38 100644
--- a/work_files/romapidoc/romapidoc.log
+++ b/work_files/romapidoc/romapidoc.log
@@ -1,4 +1,4 @@
-This is LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238) (format=lualatex 2015.10.5) 28 SEP 2016 00:42
+This is LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238) (format=lualatex 2015.10.5) 29 SEP 2016 00:19
restricted \write18 enabled.
file:line:error style messages enabled.
**romapidoc.tex
@@ -552,7 +552,7 @@ luatexbase-attr: luatexbase.attributes["luaotfload@cursbase"] = 6
luatexbase-attr: luatexbase.attributes["luaotfload@curscurs"] = 7
luatexbase-attr: luatexbase.attributes["luaotfload@cursdone"] = 8
luatexbase-attr: luatexbase.attributes["luaotfload@state"] = 9
-luaotfload | main : fontloader loaded in 0.032 seconds
+luaotfload | main : fontloader loaded in 0.031 seconds
luatexbase-mcb: inserting 'luaotfload.node_processor'
at position 1 in 'pre_linebreak_filter'
luatexbase-mcb: inserting 'luaotfload.node_processor'
@@ -1515,6 +1515,13 @@ Overfull \hbox (15.58pt too wide) in paragraph at lines 72--72
) [11
+] (./api_os.tex
+Underfull \hbox (badness 10000) in paragraph at lines 33--33
+[][]|\EU2/MyriadPro(0)/m/n/10 Short month name. (e.g.
+ []
+
+) [12
+
] (./api_security.tex
Underfull \hbox (badness 3354) in paragraph at lines 20--20
[][]|\EU2/MyriadPro(0)/m/n/10 Re-turns SHA-256 hash of in-put
@@ -1530,179 +1537,164 @@ Underfull \hbox (badness 2707) in paragraph at lines 20--20
[][]|\EU2/MyriadPro(0)/m/n/10 En-codes in-put string as Base64
[]
-) [12
+) [13
-] (./api_shell.tex) [13
+] (./api_shell.tex) [14
] (./api_speaker.tex
Underfull \hbox (badness 6961) in paragraph at lines 10--10
[][]|\EU2/MyriadPro(0)/m/n/10 En-queues speaker driv-ing
[]
-) [14
+) [15
] (./api_terminal.tex
-Underfull \hbox (badness 2165) in paragraph at lines 66--66
+Underfull \hbox (badness 2165) in paragraph at lines 68--68
\EU2/MyriadPro(0)/m/n/10 nal. Graphic ter-mi-nals also can
[]
-Underfull \hbox (badness 2932) in paragraph at lines 66--66
+Underfull \hbox (badness 2932) in paragraph at lines 68--68
[][]|\EU2/MyriadPro(0)/m/n/10 Re-turns \EU2/MyriadPro(0)/bx/n/10 true \EU2/Myri
adPro(0)/m/n/10 if the ter-mi-nal is
[]
-Underfull \hbox (badness 2772) in paragraph at lines 66--66
+Underfull \hbox (badness 2772) in paragraph at lines 68--68
[][]|\EU2/MyriadPro(0)/m/n/10 Emits \EU2/MyriadPro(0)/bx/n/10 c \EU2/MyriadPro(
0)/m/n/10 into (\EU2/MyriadPro(0)/bx/n/10 x\EU2/MyriadPro(0)/m/n/10 , \EU2/Myri
adPro(0)/bx/n/10 y\EU2/MyriadPro(0)/m/n/10 ), con-trol se-
[]
-Underfull \hbox (badness 3118) in paragraph at lines 66--66
+Underfull \hbox (badness 3118) in paragraph at lines 68--68
\EU2/MyriadPro(0)/m/n/10 ing con-trol se-quences as sym-
[]
-Underfull \hbox (badness 1365) in paragraph at lines 66--66
+Underfull \hbox (badness 1365) in paragraph at lines 68--68
[][]|\EU2/MyriadPro(0)/m/n/10 Clears whole screen buffer and
[]
-Underfull \hbox (badness 5022) in paragraph at lines 66--66
+Underfull \hbox (badness 5022) in paragraph at lines 68--68
[][]|\EU2/MyriadPro(0)/m/n/10 Re-turns cur-rent co-or-di-nates of
[]
-Underfull \hbox (badness 10000) in paragraph at lines 66--66
+Underfull \hbox (badness 10000) in paragraph at lines 68--68
[][]|\EU2/MyriadPro(0)/m/n/10 Re-turns cur-rent fore-ground
[]
-Underfull \hbox (badness 10000) in paragraph at lines 66--66
+Underfull \hbox (badness 10000) in paragraph at lines 68--68
[][]|\EU2/MyriadPro(0)/m/n/10 Re-turns cur-rent back-ground
[]
-[15
+[16
-] [16]
+] [17]
\cpimagew=\skip279
-
+
File: mda.png Graphic file (type png)