diff options
Diffstat (limited to 'src/cpu')
| -rw-r--r-- | src/cpu/cpu.ts | 43 | ||||
| -rw-r--r-- | src/cpu/instruction.ts | 4 | ||||
| -rw-r--r-- | src/cpu/interrupt.ts | 4 |
3 files changed, 18 insertions, 33 deletions
diff --git a/src/cpu/cpu.ts b/src/cpu/cpu.ts index 7a518b8..2675d1d 100644 --- a/src/cpu/cpu.ts +++ b/src/cpu/cpu.ts @@ -11,33 +11,6 @@ import { avrInterrupt } from './interrupt'; const registerSpace = 0x100; -// eslint-disable-next-line @typescript-eslint/interface-name-prefix -export interface ICPU { - readonly data: Uint8Array; - readonly dataView: DataView; - readonly progMem: Uint16Array; - readonly progBytes: Uint8Array; - - /** - * Whether the program counter (PC) can address 22 bits (the default is 16) - */ - readonly pc22Bits: boolean; - - /** - * Program counter - */ - pc: u32; - - /** - * Clock cycle counter - */ - cycles: number; - - readData(addr: u16): u8; - writeData(addr: u16, value: u8, mask?: u8): void; - onWatchdogReset(): void; -} - export type CPUMemoryHook = (value: u8, oldValue: u8, addr: u16, mask: u8) => boolean | void; export interface CPUMemoryHooks { [key: number]: CPUMemoryHook; @@ -66,7 +39,7 @@ interface AVRClockEventEntry { next: AVRClockEventEntry | null; } -export class CPU implements ICPU { +export class CPU { readonly data: Uint8Array = new Uint8Array(this.sramBytes + registerSpace); readonly data16 = new Uint16Array(this.data.buffer); readonly dataView = new DataView(this.data.buffer); @@ -76,6 +49,10 @@ export class CPU implements ICPU { private readonly pendingInterrupts: AVRInterruptConfig[] = []; private nextClockEvent: AVRClockEventEntry | null = null; private readonly clockEventPool: AVRClockEventEntry[] = []; // helps avoid garbage collection + + /** + * Whether the program counter (PC) can address 22 bits (the default is 16) + */ readonly pc22Bits = this.progBytes.length > 0x20000; readonly gpioPorts = new Set<AVRIOPort>(); @@ -89,8 +66,16 @@ export class CPU implements ICPU { /* empty by default */ }; + /** + * Program counter + */ pc: u32 = 0; - cycles: u32 = 0; + + /** + * Clock cycle counter + */ + cycles = 0; + nextInterrupt: i16 = -1; constructor(public progMem: Uint16Array, private sramBytes = 8192) { diff --git a/src/cpu/instruction.ts b/src/cpu/instruction.ts index 9937ec9..e2bed5d 100644 --- a/src/cpu/instruction.ts +++ b/src/cpu/instruction.ts @@ -10,7 +10,7 @@ * Copyright (C) 2019, 2020 Uri Shaked */ -import { ICPU } from './cpu'; +import { CPU } from './cpu'; import { u16 } from '../types'; function isTwoWordInstruction(opcode: u16) { @@ -26,7 +26,7 @@ function isTwoWordInstruction(opcode: u16) { ); } -export function avrInstruction(cpu: ICPU) { +export function avrInstruction(cpu: CPU) { const opcode = cpu.progMem[cpu.pc]; if ((opcode & 0xfc00) === 0x1c00) { diff --git a/src/cpu/interrupt.ts b/src/cpu/interrupt.ts index 1bfa035..2e4ceb9 100644 --- a/src/cpu/interrupt.ts +++ b/src/cpu/interrupt.ts @@ -6,9 +6,9 @@ * Copyright (C) 2019, Uri Shaked */ -import { ICPU } from './cpu'; +import { CPU } from './cpu'; -export function avrInterrupt(cpu: ICPU, addr: number) { +export function avrInterrupt(cpu: CPU, addr: number) { const sp = cpu.dataView.getUint16(93, true); cpu.data[sp] = cpu.pc & 0xff; cpu.data[sp - 1] = (cpu.pc >> 8) & 0xff; |
