aboutsummaryrefslogtreecommitdiff
path: root/src/cpu
diff options
context:
space:
mode:
authorUri Shaked2020-04-28 23:42:20 +0300
committerUri Shaked2020-04-28 23:42:20 +0300
commitf16d9f9f48fb5e74ab10fe79a8206223342d5010 (patch)
tree0ae771f977ce51e1d34ab7f79cd6a31d918bfd12 /src/cpu
parentchore: release 0.8.2 (diff)
downloadavr8js-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.ts8
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];
}