From 63fa147a1638c0aab00405fc5603d77a10a8aa9a Mon Sep 17 00:00:00 2001 From: steve Date: Mon, 2 Jul 2018 18:58:43 +0100 Subject: [PATCH] o debugger - ONHALT now performs the new command sequence straight away - added RAM command - HEX output alongside disassembly --- debugger/commands.go | 3 +++ debugger/debugger.go | 6 ++++++ disassembly/symbols/style.go | 2 +- hardware/cpu/instruction_result.go | 20 +++++++++++++++++++- hardware/memory/pia.go | 27 +++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/debugger/commands.go b/debugger/commands.go index f5a0e834..db63c30c 100644 --- a/debugger/commands.go +++ b/debugger/commands.go @@ -25,6 +25,7 @@ const ( KeywordDebuggerState = "DEBUGGERSTATE" KeywordCPU = "CPU" KeywordPeek = "PEEK" + KeywordRAM = "RAM" KeywordRIOT = "RIOT" KeywordTIA = "TIA" KeywordTV = "TV" @@ -64,6 +65,7 @@ var DebuggerCommands = parser.Commands{ KeywordDebuggerState: parser.CommandArgs{}, KeywordCPU: parser.CommandArgs{}, KeywordPeek: parser.CommandArgs{parser.Arg{Typ: parser.ArgValue, Req: true}}, + KeywordRAM: parser.CommandArgs{}, KeywordRIOT: parser.CommandArgs{}, KeywordTIA: parser.CommandArgs{}, KeywordTV: parser.CommandArgs{}, @@ -104,6 +106,7 @@ var Help = map[string]string{ KeywordDebuggerState: "Display summary of debugger options", KeywordCPU: "Display the current state of the CPU", KeywordPeek: "Inspect an individual memory address", + KeywordRAM: "Display the current contents of PIA RAM", KeywordRIOT: "Display the current state of the RIOT", KeywordTIA: "Display current state of the TIA", KeywordTV: "Display the current TV state", diff --git a/debugger/debugger.go b/debugger/debugger.go index 51646e1c..2e4e472b 100644 --- a/debugger/debugger.go +++ b/debugger/debugger.go @@ -454,6 +454,9 @@ func (dbg *Debugger) parseCommand(input string) (bool, error) { dbg.print(ui.Feedback, "auto-command on halt: %s", dbg.commandOnHalt) + // run the new onhalt command(s) + _, _ = dbg.parseInput(dbg.commandOnHalt) + case KeywordMemMap: dbg.print(ui.MachineInfo, "%v", dbg.vcs.Mem.MemoryMap()) @@ -554,6 +557,9 @@ func (dbg *Debugger) parseCommand(input string) (bool, error) { dbg.print(ui.MachineInfo, s) } + case KeywordRAM: + dbg.printMachineInfo(dbg.vcs.Mem.PIA) + case KeywordRIOT: dbg.printMachineInfo(dbg.vcs.RIOT) diff --git a/disassembly/symbols/style.go b/disassembly/symbols/style.go index 8f59da67..b5b559ff 100644 --- a/disassembly/symbols/style.go +++ b/disassembly/symbols/style.go @@ -18,7 +18,7 @@ const ( // compound styles const ( StyleBrief = StyleFlagSymbols - StyleFull = StyleFlagSymbols | StyleFlagLocation | StyleFlagColumns | StyleFlagNotes + StyleFull = StyleFlagHex | StyleFlagSymbols | StyleFlagLocation | StyleFlagColumns | StyleFlagNotes ) // Has tests to see if style has the supplied flag in its definition diff --git a/hardware/cpu/instruction_result.go b/hardware/cpu/instruction_result.go index e0572464..5cdb3e76 100644 --- a/hardware/cpu/instruction_result.go +++ b/hardware/cpu/instruction_result.go @@ -47,6 +47,7 @@ func columnise(s string, width int) string { // function to implicit calls to String() func (result InstructionResult) GetString(symtable *symbols.Table, style symbols.Style) string { // columns + var hex string var label, programCounter string var operator, operand string var notes string @@ -86,6 +87,21 @@ func (result InstructionResult) GetString(symtable *symbols.Table, style symbols } } + if style.Has(symbols.StyleFlagHex) { + switch result.Defn.Bytes { + case 3: + hex = fmt.Sprintf("%02x", idx&0xff00>>8) + fallthrough + case 2: + hex = fmt.Sprintf("%02x %s", idx&0x00ff, hex) + fallthrough + case 1: + hex = fmt.Sprintf("%02x %s", result.Defn.ObjectCode, hex) + default: + panic("unsupported number of bytes in instruction") + } + } + // ... and use assembler symbol for the operand if available/appropriate if symtable.Valid && style.Has(symbols.StyleFlagSymbols) && result.InstructionData != nil && (operand == "" || operand[0] != '?') { if result.Defn.AddressingMode != definitions.Immediate { @@ -183,6 +199,7 @@ func (result InstructionResult) GetString(symtable *symbols.Table, style symbols // force column widths if style.Has(symbols.StyleFlagColumns) { + hex = columnise(hex, 8) programCounter = columnise(programCounter, 6) operator = columnise(operator, 3) if symtable.Valid { @@ -195,7 +212,8 @@ func (result InstructionResult) GetString(symtable *symbols.Table, style symbols } // build final string - s := fmt.Sprintf("%s %s %s %s %s", + s := fmt.Sprintf("%s %s %s %s %s %s", + hex, label, programCounter, operator, diff --git a/hardware/memory/pia.go b/hardware/memory/pia.go index 67f6f448..159b6a9c 100644 --- a/hardware/memory/pia.go +++ b/hardware/memory/pia.go @@ -1,5 +1,10 @@ package memory +import ( + "fmt" + "strings" +) + // PIA defines the information for and operation allowed for PIA PIA type PIA struct { CPUBus @@ -55,3 +60,25 @@ func (pia PIA) Peek(address uint16) (uint8, string, error) { oa := address - pia.origin return pia.memory[oa], "", nil } + +// MachineInfoTerse returns the RIOT information in terse format +func (pia PIA) MachineInfoTerse() string { + return pia.MachineInfo() +} + +// MachineInfo returns the RIOT information in verbose format +func (pia PIA) MachineInfo() string { + s := "" + for y := 0; y < 8; y++ { + for x := 0; x < 16; x++ { + s = fmt.Sprintf("%s %02x", s, pia.memory[uint16((y*16)+x)]) + } + s = fmt.Sprintf("%s\n", s) + } + return strings.Trim(s, "\n") +} + +// map String to MachineInfo +func (pia PIA) String() string { + return pia.MachineInfo() +}