aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorUri Shaked2020-12-09 15:46:53 +0200
committerUri Shaked2020-12-09 15:49:41 +0200
commit9c1288f18889ae3bd10869a9f6ebc53defa3024b (patch)
tree1857fe48d3e2d32a39cfe810a0dfdd7d96526b3a /src/utils
parentrefactor: central interrupt handling #38 (diff)
downloadavr8js-9c1288f18889ae3bd10869a9f6ebc53defa3024b.tar.gz
avr8js-9c1288f18889ae3bd10869a9f6ebc53defa3024b.tar.bz2
avr8js-9c1288f18889ae3bd10869a9f6ebc53defa3024b.zip
perf!: centeral timekeeping
This should improve performance, especially when running simulations with multiple peripherals. For instance, the demo project now runs at ~322%, up from ~185% in AVR8js 0.13.1. BREAKING CHANGE: `tick()` methods were removed from individual peripherals. You now need to call `cpu.tick()` instead.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/test-utils.ts14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/utils/test-utils.ts b/src/utils/test-utils.ts
index 2bec178..4b2efff 100644
--- a/src/utils/test-utils.ts
+++ b/src/utils/test-utils.ts
@@ -13,33 +13,29 @@ export function asmProgram(source: string) {
}
export class TestProgramRunner {
- constructor(
- private readonly cpu: CPU,
- private readonly peripheral: { tick: () => void },
- private readonly onBreak?: (cpu: CPU) => void
- ) {}
+ constructor(private readonly cpu: CPU, private readonly onBreak?: (cpu: CPU) => void) {}
runInstructions(count: number) {
- const { cpu, peripheral, onBreak } = this;
+ const { cpu, onBreak } = this;
for (let i = 0; i < count; i++) {
if (cpu.progMem[cpu.pc] === BREAK_OPCODE) {
onBreak?.(cpu);
throw new Error('BREAK instruction encountered');
}
avrInstruction(cpu);
- peripheral.tick();
+ cpu.tick();
}
}
runToBreak(maxIterations = 5000) {
- const { cpu, peripheral, onBreak } = this;
+ const { cpu, onBreak } = this;
for (let i = 0; i < maxIterations; i++) {
if (cpu.progMem[cpu.pc] === BREAK_OPCODE) {
onBreak?.(cpu);
return;
}
avrInstruction(cpu);
- peripheral.tick();
+ cpu.tick();
}
throw new Error('Program ran for too long without a BREAK instruction');
}