From 8dcafb11983f3918378332db8dba978614b1692c Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Wed, 30 Sep 2020 10:39:56 +0300 Subject: fix(cpu): incorrect address for RAMPZ / EIND We used their I/O space address intead of their data space address. close #61 --- src/cpu/instruction.spec.ts | 4 ++-- src/cpu/instruction.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/cpu') diff --git a/src/cpu/instruction.spec.ts b/src/cpu/instruction.spec.ts index 0665fe8..18ff76b 100644 --- a/src/cpu/instruction.spec.ts +++ b/src/cpu/instruction.spec.ts @@ -26,8 +26,8 @@ const r31 = 31; const X = 26; const Y = 28; const Z = 30; -const RAMPZ = 59; -const EIND = 60; +const RAMPZ = 0x5b; +const EIND = 0x5c; const SP = 93; const SPH = 94; const SREG = 95; diff --git a/src/cpu/instruction.ts b/src/cpu/instruction.ts index e82b811..bd9d2a2 100644 --- a/src/cpu/instruction.ts +++ b/src/cpu/instruction.ts @@ -221,7 +221,7 @@ export function avrInstruction(cpu: ICPU) { /* EICALL, 1001 0101 0001 1001 */ const retAddr = cpu.pc + 1; const sp = cpu.dataView.getUint16(93, true); - const eind = cpu.data[0x3c]; + const eind = cpu.data[0x5c]; cpu.data[sp] = retAddr & 255; cpu.data[sp - 1] = (retAddr >> 8) & 255; cpu.data[sp - 2] = (retAddr >> 16) & 255; @@ -230,28 +230,28 @@ export function avrInstruction(cpu: ICPU) { cpu.cycles += 3; } else if (opcode === 0x9419) { /* EIJMP, 1001 0100 0001 1001 */ - const eind = cpu.data[0x3c]; + const eind = cpu.data[0x5c]; cpu.pc = ((eind << 16) | cpu.dataView.getUint16(30, true)) - 1; cpu.cycles++; } else if (opcode === 0x95d8) { /* ELPM, 1001 0101 1101 1000 */ - const rampz = cpu.data[0x3b]; + const rampz = cpu.data[0x5b]; cpu.data[0] = cpu.progBytes[(rampz << 16) | cpu.dataView.getUint16(30, true)]; cpu.cycles += 2; } else if ((opcode & 0xfe0f) === 0x9006) { /* ELPM(REG), 1001 000d dddd 0110 */ - const rampz = cpu.data[0x3b]; + const rampz = cpu.data[0x5b]; cpu.data[(opcode & 0x1f0) >> 4] = cpu.progBytes[(rampz << 16) | cpu.dataView.getUint16(30, true)]; cpu.cycles += 2; } else if ((opcode & 0xfe0f) === 0x9007) { /* ELPM(INC), 1001 000d dddd 0111 */ - const rampz = cpu.data[0x3b]; + const rampz = cpu.data[0x5b]; const i = cpu.dataView.getUint16(30, true); cpu.data[(opcode & 0x1f0) >> 4] = cpu.progBytes[(rampz << 16) | i]; cpu.dataView.setUint16(30, i + 1, true); if (i === 0xffff) { - cpu.data[0x3b] = (rampz + 1) % (cpu.progBytes.length >> 16); + cpu.data[0x5b] = (rampz + 1) % (cpu.progBytes.length >> 16); } cpu.cycles += 2; } else if ((opcode & 0xfc00) === 0x2400) { -- cgit v1.2.3