diff --git a/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua b/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua index e88d626ce..b37c957cb 100644 --- a/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua +++ b/src/net/torvald/terrarum/virtualcomputer/assets/lua/BOOT.lua @@ -954,7 +954,7 @@ _G._VERSION = "Luaj-jse 3.0.1 (Lua 5.2.3)" _G.EMDASH = string.char(0xC4) _G.UNCHECKED = string.char(0x9C) -- box unchecked _G.CHECKED = string.char(0x9D) -- box checked -_G.MONEYSYM = string.char(0x9E) -- currency sign +_G.MONEY = string.char(0x9E) -- currency sign _G.MIDDOT = string.char(0xFA) -- middle dot sign _G.DC1 = string.char(17) -- black _G.DC2 = string.char(18) -- white @@ -988,6 +988,7 @@ computer.verbose = true -- print debug info computer.loadedCLayer = {} -- list of loaded compatibility layers computer.bootloader = "/boot/efi" computer.OEM = "" +computer.beep = emittone computer.totalMemory = _G.totalMemory local getMemory = function() collectgarbage() diff --git a/src/net/torvald/terrarum/virtualcomputer/computer/BaseTerrarumComputer.kt b/src/net/torvald/terrarum/virtualcomputer/computer/BaseTerrarumComputer.kt index 02a1f22ab..2891c841d 100644 --- a/src/net/torvald/terrarum/virtualcomputer/computer/BaseTerrarumComputer.kt +++ b/src/net/torvald/terrarum/virtualcomputer/computer/BaseTerrarumComputer.kt @@ -131,6 +131,9 @@ class BaseTerrarumComputer() { // computer-related global functions luaJ_globals["totalMemory"] = LuaFunGetTotalMem(this) + + luaJ_globals["computer"] = LuaTable() + luaJ_globals["emittone"] = ComputerEmitTone(this) } var threadTimer = 0 @@ -233,7 +236,7 @@ class BaseTerrarumComputer() { } } - class EmitTone(val computer: BaseTerrarumComputer) : TwoArgFunction() { + class ComputerEmitTone(val computer: BaseTerrarumComputer) : TwoArgFunction() { override fun call(millisec: LuaValue, freq: LuaValue): LuaValue { computer.playTone(millisec.toint(), freq.tofloat()) return LuaValue.NONE @@ -251,18 +254,27 @@ class BaseTerrarumComputer() { /** * @param duration : milliseconds + * @param rampUp + * @param rampDown + * + * ,---. (true, true) ,---- (true, false) ----. (false, true) ----- (false, false) */ - private fun makeAudioData(duration: Int, freq: Float): ByteBuffer { + private fun makeAudioData(duration: Int, freq: Float, + rampUp: Boolean = true, rampDown: Boolean = true): ByteBuffer { val audioData = BufferUtils.createByteBuffer(duration.times(sampleRate).div(1000)) val realDuration = duration * sampleRate / 1000 - val chopSize = freq * 2f / sampleRate + val chopSize = freq / sampleRate val amp = Math.max(4600f / freq, 1f) - val nHarmonics = 2 + val nHarmonics = if (freq >= 5400) 1 + else if (freq >= 3600) 2 + else if (freq >= 1800) 3 + else 4 - val transitionThre = 2300f + val transitionThre = 1150f + // TODO volume ramping? if (freq == 0f) { for (x in 0..realDuration - 1) { audioData.put(0x00.toByte()) @@ -270,7 +282,7 @@ class BaseTerrarumComputer() { } else if (freq < transitionThre) { // chopper generator (for low freq) for (x in 0..realDuration - 1) { - var sine: Float = amp * FastMath.cos(FastMath.PI * x * chopSize) + var sine: Float = amp * FastMath.cos(FastMath.TWO_PI * x * chopSize) if (sine > 1f) sine = 1f else if (sine < -1f) sine = -1f audioData.put( @@ -281,9 +293,8 @@ class BaseTerrarumComputer() { else { // harmonics generator (for high freq) for (x in 0..realDuration - 1) { var sine: Float = 0f - for (k in 0..nHarmonics) { // mix only odd harmonics to make squarewave - sine += (1f / (2*k + 1)) * - FastMath.sin((2 * k + 1) * FastMath.PI * x * chopSize) + for (k in 1..nHarmonics) { // mix only odd harmonics in order to make a squarewave + sine += FastMath.sin(FastMath.TWO_PI * (2*k - 1) * chopSize * x) / (2*k - 1) } audioData.put( (0.5f + 0.5f * sine).times(0xFF).toByte() diff --git a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt index 25a945e00..274cd1eb8 100644 --- a/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt +++ b/src/net/torvald/terrarum/virtualcomputer/terminal/SimpleTextTerminal.kt @@ -124,7 +124,7 @@ open class SimpleTextTerminal( // complete beep queue if (beepCursor >= beepQueue.size) { clearBeepQueue() - println("!! Beep queue clear") + // println("!! Beep queue clear") } // actually play queue @@ -345,7 +345,7 @@ open class SimpleTextTerminal( * @param freg: Frequency (float) */ override fun beep(duration: Int, freq: Float) { - println("!! Beep playing row $beepCursor, d ${Math.min(duration, maxDuration)} f $freq") + // println("!! Beep playing row $beepCursor, d ${Math.min(duration, maxDuration)} f $freq") host.playTone(Math.min(duration, maxDuration), freq) } diff --git a/work_files/romapidoc/api_terminal.tex b/work_files/romapidoc/api_terminal.tex index 081a7c86c..bb1a21848 100644 --- a/work_files/romapidoc/api_terminal.tex +++ b/work_files/romapidoc/api_terminal.tex @@ -87,7 +87,7 @@ Non-colour terminals support colour index of 0--3. \begin{center}\includegraphics[width=\cpimagew]{mda.png}\end{center} -Character 0x9E (currency symbol) and 0xFA (middle dot) can be accessed with following Lua constants: \emph{MONEYSYM} and \emph{MIDDOT}. See \emph{Lua Globals} > \emph{Constants} section. +Character 0x9E (currency symbol) and 0xFA (middle dot) can be accessed with following Lua constants: \emph{MONEY} and \emph{MIDDOT}. See \emph{Lua Globals} > \emph{Constants} section. \subsection{Accepted Control Sequences} diff --git a/work_files/romapidoc/luaglobals.tex b/work_files/romapidoc/luaglobals.tex index ddc56af53..894ef2a81 100644 --- a/work_files/romapidoc/luaglobals.tex +++ b/work_files/romapidoc/luaglobals.tex @@ -8,6 +8,8 @@ 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. Accepted pattern letters: . - (space) Aliased to \unemph{\_G.}beep. + \\ \\ computer.totalMemory() & int & Returns the total size of the memory installed in the computer, in bytes. \\ \\ computer.freeMemory() & int & Returns the amount of free memory on the computer. @@ -25,7 +27,7 @@ ROMBASIC adds global functions and constants for operability. \\ \\ \unemph{\_G.}CHECKED & string & Checked checkbox. Code 0x9D \\ \\ - \unemph{\_G.}MONEYSYM & string & Currency symbol used in the world. Code 0x9E + \unemph{\_G.}MONEY & string & Currency symbol used in the world. Code 0x9E \\ \\ \unemph{\_G.}MIDDOT & string & Middle dot used in typography. Code 0xFA (note: 0xF9 is a Dot Product used in Mathematics) \\ \\ @@ -48,4 +50,6 @@ ROMBASIC adds global functions and constants for operability. computer.bootloader & string & Path to the boot file. Should point to the EFI (/boot/efi). \\ \\ 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. \end{tabularx} \ No newline at end of file diff --git a/work_files/romapidoc/romapidoc.aux b/work_files/romapidoc/romapidoc.aux index 0f10373cc..8a6e06ea3 100644 --- a/work_files/romapidoc/romapidoc.aux +++ b/work_files/romapidoc/romapidoc.aux @@ -87,9 +87,9 @@ {1}{45.25516pt}\LT@entry {1}{155.61479pt}} \gdef \LT@xii {\LT@entry - {2}{111.63007pt}\LT@entry + {2}{118.04002pt}\LT@entry {2}{36.06001pt}\LT@entry - {1}{187.30992pt}} + {1}{180.89996pt}} \@writefile{toc}{\contentsline {section}{\numberline {1.8}Lua Globals}{18}{section.1.8}} \@writefile{toc}{\contentsline {subsection}{\numberline {1.8.1}Functions}{18}{subsection.1.8.1}} \@writefile{toc}{\contentsline {subsection}{\numberline {1.8.2}Constants}{18}{subsection.1.8.2}} diff --git a/work_files/romapidoc/romapidoc.log b/work_files/romapidoc/romapidoc.log index d3c7620fa..2dda7dfa0 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) 26 SEP 2016 12:12 +This is LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238) (format=lualatex 2015.10.5) 27 SEP 2016 00:50 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.031 seconds +luaotfload | main : fontloader loaded in 0.029 seconds luatexbase-mcb: inserting 'luaotfload.node_processor' at position 1 in 'pre_linebreak_filter' luatexbase-mcb: inserting 'luaotfload.node_processor' @@ -1595,39 +1595,53 @@ Underfull \hbox (badness 6658) in paragraph at lines 109--109 [] ) [17<./mda.png>] (./luaglobals.tex -Underfull \hbox (badness 1092) in paragraph at lines 14--14 +Underfull \hbox (badness 1092) in paragraph at lines 16--16 \EU2/MyriadPro(0)/m/n/10 ory in-stalled in the com-puter, in [] -Underfull \hbox (badness 10000) in paragraph at lines 51--51 +Overfull \hbox (38.91pt too wide) in alignment at lines 55--55 + [] [] [] + [] + + +Underfull \hbox (badness 3168) in paragraph at lines 55--55 +[][]|\EU2/MyriadPro(0)/m/n/10 EM dash rep-re-sented by box-drawing + [] + + +Underfull \hbox (badness 2050) in paragraph at lines 55--55 +[][]|\EU2/MyriadPro(0)/m/n/10 Mid-dle dot used in ty-pog-ra-phy. Code + [] + + +Underfull \hbox (badness 5245) in paragraph at lines 55--55 [][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DC1. Used to [] -Underfull \hbox (badness 10000) in paragraph at lines 51--51 +Underfull \hbox (badness 5245) in paragraph at lines 55--55 [][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DC2. Used to [] -Underfull \hbox (badness 10000) in paragraph at lines 51--51 +Underfull \hbox (badness 5245) in paragraph at lines 55--55 [][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DC3. Used to [] -Underfull \hbox (badness 10000) in paragraph at lines 51--51 +Underfull \hbox (badness 5245) in paragraph at lines 55--55 [][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DC4. Used to [] -Underfull \hbox (badness 10000) in paragraph at lines 51--51 +Underfull \hbox (badness 6364) in paragraph at lines 55--55 [][]|\EU2/MyriadPro(0)/m/n/10 Ascii con-trol se-quence DLE. Used to [] -Underfull \hbox (badness 2781) in paragraph at lines 51--51 -\EU2/MyriadPro(0)/m/n/10 change fore-ground colour to ter-mi-nal’s - [] +Package longtable Warning: Column widths have changed +(longtable) in table 1.12 on input line 55. [18 @@ -1665,9 +1679,13 @@ luaotfload | load : Lookup/name: "MyriadPro" -> "MyriadPro-Bold.otf" [21 \tf@toc=\write5 \openout5 = romapidoc.toc + + +Package longtable Warning: Table widths have changed. Rerun LaTeX. + Package atveryend Info: Empty hook `BeforeClearDocument' on input line 165. Package atveryend Info: Empty hook `AfterLastShipout' on input line 165. - (./romapidoc.aux) +(./romapidoc.aux) Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 165. Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 165. Package rerunfilecheck Info: File `romapidoc.out' has not changed. @@ -1687,7 +1705,7 @@ bute_list, 2 write nodes 67i,12n,59p,1189b,492s stack positions out of 5000i,500n,10000p,200000b,100000s -Output written on romapidoc.pdf (33 pages, 95180 bytes). +Output written on romapidoc.pdf (33 pages, 95556 bytes). PDF statistics: 304 PDF objects out of 1000 (max. 8388607) 255 compressed objects within 3 object streams diff --git a/work_files/romapidoc/romapidoc.pdf b/work_files/romapidoc/romapidoc.pdf index 1187dcc07..93a3d0942 100644 Binary files a/work_files/romapidoc/romapidoc.pdf and b/work_files/romapidoc/romapidoc.pdf differ diff --git a/work_files/romapidoc/romapidoc.synctex.gz b/work_files/romapidoc/romapidoc.synctex.gz index 1c4b58d11..b2ee24313 100644 Binary files a/work_files/romapidoc/romapidoc.synctex.gz and b/work_files/romapidoc/romapidoc.synctex.gz differ