diff --git a/cmd/disasm.go b/cmd/disasm.go index dbfc5e6..0f45bb7 100644 --- a/cmd/disasm.go +++ b/cmd/disasm.go @@ -13,24 +13,19 @@ func main() { endString := flag.String("end", "", "End address") flag.Parse() - startAddress := utils.DecodeCmdLineAddress(startString) - endAddress := utils.DecodeCmdLineAddress(endString) + start := utils.DecodeCmdLineAddress(startString) + end := utils.DecodeCmdLineAddress(endString) - if startAddress == nil { + if start == nil { panic("Must include -start") } - if endAddress == nil { + if end == nil { e := uint16(0xffff) - endAddress = &e + end = &e } cpu.InitInstructionDecoder() mmu.InitApple2eROM() - - cpu.State.PC = *startAddress - for cpu.State.PC <= *endAddress { - cpu.PrintInstruction(false) - cpu.AdvanceInstruction() - } + utils.Disassemble(*start, *end) } diff --git a/cpu/cpu.go b/cpu/cpu.go index 081ae99..e4d51cf 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -851,7 +851,7 @@ func Run(showInstructions bool, breakAddress *uint16, exitAtBreak bool, disableF postProcessIncDec(addressMode) default: - fmt.Printf("Unknown opcode $%02x\n", opcode) + fmt.Printf("Unknown opcode $%02x at %04x\n", opcode, State.PC) return } } diff --git a/utils/utils.go b/utils/utils.go index e8e7d70..0c54a25 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -60,3 +60,15 @@ func RunUntilBreakPoint(t *testing.T, breakAddress uint16, seconds int, showInst t.Fatalf("Did not reach breakpoint at %04x. Got to %04x", breakAddress, cpu.State.PC) } } + +func Disassemble(start uint16, end uint16) { + oldPC := cpu.State.PC + + cpu.State.PC = start + for cpu.State.PC <= end { + cpu.PrintInstruction(false) + cpu.AdvanceInstruction() + } + + cpu.State.PC = oldPC +}