Miscellaneous hacking

This commit is contained in:
2023-09-12 19:30:36 +02:00
parent 83cccea9c7
commit 79efc4e8d3
3 changed files with 39 additions and 8 deletions

View File

@@ -7,16 +7,19 @@ import java.io.File
fun main(args: Array<String>) {
val tb = org.jline.terminal.TerminalBuilder.terminal()
var mbus = MemBus(65536)
var cpu = CPU(mbus)
val console = DL11(tb.input(), tb.output()).apply { mount(mbus.unibus) }
try {
tb.enterRawMode()
var mbus = MemBus(65536)
var cpu = CPU(mbus)
val console = DL11(tb.input(), tb.output()).apply { mount(mbus.unibus) }
console.start()
cpu.loadAbs(File(args[0]))
cpu.runState = CPU.RunState.RUNNING
cpu.run()
} finally {
println("Exiting")
console.stop()
}
}

View File

@@ -9,23 +9,40 @@ import java.io.File
/// Loads an RT-11 object file into memory
fun CPU.loadAbs(infile: File) {
val core = this.core.modeSpace
val inStream = infile.inputStream().buffered()
val inStream = infile.inputStream()
var buf = ByteArray(6)
var offset = 0
var addr: UShort = 0u
var len: Int = 0
var cksum: Int = 0
var pos = 0
// Skip over leading zeros
while (true) {
while(true) {
val b = inStream.read()
pos++
when {
b < 0 -> throw Exception("EOF before data start")
b == 1 -> { inStream.skip(-1); pos--; break }
b == 0 -> continue
else -> throw Exception("Invalid first character")
}
}
var read = inStream.read(buf, 0, 6)
if (read == -1) {
return
}
if (read < 6) {
// TODO: report the error
throw Exception("Short record: $read bytes")
throw Exception("Short record: $read bytes at $pos")
}
if (buf[0] != 1.toByte() || buf[1] != 0.toByte()) {
throw Exception("Invalid block header")
throw Exception("Invalid block header at $pos: ${buf[0]},${buf[1]}")
}
len = buf[3].toInt().shl(8) + buf[2].toInt() - 6
addr = (buf[5].toUByte().toUShort().shl(8) + buf[4].toUByte().toUShort()).toUShort()
@@ -42,9 +59,14 @@ fun CPU.loadAbs(infile: File) {
}
cksum = cksum and 0xFF
// TODO: validate checksum == 0
println("Loading 0x${len.toString(16)} bytes at 0x${addr.toString(16)}")
if (len == 0) {
// end of file
if (!(addr bit 0)) this.pc = addr
println("Tape ended at ${pos+len+7}")
if (!(addr bit 0)){
this.pc = addr
println("Ready to run")
}
return
} else {
// copy data to memory
@@ -53,5 +75,6 @@ fun CPU.loadAbs(infile: File) {
core.setb(addr++, buf[i].toUByte())
}
}
pos += len+7
}
}

View File

@@ -86,8 +86,13 @@ class DL11(private var istr: InputStream, private val ostr: OutputStream, val re
}
override fun start() {
super.start()
reader = thread(block = this::readThread)
reader = thread(block = this::readThread, isDaemon = false)
// reader?.interrupt()
}
override fun stop() {
super.stop()
reader?.interrupt()
}
}