1
0
mirror of https://github.com/irmen/ksim65.git synced 2024-06-13 22:29:29 +00:00
ksim65/src/main/kotlin/razorvine/ksim65/components/Keyboard.kt

35 lines
1.0 KiB
Kotlin
Raw Normal View History

2019-09-15 03:04:57 +00:00
package razorvine.ksim65.components
import razorvine.ksim65.IHostInterface
/**
* Simple keyboard for text entry.
* The keyboard device itself takes care of decoding the keys,
* this device simply produces the actual keys pressed.
* There's NO support right now to detect keydown/keyup events or the
* state of the shift/control/function keys.
*
* reg. value
* ---- ---------
* 00 character from keyboard, 0 = no character/key pressed
*/
class Keyboard(startAddress: Address, endAddress: Address, private val host: IHostInterface) :
2019-10-12 10:35:18 +00:00
MemMappedComponent(startAddress, endAddress) {
2019-09-15 03:04:57 +00:00
init {
2019-10-12 10:35:18 +00:00
require(endAddress-startAddress+1 == 1) { "keyboard needs exactly 1 memory byte" }
2019-09-15 03:04:57 +00:00
}
override fun clock() {}
override fun reset() {}
override operator fun get(offset: Int): UByte {
return when (offset) {
2021-07-06 21:37:19 +00:00
0x00 -> host.keyboard()?.code?.toShort() ?: 0
2019-09-15 03:04:57 +00:00
else -> 0xff
}
}
override operator fun set(offset: Int, data: UByte) { /* read-only device */ }
2019-09-15 03:04:57 +00:00
}