generated from rnentjes/kotlin-server-web-undertow
Refactor PlatformSpecific, update MonTanaMiniComputer and MTMCDisplay logic, add splash screen rendering with SplashData, and optimize observer calls and color initialization.
This commit is contained in:
@@ -18,13 +18,8 @@ class MTMCDisplay(private val computer: MonTanaMiniComputer) {
|
||||
LIGHT(87, 124, 68),
|
||||
LIGHTEST(127, 134, 15);
|
||||
|
||||
val intVal: Int
|
||||
val javaColor: Color
|
||||
|
||||
init {
|
||||
this.intVal = 0xFF shl 24 or (r shl 16) or (g shl 8) or b
|
||||
javaColor = Color(r, g, b)
|
||||
}
|
||||
val intVal: Int = 0xFF shl 24 or (r shl 16) or (g shl 8) or b
|
||||
val javaColor: Color = Color(r, g, b)
|
||||
|
||||
fun distance(r: Int, g: Int, b: Int): Int {
|
||||
val dr = this.r - r
|
||||
@@ -56,15 +51,20 @@ class MTMCDisplay(private val computer: MonTanaMiniComputer) {
|
||||
}
|
||||
|
||||
private fun loadSplashScreen() {
|
||||
/* try {
|
||||
val bytes: ByteArray = Base64.getDecoder().decode(SPLASH_SCREEN)
|
||||
val bais = ByteArrayInputStream(bytes)
|
||||
var img: BufferedImage? = null
|
||||
img = ImageIO.read(bais)
|
||||
loadScaledImage(img)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}*/
|
||||
currentColor = DisplayColor.DARK
|
||||
var currentColorCount = 0
|
||||
var currentColor = 0
|
||||
var colorIndex = 0
|
||||
for (col in 0..<COLS) {
|
||||
for (row in 0..<ROWS) {
|
||||
if (currentColorCount == 0) {
|
||||
currentColorCount = SPLASH_SCREEN_COLORS[colorIndex++]
|
||||
currentColor = SPLASH_SCREEN_COLORS[colorIndex++]
|
||||
}
|
||||
setPixel(col, row, DisplayColor.entries[currentColor])
|
||||
currentColorCount--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadImage(data: ByteArray): BufferedImage? {
|
||||
@@ -107,7 +107,11 @@ class MTMCDisplay(private val computer: MonTanaMiniComputer) {
|
||||
}
|
||||
|
||||
fun setPixel(col: Int, row: Int, color: DisplayColor) {
|
||||
buffer.setRGB(col, row, color.intVal)
|
||||
try {
|
||||
buffer.setRGB(col, row, color.intVal)
|
||||
} catch (e: Throwable) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
fun getPixel(col: Int, row: Int): Short {
|
||||
@@ -173,7 +177,7 @@ class MTMCDisplay(private val computer: MonTanaMiniComputer) {
|
||||
//computer.notifyOfDisplayUpdate()
|
||||
}
|
||||
|
||||
fun toPng(): ByteArray? {
|
||||
fun toPng(): ByteArray {
|
||||
return byteArray
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ class MonTanaMiniComputer {
|
||||
registerFile = ShortArray(Register.entries.size)
|
||||
memory = ByteArray(MEMORY_SIZE)
|
||||
breakpoints = ByteArray(MEMORY_SIZE)
|
||||
rewindIndex = -1
|
||||
setRegisterValue(
|
||||
Register.SP,
|
||||
MEMORY_SIZE.toShort().toInt()
|
||||
@@ -792,7 +791,7 @@ class MonTanaMiniComputer {
|
||||
val currentValue = memory[address]
|
||||
addRewindStep { memory[address] = currentValue }
|
||||
memory[address] = value
|
||||
observers!!.forEach { o: MTMCObserver? ->
|
||||
observers.forEach { o: MTMCObserver? ->
|
||||
o!!.memoryUpdated(address, value)
|
||||
}
|
||||
}
|
||||
@@ -816,7 +815,7 @@ class MonTanaMiniComputer {
|
||||
registerFile[register] = currentValue
|
||||
}
|
||||
registerFile[register] = value.toShort()
|
||||
observers!!.forEach { o: MTMCObserver? ->
|
||||
observers.forEach { o: MTMCObserver? ->
|
||||
o!!.registerUpdated(register, value)
|
||||
}
|
||||
}
|
||||
|
||||
1727
src/commonMain/kotlin/mtmc/emulator/SplashData.kt
Normal file
1727
src/commonMain/kotlin/mtmc/emulator/SplashData.kt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -11,12 +11,14 @@ val mainView = MTMCView(computer)
|
||||
val display = DisplayView(computer)
|
||||
|
||||
fun main() {
|
||||
computer.speed = 2000000 // default to 1hz
|
||||
computer.speed = 1000000
|
||||
computer.load(lifeCode, lifeData)
|
||||
//computer.load(snakeCode, snakeData)
|
||||
|
||||
Komponent.create(document.body!!, mainView)
|
||||
|
||||
computer.start()
|
||||
|
||||
mainView.requestUpdate()
|
||||
display.requestUpdate()
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ actual fun requestAnimationFrame(action: (Double) -> Unit) {
|
||||
action(it)
|
||||
|
||||
display.requestUpdate()
|
||||
if (currentTimeMillis() - lastMemoryUpdate > 100) {
|
||||
if (currentTimeMillis() - lastMemoryUpdate > 125) {
|
||||
mainView.registerView.requestUpdate()
|
||||
mainView.memoryView.requestUpdate()
|
||||
lastMemoryUpdate = currentTimeMillis()
|
||||
|
||||
@@ -1,18 +1,69 @@
|
||||
package mtmc.view
|
||||
|
||||
import kotlinx.html.div
|
||||
import kotlinx.html.i
|
||||
import kotlinx.html.span
|
||||
import mtmc.emulator.MonTanaMiniComputer
|
||||
import nl.astraeus.komp.HtmlBuilder
|
||||
import nl.astraeus.komp.Komponent
|
||||
import kotlin.text.Typography.nbsp
|
||||
|
||||
class ControlView(
|
||||
val computer: MonTanaMiniComputer
|
||||
) : Komponent() {
|
||||
|
||||
override fun HtmlBuilder.render() {
|
||||
div {
|
||||
+"Controls view"
|
||||
/*
|
||||
<div id="control-secondary">
|
||||
MonTana Mini-Computer
|
||||
</div>
|
||||
<div id="control-buttons">
|
||||
<label>
|
||||
<select style="font-family: monospace;background-color: black;color: #ffcc00" name="speed" fx-action="/speed" fx-method="post" fx-swap="outerHTML" fx-target="#controls">
|
||||
<option value="1">1 Hz</option>
|
||||
<option value="10">10 Hz</option>
|
||||
<option value="100">100 Hz</option>
|
||||
<option value="1000">1 Khz</option>
|
||||
<option value="1000000" selected="">1 Mhz</option>
|
||||
</select>
|
||||
</label>
|
||||
<button fx-action="/control/run" fx-method="post" fx-swap="none">
|
||||
run
|
||||
</button>
|
||||
<button fx-action="/control/back" fx-method="post" fx-swap="outerHTML" fx-target="#controls" disabled="disabled">
|
||||
back
|
||||
</button>
|
||||
<button fx-action="/control/step" fx-method="post" fx-swap="outerHTML" fx-target="#controls">
|
||||
step
|
||||
</button>
|
||||
<button fx-action="/control/reset" fx-method="post" fx-swap="outerHTML" fx-target="#controls">
|
||||
reset
|
||||
</button>
|
||||
</div>
|
||||
*/
|
||||
|
||||
div("control-panel") {
|
||||
div("control-header") {
|
||||
span {
|
||||
+"m"
|
||||
}
|
||||
span {
|
||||
+"s"
|
||||
}
|
||||
span {
|
||||
+"u"
|
||||
}
|
||||
nbsp
|
||||
i {
|
||||
+"MTMC-16"
|
||||
}
|
||||
}
|
||||
div("control-secondary") {
|
||||
|
||||
}
|
||||
div("control-buttons") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
root {
|
||||
--pdp-blue: #243571;
|
||||
--pdp-light-blue: #3286ce;
|
||||
--pdp-beige: #fdfddc;
|
||||
--pdp-white: #f1f1f6;
|
||||
--pdp-off-white: #F0EBCD;
|
||||
--filetree-gray: #666;
|
||||
}
|
||||
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
@@ -52,6 +61,18 @@ body {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* control */
|
||||
|
||||
.control-header {
|
||||
background-color: var(--pdp-blue);
|
||||
color: var(--pdp-white);
|
||||
font-family: monospace;
|
||||
font-size: 32px;
|
||||
padding: 4px 24px;
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
/* registers */
|
||||
|
||||
table.register-table {
|
||||
|
||||
Reference in New Issue
Block a user