aboutsummaryrefslogtreecommitdiff
path: root/src/cpu
diff options
context:
space:
mode:
authorUri Shaked2020-09-30 10:39:56 +0300
committerUri Shaked2020-09-30 10:39:56 +0300
commit8dcafb11983f3918378332db8dba978614b1692c (patch)
tree33b2cf0fe54e7c90f36161f8ffea88f84b2042cb /src/cpu
parent0.11.2 (diff)
downloadavr8js-8dcafb11983f3918378332db8dba978614b1692c.tar.gz
avr8js-8dcafb11983f3918378332db8dba978614b1692c.tar.bz2
avr8js-8dcafb11983f3918378332db8dba978614b1692c.zip
fix(cpu): incorrect address for RAMPZ / EIND
We used their I/O space address intead of their data space address. close #61
Diffstat (limited to 'src/cpu')
-rw-r--r--src/cpu/instruction.spec.ts4
-rw-r--r--src/cpu/instruction.ts12
2 files changed, 8 insertions, 8 deletions
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) {