2019-09-15 03:04:57 +00:00
|
|
|
package razorvine.examplemachine
|
|
|
|
|
|
|
|
import kotlin.concurrent.scheduleAtFixedRate
|
|
|
|
import razorvine.ksim65.Bus
|
|
|
|
import razorvine.ksim65.Cpu6502
|
|
|
|
import razorvine.ksim65.Version
|
|
|
|
import razorvine.ksim65.components.*
|
2019-09-18 00:00:29 +00:00
|
|
|
import javax.swing.ImageIcon
|
2019-09-15 03:04:57 +00:00
|
|
|
|
|
|
|
/**
|
2019-09-18 23:22:11 +00:00
|
|
|
* A virtual computer constructed from the various virtual components,
|
|
|
|
* running the 6502 Enhanced Basic ROM.
|
2019-09-15 03:04:57 +00:00
|
|
|
*/
|
2019-09-18 23:22:11 +00:00
|
|
|
class EhBasicMachine(title: String) {
|
2019-09-15 03:04:57 +00:00
|
|
|
val bus = Bus()
|
|
|
|
val cpu = Cpu6502(false)
|
2019-09-18 23:22:11 +00:00
|
|
|
val ram = Ram(0x0000, 0xbfff)
|
|
|
|
val rom = Rom(0xc000, 0xffff).also { it.load(javaClass.getResourceAsStream("/ehbasic_C000.bin").readAllBytes()) }
|
2019-09-15 03:04:57 +00:00
|
|
|
|
|
|
|
private val hostDisplay = MainWindow(title)
|
|
|
|
private val display = Display(0xd000, 0xd00a, hostDisplay,
|
|
|
|
ScreenDefs.SCREEN_WIDTH_CHARS, ScreenDefs.SCREEN_HEIGHT_CHARS,
|
|
|
|
ScreenDefs.SCREEN_WIDTH, ScreenDefs.SCREEN_HEIGHT)
|
|
|
|
private val keyboard = Keyboard(0xd400, 0xd400, hostDisplay)
|
|
|
|
|
|
|
|
init {
|
2019-09-18 00:00:29 +00:00
|
|
|
hostDisplay.iconImage = ImageIcon(javaClass.getResource("/icon.png")).image
|
|
|
|
|
2019-09-15 03:04:57 +00:00
|
|
|
bus += display
|
|
|
|
bus += keyboard
|
2019-09-18 23:22:11 +00:00
|
|
|
bus += rom
|
2019-09-15 03:04:57 +00:00
|
|
|
bus += ram
|
|
|
|
bus += cpu
|
|
|
|
bus.reset()
|
|
|
|
|
|
|
|
hostDisplay.start()
|
2019-09-18 23:22:11 +00:00
|
|
|
hostDisplay.requestFocus()
|
2019-09-15 03:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var paused = false
|
|
|
|
|
2019-09-16 00:31:48 +00:00
|
|
|
fun stepInstruction() {
|
|
|
|
while (cpu.instrCycles > 0) bus.clock()
|
|
|
|
bus.clock()
|
|
|
|
while (cpu.instrCycles > 0) bus.clock()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun start() {
|
|
|
|
val timer = java.util.Timer("clock", true)
|
|
|
|
timer.scheduleAtFixedRate(1, 1) {
|
|
|
|
if(!paused) {
|
2019-09-18 23:22:11 +00:00
|
|
|
repeat(500) {
|
2019-09-16 00:31:48 +00:00
|
|
|
stepInstruction()
|
|
|
|
}
|
|
|
|
}
|
2019-09-15 03:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun main(args: Array<String>) {
|
2019-09-18 23:22:11 +00:00
|
|
|
val machine = EhBasicMachine("KSim65 demo virtual machine - using ksim65 v${Version.version}")
|
2019-09-16 00:31:48 +00:00
|
|
|
machine.start()
|
2019-09-15 03:04:57 +00:00
|
|
|
}
|