-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added buttons to select display type #5
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really good change! I just added some comments about the code itself.
<div class="tile is-parent"> | ||
<article class="tile is-child"> | ||
<label>Display Settings</label> | ||
<div class="tabs is-toggle"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this would be better stylistically as a bulma select?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this and I think it looks better as a toggle switch actually, but you are welcome to switch it to the select if you think it is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's keep it as a toggle switch for now.
src/main/kotlin/venus/glue/Driver.kt
Outdated
@@ -155,4 +155,8 @@ import kotlin.browser.window | |||
} | |||
Renderer.updateRegister(id, sim.getReg(id)) | |||
} | |||
|
|||
@JsName("setDisplay") fun render_setDisplay(dis_type: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to camelCase? Also maybe a better name would be setRegisterDisplay
.
@@ -166,7 +168,17 @@ internal object Renderer { | |||
*/ | |||
fun updateRegister(id: Int, value: Int, setActive: Boolean = false) { | |||
val register = getElement("reg-$id-val") as HTMLInputElement | |||
register.value = toHex(value) | |||
var shown_val: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kotlin supports the when
block, so this could be more cleanly written as:
register.value = when (displayType) {
"hex" -> toHex(value)
"dec" -> value.toString()
"unsign" -> toUnsigned(value)
else -> toHex(value)
}
private fun optSetVisibily(opt: String) { | ||
var tabDisplay: HTMLElement? | ||
for (option in opts) { | ||
if (opt.equals(option)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need .equals for strings in Kotlin, just ==
is good. (If you need Object.equals
from Java, that's ===
.)
var tabDisplay: HTMLElement? | ||
for (option in opts) { | ||
if (opt.equals(option)) { | ||
tabDisplay = document.getElementById("$option-opt") as HTMLElement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this line out of the if statement?
for (option in opts) { | ||
if (opt.equals(option)) { | ||
tabDisplay = document.getElementById("$option-opt") as HTMLElement | ||
tabDisplay.className = "is-active" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make this a single line using the if
statement:
tabDisplay.className = if (opt == option) "is-active" else ""
All great changes. Most of the caused by teaching myself Kotlin as I write it 😂 |
The ASCII renders a little weird, but that does make sense since most of ASCII is not human readable. Would like to add ASCII/Hex support at some point similar to MARS, but this should be good for now. |
Thanks for this! I'll take a look when I have the time. |
Okay, so I've made some changes:
I will probably reconsider some of this when I eventually update the memory display. Let me know if you have any suggestions! |
Added buttons to the bottom of the simulator screen that allows the user to choose how the values in registers are displayed (either hex, unsigned decimal, or decimal). This is very nice for debugging.
Currently does not support ASCII or changing the memory's display. These two features to come