generated from rnentjes/kotlin-server-web-undertow
39 lines
1.0 KiB
Kotlin
39 lines
1.0 KiB
Kotlin
package mtmc.os.shell.builtins
|
|
|
|
import mtmc.emulator.MonTanaMiniComputer
|
|
import mtmc.os.shell.ShellCommand
|
|
import mtmc.tokenizer.MTMCToken
|
|
import mtmc.tokenizer.MTMCTokenizer
|
|
|
|
class SpeedCommand : ShellCommand() {
|
|
private val speeds = listOf(
|
|
1, 10, 100, 1000, 10000, 100000, 1000000
|
|
)
|
|
|
|
@Throws(Exception::class)
|
|
override fun exec(tokens: MTMCTokenizer, computer: MonTanaMiniComputer) {
|
|
if (tokens.match(MTMCToken.TokenType.IDENTIFIER)) {
|
|
computer.speed = 0
|
|
} else if (tokens.match(MTMCToken.TokenType.INTEGER)) {
|
|
val speed = tokens.consumeAsInteger()
|
|
if (!speeds.contains(speed)) {
|
|
usageException()
|
|
}
|
|
computer.speed = speed
|
|
} else {
|
|
usageException()
|
|
}
|
|
}
|
|
|
|
override val help: String
|
|
get() = """
|
|
speed <val> - set the speed of the computer
|
|
where <val> is one of:
|
|
raw - run with no simulated speed delay
|
|
1 - run the computer at 1hz
|
|
10 - run the computer at 10hz
|
|
100 - run the computer at 100hz
|
|
1000 - run the computer at 1khz
|
|
""".trimIndent()
|
|
}
|