aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorUri Shaked2020-12-09 15:55:12 +0200
committerGitHub2020-12-09 15:55:12 +0200
commitb2280efa5457685db66d6ce6b156f37d5e678204 (patch)
tree1857fe48d3e2d32a39cfe810a0dfdd7d96526b3a /src/utils
parenttest(cpu): improve test name (diff)
parentperf!: centeral timekeeping (diff)
downloadavr8js-b2280efa5457685db66d6ce6b156f37d5e678204.tar.gz
avr8js-b2280efa5457685db66d6ce6b156f37d5e678204.tar.bz2
avr8js-b2280efa5457685db66d6ce6b156f37d5e678204.zip
Merge pull request #71 from wokwi/interrupt-refactor
refactor: central interrupt handling #38
Diffstat (limited to '')
-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');
}