more minor changes

This commit is contained in:
minjaesong
2017-06-11 18:01:03 +09:00
parent 687a7f901e
commit 2ca8c2c263
20 changed files with 115 additions and 22 deletions

View File

@@ -537,7 +537,7 @@ class TerrarumComputer(peripheralSlots: Int) {
}
private fun playTone(leninmilli: Int, freq: Double) {
audioData = makeAudioData(leninmilli, freq)
/*audioData = makeAudioData(leninmilli, freq)
if (!AL.isCreated()) AL.create()
@@ -577,7 +577,7 @@ class TerrarumComputer(peripheralSlots: Int) {
}
catch (e: ALException) {
AL10.alDeleteSources(beepSource)
}
}*/
}
// Custom implementation of Util.checkALError() that uses our custom exception.

View File

@@ -12,4 +12,6 @@ abstract class Peripheral(val tableName: String) {
abstract fun loadLib(globals: Globals)
override fun toString(): String = "Peripheral:$tableName"
abstract val memSize: Int
}

View File

@@ -0,0 +1,44 @@
package net.torvald.terrarum.virtualcomputer.peripheral
import net.torvald.terrarum.ModMgr
import org.luaj.vm2.Globals
import org.newdawn.slick.Graphics
import org.newdawn.slick.SpriteSheet
import org.newdawn.slick.SpriteSheetFont
/**
* Created by minjaesong on 2017-05-31.
*/
class PeripheralCharLCD(val width: Int, val height: Int) : Peripheral("charLCD") {
companion object {
private val fontSheet = SpriteSheet(ModMgr.getPath("dwarventech", "mt-32.tga"), 16, 16)
private val font = SpriteSheetFont(fontSheet, 0.toChar())
private val fontW = fontSheet.width / fontSheet.horizontalCount
private val fontH = fontSheet.height / fontSheet.verticalCount
}
override fun loadLib(globals: Globals) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun toString(): String {
return super.toString()
}
override val memSize = width * height
var cursor: Int = 0 // character LCDs are mostly single long line wrapped
val memory = ByteArray(memSize) // temporary; replace with proper VMPeripheralWrapper
/**
* @param g Frame Buffer that holds the display of LCD screen
*/
fun render(g: Graphics) {
g.font = PeripheralCharLCD.font
memory.forEachIndexed { index, byte ->
g.drawString("${byte.toChar()}", (index % width) * fontW.toFloat(), (index / width) * fontH.toFloat())
}
}
}

View File

@@ -17,6 +17,8 @@ import java.net.URL
internal class PeripheralInternet(val host: TerrarumComputer)
: Peripheral("internet"){
override val memSize = 1024
override fun loadLib(globals: Globals) {
globals["internet"] = LuaTable()
globals["internet"]["fetch"] = FetchWebPage()

View File

@@ -14,6 +14,8 @@ import org.luaj.vm2.LuaValue
internal class PeripheralPSG(val host: TerrarumComputer)
: Peripheral("psg") {
override val memSize = 1024
override fun loadLib(globals: Globals) {
globals["psg"] = LuaTable()
}

View File

@@ -83,6 +83,11 @@ class PeripheralVideoCard(val host: TerrarumComputer, val termW: Int = 80, val t
val cursorSprite = ImageBuffer(blockW, blockH * 2)
val cursorImage: Image
override val memSize = 256 * 8 + (width * height * 2) + spritesCount * 16 * 7
// fontRom + framebuffers + sprites
init {
Arrays.fill(cursorSprite.rgba, 0xFF.toByte())
cursorImage = cursorSprite.image