2019-09-11 00:39:58 +00:00
|
|
|
package razorvine.ksim65.components
|
2019-09-11 00:17:59 +00:00
|
|
|
|
2019-09-11 00:39:58 +00:00
|
|
|
import razorvine.ksim65.c64.Petscii
|
2019-09-11 00:17:59 +00:00
|
|
|
|
|
|
|
typealias UByte = Short
|
|
|
|
typealias Address = Int
|
|
|
|
|
|
|
|
|
|
|
|
abstract class BusComponent {
|
|
|
|
lateinit var bus: Bus
|
|
|
|
|
|
|
|
abstract fun clock()
|
|
|
|
abstract fun reset()
|
|
|
|
}
|
|
|
|
|
2019-09-11 00:19:33 +00:00
|
|
|
abstract class MemMappedComponent(val startAddress: Address, val endAddress: Address) : BusComponent() {
|
2019-09-11 00:17:59 +00:00
|
|
|
abstract operator fun get(address: Address): UByte
|
|
|
|
abstract operator fun set(address: Address, data: UByte)
|
|
|
|
|
|
|
|
init {
|
2019-09-11 00:19:33 +00:00
|
|
|
require(endAddress >= startAddress)
|
|
|
|
require(startAddress >= 0 && endAddress <= 0xffff) { "can only have 16-bit address space" }
|
2019-09-11 00:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fun hexDump(from: Address, to: Address) {
|
2019-09-11 00:19:33 +00:00
|
|
|
(from..to).chunked(16).forEach {
|
2019-09-11 00:17:59 +00:00
|
|
|
print("\$${it.first().toString(16).padStart(4, '0')} ")
|
|
|
|
val bytes = it.map { address -> get(address) }
|
|
|
|
bytes.forEach { byte ->
|
|
|
|
print(byte.toString(16).padStart(2, '0') + " ")
|
|
|
|
}
|
|
|
|
print(" ")
|
|
|
|
print(Petscii.decodeScreencode(bytes, false).replace('\ufffe', '.'))
|
|
|
|
println()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 00:19:33 +00:00
|
|
|
abstract class MemoryComponent(startAddress: Address, endAddress: Address) :
|
|
|
|
MemMappedComponent(startAddress, endAddress) {
|
2019-09-11 00:17:59 +00:00
|
|
|
abstract fun cloneContents(): Array<UByte>
|
|
|
|
}
|