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() {}
|
|
|
|
|
2020-02-05 00:02:27 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 00:02:27 +00:00
|
|
|
override operator fun set(offset: Int, data: UByte) { /* read-only device */ }
|
2019-09-15 03:04:57 +00:00
|
|
|
}
|