mirror of
https://github.com/irmen/ksim65.git
synced 2024-06-26 18:29:30 +00:00
monitor assembler address now supports '*' and relative addresses to that
This commit is contained in:
parent
3f86d5185e
commit
606a587bb5
|
@ -123,7 +123,7 @@ class Monitor(val bus: Bus, val cpu: Cpu6502) {
|
||||||
// immediate
|
// immediate
|
||||||
val instruction = instructions[Pair(mnemonic, Cpu6502.AddrMode.Imm)] ?: return IVirtualMachine.MonitorCmdResult("?invalid instruction", command, false)
|
val instruction = instructions[Pair(mnemonic, Cpu6502.AddrMode.Imm)] ?: return IVirtualMachine.MonitorCmdResult("?invalid instruction", command, false)
|
||||||
bus.write(address, instruction.toShort())
|
bus.write(address, instruction.toShort())
|
||||||
bus.write(address+1, parseNumber(arg.substring(1), true).toShort())
|
bus.write(address+1, parseNumber(arg.substring(1), decimalFirst = true).toShort())
|
||||||
}
|
}
|
||||||
arg.startsWith("(") && arg.endsWith(",x)") -> {
|
arg.startsWith("(") && arg.endsWith(",x)") -> {
|
||||||
// indirect X
|
// indirect X
|
||||||
|
@ -204,7 +204,7 @@ class Monitor(val bus: Bus, val cpu: Cpu6502) {
|
||||||
if (instr != null) {
|
if (instr != null) {
|
||||||
// relative address
|
// relative address
|
||||||
val rel = try {
|
val rel = try {
|
||||||
parseNumber(arg)
|
parseRelativeToPC(arg, address)
|
||||||
} catch (x: NumberFormatException) {
|
} catch (x: NumberFormatException) {
|
||||||
return IVirtualMachine.MonitorCmdResult("?invalid instruction", command, false)
|
return IVirtualMachine.MonitorCmdResult("?invalid instruction", command, false)
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ class Monitor(val bus: Bus, val cpu: Cpu6502) {
|
||||||
} else {
|
} else {
|
||||||
// absolute or absZp
|
// absolute or absZp
|
||||||
val absAddress = try {
|
val absAddress = try {
|
||||||
parseNumber(arg)
|
parseRelativeToPC(arg, address)
|
||||||
} catch (x: NumberFormatException) {
|
} catch (x: NumberFormatException) {
|
||||||
return IVirtualMachine.MonitorCmdResult("?invalid instruction", command, false)
|
return IVirtualMachine.MonitorCmdResult("?invalid instruction", command, false)
|
||||||
}
|
}
|
||||||
|
@ -240,6 +240,18 @@ class Monitor(val bus: Bus, val cpu: Cpu6502) {
|
||||||
return IVirtualMachine.MonitorCmdResult(disassem.first.single(), "a$${hexW(disassem.second)} ", false)
|
return IVirtualMachine.MonitorCmdResult(disassem.first.single(), "a$${hexW(disassem.second)} ", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseRelativeToPC(relative: String, currentAddress: Int): Int {
|
||||||
|
val rest = relative.substring(1).trimStart()
|
||||||
|
if(rest.any()) {
|
||||||
|
return when(rest[0]) {
|
||||||
|
'-' -> currentAddress-parseNumber(rest.substring(1))
|
||||||
|
'+' -> currentAddress+parseNumber(rest.substring(1))
|
||||||
|
else -> throw Cpu6502.InstructionError("invalid address syntax")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return currentAddress
|
||||||
|
}
|
||||||
|
|
||||||
private fun parseNumber(number: String, decimalFirst: Boolean = false): Int {
|
private fun parseNumber(number: String, decimalFirst: Boolean = false): Int {
|
||||||
val num = number.trim()
|
val num = number.trim()
|
||||||
if (num.isBlank()) return 0
|
if (num.isBlank()) return 0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user