diff options
| author | Uri Shaked | 2020-08-22 16:43:31 +0300 |
|---|---|---|
| committer | Uri Shaked | 2020-08-22 16:43:31 +0300 |
| commit | ad8f51916db816464331e1e0816d83ad69f7bf8d (patch) | |
| tree | 66f4991445e08f3d7c706c22a124bc1960641a56 /src/utils/test-utils.ts | |
| parent | test(eeprom): remove useless line (diff) | |
| download | avr8js-ad8f51916db816464331e1e0816d83ad69f7bf8d.tar.gz avr8js-ad8f51916db816464331e1e0816d83ad69f7bf8d.tar.bz2 avr8js-ad8f51916db816464331e1e0816d83ad69f7bf8d.zip | |
feat(spi): implement SPI master #33
close #33
Diffstat (limited to 'src/utils/test-utils.ts')
| -rw-r--r-- | src/utils/test-utils.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/utils/test-utils.ts b/src/utils/test-utils.ts index ca483f3..2bec178 100644 --- a/src/utils/test-utils.ts +++ b/src/utils/test-utils.ts @@ -2,6 +2,8 @@ import { CPU } from '../cpu/cpu'; import { assemble } from './assembler'; import { avrInstruction } from '../cpu/instruction'; +const BREAK_OPCODE = 0x9598; + export function asmProgram(source: string) { const { bytes, errors, lines } = assemble(source); if (errors.length) { @@ -20,7 +22,7 @@ export class TestProgramRunner { runInstructions(count: number) { const { cpu, peripheral, onBreak } = this; for (let i = 0; i < count; i++) { - if (cpu.progMem[cpu.pc] === 0x9598) { + if (cpu.progMem[cpu.pc] === BREAK_OPCODE) { onBreak?.(cpu); throw new Error('BREAK instruction encountered'); } @@ -28,4 +30,17 @@ export class TestProgramRunner { peripheral.tick(); } } + + runToBreak(maxIterations = 5000) { + const { cpu, peripheral, onBreak } = this; + for (let i = 0; i < maxIterations; i++) { + if (cpu.progMem[cpu.pc] === BREAK_OPCODE) { + onBreak?.(cpu); + return; + } + avrInstruction(cpu); + peripheral.tick(); + } + throw new Error('Program ran for too long without a BREAK instruction'); + } } |
