mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
adding BMS display
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.3 KiB |
BIN
assets/lcd.png
BIN
assets/lcd.png
Binary file not shown.
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
100
src/net/torvald/terrarumsansbitmap/gdx/TextureRegionPack.kt
Executable file
100
src/net/torvald/terrarumsansbitmap/gdx/TextureRegionPack.kt
Executable file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Terrarum Sans Bitmap
|
||||
*
|
||||
* Copyright (c) 2017 Minjae Song (Torvald)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.torvald.terrarumsansbitmap.gdx
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-15.
|
||||
*/
|
||||
class TextureRegionPack(
|
||||
val texture: Texture,
|
||||
val tileW: Int,
|
||||
val tileH: Int,
|
||||
val hGap: Int = 0,
|
||||
val vGap: Int = 0,
|
||||
val hFrame: Int = 0,
|
||||
val vFrame: Int = 0,
|
||||
val xySwapped: Boolean = false // because Unicode chart does, duh
|
||||
): Disposable {
|
||||
|
||||
constructor(ref: String, tileW: Int, tileH: Int, hGap: Int = 0, vGap: Int = 0, hFrame: Int = 0, vFrame: Int = 0, xySwapped: Boolean = false) :
|
||||
this(Texture(ref), tileW, tileH, hGap, vGap, hFrame, vFrame, xySwapped)
|
||||
constructor(fileHandle: FileHandle, tileW: Int, tileH: Int, hGap: Int = 0, vGap: Int = 0, hFrame: Int = 0, vFrame: Int = 0, xySwapped: Boolean = false) :
|
||||
this(Texture(fileHandle), tileW, tileH, hGap, vGap, hFrame, vFrame, xySwapped)
|
||||
|
||||
companion object {
|
||||
/** Intented for Y-down coord system, typically fon Non-GDX codebase */
|
||||
var globalFlipY = false
|
||||
}
|
||||
|
||||
val regions: Array<TextureRegion>
|
||||
|
||||
val horizontalCount = (texture.width - 2 * hFrame + hGap) / (tileW + hGap)
|
||||
val verticalCount = (texture.height - 2 * vFrame + vGap) / (tileH + vGap)
|
||||
|
||||
init {
|
||||
//println("texture: $texture, dim: ${texture.width} x ${texture.height}, grid: $horizontalCount x $verticalCount, cellDim: $tileW x $tileH")
|
||||
|
||||
if (!xySwapped) {
|
||||
regions = Array<TextureRegion>(horizontalCount * verticalCount) {
|
||||
val region = TextureRegion()
|
||||
val rx = (it % horizontalCount * (tileW + hGap)) + hFrame
|
||||
val ry = (it / horizontalCount * (tileH + vGap)) + vFrame
|
||||
|
||||
region.setRegion(texture)
|
||||
region.setRegion(rx, ry, tileW, tileH)
|
||||
|
||||
region.flip(false, globalFlipY)
|
||||
|
||||
/*return*/region
|
||||
}
|
||||
}
|
||||
else {
|
||||
regions = Array<TextureRegion>(horizontalCount * verticalCount) {
|
||||
val region = TextureRegion()
|
||||
val rx = (it / verticalCount * (tileW + hGap)) + hFrame
|
||||
val ry = (it % verticalCount * (tileH + vGap)) + vFrame
|
||||
|
||||
region.setRegion(texture)
|
||||
region.setRegion(rx, ry, tileW, tileH)
|
||||
|
||||
region.flip(false, globalFlipY)
|
||||
|
||||
/*return*/region
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun get(x: Int, y: Int) = regions[y * horizontalCount + x]
|
||||
|
||||
override fun dispose() {
|
||||
texture.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package net.torvald.tsvm.peripheral
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUlong
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.tsvm.VM
|
||||
|
||||
class CharacterLCDdisplay(vm: VM) : GraphicsAdapter(vm, AdapterConfig(
|
||||
@@ -11,6 +13,7 @@ class CharacterLCDdisplay(vm: VM) : GraphicsAdapter(vm, AdapterConfig(
|
||||
) {
|
||||
|
||||
private val machine = Texture("./assets/4008_portable_full.png")
|
||||
private val lcdFont = TextureRegionPack(Texture("./assets/lcd.png"), 12, 16)
|
||||
|
||||
override fun peek(addr: Long): Byte? {
|
||||
return when (addr) {
|
||||
@@ -33,10 +36,48 @@ class CharacterLCDdisplay(vm: VM) : GraphicsAdapter(vm, AdapterConfig(
|
||||
batch.draw(machine, xoff, yoff)
|
||||
}
|
||||
super.render(delta, batch, xoff+74, yoff+102)
|
||||
|
||||
// draw BMS and RTC
|
||||
val batPerc = "89"
|
||||
val batVolt = "5.1"
|
||||
val batText = " $batPerc% ${batVolt}V"
|
||||
vm.poke(-69,2)
|
||||
val time_t = currentTimeInMills()
|
||||
val min = (time_t / 60000) % 60
|
||||
val hour = (time_t / 3600000) % 24
|
||||
val clock = "${"$hour".padStart(2,'0')}:${"$min".padStart(2,'0')} "
|
||||
|
||||
batch.shader = null
|
||||
batch.inUse {
|
||||
batch.color = Color.WHITE
|
||||
val y = yoff + 102 + config.height * config.drawScale
|
||||
for (x in 0 until config.textCols) {
|
||||
batch.draw(lcdFont.get(0,0), xoff+74 + x * lcdFont.tileW, y)
|
||||
}
|
||||
for (x in clock.indices) {
|
||||
val ccode = clock[x].toInt()
|
||||
batch.draw(lcdFont.get(ccode % 16, ccode / 16), xoff+74 + x * lcdFont.tileW, y)
|
||||
}
|
||||
for (x in batText.indices) {
|
||||
val ccode = batText[x].toInt()
|
||||
batch.draw(lcdFont.get(ccode % 16, ccode / 16), xoff+74 + (config.textCols - batText.length + x) * lcdFont.tileW, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun currentTimeInMills(): Long {
|
||||
vm.poke(-69, -1)
|
||||
var r = 0L
|
||||
for (i in 0L..7L) {
|
||||
r = r or vm.peek(-81 - i)!!.toUlong().shl(8 * i.toInt())
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
override fun dispose() {
|
||||
machine.dispose()
|
||||
lcdFont.dispose()
|
||||
super.dispose()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user