diff options
| author | Uri Shaked | 2020-07-16 19:34:28 +0300 |
|---|---|---|
| committer | Uri Shaked | 2020-07-16 19:51:59 +0300 |
| commit | 3685e1a9b43f8c79d1e0a5554a1a15d4d0c77142 (patch) | |
| tree | 365bfa8634f75c1ef4fc84ecbc4ab290f4d2734a /src/utils | |
| parent | test(timer): remove stray console.log (diff) | |
| download | avr8js-3685e1a9b43f8c79d1e0a5554a1a15d4d0c77142.tar.gz avr8js-3685e1a9b43f8c79d1e0a5554a1a15d4d0c77142.tar.bz2 avr8js-3685e1a9b43f8c79d1e0a5554a1a15d4d0c77142.zip | |
feat(eeprom): implement EEPROM peripheral
close #15
Diffstat (limited to '')
| -rw-r--r-- | src/utils/assembler.ts | 2 | ||||
| -rw-r--r-- | src/utils/test-utils.ts | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/utils/assembler.ts b/src/utils/assembler.ts index 17b20b4..4823937 100644 --- a/src/utils/assembler.ts +++ b/src/utils/assembler.ts @@ -46,7 +46,7 @@ interface LineTablePass1 { byteOffset: number; } -interface LineTable extends LineTablePass1 { +export interface LineTable extends LineTablePass1 { bytes: string; } diff --git a/src/utils/test-utils.ts b/src/utils/test-utils.ts new file mode 100644 index 0000000..dfb6b32 --- /dev/null +++ b/src/utils/test-utils.ts @@ -0,0 +1,31 @@ +import { CPU } from '../cpu/cpu'; +import { assemble } from './assembler'; +import { avrInstruction } from '../cpu/instruction'; + +export function asmProgram(source: string) { + const { bytes, errors, lines } = assemble(source); + if (errors.length) { + throw new Error('Assembly failed: ' + errors); + } + return { program: new Uint16Array(bytes.buffer), lines }; +} + +export class TestProgramRunner { + constructor( + private readonly cpu: CPU, + private readonly peripheral: { tick: () => void }, + private readonly onBreak?: (cpu: CPU) => void + ) {} + + runInstructions(count: number) { + const { cpu, peripheral, onBreak } = this; + for (let i = 0; i < count; i++) { + if (cpu.progMem[cpu.pc] === 0x9598) { + onBreak?.(cpu); + throw new Error('BREAK instruction encountered'); + } + avrInstruction(cpu); + peripheral.tick(); + } + } +} |
