diff options
| author | Uri Shaked | 2020-04-28 23:42:20 +0300 |
|---|---|---|
| committer | Uri Shaked | 2020-04-28 23:42:20 +0300 |
| commit | f16d9f9f48fb5e74ab10fe79a8206223342d5010 (patch) | |
| tree | 0ae771f977ce51e1d34ab7f79cd6a31d918bfd12 /src/cpu/cpu.ts | |
| parent | chore: release 0.8.2 (diff) | |
| download | avr8js-f16d9f9f48fb5e74ab10fe79a8206223342d5010.tar.gz avr8js-f16d9f9f48fb5e74ab10fe79a8206223342d5010.tar.bz2 avr8js-f16d9f9f48fb5e74ab10fe79a8206223342d5010.zip | |
fix(timer): incorrect high counter byte behavior
According to the datasheet, the value of the high byte of the counter for 16-bit timers (such as timer 1) is only updated when the low byte is being read/written.
close #37
Diffstat (limited to '')
| -rw-r--r-- | src/cpu/cpu.ts | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cpu/cpu.ts b/src/cpu/cpu.ts index 0c60c9e..5663a1c 100644 --- a/src/cpu/cpu.ts +++ b/src/cpu/cpu.ts @@ -40,11 +40,16 @@ export interface CPUMemoryHooks { [key: number]: CPUMemoryHook; } +export type CPUMemoryReadHook = (addr: u16) => u8; +export interface CPUMemoryReadHooks { + [key: number]: CPUMemoryReadHook; +} export class CPU implements ICPU { readonly data: Uint8Array = new Uint8Array(this.sramBytes + registerSpace); readonly data16 = new Uint16Array(this.data.buffer); readonly dataView = new DataView(this.data.buffer); readonly progBytes = new Uint8Array(this.progMem.buffer); + readonly readHooks: CPUMemoryReadHooks = []; readonly writeHooks: CPUMemoryHooks = []; readonly pc22Bits = this.progBytes.length > 0x20000; @@ -61,6 +66,9 @@ export class CPU implements ICPU { } readData(addr: number) { + if (addr >= 32 && this.readHooks[addr]) { + return this.readHooks[addr](addr); + } return this.data[addr]; } |
