2019-09-11 00:39:58 +00:00
|
|
|
package razorvine.ksim65.components
|
2019-09-11 00:17:59 +00:00
|
|
|
|
|
|
|
/**
|
2019-09-14 19:11:20 +00:00
|
|
|
* A simple parallel output device (basically, prints bytes as characters to the console)
|
|
|
|
*
|
2019-09-15 03:04:57 +00:00
|
|
|
* reg. value
|
2019-09-14 19:11:20 +00:00
|
|
|
* ---- ---------
|
|
|
|
* 00 data (the 8 parallel bits)
|
|
|
|
* 01 control latch (set bit 0 to write the data byte)
|
2019-09-11 00:17:59 +00:00
|
|
|
*/
|
|
|
|
class ParallelPort(startAddress: Address, endAddress: Address) : MemMappedComponent(startAddress, endAddress) {
|
2019-09-14 16:58:45 +00:00
|
|
|
private var dataByte: UByte = 0
|
2019-09-11 00:17:59 +00:00
|
|
|
|
|
|
|
init {
|
2019-10-12 10:35:18 +00:00
|
|
|
require(endAddress-startAddress+1 == 2) { "parallel needs exactly 2 memory bytes (data + control)" }
|
2019-09-11 00:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun clock() {}
|
|
|
|
override fun reset() {}
|
|
|
|
|
2020-02-05 00:02:27 +00:00
|
|
|
override operator fun get(offset: Int): UByte {
|
|
|
|
return if (offset == 0) dataByte
|
2019-10-12 10:35:18 +00:00
|
|
|
else 0xff
|
2019-09-11 00:17:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 00:02:27 +00:00
|
|
|
override operator fun set(offset: Int, data: UByte) {
|
|
|
|
if (offset == 0) dataByte = data
|
|
|
|
else if (offset == 1) {
|
2019-09-11 00:17:59 +00:00
|
|
|
if ((data.toInt() and 1) == 1) {
|
2021-07-06 21:37:19 +00:00
|
|
|
val char = dataByte.toInt().toChar()
|
2019-09-11 00:17:59 +00:00
|
|
|
println("PARALLEL WRITE: '$char'")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|