aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorUri Shaked2020-07-16 19:34:28 +0300
committerUri Shaked2020-07-16 19:51:59 +0300
commit3685e1a9b43f8c79d1e0a5554a1a15d4d0c77142 (patch)
tree365bfa8634f75c1ef4fc84ecbc4ab290f4d2734a /src/utils
parenttest(timer): remove stray console.log (diff)
downloadavr8js-3685e1a9b43f8c79d1e0a5554a1a15d4d0c77142.tar.gz
avr8js-3685e1a9b43f8c79d1e0a5554a1a15d4d0c77142.tar.bz2
avr8js-3685e1a9b43f8c79d1e0a5554a1a15d4d0c77142.zip
feat(eeprom): implement EEPROM peripheral
close #15
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/assembler.ts2
-rw-r--r--src/utils/test-utils.ts31
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();
+ }
+ }
+}
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.