aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2019-01-22 12:25:57 -0500
committerAustin Adams <git@austinjadams.com>2019-01-22 12:25:57 -0500
commit867513d0d883ad504144733deda52e3f78e40c67 (patch)
treedea96d367645978b443a40e9bf86c39325bc50ec
parent4079c706f77fec43ef5b469ffa1f379d1805ff8a (diff)
downloadnovice-867513d0d883ad504144733deda52e3f78e40c67.tar.gz
novice-867513d0d883ad504144733deda52e3f78e40c67.tar.xz
Allow travelling back in time
-rw-r--r--novice/simulator/cli-debugger.ts8
-rw-r--r--novice/simulator/debugger.ts4
-rw-r--r--novice/simulator/simulator.ts5
3 files changed, 17 insertions, 0 deletions
diff --git a/novice/simulator/cli-debugger.ts b/novice/simulator/cli-debugger.ts
index 6fa04fa..8eebcf4 100644
--- a/novice/simulator/cli-debugger.ts
+++ b/novice/simulator/cli-debugger.ts
@@ -76,6 +76,10 @@ class CliDebugger extends Debugger {
showState: true, method: this.step,
help: 'run a single instruction'},
+ {op: ['unstep', 'undo'], operands: 0,
+ showState: true, method: this.unstepCmd,
+ help: 'undo the last instruction'},
+
{op: ['print'], operands: 1,
showState: false, method: this.printCmd,
help: 'print an address range, ex: 0xef00-0xf000'},
@@ -192,6 +196,10 @@ class CliDebugger extends Debugger {
return this.fmtHex(word, this.isa.mem.word);
}
+ private async unstepCmd(): Promise<void> {
+ this.unstep();
+ }
+
private async breakCmd(operands: string[]): Promise<void> {
const addr = this.parseAddr(operands[0]);
this.addBreakpoint(addr);
diff --git a/novice/simulator/debugger.ts b/novice/simulator/debugger.ts
index 36c27b1..445f2cd 100644
--- a/novice/simulator/debugger.ts
+++ b/novice/simulator/debugger.ts
@@ -61,6 +61,10 @@ class Debugger extends Simulator {
return null;
}
+ return this.reassemble(spec, fields);
+ }
+
+ public reassemble(spec: InstructionSpec, fields: Fields): string {
const operands: string[] = [];
for (const field of spec.fields) {
diff --git a/novice/simulator/simulator.ts b/novice/simulator/simulator.ts
index d35a596..707266a 100644
--- a/novice/simulator/simulator.ts
+++ b/novice/simulator/simulator.ts
@@ -121,6 +121,11 @@ class Simulator {
this.log.push(logEntry);
}
+ public unstep(): void {
+ this.popLogEntry();
+ this.pc -= this.isa.pc.increment;
+ }
+
public popLogEntry(): MachineStateLogEntry {
const logEntry = this.log.pop();