mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
http, pcspeaker driver
Former-commit-id: a3ad38695e8c1e1040a6a3f4b8470217e8a98489 Former-commit-id: cd3809edcae7b26e7b3d846dab17f1f63761f30f
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package net.torvald.terrarum.virtualcomputer.peripheral
|
||||
|
||||
import org.luaj.vm2.Globals
|
||||
import org.luaj.vm2.LuaTable
|
||||
import org.luaj.vm2.LuaValue
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-29.
|
||||
*/
|
||||
open class Peripheral(val luaG: Globals, val tableName: String) {
|
||||
|
||||
open fun loadLib() {
|
||||
luaG[tableName] = LuaTable()
|
||||
}
|
||||
open fun unloadLib() {
|
||||
luaG[tableName] = LuaValue.NIL
|
||||
}
|
||||
|
||||
override fun toString(): String = tableName
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.torvald.terrarum.virtualcomputer.peripheral
|
||||
|
||||
import org.luaj.vm2.Globals
|
||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||
import org.luaj.vm2.LuaValue
|
||||
import org.luaj.vm2.lib.OneArgFunction
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import java.net.URL
|
||||
|
||||
/**
|
||||
* Provides internet access.
|
||||
*
|
||||
* Created by minjaesong on 16-09-24.
|
||||
*/
|
||||
internal class PeripheralInternet(val globals: Globals, val host: BaseTerrarumComputer)
|
||||
: Peripheral(globals, "internet"){
|
||||
|
||||
override fun loadLib() {
|
||||
super.loadLib()
|
||||
globals["internet"]["fetch"] = FetchWebPage()
|
||||
}
|
||||
|
||||
class FetchWebPage() : OneArgFunction() {
|
||||
override fun call(urlstr: LuaValue): LuaValue {
|
||||
val url = URL(urlstr.checkjstring())
|
||||
val inputstream = BufferedReader(InputStreamReader(url.openStream()))
|
||||
|
||||
var inline = ""
|
||||
var readline = inputstream.readLine()
|
||||
while (readline != null) {
|
||||
inline += readline
|
||||
readline = inputstream.readLine()
|
||||
}
|
||||
inputstream.close()
|
||||
|
||||
return LuaValue.valueOf(inline)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.torvald.terrarum.virtualcomputer.peripheral
|
||||
|
||||
import net.torvald.terrarum.virtualcomputer.computer.BaseTerrarumComputer
|
||||
import org.luaj.vm2.Globals
|
||||
import org.luaj.vm2.LuaTable
|
||||
import org.luaj.vm2.LuaValue
|
||||
|
||||
/**
|
||||
* Virtual driver for 4-track squarewave PSG, which has no ability of changing a duty cycle
|
||||
* but has a volume control
|
||||
*
|
||||
* Created by minjaesong on 16-09-27.
|
||||
*/
|
||||
internal class PeripheralPSG(val globals: Globals, val host: BaseTerrarumComputer)
|
||||
: Peripheral(globals, "psg") {
|
||||
|
||||
override fun loadLib() {
|
||||
super.loadLib()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user